function cotizarTodo(monedaFinal){
	var monedaActual = $("#monedaActual").attr("value");
	var arrayPrices  = new Array();
	var precio;
		
	$.ajax({
	   type: "GET",
	   cache: false,
	   url: "/include/ajaxServices/currencyService.php",
	   data: "monedaActual="+monedaActual+"&monedaFinal="+monedaFinal,
	   beforeSend: function(){
	   	$(".currencySimbolSpan,.priceSpan").css("display","none");	
	   	$(".currencyWaiting").css("display","inline"); 
	   	  	
	   	
	   },
	   success: function(msg){

		var result    	  = msg.split('@');
                var divisa_intermedia   = parseFloat(result[0]);
	   	var multiplicador = parseFloat(result[1]);
	   	var simbolo       = result[2];

	   	//Ahora la nueva moneda es la seleccionada
		$("#monedaActual").attr("value",monedaFinal);

		//realizamos la multiplicación para convertir las monedas
		$(".priceSpan").each(function(){
			precio = parseFloat(this.innerHTML);
                        cotizacion_intermedia = (precio * divisa_intermedia).toFixed(2);
			this.innerHTML = (cotizacion_intermedia * multiplicador).toFixed(2);
			
		});
		
		$(".currencySimbolSpan").each(function(){
			this.innerHTML = simbolo;
                        
		});

		$(".currencySimbolSpan,.priceSpan").css("display","inline");
		$(".currencyWaiting").css("display","none");

                var search_term = 'reservation_info';
                var str = document.URL;

                var url_check = str.indexOf( search_term );

                if ( url_check != -1 ) {

                    if(divisa_destino != $("#select_divisa").val()) {
                        $("#texto_conversor").css('display','inline');
                        $('.conversor').css('display','inline');
                    } else {
                        $("#texto_conversor").css('display','none');
                        $('.conversor').css('display','none');
    }                } else {
                    ajustar_tamanios_precios();
                }

	   }
	 });


}

function ajustar_tamanios_precios() { 
    //$('[id^=precioAlojamiento]').each( function() { if ($(this).height() <= 26) { $(this).css("font-size","18px"); $(this).css("top","2px"); } else { $(this).css("font-size","14px"); $(this).css("top","0px"); } } );
     var precio = null;
        var curr_largo = null;

        if( $(".currencySimbolSpan").html()) {
            var largo = $(".currencySimbolSpan").html().length;

            $('.precio_box').each(function(){

                //bug de IE6 no funciona bien con clases multiples
                //$(this).removeClass('priceSizeSmall priceSizeMedium priceSizeLarge');

                precio = $(this).find('.priceSpan').html();

                curr_largo = largo + precio.length;
                if(curr_largo <= 6) {

                    //$(this).addClass('priceSizeLarge');
                    $(this).css('font-size',18);
                    $(this).css('padding-top', 0);
                }
                if(curr_largo > 6 && curr_largo < 9) {

                    //$(this).addClass('priceSizeMedium');
                    $(this).css('font-size',14);
                    $(this).css('padding-top', 2);
                }
                if(curr_largo >= 9) {

                    //$(this).addClass('priceSizeSmall');
                    $(this).css('font-size',12);
                    $(this).css('padding-top', 3);
                }

            });

       }

}
function ajustar_tamanios_titulos() { $('.titulo_ciudad').each( function() { if ($(this).height() <= 60) { $(this).css("font-size","16px"); $(this).css("top","2px"); } else { $(this).css("font-size","12px"); $(this).css("top","0px"); } } ); }
function MM_swapImgRestore()
{ //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages()
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() 
{ //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc)x.oSrc=x.src; x.src=a[i+2];
	 
	}
	
}

function swapImage(id,x,source) 
{ 
  var img = document.getElementById("Image1");
    if(img)
	  img.src = source;
}

function point(x,y) 
{
  var reddot = MM_findObj("reddot");
  reddot.style.left = x + 'px';
  reddot.style.top = y + 'px';
}


// hoteliers area 
function login(url)
{
	nWidth  = 340;
	nHeight = 260;
	nLeft = (screen.availWidth-nWidth)/2;
	nTop	= (screen.availHeight-nHeight)/2;
	window.open(url,null,"height="+nHeight+",width="+nWidth+",top="+nTop+",left="+nLeft+",scrollbars=no");
}



// div descripcion
function moredesc() 
{
	var divmore = document.getElementById("moredesc");
	var linkmore = document.getElementById("mrdet");
	if (divmore.style.display == "none") {
		divmore.style.display = "inline";
		linkmore.style.display = "none";
	}else {
		divmore.style.display = "none";
		linkmore.style.display = "inline";
	}
return;  
}



// div hab options 
function showdesc(opt) 
{
	var target = document.getElementById('desc-'+opt);
	var linkshow = document.getElementById('linkshow-'+opt);
	var linkhide = document.getElementById('linkhide-'+opt);

	if (target.style.display == 'none') {
		target.style.display = 'inline';
		linkshow.style.display = 'none';
		linkhide.style.display = 'inline';
		return 1;
	}
	if (target.style.display == 'inline') {
		target.style.display = 'none';
		linkshow.style.display = 'inline';
		linkhide.style.display = 'none';
		return 1;
	}
}

function bottomshowdesc(opt) 
{
	var bottomtarget = document.getElementById('bottomdesc-'+opt);
	var bottomlinkshow = document.getElementById('bottomlinkshow-'+opt);
	var bottomlinkhide = document.getElementById('bottomlinkhide-'+opt);

	if (bottomtarget.style.display == 'none') {
		bottomtarget.style.display = 'inline';
		bottomlinkshow.style.display = 'none';
		bottomlinkhide.style.display = 'inline';
		return 1;
	}
	if (bottomtarget.style.display == 'inline') {
		bottomtarget.style.display = 'none';
		bottomlinkshow.style.display = 'inline';
		bottomlinkhide.style.display = 'none';
		return 1;
	}
}


// sort select
function change_sorting(obj)
{
  goto_url(obj.options[obj.selectedIndex].value);
}

function goto_url(col){
	if(col == "rank")
	  window.location.href = window.location.href.replace(/-sort-by-.+\.html/,".html");
	else
	  window.location.href = window.location.href.replace(/([0-9]+)(-sort-by-[^\.]+)?\.html/,"$1-sort-by-"+col+".html"); 
}

function setCookie(value)
{
	var date = new Date();
	date.setTime(date.getTime()+(1000));
	var expires = "; expires="+date.toGMTString();

	document.cookie = "link_order="+value+expires+"; path=/";

}


function cambiofecha() 
{

	if(document.getElementById('check_in').value != "" && document.getElementById('check_out').value != "")
	{
		var cin = document.getElementById('check_in').value.split("/");
		var cout = document.getElementById('check_out').value.split("/");
			   
		var from = new Date(0,cin[1],0);
		from.setYear(cin[2]);
		from.setDate(cin[0]);
		
		var to = new Date(0,cout[1],0);
		to.setYear(cout[2]);
		to.setDate(cout[0]);
		
		if(from >= to )
		 {
		   alert("<x>Please, check the check-in and check-out dates.</x>");
		   
		   return false;
		 }
	 
	}
	else
		return false;
		

 return true;
	
}

// form validation
function vali()
{
	if(document.getElementById('email').value ==""){
		alert('<x>Please enter the email</x>');
		return false;
	}
	if((document.getElementById('form').check_in_d.value == "")||(document.getElementById('form').check_in_m.value == "")||(document.getElementById('form').check_in_a.value == "")){
		alert('<x>Please select the check in date (dd/mm/yyyy)</x>');
		return false;
	}
	return true;
}

var flag_mostrar = false;
var flag = false;

function telefonos_ver() {
    flag_mostrar = true;
	setTimeout("mostrar('fonos')",1);
	flag = false;
}

function telefonos_ocultar() {
	flag = true;
    setTimeout("ocultar('fonos')",1);
}

function mostrar(nombreCapa){
	if(flag_mostrar){
		document.getElementById(nombreCapa).style.visibility="visible";
	}
}
function ocultar(nombreCapa){
	if(flag) {
		document.getElementById(nombreCapa).style.visibility="hidden";	
	}
}

function change_barrio(barrio)
{

	arr = window.location.href.split("&");
	
	if ( window.location.href.search("zone") == -1 ) {
		window.location.href = window.location.href + "&zone="+barrio.value;
	} else {
		window.location.href = arr[0] + "&zone="+barrio.value;;
	}

}

function change_sorting(obj)
{
  goto_url(obj.options[obj.selectedIndex].value);
}

function cargaImagen(arg)
{
	if (document.images)
	{
		//document.write("Cargando imagen: " + arg + "...<br>");
		rslt = new Image();
		rslt.src = arg;
		//document.write("\t cargada con éxito<br>");
		return rslt;
	}
}

function echeck(str) {

		var mtch  = str.match(/^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$/);
		
		if(mtch==null)
			return false;
		else
			return true;
				
}


function enviar_suscripcion() {
	email = document.getElementById("email");
	
	ok = echeck(email.value);
	
	if(ok==false) {
		news = document.getElementById("news_error");
		news.style.display = "block";
		
		news = document.getElementById("news_ok");
		news.style.display = "none";
		news = document.getElementById("mail_existe");
		news.style.display = "none";
	} else {
		
	var html = $.ajax(
					 {
					  url: "/"+idio+"newsletter_add.php?email="+email.value,
					  async: false,
					  cache: false
					 }
					 ).responseText;
			
		if(html==1) {
			news = document.getElementById("news_ok");
			news.style.display = "block";
			
			news = document.getElementById("mail_existe");
			news.style.display = "none";
			
			news = document.getElementById("news_error");
			news.style.display = "none";
			
		} else {
			news = document.getElementById("mail_existe");
			news.style.display = "block";
			
			news = document.getElementById("news_error");
			news.style.display = "none";
			
			news = document.getElementById("news_ok");
			news.style.display = "none";
			
		}
		
	}
}

  window.g_PopupIFrame = null;

    function IsIE()
    {
        return ( (navigator.appName=='Microsoft Internet Explorer')? parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):0);
    }

    function HidePopupDiv(divID)
    {
        var  divTelefonos=document.getElementById('contenedor');
        var divPopup;
        divPopup=document.getElementById(divID);
        divPopup.style.visibility = "hidden";

        if (IsIE() && IsIE() <= 6)
        {
            if (window.g_PopupIFrame != null)
                divTelefonos.removeChild(window.g_PopupIFrame);
            window.g_PopupIFrame=null;
        }
    }
    function ShowPopupDiv(divID)
    {
        var divTelefonos=document.getElementById('contenedor');
        var divPopup=document.getElementById(divID);
        if (!IsIE() || IsIE() > 6)
        {
            //Just display the div
            divPopup.style.visibility ="visible";
            return;
        }

        //Increase default zIndex of div by 1, so that DIV appears before IFrame
        divPopup.style.zIndex=divPopup.style.zIndex+1;
        var iFrame = document.createElement("IFRAME");
        iFrame.setAttribute("src", "");
        //Match IFrame position with divPopup
        iFrame.style.position="absolute";
        iFrame.style.left =divPopup.offsetLeft + 'px';
        iFrame.style.top =divPopup.offsetTop + 'px';
        iFrame.style.width =divPopup.offsetWidth + 'px';
        iFrame.style.height =divPopup.offsetHeight + 'px';
        iFrame.style.zindex = 0;
        divTelefonos.appendChild(iFrame);
        //Store iFrame in global variable, so it can get removed when divPopup is hidden
        window.g_PopupIFrame=iFrame;
        divPopup.style.visibility ="visible";
    }

    function getCookie(c_name) {
    if (document.cookie.length>0) {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        {
        c_start=c_start + c_name.length+1;
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
        }
      }
    return "";
}
