// JavaScript Document
var http;
var idToDisplayMsg;
var urlForAjax;
var idToDisplayMsgVoucher;



// HTTP REQUEST Function Use this to call a HTTP request
function getHTTPObject() {
	var xmlhttp=null;
 	if(window.XMLHttpRequest){
    	xmlhttp = new XMLHttpRequest();
  	}
  	else if (window.ActiveXObject){
    	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	if (!xmlhttp){
        	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
    }
  	return xmlhttp;
}

// Call this function on state change
function stateChanged(){
		var docEle=eval("document.getElementById('"+idToDisplayMsg+"')");	
		if( http.readyState == 4){
			contentArray=http.responseText.split("|");
			document.getElementById('withvat').value=contentArray[2];
			document.getElementById('voucherId').value=contentArray[3];
			document.getElementById('voucherAmount').value=contentArray[4];
			document.getElementById('voucherType').value=contentArray[5];
			document.getElementById('voucher_code').value=contentArray[6];
			
			if(contentArray[1]=="1")
			{
				document.getElementById('hiddenDiv').style.display="block";
			}
			if(contentArray[6]!='0' || contentArray[6]!='1')
			{
				document.getElementById(idToDisplayMsg).style.background="#FFFFCC";
				
				
			}
			if(contentArray[7]=='refresh')
			{
				document.getElementById(idToDisplayMsg).style.background="#FFFFFF";
				
			}
			
			docEle.innerHTML=contentArray[0];
			
			
			//document.getElementById('hiddenDiv').style.display="block";
			var inner = document.getElementById(idToDisplayMsg).innerHTML;			 
		}
		else
		{
			document.getElementById(idToDisplayMsg).innerHTML = "<img src='images/loading_animation.gif />'";		 
		}
}
// end State Changed

function getImages(gallery_id){// get the from DD
	
	
	idToDisplayMsg='link';	
	http=null;
	http = getHTTPObject();
	
	urlForAjax = "displayImage.php?gid="+gallery_id+"&mathRandomNum="+Math.random();	
	http.open("GET", urlForAjax , true);
	http.onreadystatechange = stateChanged;	
	http.send(null);

}

function checkDiscount(discount_voucher,withvat){// get the from DD
	
	idToDisplayMsg='voucher';	
	http=null;
	http = getHTTPObject();
	//alert(withvat);
	
	urlForAjax = "check_voucher.php?discount_voucher="+discount_voucher+"&woVoucher="+withvat+"&mathRandomNum="+Math.random();	
	http.open("GET", urlForAjax , true);
	http.onreadystatechange = stateChanged;	
	http.send(null);

}

function voucherTextbox(woVoucher){
	idToDisplayMsg='voucher';	
	http=null;
	http = getHTTPObject();
	
	urlForAjax = "check_voucher.php?refresh=1&woVoucher="+woVoucher+"&mathRandomNum="+Math.random();	
	http.open("GET", urlForAjax , true);
	http.onreadystatechange = stateChanged;	
	http.send(null);
	
	
}



function getModel(funcName,txttype,txtsubcat,sel){

	var xmlhttp=false; //Clear our fetching variable
	try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object.
	} catch (e) {
			try {
					xmlhttp = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			xmlhttp = false;
					}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}		
var type=document.getElementById(txttype).value;
	var file = 'ajaxpage.php?funcName='+funcName+'&type='+type+'&sel='+sel;
	//This is the path to the file we just finished making *
    //alert(file);
	xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
		//alert(xmlhttp.readyState);
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ 
				contentArray=content.split("|");
					document.getElementById(txtsubcat).innerHTML = contentArray[0];
					document.getElementById('quantity').value='0';
					//document.getElementById('cost').value=contentArray[2];
					//document.getElementById('minimum_pages').value=contentArray[1];
					//document.getElementById('load1').innerHTML = "";
					return;
                }
        }
		else{
				document.getElementById(txtsubcat).innerHTML = "<img src='images/loading_animation.gif />'";
			
			}
		
        }
		
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function getCover(funcName,txttype,txtsubcat,radioVal,sel){
	//alert(radioVal);

	
	var xmlhttp=false; //Clear our fetching variable
	try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object.
	} catch (e) {
			try {
					xmlhttp = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			xmlhttp = false;
					}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}		
var type=document.getElementById(txttype).value;
	var file = 'ajaxpage.php?funcName='+funcName+'&type='+type+'&sel='+sel+'&radioVal='+radioVal;
	//This is the path to the file we just finished making *
    //alert(file);
	xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
		//alert(xmlhttp.readyState);
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ 
				contentArray=content.split("|");
					document.getElementById(txtsubcat).innerHTML = contentArray[0];
					document.getElementById('amount1').innerHTML=contentArray[1];
					document.getElementById('amount2').innerHTML=contentArray[2];
					document.getElementById('minimum_pages').innerHTML=contentArray[4];
					document.getElementById('cost').value=contentArray[5];
					document.getElementById('quantity').value='0';
					document.getElementById('amount3').innerHTML=contentArray[3];
					if(contentArray[6]!=radioVal && contentArray[6]!='3')
					{
						alert('Chosen option of days not available for selected cover option, size and orientation. Available option for number of days will be selected.');
						
						if(radioVal==1)
						{	
							document.getElementById('time2').checked="checked";
							document.getElementById('add_option').style.display="block";
							document.getElementById('aaa').value=2;
						}
						else if(radioVal==2)
						{
							document.getElementById('time').checked="checked";
							document.getElementById('add_option').style.display="none";
							document.getElementById('aaa').value=1;
							
							
						}
						
					}
					//document.getElementById('amount3').value=contentArray[3];
					//document.getElementById('subcount').value=contentArray[1];
					//document.getElementById('load1').innerHTML = "";
					return;
                }
        }
		else{
				//document.getElementById('load1').innerHTML = "<img src='images/loading_animation.gif />'";
			
			}
		
        }
		
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function getCost(funcName,txttype,priceid,txtsubcat){
	
	
	var xmlhttp=false; //Clear our fetching variable
	try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object.
	} catch (e) {
			try {
					xmlhttp = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			xmlhttp = false;
					}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}		
var type=document.getElementById(txttype).value;
	var file = 'ajaxpage.php?funcName='+funcName+'&type='+type+'&priceid='+priceid;
	//This is the path to the file we just finished making *
    //alert(file);
	xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
		//alert(xmlhttp.readyState);
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ 
				contentArray=content.split("|");
				
					document.getElementById('cost').value = contentArray[0];
					document.getElementById('quantity').value='0';

					
					//document.getElementById('subcount').value=contentArray[1];
					//document.getElementById('load1').innerHTML = "";
					
					return;
                }
        }
		else{
				//document.getElementById('load1').innerHTML = "<img src='images/loading_animation.gif />'";
			
			}
		
        }
		
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function getFinalCost(funcName,txttype,cost,txtsubcat){
	
	
	var xmlhttp=false; //Clear our fetching variable
	try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object.
	} catch (e) {
			try {
					xmlhttp = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			xmlhttp = false;
					}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}		
var type=document.getElementById(txttype).value;
	var file = 'ajaxpage.php?funcName='+funcName+'&cost='+cost+'&qty='+type;
	//This is the path to the file we just finished making *
    //alert(file);
	xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
		//alert(xmlhttp.readyState);
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ 
				contentArray=content.split("|");
				
					document.getElementById('total').innerHTML = contentArray[1];
					document.getElementById('subcount').value=contentArray[0];
					
					return;
                }
        }
		else{
				document.getElementById('total').innerHTML = "<img src='images/loading_animation.gif />'";
			
			}
		
        }
		
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function ajaxTotal(id,pages,qty,radioVal,addCost){
	
	
	
	var xmlhttp=false; //Clear our fetching variable
	try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object.
	} catch (e) {
			try {
					xmlhttp = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			xmlhttp = false;
					}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}		
//var type=document.getElementById(txttype).value;
	var file = 'orderCost.php?pid='+id+'&pages='+pages+'&qty='+qty+'&addCost='+addCost+'&radioVal='+radioVal;
	//This is the path to the file we just finished making *
    //alert(file);
	xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
		//alert(xmlhttp.readyState);
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ 
				contentArray=content.split("|");
				if(contentArray[4]!=radioVal && contentArray[4]!='3')
					{
						alert('Chosen option of days not available for selected cover option, size and orientation ');
						if(radioVal==1)
						{	
							document.getElementById('add_option').style.display="";
							document.getElementById('time2').checked="checked";
							document.getElementById('aaa').value=2;
							
						}
						else if(radioVal==2)
						{
							document.getElementById('add_option').style.display="none";
							document.getElementById('time').checked="checked";
							document.getElementById('aaa').value=1;
							
							
						}
					}	
					
					document.getElementById('total').innerHTML = contentArray[3];
										
					document.getElementById('subcount').value=contentArray[0];
					
					
					//document.getElementById('load1').innerHTML = "";
					return;
                }
        }
		else{
				//document.getElementById('load1').innerHTML = "Loading...";
			
			}
		
        }
		
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function additionalCost(prevCost,addId,pid,qty){
	//alert(prevCost);
	
	var xmlhttp=false; //Clear our fetching variable
	try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object.
	} catch (e) {
			try {
					xmlhttp = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			xmlhttp = false;
					}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}		
//var type=document.getElementById(txttype).value;
	var file = 'addOrderCost.php?prevCost='+prevCost+'&addId='+addId+'&pid='+pid+'&qty='+qty;
	//This is the path to the file we just finished making *
    //alert(file);
	xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
		//alert(xmlhttp.readyState);
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ 
				contentArray=content.split("|");
				
					document.getElementById('total').innerHTML = contentArray[0];
					document.getElementById('subcount').value=contentArray[0];
					//document.getElementById('load1').innerHTML = "";
					return;
                }
        }
		else{
				//document.getElementById('load1').innerHTML = "Loading...";
			
			}
		
        }
		
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function getCoverOption(id)
{
	var xmlhttp=false; //Clear our fetching variable
	try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object.
	} catch (e) {
			try {
					xmlhttp = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			xmlhttp = false;
					}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}		
//var type=document.getElementById(txttype).value;
	var file = 'get_cover_option.php?id='+id;
	//This is the path to the file we just finished making *
    //alert(file);
	xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
		//alert(xmlhttp.readyState);
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ 
				contentArray=content.split("|");
				
					document.getElementById('total').innerHTML = contentArray[0];
					document.getElementById('subcount').value=contentArray[0];
					//document.getElementById('load1').innerHTML = "";
					return;
                }
        }
		else{
				//document.getElementById('load1').innerHTML = "Loading...";
			
			}
		
        }
		
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function stateChangedVoucher(){
		
		var docEle=eval("document.getElementById('"+idToDisplayMsgVoucher1+"')");	
		if( http.readyState == 4){
			var contentArray=http.responseText.split("|");
			//alert(http.responseText);
/*			if(contentArray[2]=='0')
			{*/
				document.getElementById('withvat').value=contentArray[2];
				/*window.location='index.php?page=gift&id='+idToDisplayMsgVoucher+'&msg=lessorder';	
				exit();
			}*/
			document.getElementById('voucherId').value=contentArray[3];
			document.getElementById('voucherAmount').value=contentArray[4];
			document.getElementById('voucherType').value=contentArray[5];
			document.getElementById('voucher_code').value=contentArray[6];
			
			if(contentArray[6]!='0' || contentArray[6]!='1')
			{
				document.getElementById(idToDisplayMsgVoucher1).style.background="#FFFFCC";
				
				
			}
			
			if(contentArray[1]=="1")
			{
				document.getElementById('hiddenDiv').style.display="block";
			}
			
			
			docEle.innerHTML=contentArray[0];
			
			
			//document.getElementById('hiddenDiv').style.display="block";
			//var inner = document.getElementById(idToDisplayMsg).innerHTML;			 
		}
		else
		{
			//document.getElementById(idToDisplayMsg).innerHTML = "<img src='images/loading_animation.gif />'";		 
		}
}

function checkDiscountVoucher(discount_voucher,withvat,voucherId){// get the from DD
	
	idToDisplayMsgVoucher=voucherId;
	idToDisplayMsgVoucher1='voucher';
	http=null;
	http = getHTTPObject();
	//alert(withvat);
	
	urlForAjax = "check_voucher.php?discount_voucher="+discount_voucher+"&woVoucher="+withvat+"&voucherId="+voucherId+"&mathRandomNum="+Math.random();	
	http.open("GET", urlForAjax , true);
	http.onreadystatechange = stateChangedVoucher;	
	http.send(null);

}



