// functions for course tracking

function createVersionCookie(name,value) {
    // set the version of the CD, store it as a cookie
    name = 'cdVersion';
    value = '1.00'; // modified for each new release
    days = 90
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function checkVersionCookie() {
    name = 'cdVersion';
    value = '1.00'; // modified for each new release

	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 the CD version cookie exists and is the correct version, return true.
		if (c.indexOf(nameEQ) == 0) return (c.substring(nameEQ.length,c.length)==value);
	}
	return 0;
}

function clearCookie(name)
{
	var date = new Date();
	date.setTime(date.getTime()-(24*60*60*1000)); // current date/time minus one day
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
}

function setCookie(name, value){
	var exp = new Date();
	var expire = exp.getTime() + (90 * 24 * 60 * 60 * 1000); // expire in 3 months
	exp.setTime(expire);
	document.cookie = "curMod=" + name + "; expires=" + exp.toGMTString();
	document.cookie = name + "=" + value + "; expires=" + exp.toGMTString();
}

function startAssessment(){
	MM_openBrWindow("http://www.beermaster.com.auassessment/login.asp","Login","scrollbars=NO,location=NO,status=YES,toolbar=NO,width=775,height=525");
}

function getCookie(name){
	// get the cookieString
	var cookieString = document.cookie;

	// replace white space with Nothing
	cookieString = replaceChars(cookieString);	
	
	if(cookieString != ""){
		// we found some query string
		var parameters = cookieString.split(";");
		
		var values = new Array();

		// split the queryString 
		for(i=0;i<parameters.length;i++){
			valuePair = parameters[i].split("=");
			values[valuePair[0]] = valuePair[1];

		}
	
		if(values[name]){
			return values[name];
		}else{
			return "";

		}

	}else{
		// no query string
		return "";

	}
}

function openWindow(url){
	window.open(url,"","width=775,height=525,scrollbars=yes,location=no,status=no");
}

function replaceChars(entry) {
	out = " "; // replace this
	add = ""; // with this
	temp = "" + entry; // temporary holder

	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

// return to menu
function gotoMenu(){
	// reset menu cookie
	resetMenu(1);
	
	location.href = "menu.htm";
}

function resetMenu(value){
	// reset menu cookie
	var exp = new Date();
	var expire = exp.getTime() + (90 * 24 * 60 * 60 * 1000);
	exp.setTime(expire);
	document.cookie = "menu=" + value + "; expires=" + exp.toGMTString();
}

function openHelp(){
	var win = window.open("help.htm","Help","width=646,height=385,scrollbars=no,location=no,status=no");
	win.focus();
}

function openAssess(){
	var win5 = window.open("http://www.beermaster.com.au/assessment/login.asp","Login","width=775,height=525,scrollbars=no,location=no,status=no");
	win5.focus();
}

function openGlossary(){
	var win1 = window.open("glossary.htm","Glossary","width=375,height=254,scrollbars=no,location=no,status=no");
	win1.focus();
}

function openMinReq(){
	var win2 = window.open("min_req.htm","MinReq","width=646,height=385,scrollbars=no,location=no,status=no");
	win2.focus();
}

function openLicense(){
	var win3 = window.open("license.htm","License","width=646,height=385,scrollbars=no,location=no,status=no");
	win3.focus();
}

function openPolicy(){
	var win4 = window.open("policy.htm","Policy","width=646,height=385,scrollbars=no,location=no,status=no");
	win4.focus();
}