// * scripts.js **04/08/2009**V09/5**

// jump menu
// used in includes/header.jsp
function jumpTo(theItem) {
	theURL = theItem.options[theItem.selectedIndex].value;
	location.href=theURL;
}

// popup window
// used in includes/header.jsp and deprecated includes/diagram.jsp
function popUp(winURL,winName,winWidth,winHeight,winScroll,winResize) {
	// set default scroll and resize behaviour if not defined by referer
	if (winScroll == undefined) {
		winScroll = 'no';
	}
	if (winResize == undefined) {
		winResize = 'yes';
	}
	// set variables to centre popup onscreen
	var winLeft = (screen.width - winWidth) / 2;
	var winUp = (screen.height - winHeight) / 2;
	// add 50px to allow for credits, close window link
	winHeight = (winHeight+50);
	// wrap up window properties in a single variable
	winProp = 'width='+winWidth+',height='+winHeight+',left="'+winLeft+',top='+winUp+',scrollbars='+winScroll+',resizable='+winResize+''
	// open named window; set focus in case it's already open behind another window
	window.open(winURL,winName,winProp).focus();
}

// cookie code from http://www.quirksmode.org/js/cookies.html
// used in includes/payPalProduct.jsp
// set cookie
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// get cookie
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// "rate this page" validation
function ratePage() {
	// default comment field value for comparison below
	var defaultComment = $('#ratepage #comment').attr('value');
	// validation on submission
	$('#ratepage').submit(function() {
		// empty alert message
		var alertMessage = "";
		// rating checkbox value
		var submittedRating = $('#ratepage input[name=rating]:checked').val();
		if (submittedRating == null) { // no rating checkbox selected
			alertMessage += "Please provide a rating\n"; // alert user
		}
		// comment field value
		var submittedComment =  $('input#comment').val();
		if (submittedComment == defaultComment || submittedComment == "") { // comment is empty or default
			alertMessage += "Please provide a comment\n"; // alert user
		}
		if (alertMessage != "") { // if alert message isn't empty, alert and stop form submission
			alert (alertMessage);
			return false;
		}
	});
}
