var $jQ = jQuery.noConflict();

$jQ(document).ready(function(){
						   
	// Set up selects
//	setTimeout("setLinkSelect()",10000);
	
	
	$jQ("#nav-"+main_nav).addClass("on");
	$jQ("#sub-nav-"+sub_nav).addClass("on");

		
});

function setLinkSelect(){
	//console.log("done");
//	$jQ("form#stay_details select").linkselect(); // convert selects to CSS
//	$jQ("#testselect").linkselect(); // convert selects to CSS
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



function showhide(layer_ref){
  
	var mydiv = document.getElementById(layer_ref);
	
	if(mydiv){

	/*document.getElementById('city').className = "";
	document.getElementById('bay').className = "";
	document.getElementById('pontcanna').className = "";
	
	
	document.getElementById('city').className = "hide";
	document.getElementById('bay').className = "hide";
	document.getElementById('pontcanna').className = "hide";*/
	
	//mydiv.className = "show";
	
	//alert("nothing");
	
	
	if (mydiv.className == "hide") {
		
		document.getElementById('city').className = "hide";
		document.getElementById('bay').className = "hide";
		document.getElementById('pontcanna').className = "hide";
		
		mydiv.className = "show";
	//	alert("showing");
		
	}
	
	else if (mydiv.className == "show") {
		
		document.getElementById('city').className = "hide";
		document.getElementById('bay').className = "hide";
		document.getElementById('pontcanna').className = "hide";
		
		mydiv.className = "hide";
	//	alert("hiding");
	}
	
	//document.getElementById(layer_ref+'-li').className = "on";


	}

	
}

function hide(){
		document.getElementById('voucher').className = "hidden";
}

function checkVal(){
		document.getElementById('area').value = "";

}

//------ SET DATES ON PAGE TO TODAY
function todaysDate(){
	return new Date();	
}

function bookYourStay(){
	var today = todaysDate();
	document.book_your_stay.day.value = today.getDate();
	document.book_your_stay.month.value = today.getMonth() + 1;
	document.book_your_stay.year.value = today.getFullYear();
}

//------ VALIDATE FORM

function bookingDate(form){
	//get selected values
	var selDay    = form.day.value;	
	var selMonth  = form.month.value;
	var selYear   = form.year.value;
	
	//convert to date format
	//alert(selYear);
	var selDate = new Date();
	selDate.setFullYear(selYear, selMonth-1, selDay);
	
	var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
	
	//compare date to today
	//alert(selDate + "  " +  todaysDate());
	if(selDate < todaysDate()){
		//if before today then error
		alert("Please select an arrival date from today onwards.\n\nToday's date is " + todaysDate().getDate() + " " + (months[todaysDate().getMonth()]) + " " + todaysDate().getFullYear());
		return false;
	} else {
		//otherwise proceed
		return true;
	}
	
}

/*------------------------------------------------------------------------------
  cookie functions
------------------------------------------------------------------------------*/

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0)
                                break;
                }
   return null;
}

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}