browsername = navigator.appName;
if (browsername.indexOf("Netscape")!=-1) {
	browsername="NS";
}else{
	if (browsername.indexOf("Microsoft")!=-1) {
		browsername="MSIE";
	}else {
		browsername="N/A";
	}
}

var requiredMajorVersion = 8; // Major version of Flash required
var requiredMinorVersion = 0; // Minor version of Flash required
var requiredRevision = 0; // Minor version of Flash required
var jsVersion = 1.0; // the version of javascript supported

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;

/*Case Study Images*/
image = new StringArray(12);
links = new StringArray(12);
imageFlat = new StringArray(12);
styleColor = new StringArray(12);

image[0] = '/file_source/StaticFiles/Flash Banners/Final Banner(Astral).swf';
image[1] = '/file_source/StaticFiles/Flash Banners/Final Banner(Bang).swf';
image[2] = '/file_source/StaticFiles/Flash Banners/Final Banner(Croke).swf';
image[3] = '/file_source/StaticFiles/Flash Banners/Final Banner(Devonshire).swf';
image[4] = '/file_source/StaticFiles/Flash Banners/Final Banner(JohnMills).swf';
image[5] = '/file_source/StaticFiles/Flash Banners/Final Banner(StKath).swf';
image[6] = '/file_source/StaticFiles/Flash Banners/Final Banner(StRichards).swf';
image[7] = '/file_source/StaticFiles/Flash Banners/Final Banner(Wellcome).swf';

imageFlat[0] = '/file_source/StaticFiles/Flash Banners/Flatbanner(Astral).jpg';
imageFlat[1] = '/file_source/StaticFiles/Flash Banners/Flatbanner(Bang).jpg';
imageFlat[2] = '/file_source/StaticFiles/Flash Banners/Flatbanner(Croke).jpg';
imageFlat[3] = '/file_source/StaticFiles/Flash Banners/Flatbanner(Devonshire).jpg';
imageFlat[4] = '/file_source/StaticFiles/Flash Banners/Flatbanner(JohnMills).jpg';
imageFlat[5] = '/file_source/StaticFiles/Flash Banners/Flatbanner(StKath).jpg';
imageFlat[6] = '/file_source/StaticFiles/Flash Banners/Flatbanner(StRich).jpg';
imageFlat[7] = '/file_source/StaticFiles/Flash Banners/Flatbanner(Wellcome).jpg';

links[0] = '/en/market_sectors/industrial/astral_court/astral_court_casestudy';
links[1] = '/en/market_sectors/leisure/b_of_the_bang/b_of_the_bang_casestudy';
links[2] = '/en/market_sectors/leisure/croke_park/croke_park_casestudy';
links[3] = '/en/market_sectors/education/devonshire_building/devonshire_casestudy';
links[4] = '/en/market_sectors/leisure/john_mills_racing_hq/john_mills_casestudy';
links[5] = '/en/market_sectors/commercial/k2_st_katherines/k2_casestudy';
links[6] ='/en/market_sectors/health/st_richards/st_richards_hospital';
links[7] ='/en/market_sectors/commercial/wellcome_trust/wellcome_trust';

styleColor[0] = '#87CDB5';
styleColor[1] = '#050506';
styleColor[2] = '#00ADEF';
styleColor[3] = '#00ADEF';
styleColor[4] = '#EF4123';
styleColor[5] = '#00ADEF';
styleColor[6] = '#5C3F99';
styleColor[7] = '#87CDB5';

// Images and links for the colors page
imageFile  = new StringArray(4);
linksHref  = new StringArray(4);

imageFile [0] = "/file_source/StaticFiles/Colorcoat Online/Images/Homepage/ColorConnectBan.gif";
imageFile [1] = "/file_source/StaticFiles/Colorcoat Online/Images/Homepage/Confidex_ban.gif";
imageFile [2] = "/file_source/StaticFiles/Colorcoat Online/Images/Homepage/PrismaBan.gif ";
imageFile [3] = "/file_source/StaticFiles/Colorcoat Online/Images/Homepage/RepBan.gif";

linksHref [0] = "http://www.colorcoat-online.com/en-GB/products/services/colorcoat_connection/";
linksHref [1] = "http://www.colorcoat-online.com/en-GB/products/guarantees/confidex/";
linksHref [2] = "http://www.colorcoat-online.com/en-GB/products/exterior_products/colorcoat_prisma_pro";
linksHref [3] = "http://www.colorcoat-online.com/en-GB/products/services/repertoire/";

// Number of images for the randomization;
var ran = 8;

//Naviation Functions///
//-----------------------------------------------------------------
function changeFromSelect(sel) {
//-----------------------------------------------------------------
	var target = sel.value;
	window.location.href = target;
	return false;
}

//-----------------------------------------------------------------
function changeToProductSection(path) {
//-----------------------------------------------------------------
	if (country != "") country = "-" + country;
	var target = prefix + country + path;
	// alert("Change Sector: " + target);
	window.location.href = target;
}

//-----------------------------------------------------------------
function changeLanguage(country, fullpath) {
//-----------------------------------------------------------------
	//XX = ANY
	if (country == '' || country == 'XX') {
		DeleteCookie("corus-country");
	} else {
		SetCookie("corus-country", country);
		country = "-" + country;
	}
	var target = prefix + country + fullpath;
	// alert("Change Language: " + target);
	window.location.href = target;
}

//-----------------------------------------------------------------
function changeHomeAndGo(path) {
//-----------------------------------------------------------------
	if (path == '') {
		DeleteCookie("corus-home");
		path = '/';
	} else {
		SetCookie("corus-home", path);
	}

	if (country != "") country = "-" + country;
	var target = prefix + country + path;
	window.location.href = target;
}

function clearHome() {
	changeHomeAndGo('');
}

//-----------------------------------------------------------------
function checkIsHome() {
//-----------------------------------------------------------------
	var currcookie = GetCookie("corus-home");
	/*
	JM: This confuses Ultraseek.
	var currpath = '<xsl:value-of select="$current-path" />';

	if (currpath == currcookie) {
		// document.write('<b>This page is currently set as your home page. <a href="javascript:clearHome();">Clear</a></b><br />');
		document.getElementById("thisismyhome").style.display="block";
	}
	*/
	return false;
}

//-----------------------------------------------------------------
function submitProductForm() {
//-----------------------------------------------------------------
	var f = document.forms.prodform;
	changeToProductSection( f.sector.value);
	return false;
}

//-----------------------------------------------------------------
function submitCountryForm(el, fullpath) {
//-----------------------------------------------------------------
	changeLanguage(el.value, fullpath);
	return false;
}

//-----------------------------------------------------------------
function JSGetSwfVer(i){
// JavaScript helper required to detect Flash Player PlugIn version information
//-----------------------------------------------------------------

	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];

			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}

      			versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            		flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      		} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {

		flashVer = -1;
	}
	return flashVer;
}

//-----------------------------------------------------------------
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
//-----------------------------------------------------------------

 	//alert(reqMajorVer + ' ' + reqMinorVer + ' ' +  reqRevision);

 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);

   	// loop backwards through the versions until we find the newest version
	for (i=25; i > 0; i--) {

		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);
		}
		if (versionStr == -1 ) {
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray = versionStr.split(" ");
				tempString = tempArray[1];
				versionArray = tempString .split(",");
			} else {
				versionArray = versionStr.split(".");
			}

			versionMajor = versionArray[0];
			versionMinor = versionArray[1];
			versionRevision = versionArray[2];

			versionString = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum = parseFloat(versionString);

			// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
			}
		}
	}
}

//-----------------------------------------------------------------
function getMouseXY(e) {
//-----------------------------------------------------------------
	if(isIE) {

		if (document.documentElement && document.documentElement.scrollTop) {
			//grab the x-y pos.s if browser is IE 6
			tempX = event.clientX + document.documentElement.scrollLeft;
			tempY = event.clientY + document.documentElement.scrollTop;
		}else{
			try {
				// grab the x-y pos.s if browser is IE
				tempX = event.clientX + document.body.scrollLeft;
				tempY = event.clientY + document.body.scrollTop;
			} catch (error) {
				// sweep error under the carpet.
				// Probably happen if scrollbars not loaded.
			}
		}

	}else{
		// all except Explorer
		tempX = e.pageX;
		tempY = e.pageY;
	}
	return true;
}

//-----------------------------------------------------------------
function displayImage(img){
//-----------------------------------------------------------------
	if (img != '') {
		// getMouseXY();
		MM_swapImage('rp-cwp-multiformat-rolledImage','',img,1);
		document.getElementById('rp-cwp-multiformat-rollableImage').style.left = (tempX + 25) + "px";
		document.getElementById('rp-cwp-multiformat-rollableImage').style.top = (tempY - 25) + "px";
		document.getElementById('rp-cwp-multiformat-rollableImage').style.display = 'block';
	}
}

//-----------------------------------------------------------------
function hideImage(){
//-----------------------------------------------------------------
	document.getElementById('rp-cwp-multiformat-rollableImage').style.display = 'none';
	MM_swapImgRestore();
}

//-----------------------------------------------------------------
function displayHiddenFieldCheck(HiddenFieldID, oCheck, isOn){
//-----------------------------------------------------------------
	if (oCheck.checked == true){
		document.getElementById(HiddenFieldID).style.display = "block";
	}else{
		document.getElementById(HiddenFieldID).style.display = "none";
	}
}

//-----------------------------------------------------------------
function displayHiddenField(HiddenFieldID, oSelect, isOn){
//-----------------------------------------------------------------
	if (oSelect.value == "Other"){
		document.getElementById(HiddenFieldID).style.display = "block";
	}else{
		document.getElementById(HiddenFieldID).style.display = "none";
	}
}


//-----------------------------------------------------------------
function openNewWindow(iHeight, iWidth, url, bScroll, bResize){
//-----------------------------------------------------------------
	window.open(url, '', 'scrollbars=yes,resizable=yes,toolbar=no,width='+iWidth+',height='+iHeight+'');
}

//-----------------------------------------------------------------
function StringArray (n){
//-----------------------------------------------------------------
  this.length = n;
  for (var i =1; i <= n; i++)
  {
    this[i] = ' ';
  }
}

//-----------------------------------------------------------------
function get_random(){
//-----------------------------------------------------------------
    var ranNum= Math.round(Math.floor(Math.random()*ran));
    return ranNum;
}

var core = get_random();

//-----------------------------------------------------------------
function ranflashimage(){
//-----------------------------------------------------------------
	return(image[core]);
}

//-----------------------------------------------------------------
function ranlnk(){
//-----------------------------------------------------------------
	return(links[core]);
}

//-----------------------------------------------------------------
function ranflatimage(){
//-----------------------------------------------------------------
	return(imageFlat[core]);
}

//-----------------------------------------------------------------
function drawFlash(oDev){
// Draws the flash object or static image - only for costruction
//-----------------------------------------------------------------

var str = "";

// Version check based upon the values entered above in "Globals"
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

// Check to see if the version meets the requirements for playback
if (hasReqestedVersion) {
	// if we've detected an acceptable version

	str = str + '<div style="background:' + styleColor[core] +';">';

	str = str + "<object width=\"445\" height=\"190\">";
	str = str + "<param name=\"movie\" value=\"";
	str = str +  ranflashimage();
	str = str +  "\"/>";
	str = str + "<param name=\"FlashVars\" value=\"link="+ranlnk()+"\" />";
	str = str + "<param name=\"wmode\" value=\"Transparent\" />";
	str = str +  "<embed src=\"";
	str = str +  ranflashimage();
	str = str +  "\" FlashVars=\"link="+ranlnk()+"\" width=\"445\" height=\"190\" wmode=\"Transparent\"  ></embed>";
	str = str +  "</object>";
	str = str +  "</div>";
  } else {
  	// flash is too old or we can't detect the plugin
	str = '<a href="'+links[core]+'"><img src="'+ imageFlat[core]+'" border="0" vspace="3" /></a>'
	+ '<br />This content requires Adobe Flash Player.<br /><br />'
	+ '<a href=http://get.adobe.com/flashplayer/><img src="/file_source/images/get_flash_player.gif" border="0" /></a><br />';
  }

document.write(str);

}

//-----------------------------------------------------------------
function get_random_limit(rval){
// Random value from 0 up to rval
//-----------------------------------------------------------------
    var ranNum= Math.round(Math.floor(Math.random()*rval));
    return ranNum;
}

// -------------------------------------
function rotateBannerTimed()
// Rotate banners
// -------------------------------------
{

		var rnumber = get_random_limit(4);

		var bannerCode = document.getElementById('bannerBlock')

		bannerCode.innerHTML = '<a id="link" href="'+linksHref[rnumber]+'"><img id="image" src="'+ imageFile[rnumber]+'" HEIGHT="150" WIDTH="448" border="0" vspace="3" /></a>';

		t=setTimeout("rotateBannerTimed()",7000)
}

// -------------------------------------
function drawColorBanner()
// Corus - colors Rotating banners
// -------------------------------------
{
	// Set up our initial values
	var rnumber = get_random_limit(4);

	// Create initial image element
	msg = '<div id="bannerBlock"><a id="link" href="'+linksHref[rnumber]+'"><img id="image" src="'+ imageFile[rnumber]+'" HEIGHT="150" WIDTH="448" border="0" vspace="3" /></a></div>'

	// Write initial element to page
	document.write(msg);
	rotateBannerTimed();
}

//-----------------------------------------------------------------
function showImgAni() {
//-----------------------------------------------------------------
	document.getElementById('imgAni').style.display = 'block';
	document.getElementById('imgStatic').style.display = 'none';
}

//-----------------------------------------------------------------
function showImgStatic() {
//-----------------------------------------------------------------
	document.getElementById('imgAni').style.display = 'none';
	document.getElementById('imgStatic').style.display = 'block';
}


//-----------------------------------------------------------------
function makeHomepage(url, me, forwardUrl){
//-----------------------------------------------------------------
	if (navigator.userAgent.indexOf("MSIE")!=-1) {
		
		me.style.behavior='url(#default#homepage)';
		me.setHomePage(url);
		
		//Set the values for the holding page to forward to
		SetCookie("makeHPForwardURL", forwardUrl);
		SetCookie("makeHPURL", url);

		location.href='/static/htm/homepage_holding.html';
	}else{
		alert('Sorry! This function will not work with non-IE browsers. To make ' + url + ' your homepage just drag the URL from your URL box to your HOME icon.');
	}
}

//-----------------------------------------------------------------
function addToFavorites(urlAddress, pageName, forwardUrl) {
//-----------------------------------------------------------------
	if (document.all) {
		window.external.AddFavorite(urlAddress, pageName); 
	} else {
		window.sidebar.addPanel(pageName, urlAddress, "");
	}
	
	//TODO: Catch when user clicks "No"
	location.href=forwardUrl;
}

//-----------------------------------------------------------------
function interestClick(id) {
//-----------------------------------------------------------------
	var CheckField = document.getElementById('other_interest_' + id);
	var txtField = document.getElementById('secondaryInterest');
	var sField = "";
	
	sField = txtField.value;
	sField = leftTrim(sField);
	sField = rightTrim(sField);
	
	//Click
	if (CheckField.checked == true){
		if (sField != '') sField = sField + ',';
		txtField.value = sField + CheckField.value;	
	}else{
		sField = sField.replace(',' + CheckField.value , '');
		sField = sField.replace(CheckField.value + ',' , '');
		sField = sField.replace(CheckField.value, '');
		txtField.value = sField;
	}
	
}
//-----------------------------------------------------------------
function interestClickForTargetZero(id) {
//-----------------------------------------------------------------
	var CheckField = document.getElementById('other_interest_' + id);
	var txtField = document.getElementById('primaryInterest');
	var sField = "";
	
	sField = txtField.value;
	sField = leftTrim(sField);
	sField = rightTrim(sField);
	
	//Click
	if (CheckField.checked == true){
		if (sField != '') sField = sField + ',';
		txtField.value = sField + CheckField.value;	
	}else{
		sField = sField.replace(',' + CheckField.value , '');
		sField = sField.replace(CheckField.value + ',' , '');
		sField = sField.replace(CheckField.value, '');
		txtField.value = sField;
	}
	//alert(txtField.value);
	
}
//-----------------------------------------------------------------
function interestClickIsChecked(from, to) {
//-----------------------------------------------------------------
	var txtField = document.getElementById('secondaryInterest');
	var CheckField = "";
	var str = "";
	var pos = "";
	
	for (var i=1; i<=to; i++){
		CheckField = document.getElementById('other_interest_' + i);
		
		str = txtField.value;
		pos = str.indexOf(CheckField.value);
		
		if (pos>=0){
			CheckField.checked=true;
		} else {
			CheckField.checked=false;
		}		
	}
}

//-----------------------------------------------------------------
function leftTrim(sString) {
//-----------------------------------------------------------------
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

//-----------------------------------------------------------------
function rightTrim(sString) {
//-----------------------------------------------------------------
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

//-----------------------------------------------------------------
function printPage(pagetitle, currentsite, sPrint, p) {
//-----------------------------------------------------------------

	var da = (document.all) ? 1 : 0;
	var pr = (window.print) ? 1 : 0;
	
	if(!pr)
		return;
	
	var printArea = document.getElementById("mainareadiv");

	if (printArea == null) {
		if (da) {
			printArea = document.all.mainareadiv;
		}
	}
	
	
	if (printArea) {
	
		SetCookie("IS_PRINTING","TRUE");
		
		
		
		var sStart = '<html>';
			sStart += '<head><title>' + pagetitle + '</title>';
			sStart += '<script type="text/javascript" src="/static/js/common.js"></script>';
			sStart += '<script type="text/javascript" src="/static/js/cookies.js"></script>';
			sStart += '<link href="/static/css/common/style.css" rel="stylesheet" type="text/css" />';
			sStart += '<link href="/static/sites/' + currentsite + '/css/style.css" rel="stylesheet" type="text/css" /></head>';
			sStart += '<body style="margin: 10px;">';
			sStart += '<div class="header"><img src="/static/images/logos/logo_small_white.gif" alt="Corus" /></div>';
		
		var sStop = '<div class="printerFriendlyFooter">';
			sStop += '<a class="button" onclick="window.print(); return false;" href="#">' + sPrint + '</a>&#160;';
			sStop += '<a class="button" onclick="window.close(); return false;" href="#">' + sClose + '</a>';
			sStop += '</div>';
			sStop += '</body></html>';
		
		var w = window.open('','printWin','width=650,height=440,scrollbars=yes');
		wdoc = w.document;
		wdoc.open();
		
		var sContent = sStart + printArea.innerHTML + sStop;
		wdoc.write(sContent);
		wdoc.close();
	}
	
}

// Mouse X and Y Co-ods
if (!isIE) document.captureEvents(Event.MOUSEMOVE)
var tempX = 0;
var tempY = 0;

//Call the MouseMove events
document.onmousemove = getMouseXY;

//-----------------------------------------------------------------
function echeck(str) {
//Email checker
//-----------------------------------------------------------------

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }

	 if (str.indexOf(" ")!=-1){
	    return false
	 }

	 return true					
}


//Check all radio/check buttons script- by javascriptkit.com
//Visit JavaScript Kit (http://javascriptkit.com) for script
//Credit must stay intact for use  

function checkAll(checkboxgroup, theCheckBox) {
  for (i = 0; i < checkboxgroup.length; i++)
  {
  		checkboxgroup[i].checked = theCheckBox.checked? true:false; 		
  }
  //calling function, this will build string
  for (j = 0; j < checkboxgroup.length; j++)
  {
  			interestClickForTargetZero(j+1);
  }  
}

function validate(formObj){
	var elements = formObj.elements;
	var flag = true;
	var email = "";
	var password="";
	for (var i=2; i<elements.length && flag; i++) {
		var name = elements[i].getAttribute("name");
		
		if(name == "email"){
			if(echeck(elements[i].value)) email = elements[i].value;
			else {flag =!flag;  alert("Invalid email!");}
		}
		if(name == "confirmEmail"){			
			if(echeck(elements[i].value)){
				if(elements[i].value != email){flag= !flag; alert("emails does not match !")}
			}else{flag =!flag;  alert("Invalid email!");}
		}
		
		if(name == "fullName" ||name == "otherProfession" ||name == "companyName" || 
			name == "address1" ||name == "address2" ||name == "address3" ||
			name == "postCode" ||name == "telephone"){
				if(elements[i].value == "" ||elements[i].value.length == 0){elements[i].value = "N/A";}
		}
	}
	return flag;
}