// JavaScript hotels_infohotel.asp

function envia(){
	//if (CapacitatNens()){
		//document.cerca_hotel.detall.value=0;
	//registrarAceptacion("/_prgr01/clickBuscarDisponInfoHotel.asp");

	var obj = document.createElement("INPUT");
	obj.type = "hidden";
	obj.name = "hab3";
	obj.value = 1;
	document.cerca_hotel.appendChild(obj);
		document.cerca_hotel.detall.value = -1;
		document.cerca_hotel.submit();
	//}
}
function posarcoma(txt) {
    var ret = "";
    var x = 0;
    var c = "";
	var trobat = false;
	var cont = 0;
    while ( x < txt.length ) {
        c = txt.charAt(x++);
		//alert("Texto Char "+c+" Ret:"+ret);
        if ( c=='.'  ) {
    		ret += ",";
			trobat = true;
        } else {
       		ret += c;
      	}
		if (trobat){
			cont++;
		}
    }
	
	if (!(trobat)){
		ret=ret+',00';
	}
	if (cont==2){
		ret=ret+'0';
	}
	
	return ret;
}

function posarpunt(txt) {
    var ret = "";
    var x = 0;
    var c = "";
    while ( x < txt.length ) {
        c = txt.charAt(x++);
		//alert("Texto Char "+c+" Ret:"+ret);
        if ( c==','  ) {
    		ret += ".";
        } else {
       		ret += c;
      	}
    }
	return ret;
}

function treurepunt(txt) {
    var ret = "";
    var x = 0;
    var c = "";
    while ( x < txt.length ) {
        c = txt.charAt(x++);
		//alert("Texto Char "+c+" Ret:"+ret);
        if ( c=='.'  ) {
    		ret += "";
        } else {
       		ret += c;
      	}
    }
	return ret;
}


function IniciarValores()
{
    var x
    x=8;
    //sb();
    while ( x > 0 ) {
        x = x - 1
        CanviPreu(x);
    }
}

var Habitaciones = new Array();


function CanviPreu(obj,hab,pos){
    
    //debugger;
    
    //alert(hab);    
    
    if (obj.value == undefined)
        obj=document.getElementById(obj);
        
    //Habitaciones= Habitaciones+ obj.value
    //trozos = Habitaciones.split ("-"); // el separador es el espacio
    
    var x
    var Encontrado
    Encontrado=false;
    x=Habitaciones.length - 1;
    while ( x >= 0 ) {
        if (Habitaciones[x].split(';')[0] == hab )
        {
            Habitaciones[x] = hab + ';' + obj.value;
            Encontrado=true;
            break;
        }
        x = x - 1
    }
    
    if (Encontrado == false)
        Habitaciones[Habitaciones.length] = hab + ';' + obj.value;
    
    
    x=Habitaciones.length - 1;
    var Reservar
    Reservar="";
    while ( x >= 0 ) {
        Reservar = Reservar + Habitaciones[x] + "-";
        x = x - 1
    }
    
    document.cerca_hotel.ReservaFinal.value=Reservar;
    
    //alert(Reservar);
    
	var form=document.tria_hab;
	var precio=0.0;
	
	if (form["Preu"+hab] == undefined)
	    return
	
	if (form["Preu"+hab].length>0)
	{
	    var precio_hab = parseFloat(form["Preu"+hab][pos].value);
	}
	else
	{
	    var precio_hab = parseFloat(form["Preu"+hab].value);
	}
	
	//var precio_hab = parseFloat(form["Preu"+hab].value);
	
	//var precio_desayuno = parseFloat(<%=replace(strDesayuno,",",".")%> * form["Persones"+hab].value);
	var precio_desayuno = 0
	//var precio_banyo = parseFloat(form["PreuBany"+hab].value);
	var precio_banyo = 0
	
	//if (form["HAB"+hab].checked==true)
	//{
    	
//	    if (eval(form["SelPreuBany"+hab])==null){
//		    precio = precio_hab
//	    }else{
//		    if (form["SelPreuBany"+hab].selectedIndex=="1") {
//			    precio = precio_hab - precio_banyo;
//		    }else{
//			    precio = precio_hab;
//		    }
//		    document.getElementById('TipusPreu').innerHTML = posarcoma(precio.toString());
//	    }
    	
//	    if (form["Esmorzar"+hab].selectedIndex=="1") {
//		    precio = precio + precio_desayuno;
//	    }
    		
	//}
    
    precio = precio_hab;
    //ESTE ES BUENO
    //document.getElementById('TipusPreu').innerHTML = posarcoma(precio.toString());
	precio = precio * 100 ;

	//precio=Math.round(form["Disp"+hab].value * precio * <%=Nits%>);
	
	if (form["Disp"+hab].length>0)
	{
	    precio=Math.round(form["Disp"+hab][pos].value * precio *form["hab"+hab][pos].value) / 100;
	}
	else
	{
	    precio=Math.round(form["Disp"+hab].value * precio *form["hab"+hab].value) / 100;
	}
	
	//precio=Math.round(form["Disp"+hab].value * precio *form["hab"+hab].value) / 100;
	precio=precio + (precio*7/100);
	
	//ESTE ES BUENO
	//form["preu_hab"+hab].value=posarcoma(String(precio));


	//CanviTotals();
}

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 setFecha(c,fecha)
{
	switch(parseInt(c))
	{
	case 1: document.getElementById('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.getElementById('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.getElementById('DataFi').value=fecha;
			posarNits();
			break;
	}
}

function getFecha(c){
	switch(parseInt(c)){
	case 1: return document.getElementById('DataIni').value;
			//document.cerca_hotel.DataFi.value=fecha;
			break;
	case 2: return document.getElementById('DataFi').value;
			break;
	}
}





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_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;
}


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;
  };

