// JavaScript Document
var xmlHttp;


	
function showCustomer(users)
{
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null) {
  	    alert ("Your browser does not support AJAX!");
  	    return;
  	} 
	 
	//if (users != "") { 
	    var url="myphp.php?usernm="+users;
		window.location="#form";
		//alert(url);
	//} else { 
	   // return;
    //    }

	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function showCustomer1(email,firstname,lastname,theForm)
{
	
		
	if(theForm.firstname.value=="")
	{
			alert("Please enter firstname.");
			theForm.firstname.focus();
			return false;		
	}
		
	if(theForm.firstname.value!="" && theForm.lastname.value=="")
	{
			alert("Please enter lastname.");
			theForm.lastname.focus();
			return false;		
	}
	
	xmlHttp=GetXmlHttpObject()
		
	if (xmlHttp==null) 
	{
  	   alert ("Your browser does not support AJAX!");
  	   return;
  	} 
	
	if (firstname != "" && lastname != "" && email != "") 
	    var url="myphp102.php?email="+email+"&fn="+firstname+"&ln="+lastname; 
	else 
	    return;
	
	xmlHttp.onreadystatechange=stateChanged1_grp;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}




function stateChanged() 
{ 
	if(xmlHttp.readyState==0) 
  {
	  document.getElementById("txtHint").innerHTML="<span class=span_green> not initialized</span>";
  }
  else if(xmlHttp.readyState==1) 
  {
	  document.getElementById("txtHint").innerHTML="<span class=span_green> Loading.</span>";
  }
  else if(xmlHttp.readyState==2) 
  {
	  document.getElementById("txtHint").innerHTML="<span class=span_green> Loading..</span>";
  }
  else if (xmlHttp.readyState==3)
	{ 
		document.getElementById("txtHint").innerHTML="<span class=span_green> Loading...</span>";
	}
	else if (xmlHttp.readyState==4)
	{ 
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
		initCountry('US');
	}
}


function stateChanged1_grp() 
{ 
	if(xmlHttp.readyState==0) 
  {
	  document.getElementById("txt_hid").innerHTML="<span class=span_green> Not Initialized</span>";
  }
  else if(xmlHttp.readyState==1) 
  {
	  document.getElementById("txt_hid").innerHTML="<span class=span_green> Loading..</span>";
  }
  else if(xmlHttp.readyState==2) 
  {
	  document.getElementById("txt_hid").innerHTML="<span class=span_green> Loading..</span>";
  }
  else if (xmlHttp.readyState==3)
  { 
	document.getElementById("txt_hid").innerHTML="<span class=span_green> Loading..</span>";
  }
  else if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
	 
			
		var xmlDoc=xmlHttp.responseXML;	
		
		if(xmlDoc.getElementsByTagName("spanval")[0].childNodes[0].nodeValue=="1")
		{
			
			var temp=document.getElementById("countrySelect").options.length;	
			for(i=0;i<temp;i++)
			{
				if(document.getElementById("countrySelect").options[i].value==xmlDoc.getElementsByTagName("Country")[0].childNodes[0].nodeValue)
				{
					document.getElementById("countrySelect").options[i].selected=true;
					populateState();
				}
			}
			
			var cs=xmlDoc.getElementsByTagName("Country")[0].childNodes[0].nodeValue;
			if(cs!="CA" || cs!="EI" || cs!="NL" || cs!="UK" || cs!="US" || cs!="AU" || cs!="BZ")
				document.getElementById("stateSelect").value=xmlDoc.getElementsByTagName("WorkState")[0].childNodes[0].nodeValue;
			else
			{
				temp=document.getElementById("stateSelect").options.length;
				for(i=0;i<temp;i++)
				{
					if(document.getElementById("stateSelect").options[i].value==xmlDoc.getElementsByTagName("WorkState")[0].childNodes[0].nodeValue)
						document.getElementById("stateSelect").options[i].selected=true;
				}
			}
		
			var str=xmlDoc.getElementsByTagName("HomePhone")[0].childNodes[0].nodeValue;
			if(str != "-")
			{
				if(str.length<13)
				{
					if(str.indexOf('(')==0 && str.indexOf(')')==4 && str.indexOf('-')==8)
						document.getElementById("phonenumber1").value=str.substring(0,13);
					else
						document.getElementById("phonenumber1").value=xmlDoc.getElementsByTagName("HomePhone")[0].childNodes[0].nodeValue;
				}
				else
				{
					if(str.indexOf('(')==0 && str.indexOf(')')==4 && str.indexOf('-')==8 && str.length==13)
					{
						document.getElementById("phonenumber1").value=str.substring(0,13);					
					}
					else
					{
						document.getElementById("phonenumber1").value=str.substring(0,13);
						document.getElementById("phonenumber2").value=str.substring(14,str.length-14);
					}
				}
			}
			else
			{
				document.getElementById("phonenumber1").value="";
				document.getElementById("phonenumber2").value="";
			}
			
			temp=document.getElementById("fmsalutation").options.length;	
			for(i=0;i<temp;i++)
			{
				if(document.getElementById("fmsalutation").options[i].value==xmlDoc.getElementsByTagName("Salutation")[0].childNodes[0].nodeValue)
					document.getElementById("fmsalutation").options[i].selected=true;
			}
		
			document.getElementById("ID").value=xmlDoc.getElementsByTagName("ID")[0].childNodes[0].nodeValue;
			document.getElementById("emailid").value=xmlDoc.getElementsByTagName("EmailAddress")[0].childNodes[0].nodeValue;
			document.getElementById("firstname").value=xmlDoc.getElementsByTagName("FirstName")[0].childNodes[0].nodeValue;
			document.getElementById("lastname").value=xmlDoc.getElementsByTagName("LastName")[0].childNodes[0].nodeValue;
			
			if(xmlDoc.getElementsByTagName("Organization")[0].childNodes[0].nodeValue!="-")
				document.getElementById("organization").value=xmlDoc.getElementsByTagName("Organization")[0].childNodes[0].nodeValue;
			else
				document.getElementById("organization").value="";
			
			if(xmlDoc.getElementsByTagName("Degree")[0].childNodes[0].nodeValue!="-")
				document.getElementById("Degree").value=xmlDoc.getElementsByTagName("Degree")[0].childNodes[0].nodeValue;
			else
				document.getElementById("Degree").value="";
			
			if(xmlDoc.getElementsByTagName("WorkAddress")[0].childNodes[0].nodeValue != "-")
				document.getElementById("address1").value=xmlDoc.getElementsByTagName("WorkAddress")[0].childNodes[0].nodeValue;	
			else
				document.getElementById("address1").value="";	
				
			if(xmlDoc.getElementsByTagName("WorkAddress1")[0].childNodes[0].nodeValue != "-")
				document.getElementById("address2").value=xmlDoc.getElementsByTagName("WorkAddress1")[0].childNodes[0].nodeValue;
			else
				document.getElementById("address2").value="";
			
			if(xmlDoc.getElementsByTagName("WorkCity")[0].childNodes[0].nodeValue != "-")
				document.getElementById("city").value=xmlDoc.getElementsByTagName("WorkCity")[0].childNodes[0].nodeValue;
			else
				document.getElementById("city").value="";
			
			if(xmlDoc.getElementsByTagName("WorkZipCode")[0].childNodes[0].nodeValue != "-")
				document.getElementById("zip").value=xmlDoc.getElementsByTagName("WorkZipCode")[0].childNodes[0].nodeValue;	
			else
				document.getElementById("zip").value="";
			
			if(xmlDoc.getElementsByTagName("spanmsg")[0].childNodes[0].nodeValue=="2")
			{
					document.getElementById("txt_hid").className="span_green";				
					document.getElementById("txt_hid").innerHTML="emai-Id exists and fields are updated.";
							
			}
			document.getElementById("email_val").value="true";	
			
	}
	else
	{
			document.getElementById("ID").value="0";			
			document.getElementById("organization").value="";
			document.getElementById("phonenumber1").value="";
			document.getElementById("phonenumber2").value="";		
		
			document.getElementById("address1").value="";			
			document.getElementById("address2").value="";			
			document.getElementById("city").value="";				
			document.getElementById("zip").value="";			
			document.getElementById("countrySelect").options[0].selected=true;
			initCountry('US');
		
		if(xmlDoc.getElementsByTagName("spanmsg")[0].childNodes[0].nodeValue=="1")
		{
			document.getElementById("txt_hid").className="span_red";
			document.getElementById("txt_hid").innerHTML=xmlDoc.getElementsByTagName("span1")[0].childNodes[0].nodeValue;
			document.getElementById("email_val").value="false";	
		}
		else
		{
			document.getElementById("txt_hid").className="span_border";
			document.getElementById("txt_hid").innerHTML="";
		}
	}	
  }
}

function showDiscount(groupCode,formName)
{
	//var randomNumber=0;
	
	xmlHttp=GetXmlHttpObject()
		
	if (xmlHttp==null) 
	{
  	   alert ("Your browser does not support AJAX!");
  	   return;
  	} 
	
	//randomNumber=Math.floor(Math.random()*32724);
	
	if (groupCode != "") 
	    var url="getGroupCode.php?groupcode="+groupCode; 
	else 
	{
		document.getElementById("grpDiscountAmount").value=0;
		document.getElementById("grpDiscountAmountType").value="$";
		
		grand_total(document.Form1);
		return;
	}
	    
	
	xmlHttp.onreadystatechange=stateChanged_grpCode;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged_grpCode() 
{ 
  var tempText,discount;
  
  if(xmlHttp.readyState==0) 
  {
	  document.getElementById("txt_grpdis").innerHTML="Loading.....";
  }
  else if(xmlHttp.readyState==1) 
  {
	  document.getElementById("txt_grpdis").innerHTML="Loading.....";
  }
  else if(xmlHttp.readyState==2) 
  {
	  document.getElementById("txt_grpdis").innerHTML="Loading.....";
  }
  else if (xmlHttp.readyState==3)
  { 
	 document.getElementById("txt_grpdis").innerHTML="Loading.....";
  }
  else if (xmlHttp.readyState==4)
  { 
	tempText=xmlHttp.responseText
	discount=tempText.split("|");
	
	/*if(discount[2]=="%")
		totalAmount=((Number(document.getElementById("total_conf_fee").value) + Number(document.getElementById("total_workshop_fee").value))*discount[1])/100;
	else
		totalAmount=discount[1];
	
	document.getElementById("total_discount").value=totalAmount;*/
	if(discount[0]==0)
	{
		document.getElementById("txt_grpdis").className="span_red";
		document.getElementById("txt_grpdis").innerHTML="Invalid Group Code";
		document.getElementById("grpDiscountAmount").value=0;
		document.getElementById("grpDiscountAmountType").value="$";
		
	}
	else
	{
		document.getElementById("txt_grpdis").className="span_border";
		document.getElementById("txt_grpdis").innerHTML="";
		document.getElementById("grpDiscountAmount").value=discount[1];
		document.getElementById("grpDiscountAmountType").value=discount[2];
	}
		
	grand_total(document.Form1);
  }
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  	  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  	 try
    	{
		    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
	catch (e)
    	{
		    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  }
return xmlHttp;
}
