﻿
function abreventana(mipage,mititulo,ancho,alto)
        {
            var idioma = 'ES'
            aWindow= open(mipage + '&lang=' + idioma ,mititulo,'scrollbars=no,toolbar=no,status=no,resizable=no,width=' + ancho + ',height=' + alto);
            aWindow.focus()
        }
function abreventanascroll(mipage,mititulo,ancho,alto)
        {
            miresize="no"
            if (navigator.appName == "Netscape")
            {
                miresize="yes"
            }
            aWindow= open(mipage,mititulo,'scrollbars=yes,toolbar=no,status=no,resizable=' + miresize + ',width=' + ancho + ',height=' + alto);
        }
function abreventananoscroll(mipage,mititulo,ancho,alto)
        {
            miresize="no"
            if (navigator.appName == "Netscape")
            {
                miresize="yes"
            }
            aWindow= open(mipage,mititulo,'scrollbars=no,toolbar=no,status=no,resizable=' + miresize + ',width=' + ancho + ',height=' + alto);
        }
function antGrande() {
	//reempleza el imagen grande con el imagen anterior
	curr = parseInt(document.getElementById('currHolder').value);
	imgArr = returnArray();
	if(curr > 0) {
		verGrande(curr-1);
	}
}
function sigGrande() {
	//reempleza el imagen grande con el imagen siguiente
	curr = parseInt(document.getElementById('currHolder').value);
	imgArr = returnArray();
	if(curr < imgArr.length - 1) {
		verGrande(curr+1);
	}
}
function initGrande() {
	curr = parseInt(document.getElementById('currHolder').value);
	verGrande(curr);
}
function verGrande(n) {
	//reempleza el imagen grande con el imagen peq pinchado
	imgArr = returnArray();
	
	if(imgArr.length>0) {
		document.getElementById('ctl00_cphPrincipal_ctrlFichaPaquete_img_grande').src = imgArr[n];

		document.getElementById('ctl00_cphPrincipal_ctrlFichaPaquete_img_grande2').src = imgArr[n];

		document.getElementById('currHolder').value = n;
		indGrande();
	}
}
function indGrande() {
	//cambia el indice del image ej. 1 de 6, 2 de 6 etc
	curr = parseInt(document.getElementById('currHolder').value) + 1;
	imgArr = returnArray();
	document.getElementById('ctl00_cphPrincipal_ctrlFichaPaquete_indGrande').innerHTML = curr + " de " + imgArr.length;
}
function MostrarEsperaReserva() {
 //alert('inicial');
    if (document.getElementById("tEsperaReservaFlash")) {
		//document.getElementById("Espera").style.display="block";
		//document.getElementById("Espera").style.height = document.body.scrollHeight + "px";
		////document.getElementById("Espera").style.width = document.body.scrollWidth + "px";
		//document.getElementById("tEsperaReservaFlash").style.visibility="visible";
        //abrir(450, 225, "tEsperaReservaFlash");
        document.getElementById("Espera").style.display="block";
	    document.getElementById("Espera").style.height = document.body.scrollHeight + "px";
        //centrarCapa('Espera');

        //abrir(450, 225, "tEsperaReservaFlash");
        document.getElementById("tEsperaReservaFlash").style.visibility="visible";
        centrarCapa('tEsperaReservaFlash');

    } else if (document.getElementById("EsperaFlash")) {
        //alert('EsperaFlash');
		document.getElementById("Espera").style.display="block";
		document.getElementById("EsperaFlash").style.display="block";
		document.getElementById("Espera").style.height = document.body.scrollHeight + "px";
		document.getElementById("EsperaFlash").style.height = document.body.scrollHeight + "px";
		//document.getElementById("Espera").style.width = document.body.scrollWidth + "px";
		//document.getElementById("EsperaFlash").style.width = document.body.scrollWidth + "px";
        //abrir(450, 225, "EsperaFlash");
        //abrir(450, 225, "Espera");
        abrir(450, 225, "tEsperaReservaFlash");
	} else if (document.getElementById("global")) {
	        //alert('global');

		document.getElementById("global").style.display = "none";
		document.getElementById("Espera").style.visibility="visible";
		document.getElementById("Espera").focus();
		document.getElementById("Contenido").style.visibility="hidden";		
	} else if (document.getElementById("Contenido")) {
	    //alert('Contenido');
		document.getElementById("Contenido").style.display = "none";
		document.getElementById("Espera").style.visibility="visible";
		document.getElementById("Espera").focus();
	}
	
	//$("#EsperaFlash").slideDown("slow")
	//$("#Espera").slideDown("slow");
	//$("#EsperaFlash").slideDown("slow");
		
	//return false;
	//ocultarCombos();
}
function getWindowData(){ 
    var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal; 
    //if (typeof window.innerWidth != 'undefined'){ 
    //    widthViewport= window.innerWidth-17; 
//        heightViewport= window.innerHeight-17; 
//    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){ 
//        widthViewport=document.documentElement.clientWidth; 
//        heightViewport=document.documentElement.clientHeight; 
//    }else{ 
        widthViewport= document.getElementById('Espera').style.width; 
        heightViewport=document.getElementById('Espera').style.height; 
//    } 
    xScroll=self.pageXOffset || (document.documentElement.scrollLeft+document.body.scrollLeft); 
    yScroll=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop); 
    widthTotal=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth,widthViewport); 
    heightTotal=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,heightViewport); 
    return [widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal]; 
} 
function abrir(W,H,element){ 
    var pagina=getWindowData(); 
    document.getElementById(element).style.width=W+'px'; 
    document.getElementById(element).style.height=H+'px'; 
    //document.getElementById(element).style.top=(pagina[1]/2)-(H/2)+pagina[3]+'px'; 
   // document.getElementById(element).style.left=(pagina[0]/2)-(W/2)+pagina[2]+'px'; 

} 

function changeDisplayDiv (name) {
//alert('pruebachange');
    if (!$('#' + name).is(':visible')) {
        $('#' + name).slideDown(500);
    } else {
        $('#' + name).slideUp(500);
    }
}

// Lo utilizamos para ocultar la publicidad con los fancyfox
function changeDisplayPublicidad (name) {
    if ($('#' + name).css("display") != "none") {    
        $('#' + name).css('display','none');
    } else {
    
        $('#' + name).css('display','block');
    }
}



function changeTextInput (name, text1, text2) {
    if (!$('#' + name).value == text1) {
        $('#' + name).value = text2;
    } else {
        $('#' + name).value = text1;
    }
}

function changeTextInner (name, text1, text2) {
    if ($('#' + name).html() == text1) {
        $('#' + name).html(text2);
    } else {
        $('#' + name).html(text1);
    }
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
	        curleft += obj.offsetLeft;
	        curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
        return [curleft,curtop];
    }
}//findPos
function llamaralancla(destino){
document.getElementById(destino).scrollIntoView(true);
//destination=destino.offsetTop;
//alert(destination);
//alert($(destino).);
//$("html:not(:animated),body:not(:animated)").animate({scrollTop:destination},1100);
//return false;
}
function centrarCapa(name) {
 $('#' + name).css("position","absolute");
 $('#' + name).css("top", ((( $(window).height() -  $('#' + name).outerHeight() ) )+$(window).scrollTop()) + "px");
 //$('#' + name).css("left", ((( $(window).width() -  $('#' + name).outerWidth() ) )+$(window).scrollLeft()) + "px");
}


function AplicarConversion()
{
    var ValorConversion;
    var DivisaAnterior;
    if($("#ctl00_cphPrincipal_cmbDivisa").val() == "EUR")
    {
        for(i=0;i<arrayValoresConversiones.length; i++)
        {
            if($("#DivisaAnterior").val() == arrayValoresConversiones[i][0].toString())
                ValorConversion = arrayValoresConversiones[i][1];
        }
        CambiarPrecios(ValorConversion,true);
    }
    else
    {        
        for(i=0;i<arrayValoresConversiones.length; i++)
        {            
            if($("#ctl00_cphPrincipal_cmbDivisa").val() == arrayValoresConversiones[i][0].toString())
                ValorConversion = arrayValoresConversiones[i][1];
        }        
        CambiarPrecios(ValorConversion,false);
    }        
               
    $("#DivisaAnterior").val($("#ctl00_cphPrincipal_cmbDivisa").val());
}


function dias(mes, anno) 
{
    mes = parseInt(mes);
    anno = parseInt(anno);
    switch (mes) {
        case 1 : 
        case 3 : 
        case 5 : 
        case 7 : 
        case 8 : 
        case 10 : 
        case 12 : 
            return 31;
        case 2 : 
            return (anno % 4 == 0) ? 29 : 28;
    }
        return 30;
}
   
   
function CambiarPrecios(ValorConversion, Signo)
{    
    var mesAnio = $("#ctl00_cphPrincipal_ctrlCalendario_ddlMes").val();    
    var ModificarCalendario = false;
    var idDia = "";
    if(mesAnio!=null)
    {
        var DiasdelMes = dias(mesAnio.substring(4,6),mesAnio.substring(0,4));
        for(v = 1; v <= DiasdelMes; v++)
        {
            idDia = v;
            if(idDia.length < 2)
                idDia = "0" + v;
            
            var idPrecio = "ctl00_cphPrincipal_ctrlCalendario_dlstMes_ctl" + idDia + "_lblDato";
            PrecioDiaCalendario = $("#" + idPrecio).text();
            if(PrecioDiaCalendario != null && PrecioDiaCalendario != "")
            {
                $("#" + idPrecio).text($("#ctl00_cphPrincipal_ctrlFichaPaquete_lblPrecio").text() + Signo);             
                ModificarCalendario = true;
            }
        }        
        
    }
}


function CambiarPrecioFicha(ValorConversion, Signo)
{
    
    if($("#ctl00_cphPrincipal_ctrlAlojamientos_divAlojamientos").val() != null)
    {
        var PrecioFicha = parseFloat($("#ctl00_cphPrincipal_ctrlFichaPaquete_lblPrecio").text());
        if($("#ctl00_cphPrincipal_cmbDivisa").val() == "EUR")
        {
            $("#ctl00_cphPrincipal_ctrlFichaPaquete_lblPrecio").text(Math.round(parseFloat($("#ctl00_cphPrincipal_ctrlFichaPaquete_precioinicioEuro").val().replace(".",","))));
            
            $("#ctl00_cphPrincipal_ctrlFichaPaquete_lblMoneda").text(Signo);
        }
        else
        {
            if(Signo != $("#ctl00_cphPrincipal_ctrlFichaPaquete_lblMoneda").text())
            {
                $("#ctl00_cphPrincipal_ctrlFichaPaquete_lblMoneda").text(Signo);
                $("#ctl00_cphPrincipal_ctrlFichaPaquete_lblPrecio").text(Math.round(PrecioFicha * ValorConversion));
            }
        }
    }
}




//    var lblPrecio = parseFloat($("#ctl00_cphPrincipal_ctrlFichaPaquete_lblPrecio").text());
//    if(ConversionAEuro)
//    {
//        $("#ctl00_cphPrincipal_ctrlFichaPaquete_lblPrecio").text(Math.round((lblPrecio / parseFloat(ValorConversion.replace(",",".")))));
//        $("#ctl00_cphPrincipal_ctrlFichaPaquete_lblMoneda").text("€");
//    }
//    else
//    {
//        $("#ctl00_cphPrincipal_ctrlFichaPaquete_lblPrecio").text(Math.round((lblPrecio * parseFloat(ValorConversion.replace(",",".")))));
//        $("#ctl00_cphPrincipal_ctrlFichaPaquete_lblMoneda").text("$");
//    }
//        
//        
//    var mesAnio = $("#ctl00_cphPrincipal_ctrlCalendario_ddlMes").val();
//    if(mesAnio!=null)
//    {
//        var PrecioDiaCalendario;
//        var DiasdelMes = dias(mesAnio.substring(4,6),mesAnio.substring(0,4));
//        for(v = 1; v <= DiasdelMes; v++)
//        {
//            var idPrecio = "ctl00_cphPrincipal_ctrlCalendario_dlstMes_ctl" + v + "_lblDato";
//            PrecioDiaCalendario = $("#" + idPrecio).text();
//            if(PrecioDiaCalendario != null && PrecioDiaCalendario != "")
//            {
//                var PrecioCalendario = parseFloat(PrecioDiaCalendario.substring(0, PrecioDiaCalendario.length));
//                if(ConversionAEuro)
//                    $("#" + idPrecio).text(Math.round(PrecioCalendario / parseFloat(ValorConversion.replace(",","."))) + "€");
//                else
//                    $("#" + idPrecio).text(Math.round(PrecioCalendario * parseFloat(ValorConversion.replace(",","."))) + "$");                    
//            }
//        }
//    }
//    
//    var PrecioCategoria = $("#ctl00_cphPrincipal_ctrlAlojamientos_rptrCategorias_ctl00_lblPrecioCat2").text();
//    if(PrecioCategoria != null)
//    {
//        if(ConversionAEuro)
//            $("#ctl00_cphPrincipal_ctrlAlojamientos_rptrCategorias_ctl00_lblPrecioCat2").text(Math.round(PrecioCategoria / parseFloat(ValorConversion.replace(",","."))) + "€");
//        else
//            $("#ctl00_cphPrincipal_ctrlAlojamientos_rptrCategorias_ctl00_lblPrecioCat2").text(Math.round(PrecioCategoria * parseFloat(ValorConversion.replace(",","."))) + "$");
//    }
//}
