
function objetoAjax(){
        var xmlhttp=false;
        try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
                try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }
        return xmlhttp;
}

function postAjax(url,param,func) {
        var ajax = objetoAjax();
        if (!param) param = "";
        if (!func) func = function(ajax) { if (ajax.readyState==4) eval(ajax.responseText); };

        var func2 = function() { func( ajax ); };
        ajax.open("POST", url);
        ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        ajax.setRequestHeader("Content-length", param.length);
        ajax.setRequestHeader("Connection", "close");
        ajax.onreadystatechange=func2;
        ajax.send(param);   
}

function load_hotels(ajax){
        if (ajax.readyState==4){
		var str = '<label for="f_combo_hotel" class="left">Hotel: *</label> <select name="f_combo_hotel" id="f_combo_hotel" class="combo" onChange="javascript:reset_input_hotel();"> '+ajax.responseText+' </select>';
                document.getElementById("container_combo_hotel").innerHTML = str;
        }
}

function reset_combo_hotels(){                                                            
        document.getElementById("f_combo_hotel").selectedIndex = 0;
}

function reset_input_hotel(){
        document.getElementById("f_hotel").value = "";
}

function validar_form_comentario(){
	if (!validar_campo("f_autor")){ alert("El campo AUTOR es obligatorio."); return; }
	if (!validar_campo("f_email")){ alert("El campo EMAIL es obligatorio."); return; }
    if (!validar_campo("f_provincia")){ alert("Debe seleccionar la provincia en que se encuentra el hotel"); return; }     
	if (!validar_campo("f_hotel") && !validar_campo("f_combo_hotel")){ alert("Si no encuentra el hotel en la lista,\ndebe introducir el nombre del hotel en el campo Hotel nuevo:"); return; }

	if (!validar_campo("f_comentario")){ alert("El campo COMENTARIO es obligatorio."); return;  }
	if (confirm("¿Confirma que desea enviar el comentario?")){ document.form_comentario.submit(); }
}

function validar_form_contactar(){
	if (!validar_campo("f_nombre")){ alert("El campo NOMBRE es obligatorio."); return; }
	if (!validar_campo("f_email")){ alert("El campo EMAIL es obligatorio."); return; }
	if (!validar_campo("f_asunto")){ alert("El campo ASUNTO es obligatorio."); return; }
	if (!validar_campo("f_mensaje")){ alert("El campo MENSAJE es obligatorio."); return; }
	if (confirm("¿Confirma que desea enviar el mensaje?")){
		document.form_contactar.action = "contactar.php?accion=email";
		document.form_contactar.submit();
	}
}

function validar_campo(campo){
	if (document.getElementById(campo).value == null || document.getElementById(campo).value == "0" || document.getElementById(campo).value == '' || document.getElementById(campo).value == ' '){
		return (false);	
	}
	return true;
}

function buscar_hotel(){
	alert("El buscador NO está operativo.\nDisculpen las moléstias.")
}


