function obj_ajax()
{
	var xmlhttp;

	if(window.XMLHttpRequest)		xmlhttp = new XMLHttpRequest();
	else if(window.ActiveXObject)	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	else							alert("Your browser does not support XMLHTTP!");
	
	return xmlhttp;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function get_window_data()
{
	var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal;
	
	if(typeof window.innerWidth != 'undefined')
	{
		widthViewport = window.innerWidth-17;
		heightViewport = window.innerHeight-17;
	}
	else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0)
	{
		widthViewport = document.documentElement.clientWidth;
		heightViewport = document.documentElement.clientHeight;
	}
	else
	{
		widthViewport = document.getElementsByTagName('body')[0].clientWidth;
		heightViewport = document.getElementsByTagName('body')[0].clientHeight;
	}

    xScroll = self.pageXOffset || (document.documentElement.scrollLeft+document.body.scrollLeft);
    yScroll = self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop);
    widthTotal = Math.max(document.documentElement.scrollWidth,document.body.scrollWidth,widthViewport);
    heightTotal = Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,heightViewport);
	
    return [widthTotal,heightTotal];
} 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function dark()
{
	if(!document.getElementById('fondo'))
	{
		var t = get_window_data();
	
		var fnd = document.createElement('div');
		fnd.setAttribute('id','fondo');
		fnd.style.position = 'absolute';
		fnd.style.top = '0px';
		fnd.style.left = '0px';
		fnd.style.zIndex = 1;
		fnd.style.filter = 'alpha(opacity=50)';
		fnd.style.opacity = '0.5';
		fnd.style.width = t[0] + 'px';
		fnd.style.height = t[1] + 'px';
		fnd.style.backgroundColor = '#000000';
		document.body.appendChild(fnd);
	}
	else
		document.body.removeChild(document.getElementById('fondo'));
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function add_error(input,txt,estilo)
{
	clear_error(input,estilo);
	var sp = document.createElement('p');
	sp.className = estilo;
	sp.innerHTML = txt;
	document.getElementById(input).parentNode.appendChild(sp);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function clear_error(input, estilo)
{
	var nodes = document.getElementById(input).parentNode.childNodes;
	
	for(var i = 0; i < nodes.length;i++)
	{
		if(nodes[i].className == estilo)
			document.getElementById(input).parentNode.removeChild(nodes[i]);
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function numeric_only(e)
{
	var keycode;
	
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	
	if(((keycode >= 48) && (keycode <= 57)) || (keycode == 0) || (keycode == 8))	return true;
	else																			return false;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function press_enter(e)
{
	var keycode;
	
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	
	if(keycode == 13)	return true;
	else				return false;	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function coord_only(e)
{
	var keycode;
	
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	
	if(((keycode >= 48) && (keycode <= 57)) || (keycode == 0) || (keycode == 8) || (keycode == 45) || (keycode == 46))	return true;
	else																												return false;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function valid_email(value)
{
	if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(value))	return true;
	else																return false;
} 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function is_number(value){
	if (!/^([0-9])*$/.test(value))
		return false;
	else
		return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function acceder(e)
{
	var keycode;
	
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	if(keycode == '13')	document.frm_login.submit(); 	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function check_frm_presupuesto_portada()
{
	valid = 1;
	
	var d1 = document.getElementById('fecha_hora_recogida').value.split('@');
	var d1_date = d1[0].split('/');
	var d1_hour = d1[1].split(':');
	var d2 = document.getElementById('fecha_hora_devolucion').value.split('@');
	var d2_date = d2[0].split('/');
	var d2_hour = d2[1].split(':');
	
	var d_recogida = new Date(d1_date[2], d1_date[1], d1_date[0], d1_hour[0], d1_hour[1], 0);
	var d_devolucion = new Date(d2_date[2], d2_date[1], d2_date[0], d2_hour[0], d2_hour[1], 0);

	if (d_devolucion < d_recogida) {
		add_error('fecha_hora_devolucion','Fecha devolución debe ser posterior a la de recogida','alerta');
		valid = 0;
  } else
  	clear_error('fecha_hora_devolucion','alerta');

	if(document.getElementById('id_lugar_recogida').value == '0')	
	{
		add_error('id_lugar_recogida','Campo obligatorio','alerta');
		valid = 0;
	}
	else
		clear_error('id_lugar_recogida','alerta');

	if(document.getElementById('id_lugar_devolucion').value == '0')	
	{
		add_error('id_lugar_devolucion','Campo obligatorio','alerta');
		valid = 0;
	}
	else
		clear_error('id_lugar_devolucion','alerta');

	if(document.getElementById('email').value == '')	
	{
		add_error('email','Campo obligatorio','alerta');
		valid = 0;
	}
	else if (!valid_email(document.getElementById('email').value))
	{
		add_error('email','Formato incorrecto','alerta');
		valid = 0;
	}
	else
		clear_error('email','alerta');
	
	if (valid == 1)		document.frm_presupuesto_portada.submit();
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function check_frm_presupuesto()
{
	var valid = 1;

	if(document.getElementById('nombre').value == '')	
	{
		add_error('nombre','No ha introducido el nombre','alerta');
		if (valid==1)
			document.getElementById('nombre').focus();
		valid = 0;		
	}
	else
		clear_error('nombre','alerta');

	if(document.getElementById('apellidos').value == '')	
	{
		add_error('apellidos','No ha introducido los apellidos','alerta');
		if (valid==1)
			document.getElementById('apellidos').focus();		
		valid = 0;
	}
	else
		clear_error('apellidos','alerta');

	if ((document.getElementById('fecha_nacimiento').value != '') && (!check_date(document.getElementById('fecha_nacimiento').value)))
	{
		add_error('fecha_nacimiento','El formato no es válido','alerta');
		if (valid==1)
			document.getElementById('fecha_nacimiento').focus();		
		valid = 0;
	}
	else
		clear_error('fecha_nacimiento','alerta');		

	if(document.getElementById('email').value == '')	
	{
		add_error('email','No ha introducido el email','alerta');
		if (valid==1)
			document.getElementById('email').focus();		
		valid = 0;
	}
	else if (!valid_email(document.getElementById('email').value))
	{
		add_error('email','La dirección de email no tiene un formato correcto','alerta');
		if (valid==1)
			document.getElementById('email').focus();		
		valid = 0;
	}
	else if (document.getElementById('email').value!=document.getElementById('email_confirmar').value)
	{
		add_error('email_confirmar','La dirección de email debe coincidir con la de reconfirmación','alerta');
		if (valid==1)
			document.getElementById('email_confirmar').focus();		
		clear_error('email','alerta');
		valid = 0;
	}
	else {
		clear_error('email','alerta');
		clear_error('email_confirmar','alerta');
	}


	// Campo número de cliente numérico
	/*if ((!document.getElementById('num_cliente').disabled) && (document.getElementById('num_cliente').value != '')
			&& (!is_number(document.getElementById('num_cliente').value))) {
			add_error('num_cliente','El número de cliente debe ser numérico','alerta');
			valid = 0;
	} else if ((!document.getElementById('num_cliente').disabled) && (document.getElementById('num_cliente').value == '')) {
			add_error('num_cliente','Por favor, indique el número de cliente','alerta');
			valid = 0;
	} else {
		clear_error('num_cliente','alerta');
	}*/

	var d1 = document.getElementById('fecha_hora_recogida').value.split('@');
	var d1_date = d1[0].split('/');
	var d1_hour = d1[1].split(':');
	var d2 = document.getElementById('fecha_hora_devolucion').value.split('@');
	var d2_date = d2[0].split('/');
	var d2_hour = d2[1].split(':');
	
	var d_recogida = new Date(d1_date[2], d1_date[1], d1_date[0], d1_hour[0], d1_hour[1], 0);
	var d_devolucion = new Date(d2_date[2], d2_date[1], d2_date[0], d2_hour[0], d2_hour[1], 0);

	if (d_devolucion < d_recogida) {
		add_error('fecha_hora_devolucion','Fecha devolución debe ser posterior a la de recogida','alerta');
		if (valid==1)
			document.getElementById('fecha_hora_devolucion').focus();		
		valid = 0;
  } else
  	clear_error('fecha_hora_devolucion','alerta');

	//clear_error('num_vuelo_llegada','alerta');
	clear_error('domicilio_hotel_llegada','alerta');
	//clear_error('num_vuelo_salida','alerta');
	clear_error('domicilio_hotel_salida','alerta');
	
	// Número de vuelo o Dirección / Hotel
	if (document.getElementById('id_lugar_recogida').value == 1) {
		/*if (document.getElementById('num_vuelo_llegada').value == '') {
			add_error('num_vuelo_llegada','No ha introducido el vuelo de llegada','alerta');
			valid = 0;
		} else {
			clear_error('num_vuelo_llegada','alerta');
		}*/
	} else if (document.getElementById('id_lugar_recogida').value == 3) {
		if (document.getElementById('domicilio_hotel_llegada').value == '') {
			add_error('domicilio_hotel_llegada','No ha introducido el domicilio o hotel','alerta');
			if (valid==1)
				document.getElementById('domicilio_hotel_llegada').focus();		
			valid = 0;
		} else {
			clear_error('domicilio_hotel_llegada','alerta');
		}
	}

	if (document.getElementById('id_lugar_devolucion').value == 1) {
		/*if (document.getElementById('num_vuelo_salida').value == '') {
			add_error('num_vuelo_salida','No ha introducido el vuelo de salida','alerta');
			valid = 0;
		} else {
			clear_error('num_vuelo_salida','alerta');
		}*/
	} else if (document.getElementById('id_lugar_devolucion').value == 3) {		
		if (document.getElementById('domicilio_hotel_salida').value == '') {
			add_error('domicilio_hotel_salida','No ha introducido el domicilio o hotel','alerta');
			if (valid==1)
				document.getElementById('domicilio_hotel_salida').focus();		
			valid = 0;
		} else {
			clear_error('domicilio_hotel_salida','alerta');
		}
	}
	
	// Opciones
	var inputs = document.getElementById('tbl_opciones').getElementsByTagName('input');
	
	for(var j=0;j<inputs.length;j++) {
		if (inputs[j].type == 'checkbox') {
			if (document.getElementById('cantidad['+inputs[j].id+']'))
				clear_error('cantidad['+inputs[j].id+']','alerta_mini');
			if (inputs[j].checked) {
				if (document.getElementById('cantidad['+inputs[j].id+']')) {
					if (document.getElementById('cantidad['+inputs[j].id+']').value == '') {
						add_error('cantidad['+inputs[j].id+']','No ha introducido la cantidad','alerta_mini');
						if (valid==1)
							document.getElementById('cantidad['+inputs[j].id+']').focus();		
						valid = 0;
					} else if (!is_number(document.getElementById('cantidad['+inputs[j].id+']').value)) {
						add_error('cantidad['+inputs[j].id+']','La cantidad debe ser numérica','alerta_mini');
						if (valid==1)
							document.getElementById('cantidad['+inputs[j].id+']').focus();		
						valid = 0;
					}
				}
			}
		}
	}

	if(valid == 1) {
		document.frm_presupuesto.reserva.value = 1;
		document.frm_presupuesto.submit();
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function check_frm_presupuesto_fecha_nacimiento()
{
	if ((document.getElementById('fecha_nacimiento').value != '') && (!check_date(document.getElementById('fecha_nacimiento').value)))
	{
		add_error('fecha_nacimiento','El formato no es válido','alerta');
	}
	else
		clear_error('fecha_nacimiento','alerta');		
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function check_frm_reserva()
{
	var valid = 1;

	var d1 = document.getElementById('fecha_hora_recogida').value.split('@');
	var d1_date = d1[0].split('/');
	var d1_hour = d1[1].split(':');
	var d2 = document.getElementById('fecha_hora_devolucion').value.split('@');
	var d2_date = d2[0].split('/');
	var d2_hour = d2[1].split(':');
	
	var d_recogida = new Date(d1_date[2], d1_date[1], d1_date[0], d1_hour[0], d1_hour[1], 0);
	var d_devolucion = new Date(d2_date[2], d2_date[1], d2_date[0], d2_hour[0], d2_hour[1], 0);

	if (d_devolucion < d_recogida) {
		add_error('fecha_hora_devolucion','Fecha devolución debe ser posterior a la de recogida','alerta');
		if (valid==1)
			document.getElementById('fecha_hora_devolucion').focus();		
		valid = 0;
  } else
  	clear_error('fecha_hora_devolucion','alerta');

	clear_error('num_vuelo_llegada','alerta');
	clear_error('domicilio_hotel_llegada','alerta');
	clear_error('num_vuelo_salida','alerta');
	clear_error('domicilio_hotel_salida','alerta');
	
	// Número de vuelo o Dirección / Hotel
	if (document.getElementById('id_lugar_recogida').value == 1) {
		if (document.getElementById('num_vuelo_llegada').value == '') {
			add_error('num_vuelo_llegada','No ha introducido el vuelo de llegada','alerta');
			if (valid==1)
				document.getElementById('num_vuelo_llegada').focus();		
			valid = 0;
		} else {
			clear_error('num_vuelo_llegada','alerta');
		}
	} else if (document.getElementById('id_lugar_recogida').value == 3) {
		if (document.getElementById('domicilio_hotel_llegada').value == '') {
			add_error('domicilio_hotel_llegada','No ha introducido el domicilio o hotel','alerta');
			if (valid==1)
				document.getElementById('domicilio_hotel_llegada').focus();		
			valid = 0;
		} else {
			clear_error('domicilio_hotel_llegada','alerta');
		}
	}

	if (document.getElementById('id_lugar_devolucion').value == 1) {
		/*if (document.getElementById('num_vuelo_salida').value == '') {
			add_error('num_vuelo_salida','No ha introducido el vuelo de salida','alerta');
			valid = 0;
		} else {
			clear_error('num_vuelo_salida','alerta');
		}*/
	} else if (document.getElementById('id_lugar_devolucion').value == 3) {		
		if (document.getElementById('domicilio_hotel_salida').value == '') {
			add_error('domicilio_hotel_salida','No ha introducido el domicilio o hotel','alerta');
			if (valid==1)
				document.getElementById('domicilio_hotel_salida').focus();		
			valid = 0;
		} else {
			clear_error('domicilio_hotel_salida','alerta');
		}
	}
	
	// Opciones
	var inputs = document.getElementById('tbl_opciones').getElementsByTagName('input');
	
	for(var j=0;j<inputs.length;j++) {
		if (inputs[j].type == 'checkbox') {
			if (document.getElementById('cantidad['+inputs[j].id+']'))
				clear_error('cantidad['+inputs[j].id+']', 'alerta_mini');
			if (inputs[j].checked) {
				if (document.getElementById('cantidad['+inputs[j].id+']')) {
					if (document.getElementById('cantidad['+inputs[j].id+']').value == '') {
						add_error('cantidad['+inputs[j].id+']','No ha introducido la cantidad','alerta_mini');
						if (valid==1)
							document.getElementById('cantidad['+inputs[j].id+']').focus();		
						valid = 0;
					} else if (!is_number(document.getElementById('cantidad['+inputs[j].id+']').value)) {
						add_error('cantidad['+inputs[j].id+']','La cantidad debe ser numérica','alerta_mini');
						if (valid==1)
							document.getElementById('cantidad['+inputs[j].id+']').focus();		
						valid = 0;
					}
				}
			}
		}
	}

	if(document.getElementById('nombre').value == '')	
	{
		add_error('nombre','No ha introducido el nombre','alerta');
		if (valid==1)
			document.getElementById('nombre').focus();		
		valid = 0;
	}
	else
		clear_error('nombre','alerta');

	if(document.getElementById('apellidos').value == '')	
	{
		add_error('apellidos','No ha introducido los apellidos','alerta');
		if (valid==1)
			document.getElementById('apellidos').focus();		
		valid = 0;
	}
	else
		clear_error('apellidos','alerta');

	if ((document.getElementById('fecha_nacimiento').value != '') && (!check_date(document.getElementById('fecha_nacimiento').value)))
	{
		add_error('fecha_nacimiento','El formato no es válido','alerta');
		if (valid==1)
			document.getElementById('fecha_nacimiento').focus();		
		valid = 0;
	}
	else
		clear_error('fecha_nacimiento','alerta');		

	if((document.getElementById('tlf_fijo').value == '') && (document.getElementById('tlf_movil').value == ''))
	{
		add_error('tlf_fijo','No ha introducido al menos un número de teléfono','alerta');
		if (valid==1)
			document.getElementById('tlf_fijo').focus();		
		valid = 0;
	}
	else
		clear_error('tlf_fijo','alerta');

	if(document.getElementById('email').value == '')	
	{
		add_error('email','No ha introducido el email','alerta');
		if (valid==1)
			document.getElementById('email').focus();		
		valid = 0;
	}
	else if (!valid_email(document.getElementById('email').value))
	{
		add_error('email','La dirección de email no tiene un formato correcto','alerta');
		if (valid==1)
			document.getElementById('email').focus();		
		valid = 0;
	}
	else if (document.getElementById('email').value!=document.getElementById('email_confirmar').value)
	{
		add_error('email_confirmar','La dirección de email debe coincidir con la de reconfirmación','alerta');
		if (valid==1)
			document.getElementById('email_confirmar').focus();		
		clear_error('email','alerta');
		valid = 0;
	}
	else {
		clear_error('email','alerta');
		clear_error('email_confirmar','alerta');
	}

	if ((document.getElementById('dni_fecha_exp').value != '') && (!check_date(document.getElementById('dni_fecha_exp').value)))
	{
		add_error('dni_fecha_exp','El formato no es válido','alerta');
		if (valid==1)
			document.getElementById('dni_fecha_exp').focus();		
		valid = 0;
	}
	else
		clear_error('dni_fecha_exp','alerta');		

	if ((document.getElementById('permiso_fecha_exp').value != '') && (!check_date(document.getElementById('permiso_fecha_exp').value)))
	{
		add_error('permiso_fecha_exp','El formato no es válido','alerta');
		if (valid==1)
			document.getElementById('permiso_fecha_exp').focus();		
		valid = 0;
	}
	else
		clear_error('permiso_fecha_exp','alerta');

	// Campo número de cliente numérico
	/*if ((!document.getElementById('num_cliente').disabled) && (document.getElementById('num_cliente').value != '')
			&& (!is_number(document.getElementById('num_cliente').value))) {
			add_error('num_cliente','El número de cliente debe ser numérico','alerta');
			if (valid==1)
				document.getElementById('num_cliente').focus();		
			valid = 0;
	} else if ((!document.getElementById('num_cliente').disabled) && (document.getElementById('num_cliente').value == '')) {
			add_error('num_cliente','Por favor, indique el número de cliente','alerta');
			if (valid==1)
				document.getElementById('num_cliente').focus();		
			valid = 0;
	} else {
		clear_error('num_cliente','alerta');
	}*/

	if(valid == 1) {
		document.frm_reserva.reserva.value = 0;
		document.frm_reserva.submit();
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function check_frm_enviar_correo_portada()
{
	valid = 1;

	if(document.getElementById('nombre_enviar_correo').value == '')	
	{
		add_error('nombre_enviar_correo','El nombre es obligatorio','erroresPie');		
		valid = 0;
	}
	else
		clear_error('nombre_enviar_correo','erroresPie');

	if(document.getElementById('email_enviar_correo').value == '')	
	{
		if (valid == 1) {
			add_error('email_enviar_correo','El e-mail es obligatorio','erroresPie');
			valid = 0;
		}
	}
	else if (!valid_email(document.getElementById('email_enviar_correo').value))
	{
		if (valid == 1) {
			add_error('email_enviar_correo','Formato incorrecto de e-mail','erroresPie');
			valid = 0;
		}
	}
	else
		clear_error('email_enviar_correo','erroresPie');

	if(document.getElementById('asunto').value == '')	
	{
		if (valid == 1) {
			add_error('asunto','El asunto es obligatorio','erroresPie');
			valid = 0;
		}
	}
	else
		clear_error('asunto','erroresPie');	

	if (valid == 1)		document.frm_enviar_correo_portada.submit();
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function check_frm_solicitar_llamada_portada()
{
	valid = 1;

	if(document.getElementById('nombre_solicitar_llamada').value == '')	
	{
		add_error('nombre_solicitar_llamada','El nombre es obligatorio','erroresPie');		
		valid = 0;
	}
	else
		clear_error('nombre_solicitar_llamada','erroresPie');

	if(document.getElementById('telefono').value == '')	
	{
		if (valid == 1) {
			add_error('telefono','El teléfono es obligatorio','erroresPie');
			valid = 0;
		}
	}
	else
		clear_error('telefono','erroresPie');

	if(document.getElementById('horario').value == '0')	
	{
		if (valid == 1) {
			add_error('horario','El horario es obligatorio','erroresPie');
			valid = 0;
		}
	}
	else
		clear_error('horario','erroresPie');	

	if (valid == 1)		document.frm_solicitar_llamada_portada.submit();
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ya_es_cliente(objeto) {
	if (objeto.value == 1) {
		document.getElementById('num_cliente').disabled = false;
		//document.getElementById('num_cliente').value = 'Nº Cliente';
		document.getElementById('num_cliente').focus();
		
	} else {
		document.getElementById('num_cliente').value = '';
		document.getElementById('num_cliente').disabled = true;
		
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function check_airport_address() {
	if (document.getElementById('id_lugar_recogida').value == 1) {
		if (!document.getElementById('otros_modelos')) {
			document.getElementById('num_vuelo_llegada').disabled = false;
			document.getElementById('div_vuelo_llegada').style.display = 'block';
		}
		document.getElementById('domicilio_hotel_llegada').value = '';
		document.getElementById('domicilio_hotel_llegada').disabled = true;
		document.getElementById('div_domicilio_hotel_llegada').style.display = 'none';
	} else if (document.getElementById('id_lugar_recogida').value == 3) {
		if (!document.getElementById('otros_modelos')) {
			document.getElementById('num_vuelo_llegada').value = '';
			document.getElementById('num_vuelo_llegada').disabled = true;
			document.getElementById('div_vuelo_llegada').style.display = 'none';
		}
		document.getElementById('domicilio_hotel_llegada').disabled = false;
		document.getElementById('div_domicilio_hotel_llegada').style.display = 'block';
	} else {
		document.getElementById('domicilio_hotel_llegada').value = '';
		if (!document.getElementById('otros_modelos')) {
			document.getElementById('num_vuelo_llegada').value = '';
			document.getElementById('num_vuelo_llegada').disabled = true;
			document.getElementById('div_vuelo_llegada').style.display = 'none';
		}
		document.getElementById('domicilio_hotel_llegada').disabled = true;		
		document.getElementById('div_domicilio_hotel_llegada').style.display = 'none';
	}

	if (document.getElementById('id_lugar_devolucion').value == 1) {
		if (!document.getElementById('otros_modelos')) {
			document.getElementById('num_vuelo_salida').disabled = false;
			document.getElementById('div_vuelo_salida').style.display = 'block';
		}
		document.getElementById('domicilio_hotel_salida').value = '';
		document.getElementById('domicilio_hotel_salida').disabled = true;		
		document.getElementById('div_domicilio_hotel_salida').style.display = 'none';
	} else if (document.getElementById('id_lugar_devolucion').value == 3) {
		if (!document.getElementById('otros_modelos')) {
			document.getElementById('num_vuelo_salida').value = '';
			document.getElementById('num_vuelo_salida').disabled = true;
			document.getElementById('div_vuelo_salida').style.display = 'none';
		}
		document.getElementById('domicilio_hotel_salida').disabled = false;		
		document.getElementById('div_domicilio_hotel_salida').style.display = 'block';
	} else {
		if (!document.getElementById('otros_modelos')) {
			document.getElementById('num_vuelo_salida').value = '';
			document.getElementById('num_vuelo_salida').disabled = true;
			document.getElementById('div_vuelo_salida').style.display = 'none';
		}
		document.getElementById('domicilio_hotel_salida').value = '';		
		document.getElementById('domicilio_hotel_salida').disabled = true;		
		document.getElementById('div_domicilio_hotel_salida').style.display = 'none';
	}	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function cambiar_grupo() {
	idgrupo = document.getElementById('id_grupo_alquiler').value;
	document.getElementById('imagen_vehiculo').innerHTML = '<img style="margin: 40px 40px 40px 40px;" src="/img/frontend/rotating_arrow.gif"/>';
	var ajax = obj_ajax();	
	ajax.open('GET',url_app + 'vehiculos/recargar-vehiculos/' + idgrupo + '/',true);
	ajax.onreadystatechange = function(){
		if(ajax.readyState == 4){			
			var response = eval(ajax.responseText);
			//document.getElementById('id_vehiculo').innerHTML = response[0];	
			select_innerHTML(document.getElementById("id_vehiculo"),response[0]);
			document.getElementById('imagen_vehiculo').innerHTML = '<a href="'+response[1]+'" title="" id="foto_vehiculo_reserva"><img src="'+response[2]+'" alt="" /></a><span style="float:right;width:145px;">'+response[4]+'</span>';
			jQuery("a#foto_vehiculo_reserva").fancybox({
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'titlePosition' 	: 'over'
			});
		} 
	}
	ajax.send(null);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function cambiar_foto_vehiculo(idvehiculo) {
	document.getElementById('imagen_vehiculo').innerHTML = '<img style="margin: 40px 40px 40px 40px;" src="/img/frontend/rotating_arrow.gif"/>';
	var ajax = obj_ajax();
	ajax.open('GET',url_app + 'vehiculos/recargar-foto-vehiculo/' + idvehiculo + '/',true);
	ajax.onreadystatechange = function(){
		if(ajax.readyState == 4){			
			var response = eval(ajax.responseText);
			document.getElementById('imagen_vehiculo').innerHTML = '<a href="'+response[0]+'" title="" id="foto_vehiculo_reserva"><img src="'+response[1]+'" alt="" /></a><span style="float:right;width:145px;">'+response[3]+'</span>';
			jQuery("a#foto_vehiculo_reserva").fancybox({
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'titlePosition' 	: 'over'
			});
		} 
	}
	ajax.send(null);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function cambiar_opcion(objeto_check) {
	var inputs = document.getElementById('tbl_opciones').getElementsByTagName('input');
	if (objeto_check.checked) {
		for(i=0;i<inputs.length;i++) {
			if(inputs[i].name === 'cantidad['+objeto_check.id+']') {
				inputs[i].disabled = false;
				//inputs[i].value = 'Nº';
				inputs[i].focus();
				break;
			}
		}
	} else {
		for(i=0;i<inputs.length;i++) {
			if(inputs[i].name === 'cantidad['+objeto_check.id+']') {
				inputs[i].value = '';
				inputs[i].disabled = true;
				break;
			}
		}
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function filtro_vehiculos(obj) {
	// Categorías
	if (obj.name == 'categorias[]') {
		if (!obj.checked)
			document.getElementById("todos").checked = false;
		else {
			document.getElementById("todos").checked = true;
			for(i=0;i<document.getElementsByTagName("input").length;i++) {
				if(document.getElementsByTagName("input")[i].type == "checkbox") {
					if (document.getElementsByTagName("input")[i].name == 'categorias[]') {
						if (document.getElementsByTagName("input")[i].checked == false) {
							document.getElementById("todos").checked = false;
							break;
						}
					}
				}
			}
		}
	} else if (obj.name == 'todos') {
		if (obj.checked) {
			for(i=0;i<document.getElementsByTagName("input").length;i++) {
				if(document.getElementsByTagName("input")[i].type == "checkbox") {
					document.getElementsByTagName("input")[i].checked = true;
				}
			}
		} else {
			for(i=0;i<document.getElementsByTagName("input").length;i++) {
				if(document.getElementsByTagName("input")[i].type == "checkbox") {
					if (document.getElementsByTagName("input")[i].name == 'categorias[]') {
						document.getElementsByTagName("input")[i].checked = false;
					}
				}
			}
		}
	}

	var categorias = '';
	
	for(i=0;i<document.getElementsByTagName("input").length;i++) {
		if(document.getElementsByTagName("input")[i].type == "checkbox") {
			if ((document.getElementsByTagName("input")[i].checked) && (document.getElementsByTagName("input")[i].value > 0)) {
				categorias += document.getElementsByTagName("input")[i].value + '_';
			}
		}
	}
	
	if (categorias == '')
		categorias = '0_';
	
	var ajax = obj_ajax();
	ajax.open('GET',url_app + 'vehiculos/filtro/' + categorias.substring(0,categorias.length-1) + '/',true);
	ajax.onreadystatechange = function(){
		if(ajax.readyState == 4){
			document.getElementById('vehiculos_dinamico').innerHTML = ajax.responseText;
			jQuery("a[rel=fotos_vehiculo]").fancybox({
						'transitionIn'		: 'none',
						'transitionOut'		: 'none',
						'titleShow' 			: false
			});
		} 
	}
	ajax.send(null);
}

function check_date(field)
{
	// regular expression to match required date format
    re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;

    if(!field.match(re)) {
      return false;
    }

    return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function select_innerHTML(objeto,innerHTML){
/******
* select_innerHTML - corrige o bug do InnerHTML em selects no IE
* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Versão: 2.1 - 04/09/2007
* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
* @objeto(tipo HTMLobject): o select a ser alterado
* @innerHTML(tipo string): o novo valor do innerHTML
*******/
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
      
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if(document.getElementById('btn_frm_presupuesto_portada'))	document.getElementById('btn_frm_presupuesto_portada').onclick = function(){ check_frm_presupuesto_portada(); };
if(document.getElementById('btn_frm_enviar_correo_portada'))	document.getElementById('btn_frm_enviar_correo_portada').onclick = function(){ check_frm_enviar_correo_portada(); };
if(document.getElementById('btn_frm_solicitar_llamada_portada'))	document.getElementById('btn_frm_solicitar_llamada_portada').onclick = function(){ check_frm_solicitar_llamada_portada(); };
if(document.getElementById('btn_frm_presupuesto'))	{ 
	document.getElementById('btn_frm_presupuesto').onclick = function(){ check_frm_presupuesto(); };
	//ya_es_cliente(document.frm_presupuesto.es_cliente);
	check_airport_address();
	cambiar_foto_vehiculo(document.getElementById('id_vehiculo').value);
}
if(document.getElementById('btn_frm_reserva'))	{ 
	document.getElementById('btn_frm_reserva').onclick = function(){ check_frm_reserva(); };
	ya_es_cliente(document.frm_reserva.es_cliente);
	check_airport_address();
	cambiar_foto_vehiculo(document.getElementById('id_vehiculo').value);
}
