// JavaScript Document

// FECHA

var pong;
function makeArray(n){
  this.length = n;
  for (i=1;i<=n;i++){
    this[i]=0;
  }
  return this;
}

function displayDate() {
  var this_month = new makeArray(12);
  this_month[0]  = "Enero";
  this_month[1]  = "Febrero";
  this_month[2]  = "Marzo";
  this_month[3]  = "Abril";
  this_month[4]  = "Mayo";
  this_month[5]  = "Junio";
  this_month[6]  = "Julio";
  this_month[7]  = "Agosto";
  this_month[8]  = "Septiembre";
  this_month[9]  = "Octubre";
  this_month[10] = "Noviembre";
  this_month[11] = "Diciembre";

  var this_day_e = new makeArray(7);
  this_day_e[0]  = "Domingo";
  this_day_e[1]  = "Lunes";
  this_day_e[2]  = "Martes";
  this_day_e[3]  = "Miércoles";
  this_day_e[4]  = "Jueves";
  this_day_e[5]  = "Viernes";
  this_day_e[6]  = "Sábado";

  var today = new Date();
  var day   = today.getDate();
  var month = today.getMonth();
  var year  = today.getYear();
  var dia = today.getDay();
    if (year < 1000) {
       year += 1900; }
  return( day + " de " + this_month[month] + " " + year);
}

// MENÚ PRINCIPAL

var MenuPrincipal = new Array(5);
MenuPrincipal[0] = new Array(4);
MenuPrincipal[0][0] = "b0";  // id de la imagen que hace de boton
MenuPrincipal[0][1] = "img/cabecera/menu/b1_on.gif";
MenuPrincipal[0][2] = "img/cabecera/menu/b1_off.gif";
MenuPrincipal[0][3] = "alojamientos.php";

MenuPrincipal[1] = new Array(4);
MenuPrincipal[1][0] = "b1";  // id de la imagen que hace de boton
MenuPrincipal[1][1] = "img/cabecera/menu/b2_on.gif";
MenuPrincipal[1][2] = "img/cabecera/menu/b2_off.gif";
MenuPrincipal[1][3] = "ofertas_promociones.php";

MenuPrincipal[2] = new Array(4);
MenuPrincipal[2][0] = "b2";  // id de la imagen que hace de boton
MenuPrincipal[2][1] = "img/cabecera/menu/b3_on.gif";
MenuPrincipal[2][2] = "img/cabecera/menu/b3_off.gif";
MenuPrincipal[2][3] = "info_reservas.php";

MenuPrincipal[3] = new Array(4);
MenuPrincipal[3][0] = "b3";  // id de la imagen que hace de boton
MenuPrincipal[3][1] = "img/cabecera/menu/b4_on.gif";
MenuPrincipal[3][2] = "img/cabecera/menu/b4_off.gif";
MenuPrincipal[3][3] = "reuniones_eventos.html";

MenuPrincipal[4] = new Array(4);
MenuPrincipal[4][0] = "b4";  // id de la imagen que hace de boton
MenuPrincipal[4][1] = "img/cabecera/menu/b5_on.gif";
MenuPrincipal[4][2] = "img/cabecera/menu/b5_off.gif";
//MenuPrincipal[4][3] = "clubberh.php";
MenuPrincipal[4][3] = "clubberh.html";

/*MenuPrincipal[5] = new Array(4);
MenuPrincipal[5][0] = "b4";  // id de la imagen que hace de boton
MenuPrincipal[5][1] = "img/cabecera/menu/b5_on.gif";
MenuPrincipal[5][2] = "img/cabecera/menu/b5_off.gif";
MenuPrincipal[5][3] = "clubberh2.php";
*/

function stopEvent(e) {
    if (!e) e = window.event;
    if (e.stopPropagation) {
        e.stopPropagation();
    } else {
        e.cancelBubble = true;
    }
}


function seleccionaMenu(id){

	// desactivamos todas las opciones  del menu
	desactivar();
		
	// activamos solo la seleccionada
	document.getElementById(MenuPrincipal[id][0]).src = MenuPrincipal[id][1];
	document.getElementById(MenuPrincipal[id][0]).onmouseout = stopEvent;
	
	// hacemos la llamada de Ajax
	TomyAjaxRapido.peticion(MenuPrincipal[id][3], 'contenidocentral');
}	

// MENÚ INFERIOR

var MenuInferior = new Array(4);
MenuInferior[0] = new Array(4);
MenuInferior[0][0] = "inf0";  // id de la imagen que hace de boton
MenuInferior[0][1] = "img/pie/menp_1_on.gif";
MenuInferior[0][2] = "img/pie/menp_1_off.gif";
MenuInferior[0][3] = "nosotros.html";

MenuInferior[1] = new Array(4);
MenuInferior[1][0] = "inf1";  // id de la imagen que hace de boton
MenuInferior[1][1] = "img/pie/menp_2_on.gif";
MenuInferior[1][2] = "img/pie/menp_2_off.gif";
MenuInferior[1][3] = "recursos_humanos.html";

MenuInferior[2] = new Array(4);
MenuInferior[2][0] = "inf2";  // id de la imagen que hace de boton
MenuInferior[2][1] = "img/pie/menp_3_on.gif";
MenuInferior[2][2] = "img/pie/menp_3_off.gif";
MenuInferior[2][3] = "contacto.html";

MenuInferior[3] = new Array(4);
MenuInferior[3][0] = "inf3";  // id de la imagen que hace de boton
MenuInferior[3][1] = "img/pie/menp_4_on.gif";
MenuInferior[3][2] = "img/pie/menp_4_off.gif";
MenuInferior[3][3] = "";

function seleccionaMenuInf(id){
	// desactivamos todas las opciones  del menu
	desactivar();
				
	// activamos solo la seleccionada
	document.getElementById(MenuInferior[id][0]).src = MenuInferior[id][1];
	document.getElementById(MenuInferior[id][0]).onmouseout = stopEvent;
	
	// hacemos la llamada de Ajax
	if(id == 3){
		muestra_pagina('aviso_legal.html');
	}else{
		TomyAjaxRapido.peticion(MenuInferior[id][3], 'contenidocentral');
	}	
}	
//TomyDebug.ver = true;

function desactivar(){
	for(i=0; i<MenuPrincipal.length; i++){
		document.getElementById(MenuPrincipal[i][0]).src = MenuPrincipal[i][2];
		document.getElementById(MenuPrincipal[i][0]).onmouseout = function(){MM_swapImgRestore();};		
	}

	for(i=0; i<MenuInferior.length; i++){
		if(i != 1){
			document.getElementById(MenuInferior[i][0]).src = MenuInferior[i][2];
			document.getElementById(MenuInferior[i][0]).onmouseout = function(){MM_swapImgRestore();};
		}	
	}
}



// MM FUNCTIONS

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// CARGA ONLOAD
window.onload=function(){
	// TomyAjaxRapido.peticion('home.php', 'contenidocentral');
	MM_preloadImages('img/cabecera/menu/b1_on.gif','img/cabecera/menu/b2_on.gif','img/cabecera/menu/b3_on.gif','img/cabecera/menu/b4_on.gif','img/cabecera/menu/b5_on.gif','img/cabecera/menu/b6_on.gif','img/pie/menp_1_on.gif','img/pie/menp_2_on.gif','img/pie/menp_3_on.gif','img/pie/menp_4_on.gif');	
}


// UP-DOWN NUMERICO

function addEvent(obj, evType, fn, useCapture){
        if (obj.addEventListener){
                obj.addEventListener(evType, fn, useCapture);
                return true;
        } else if (obj.attachEvent){
                var r = obj.attachEvent("on"+evType, fn);
                return r;
        }
        return false;
}

function removeEvent(obj, evType, fn, useCapture){
        if (obj.removeEventListener){
                obj.removeEventListener(evType, fn, useCapture);
                return true;
        } else if (obj.detachEvent){
                var r = obj.detachEvent("on"+evType, fn);
                return r;
        }
        return false;
}

if(!String.prototype.trim) String.prototype.trim = function() { return this.replace(/^\s*/,'').replace(/\s*$/, ''); }

var incrementalInputController;

// Encapsulate the Timer and incrementalInput objects
(function() {

// WEBFX Timer : http://www.webfx.com/
function Timer(nPauseTime) {
        this._pauseTime = typeof nPauseTime == "undefined" ? 1000 : nPauseTime;
        this._timer = null;
        this._isStarted = false;
}

Timer.prototype.start = function () {
        if (this.isStarted())
                this.stop();
        var oThis = this;
        this._timer = window.setTimeout(function () {
                if (typeof oThis.ontimer == "function")
                        oThis.ontimer();
        }, this._pauseTime);
        this._isStarted = false;
};

Timer.prototype.stop = function () {
        if (this._timer != null)
                window.clearTimeout(this._timer);
        this._isStarted = false;
};

Timer.prototype.isStarted = function () {
        return this._isStarted;
};

Timer.prototype.getPauseTime = function () {
        return this._pauseTime;
};

Timer.prototype.setPauseTime = function (nPauseTime) {
        this._pauseTime = nPauseTime;
};

function incrementalInput(inp, range, increment, classInc, classDec) {
        if(!inp || !range) return;

        this._inp = inp;
        this._buttonInc;
        this._buttonDec;
        this._value;
        this._classInc = classInc;
        this._classDec = classDec;
        this._minv = Number(range[0]);
        this._maxv = Number(range[1]);
        this._incBase = Number(increment) || 1;
        this._precision = 0;
        if(increment.indexOf('.') != -1) {
                this._precision = increment.substr(increment.indexOf('.')+1, increment.length);
                this._precision = this._precision.length;
        }

        this._increment;
        this._timerInc = 1000;
        this._timer = new Timer(1000);
        this._stop = false;
        this._key = false;

        this._events = {

                dec: function(e) {
                        self._increment = -self._incBase;
                        self.updateValue();
                        return false;
                },
                inc: function(e) {
                        self._increment = self._incBase;
                        self.updateValue();
                        return false;
                },
                keydec: function(e) {
                        var kc;
                        if (!e) var e = window.event;

                        if (e.keyCode) kc = e.keyCode;
                        else if (e.charCode) kc = e.charCode;

                        if ( kc != 13 || self._key ) return true;

                        self._key = true;
                        self._increment = -self._incBase;
                        self._timerInc = 1000;
                        self.updateValue();
                        return false;
                },
                keyinc: function(e) {
                        var kc;
                        if (!e) var e = window.event;

                        if (e.keyCode) kc = e.keyCode;
                        else if (e.charCode) kc = e.charCode;


                        if ( kc != 13 || self._key ) return true;

                        self._key = true;
                        self._increment = self._incBase;
                        self._timerInc = 1000;
                        self.updateValue();
                        return false;
                },
                clearTimer: function(e) {
                        self._key = false;
                        self._events.stopTimer();
                },
                stopTimer: function(e) {
                        self._timer.stop();
                        self._timerInc = 1000;
                        self._timer.setPauseTime(self._timerInc);
                },
                onchange: function(e){
                        var value = Number(parseFloat(self._inp.value).toFixed(self._precision));

                        if( Number(value % self._incBase).toFixed(self._precision) != self._incBase ) {
                                value -= Number(parseFloat(value % self._incBase)).toFixed(self._precision);
                        };
                        if(value < self._minv) value = self._minv;
                        else if(value > self._maxv) value = self._maxv;
                        self._inp.value = parseFloat(value).toFixed(self._precision);
                }
        };

        this.updateValue = function() {
                if(self._inp.disabled) {
                        stopTimer();
                        return;
                }


                var value = Number(parseFloat(self._inp.value).toFixed(self._precision));
                var stop = self._timerInc == 0 ? true : false;

                if( Math.abs(Number(value % self._incBase).toFixed(self._precision)) != self._incBase ) {
                        value -= Number(parseFloat(value % self._incBase)).toFixed(self._precision);
                }

                value += Number(parseFloat(self._increment).toFixed(self._precision));

                if(value < self._minv) {
                        value = self._minv;
                        stop = true;
                } else if(value > self._maxv) {
                        value = self._maxv;
                        stop = true;
                }

                self._inp.value = parseFloat(value).toFixed(self._precision);

                if(self._timerInc > 50) {
                        self._timerInc = 50 + Math.round(((self._timerInc - 50) / 1.8));
                }

                self._timer.setPauseTime(self._timerInc);
                if(!stop) self._timer.start();
        }

        this.construct = function() {
                var h = self._inp.offsetHeight;

                self._inp.onchange = self._events.onchange;

                self._buttonInc = document.createElement('button');
                self._buttonDec = document.createElement('button');

                if(self._classDec) self._buttonDec.className = self._classDec;
                if(self._classInc) self._buttonInc.className = self._classInc;

                self._buttonDec.setAttribute('type','button');
                self._buttonInc.setAttribute('type','button');

                self._buttonDec.appendChild(document.createTextNode('-'));
                self._buttonInc.appendChild(document.createTextNode('+'));

                self._buttonDec.onmousedown = self._events.dec;
                self._buttonInc.onmousedown = self._events.inc;

                addEvent(self._buttonDec, "keypress", self._events.keydec, true);
                addEvent(self._buttonDec, "keyup", self._events.clearTimer, true);
                addEvent(self._buttonInc, "keypress", self._events.keyinc, true);
                addEvent(self._buttonInc, "keyup", self._events.clearTimer, true);

                self._buttonInc.onmouseout  = self._events.stopTimer;
                self._buttonDec.onmouseout  = self._events.stopTimer;

                addEvent(document, 'mouseup', self._events.stopTimer, false);

                if(self._inp.nextSibling) {
                        self._inp.parentNode.insertBefore( self._buttonDec, self._inp.nextSibling );
                        self._inp.parentNode.insertBefore( self._buttonInc, self._inp.nextSibling );
                } else {
                        self._inp.parentNode.appendChild( self._buttonInc );
                        self._inp.parentNode.appendChild( self._buttonDec );
                };
        };

        var self = this;

        self._timer.ontimer = function() { self.updateValue(); }
        self.construct();
}

incremetalInputController = {
        inputCollection: [],
        constructor: function() {

                if(!document.getElementById || !document.createElement) return;

                // TODO : cut the regExps down to readable levels - they are hideous at present...
                var regExp_1 = /fd_incremental_inp_range_([-]{0,1}[0-9]+(f[0-9]+){0,1}){1}_([-]{0,1}[0-9]+(f[0-9]+){0,1}){1}/ig;
                var regExp_2 = /fd_increment_([0-9]+(f[0-9]+){0,1}){1}/ig;
                var regExp_3 = /fd_classname_inc_([\-_0-9a-zA-Z]+){1}/ig;
                var regExp_4 = /fd_classname_dec_([\-_0-9a-zA-Z]+){1}/ig;

                var inputCollection = document.getElementsByTagName('input');
                var obj, range, classname, classes, classInc, classDec, increment;

                for(var i = 0, inp; inp = inputCollection[i]; i++) {
                        if(inp.type == 'text' && inp.className && inp.className.search(regExp_1) != -1) {
                                classes = inp.className.split(' ');
                                increment = 1;
                                range = [0,0];
                                classInc = "";
                                classDec = "";

                                for(var z = 0, classname; classname = classes[z]; z++) {
                                        if(classname.search(regExp_1) != -1) {
                                                range = classname.trim();
                                                range = range.replace(/fd_incremental_inp_range_/ig, '');
                                                range = range.replace(/f/g,'.');
                                                range = range.split('_');
                                        } else if(classname.search(regExp_2) != -1) {
                                                increment = classname.trim();
                                                increment = increment.replace(/fd_increment_/ig, '');
                                                increment = increment.replace('f','.');
                                        } else if(classname.search(regExp_3) != -1) {
                                                classInc = classname.trim();
                                                classInc = classInc.replace(/fd_classname_inc_/ig, '');
                                        } else if(classname.search(regExp_4) != -1) {
                                                classDec = classname.trim();
                                                classDec = classDec.replace(/fd_classname_dec_/ig, '');
                                        }
                                }
                                obj = new incrementalInput(inp, range, increment, classInc, classDec);
                                incremetalInputController.inputCollection.push(obj);
                        }
                }
        }
}

// Close and call anonymous function
})();

addEvent(window, 'load', incremetalInputController.constructor, true);


// CALENDARIO

/*
        A "Reservation Date" example using two datePickers
        --------------------------------------------------

        * Functionality
        
        1. When the page loads:
                - We clear the value of the two inputs (to clear any values cached by the browser)
                - We set "onchange" event handler on the startDate input to call the setReservationDates function
        2. When a start date is selected
                - We set the low range of the endDate datePicker to be the start date the user has just selected
                - If the endDate input already has a date stipulated and the date falls before the new start date then we clear the input's value
                
        * Caveats (aren't there always)

        - This demo has been written for dates that have NOT been split across three inputs
        
*/

function makeTwoChars(inp) {
        return String(inp).length < 2 ? "0" + inp : inp;
}

function initialiseInputs() {
        // Clear any old values from the inputs (that might be cached by the browser after a page reload)
        document.getElementById("sd").value = "";
        document.getElementById("ed").value = "";

        // Add the onchange event handler to the start date input
        document.getElementById("sd").onchange = setReservationDates;
}
function setReservationDates(e) {
        // Check the associated datePicker object is available (be safe)
        if(!("sd" in datePickerController.datePickers)) {
                return;
        }
        
        // Check the value of the input is a date of the correct format
        var dt = datePickerController.dateFormat(this.value, datePickerController.datePickers["sd"].format.charAt(0) == "m");
        
        // If the input's value cannot be parsed as a valid date then return
        if(dt == 0) return;

        // Grab the value set within the endDate input and parse it using the dateFormat method
        // N.B: The second parameter to the dateFormat function, if TRUE, tells the function to favour the m-d-y date format
        var edv = datePickerController.dateFormat(document.getElementById("ed").value, datePickerController.datePickers["ed"].format.charAt(0) == "m");

        // Grab the end date datePicker Objects
        var ed = datePickerController.datePickers["ed"];

        ed.setRangeLow( dt );
        
        // If theres a value already present within the end date input and it's smaller than the start date
        // then clear the end date value
        if(edv < dt) {
                document.getElementById("ed").value = "";
        }
}

// datePickerController.addEvent(window, 'load', initialiseInputs);



buscarAlojamiento = function(){
	llamada = new TomyAjax(); 
	llamada.url = "alojamientos_busqueda.php";
	llamada.parametros = TomyForm.Valores("formBusca");
	llamada.metodo = "POST";
	llamada.resultado = "resultado_buscarAlojamiento";
	llamada.llamada();
}

resultado_buscarAlojamiento = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado){
		document.getElementById("contenidocentral").innerHTML = resultado;			
	}
};

var ContenidoVolver;
detalleAlojamiento = function(id){
	ContenidoVolver = document.getElementById("contenidocentral").innerHTML;  
	TomyAjaxRapido.peticion('ficha_hotel.php?id='+id, 'contenidocentral');
}

Volver = function(){
	if(document.getElementById("contenidocentral")){
		document.getElementById("contenidocentral").innerHTML = ContenidoVolver;  
	}
}

mostrarDetalle = function(campo){
	document.getElementById("detalle_hotel").innerHTML = document.getElementById(campo).value;
}	

VerOferta = function(id){
	ContenidoVolver = document.getElementById("contenidocentral").innerHTML;  
	TomyAjaxRapido.peticion('ofertas_promociones_detalle.php?id='+id, 'contenidocentral');
}

	
	
registro_empresas = function(){
	if(document.registro.password.value.length == 0){
		alert('Debe introducir su contraseña');
	}else if(document.registro.password.value != document.registro.password2.value){
		alert('No coincide la contraseña');
	}else if(document.registro.tratamiento.selectedIndex == 0){
		alert('Debe introducir su tratamiento');
	}else if(document.registro.nombre.value.length == 0){
		alert('Debe introducir su nombre');	
	}else if(document.registro.apellidos.value.length == 0){
		alert('Debe introducir sus apellidos');		
	}else if(document.registro.empresa.value.length == 0){
		alert('Debe introducir su empresa');	
	}else if(document.registro.direccion.value.length == 0){
		alert('Debe introducir su dirección');		
	}else if(document.registro.localidad.value.length == 0){
		alert('Debe introducir su localidad');		
	}else if(document.registro.cp.value.length == 0){
		alert('Debe introducir su código postal');		
	}else if(document.registro.provincia.selectedIndex == 0){
		alert('Debe introducir su provincia');		
	}else if(document.registro.tlf_fijo.value.length == 0){
		alert('Debe introducir su telefono fijo');		
	}else if(TomyForm.ValidaEmail(document.registro.email.value) != 1){
		alert('Debe introducir su email');		
	}else if(!document.registro.chk_programa.checked){
		alert('Debe aceptar el programa de fidelización');			
	}else{	
		llamada = new TomyAjax(); 
		llamada.url = "registro.php";
		llamada.parametros = "tipo_registro=E" + TomyForm.Valores('registro');
		llamada.metodo = "POST";
		llamada.resultado = "resultado_registro";
		llamada.llamada();						
	}	
}

resultado_registro = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado){
		if(resultado == "-1"){
			alert("el email ya esta registrado por otro usuario");
		}else{
			document.getElementById("cb_colder").innerHTML = resultado;			
		}	
	}
};


registro_particulares = function(){
	if(document.registro.password.value.length == 0){
		alert('Debe introducir su contraseña');
	}else if(document.registro.password.value != document.registro.password2.value){
		alert('No coincide la contraseña');
	}else if(document.registro.tratamiento.selectedIndex == 0){
		alert('Debe introducir su tratamiento');
	}else if(document.registro.nombre.value.length == 0){
		alert('Debe introducir su nombre');	
	}else if(document.registro.apellidos.value.length == 0){
		alert('Debe introducir sus apellidos');				
	}else if(document.registro.dni.value.length == 0){
		alert('Debe introducir su dni');	
	}else if(document.registro.fech_nacimiento.value.length == 0){
		alert('Debe introducir su fecha de nacimiento');	
	}else if(document.registro.direccion.value.length == 0){
		alert('Debe introducir su direccion');
			
			
	}else if(document.registro.localidad.value.length == 0){
		alert('Debe introducir su localidad');		
	}else if(document.registro.cp.value.length == 0){
		alert('Debe introducir su código postal');		
	}else if(document.registro.provincia.selectedIndex == 0){
		alert('Debe introducir su provincia');		
		
	}else if(document.registro.tlf_fijo.value.length == 0){
		alert('Debe introducir su telefono fijo');		
	}else if(document.registro.tlf_movil.value.length == 0){
		alert('Debe introducir su telefono movil');		
		
	}else if(TomyForm.ValidaEmail(document.registro.email.value) != 1){
		alert('Debe introducir su email');		
	}else if(!document.registro.chk_programa.checked){
		alert('Debe aceptar el programa de fidelización');			
	}else{	
		llamada = new TomyAjax(); 
		llamada.url = "registro.php";
		llamada.parametros = "tipo_registro=P" + TomyForm.Valores('registro');
		llamada.metodo = "POST";
		llamada.resultado = "resultado_registro";
		llamada.llamada();						
	}	
}


resultado_login = function()
{
	resultado = TomyAjaxResultado(llamada);
	
	if (resultado)
	{
		if (resultado == "-1")
		{
			alert ("Usuario y/o contraseña incorrectos.");
		}//fin if
		else
		{
			//document.getElementById("login_clubberh").innerHTML = resultado;	
			TomyAjaxRapido.peticion('clubberh2.php', 'login_clubberh');	
			TomyAjaxRapido.peticion('cluberh_home_logado.php', 'cb_colder');	
		}//fin else	
	}//fin if
};//fin funcion


lojin = function()
{
	if (document.login.txtUsuario.value.length == 0)
	{
		alert ('Debe introducir su usuario');
	}//fin if
	else if (document.login.txtPass.value.length == 0)
	{
		alert ('Debe introducir su usuario');
	}//fin else if
	else 
	{	
		llamada = new TomyAjax(); 
		llamada.url = "login.php";
		llamada.parametros = "usuario=" + document.login.txtUsuario.value + "&pass=" + document.login.txtPass.value;
		llamada.metodo = "POST";
		llamada.resultado = "resultado_login";
		llamada.llamada();						
	}//fin else
};//fin funcion

resultado_cambioDatos = function()
{
	resultado = TomyAjaxResultado(llamada);
	
	if(resultado)
	{
		if(resultado == "-1")
		{
			alert("el email ya esta registrado por otro usuario");
		}
		else if (resultado == "-2")
		{
			alert("el usuario es incorrecto");
		}
		else if (resultado == "-3")
		{
			alert("ha ocurrido un error al guardar los datos");
		}
		else if(resultado == "-4")
		{
			alert("El usuario es incorrecto");
		}
		else if(resultado == "1")
		{
			TomyAjaxRapido.peticion('clubberh2.php', 'login_clubberh');
			TomyAjaxRapido.peticion('clubberh_datos_modificados_ok.html', 'cb_colder');			
		}	
		else
		{
			alert(resultado);
		}
	}
};


cambiarDatosUsuario = function()
{
	 if(document.cambiaRegistro.tratamiento.selectedIndex == 0)
	 {
		alert('Debe introducir su tratamiento');
	}
	else if(document.cambiaRegistro.txtNombre.value.length == 0)
	{
		alert('Debe introducir su nombre');	
	}
	else if(document.cambiaRegistro.txtApellidos.value.length == 0)
	{
		alert('Debe introducir sus apellidos');				
	}
	else if(document.cambiaRegistro.txtDni.value.length == 0)
	{
		alert('Debe introducir su dni');	
	}
	else if(document.cambiaRegistro.txtFechaN.value.length == 0)
	{
		alert('Debe introducir su fecha de nacimiento');	
	}
	else if(document.cambiaRegistro.txtDireccion.value.length == 0)
	{
		alert('Debe introducir su direccion');	
	}
	else if(document.cambiaRegistro.txtLocalidad.value.length == 0)
	{
		alert('Debe introducir su localidad');		
	}
	else if(document.cambiaRegistro.txtCp.value.length == 0)
	{
		alert('Debe introducir su código postal');		
	}
	else if(document.cambiaRegistro.provincia.selectedIndex == 0)
	{
		alert('Debe introducir su provincia');		
	}
	else if(document.cambiaRegistro.txtTelefono.value.length == 0)
	{
		alert('Debe introducir su telefono fijo');		
	}
	else if(document.cambiaRegistro.txtMovil.value.length == 0)
	{
		alert('Debe introducir su telefono movil');		
	}
	else if(document.cambiaRegistro.txtEmail.value.length == 0)
	{
		alert('Debe introducir su email');		
	}
	else
	{	
		llamada = new TomyAjax(); 
		llamada.url = "cambiar_datos.php";
		llamada.parametros = "tipo_registro=p&tipoCambio=datos&tratamiento=" + document.cambiaRegistro.tratamiento.value + "&nombre=" + document.cambiaRegistro.txtNombre.value + "&apellidos=" + document.cambiaRegistro.txtApellidos.value + "&dni=" + document.cambiaRegistro.txtDni.value + "&fechaN=" + document.cambiaRegistro.txtFechaN.value + "&direccion=" + document.cambiaRegistro.txtDireccion.value + "&localidad=" + document.cambiaRegistro.txtLocalidad.value + "&cp=" + document.cambiaRegistro.txtCp.value + "&pais=" + document.cambiaRegistro.txtPais.value + "&provincia=" + document.cambiaRegistro.provincia.value + "&telefono=" + document.cambiaRegistro.txtTelefono.value + "&movil=" + document.cambiaRegistro.txtMovil.value + "&email=" + document.cambiaRegistro.txtEmail.value + "&emailViejo=" + document.cambiaRegistro.hdnEmail.value;
		llamada.metodo = "POST";
		llamada.resultado = "resultado_cambioDatos";
		llamada.llamada();						
	}	
};//fin funcion

cambiarDatosEmpresa = function()
{
	 if(document.cambiaRegistro.tratamiento.selectedIndex == 0)
	 {
		alert('Debe introducir su tratamiento');
	}
	else if(document.cambiaRegistro.txtNombre.value.length == 0)
	{
		alert('Debe introducir su nombre');	
	}
	else if(document.cambiaRegistro.txtApellidos.value.length == 0)
	{
		alert('Debe introducir sus apellidos');				
	}
	else if(document.cambiaRegistro.txtEmpresa.value.length == 0)
	{
		alert('Debe introducir el nombre de su empresa');	
	}
	else if(document.cambiaRegistro.txtDireccion.value.length == 0)
	{
		alert('Debe introducir su direccion');	
	}
	else if(document.cambiaRegistro.txtLocalidad.value.length == 0)
	{
		alert('Debe introducir su localidad');		
	}
	else if(document.cambiaRegistro.txtCp.value.length == 0)
	{
		alert('Debe introducir su código postal');		
	}
	else if(document.cambiaRegistro.provincia.selectedIndex == 0)
	{
		alert('Debe introducir su provincia');		
	}
	else if(document.cambiaRegistro.txtTelefono.value.length == 0)
	{
		alert('Debe introducir su telefono fijo');		
	}
	else if(document.cambiaRegistro.txtFax.value.length == 0)
	{
		alert('Debe introducir su fax');		
	}
	else if(document.cambiaRegistro.txtEmail.value.length == 0)
	{
		alert('Debe introducir su email');		
	}
	else
	{	
		llamada = new TomyAjax(); 
		llamada.url = "cambiar_datos.php";
		llamada.parametros = "tipo_registro="+ document.cambiaRegistro.hdnTipo.value + "&tipoCambio=datos&tratamiento=" + document.cambiaRegistro.tratamiento.value + "&nombre=" + document.cambiaRegistro.txtNombre.value + "&apellidos=" + document.cambiaRegistro.txtApellidos.value + "&empresa=" + document.cambiaRegistro.txtEmpresa.value +  "&direccion=" + document.cambiaRegistro.txtDireccion.value + "&localidad=" + document.cambiaRegistro.txtLocalidad.value + "&cp=" + document.cambiaRegistro.txtCp.value + "&pais=" + document.cambiaRegistro.txtPais.value + "&provincia=" + document.cambiaRegistro.provincia.value + "&telefono=" + document.cambiaRegistro.txtTelefono.value + "&fax=" + document.cambiaRegistro.txtFax.value + "&email=" + document.cambiaRegistro.txtEmail.value + "&emailViejo=" + document.cambiaRegistro.hdnEmail.value;
		llamada.metodo = "POST";
		llamada.resultado = "resultado_cambioDatos";
		llamada.llamada();						
	}	
};//fin funcion

/* version antigua
cambiarPass = function()
{
	 if(document.cambiaRegistro.txtUsuario.value.length== 0)
	 {
		alert('Debe introducir su usuario');
	}
	else if(document.cambiaRegistro.txtPass.value.length == 0)
	{
		alert('Debe introducir su nuevo password');	
	}
	else
	{
		llamada = new TomyAjax(); 
		llamada.url = "cambiar_datos.php";
		llamada.parametros = "tipo_registro="+ document.cambiaRegistro.hdnTipo.value + "&tipoCambio=pass&usuario=" + document.cambiaRegistro.txtUsuario.value + "&pass=" + document.cambiaRegistro.txtPass.value;
		llamada.metodo = "POST";
		llamada.resultado = "resultado_cambioDatos";
		llamada.llamada();						
	}
};
*/
cambiarPass = function(){
	document.getElementById("modcontra1").style.display="none";
	document.getElementById("modcontra2").style.display="none";
	document.getElementById("cab_mod_pass").src="img/clubberh/txt_modif_contrasena.gif";
	document.getElementById("mod_contrasena").style.display="block";
}

cambiarPass2 = function(){
	if(document.cambiaRegistro.nueva_contrasena.value == document.cambiaRegistro.nueva_contrasena2.value && document.cambiaRegistro.nueva_contrasena.value.length > 0){
		llamada = new TomyAjax(); 
		llamada.url = "cambiar_datos.php";
		llamada.parametros = "tipo_registro="+ document.cambiaRegistro.hdnTipo.value + "&tipoCambio=pass&usuario=" + document.cambiaRegistro.txtUsuario.value + "&pass=" + document.cambiaRegistro.nueva_contrasena.value;
		llamada.metodo = "POST";
		llamada.resultado = "resultado_cambioDatos";
		llamada.llamada();		
	}else{
		alert('Deben coincidir la contraseña y su confirmación');
	}
	
}



resultado_solicitudReserva = function()
{
	resultado = TomyAjaxResultado(llamada);
	
	if(resultado)
	{
		if(resultado == -1)
		{
			alert("El usuario es incorrecto.");
		}
		else if (resultado == -2)
		{
			// alert("Ha ocurrido un error al guardar los datos.");
			document.getElementById("inf_form").innerHTML = "<img src='img/infor_reservas/txt_solicitud_error.gif'>";			
		}
		else if(resultado == 1)
		{
			//alert("Solicitud enviada con éxito.");
			document.getElementById("inf_form").innerHTML = "<img src='img/infor_reservas/txt_solicitud_ok.gif'>";
		}	
		else
		{
			alert(resultado);
		}
	}
};//fin funcion

enviar_reserva = function()
{
	var param;

	if (document.soilicitud1.chkCondiciones.checked)
	{
		var info = "oferta="+ document.soilicitud1.cb_oferta.value;
		info += "&alojamiento=" + document.soilicitud1.cb_alojamiento.value;
		info += "&provincia=" + document.soilicitud1.cb_provincia.value;
		info += "&tipo_alojamiento=" + document.soilicitud1.cb_tipo.value;
		info += "&fecha_entrada=" + document.soilicitud1.sd.value;
		info += "&fecha_salida=" + document.soilicitud1.ed.value;
		info += "&noches=" + document.soilicitud1.noches.value;
		info += "&adultos=" + document.soilicitud1.adultos.value;
		info += "&ninos=" + document.soilicitud1.ninos.value;
		info += "&regimen=" + document.getElementById("cb_regimen").value;
		info += "&idProcedencia=0"; //0= id de procedencia de Ber 
		
		if(document.soilicitud1.txtUsuario.value.length > 0)
		{
			param = info + "&usuario="+ document.soilicitud1.txtUsuario.value;
		}//fin if
		else
		{
			var datos = "&nombre="+ document.soilicitud1.txtNombre.value;
			datos += "&apellidos=" + document.soilicitud1.txtApellidos.value;
			datos += "&direccion=" + document.soilicitud1.txtDireccion.value;
			datos += "&cp=" + document.soilicitud1.txtCp.value;
			datos += "&localidad=" + document.soilicitud1.txtLocalidad.value;
			datos += "&provincia=" + document.soilicitud1.cmbProvincia.value;
			datos += "&email=" + document.soilicitud1.txtEmail.value;
			datos += "&movil=" + document.soilicitud1.txtMovil.value;
			datos += "&telefono=" + document.soilicitud1.txtTelefono.value;
			
			document.soilicitud1.chkLSSI.value = (document.soilicitud1.chkLSSI.checked) ? 1 : 0;
			
			datos += "&lssi=" + document.soilicitud1.chkLSSI.value;
			
			param = info + datos;
		}//fin else
		
		llamada = new TomyAjax(); 
		llamada.url = "ingresar_solicitud.php";
		llamada.parametros = param ;
		llamada.metodo = "POST";
		llamada.resultado = "resultado_solicitudReserva";
		llamada.llamada();	
	}//fin if
	else
	{
		alert("Para continuar debe aceptar las condiciones generales.");
		return;
	}//fin else
}//fin funcion

paso3 = function()
{
	if(document.soilicitud1.txtUsuario.value.length == 0)
	{		
		if (document.soilicitud1.txtNombre.value.length == 0)
		{
			alert("Debe introducir su nombre");
			return;
		}//fin if
		else if (document.soilicitud1.txtApellidos.value.length == 0)
		{
			alert("Debe introducir sus apellidos");
			return;
		}//fin if
		else if (document.soilicitud1.txtDireccion.value.length == 0)
		{
			alert("Debe introducir su dirección postal");
			return;
		}//fin if
		else if (document.soilicitud1.txtCp.value.length == 0)
		{
			alert("Debe introducir su código postal");
			return;
		}//fin if
		else if (document.soilicitud1.txtLocalidad.value.length == 0)
		{
			alert("Debe introducir su localidad");
			return;
		}//fin if
		else if (document.soilicitud1.cmbProvincia.value == 0)
		{
			alert("Debe elegir su provincia");
			return;
		}//fin if
		else if (document.soilicitud1.txtEmail.value.length == 0)
		{
			alert("Debe introducir su E-mail");
			return;
		}//fin if
		else if (document.soilicitud1.txtTelefono.value.length == 0)
		{
			alert("Debe introducir su teléfono");
			return;
		}//fin if
	}//fin if

	document.getElementById("paso1").style.display = "none";
	document.getElementById("paso2").style.display = "none";
	document.getElementById("paso3").style.display = "block";			
};//fin funcion

function paso2() //para la solicitud de reserva
{
	if (document.soilicitud1.cb_alojamiento.value == 0)
	{
		alert("Debes elegir un alojamiento");
	}//fin if
	else if (document.soilicitud1.cb_provincia.value == 0)
	{
		alert("Debes elegir una provincia");		
	}//fin elseif
	else if (document.soilicitud1.cb_tipo.value == 0)
	{
		alert("Debes elegir un tipo de alojamiento");				
	}
	else if (document.getElementById("cb_regimen").value == 0)
	{
		alert("Debes elegir un regimen");				
	}
	else if (document.soilicitud1.sd.value == "")
	{
		alert("Debes elegir una fecha de entrada");				
	}
	else if (document.soilicitud1.ed.value == "")
	{
		alert("Debes elegir una fecha de salida");				
	}
	else if (document.soilicitud1.noches.value == "")
	{
		alert("Debes elegir un nº de noches");				
	}
	else if (document.soilicitud1.adultos.value == "")
	{
		alert("Debes elegir un nº de adultos");				
	}
	else if (document.soilicitud1.ninos.value == "")
	{
		alert("Debes elegir un nº de niños");				
	}
	else
	{	
		document.getElementById("paso1").style.display = "none";
		document.getElementById("paso2").style.display = "block";
	}//fin else
}//fin if

irpaso = function(pag){
	document.getElementById("paso1").style.display = "none";
	document.getElementById("paso2").style.display = "none";
	document.getElementById("paso3").style.display = "none";
	document.getElementById("paso"+pag).style.display = "block";
}



/*************CARGA DE LOS COMBOS DE SOLICITUD**************************************/

sacaComboAlojamientos = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado)
	{
		document.getElementById("comboAlojamientos").innerHTML = resultado;
		//cargaOpsCombo(1, 'sacaComboOfertas');	
	}
};

sacaComboOfertas = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado)
	{
		document.getElementById("comboOfertas").innerHTML = resultado;
		cargaOpsCombo(2, 'sacaComboTiposAlojamiento', document.getElementById("cb_alojamiento").value);	
	}
};

sacaComboTiposAlojamiento = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado)
	{
		document.getElementById("comboTipoAlojamiento").innerHTML = resultado;
		cargaOpsCombo(3, 'sacaComboRegimenes');	
	}	
	
};

sacaComboRegimenes = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado)
	{
		document.getElementById("comboRegimenes").innerHTML = resultado;
	}		
};


cargaOpsCombo = function(op, func, valor)
{
	if(document.soilicitud1.cb_provincia.value != 0)
	{
		document.getElementById("cb_alojamiento").disabled = false;
		
		if (func == "sacaComboRegimenes")
		{
			valor = document.getElementById("cb_tipo").value + "&idAlojamiento=" + document.getElementById("cb_alojamiento").value;
		}//fin if
		
		/*if (op == 2)
		{
			valor = document.getElementById("cb_alojamiento").value;
		}//fin if
		*/
		
		if (func == "sacaComboTiposAlojamiento" && document.getElementById("cb_oferta").value > 0)
		{
			valor = document.getElementById("cb_oferta").value + "&conOferta=1";
		}//fin if
		
		llamada = new TomyAjax(); 
		llamada.url = "carga_combo.php";
		llamada.parametros = "id="+ valor +"&op="+op;
		llamada.metodo = "POST";
		llamada.resultado = func;
		llamada.llamada();
		
		if (document.soilicitud1.cb_alojamiento.value != 0)
		{
			//document.getElementById("cb_regimen").disabled = false;
			document.getElementById("cb_oferta").disabled = false;
			document.getElementById("cb_tipo").disabled = false;
		}//fin if
		else
		{
			document.getElementById("cb_oferta").disabled = false;
			document.getElementById("cb_oferta").value = 0;
			document.getElementById("cb_tipo").disabled = false;
			document.getElementById("cb_tipo").value = 0;
			document.getElementById("cb_regimen").disabled = false;
			document.getElementById("cb_regimen").value = 0;	
		}//fin if
		
		if (document.getElementById("cb_tipo").value != 0)
		{
			document.getElementById("cb_regimen").disabled = false;
		}//fin if
	}//fin if
	else
	{
		document.getElementById("cb_alojamiento").value = 0;
		document.getElementById("cb_oferta").value = 0;
		document.getElementById("cb_tipo").value = 0;
		document.getElementById("cb_regimen").value = 0;
		document.getElementById("cb_alojamiento").disabled = false;
		document.getElementById("cb_oferta").disabled = false;
		document.getElementById("cb_tipo").disabled = false;
		document.getElementById("cb_regimen").disabled = false;
	}//fin else
};//fin funcion

/*************///CARGA DE LOS COMBOS DE SOLICITUD**************************************/

// REGISTRO DEL BOLETIN

grabar_boletin = function(){
	if(TomyForm.ValidaEmail(document.boletin.email.value) != 1){
		alert("Debe introducir su email");
	}else{
		llamada = new TomyAjax(); 
		llamada.url = "boletin_insertar.php";
		llamada.parametros = "email=" + document.boletin.email.value + "&tipo=" + document.boletin.tipo.value;
		llamada.metodo = "POST";
		llamada.resultado = "resultado_grabar_boletin";
		llamada.llamada();
	}
}

resultado_grabar_boletin = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado){
		if(document.getElementById("subscrip_news")){
			document.getElementById("subscrip_news").innerHTML = resultado;					
		}else if(document.getElementById("nuestrasnoti_alojamientos")){
			document.getElementById("nuestrasnoti_alojamientos").innerHTML = resultado;
		}							
	}
};

// MENSAJES DE ALERTA GLOBALES

var contenido_contenidocentral;
muestra_pagina = function(url){
	llamada = new TomyAjax(); 
	llamada.url = url;
	llamada.metodo = "GET";
	llamada.resultado = "resultado_muestra_pagina";
	llamada.llamada();	
}

resultado_muestra_pagina = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado){
		contenido_contenedor = document.getElementById("contenidocentral").innerHTML;
		document.getElementById("menu").style.display = "none";
		document.getElementById("pie").style.display = "none";
		
		document.getElementById("cabecera").style.opacity = ".5";
		document.getElementById("cabecera").style.filter = "alpha(opacity=50)";
	
		document.getElementById("contenidocentral").innerHTML = resultado;									
	}
};

cerrar_pagina = function(){
	document.getElementById("menu").style.display = "block";
	document.getElementById("pie").style.display = "block";
	document.getElementById("cabecera").style.opacity = "1";
	document.getElementById("cabecera").style.filter = "alpha(opacity=100)";
	document.getElementById("contenidocentral").innerHTML = contenido_contenedor;
}

// formulario de contacto

contactar = function(){
	if(document.formcontacto.cb_establecimiento.selectedIndex == 0){
		alert('Debe seleccionar el establecimiento');
	}else if(document.formcontacto.nombre.value.length == 0){
		alert('Debe introducir su nombre');	
	}else if(TomyForm.ValidaEmail(document.formcontacto.email.value) != 1){
		alert('Debe introducir un email valido');	
	}else if(document.formcontacto.comentrio.value.length == 0){
		alert('Debe introducir su comentrio');	
	}else{
		llamada = new TomyAjax(); 
		llamada.url = "contacto_enviar.php";
		llamada.parametros = TomyForm.Valores('formcontacto');
		llamada.metodo = "POST";
		llamada.resultado = "resultado_contactar";
		llamada.llamada();		
	}
}

resultado_contactar = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado){
		document.getElementById("formconsulta").innerHTML = resultado;									
	}
};

// recordar contrasena
recordarContra = function(){
	if(TomyForm.ValidaEmail(document.recordar_form.txtEmail.value) != 1){
		alert('Debe introducir un email valido');
	}else{
		llamada = new TomyAjax(); 
		llamada.url = "recordarPass_enviar.php";
		llamada.parametros = "email="+document.recordar_form.txtEmail.value;
		llamada.metodo = "POST";
		llamada.resultado = "resultado_recordarContra";
		llamada.llamada();
	}	
}
resultado_recordarContra = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado){
		document.getElementById("login_clubberh").innerHTML = resultado;									
	}
};

// desconectar sesion

desconectar = function(){
	llamada = new TomyAjax(); 
	llamada.url = "desconectar.php";
	llamada.metodo = "GET";
	llamada.resultado = "resultado_cerrar";
	llamada.llamada();	
}
resultado_cerrar = function(){
	resultado = TomyAjaxResultado(llamada);
	if(resultado){
		seleccionaMenu(4);
	}	
}

// opciones del menu personal

MenuPers = function(id){
	if(id == 1){
		TomyAjaxRapido.peticion('cluberh_datospersonales.php', 'cb_colder');
		document.getElementById("btn_datospers").src = "img/clubberh/btn_datospersonales_on.gif";
		document.getElementById("btn_infoest").src = "img/clubberh/btn_infoestancias.gif";
	}else if(id == 2){
		TomyAjaxRapido.peticion('cluberh_infoestancias.html', 'cb_colder');
		document.getElementById("btn_datospers").src = "img/clubberh/btn_datospersonales.gif";
		document.getElementById("btn_infoest").src = "img/clubberh/btn_infoestancias_on.gif";
	}

}


