	// JavaScript Document
	
	String.prototype.trim = function() {return this.replace(/^\s+|\s+$/,"")};
	
	function validateSmartPhn(SmartPhnFormElement)
	{
		var formObj = this.document.smartphn;
		var regName = /^[a-zA-Z]+[a-zA-Z0-9\s\-\']*$/;
		var otherPostal=/(^\d{4,12}$)|(^[A-Za-z0-9_\.\-\ ]{4,12}$)/;
		var zipRE=/(^\d{5}$)|(^\d{5}-\d{4})$/; 
		var ZipName=/(^\d{5})$|(^\d{5}(-)|(\s)\d{4}$)/;
		var OtherZip=/(^\d{4,12}$)/;
		//var phoneRE = /(^\d{4,15}$)|(^\d{3}-\d{3}-\d{4})$|(^\(\d{3}\)-\d{3}-\d{4})$|(^\(\d{3}\)[\s]?\d{3}-\d{4})$|(^(\d{3})\.\d{3}\.\d{4})$/;
		//var phoneRE=  /(^\d{10})$|(^\d{3}-\d{3}-\d{4})$|(^\(\d{3}\)-\d{3}-\d{4})$|(^\(\d{3}\).\d{3}.\d{4})$|(^\(\d{3}\)[\s]?\d{3}-\d{4})$|(^(\d{3})\.\d{3}\.\d{4})$/;
		 //var phoneRE=  /(^\d{10})$|(^\d{3}-\d{3}-\d{4})$|(^\(\d{3}\)-\d{3}-\d{4})$|(^\(\d{3}\).\d{3}.\d{4})$|(^\(\d{3}\)[\s]?\d{3}-\d{4})$|(^(\d{3})\.\d{3}\.\d{4})$/;
		  var phoneRE=  /(^\d{10})$|(^\d{3}-\d{3}-\d{4})$|(^\(\d{3}\)-\d{3}-\d{4})$|(^\(\d{3}\).\d{3}.\d{4})$|(^\(\d{3}\)[\s]?\d{3}-\d{4})$|(^(\d{3})\.\d{3}\.\d{4})$/;
		  var phoneREother=  /(^\d{4,16})$|(^\d{3}-\d{3}-\d{4})$|(^\(\d{3}\)-\d{3}-\d{4})$|(^\(\d{3}\).\d{3}.\d{4})$|(^\(\d{3}\)[\s]?\d{3}-\d{4})$|(^(\d{3})\.\d{3}\.\d{4})$/;
		//var phoneRE=/(^\d{10}$)|(^\d{3}-\d{3}-\d{4})$/;    (^\d{4})$|
		var otherPhone=/(^\d{4,16}$)/;
		
		//if(!regName.test(formObj.First.value))
		if(formObj.First.value.trim() == "")		
		{
			alert("Please enter a valid First Name");
			formObj.First.value = "";
			formObj.First.focus();
			return false; 
		}
		
		//if(!regName.test(formObj.Last.value))
		if(formObj.Last.value.trim() == "")		
		{
			alert("Please enter a valid Last Name");
			formObj.Last.value = "";
			formObj.Last.focus();
			return false; 
		}
		
		
		if(!emailCheck(formObj.email.value))
		{
			
			formObj.email.value = "";
			formObj.email.focus();
			return false; 
		}
		
		// Validate Confirm Password
		if(formObj.password.value.trim() == "")		
		{
			alert("Please enter a password with a minimum of 6 characters and maximum of 15 characters into the Create Password field.");
			formObj.password.focus();
			return false;
		}
		
		if(formObj.password.value.length < 6)
		{
			alert("Please enter a password with a minimum of 6 characters and maximum of 15 characters into the Create Password field.");
			formObj.password.focus();
			return false;
		}
		if(formObj.password.value.length > 15)
		{
			alert("Please enter a password with a minimum of 6 characters and maximum of 15 characters into the Create Password field.");
			formObj.password.focus();
			return false;
		}
		if(formObj.cpassword.value.length > 15)
		{
			alert("Please enter a password with a minimum of 6 characters and maximum of 15 characters into the Confirm Password field.");
			formObj.cpassword.focus();
			return false;
		}
			
		if(formObj.password.value != formObj.cpassword.value)
		{
			alert("Please confirm that your Create Password and Confirm Password fields contain the same information.");
			formObj.cpassword.focus();
			return false;
		} 	
		// Validate Confirm Password End here
		
		/*if(formObj.prd_url.value.trim() != formObj.mp_header.value.trim())
		{
			if(formObj.cmpName.value.trim()=="")
			{
				alert("Please enter a valid Company name.");
				formObj.cmpName.focus();
				return false;
			} 
		}*/
		if(formObj.address.value.trim()=="")
		{
			alert("Please enter a valid Address.");
			formObj.address.focus();
			return false;
		} 	
		
		if(formObj.city.value.trim()=="")
		{
			alert("Please enter a valid City name.");
			formObj.city.value = "";
			formObj.city.focus();
			return false; 
		}
		/*
		if(formObj.country.value!='US')
		{
		
			if(formObj.txtstatename.value=="")
			{
			alert("Please enter valid state ");
			formObj.txtstatename.value= "";
			formObj.txtstatename.focus();
			return false; 
			}
		}
		
        else
		{*/
		if(formObj.country.value=='US')
		{
			if(formObj.state.value=="0")
			{
				alert("Please select a valid state from the drop down.");
				formObj.state.value ="0";
				formObj.state.focus();
				return false; 
			}
			if(formObj.state.value=="-1")
			{
				if(formObj.txtstatename.value=="")
				{
					alert("Please enter the valid state name.");
					formObj.txtstatename.value ="";
					formObj.txtstatename.focus();
					return false;
				}
			}
		}
		//}
	
		
		var cntry=formObj.country.value;
		var postalvalue=formObj.POSTAL_CODE.value;
		
		if(formObj.POSTAL_CODE.value.trim()=="" && cntry=='US')
		{
			alert("Please enter a valid Postal Code.");
			formObj.POSTAL_CODE.focus();
			return false;
		}
		else
		{
						
			if(cntry=='US') //for US Country
			{
				if(!ZipName.test(postalvalue))
				{
					 alert('Please enter a valid postal code:(e.g: 12345-1234).');
					 formObj.POSTAL_CODE.value="";
					 formObj.POSTAL_CODE.focus();
					 return false;			 
				}
				//alert(postalvalue);
			}
			
			else //other countries 
			{
				if(formObj.POSTAL_CODE.value!="")
				{
					if(!otherZipCode(formObj.POSTAL_CODE.value))
					{
						 alert('Please enter a valid postal code.');
						 formObj.POSTAL_CODE.value="";
						 formObj.POSTAL_CODE.focus();
						 return false;			 
					}
				}
			}
			//return true;
	  }
		
		if(formObj.country.value=="")
		{
			alert("Please select a valid country from the drop down.");
			formObj.country.value = "";
			formObj.country.focus();
			return false; 
		}
		
		if(formObj.phone.value.trim() == "")
		{
			alert("Please enter a valid Telephone number");
			formObj.phone.focus();
			return false;
		}
		else
		{
			if(cntry=='US')/*for US*/
			{
				if(!phoneRE.test(formObj.phone.value.trim()))
				{
					
					alert("Please enter a valid Telephone number"); 
					formObj.phone.focus();
					return false;
				
				}
			}
			else/*for other country*/
			{	
				var str=formObj.phone.value;
				str=str.replace(/\s+/g,'');
				//alert(str);
				/*if(!otherPhone.test(str.trim()))*/
				if(!phoneREother.test(str.trim()))
				{
					
					alert("Please enter a valid Telephone number"); 
					formObj.phone.focus();
					return false;
				
				}
			}
		}
	if(formObj.bulk_id.value.trim() > 0)
	{
		if(formObj.entr_product.value.trim() == "")
		{
			alert("Please select a valid product");
			formObj.entr_product.focus();
			return false;
		}
		
	}
	else
	{
		if(formObj.scrbr_product.value.trim() == "")
		{
			alert("Please select a valid product");
			formObj.scrbr_product.focus();
			return false;
		}
	}
	if(formObj.mobile.value.trim() == "")
	{
		alert("Please enter a valid Mobile number");
		formObj.mobile.focus();
		return false;
	}
	else
	{
			
		if(cntry=='US')
		{
			if(!phoneRE.test(formObj.mobile.value.trim()))
			{
				alert("Please enter a valid Mobile Phone Number."); 
				formObj.mobile.focus();
				return false;
			}
		}
		else
		{
			
			var str=formObj.mobile.value;
			str=str.replace(/\s+/g,'');
			//alert(str);
			if(!phoneREother.test(str.trim()))
			{
				
				alert("Please enter a valid Mobile number"); 
				formObj.mobile.focus();
				return false;
			
			}
			

		}
	}
	if(formObj.scrbr_carrier1.value==0)
	{
		alert("Please select a valid Mobile Carrier from the drop down.");
		formObj.scrbr_carrier1.focus();
		return false;
	}
	
	/*if(formObj.scrbr_os1.value=="")
	{
		alert("Please select a valid Mobile Operating System from the drop down.");
		formObj.scrbr_os1.focus();
		return false;
	}
	
	if(formObj.scrbr_make1.value=="")
	{
		alert("Please select a valid Cell Phone Make from the drop down.");
		formObj.scrbr_make1.focus();
		return false;
	}*/
	
	
	/*if(formObj.scrbr_model1.value=="")
	{
		alert("Please select the mobile model");
		formObj.scrbr_model1.focus();
		return false;
	}*/
	
	if(formObj.terms.checked==false)
	{
		alert("Please agree to the Terms & Conditions.");
		formObj.terms.focus();
		return false;
		
	}

	
	return true;
	}
	
	function emailCheck (emailStr)
	{
		var checkTLD=1;
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		var emailPat=/^(.+)@(.+)$/;
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+';
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		var matchArray=emailStr.match(emailPat);
		
		if (matchArray==null) 
		{
			alert("Please enter a valid E-mail Address.");
			return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
		
		for (i=0; i<user.length; i++) 
		{
			if (user.charCodeAt(i)>127) 
			{
				alert("Ths username contains invalid characters.");
				return false;
			}
		}
		
		for (i=0; i<domain.length; i++) 
		{
			if (domain.charCodeAt(i)>127) 
			{
				alert("Ths domain name contains invalid characters.");
				return false;
			}
		}
		
		if (user.match(userPat)==null) 
		{
			alert("Please enter a valid E-mail Address.");
			return false;
		}
		
		var IPArray=domain.match(ipDomainPat);
		
		if (IPArray!=null) 
		{
			for (var i=1;i<=4;i++) 
			{
				if (IPArray[i]>255) 
				{
					alert("Destination IP address is invalid!");
					return false;
				}
			}
		return true;
		}
				 
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		
		for (i=0;i<len;i++) 
		{
			if (domArr[i].search(atomPat)==-1) 
			{
				alert("Please enter a valid E-mail Address.");
				return false;
			}
		}
		
		if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
		{
			alert("Please enter a valid E-mail Address.");
			return false;
		}
		
		if (len<2) 
		{
			alert("This address is missing a hostname!");
			return false;
		}
return true;
}

function showTextBox()
{
		
	if(document.getElementById('State1').value=="-1" && document.getElementById('State1').selectedIndex!=0 )
		document.getElementById('otherState').style.display = 'block';
	else
		document.getElementById('otherState').style.display = 'none';
		
	if(document.getElementById('countryselect').value!='US')
	{
		
		
		var drp_down = document.getElementById('State1');
		for(i=1; i < drp_down.length ; i++)
		{
			if(drp_down[i].value=="-1")
			{
				break;
			}
		}
		document.getElementById('State1').selectedIndex = i;
		document.getElementById('otherState').style.display = 'block';
	}	
}
function changeState(value)
{
	//alert(value);
	populateCarrier(value)
	if(value!='US')
	{
		//alert("hi");
		var selected_index = 0;
		var drp_down = document.getElementById('State1');
		
		for(i=1; i < drp_down.length ; i++)
		{
			
			if(drp_down[i].value=="-1")
			{
				break;
			}
		}
		//alert(i);
		document.getElementById('State1').selectedIndex = i;
		document.getElementById('otherState').style.display = 'block';
		document.getElementById("spPostal2").style.display="none";
		document.getElementById("spPostal").style.display="none";
	}
	else
	{
		document.getElementById('State1').selectedIndex = 0;
		document.getElementById('otherState').style.display = 'none';
		document.getElementById("spPostal2").style.display="inline";
		document.getElementById("spPostal").style.display="inline";
	}
}

function getXmlHttpRequestObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if(window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("It's about time to upgrade don't you think?");
    }
}

var searchReq = getXmlHttpRequestObject();

function searchValidPromo(url)
 {
	var num=1; 
	var company='';
  	if(document.getElementById('promoID').value=='')
	{
		num=0;
		alert("Please enter a valid promo code.");
		document.getElementById('promoID').focus();
		return false;
	}
	/*if(document.getElementById('prd_url').value != document.getElementById('mp_header').value)
	{
		if(document.getElementById('companyinput').value=='')
		{
			num=0;
			alert("Please enter a valid company name.");
			document.getElementById('companyinput').focus();
			return false;
		}
	}
	else
	{
		company = 'direct';
	}*/
	if(document.getElementById('scrbr_product').value=="")
	{
		num=0;
		alert("Please select a product from the drop down.");
		document.getElementById('scrbr_product').focus();
		return false;
	}
	
	if(num==1)
	{
		if(searchReq.readyState == 4 || searchReq.readyState == 0) 
		{
			var str = escape(document.getElementById('promoID').value);
			var prd;
			var cmp;
			var cmpo;
			//if(document.getElementById('optBill1').checked)
			prd=document.getElementById('scrbr_product').value;
			cmp=document.getElementById('companyinput').value;
			//alert(url+'&search='+str+'&prd='+prd+'&cmp='+cmp);
			searchReq.open("GET", url+'&search='+str+'&prd='+prd+'&cmp='+cmp+'&company='+company, true);
			searchReq.onreadystatechange = handleSearchPromo; 
			searchReq.send(null);
			
    	}
	}
}

function handleSearchPromo() {
    if (searchReq.readyState == 4) {
     // var ss = document.getElementById('DivselDisProduct');
       //ss.innerHTML = '';
     	var str = searchReq.responseText;
		//var selectTagStart='<select name="selDisProduct" id="selDisProduct"  style="width:150px;" >';
			// var selectTagEnd='</select>';
			 var OptionString= "" ;
		if(searchReq.responseText!="")
		{	
			//alert(str);
			var StrArr= str.split('@');
			
			if(StrArr[0]!=0)
			{
				var StrArr1= str.split('@');
				//alert('Valid promotional code.');
				if(StrArr1[0]=="NULL")
				{
					alert('Please enter a valid promo code.');
					document.getElementById('promoID').value='';
					document.getElementById('prdAmt').innerHTML=StrArr1[1];
					//document.getElementById('promoLable').innerHTML=none;
				}
				else
				{
					var tmpstr=StrArr1[0];
					if(tmpstr=="NO")
					  	tmpstr="0.00"
					else
						tmpstr=StrArr1[0];
					  
					alert("Promo applied successfully. Product actual price is $"+StrArr1[1]+". Product price after promo is $"+tmpstr);
					//document.getElementById('promoLable').style.display = 'none';
					document.getElementById('promo_desc').innerHTML=StrArr1[2];
					document.getElementById('prdAmt').innerHTML='$'+tmpstr;
				}
			}
			else
			{
				alert('Please enter a valid promo code.');
				document.getElementById('promoID').focus();
				document.getElementById('promoID').value='';
				document.getElementById('promo_desc').innerHTML='';
				document.getElementById('prdAmt').innerHTML=StrArr[1];
				//document.getElementById('promoLableID').innerHTML=StrArr[1];
			}
		
		}
		//ss.innerHTML=selectTagStart+OptionString+selectTagEnd;
	}
}
/*
function showTextBox(cnt)
{
	if(cnt.value=='US')
	{
		document.getElementById("statespan").innerHTML="";
		document.getElementById("statespan").innerHTML='<select name="state" id="State"><option value="">Please select one</option><option value="AL">Alabama</option><option value="AK">Alaska</option><option value="AZ">Arizona</option><option value="AR">Arkansas</option><option value="CA">California</option><option value="CO">Colorado</option><option value="CT">Connecticut</option><option value="DE">Delaware</option><option value="DC">Dist Columbia</option><option value="FL">Florida</option><option value="GA">Georgia</option><option value="HI">Hawaii</option><option value="ID">Idaho</option><option value="IL">Illinois</option><option value="IN">Indiana</option><option value="IA">Iowa</option><option value="KS">Kansas</option><option value="KY">Kentucky</option><option value="LA">Louisiana</option><option value="ME">Maine</option><option value="MD">Maryland</option><option value="MA">Massachusetts</option><option value="MI">Michigan</option><option value="MN">Minnesota</option><option value="MS">Mississippi</option><option value="MO">Missouri</option><option value="MT">Montana</option><option value="NE">Nebraska</option><option value="NV">Nevada</option><option value="NH">New Hampshire</option><option value="NJ">New Jersey</option><option value="NM">New Mexico</option><option value="NY">New York</option><option value="NC">North Carolina</option><option value="ND">North Dakota</option><option value="OH">Ohio</option><option value="OK">Oklahoma</option><option value="OR">Oregon</option><option value="PA">Pennsylvania</option><option value="RI">Rhode Island</option><option value="SC">South Carolina</option><option value="SD">South Dakota</option><option value="TN">Tennessee</option><option value="TX">Texas</option><option value="UT">Utah</option><option value="VT">Vermont</option><option value="VA">Virginia</option><option value="WA">Washington</option><option value="WV">West Virginia</option><option value="WI">Wisconsin</option><option value="WY">Wyoming</option></select>';

	}
	else
	{
		document.getElementById("statespan").innerHTML="";
		document.getElementById("statespan").innerHTML="<input type='text' name='txtstatename' id='txtstatename'>";
	}
}

*/

function populateCarrier(countryselect)
{
	var selectedCountryID=countryselect;
	var carrDropDownID;
	var txtID;
	var ajaxResponseText
	carrDropDownID='scrbr_carrier1' ;
	 
	
	if(selectedCountryID=='')
	{
										
		return false;
		
	} else{
		

		 var ajaxReqObj = getXmlHttpRequestObject();
		 

		 
		 
			
		if(ajaxReqObj)
		{	
				
				var randomnumber = Math.floor(Math.random()*1000001);
				ajaxReqObj.open("GET","./get_ajax_response.php?requestType=getcarrier&countryID="+selectedCountryID+"&carrDropDownID="+carrDropDownID+"&dummy="+randomnumber,true);

			ajaxReqObj.onreadystatechange=function () {


					
						{
							if (ajaxReqObj.readyState==4)
							{
							
							
							document.getElementById("div_carrier").innerHTML = "";
							var str=ajaxReqObj.responseText;		
							document.getElementById("div_carrier").innerHTML=str;
							
							
							
							return true;
								
							}
							else
							{							
			 			 		return false;
							}
							
						}
				

					};
				ajaxReqObj.send(null);
				
		}

		//end of if(ajaxReqObj)
		
	}
} 
function populateAmt(prdID)
{
		
	var prdID=prdID;
	var carrDropDownID;
	var txtID;
	var ajaxResponseText
	carrDropDownID='scrbr_carrier1' ;
	 
	
	if(prdID=='')
	{
										
		return false;
		
	} else{
		

		 var ajaxReqObj = getXmlHttpRequestObject();
		 

		 
		 
			
		if(ajaxReqObj)
		{	
				
				var randomnumber = Math.floor(Math.random()*1000001);
				ajaxReqObj.open("GET","./get_ajax_response.php?requestType=getprdamt&prdID="+prdID+"&carrDropDownID="+carrDropDownID+"&dummy="+randomnumber,true);

			ajaxReqObj.onreadystatechange=function () {


					
						{
							if (ajaxReqObj.readyState==4)
							{
							
							
							document.getElementById("prdAmt").innerHTML = '';
							//document.getElementById("promoID").value = '';
							document.getElementById("promo_desc").innerHTML = '';
							var str=ajaxReqObj.responseText;	
							document.getElementById("prdAmt").innerHTML=str;
							
							
							
							return true;
								
							}
							else
							{							
			 			 		return false;
							}
							
						}
				

					};
				ajaxReqObj.send(null);
				
		}

		//end of if(ajaxReqObj)
		
	}
} 

function clearTxt()
{
	document.getElementById('promo_desc').innerHTML='';
}