// Form Validation JavaScript
function actualizaFechas(fechaDefecto){
	if (document.getElementById('fecha_entrada') && document.getElementById('fecha_salida')) {
		if (dias_entre(fechaDefecto, document.getElementById('fecha_entrada').value) < 0) {
			document.getElementById('fecha_entrada').value = fechaDefecto;
		} else {
			document.getElementById('fecha_salida').value = addToDate(document.getElementById('fecha_entrada').value, document.getElementById('noches').value);
		}
	} else if (document.getElementById('fecha_salida') && document.getElementById('fecha_regreso')) {
		fecha_salida = document.getElementById('fecha_salida');
		fecha_regreso = document.getElementById('fecha_regreso');
		if (fechaDefecto) {
			if (dias_entre(fechaDefecto, fecha_salida.value) < 0) {
				fecha_salida.value = fechaDefecto;
			} else if (dias_entre(fechaDefecto, fecha_regreso.value) < 0) {
				fecha_regreso.value = fechaDefecto;
			}
		}
		if (dias_entre(fecha_salida.value, fecha_regreso.value) < 0) {
			fecha_regreso.value = fecha_salida.value;
		}

	}
}
function actualizaFechasSalida(){
	var noches = restarFechas(document.getElementById('fecha_entrada').value,document.getElementById('fecha_salida').value);
	if(noches<1){
		alert("La fecha final no puede ser anterior a la fecha inicial");
		document.getElementById('noches').value = 1;
		actualizaFechas();
	}else
		document.getElementById('noches').value = noches;
}
function cargarSelectEdadNinos(num, edadmax, ninos){
	var html = '';
	for(var j=1;j<=ninos;j++){
		html += '<select name="edad_nino_'+num+'_'+j+'"  class="input_grid_nuevo" id="edad_nino_'+num+'_'+j+'">';
		html +=	'<option value="-1" selected="selected">--</option>';
		for(var i=0;i<=edadmax;i++){
			html +=	'<option value='+i+'>'+i+'</option>';
		}
		html +=	'</select>';
	}
	document.getElementById('div_edad_nino_'+num).innerHTML = html;
}
function EW_onError(form_object, input_object, object_type, error_message) {
	alert(error_message);
	if (object_type == "RADIO" || object_type == "CHECKBOX") {
		if (input_object[0] && input_object[0].disabled==false && input_object[0].display=='block')
		input_object[0].focus();
		else {
			if((input_object.disabled==false) && (input_object.display=='block')) input_object.focus();
		}
	}	else if (!(document.all && document.all["_"+input_object.name+"_editor"])) {
		if((input_object.disabled==false) && (input_object.display=='block')) input_object.focus();
	}
	if (object_type == "TEXT" || object_type == "PASSWORD" || object_type == "TEXTAREA" || object_type == "FILE") {
		if (!(document.all && document.all["_"+input_object.name+"_editor"])){
			if((input_object.disabled==false) && (input_object.display=='block')) input_object.select();
		}
	}
	return false;
}

function EW_hasValue(obj, obj_type) {
	if (obj_type == "TEXT" || obj_type == "PASSWORD" || obj_type == "TEXTAREA" || obj_type == "FILE")	{
		if (obj.value.length == 0)
		return false;
		else if (document.all && document.all["_"+obj.name+"_editor"] && (obj.value == '<P>&nbsp;</P>'))
		return false;
		else
		return true;
	}	else if (obj_type == "SELECT") {
		if (obj.type != "select-multiple" && obj.selectedIndex == -1)
		return false;
		else if (obj.type == "select-multiple" && obj.selectedIndex == -1)
		return false;
		else
		return true;
	}	else if (obj_type == "RADIO" || obj_type == "CHECKBOX")	{
		if (obj[0]) {
			for (i=0; i < obj.length; i++) {
				if (obj[i].checked)
				return true;
			}
		} else {
			return (obj.checked);
		}
		return false;
	}
}

// Date (mm/dd/yyyy)
function EW_checkusdate(object_value) {
	if (object_value.length == 0)
	return true;

	isplit = object_value.indexOf('/');

	if (isplit == -1 || isplit == object_value.length)
	return false;

	sMonth = object_value.substring(0, isplit);

	if (sMonth.length == 0)
	return false;

	isplit = object_value.indexOf('/', isplit + 1);

	if (isplit == -1 || (isplit + 1 ) == object_value.length)
	return false;

	sDay = object_value.substring((sMonth.length + 1), isplit);

	if (sDay.length == 0)
	return false;

	isep = object_value.indexOf(' ', isplit + 1);
	if (isep == -1) {
		sYear = object_value.substring(isplit + 1);
	} else {
		sYear = object_value.substring(isplit + 1, isep);
		sTime = object_value.substring(isep + 1);
		if (!EW_checktime(sTime))
		return false;
	}

	if (!EW_checkinteger(sMonth))
	return false;
	else if (!EW_checkrange(sMonth, 1, 12))
	return false;
	else if (!EW_checkinteger(sYear))
	return false;
	else if (!EW_checkrange(sYear, 0, 9999))
	return false;
	else if (!EW_checkinteger(sDay))
	return false;
	else if (!EW_checkday(sYear, sMonth, sDay))
	return false;
	else
	return true;
}

// Date (yyyy/mm/dd)
function EW_checkdate(object_value) {
	if (object_value.length == 0)
	return true;

	isplit = object_value.indexOf('/');

	if (isplit == -1 || isplit == object_value.length)
	return false;

	sYear = object_value.substring(0, isplit);

	isplit = object_value.indexOf('/', isplit + 1);

	if (isplit == -1 || (isplit + 1 ) == object_value.length)
	return false;

	sMonth = object_value.substring((sYear.length + 1), isplit);

	if (sMonth.length == 0)
	return false;

	isep = object_value.indexOf(' ', isplit + 1);
	if (isep == -1) {
		sDay = object_value.substring(isplit + 1);
	} else {
		sDay = object_value.substring(isplit + 1, isep);
		sTime = object_value.substring(isep + 1);
		if (!EW_checktime(sTime))
		return false;
	}

	if (sDay.length == 0)
	return false;

	if (!EW_checkinteger(sMonth))
	return false;
	else if (!EW_checkrange(sMonth, 1, 12))
	return false;
	else if (!EW_checkinteger(sYear))
	return false;
	else if (!EW_checkrange(sYear, 0, 9999))
	return false;
	else if (!EW_checkinteger(sDay))
	return false;
	else if (!EW_checkday(sYear, sMonth, sDay))
	return false;
	else
	return true;
}

// Date (dd/mm/yyyy)
function EW_checkeurodate(object_value) {
	if (object_value.length == 0)
	return false;

	isplit = object_value.indexOf('/');

	if (isplit == -1)	{
		isplit = object_value.indexOf('.');
	}

	if (isplit == -1 || isplit == object_value.length)
	return false;

	sDay = object_value.substring(0, isplit);

	monthSplit = isplit + 1;

	isplit = object_value.indexOf('/', monthSplit);

	if (isplit == -1)	{
		isplit = object_value.indexOf('.', monthSplit);
	}

	if (isplit == -1 ||  (isplit + 1 )  == object_value.length)
	return false;

	sMonth = object_value.substring((sDay.length + 1), isplit);

	isep = object_value.indexOf(' ', isplit + 1);
	if (isep == -1) {
		sYear = object_value.substring(isplit + 1);
	} else {
		sYear = object_value.substring(isplit + 1, isep);
		sTime = object_value.substring(isep + 1);
		if (!EW_checktime(sTime))
		return false;
	}

	if (!EW_checkinteger(sMonth))
	return false;
	else if (!EW_checkrange(sMonth, 1, 12))
	return false;
	else if (!EW_checkinteger(sYear))
	return false;
	else if (!EW_checkrange(sYear, 0, null))
	return false;
	else if (!EW_checkinteger(sDay))
	return false;
	else if (!EW_checkday(sYear, sMonth, sDay))
	return false;
	else
	return true;
}

function EW_checkday(checkYear, checkMonth, checkDay) {
	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||	checkMonth == 9 || checkMonth == 11) {
		maxDay = 30;
	} else if (checkMonth == 2)	{
		if (checkYear % 4 > 0)
		maxDay =28;
		else if (checkYear % 100 == 0 && checkYear % 400 > 0)
		maxDay = 28;
		else
		maxDay = 29;
	}

	return EW_checkrange(checkDay, 1, maxDay);
}

function EW_checkinteger(object_value) {
	if (object_value.length == 0)
	return true;

	var decimal_format = ".";
	var check_char;

	check_char = object_value.indexOf(decimal_format);
	if (check_char < 1)
	return EW_checknumber(object_value);
	else
	return false;
}

function EW_numberrange(object_value, min_value, max_value) {
	if (min_value != null) {
		if (object_value < min_value)
		return false;
	}

	if (max_value != null) {
		if (object_value > max_value)
		return false;
	}

	return true;
}

function EW_checknumber(object_value) {
	if (object_value.length == 0)
	return true;

	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

	check_char = start_format.indexOf(object_value.charAt(0));
	if (check_char == 1)
	decimal = true;
	else if (check_char < 1)
	return false;

	for (var i = 1; i < object_value.length; i++)	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0) {
			return false;
		} else if (check_char == 1)	{
			if (decimal)
			return false;
			else
			decimal = true;
		} else if (check_char == 0) {
			if (decimal || digits)
			trailing_blank = true;
		}	else if (trailing_blank) {
			return false;
		} else {
			digits = true;
		}
	}

	return true;
}

function EW_checkrange(object_value, min_value, max_value) {
	if (object_value.length == 0)
	return true;

	if (!EW_checknumber(object_value))
	return false;
	else
	return (EW_numberrange((eval(object_value)), min_value, max_value));

	return true;
}

function EW_checktime(object_value) {
	if (object_value.length == 0)
	return true;

	isplit = object_value.indexOf(':');

	if (isplit == -1 || isplit == object_value.length)
	return false;

	sHour = object_value.substring(0, isplit);
	iminute = object_value.indexOf(':', isplit + 1);

	if (iminute == -1 || iminute == object_value.length)
	sMin = object_value.substring((sHour.length + 1));
	else
	sMin = object_value.substring((sHour.length + 1), iminute);

	if (!EW_checkinteger(sHour))
	return false;
	else if (!EW_checkrange(sHour, 0, 23))
	return false;

	if (!EW_checkinteger(sMin))
	return false;
	else if (!EW_checkrange(sMin, 0, 59))
	return false;

	if (iminute != -1) {
		sSec = object_value.substring(iminute + 1);
		if (!EW_checkinteger(sSec))
		return false;
		else if (!EW_checkrange(sSec, 0, 59))
		return false;
	}

	return true;
}

function EW_checkphone(object_value) {
	if (object_value.length == 0)
	return true;

	if (object_value.length != 12)
	return false;

	if (!EW_checknumber(object_value.substring(0,3)))
	return false;
	else if (!EW_numberrange((eval(object_value.substring(0,3))), 100, 1000))
	return false;

	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " ")
	return false

	if (!EW_checknumber(object_value.substring(4,7)))
	return false;
	else if (!EW_numberrange((eval(object_value.substring(4,7))), 100, 1000))
	return false;

	if (object_value.charAt(7) != "-" && object_value.charAt(7) != " ")
	return false;

	if (object_value.charAt(8) == "-" || object_value.charAt(8) == "+")
	return false;
	else
	return (EW_checkinteger(object_value.substring(8,12)));
}


function EW_checkzip(object_value) {
	if (object_value.length == 0)
	return true;

	if (object_value.length != 5 && object_value.length != 10)
	return false;

	if (object_value.charAt(0) == "-" || object_value.charAt(0) == "+")
	return false;

	if (!EW_checkinteger(object_value.substring(0,5)))
	return false;

	if (object_value.length == 5)
	return true;

	if (object_value.charAt(5) != "-" && object_value.charAt(5) != " ")
	return false;

	if (object_value.charAt(6) == "-" || object_value.charAt(6) == "+")
	return false;

	return (EW_checkinteger(object_value.substring(6,10)));
}


function EW_checkcreditcard(object_value) {
	var white_space = " -";
	var creditcard_string = "";
	var check_char;

	if (object_value.length == 0)
	return true;

	for (var i = 0; i < object_value.length; i++) {
		check_char = white_space.indexOf(object_value.charAt(i));
		if (check_char < 0)
		creditcard_string += object_value.substring(i, (i + 1));
	}

	if (creditcard_string.length == 0)
	return false;

	if (creditcard_string.charAt(0) == "+")
	return false;

	if (!EW_checkinteger(creditcard_string))
	return false;

	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for (var i = 0; i < creditcard_string.length; i++) {
		tempdigit = eval(creditcard_string.charAt(i));
		if (doubledigit) {
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);
			if ((tempdigit / 10) >= 1.0)
			checkdigit++;
			doubledigit = false;
		}	else {
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}

	return (checkdigit % 10) == 0 ? true : false;
}


function EW_checkssc(object_value) {
	var white_space = " -+.";
	var ssc_string="";
	var check_char;

	if (object_value.length == 0)
	return true;

	if (object_value.length != 11)
	return false;

	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " ")
	return false;

	if (object_value.charAt(6) != "-" && object_value.charAt(6) != " ")
	return false;

	for (var i = 0; i < object_value.length; i++) {
		check_char = white_space.indexOf(object_value.charAt(i));
		if (check_char < 0)
		ssc_string += object_value.substring(i, (i + 1));
	}

	if (ssc_string.length != 9)
	return false;

	if (!EW_checkinteger(ssc_string))
	return false;

	return true;
}


function EW_checkemail(object_value) {
	if (object_value.length == 0)
	return true;

	if (!(object_value.indexOf("@") > -1 && object_value.indexOf(".") > -1))
	return false;

	return true;
}

// GUID {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
function EW_checkGUID(object_value)	{
	if (object_value.length == 0)
	return true;
	if (object_value.length != 38)
	return false;
	if (object_value.charAt(0)!="{")
	return false;
	if (object_value.charAt(37)!="}")
	return false;

	var hex_format = "0123456789abcdefABCDEF";
	var check_char;

	for (var i = 1; i < 37; i++) {
		if ((i==9) || (i==14) || (i==19) || (i==24)) {
			if (object_value.charAt(i)!="-")
			return false;
		} else {
			check_char = hex_format.indexOf(object_value.charAt(i));
			if (check_char < 0)
			return false;
		}
	}
	return true;
}


// Update a combobox with filter value
// object_value_array format
// object_value_array[n] = option value
// object_value_array[n+1] = option text 1
// object_value_array[n+2] = option text 2
// object_value_array[n+3] = option filter value
function EW_updatecombo(obj, object_value_array, filter_value) {
	var value = obj.options[obj.selectedIndex].value;
	for (var i = obj.length-1; i > 0; i--) {
		obj.options[i] = null;
	}
	for (var j=0; j<object_value_array.length; j=j+4) {
		if (object_value_array[j+3].toUpperCase() == filter_value.toUpperCase()) {
			EW_newopt(obj, object_value_array[j], object_value_array[j+1], object_value_array[j+2]);
		}
	}
	EW_selectopt(obj, value);
}

// Create combobox option
function EW_newopt(obj, value, text1, text2) {
	var text = text1;
	if (text2 != "")
	text += ", " + text2;
	var optionName = new Option(text, value, false, false)
	var length = obj.length;
	obj.options[length] = optionName;
}

// Select combobox option
function EW_selectopt(obj, value) {
	for (var i = obj.length-1; i>=0; i--) {
		if (obj.options[i].value == value) {
			obj.selectedIndex = i;
			break;
		}
	}
}

// Get image width/height
function EW_getimagesize(file_object, width_object, height_object) {
	if (navigator.appVersion.indexOf("MSIE") != -1)	{
		myimage = new Image();
		myimage.onload = function () {
			width_object.value = myimage.width; height_object.value = myimage.height;
		}
		myimage.src = file_object.value;
	}
}

function desactivaTodos(){
	var i;
	for (i=0;i<document.forms.length;i++){
		desactiva(document.forms[i]);
	}
}

function desactiva(f){
	for ( i=0;i<f.elements.length;i++){
		if(f.name.substr(0,5)=='form_' && f.name != 'form_alta'){
			//			alert(f.elements[i].type);
			if(f.elements[i].type == 'text') {
				f.elements[i].className='input_grid';
				f.elements[i].readOnly=true;
			}
			if(f.elements[i].type == 'select-one' || f.elements[i].type == 'checkbox'){
				f.elements[i].className='input_boton'
				f.elements[i].disabled=true;
			}
			f.elements['modificar'].value = 'Modificar';
		}
	}
	return true;
}

function activa(f){
	var i;
	var miForm;
	var miFormName;
	var miElementos;
	if(f){

		miFormName='form_'+f;

		for (i=0;i<document.forms.length;i++){
			if(document.forms[i].name != miFormName)
			desactiva(document.forms[i]);
		}

		miForm = document.forms[miFormName];
		miElementos = miForm.elements;
		if(miElementos['modificar'].value == 'Validar' && EW_checkMyForm(miForm)) {
			miForm.submit();
			return true;
		}

		for ( i=0;i<miElementos.length;i++){
			if(miElementos[i].type == 'text'){
				miElementos[i].className='input_grid_modificar';
				miElementos[i].readOnly=false;
			}
			if(miElementos[i].type == 'select-one' || miElementos[i].type == 'checkbox'){
				miElementos[i].className='input_boton';
				miElementos[i].disabled=false;
			}
		}

		miElementos['modificar'].value = 'Validar';
		return true;
	}
	return false;
}

function rellena_traslados(formulario, campo, indice)
{
	eval('campo = document.' + formulario + '.' + campo + ';');
	eval("traslados = traslados_"+campo.name+";");

	campo.disabled = false;
	if(campo.options)
	{
		for (contador = campo.options.length; contador != 0; contador--)
		{
			campo.options[contador] = null;
		}
	}
	campo.options[0] = new Option('(Ninguno)', 0);
	for (contador = 1; contador != traslados[indice].length; contador++)
	{
		campo.options[contador] = traslados[indice][contador];
	}
}

function rellena_opciones(combo, idOpcion, opciones, f){
	if(combo.options){
		for (m=combo.options.length-1;m>0;m--)
		combo.options[m]=null
	}

	combo.options[0]=new Option("(Ninguna)","0");
	if(opciones){
		if(idOpcion>0 && opciones[idOpcion].length>0){
			j=1;
			for (i=1;i<opciones[idOpcion].length;i++){

				if((f && filtro[opciones[idOpcion][i].value] == f) || !f){
					combo.options[j]=new Option(opciones[idOpcion][i].text,opciones[idOpcion][i].value);
					combo.disabled=false;
					j++;
				}
			}
		} else combo.disabled=true;
	} else combo.disabled=true;
	//alert("Fin rellenando "+combo.name);
}

function rellena_zonas_todos(Forms){
	//alert("Rellenando todas las forms ");
	for(index in Forms){
		F = Forms[index];
		thisForm = document.getElementById(F[1]);
		if(thisForm){
			if(thisForm.id_zona_pais){
				rellena_opciones(thisForm.id_zona,F[2],zonas[thisForm.id_zona_pais.value]);
			}
		}
	}
	//alert("Fin rellenando todas las forms ");
}

//----------------------------------------------------------------------------
// Funciones para activacion de varios tipos de formularios en una misma hoja
//----------------------------------------------------------------------------

function desactivaTodos_2(miImgNombre){
	var i;
	var miImgNombre;
	for (i=0;i<document.forms.length;i++){
		desactiva_2(document.forms[i].name,miImgNombre);
	}
}

function desactiva_2(miFormName,miImgNombre){
	var miForm;
	var miImgNombre;
	var miImgEditarClass;
	var miImgGuardarClass;

	miImgEditarClass = 'img_boton_b_edit';
  miImgGuardarClass = 'img_boton_guardar';

	if(!miImgNombre || miImgNombre == '') miImgNombre = 'b_edit.gif';

	if(miFormName.substr(0,5)=='form_' && miFormName.substr(0,9)!= 'form_alta'){
		miForm = document.forms[miFormName];
		if(miForm){
			miElementos = miForm.elements;

			for ( i=0;i<miElementos.length;i++){
				if(miElementos[i].type == 'text') {
				  if ((miElementos[i].className!='input_grid_fijo')&&(miElementos[i].className!='input_grid_readonly')){
  					miElementos[i].className='input_grid';
				  }
					miElementos[i].readOnly=true;
				}
				if(miElementos[i].type == 'select-one' || miElementos[i].type == 'checkbox' || miElementos[i].type == 'textarea'){
					miElementos[i].className='input_boton'
					miElementos[i].disabled=true;
				}
				if (miElementos['modificar']) {
					miElementos['modificar'].value = 'Modificar';
				}
				if (miElementos['btn_modificar'])
				{
          if (miElementos['btn_modificar'].className == miImgGuardarClass){
  		      miElementos['btn_modificar'].className = miImgEditarClass
  		    }
  		    else if (miElementos['btn_modificar'].className != miImgEditarClass){
  					miElementos['btn_modificar'].src=imgDir+miImgNombre;
  		    }
				}
			}
			return true;
		}
	}
	return false;
}

function activa_2(miFormName,miImgEditarNombre,miImgGuardarNombre){
	var i;
	var miForm;
	var miFormName;
	var miElementos;
	var miElementoNombre;
	var miImgNombre;
	var miImgEditarClass;
	var miImgGuardarClass;

	miImgEditarClass = 'img_boton_b_edit';
  miImgGuardarClass = 'img_boton_guardar';

	if(!miImgEditarNombre || miImgEditarNombre == '') miImgEditarNombre = 'b_edit.gif';
	if(!miImgGuardarNombre || miImgGuardarNombre == '') miImgGuardarNombre = 'guardar.gif';

	for (i=0;i<document.forms.length;i++){
		if(document.forms[i].name != miFormName)
		desactiva_2(document.forms[i].name,miImgEditarNombre);
	}

	miForm = document.forms[miFormName];
	if(miForm){
		miElementos = miForm.elements;

		if(miElementos['modificar'].value == 'Validar') {
			if(window.f_validar_form){
				if(f_validar_form(miForm) == false){
					return false;
				}
			}
			miForm.submit();
			return true;
		}

		for ( i=0;i<miElementos.length;i++){
			miElementoNombre = new String(miElementos[i].name);
			if(miElementoNombre.search('disabled')<0){
				if(miElementos[i].type == 'text'){
				  if (miElementos[i].className=='input_grid_readonly'){
				     miElementos[i].readOnly=true;
				  }
				  else{
					//miElementos[i].disabled=false;
				    miElementos[i].readOnly=false;
				  }
				  if (miElementos[i].className!='input_grid_fijo'){
  					miElementos[i].className='input_grid_modificar';
				  }
				}
				if(miElementos[i].type == 'select-one' ){
					miElementos[i].className='input_grid_modificar';
					miElementos[i].disabled=false;
				}
				if(miElementos[i].type == 'textarea'){
					miElementos[i].className='input_textarea_modificar';
					miElementos[i].disabled=false;
				}
				if(miElementos[i].type == 'checkbox' ){
					miElementos[i].disabled=false;
				}
			}
		}

		miElementos['modificar'].value = 'Validar';
		if (miElementos['btn_modificar']){
  		if (miElementos['btn_modificar'].className == miImgEditarClass){
  		  miElementos['btn_modificar'].className = miImgGuardarClass
  		}
  		else  if (miElementos['btn_modificar'].className == miImgGuardarClass){
  		      miElementos['btn_modificar'].className = miImgGuardarClass
  		      }
  		else {
  		miElementos['btn_modificar'].src=imgDir+miImgGuardarNombre;
  		}
		}
		return true;
	}
	return false;
}

//----------------------------------------------------------------------------
// Funciones para la comprobacion de filtros de busqueda
//----------------------------------------------------------------------------

function  check_reserva_basico(EW_this) {
	if (EW_this.id_zona_pais && !EW_hasValue(EW_this.id_zona_pais, "SELECT" )) {
		if (!EW_onError(EW_this, EW_this.id_zona_pais, "SELECT", "País - Campo obligatorio"))
		return false;
	}
	if (EW_this.fecha_entrada && !EW_hasValue(EW_this.fecha_entrada, "TEXT" )) {
		if (!EW_onError(EW_this, EW_this.fecha_entrada, "TEXT", "Fecha entrada - Campo obligatorio"))
		return false;
	}
	if (EW_this.fecha_salida && !EW_hasValue(EW_this.fecha_salida, "TEXT" )) {
		if (!EW_onError(EW_this, EW_this.fecha_salida, "TEXT", "Fecha salida - Campo obligatorio"))
		return false;
	}
	return true;
}

function check_dias(f) {
	var error = '';
	if (f.max_dias_editar && f.min_dias_editar && f.noches) {
		var valorMax = parseInt(f.max_dias_editar.value);
		var valorMin = parseInt(f.min_dias_editar.value);
		var valorFormulario = f.noches.value;
	}

	if(f.noches && f.max_dias_editar) {
		if(valorFormulario > valorMax) {
			error = 'Por favor, el número de noches ha de ser igual o inferior a '+f.max_dias_editar.value+', ahora es '+f.noches.value;
		}
	}

	if(f.noches && f.min_dias_editar) {
		if(valorFormulario < valorMin) {
			error = 'Por favor, el número de noches ha de ser igual o superior a '+f.min_dias_editar.value+', ahora es '+f.noches.value;
		}
	}
	return error;
}


function checkOcupaciones(f) 
{
    var ocupacion_minima = f.ocupacion_minima.value;
    var num_min_adultos  = f.num_min_adultos.value;
    var num_min_total    = f.num_min_total.value;

    var num_ocupaciones=0;

    if((f.adultos_1 && EW_hasValue(f.adultos_1, "SELECT")) || (f.ninos_1 && EW_hasValue(f.ninos_1, "SELECT"))){
        num_ocupaciones++;
    }
    if((f.adultos_2 && EW_hasValue(f.adultos_2, "SELECT")) || (f.ninos_2 && EW_hasValue(f.ninos_2, "SELECT"))){
        num_ocupaciones++;
    }
    if((f.adultos_3 && EW_hasValue(f.adultos_3, "SELECT")) || (f.ninos_3 && EW_hasValue(f.ninos_3, "SELECT"))){
        num_ocupaciones++;
    }

    // Comprobamos que estan cubiertas las ocupaciones minimas
    if(num_ocupaciones<ocupacion_minima){ alert('Debe seleccionar un mínimo de '+ocupacion_minima+' ocupaciones');return false;}

    // Comprobamos que se cumple el minimo numero de adultos para cada ocupacion
    if(num_min_adultos>0)
    {
         if(num_ocupaciones>0)
         {
             if(parseInt(f.adultos_1.value)<num_min_adultos)
             {
                 alert('Debe seleccionar un mínimo de '+num_min_adultos+' adultos');
                 f.adultos_1.focus();
                 return false;
             }
         }
         if(num_ocupaciones>1)
         {
             if(parseInt(f.adultos_2.value)<num_min_adultos)
             {
                 alert('Debe seleccionar un mínimo de '+num_min_adultos+' adultos');
                 f.adultos_2.focus();
                 return false;
             }
         }
         if(num_ocupaciones>2)
         {
             if(parseInt(f.adultos_3.value)<num_min_adultos)
             {
                 alert('Debe seleccionar un mínimo de '+num_min_adultos+' adultos');
                 f.adultos_3.focus();
                 return false;
             }
         }
    }

    // Comprobamos que se cumple el minimo numero de personas para cada ocupacion
    if(num_min_total>0)
    {
         if(num_ocupaciones>0)
         {
             if((parseInt(f.adultos_1.value)+parseInt(f.ninos_1.value))<num_min_total)
             {
                 alert('Debe seleccionar un mínimo de '+num_min_total+' personas');
                 f.adultos_1.focus();
                 return false;
             }
         }
         if(num_ocupaciones>1)
         {
             if((parseInt(f.adultos_2.value)+parseInt(f.ninos_2.value))<num_min_total)
             {
                 alert('Debe seleccionar un mínimo de '+num_min_total+' personas');
                 f.adultos_2.focus();
                 return false;
             }
         }
         if(num_ocupaciones>2)
         {
             if((parseInt(f.adultos_3.value)+parseInt(f.ninos_3.value))<num_min_total)
             {
                 alert('Debe seleccionar un mínimo de '+num_min_total+' personas');
                 f.adultos_3.focus();
                 return false;
             }
         }
    }

    return true;
}

function checkFechas(f, tipo_formulario){
    var estancia_minima  = parseInt(f.estancia_minima.value);
    var estancia_maxima  = parseInt(f.estancia_maxima.value);
    if( tipo_formulario!=1 && tipo_formulario!=2 )  var noches           = parseInt(f.noches.value);
    var fecha_entrada_min  = f.fecha_entrada_min.value;
    var fecha_salida_max   = f.fecha_salida_max.value;

    if(tipo_formulario==1)
    {
        // Se trata de un vuelo y por lo tanto sus fechas tienen otro nombre (fecha_ida, fecha_vuelta) :-(
        fecha_entrada = f.fecha_ida;
        fecha_salida  = f.fecha_vuelta;
    }
    else if(tipo_formulario==2)
    {
        // Se trata de un traslado y por lo tanto solo tiene "fecha_desde"  :-(
        fecha_entrada = f.fecha_desde;
    }
    else
    {
        fecha_entrada = f.fecha_entrada;
        fecha_salida  = f.fecha_salida;
    }


    if(fecha_entrada_min!="")
    {
        if(!comprueba_fecha_min(fecha_entrada,fecha_entrada_min))
        {
             return false;
        }
    }

    if(fecha_salida_max!="")
    {
        if(!comprueba_fecha_max(fecha_salida,fecha_salida_max))
        {
             return false;
        }
    }

    // Si el formulario no se trata de un aereo o traslado controlamos la estancia (num_noches)
    if( tipo_formulario!=1 && tipo_formulario!=2 )
    {
      if( estancia_minima>0 && estancia_minima>noches)
      {
          alert('La estancia mímina son '+estancia_minima+' noches');
          return false;
      }

      if( estancia_maxima>0 && estancia_maxima<noches)
      {
          alert('La estancia máxima son '+estancia_maxima+' noches');
          return false;
      }
    }

    return true;
}



function check_reserva_buscar_hotel(f, bModoPredictivo) {
	var error = '';

	error += new String(check_dias(f));
	if (error.length > 0) {
		alert(error);
		return false;
	}
	if(!controlEdadesCriosRemix()) {
		alert("No están definidas todas las edades de los niños o las edades no están puestas en orden\n(deben estar de menor a mayor)");
		return false;
	}

	if (!bModoPredictivo) {
		if(checkPoblacion(f)){
			error += "- Poblacion\n";
		}
		if(checkHotel(f)){
			error += "- Hotel\n";
		}
		if(checkProvincia(f)){
			error += "- Provincia\n";
		}
		if(checkZona(f)){
			error += "Elija una Zona que no sea '(Cualquiera)'\n";
		}
		if (checkRegimen(f)) {
			error += "Elija un Régimen que no sea '(Cualquiera)'\n";
		}
	} else {
		if (document.getElementById('poblacion').value == '' || document.getElementById('id_zona_pais').value == 0) {
			error += "- Población\no\n- Hotel\n";
		}
	}

	if(error.length>0){
		error = "Uno de los siguientes campos ha de estar relleno:\n" + error;
		alert(error);
		return false;
	}
	if(!checkFechas(f,0))
		return false;
	if(!checkOcupaciones(f))
		return false;

	if(check_reserva_basico(f)){
		if(f.adultos_1 && !EW_hasValue(f.adultos_1, "SELECT")){
			if(!f.edad_nino_1_1){
				alert('Tienes que establecer como minimo el numero\n de adultos para la primera ocupacion.');
				return false;
			}
			if(f.edad_nino_1_1 && !EW_hasValue(f.edad_nino_1_1,"SELECT")){
				EW_onError(f,f.edad_nino_1_1,"SELECT","Si no se establece numero de adultos la edad del niño 1 no puede estar vacia");
				return false;
			} else return true;
		} else return true;
	}

	return false;
}

function check_reserva_buscar_casa_rural(f) {
	var error = '';

	error += new String(check_dias(f));
	if (error.length > 0) {
		alert(error);
		return false;
	}

	if (checkPoblacion(f) && checkHotel(f) && checkProvincia(f)) {
		return false;
	}

	if (checkZona(f)) {
		return false;
	}

        if(!checkFechas(f,0))
        {
            return false;
        }

        if(!checkOcupaciones(f))
        {
            return false;
        }

	if(check_reserva_basico(f)){
		if(f.adultos_1 && !EW_hasValue(f.adultos_1, "SELECT")){
			EW_onError(f,f.adultos_1,"SELECT","El numero de adultos no puede ser cero");
			return false;
		} else return true;
	}
	return false;
}

function check_reserva_buscar_apartamento(f) {
	var error = '';

	error += new String(check_dias(f));
	if (error.length > 0) {
		alert(error);
		return false;
	}

	if (controlEdadesCrios(f) == 1) {
		return false;
	}

	if (checkPoblacion(f) && checkHotel(f) && checkProvincia(f)) {
		return false;
	}

	if (checkZona(f))
		return false;

        if(!checkFechas(f,0))
        {
            return false;
        }

        if(!checkOcupaciones(f))
        {
            return false;
        }

	if(check_reserva_basico(f)) {
		if(f.adultos_1 && !EW_hasValue(f.adultos_1, "SELECT")){
			if(f.ninos_1 && !EW_hasValue(f.ninos_1,"SELECT")){
				EW_onError(f,f.ninos_1,"SELECT","Si no se establece numero de adultos se debe establecer numero de niños");
				return false;
			} else return true;
		} else return true;
	}

	return false;
}

function check_reserva_buscar_aereo(f) {
	var error = '';

        error += new String(check_dias(f));
	if (error.length > 0) {
		alert(error);
		return false;
	}

	if (controlEdadesCrios(f) == 1) {
		return false;
	}

	if (f.id_aeropuerto_salida && f.id_aeropuerto_salida.value==0) {
		alert("Campo obligatorio - Aeropuerto de origen");
		return false;
	}
	if (f.id_aeropuerto_llegada && f.id_aeropuerto_llegada.value==0) {
		alert("Campo obligatorio - Aeropuerto de destino");
		return false;
	}

        if(!checkFechas(f,1))
        {
            return false;
        }

        if(!checkOcupaciones(f))
        {
            return false;
        }

	if(f.adultos_1 && !EW_hasValue(f.adultos_1, "SELECT")){
			if(f.ninos_1 && !EW_hasValue(f.ninos_1,"SELECT")){
				EW_onError(f,f.ninos_1,"SELECT","Si no se establece numero de adultos se debe establecer numero de niños");
				return false;
			} else return true;
		} else return true;
	return true;
}

function check_reserva_buscar_traslado(f)
{
	if (f.fecha_desde.value == "")
	{
		alert("Debe introducir la fecha del traslado.");
		return false;
	}

	if (f.traslado_tipo_origen.value == 0 || f.origen.value == 0 || f.lugar_origen.value == 0)
	{
		alert("Debe introducir los datos del origen.");
		return false;
	}

	if (f.traslado_tipo_destino.value == 0 || f.destino.value == 0 || f.lugar_destino.value == 0)
	{
		alert("Debe introducir los datos del destino.");
		return false;
	}

        if(!checkFechas(f,2))
        {
            return false;
        }

        if(!checkOcupaciones(f))
        {
            return false;
        }

	if(controlEdadesCrios(f)==1)
	{
		return false;
	}

	return true;
}

// Funciones para el validado del formulario de alta de agencias
function check_agencia(f){
	if(f.nombre_comercial && !EW_hasValue(f.nombre_comercial,"TEXT")){
		EW_onError(f,f.nombre_comercial,"TEXT","Campo obligatorio - Nombre comercial");
		return false;
	}
	return true;
}

// Funciones para el validado del formulario de alta de agencias por web
function check_agencia_web(f){
	var error = '';
	if (f.enviar)
		var boton = f.enviar;
	if(f.titulo && f.titulo.value == ''){
		error += "Campo obligatorio - Título agencia\n";
	}
	if(f.nif && f.nif.value == ''){
		error += "Campo obligatorio - N.I.F.\n";
	}
	if(f.nombre_comercial && f.nombre_comercial.value == ''){
		error += "Campo obligatorio - Nombre comercial\n";
	}
	if(f.email && f.email.value == ''){
		error += "Campo obligatorio - E-mail";
	}
	if (error != '') {
		alert(error);
		if (boton) {
			boton.disabled = false;
			boton.style.cursor = "pointer";
		}
		return false;
	}
	return true;
}


// Funcion para el validado del formulario de articulos
function check_articulo(f) {
	if (f.num_pax_min != null)
	{
		if(parseInt(f.num_pax_min.value) > parseInt(f.num_pax_max.value)){
			alert("La ocupación mínima no puede ser superior a la máxima");
			return false;
		}

		if(parseInt(f.num_adultos_min.value) > parseInt(f.num_adultos_max.value)){
			alert("El número mínimo de adultos no puede ser superior al número máximo");
			return false;
		}
	}

	if (f.id_prestatario && f.id_prestatario.value==0) {
		alert("Campo obligatorio - Prestatario");
		return false;
	}
	if (f.id_tipo_articulo && f.id_tipo_articulo.value==0) {
		alert("Campo obligatorio - Tipo de articulo");
		return false;
	}
	return true;
}

// Funcion para el validado del formulario de busqueda de reservas
function  check_buscar_reserva(f) {
	if (f.id_reserva && (f.id_reserva.value==0 || f.id_reserva.value == '')) {
		alert("No se ha especificado ningun número de reserva.");
		return false;
	}
	return true;
}

// Funcion para el validado del formulario de busqueda
function check_busqueda(f, busqueda)
{
	if (!busqueda)
		busqueda = 0;
	if (f.max_dias_editar)
		valorMax = parseInt(f.max_dias_editar.value);
	if (f.min_dias_editar)
		valorMin = parseInt(f.min_dias_editar.value);
	if (f.noches)
		valorFormulario=f.noches.value;

	if(f.noches && f.max_dias_editar)
	{
		if(valorFormulario > valorMax)
		{
			alert('Por favor, el número de noches ha de ser igual o inferior a '+f.max_dias_editar.value+', ahora es '+f.noches.value);
			return false;
		}
	}

	if(f.noches && f.min_dias_editar)
	{
		if(valorFormulario < valorMin)
		{
			alert('Por favor, el número de noches ha de ser igual o superior a '+f.min_dias_editar.value+', ahora es '+f.noches.value);
			return false;
		}
	}

	var ids = new Array()
	var i=0
	if(f.articulo1){
			ids[i] = new Option('articulo1',f.articulo1.value);
			i++;
	}
	if(f.articulo2){
			ids[i] = new Option('articulo1',f.articulo1.value);
			i++;
	}
	if(f.articulo3){
			ids[i] = new Option('articulo1',f.articulo1.value);
			i++;
	}
	articulo_seleccionado = false;
	for(index in ids){
		if(ids[index].value!=0) articulo_seleccionado = true;
	}
	if (busqueda == 1)
		articulo_seleccionado = true;
	if(!articulo_seleccionado){
		alert("Debes seleccionar una articulo");
		return false;
	}
	return true;
}

// Funcion para el validado de los datos del cliete de una solicitud
function check_datos_solicitud(f)
{
	if(f.forma_cobro>-1)	// SE OMITE EL TEST DE 'forma_cobro' SI ESTE CAMPO NO EXISTE EN EL FORMULARIO
		if (f.nombre && !EW_hasValue(f.forma_cobro, "RADIO" )) {
			if (!EW_onError(f, f.nombre, "RADIO", "Campo obligatorio - Forma de pago"))
			return false;
		}
	if (f.nombre && !EW_hasValue(f.nombre, "TEXT" )) {
		if (!EW_onError(f, f.nombre, "TEXT", "Campo obligatorio - Nombre"))
		return false;
	}
	if (f.apellidos && !EW_hasValue(f.apellidos, "TEXT" )) {
		if (!EW_onError(f, f.apellidos, "TEXT", "Campo obligatorio - Apellidos"))
		return false;
	}
	if (f.direccion && !EW_hasValue(f.direccion, "TEXT" )) {
		if (!EW_onError(f, f.direccion, "TEXT", "Campo obligatorio - Dirección"))
		return false;
	}
	if (f.codigopostal && !EW_hasValue(f.codigopostal, "TEXT" )) {
		if (!EW_onError(f, f.codigopostal, "TEXT", "Campo obligatorio - Código Postal"))
		return false;
	}
	if (f.poblacion && !EW_hasValue(f.poblacion, "TEXT" )) {
		if (!EW_onError(f, f.poblacion, "TEXT", "Campo obligatorio - Población"))
		return false;
	}
	if (f.provincia && !EW_hasValue(f.provincia, "TEXT" )) {
		if (!EW_onError(f, f.provincia, "TEXT", "Campo obligatorio - Provincia"))
		return false;
	}
	if (f.telefono && !EW_hasValue(f.telefono, "TEXT" )) {
		if (!EW_onError(f, f.telefono, "TEXT", "Campo obligatorio - Teléfono"))
		return false;
	}
	return true;
}

// Funcion para el validado del formulario de alta de cupos
function  check_cupos(f) {
	if(f.tipo_cupo.value == tipos_cupos[1].value || f.tipo_cupo.value == tipos_cupos[2].value){
		if(!f.items.value || f.items.value == 0){
			alert ("El numero de items debe se mayor que cero");
			return false;
		}
	}
	if(!EW_checkeurodate(f.Cdesde.value)){
		alert("Campo obligatorio - Fecha desde - No establecida o fecha no válida");
		return false;
	}
	if(!EW_checkeurodate(f.Chasta.value)){
		alert("Campo obligatorio - Fecha hasta - No establecida o fecha no válida");
		return false;
	}
	return true;
}

function check_form_disponibilidad_index(f){
	if (f.id_zona_pais_desde && !EW_hasValue(f.id_zona_pais_desde, "SELECT" )) {
		if (!EW_onError(f, f.id_zona_pais_desde, "SELECT", "País - Campo obligatorio"))
		return false;
	}
	if(!EW_checkeurodate(f.fecha_desde.value)){
		alert("Campo obligatorio - Fecha desde - No establecida o fecha no válida");
		return false;
	}
	if(!EW_checkeurodate(f.fecha_hasta.value)){
		alert("Campo obligatorio - Fecha hasta - No establecida o fecha no válida");
		return false;
	}
	if(f.adultos_1 && !EW_hasValue(f.adultos_1, "SELECT")){
		if(f.edad_nino_1_1 && !EW_hasValue(f.edad_nino_1_1,"SELECT")){
			EW_onError(f,f.edad_nino_1_1,"SELECT","Si no se establece numero de adultos la edad del niño 1 no puede estar vacia");
			return false;
		}
	}
	return true;
}

function check_form_disponibilidad_buscar(f){
	var hay_seleccionados = false;
	for(i=0;i<f.ids_articulos.options.length;i++){
		if(f.ids_articulos.options[i].selected)	hay_seleccionados = true;
	}
	if(!hay_seleccionados){
		alert('No hay seleccionado ningun rango en los articulos.');
		return false;
	}

	return true;
}

function checkPoblacion(f) {
	if (f.poblacion)
		if (f.poblacion_check.value == '1')
			if (f.poblacion.value == '')
				return true;
	return false;
}

function checkHotel(f) {
	if (f.nombre_comercial)
		if (f.nombre_comercial_check.value == '1')
			if (f.nombre_comercial.value == '')
				return true;
	return false;
}

function checkZona(f) {
	if (f.id_zona)
		if (f.permitir_cualquier_zona.value == '0')
			if (f.id_zona.options.item(f.id_zona.selectedIndex).value == '0')
				return true;
	return false;
}

function checkProvincia(f) {
	if (f.provincia) {
		if (f.provincia_check.value == '1')
			if (f.provincia.value == '')
				return true;
	}
	return false;
}

function checkRegimen(f) {
	if (f.suplemento_filtro_1)
		if (f.permitir_cualquier_regimen)
			if (f.permitir_cualquier_regimen.value == '0')
				if (f.suplemento_filtro_1.options.item(f.suplemento_filtro_1.selectedIndex).value == '0')
					return true;
	return false;
}

function cambia_foto(campo,valor){
	valor = valor.replace(/\\/g,'/');
	cmd = campo+'.src = \''+valor+'\';';
	eval(cmd);
}

function resta(campo,liminte_sup,campo_aux){
	if(!campo.value)
		valor=1;
	else
		valor = campo.value-1;

	if(EW_numberrange(valor, 1, liminte_sup)){
		campo.value = valor;
		if(campo_aux)
			campo_aux.value = valor;
		return true;
	}
	return false;
}

function suma(campo,liminte_sup,campo_aux){
	if(!campo.value)
		valor=1;
	else{
		valor = campo.value;
		valor++;
	}
	if(EW_numberrange(valor, 1, liminte_sup)){
		campo.value = valor;
		if(campo_aux)
			campo_aux.value = valor;
		return true;
	}
	return false;
}

function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	if(x.length > 1){
		if(x[x.length-1].length<2){
			x2 = ','+x[x.length-1]+'0';
		}else{
			x2 = ','+x[x.length-1].substr(0,2);
		}
	}else{
		x2 = ',00';
	}
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}

function cesta_total(campo_total,campo_comision,campo_coste,campo_tasas,articulos){
	miTotal = 0;
	miComisionTotal = 0;
	miCosteTotal = 0;
	miTasasTotal = 0;

	total = document.getElementById(campo_total);
	comision = document.getElementById(campo_comision);
	coste = document.getElementById(campo_coste);
	tasas = document.getElementById(campo_tasas);

	for(i=1;i<=articulos;i++){
		art_pvp  = document.getElementById('precio_'+i);
		art_pvp  = art_pvp.value.replace('.','');
		art_pvp  = art_pvp.replace(',','.');

		art_cant = document.getElementById('cant_'+i);


		art_com  = document.getElementById('comision_'+i);
		if(art_com){
			art_com  = art_com.value.replace(',','.');
		}else{
			art_com = 0;
		}

		art_tas  = document.getElementById('tasas_'+i);
		if(art_tas){
			art_tas  = art_tas.value.replace(',','.');
		}else{
			art_tas = 0;
		}
		art_total = art_pvp * art_cant.value;
		art_tas_total = art_tas * art_cant.value;
		art_com_total = art_total * (art_com / 100);

		miTotal += art_total;
		miComisionTotal += art_com_total;
		miTasasTotal += art_tas_total;
	}

	total.value = addCommas(miTotal + miTasasTotal);
	if(comision) comision.value = addCommas(miComisionTotal);
	if(coste) coste.value = addCommas(miTotal - miComisionTotal);
	if(tasas) tasas.value = addCommas(miTasasTotal);
}

function caracteres_permitidos(myfield, e, permitidos)
{
var key;
var keychar;

if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
(key==9) || (key==13) || (key==27) )
return true;

// comprobar caracteres permitidos
else if ((permitidos.indexOf(keychar) > -1))
return true;

else
return false;
}

function procesa_array_campos(inputType, objCampoEntrada, objCampoSalida)
{
	var valor = '|';

	if (objCampoEntrada.length == null)
	{
		switch (inputType)
		{
			case 'checkbox':
				if (objCampoEntrada.checked == true)
				{
					valor += objCampoEntrada.value + '|';
				}
			break;
		}
	}
	else
	{
		for (contador = 0; contador != objCampoEntrada.length; contador++)
		{
			switch (inputType)
			{
				case 'checkbox':
					if (objCampoEntrada[contador].checked == true)
					{
						valor += objCampoEntrada[contador].value + '|';
					}
				break;
			}
		}
	}
	objCampoSalida.value = valor;
}

function controlEdadesCriosRemix(){
	var todosNinos = new Array();
	todosNinos = $('select[id^="edad_nino_"]');
	for(var i=0;i<todosNinos.length;i++){
		if(todosNinos[i].value=="-1")
			return false;
	}
	var ant = 0;
	var sigid = 0;
	for(var i=0;i<todosNinos.length;i++){
		if(parseInt(todosNinos[i].value)<ant)
			return false;
		sigid = todosNinos[i+1].id.substr(10,1);
		if(sigid!=todosNinos[i].id.substr(10,1))
			ant = 0;
		else
			ant = todosNinos[i].value;
	}
	return true;
}
function controlEdadesCrios(f)
{	// NO SE PERMITE EFECTUAR LA BÚSQUEDA HASTA QUE NO SE INDIQUEN LAS EDADES DE LOS NIÑOS, SOLO EN EL CASO HUBIERE ALGUNO INCLUIDO PARA EL PRODUCTO SELECCIONADO
	if(f.ninos_1)
	{
		if(f.edad_nino_1_1.value<0 && f.ninos_1.value>0)
		{
			alert('Por favor, selecciona la edad del niño 1');
			f.edad_nino_1_1.focus();
			return 1;
		}

		if(f.edad_nino_1_2.value<0 && f.ninos_1.value>1)
		{
			alert('Por favor, selecciona la edad del niño 2');
			f.edad_nino_1_2.focus();
			return 1;
		}
		if(f.edad_nino_1_3 && f.edad_nino_1_3.value<0 && f.ninos_1.value>2)
		{
			alert('Por favor, selecciona la edad del niño 3');
			f.edad_nino_1_3.focus();
			return 1;
		}
		if(f.edad_nino_1_4 && f.edad_nino_1_4.value<0 && f.ninos_1.value>3)
		{
			alert('Por favor, selecciona la edad del niño 4');
			f.edad_nino_1_4.focus();
			return 1;
		}
		if(f.ninos_1.value>1 && Math.ceil(f.edad_nino_1_2.value) < Math.ceil(f.edad_nino_1_1.value))
		{
			alert('Por favor, la edad del niño 2 ha de ser igual o superior a la del niño 1');
			f.edad_nino_1_2.focus();
			return 1;
		}

		if(f.ninos_1.value>2 && (Math.ceil(f.edad_nino_1_3.value) < Math.ceil(f.edad_nino_1_2.value)))
		{
			alert('Por favor, la edad del niño 3 ha de ser igual o superior a la del niño 2');
			f.edad_nino_1_3.focus();
			return 1;
		}

		if(f.ninos_1.value>3 && (Math.ceil(f.edad_nino_1_4.value) < Math.ceil(f.edad_nino_1_3.value)))
		{
			alert('Por favor, la edad del niño 4 ha de ser igual o superior a la del niño 3');
			f.edad_nino_1_4.focus();
			return 1;
		}
	}

	if(f.ninos_2)
	{
		if(f.edad_nino_2_1.value<0 && f.ninos_2.value>0)
		{
			alert('Por favor, selecciona la edad del niño 1');
			f.edad_nino_2_1.focus();
			return 1;
		}
		if(f.edad_nino_2_2.value<0 && f.ninos_2.value>1)
		{
			alert('Por favor, selecciona la edad del niño 2');
			f.edad_nino_2_2.focus();
			return 1;
		}
		if(f.edad_nino_2_3 && f.edad_nino_2_3.value<0 && f.ninos_2.value>2)
		{
			alert('Por favor, selecciona la edad del niño 3');
			f.edad_nino_2_3.focus();
			return 1;
		}
		if(f.edad_nino_2_4 && f.edad_nino_2_4.value<0 && f.ninos_2.value>3)
		{
			alert('Por favor, selecciona la edad del niño 4');
			f.edad_nino_2_4.focus();
			return 1;
		}
		if(f.ninos_2.value>1 && Math.ceil(f.edad_nino_2_2.value) < Math.ceil(f.edad_nino_2_1.value))
		{
			alert('Por favor, la edad del niño 2 ha de ser igual o superior a la del niño 1');
			f.edad_nino_2_2.focus();
			return 1;
		}

		if(f.ninos_2.value>2 && (Math.ceil(f.edad_nino_2_3.value) < Math.ceil(f.edad_nino_2_2.value)))
		{
			alert('Por favor, la edad del niño 3 ha de ser igual o superior a la del niño 2');
			f.edad_nino_2_3.focus();
			return 1;
		}

		if(f.ninos_2.value>3 && (Math.ceil(f.edad_nino_2_4.value) < Math.ceil(f.edad_nino_2_3.value)))
		{
			alert('Por favor, la edad del niño 4 ha de ser igual o superior a la del niño 3');
			f.edad_nino_2_4.focus();
			return 1;
		}
	}
	if(f.ninos_3)
	{
		if(f.edad_nino_3_1.value<0 && f.ninos_3.value>0)
		{
			alert('Por favor, selecciona la edad del niño 1');
			f.edad_nino_3_1.focus();
			return 1;
		}
		if(f.edad_nino_3_2.value<0 && f.ninos_3.value>1)
		{
			alert('Por favor, selecciona la edad del niño 2');
			f.edad_nino_3_2.focus();
			return 1;
		}
		if(f.edad_nino_3_3 && f.edad_nino_3_3.value<0 && f.ninos_3.value>2)
		{
			alert('Por favor, selecciona la edad del niño 3');
			f.edad_nino_3_3.focus();
			return 1;
		}
		if(f.edad_nino_3_4 && f.edad_nino_3_4.value<0 && f.ninos_3.value>3)
		{
			alert('Por favor, selecciona la edad del niño 4');
			f.edad_nino_3_4.focus();
			return 1;
		}
		if(f.ninos_3.value>1 && Math.ceil(f.edad_nino_3_2.value) < Math.ceil(f.edad_nino_3_1.value))
		{
			alert('Por favor, la edad del niño 2 ha de ser igual o superior a la del niño 1');
			f.edad_nino_3_2.focus();
			return 1;
		}

		if(f.ninos_3.value>2 && (Math.ceil(f.edad_nino_3_3.value) < Math.ceil(f.edad_nino_3_2.value)))
		{
			alert('Por favor, la edad del niño 3 ha de ser igual o superior a la del niño 2');
			f.edad_nino_3_3.focus();
			return 1;
		}

		if(f.ninos_3.value>3 && (Math.ceil(f.edad_nino_3_4.value) < Math.ceil(f.edad_nino_3_3.value)))
		{
			alert('Por favor, la edad del niño 4 ha de ser igual o superior a la del niño 3');
			f.edad_nino_3_4.focus();
			return 1;
		}
	}
	return 0;
/*	 GENERA UN ERROR JAVASCRIPT AL ENVIAR EL FORMULARIO
	if(f.ninos_1)
	{
		for(n=1;n<=f.ninos_1.value;n++)
		{
			if(f['edad_nino_1_'+n].value<0 && f.ninos_1.value>0)	// no se ha seleccionado ninguna edad para el niño
			{
				alert('Por favor, selecciona la edad del niño '+n);
				f['edad_nino_1_'+n].focus();
				return;
			}
		}
	}
*/
}
function chk_traslado_con_vuelo(idTAC){
	if($('#TLHotel').val()=='0'){
		alert("Falta el hotel");
		return false;
	}else if($('#aeropuertos_todos').val()==''){
		alert("Falta un aeropuerto");
		return false;
	}
	if(!document.getElementById('vueloYhora')){
		alert("Falta el vuelo (si lo desconoce, haga clic en 'buscar vuelos' y seleccione 'UNKNOWN')");
		return false;
	}
	var tmp = $('#aeropuerto_asociado').val();
	var id_traslado_lugar_aeropuerto = $('#TL'+tmp).val();
	var tmp2 = $('#TLHotel').val().split("|");
	var id_prestatario = tmp2[0];
	var id_traslado_lugar_hotel = tmp2[1];
	$('#aeropuerto_hotel').val($('#aero-hot:checked').length);
	if($('#aero-hot:checked').length == 1){
		$('#origen').val(id_traslado_lugar_aeropuerto);
		$('#destino').val(id_traslado_lugar_hotel);
	}else{
		$('#origen').val(id_traslado_lugar_hotel);
		$('#destino').val(id_traslado_lugar_aeropuerto);
	}
	$('#presta').val(id_prestatario);
	muestra_buscando();
	$('#frm_busc_tras_con_vuel'+idTAC).submit();
}

function check_reserva_buscar_paquete_por_fecha(f) {
	if ($('#id_zona_pais').val() == 0) {
		alert('Ha de seleccionar un país.');
		return false;
	}
	if ($('#permitir_cualquier_zona').val() == 0 && $('id_zona').val() == 0) {
		alert('Ha de seleccionar una zona.');
		return false;
	}
	if ($('#fecha_entrada').val() == 0) {
		alert('No existe una fecha válida seleccionada.');
		return false;
	}
	if ($('#adultos_1').val() == 0) {
		alert('Ha de seleccionar más de un adulto (Ocupación 1).');
		return false;
	}
	if ($('#ninos_2').val() > 0 && $('#adultos_2').val() == 0) {
		alert('No se pueden realizar búsquedas con niños únicamente (Ocupación 2).');
		return false;
	}
	if ($('#ninos_3').val() > 0 && $('#adultos_3').val() == 0) {
		alert('No se pueden realizar búsquedas con niños únicamente (Ocupación 3).');
		return false;
	}
	if ($('#adultos_3').val() > 0 && $('#adultos_2').val() == 0) {
		alert('Las ocupaciones han de ser contiguas.');
		return false;
	}

        var error = '';

	error += new String(check_dias(f));
	if (error.length > 0) {
		alert(error);
		return false;
	}
}