﻿/**
 * Devuelve si un campo esta en blanco.
 */
function getElement(frm2, name) {
	var i;
	var j;
	var s;
	var frm;
	for (i = 0; i < document.forms.length; i++) {
		frm = document.forms[i];
		for (j = 0; j < frm.length; j++) {
			s = frm.elements[j].name;
			if (s.search(name) != -1) {
				return frm.elements[j];
			}
		}
	}
}

function ComprobarFechas(Entrada, Salida, Idioma) {
	var i;
	var di;
	var df;
	var diDd;
	var diMm;
	var diYy;
	var dfDd;
	var dfMm;
	var dfYy;
	var Hoy= new Date()
	var dhDd;
	var dhMm;
	var dhYy;
	
	// Llamamos a la funcion getElement para comprobar los campos
	di = getElement(document.forms[0], Entrada);
	df = getElement(document.forms[0], Salida);
	
	// Si uno de los dos campos esta en blanco mostramos el mensaje
    if ((di != undefined) || (df != undefined))
    {
        diDd = new String(di.value.substring(0,di.value.indexOf("/")))
        diMm = new String(di.value.substring(di.value.indexOf("/")+1,di.value.lastIndexOf("/")));
        diYy = new String(di.value.substring(di.value.lastIndexOf("/")+1,di.value.length));

        dfDd = new String(df.value.substring(0,df.value.indexOf("/")))
        dfMm = new String(df.value.substring(df.value.indexOf("/")+1,df.value.lastIndexOf("/")));
        dfYy = new String(df.value.substring(df.value.lastIndexOf("/")+1,df.value.length));

        dhDd = String("" + Hoy.getDate());
        dhMm = String("" + Hoy.getMonth());
        dhYy = String("" + Hoy.getFullYear());
        
	    if ((di.value == "") || (df.value == "") || (dfYy + dfMm + dfDd) <= (diYy + diMm + diDd) || (diDd < "01") || (diDd > "31") || (dfDd < "01") || (dfDd > "31"))
	    {
	    switch (Idioma)
	    {
          case "ca":
              alert("Error a les dates d'entrada i sortida");
              break;
          case "es":
              alert("Error en las fechas de entrada y salida");              
              break;
          case "fr":
              alert("Choisisez les dates d'arrivée et dèpart");              
              break;
          default:    
              alert("Error on the arrival and departure dates");              
              break;
        }     
		di.focus();
		return false;
	  }
	}
	return true;
}

function PopWindow()
{
window.open('http://localhost/webguest/hoteles/FrmOHoteles.aspx?hotel=999&idioma=ca','Vectork','width=800,height=450,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no,top=50,left=50');
}

function PopDetalle(peticion, dbg)
{
    window.open('../disponibilidad/FrmOtrosDias.aspx?pet=' + peticion + '&dbg=' + dbg, 'Vectork', 'width=670,height=150,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=300,left=80');
    return false;
}

function PopDetalleSql(peticion, idioma)
{
    window.open('../disponibilidad/VerPlanning.aspx?pet=' + peticion + '&id=' + idioma, 'Vectork', 'width=670,height=150,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=300,left=80');
    return false;
}


function ReOfertas(hotel, idioma)
{
    window.top.location.href = '../ofertas/PortalOfertas.aspx?ht=' + hotel + '&id=' + idioma
    return false;
}

function RePeticiones(hotel, idioma, portal, agencia, entrada, salida, regimen, tiphab1, adultosh1, nensh1, brasaolh1, tiphab2, adultosh2, nensh2, brasaolh2)
{
    window.top.location.href = '../peticiones/frmPeticion.aspx?hotel=' + hotel + '&idioma=' + idioma + '&prt=' + portal + '&age=' + agencia + '&en=' + entrada + '&sa=' + salida + '&rg=' + regimen + '&th1=' + tiphab1 + '&p1=' + adultosh1 + '&n1=' + nensh1 + '&c1=' + brasaolh1 + '&th2=' + tiphab2 + '&p2=' + adultosh2 + '&n2=' + nensh2 + '&c2=' + brasaolh2
    return false;
}



function PopAgencias()
{
  window.open('../agencias/FrmAgencias.aspx' ,'Vectork','width=300,height=200,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,top=300,left=500');
}

function CloseWindow()
{
  window.alert();
}

function Calendario(ctl, xx, yy)
{
    var PopupWindow=null;
    settings='width=275,height=185,left=' + xx + ',top=' + yy +',location=no,directories=no, menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';
    PopupWindow=window.open('../Generales/Calendario.aspx?Ctl=' + ctl,'NomVentana', settings);
    PopupWindow.focus();
}





