// 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)|| (lint_Index==1))
		{
		document.all("lst_State").style.display='';
		document.all("txt_State").style.display='none';
	
		}
	else
		{
			document.all("lst_State").style.display='none';
			document.all("txt_State").style.display='';
		}
		if((lint_Index==0))
		{
		document.frmPage.lst_State.disabled=true;
			document.frmPage.lst_Country.selectedIndex=0;
		document.frmPage.lst_State.selectedIndex=0;
		}
		else{
		
		document.frmPage.lst_State.disabled=false;
		
		}
		 
}
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;
	}
	
	
	// For Institute
	lstr_FieldString = document.frmPage.txt_CustomerLastName.value;
	
		
		if(lstr_FieldString.length>100)
		{
			alert("campo de apellido no puede aceptar mas de 100 caracteres!")
			document.frmPage.txt_CustomerLastName.select();
			document.frmPage.txt_CustomerLastName.focus();
   			return false;
		}
		if(AbortNonRequiredCharacters('frmPage','txt_CustomerLastName','></%','apellido no debe contener caracteres no validos (`></%')==false)
		{
			document.frmPage.txt_CustomerLastName.select();
			document.frmPage.txt_CustomerLastName.focus();
			return false;
		}	
		
			var lint_Index
	lint_Index=0;
	lint_Index = document.frmPage.lst_Country.selectedIndex;
	
	if((lint_Index==0))
		{
			alert("Por favor seleccione el pais.");
			document.frmPage.lst_Country.focus();
			return false;
		}
	//Optional - Address Field check Length 250
	lstr_FieldString = document.frmPage.txt_Address_I.value;
	//lstr_FieldString =	FCKeditorAPI.GetInstance(document.frmPage.txt_Address_I.id).GetXHTML(true);
	
		
		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 - City Field check Length 100
	lstr_FieldString = document.frmPage.txt_City.value;
	
		
		if(lstr_FieldString.length>100)
		{
			alert("Usted no puede ingresar mas de 100 caracteres de longitud Ciudad!")
			document.frmPage.txt_City.select();
			document.frmPage.txt_City.focus();
   			return false;
		}
	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
	var Lindex= document.frmPage.lst_Country.selectedIndex;

	if((lint_Index!=0) && (lint_Index!=1)){
		lstr_FieldString = document.frmPage.txt_State.value;
		if(lstr_FieldString='')
		{
		alert("Estado debera consignarse")
				document.frmPage.txt_State.select();
				document.frmPage.txt_State.focus();
   				return false;
		}
			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(lstr_FieldString.length < 1)
	{
			alert("Codigo postal debe introducirse.");
			document.frmPage.txt_Address_I.select();
			document.frmPage.txt_Address_I.focus();
			return false;
	}*/
		
		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_WorkPhone.value;
	if(lstr_FieldString.length!=0)
	{
	if(AbortNonRequiredCharacters('frmPage','txt_WorkPhone','></%','Telefono de trabajo debe contener caracteres invalidos (`></%')==false)
		{
			document.frmPage.txt_WorkPhone.select();
			document.frmPage.txt_WorkPhone.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 - Comments Field Check length 4000
	lstr_FieldString = document.frmPage.txt_Comments.value;
		//var oFckEditor1=FCKeditorAPI.GetInstance(document.frmPage.txt_Comments.id);
		//var txtString1=oFckEditor.EditorDocument.body.textContent;
		/* lstr_FieldString=txtString1.trim();
		if(lstr_FieldString.length<=0)
		{
			alert("Los comentarios deben consignarse!")
			document.frmPage.txt_Comments.select();
			document.frmPage.txt_Comments.focus();
   			return false;
		}*/
		
		if(lstr_FieldString.length>4000)
		{
			alert("ĦComentarios no mas de 4000 caracteres!")
			document.frmPage.txt_Comments.select();
			document.frmPage.txt_Comments.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;
		}
		
	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;
		}	
	}
	
	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("El e-mail debe ser valido")
		   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;
}


