// Corinthia JavaScript Document

$(function () {
    var dtMinDate = new Date();
    var checkout, checkin;
    

    /*FOR THE SEARCH POD*/
    checkin = $(".datepickerhidden[name$='checkin']").datepicker({
        showOn: "button",
        buttonImageOnly: true,
        buttonImage: "imgs/checkin-btn_transparent.gif",
        dateFormat: "dd/mm/yy",
        minDate: dtMinDate,
        onSelect: function (dateText, inst) {
            $(this).parent().children("img.bottomSearchBK").attr("src", "imgs/" + $(this).attr("name") + "-btn-blank.png");
            $(this).parent().children("span").text(dateText);
            $(this).parent().children("input.bookingwidgetInfo").val($(this).val());
            checkout.datepicker("option", "minDate", new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay));
        }
    });
    checkout = $(".datepickerhidden[name$='checkout']").datepicker({
        showOn: "button",
        buttonImageOnly: true,
        buttonImage: "imgs/checkout-btn_transparent.gif",
        dateFormat: "dd/mm/yy",
        minDate: dtMinDate,
        onSelect: function (dateText, inst) {
            $(this).parent().children("img.bottomSearchBK").attr("src", "imgs/" + $(this).attr("name") + "-btn-blank.png");
            $(this).parent().children("span").text(dateText);
            $(this).parent().children("input.bookingwidgetInfo").val($(this).val());
        }
    });
    //    $(".datepickerhidden").change(function () {
    //        if ($(this).val() != "") {
    //            $(this).parent().children("img.bottomSearchBK").attr("src", "imgs/" + $(this).attr("name") + "-btn-blank.png");
    //            $(this).parent().children("span").text($(this).val());
    //            $(this).parent().children("input.bookingwidgetInfo").val($(this).val());
    //        }
    //    });
    $(".bottomDropUp li").click(function () {
        $(this).parent().parent().children("input.bookingwidgetInfo").val($(this).text());
        $(this).parent().parent().children("input.datepickerhidden").val($(this).text());

    });


    if ($("#contentBox .checkinForm").length > 0) {
        var formcheckin, formcheckout;
        formcheckin = $("#contentBox .checkinForm").datepicker({
            showOn: 'button',
            buttonImage: 'imgs/calendar.png',
            buttonImageOnly: true,
            dateFormat: "dd/mm/yy",
            minDate: dtMinDate,
            onSelect: function (dateText, inst) {
                formcheckout.datepicker("option", "minDate", new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay));
            }
        });
        formcheckout = $("#contentBox .checkoutForm").datepicker({
            showOn: 'button',
            buttonImage: 'imgs/calendar.png',
            buttonImageOnly: true,
            dateFormat: "dd/mm/yy",
            minDate: formcheckin.val() == "" ? dtMinDate : new Date(formcheckin.val().substr(6, 4), (formcheckin.val().substr(3, 2)) - 1, formcheckin.val().substr(0, 2))
        });
    }


});

/*****************************/
/***** Dropdown Lists ********/
/*****************************/
$(document).ready(function(){
	$('#aspnetForm').submit(function() {
		fleXenv.updateScrollBars();
		try{
		    contentArea = document.getElementById("contentBox");
		    contentArea.fleXcroll.setScrollPos(false,0);
        }
        catch(e){
        }
	});
});

$(function() {
	$("#navMenu ul .topSelect").mouseover(function() {
		$(this).children("a").addClass("highlight");
		$(this).children("ul").css("display", "block");
	});
	$("#navMenu ul .topSelect").mouseout(function() {
		$(this).children("a").removeClass("highlight");
		$(this).children("ul").css("display", "none");
	});
});

/*var dropdownids= new Array("dropdownAccomomdation", "dropdownSpa", "dropdownResturants", "dropdownFacilities", "dropdownWeddings"); // Enter ids separated by a comma

function build_dropdown(){
for (var c=0; c<dropdownids.length; c++){
	var ultag=document.getElementById(dropdownids[c]);
	
	// Set background color for dropdown on onmouseover
	ultag.onmouseover=function(){
		//this.getElementsByTagName("a")[0].className = 'highlight';
		this.getElementsByTagName("ul")[0].style.display = "block";
    }
	
	ultag.onmouseout=function(){
		//this.getElementsByTagName("a")[0].className = '';
		this.getElementsByTagName("ul")[0].style.display = "none";
    }
	
	
    ultags[0].parentNode.onclick=function(){
	// Hide open dropdowns
	if (dropdownOpen==true){
		for (var a=0; a<dropdownids.length; a++){
				document.getElementById(dropdownids[a]).style.zIndex="990";
				document.getElementById(dropdownids[a]).getElementsByTagName("ul")[0].style.display="none";		
				dropdownOpen = false;
			}
	}else{
	//Show clicked dropdown
		this.parentNode.style.zIndex="999";
		this.getElementsByTagName("ul")[0].style.display="block";
		dropdownOpen = true;
	}
	}
	
  	// Hide clicked dropdown
	for (var c=1; c<litags.length; c++){
	litags[c].onclick=function(){
		this.parentNode.parentNode.childNodes[0].setAttribute("class", "selectOption");
		this.parentNode.parentNode.childNodes[0].innerHTML = this.innerHTML;
		//this.parentNode.childNodes[1].style.display="none";
	}
	// Set background color for dropdown on onmouseover
	ultags[c].onmouseover=function(){
		this.setAttribute("class", "selected");
    }	
	// Set background color for dropdown on onmouseout
	litags[c].onmouseout=function(){
		this.setAttribute("class", "");
	}
	}
	
  }
}

if (window.addEventListener)
window.addEventListener("load", build_dropdown, false);
else if (window.attachEvent)
window.attachEvent("onload", build_dropdown);*/


/* var dropupids= new Array("dropdownRooms", "dropdownBoardBasis","dropdownAdults","dropdownChildren"); // Enter ids separated by a comma */
var dropupids= new Array("dropdownRooms", "dropdownAdults","dropdownChildren"); // Enter ids separated by a comma
var dropdownOpen = false;

function build_dropup(){
for (var i=0; i<dropupids.length; i++){
	var ultags=document.getElementById(dropupids[i]).getElementsByTagName("ul");
	var litags=document.getElementById(dropupids[i]).getElementsByTagName("li");
	
    ultags[0].parentNode.onclick=function(){
	// Hide open dropdowns
	if (dropdownOpen==true){
		for (var a=0; a<dropupids.length; a++){
				document.getElementById(dropupids[a]).style.zIndex="990";
				document.getElementById(dropupids[a]).getElementsByTagName("ul")[0].style.display="none";		
				dropdownOpen = false;
			}
	}else{
	//Show clicked dropdown
		this.parentNode.style.zIndex="999";
		this.getElementsByTagName("ul")[0].style.display="block";
		dropdownOpen = true;
	}
	}
	
  	// Hide clicked dropdown
	for (var c=1; c<litags.length; c++){
	    litags[c].onclick = function () {
	        var counter = 0;
	        if (this.parentNode.parentNode.childNodes[counter].nodeType == 3) {
	            counter = 1;
	        }
	        this.parentNode.parentNode.childNodes[counter].className = 'selectOption';
	        this.parentNode.parentNode.childNodes[counter].innerHTML = this.innerHTML;
	        //this.parentNode.childNodes[1].style.display="none";
	    }
	// Set background color for dropdown on onmouseover
	litags[c].onmouseover=function(){
		this.className = "selected";
    }	
	// Set background color for dropdown on onmouseout
	litags[c].onmouseout=function(){
		this.className = "";
	}
	}
  }
}

if (window.addEventListener)
window.addEventListener("load", build_dropup, false);
else if (window.attachEvent)
window.attachEvent("onload", build_dropup);


/*****************************/
/******* Swap Images *********/
/*****************************/
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_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_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];}
}

/*****************************/
/****** Show/Hide Div ********/
/*****************************/
function showHideDiv(object){
	if(document.getElementById(object).style.display=="block"){
		document.getElementById(object).style.display="none";
	}else{
		document.getElementById(object).style.display="block";
	}
}


// Corinthia JavaScript Document
/*****************************/
/***** Dropdown Lists ********/
/*****************************/

var dropdownOpen = null;
function ShowDropDown(object){
    if((dropdownOpen!=null)&&(dropdownOpen!=object)){
           document.getElementById(dropdownOpen).style.zIndex="990";
           document.getElementById(dropdownOpen).getElementsByTagName("ul")[0].style.display="none";
        }

    if (document.getElementById(object).getElementsByTagName("ul")[0].style.display=="block"){
        document.getElementById(object).style.zIndex="990";
        document.getElementById(object).getElementsByTagName("ul")[0].style.display="none";      
    }else{
        document.getElementById(object).style.zIndex="998";
        document.getElementById(object).getElementsByTagName("ul")[0].style.display="block";
                
        dropdownOpen = object;
    }
}

function ChangeColour(item, colour){
    item.style.backgroundColor=colour;
}

function RestoreColour(item, colour){
    item.style.backgroundColor=colour;
}

function SetSelectedItem(TextDisplay,TextObject,text,ValueObject,sValue,SubmitForm){
    document.getElementById(ValueObject).value = sValue;
    document.getElementById(TextObject).value = text;
    document.getElementById(TextDisplay).innerHTML = text;
    
    if (SubmitForm == true){
        //document.forms[0].submit();
        __doPostBack(ValueObject, sValue);
    }
}

/*
var checkboxids= new Array("checkboxFixedDates", "checkboxInclFlights"); // Enter ids separated by a comma

function build_checkboxes(){
	for (var c=0; c<checkboxids.length; c++){
		
		document.getElementById(checkboxids[c]).onclick=function(){

			var div_class = this.className;
			if(div_class == "checked") this.className = '';
				else this.className = 'checked';
			
		}
	}
}

if (window.addEventListener)
window.addEventListener("load", build_checkboxes, false);
else if (window.attachEvent)
window.attachEvent("onload", build_checkboxes);
*/

/**SCROLLBAR**/
var contentArea;

function activateScrollbar() {
	contentArea = document.getElementById("contentBox");
	fleXenv.fleXcrollMain(contentArea);
}
window.onload = activateScrollbar;

function updateScrollbar() {
	contentArea.fleXcroll.updateScrollBars();
}

var myInterval;

function startIntervalCheck() {
	var currentNumber = $(".errorBox").length;	
	myInterval = setInterval(function() {
		if ( $(".errorBox").css("display") != null) {
			if ( $(".errorBox li").length != currentNumber ) {
				currentNumber =  $(".errorBox").length;
				updateScrollbar();
			}
		}
	}, 500);
}








