// Function for toggling withing State text box and combo box
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 PageOnload()
{
document.frmPage.txt_CustomerName.focus();

}
function NewWin()
	{           
				newwindow=window.open("SurveyForm.aspx","","width=800, height=800, top = 20%, left = 30%,scrollBars=yes");
				if (window.focus)
				{
					newwindow.focus()
				}
	}	

	
	function CheckValidation()
{	
	var lstr_FieldString = "";
	
	//Mandatory - Name Field Check length=100
	
	lstr_FieldString = document.frmPage.txt_CustomerName.value;
	if(lstr_FieldString=='') 
	{
       alert("Ingresar el nombre!")
   		return false;
	}
	
	if(lstr_FieldString.length>100)
	{
		alert("ˇNo puede ingresar mas de 100 caracteres!")
		document.frmPage.txt_CustomerName.select();
		document.frmPage.txt_CustomerName.focus();
   		return false;
	}
	if(AbortNonRequiredCharacters('frmPage','txt_CustomerName','></%','El nombre no debe contener caracteres invalidos (`></%')==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_I.value;
	if((LTrim(RTrim(document.frmPage.txt_Address_I.value))!="") || (lstr_FieldString.length!=0))
	{
		
		if(lstr_FieldString.length>100)
		{
			alert("ˇLa direccion no puede tener mas 100 caracteres!")
			document.frmPage.txt_Address_I.select();
			document.frmPage.txt_Address_I.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_Address_I','></%','La direccion no debe contener caracteres invalidos (`></%')==false)
		{
			document.frmPage.txt_Address_I.select();
			document.frmPage.txt_Address_I.focus();
			return false;
		}	
	}		
	
	//Optional - Address Field check Length 250
	lstr_FieldString = document.frmPage.txt_Address_II.value;
	if((LTrim(RTrim(document.frmPage.txt_Address_II.value))!="") || (lstr_FieldString.length!=0))
	{
		
		if(lstr_FieldString.length>100)
		{
			alert("ˇLa direccion 1 no puede tener mas 100 caracteres!")
			document.frmPage.txt_Address_II.select();
			document.frmPage.txt_Address_II.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_Address_II','></%','La direccion 11 no debe contener caracteres invalidos (`></%')==false)
		{
			document.frmPage.txt_Address_II.select();
			document.frmPage.txt_Address_II.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(AbortNonRequiredCharacters('frmPage','txt_City','></%','El nombre ciudad no debe contener caracteres invalidos (`></%')==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(lstr_FieldString.length>100)
			{
				alert("ˇEl nombre del estado no debe contener mas de 100 caracteres!!")
				document.frmPage.txt_State.select();
				document.frmPage.txt_State.focus();
   				return false;
			}
			if(AbortNonRequiredCharacters('frmPage','txt_City','></%','El nombre del estado no debe contener caracteres invalidos (`></%')==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(lstr_FieldString.length>15)
		{
			alert("El codigo postal no debe contener mas de 15 caracteres!");
			document.frmPage.txt_Postalcode.select();
			document.frmPage.txt_Postalcode.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_Postalcode','></%','El codigo postal no debe contener caracteres invalidos (`></%')==false)
		{
			document.frmPage.txt_Postalcode.select();
			document.frmPage.txt_Postalcode.focus();
			return false;
		}	
	}
	
	//Mandatory - Phone Field Check length 50 
	lstr_FieldString = document.frmPage.txt_Phone.value;
	if(lstr_FieldString.length!=0)
	{
	if(AbortNonRequiredCharacters('frmPage','txt_Phone','></%','Numero Telefonico no debe contener caracteres invalidos (`></%')==false)
		{
			document.frmPage.txt_Phone.select();
			document.frmPage.txt_Phone.focus();
			return false;
		}	
	}
	lstr_FieldString = document.frmPage.txt_WorkPhoneArea.value;
	if(lstr_FieldString.length!=0)
	{
	if(AbortNonRequiredCharacters('frmPage','txt_WorkPhoneArea','></%','Telefono del trabajo no debe contener caracteres invalidos (`></%')==false)
		{
			document.frmPage.txt_WorkPhoneArea.select();
			document.frmPage.txt_WorkPhoneArea.focus();
			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('txt_WorkPhoneArea','txt_WorkPhone','txt_WorkPhoneExt','O','WorkPhone No')==false) return false
	
	//Mandatory  - Email Field Check length 100
	lstr_FieldString = document.frmPage.txt_Email.value;
	if(lstr_FieldString=='')
	{
	alert("Ingresar su E-mail!")
		document.frmPage.txt_Email.focus();
		return false;
	}
	if(lstr_FieldString.length>100)
	{
		alert("ˇEl E-mail no puede contener mas de 15 caracteres!")
		document.frmPage.txt_Email.select();
		document.frmPage.txt_Email.focus();
   		return false;
	}
	if (echeck(lstr_FieldString)==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(lstr_FieldString.length>100)
		{
			alert("ˇOtros no mas de 15 caracteres!!")
			document.frmPage.txt_OtherOptions.select();
			document.frmPage.txt_OtherOptions.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_OtherOptions','></%','Otros no deben contener caracteres invalidos (`></%')==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(lstr_FieldString.length>4000)
		{
			alert("ˇComentarios no mas de 4000 caracteres!")
			document.frmPage.txt_OtherOptions.select();
			document.frmPage.txt_OtherOptions.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_Comments','></%','Comentario no debe contener caracteres invalidos (`></%')==false)
		{
			document.frmPage.txt_Comments.select();
			document.frmPage.txt_Comments.focus();
			return false;
		}	
	}
	var lstrCodeNo = document.getElementById('CodeNumberTextBox').value;	
		if(lstrCodeNo=='')
		{
		   alert("Codigo de Seguridad (requerido)!")
			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("ˇOlvido ingresar el codigo de area del telefono!");
			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("ˇOlvido ingresar el codigo de area del telefono!");
			document.getElementById(objAreaCode).select();
			document.getElementById(objAreaCode).focus();	
			return false;
		}
		if(parseInt(lstrAreaCode.length)>4)
		{
			alert("ˇIngresar el codigo de area del telefono no debe contener mas de 4 digitos!")
			document.getElementById(objAreaCode).select();
			document.getElementById(objAreaCode).focus();
   			return false;
		}
		
		if(lstrPhone.length>10)
		{
			alert("ˇEl  numero telefonico no debe contener mas de 10 digitos!")
			document.getElementById(objPhone).select();
			document.getElementById(objPhone).focus();
   			return false;
		}
		
		var lstrExt = document.getElementById(objExt).value;	
		if(lstrExt.length>4)
		{
			alert("ˇIngresar el codigo de area del telefono no debe contener mas de 4 digitos!!")
			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 echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("ˇEl e-mail debe ser valido!")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("ˇEl e-mail debe ser valido!")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("ˇEl e-mail debe ser valido!")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("ˇEl e-mail debe ser valido!")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("ˇEl e-mail debe ser valido!")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("ˇEl e-mail debe ser valido!")
		    return false
		 }

 		 return true					
	}
	
var id=0;
function refreshCaptcha()
{  
	id++;
   document.getElementById("captchaImg").src="JpegImage.aspx?id="+id;
}

