// Function for toggling withing State text box and combo box
function numberKeypress(e)
{
    if ([e.keyCode||e.which]==8) //this is to allow backspace
    return true;
    if ([e.keyCode||e.which]==9) //this is to allow tab
    return true;
//    if ([e.keyCode||e.which]==46) //this is to allow period
//    return true;
    if ([e.keyCode||e.which] < 48 || [e.keyCode||e.which] > 57)
    e.preventDefault? e.preventDefault() : e.returnValue = false;
}

function ShowTextBoxState()
{

   
	var lint_Index
	lint_Index=0;
	lint_Index = document.frmPage.lst_Country.selectedIndex;
	if(lint_Index!=0)
		{
			document.all("DisplayStateDropDownList").style.display='none';
			document.all("DisplayStateTextBox").style.display='';
		}
	else
		{
			document.all("DisplayStateDropDownList").style.display='';
			document.all("DisplayStateTextBox").style.display='none';
		}
		 
}
function NewWin()
	{           
				newwindow=window.open("SurveyForm.aspx","","width=800, height=800, top = 20%, left = 30%,scrollBars=yes");
				if (window.focus)
				{
					newwindow.focus()
				}
	}	
	function NewPromoWin()
	{           
				newwindow=window.open("promoform.aspx","","width=840, height=400, top = 20%, left = 30%,scrollBars=yes");
				if (window.focus)
				{
					newwindow.focus()
				}
	}	
function PageOnload()
{
document.frmPage.txt_CustomerName.focus();

}

// Function for validating the form inputs
function CheckValidation()
{	
	var lstr_FieldString = "";
	
	//Mandatory - Name Field Check length=100
	
	lstr_FieldString = document.frmPage.txt_CustomerName.value;
	if(CheckForNull('frmPage','Name','txt_CustomerName')==false) 
	{

        document.frmPage.txt_CustomerName.focus();
   		return false;
	}
	
	if(lstr_FieldString.length>100)
	{
		alert("You can't Enter more than 100 character length name!")
		document.frmPage.txt_CustomerName.select();
		document.frmPage.txt_CustomerName.focus();
   		return false;
	}
	if(AbortNonRequiredCharacters('frmPage','txt_CustomerName','></%','Name Must Not Contain InValid Characters (`></%')==false)
	{
		document.frmPage.txt_CustomerName.select();
		document.frmPage.txt_CustomerName.focus();
		return false;
	}
	
	//Optional - Address Field check Length 250
	lstr_FieldString = document.frmPage.txt_Address.value;
	if((LTrim(RTrim(document.frmPage.txt_Address.value))!="") || (lstr_FieldString.length!=0))
	{
		if(CheckForNull('frmPage','Address','txt_Address')==false)
		{
			document.frmPage.txt_Address.select();
			document.frmPage.txt_Address.focus();
			return false;
		}
		if(lstr_FieldString.length>200)
		{
			alert("You can't enter more than 200 character length address!")
			document.frmPage.txt_Address.select();
			document.frmPage.txt_Address.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_Address','></%','Address Must Not Contain InValid Characters (`></%')==false)
		{
			document.frmPage.txt_Address.select();
			document.frmPage.txt_Address.focus();
			return false;
		}	
	}		
	
	//Optional - City Field check Length 100
	lstr_FieldString = document.frmPage.txt_City.value;
	if((LTrim(RTrim(document.frmPage.txt_City.value))!="") || (lstr_FieldString.length!=0))
	{
		//if(CheckForNull('frmPage','City','txt_City')==false)
		//{
		//	document.frmPage.txt_City.select();
		//	document.frmPage.txt_City.focus();
		//	return false;
		//}
		if(lstr_FieldString.length>100)
		{
			alert("You can't enter more than 100 character length City!")
			document.frmPage.txt_City.select();
			document.frmPage.txt_City.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_City','></%','City Must Not Contain InValid Characters (`></%')==false)
		{
			document.frmPage.txt_City.select();
			document.frmPage.txt_City.focus();
			return false;
		}	
	}
	
	//Optional - State Field check Length 100
	// Depending on the Country Selected
	if(document.getElementById("lst_Country").value!="US"){
		lstr_FieldString = document.frmPage.txt_State.value;
		if((LTrim(RTrim(document.frmPage.txt_State.value))!="") || (lstr_FieldString.length!=0))
		{
			//if(CheckForNull('frmPage','State','txt_State')==false)
			//{
			//	document.frmPage.txt_State.select();
			//	document.frmPage.txt_State.focus();
			//	return false;
			//}
			if(lstr_FieldString.length>100)
			{
				alert("You can't enter more than 100 character length State!!")
				document.frmPage.txt_State.select();
				document.frmPage.txt_State.focus();
   				return false;
			}
			if(AbortNonRequiredCharacters('frmPage','txt_City','></%','State Must Not Contain InValid Characters (`></%')==false)
			{
				document.frmPage.txt_State.select();
				document.frmPage.txt_State.focus();
				return false;
			}	
		}
	}
	
	//Optional - Postalcode Field check Length 15
	lstr_FieldString = document.frmPage.txt_Postalcode.value;
	if((LTrim(RTrim(document.frmPage.txt_Postalcode.value))!="") || (lstr_FieldString.length!=0))
	{
		//if(CheckForNull('frmPage','City','txt_Postalcode')==false)
		//{
		//	document.frmPage.txt_Postalcode.select();
		//	document.frmPage.txt_Postalcode.focus();
		//	return false;
		//}
		if(lstr_FieldString.length>15)
		{
			alert("You can't enter more than 15 character length Postal Code!")
			document.frmPage.txt_Postalcode.select();
			document.frmPage.txt_Postalcode.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_Postalcode','></%','Postal code Must Not Contain InValid Characters (`></%')==false)
		{
			document.frmPage.txt_Postalcode.select();
			document.frmPage.txt_Postalcode.focus();
			return false;
		}	
	}
	
	//Mandatory - Phone Field Check length 20 
	lstr_FieldString = document.frmPage.txtPhone.value;
	if(lstr_FieldString.length!=0)
	{
	if(AbortNonRequiredCharacters('frmPage','txtPhone','></%','Phone No Not Contain InValid Characters (`></%')==false)
		{
			document.frmPage.txtPhone.select();
			document.frmPage.txtPhone.focus();
			return false;
		}	
	}
	lstr_FieldString = document.frmPage.txtWorkNumber.value;
	if(lstr_FieldString.length!=0)
	{
	if(AbortNonRequiredCharacters('frmPage','txtWorkNumber','></%','WorkPhone No Not Contain InValid Characters (`></%')==false)
		{
			document.frmPage.txtWorkNumber.select();
			document.frmPage.txtWorkNumber.focus();
			return false;
		}	
	}
	
	if(AbortNonRequiredCharacters('frmPage','txtQty','ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=`~!@#^&*(). +{};:,<_-+?/>?|','Quantity of sample must be numeric!')==false) return false;
	
	
	//if(local_CheckPhone('txt_PhoneArea','txt_Phone','txt_PhoneExt','M','Phone No')==false) return false
	
	//Optional - Work Phone Field Check length 50
	//if(local_CheckPhone('txtWorkNumber','txt_WorkPhone','txt_WorkPhoneExt','O','WorkPhone No')==false) return false
	
	//Mandatory  - Email Field Check length 100
	/*lstr_FieldString = document.frmPage.txt_Email.value;
	if(CheckForNull('frmPage','Email','txt_Email')==false)
	{
		document.frmPage.txt_Email.select();
		document.frmPage.txt_Email.focus();
		return false;
	}
	if(lstr_FieldString.length>100)
	{
		alert("You can't enter more than 15 character length Email!")
		document.frmPage.txt_Email.select();
		document.frmPage.txt_Email.focus();
   		return false;
	}
	if(CheckEmail('frmPage','txt_Email')==false)
	{
		document.frmPage.txt_Email.select();
		document.frmPage.txt_Email.focus();
		return false;
	}*/
	
	//Optional - Others field Check length 100
	//txt_OtherOptions
	/*lstr_FieldString = document.frmPage.txt_OtherOptions.value;
	if((LTrim(RTrim(document.frmPage.txt_OtherOptions.value))!="") || (lstr_FieldString.length!=0))
	{
		if(CheckForNull('frmPage','Others','txt_OtherOptions')==false)
		{
			document.frmPage.txt_OtherOptions.select();
			document.frmPage.txt_OtherOptions.focus();
			return false;
		}
		if(lstr_FieldString.length>100)
		{
			alert("You can't enter more than 15 character length Others!")
			document.frmPage.txt_OtherOptions.select();
			document.frmPage.txt_OtherOptions.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_OtherOptions','></%','Others Must Not Contain InValid Characters (`></%')==false)
		{
			document.frmPage.txt_OtherOptions.select();
			document.frmPage.txt_OtherOptions.focus();
			return false;
		}	
	}
	//Optional - Comments Field Check length 4000
	lstr_FieldString = document.frmPage.txt_Comments.value;
	if((LTrim(RTrim(document.frmPage.txt_Comments.value))!="") || (lstr_FieldString.length!=0))
	{
		if(CheckForNull('frmPage','Comments','txt_Comments')==false)
		{
			document.frmPage.txt_Comments.select();
			document.frmPage.txt_Comments.focus();
			return false;
		}
		if(lstr_FieldString.length>4000)
		{
			alert("You can't enter more than 4000 character length Comments!")
			document.frmPage.txt_OtherOptions.select();
			document.frmPage.txt_OtherOptions.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_Comments','></%','Comment Must Not Contain InValid Characters (`></%')==false)
		{
			document.frmPage.txt_Comments.select();
			document.frmPage.txt_Comments.focus();
			return false;
		}	
	}*/
	
		var lstrCodeNo = document.getElementById('CodeNumberTextBox').value;	
		if(lstrCodeNo=='')
		{
		   alert("Security Code must be entered!")
			document.getElementById('CodeNumberTextBox').select();
			document.getElementById('CodeNumberTextBox').focus();
   			return false;
		
		}
	return true;	
	}	

	function local_CheckPhone(objAreaCode,objPhone,objExt,objType,objCaption)
	{
		var lstrPhone = document.getElementById(objPhone).value;
		if(lstrPhone.length<=0 && objType=="M"){
			alert("You have missed to Provide "+ objCaption + "!");
			document.getElementById(objAreaCode).select();
			document.getElementById(objAreaCode).focus();	
			return false;
		}
		
		if(lstrPhone.length<=0 && objType=="O"){
			return true;
		}
		
		var lstrAreaCode = document.getElementById(objAreaCode).value;	
		if(lstrAreaCode.length<=0 && objType=="M"){
			alert("You have missed to provide "+ objCaption + " Area Code!");
			document.getElementById(objAreaCode).select();
			document.getElementById(objAreaCode).focus();	
			return false;
		}
		if(parseInt(lstrAreaCode.length)>4)
		{
			alert("You can't enter more than 4 character length "+ objCaption + " Area Code  !")
			document.getElementById(objAreaCode).select();
			document.getElementById(objAreaCode).focus();
   			return false;
		}
		
		if(lstrPhone.length>10)
		{
			alert("You can't enter more than 10 character length "+ objCaption + "!")
			document.getElementById(objPhone).select();
			document.getElementById(objPhone).focus();
   			return false;
		}
		
		var lstrExt = document.getElementById(objExt).value;	
		if(lstrExt.length>4)
		{
			alert("You can't enter more than 4 character length "+ objCaption + " Extention!")
			document.getElementById(objExt).select();
			document.getElementById(objExt).focus();
   			return false;
		}
		
		
		
		lstrPhone = "";
		lstrAreaCode = "";
		lstrExt = "";
		return true;
	}
	function OnEnterKeyPress()
		{
			if(event.keyCode == 13)			
			{
			if(CheckValidation()==false)return false;
			}
		
		}
	
function refreshCaptcha()
{  
   document.getElementById("captchaImg").src="JpegImage.aspx";
}
