 function submitForm(lang)
 {
	var myForm = document.getElementById('myForm');
	var countChk = 0;
	var Msg_ChooseDest			= lang == 1 ? "Elija al menos un destino" : "Choose one destiny at least";
 	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 ? "Ingrese su páis" : "Choose country";
 	var Msg_City 				= lang == 1 ? "Ingrese la ciudad" : "Write ciudad";
 	var Msg_Phone 				= lang == 1 ? "Ingrese su telefono" : "Write Phone";
 	var Msg_Email	  			= lang == 1 ? "Ingrese su E-mail" : "Write E-mail";
	var Msg_InvalidEmail		= lang == 1 ? "E-mail invalido" : "Invalid 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_Typeofaccommodation = lang == 1 ? "Elija el tipo de Alojamiento" : "Choose type of accommodation";
 	var Msg_Tourguide	  		= lang == 1 ? "Elija el tipo de Servicio" : "Choose tourguide:";
 	var Msg_Month  				= lang == 1 ? "Elija el mes" : "Choose month"; 
 	var Msg_Staying				= lang == 1 ? "Elija el numero de dias" : "Choose number of days";
 	var Msg_Year  				= lang == 1 ? "Elija el año" : "Choose Year";
 	var Msg_Comentary 			= lang == 1 ? "Ingrese el comentario" : "Write commentary";
 	var Msg_npasajeros 			= lang == 1 ? "Ingrese el numero de pasajeros en adultos o niños" : "Write number of passengers in adults or children";

 	for(var i=0;i<myForm.elements.length;i++) 
	{
		if(myForm.elements[i].checked) 
			countChk+=1;
	}
	
	if(countChk == 0) 
	{
		window.alert(Msg_ChooseDest);
		document.getElementById('des1-1').focus();	
		return;
	}

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

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

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

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

 	if(trim(document.getElementById('vpd_telefono').value)=='')
	{
		window.alert(Msg_Phone);
		document.getElementById('vpd_telefono').focus();
		return;
	}
	
	if(trim(document.getElementById('vpd_correo').value)=='')
	{
		window.alert(Msg_Email);
		document.getElementById('vpd_correo').focus();
		return;
	}
	
	if (!checkemail(trim(document.getElementById('vpd_correo').value )))
	{
		window.alert(Msg_InvalidEmail);		
		document.getElementById('vpd_correo').focus();
		return;
	}
	
	if(document.getElementById('vpd_conocistes').selectedIndex == 0)
	{
		window.alert(Msg_HowDidYouFindUs);
		document.getElementById('vpd_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;
		}
	}
	
	if(document.getElementById('vpd_tipoalojamiento').selectedIndex == 0)
	{
		window.alert(Msg_Typeofaccommodation);
		document.getElementById('vpd_tipoalojamiento').focus();
		return;
	}
	 	
 	if(document.getElementById('vpd_tiposervicio').selectedIndex == 0)
	{
		window.alert(Msg_Tourguide);
		document.getElementById('vpd_tiposervicio').focus();
		return;
	}

 	if(document.getElementById('vpd_mes').selectedIndex == 0)
	{
		window.alert(Msg_Month);
		document.getElementById('vpd_mes').focus();
		return;
	}
	
 	if(document.getElementById('vpd_estadia').selectedIndex == 0)
	{
		window.alert(Msg_Staying);
		document.getElementById('vpd_estadia').focus();
		return;
	}

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

 	if(trim(document.getElementById('vpd_adultos').value)=='' && trim(document.getElementById('vpd_ninos').value)=='')
	{
		window.alert(Msg_npasajeros);
		document.getElementById('vpd_adultos').focus();
		return;
	}

	myForm.action = 'graba_viajexdetino.php';
	myForm.submit();
 }
 
function clearForm()
{
	for (i=0;i<document.forms[0].elements.length;i++) {
		if (document.forms[0].elements[i].name.substr(0,3)=='des' && document.forms[0].elements[i].type == 'checkbox') {
			document.forms[0].elements[i].checked = 0;
		}
	}
	document.getElementById('vpd_nombre').value='';
	document.getElementById('vpd_apellido').value='';
	document.getElementById('vpd_pais').value='';
	document.getElementById('vpd_ciudad').value='';	
	document.getElementById('vpd_telefono').value='';
	document.getElementById('vpd_correo').value='';
 	document.getElementById('vpd_conocistes').selectedIndex = 0;
 	var contenedor = document.getElementById("inputOtros");
	if (contenedor.firstChild != null ){contenedor.removeChild(contenedor.firstChild);}
	document.getElementById('vpd_tipoalojamiento').selectedIndex = 0;	 	
	document.getElementById('vpd_tiposervicio').selectedIndex = 0
	document.getElementById('vpd_mes').selectedIndex = 0;
	document.getElementById('vpd_estadia').selectedIndex = 0;
	document.getElementById('vpd_ano').selectedIndex = 0;
 	document.getElementById('vpd_adultos').value='';
	document.getElementById('vpd_ninos').value='';
	document.getElementById('vpd_comentario').value ='';
	document.getElementById('des1-1').focus();
}
  
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 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;
return (key <= 13 || (key >= 48 && key <= 57) || key == 91 || key == 93 || key == 40 || key == 41);
}