﻿// for Mozilla browsers

if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}

/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
	if (this.readyState == "complete") {
		init(); // call the onload handler
	}
};
/*@end @*/

if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      clearInterval(_timer);
      init(); // call the onload handler
    }
  }, 10);
}

window.onload = init;


function init() {
  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  // do stuff
  scroll();
};


var search = false;

function pageLoad(sender, args){  
    if(!args.get_isPartialLoad()){  
        //  register for our events
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);    
    }
}

function setSearch()
{    
    search = true;
}

function removeSearch()
{    
    search = false;
    enableScreen();
}

function beginRequest(sender, args)
{
    if( search )
    {
        disableScreen();
    }
}

function pageLoadingHandler(sender, args) 
{
}

function endRequest(sender, args) 
{
    if( search )
    {
        enableScreen();
    }    
}          

function disableScreen()
{   
    var a = $get('ctl00_pnlAll');
    
    a.style.display = 'none';
    
    var b = $get('searchwait');
    
    b.style.display = '';
}

function enableScreen()
{
    var a = $get('ctl00_pnlAll');
    
    a.style.display = '';
    
    var b = $get('searchwait');
    
    b.style.display = 'none';
}

var scrollID = null;
///////////////////////////////////////////////////////////////////////////////////
function a1_on() {
    document.getElementById('a1_text').style.fontWeight= 'bold';
    /*document.getElementById('menu').style.borderCollapse = "collapse";*/
    document.getElementById('a1').style.borderBottom="solid 1px black";
    document.getElementById('a1').style.borderRight="solid 1px black";
    document.getElementById('a2').style.borderRight="solid 1px black";
    document.getElementById('a3').style.borderRight="solid 1px black";
    };
    
function a1_off() {
    document.getElementById('a1_text').style.fontWeight='normal';
    document.getElementById('a1').style.borderBottom="solid 0px black";
    document.getElementById('a1').style.borderRight="solid 0px black";
    document.getElementById('a2').style.borderRight="solid 0px black";
    document.getElementById('a3').style.borderRight="solid 0px black";
    };  
function b1_on() {
    a1_off();
    document.getElementById('b1_text').style.fontWeight= 'bold';
    /*document.getElementById('menu').style.borderCollapse = "collapse";*/
    document.getElementById('b1').style.borderBottom="solid 1px black";
    document.getElementById('b1').style.borderLeft="solid 1px black";
    document.getElementById('b2').style.borderLeft="solid 1px black";
    /*document.getElementById('b3').style.borderLeft="solid 1px black";*/
    }
    
function b1_off() {
    document.getElementById('b1_text').style.fontWeight='normal';
    document.getElementById('b1').style.borderBottom="solid 0px black";
    document.getElementById('b1').style.borderLeft="solid 0px black";
    document.getElementById('b2').style.borderLeft="solid 0px black";
    /*document.getElementById('b3').style.borderLeft="solid 0px black";*/
    };  
function a2_on() {
    a1_off();
    document.getElementById('a2_text').style.fontWeight= 'bold';
    /*document.getElementById('menu').style.borderCollapse = "collapse";*/
    document.getElementById('a2').style.borderBottom="solid 1px black";
    document.getElementById('a2').style.borderRight="solid 1px black";
    document.getElementById('a1').style.borderRight="solid 1px black";
    document.getElementById('a3').style.borderRight="solid 1px black";
    };
    
function a2_off() {
    document.getElementById('a2_text').style.fontWeight='normal';
    document.getElementById('a2').style.borderBottom="solid 0px black";
    document.getElementById('a2').style.borderRight="solid 0px black";
    document.getElementById('a1').style.borderRight="solid 0px black";
    document.getElementById('a3').style.borderRight="solid 0px black";
    };  
function b2_on() {
    a1_off();
    document.getElementById('b2_text').style.fontWeight= 'bold';
    /*document.getElementById('menu').style.borderCollapse = "collapse";*/
    document.getElementById('b2').style.borderBottom="solid 1px black";
    document.getElementById('b2').style.borderLeft="solid 1px black";
    document.getElementById('b1').style.borderLeft="solid 1px black";
    /*document.getElementById('b3').style.borderRight="solid 1px black";*/
    };
    
function b2_off() {
    document.getElementById('b2_text').style.fontWeight='normal';
    document.getElementById('b2').style.borderBottom="solid 0px black";
    document.getElementById('b2').style.borderLeft="solid 0px black";
    document.getElementById('b1').style.borderLeft="solid 0px black";
    /*document.getElementById('b3').style.borderRight="solid 0px black";*/
    };  
 function a3_on() {
    a1_off();
    document.getElementById('a3_text').style.fontWeight= 'bold';
    /*document.getElementById('menu').style.borderCollapse = "collapse";*/
    document.getElementById('a3').style.borderBottom="solid 1px black";
    document.getElementById('a3').style.borderRight="solid 1px black";
    document.getElementById('a1').style.borderRight="solid 1px black";
    document.getElementById('a2').style.borderRight="solid 1px black";
    };
    
function a3_off() {
    document.getElementById('a3_text').style.fontWeight='normal';
    document.getElementById('a3').style.borderBottom="solid 0px black";
    document.getElementById('a3').style.borderRight="solid 0px black";
    document.getElementById('a1').style.borderRight="solid 0px black";
    document.getElementById('a2').style.borderRight="solid 0px black";
    };  
    
    
////////////////////////////////////////////////////////////////////////////////
var xmlHttp;
function CreateXmlHttp(){
// verificamos que tipo de navegador se está utilizando
if (window.XMLHttpRequest) {
// en el caso de que sea Mozilla u otro distino a IE
xmlHttp = new XMLHttpRequest()
} else {
/*
antes de crear el objeto en IE, en el caso de que
no se cumpla la primera opción, se debe verificar
que los controles activex existen, en caso contrario
no podremos crear el objeto que lleva a transacción
*/
if (!window.ActiveXObject){
return false;
}else{
/*
para las ultimas versiones de IE se crea un
objeto ActiveXObject("Msxml2.XMLHTTP")
*/
try { xmlHttp =
new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e){
/*
si es una versión anterior de IE se crea un
objeto ActiveXObject("Microsoft.XMLHTTP")
*/
try{ xmlHttp =
new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e){}
}
}
}
return xmlHttp;
}

function photo_position(position) {
    var arrValues = window.name.split('|');
    window.name = position + '|' + arrValues[1];
    };
    
function virtual_position(position) {
    var arrValues = window.name.split('|');
    window.name = arrValues[0] + '|' + position;
    };

function photo_position_new(position) {
    var url = "FacilitiesPhotos.aspx?posPhoto= " + position;
    xmlHttp=CreateXmlHttp();
    xmlHttp.open("POST", url, true);
    xmlHttp.send("");
    };
        
function virtual_position_new(position) {
    var url = "FacilitiesPhotos.aspx?posVirtual= " + position;
    xmlHttp=CreateXmlHttp();
    xmlHttp.open("POST", url, true);
    xmlHttp.send("");
 };

    

/*function scroll_to_photo_and_to_virtual(posPhoto, posVirtual) {*/
function scroll_to_photo_and_to_virtual() {
/*a1_on();
if (window.name != 1) {
    window.name = 1;
    alert('ajax');*/
    /*location.reload(true);*/
    /*alert('onload');*/
    var url = "FacilitiesPhotos.aspx?req=0";
    xmlHttp=CreateXmlHttp();
    xmlHttp.onreadystatechange = function(){recogepos(xmlHttp);}
    /*req.open("POST", url, true);*/
     xmlHttp.open("POST", url, true);
    xmlHttp.send("");
   
 /*   }
else {
 alert('pintar result:'+posPhoto+' '+posVirtual);
    scroll_to_photo_new(posPhoto);
    scroll_to_virtual_new(posVirtual);
    window.name = 0;
    }*/
};
 
function recogepos(xmlHttp) {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { 
    var arrValues = xmlHttp.responseText.split('|');
    scroll_to_photo_new(arrValues[0]);
    scroll_to_virtual_new(arrValues[1]);
    }
};
function Reception(){
  document.getElementById('ctl00_ContentPlaceHolder1_BodyTextIni').innerHTML  = '';
   var url = "FacilitiesPhotos.aspx?text=Reception";
   xmlHttp=CreateXmlHttp();
   xmlHttp.onreadystatechange = function(){recogetext(xmlHttp);}
   xmlHttp.open("POST", url, true);
   xmlHttp.send("");
}
function SwimmingPool(){
document.getElementById('ctl00_ContentPlaceHolder1_BodyTextIni').innerHTML  = '';
   var url = "FacilitiesPhotos.aspx?text=SwimmingPool";
   xmlHttp=CreateXmlHttp();
   xmlHttp.onreadystatechange = function(){recogetext(xmlHttp);}
   xmlHttp.open("POST", url, true);
   xmlHttp.send("");
}
function Restaurant(){
document.getElementById('ctl00_ContentPlaceHolder1_BodyTextIni').innerHTML  = '';
   var url = "FacilitiesPhotos.aspx?text=Restaurant";
   xmlHttp=CreateXmlHttp();
   xmlHttp.onreadystatechange = function(){recogetext(xmlHttp);}
   xmlHttp.open("POST", url, true);
   xmlHttp.send("");
}
function Sports(){
document.getElementById('ctl00_ContentPlaceHolder1_BodyTextIni').innerHTML  = '';
   var url = "FacilitiesPhotos.aspx?text=Sports";
   xmlHttp=CreateXmlHttp();
   xmlHttp.onreadystatechange = function(){recogetext(xmlHttp);}
   xmlHttp.open("POST", url, true);
   xmlHttp.send("");
}
function Others(){
document.getElementById('ctl00_ContentPlaceHolder1_BodyTextIni').innerHTML  = '';
   var url = "FacilitiesPhotos.aspx?text=Others";
   xmlHttp=CreateXmlHttp();
   xmlHttp.onreadystatechange = function(){recogetext(xmlHttp);}
   xmlHttp.open("POST", url, true);
   xmlHttp.send("");
}

function recogetext(xmlHttp) {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { 
     document.getElementById('BodyText').innerHTML = xmlHttp.responseText;
    }
};
    
function scroll_to_photo() {
    var arrValues = window.name.split('|');
    var test = $get('scrollbar_container');

    if (test != null) {
            clearInterval(scrollID);
            var scrollElementID = 'scrollbar_container';
            var scrollElement = $get(scrollElementID);
            var newPosition = 0;
            var moveOffset = arrValues[0] * 575;
            newPosition = scrollElement.scrollLeft + moveOffset;
            if (newPosition > scrollElement.scrollWidth) newPosition = scrollElement.scrollWidth;
                scrollElement.scrollLeft = newPosition;
            }
     };
     
function scroll_to_virtual() {
    var arrValues = window.name.split('|');
    var test = $get('scrollbar_container2');
   
    if (test != null) {
            clearInterval(scrollID);
            var scrollElementID = 'scrollbar_container2';
            var scrollElement = $get(scrollElementID);
            var newPosition = 0;
            var moveOffset = arrValues[1] * 575;
            newPosition = scrollElement.scrollLeft + moveOffset;
            if (newPosition > scrollElement.scrollWidth) newPosition = scrollElement.scrollWidth;
                scrollElement.scrollLeft = newPosition;
            }
     };
     
function scroll_to_photo_new(position) {
    var test = $get('scrollbar_container');

    if (test != null) {
            clearInterval(scrollID);
            var scrollElementID = 'scrollbar_container';
            var scrollElement = $get(scrollElementID);
            var newPosition = 0;
            var moveOffset = position * 310;
            newPosition = scrollElement.scrollLeft + moveOffset;
            
            if (newPosition > scrollElement.scrollWidth) newPosition = scrollElement.scrollWidth;
                scrollElement.scrollLeft = newPosition;
            }
     };
     
function scroll_to_virtual_new(position) {
    var test = $get('scrollbar_container2');
   
    if (test != null) {
            clearInterval(scrollID);
            var scrollElementID = 'scrollbar_container2';
            var scrollElement = $get(scrollElementID);
            var newPosition = 0;
            var moveOffset = position * 290;
            newPosition = scrollElement.scrollLeft + moveOffset;
            
            if (newPosition > scrollElement.scrollWidth) newPosition = scrollElement.scrollWidth;
                scrollElement.scrollLeft = newPosition;
            }
     };

function scroll() {

    var test = $get('scrollbar_container');

    if (test != null) {
        $addHandler($get('ctl00_ContentPlaceHolder1_scroll_left'), 'click',
            function scrollLeft() {
            
                clearInterval(scrollID);
                var scrollElementID = 'scrollbar_container';

                var scrollElement = $get(scrollElementID);
                var n = scrollElement.scrollLeft;

                var newPosition = n - 310; /* 580 en photos */
                
                if (newPosition < 0) newPosition = 0;
               

                //scrollElement.scrollLeft = newPosition;
                scrollID = setInterval("NiceScroll('" + scrollElementID + "', '" + newPosition + "', 'left')", 10);
            }
        );


            $addHandler($get('ctl00_ContentPlaceHolder1_scroll_right'), 'click',
            function scrollRight() {
            
            clearInterval(scrollID);
            var scrollElementID = 'scrollbar_container';

            var scrollElement = $get(scrollElementID);

                var n = scrollElement.scrollLeft;

                var newPosition = n + 310; /* 580 en photos */
                if (newPosition > scrollElement.scrollWidth) newPosition = scrollElement.scrollWidth;
 
 
                //scrollElement.scrollLeft = newPosition;
                scrollID = setInterval("NiceScroll('" + scrollElementID + "', '" + newPosition + "', 'right')", 10);

            }
        );
        }
        
        var test2 = $get('scrollbar_container2');
        if (test2 != null) {

            $addHandler($get('ctl00_ContentPlaceHolder1_scroll_left2'), 'click',
            function scrollLeft() {
                clearInterval(scrollID);
                var scrollElementID = 'scrollbar_container2';

                var scrollElement = $get(scrollElementID);
                var n = scrollElement.scrollLeft;

                var newPosition = n - 290; /* 580 en photos */
                if (newPosition < 0) newPosition = 0;

                //scrollElement.scrollLeft = newPosition;
                scrollID = setInterval("NiceScroll('" + scrollElementID + "', '" + newPosition + "', 'left')", 10);
            }
        );

            $addHandler($get('ctl00_ContentPlaceHolder1_scroll_right2'), 'click',
            function scrollRight() {
                clearInterval(scrollID);
                var scrollElementID = 'scrollbar_container2';

                var scrollElement = $get(scrollElementID);

                var n = scrollElement.scrollLeft;

                var newPosition = n + 290; /* 580 en photos */
                if (newPosition > scrollElement.scrollWidth) newPosition = scrollElement.scrollWidth;

                //scrollElement.scrollLeft = newPosition;
                scrollID = setInterval("NiceScroll('" + scrollElementID + "', '" + newPosition + "', 'right')", 10);

            }
        );
    }
}

function NiceScroll(containerID, finishPoint, side) {
    var scrollElement = $get(containerID);

    var newPosition = 0;

    var moveOffset = 1; /* en photos 5*/

    if (side == 'right') {
        newPosition = scrollElement.scrollLeft + moveOffset;
        if (newPosition > scrollElement.scrollWidth) newPosition = scrollElement.scrollWidth;
    }
    else {
        newPosition = scrollElement.scrollLeft - moveOffset;
        if (newPosition < 0) newPosition = 0;
    }    

    if (newPosition != finishPoint) {
        scrollElement.scrollLeft = newPosition;
    }
    else {
        clearInterval(scrollID);
    }
}

/*                         Fin Scroll Images                               */


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function printTable() {
    var obj = document.getElementById("vueltaTPV1_tblConf").outerHTML;
    var content = "<html><head><title>Ferrera Beach</title>";
    content += "<LINK href='styles/main.css' type=text/css rel=stylesheet></head><body topmargin='0' leftmargin='0' rightmargin='0' bottommargin='0' style='background-color:#ffffff'><div class='resprint'><br><center><table width='660' border=0 cellpadding=0 cellspacing=4><tr><td align='left' valign='top'><img src='images/logo_820s3.jpg' border='0' /></td></tr><tr><td align='left'>";
    content += obj;
    content += "</center></body></html>";
    _W = window.open("", '_blank', 'top=0,width=930,height=570,scrollbars=yes,resizable=1,toolbar=yes,status=0,menubar=yes');
    _W.document.write(content);
    _W.history.go(0); //Refrescar
}

function cargarImg(src) {
    document.getElementById("divImg").innerHTML = "<img class='imagen' src='~/App_Themes/FerreraBeach/gallery/" + src + "'>"
}

function toggleRooms() {
    var drpRooms = document.getElementById('iRooms');
    if (drpRooms != null) {
        var iRoomCount = drpRooms.options[drpRooms.selectedIndex].value;
        var innerHtml = '<table id="headers"><tr><td style="WIDTH:20px">&nbsp;</td><td style="WIDTH:41px; FONT-WEIGHT: bold" align="center">Adult</td><td style="WIDTH:41px; FONT-WEIGHT: bold" align="center">Child</td></tr></table>';
        for (i = 1; i <= iRoomCount; i++) {
            innerHtml = innerHtml + '<table id="room' + i + '" ><tr><td style="FONT-WEIGHT: bold">R' + i + '</td><td><select id="iAdults' + i + '" name="iAdults' + i + '" style="WIDTH:40px"><option value="0" selected>0</option><option value="1">1</option><option value="2" selected>2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option></select></td><td><select name="iChildren' + i + '" id="iChildren' + i + '" style="WIDTH:40px" onchange="toggleChildren(\'iChildren' + i + '\',' + i + ');"><option value="0" selected>0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option></select></td><td>';
            innerHtml = innerHtml + '<div id="pnlAges' + i + '"></div></td></tr></table>';
        }
        document.getElementById('pnlRooms').innerHTML = innerHtml;
    }
}

function toggleChildren(elString, iRoom) {
    var iChildren = document.getElementById(elString);
    var iCount = iChildren.options[iChildren.selectedIndex].value;
    var innerHtml = '<table><tr>';
    for (j = 1; j <= iCount; j++) {
        innerHtml = innerHtml + '<td><select name="iChildren' + iRoom + '_age' + j + '" id="iChildren' + iRoom + '_age' + j + '"><option value="0" selected>0-12m.</option><option value="1">&lt; 24m.</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option></select></td>';
    }
    if (iCount > 0) {
        innerHtml = innerHtml + '<td>Cot (3&euro; per day) <input type="checkbox" id="iCot' + iRoom + '" name="iCot' + iRoom + '"></td>';
    }
    innerHtml = innerHtml + '</tr></table>';
    document.getElementById('pnlAges' + iRoom).innerHTML = innerHtml;
}

function ShowHideDiv(vcodigo) {
    if (document.getElementById && self.document) {
        if (self.document.getElementById(vcodigo).style.display == 'none') {
            self.document.getElementById(vcodigo).style.display = 'block';
        }
        else {
            self.document.getElementById(vcodigo).style.display = 'none';
        }
    }
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////