// --------------------------
// Sitecore default functions
// --------------------------
function newImage(ID,file) {
	document.getElementById(ID).src='/images/'+file;
}

function open_window(URL,name,left,top,width,height,menubar){
	 rp=window.open(URL,name,"top="+top+",left="+left+",height="+height+",width="+width+",menubar="+menubar+",scrollbars=1,resizable=1,status=1");
	 rp.focus();
	 return(false);
}

// --------------------------------------------------
// Document Ready
// --------------------------------------------------
j$(document).ready(function() {
	initTextResizing();
	initPrintPage();
});

// --------------------------------------------------
// Text Resizing
// --------------------------------------------------
function initTextResizing() {
	j$("span.text-resize").css("display", "inline");
	
	var textSize = (j$.cookie("TEXT_SIZE") != null) ? j$.cookie("TEXT_SIZE") : "text-m";
	j$("body").addClass(textSize);				// Add class to BODY
	j$("#" + textSize).addClass("selected");	// Find anchor, set selected

	j$("span.text-resize a").click(function() {
		var textSize = j$(this).attr("id");
		j$(this).parent().children().each(function() { j$(this).removeClass("selected"); });
		j$(this).addClass("selected");
		j$("body").removeClass("text-s text-m text-l").addClass(textSize);
		j$.cookie("TEXT_SIZE", textSize, { path: "/", expires: 10000 });

		return false;
	});
}

// --------------------------------------------------
// Print Page
// --------------------------------------------------
function initPrintPage() {
	j$("span.print-page").css("display", "inline");

	j$("span.print-page a").click(function() {
		window.print();
		return false;
	});
}

// -----------------------------------------------------
// Validate Date - Quick Format Check, Min Sanity Checks
// -----------------------------------------------------
function ValidateDate(value) {
	var date = value.split("/");

	if (date.length == 3) {
		var d = parseInt(date[0],10);
		var m = parseInt(date[1],10);
		var y = parseInt(date[2],10);

		if (isNaN(d)) return false;
		if (isNaN(m)) return false;
		if (isNaN(y)) return false;
		
		if ((m < 1) || (m > 12))
			return false;

		if ((d < 1) || (d > 31))
			return false;

		if (y < 1000)
			return false;

		return true;
	}

	return false;
}

j$(document).ready(function() {
	j$("#ie6splash").height(j$(document).height() + 100);
	j$("#ie6splash").width(j$(document).width());
});

j$("Internet Explorer 6 or Below Detected").appendTo(".dialogTitle");
j$("We note that you are using Internet Explorer version 6, which is not compatible with this website.<br /><br />Please upgrade to a more recent version of <a href='http://www.microsoft.com/internet-explorer'>Internet Explorer</a>, which is available for free from <a href='http://www.microsoft.com/internet-explorer'>Microsoft</a>.<br /><br />You will then be able to access this website.").appendTo(".dialogText");

// -----------------------------------------------------
// hover - For Accessibility - on link buttons focussed 
// via an access key, treat as though mousehover is 
// occurring.
// -----------------------------------------------------
function Hover(element) {
    j$(element).toggleClass('focussed');
}