function ltrim(s) {     return s.replace(/^\s+/, ""); }  
function rtrim(s) {     return s.replace(/\s+$/, ""); }  
function trim(s) {     return rtrim(ltrim(s)); }
var ventanaCalendario=false;
var expresion0 = "[\'\@\.\,\*\+\|\^\$\?\{\(\[]";
var expresion1 = "[\'\@\ \.\,\*\+\|\^\$\?\{\(\[]";
var expresion2 = "[0-9]";
var expresion3 = "[a-z]|[A-Z]|ñ|Ñ";
var expresion4 = "[\á\é\í\ó\ú\Á\É\Í\Ó\Ú]";

var exp0 = new RegExp(expresion0);
var exp1 = new RegExp(expresion1);
var exp2 = new RegExp(expresion2);
var exp3 = new RegExp(expresion3);
var exp4 = new RegExp(expresion4);
var exp5 = new RegExp(/^\d+$/); //acepta solo numeros sin signos
function GeneralVeriPhone(tel1,tel2,tel3){
	res = "";
	tel1 = trim(tel1); tel2 = trim(tel2); tel3 = trim(tel3);
	if( tel1.length==0 && tel2.length==0 && tel3.length==0 ){ res="vacio"; 
	}else{
		if( exp5.test(tel1) && exp5.test(tel2) && exp5.test(tel3) ){
			if( tel1.length==3 && tel2.length==3 && tel3.length==4 ){ res="ok"; }else{ res="incompleto"; }
		}else{
			res="invalido"; 
		}
	}
	return res;
}

function verContador(){
	estado = window.document.getElementById("frameconta").style.display;
	if( estado=="none" ){
		window.document.getElementById("frameconta").style.display = "block";
	}else{
		window.document.getElementById("frameconta").style.display = "none";
	}
}

function verInfo(fpag){
	window.document.getElementById("op1").style.display = "none";
	window.document.getElementById("op2").style.display = "none";
	window.document.getElementById("op3").style.display = "none";
	window.document.getElementById("op4").style.display = "none";
	
	window.document.getElementById(fpag).style.display = "block";
}

function escogido(jscodigo,jsserie){
	window.location = "tours_a_europa_"+jscodigo+"_clase_"+jsserie+"_europa.htm";
}

function escogidoH(listado){
	window.location = "sudamerica_hoteles_hotel.php?codigo=" + listado;
}

function FSfncValidateEmailAddress (FormField,CheckTLD) {
	// CheckTLD es opcionalis optional, acepta los valores true, false, y null.
	emailStr = FormField.value.toLowerCase()
	if (CheckTLD==null) {CheckTLD=true}
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {alert(FormField.name + " parece ser incorrecta (Compruebe arroba (@) y puntos (.))"); FormField.focus(); FormField.focus(); return false}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {if (user.charCodeAt(i)>127) {alert(FormField.title + ": nombre de usuario contiene caracteres inválidos"); return false}}
	for (i=0; i<domain.length; i++) {if (domain.charCodeAt(i)>127) {alert(FormField.title + ": nombre de dominio contiene caracteres inválidos"); FormField.focus(); return false}}
	if (user.match(userPat)==null) {alert(FormField.title + ": nombre de usuario no es válido."); FormField.focus(); return false}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {for (var i=1;i<=4;i++) {if (IPArray[i]>255) {alert(FormField.title + ": dirección IP no es válida"); FormField.focus(); return false}}; return true}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	var knownDomsPat = "com net biz";
	for (i=0;i<len;i++) {if (domArr[i].search(atomPat)==-1) {alert(FormField.name + ": nombre de dominio no es válido."); FormField.focus(); return false}}
	if ((CheckTLD) && (domArr[domArr.length-1].length!=2) && (domArr[domArr.length-1].search(knownDomsPat)==-1)) {alert(FormField.title + ": debe terminar en dominio bien conocido o país de dos letras."); FormField.focus(); return false}
	if (len<2) {alert(FormField.title + ": le falta un nombre de anfitrión"); FormField.focus(); return false}
	return true;
}

function valEmail(FormField,CheckTLD) {
	emailStr = FormField.toLowerCase();
	if( emailStr=="" ){ return "vacio"; 
	}else{
		if (CheckTLD==null) {CheckTLD=true}
		var emailPat=/^(.+)@(.+)$/;
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+';
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		var matchArray=emailStr.match(emailPat);
		if (matchArray==null) { return "incorrecto"; }
		var user=matchArray[1];
		var domain=matchArray[2];
		for (i=0; i<user.length; i++){ if(user.charCodeAt(i)>127){ return "invalido"; } }
		for (i=0; i<domain.length; i++){ if(domain.charCodeAt(i)>127){ return "invalido"; } }
		if (user.match(userPat)==null){ return "invalido.\n"; }
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null){ for(var i=1;i<=4;i++){ if(IPArray[i]>255){ return "invalido"; } }; return "ok"; }
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		var knownDomsPat = "com net biz";
		for (i=0;i<len;i++){ if(domArr[i].search(atomPat)==-1){ return "invalido"; } }
		if ((CheckTLD) && (domArr[domArr.length-1].length!=2) && (domArr[domArr.length-1].search(knownDomsPat)==-1)){ return "invalido"; }
		if (len<2){ return "incompleto"; }
	}
	return "ok";
}


function abrirVentana(pagina,titulo){
	ancho = "350";
	alto = "250";
	switch(titulo){
	case "SUGERENCIAS": ancho="400"; alto="400"; break;
	case "Suplementos": ancho="500"; alto="600"; break;
	case "CardDocument": ancho="700"; alto="500"; break;
	case "RESERVACIONES": ancho="400"; alto="330"; break;
	case "Presupuesto": ancho="650"; alto="600"; break;
	case "Aerolinea": ancho="650"; alto="600"; break;
	case "publicidad": ancho="780"; alto="700"; break;
	case "tickets": ancho="400"; alto="350"; break;
	case "info": ancho="465"; alto="402"; break;
	case "Condiciones": ancho="550"; alto="470"; break;
	case "Pension": ancho="700"; alto="500"; break;
	}
	ventana = window.open(pagina,titulo,'scrollbars=yes,resizable=yes,width='+ancho+',height='+alto+',status=no,location=no,toolbar=no');
}
function validarSugerencia(){
	msn = "";
	campo1 = window.document.frm.nombre.value;
	campo2 = window.document.frm.email.value;
	campo3 = window.document.frm.texto.value;
	campo4 = window.document.frm.area.value;
	campo5 = window.document.frm.telepri.value;
	campo6 = window.document.frm.telefono.value;
	campo7 = window.document.frm.pais.value;
	campo8 = window.document.frm.ciudad.value;
	if(campo1!=""){ 
			var expresion = "[0-9]|[\.\,\*\+\|\^\$\?\{\(\[]";
			var expresion2 = "[a-z]|[A-Z]|ñ|Ñ";
			var exp1 = new RegExp(expresion);
			var exp2 = new RegExp(expresion2);
			if( exp1.test(campo1) ){ msn+="- Campo Nombre debe contener solo letras.\n"; }
	}else{ msn+="- Campo Nombre esta vacio.\n"; }
	if(campo2!=""){
		if (!FSfncValidateEmailAddress(window.document.frm.email,false)){ 
			msn+="- Campo Email no es valido.\n"; 
		}
	}else{ msn+="- Campo Email esta vacio.\n"; }
	
	msnTel = GeneralVeriPhone(campo4,campo5,campo6);
	if( msnTel!="ok" ){ msn+="- Campo Telefono "+msnTel+".\n"; }
	
	if(campo3==""){ msn+="- Campo Comentario esta vacio.\n"; }
	
	if(campo7==""){ msn+="- Campo Pais esta vacio.\n"; }
	
	if(campo8==""){ msn+="- Campo Ciudad esta vacio.\n"; }
	
	if( msn=="" ){ 
		window.document.frm.submit(); 
	}else{ alert(msn); }
}

function muestraCalendario(raiz,formulario_destino,campo_destino,mes_destino,ano_destino){
	//funcion para abrir una ventana con un calendario.
	//Se deben indicar los datos del formulario y campos que se desean editar con el calendario, es decir, los campos donde va la fecha.
	if (typeof ventanaCalendario.document == "object") {
		ventanaCalendario.close()
	}
	ventanaCalendario = window.open("calendario/index.php?formulario=" + formulario_destino + "&nomcampo=" + campo_destino,"calendario","width=300,height=300,left=100,top=100,scrollbars=no,menubars=no,statusbar=NO,status=NO,resizable=YES,location=NO")
}

function formReservas(){
	msn = "";
	campo1 = window.document.getElementById("cliente").value;
	campo2 = window.document.getElementById("email").value;
	campo3 = window.document.getElementById("area").value;
	campo4 = window.document.getElementById("telepri").value;
	campo5 = window.document.getElementById("telefono").value;

	if( campo1=="" ){ msn+="- Nombre vacio.\n"; }else{ 
		if( exp0.test(campo1) || exp2.test(campo1) ){ msn+="- Nombre incorrecto.\n";  }
	}
	if(campo2==""){ msn+="- Email vacio.\n"; }else{
		if( !FSfncValidateEmailAddress(window.document.getElementById("email"),false) ){ msn+="- Email incorrecto.\n"; }
	}
	msnTel = GeneralVeriPhone(campo3,campo4,campo5);
	if( msnTel!="ok" ){ msn+="- Telefono "+msnTel+".\n"; }

	if( msn!="" ){ alert(msn); }else{ window.document.form1.submit(); }
	

}
function busqueda(clase){
	fVariables = "";
	veri1 = "no";
	if(clase=="pais"){
		cliEscojidos = "";
		for(var i=0;i < document.forms[0].elements.length;i++){
			var elemento = document.forms[0].elements[i];
			if(elemento.type == "checkbox" && elemento.checked){
				if( cliEscojidos!="" ){ cliEscojidos = cliEscojidos + " - " + elemento.value;
				}else{ cliEscojidos = elemento.value; }
			}
		}
		if( cliEscojidos!="" ){
			window.document.form1.frEscojidos.value = cliEscojidos;
			window.document.form1.frclase.value="pais"; 
			fVariables = "frEscojidos="+cliEscojidos+"&frclase=pais";
		}else{ alert("Por Favor elija algun pais.\nGracias!"); }
	}
	if( clase=="dias" ){
		campo4 = window.document.form1.tourdias1.value*1;
		campo5 = window.document.form1.tourdias2.value*1;
		if(campo4<=campo5){ veri1="ok"; 
		}else{ alert("el 1er Numero de dias debe ser menor o igual al segundo."); }
		if(veri1=="ok"){ 
			window.document.form1.frclase.value="dias"; 
			fVariables = "tourdias1="+campo4+"&tourdias2="+campo5+"&frclase=dias";
		}
	}
	if( clase=="otros" ){
		jsotros = window.document.form1.frotros.value;
		if( jsotros!="" ){ 
			window.document.form1.frclase.value="palabras"; 
			fVariables = "frotros="+jsotros+"&frclase=palabras";
		}else{ alert("Por favor escriba una o varias ciudades separados por comas."); }
	}
	if( clase=="varios" ){ 
		cliEscojidos = "";
		for(var i=0;i < document.forms[0].elements.length;i++){
			var elemento = document.forms[0].elements[i];
			if(elemento.type == "checkbox" && elemento.checked){
				if( cliEscojidos!="" ){ cliEscojidos = cliEscojidos + " - " + elemento.value;
				}else{ cliEscojidos = elemento.value; }
			}
		}
		if( cliEscojidos!="" ){
			window.document.form1.frEscojidos.value = cliEscojidos;
		}
		campo4 = window.document.form1.tourdias1.value*1;
		campo5 = window.document.form1.tourdias2.value*1;
		jsotros = window.document.form1.frotros.value;
		window.document.form1.frclase.value="varios"; 
		fVariables = "frEscojidos="+cliEscojidos+"&tourdias1="+campo4+"&tourdias2="+campo5+"&frotros="+jsotros+"&frclase=varios";
	}
	procesar("busquedaResul","nuevo=si&"+fVariables,"resultado");
}
function openHotel(codigo,tipo){
	str = "hotel.php?codigo="+codigo+"&tipo="+tipo;
	ventana = window.open(str,'Hotel','scrollbars=yes,resizable=yes,width=350,height=400,status=no,location=no,toolbar=no');

}
function openMap(nombre){
	ventana = window.open('','Hotel','scrollbars=yes,resizable=yes,width=400,height=400,status=no,location=no,toolbar=no');
	ventana.document.write("<img src='../utilitarios/imagenes_hoteles/%22+nombre+%22.gif' border=0>");
}
function borrarTexto(obj){
	if(obj.value=="enter your e-mail"){
		obj.value="";
	}
}
function ponerTexto(obj){
	if(obj.value==""){
		obj.value="enter your e-mail";
	}
}
function seleccionar_todos(chknox){
	for(var i=0;i < document.forms[0].elements.length;i++){
		var elemento = document.forms[0].elements[i];
		if(elemento.type == "checkbox"){
			elemento.checked = chknox.checked;
		}
	}
}

function verPelis(){
	verFlash("cabecera.swf","cabe","773","156","#000000","cabecera");
	verFlash("ejemplo.swf","mP","164","290","#DCB894","mPrincipal");
	verFlash("logo.swf","ml","164","87","#000000","mlogo");
	verFlash("menu-horizontal.swf","mH","606","24","#000000","mHorizontal");
	verFlash("mapamundi.swf","mapa","469","288","#ffffff","mapamundi");
}
function verifNum(e){
	var keynum;
	var keychar;
	if(window.event){ 
		keynum = e.keyCode;
		if( (keynum >= 48 && keynum <= 57) || keynum==8 ){ 
		}else{ event.returnValue = false; }
	}else if(e.which){ 
		keynum = e.which;
		if( (keynum >= 48 && keynum <= 57) || keynum==8 ){ 
		}else{ return false; }
	} 
}