/**
*	Initialize page
*/
Event.observe(document, "dom:loaded", function () {
	// check if age has not been verified in origin.html 
	// if so kick them back to the index.html page
	if (location.href.indexOf("origin.html") != -1) {
		if (getAgeVerified() != "true") location.replace('index.html');
	}
	
	// all underage get the wb portal site
	if (getUnderageStatus() == "true") location.replace('http://www.wb.com');
	


}); 	

/**
*	Retrieve the selected language code from cookie
*	Possible values: en | es | fr | de | it | uk
*/
function getLanguage() {
	var arg = getCookieValue('lang');

	if (arg == undefined || arg == null) {
		return "en";
	} else {
		return arg;
	}	
}

/**
*	Retrieve the age verified boolean from cookie
*/
function getUnderageStatus() {
	var arg = getCookieValue('underage_status');

	if (arg == undefined || arg == null) {
		return "false";
	} else {
		return arg;
	}	
}


/**
*	Retrieve the age verified boolean from cookie
*/
function getAgeVerified() {
	var arg = getCookieValue('age_verified');

	if (arg == undefined || arg == null) {
		return "false";
	} else {
		return arg;
	}	
}


/**
*	Retrieve the skip-intro boolean from cookie
*/
function getSkipIntro() {
	var arg = getCookieValue('skip_intro');

	if (arg == undefined || arg == null) {
		return "false";
	} else {
		return arg;
	}	
}



/**
*	Store the age verification boolean and selected language code to cookie
*/
function setAgeVerifiedAndLanguage(lang) {
//	console.log('set age verified and selected language = ' + lang);

	var arg0 = writePersistentCookie('lang', lang, 'years', 1);
	var arg1 = writePersistentCookie('age_verified', 'true', 'years', 1);
}

/**
*	Store the age verification boolean and selected language code to cookie
*	Then redirect to the WB Portal site
*/
function setUnderageStatusAndLanguage(lang) {
//	console.log('set under age status and selected language = ' + lang);

	var arg0 = writePersistentCookie('lang', lang, 'years', 1);
	var arg1 = writePersistentCookie('underage_status', 'true', 'years', 1);
	
	location.replace('http://www.wb.com');
}



/**
*	Store the selected language to cookie
*/
function setLanguage(lang) {
	var arg = writePersistentCookie('lang', lang, 'years', 1);	
}


/**
*	Store the age verified boolean to cookie
*/
function setAgeVerified() {
	var arg = writePersistentCookie('age_verified', 'true', 'years', 1);	
}


/**
*	Set the skip-intro boolean from cookie
*/
function setSkipIntro() {
	var arg = writePersistentCookie('skip_intro', 'true', 'years', 1);
}

/**
*	Store the user underage boolean to cookie
*/
function setUnderageStatus() {
	var arg = writePersistentCookie('underage_status', 'true', 'years', 1);	
}
