/*////////////////////////////////////////////////////////////
JavaScript Code Library
Developed by GrafX Design Division Pty Ltd
http://www.grafx.com.au

Last Checked In By : Richard Czeiger
Public Revision No : 1.0

The software and related user documentation are
protected under copyright laws and remain the sole
property of GrafX Design Division. Full license is
available on the GrafX Design Division web site or
in the original download.

Technical support is available via the GrafX web site at
http://www.grafx.com.au
////////////////////////////////////////////////////////////*/



// Get the hacked stylesheet
document.write('<style type="text/css">@import url("styles/hacks.css");</style>');



// Suppress JavaScript Errors
window.onerror=new Function("return true")



// Set the Status Bar Message
var statusMsg = 'St Marks Lodge - Macleay Lodge - Alison Lodge';
window.defaultStatus=statusMsg;



// Fixes IE6 CSS Rendering Bug
if (document.all && window.attachEvent) window.attachEvent("onload", fixWinIE);
function fixWinIE() {
	if (document.body.scrollHeight < document.body.offsetHeight) { document.body.style.display = 'block'; }
}



// Spam Suppression for Emails
function stopSpam(name, domain, subject) {
	var symbol = '@';
	// Took out the Subject due to MS fault in Outlook Express (Source - http://support.microsoft.com/kb/q182985/ )
	// document.write('<a href="mailto:' + name + symbol + domain + '&subject=' + subject + '">' + name + symbol + domain + '</a>');
	document.write('<a href="mailto:' + name + symbol + domain + '">' + name + symbol + domain + '</a>');
}



// XHTML External Link Script
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup") {
			anchor.onclick = function PopupPic() {
				window.open('image.html?'+this.href+'&'+this.title, 'imagePopUp', 'resizable=1,width=20,height=20');
				return false;
			}
		}
	}
}



// Rotate images randomly

// Unique Random Numbers Picker
// -Picks a number of unique random numbers from an array
// (c) 2002 Premshree Pillai
// http://www.qiksearch.com, http://javascript.qik.cjb.net
// E-mail : qiksearch@rediffmail.com

function randomMiniImages() {
	if (!document.getElementsByTagName) return;
	var gallery = document.getElementById('gallery');
	var images = gallery.getElementsByTagName('img');
	nums = images.length;
	pickNums(nums);
}

var numArr = new Array("01","02","03","04","05","06","07","08", "09", "10", "11"); // Add elements here
var pickArr = new Array(); // The array that will be formed
var count=0;
var doFlag=false;
var iterations=0;

function pickNums(nums) {
	var gallery = document.getElementById('gallery');
	var images = gallery.getElementsByTagName('img');
	iterations+=1;
	var currNum = Math.round((numArr.length-1)*Math.random());
	if(count!=0) {
		for(var i=0; i<pickArr.length; i++) {
			if(numArr[currNum]==pickArr[i]) {
				doFlag=true;
				break;
			}
		}
	}
	if(!doFlag) {
		pickArr[count]=numArr[currNum];
		images[count].src = "http://www.springfieldlodge.com.au/images/ksStamp" + numArr[currNum] + ".jpg";
		count+=1;
	}
	// Compare for max iterations you want
	if(iterations<(numArr.length*3)) {
		if((count<nums)) {
			pickNums(nums);
		}
	} else {
		location.reload();
	}
}



// Toggle Function
function toggle(obj) {
	if (obj.style.display == "none") {
		obj.style.display = "";
	} else {
		obj.style.display = "none";
	}
}



// Pop Up Window
function popUp(sPicURL, w, h) {
	window.open(sPicURL, 'popUp', 'resizable=0,width='+w+',height='+h+', scrollbars=no');
}



// Pop Up Image Window
function PopupPic(sPicURL, sPicTitle) {
	window.open('image.html?'+sPicURL, 'imagePopUp', 'resizable=1,width=20,height=20');
}



// Focus on Input Fields
// inputFocus = function () {
function inputFocus() {
	var focusEl = document.getElementsByTagName("INPUT");
	for (var i=0; i<focusEl.length; i++) {
		if ((focusEl[i].getAttribute("type") == "text")||(focusEl[i].getAttribute("type") == "password")) {
			focusEl[i].onfocus=function() {
				this.className+="sffocus";
			}
			focusEl[i].onblur=function() {
				this.className=this.className.replace(new RegExp("sffocus\\b"), "");
			}
		}
	}
	var focusTx = document.getElementsByTagName("TEXTAREA");
	for (var i=0; i<focusTx.length; i++) {
		focusTx[i].onfocus=function() {
			this.className+="sffocus";
		}
		focusTx[i].onblur=function() {
			this.className=this.className.replace(new RegExp("sffocus\\b"), "");
		}
	}
}
// if (window.attachEvent) window.attachEvent("onload", inputFocus);



// Global Cookie Function
function setCookie(NameOfCookie, value, expiredays, path, domain, secure) {
	//The first lines in the function converts the number of days to a valid date.
	var ExpireDate = new Date();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays*24*3600*1000));

	//The next line stores the cookie, simple by assigning
	//the values to the document.cookie-object
	//Note the date is converted to Greenwich Meantime using
	//the 'toGMTstring()'-function

	document.cookie = NameOfCookie +"="+ escape(value) +
	((expiredays == null)? "": ";expires="+ ExpireDate.toGMTString()) +
	((path == null)? "": (";path=" + path)) +
	((domain == null) ? "" : (";domain=" + domein)) +
	((secure == true) ?";secure":"");
}

function getCookie(NameOfCookie) {
	if(document.cookie.length > 0) {
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if(begin != -1) {
			// our cookie was set.
			// The value stored in the cookie is returned from the function
			begin += NameOfCookie.length + 1;
			end = document.cookie.indexOf(";",begin);
			if(end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin,end));
		}
	}
	return null;
	// Our cookie was not set.
	// The value "null" is returned from the function
}

function delCookie(NameOfCookie) {
	// The function simply checks if the cookie is set. If so expiredate is set to Jan. 1st 1970
	if(getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie +"=" +
		";expires= Thu, 01-Jan-70 00:00:01 GMT";
	}
}



// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.
//
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// --- version date: 01/24/03 ---------------------------------------------------------

// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Cross-Browser Functions

var dom = document.getElementById;
var iex = document.all;
var ns4 = document.layers;

function addEvent(event,method){
	this[event] = method;
	if(ns4) this.captureEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function removeEvent(event){
	this[event] = null;
	if(ns4) this.releaseEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function getElement(name,nest){
	nest = nest ? "document."+nest+"." : "";
	var el = dom ? document.getElementById(name) : iex ? document.all[name] : ns4 ? eval(nest+"document."+name) : false;
	el.css = ns4 ? el : el.style;
	el.getTop = function(){return parseInt(el.css.top) || 0};
	el.setTop = function(y){el.css.top = ns4 ? y: y+"px"};
	el.getHeight = function(){return ns4 ? el.document.height : el.offsetHeight};
	el.getClipHeight = function(){return ns4 ? el.clip.height : el.offsetHeight};
	el.hideVis = function(){el.css.visibility="hidden"};
	el.addEvent = addEvent;
	el.removeEvent = removeEvent;
	return el;
}
function getYMouse(e){
	return iex ? event.clientY : e.pageY;
}

document.addEvent = addEvent;
document.removeEvent = removeEvent;

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Scroller Class

ScrollObj = function(speed, dragHeight, trackHeight, trackObj, upObj, downObj, dragObj, contentMaskObj, contentObj){
	this.speed = speed;
	this.dragHeight = dragHeight;
	this.trackHeight = trackHeight;
	this.trackObj = getElement(trackObj);
	this.upObj = getElement(upObj);
	this.downObj = getElement(downObj);
	this.dragObj = getElement(dragObj);
	this.contentMaskObj = getElement(contentMaskObj);
	this.contentObj = getElement(contentObj,contentMaskObj);
	this.obj = contentObj+"Object";
	eval(this.obj+"=this");

	this.trackTop = this.dragObj.getTop();
	this.trackLength = this.trackHeight-this.dragHeight;
	this.trackBottom = this.trackTop+this.trackLength;
	this.contentMaskHeight = this.contentMaskObj.getClipHeight();
	this.contentHeight = this.contentObj.getHeight();
	this.contentLength = this.contentHeight-this.contentMaskHeight;
	this.scrollLength = this.trackLength/this.contentLength;
	this.scrollTimer = null;

	if(this.contentHeight <= this.contentMaskHeight){
		this.dragObj.hideVis();
		this.upObj.hideVis();
		this.downObj.hideVis();
	}else{
		var self = this;
		this.trackObj.addEvent("onmousedown", function(e){self.scrollJump(e);return false});
		this.upObj.addEvent("onmousedown", function(){self.scroll(self.speed);return false});
		this.upObj.addEvent("onmouseup", function(){self.stopScroll()});
		this.upObj.addEvent("onmouseout", function(){self.stopScroll()});
		this.downObj.addEvent("onmousedown", function(){self.scroll(-self.speed);return false});
		this.downObj.addEvent("onmouseup", function(){self.stopScroll()});
		this.downObj.addEvent("onmouseout", function(){self.stopScroll()});
		this.dragObj.addEvent("onmousedown", function(e){self.startDrag(e);return false});
		if(iex) this.dragObj.addEvent("ondragstart", function(){return false});
	}
}
ScrollObj.prototype.startDrag = function(e){
	this.dragStartMouse = getYMouse(e);
	this.dragStartOffset = this.dragObj.getTop();
	var self = this;
	document.addEvent("onmousemove", function(e){self.drag(e)});
	document.addEvent("onmouseup", function(){self.stopDrag()});
}
ScrollObj.prototype.stopDrag = function(){
	document.removeEvent("onmousemove");
	document.removeEvent("onmouseup");
}
ScrollObj.prototype.drag = function(e){
	var currentMouse = getYMouse(e);
	var mouseDifference = currentMouse-this.dragStartMouse;
	var dragDistance = this.dragStartOffset+mouseDifference;
	var dragMovement = (dragDistance<this.trackTop) ? this.trackTop : (dragDistance>this.trackBottom) ? this.trackBottom : dragDistance;
	this.dragObj.setTop(dragMovement);
	var contentMovement = -(dragMovement-this.trackTop)*(1/this.scrollLength);
	this.contentObj.setTop(contentMovement);
}
ScrollObj.prototype.scroll = function(speed){
	var contentMovement = this.contentObj.getTop()+speed;
	var dragMovement = this.trackTop-Math.round(this.contentObj.getTop()*(this.trackLength/this.contentLength));
	if(contentMovement > 0){
		contentMovement = 0;
	}else if(contentMovement < -this.contentLength){
		contentMovement = -this.contentLength;
	}
	if(dragMovement < this.trackTop){
		dragMovement = this.trackTop;
	}else if(dragMovement > this.trackBottom){
		dragMovement = this.trackBottom;
	}
	this.contentObj.setTop(contentMovement);
	this.dragObj.setTop(dragMovement);
	this.scrollTimer = window.setTimeout(this.obj+".scroll("+speed+")",25);
}
ScrollObj.prototype.stopScroll = function(){
	if(this.scrollTimer){
		window.clearTimeout(this.scrollTimer);
		this.scrollTimer = null;
	}
}
ScrollObj.prototype.scrollJump = function(e){
	var currentMouse = getYMouse(e);
	var dragDistance = currentMouse-(this.dragHeight/2);
	var dragMovement = (dragDistance<this.trackTop) ? this.trackTop : (dragDistance>this.trackBottom) ? this.trackBottom : dragDistance;
	this.dragObj.setTop(dragMovement);
	var contentMovement = -(dragMovement-this.trackTop)*(1/this.scrollLength);
	this.contentObj.setTop(contentMovement);
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Misc Functions

function fixNetscape4(){
	if(ns4origWidth != window.innerWidth || ns4origHeight != window.innerHeight){
		window.location.reload();
	}
}
if(document.layers){
	ns4origWidth = window.innerWidth;
	ns4origHeight = window.innerHeight;
	window.onresize = fixNetscape4;
}



// Multiple Onload Functions to be called
function multipleOnload() {
	externalLinks();
	randomMiniImages();
	//inputFocus();
}
window.onload = multipleOnload;

// Booking button code

function bb_set_date(){
	
	var today = new Date();
	var month = today.getMonth() + 1;
	var bb_dateFrom_day = document.getElementById("bb_dateFrom_day");
	var bb_dateFrom_month = document.getElementById("bb_dateFrom_month");
	
	if(today.getDate()<10){
		bb_dateFrom_day.value = '0' + today.getDate();
	}else{
		bb_dateFrom_day.value = today.getDate();
	}

	if(month<10){
		month = '0' + month;
	}
	
	var value = today.getFullYear() + "-" + month;
	bb_dateFrom_month.value = value;
	
}
window.onload = bb_set_date;

function bb_submit()
{
	var bb_dateFrom = document.getElementById('bb_dateFrom_month').value + "-" + document.getElementById('bb_dateFrom_day').value;
	
	document.getElementById('dateFrom').value = bb_dateFrom;
	try
  	{
  		pageTracker._linkByPost(document.getElementById('bb_check_availability'));
  	}
	catch(err)
  	{
  	}
	document.getElementById('bb_check_availability').submit();
}
