
//Check cookie value
function create_cookie(strName, strLanguage, numDays) {
	if(numDays) {
		var datDate = new Date();
		datDate.setTime(datDate.getTime()+(numDays*24*60*60*1000));
		var expires = "; expires="+datDate.toGMTString();
	}			
	document.cookie = strName+"="+strLanguage+expires+"; path=/";
}

function read_cookie(strCookieName) {
	var strCookieNameEQ = strCookieName + "=";
	var arrCookieSplit = document.cookie.split(';');
	for(var i=0;i < arrCookieSplit.length;i++) {
		var strCookieValue = arrCookieSplit[i];
		while (strCookieValue.charAt(0)==' ') strCookieValue = strCookieValue.substring(1,strCookieValue.length);
		if(strCookieValue.indexOf(strCookieNameEQ) == 0) return strCookieValue.substring(strCookieNameEQ.length,strCookieValue.length);
	}
	return null;
}

function erase_cookie(strName) {
	create_cookie(strName,"","",-1);
}	

function cookie_detect(strCookieName) {
	//Check cookie for value, and if null, use default of en
	if(read_cookie(strCookieName)==null) {
		if (flash.ver[8]){
			document.write('<style>.flashBox{display:none;.langBox{display:block;.container-page-templates{display:none;}}</style>');
		}
		else{
			document.write('<style>.flashBox{display:block;.langBox{display:none;.container-page-templates{display:none;}}</style>');
		}
	} else {
		top.location.href='/?lang=' + read_cookie(strCookieName);
	}
}

function getLanguage() {
	var lang="";
	if (navigator.userLanguage!=null) lang=navigator.userLanguage.substr(0,2);
	if (read_cookie('lang')!=null) lang=read_cookie('lang');
	if (location.search.match('lang=')) lang=location.search.split('lang=')[1].split('&')[0];
	create_cookie("lang", lang, 30);
	return lang;
}

function write_flash_to_screen(strFlashPath,numMovieWidth,numMovieHeight,strFlashVars) {
	var strFlashEmbed = '';
	strFlashEmbed += '<div id="flashContent">';
	strFlashEmbed += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+numMovieWidth+'" height="'+numMovieHeight+'" id="home_template" align="middle" viewastext>';
	strFlashEmbed += '<param name="allowScriptAccess" value="sameDomain" />';
	strFlashEmbed += '<param name="movie" value="'+strFlashPath+'?'+strFlashVars+'" />';
	strFlashEmbed += '<param name="quality" value="high" />';
	strFlashEmbed += '<param name="scale" value="noscale" />';
	strFlashEmbed += '<param name="salign" value="t" />';
	strFlashEmbed += '<param name="bgcolor" value="#000000" />';
	strFlashEmbed += '<embed src="'+strFlashPath+'?'+strFlashVars+'" scale="noscale" salign="t" quality="high" bgcolor="#000000" width="'+numMovieWidth+'" height="'+numMovieHeight+'" name="home_template" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	strFlashEmbed += '</object>';
	strFlashEmbed += '</div>'
	
	document.write(strFlashEmbed);
}

function write_flash_to_screen_floated(strFlashPath,numMovieWidth,numMovieHeight) {

	var strFlashEmbed = '';
	strFlashEmbed += '<div style="float:left">';
	strFlashEmbed += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+numMovieWidth+'" height="'+numMovieHeight+'" id="home_template" align="middle" viewastext>';
	strFlashEmbed += '<param name="movie" value="'+strFlashPath+'" />';
	strFlashEmbed += '<embed src="'+strFlashPath+'" scale="noscale" salign="t" quality="high" bgcolor="#000000" width="'+numMovieWidth+'" height="'+numMovieHeight+'" name="home_template" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	strFlashEmbed += '</object>';
	strFlashEmbed += '</div>'
		
	document.write(strFlashEmbed);
}

function check_iframe_loading() {
	if(top.location.href.match('page=')) {
		top.frames.content.location.replace(top.location.href.split("page=")[1].split("&")[0]);
	}
}

var size="big";
var targetWidth = 766;
var targetHeight = 396;
var flashRollerTimer = 0;

function rollFlash() {
	var actualHeight = parseInt(document.getElementById('flashContent').offsetHeight);
	if (targetHeight!=actualHeight) {
		if (Math.abs(targetHeight-actualHeight)<10) {
			document.getElementById('flashContent').style.height = targetHeight + "px";
			document.getElementById('home_template').style.height = targetHeight + "px";
			if (!document.all) document.getElementsByTagName('embed')[0].setAttribute('height',targetHeight + "px");
			return;
		}
		if (targetHeight>actualHeight) {
			document.getElementById('flashContent').style.height = actualHeight + 10 + "px";
			document.getElementById('home_template').style.height = actualHeight + 10 + "px";
			if (!document.all) document.getElementsByTagName('embed')[0].setAttribute('height',actualHeight + 10 + "px");
		} else {
			document.getElementById('flashContent').style.height = actualHeight - 10 + "px";
			document.getElementById('home_template').style.height = actualHeight - 10 + "px";
			if (!document.all) document.getElementsByTagName('embed')[0].setAttribute('height',actualHeight - 10 + "px");
		}
		clearTimeout(flashRollerTimer);
		flashRollerTimer = setTimeout("rollFlash()",10);
	}
}

function makeSmall() {
	clearTimeout(flashRollerTimer);
	if (size!="small") {
		targetWidth=766;
		targetHeight=100;
		size="small";
		try {
			thisMovie("home_template").goSmallNav();
		} catch(e) {
		}
	}
	flashRollerTimer = setTimeout("rollFlash()",10);
}
function makeBig() {
	clearTimeout(flashRollerTimer);
	if (size!="big") {
		targetWidth=766;
		targetHeight=396;
		size="big";
	}
	flashRollerTimer = setTimeout("rollFlash()",10);
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) return window[movieName];
    else return document[movieName];
}

function site_detect() {
	var blnDebug = false;
	
	if(location.href.indexOf("?blnDebug=true") != -1){
		blnDebug = true;
	}
	
	//First of all, check cookie. If it has a valid key, then both javascript and flash are ok
	//If no querystring parameter has been passed, check the cookie key value
	if(typeof(location.href.split('?lang=')[1]) == 'undefined') {
		//Once the cookie check has been performed, and a language value has not been set, null changes to a null string, hence both checks below are needed (== null and == 'null)
		if((typeof(lang) == 'undefined') || (lang == null) || (lang == 'null')) {
			//Check whether flash is installed
			if(flash.ver[8]) {
				if(blnDebug) alert(1);
				//Show choose language page, as both flash 8 and javascript are supported
				change_display('flashBox','none');
				change_display('validBox','none');
				change_display('langBox','block');
				
				//Track choose language page state
				urchinTracker('choose_language_index_page');
			}
			else {
				if(blnDebug) alert(2);
				//Flash 8 is not installed, so show no flash, upgrade flash
				change_display('validBox','none');
				change_display('langBox','none');
				change_display('flashBox','block');
				
				//Track choose language page state
				urchinTracker('no_flash_index_page');				
			}
		}
		else {
			if(!flash.ver[8]) {
				if(blnDebug) alert(3);
				//Flash 8 is not installed, so show no flash, upgrade flash
				change_display('validBox','none');
				change_display('langBox','none');
				change_display('flashBox','block');	
				
				//Track choose language page state
				urchinTracker('no_flash_index_page');						
			}
			else {
				if(blnDebug) alert(4);
				
				//Run site, passing in retrieved lang value as flash attribute
				change_display('flashBox','none');
				change_display('langBox','none');
				change_display('validBox','block');
				
				//Track choose language page state
				urchinTracker('index.html');				
			}
		}
	}
	else {
		if(blnDebug) alert(5);
		//Reset cookie value based on parameter passed in via querystring, and pass in new value as flash attribute
		change_display('flashBox','none');
		change_display('langBox','none');
		change_display('validBox','block');
		
		//Track choose language page state
		urchinTracker('index.html');					
	}
}

function change_display(element,displaytype) {
	document.getElementById(''+element).style.display = displaytype;
}