

function getCookie(name)
{
    var sCookies = document.cookie;
    var sPrefix = name + '=';
    if(sCookies == null)
    {
        return null;
    }
    var nBegin = sCookies.indexOf('; ' + sPrefix);
    if(nBegin == -1)
    {
        nBegin = sCookies.indexOf(sPrefix);
        if(nBegin == -1)
        {
            return null;
        }
    }
    else
    {
        nBegin += 2;
    }
    var nEnd = sCookies.indexOf(';', nBegin);
    if(nEnd == -1)
    {
        nEnd = sCookies.length;
    }
    return unescape(sCookies.substring(nBegin + sPrefix.length, nEnd));
}


function setCookie(sName, sValue, nDays)
{
    var dExpires = null;
    if(nDays > 0)
    {
        dExpires = new Date();
        dExpires.setTime(dExpires.getTime() + (nDays * 24 * 3600 * 1000));
    }
    var sCookie = sName + "=" + escape(sValue) +
    ((dExpires == null) ? "" : "; expires="
    + dExpires.toGMTString())
    + "; path=/";
    
    document.cookie = sCookie;
}

function getMouseY(e)
{
    if (!e && window.event) var e = window.event;
    if (e && e.pageY) return e.pageY+20;
    if (e && e.clientY) return e.clientY + document.body.scrollTop+20;
    return 50;
}


function getMouseX(e)
{
    if (!e && window.event) var e = window.event;
    if (e && e.pageX) return e.pageX;
    if (e && e.clientX) return e.clientX + document.body.scrollLeft;
    return 50;
}


function doCookieCheck()
{
    var sCookie = getCookie('NLPB');
    if(sCookie != null)
    {
        return false;
    }
    sCookie = getCookie('NLPS');
    if(sCookie != null)
    {
        return false;
    }
    sCookie = getCookie('NLPP');
    if(sCookie != null)
    {
        return false;
    }
    // Session cookies not accepted
    setCookie('NLPS', 'true', 0);
    sCookie = getCookie('NLPS');
    if(sCookie == null)
    {
        return false;
    }
    setCookie('NLPP', 'true', 1/2);
    return true;
}


function showObsoleteWarning()
{
    cookie = getCookie('OBW');
    if (cookie == null)
    {
        setCookie('OBW', '1', '1');
        document.write('<br />');
        document.write('<table border="0" width="98%" cellspacing="0" cellpadding="10" bgcolor="#FFCC33" align="center">');
        document.write('<tr>');
        document.write('<td class="dt1">');
        document.write('<b>We noticed that you\'re using an outdated browser. The TripAdvisor web site may not display properly. Upgrading your browser will ensure the best possible experience on our web site: ');
        document.write('<a href="http://www.microsoft.com/ie/">Internet Explorer</a> &#183; ');
        document.write('<a href="http://www.mozilla.org/">Mozilla</a> &#183; ');
        document.write('<a href="http://channels.netscape.com/ns/browsers/default.jsp">Netscape</a> &#183; ');
        document.write('<a href="http://www.opera.com/">Opera</a>.</b>');
        document.write('</td>');
        document.write('</tr>');
        document.write('</table>');
        document.write('<br />');
    }
}



function OnSelectDestination (newURL)
{
//window.alert(newURL);
    if ( newURL != "00"){ location.href =newURL;}
    else{alert("Please, select a destination !")}
}

//---------------------------------------------------------------------
//--------------------------------------------------------------------

function padMonth(m)
{
    var s=""+m;
    if (s.length==1) return "0"+s;
    return s;
}


function setInDate(d)
{
    if(cal_dcomp(getInDate(0),d)>=0){
	var din=new Date(d);
	din.setMilliseconds(-86400000);
	HotelForm.inDay.selectedIndex=din.getDate()-1;
	HotelForm.inMonth.selectedIndex=din.getMonth();
    }
return;
}


function setInDate1(d)
{
	HotelForm.inDay.selectedIndex=d.getDate()-1;
	HotelForm.inMonth.selectedIndex=d.getMonth();
	setOutDate(d);
return;
}


function setOutDate(d)
{
    if(cal_dcomp(getOutDate(0),d)<=0){
	var dout=new Date(d);

	dout.setMilliseconds(86400000);
	HotelForm.outDay.selectedIndex=dout.getDate()-1;
	HotelForm.outMonth.selectedIndex=dout.getMonth();
    }
return;
}


function setOutDate1(d)
{
	HotelForm.outDay.selectedIndex=d.getDate()-1;
	HotelForm.outMonth.selectedIndex=d.getMonth();
	setInDate(d);
return;
}


function getInDate(n)
{
    var f;
    var date=new Date();
    var year=date.getFullYear();
    if(n==0){f=HotelForm;}

   var month=f.inMonth.selectedIndex;
   var day=f.inDay.selectedIndex+1;

   return new Date(year,month,day);
}


function getOutDate(n)
{
    var f;
    var date=new Date();
    var year=date.getFullYear();
    if(n==0){f=HotelForm;}

   var month=f.outMonth.selectedIndex;
   var day=f.outDay.selectedIndex+1;

      return new Date(year,month,day);
}





function getLastDate()
{
    var d = new Date();
    d.setFullYear(d.getFullYear()+1);
    d.setDate(1);
    d.setMilliseconds(-86400000);
}


function showHideCurrency() 
{
	document.getElementById('ExpandCurrency').style.display = "none";
    document.getElementById('CurrencyBox').style.display = "block"; 
}


function fillRates(currency) 
{
   try 
   {
      currency = (currency == null) ? "USD" : currency;
      var currencySelect = document.getElementById("currency");
      currencySelect.value = currency;
      var rateSelect = document.getElementById("minmaxrate").options;
      rateSelect.length = 0;
      var levels = currencyLevel[currency];
      for (var i = 0 ; i < levels.length ; i += 2) 
      {
         rateSelect[i/2] = new Option(levels[i], levels[i+1]);
         // if the current max rate is in the minmax value string, select it
         if ( levels[i+1].indexOf(maxRate) > 0) 
         {
            rateSelect.selectedIndex = i/2;
         }
      }
   }
   catch(e)
   {
   // form not generated for this page
   }
}

function fillRatesAndClear(currency)
{
	maxRate = '9999999';
	fillRates(currency);
}


function openSurveyWindow(sURL)
{
   try 
   {
      window.open(sURL, "tawebsurveyor", "toolbar=0,resizable=1,menubar=0,location=0,status=0,scrollbars=3,width=480,height=640,screenX=30,screenY=25,left=30,top=25");
   }
   catch(e)
   {
      // popup blocker?
   }
}


//-------------------------------------------------------------------------------------------------------------------------
function d_setHTMLselectMonths(){
          var date=new Date();
          document.getElementById("'inMonth").innerHTML= d_selectMonths(date);
}


function d_selectMonths(d){
          var language=L;
          var date=d; var j;var z;

        var month=date.getMonth();
        var year= date.getFullYear();

        var s="";
       
        for (var i=0; i<=11; i++){
	j=month+i;
	z=month+i;
	if(j>11){j=j%11-1;if(z==12){year+=1;}}
//        alert("i= "+i);
	s+="<option value='"+cal_valueOption(j,year)+"'>"+cal_months[j]+year+"</option>";
	 }
        return s;
}

function cal_valueOption(m,y) {
        var m=m;var y=y;
        m=padMonth(m+1);
        var s=m+"/"+y;
//         alert("s= "+s);
       return s;
}

//----------------------------------------------------------------------------------------------------------------------------
function setDateForm(q){
          var form=document.HotelForm;
          var date=new Date();
          var year=date.getFullYear();
          var monthin=date.getMonth();
          var dayin=date.getDate()-1;

         if(q==0){
//window.alert("monthin="+monthin+"\n"+" dayin="+ dayin);
          form.inMonth.selectedIndex=monthin;
          form.inDay.selectedIndex=dayin;
	    switch(monthin)
		{
	    	  case 1:
			    var lastLeapYear= 2004;
			    var isLeapYear=false;
			    var testforLeapYear=(year - lastLeapYear)%4;
			    var dayoffebruary;
			    if(testforLeapYear==0)
				   {
					isLeapYear=true;
				   }
			    else
				   {
					isLeapYear=false;
				   }
			    if(isLeapYear)
				   {
					dayoffebruary= 29;
				   }
			    else
				   {
					dayoffebruary= 28;
				   }
			    if(dayin<(dayoffebruary-1))
				   {
					form.outDay.selectedIndex=dayin+1;
          				form.outMonth.selectedIndex=monthin;
				   }
			    else
				   {
					form.outDay.selectedIndex=0;
					form.outMonth.selectedIndex=monthin+1;
				   }	
			break;
		  default:
			if(monthin==0 || monthin==2 || monthin==4 || monthin==6 || monthin==7 ||monthin==9 || monthin==11)
			  {
//window.alert("month31");
			    if(dayin<30)
				   {
					form.outDay.selectedIndex=dayin+1;
          				form.outMonth.selectedIndex=monthin;
				   }
			    else
				   {
					form.outDay.selectedIndex=0;
					form.outMonth.selectedIndex=monthin+1;
				   }	
			  }
			else
			  {
//window.alert("month30");
			    if(dayin<29)
				   {
					form.outDay.selectedIndex=dayin+1;
          				form.outMonth.selectedIndex=monthin;
				   }
			    else
				   {
					form.outDay.selectedIndex=0;
					form.outMonth.selectedIndex=monthin+1;
				   }
			  }
			break;
		}
         }
          else if(q==1){
//window.alert("nessun settaggio delle date di check in e check out"+"\n"+"data di return=  "+ new Date(year,monthin,dayin+1));
	return new Date(year,monthin,dayin+1);
          }

}



function setDateFormX(q){
          var form=document.HotelForm;
          var date=new Date();
          var year=date.getFullYear();
          var monthin=date.getMonth();
          var dayin=date.getDate()-1;

         if(q==0){
//window.alert("monthin="+monthin+"\n"+" dayin="+ dayin);
          form.inMonth.selectedIndex=monthin;
          form.inDay.selectedIndex=dayin;
          form.outMonth.selectedIndex=monthin;
          form.outDay.selectedIndex=dayin+1;
         }
          else if(q==1){
//window.alert("nessun settaggio delle date di check in e check out"+"\n"+"data di return=  "+ new Date(year,monthin,dayin+1));
	return new Date(year,monthin,dayin+1);
          }

}

//---------------------------------------------------------------------
//--------------------------------------------------------------------


function controldate(a){
	var x1;var x2;
	if(a==1){ x1=document.HotelForm.inDay; x2=document.HotelForm.inMonth; }
	else if(a==2){ x1=document.HotelForm.outDay; x2=document.HotelForm.outMonth; }
	var d=x1.selectedIndex+1;
	var m=x2.selectedIndex;

           if(m==3 || m==5 || m==8 || m==10) {
              if(d>30) {
              x1.selectedIndex=29;

              }
            } else if(m==1){
                   var date=new Date();date.setMonth(2);date.setDate(1);date.setMilliseconds(-86400000);
	    var d1= date.getDate();
		     if( d1==29 && d>29){x1.selectedIndex=28; }
		    else if(d1==28 && d>28){x1.selectedIndex=27; }
            }
}

//---------------------------------------------------------------------
//--------------------------------------------------------------------

function newPano(a,b,c,d){

document.ptviewer.newPanoFromList(a,b,c,d)
document.ptviewer.startAutoPan(0.1,0,1)
              }
