﻿// JScript File
// Open the big map on Localização channel
// PRODUCAO
//var strNormalHost = "http://192.168.12.13/CasadaInsua/siteCasadaInsua/";
var strNormalHost = "http://www.casadainsua.pt/";
var strSecureHost = "https://www.visabeiraturismo.pt/secure/casadainsua/";
var strHostName = "www.casadainsua.pt";
// var strHostName = "192.168.12.13";

function openMap( number )
{
    if ( number == 1 ) {
        dmapaP.style.display='block';
        dmapaP.style.visibility='visible';
        dmapaR.style.display='none';
        dmapaR.style.visibility='hidden';        
    }
    else if ( number == 2 ) {
        dmapaP.style.display='none';
        dmapaP.style.visibility='hidden';
        dmapaR.style.display='block';
        dmapaR.style.visibility='visible';
    }

    try{
        xmlhttp1 = new XMLHttpRequest();
    }catch(ee){
        try{
            xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                xmlhttp1 = false;
            }
        }
    }

    if ( number == 1 ) {
        window.location.hash = 'MP';    
        xmlhttp1.open("GET", "Content.aspx#MP",true);
    }
    else if ( number == 2 ) {
        window.location.hash = 'MR';    
        xmlhttp1.open("GET", "Content.aspx#MR",true);
    }

    xmlhttp1.onreadystatechange=function() {
        if (xmlhttp1.readyState==4){ 
        }
    }
    xmlhttp1.send(null)
    
    var txtTitle = window.document.title;
    var txtUrl = window.location.href;
    
    if ( number == 1 ) {
        if (txtTitle.indexOf("#MP") > 0)
           window.document.title = 'Hotel Casa da Ínsua';
        else if (txtUrl.indexOf("#MP") > 0)
            window.document.title = 'Hotel Casa da Ínsua';
    }
    else if ( number == 2 ) {
        if (txtTitle.indexOf("#MR") > 0)
           window.document.title = 'Hotel Casa da Ínsua';
        else if (txtUrl.indexOf("#MR") > 0)
            window.document.title = 'Hotel Casa da Ínsua';
    }
}


// Jump from FAQS
function jumpFAQs( number )
{
    try {
        xmlhttp1 = new XMLHttpRequest();
    }
    catch(ee) {
        try {
            xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(E) {
                xmlhttp1 = false;
            }
        }
    }

    switch ( number ) {
        case 0:        
            window.location.hash = 'faqTop';    
            xmlhttp1.open("GET", "Content.aspx#faqTop",true);
            break;
    
        case 1:        
            window.location.hash = 'P1';    
            xmlhttp1.open("GET", "Content.aspx#P1",true);
            break;
        case 2:        
            window.location.hash = 'P2';    
            xmlhttp1.open("GET", "Content.aspx#P2",true);
            break;
        case 3:        
            window.location.hash = 'P3';    
            xmlhttp1.open("GET", "Content.aspx#P3",true);
            break;
        case 4:        
            window.location.hash = 'P4';    
            xmlhttp1.open("GET", "Content.aspx#P4",true);
            break;
        case 5:
            window.location.hash = 'P5';    
            xmlhttp1.open("GET", "Content.aspx#P5",true);
            break;
        case 6:
            window.location.hash = 'P6';    
            xmlhttp1.open("GET", "Content.aspx#P6",true);
            break;
    }
        
    xmlhttp1.onreadystatechange=function() {
        if (xmlhttp1.readyState==4){ 
        }
    }
    xmlhttp1.send(null)
    
    var txtTitle = window.document.title;
    var txtUrl = window.location.href;
    
    if (txtTitle.indexOf("#faqTop") > 0 || txtTitle.indexOf("#P1") > 0 || txtTitle.indexOf("#P2") > 0 || txtTitle.indexOf("#P3") > 0 || txtTitle.indexOf("#P4") > 0 || txtTitle.indexOf("#P5") > 0 || txtTitle.indexOf("#P6") > 0)
       window.document.title = 'Hotel Casa da Ínsua';
    else if (txtUrl.indexOf("#faqTop") > 0 || txtUrl.indexOf("#P1") > 0 || txtUrl.indexOf("#P2") > 0 || txtUrl.indexOf("#P3") > 0 || txtUrl.indexOf("#P4") > 0 || txtUrl.indexOf("#P5") > 0 || txtUrl.indexOf("#P6") > 0 )
        window.document.title = 'Hotel Casa da Ínsua';
}

function openMenu(openItem)
{    
}

function setCookie(c_name,value,expiredays) {
    var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

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 "";
}


function displayContent(contentid)
{
    setCookie('canalid',contentid,1);

    var txtTitle = window.document.title;
    var txtUrl = window.location.href;

    if ( getCookie('canalid') == 1)
    {
        if ( txtUrl.indexOf("#MP") > 0 || txtUrl.indexOf("#MR") > 0 || txtUrl.indexOf("#pagePhoto") > 0 || txtUrl.indexOf("#faqTop") > 0 || txtUrl.indexOf("#P1") > 0 || txtUrl.indexOf("#P2") > 0 || txtUrl.indexOf("#P3") > 0 || txtUrl.indexOf("#P4") > 0 || txtUrl.indexOf("#P5") > 0 || txtUrl.indexOf("#P6") > 0 ) {
            window.document.title = 'Hotel Casa da Ínsua';
        }
    }
    
    if(contentid.toString()!="0")
    {
        displayPath(contentid);
        var content = document.getElementById("content");
        content.innerHTML = loadingMsg;
        var strContent = "";
        try{
            xmlhttp1 = new XMLHttpRequest();
        }catch(ee){
            try{
                xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
                try{
                    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(E){
                    xmlhttp1 = false;
                }
            }
        }

        xmlhttp1.open("GET", "Content.aspx?contentid="+contentid,true);
        xmlhttp1.onreadystatechange=function() {
            if (xmlhttp1.readyState==4){ 
                //building the content
               strContent = xmlhttp1.responseText.toString();
               content.innerHTML = strContent;     
               
               if (strContent.indexOf("ReNameTitle") != -1 )
                    window.document.title = 'Hotel Casa da Ínsua';                    
               resetTitle()
            }
        }
        xmlhttp1.send(null)
    }
    else
    {
        var content = document.getElementById("content");
        content.innerHTML = "";
        resetTitle()
    }
}

function openMenuAndDisplayContentWithSearch(channelid,contentid, searchStr)
{
    openMenuAndDisplayContent(channelid,contentid + "&searchStr="+searchStr)
    fillTxtSearch();
}

//This function is used to display content and open the side menu in once
function openMenuAndDisplayContent(channelid,contentid)
{
    // alert("channelid: " + channelid + " - contentid: " + contentid);
    // PARA SECURE
    if ( (channelid.toString() == "21") || (contentid.toString() == "34") ) {
            //window.location.href = strSecureHost + "default.aspx?channelid=" + channelid + "&contentid=" + contentid;
    }
    else
    {
        /*
        if ( location.hostname == strHostName && location.pathname == "/CasadaInsua/siteCasadaInsua/" ) {
            strHost = strNormalHost;
        } else if ( location.hostname == strHostName && location.pathname == "/CasadaInsua/siteCasadaInsua/" ) { 
            strHost = strNormalHost;
        }
        */
    }

    // PARA PEDIDO DE INFORMAÇÃO
    if ( (channelid.toString() == "18") || (contentid.toString() == "29") ) {
        window.location.href = strNormalHost + "InformationForm.aspx?channelid=" + channelid + "&contentid=" + contentid + "&lang=" + document.getElementById("hidLang").value;
    }

    // PARA GALLERY 
    // NEW 2009-09-25
    else if ( (channelid.toString() == "44") || (contentid.toString() == "90") ) {
        window.location.href = strNormalHost + "Gallery.aspx?channelid=" + channelid + "&contentid=" + contentid + "&lang=" + document.getElementById("hidLang").value;
    }
    // SE PEDIDO PARA VOLTAR NORMAL SEM PEDIDO DE INFORMAÇÃO
    else if ( document.getElementById("hidChannel").value == "18" || document.getElementById("hidChannel").value == "29" || document.getElementById("hidChannel").value == "44" || document.getElementById("hidChannel").value == "90" )
    {
        window.location.href = strNormalHost + "default.aspx?channelid=" + channelid + "&contentid=" + contentid + "&lang=" + document.getElementById("hidLang").value;
    }
    else if(contentid.toString() != "0")
    {
        // SE É 8 não mostra conteúdo e só banners
        if ( ( channelid.toString() != "0" ) || ( channelid.toString() != "8" ) ) {
            displayBanners(channelid);
        }
        else 
        { 
            displayBanners(0);
        }
        
        
        if (channelid.toString() == "54")
        {
            if ( document.getElementById("dvGallery") != null ) {
                document.getElementById("dvGallery").style.display = "block";
                document.getElementById("dvGallery").style.visibility = "visible";
            }
        }
        else
        {
            if ( document.getElementById("dvGallery") != null ) {
                document.getElementById("dvGallery").style.display = "none";
                document.getElementById("dvGallery").style.visibility = "hidden";
            }
        }
        
        // openMenu(channelid);

        displayContent(contentid);

        if ( channelid.toString() != "8" ) {
            resizeFlash('diminuir'); 

            document.getElementById("dvHome").style.display = "block";
            document.getElementById("dvHome").style.visibility = "visible";
            document.getElementById("dvHomeLoop").style.display = "none";
            document.getElementById("dvHomeLoop").style.visibility = "hidden";
            
            if ( ( navigator.appName.indexOf("Microsoft") !=-1 ) || ( navigator.appVersion.indexOf("MSIE") != -1 )) {
                var flashObj = getFlashMovie("home");

                if (channelid.toString() == "9" || channelid.toString() == "10" ||
                    channelid.toString() == "11" || channelid.toString() == "38" ||
                     channelid.toString() == "39" || channelid.toString() == "40" ||
                     channelid.toString() == "42" || channelid.toString() == "54" ||
                     channelid.toString() == "53" || channelid.toString() == "5") 

                    flashObj.SetVariable("imgToLoad", channelid + ".swf");
                  

                else

                    flashObj.SetVariable("imgToLoad", channelid + ".jpg");
                              
            } 
            
            else if ( ( navigator.appName == "Netscape" ) || ( navigator.userAgent.indexOf("Firefox") != -1 )) {

                if ( channelid.toString() == "9" || channelid.toString() == "10" || 
                    channelid.toString() == "11" || channelid.toString() == "38" || 
                     channelid.toString() == "39" || channelid.toString() == "40" || 
                     channelid.toString() == "42" || channelid.toString() == "54" ||
                     channelid.toString() == "53" || channelid.toString() == "5")
                     
                    document.getElementById('objHomeFF').innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='802' height='293' id='homeFF'><embed src='swf/home.swf?imgToLoad="+ channelid + ".swf' loop='false' menu='false' quality='high'  width='802' height='213' name='homeFF' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' wmode='transparent'  swLiveConnect='true' /></object>";
                else
                    document.getElementById('objHomeFF').innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='802' height='293' id='homeFF'><embed src='swf/home.swf?imgToLoad="+ channelid + ".jpg' loop='false' menu='false' quality='high'  width='802' height='213' name='homeFF' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' wmode='transparent'  swLiveConnect='true' /></object>";
            }
            
        }
        else if ( channelid.toString() == "8" ) {
            document.getElementById("dvHomeLoop").style.display = "block";
            document.getElementById("dvHomeLoop").style.visibility = "visible";            
             document.getElementById("dvHome").style.display = "none";
             document.getElementById("dvHome").style.visibility = "hidden";
            var flashObj = getFlashMovie("home_loop");
            resizeFlash('aumentar');
        }


    }
}

//This function is used to display content and open the side menu in once
function openMenuAndDisplayContentReserves(channelid,contentid, rooms, grownups, children, checkin, checkout)
{
    openMenuAndDisplayContent(channelid, contentid);
    if ( (channelid.toString() == "21") || (contentid.toString() == "34") ) {
        //window.location.href = strSecureHost + "ReservesForm.aspx?channelid=" + channelid + "&contentid=" + contentid + "&rooms=" + rooms + "&grownups=" + grownups + "&children=" + children + "&checkin=" + checkin + "&checkout=" + checkout + "&lang=" + document.getElementById("hidLang").value;
    }
    else
    {
        /*
        if ( location.hostname == strHostName && location.pathname == "/site/" ) {
            strHost = strNormalHost;
        } else if ( location.hostname == strHostName && location.pathname == "/site/" ) { 
            strHost = strNormalHost;
        } 
        */
        // strHost = "http://www.hotelmontebelo.pt/site";
    }
}

function posLayers()
{
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            winW = window.innerWidth;
            document.getElementById("banners").style.left = (winW/2)-225;
        }
        else if (navigator.appName.indexOf("Microsoft")!=-1) {
            winW = document.body.offsetWidth;
            document.getElementById("banners").style.left = (winW/2)-225;
        }
        else
        {
        }
    } 
}

function posLayersReserves()
{
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            winW = window.innerWidth;
        }
        else if (navigator.appName.indexOf("Microsoft")!=-1) {
            winW = document.body.offsetWidth;
        }
        else
        {
        
        }
    }
}

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;


function openMenuFlash(channelid)
{
    var flashObj = getFlashMovie("menuflash");
    if(navigator.appName.indexOf("Microsoft") > -1)
    {
        flashObj.sendTextToFlash(channelid);
    }
}

function getFlashMovie(movieName) {
    var flashObj = (document[movieName] == null) ? window[movieName] : document[movieName];
    return flashObj;
}


function menuflash_DoFSCommand(command, args) 
{
    var sampleFlaMovieObj = getFlashMovie("menuflash");
    
    if (command == "openMenuAndDisplayContent")
    {
        var args1 = args.split(",");
        openMenuAndDisplayContent(args1[0],args1[1]);
    }
    if (command == "closeDiv")
    {
        closeDiv();
    }
    if (command == "openDiv")
    {
        openDiv();
    }
}

function resizeFlash(command) 
{
    var sampleFlaMovieObj;
        
    if (command == "aumentar")
    {
        document.getElementById("tdTopImg").style.height = 293;
        
        if ( ( navigator.appName.indexOf("Microsoft") !=-1 ) || ( navigator.appVersion.indexOf("MSIE") != -1 )) {
            sampleFlaMovieObj = getFlashMovie("home");
            sampleFlaMovieObj.height = 293;
        }
        document.getElementById("dvBoxLeft").style.height = 278;
    }
    if (command == "diminuir")
    {
        if ( ( navigator.appName.indexOf("Microsoft") !=-1 ) || ( navigator.appVersion.indexOf("MSIE") != -1 )) {
            document.getElementById("tdTopImg").style.height = 213;
            sampleFlaMovieObj = getFlashMovie("home");
            sampleFlaMovieObj.height = 213;
            document.getElementById("dvBoxLeft").style.height = 200;
        } 

        if ( ( navigator.appName == "Netscape" ) || ( navigator.userAgent.indexOf("Firefox") != -1 )) {
            if ( navigator.userAgent.indexOf("Safari") != -1 )
            {
                document.getElementById("tdTopImg").style.height = 213 + 'px';
                document.getElementById("dvHome").style.height = 213 + 'px';
                document.getElementById("dvBoxLeft").style.height = 198 + 'px';
                document.getElementById("tdLeftBox").style.height = 198 + 'px';
            }
            
            if ( navigator.userAgent.indexOf("Firefox") != -1 ) {
                document.getElementById("tdTopImg").style.height = 213 + 'px';
                document.getElementById("dvHome").style.height = 213 + 'px';
                document.getElementById("dvBoxLeft").style.height = 198 + 'px';
                document.getElementById("tdLeftBox").style.height = 198 + 'px';
            }
        }
    }
}

// Hook for Internet Explorer
if (navigator.appName && 
  navigator.appName.indexOf("Microsoft") != -1 &&
  navigator.userAgent.indexOf("Windows") != -1 && 
  navigator.userAgent.indexOf("Windows 3.1") == -1) 
{
  document.write('<SCRIPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write(
    'Sub menuflash_FSCommand(ByVal command, ByVal args)\n');
  document.write(
    ' call menuflash_DoFSCommand(command, args)\n');
  document.write('end sub\n');
  document.write('</SCRIPT\> \n');
}

function openDiv()
{
     //document.getElementById("menu").style.clip = "rect(auto auto auto auto)"; 
}

function closeDiv()
{
    document.getElementById("menu").style.clip = "rect(auto auto 50 auto)"; 
}

function displayPath(contentid)
{
    //alert(contentid);
    var strPath = "";
    try{
        xmlhttp2 = new XMLHttpRequest();
    }catch(ee){
        try{
            xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                xmlhttp2 = false;
            }
        }
    }

    xmlhttp2.open("GET", "Path.aspx?contentid="+contentid,true);
    xmlhttp2.onreadystatechange=function() {
        if (xmlhttp2.readyState==4){ 
            //building the path
           strPath = xmlhttp2.responseText.toString();
           var path = document.getElementById("path");
           path.innerHTML = strPath;
           //alert(strPath);
        }
    }
    xmlhttp2.send(null)
}


//Function used to set the language links style
function markLang(lang)
{
    document.getElementById("but"+lang).className = "selectedLang";
}

//Function used to set the language links style
function markLangWithGallery(lang, channelid)
{
    resizeFlash('diminuir');
    
    if ( channelid.toString() != "8" ) {
        document.getElementById("dvHome").style.display = "block";
        document.getElementById("dvHome").style.visibility = "visible";

        document.getElementById("dvHomeLoop").style.display = "none";
        document.getElementById("dvHomeLoop").style.visibility = "hidden";
        
        if ( ( navigator.appName.indexOf("Microsoft") !=-1 ) || ( navigator.appVersion.indexOf("MSIE") != -1 )) {
            var flashObj = getFlashMovie("home");
            flashObj.SetVariable("imgToLoad","18.jpg");
        } 
        else if ( ( navigator.appName == "Netscape" ) || ( navigator.userAgent.indexOf("Firefox") != -1 )) {
            // document.embeds['objHomeFF'].SetVariable("imgToLoad","18.jpg");
            document.getElementById('objHomeFF').innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='802' height='293' id='homeFF'><embed src='swf/home.swf?imgToLoad="+channelid + ".jpg' loop='false' menu='false' quality='high'  width='802' height='213' name='homeFF' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' wmode='transparent'  swLiveConnect='true' /></object>";
            
        }    
    }
}

//Function used to set the language links style
function markLangWithInformationForm(lang, channelid)
{
    //document.getElementById("but"+lang).className = "selectedLang";

    resizeFlash('diminuir');
    
    if ( channelid.toString() != "8" ) {
        document.getElementById("dvHome").style.display = "block";
        document.getElementById("dvHome").style.visibility = "visible";

        document.getElementById("dvHomeLoop").style.display = "none";
        document.getElementById("dvHomeLoop").style.visibility = "hidden";
        
        if ( ( navigator.appName.indexOf("Microsoft") !=-1 ) || ( navigator.appVersion.indexOf("MSIE") != -1 )) {
            var flashObj = getFlashMovie("home");
            flashObj.SetVariable("imgToLoad","18.jpg");
        } 
        else if ( ( navigator.appName == "Netscape" ) || ( navigator.userAgent.indexOf("Firefox") != -1 )) {
            // document.embeds['objHomeFF'].SetVariable("imgToLoad","18.jpg");
            document.getElementById('objHomeFF').innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='802' height='293' id='homeFF'><embed src='swf/home.swf?imgToLoad="+channelid + ".jpg' loop='false' menu='false' quality='high'  width='802' height='213' name='homeFF' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' wmode='transparent'  swLiveConnect='true' /></object>";
            
        }    
    }
}

function openSearch(searchStr,channelid,contentid)
{
    openMenuAndDisplayContent(channelid,contentid + "&searchStr="+searchStr)
    fillTxtSearch();
}

function changeSearchImg()
{
    document.getElementById("imgSearch").src = "imgs/arrow_search_hover.gif";
}

function resetSearchImg()
{
    document.getElementById("imgSearch").src = "imgs/arrow_search.gif";
}
function fillTxtSearch()
{
    
    document.getElementById("txtSearch").value = searchMsg;
    //align the search button in firefox
    if(navigator.appName.indexOf("Microsoft") == -1)
    {
        document.getElementById("imgSearch").style.paddingBottom="2";
    }
}
function resetTxtSearch()
{
    document.getElementById("txtSearch").value = "";
}

//RESERVAS ***********************************************************

function setReservationDates(sDate)
{
     var now = new Date();
     var strD = now.getDate();
     var strDD = (strD < 10) ? '0' + strD : strD;
     var strM = now.getMonth() + 1;
     var strMM = (strM < 10) ? '0' + strM : strM;
     var strYear = now.getYear();
     
     //Data a validar
     var vReservationDateD = sDate.substring(0,2);
     var vReservationDateM = sDate.substring(3,5);
     var vReservationDateY = sDate.substring(6,10);

     if ( parseFloat(vReservationDateY) == parseFloat(strYear))
     {
        if (parseFloat(vReservationDateM) > parseFloat(strMM))
        {
            //se  mes for no futuro a data é sempre maior e não precisamos de testar o dia
            return true;
        }//mes
        else
        {
            if (parseFloat(vReservationDateM) == parseFloat(strMM)) //mesmo mes que a data de hoje
            {
                if (parseFloat(vReservationDateD) >= parseFloat(strDD))//testar o dia
                {
                    return true;
                }
                else// mes inferior
                {
                    return false;
                }
            
            }else
            {
            //mes inferior
                return false;
            }
        }
     } //ano

     //maior que data corrente
     else if ( parseFloat(vReservationDateY) > parseFloat(strYear))
     {
        return true;
     } //ano
     else
     {
        return false;
     }  
}

function CompareCheckInCheckOut(sDateIn, sDateOut)
{
          
     var vReservationDateInD = sDateIn.substring(0,2);
     var vReservationDateInM = sDateIn.substring(3,5);
     var vReservationDateInY = sDateIn.substring(6,10);
     
     //Data check out a validar
     
     var vReservationDateOutD = sDateOut.substring(0,2);
     var vReservationDateOutM = sDateOut.substring(3,5);
     var vReservationDateOutY = sDateOut.substring(6,10);

     //maior que data corrente
     if ( parseFloat(vReservationDateOutY) == parseFloat(vReservationDateInY))
     {
        if (parseFloat(vReservationDateOutM) > parseFloat(vReservationDateInM))
        {
            //se  mes for no futuro a data é sempre maior e não precisamos de testar o dia
            return true;
        }//mes
        else
        {
            if (parseFloat(vReservationDateOutM) == parseFloat(vReservationDateInM)) //mesmo mes que a data de hoje
            {
                if (parseFloat(vReservationDateOutD) >= parseFloat(vReservationDateInD))//testar o dia
                {
                    return true;
                }
                else// mes inferior
                {
                    return false;
                }
            
            }else
            {
            //mes inferior
                return false;
            }
        }
     } //ano

     //maior que data corrente
     else if ( parseFloat(vReservationDateOutY) > parseFloat(vReservationDateInY))
     {
        return true;
     } //ano
     else
     {
        return false;
     }  
}


function openAvailability(channelid,contentid,rooms,grownups,children,checkin,checkout)
{  
     var now = new Date();
     
     var strD = now.getDate();
     var strDD = (strD < 10) ? '0' + strD : strD;
     var strM = now.getMonth() + 1;
     var strMM = (strM < 10) ? '0' + strM : strM;
     var strYear = now.getYear();
     
     var strDate = strDD + "/" + strMM + "/" + strYear;
     
    var msg = new String('');
    var lang = "";
    lang = document.getElementById("hidLang").value;

    var maxPersonInRoom = 3;
    var auxRoomPessoa = 0;
    auxRoomPessoa = (parseFloat(grownups) + parseFloat(children)) / rooms;

    if ( auxRoomPessoa > maxPersonInRoom ) 
    {
	    if ( lang == 'pt' ) {
		    msg = msg + 'Cada quarto apenas permite uma ocupação máxima de 3 pessoas. \n';
        }		    
        else if ( lang == 'en' ) {
		    msg = msg + 'Each room only allows a maximum occupancy of 3 persons. \n';
        }		    
        else if ( lang == 'sp' ) {
		    msg = msg + 'Todas las habitaciones sólo permite una ocupación máxima de 3 personas. \n';
        }		          
    }

    if ( checkin == "" ) {
	    if ( lang == 'pt' ) {
		    msg = msg + 'A data de Check-in tem de estar preenchida.' + '\n' 
        }		    
        else if ( lang == 'en' ) {
		    msg = msg + 'The Check-in date slhould be filled.' + '\n' 
        }		    
        else if ( lang == 'sp' ) {
		    msg = msg + 'La fecha de Check-in tien que ser digitada.' + '\n' 
        }		    
	}  

	if ( checkout == "" ) {
	    if ( lang == 'pt' ) {
		    msg = msg + 'A data de Check-out tem de estar preenchida.' + '\n' 
        }		    
        else if ( lang == 'en' ) {
		    msg = msg + 'The Check-out date slhould be filled.' + '\n' 
        }		    
        else if ( lang == 'sp' ) {
		    msg = msg + 'la fecha de Check-out tien que ser digitada.' + '\n' 
        }		    
	} 

    if ( checkin != ""  && checkout != "" ) {	    
        if (!setReservationDates(checkin)) {
	        if ( lang == 'pt' ) {
		        msg = msg + 'A data de Check-in é inferior da data hoje.' + '\n'
            }		    
            else if ( lang == 'en' ) {
		        msg = msg + 'The Check-in date is earlier than today.' + '\n'
            }		    
            else if ( lang == 'sp' ) {
		        msg = msg + 'La fecha de Check-in es mas baja que a fecha de hoy.' + '\n'
            }		    
        }
            // }
        // }
        //depois tens de compara a checkin e a checkout
        if (!setReservationDates(checkout)) {
	        if ( lang == 'pt' ) {
		        msg = msg + 'A data de Check-out é inferior da data hoje.' + '\n'
            }		    
            else if ( lang == 'en' ) {
		        msg = msg + 'The Check-out date is earlier than today.' + '\n'
            }		    
            else if ( lang == 'sp' ) {
		        msg = msg + 'La fecha de Check-out es mas baja que a fecha de hoy.' + '\n'
            }		    
        }
        else if ( !CompareCheckInCheckOut(checkin,checkout) ) {
            if ( lang == 'pt' ) {
                msg = msg + 'A data de Check-out tem de ser maior que a data de Check-in.' + '\n'
            }		    
            else if ( lang == 'en' ) {
                msg = msg + 'The Check-out date should be higher than the Check-in date.' + '\n'
            }		    
            else if ( lang == 'sp' ) {
                msg = msg + 'La fecha de Check-out tien que ser major que la fecha de Check-in.' + '\n'
            }		    
        }
        else if ( checkin == checkout ) {
            if ( lang == 'pt' ) {
                msg = msg + 'A data de Check-out tem de ser superior à data de Check-in.' + '\n'
            }		    
            else if ( lang == 'en' ) {
                msg = msg + 'The Check-out date must be higher than the Check-in date.' + '\n'
            }		    
            else if ( lang == 'sp' ) {
                msg = msg + 'La fecha de Check-out tien que ser major que la fecha de Check-in.' + '\n'
            }		    
        }
    }
	
    if (msg != '')	{
	    if ( lang == 'pt' ) {
		    alert('Por favor verificar:\n\n' + msg);
        }		    
        else if ( lang == 'en' ) {
		    alert('Please check:\n\n' + msg);
        }		    
        else if ( lang == 'sp' ) {
		    alert('Por favor verifique:\n\n' + msg);		
        }		    
	    return;
	}
    else {    
        openMenuAndDisplayContent(channelid, contentid);

        //window.location.href= strSecureHost + "ReservesForm.aspx?channelid=" + channelid + "&contentid=" + contentid + "&rooms=" + rooms + "&grownups=" + grownups + "&children=" + children + "&checkin=" + checkin + "&checkout=" + checkout + "&lang=" + lang;
    }
}

function openAvailabilityWithContact(channelid,contentid)
{ 
    openMenuAndDisplayContent(channelid, contentid);

    lang = document.getElementById("hidLang").value;
    //window.location.href= strSecureHost + "ReservesForm.aspx?channelid=" + channelid + "&contentid=" + contentid + "&lang=" + lang;
}

//END RESERVAS *******************************************************************

function openPics(channelid,contentid,parentid)
{
    document.location.href= "#pagePhoto";
    document.getElementById("pagePhoto").style.display = 'block';    
    
    var txtTitle = window.document.title;
    var txtUrl = window.location.href;
    
    if (txtTitle.indexOf("#pagePhoto") > 0)
       window.document.title = 'Hotel Casa da Ínsua';
    
}

function openMovie(channelid,contentid,parentid)
{
    openMenuAndDisplayContent(channelid,contentid + "&parentid="+parentid)
}

function openView360(channelid,contentid,parentid)
{
    openMenuAndDisplayContent(channelid,contentid + "&parentid="+parentid)
}

//Function that calls and display the html of the banners at the bottom of the page
function displayBanners(channelid)
{

    var strBanners = "";
    try{
        xmlhttp3 = new XMLHttpRequest();
    }catch(ee){
        try{
            xmlhttp3 = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                xmlhttp3 = false;
            }
        }
    }
    
    if ((channelid.toString() != "0") && (channelid.toString() != "8") )
    {
        document.getElementById("banners").style.visibility = 'hidden';
        document.getElementById("banners").style.display = 'none';    
        xmlhttp3.open("GET", strNormalHost + "Banners.aspx?channelid=" + channelid + "&v=0");
    }
    else {
        document.getElementById("banners").style.visibility = 'visible';
        document.getElementById("banners").style.display = 'block';    
    
        xmlhttp3.open("GET", "Banners.aspx?channelid=0&v=1");    
    }

    xmlhttp3.onreadystatechange=function() {
        if (xmlhttp3.readyState==4){ 
            //building the menu
           strBanners = xmlhttp3.responseText.toString();

           var banners = document.getElementById("banners");
           banners.innerHTML = strBanners;
        }
    }
    xmlhttp3.send(null)        
}

function resetTitle()
{
    var txtTitle = window.document.title;
    var txtUrl = window.location.href;
    
    if ( txtUrl.indexOf("#MP") > 0 || txtUrl.indexOf("#MR") > 0 || txtUrl.indexOf("#pagePhoto") > 0 || txtUrl.indexOf("#faqTop") > 0 || txtUrl.indexOf("#P1") > 0 || txtUrl.indexOf("#P2") > 0 || txtUrl.indexOf("#P3") > 0 || txtUrl.indexOf("#P4") > 0 || txtUrl.indexOf("#P5") > 0 || txtUrl.indexOf("#P6") > 0 ) {
        window.document.title = 'Hotel Casa da Ínsua';
    }
}


/* *******************************************
START - PUBLICIDADE
*********************************************
*/

function OpenDivPublicidade() 
{
    document.getElementById("dvPublicidade").style.visibility = 'visible';
    document.getElementById("dvPublicidade").style.display = 'block';     
}

function CloseDivPublicidade() 
{
    document.getElementById("dvPublicidade").style.visibility = 'hidden';
    document.getElementById("dvPublicidade").style.display = 'none';    
}


function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

var fixEmbeddedVideo = function(embedCode) {
   if(embedCode && embedCode.toLowerCase().indexOf('classid') == -1) {
      var objPos = embedCode.toLowerCase().indexOf('object') + 'object'.length;
      return embedCode.substr(0, objPos) + 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″' + embedCode.substr(objPos);
   } else {
      return embedCode;
   }
}