// JavaScript home.asp

function AbrirHotel(x){
    //alert(document.cerca_hotel.DataFi.value);
	//document.location.href='hotels_infohotel.asp?id=' + x
	//document.location.href='hotels_infohotel2.asp?id=' + x + "&Ini=" + document.cerca_hotel.DataIni.value + "&Fin=" + document.cerca_hotel.DataFi.value
	document.cerca_hotel.miHotel.value=x
	
    document.cerca_hotel.detall.value=-1;
	document.cerca_hotel.submit();
}

function AbrirListado(orden,categoria,FechaIni, FechaFin, paginaRegla)
{
    
	//window.location.href="cerca_hotels.asp?ordre=" + orden + "&idcategoria=" + categoria
	document.cerca_hotel.DataIni.value = FechaIni;
	document.cerca_hotel.DataFi.value = FechaFin;

	posarNits();

  document.cerca_hotel.hab1.value=0;
	document.cerca_hotel.hab2.value=0;
	document.cerca_hotel.hab3.value=1;
	document.cerca_hotel.hab4.value=0;
	
	document.cerca_hotel.nens.value=0;
	document.cerca_hotel.preu.value=0;
	
	document.cerca_hotel.Servei.checked=false;
   
  document.cerca_hotel.miOrden.value = orden
  document.cerca_hotel.miCategoria.value = categoria
  document.cerca_hotel.detall.value=-4;
    
	document.getElementById("paginaRegla").value = paginaRegla;

	document.cerca_hotel.submit();
}


function envia(){
	if (CapacitatNens()){
		registrarAceptacion("/_prgr01/clickBuscarHome.asp");
		document.cerca_hotel.detall.value=0;
		document.cerca_hotel.submit();
	}
}

function detallada(){
	if (CapacitatNens()){
		document.cerca_hotel.detall.value=1;
		document.cerca_hotel.submit();
	}
}

function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth;
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0;
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}

function SumarDies(fechaIni,num){
	var msPorDia = 24 * 60 * 60 * 1000
	var fechaFin = Date.parse(fechaIni)+(msPorDia*num);
	var fechaFinNew = new Date(fechaFin);
	var Fdia=fechaFinNew.getDate();
	if (Fdia < 10 ) {
		Fdia = '0' + Fdia;
	}
	var Fmes=fechaFinNew.getMonth()+1;
	if (Fmes < 10 ) {
		Fmes = '0' + Fmes;
	}
	var Fany=fechaFinNew.getYear();
	if (Fany < 1000) { //Modificaciï¿½ necessï¿½ria per Firefox
		Fany+=1900
	}	
	document.cerca_hotel3.DataFi.value = Fdia +'/'+ Fmes +'/'+ Fany;
	var fechaFinDia = new Date( Fmes +'/'+ Fdia +'/'+ Fany );
	//document.getElementById('divDiaSortida').innerHTML = weekDay[fechaFinDia.getDay()];
	document.cerca_hotel3.numNits.value = num;
}

function SumarDies_LastMinute(fechaIni,num){
	var msPorDia = 24 * 60 * 60 * 1000
	var fechaFin = Date.parse(fechaIni)+(msPorDia*num);
	var fechaFinNew = new Date(fechaFin);
	var Fdia=fechaFinNew.getDate();
	if (Fdia < 10 ) {
		Fdia = '0' + Fdia;
	}
	var Fmes=fechaFinNew.getMonth()+1;
	if (Fmes < 10 ) {
		Fmes = '0' + Fmes;
	}
	var Fany=fechaFinNew.getYear();
	if (Fany < 1000) { //Modificaciï¿½ necessï¿½ria per Firefox
		Fany+=1900
	}	
	document.cerca_hotel.DataFi.value = Fdia +'/'+ Fmes +'/'+ Fany;
	var fechaFinDia = new Date( Fmes +'/'+ Fdia +'/'+ Fany );
	//document.getElementById('divDiaSortida').innerHTML = weekDay[fechaFinDia.getDay()];
	document.cerca_hotel.numNits.value = num;
}


function setFecha(c,fecha)
{
	switch(parseInt(c))
	{
	case 1: document.cerca_hotel.DataIni.value=fecha;
			var fechaIni = new Date( fecha.substr(3,2) +'/'+ fecha.substr(0,2) +'/'+ fecha.substr(6,4) );
			//document.getElementById('divDiaEntrada').innerHTML = weekDay[fechaIni.getDay()];
			fecha_final = document.cerca_hotel.DataFi.value;
			var fechaFin = new Date( fecha_final.substr(3,2) +'/'+ fecha_final.substr(0,2) +'/'+ fecha_final.substr(6,4) );
			if (isNaN(document.cerca_hotel.numNits.value) || isNaN(fechaFin) || fechaIni>=fechaFin ){
				SumarDies(fechaIni,1);
			}else{
				posarNits();
			}
			break;
	case 2: document.cerca_hotel.DataFi.value=fecha;
			posarNits();
			break;
	}
}

function getFecha(c){
	switch(parseInt(c)){
	case 1: return document.cerca_hotel.DataIni.value;
			//document.cerca_hotel.DataFi.value=fecha;
			break;
	case 2: return document.cerca_hotel.DataFi.value;
			break;
	}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_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; }
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;

function isDisabledIni(date) 
{
	var today = new Date();

	// Es menor a hoy
	if (date.getTime() < (today.getTime()-DAY))
	{	
		return true;
	}

	// Es mayor a un aï¿½o
	if (((date.getTime() - today.getTime()) / DAY) > 366)
	{
		return true;
	}

	return false;
}

function isDisabledFi(date) 
{
//    var today = new Date();
	
	fecha_inicial = document.cerca_hotel.DataIni.value;
	var today = new Date( fecha_inicial.substr(3,2) +'/'+ fecha_inicial.substr(0,2) +'/'+ fecha_inicial.substr(6,4) );

	// Es menor a hoy
	if (date.getTime() < (today.getTime()+1))
	{	
		return true;
	}

	// Es mayo a un aï¿½o
	if (((date.getTime() - today.getTime()) / DAY) > 15)
	{
		return true;
	}

	return false;
}

  function closeCalendar(cal) 
  {
    cal.hide();
	  posarNits();
    return true;
  };
	
	
function isDisabledIni2(date) 
{
	var today = new Date();

	// Es menor a hoy
	if (date.getTime() < (today.getTime()-DAY))
	{	
		return true;
	}

	// Es mayor a un aï¿½o
	if (((date.getTime() - today.getTime()) / DAY) > 366)
	{
		return true;
	}

	return false;
}

function isDisabledFi2(date) 
{
//    var today = new Date();
	
	fecha_inicial = document.cerca_hotel3.DataIni.value;
	var today = new Date( fecha_inicial.substr(3,2) +'/'+ fecha_inicial.substr(0,2) +'/'+ fecha_inicial.substr(6,4) );

	// Es menor a hoy
	if (date.getTime() < (today.getTime()+1))
	{	
		return true;
	}

	// Es mayo a un aï¿½o
	if (((date.getTime() - today.getTime()) / DAY) > 15)
	{
		return true;
	}

	return false;
}

  function closeCalendar2(cal) 
  {
    cal.hide();
	  posarNits2();
    return true;
  };
	


function setFecha2(c,fecha)
{
	switch(parseInt(c))
	{
	case 1: document.cerca_hotel.DataIni2.value=fecha;
			var fechaIni = new Date( fecha.substr(3,2) +'/'+ fecha.substr(0,2) +'/'+ fecha.substr(6,4) );
			//document.getElementById('divDiaEntrada').innerHTML = weekDay[fechaIni.getDay()];
			fecha_final = document.cerca_hotel.DataFi2.value;
			var fechaFin = new Date( fecha_final.substr(3,2) +'/'+ fecha_final.substr(0,2) +'/'+ fecha_final.substr(6,4) );
			if (isNaN(document.cerca_hotel.numNits.value) || isNaN(fechaFin) || fechaIni>=fechaFin ){
				SumarDies2(fechaIni,1);
			}else{
				posarNits2();
			}
			break;
	case 2: document.cerca_hotel.DataFi2.value=fecha;
			posarNits2();
			break;
	}
}

function getFecha2(c){
	switch(parseInt(c)){
	case 1: return document.cerca_hotel.DataIni2.value;
			//document.cerca_hotel.DataFi.value=fecha;
			break;
	case 2: return document.cerca_hotel.DataFi2.value;
			break;
	}
}
