var xmlhttp
var response;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}

function myXMLHttpRequest() {
	var xmlhttplocal;
	try{
		xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	}catch (e){
		try{
			xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
		}catch (E){
			xmlhttplocal=false;
		}
	}

	if(!xmlhttplocal && typeof XMLHttpRequest!='undefined'){
		try{
			var xmlhttplocal = new XMLHttpRequest();
		}catch (e){
			var xmlhttplocal=false;
			alert('couldn\'t create xmlhttp object');
		}
	}
	return(xmlhttplocal);
}

function handleStateChange()
{        
	if (xmlhttp.readyState == 3){
		alert(xmlhttp.responseText);
	}
}

function ajax_call_bob(Url, param, returnDiv, showAlert) {
	xmlhttp.open("GET",Url+"?"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			//document.getElementById(returnDiv).innerHTML = xmlhttp.responseText;
			callBob();
			if(showAlert == true)
				alert(xmlhttp.responseText)
		}
	}
	xmlhttp.send(null);
	return false;
}

function ajax_call(Url, param, returnDiv, showAlert) {
    xmlhttp.open("GET",Url+"?"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById(returnDiv).innerHTML = xmlhttp.responseText;
			if(showAlert == true)
				alert(xmlhttp.responseText)
		}
	}
	xmlhttp.send(null);
	return false;
}




function ajax_call_compare_list(Url, param, returnDiv, showAlert) {   
    xmlhttp.open("GET",Url+"?"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
				//retvalue = trim(xmlhttp.responseText);
				
				window.location.reload(true);
		}
	}
	xmlhttp.send(null);
	return false;
}

function ajax_call_address(Url, param, returnDiv, showAlert) {
    xmlhttp.open("GET",Url+"?"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		   
		    retvalue = trim(xmlhttp.responseText);
		    if(retvalue=="false"){
		        document.location.href="login.php";	
		    }else{
		        document.getElementById('txtUserAddressid').value="";
		    	document.getElementById(returnDiv).innerHTML = xmlhttp.responseText;
		    }
	
		}
	}
	xmlhttp.send(null);
	return false;
}


function ajax_call_add_address(Url, param, returnDiv, showAlert) {
    xmlhttp.open("GET",Url+"?"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		    retvalue = trim(xmlhttp.responseText);
		    
		    if(retvalue=="false"){
		        window.opener.location.href="login.php";	
		        window.close();
		    }else{
		        window.opener.document.getElementById('deliveryDetails').innerHTML = retvalue;
		        
				var openerForm = opener.document.forms.frmCheckout;
				openerForm.action = "cart.php";
				openerForm.method = "post";
				openerForm.submit();
				
				setTimeout("closewindow()", 10);
		    }
		    
		}
	}
	xmlhttp.send(null);
	return false;
}

function closewindow(){
	window.close();
}


/**function ajax_call_paypal(Url, param) {
    alert(Url+"?"+param);
    xmlhttp.open("GET",Url+"?"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
				alert(xmlhttp.responseText);
				return true;
		}
	}
	xmlhttp.send(null);
	return false;
} **/

function ajax_call_test(Url, param, showAlert) {
	xmlhttp.open("GET",Url+"?"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var strString;
			strString = xmlhttp.responseText;
			var MyArray = strString.split("|");
			document.getElementById('img_block').innerHTML = MyArray[0];
			document.getElementById('frame_features').innerHTML = MyArray[1];
			document.getElementById('frame_measurements').innerHTML = MyArray[2];
			document.getElementById('sku_id').innerHTML = MyArray[3];
			
			if(showAlert == true)
				alert(xmlhttp.responseText)
		}
	}
	xmlhttp.send(null);
	return false;
}

/**
function ajax_call_checkaddress(Url, param, returnDiv, showAlert) {
  	xmlhttp.open("GET",Url+"?"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

			var retvalue = trim(xmlhttp.responseText);
			
			if(retvalue != "false" && retvalue == "addhomeupdate"){
				var answer = confirm("You are already having a home Address, You want to replace it with this address");
				if(answer){
					param = param+"&mode=update";
					Url = "addaddress.php";
					ajax_call_addaddress(Url, param, returnDiv, true);				   
				}else{
					return false;
				}
			}else if(retvalue != "false" && retvalue == "addothersupdate"){
				var answer = confirm("You are already having this Address, You want to replace it with this address");
				if(answer){
					param = param+"&mode=update";
					Url = "addaddress.php";
					ajax_call_addaddress(Url, param, returnDiv, true);				   
				}else{
					return false;
				}
			}else{
			    param = param+"&mode=add";
			    Url = "addaddress.php";
				ajax_call_addaddress(Url, param, returnDiv, true);
			}	

		}
	}
	xmlhttp.send(null);
	return false;
}



function ajax_call_addaddress(Url, param, returnDiv, showAlert) {
   	xmlhttp.open("GET",Url+"?"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			retvalue = trim(xmlhttp.responseText);
			retarray = retvalue.split("|||");
			if(retarray.length > 1){
				addtype =  trim(retarray[0]);
				dispvalue = trim(retarray[1]);
			}else{
				addtype =  "";
				dispvalue = retarray[0];
			}
		//	alert(dispvalue);
			document.getElementById(returnDiv).innerHTML = dispvalue;


//   		document.getElementById('selHomeStore')[document.getElementById('selHomeStore').selectedIndex].value == "";
			if(addtype!="" && addtype=="home" && document.getElementById('selHomeStore').value == ""){
				url = "homestoredetail.php";
		    	param = "";
		    	ajax_call_storeadd(url,param,"homestoreadd",true); 
			}else if(showAlert == true){
			    emptyaddressfields();
	
			}	
		}
	}
	xmlhttp.send(null);
	return false;
}

**/

function ajax_call_country_by_postcode(Url, param, returnDiv, showAlert, postcode) {    
	
	xmlhttp.open("GET",Url+"&"+param,true);
	var oldcountry = document.getElementById('selUserCountry').value;
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var retvalue = trim(xmlhttp.responseText);		
			if(retvalue != ""){
				document.getElementById(returnDiv).innerHTML = retvalue;	
			}
			
    			country=document.getElementById('selUserCountry').value;
    			if(oldcountry!=country && document.getElementById('selHomeStore').value != ""){
    				emptyaddressfields();
    			}
    			if(oldcountry!=country || document.getElementById('selHomeStore').value == ""){
					url = "registration";
	    			param = "method_name=findNearestStoresByPostcode&postcode="+postcode+"&country="+country;
					msg ="";
		        	ajax_call_storeadd(url,param,"homestoreadd",msg, postcode);		        
        	    }
	        	    	          	    
		}
	}
	xmlhttp.send(null);
	return false;
}

function ajax_call_storeadd(Url, param, returnDiv, showAlert, postcode) {
	xmlhttp.open("GET",Url+"&"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var retvalue = trim(xmlhttp.responseText);		
			if(retvalue !="" && retvalue != "false"){
				document.getElementById(returnDiv).innerHTML = retvalue;	
			}
			
		/*  	url = "delCountryByPostcode.php";
			alert(url);
    		country=document.getElementById('selUserCountry').value;
    		param = "country="+country;
			msg ="";
	        ajax_call_delivery(url,param,"userdelcountry",msg); */
	        url = "Country";
    		param = "method_name=showDeliveryCountryByPostcode&postcode="+postcode;
			msg ="";
	        ajax_call_delivery(url,param,"userdelcountry", msg);	
			
		}
	}
					 
	
	xmlhttp.send(null);
	return false;
}

function ajax_call_delivery(Url, param, returnDiv, showAlert) {
	
	xmlhttp.open("GET",Url+"&"+param,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var retvalue = trim(xmlhttp.responseText);		
			if(retvalue != ""){
				document.getElementById(returnDiv).innerHTML = retvalue;	
			}
			
		}
	}
					 
	
	xmlhttp.send(null);
	return false;
}

function ajax_call_postcodeByCountry(Url, param, returnDiv, showAlert) {	 
	xmlhttp.open("GET",Url+"/"+param,true);
	xmlhttp.onreadystatechange=function() {
	  
		if (xmlhttp.readyState==4) {
		    
			var retvalue = trim(xmlhttp.responseText);		
			
			if(retvalue != ""){
			
				if(retvalue == "true"){
					country=document.getElementById('selDeliveryCountry').value;
					if(country==1){
						validatePostcodeFormat();
						return true;
					}else{
						return true;
					}
				
				}else{
				alert(MUST_ENTER_DELIVERY_ADDRESS_POSTCODE_BY_HOME_COUNTRY);				
				document.getElementById('txtDeliveryPostcode').focus();
				return false;
				
				}		

			}
			
		}
	}
	
	
					 
	
	xmlhttp.send(null);
	return false;
}

function ajax_bob_usage(Url){	
        xmlhttp.open("GET",Url,true);
	xmlhttp.onreadystatechange=function() {		
		if (xmlhttp.readyState==4) {
			return true;
		}
	}
	xmlhttp.send(null);
	return false;
}

function ajax_fast_track(Url){
	xmlhttp.open("GET",Url,false);
	xmlhttp.send(null);
	var retvalue = trim(xmlhttp.responseText);
			if(retvalue != ""){
				if(retvalue == "true"){
					return true;
				}else if(retvalue == "false"){
					alert(PLEASE_ENTER_FAST_TRACK_CODE);				
					document.getElementById('txtCode1').focus();
					return false;
				}else if(retvalue == "invalid"){
					alert(UNABLE_TO_PROCESS_FAST_TRACK_CODE);				
					document.getElementById('txtCode1').focus();
					return false;
				}			

			}
}
