/*
	creado por: Ricardo Valle (cnx.v86 [at] gmail [dot] com)
	Octubre 2007.
*/
var browser=navigator.appName;
var Targets=Array("sectorPersonaEstados","sectorPersonaCiudades","sectorPersonaZip","sectorPersonaArea1","sectorPersonaArea2",'sectorHotelEstados', 'sectorHotelCiudades','sectorHotelZip','listaHoteles');
var referer="";
var focused="";		//Para guardar el id del elemento con focus
var datos;
var hoteles="";
var current;		//Para almacenar el valor previo...
/************* Cambios Mayo 2008***************/
/**********************************************/
$(document).ready(function(){
/**********************************
	Funciones para todas las paginas
**********************************/
	try{ $("form").resetForm(); } catch(e){ }
	referer=set.referer();
	$(document).click(function(event){
		var targ;
		if (event.target)
			targ = event.target;
		else if (event.srcElement)
			targ = event.srcElement;
		if (targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;
		//
		if (targ.id!='divFinal'){
			try{ hayErrores(0); } catch(e){	}
		}
	});
	$("input, select").focus(function(){
		focused=this.id;
		focusInput(1,this);
	}).blur(function(){
		focusInput(0,this);
	});
	$("input[type='text'],textarea").blur(function(){
		$(this).val($.trim($(this).val()));
		mayuscula(this);
	}).focus(function(){
		$(this).val((String($(this).val()).toLowerCase()).toProperCase())
	});
	$("input[id$='Dia'], input[id$='Mes'], input[id$='Anio']").keyup(function(){
		soloNumeros(this);
	}).focus(function(){
		current=$(this).val();
		if(String($(this).val()).charAt(0)=="D" || $(this).val()=="Mes" || String($(this).val()).charAt(0)=="A"){
			$(this).val("");
		}
	}).blur(function(){
		if ($(this).val()==''){	$(this).val(current); }
	});
/**********************************
	Funciones por pagina
**********************************/
	switch(referer){
		case "page1.php":
			init.page1();
			$("#pasaportePais").focus();
			break;
		case "page2.php":
			init.page2();
			$("#pasaporteEmisionDia").trigger("focus");
			break;
		case "page3.php":
			init.page3();
			$("#cedulaNacAnio").trigger("click");
			break;
		case "page4.php":
			init.page4();
			break;
		case "page5.php":
			init.page5();
			break;
		case "page7.php":
			init.page7();
			break;
		case "fin.php":
			init.fin();
			break;
	}
});	//document.ready
var init={
	page1:function(){
		var currentEstado="";
		var currentCiudad="";
		$("#ckBrowser").val(navigator.appName+" v: "+navigator.appVersion);
		/*********************************************/
		$("#sectorOne input").focus(function(){
			myFocusDiv(1,'sectorOne');
			myFocusNumber(true,1);
			showImage('1',url1,true);
		}).blur(function(){
			myFocusDiv(0,'sectorOne');
			myFocusNumber(false,1);
			showImage('1','',false);
		});
		$("#pasaportePais").focus(function(){
			//$(this).select();
			this.select();
		}).keyup(function(event){
			var key=event.keyCode;
			myProgress();
			$.get("generator.php",{
				request:"officialCountries",
				query:$.trim($(this).val()),
				seed:Math.random()
			},function(json){
				eval('datos = ' + json);
				$("#listaPaises").addClass("hide").empty();	//inicializar el div
				if ($("#pasaportePais").val()!='' && focused==$("#pasaportePais").attr("id")){ //para los casos de peticiones colgadas...
					$.each(datos.data,function(i,item){
						$("#listaPaises").append('<a href="#" id="'+item.valor+'">'+String(item.texto).toProperCase()+'</a>');
						$("#listaPaises").removeClass("hide");
					})
					$("#listaPaises a").click(function(){
						var arreglo=find.countryInDatos($(this).text());
						$("#pasaportePais").val(String(arreglo.texto).toUpperCase());
						$("#pasaportePaisCodigo").val(arreglo.valor);
						$("#listaPaises").empty().addClass("hide");
						if (arreglo.ciudad!=''){	//si se conoce la ciudad de emision, se asigna a pasaporteCiudad
							$("#pasaporteCiudad").val(String(arreglo.ciudad).toUpperCase());
							$("#pasaporteNumero").trigger("focus");
						}
						else{
							$("#pasaporteCiudad").val("").trigger("focus");
						}
						return false;
					});
				}
				else{
					$("#listaPaises").addClass("hide").empty();
				}
			});
			set.shorcutKeys("pasaportePais", "listaPaises");
		});
		$("#pasaporteCiudad, #pasaporteNumero").focus(function(){
			valid.country("pasaportePais","pasaportePaisCodigo", true);
		});
		$("#pasaporteNumero").blur(function(){
			mayuscula(this);
			if (validPassport(this)==false){
				messagePassport(true);
			}
			else{
				messagePassport(false);
			}
		});
		/*********************************************/
		$("#sectorTwo input").focus(function(){
			myFocusDiv(1,'sectorTwo');
			myFocusNumber(true,2);
			showImage('2',url2,true);
		}).blur(function(){
			myFocusDiv(0,'sectorTwo');
			myFocusNumber(false,2);
			showImage('2','',false);
		});
		$("#cedulaNumero").focus(function(){
			showExplanationM(1,'explicacionCedulaNumero');
		}).blur(function(){
			quitarGuion(this);
			mayuscula(this);
			revisarCedula(this);
			showExplanationM(0,'explicacionCedulaNumero');
			myProgress();
		}).keyup(function(){
			quitarGuion(this);
		});
		/*********************************************/
		$("#sectorThree input").focus(function(){
			myFocusNumber(true,3);
			myFocusDiv(1,'sectorThree');
		}).blur(function(){
			myFocusNumber(false,3);
			myFocusDiv(0,'sectorThree');
		})
		$("#sectorThree input[type='radio']").focus(function(){
			setEstadia();
		}).click(function(){
			setEstadia();
		});
		$("#hotelNombre").focus(function(){
			if (currentEstado!=$.trim($("#hotelEstado").val()) || currentCiudad!=$.trim($("#hotelCiudad").val())){
				if ( $.trim($("#hotelEstado").val())!="" && $.trim($("#hotelEstado").val())!="" ){
					currentEstado=$("#hotelEstado").val();
					currentCiudad=$("#hotelCiudad").val();
					$("input").attr("readonly","readonly");
					$(this).css({
						color:"#A9A9A9"
					}).val("Cargando sugerencias...");
					execute.hotelFinder(currentEstado,currentCiudad,$(this).attr("id"),"listaHoteles","hotelDireccion","hotelTelefono","hotelZip");
				}
			}
		}).keyup(function(){
			$("#listaHoteles").addClass("hide");
		});
		$("#divFinal").click(function(){
			validForm1(true);
		}).mouseover(function(){
			overButton(this);
		}).mouseout(function(){
			outButton(this);
		})
	},
	page2:function(){
		/**********************************
					Zoom
		**********************************/
		$("#question1 input").focus(function(){
			execute.zoom("zoom1","question1",true)
		}).blur(function(){
			execute.zoom("zoom1","question1",false)
		});
		$("#question2 input").focus(function(){
			execute.zoom("zoom2","question2",true)
		}).blur(function(){
			execute.zoom("zoom2","question2",false)
		});
		$("#question3 input").focus(function(){
			execute.zoom("zoom3","question3",true)
		}).blur(function(){
			execute.zoom("zoom3","question3",false)
		});
		$("#question4 input").focus(function(){
			execute.zoom("zoom4","question4",true)
		}).blur(function(){
			execute.zoom("zoom4","question4",false)
		});
		$("#question5 input").focus(function(){
			execute.zoom("zoom5","question5",true)
		}).blur(function(){
			execute.zoom("zoom5","question5",false)
		});
		$("#question6 input").focus(function(){
			execute.zoom("zoom6","question6",true)
		}).blur(function(){
			execute.zoom("zoom6","question6",false)
		});
	},
	page3:function(){
		init.fecha("cedulaNacAnio","cedulaNacMes","cedulaNacDia",true);	//relacionar los elementos y asignar eventos...
		init.fecha("esposaAnio","esposaMes","esposaDia",true);
		$("input[id!='cedulaNacAnio'][id!='cedulaNacMes'], select[id!='cedulaNacAnio'][id!='cedulaNacMes']").blur(function(){
			myProgress();
		}).change(function(){ myProgress(); }).keyup(function(){ myProgress(); });
		$("#cedulaNacDia").blur(function(){
			validarFechaNac($('#cedulaNacAnio').val(),$('#cedulaNacMes').val(), $('#cedulaNacDia').val(),1);
		});
		/***************************
				ZOOMs
		***************************/
		$("#question1 select").focus(function(){
			execute.zoom("zoom1","question1",true)
		}).blur(function(){
			execute.zoom("zoom1","question1",false)
		});
		$("#question2 input").focus(function(){
			execute.zoom("zoom2","question2",true)
		}).blur(function(){
			execute.zoom("zoom2","question2",false)
		});
		$("#question3 input").focus(function(){
			execute.zoom("zoom3","question3",true)
		}).blur(function(){
			execute.zoom("zoom3","question3",false)
		});
		$("#question5 input").focus(function(){
			execute.zoom("zoom5","question5",true)
		}).blur(function(){
			execute.zoom("zoom5","question5",false)
		});
		$("#question6 input").focus(function(){
			execute.zoom("zoom6","question6",true)
		}).blur(function(){
			execute.zoom("zoom6","question6",false)
		});
		$("#question7 input").focus(function(){
			execute.zoom("zoom7","question7",true)
		}).blur(function(){
			execute.zoom("zoom7","question7",false)
		});
		$("#question8 input").focus(function(){
			execute.zoom("zoom8","question8",true)
		}).blur(function(){
			execute.zoom("zoom8","question8",false)
		});
	},
	page4:function(){
		var ocupaciones="";
		$.get("generator.php?request=ocupaciones",function(json){
			eval("ocupaciones = "+json);
			$("#trabajandoOcupacion").empty().append('<option value="">Seleccione</option>');
			$.each(ocupaciones.data,function(i,item){
				var texto=String(item.texto).toProperCase();
				//texto=String(texto).toProperCase();
				$("#trabajandoOcupacion").append('<option value="'+item.valor+'">'+texto+'</option>');
			});
		})
	},
	page5:function(){
		var motivos="";
		var pagadores="";
		$.get("generator.php?request=motivos",function(json){
			eval("motivos = "+json);
			$("#viajeMotivo").empty().append('<option value="">Seleccione</option>');
			$.each(motivos.data,function(i,item){
				var texto=String(item.texto).toProperCase();
				//texto=String(texto).toProperCase();
				$("#viajeMotivo").append('<option value="'+item.valor+'">'+texto+'</option>');
			});
		});
		$.get("generator.php?request=pagadores",function(json){
			eval("pagadores = "+json);
			$("#viajePagador").empty().append('<option value="">Seleccione</option>');
			$.each(pagadores.data,function(i,item){
				var texto=String(item.texto).toProperCase();
				//texto=String(texto).toProperCase();
				$("#viajePagador").append('<option value="'+item.valor+'">'+texto+'</option>');
			});
		});
		/*$("#acompanantes").blur(function(){
			if($.trim($(this).val())==""){
				$(this).val("NONE");
			}
		}).focus(function(){
			if ($.trim($(this).val())=="NONE" || $.trim($(this).val())=="none"){
				$(this).val("");
			}
		})*/
	},
	page7:function(){
		$.get("generator.php?request=condiciones",function(json){
			eval("motivos = "+json);
			$("select[id$='ondicion']").empty().append('<option value="">Seleccione</option>');
			$.each(motivos.data,function(i,item){
				var texto=String(item.texto).toProperCase();
				$("select[id$='ondicion']").append('<option value="'+item.valor+'">'+texto+'</option>');
			});
		});
	},
	fin:function(){
		$("#popup a.close").click(function(){
			$("#popup").slideUp("normal");
			return false;
		});
		$("#successMessage a.invite").click(function(){
			$("#popup").slideDown("normal",function(){
				var container=document.getElementById("myIframe");
				if (container.contenDocument){
					container.contentDocument.getElementById("email").focus();
				}
				else if(container.contentWindow){
					container.contentWindow.document.getElementById("email").focus();
				}
			});
			return false;
		});
	},
	fecha:function(idAnio,idMes,idDia,bandera){
		set.dias($("#"+idAnio).val(),$("#"+idMes).val(),idDia);	//Inicializar los dias...
		set.anios(idAnio,bandera);					//Inicializar los anios...
		$("#"+idAnio+" ,#"+idMes).change(function(){			//Al cambiar el mes, deben actualizarse los dias..
			set.dias($("#"+idAnio).val(),$("#"+idMes).val(),idDia);
		});
	}
}
var set={
	referer:function(){
		var URL=String(window.location).split("/");
		URL=URL[URL.length-1];
		URL=String(URL).split("#");
		URL=String(URL).split("?");
		URL=String(URL[0]).replace(",","");	//para error desconocido...
		return URL;
	},
	dias:function(Anio,Mes,idTarget){
		var mes=Number(Mes);
		var anio=Number(Anio);
		var dias=0;
		$("#"+idTarget).empty();
		if (mes == "1" || mes == "3" || mes == "5" || mes == "7" || mes == "8" || mes == "10" || mes == "12") {
			dias=31;
		}
		if (mes == "4" || mes == "6" || mes == "9" || mes == "11") {
			dias=30;
		}
		if (mes=="2" && (anio%4==0)){
			dias=29;
		}
		else if (mes=="2"){
			dias=28;
		}
		$("#"+idTarget).append('<option value="" disabled="disabled">D&iacute;a</option>');
		for (var i=1; i<=dias; i++){
			$("#"+idTarget).append('<option value="'+i+'">'+i+'</option>');
		}
	},
	anios:function(idTarget,reverse){	//requiere uso de currentYear (variable global)
		$("#"+idTarget).empty().append('<option value="" disabled="disabled">A&ntilde;o</option>');
		if(reverse){
			var inicio=currentYear-100;
			var fin=currentYear;
			for (var i=fin;i>=inicio;i--){
				$("#"+idTarget).append('<option value="'+i+'">'+i+'</option>');
			}
		}
		else{
			var inicio=currentYear;
			var fin=currentYear+20;
			for (var i=inicio;i<=fin;i++){
				$("#"+idTarget).append('<option value="'+i+'">'+i+'</option>');
			}
		}
	},
	shorcutKeys:function(idSource,idTarget){
		$(document).keyup(function(event){
			var key=event.keyCode;
			if ((focused==idSource || focused==idTarget) && key==40){
				var currentIndex=$("#"+idTarget).index("a [id='"+focused+"']");
				if (currentIndex=="-1"){
					currentIndex=0;
				}
				$("#"+idTarget+" a").eq(currentIndex).trigger("focus");
			}
		})
	}
}
var find={
	countryInDatos:function(valor){
		valor=String(valor).toUpperCase();
		var response;
		$.each(datos.data,function(i,item){
			if (item.texto===valor){
				response=item;
			}
		});
		return response;
	},
	hotelInDatos:function(id){
		var response;
		$.each(hoteles.ResultSet.Result,function(i,item){
			if(item.id===id){
				response=item;
			}
		});
		return response;
	}
}
var valid={
	country:function(idPais,idCodigo,bandera){
		$.get("generator.php",{
			request:"validCountry",
			country:$("#"+idPais).val(),
			code:$("#"+idCodigo).val(),
			seed:Math.random()
		},function(data){
			if(data!=1 && focused!='pasaportePais' && bandera==true){
				alert("Favor seleccione un pais de la lista desplegable")
				$("#pasaporteCiudad").trigger("blur");
				$("#pasaportePais").trigger("focus");
			}
			if (data==1){
				return true;
			}
			if (data==0){
				return false;
			}
		})
	}
}
var execute={
	hideInvite:function(){
		$("#popup").slideUp("normal");
	},
	zoom:function(idTarget, idRow, bandera){
		if (bandera==true){
			$("#"+idRow).css({ backgroundColor:"#DCECFF" });
			$("#"+idTarget).removeClass("hide").addClass("divZoom");
			fixToOthers(idTarget);
		}
		else{
			$("#"+idRow).css({ backgroundColor:"" });
			$("#"+idTarget).removeClass("divZoom").addClass("hide");
		}
	},
	hotelFinder:function(estado,ciudad,idSource,idTarget,idDireccion,idTelefono,idZip){
		$.post("generator.php?request=hotels",{
			estado:estado,
			ciudad:ciudad,
			seed:Math.random()
		},function(json){
			try{ eval("hoteles = "+json); } catch(e) { }
			$("input").attr("readonly","");
			$("#"+idSource).css({
				color:"#000000"
			}).val("");
			$("#"+idTarget).addClass("hide").empty();
			//if (focused==idSource){
				try{	//hay que contemplar errores por los casos en que se envien incoherencias al api...
					$.each(hoteles.ResultSet.Result,function(i,item){
						$("#"+idTarget).append('<a href="#" id="'+item.id+'">'+String(item.Title).toProperCase()+'</a>');
						$("#"+idTarget).removeClass("hide");
					})
					$("#"+idTarget+" a").click(function(){
						var arreglo=find.hotelInDatos(this.id);
						$("#"+idSource).val(String(arreglo.Title).toUpperCase());
						$("#"+idDireccion).val(String(arreglo.Address).toUpperCase());
						$("#"+idTelefono).val(String(arreglo.Phone)).trigger("keyup");
						$("#"+idTarget).empty().addClass("hide");
						$("#"+idZip).trigger("focus");
						return false;
					});
				}
				catch(e){
					
				}
			//}
		});
	}
}
/**********************************************/
/**********************************************/
function isIn(valor, arreglo){
	for (var i = 0; i < arreglo.length; i++) {
		if (valor == arreglo[i]) {
			return true;
		}
	}
	return false;
}
String.prototype.toProperCase = function(){
     return this.toLowerCase().replace(/\w+/g,function(s){
          return s.charAt(0).toUpperCase() + s.substr(1);
     })
}

function validPassport(objeto){
	var respuesta=true;
	var codigo=String(objeto.value);
	if (codigo.length>8 || codigo.length<8){
		respuesta = false;
	}
	if (isNaN(codigo.charAt(0))==false){
		respuesta = false;
	}
	for (var i=1; i<8; i++){
		if (isNaN(codigo.charAt(i))==true){
			respuesta = false;
		}
	}
	if (document.getElementById("pasaportePais").value!="NICARAGUA" && $.trim(objeto.value)!=''){
		respuesta=true;
	}
	return respuesta;
	/*if (respuesta==false){
		messagePassport(true);
	}
	else{
		messagePassport(false);
	}*/
}
function messagePassport(bandera){
	if (bandera==true){
		document.getElementById("pasaporteNumeroGood").className="oculto";
		document.getElementById("pasaporteNumeroBad").className="display";
		document.getElementById("pasaporteNumeroMessage").className="txtMessage";
	}
	else{
		document.getElementById("pasaporteNumeroGood").className="display";
		document.getElementById("pasaporteNumeroBad").className="oculto";
		document.getElementById("pasaporteNumeroMessage").className="oculto";
	}
}
function isVacio(objeto, Good, Bad, Message){
	if (objeto.value==''){
		document.getElementById(Good).className="oculto";
		document.getElementById(Bad).className="display";
		document.getElementById(Message).className="txtMessage";
	}
	else{
		document.getElementById(Good).className="display";
		document.getElementById(Bad).className="oculto";
		document.getElementById(Message).className="oculto";
	}
}
function espVacio(objeto, Good, Bad, Message, Default){
	if (objeto.value=='' || objeto.value==Default){
		document.getElementById(Good).className="oculto";
		document.getElementById(Bad).className="display";
		document.getElementById(Message).className="txtMessage";
	}
	else{
		document.getElementById(Good).className="display";
		document.getElementById(Bad).className="oculto";
		document.getElementById(Message).className="oculto";
	}
}
function fix(){
	if (browser=="Netscape"){
		document.getElementById("progressBlank").style.marginTop="0px";
	}
}
function overButton(objeto){
	objeto.style.backgroundColor="#DCECFF";
}
function outButton(objeto){
	objeto.style.backgroundColor="#FFFFFF";
}
function myZoom(bandera, question, target){
	if (bandera==1){
		document.getElementById(question).style.backgroundColor="#DCECFF";
		if (target){
			document.getElementById(target).className="divZoom";
			fixToOthers(target);
		}
	}
	else{
		document.getElementById(question).style.backgroundColor="";
		if (target){
			document.getElementById(target).className="oculto";
		}
	}
}
function fixToOthers(target){
	//if (browser=="Netscape" || browser=="Opera"){
	if (browser!="Microsoft Internet Explorer"){
		document.getElementById(target).style.marginTop="-20px";
		document.getElementById(target).style.marginLeft="210px";
	}
	/*margin-top:-20px;
	margin-left:210px;*/
}
function prepareForm(){
	var Inputs=document.forms[0].getElementsByTagName("input");
	for (var i=0; i<Inputs.lenght; i++){
		alert(Inputs.type);
		if (Inputs[i].type.toLowerCase()=="radio"){
			Inputs[i].checked=false;
		}
	}
}
function focusInput(bandera, target){
	if (bandera==1){
		target.style.color="#000000";
		target.style.borderColor="#339900";
	}
	else{
		target.style.color="";
		target.style.borderColor="";
	}
}
function showExplanationB(bandera, Target){
	var target=document.getElementById(Target);
	if (bandera==1){
		target.className="divFloatExplanationB";
	}
	else{
		target.className="oculto";
	}
}
function showExplanationM(bandera, Target){
	var target=document.getElementById(Target);
	if (bandera==1){
		target.className="divFloatExplanationM";
	}
	else{
		target.className="oculto";
	}
}
function showExplanationS(bandera, Target){
	var target=document.getElementById(Target);
	if (bandera==1){
		target.className="divFloatExplanationS";
	}
	else{
		target.className="oculto";
	}
}
function setEstadia(){
	if (document.getElementById("dondeusaPersona").checked){
		document.getElementById("estadiaPersona").className="visible";
		document.getElementById("estadiaHotel").className="oculto";
	}
	if (document.getElementById("dondeusaHotel").checked){
		document.getElementById("estadiaPersona").className="oculto";
		document.getElementById("estadiaHotel").className="visible";
	}
	if (document.getElementById("dondeusaTransito").checked){
		document.getElementById("estadiaPersona").className="oculto";
		document.getElementById("estadiaHotel").className="oculto";
	}
}
function decidirOtrosNombres(){
	if (document.getElementById("otrosNombresSi").checked){
		document.getElementById('sectorOtrosNombres').className="visible";
	}
	if (document.getElementById("otrosNombresNo").checked){
		document.getElementById('sectorOtrosNombres').className="oculto";
	}
}
function decidirOtrosApellidos(){
	if (document.getElementById("otrosApellidosSi").checked){
		document.getElementById('sectorOtrosApellidos').className="visible";
	}
	if (document.getElementById("otrosApellidosNo").checked){
		document.getElementById('sectorOtrosApellidos').className="oculto";
	}
}
function decidirOcupacion(){
	if (document.getElementById("ocupacionTrabajando").checked){
		document.getElementById('sectorTrabajo').className="visible";
		document.getElementById('sectorEstudio').className="oculto";
	}
	if (document.getElementById("ocupacionEstudiando").checked){
		document.getElementById('sectorTrabajo').className="oculto";
		document.getElementById('sectorEstudio').className="visible";
	}
	if (document.getElementById("ocupacionDesempleado").checked){
		document.getElementById('sectorTrabajo').className="oculto";
		document.getElementById('sectorEstudio').className="oculto";
	}
	if (document.getElementById("ocupacionJubilado").checked){
		document.getElementById('sectorTrabajo').className="oculto";
		document.getElementById('sectorEstudio').className="oculto";
	}
}
function decidirTrabajoFax(){
	if (document.getElementById("trabajandoFaxSi").checked){
		document.getElementById("sectorTrabajoFax").className="visible";
	}
	if (document.getElementById("trabajandoFaxNo").checked){
		document.getElementById("sectorTrabajoFax").className="oculto";
	}
}
function decidir(check1, check2, target){
	if (document.getElementById(check1).checked){
		document.getElementById(target).className="visible";
	}
	if (document.getElementById(check2).checked){
		document.getElementById(target).className="oculto";
	}
}
function preguntarEmpresa(objeto){
	if (objeto.value=="COMPANY"){
		document.getElementById("sectorCompania").className="visible";
	}
	else{
		document.getElementById("sectorCompania").className="oculto";
	}
}
function setNombre(valor){
	if (valor!='' && valor!=' '){
		var nombre="";
		nombre=valor.split(" ")[0];
		if (nombre!='' && nombre!=' '){
			resto=nombre.substring(1,nombre.length);
			resto=resto.toLowerCase();
			primeraLetra=String(nombre.charAt(0));
			primeraLetra=primeraLetra.toUpperCase();
			nombre=primeraLetra+resto;
			document.getElementById("telefonodeldomicilio").innerHTML="Tel&eacute;fono del domicilio de "+nombre;
			document.getElementById("telefonodeltrabajo").innerHTML="Tel&eacute;fono del trabajo de "+nombre;
			document.getElementById("celular").innerHTML="Celular de "+nombre;
		}
	}
	else{
		document.getElementById("telefonodeldomicilio").innerHTML="Tel&eacute;fono del domicilio";
		document.getElementById("telefonodeltrabajo").innerHTML="Tel&eacute;fono del trabajo";
		document.getElementById("celular").innerHTML="Celular";
	}
}
function setEstadoCivil(valor){
	if (valor=="Married" || valor=="Divorced" || valor=="Separated"){
		document.getElementById("sectorEstadoCivil").className="myTr";
	}
	else{
		document.getElementById("sectorEstadoCivil").className="oculto";
	}
}
function trimFirstSpace(objeto){
	var cadena=objeto.value;
	var myCadena="";
	if (cadena.charAt(0)===" "){
		myCadena=cadena.substring(1,cadena.length);
		objeto.value=myCadena;
	}
}
function makeNewLines(objeto){
	var cadena=objeto.value;
	var myCadena="";
	for (var i=0; i<cadena.length; i++){
		if (cadena.charAt(i)==="\n"){
			myCadena+=". ";
		}
		else{
			myCadena+=cadena.charAt(i);
		}
	}
	objeto.value=myCadena;
}
function quitarGuion(objeto){
	cadena=String(objeto.value);
	var mycadena='';
	for (var i=0; i<cadena.length; i++)	{
		if (cadena.charAt(i)=='-'||cadena.charAt(i)==' ')
			mycadena+='';
		else
			mycadena+=cadena.charAt(i);
	}
	objeto.value=String(mycadena);
}
function isNumber(expresion){
	var ValidChars = "0123456789";
 	var IsNumber=true;
 	var Char;
 	for (i = 0; i < expresion.length && IsNumber == true; i++) { 
   		Char = expresion.charAt(i); 
      	if (ValidChars.indexOf(Char) == -1) {
        	IsNumber = false;
		}
	}
	if (expresion==''){
		IsNumber = false;
	}
   	return IsNumber;   
}
function soloNumeros(objeto){
	cadena=String(objeto.value);
	var mycadena='';
	for (var i=0; i<cadena.length; i++){
		if (isNumber(cadena.charAt(i))==false)
			mycadena+='';
		else
			mycadena+=cadena.charAt(i);
	}
	objeto.value=String(mycadena);
}
function validarTiempoUsa(display){
	var anios=document.getElementById("viajeTiempoAnios").value;
	var meses=document.getElementById("viajeTiempoMeses").value;
	var dias=document.getElementById("viajeTiempoDias").value;
	if (anios=='' && meses=='' && dias==''){
		if (display=='1')
			messageTiempoUsa(0);
		return false;
	}
	else{
		if (display=='1')
			messageTiempoUsa(1);
		return true;
	}
}
function messageTiempoUsa(bandera){
	if (bandera=='1'){
		document.getElementById("viajeTiempoGood").className="display";
		document.getElementById("viajeTiempoBad").className="oculto";
		document.getElementById("viajeTiempoMessage").className="oculto"
	}
	else{
		document.getElementById("viajeTiempoGood").className="oculto";
		document.getElementById("viajeTiempoBad").className="display";
		document.getElementById("viajeTiempoMessage").className="txtMessage"
	}
}
function validarTiempoUsaAnterior(display){
	var anios=document.getElementById("viajeAnteriorAnios").value;
	var meses=document.getElementById("viajeAnteriorMeses").value;
	var dias=document.getElementById("viajeAnteriorDias").value;
	if (anios=='' && meses=='' && dias==''){
		if (display=='1')
			messageTiempoAnterior(0);
		return false;
	}
	else{
		if (display=='1')
			messageTiempoAnterior(1);
		return true;
	}
}
function messageTiempoAnterior(bandera){
	if (bandera=='1'){
		document.getElementById("viajeAnteriorGood").className="display";
		document.getElementById("viajeAnteriorBad").className="oculto";
		document.getElementById("viajeAnteriorMessage").className="oculto"
	}
	else{
		document.getElementById("viajeAnteriorGood").className="oculto";
		document.getElementById("viajeAnteriorBad").className="display";
		document.getElementById("viajeAnteriorMessage").className="txtMessage"
	}
}
function validarTiempoUsaAnterior(display){
	var anios=document.getElementById("viajeAnteriorAnios").value;
	var meses=document.getElementById("viajeAnteriorMeses").value;
	var dias=document.getElementById("viajeAnteriorDias").value;
	if (anios=='' && meses=='' && dias==''){
		if (display=='1')
			messageTiempoUsaAnterior(0);
		return false;
	}
	else{
		if (display=='1')
			messageTiempoUsaAnterior(1);
		return true;
	}
}
function messageTiempoUsaAnterior(bandera){
	if (bandera=='1'){
		document.getElementById("viajeAnteriorGood").className="display";
		document.getElementById("viajeAnteriorBad").className="oculto";
		document.getElementById("viajeAnteriorMessage").className="oculto"
	}
	else{
		document.getElementById("viajeAnteriorGood").className="oculto";
		document.getElementById("viajeAnteriorBad").className="display";
		document.getElementById("viajeAnteriorMessage").className="txtMessage"
	}
}
function validarCedula(objeto){
	//Esto se hara despues de quitar los guiones y espacios.
	//quitar_guion(objeto);
	cadena=$.trim(objeto.value);
	respuesta=true;
	if (cadena.length>0){
		if (cadena.length==14){
			evaluar=cadena.substring(0,(cadena.length-1));
			if (!(isNumber(evaluar))){
				respuesta = false;
			}
			else{
				if (isNumber(cadena.charAt(cadena.length-1))){
					respuesta = false;	
				}
			}
		}
		else{
			respuesta=false;
		}
	}
	else{
		respuesta=false;	
	}
	if (document.getElementById("pasaportePais").value!="NICARAGUA" && cadena!=''){
		respuesta=true;
	}
	return respuesta;
}
function revisarCedula(objeto){
	var respuesta=validarCedula(objeto);
	if (respuesta==true){
		document.getElementById("cedulaNumeroGood").className="display";
		document.getElementById("cedulaNumeroBad").className="oculto";
		document.getElementById("cedulaNumeroMessage").className="oculto";
	}
	else{
		document.getElementById("cedulaNumeroBad").className="display";
		document.getElementById("cedulaNumeroGood").className="oculto";
		document.getElementById("cedulaNumeroMessage").className="txtMessage";
	}
}
function mayuscula(objeto){
	myText=String(objeto.value);
	myText=myText.toUpperCase();
	objeto.value=myText;
}
function hayErrores(bandera){
	if (bandera==1){
		if(browser!="Microsoft Internet Explorer"){
			document.getElementById("divAlert").style.marginLeft="-78px";
		}
		document.getElementById("divAlert").className="divAlert";
	}
	else{
		document.getElementById("divAlert").className="oculto";
	}
}
function validForm1(guardar){
	var errores=0;
	//if (validPassport(document.getElementById("pasaporteNumero").value))
	/*if (document.getElementById("pasaportePais").value=='' || document.getElementById("pasaportePais").value==' '){
		errores++;
	}*/
	if (valid.country("pasaportePais","pasaportePaisCodigo",false)==false){
		errores++;
	}
	if (validPassport(document.getElementById("pasaporteNumero"))==false){
		errores++;
	}
	if (validarCedula(document.getElementById("cedulaNumero"))==false){
		errores++;
	}
	if (document.getElementById("dondeusaPersona").checked){
		if(document.getElementById("personausaNombre").value==''){
			errores++;
		}
		if(document.getElementById("personausaDireccion").value==''){
			errores++;
		}
		if(document.getElementById("personausaCiudad").value==''){
			errores++;
		}
		if(document.getElementById("personausaEstado").value==''){
			errores++;
		}
		if(document.getElementById("personausaZip").value==''){
			errores++;
		}
		if(document.getElementById("personausaTelefono1").value=='' && document.getElementById("personausaTelefono2").value=='' && document.getElementById("personausaTelefono3").value==''){
			errores++;
		}
	}
	if (document.getElementById("dondeusaHotel").checked){
		if(document.getElementById("hotelEstado").value==''){
			errores++;
		}
		if(document.getElementById("hotelCiudad").value==''){
			errores++;
		}
		if(document.getElementById("hotelNombre").value==''){
			errores++;
		}
		if(document.getElementById("hotelDireccion").value==''){
			errores++;
		}
		if(document.getElementById("hotelTelefono").value==''){
			errores++;
		}
		if(document.getElementById("hotelZip").value==''){
			errores++;
		}
	}
	if (document.getElementById("dondeusaPersona").checked==false && document.getElementById("dondeusaHotel").checked==false && document.getElementById("dondeusaTransito").checked==false){
		errores++;
	}
	if (guardar==true){
		if (errores>0){
			hayErrores(1);
		}
		else{
			hayErrores(0);
			document.myForm1.submit();
		}
	}
	else{
		return errores;
	}
}
function validForm2(guardar){
	var errores=0;
	if (validarFechaEmision(document.getElementById('pasaporteEmisionDia').value, document.getElementById('pasaporteEmisionMes').value, document.getElementById('pasaporteEmisionAnio').value)==false)
		errores++;
	if (validarFechaExpiracion(document.getElementById('pasaporteExpiracionDia').value, document.getElementById('pasaporteExpiracionMes').value, document.getElementById('pasaporteExpiracionAnio').value)==false)
		errores++;
	if (document.getElementById("pasaporteNombre1").value=='' || document.getElementById("pasaporteNombre1").value==' ')
		errores++;
	if (document.getElementById("pasaporteNombre2").value=='' || document.getElementById("pasaporteNombre2").value==' ')
		errores++;
	if (document.getElementById("otrosNombresSi").checked){
		if (document.getElementById("otrosNombresText").value=='' || document.getElementById("otrosNombresText").value==' ')
			errores++;
	}
	if (document.getElementById("otrosNombresNo").checked == false && document.getElementById("otrosNombresSi").checked == false){
		errores++;
	}
	if (document.getElementById("pasaporteApellido1").value=='' || document.getElementById("pasaporteApellido1").value==' ')
		errores++;
	if (document.getElementById("pasaporteApellido2").value=='' || document.getElementById("pasaporteApellido2").value==' ')
		errores++;
	if (document.getElementById("otrosApellidosSi").checked){
		if (document.getElementById("otrosApellidosText").value=='' || document.getElementById("otrosApellidosText").value==' ')
			errores++;
	}
	if (document.getElementById("otrosApellidosNo").checked == false && document.getElementById("otrosApellidosSi").checked == false){
		errores++;
	}

	if (guardar==true){
		if (errores>0){
			hayErrores(1);
		}
		else{
			document.myForm2.submit();
		}
	}
	else{
		return errores;
	}
}
function validForm3(guardar){
	var errores=0;
	if (validarFechaNac($('#cedulaNacAnio').val(), $('#cedulaNacMes').val(), $('#cedulaNacDia').val())==false)
		errores++;
	if (document.getElementById("cedulaNacLugar").value=='' || document.getElementById("cedulaNacLugar").value==' ')
		errores++;
	if (document.getElementById("cedulaNacDepartamento").value=='' || document.getElementById("cedulaNacDepartamento").value==' ')
		errores++;
	if (document.getElementById("cedulaSexoM").checked == false && document.getElementById("cedulaSexoF").checked == false){
		errores++;
	}
	if (document.getElementById("cedulaDirDomicilio").value=='' || document.getElementById("cedulaDirDomicilio").value==' ')
		errores++;
	if (document.getElementById("cedulaDirDomicilio2").value=='' || document.getElementById("cedulaDirDomicilio2").value==' ')
		errores++;
	if (document.getElementById("cedulaCiudad").value=='' || document.getElementById("cedulaCiudad").value==' ')
		errores++;
	if (document.getElementById("cedulaDepartamento").value=='' || document.getElementById("cedulaDepartamento").value==' ')
		errores++;
	valor=document.getElementById("cmbEstadoCivil").value;
	if (valor!="Single" && valor!=""){
		if (document.getElementById("estadoCivilNombre").value=='' || document.getElementById("estadoCivilNombre").value==' ')
			errores++;
		if (validarFechaGen('esposaDia', 'esposaMes', 'esposaAnio', 'esposaGood', 'esposaBad', 'esposaMessage')==false){
			errores++;
		}
	}
	/*if (valor==''){
		respuesta=false;
	}*/
	
	if (guardar==true){
		if (errores>0){
			hayErrores(1);
		}
		else{
			document.myForm3.submit();
		}
	}
	else{
		return errores;
	}
}
function validForm4(guardar){
	var errores=0;
	if (isNumber(document.getElementById("contactoTelefono").value)==false){
		errores++;
	}
	if (document.getElementById("ocupacionTrabajando").checked==false && document.getElementById("ocupacionDesempleado").checked==false && document.getElementById("ocupacionEstudiando").checked==false && document.getElementById("ocupacionJubilado").checked==false){
		errores++;
	}
	if (document.getElementById("faxSi").checked==false && document.getElementById("faxNo").checked==false){
		errores++;
	}
	if (document.getElementById("celularSi").checked==false && document.getElementById("celularNo").checked==false){
		errores++;
	}
	if (document.getElementById("beeperSi").checked==false && document.getElementById("beeperNo").checked==false){
		errores++;
	}
	if (document.getElementById("emailSi").checked==false && document.getElementById("emailNo").checked==false){
		errores++;
	}
	if (document.getElementById("ocupacionTrabajando").checked){
		if (document.getElementById("trabajandoOcupacion").value == '' || document.getElementById("trabajandoOcupacion").value== ' ')
			errores++;
		if (document.getElementById("trabajandoEmpleador").value == '' || document.getElementById("trabajandoEmpleador").value== ' ')
			errores++;
		if (document.getElementById("trabajandoDireccionEmpleador").value == '' || document.getElementById("trabajandoDireccionEmpleador").value== ' ')
			errores++;
		if (document.getElementById("trabajandoCiudad").value == '' || document.getElementById("trabajandoCiudad").value== ' ')
			errores++;
		if (document.getElementById("trabajandoDepartamento").value == '' || document.getElementById("trabajandoDepartamento").value== ' ')
			errores++;
		if (isNumber(document.getElementById("trabajandoTelefono").value)==false)
			errores++;
		if (document.getElementById("trabajandoFaxSi").checked == false && document.getElementById("trabajandoFaxNo").checked == false){
			errores++;
		}
		else{
			if (document.getElementById("trabajandoFaxSi").checked){
				if (isNumber(document.getElementById("trabajandoFaxNumero").value)==false)
					errores++;
			}
		}
	}
	if (document.getElementById("ocupacionEstudiando").checked){
		if (document.getElementById("estudiandoNombre").value == '' || document.getElementById("estudiandoNombre").value== ' ')
			errores++;
		if (document.getElementById("estudiandoDireccion").value == '' || document.getElementById("estudiandoDireccion").value== ' ')
			errores++;
		if (document.getElementById("estudiandoCiudad").value == '' || document.getElementById("estudiandoCiudad").value== ' ')
			errores++;
		if (document.getElementById("estudiandoDepartamento").value == '' || document.getElementById("estudiandoDepartamento").value== ' ')
			errores++;
	}
	if (document.getElementById("faxSi").checked){
		if (isNumber(document.getElementById("contactoFax").value)==false)
			errores++;
	}
	if (document.getElementById("celularSi").checked){
		if (isNumber(document.getElementById("contactoCelular").value)==false)
			errores++;
	}
	if (document.getElementById("beeperSi").checked){
		if (isNumber(document.getElementById("contactoBeeper").value)==false)
			errores++;
	}
	if (document.getElementById("emailSi").checked){
		if (document.getElementById("contactoEmail").value == '')
			errores++;
	}
	if (guardar==true){
		if (errores>0){
			hayErrores(1);
		}
		else{
			document.myForm4.submit();
		}
	}
	else{
		return errores;
	}
}
function validForm5(guardar){
	var errores=0;
	if (document.getElementById("viajeMotivo").value==''){
		errores++;
	}
	if (validarFechaViaje(document.getElementById('viajeDia').value, document.getElementById('viajeMes').value, document.getElementById('viajeAnio').value)==false){
		errores++;
	}
	if (validarTiempoUsa()==false){
		errores++;
	}
	/*if (document.getElementById("acompanantes").value==""){
		errores++;
	}*/
	if (document.getElementById("viajePagador").value==''){
		errores++;
	}
	if (document.getElementById("viajePagador").value=="COMPANY"){
		if (document.getElementById("nombreEmpresa").value==""){
			errores++;
		}
	}
	if (document.getElementById("usaSi").checked==false && document.getElementById("usaNo").checked==false){
		errores++;
	}
	if (document.getElementById("trabajoUsaSi").checked==false && document.getElementById("trabajoUsaNo").checked==false){
		errores++;
	}
	if (document.getElementById("estudiarUsaSi").checked==false && document.getElementById("estudiarUsaNo").checked==false){
		errores++;
	}
	if (document.getElementById("usaSi").checked){
		if (validarFechaGen('usaSiDia', 'usaSiMes', 'usaSiAnio', 'usaSiGood', 'usaSiBad', 'usaSiMessage')==false){
			errores++;
		}
		if (validarTiempoUsaAnterior()==false){
			errores++;
		}
		if (document.getElementById("usaOtrasSi").checked==false && document.getElementById("usaOtrasNo").checked==false){
			errores++;
		}
		if (document.getElementById("usaOtrasSi").checked){
			if (validarFechaGen('usaOtrasDia', 'usaOtrasMes', 'usaOtrasAnio', 'usaOtrasGood', 'usaOtrasBad', 'usaOtrasMessage')==false){
				errores++;
			}
		}
	}
	if(document.getElementById("trabajoUsaSi").checked){
		if (document.getElementById("trabajoUsaEmpleador").value==''){
			errores++;
		}
		if (document.getElementById("trabajoUsaCiudad").value==''){
			errores++;
		}
		if (document.getElementById("trabajoUsaEstado").value==''){
			errores++;
		}
	}
	if(document.getElementById("estudiarUsaSi").checked){
		if (document.getElementById("estudioUsaNombre").value==''){
			errores++;
		}
		if (document.getElementById("estudioUsaDireccion").value==''){
			errores++;
		}
		if (document.getElementById("estudioUsaCiudad").value==''){
			errores++;
		}
		if (document.getElementById("estudioUsaEstado").value==''){
			errores++;
		}
	}
	if (guardar==true){
		if (errores>0){
			hayErrores(1);
		}
		else{
			document.myForm5.submit();
		}
	}
	else{
		return errores;
	}
}
function validForm6(guardar){
	var errores=0;
	if (document.getElementById("visaOtorgadaSi").checked==false && document.getElementById("visaOtorgadaNo").checked==false){
		errores++;
	}
	if (document.getElementById("visaNegadaSi").checked==false && document.getElementById("visaNegadaNo").checked==false){
		errores++;
	}
	if (document.getElementById("visaCanceladaSi").checked==false && document.getElementById("visaCanceladaNo").checked==false){
		errores++;
	}
	if (document.getElementById("visaQuienSi").checked==false && document.getElementById("visaQuienNo").checked==false){
		errores++;
	}
	if (document.getElementById("visaOtorgadaSi").checked){
		if(validarFechaGen('visaOtorgadaDia', 'visaOtorgadaMes', 'visaOtorgadaAnio', 'visaOtorgadaFechaGood', 'visaOtorgadaFechaBad', 'visaOtorgadaFechaMessage')==false)
			errores++;
		if(document.getElementById("visaOtorgadaDepartamento").value=='')
			errores++;
		if(document.getElementById("visaOtorgadaTipo").value=='')
			errores++;
	}
	if (document.getElementById("visaNegadaSi").checked){
		if(validarFechaGen('visaNegadaDia', 'visaNegadaMes', 'visaNegadaAnio', 'visaNegadaFechaGood', 'visaNegadaFechaBad', 'visaNegadaFechaMessage')==false)
			errores++;
		if(document.getElementById("visaNegadaDepartamento").value=='')
			errores++;
		if(document.getElementById("visaNegadaTipo").value=='')
			errores++;
	}
	if (document.getElementById("visaQuienSi").checked){
		if(document.getElementById("visaQuienNombre").value=='')
			errores++;
	}
	if (guardar==true){
		if (errores>0){
			hayErrores(1);
		}
		else{
			document.myForm6.submit();
		}
	}
	else{
		return errores;
	}
}
function validForm7(guardar){
	var errores=0;
	if (document.getElementById("esposaSi").checked==false && document.getElementById("esposaNo").checked==false){
		errores++;
	}
	if (document.getElementById("noviaSi").checked==false && document.getElementById("noviaNo").checked==false){
		errores++;
	}
	if (document.getElementById("madreSi").checked==false && document.getElementById("madreNo").checked==false){
		errores++;
	}
	if (document.getElementById("hijaSi").checked==false && document.getElementById("hijaNo").checked==false){
		errores++;
	}
	if (document.getElementById("hermanaSi").checked==false && document.getElementById("hermanaNo").checked==false){
		errores++;
	}
	if (document.getElementById("esposaSi").checked){
		if (document.getElementById("esposaCual").value==""){
			errores++;
		}
		if (document.getElementById("esposaCondicion").value==""){
			errores++;
		}
	}
	if (document.getElementById("noviaSi").checked){
		if (document.getElementById("noviaCual").value==""){
			errores++;
		}
		if (document.getElementById("noviaCondicion").value==""){
			errores++;
		}
	}
	if (document.getElementById("madreSi").checked){
		if (document.getElementById("madreCual").value==""){
			errores++;
		}
		if (document.getElementById("madreCondicion").value==""){
			errores++;
		}
	}
	if (document.getElementById("hijaSi").checked){
		if (document.getElementById("hijaCual").value==""){
			errores++;
		}
		if (document.getElementById("hijaCondicion").value==""){
			errores++;
		}
	}
	if (document.getElementById("hermanaSi").checked){
		if (document.getElementById("hermanaCual").value==""){
			errores++;
		}
		if (document.getElementById("hermanaCondicion").value==""){
			errores++;
		}
	}
	if (guardar==true){
		if (errores>0){
			hayErrores(1);
		}
		else{
			document.myForm7.submit();
		}
	}
	else{
		return errores;
	}
}
function validForm8(guardar){
	var errores=0;
	if (document.getElementById("arrestadoSi").checked==false && document.getElementById("arrestadoNo").checked==false){
		errores++;
	}
	if (document.getElementById("fraudeSi").checked==false && document.getElementById("fraudeNo").checked==false){
		errores++;
	}
	if (document.getElementById("terroristaSi").checked==false && document.getElementById("terroristaNo").checked==false){
		errores++;
	}
	if (document.getElementById("deportadoSi").checked==false && document.getElementById("deportadoNo").checked==false){
		errores++;
	}
	if (document.getElementById("custodiaSi").checked==false && document.getElementById("custodiaNo").checked==false){
		errores++;
	}
	if (document.getElementById("enfermedadSi").checked==false && document.getElementById("enfermedadNo").checked==false){
		errores++;
	}
	if(guardar==true){
		if (errores>0){
			hayErrores(1);
		}
		else{
			document.myForm8.submit();
		}
	}
	else{
		return errores;
	}
}
function validarFechaGen(Dia, Mes, Anio, Good, Bad, Message, display){
	var dia=document.getElementById(Dia).value;
	var mes=document.getElementById(Mes).value;
	var anio=document.getElementById(Anio).value;
	var respuesta=true;
	if (isNaN(dia))	dia="32";
	if (isNaN(mes))	mes="14";
	if (isNaN(anio))	anio="1";
	
	var fecha=anio+addZero(mes)+addZero(dia);
	if (validarFecha(dia, mes, anio)==1 || fecha>currentDate){
		if (display==1)
			fechaGen(1, Good, Bad, Message);
		respuesta=false;
	}
	else{
		if (display==1)
			fechaGen(0, Good, Bad, Message);
		respuesta=true;
	}
	return respuesta;
}
function fechaGen(bandera, Good, Bad, Message){
	if (bandera==1){
		document.getElementById(Bad).className="display";
		document.getElementById(Good).className="oculto";
		document.getElementById(Message).className="txtMessage";
	}
	else{
		document.getElementById(Bad).className="oculto";
		document.getElementById(Good).className="display";
		document.getElementById(Message).className="oculto";
	}
}
function validarFechaEmision(dia, mes, anio, display){
	var respuesta=true;
	if (isNaN(dia))	dia="32";
	if (isNaN(mes))	mes="14";
	if (isNaN(anio))	anio="1";
	
	var fecha=anio+addZero(mes)+addZero(dia);
	if (validarFecha(dia, mes, anio)==1 || fecha>currentDate){
		if (display==1){
			fechaEmision(1);
		}
		respuesta=false;
	}
	else{
		if (display==1){
			fechaEmision(0);
		}
		respuesta=true;
	}
	return respuesta;
}
function fechaEmision(bandera){
	if (bandera==1){
		document.getElementById('pasaporteEmisionBad').className="display";
		document.getElementById('pasaporteEmisionGood').className="oculto";
		document.getElementById('pasaporteEmisionMessage').className="txtMessage";
	}
	else{
		document.getElementById('pasaporteEmisionBad').className="oculto";
		document.getElementById('pasaporteEmisionGood').className="display";
		document.getElementById('pasaporteEmisionMessage').className="oculto";
	}
}
function validarFechaExpiracion(dia, mes, anio, display){
	var respuesta=true;
	if (isNaN(dia))	dia="32";
	if (isNaN(mes))	mes="14";
	if (isNaN(anio))	anio="1";
	var fecha=anio+addZero(mes)+addZero(dia);
	if (validarFecha(dia, mes, anio)==1 || fecha<currentDate){
		if (display==1){
			fechaExpiracion(1);
		}
		respuesta=false;
	}
	else{
		if (display==1){
			fechaExpiracion(0);
		}
		respuesta=true;
	}
	return respuesta;
}
function fechaExpiracion(bandera){
	if (bandera==1){
		document.getElementById('pasaporteExpiracionBad').className="display";
		document.getElementById('pasaporteExpiracionGood').className="oculto";
		document.getElementById('pasaporteExpiracionMessage').className="txtMessage";
	}
	else{
		document.getElementById('pasaporteExpiracionBad').className="oculto";
		document.getElementById('pasaporteExpiracionGood').className="display";
		document.getElementById('pasaporteExpiracionMessage').className="oculto";
	}
}
function validarFechaViaje(dia, mes, anio, display){
	var respuesta=true;
	if (isNaN(dia))	dia="32";
	if (isNaN(mes))	mes="14";
	if (isNaN(anio))	anio="1";
	var fecha=anio+addZero(mes)+addZero(dia);
	if (validarFecha(dia, mes, anio)==1 || fecha<currentDate){
		if (display==1){
			fechaViaje(1);
		}
		respuesta=false;
	}
	else{
		if (display==1){
			fechaViaje(0);
		}
		respuesta=true;
	}
	return respuesta;
}
function fechaViaje(bandera){
	if (bandera==1){
		document.getElementById('viajeBad').className="display";
		document.getElementById('viajeGood').className="oculto";
		document.getElementById('viajeMessage').className="txtMessage";
	}
	else{
		document.getElementById('viajeBad').className="oculto";
		document.getElementById('viajeGood').className="display";
		document.getElementById('viajeMessage').className="oculto";
	}
}
function validarFechaNac(anio, mes, dia, display){
	var respuesta=true;
	if (isNaN(dia))	dia="32";
	if (isNaN(mes))	mes="14";
	if (isNaN(anio)) anio="1";
	
	var fecha=anio+addZero(mes)+addZero(dia);
	if (validarFecha(dia, mes, anio)==1 || fecha>=currentDate){
		if (display==1)
			fechaNac(1);
		respuesta=false;
	}
	else{
		if (display==1)
			fechaNac(0);
		respuesta=true;
	}
	return respuesta;
}
function fechaNac(bandera){
	if (bandera==1){
		document.getElementById('cedulaNacBad').className="display";
		document.getElementById('cedulaNacGood').className="oculto";
		document.getElementById('cedulaNacMessage').className="txtMessage";
	}
	else{
		document.getElementById('cedulaNacBad').className="oculto";
		document.getElementById('cedulaNacGood').className="display";
		document.getElementById('cedulaNacMessage').className="oculto";
	}
}
function validarFechaHijo(dia, mes, anio){
	var respuesta=true;
	if (isNaN(dia))	dia="32";
	if (isNaN(mes))	mes="14";
	if (isNaN(anio))	anio="1";
	
	var fecha=anio+addZero(mes)+addZero(dia);
	if (validarFecha(dia, mes, anio)==1 || fecha>currentDate){
		fechaHijo(1);
		respuesta=false;
	}
	else{
		fechaHijo(0);
		respuesta=true;
	}
	return respuesta;
}
function fechaHijo(bandera){
	if (bandera==1){
		document.getElementById('hijoNacBad').className="display";
		document.getElementById('hijoNacGood').className="oculto";
		document.getElementById('hijoNacMessage').className="txtMessage";
	}
	else{
		document.getElementById('hijoNacBad').className="oculto";
		document.getElementById('hijoNacGood').className="display";
		document.getElementById('hijoNacMessage').className="oculto";
	}
}
function addZero(value){
	var valor=Number(value);
	if (valor<10)
		return "0"+valor;
	else
		return valor;
}
/***********************************************************************************************
 Funcion adaptada a partir del codigo publicado en:
 http://www.todoexpertos.com/categorias/tecnologia-e-internet/desarrollo-de-sitios-web/javascript/respuestas/370695/validar-fechas-en-javascript
 Agradecimientos a su autor...
************************************************************************************************/

function validarFecha(dia,mes,anio)
{
	var elAnio=parseInt(anio);
	if (elAnio<1900)
		return 1;
	var elMes = parseInt(mes);

	if(elMes>12)
		return 1;
			// MES FEBRERO
	if(elMes == 2){
		if(esBisiesto(anio)){
			if(parseInt(dia) > 29){
				return 1;
			}
		else
			return 0;
		}
		else{
			if(parseInt(dia) > 28){
				return 1;
			}
			else
				return 0;
		}
	}
	//RESTO DE MESES

	if(elMes== 4 || elMes==6 || elMes==9 || elMes==11){
		if(parseInt(dia) > 30){
			return 1;
		}
	}
	if (elMes==1 || elMes==3 || elMes==5 || elMes==7 || elMes==8 || elMes==10 || elMes==12){
		if(parseInt(dia) > 31){
			return 1;
		}
	}
	return 0;
}
function setDias(Mes,idTarget){
	//var target=document.getElementById(idTarget);
	var mes=Number(Mes);
	var dias=0;
	$("#"+idTarget).empty();
	if (mes == "1" || mes == "3" || mes == "5" || mes == "7" || mes == "8" || mes == "10" || mes == "12") {
		dias=31;
	}
	if (mes == "4" || mes == "6" || mes == "9" || mes == "11") {
		dias=30;
	}
	if (mes=="2" && (currentYear%4==0)){
		dias=29;
	}
	else if (mes=="2"){
		dias=28;
	}
	$("#"+idTarget).append('<option value="">D&iacute;a</option>');
	for (var i=1; i<=dias; i++){
		$("#"+idTarget).append('<option value="'+i+'">'+i+'</option>');
	}
}
function initAnios(idBase,idTarget){
	var base=document.getElementById(idBase).value;
	var target=document.getElementById(idTarget);
	var inicio=Number(base)-100;
	var fin=Number(base);
	for (var i=target.length; i>=0; i--){
		target.options[i]=null;
	}
	target[target.options.length]=new Option("A&ntilde;o","A");
	for (var i=fin; i>=inicio; i--){
		target[target.options.length]=new Option(i,i);
	}
}
function initAniosForward(idBase,idTarget){
	var base=document.getElementById(idBase).value;
	var target=document.getElementById(idTarget);
	var inicio=Number(base);
	var fin=Number(base)+10;
	for (var i=target.length; i>=0; i--){
		target.options[i]=null;
	}
	target[target.options.length]=new Option("A&ntilde;o","A");
	for (var i=fin; i>=inicio; i--){
		target[target.options.length]=new Option(i,i);
	}
}
//*****************************************************************************************
// esBisiesto(anio)
//
// Determina si el a�o pasado com par�metro es o no bisiesto
//*****************************************************************************************
function esBisiesto(anio)
{
var BISIESTO;
if(parseInt(anio)%4==0){
if(parseInt(anio)%100==0){
if(parseInt(anio)%400==0){
BISIESTO=true;
}
else{
BISIESTO=false;
}
}
else{
BISIESTO=true;
}
}
else
BISIESTO=false;

return BISIESTO;
} 