// JavaScript Document

function trim(inputString) 
{
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user 
   
} // Ends the "trim" function


// Seleccionar Nacionalidad: Peruano o Extranjero

function SeleccionarNacionalidad(objPE)
{
	//Peruano--------------------------------------------------------------
	if(objPE.value=="0")
	{
		
		
		document.getElementById("IdTablaPer").style.display='block';
		document.getElementById("IdJuridica").style.display='block';
		document.getElementById("IdNatural").style.display='none';
		document.getElementById("IdAsuntoSoli").style.display='block';
		
		document.getElementById("IdTablaEx").style.display='none';
		document.getElementById("IdTablaBuss").style.display='none';
		document.getElementById("IdTablaNaturalEx").style.display='none';
		document.getElementById("IdAsuntoSoli2").style.display='none';
		
		//input name="btnEnviar" type="submit" id="IdbtnEnviar" value="Enviar"
		//document.getElementById("IdAsuntoSoli2").style.display='none';
		document.getElementById("IdbtnEnviar").value='Enviar';
		document.getElementById("IdbtnLimpiar").value='Limpiar';
		
		document.getElementById("Idtextfield").value='Código de validación';
		document.frm_solinfo.rdbTipoPersona[0].checked = "true"
	
	}
	else
	{
		

		document.getElementById("IdTablaEx").style.display='block';
		document.getElementById("IdTablaBuss").style.display='block';
		document.getElementById("IdTablaNaturalEx").style.display='none';
		document.getElementById("IdAsuntoSoli2").style.display='block';
		
		document.getElementById("IdTablaPer").style.display='none';
		document.getElementById("IdJuridica").style.display='none';
		document.getElementById("IdNatural").style.display='none';
		document.getElementById("IdAsuntoSoli").style.display='none';
		
		document.getElementById("IdbtnEnviar").value='Submit';
		document.getElementById("IdbtnLimpiar").value='Reset';

		document.getElementById("Idtextfield").value='Validation code';
		document.frm_solinfo.rdbTipoPersonaEx[0].checked = "true"

	
	}
	

}//fin SeleccionarNacionalidad(objPE)


//Person Business or Person Natural
function SeleccionEx(objBuss)
{
  if(objBuss.value=="0")	
  {
  	document.getElementById("IdTablaBuss").style.display='block';
	document.getElementById("IdTablaNaturalEx").style.display='none';
	document.getElementById("IdAsuntoSoli2").style.display='block';
	
	document.getElementById("IdtxtNameBus").value='';
	document.getElementById("IdtxtDirBus").value='';
	document.getElementById("IdtxtCityBus").value='';
	document.getElementById("IdtxtEstadoProvBus").value='';
	document.getElementById("IdselectCountryBus").value='';
	
	document.getElementById("IdtxtCodiPostalBus").value='';
	document.getElementById("IdselectCountryBus").value='';
	document.getElementById("IdtxtURLBus").value='';
	document.getElementById("IdtxtBusAs").value='';
	

	
	document.getElementById("IdtxtFirstNameBus").value='';
	document.getElementById("IdtxtLastNameBus").value='';
	document.getElementById("IdtxtJobTitleBus").value='';
	
	document.getElementById("IdtxtTelefBus").value='';
	document.getElementById("IdtxtFaxBus").value='';
	document.getElementById("IdtxtEmailBus").value='';
	
	document.getElementById("IdtxtAsuntoSoli2").value='';
	document.getElementById("IdtxtareaAsuntoSoli2").value='';	
	document.getElementById("IdOficinaComercial2").value='';	
  }
  else
  {
  	document.getElementById("IdTablaBuss").style.display='none';
	document.getElementById("IdTablaNaturalEx").style.display='block';
	document.getElementById("IdAsuntoSoli2").style.display='block';
	
	document.getElementById("IdtxtFirstNameN").value='';
	document.getElementById("IdtxtLastNameN").value='';		
	document.getElementById("IdtxtCityN").value='';		

	document.getElementById("IdtxtEstadoProvN").value='';		
	document.getElementById("IdselectCountryN").value='';
	document.getElementById("IdtxtOccupN").value='';		
	document.getElementById("IdtxtTelefN").value='';		
	document.getElementById("IdtxtFaxN").value='';
	document.getElementById("IdtxtEmailN").value='';		
	document.getElementById("IdtxtURLN").value='';	
	
	document.getElementById("IdtxtAsuntoSoli2").value='';
	document.getElementById("IdtxtareaAsuntoSoli2").value='';	
	document.getElementById("IdOficinaComercial2").value='';	
  }
  
  
		
}//fin SeleccionEx(objBuss)


//Persona Jurídica o Persona Natural
function Seleccion(objRadio)
{
  if(objRadio.value=="0")
  {
  	
	document.getElementById("IdJuridica").style.display='block';
	document.getElementById("IdNatural").style.display='none';
	
	document.getElementById("IdtxtNomEmp").value='';
	document.getElementById("IdRUC").value='';

	//Direccion de la Empresa
	document.getElementById("IdtxtDireccionEmp1").value='';
	
	//ciudad o poblado. IdDireccionEmp
	document.getElementById("IdDireccionEmp").value='';

	document.getElementById("IdDepartamento").value='';
	document.getElementById("IdtxtProvincia").value='';
	document.getElementById("IdtxtDistrito").value='';
	document.getElementById("IdtxtCodiPostal").value='';
	document.getElementById("IdtxtURLEmp").value='';
	
	document.getElementById("IdGremio").value='';
	document.getElementById("IdOtrosLugar").value='';
	document.getElementById("IdOtrosLugar").style.display='none';

	document.getElementById("IdtxtNomCon").value='';
	document.getElementById("IdtxtApeCon").value='';
	document.getElementById("IdtxtCargoCon").value='';
	document.getElementById("IdtxtTelefonoCon").value='';
	document.getElementById("IdtxtFaxCon").value='';
	document.getElementById("IdtxtCorreoCon").value='';	

	document.getElementById("IdtxtAsuntoSoli").value='';
	document.getElementById("IdtxtareaAsuntoSoli").value='';
	document.getElementById("IdOficinaComercial").value='';
	

  }
  else
 { 
	
	//alert('entre a ELSE');
	document.getElementById("IdJuridica").style.display='none'; 
	document.getElementById("IdNatural").style.display='block';

	//IdrdbTipoIdentidad
	document.getElementById("IdtxtNumIdentidad").value='';
	document.getElementById("IdtxtNomSoliEmpN").value='';
	document.getElementById("IdtxtApeSoliEmpN").value='';
	document.getElementById("IdDireccionN").value='';
	document.getElementById("IdDepartamento2").value='';
	document.getElementById("IdtxtProvincia2").value='';
	document.getElementById("IdtxtDistrito2").value='';
	document.getElementById("IdtxtCargoSoliEmpN").value='';
	
	document.getElementById("IdtxtTelefonoEmpN").value='';
	document.getElementById("IdtxtFaxEmpN").value='';	
	document.getElementById("IdtxtCorreoSoliEmpN").value='';
	document.getElementById("IdtxtURLEmpN").value='';
	
	
	document.getElementById("IdtxtAsuntoSoli").value='';
	document.getElementById("IdtxtareaAsuntoSoli").value='';;
	document.getElementById("IdOficinaComercial").value='';
	
	
 }	
}

function Display(obj3)
{
  	
	var obj4=document.frm_solinfo.IdGremio.value;
	if(obj4=="38")
	{
	  	//OtrosLugar
		
		document.getElementById("IdOtrosLugar").style.display='block';
		
	}
	else
	{
	  document.getElementById("IdOtrosLugar").style.display='none';
	}

}





function validacion()
{
	// No seas pirata pes by @CCR
	//Validación de Nacionalidad Peruano o Extranjero
	
	//Validación de Nacionalidad 
	var rdbPeruano=document.frm_solinfo.IdrdbTipoPerEx[0];
	var rdbExtranjero=document.frm_solinfo.IdrdbTipoPerEx[1];
	
	if(rdbPeruano.checked)
	{
		//validacion de Juridica / Natural
		var rdbJuridica=document.frm_solinfo.rdbTipoPersona[0];
		var rdbNatural=document.frm_solinfo.rdbTipoPersona[1];

		if(rdbJuridica.checked)//opción Jurídica
		{
			var NomEmp=trim(document.getElementById("IdtxtNomEmp").value);
			if(NomEmp =="") 
			{
				alert("Por favor verifique lo siguiente: Ingrese el Nombre de la Empresa o Institución");		
				return false;
			}		
		
			var ruc=document.getElementById("IdRUC").value;
			if(!(/^\d{11}$/.test(ruc))) 
			{
				alert("Por favor verifique lo siguiente: El RUC debe tener 11 números");
				document.getElementById("IdRUC").value='';
				return false;
			}

			var direccEmp1=trim(document.getElementById("IdtxtDireccionEmp1").value);
			if(direccEmp1=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese la Dirección de la empresa");
				return false;
			}		


			var direccEmp=trim(document.getElementById("IdDireccionEmp").value);
			if(direccEmp=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese la Ciudad o centro poblado");
				return false;
			}		
			
			//validación de Departamento
			var cmbDepartamento=document.getElementById("IdDepartamento");
			if(cmbDepartamento.selectedIndex<=0)
			{
				alert("Por favor verifique lo siguiente: Debe seleccionar el Departamento");
				cmbDepartamento.focus();
	    		return false;	
			}
			
			//validación de Provincia
			var provEmp=trim(document.getElementById("IdtxtProvincia").value);
			if(provEmp=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese la Provincia");
				return false;
			}		
			//validación de Distrito
			var distEmp=trim(document.getElementById("IdtxtProvincia").value);
			if(distEmp=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese el Distrito");
				return false;
			}		
									
			//validación de Gremio y campo: Otros - Especificar
			var cmbGremio=document.getElementById("IdGremio");
			if(cmbGremio.selectedIndex<=0)
			{
				alert("Por favor verifique lo siguiente: Debe seleccionar el Gremio");
				cmbGremio.focus();
	    		return false;	
			}
			var lugarOtros=document.getElementById("IdOtrosLugar").value;
			codiLugar=document.getElementById("IdGremio").value;
			if(codiLugar=="38" && trim(lugarOtros)=="")
			{
				alert("Por favor verifique lo siguiente: Especifíque en el campo otro Gremio");
				cmbGremio.focus();
		     	return false;				
			}		
			// validación de nombre de contacto
			var nomContacto=trim(document.getElementById("IdtxtNomCon").value);
			if(nomContacto=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese el Nombre del contacto");
				return false;
			}
			// validación de apellido de contacto	
			var apeContacto=trim(document.getElementById("IdtxtApeCon").value);
			if(apeContacto=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese el Apellido del contacto");
				return false;
			}
			// validación de cargo de contacto	
			var cargoContacto=trim(document.getElementById("IdtxtCargoCon").value);
			if(cargoContacto=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese el Cargo del contacto");
				return false;
			}
			// validación de correo de contacto			
			var emailCon=trim(document.getElementById("IdtxtCorreoCon").value);
			if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailCon))) 
			{
				alert("Por favor verifique lo siguiente: Dirección de correo electrónico no válida");
				return false;
			}
			
			//validar3();
						
			// validación del asunto
			var asuntoSoliEmp=trim(document.getElementById("IdtxtAsuntoSoli").value);
			if(asuntoSoliEmp=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese el asunto de la solicitud");
				return false;
			}
			// validación de la solicitud	
			var solicitudSoliEmp=trim(document.getElementById("IdtxtareaAsuntoSoli").value);
			if(solicitudSoliEmp=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese la solicitud");
				return false;
			}
			// validación de la oficina comercial	
			var cmbOficinaComercial=document.getElementById("IdOficinaComercial");
			if(cmbOficinaComercial.selectedIndex<=0)
			{
				alert("Por favor verifique lo siguiente: Debe seleccionar la Oficina Comercial.");
				cmbOficinaComercial.focus();
		    	return false;	
			}
			

		}//fin juridica
		
		if(rdbNatural.checked)//opción Natural
		{

			var rdbDNI=document.frm_solinfo.rdbTipoIdentidad[0];
			var rdbCE=document.frm_solinfo.rdbTipoIdentidad[1];
			if(rdbDNI.checked)
			{
				var numIden=trim(document.getElementById("IdtxtNumIdentidad").value);
				if(numIden =="") 
				{
					alert("Por favor verifique lo siguiente: Ingrese el Número de su documento de identidad");		
					return false;
				}		
			}
			
			if(rdbCE.checked)
			{
				var numCE=trim(document.getElementById("IdtxtNumIdentidad").value);
				if(numCE =="") 
				{
					alert("Por favor verifique lo siguiente: Ingrese el Número de su carné de extranjería");		
					return false;
				}		
			}
			
			var NomSol=trim(document.getElementById("IdtxtNomSoliEmpN").value);
			if(NomSol =="") 
			{
				alert("Por favor verifique lo siguiente: Ingrese el Nombre del solicitante");		
				return false;
			}
			
			var ApeSol=trim(document.getElementById("IdtxtApeSoliEmpN").value);
			if(ApeSol =="") 
			{
				alert("Por favor verifique lo siguiente: Ingrese el Apellido del solicitante");		
				return false;
			}
			
			var ciudadDirSol=trim(document.getElementById("IdDireccionN").value);
			if(ciudadDirSol =="") 
			{
				alert("Por favor verifique lo siguiente: Ingrese el nombre de la ciudad o centro poblado");		
				return false;
			}

			// validación del Departamento
			var cmbDepartamento2=document.getElementById("IdDepartamento2");
			if(cmbDepartamento2.selectedIndex<=0)
			{
				alert("Por favor verifique lo siguiente: Debe seleccionar el Departamento");
				cmbDepartamento2.focus();
		    	return false;	
			}
			var prov2=trim(document.getElementById("IdtxtProvincia2").value);
			if(prov2 =="") 
			{
				alert("Por favor verifique lo siguiente: Ingrese la provincia");		
				return false;
			}
			var dist2=trim(document.getElementById("IdtxtDistrito2").value);
			if(dist2 =="") 
			{
				alert("Por favor verifique lo siguiente: Ingrese el distrito");		
				return false;
			}

			var ocupacionSoli=trim(document.getElementById("IdtxtCargoSoliEmpN").value);
			if(ocupacionSoli =="") 
			{
				alert("Por favor verifique lo siguiente: Ingrese la ocupación");		
				return false;
			}
			// validación de correo de la persona natural
			var emailPerNatural=trim(document.getElementById("IdtxtCorreoSoliEmpN").value);
			if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailPerNatural))) 
			{
				alert("Por favor verifique lo siguiente: Dirección de correo electrónico no válida");
				return false;
			}
			
			//validar3();
			// validación del asunto
			var asuntoSoliEmp=trim(document.getElementById("IdtxtAsuntoSoli").value);
			if(asuntoSoliEmp=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese el asunto de la solicitud");
				return false;
			}
			// validación de la solicitud	
			var solicitudSoliEmp=trim(document.getElementById("IdtxtareaAsuntoSoli").value);
			if(solicitudSoliEmp=="")
			{
				alert("Por favor verifique lo siguiente: Ingrese la solicitud");
				return false;
			}
			// validación de la oficina comercial	
			var cmbOficinaComercial=document.getElementById("IdOficinaComercial");
			if(cmbOficinaComercial.selectedIndex<=0)
			{
				alert("Por favor verifique lo siguiente: Debe seleccionar la Oficina Comercial.");
				cmbOficinaComercial.focus();
		    	return false;	
			}
			
			
			
		}//fin Natural
		
	}//fin rdbPeruano

	//Validación de Nacionalidad Extranjero
	if(rdbExtranjero.checked)
	{
		var rdbBuss=document.frm_solinfo.rdbTipoPersonaEx[0];
		var rdbNaturalEx=document.frm_solinfo.rdbTipoPersonaEx[1];
		
		if(rdbBuss.checked)
		{
			var NameBuss=trim(document.getElementById("IdtxtNameBus").value);
			if(NameBuss =="") 
			{
				alert("Please complete the following field: Business name");		
				return false;
			}
			
			var StreetBuss=trim(document.getElementById("IdtxtDirBus").value);
			if(StreetBuss =="") 
			{
				alert("Please complete the following field: Street Address");		
				return false;
			}
					
			var cityBuss=trim(document.getElementById("IdtxtCityBus").value);
			if(cityBuss =="") 
			{
				alert("Please complete the following field: City");		
				return false;
			}
			
			var StateBuss=trim(document.getElementById("IdtxtEstadoProvBus").value);
			if(StateBuss =="") 
			{
				alert("Please complete the following field: State or Province");		
				return false;
			}
			
			//IdselectCountryBus
			var cmbCountryBuss=document.getElementById("IdselectCountryBus");
			if(cmbCountryBuss.selectedIndex<=0)
			{
				alert("Please complete the following field: Country");
				cmbCountryBuss.focus();
		    	return false;	
			}
			
			var firstName=trim(document.getElementById("IdtxtFirstNameBus").value);
			if(firstName =="") 
			{
				alert("Please complete the following field: First Name(s)");		
				return false;
			}
			
			var lastName=trim(document.getElementById("IdtxtLastNameBus").value);
			if(lastName =="") 
			{
				alert("Please complete the following field: Last Name");		
				return false;
			}
			
			var jobTitle=trim(document.getElementById("IdtxtJobTitleBus").value);
			if(jobTitle =="") 
			{
				alert("Please complete the following field: Job Title");		
				return false;
			}

			var emailPerBuss=trim(document.getElementById("IdtxtEmailBus").value);
			if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailPerBuss))) 
			{
				alert("Please complete the following field: Email");
				return false;
			}
			
			// validación del asunto
			var asuntoBuss=trim(document.getElementById("IdtxtAsuntoSoli2").value);
			if(asuntoBuss=="")
			{
				alert("Please complete the following field: Subject");
				return false;
			}
			// validación de la solicitud	
			var solicitudBuss=trim(document.getElementById("IdtxtareaAsuntoSoli2").value);
			if(solicitudBuss=="")
			{
				alert("Please complete the following field: Detailed Request");
				return false;
			}
			// validación de la oficina comercial	
			var cmbtradeOffice=document.getElementById("IdOficinaComercial2");
			if(cmbtradeOffice.selectedIndex<=0)
			{
				alert("Please complete the following field: Select Trade Office ");
				cmbtradeOffice.focus();
		    	return false;
			}
			
		}//fin de rdbBuss
		
		if(rdbNaturalEx.checked)
		{
			var firstNameN=trim(document.getElementById("IdtxtFirstNameN").value);
			if(firstNameN=="")
			{
				alert("Please complete the following field: First Name");
				return false;
			}
			
			var lastNameN=trim(document.getElementById("IdtxtLastNameN").value);
			if(lastNameN=="")
			{
				alert("Please complete the following field: Last Name");
				return false;
			}
			
			var cityN=trim(document.getElementById("IdtxtCityN").value);
			if(cityN=="")
			{
				alert("Please complete the following field: City");
				return false;
			}
			
			var StateProvN=trim(document.getElementById("IdtxtEstadoProvN").value);
			if(StateProvN=="")
			{
				alert("Please complete the following field: State or Province");
				return false;
			}
			
			//IdselectCountryN
			var cmbCountryN=document.getElementById("IdselectCountryN");
			if(cmbCountryN.selectedIndex<=0)
			{
				alert("Please complete the following field: Country");
				cmbCountryBuss.focus();
		    	return false;	
			}
			
			var occupationN=trim(document.getElementById("IdtxtOccupN").value);
			if(occupationN=="")
			{
				alert("Please complete the following field: Occupation");
				return false;
			}
			
			var emailPerN=trim(document.getElementById("IdtxtEmailN").value);
			if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailPerN))) 
			{
				alert("Please complete the following field: Email");
				return false;
			}
			
			// validación del asunto
			var asuntoBuss=trim(document.getElementById("IdtxtAsuntoSoli2").value);
			if(asuntoBuss=="")
			{
				alert("Please complete the following field: Subject");
				return false;
			}
			// validación de la solicitud	
			var solicitudBuss=trim(document.getElementById("IdtxtareaAsuntoSoli2").value);
			if(solicitudBuss=="")
			{
				alert("Please complete the following field: Detailed Request");
				return false;
			}
			
			// validación de la oficina comercial	
			var cmbtradeOffice=document.getElementById("IdOficinaComercial2");
			if(cmbtradeOffice.selectedIndex<=0)
			{
				alert("Please complete the following field: Select Trade Office ");
				cmbtradeOffice.focus();
		    	return false;
			}
			
			/*
			//IdselectCountryBus
			var cmbCountryBuss=document.getElementById("IdselectCountryBus");
			if(cmbCountryBuss.selectedIndex<=0)
			{
				alert("Please complete the following field: Country");
				cmbCountryBuss.focus();
		    	return false;	
			}
			*/
			
			
			
			
			
			
		}//fin de rdbNaturalEx
		
		
	}// fin de Nacionalidad Extranjero




}//Fin validacion


	
		
	
		
		

	
	
		
		


	
	
