function querystring( name )
{
  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 gup( name )
{
  var array= window.location.href.split("/");
  if (name=="oid") return array[4];
  if (name=="cid") return array[5];
}

	function switch_form_1(){
		var destination;
		
		if (querystring('refid')==""){
			destination="/offers/"+gup('oid')+"/"+gup('cid')+"/?intl=1";
		}
		else{
			destination="/offers/"+gup('oid')+"/"+gup('cid')+"/?intl=1&refid="+querystring('refid');
		}
		location.href=destination;
	}
	function switch_form_2(){
		var destination;
		
		if (querystring('refid')==""){
			destination="/offers/"+gup('oid')+"/"+gup('cid')+"/?intl=0";
		}
		else{
			destination="/offers/"+gup('oid')+"/"+gup('cid')+"/?intl=0&refid="+querystring('refid');
		}		
		location.href=destination;
	}
	function enableSubmit(){
		if (document.getElementById("checkphone").innerHTML.search("Unknown Area")!=-1 ||
			document.getElementById("checkemail").innerHTML.search("Invalid Domain")!=-1 ||
			document.getElementById("checkzip").innerHTML.search("Unknown Zip")!=-1
			){
			document.getElementsByName("submitbtn")[0].disabled=true;
		}
		else document.getElementsByName("submitbtn")[0].disabled=false;
	}
	
	function checkemail(){
		var fragment="/offers/scripts/validation_email.php?email="+document.getElementById("txtEmail").value;
		loadFragmentInToElement(fragment,'checkemail'); //async function
	}
	function checkphone(){
		var fragment="/offers/scripts/validation_phone.php?phone="+document.getElementById("txtPhone").value;
		loadFragmentInToElement(fragment,'checkphone'); //async function
	}
	function checkintlphone(el,country_code){
			var number=document.getElementById("txtPhone").value;
			for (i=0;i<number.length-5;i++){
				if (	number[i]==number[i+1] &&
						number[i]==number[i+2] &&
					  	number[i]==number[i+3] &&
					  	number[i]==number[i+4]){
				add_prefix(el,country_code);
				}
									  
			}
	}
	function checkzip(){
		//add 0 ahead ZipCode with less than 5 digits
		if (document.frmContact.txtZip.value.length==3)
			document.frmContact.txtZip.value="00"+document.frmContact.txtZip.value;
		if (document.frmContact.txtZip.value.length==4)
			document.frmContact.txtZip.value="0"+document.frmContact.txtZip.value;
		var fragment="/offers/scripts/getcity_byzip.php?zipcode="+document.getElementById("txtZip").value;
		loadFragmentInToElement(fragment,'checkzip'); //async function
	}
	//change background and disable Submit Button
	function updateForm(id){
		if (id=='checkemail'){
			if (document.getElementById("checkemail").innerHTML.search("Valid Email")==-1){
				document.getElementsByName("submitbtn")[0].disabled=false;
				document.getElementById("txtEmail").style.backgroundColor="#ff9f9f";
			}
			else document.getElementById("txtEmail").style.backgroundColor="#b8f5b1";	
		}
		if (id=='checkphone'){
			if (document.getElementById("checkphone").innerHTML.search("Unknown Area")==-1){
				document.getElementsByName("submitbtn")[0].disabled=false;
				document.getElementById("txtPhone").style.backgroundColor="#b8f5b1";
			}
			else document.getElementById("txtPhone").style.backgroundColor="#ff9f9f";
		}
		if (id=='checkzip'){
			if (document.getElementById("checkzip").innerHTML.search("Unknown Zip")==-1){
				document.getElementsByName("submitbtn")[0].disabled=false;
				document.getElementById("txtZip").style.backgroundColor="#b8f5b1";
			}
			else document.getElementById("txtZip").style.backgroundColor="#ff9f9f";
		}
	}
	function loadFragmentInToElement(fragment_url, element_id) { 
		var xmlhttp=false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		// JScript gives us Conditional compilation, we can cope with old IE versions.
		// and security blocked creation of the objects.
		try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		xmlhttp = false;
		}
		}
		@end @*/
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
		}
	    var element = document.getElementById(element_id); 
	    element.innerHTML = '<p style="font-size:10px;"><em>checking...</em></p>'; 
	    xmlhttp.open("GET", fragment_url); 
	    xmlhttp.onreadystatechange = function() { 
	        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
	            element.innerHTML = xmlhttp.responseText; 
				updateForm(element_id);
	        } 
	    } 
	    xmlhttp.send(null); 
	}

	function add_prefix(el,country_code) { 
		var xmlhttp=false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		// JScript gives us Conditional compilation, we can cope with old IE versions.
		// and security blocked creation of the objects.
		try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		xmlhttp = false;
		}
		}
		@end @*/
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
		}
	    xmlhttp.open("GET", "/offers/scripts/validation_intl_phone.php?country_code="+country_code); 
	    xmlhttp.onreadystatechange = function() { 
	        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
				el.focus();
				el.value = xmlhttp.responseText; 

	        } 
	    } 
	    xmlhttp.send(null); 
	}
