function submitForm(lang)
 { 	
 	var Msg_Checkin 			= lang == 1 ? "Selecione Fecha Ingreso" : "Choose Check in";
 	var Msg_Checkout 			= lang == 1 ? "Selecione Fecha Salida" : "Choose Check out";
 	var Msg_val_date 			= lang == 1 ? "Verifique el formato de la fecha" : "Verify date format";
 	var Msg_rooms	  			= lang == 1 ? "Seleccione numero de cuartos" : "Choose number of rooms";
 	var Msg_guests	  			= lang == 1 ? "Seleccione numero de invitados" : "Choose number of guests";
 	var Msg_Adults				= lang == 1 ? "Ingrese el numero de adultos" : "Write the number of adults";
 	var Msg_Children 			= lang == 1 ? "Ingrese el numero de niños" : "Write the number of children";
 	var Msg_Adults_ninos_sum	= lang == 1 ? "La sumatoria de el Nro. de adultos y niños no es igual al total de pasajeros" : "Sumatoria of the Nro. of adults and children he is not equal to the total of passengers";
 	var Msg_npasajeros 			= lang == 1 ? "Ingrese el numero de pasajeros en adultos o niños" : "Write number of passengers in adults or children";
 	var Msg_Comentario 			= lang == 1 ? "Ingrese su comentario" : "Write comment";

 	var Msg_FirstName  			= lang == 1 ? "Ingrese su nombre" : "Write name";
 	var Msg_LastName 			= lang == 1 ? "Ingrese su apellido" : "Write Lastname";
 	var Msg_Country 			= lang == 1 ? "Elija su páis" : "Select country";
 	var Msg_City 				= lang == 1 ? "Ingrese la ciudad" : "Write city";	
 	var Msg_Phone 				= lang == 1 ? "Ingrese su telefono" : "Write phone";
 	var Msg_Email	  			= lang == 1 ? "Ingrese su E-mail" : "Write E-mail";
 	var Msg_HowDidYouFindUs 	= lang == 1 ? "Escoja opción en Cómo nos encontró" : "Choose option in How Did You Find Us?";
 	var Msg_HowDidYouFindUs2	= lang == 1 ? "Cómo nos encontró" : "How Did You Find Us?";
 	var Msg_InvalidEmail		= lang == 1 ? "E-mail invalido" : "Invalid E-mail";
 
	xdia1  = document.getElementById('ho_TxtDia1').options[document.getElementById('ho_TxtDia1').selectedIndex].value;
	xmes1  = document.getElementById('ho_TxtMes1').options[document.getElementById('ho_TxtMes1').selectedIndex].value;
	xanio1 = document.getElementById('ho_TxtAnio1').options[document.getElementById('ho_TxtAnio1').selectedIndex].value;

	xdia2  = document.getElementById('ho_TxtDia2').options[document.getElementById('ho_TxtDia2').selectedIndex].value;
	xmes2  = document.getElementById('ho_TxtMes2').options[document.getElementById('ho_TxtMes2').selectedIndex].value;
	xanio2 = document.getElementById('ho_TxtAnio2').options[document.getElementById('ho_TxtAnio2').selectedIndex].value;

	
	if (xdia1 == "00" || xmes1 == "00" || xanio1 == "0000")
	{
		window.alert(Msg_Checkin);
		document.getElementById('ho_TxtDia1').focus();
		return;
	}

	if (consisfec(xdia1 , xmes1, xanio1) == false)
	{ 
		window.alert(Msg_val_date);
		document.getElementById('ho_TxtDia1').focus();
		return;
	}
	
	if (xdia2 == "00" || xmes2 == "00" || xanio2 == "0000")
	{
		window.alert(Msg_Checkout);
		document.getElementById('ho_TxtDia2').focus();
		return;
	}

	if (consisfec(xdia2 , xmes2, xanio2) == false)
	{ 
		window.alert(Msg_val_date);
		document.getElementById('ho_TxtDia2').focus();
		return;
	}
	
	if(document.getElementById('ho_cuartos').selectedIndex == 0)
	{
		window.alert(Msg_rooms);
		document.getElementById('ho_cuartos').focus();
		return;
	}

	if(document.getElementById('ho_invitados').selectedIndex == 0)
	{
		window.alert(Msg_guests);
		document.getElementById('ho_invitados').focus();
		return;
	}

	var var_nro_pasajeros 		= parseInt(document.getElementById('ho_invitados').value);
	var var_nro_adultos 		= parseInt(document.getElementById('ho_adultos').value);
	var var_nro_ninos   		= parseInt(document.getElementById('ho_ninos').value);
	var tot_nro_adultos_ninos 	= var_nro_adultos + var_nro_ninos;
	
	if (tot_nro_adultos_ninos != var_nro_pasajeros)
	{
		window.alert(Msg_Adults_ninos_sum);
		document.getElementById('ho_invitados').focus();
		return;
	}
	
	if(trim(document.getElementById('ho_nombre').value)=='')
	{
		window.alert(Msg_FirstName);
		document.getElementById('ho_nombre').focus();
		return;
	}

	if(trim(document.getElementById('ho_apellido').value)=='')
	{
		window.alert(Msg_LastName);
		document.getElementById('ho_apellido').focus();
		return;
	}

	if(trim(document.getElementById('ho_pais').value)=='')
	{
		window.alert(Msg_Country);
		document.getElementById('ho_pais').focus();
		return;
	}

	if(trim(document.getElementById('ho_ciudad2').value)=='')
	{
		window.alert(Msg_City);
		document.getElementById('ho_ciudad2').focus();
		return;
	}
	
 	if(trim(document.getElementById('ho_telefono').value)=='')
	{
		window.alert(Msg_Phone);
		document.getElementById('ho_telefono').focus();
		return;
	}

	if(trim(document.getElementById('ho_email').value)=='')
	{
		window.alert(Msg_Email);
		document.getElementById('ho_email').focus();
		return;
	}

	if (!checkemail(trim(document.getElementById('ho_email').value )))
	{
		window.alert(Msg_InvalidEmail);
		document.getElementById('ho_email').focus();
		return;
	}

	if(trim(document.getElementById('ho_email').value)=='')
	{
		window.alert(Msg_Email);
		document.getElementById('ho_email').focus();
		return;
	}
	
	if(document.getElementById('ho_conocistes').selectedIndex == 0)
	{
		window.alert(Msg_HowDidYouFindUs);
		document.getElementById('ho_conocistes').focus();
		return;
	}
	
	if (document.getElementById("otros") != null )
	{
		var valOtros = document.getElementById("otros").value;
		if (valOtros == ' Escriba aqui ...' || valOtros == ' Write here ...' || valOtros == '')
		{
			window.alert(Msg_HowDidYouFindUs2);
			document.getElementById('otros').focus();
			return;
		}
	}
	
	var myForm = document.getElementById('myForm');
	myForm.action = 'graba_hoteles.php';
	myForm.submit();
 }
 
function clearForm()
{ 	
	document.getElementById('ho_TxtDia1').selectedIndex=0;
	document.getElementById('ho_TxtMes1').selectedIndex=0;
	document.getElementById('ho_TxtAnio1').selectedIndex=0;
	document.getElementById('ho_TxtDia2').selectedIndex=0;
	document.getElementById('ho_TxtMes2').selectedIndex=0;
	document.getElementById('ho_TxtAnio2').selectedIndex=0;
	document.getElementById('ho_cuartos').selectedIndex=0;
	document.getElementById('ho_cuartos').selectedIndex=0;
	document.getElementById('ho_invitados').selectedIndex=0;
	document.getElementById('ho_adultos').selectedIndex=0;
	document.getElementById('ho_ninos').selectedIndex=0;
	document.getElementById('ho_comentario').value='';
	document.getElementById('ho_nombre').value='';
	document.getElementById('ho_apellido').value='';
	document.getElementById('ho_pais').value='';
	document.getElementById('ho_ciudad').value='';	 	
	document.getElementById('ho_telefono').value='';
	document.getElementById('ho_email').value='';
	document.getElementById('ho_conocistes').selectedIndex = 0;
	var contenedor = document.getElementById("inputOtros");
	if (contenedor.firstChild != null ) {
		contenedor.removeChild(contenedor.firstChild);
	}
}
  
function ltrim(str)
{
	while(""+str.charAt(0)==" "){
		str=str.substring(1,str.length);}
	return str; 
}

function reverse(str)
	{
	var reversedstr = "";
	var strArray;
	strArray = str.split("");
	for(var i = str.length -1 ; i >= 0 ; i--)
	{
		reversedstr += strArray[i];
	}
	return reversedstr;
}

function trim(str)
{
	str = ltrim(str);
	str = reverse(str);
	str = ltrim(str);
	str = reverse(str);
	return str; 
}

function checkemail(str)
{
	var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	return (filter.test(str))
}

function addDynamicComboCiudad(source, obj, idioma)
{	
	var total1			= dameNrSelects();
	var numRow1 		= total1+1;
	var varTbody 		= document.createElement('tbody');
	var varTr 			= document.createElement('tr');	
	varTr.id 			= 'row_ciudad'+'_'+numRow1;
	var varTdCaption	= document.createElement('td');
	var captionLeft		= idioma == 1 ? "Destino " : "Destination ";
	var nodoTextoOption = document.createTextNode(captionLeft);
	varTdCaption.appendChild(nodoTextoOption);
	varTdCaption.className = 'arial10';
	var varTdCiudad 	= document.createElement('td');
	varTdCiudad.align   = "center"; 
    var varTdDelete 	= document.createElement('td');    
    var varImg 			= document.createElement('img');
    varImg.src 			= 'images/publish_x.png';
    varImg.border 		= 0;
    varImg.title 		= 'Eliminar esta Fila';
	var varHref 		= document.createElement('a');
	varHref.href		= 'javascript:;';
	varHref.onclick 	= function(){delURL(varTr, idioma);};
	varHref.appendChild(varImg);
	varTdDelete.appendChild(varHref);	
	var varSelect 		= document.createElement("select");
	var selectName  	= 'ciudad' + numRow1;
	varSelect.id 		= selectName;
	varSelect.name 		= selectName;
	varSelect.onchange 	= function(){addDynamicComboCiudad('ciudades',this, idioma)};
	var varOption   	= document.createElement("option");
	var nodoTextoOption = idioma == 1 ? document.createTextNode("[ Selecione ]") : document.createTextNode("[ Choose ]");

	varOption.appendChild(nodoTextoOption);
 	varSelect.appendChild(varOption);
    source = eval(source);
    
    for (x in source) {
		var varOption = document.createElement("option");
  	    var nodoTextoOption = document.createTextNode(source[x][2]) ;
  	    varOption.appendChild(nodoTextoOption);
	    varSelect.appendChild(varOption);
    }
    
	varTdCiudad.appendChild(varSelect);	
	varTr.appendChild(varTdCaption);
	varTr.appendChild(varTdCiudad);
	varTr.appendChild(varTdDelete);

	if(total1 == 0) {
		document.getElementById("ciudad").appendChild(varTr);
	} else {
		var id =obj.id.substr(obj.id.lastIndexOf("d")+1, obj.id.length);
		if (total1 == id) {
			document.getElementById("ciudad").appendChild(varTr);
		}
	}
}

function delURL(obj, idioma)
{
	var id = parseInt(obj.id.substr(obj.id.lastIndexOf("_")+1, obj.id.length));
	var total1 = dameNrSelects();

	if (total1 == 1) {
		if (idioma == 1) {
			alert('No puede eliminar todos las destinos');
			return;
		} else {
			alert('you cant not delete all the destinies');
			return;
		}
		addDynamicComboCiudad('ciudades', '', idioma)
	}
	
	obj.parentNode.removeChild(obj);

	while (id < total1) {
		var id = id+1;
		var varIdReplace = id-1;
 		document.getElementById("ciudad" + id).name =  "ciudad" + varIdReplace;
 		document.getElementById("ciudad" + id).id = "ciudad" + varIdReplace;
 		document.getElementById('row_ciudad_'+id).id = "row_ciudad_" + varIdReplace;
	}
}

function dameNrSelects()
{
	var total1=0;
	var varSelects = document.getElementsByTagName('select');
	for (var i=0; i<varSelects.length;i++) {
		var end = varSelects[i].id.lastIndexOf("d");
		if (varSelects[i].id.substr(0, end + 1)=="ciudad") {
			total1 += 1;
		}
	}
	return total1;
}

function crearInputByOtros(obj, idioma)
{

	var contenedor = document.getElementById("inputOtros");
	if (contenedor.firstChild != null){
		contenedor.removeChild(contenedor.firstChild);
	}

	if (obj.selectedIndex == 6){
		var nuevoInput = document.createElement("input");
		var nombreInput= "otros";
		nuevoInput.setAttribute("type","text");
		nuevoInput.setAttribute("name", nombreInput);
		nuevoInput.setAttribute("id",nombreInput);
		nuevoInput.setAttribute("size","31");
		var msgText = idioma==1 ? ' Escriba aqui ...' : ' Write here ...';
		nuevoInput.setAttribute("value",msgText);
		nuevoInput.onfocus = function() {clearValue(nuevoInput)};
		contenedor.appendChild(nuevoInput);
	}
}

function clearValue(obj)
{
	obj.value = '';
}


var nav4 = window.Event ? true : false;
function acceptNumTelefono(evt)
{
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57, '.' = 46
	var key = nav4 ? evt.which : evt.keyCode;
//	alert(key);
	return (key <= 13 || (key >= 48 && key <= 57) || key == 91 || key == 93 || key == 40 || key == 41 || key == 45 || key == 32);
}

function consisfec(xdia,xmes,xano)
{
	var meses=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	meses[1]=((xano % 4)==0) ? 29 : 28;
	return ((xdia<=meses[xmes-1]) ? true : false );  // true -> OK     false -> KO
}

function buscarHotel(idioma)
{
	var cat = document.getElementById('ho_categoria').value;
//	alert(cat);
	var ciu = document.getElementById('ho_ciudad').value;		
	window.location.href="frm_hoteles_list.php?idioma=" + idioma + "&cat=" + cat + "&ciu=" + ciu;
}

function detalleReservarHotel(idioma, id_hotel)
{
	window.location.href="frm_hoteles_det.php?idioma=" + idioma + "&id_hotel=" + id_hotel	
}

function reservarHotel(idioma, id_hotel)
{
	window.location.href="frm_hoteles.php?idioma=" + idioma + "&id_hotel=" + id_hotel		
}