function getTopDiv(_nomcapa)
{
    if (document.getElementById) {
    var capa1=document.getElementById(_nomcapa);
    return capa1.offsetTop;
    } else if (document.all) {
    return document.all.capa1.offsetTop;
    } else if (document.layers) {
    return document.layers[_nomcapa].pageY;
    } else return 0; //alert('Su navegador no está soportado.');
}
function showFitxa(_cobol,_opc,_nomhot)
{
    document.location.href="/interfaz/getGeneralComs.jsp?opc="+_opc+"&desti="+_nomhot+"&tipus_desti=H&codhot="+_cobol;
}
function showFitxa(_cobol,_opc,_nomhot,_verdispo)
{
    document.location.href="/interfaz/getGeneralComs.jsp?opc="+_opc+"&desti="+_nomhot+"&tipus_desti=H&codhot="+_cobol+"&verdispo="+_verdispo;
}
function showFitxa_old(_cobol)
{
    var fitxa = document.getElementById("fitxa");
    var sombra = document.getElementById("sombra");
    var fitxa_iframe = document.getElementById("fitxa_iframe");

    location.href='#refhot_'+_cobol;

    fitxa.style.left=(parseInt(document.body.offsetWidth)/2).toFixed()-(parseInt(fitxa.style.width)/2).toFixed()+"px";

    var isIE = /*@cc_on!@*/false;
    var pxDif = -50;
    if (isIE) pxDif=300;
    fitxa.style.top=""+((getTopDiv("lnkftx_"+_cobol))+parseInt(pxDif))+"px";

    sombra.style.width=""+(document.body.offsetWidth)+"px";
    sombra.style.height=""+document.body.offsetHeight+"px";
    fitxa_iframe.src="/interfaz/getGeneralComs.jsp?opc=9&codhot="+_cobol;

    fitxa.style.visibility = "visible";
    sombra.style.visibility = "visible";
}

function ocultaFitxa()
{
    var fitxa = document.getElementById("fitxa");
    var sombra = document.getElementById("sombra");
    var fitxa_iframe = document.getElementById("fitxa_iframe");

    fitxa.style.visibility = 'hidden';
    sombra.style.visibility = "hidden";
    fitxa_iframe.src="about:blank";

}


function recomptePreu(_codhot,_nhab,_preuhab,_liniahab)
{
    document.getElementById("totparchab_"+_codhot +"_"+_nhab).value = _preuhab;
    document.getElementById("liniahab_"+_codhot +"_"+_nhab).value = _liniahab;

    var _totalhab = document.getElementById("tothabshot_"+_codhot).value;
    var _suma = 0;
    for (var _compt=1;_compt <= _totalhab; _compt++)
    {
        try { _suma = parseFloat(_suma) + parseFloat(document.getElementById("totparchab_"+_codhot +"_"+_compt).value); } catch(e62) {}
    }
    document.getElementById("showtotal_"+_codhot).innerHTML="" + parseFloat(_suma/valor_moneda).toFixed(2) + moneda;
    //document.getElementById("showtotal_"+_codhot).innerHTML="" + parseFloat(Math.floor(_suma)).toFixed(0) + moneda;
    document.getElementById("preu_brut_"+_codhot).innerHTML="&nbsp;&nbsp;" + parseFloat(_suma*1.12/valor_moneda).toFixed(2) + moneda+"&nbsp;&nbsp;";
    document.getElementById("showmitja_"+_codhot).innerHTML="" + parseFloat((_suma/parseFloat(document.getElementById("ndiesres_"+_codhot ).value)/_totalhab)/valor_moneda).toFixed(2) + moneda;
    //document.getElementById("showmitja_"+_codhot).innerHTML="" + parseFloat(Math.floor(_suma/parseFloat(document.getElementById("ndiesres_"+_codhot ).value))).toFixed(0) + moneda;
    try {document.getElementById("punts_"+_codhot).innerHTML="&nbsp;" + Math.ceil(2*parseFloat(_suma)) + "&nbsp;"; }  catch(e78) {}
}
function sumaPreus(_codhot)
{
    var _totalhab = document.getElementById("tothabshot_"+_codhot).value;
    var _suma = 0;
    for (var _compt=1;_compt <= _totalhab; _compt++)
    {
        try { _suma = parseFloat(_suma) + parseFloat(document.getElementById("totparchab_"+_codhot +"_"+_compt).value); } catch(e62) {}
    }
    document.getElementById("showtotal_"+_codhot).innerHTML="" + parseFloat(_suma/valor_moneda).toFixed(2) + moneda;
    //document.getElementById("showtotal_"+_codhot).innerHTML="" + parseFloat(Math.floor(_suma)).toFixed(0) + moneda;
    document.getElementById("preu_brut_"+_codhot).innerHTML="&nbsp;&nbsp;" + parseFloat(_suma*1.12/valor_moneda).toFixed(2) + moneda+"&nbsp;&nbsp;";
    document.getElementById("showmitja_"+_codhot).innerHTML="" + parseFloat((_suma/parseFloat(document.getElementById("ndiesres_"+_codhot ).value)/_totalhab)/valor_moneda).toFixed(2) + moneda;
    //document.getElementById("showmitja_"+_codhot).innerHTML="" + parseFloat(Math.floor(_suma/parseFloat(document.getElementById("ndiesres_"+_codhot ).value))).toFixed(0) + moneda;
    try {document.getElementById("punts_"+_codhot).innerHTML="&nbsp;" + Math.ceil(2*parseFloat(_suma)) + "&nbsp;"; }  catch(e78) {}
}

function enviaPetRes(_codhot)
{
    var _totalhab = document.getElementById("tothabshot_"+_codhot).value;
    var _linies = "";
    var _suma = 0;
    for (var _compt=1;_compt <= _totalhab; _compt++)
    {
        try
        {
            _linies = _linies + document.getElementById("liniahab_"+_codhot +"_"+_compt).value;
            _suma = parseFloat(_suma) + parseFloat(document.getElementById("totparchab_"+_codhot +"_"+_compt).value);
        }
        catch(e81) {}
    }

    document.getElementById("res_pretotal").value=parseFloat(_suma).toFixed(2);
    //document.getElementById("res_pretotal").value=parseFloat(Math.floor(_suma)).toFixed(0);
    document.getElementById("res_codhot").value=_codhot;
    document.getElementById("res_opc").value="5";
    document.getElementById("res_lins").value=_linies;
    document.getElementById("res_premig").value=document.getElementById('showmitja_'+_codhot).innerHTML;
    document.getElementById("res_hotfoto").value=document.getElementById('foto_'+_codhot).src;
    document.getElementById("res_pagdir").value=document.getElementById("pagdirhot_"+_codhot).value;
    document.frmpetres.submit();
    //document.location.href="/interfaz/getGeneralComs.jsp?opc=5&pretotal="+parseFloat(_suma).toFixed(2)+"&codhot="+_codhot+"&lins="+escape(_linies)+"&premig="+escape(document.getElementById('showmitja_'+_codhot).innerHTML)+"&hotfoto="+escape(document.getElementById('foto_'+_codhot).src);
}

function desactiva()
{
    document.reservaform.action="#";
}
function ctrlmax()
{
    var cadena = document.reservaform.observaciones.value;
    if (cadena.length>200) document.reservaform.observaciones.value = cadena.substring(0,cadena.length-1);
}
function abrirURLCVV (URL){

    var left=0;
    var top=0;
    var width=150;
    var height=280;
    if(window.screen){
        var left = (screen.width-width)/2;
        var top = (screen.height-height)/2;
    }

window.open(URL,"ventanaURL", "top=" + top + "left=" + left + "width=" + width + ",height=" + height + ",scrollbars=yes,Resizable=yes,Directories=no,Location=no,Menubar=no,Status=no,Titlebar=no,Toolbar =no")
}

function helpCVV()
{
    var opcCVV = document.form1.tipo_tarjeta.selectedIndex;
    if (opcCVV==0) abrirURLCVV("/generalcoms/img/cvv_visa.jpg");
    else if (opcCVV==1) abrirURLCVV("/generalcoms/img/cvv_mastercard.jpg");
    else if (opcCVV==2) abrirURLCVV("/generalcoms/img/cvv_american.jpg");
    else if (opcCVV==3) abrirURLCVV("/generalcoms/img/cvv_diner.jpg");
    else if (opcCVV==4) abrirURLCVV("/generalcoms/img/cvv_discover.jpg");
}

function showVisa(_val)
{
    if (_val=="12")
    {
try {
        document.getElementById("div_msgFP").innerHTML="* " + msgFP_12;
        document.getElementById("capa_visa").style.visibility="visible";
        document.getElementById("capa_visa").style.height="300px";
}
catch(e154) {}
    }
    else if (_val=="250")
    {
try {
        document.getElementById("div_msgFP").innerHTML="* " + msgFP_25;
        document.getElementById("capa_visa").style.visibility="hidden";
        document.getElementById("capa_visa").style.height="0px";
}
catch(e154) {}
    }
    else
    {
        document.getElementById("div_msgFP").innerHTML="";        
    }

}



function loadMapaSearch(nom_mapa,hot_long, hot_lat)
{
  if (GBrowserIsCompatible())
  {
        var map = new GMap2(document.getElementById(nom_mapa));
        map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(hot_long, hot_lat), 13);

		// Create our "tiny" marker icon
		var icon = new GIcon();
//		icon.image = "https://labs.google.com/ridefinder/images/mm_20_red.png";
        icon.image = "https://www.hotusa.com/interfaz/images/ico_hotusacom_map.gif";
//		icon.shadow = "https://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(16, 16);
//		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(16, 16);
		icon.infoWindowAnchor = new GPoint(5, 1);
		var point = new GLatLng(hot_long, hot_lat);
		map.addOverlay(new GMarker(point, icon));
  }
}

function showMapaSearch(_codhot,hot_lat,hot_long)
{
    var mapa = document.getElementById("mapagran_"+_codhot);
    var mapa2 = document.getElementById("mapagran_barra");
    var mapa3 = document.getElementById("tancamapa_"+_codhot);

    mapa.style.left=((parseInt(document.body.offsetWidth)/2).toFixed()-(parseInt(mapa.style.width)/2).toFixed())+"px";
    mapa2.style.width=(document.body.offsetWidth) +"px";
    mapa2.style.height=(document.body.offsetHeight) + "px";

    mapa.style.visibility = "visible";
    mapa2.style.visibility = "visible";
    mapa3.style.visibility = "visible";
    loadMapaSearch("mapagran_"+_codhot,hot_lat,hot_long);
    document.location.href="#refhot_" + _codhot;
    mapa2.onclick="javascript:ocultaMapaSearch('"+_codhot+"')";
}
function ocultaMapaSearch(_codhot)
{
    var mapa = document.getElementById("mapagran_"+_codhot);
    var mapa2 = document.getElementById("mapagran_barra");
    var mapa3 = document.getElementById("tancamapa_"+_codhot);

    mapa.style.visibility = 'hidden';
    mapa2.style.visibility = "hidden";
    mapa3.style.visibility = "hidden";
}
function descPlus(_codhot)
{
    var desc = document.getElementById("descripcion_corta_"+_codhot);
    var desc2 = document.getElementById("desc_corta_plus_"+_codhot);

    var tempHTML = desc.innerHTML;
    desc.innerHTML=desc2.innerHTML;
    desc2.innerHTML=tempHTML;
}
var fotos = new Array();
var i = 0;
function posaFoto(_n,_fotosrc)
{
    if (_n==0) fotos = new Array();
    fotos[_n]=_fotosrc;
    i=_n;
}
function canviaFoto(_codhot)
{
	i++;
	if (i==fotos.length) i=0;
    document.getElementById("galeria_"+_codhot).src=fotos[i];
}
function canviaFotoFF(_codhot)
{
    i--;
    if (i==-1) i=fotos.length-1;
	document.getElementById("galeria_"+_codhot).src=fotos[i];
}

function showFotosSearch(_codhot)
{
    var mapa = document.getElementById("fotogran_"+_codhot);
    var mapa2 = document.getElementById("mapagran_barra");
    var mapa3 = document.getElementById("tancafoto_"+_codhot);
//    var foto_ocu_div = document.getElementById("foto_oculta_"+_codhot);
    var fotosifr = document.getElementById("fotos_iframe");

    fotosifr.src="/interfaz/getGeneralComs.jsp?opc=20&codhot="+_codhot;
    mapa2.style.width=(document.body.offsetWidth) +"px";
    mapa2.style.height=(document.body.offsetHeight) + "px";
    mapa3.style.left=((parseInt(document.body.offsetWidth)/2).toFixed()-66)+"px";

    mapa.style.visibility = "visible";
    mapa2.style.visibility = "visible";
    mapa3.style.visibility = "visible";

    document.location.href="#refhot_" + _codhot;
    mapa2.onclick="javascript:ocultaMapaSearch('"+_codhot+"')";
}

function ocultaFotoSearch(_codhot)
{
    var mapa = document.getElementById("fotogran_"+_codhot);
    var mapa2 = document.getElementById("mapagran_barra");
    var mapa3 = document.getElementById("tancafoto_"+_codhot);

    mapa.style.visibility = 'hidden';
    mapa2.style.visibility = "hidden";
    mapa3.style.visibility = "hidden";
}
function incrusta(_url,_ids,_opc)
{
    document.location.href='/interfaz/getGeneralComs.jsp?opc='+_opc+_ids;
}
function enviaCercaPerServei(_codserv)
{
    var res = "";
    for (var compt=0;compt<=9;compt++)
    {
        if (document.getElementById("checkboxB"+compt).checked==true)
        {
            if (document.getElementById("checkboxB"+compt).value!=_codserv) res = res + document.getElementById("checkboxB"+compt).value;
        }
        else
        {
            if (document.getElementById("checkboxB"+compt).value==_codserv) res = res + document.getElementById("checkboxB"+compt).value;
        }
    }
    document.getElementById("fltserv").value=res.substring(0,res.length-1); // treiem el guio baix últim abans d'enviar-lo
    for (var compt=1;compt<=7;compt++)
    {
        if (document.getElementById("checkbox"+compt).checked==true)
        {
            document.getElementById("marca").value = document.getElementById("checkbox"+compt).value;
        }
    }

    for (var compt=1;compt<=6;compt++)
    {
        if (document.getElementById("checkboxC"+compt).checked==true)
        {
            document.getElementById("fltpre").value = document.getElementById("checkboxC"+compt).value;
        }
    }

    res = "";
    for (var compt=0;compt<=7;compt++)
    {
        if (document.getElementById("checkboxD"+compt).checked==true)
        {
            res = res + document.getElementById("checkboxD"+compt).value;
        }
    }
    document.getElementById("fltctg").value=res;
//    document.getElementById("fltpre").value = document.getElementById("filtprec").value;
    document.getElementById("fltnmht").value = document.getElementById("filtre_hotname").value;
    EnviaCerca();
}

function enviaCercaPerPreu(_preusel)
{
    var res = "";
    for (var compt=0;compt<=9;compt++)
    {
        if (document.getElementById("checkboxB"+compt).checked==true)
        {
            res = res + document.getElementById("checkboxB"+compt).value;
        }
    }
    document.getElementById("fltserv").value=res.substring(0,res.length-1); // treiem el guio baix últim abans d'enviar-lo

    for (var compt=1;compt<=7;compt++)
    {
        if (document.getElementById("checkbox"+compt).checked==true)
        {
            document.getElementById("marca").value = document.getElementById("checkbox"+compt).value;
        }
    }

    res = "";
    for (var compt=0;compt<=7;compt++)
    {
        if (document.getElementById("checkboxD"+compt).checked==true)
        {
            res = res + document.getElementById("checkboxD"+compt).value;
        }
    }
    document.getElementById("fltctg").value=res;

    document.getElementById("fltpre").value = _preusel;
    document.getElementById("fltnmht").value = document.getElementById("filtre_hotname").value;
    EnviaCerca();
}
function enviaCercaPerMarca(_marca)
{
    var res = "";
    for (var compt=0;compt<=9;compt++)
    {
        if (document.getElementById("checkboxB"+compt).checked==true)
        {
            res = res + document.getElementById("checkboxB"+compt).value;
        }
    }
    document.getElementById("fltserv").value=res.substring(0,res.length-1); // treiem el guio baix últim abans d'enviar-lo

    document.getElementById("marca").value = _marca;

    for (var compt=1;compt<=6;compt++)
    {
        if (document.getElementById("checkboxC"+compt).checked==true)
        {
            document.getElementById("fltpre").value = document.getElementById("checkboxC"+compt).value;
        }
    }

    res = "";
    for (var compt=0;compt<=7;compt++)
    {
        if (document.getElementById("checkboxD"+compt).checked==true)
        {
            res = res + document.getElementById("checkboxD"+compt).value;
        }
    }
    document.getElementById("fltctg").value=res;

//    document.getElementById("fltpre").value = document.getElementById("filtprec").value;
    document.getElementById("fltnmht").value = document.getElementById("filtre_hotname").value;
    EnviaCerca();
}
function enviaCercaPerCateg(_codctg)
{
    var res = "";
    if (_codctg=="0")
    {
        for (var compt=1;compt<=7;compt++)
        {
            document.getElementById("checkboxD"+compt).checked=false;
        }
        res = "0";
    }
    else
    {
        for (var compt=1;compt<=7;compt++)
    {
        if (document.getElementById("checkboxD"+compt).checked==true)
        {
            if (document.getElementById("checkboxD"+compt).value!=_codctg) res = res + document.getElementById("checkboxD"+compt).value;
        }
        else
        {
            if (document.getElementById("checkboxD"+compt).value==_codctg) res = res + document.getElementById("checkboxD"+compt).value;
        }
    }
        if (res=="") res = "0"; 
    }
    document.getElementById("fltctg").value=res;
    res = "";
    for (var compt=0;compt<=9;compt++)
    {
        if (document.getElementById("checkboxB"+compt).checked==true)
        {
            res = res + document.getElementById("checkboxB"+compt).value;
        }
    }
    document.getElementById("fltserv").value=res.substring(0,res.length-1); // treiem el guio baix últim abans d'enviar-lo
    for (var compt=1;compt<=7;compt++)
    {
        if (document.getElementById("checkbox"+compt).checked==true)
        {
            document.getElementById("marca").value = document.getElementById("checkbox"+compt).value;
        }
    }

    for (var compt=1;compt<=6;compt++)
    {
        if (document.getElementById("checkboxC"+compt).checked==true)
        {
            document.getElementById("fltpre").value = document.getElementById("checkboxC"+compt).value;
        }
    }

//    document.getElementById("fltpre").value = document.getElementById("filtprec").value;
    document.getElementById("fltnmht").value = document.getElementById("filtre_hotname").value;
    EnviaCerca();
}
function enviaCercaPerNomHotel()
{
    var res = "";
    res = "";
    for (var compt=0;compt<=7;compt++)
    {
        if (document.getElementById("checkboxD"+compt).checked==true)
        {
            res = res + document.getElementById("checkboxD"+compt).value;
        }
    }
    document.getElementById("fltctg").value=res;
    res = "";
    for (var compt=0;compt<=9;compt++)
    {
        if (document.getElementById("checkboxB"+compt).checked==true)
        {
            res = res + document.getElementById("checkboxB"+compt).value;
        }
    }
    document.getElementById("fltserv").value=res.substring(0,res.length-1); // treiem el guio baix últim abans d'enviar-lo
    for (var compt=1;compt<=7;compt++)
    {
        if (document.getElementById("checkbox"+compt).checked==true)
        {
            document.getElementById("marca").value = document.getElementById("checkbox"+compt).value;
        }
    }

    for (var compt=1;compt<=6;compt++)
    {
        if (document.getElementById("checkboxC"+compt).checked==true)
        {
            document.getElementById("fltpre").value = document.getElementById("checkboxC"+compt).value;
        }
    }

//    document.getElementById("fltpre").value = document.getElementById("filtprec").value;
    document.getElementById("fltnmht").value = document.getElementById("filtre_hotname").value;
    EnviaCerca();
}

function PreEnviaCerca()
{
    document.getElementById("fltserv").value="";
    document.getElementById("marca").value = "";
    document.getElementById("fltpre").value = "0-90000";
    document.getElementById("fltctg").value = "0";
    EnviaCerca();
}

function clickaLinia(reflin)
{
    if (reflin!='')
    {
        try { document.getElementById(reflin).checked='true'; } catch(e19) {}
        var cadena = new String(document.getElementById(reflin).onclick);
        var ini = cadena.indexOf("recomptePreu");
        var fi = cadena.indexOf(";");
//	document.location.href="javascript:"+cadena.substring(ini,fi+1);
        try { eval (""+cadena.substring(ini,fi+1)); } catch(e454) {}
    }
}

function showCanvisTotal(_lit,_codhot)
{
    var preu = document.getElementById("showtotal_"+_codhot).innerHTML;
    preu = parseFloat(preu.replace(moneda,""));
    var cadena = '<span onClick=javascript:ocultaCanvisTotal("' + _codhot + '") style="cursor:pointer; padding-bottom:10px;">X</span><br/>';
    cadena = cadena + '<table border="0" cellspacing="0" cellpadding="0" style="padding-top:3px;">'
    cadena = cadena + '<tr><td width="140px" align="left"><img src="http://www.eurostarshotels.com/buscador_eurostars/templates/public/PERSONAL/CLIENTS/buscador_eurostars/images/calculadora.png" alt=""/>&nbsp;&nbsp;' + _lit + ':</td>';
    cadena = cadena + '<td width="60px">' + document.getElementById("showtotal_"+_codhot).innerHTML + '</td></tr>';
    for (var compt=0;compt<=div_signes.length-1;compt++)
    {
        if (div_signes[compt]=="LB") div_signes[compt] = "&pound;";
        else if (div_signes[compt]=="DO") div_signes[compt] = "$";
        cadena = cadena + '<tr><td></td><td>' + (preu * valor_moneda / parseFloat(div_canvis[compt])).toFixed(2)  + '<b>' + div_signes[compt] + '</b></td></tr>';
    }
    if(moneda == "R$"){
        cadena = cadena + '<tr><td></td><td>' + parseFloat(preu * valor_moneda).toFixed(2) + '<b>&euro;</b></td></tr>';    
    }
    cadena = cadena + '</table';
    document.getElementById("preusdiv_"+_codhot).innerHTML='<span style="float:right;">' + cadena + '</span>';
    document.getElementById("preusdiv_"+_codhot).style.visibility="visible";
}

function ocultaCanvisTotal(_codhot)
{
    document.getElementById("preusdiv_"+_codhot).style.visibility="hidden";
}

function getCookieVal (offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;

	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) break;

	}

	return null;
}

function showTels()
{
    // Si es referer Affilired ocultem telčfons
    if (GetCookie("ID_LINK_HOTCORP")=="11")
    {
        //oculta telčfons
        document.getElementById("header_telf").style.visibility="hidden";
    }
}

function setFotoGran(foto_url){
    document.getElementById("fotogran").src = foto_url;
}

function abrirVentana(_url){
    window.open(_url, 'open_window', 'menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=640, height=480, left=0, top=0')
}

function canviaBoton(_tag, _url){
    document.getElementById(_tag).src = _url;
}
