function submitForm(lang)
{ 	

 	
 	var Msg_DepartureCity		= lang == 1 ? "Ingrese Origen" : "Write From";
 	var Msg_DeparureDate		= lang == 1 ? "Escoja Fecha de salida" : "Select Departure Date";
 	var Msg_ArrivalCity			= lang == 1 ? "Ingrese Destino" : "Write To";
 	var Msg_ReturnDate			= lang == 1 ? "Escoja Fecha de retorno" : "Select Return Date";
 	var Msg_val_date 			= lang == 1 ? "Verifique el formato de la fecha" : "Verify date format";
 	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";
 	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_Pasajeros 			= lang == 1 ? "Escoja el numero de pasajeros" : "Choose number of passengers";
 	var Msg_Fullname 			= lang == 1 ? "Ingrese su nombre y apellido" : "Write firstname and lastname";
 	var Msg_Passportnumber		= lang == 1 ? "Ingrese el Numero de Pasaporte" : "Write Passport number";
 	
	xdia1  = document.getElementById('pa_TxtDia1').options[document.getElementById('pa_TxtDia1').selectedIndex].value;
	xmes1  = document.getElementById('pa_TxtMes1').options[document.getElementById('pa_TxtMes1').selectedIndex].value;
	xanio1 = document.getElementById('pa_TxtAnio1').options[document.getElementById('pa_TxtAnio1').selectedIndex].value;

	xdia2  = document.getElementById('pa_TxtDia2').options[document.getElementById('pa_TxtDia2').selectedIndex].value;
	xmes2  = document.getElementById('pa_TxtMes2').options[document.getElementById('pa_TxtMes2').selectedIndex].value;
	xanio2 = document.getElementById('pa_TxtAnio2').options[document.getElementById('pa_TxtAnio2').selectedIndex].value;
	
	xdia3  = document.getElementById('pa_TxtDia3').options[document.getElementById('pa_TxtDia3').selectedIndex].value;
	xmes3  = document.getElementById('pa_TxtMes3').options[document.getElementById('pa_TxtMes3').selectedIndex].value;
	xanio3 = document.getElementById('pa_TxtAnio3').options[document.getElementById('pa_TxtAnio3').selectedIndex].value;

	xdia4  = document.getElementById('pa_TxtDia4').options[document.getElementById('pa_TxtDia4').selectedIndex].value;
	xmes4  = document.getElementById('pa_TxtMes4').options[document.getElementById('pa_TxtMes4').selectedIndex].value;
	xanio4 = document.getElementById('pa_TxtAnio4').options[document.getElementById('pa_TxtAnio4').selectedIndex].value;

	xdia5  = document.getElementById('pa_TxtDia5').options[document.getElementById('pa_TxtDia5').selectedIndex].value;
	xmes5  = document.getElementById('pa_TxtMes5').options[document.getElementById('pa_TxtMes5').selectedIndex].value;
	xanio5 = document.getElementById('pa_TxtAnio5').options[document.getElementById('pa_TxtAnio5').selectedIndex].value;

	xdia6  = document.getElementById('pa_TxtDia6').options[document.getElementById('pa_TxtDia6').selectedIndex].value;
	xmes6  = document.getElementById('pa_TxtMes6').options[document.getElementById('pa_TxtMes6').selectedIndex].value;
	xanio6 = document.getElementById('pa_TxtAnio6').options[document.getElementById('pa_TxtAnio6').selectedIndex].value;
	
	if (document.getElementById("pa_opt1_1").checked == 1)
	{	
		if(trim(document.getElementById('pa_departurecity1').value)=='')
		{
			window.alert(Msg_DepartureCity);
			document.getElementById('pa_departurecity1').focus();
			return;
		}
	
		if (xdia1 == "00" || xmes1 == "00" || xanio1 == "0000")
		{
			window.alert(Msg_DeparureDate);
			document.getElementById('pa_TxtDia1').focus();
			return;
		}
	
		if (consisfec(xdia1 , xmes1, xanio1) == false)
		{ 
			window.alert(Msg_val_date);
			document.getElementById('pa_TxtDia1').focus();
			return;
		}
		
		if(trim(document.getElementById('pa_arrivalcity1').value)=='')
		{
			window.alert(Msg_ArrivalCity);
			document.getElementById('pa_arrivalcity1').focus();
			return;
		}
	
		if (xdia2 == "00" || xmes2 == "00" || xanio2 == "0000")
		{
			window.alert(Msg_ReturnDate);
			document.getElementById('pa_TxtDia2').focus();
			return;
		}
	
		if (consisfec(xdia2 , xmes2, xanio2) == false)
		{ 
			window.alert(Msg_val_date);
			document.getElementById('pa_TxtDia2').focus();
			return;
		}
	}

	if (document.getElementById('pa_opt1_2').checked == 1)
	{
		if(trim(document.getElementById('pa_departurecity2').value)=='')
		{
			window.alert(Msg_DepartureCity);
			document.getElementById('pa_departurecity2').focus();
			return;
		}
		
		if (xdia3 == "00" || xmes3 == "00" || xanio3 == "0000")
		{
			window.alert(Msg_DeparureDate);
			document.getElementById('pa_TxtDia3').focus();
			return;
		}
	
		if (consisfec(xdia3 , xmes3, xanio3) == false)
		{ 
			window.alert(Msg_val_date);
			document.getElementById('pa_TxtDia3').focus();
			return;
		}
		
		if(trim(document.getElementById('pa_arrivalcity2').value)=='')
		{
			window.alert(Msg_ArrivalCity);
			document.getElementById('pa_arrivalcity2').focus();
			return;
		}	
	}
	
	if (document.getElementById('pa_opt1_3').checked == 1)
	{
		if(trim(document.getElementById('pa_departurecity3').value)=='')
		{
			window.alert(Msg_DepartureCity);
			document.getElementById('pa_departurecity3').focus();
			return;
		}
	
		if (xdia4 == "00" || xmes4 == "00" || xanio4 == "0000")
		{
			window.alert(Msg_DeparureDate);
			document.getElementById('pa_TxtDia3').focus();
			return;
		}
	
		if (consisfec(xdia4 , xmes4, xanio4) == false)
		{ 
			window.alert(Msg_val_date);
			document.getElementById('pa_TxtDia4').focus();
			return;
		}
		
		if(trim(document.getElementById('pa_arrivalcity3').value)=='')
		{
			window.alert(Msg_ArrivalCity);
			document.getElementById('pa_arrivalcity3').focus();
			return;
		}

		
		if(trim(document.getElementById('pa_departurecity4').value)=='')
		{
			window.alert(Msg_DepartureCity);
			document.getElementById('pa_departurecity4').focus();
			return;
		}
	
		if (xdia5 == "00" || xmes5 == "00" || xanio5 == "0000")
		{
			window.alert(Msg_DeparureDate);
			document.getElementById('pa_TxtDia5').focus();
			return;
		}
	
		if (consisfec(xdia5 , xmes5, xanio5) == false)
		{ 
			window.alert(Msg_val_date);
			document.getElementById('pa_TxtDia5').focus();
			return;
		}
		
		if(trim(document.getElementById('pa_arrivalcity4').value)=='')
		{
			window.alert(Msg_ArrivalCity);
			document.getElementById('pa_arrivalcity4').focus();
			return;
		}
		if(trim(document.getElementById('pa_departurecity5').value)=='')
		{
			window.alert(Msg_DepartureCity);
			document.getElementById('pa_departurecity5').focus();
			return;
		}
	
		if (xdia6 == "00" || xmes6 == "00" || xanio6 == "0000")
		{
			window.alert(Msg_DeparureDate);
			document.getElementById('pa_TxtDia6').focus();
			return;
		}
	
		if (consisfec(xdia6 , xmes6, xanio6) == false)
		{ 
			window.alert(Msg_val_date);
			document.getElementById('pa_TxtDia6').focus();
			return;
		}
		
		if(trim(document.getElementById('pa_arrivalcity5').value)=='')
		{
			window.alert(Msg_ArrivalCity);
			document.getElementById('pa_arrivalcity5').focus();
			return;
		}
	}

	var var_nro_pasajeros 		= parseInt(document.getElementById('pa_pessengers').value);
	var var_nro_adultos 		= parseInt(document.getElementById('pa_adultos').value);
	var var_nro_ninos   		= parseInt(document.getElementById('pa_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('pa_pessengers').focus();
		return;
	}

	var nro_paajeros = document.getElementById('pa_pessengers').value;
	
 	for (t=1; t<=nro_paajeros; t++)
 	{
 		var eachNroPass = document.getElementById('pa_passportnumber'+t);
 		var eachFN 		= document.getElementById('pa_firstname'+t);
 		var eachLN 		= document.getElementById('pa_lastname'+t);
 		
 		if (trim(eachFN.value)=='')
 		{
 			if (lang==2)
 			{
	 			window.alert(' You must enter the passenger name '+t);
 			}
 			else
 			{
	 			window.alert('Debe ingresar el El Nombre del pasajero '+t); 				
 			}
 
	 		document.getElementById('pa_firstname'+t).focus();
	 		return;
 		}
 		
 		if (trim(eachLN.value)=='')
 		{
 			if (lang==2)
 			{
 				window.alert('You must enter the passenger lastname '+t);
 			}
 			else
 			{
 				window.alert('Debe ingresar el El Apellido del pasajero '+t); 				
 			}
	 		document.getElementById('pa_lastname'+t).focus();
	 		return;
 		}

 		if (trim(eachNroPass.value)=='')
 		{
 			if (lang==2)
 			{ 			
	 			window.alert('You must enter the Nº Passport '+t);
 			}
 			else
 			{
	 			window.alert('Debe ingresar el El Nº Passport '+t); 				
 			}
 			
	 		document.getElementById('pa_passportnumber'+t).focus();
	 		return;
 		}
 		
 		if (isBadNroPassport(eachNroPass))
 		{ 
 			if (lang==1)
 			{
	 			window.alert('El Nº Passport '+t+' es incorrecto. Solo aceptan numeros, letras y hasta 15 caracteres');
 			}
 			else
 			{
	 			window.alert('The Nº Passport '+t+' es invalid .  allow letters, numbers, and until 15 characteres');
 			}
 			
	 		document.getElementById('pa_passportnumber'+t).focus();
	 		return;
 		}
 	}
	
	if(trim(document.getElementById('pa_nombre').value)=='')
	{
		window.alert(Msg_FirstName);
		document.getElementById('pa_nombre').focus();
		return;
	}

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

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

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

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

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

	if(trim(document.getElementById('pa_email').value)=='')
	{
		window.alert(Msg_Email);
		document.getElementById('pa_email').focus();
		return;
	}
	
	if(document.getElementById('pa_conocistes').selectedIndex == 0)
	{
		window.alert(Msg_HowDidYouFindUs);
		document.getElementById('pa_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_pasajes.php';
	myForm.submit();
 }
 
function clearForm()
{	
	//document.getElementById('pa_opt1_1').checked =1;
	var varSelects = document.getElementsByTagName('input');

	for (var i=0; i<varSelects.length;i++)
	{
		if (varSelects[i].id.substr(0, 12) == "pa_firstname" || varSelects[i].id.substr(0, 11) == "pa_lastname" || varSelects[i].id.substr(0, 17) == "pa_passportnumber")
		{
			varSelects[i].value='';
		}
	}

	document.getElementById('pa_opt2_2').checked =1;


	document.getElementById('pa_firstname1').value='';
	document.getElementById('pa_lastname1').value='';
	document.getElementById('pa_passportnumber1').value='';
	document.getElementById('pa_pessengers').selectedIndex=0;
	document.getElementById('pa_adultos').selectedIndex=0;
	document.getElementById('pa_ninos').selectedIndex=0;
	document.getElementById('pa_departurecity3').value='';
	document.getElementById('pa_departurecity4').value='';
	document.getElementById('pa_departurecity5').value='';
	document.getElementById('pa_arrivalcity3').value='';
	document.getElementById('pa_arrivalcity4').value='';
	document.getElementById('pa_arrivalcity5').value='';
	document.getElementById('pa_departurecity2').value='';
	document.getElementById('pa_arrivalcity2').value='';
	document.getElementById('pa_departurecity1').value='';
	document.getElementById('pa_arrivalcity1').value='';
	document.getElementById('pa_TxtDia1').selectedIndex=0;
	document.getElementById('pa_TxtMes1').selectedIndex=0;
	document.getElementById('pa_TxtAnio1').selectedIndex=0;
	document.getElementById('pa_TxtDia2').selectedIndex=0;
	document.getElementById('pa_TxtMes2').selectedIndex=0;
	document.getElementById('pa_TxtAnio2').selectedIndex=0;
	
	document.getElementById('pa_TxtAnio3').selectedIndex=0;
	document.getElementById('pa_TxtMes3').selectedIndex=0;
	document.getElementById('pa_TxtDia3').selectedIndex=0;

	document.getElementById('pa_TxtAnio4').selectedIndex=0;
	document.getElementById('pa_TxtMes4').selectedIndex=0;
	document.getElementById('pa_TxtDia4').selectedIndex=0;

	document.getElementById('pa_TxtAnio5').selectedIndex=0;
	document.getElementById('pa_TxtMes5').selectedIndex=0;
	document.getElementById('pa_TxtDia5').selectedIndex=0;

	document.getElementById('pa_TxtAnio6').selectedIndex=0;
	document.getElementById('pa_TxtMes6').selectedIndex=0;
	document.getElementById('pa_TxtDia6').selectedIndex=0;	
	
	document.getElementById('pa_pessengers').value='';
	document.getElementById('pa_adultos').value='';
	document.getElementById('pa_ninos').value='';
	document.getElementById('pa_comentario').value='';
	document.getElementById('pa_nombre').value='';
	document.getElementById('pa_apellido').value='';
	document.getElementById('pa_pais').value='';
	document.getElementById('pa_ciudad').value='';	 	
	document.getElementById('pa_telefono').value='';
	document.getElementById('pa_email').value='';
	document.getElementById('pa_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;
	return (key <= 13 || (key >= 48 && key <= 57) || key == 91 || key == 93 || key == 40 || key == 41);
}

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 display_mult_dest()
{
	if (document.getElementById("pa_opt1_1").checked == 1)
	{
		document.getElementById('row_1').style.display='';
		document.getElementById('row_2').style.display='none';				
		document.getElementById('row_3').style.display='none';
		document.getElementById('row_4').style.display='none';
		document.getElementById('row_5').style.display='none';
		document.getElementById('row_add_another_city').style.display='none';
		del_rows_Multi_city_add();
	}
	else if (document.getElementById("pa_opt1_2").checked == 1)
	{
		document.getElementById('row_1').style.display='none';
		document.getElementById('row_2').style.display='';				
		document.getElementById('row_3').style.display='none';
		document.getElementById('row_4').style.display='none';
		document.getElementById('row_5').style.display='none';
		document.getElementById('row_add_another_city').style.display='none';
		del_rows_Multi_city_add();
	}
	else
	{
		document.getElementById('row_1').style.display='none';
		document.getElementById('row_2').style.display='none';
		document.getElementById('row_3').style.display='';
		document.getElementById('row_4').style.display='';
		document.getElementById('row_5').style.display='';
		document.getElementById('row_add_another_city').style.display='';
	}
}

function dameNrInputs()
{
	var total1=0;
	var varInputs = document.getElementsByTagName('input');
	for (var i=0; i<varInputs.length;i++) 
	{
		if (varInputs[i].id.substr(0, 16) == "pa_departurecity")
		{
			var index = eval(varInputs[i].id.substr(16, 1));
			if (index > 2)
			{
				var index_loop = index;
				index_loop = parseInt(index) + 1;
			}
		}
	}
	return index_loop;
}

function dameNrInputs_cons()
{
	var index_loop=0;
	var varInputs = document.getElementsByTagName('input');
	for (var i=0; i<varInputs.length;i++) 
	{
		if (varInputs[i].id.substr(0, 16) == "pa_departurecity")
		{
			var index = eval(varInputs[i].id.substr(16, 1));
			if (index > 2)
			{
				index_loop = index_loop +1;				
			}
		}
	}
	return index_loop;
}

function dameNrCombos()
{
	var total1=0;
	var varCombos = document.getElementsByTagName('select');
	for (var i=0; i<varCombos.length;i++) 
	{
		if (varCombos[i].id.substr(0, 9) == "pa_TxtDia")
		{
			total1 += 1;
		}
	}
	return total1;
}

function addAnotherFlight(idioma)
{
	var total1			= dameNrInputs();
	var total1_c		= dameNrCombos() + 1;
	var total1_lbl		= dameNrInputs_cons() + 1;
	var numRow1 		= total1;

	if (numRow1 <= 9) 
	{
		var varTrPadre		= document.createElement('tr');
		varTrPadre.id 		= 'row_'+numRow1;
	
		var varTd_Padre		= document.createElement('td');
		varTd_Padre.height 	= "27";
		varTd_Padre.align 	= "center";
	
		var varTbl_main		= document.createElement('table');
		varTbl_main.width	= "526";
		varTbl_main.border 	= "0";
	
		var varTbody_main	= document.createElement('tbody');
	
		var varTr1_main		= document.createElement('tr');
	
			var varTd1_Tr1_main			= document.createElement('td');
			varTd1_Tr1_main.width 		= "12";
			varTd1_Tr1_main.align 		= "left";
			var varImg 					= document.createElement('img');
			varImg.src 					= "images/spacer.gif";
			varImg.width 				= "12";
			varImg.height				= "10";
			varTd1_Tr1_main.appendChild(varImg);
	
			var varTd2_Tr1_main			= document.createElement('td');
			varTd2_Tr1_main.className 	= "arial10 padright15";
			varTd2_Tr1_main.align 		= "left";
			var varb					= document.createElement('b');
			var text_blank 				= "";
			var nodoTextoOption 		= document.createTextNode(text_blank);
			varTd2_Tr1_main.appendChild(varb);
	
			var varTd3_Tr1_main			= document.createElement('td');
			varTd3_Tr1_main.width 		= "164";
			varTd3_Tr1_main.align 		= "left";
			var text_blank 				= "";
			var nodoTextoOption 		= document.createTextNode(text_blank);
			varTd3_Tr1_main.appendChild(nodoTextoOption);
	
		var varTr2_main	= document.createElement('tr');
		
			var varTd1_Tr2_main			= document.createElement('td');
			varTd1_Tr2_main.width 		= "12";
			varTd1_Tr2_main.align 		= "left";
			var varImg					= document.createElement('img');
			varImg.src 					= "images/spacer.gif";
			varImg.width 				= "12";
			varImg.height				= "10";
			varTd1_Tr2_main.appendChild(varImg);
	
			var varTd2_Tr2_main			= document.createElement('td');
			if (idioma == 1) {
				var caption 			= 'Ciudad ' + total1_lbl;
			} else {
				var caption 			= 'City ' + total1_lbl;
			}
			var varb					= document.createElement('b');
			var nodoTextoOption 		= document.createTextNode(caption);
			varTd2_Tr2_main.className 	= 'arial10 padright15';
			varTd2_Tr2_main.align 		= "left";
			varb.appendChild(nodoTextoOption);
			varTd2_Tr2_main.appendChild(varb);
					
			var varTd3_Tr2_main			= document.createElement('td');					
			varTd3_Tr2_main.width 		= "164";
			varTd3_Tr2_main.align 		= "left";
	
		var varTr3_main	= document.createElement('tr');
	
			var varTd1_Tr3_main			= document.createElement('td');
			varTd1_Tr3_main.height		= "27";
			varTd1_Tr3_main.align		= "left";
			var varImg 					= document.createElement('img');
			varImg.src 					= "images/spacer.gif";
			varImg.width 				= "12";
			varImg.height				= "10";
			varTd1_Tr3_main.appendChild(varImg);
			
			var varTd2_Tr3_main			= document.createElement('td');
			varTd2_Tr3_main.className	= "arial10 padright15";
			if (idioma == 1) {
				var caption 			= 'Origen';
			} else {
				var caption 			= 'From';
			}
			varTd2_Tr3_main.align		= "left";
			varTd2_Tr3_main.height		= "27";
			var nodoTextoOption 		= document.createTextNode(caption);
			varTd2_Tr3_main.appendChild(nodoTextoOption);
	  		
			var varTd3_Tr3_main			= document.createElement('td');
			varTd3_Tr3_main.align		= "left";
			varTd3_Tr3_main.height		= "27";
			var inputBox1 				= document.createElement("input");
			var nombreInput 			= "pa_departurecity" + numRow1;
			inputBox1.type 				= "text";
			inputBox1.name 				= nombreInput;
			inputBox1.id 				= nombreInput;
			inputBox1.style.width 		= "145px";
			varTd3_Tr3_main.appendChild(inputBox1);
				
			var varTd4_Tr3_main			= document.createElement('td');
			varTd4_Tr3_main.className 	= "arial10 padright15";
			if (idioma == 1) {
				var caption 			= 'Fecha de Salida';
			} else {
				var caption 			= 'Departure Date';
			}
			var nodoTextoOption 		= document.createTextNode(caption);
			varTd4_Tr3_main.align		= "left";
			varTd4_Tr3_main.height		= "27";
			varTd4_Tr3_main.appendChild(nodoTextoOption);
			
			var varTd5_Tr3_main			= document.createElement('td');
			varTd5_Tr3_main.height		= "27";
			varTd5_Tr3_main.align		= "left";
			varTd5_Tr3_main.className 	= "arial10";
			var varSelect1 				= document.createElement('select');
			varSelect1.name 			= "pa_TxtDia" + total1_c;
			varSelect1.id 				= "pa_TxtDia" + total1_c;
			varSelect1.size 			= "1";
			var varOption   			= document.createElement('option');
			varOption.value 			= "00";
			var nodoTextoOption 		= document.createTextNode("--");
			varOption.appendChild(nodoTextoOption);
			varSelect1.appendChild(varOption);
			for (var i=1; i<=31; i++)
			{
				var varOption 			= document.createElement('option');
				varOption.value 		= i;
				var nodoTextoOption 	= document.createTextNode(i);
				varOption.appendChild(nodoTextoOption);
				varSelect1.appendChild(varOption);
			}
			var varSelect2 				= document.createElement('select');
			varSelect2.name 			= "pa_TxtMes" + total1_c;
			varSelect2.id 				= "pa_TxtMes" + total1_c;
			varSelect2.style.width 		= "75px";
			var varOption   			= document.createElement('option');
			varOption.value 			= "00";
			var nodoTextoOption 		= document.createTextNode("--");
			varOption.appendChild(nodoTextoOption);
			varSelect2.appendChild(varOption);
			if (idioma == 1) 
			{
				arrayMeses 				= new Array("Enero","Febrero","Marzo","Abril","Mayo","Julio","Agosto","Setiembre","Octubre","Noviembre","Diciembre");				
			} else {
				arrayMeses 				= new Array("January","February","March","April","May","June","July","August","September","October","November","December");
			}
		    for (x in arrayMeses) 
		    {
				var varOption 			= document.createElement("option");
				varOption.value 		= x;
				var nodoTextoOption		= document.createTextNode(arrayMeses[x]);
				varOption.appendChild(nodoTextoOption);
				varSelect2.appendChild(varOption);
		    }	    
		    var varSelect3 				= document.createElement('select');
			varSelect3.name 			= "pa_TxtAnio" + total1_c;
			varSelect3.id 				= "pa_TxtAnio" + total1_c;
			varSelect3.size 			="1";
		    var varOption   			= document.createElement('option');
			var nodoTextoOption 		= document.createTextNode("-----");
			varOption.appendChild(nodoTextoOption);
			varOption.value 			= "0000";
			varSelect3.appendChild(varOption);
			//	var now = new Date();
			//	var year = now.getYear() + 1900;
			for (var i=2007; i<=2010; i++)
			{
				var varOption 			= document.createElement('option');
				varOption.value 		= i;
				var nodoTextoOption 	= document.createTextNode(i);
				varOption.appendChild(nodoTextoOption);
				varSelect3.appendChild(varOption);
			}
			varTd5_Tr3_main.appendChild(varSelect1);
			varTd5_Tr3_main.appendChild(varSelect2);
			varTd5_Tr3_main.appendChild(varSelect3);
	
		var varTr4_main	= document.createElement('tr');
			var varTd1_Tr4_main			= document.createElement('td');
			varTd1_Tr4_main.width		= "12";
			varTd1_Tr4_main.align		= "left";
			var varImg 					= document.createElement('img');
			varImg.src 					= "images/spacer.gif";
			varImg.width 				= "12";
			varImg.height				= "10";
			varTd1_Tr4_main.appendChild(varImg);
			
			var varTd2_Tr4_main			= document.createElement('td');
			varTd2_Tr4_main.align		= "left";
			varTd2_Tr4_main.className 	= "arial10 padright15";
			if (idioma == 1) 
			{
				var caption 			= 'Destino';
			} else {
				var caption 			= 'To';
			}
			var nodoTextoOption 		= document.createTextNode(caption);
			varTd2_Tr4_main.appendChild(nodoTextoOption);
	
			var varTd3_Tr4_main			= document.createElement('td');
			varTd3_Tr4_main.width		= "164";
			varTd3_Tr4_main.align		= "left";
	
			var inputBox2 				= document.createElement("input");
			var nombreInput 			= "pa_arrivalcity" + numRow1;
			inputBox2.type 				= "text";
			inputBox2.name 				= nombreInput;
			inputBox2.id 				= nombreInput;
			inputBox2.style.width 		= "145px";
			varTd3_Tr4_main.appendChild(inputBox2);
	
		varTr1_main.appendChild(varTd1_Tr1_main);
		varTr1_main.appendChild(varTd2_Tr1_main);
		varTr1_main.appendChild(varTd3_Tr1_main);
		
		varTr2_main.appendChild(varTd1_Tr2_main);
		varTr2_main.appendChild(varTd2_Tr2_main);
		varTr2_main.appendChild(varTd3_Tr2_main);
		
		varTr3_main.appendChild(varTd1_Tr3_main);
		varTr3_main.appendChild(varTd2_Tr3_main);
		varTr3_main.appendChild(varTd3_Tr3_main);
		varTr3_main.appendChild(varTd4_Tr3_main);
		varTr3_main.appendChild(varTd5_Tr3_main);
	
		varTr4_main.appendChild(varTd1_Tr4_main);
		varTr4_main.appendChild(varTd2_Tr4_main);
		varTr4_main.appendChild(varTd3_Tr4_main);
		
		varTbody_main.appendChild(varTr1_main);
		varTbody_main.appendChild(varTr2_main);
		varTbody_main.appendChild(varTr3_main);
		varTbody_main.appendChild(varTr4_main);
		
		varTbl_main.appendChild(varTbody_main);
		
		varTd_Padre.appendChild(varTbl_main);
		
		varTrPadre.appendChild(varTd_Padre);
	
		document.getElementById("contenedor").appendChild(varTrPadre);
		
		if (numRow1 == 9)
		{
			document.getElementById('row_add_another_city').style.display='none';
		}
	}
}

function del_rows_Multi_city_add()
{
	var obj1  = document.getElementById("row_6");
	if (obj1 != null)
	{
		obj1.parentNode.removeChild(obj1);		
	}
	
	var obj2  = document.getElementById("row_7");
	if (obj2 != null)
	{
		obj2.parentNode.removeChild(obj2);		
	}
	
	var obj3  = document.getElementById("row_8");
	if (obj3 != null)
	{
		obj3.parentNode.removeChild(obj3);
	}
	
	var obj4  = document.getElementById("row_9");
	if (obj4 != null)
	{
		obj4.parentNode.removeChild(obj4);		
	}
}

function dameNrInputs_Passengers()
{
	var total1=0;
	var varInputs = document.getElementsByTagName('input');
	for (var i=0; i<varInputs.length;i++) 
	{
		if (varInputs[i].id.substr(0, 12) == "pa_firstname")
		{
			total1 += 1;
		}
	}
	return total1;
}

function addAnotherPassenger(idioma, obj)
{
	var nro_txt_passengers = dameNrInputs_Passengers();
	var inc = 2;
	
	while (inc <= nro_txt_passengers) 
	{
 		var obj1 = document.getElementById("guest_detail_block" + inc);
 		var obj2 = document.getElementById("guest_main_block" + inc);
		obj1.parentNode.removeChild(obj1);
		obj2.parentNode.removeChild(obj2);
		inc++;
	}
	
	var total1	= parseInt(obj.value);
	for (var i=2; i<=total1; i++)
	{
		var varTr1_main	= document.createElement('tr');
		varTr1_main.id 	= "guest_main_block" + i;
	
			var varTd1_Tr1_main			= document.createElement('td');
			varTd1_Tr1_main.width 		= "12";
			varTd1_Tr1_main.align 		= "left";
			var varImg 					= document.createElement('img');
			varImg.src 					= "images/spacer.gif";
			varImg.width 				= "12";
			varImg.height				= "10";
			varTd1_Tr1_main.appendChild(varImg);
	
			var varTd2_Tr1_main			= document.createElement('td');
			varTd2_Tr1_main.className 	= "arial10 padright15";
			if (idioma == 1) {
				var caprion 			= "Pasajero " + i;		
			} else {
				var caprion 			= "Passanger " + i;
			}
			var nodoTextoOption 		= document.createTextNode(caprion);
			varTd2_Tr1_main.appendChild(nodoTextoOption);
	
		var varTr2_main	= document.createElement('tr');
			varTr2_main.style.height = "40px";
			varTr2_main.id = "guest_detail_block" + i;
			
			var varTd1_Tr2_main			= document.createElement('td');
			varTd1_Tr2_main.width 		= "12";
			varTd1_Tr2_main.align 		= "left";			
			var varImg					= document.createElement('img');
			varImg.src 					= "images/spacer.gif";
			varImg.width 				= "12";
			varImg.height				= "10";
			varTd1_Tr2_main.appendChild(varImg);
	
			var varTd2_Tr2_main			= document.createElement('td');
			if (idioma == 1) {
				var caption 			= 'Nombres';
			} else {
				var caption 			= 'First Name';
			}
			var nodoTextoOption 		= document.createTextNode(caption);
			varTd2_Tr2_main.className 	= 'arial10 padright15';
			varTd2_Tr2_main.align 		= "left";
			varTd2_Tr2_main.width 		= "66";
			varTd2_Tr2_main.appendChild(nodoTextoOption);
					
			var varTd3_Tr2_main			= document.createElement('td');					
			varTd3_Tr2_main.width 		= "113";
			varTd3_Tr2_main.align 		= "left";
			var inputBox2 				= document.createElement("input");
			var nombreInput 			= "pa_firstname" + i;
			inputBox2.type 				= "text";
			inputBox2.name 				= nombreInput;
			inputBox2.id 				= nombreInput;
			inputBox2.style.width 		= "85px";
			varTd3_Tr2_main.appendChild(inputBox2);
	

			var varTd4_Tr2_main			= document.createElement('td');
			if (idioma == 1) {
				var caption 			= 'Apellidos';
			} else {
				var caption 			= 'Last Name';
			}
			var nodoTextoOption 		= document.createTextNode(caption);
			varTd4_Tr2_main.className 	= 'arial10 padright15';
			varTd4_Tr2_main.align 		= "left";
			varTd4_Tr2_main.width 		= "60";
			varTd4_Tr2_main.appendChild(nodoTextoOption);
			
			var varTd5_Tr2_main			= document.createElement('td');					
			varTd3_Tr2_main.width 		= "109";
			varTd3_Tr2_main.align 		= "left";
			var inputBox2 				= document.createElement("input");
			var nombreInput 			= "pa_lastname" + i;
			inputBox2.type 				= "text";
			inputBox2.name 				= nombreInput;
			inputBox2.id 				= nombreInput;
			inputBox2.style.width 		= "85px";
			varTd5_Tr2_main.appendChild(inputBox2);

			
			var varTd6_Tr2_main			= document.createElement('td');
			if (idioma == 1) {
				var caption 			= 'Nº pasaporte';
			} else {
				var caption 			= 'Nº Passport';
			}
			var nodoTextoOption 		= document.createTextNode(caption);
			varTd6_Tr2_main.className 	= 'arial10 padright15';
			varTd6_Tr2_main.align 		= "left";
			varTd6_Tr2_main.width 		= "61";
			varTd6_Tr2_main.appendChild(nodoTextoOption);

			var varTd7_Tr2_main			= document.createElement('td');					
			varTd3_Tr2_main.width 		= "52";
			varTd3_Tr2_main.align 		= "left";
			var inputBox2 				= document.createElement("input");
			var nombreInput 			= "pa_passportnumber" + i;
			inputBox2.type 				= "text";
			inputBox2.name 				= nombreInput;
			inputBox2.id 				= nombreInput;
			inputBox2.style.width 		= "85px";
			inputBox2.maxlength			= "7"
			varTd7_Tr2_main.appendChild(inputBox2);

			var varTd8_Tr2_main			= document.createElement('td');
			varTd8_Tr2_main.width 		= "27";
			varTd8_Tr2_main.align 		= "left";
			varTd8_Tr2_main.className	= "arial10";
				
		varTr1_main.appendChild(varTd1_Tr1_main);
		varTr1_main.appendChild(varTd2_Tr1_main);
		
		varTr2_main.appendChild(varTd1_Tr2_main);
		varTr2_main.appendChild(varTd2_Tr2_main);
		varTr2_main.appendChild(varTd3_Tr2_main);
		varTr2_main.appendChild(varTd4_Tr2_main);
		varTr2_main.appendChild(varTd5_Tr2_main);
		varTr2_main.appendChild(varTd6_Tr2_main);
		varTr2_main.appendChild(varTd7_Tr2_main);
		varTr2_main.appendChild(varTd8_Tr2_main);
	
		var content = document.getElementById("contenedor_guest");
		content.appendChild(varTr1_main);
		content.appendChild(varTr2_main);
	}
}

function isBadNroPassport(fld) 
{
	var swf=false;
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
   	if (fld.value.length <= 15) 
   	{
		if (illegalChars.test(fld.value)) 
		{
			swf=true;
	    }
   	}
   	else
   	{
		swf=true;
   	}
   	
   	return swf;
}