var xmlHttp;

function gup( name )
// pass a URL parameter name and it returns the value
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function showCustomer(str) { 

	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX!");
  		return;
  	}	
	document.getElementById("theLabel").innerHTML = "processing...";
	
	// Get State info update
	var url="../_GetState.asp";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function getContact(str) { 

	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX!");
  		return;
  	}	
	// Get Contact info update	
	var url="../_GetContactInfo.asp";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=contactChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() { 
	if (xmlHttp.readyState==4) {
		// gets values from response
		var theResponse = xmlHttp.responseText
		// returns <br /> if no state for given country
		if (theResponse == "<br/>" ) {
			document.getElementById("theLabel").innerHTML = "";
			document.getElementById("theState").innerHTML = ""
		} else {
			if (gup('langcode') == "ger") {
				document.getElementById("theLabel").innerHTML = "<span style=\"color:#FF0000;\">*</span> Bundesland";			
			} else {
				document.getElementById("theLabel").innerHTML = "<span style=\"color:#FF0000;\">*</span> State or Province";
			}			
			
			document.getElementById("theState").innerHTML = theResponse;
		}
		// After new State list is returned, get new Contact info
		getContact(document.getElementById("country").value);
	}
}

function contactChanged() { 
	if (xmlHttp.readyState==4) {
		// gets values from response
		var theResponse = xmlHttp.responseText		
			document.getElementById("theContactInfo").innerHTML = theResponse;
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
  // Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e) {
  // Internet Explorer
  		try {
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e) {
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}
	return xmlHttp;
}
