window.onload = function() {
	npowerJSLoad();
}

//load this only once
var npowerLoaded = false;

//placed here so it can be called directly by other
//JS files which would override the onload event...
function npowerJSLoad(){
	if (!npowerLoaded){
		checkRoot();
		DynamicNumber.Initialise();
		doPopup();
		setFlash();
		setPopup();
		setRevealer();
		setTNC();
		setTooltips();
		renderTrackingTags();
		clean9003();
		setRotator();
		Slider.Initialize();
		FormCampaign.Initialize();
		AppendQSURLs();
		//ImageReplacement.Initialize(); << needs revision so that it fires with a timer instead.
		VoucherCodes.Initialize();
		
		//### must be last in the list! ###//
		showDeveloperMessage();
	}
	
	npowerLoaded = true;
}

// -------------------- GLOBAL CONSTANTS & VARS -------------------- //
//REVEAL & TNC...
var coRevTopNorm 			= getStellentURL('/groups/wcms_content/@wcms/@resi/documents/digitalassets/lp_revealer_top.jpg');
var coRevTopSwap 			= getStellentURL('/groups/wcms_content/@wcms/@resi/documents/digitalassets/lp_revealer_top_show.jpg');
var coRevBtnNorm 			= getStellentURL('/groups/wcms_content/@wcms/@resi/documents/digitalassets/lp_revealer_top_open.jpg');
var coRevBtnSwap 			= getStellentURL('/groups/wcms_content/@wcms/@resi/documents/digitalassets/lp_revealer_top_close.jpg');
var coRevBtnSwapClean   	= getStellentURL('/groups/wcms_content/@wcms/@resi/documents/digitalassets/lp_revealer_top_close_clean.jpg');
var coRevTopNormWide 		= getStellentURL('/groups/wcms_content/@wcms/@resi/documents/digitalassets/lp_revealer_top_wide.jpg');
var coRevTopSwapWide 		= getStellentURL('/groups/wcms_content/@wcms/@resi/documents/digitalassets/lp_revealer_top_show_wide.jpg');
var coRevTopNormSuperWide 	= getStellentURL('/groups/wcms_content/@wcms/@resi/documents/digitalassets/lp_revealer_top_superwide.jpg');
var coRevTopSwapSuperWide 	= getStellentURL('/groups/wcms_content/@wcms/@resi/documents/digitalassets/lp_revealer_top_show_superwide.jpg');
var lastTNCID = new Array(); //for showTNC();

var coRevTipNorm	= 'View or hide information about this heading';
var coTNCTip 		= 'Click here to show or hide our terms and conditions.';

//Error messages...
var errMsg			= ''; //for showDeveloperMessage();
var coMsgSeparator	= '\n________________________________________________    \n\n';

//Flash HTML code...
var flashObj		= '<object id="{id}" width="{w}" height="{h}" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0">' +
					  '  <param name="movie" value="{s}" />' +
					  '  <param name="quality" value="high" />' +
					  '  <param name="allowFullScreen" value="{afs}" />' +
					  '  <param name="allowScriptAccess" value="sameDomain" />' +
					  '  <param name="wmode" value="transparent" />' + 
					  '  <embed name="{id}" src="{s}" width="{w}" height="{h}" quality="high" wmode="transparent" allowFullScreen="{afs}" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' +
					  '</object>'
					  
var noFlash			= '<div class="no_flash"><p>This Flash movie requires version {v} or greater to run. Please <a href="http://www.macromedia.com/go/getflashplayer" target="_blank">download the latest version of Flash</a> before continuing.</p></div>';
					  
//Rotator constants...
var coDefaultImgDir	= getStellentURL('/groups/wcms_content/@wcms/documents/digitalassets/');
var coRotatorObj	= '<div id="{rid}" class="rotator_inner" style="{style}"><a id="{aid}" href="{link}"><img id="{iid}" src="{img}" border="0" onMouseOver="isBannerPaused=true" onMouseOut="isBannerPaused=false"/></a></div>';

var coRotateDelay	= 6000; //milliseconds

//Tooltip Constants...
coToolPosTop = 1;
coToolPosLeft = 2;

var dTitle = document.title;

// -------------------------------------------- -------------------- //










// ------------------------ VoucherCodes v0.1 --------------------- //
//                                                                  //
//  Used to check whether a voucher code is valid when a Q&S form   //
//  is posted.                                                      //
//                                                                  //
//  Note that this is a temporary solution and it not particularly  //
//  secure as the valid vouchers are contained within the page.     //
//                                                                  //
//  Use: onSubmit="return VoucherCodes.Validate('<input id>');">    //
//                                                                  //
//  <div id="allowedVouchers" voucherError='<error message>'>       //
//     <div class="<allowed code>"></div>                           //
//     <div class="<allowed code>"></div>                           //
//     <div class="<allowed code>"></div>                           //
//     ...                                                          //
//  </div>                                                          //
//                                                                  //
// The optional voucherError attribute can be used to override the  //
// default error message.                                           //
// -----------------------------------------------------------------//
function VoucherCodes() {}
VoucherCodes.AllowedList;
VoucherCodes.Error = 'Please enter a valid voucher code';

VoucherCodes.Initialize = function() {
	var holder = $__('allowedVouchers');
	if (holder) {
		if (holder.getAttribute('voucherError')) {
			VoucherCodes.Error= holder.getAttribute('voucherError');				
		}
		VoucherCodes.AllowedList = new Array();
		VoucherCodes.AllowedList = VoucherCodes.GetAllowedVoucherCodes(holder);
	}
}

VoucherCodes.GetAllowedVoucherCodes = function(parentID) {
	if (!document.getElementsByTagName) return false;
	var result = new Array();
	if (!parentID) { return result; }
	var items = parentID.getElementsByTagName("div");
	for(var i=0; i < items.length; i++) {
		result.push(items[i].getAttribute('voucher').toLowerCase());
	}

	return result;
}

VoucherCodes.Validate = function(elementID){
	if (!$__(elementID)) return false;
	var voucher = $__(elementID).value;
	for (i=0; i < VoucherCodes.AllowedList.length; i++){
		if (VoucherCodes.AllowedList[i] == voucher.toLowerCase()) {
			return 'voucherID='+voucher.toLowerCase();
		}
	}
	alert(VoucherCodes.Error);
	return '';
}






// ---------------------- ImageReplacement v0.2 ------------------- //
//                                                                  //
//  Looks to see if images are loaded. If not will remove text      //
//  indents from h1,h2,h3,a tags. This is so we can use image       //
//  replacement techniques on headings without worrying about users //
//  that have images turned off.                                    //
//                                                                  //
// -----------------------------------------------------------------//
function ImageReplacement() {}
ImageReplacement.imgTemp = new Image();
//This is the image on the server that the script looks for to check if images can be loaded.
ImageReplacement.imgTemp.src = window.location.protocol + '//www.npower.com/idc/groups/wcms_content/@wcms/documents/digitalassets/image_check.gif';

ImageReplacement.Initialize = function() {
	ImageReplacement.checkComplete(ImageReplacement.imgTemp);
}

ImageReplacement.checkComplete = function(img) {
	if (img.complete) {
		ImageReplacement.imageLoaded(img);
	}else{
		if (img.width == 0){
			ImageReplacement.checkComplete(img);
		}else{
			ImageReplacement.imageLoaded(img,true);
		}
	}
}

ImageReplacement.imageLoaded = function(img,isIE) {
	if (img.width == 0 || isIE) {
		ImageReplacement.resetHeadings("h1");
		ImageReplacement.resetHeadings("h2");
		ImageReplacement.resetHeadings("h3");
		ImageReplacement.resetHeadings("a");
	}
}

ImageReplacement.resetHeadings = function(element){
	if (!document.getElementsByTagName) return false;
	var items = document.getElementsByTagName(element);
	
	for(var i=0; i < items.length; i++) {
		items[i].style.textIndent = '0px';
		items[i].style.height = 'auto';
	}
}






// ------------------------ AppendQSURLs v0.3 --------------------- //
//                                                                  //
//  Searches all <a> tags for a journeyID. If found, appends any    //
//  query string to the end of the URL. Only searches if there's    //
//  a query string, otherwise does nothing.                         //
//                                                                  //
//  v0.3 (v0.2 removed):                                            //
//  Searches <a> tags for a class called "appendquery"              //
//                                                                  //
//  and if found appends any query string to the end of the href.   //
//  Only searches if there is a query string else does nothing.     //
//                                                                  //
// -----------------------------------------------------------------//
function AppendQSURLs() {
	var items = document.getElementsByTagName("a");
	var url;
	var searchString = "journeyid=";
	var q = location.search.substring(1);
	if (q) {
		for(var i=0; i < items.length; i++) {
			if (items[i].getAttribute("href")){
				url = items[i].getAttribute("href").toLowerCase();
				if (url.indexOf(searchString) > -1) {
					items[i].setAttribute("href", url + "&" + q);
				}else if (items[i].getAttribute("class") && items[i].getAttribute("class").indexOf("appendquery") > -1) {
					items[i].setAttribute("href", url + ((url.indexOf("?") > -1)? "&" : "?") + q);	
				}
			}
		}
	}
}



// ------------------------ FormCampaign v0.2 --------------------- //
//                                                                  //
//  Used to add a campaign code, affiliate id and telephone # to a  //
//  link so as to pass to a .NET form for processing.               //
//                                                                  //
//  Use: <a class="setCampaign" href="<theURL>">link</a>            //
//                                                                  //
//  <div id="allowedCampaigns" forceHash="true">                    //
//     <div telephone="<value>" campaign="<value>"></div>           //
//     <div telephone="<value>" campaign="<value>"></div>           //
//     <div telephone="<value>" campaign="<value>"></div>           //
//     ...                                                          //
//  </div>                                                          //
//                                                                  //
//  URL: http://url/page.html#c=<campaign_code>  ~ or~              //
//  URL: http://url/page.html#t=<telephone_number>                  //
//                                                                  //
//  Additionally, you may also pass:                                //
//                                                                  //
//  .../page.html#a=<affiliate_id>                                  //
//                                                                  //
//  NOTE: # is used instead of ? for the query strings for seo.     //
//                                                                  //
//  <div class="setNumber"><number to replace></div>                //
//  <span class="setNumber"><number to replace></span>              //
//  <a class="setCampaign" href="<link>">a link</a>                 //
//                                                                  //
//  forceHash="true" forces the resulting query string to be a #    //
//  instead of a ?                                                  //
//                                                                  //
//  --------------------------------------------------------------  //
//  v0.2 - Added check in case campaign is blank for non a-tag      //
// -----------------------------------------------------------------//
function FormCampaign() {}
FormCampaign.ForceHash = false;

FormCampaign.Initialize = function() {
	if (!document.getElementsByTagName) { return; }	
	var q = getCleanQueryString(); if (!q) { return; }
	var qPairs = q.split("&");
	var allowedCampaigns = FormCampaign.GetAllowedCampaigns();
	
	//search for affiliate id...
	var affiliateID = getValueFromQueryString('a', qPairs);
	var telNo = '';
	var campaignID = '';
	var index = -1;

	//search for campaign codes (look for telephone number only if this fails)...
	if (getValueFromQueryString('c', qPairs)) {
		index = getArrayIndexFromValue(getValueFromQueryString('c', qPairs),0,allowedCampaigns,true);
	}else if (getValueFromQueryString('t', qPairs)) {
		index = getArrayIndexFromValue(getValueFromQueryString('t', qPairs),1,allowedCampaigns,true);	
	}
	
	//if we've no campaigns or affiliate IDs then exit...
	if (affiliateID == "" && index == -1) { return; }
	
	//get the telephone and campaign code pairs...
	if (index > -1) {
		campaignID = getArrayValueFromIndex(index, allowedCampaigns, 0);	
		telNo = getArrayValueFromIndex(index, allowedCampaigns, 1);										   	
	}
	
	//only rewrite the markup if we've got stuff...
	if (campaignID || telNo || affiliateID) {
		FormCampaign.Execute(telNo, campaignID, affiliateID);
	}
}

FormCampaign.Execute = function(telNo, campaignID, affiliateID) {
	FormCampaign.SetMarkup('div',telNo, campaignID, affiliateID);
	FormCampaign.SetMarkup('span',telNo, campaignID, affiliateID);
	FormCampaign.SetMarkup('a',telNo, campaignID, affiliateID);
}

FormCampaign.SetMarkup = function(tag, telNo, campaignID, affiliateID)
{
	//replace innerHTML / add to href of found classes...
	var items = document.getElementsByTagName(tag);
	for(var i=0; i < items.length; i++)
	{
		if (items[i].className.match("setNumber") && telNo != "")
			items[i].innerHTML = telNo;
		if (items[i].className.match("setCampaign") && tag != 'a' && campaignID != "")
			items[i].innerHTML = campaignID;
		if (items[i].className.match("setCampaign") && items[i].getAttribute("href") && tag == 'a') {
			var needsAmp = true;
			
			if (items[i].href.indexOf('?') == -1 && (campaignID != "" || affiliateID != "")) {
				items[i].href += '?';
				needsAmp = false;
			}
				
			if (campaignID != "")
				items[i].href += needsAmp ? '&campaign=' + campaignID : 'campaign=' + campaignID ;
				
			if (affiliateID != "")
				items[i].href += (items[i].href.indexOf('campaign') > -1 ) ? '&affiliate=' + affiliateID : (needsAmp ? '&affiliate=' + affiliateID : 'affiliate=' + affiliateID);
				
			if (FormCampaign.ForceHash) {
				items[i].href = items[i].href.replace('?','#');
			}
		}	
	}
}

FormCampaign.GetAllowedCampaigns = function() {
	if (!document.getElementsByTagName) return false;
	var parentID = $__('allowedCampaigns');
	var result = new Array();
	if (!parentID) { return result; }
	
	var items = parentID.getElementsByTagName("div");
	for(var i=0; i < items.length; i++) {
		result.push(items[i].getAttribute('campaign')+','+items[i].getAttribute('telephone'));
	}
	
	//convert the resulting query string to a # instead of a ?...
	if (parentID.getAttribute('forceHash') && parentID.getAttribute('forceHash').toLowerCase() == "true")
		FormCampaign.ForceHash = true;
	
	return result;
}










// -------------------------- Slider v0.2 ------------------------- //
//                                                                  //
//  Used to slide banners automatically from right to left or by    //
//  Image buttons.                                                  //
//                                                                  //
//  sliderwidth="<value>" << width of the slider holder             //
//  sliderdelay="<value>" << delay in millisecons for auto          //
//  sliderautoslide="true" << sets the slider to auto slide         //
//                                                                  //
//  --------------------------------------------------------------  //
//  v0.2 - Swapped the left/right buttons round                     //
// -----------------------------------------------------------------//
function Slider() {}
Slider.Slides = new Array();
Slider.Width;
Slider.Delay = 4000; //default - milliseconds
Slider.AutoSlide = false; //default - don't auto slide
Slider.IsPaused = false;
Slider.TotalWidth = 0;
Slider.Container = 'slideritems';
Slider.TimerID;
Slider.Initialize = function() {
	if (!document.getElementsByTagName) return false;
	var items = document.getElementsByTagName("div");
	var sliderHolder = 'slider';
	var sliderHolderID = 'sliderHolderID';
	var sliderItem = 'slideritem';
	var sliderDelay = 'sliderdelay';
	var sliderWidth = 'sliderwidth';
	var sliderAutoSlide = 'sliderautoslide';
	var btnPrev = 'sliderprevious';
	var btnNext = 'slidernext';
	var holderID = 0;

	//start by grabbing the values we need from the html markup
	//and add IDs as needed...
	for(var i=0; i < items.length; i++) {
		//the main holder...
		if (items[i].className.toLowerCase().match(sliderHolder) && (items[i].className.length == sliderHolder.length || items[i].className.toLowerCase().match(sliderHolder+' '))) {	
			if (!items[i].getAttribute(sliderWidth)) {
				errMsg += coMsgSeparator + 'ERROR: slider tag is missing "sliderwidth" attribute.';
				break;
			}else{
				Slider.Width = 	getNoPxVal(items[i].getAttribute(sliderWidth));
			}
			
			items[i].setAttribute('id',sliderHolderID+'__'+holderID);
			$__(items[i].id).style.width = String(Slider.Width) + 'px';
			
			if (items[i].getAttribute(sliderDelay)) {
				Slider.Delay = parseInt(items[i].getAttribute(sliderDelay));
			}
			
			if (items[i].getAttribute(sliderAutoSlide)) {
				Slider.AutoSlide = items[i].getAttribute(sliderAutoSlide).toLowerCase() == "true"? true : false;
			}
			
			holderID++;
		}
		
		if (items[i].className.toLowerCase() == Slider.Container) {
			items[i].setAttribute('id',Slider.Container);
		}
		
		//look for the children and grab the html
		if (items[i].className.toLowerCase() == sliderItem) {
			Slider.Slides.push(items[i].innerHTML);
		}
	}
	
	//navigation buttons...
	var childrenLink = document.getElementsByTagName("img");
	for(var i=0; i < childrenLink.length; i++) {
		//previous button
		if (childrenLink[i].className.toLowerCase().match(btnPrev)) {
			childrenLink[i].onclick = function() { Slider.SlideRight();return false; };
			if (Slider.Slides.length == 1)
				childrenLink[i].style.visibility = 'hidden';
		}
		
		//next button
		if (childrenLink[i].className.toLowerCase().match(btnNext)) {	
			childrenLink[i].onclick = function() { Slider.SlideLeft();return false; };
			if (Slider.Slides.length == 1)
				childrenLink[i].style.visibility = 'hidden';
		}
	}

	//only continue if there is more than one slide...
	if (Slider.Slides.length > 1) {
		//add the cloned slides top and tail.
		//last slide cloned to the beginning, first slide cloned to the end...
		Slider.Slides.splice(0,0,Slider.Slides[Slider.Slides.length-1]);
		Slider.Slides.splice(Slider.Slides.length,0,Slider.Slides[1]);
		
		//create the new html from the array and re-write the slider holder html...
		$__(Slider.Container).innerHTML = String(Slider.Slides).replaceAll(',','');
		Slider.TotalWidth = (Slider.Slides.length) * Slider.Width;
		Slider.Reset();
		Slider.Animate();
	}
}

Slider.SlideLeft = function(isAuto) {
	slideLeft(Slider.Container,Slider.Width,parseInt(getNoPxVal($__(Slider.Container).style.left)));
}

Slider.SlideRight = function() {
	slideRight(Slider.Container,Slider.Width,parseInt(getNoPxVal($__(Slider.Container).style.left)));
}

Slider.Animate = function (){
	clearInterval(Slider.TimerID);
	
	if (Slider.AutoSlide) {
		Slider.TimerID = setInterval("Slider.SlideLeft(true)",Slider.Delay);
	}
}

Slider.Reset = function(isAtZero) {
	//reset the position
	if (!isAtZero) {
		$__(Slider.Container).style.left = '-' + String(Slider.Width) + 'px';
	}else{
		$__(Slider.Container).style.left = '-' + String(Slider.TotalWidth-(Slider.Width*2)) + 'px';
	}
}




// ------------------------- checkRoot v0.2 ----------------------- //
//                                                                  //
// Used to temporary fix http://npower.com to http://www equivalent //
//                                                                  //
// -----------------------------------------------------------------//
function checkRoot() {
	var p = document.location.href;

    if (p.indexOf('http://npower.com/') == 0) {
		document.location.href = 'http://www.' + p.substring(7,p.length);
	}
}



// ------------------------ setRotator v0.1 ----------------------- //
//                                                                  //
// Used to rotate the top banner on the homepage inc. css image     //
//                                                                  //
// <div class="rotatorHolder">                                      //
// 	<div class="rotator" rotatorImg="" rotatorCSSImg=""             //
//  rotatorLink="" rotatorRedEyeTag="" rotatorTarget=""             //
//  rotatorMap="">&nbsp;</div>                                      //
// </div>                                                           //
//                                                                  //
// By default, the image path is:                                   //
// /groups/wcms_content/@wcms/documents/digitalassets/              //
//                                                                  //
// for other paths, just add the full path starting from /groups/   //
//                                                                  //
// -----------------------------------------------------------------//
var isBannerPaused	= false;
var lastRotated		= 1;
var rotator 		= new Array();
var rotatorAniID;

function setRotator() {
	if (!document.getElementsByTagName) return false;
	var items = document.getElementsByTagName("div");
	var rotatorHolder = 'rotatorHolderID';

	//start by grabbing the values we need from the html markup...
	for(var i=0; i < items.length; i++) {	
		if (items[i].className == "rotatorHolder") {	
			//add ID...
			items[i].setAttribute('id',rotatorHolder);
			//items[i].setAttribute('style','height:151px;overflow:hidden');
		}
	
		if (items[i].className == "rotator") {			
			if (!items[i].getAttribute('rotatorImg') || !items[i].getAttribute('rotatorCSSImg')) {
				errMsg += coMsgSeparator + 'ERROR: rotator tag is not complete';
				break;
			}
			
			//grab all the data into a data class...
			var rTemp = new function() {}
			rTemp.Img = items[i].getAttribute('rotatorImg').indexOf('/groups/') > -1?getStellentURL(items[i].getAttribute('rotatorImg')):coDefaultImgDir+items[i].getAttribute('rotatorImg');
			rTemp.CSSImg = items[i].getAttribute('rotatorCSSImg').indexOf('/groups/') > -1?getStellentURL(items[i].getAttribute('rotatorCSSImg')):coDefaultImgDir+items[i].getAttribute('rotatorCSSImg');
			rTemp.Link = items[i].getAttribute('rotatorLink')?items[i].getAttribute('rotatorLink'):'#';
			rTemp.Tag = items[i].getAttribute('rotatorRedEyeTag')?items[i].getAttribute('rotatorRedEyeTag'):null;
			rTemp.Target = items[i].getAttribute('rotatorTarget')?items[i].getAttribute('rotatorTarget'):'';
			rTemp.Map = items[i].getAttribute('rotatorMap')?(items[i].getAttribute('rotatorMap').indexOf('#')>-1?items[i].getAttribute('rotatorMap'):'#'+items[i].getAttribute('rotatorMap')):'';
			
			//assign pause code to any maps...
			if (rTemp.Map != '') {
				var m = rTemp.Map.replace('#','');
				if ($__(m)){
					$__(m).setAttribute('onMouseOver','isBannerPaused=true');
					$__(m).setAttribute('onMouseOut','isBannerPaused=false');
				}
			}
			
			rotator.push(rTemp);
		}
	}

	//only change the html and initiate the rotator if there's more than one banner...
	if (rotator.length > 1) {
		//create the holders and assign the first two values...
		var r1 = coRotatorObj.replace('{rid}','rotator1').replace('{aid}','rotator1_link').replace('{link}',rotator[0].Link).replace('{iid}','rotator1_img').replace('{img}',rotator[0].Img).replace('{style}','height:151px;');
		var r2 = coRotatorObj.replace('{rid}','rotator2').replace('{aid}','rotator2_link').replace('{link}',rotator[1].Link).replace('{iid}','rotator2_img').replace('{img}',rotator[1].Img).replace('{style}','height:0px;');

		//default setup (in case default image is not present in the markup)...
		$__(rotatorHolder).innerHTML = r1+r2;
		$__('np_main_links').style.backgroundImage = 'url(' + rotator[0].CSSImg + ')';
		
		//cache images...
		setRotator.cacheImg();
		
		setInterval("setRotator.rotate()",coRotateDelay);
	}
}

setRotator.cacheImg = function() {
	var coCacheID = 'rotatorCache';
	
	createElement(null,null,'div',coCacheID);
	$__(coCacheID).innerHTML = '';
	
	for (var i=0; i<rotator.length; i++) {
		createElement(coCacheID,false,'img',coCacheID + '_img_'+i);
		$__(coCacheID + '_img_'+i).src = rotator[i].Img;
		createElement(coCacheID,false,'img',coCacheID + '_cssimg_'+i);
		$__(coCacheID + '_cssimg_'+i).src = rotator[i].CSSImg;
	}
	
	$__(coCacheID).style.display = 'none';
}

setRotator.rotate = function() {
	if (isBannerPaused) { return; }
	slideDown('rotator2',760,151);
}

setRotator.end = function () {
	$__('np_main_links').style.backgroundImage = 'url(' + rotator[lastRotated].CSSImg + ')';
	setRotator.resetMarkup('rotator1');
	
	lastRotated++
	if (lastRotated > rotator.length-1) {
		lastRotated = 0;	
	}
	
	$__('rotator2').style.height = '0px';
	setRotator.resetMarkup('rotator2');
}

setRotator.resetMarkup = function(theID) {
	$__(theID + '_img').src = rotator[lastRotated].Img;
	$__(theID + '_img').useMap = rotator[lastRotated].Map;
	$__(theID + '_link').href = rotator[lastRotated].Link;
	$__(theID + '_link').target = rotator[lastRotated].Target;
	if (rotator[lastRotated].Tag) {
		$__(theID + '_link').setAttribute('onClick',"RedEyeTag('nourl=" + rotator[lastRotated].Tag + "')");
	}else{
		$__(theID + '_link').removeAttribute('onClick');
	}	
}

// ------------------------- setFlash v0.4 ------------------------ //
//                                                                  //
// Used to dynamically add a Flash movie via javascript.            //
// class="flashmovie". Params:                                      //
//                                                                  //
// flashSRC="<url to the file>"                                     //
// flashHeight="<height of flash movie>"                            //
// flashWidth="<width of flash movie>"                              //
// allowFullScreen="true" - v0.2                                    //
//                                                                  //
// v0.3:                                                            //
// flashVersionCheck="<number>"                                     //
// -----------------------------------------------------------------//
function setFlash() {
	if (!document.getElementsByTagName) return false;
	var items = document.getElementsByTagName("div");
	var theID = 0;
	var fVersion = getFlashVersion();
	var canRender  = true;

	for(var i=0; i < items.length; i++) {	
		if (items[i].className.match("flashmovie")) {			
			if (!items[i].getAttribute('flashSRC') || !items[i].getAttribute('flashHeight') || !items[i].getAttribute('flashWidth')) {
				errMsg += coMsgSeparator + 'ERROR: flash tag is not complete';
				break;
			}
			
			//add ID...
			items[i].setAttribute('id','___flash_ident_' + theID);
			theID ++;
			
			var allowFullScreen = "false";
			if (items[i].getAttribute('allowFullScreen') == "true") {	
				allowFullScreen = "true";
			}
			
			//check for minimum flash version to run...
			if (items[i].getAttribute('flashVersionCheck') && !items[i].getAttribute('flashVersionCheck').isNaN) {
				if (fVersion < items[i].getAttribute('flashVersionCheck') * 1) { //<<convert string to number.
					canRender = false;
				}
			}
			

			if (canRender) {
				//assign values to the flash parameters...
				var fObj = flashObj.replaceAll('{s}',items[i].getAttribute('flashSRC'));
				fObj = fObj.replaceAll('{w}',items[i].getAttribute('flashWidth'));
				fObj = fObj.replaceAll('{h}',items[i].getAttribute('flashHeight'));
				fObj = fObj.replaceAll('{id}',items[i].id+'_obj');
				fObj = fObj.replaceAll('{afs}',allowFullScreen);
			}else{
				//assign NON-flash content...
				var fObj = noFlash.replaceAll('{v}',items[i].getAttribute('flashVersionCheck'));	

			}
			
			$__(items[i].id).innerHTML = fObj;
		}


	}
}


// -------------------- renderTrackingTags v0.6 ------------------- //
//                                                                  //
// FOR DOUBLE CLICK: class="doubleclicktag"                         //
//                                                                  //
// tagLink="http://fls.uk.doubleclick.net/activityi" by default so  //
// isn't required unless it's different.                            //
//                                                                  //
// params: tagSRC="" tagType="" tagCat=""                           //
//                                                                  //
// FOR REDEYE: class="redeyetag" tagParam="ht_book=install" (eg)    //
// tagDomain="reporting.npower.com" by default so isn't required    //
// unless it's different. tagNoURL="true" to inject tagParam        //
// directly into the nourl param and override the document.location //
//                                                                  //
// tagParamPost="<something>" << for split queries that can come    //
// from a query string. (used in Quote & Switch)                    //
//                                                                  //
// tagNoQuery="true" - strip out the query string from nourl value. //
//                                                                  //
// -----------------------------------------------------------------//
function renderTrackingTags() {
	if (!document.getElementsByTagName) return false;
	var items = document.getElementsByTagName("div");
	var server = getServer();
	var canRender = (server == 'DEV' || server == 'TEST_CONSUMPTION' || server == 'LIVE_CONSUMPTION')?true:false;
	var hasTag = false;
	var theID = 0;

	for(var i=0; i < items.length; i++) {		
		//DOUBLE CLICK...
		if (items[i].className == "doubleclicktag") {
			var tLink;
			if (items[i].getAttribute('tagLink')) {
				tLink = items[i].getAttribute('tagLink');
			}else{
				tLink = 'http://fls.uk.doubleclick.net/activityi';
			}
			
			//set the ID...
			items[i].setAttribute('id','___doubleclicktag_ident_' + theID);
			
			if (!items[i].getAttribute('tagSRC') || !items[i].getAttribute('tagType') || !items[i].getAttribute('tagCat')) {
				errMsg += coMsgSeparator + 'ERROR: DoubleClick tag is not complete';
				canRender = false;
			}
			
			//standard DoubleClick script...
			var axel = Math.random()+"";
			var a = axel * 10000000000000;
			if (canRender) {
				$__(items[i].id).innerHTML = '<iframe frameborder="0" height="1" src="' + tLink + ';src=' + items[i].getAttribute('tagSRC') + ';type=' + items[i].getAttribute('tagType') + ';cat=' + items[i].getAttribute('tagCat') + ';ord=1;num='+ a + '?" width="1"></iframe>';
				items[i].setAttribute('success','true');
			}else{
				items[i].setAttribute('success','false');
			}
			
			hasTag = true;
			theID++;
		}
		
		//REDEYE...
		if (items[i].className == "redeyetag") {
			var tDomain;
			if (items[i].getAttribute('tagDomain')) {
				tDomain = items[i].getAttribute('tagDomain');
			}else{
				tDomain = 'reporting.npower.com';
			}
			
			//set the ID...
			items[i].setAttribute('id','___redeyetag_ident_' + theID);
			
			if (!items[i].getAttribute('tagParam')) {
				errMsg += coMsgSeparator + 'ERROR: RedEye tag is missing valid "tagParam".';
				canRender = false;
			}
			
			
			if (canRender) {
				var RedEyeTag = new Image();
				var redeyedomain = tDomain;

				var nourlvalue;
				
				if (items[i].getAttribute('tagNoQuery')) {
					var x = window.location.toString();
					var qPoint = x.indexOf('?');
					nourlvalue = escape(x.substring(0, qPoint));
				}else{
					nourlvalue = escape(window.location);
				}

				nourlvalue = nourlvalue.replace(".aspx","");
				var tag = new Object();
				var tagPrefix = document.location.href.indexOf('https://') > 1?'https://':'http://';
				var theParam;
				
				//look for a query string...
				if (items[i].getAttribute('tagParamPost')) {
					var hasQueryString = document.URL.indexOf('=');
					var qFrom = "";


					if (hasQueryString > -1) {
						qFrom = document.URL.substring(hasQueryString + 1, document.URL.length) + "_";
					}
					theParam = items[i].getAttribute('tagParam') + qFrom + items[i].getAttribute('tagParamPost');
				}else{
					theParam = items[i].getAttribute('tagParam');
				}
				
				if (!items[i].getAttribute('tagNoURL')) {
					tag = tagPrefix + redeyedomain + '/cgi-bin/rr.cgi/images/blank.gif?nourl=' + nourlvalue;
					tag += '&' + theParam;
					tag += '&norefer=' + escape(document.referrer);
				}else{
					tag = tagPrefix + redeyedomain + '/cgi-bin/rr.cgi/images/blank.gif?nourl=' + theParam;
					tag += '&norefer=' + escape(document.referrer);					
				}
				tag = tag.toLowerCase();
				RedEyeTag.src = tag;
				items[i].setAttribute('success',RedEyeTag.src);
			}else{
				items[i].setAttribute('success','false');
			}
			
			theID++;
		}
	}
	
	if (!canRender && hasTag) {
		errMsg += coMsgSeparator + 'DoubleClick and RedEye tags will only be rendered on\nconsumption or dev servers.';
		return;
	}
}


// -------------------------- setTNC v0.3 ------------------------- //
//                                                                  //
//  v0.2 added showTNC()                                            //
//  v0.3 amended so pages that have #tnc will open it by default    //
// -----------------------------------------------------------------//
function setTNC() {
	if (!document.getElementsByTagName) return false;
	var items;
	var theID = 0;
	var tncID = null;

	for (j=0;j<2;j++){
		if (j==0) {
			items = document.getElementsByTagName("div");
		}else if (j==1) {
			items = document.getElementsByTagName("h4");
		}
		for(var i=0; i < items.length; i++) {		
			//get the target ID...
			if (items[i].className == "tnc" && j==0) {
				//add ID...
				items[i].setAttribute('id','___tnc_ident_' + theID);
				tncID = '___tnc_ident_' + theID;
				theID ++;
				
				lastTNCID[0] = tncID;
				
				//check for #tnc in the URL. If it's there, don't hide
				//the content by default...
				var theLoc = location.href.toLowerCase();
				if (theLoc.indexOf("#tnc") == -1) {
					//hide the content by default...
					items[i].style.display = 'none';
				}
			}
			
			//create the link to reveal the tncs...
			if (items[i].className.match("tnc") && j==1) {
				//add id?
				if (!items[i].id) {
					items[i].setAttribute('id','___link_ident_' + theID);
				}
				
				lastTNCID[1] = '___link_ident_' + theID;

				theID ++;

				$__(items[i].id).setAttribute('revealerSwapID',tncID);
				$__(items[i].id).onmouseup = function(){ reveal(this.getAttribute('id'),this.getAttribute('revealerSwapID'),null,null,true);return false; }
			}
		}
	}
}
function showTNC(checkQuery) {
    //for adding to onclick events in markup to reveal the tnc...
	reveal(lastTNCID[1],lastTNCID[0],null,null,true);
}

// ----------------------- setRevealer v0.8 ----------------------- //
//                                                                  //
//  Will reveal a container from either an a tag, span, div or img. //
//                                                                  //
//  To use, add class="revealer" to the calling element and         //
//  revealID="the_id" which is the ID of the container you wish     //
//  to reveal.                                                      //
//                                                                  //

//  Additionally, you may use revealerAutoClose="false" if you don't //
//  want the last panel to close when the next one is opened.        //
//  revealerWide="true" for refresh-width revealer or               //
//  revealerSuperWide="true" for full-width LP size.                //
//                                                                  //
//  v0.6: revealerPlain="true" if you don't want a shadowed box     //
//  v0.7: revealerDefault="true" to open  a box by default          //
//  v0.8: revealerFullClick="false" to not click the entire bar     //
//  v0.8: revealerTooltip="<the tip>" for custom tooltip            //
//                                                                  //
// -----------------------------------------------------------------//
var lastOpenedBox = '';
var lastImgSwap = new Array();

function setRevealer() {
	if (!document.getElementsByTagName) return false;
	var items;
	var theID = 0;
	var theBoxID = 0;
	var parentID;
	var revealID;
	var revCount = 0;
	var lastRevealer = 0;
	var isWide = '';
	var isPlain = false;
	var DefaultBox = null;
	var DefaultValues = new Array();
	var FullClickValues = new Array();
	var Tooltip = null;
	var FullClick = true;
	
	//preload 2nd state images...
	var img1 = new Image();
	img1.src = coRevTopSwap;
	var img2 = new Image();
	img2.src = coRevBtnSwap;
	var img3 = new Image();
	img3.src = coRevTopSwapWide;
	var img4 = new Image();
	img4.src = coRevTopSwapSuperWide;

	for (j=0;j<4;j++){
		if (j==0) {
			items = document.getElementsByTagName("a");
		}else if (j==1) {
			items = document.getElementsByTagName("span");
		}else if (j==2) {
			items = document.getElementsByTagName("div");
		}else if (j==3) {
			items = document.getElementsByTagName("img");
		}
		for(var i=0; i < items.length; i++) {
			if (items[i].className.match("revealer")) {
				//defaults
				isPlain = false;
				Tooltip = null;
				FullClick = true;
				
				//add id?
				if (!items[i].id) {
					items[i].setAttribute('id','___revealer_ident_' + theBoxID);


				}
				
				if (theBoxID > 0) {
					items[i].style.marginTop = '-5px';
				}

				if (theBoxID == revCount && revCount > 0) {
					items[i].style.marginBottom = '10px';
				}
				
				if (items[i].getAttribute('revealerWide')) {
					isWide = 'wide';
				}
				
				if (items[i].getAttribute('revealerSuperWide')) {
					isWide = 'superwide';
				}
				
				if (items[i].getAttribute('revealerPlain')) {
					isPlain = true;
				}
				
				if (items[i].getAttribute('revealerDefault')) {
					DefaultBox = items[i].id;
				}
				
				if (items[i].getAttribute('revealerTooltip')) {
					Tooltip = items[i].getAttribute('revealerTooltip');
				}
				
				if (items[i].getAttribute('revealerFullClick')) {
					FullClick = getBool(items[i].getAttribute('revealerFullClick'));
				}
				
				parentID = items[i].id;
				theBoxID++;
				lastRevealer = i;
			}
			
			//create the +/- button...
			if (items[i].className.match("revealHeading")) {
				//add id?
				if (!items[i].id) {
					items[i].setAttribute('id','___button_ident_' + theID);
					items[i].setAttribute('revealID','___target_ident_' + theID);
					revealID = '___target_ident_' + theID;
				}

				theID ++;
				
				//create the button...
				createElement(items[i].id,false,'img',items[i].id + '_button');
				$__(items[i].id + '_button').className = "revealButton";
				$__(items[i].id + '_button').src = coRevBtnNorm;
				$__(items[i].id + '_button').setAttribute('revealerSwapID',items[i].getAttribute('revealID'));
				$__(items[i].id + '_button').setAttribute('revealerAutoClose',items[i].getAttribute('revealerAutoClose'));
				$__(items[i].id + '_button').setAttribute('revealerParent',parentID);
				$__(items[i].id + '_button').setAttribute('revealerPlain',isPlain);
				if (Tooltip) {
					$__(items[i].id + '_button').setAttribute('revealerTooltip',Tooltip);
				}
				

				$__(items[i].id + '_button').onclick = function(){ reveal(this.getAttribute('id'),this.getAttribute('revealerSwapID'),this.getAttribute('revealerParent'),this.getAttribute('revealerAutoClose'),false,isWide,this.getAttribute('revealerPlain'));return false; }
								
				
				//far the auto-open code...
				if (DefaultBox == parentID) {
					DefaultValues[0] = items[i].id + '_button';
					DefaultValues[1] = items[i].getAttribute('revealID');
					DefaultValues[2] = parentID;
					DefaultValues[3] = items[i].getAttribute('revealerAutoClose');
				}
				
				//for the full-click option...
				FullClickValues[0] = items[i].id + '_button';
				FullClickValues[1] = items[i].getAttribute('revealID');
				FullClickValues[2] = parentID;
				FullClickValues[3] = items[i].getAttribute('revealerAutoClose');
			}
			
			//set source id's...
			if (items[i].className.match("source")) {
				//add id?
				if (!items[i].id) {
					items[i].setAttribute('id','___source_ident_' + theID);
				}
				
				//click the entire bar?
				if (FullClick) {
					items[i].setAttribute('revealerBtnID',FullClickValues[0]);
					items[i].setAttribute('revealerSwapID',FullClickValues[1]);
					items[i].setAttribute('revealerParent',FullClickValues[2]);
					items[i].setAttribute('revealerAutoClose',FullClickValues[3]);			
					items[i].onmouseup = function(){ reveal(this.getAttribute('revealerBtnID'),this.getAttribute('revealerSwapID'),this.getAttribute('revealerParent'),this.getAttribute('revealerAutoClose'),false,isWide,isPlain);return false; }								
				}

				//theID ++;
			}
			
			//create the bottom image for the curved bottom...
			if (items[i].className.match("target")) {
				//add id?
				if (!items[i].id) {
					items[i].setAttribute('id',revealID);
				}
				
				if (isPlain) {
					$__(items[i].id).style.background = 'none';
					$__(items[i].id).style.padding = '0px';
					$__(items[i].id).style.width = '100%';
				}else{
					createElement(items[i].id,null,'div',items[i].id + '_bottom');
					$__(items[i].id + '_bottom').className = "revealBottom";
				}
				
				//theID ++;
				
				//hide the target container...
				items[i].style.display = 'none';
			}
		}
	}
	
	//open a box by default?
	if (DefaultBox != null ) {
		reveal(DefaultValues[0],DefaultValues[1],DefaultValues[2],DefaultValues[3],false,isWide,isPlain,true);
	}
}

function reveal(btnID,swapID,parentID,isAutoClose,isTNC,isWide,isPlain,isDefault) {
	isAutoClose = false; //force to fix a bug.
	
	//check in case we need to stop any playing SWF files before opening the next box...
	resetSWF('___flash_ident_' + lastOpenedBox.substring(lastOpenedBox.lastIndexOf("_")+1) + '_obj');
	
	if ($__(swapID).style.display != 'block') {
		//open...
		$__(swapID).style.display = 'block';
		if (lastOpenedBox && (lastOpenedBox != swapID) && !isAutoClose && !isTNC) {
			$__(lastOpenedBox).style.display = 'none';
			setImage(lastImgSwap[0],swapID,parentID,false,isTNC,isWide,isPlain);
		}
		
		if (!isAutoClose && !isTNC) {
			lastOpenedBox = swapID;
			lastImgSwap[0] = btnID;
		}
		setImage(btnID,swapID,parentID,true,isTNC,isWide,isPlain);
		
		if (!isDefault) {
			//go to the box's anchor point and reset the title...
			document.location.href = '#' + parentID;
			document.title = dTitle;

		}
	}else{
		//close...
		$__(swapID).style.display = 'none';
		setImage(btnID,swapID,parentID,false,isTNC,isWide,isPlain);
	}
}

function setImage(btnID,swapID,parentID,isSwap,isTNC,isWide,isPlain) {
	var RevNorm = coRevTopNorm;
	var RevSwap = getBool(isPlain)?coRevTopNorm:coRevTopSwap;
	var BtnSwap = getBool(isPlain)?coRevBtnSwapClean:coRevBtnSwap;
	
	if (isWide == 'wide'){
		RevNorm = coRevTopNormWide;
		RevSwap = getBool(isPlain)?coRevTopNormWide:coRevTopSwapWide;
	}else if (isWide == 'superwide'){
		RevNorm = coRevTopNormSuperWide;
		RevSwap = getBool(isPlain)?coRevTopNormSuperWide:coRevTopSwapSuperWide;
	}
	
	if (isTNC) { return; }
	
	if (isSwap) {
		$__(btnID).src = BtnSwap;
		$__(parentID).style.background = 'url(' + RevSwap + ') no-repeat';
	}else{
		$__(btnID).src = coRevBtnNorm;
		$__(parentID).style.background = 'url(' + RevNorm + ') no-repeat';
	}
}




// -------------------------- clean9003 --------------------------- //
//                                                                  //
// Removes the 9003# from Stellent links for quick testing of pages //
// though the XML will still need to be downloaded and edited by    //
// hand before it goes to production!                               //
//                                                                  //
// -----------------------------------------------------------------//
function clean9003() {
    if (!document.getElementsByTagName) return false;
    var items = document.getElementsByTagName("a");
    var found = 0;
    var server = getServer();

    for(var i=0; i < items.length; i++) {
        if (items[i].getAttribute('href') && items[i].getAttribute('href').indexOf('9003#') > -1) {  
            items[i].setAttribute('href',items[i].getAttribute('href').replace(/9003#/,"#"));
            found ++;
		}
    }

    if (found > 0 && server != 'TEST_CONSUMPTION' && server != 'LIVE_CONSUMPTION') {
        var theInstance;
        if (found == 1) {
            theInstance = 'instance';
        }else{
            theInstance = 'instances';
        }
        errMsg += coMsgSeparator + 'WARNING!! This page contains [' + found + '] ' + theInstance + ' of 9003# links.\n\nThese have been removed for testing purposes but please\nremove them from the XML before putting this page live!\n\nThis message will not appear on consumption servers.';
    }
}



// ------------------------- TOOLTIP v0.5 ------------------------- //
//                                                                  //
//          (C) 2009 Mark O'Neill - designedby@iikon.co.uk          //
//                                                                  //
//  Free for use. Directions: To use this function simply put the   //
//  following class into either a div, span, a or img element:      //
//                                                                  //
//        class="tooltip"                                           //
//                                                                  //
//  You will also need to place the tooltip text like this:         //
//                                                                  //
//        tooltip="This is my tooltip"                              //
//                                                                  //
//  Examples:                                                       //
//                                                                  //
//  <a href="test.html" class="tooltip" tooltip="Click this now!">  //
//  <img src="test.gif" class="tooltip" tooltip="Nice image..."/>   //
//                                                                  //
//  If you DON'T want the tooltip underlined, (text items only)     //
//  add the following to the element:                               //
//                                                                  //
//        tooltipUnderline="false"                                  //
//                                                                  //
//  Also, if you'd like the underline to be 2px instead of 1px:     //
//                                                                  //
//        tooltipUnderline="thick"                                  //
//                                                                  //
//  You can add a heading to the tooltip too by doing:              //
//                                                                  //
//        tooltipHeading="My Heading"                               //
//                                                                  //
//  IMPORTANT: If there is another window.onload event  in your     //
//  document, remove the window.onload function from here and       //
//  place the setTooltips() function into the common                //
//  window.onload event.                                            //
// -----------------------------------------------------------------//

//tooltip setup...
var coTooltipWindow = 'tooltip_window';
var coBoxWidth  	= 300;
var coBackColor 	= '#fff9ce';
var coForeColor 	= '#60563f';
var coUnderline 	= '#916e1a';
var coBodyPadding  	= '10px';
var coHeadingStyle 	= 'background-color:'+coForeColor+';color:'+coBackColor+';height:20px;padding:5px 10px 0px 10px;font-size:12px;font-weight:bold;';

//other vars...
var IE = document.all?true:false;
var mouseX = 0;
var mouseY = 0;



function showTooltip(tBody,tHead,tPos) {
	if (tBody) {
		var tRender;
		if (tHead) {
			tRender = "<div style='" + coHeadingStyle + "'>" + tHead + "</div><div style='padding:" + coBodyPadding + ";'>" + tBody + "</div>";
		}else{
			tRender = "<div style='padding:" + coBodyPadding + ";'>" + tBody + "</div>";
		}
		$__(coTooltipWindow).innerHTML = tRender;
		
		//top...
		if (tPos == coToolPosLeft) {
			$__(coTooltipWindow).style.top = mouseY-$__(coTooltipWindow).offsetHeight + 'px';
		}else if (eval(mouseY+10+$__(coTooltipWindow).offsetHeight) >= $Height() || tPos == coToolPosTop) {
			$__(coTooltipWindow).style.top = mouseY-$__(coTooltipWindow).offsetHeight-10 + 'px';
		}else{
			$__(coTooltipWindow).style.top = mouseY+10 + 'px';
		}
		
		//left...
		if (tPos == coToolPosLeft) {
			$__(coTooltipWindow).style.left = mouseX-coBoxWidth-16 + 'px';
		}else if (eval(mouseX+16+coBoxWidth) >= $Width() || tPos == coToolPosTop) {
			$__(coTooltipWindow).style.left = mouseX-coBoxWidth-16 + 'px';
		}else{
			$__(coTooltipWindow).style.left = mouseX+16 + 'px';
		}
		$__(coTooltipWindow).style.visibility = 'visible';
	}else{
		$__(coTooltipWindow).style.visibility = 'hidden';
	}
}

function setTooltips(){
	captureMouse();
	
	if (!document.getElementsByTagName) return false;
	var items;
	var isText;
	var isLink;
	var theID = 0;

	for (j=0;j<5;j++){
		if (j==0) {
			items = document.getElementsByTagName("a");
			isLink = true;
			isText = true;
		}else if (j==1) {
			items = document.getElementsByTagName("span");
			isLink = false;
			isText = true;
		}else if (j==2) {
			items = document.getElementsByTagName("div");
			isLink = false;
			isText = true;
		}else if (j==3) {
			items = document.getElementsByTagName("img");
			isLink = false;
			isText = false;
		}else if (j==4) {
			items = document.getElementsByTagName("h4");
			isLink = false;
			isText = true;
		}
		for(var i=0; i < items.length; i++) {
			if (items[i].className.match("tooltip")) {
				items[i].onmouseover = function(){ showTooltip(this.getAttribute('tooltip'),this.getAttribute('tooltipHeading'));return false; }
				items[i].onmouseout = function(){ showTooltip();return false; }
				
				//add id?
				if (!items[i].id) {
					items[i].setAttribute('id','___tooltip_ident_' + theID);
				}
				theID ++;
				
				//underline the tooltip?
				if (isText && items[i].id && items[i].getAttribute('tooltipUnderline') != 'false') {
					if (items[i].getAttribute('tooltipUnderline') == "thick") {
						$__(items[i].id).style.borderBottom="2px dashed " + coUnderline;
					}else{
						$__(items[i].id).style.borderBottom="1px dashed " + coUnderline;
					}
					
					if (!isLink) {
						$__(items[i].id).style.cursor = "default";
					}
				}
				
				//clear alt/title...
				if (items[i].getAttribute('alt')) { items[i].setAttribute('alt','');}
				if (items[i].getAttribute('title')) { items[i].setAttribute('title','');}
			}else if (items[i].className.match("revealButton")) {
				if (items[i].getAttribute('revealerTooltip')) {
					items[i].onmouseover = function(){ showTooltip(this.getAttribute('revealerTooltip'),'',coToolPosLeft);return false; }
				}else{
					items[i].onmouseover = function(){ showTooltip(coRevTipNorm,'',coToolPosLeft);return false; }
				}
				items[i].onmouseout = function(){ showTooltip();return false; }
			}else if (items[i].className == "tnc" && j==4) {
				items[i].onmouseover = function(){ showTooltip(coTNCTip);return false; }
				items[i].onmouseout = function(){ showTooltip();return false; }
			}
		}
	}

	createElement(null,null,'div',coTooltipWindow,'hidden','absolute',coBoxWidth + 'px',null,'visible',coBackColor,null,'verdana','12px',coForeColor,'1px solid ' + coForeColor);
	changeOpacity(90,coTooltipWindow);
}

function createElement(theParent,isInsert,theElement,theID,theVisibility,thePosition,w,h,theOverflow,theBackground,thePadding,theFontFamily,theFontSize,theFontColor,theBorder) {
	var newElement = document.createElement(theElement);
	newElement.setAttribute('id', theID);
	
	//assign styles...
	if (theVisibility) 	{ newElement.style.visibility = theVisibility; }
	if (thePosition) 	{ newElement.style.position = thePosition; }
	if (w) 				{ newElement.style.width = w; }
	if (h) 				{ newElement.style.height = h; }
	if (theOverflow) 	{ newElement.style.overflow = theOverflow; }
	if (theBackground) 	{ newElement.style.background = theBackground; }
	if (thePadding) 	{ newElement.style.padding = thePadding; }
	if (theFontFamily) 	{ newElement.style.fontFamily = theFontFamily; }
	if (theFontSize) 	{ newElement.style.fontSize = theFontSize; }
	if (theFontColor) 	{ newElement.style.color = theFontColor; }
	if (theBorder) 		{ newElement.style.border = theBorder; }
	
	newElement.style.display = "block";
	if (!theParent) {
		newElement.innerHTML=coTooltipWindow;
	}
	if (theParent) {
		if (isInsert){
			$__(theParent).insertBefore(newElement,null);
		}else{
			$__(theParent).appendChild(newElement);
		}
	}else{
		document.body.appendChild(newElement);
	}
}

function captureMouse() {
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = getMouseXY;
}

function getStyle(el,styleProp)
{
	if (!el) { return null; }
	
	var x = $__(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function getMouseXY(e) {
	if (IE) {
		mouseX = event.clientX + document.documentElement.scrollLeft;
		mouseY = event.clientY + document.documentElement.scrollTop;
  	}else { 
    	mouseX = e.pageX;
    	mouseY = e.pageY;
  	}  

  	if (mouseX < 0){mouseX = 0;}
  	if (mouseY < 0){mouseY = 0;}
}

function changeOpacity(opacity, theID) {
    var object = document.getElementById(theID).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

// ------------------------ launch_popup ------------------------ //
//                                                                //
//                         MON 30/04/2009                         //
//                                                                //
// Directions: To use this function simply put the following      //
// class into your <a> link:                                      //
//                                                                //
//                      class="launch_popup"                      //
//                                                                //
// There are parameters which you can access by placing the       //
// following in the <a> tag:                                      //
//                                                                //
//       popupWidth="<number>"  - specify a width                 //
//       popupHeight="<number>" - specify a height                //
//       popupScrollbars="true" - specify if it has scrollbars    //
//                                                                //
// Additionally, if you would like the popup to open a DIFFERENT  //
// URL to the href URL simply place the URL in:                   //
//                                                                //
//       rel="url-to-different-page"                              //
//                                                                //
// The following example, by default will open an accessible      //
// version of a page if JavaScript is turned off, or a javascript //
// version if JavaScript is enabled. It also has a width of 770px //
//                                                                //
// <a href="accessible.html" rel="not-accessible.html" class="launch_popup" popupWidth="770"> //
//                                                                //
// ---------------------------------------------------------------//

function setPopup() {
  if (!document.getElementsByTagName) return false;
  var links=document.getElementsByTagName("a");
  var theRel;
  var theLink;
  
    for (var i=0; i < links.length; i++) {
        if (links[i].className.match("launch_popup")) {
            if (links[i].rel) {
                    links[i].onclick=function() {
                    showPlatform(this.getAttribute("rel"),this.getAttribute("popupWidth"),this.getAttribute("popupHeight"),this.getAttribute("popupScrollbars"));
                    return false;
                }
            }else{
                    links[i].onclick=function() {
                    showPlatform(this.getAttribute("href"),this.getAttribute("popupWidth"),this.getAttribute("popupHeight"),this.getAttribute("popupScrollbars"));
                    return false;
                }
            }
        }
    }
}


//launches the popup window size correctly in different browsers...
function showPlatform(theURL,theWidth,theHeight,theScroll) {
	var theArgs;
	var theBrowser = getBrowser();
	var w = 940;
	var h = 650;
	var scroll = '';
	
	//check if values are present...
	if (parseInt(theWidth) > 0) {
	    w = theWidth;
	}
	if (parseInt(theHeight) > 0) {
	    h = theHeight;
	}
	if (theScroll == 'true') {
	    scroll = ',scrollbars';
	}

	if (theBrowser == 'msie') {
		//IE
		theArgs = 'width=' + eval(w-2) + ',height=' + eval(h-4);
	}else if (theBrowser == 'mozilla') {
		//firefox
		theArgs = 'width=' + w + ',height=' + h;
	}else if (theBrowser == 'safari') {
		//safari
		theArgs = 'width=' + w + ',height=' + h;
	}else{
		//others...
		theArgs = 'width=' + w + ',height=' + h;
	}

    //center the window...
    var l = (screen.width/2)-(w/2);
    var t = (screen.height/2)-(h/2);

	theArgs = theArgs + scroll + ',left=' + l + ',top=' + t;

	window.open(theURL,'sm',theArgs);
}

function getBrowser(){
	var ua = navigator.userAgent.toLowerCase();
	var browserName;
	
	if (ua.indexOf('opera') != -1) {
		browserName = 'opera';
	}else if (ua.indexOf('msie') != -1) {
		browserName = 'msie';
	}else if (ua.indexOf('safari') != -1) {
		browserName = 'safari';
	}else if (ua.indexOf('mozilla') != -1) {
		browserName = 'mozilla';
	}
	
	return browserName;
	
}

// MON: 16/04/2009
//
// --------------------------------   NOTES   --------------------------------
// THIS FILE REPLACES DYNAMIC NUMBER AND POPUP JS FILES
//
// Any new code that requires an OnLoad event should go in this file
// ---------------------------------------------------------------------------


function doPopup() {
if (!document.getElementsByTagName) return false;
	var links=document.getElementsByTagName("a");
	
	for (var i=0; i < links.length; i++) {
	
		if (links[i].className.match("popup")) {
			links[i].onclick=function() {
				window.open(this.href, "", "width=776,height=600,scrollbars,resizable,status"); return false;
			}
		}
		if (links[i].className.match("popup2")) {
			links[i].onclick=function() {
				window.open(this.href, "", "width=776,height=460,scrollbars,resizable,status"); return false;
			}
		}
		
		//MON: 09/07/2008 - for video popup window (320x240 + flash control)
		if (links[i].className.match("popup_video")) {
			links[i].onclick=function() {
			window.open(this.href, "", "width=320,height=280"); return false;
			}
		}
		
		//MON: 16/07/2008 - no scrollbars thin window
		if (links[i].className.match("popup_thin")) {
			links[i].onclick=function() {
			window.open(this.href, "", "width=800,height=460"); return false;
			}
		}
		
		//Ben: 04/11/2008 - used for an image on the keven miles page
		if (links[i].className.match("popup_image")) {
			links[i].onclick=function() {
			window.open(this.href, "", "width=720,height=410"); return false;
			}
		}
		
		//BEN: 16/04/2009 - solar brochure request (273x435 and centered)
		if (links[i].className.match("popup_sbr")) {
			var w = 273;
			var h = 435;
			var l = (screen.width/2)-(w/2);
			var t = (screen.height/2)-(h/2);
			links[i].onclick=function() {
			window.open(this.href, "", "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ",resizable,status"); return false;
			}
		}
		
		//TUE: 05/08/2008 - for HTW videos (512x329 + flash control)
		if (links[i].className.match("popup_htw")) {
			links[i].onclick=function() {
			window.open(this.href, "", "width=512,height=329"); return false;
			}
		}
		
		//ROB: 25/11/2008 - education videos (600x375 inc. flash control)
		if (links[i].className.match("popup_education")) {
			links[i].onclick=function() {
			window.open(this.href, "", "width=600,height=375"); return false;
			}
		}
		
		//MON: 11/03/2009 - innit
		if (links[i].className.match("popup_howto")) {
			var w = 506;
			var h = 350;
			var l = (screen.width/2)-(w/2);
			var t = (screen.height/2)-(h/2);
			links[i].onclick=function() {
				window.open(this.href, "", "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ",resizable,status"); return false;
			}
		}
	}
}




// MON: 24/09/2008
//
// --------------------------------   NOTES   --------------------------------
// To get a number from the query string, use a query string like this:
//                
// http://www.npower.com/index.html?t=123
//                
// ...then use class="getNum" on any div or span to replace the contents of that tag with 123 - in this instance.
//                
// You can also use html spaces (%20) in the number if you want spaces. For example:
//                
// http://www.npower.com/index.html?t=0800%20123%20123
//                
// The class="getFree" will replace the contents of the tag with "Call us FREE on:" if f=true, so:
//
// http://www.npower.com/index.html?t=0800%20123%20123&f=true
//
//
//
// Amended 03/03/2009 by Adam Dalziel:
//
// Numbers are validated against a specific set of numbers (i.e. HES or Residential numbers) based on
// the span tag with class attribute set to "DynamicNumber_xxx", where xxx is, for example, "HES" or
// "Residential".  If no such span tag is found, the default HES numbers are used for backwards
// compatibility.
//
// MON - 15/12/2009
// UNHIDE:
// 
// adding class="unhide" and unhideNumber="<the number>" to a div or span will
// reveal that div or span if the number is a match.
//
// ---------------------------------------------------------------------------

function DynamicNumber()
{
}

//remove the ? from the beginning of the query and split it into a=1 var pairs...
DynamicNumber.TheQuery = location.search.substring(1);

//for SEO reasons - for spoof query strings that begin with a # instead of a ?...
if (!DynamicNumber.TheQuery && location.href.indexOf("#") > -1) {
	var lPos = location.href.lastIndexOf("#") > location.href.indexOf("#")?location.href.lastIndexOf("#"):location.href.length; //in case there's a REAL # anchor at the end!
	DynamicNumber.TheQuery = location.href.substring(location.href.indexOf("#")+1,lPos);
}

DynamicNumber.TheVars = DynamicNumber.TheQuery.split("&");

DynamicNumber.ValidNumbers = new Array();
DynamicNumber.ValidNumbers["Residential"] = new Array(
    "08009759300", "08009759301", "08009759302", "08009759303", "08009759304",
    "08009759305", "08009805520");
//DynamicNumber.ValidNumbers["Business"] = new Array();
DynamicNumber.ValidNumbers["Green"] = new Array("08009753199");


DynamicNumber.ValidNumbers["HES"] = new Array(
    "08009805761", "08009805762", "08009805763", "08009805764", "08009805765",
    "08009805766", "08009805767", "08009805768", "08009805769", "08009805770",
    "08009805880", "08009805881", "08009805882", "08009805883", "08009805884",
    "08009805885", "08009805886", "08009805887", "08001070479", "08001079318",
    "08001079328", "08001079329", "08001386253", "08001386274", "08002940880",
    "08003160071", "08003160554", "08003166728", "08003167264", "08003167267",
    "08001070398", "08001079322", "08001079324", "08001079325", "08001973921",
    "08001973928", "08001973930", "08002940876", "08002940878", "08002944981",
    "08002944982", "08003160344", "08003160603", "08003167270", "08009157713",
    "08009157771", "08009157718", "08009802142", "08009802143", "08000728606",
    "08001070396", "08009805888", "08009805889", "08000727609", "08000727610",
    "08009802120", "08009802121", "08009802122", "08009802124", "08009802125",
    "08009802126", "08009802128", "08009751372", "08002941655", "08009803644",
    "08009803645", "08009803646", "08009803647", "08009803639", "08009803640",
    "08009803641", "08009803642", "08009803643", "08009803650",
	//Added as per BAU498 - 26/06/09 - B.K
	"08000727610", "08001382650", "08001973922", "08002944980", "08009759338",
	"08000480513", "08000480517", "08000480518", "08000480519", "08000480526",
	"08000480528", "08000480534", "08000480549", "08000723462", "08001070233",
	"08001070359", "08001079317", "08001386252", "08001973923", "08001973929",
	"08001973954", "08002944987", "08003166725", "08003167263", "08003167268",
	"08009151586", "08009751359", "08009751365", "08009751403", "08009751405",
	"08009751406", "08009751407", "08009751418", "08009751419", "08009751420",
	"08009754791", "08009754795", "08009759311", "08009759312", "08009759313",
	"08009805515", "08009805516", "08001070396", "08001386253", "08001386274",
	"08001973930", "08002940873", "08002940876", "08002940878", "08002940880",
	"08002944981", "08002944982", "08003160071", "08003160344", "08009751372",
	"08009759314", "08009759321", "08009802120", "08009802124", "08009802125",
	"08009803644", "08009803645", "08009803646", "08009803647", "08009803648",
	"08009803649", "08009803650", "08009803651", "08009805513", "08009805517",
	"08009805767", "08009805768", "08009805769", "08009805770", "08009805880",
	"08009805881", "08009805888", "08000728606", "08003160554", "08003160603",
	"08003166728", "08003167264", "08003167267", "08003167270", "08009157713",
	"08009157718", "08009157771", "08009759337", "08009802121", "08009802128",
	"08009802139", "08009802142", "08009803639", "08009803640", "08009805514",
	"08009805518", "08009805882", "08009805883", "08009805884", "08009805885",
	"08009805886", "08009805887", "08009805889", "08009802126", "08009803641",
	"08009803642", "08009803643", "08009805519", "08000727609", "08001070398",
	"08001070479", "08001079318", "08001079322", "08001079324", "08001079325",
	"08001079326", "08001079328", "08001079329", "08001973921", "08001973928",
	"08002941655", "08009802122", "08009802143", "08009805761", "08009805762",
	"08009805763", "08009805764", "08009805765", "08009805766",
	//Added - 06/08/09 - B.K
	"08000481509", "08000481510", "08000481511", "08000481512", "08000481513", 
	"08000481514", "08000481515", "08000481516",
	//Added - 27/08/09 - B.K, these are used for campaign code changes.
	"renewables",
	//Added - 21/09/09 - B.K, used on the carbon monoxide page, bau735.
	"08450782931",
	//Added - 15/12/2009 - MON, 150Free page
	"08009753189",
	//Added - 21/12/2009 - BEN BAU765
	"08009803639", "08009803640", "08009803641", "08009803642", "08009803643",
	"08009803647", "08009803648", "08009803649", "08009803651", "08009805515",
	"08009805516", "08009805761", "08009805762", "08009802143", "08000727603",
	"08009805763", "08009805764", "08009805765", "08009805766", "08001070479",
	"08001079318", "08001079328", "08001079329", "08003167264", "08009751361",
	//Added - 21/12/2009 - BEN BAU774
	"08009759314", "08009759312", "08009802139", "08009754791", "08009754795",
	"08009759311", "08009759313", "08000480526", "08000480534",
	//Added - 21/01/2010 - MON 
	"08000724999");



DynamicNumber.Initialise = function()
{
	if (!document.getElementsByTagName)
	    return false;

	//assign the values to each valid div...
	DynamicNumber.SetContent("div");
	
	//now assign the values to each valid span...
	DynamicNumber.SetContent("span");

	//now set the location for the anchor tag
	DynamicNumber.SetAnchor();
}

DynamicNumber.GetParam = function(id)
{
	var thePairs;
	for (var i = 0; i < DynamicNumber.TheVars.length; i++)
	{
		thePairs = DynamicNumber.TheVars[i].split("=");
		if (thePairs[0].toLowerCase() == id.toLowerCase())
		{
			return unescape(thePairs[1]);
		}
	}


}

DynamicNumber.Tel;
DynamicNumber.GetTel = function()
{
    if (DynamicNumber.Tel == null)
    {
        DynamicNumber.Tel = DynamicNumber.GetParam("tel");
        if (DynamicNumber.Tel == null)
            DynamicNumber.Tel = DynamicNumber.GetParam("t");
    }
        
    return DynamicNumber.Tel;
}

DynamicNumber.Free;
DynamicNumber.IsFree = function()
{
    if (DynamicNumber.Free == null)
    {
        var free = DynamicNumber.GetParam("free");
        if (free == null)
            free = DynamicNumber.GetParam("f");

        DynamicNumber.Free = (free == null || free == "" || free == "false" || free == "0" ? false : true);
    }
    
    return DynamicNumber.Free;
}

DynamicNumber.Site;
DynamicNumber.GetSite = function()
{
    if (DynamicNumber.Site == null)
    {
        var elements = document.getElementsByTagName("span");
        for(var i=0; i < elements.length; i++)
        {
            var element = elements[i];
            if (element.className != null && element.className.substr(0, 14) == "DynamicNumber_")
            {
                DynamicNumber.Site = element.className.substr(14);
                break;
            }
        }
        
        if (DynamicNumber.Site == null)
            DynamicNumber.Site = "HES";
    }

    return DynamicNumber.Site;
}

DynamicNumber.SetContent = function(tag)
{
	if(!DynamicNumber.IsNumberValid(DynamicNumber.GetTel()))

	{
		return;
	}
	
	var items = document.getElementsByTagName(tag);
	for(var i=0; i < items.length; i++)
	{
		if (items[i].className.match("getNum") && DynamicNumber.GetTel())
			items[i].innerHTML = DynamicNumber.GetTel();
		if (items[i].className.match("getFree") && DynamicNumber.GetTel() && DynamicNumber.IsFree())
			items[i].innerHTML = "Call us FREE on:";
		if (items[i].className.match("unhide") && DynamicNumber.GetTel() == items[i].getAttribute('unhideNumber'))
			items[i].style.display = 'block';
	}
}

DynamicNumber.SetAnchor = function()
{
	if(!DynamicNumber.IsNumberValid(DynamicNumber.GetTel()))
	{
		//don't process anything which is not valid
		return;
	}

	// Backwards compatibility
	var anchor = document.getElementById("CallBackLink");
	if (anchor != null)
		anchor.className = anchor.className + " CallBackLink";

	var anchors = document.getElementsByTagName("a");
	for(var i=0; i < anchors.length; i++)
	{
		anchor = anchors[i];
		if(anchor != null && anchor.href.lastIndexOf("&t=") != -1 && anchor.className.match("CallBackLink") && DynamicNumber.GetTel())
			anchor.href = anchor.href.slice(0, anchor.href.lastIndexOf("&t=")).concat("&t=", DynamicNumber.GetTel());
	}
}

DynamicNumber.IsNumberValid = function(number)
{
	if (number == null)
	    return true;

    var numberNoSpaces = number.replace(/(\s|%20)/g, '');
    var validNumbers = DynamicNumber.ValidNumbers[DynamicNumber.GetSite()];
    
    for (var i = 0; i < (validNumbers == null ? 0 : validNumbers.length); i++)
        if (validNumbers[i] == numberNoSpaces)
            return true;

    return false;
}







//shortcuts to make like easier....................
function $__(theID){
	return document.getElementById(theID);
}

function $Height() {
	return $WinSize()[1];
}

function $Width() {
	return $WinSize()[0];
}

function $WinSize(){
	var winWidth, winHeight, d=document;
	if (typeof window.innerWidth!='undefined') {
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	} else if ( d.documentElement && typeof d.documentElement.clientWidth!='undefined' && d.documentElement.clientWidth!=0 ) {
		winWidth = d.documentElement.clientWidth;
		winHeight = d.documentElement.clientHeight;
	} else if ( d.body && typeof d.body.clientWidth!='undefined') {
		winWidth = d.body.clientWidth;
		winHeight = d.body.clientHeight;
	}
	return [winWidth,winHeight];
}

function showDeveloperMessage() {
	var server = getServer();
	if (errMsg && (server == 'DEV' || server == 'TEST_CONTRIBUTION' || server == 'LIVE_CONTRIBUTION')) {
		alert('THE FOLLOWING ERRORS WERE FOUND:' + errMsg);	
	}
}

function getServer() {
    var p = document.location.href;

    if (p.indexOf('kfkws03d') > -1) {
        return 'DEV';
    }else if (p.indexOf('62.190.34.16') > -1 || p.indexOf('80.169.44.') > -1) {
        return 'TEST_CONSUMPTION';
    }else if (p.indexOf('172.19.19.44') > -1 || p.indexOf('10.52.17.37') > -1) {
        return 'TEST_CONTRIBUTION';
    }else if (p.indexOf('npower.com') > -1) {
        return 'LIVE_CONSUMPTION';
    }else if (p.indexOf('10.52.17.5') > -1 || p.indexOf('10.52.17.6') > -1) {
        return 'LIVE_CONTRIBUTION';
    }
}

function getStellentURL(theURL) {
	return 'idc' + theURL;

	//old code...
	var sServer = getServer();
	if (sServer == 'DEV') {
		return 'stellent' + theURL;
	}else if (sServer == 'TEST_CONSUMPTION') {
		return 'syst_consuma' + theURL;
	}else if (sServer == 'TEST_CONTRIBUTION') {
		return 'syst_contriba' + theURL;
	}else if (sServer == 'LIVE_CONSUMPTION') {
		return 'prod_consuma' + theURL;
	}else if (sServer == 'LIVE_CONTRIBUTION') {
		return 'prod_contriba' + theURL;
	}
}

String.prototype.replaceAll = function(stringToFind,stringToReplace){
    var re = new RegExp(stringToFind,'gi');
    return this.replace(re,stringToReplace);
}

Number.prototype.noSpaces = function() {
	return this.replace(/(\s|%20)/g, '');	
}

String.prototype.noSpaces = function() {
	return this.replace(/(\s|%20)/g, '');	
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function getBool(val){
    if (val == 'true' || val == true) {
		return true;
	}else{
		return false;	
	}
}

function getValueFromQueryString(id, theQuery) {
	var thePairs;
	for (var i = 0; i < theQuery.length; i++)
	{
		thePairs = theQuery[i].split("=");
		if (thePairs[0].toLowerCase() == id.toLowerCase())
		{
			return unescape(thePairs[1]);
		}
	}
	
	return "";
}

function getCleanQueryString() {
	var q = location.search.substring(1);
	
	if (!q && location.href.indexOf("#") > -1) {
		var lPos = location.href.lastIndexOf("#") > location.href.indexOf("#")?location.href.lastIndexOf("#"):location.href.length; //in case there's a REAL # anchor at the end!
		q = location.href.substring(location.href.indexOf("#")+1,lPos);
	}
	
	return q;
}

function getArrayIndexFromValue(checkFor, index, theArray, removeHTMLSpaces) {
	for (var i=0; i < theArray.length; i++) {
		var a = theArray[i].split(',');
		if (removeHTMLSpaces) {
			if (a[index].noSpaces().toLowerCase() == checkFor.noSpaces().toLowerCase()) {
				return i;
			}
		}else{
			if (a[index].toLowerCase() == checkFor.toLowerCase()) {
				return i;
			}
		}
	}
	
	return -1;
}

function getArrayValueFromIndex(index, theArray, node) {
	if (index > theArray.length) { return ""; }
	var a = theArray[index].split(',');
	if (node > a.length) { return ""; }
	return a[node];
}













// **************************** FLASH STUFF *****************************
function getFlashVersion(){
	// ie
	try {
		try {
		// avoid fp6 minor version lookup issues
		// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
		try { axo.AllowScriptAccess = 'always'; }
		catch(e) { return '6'; }
	} catch(e) {}
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1].split(',').shift();
		// other browsers
	} catch(e) {
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1].split(',').shift();
			}
		} catch(e) {}
	}
	return '0';
}


function resetSWF(theID) {
	if ($__(theID) && IE) {
		//alert('ok');
		try {
			$__(theID).TGotoLabel("_root", "reset"); 
		}catch(e){
		}
	}
}




// **************************** ANIMATION EVENTS *****************************
function endSlideDown(theID){
	if (theID == 'rotator1' || theID == 'rotator2') {
		setRotator.end();
	}
}

function endSlideUp(theID){
	
}

function endSlideLeft(theID){
	if (theID == Slider.Container) {
		if (Slider.TotalWidth + parseInt(getNoPxVal($__(Slider.Container).style.left)) == Slider.Width) {
			Slider.Reset();
		}
		Slider.Animate();
	}
}

function endSlideRight(theID){
	if (theID == Slider.Container) {
		if (parseInt(getNoPxVal($__(Slider.Container).style.left)) == 0) {
			Slider.Reset(true);
		}
		Slider.Animate();
	}
}


// **************************** ANIMATION EFFECTS ****************************
//for animation effects...
var slideDownID = new Array();
var slideUpID = new Array();
var slideLeftID = new Array();
var slideRightID = new Array();
var slidePos = new Array();
var slideInterval = 10;
var slideSteps = 20;

function slideUp(theID,h){
	slidePos[theID] = getNoPxVal($__(theID).style.height);
	slideUpID[theID] = setInterval("doSlide(\'" + theID + "\','Up'," + h + ")",slideInterval);
}

function slideDown(theID,w,h){
	$__(theID).style.width = w + 'px';
	slidePos[theID] = -1;
	slideDownID[theID] = setInterval("doSlide(\'" + theID + "\','Down'," + h + ")",slideInterval);
}

function slideLeft(theID,l,startPos){
	if (slidePos[theID] && slidePos[theID] != -1) { return; }
	$__(theID).style.left = startPos + 'px';
	slidePos[theID] = -1;
	slideLeftID[theID] = setInterval("doSlide(\'" + theID + "\','Left'," + l + "," + startPos + ")",slideInterval);
}

function slideRight(theID,l,startPos){
	if (slidePos[theID] && slidePos[theID] != -1) { return; }
	$__(theID).style.left = startPos + 'px';
	slidePos[theID] = -1;
	slideRightID[theID] = setInterval("doSlide(\'" + theID + "\','Right'," + l + "," + startPos + ")",slideInterval);
}

function doSlide(theID, theDirection, offset, startPos){
	var object = $__(theID).style;
	
	if (slidePos[theID] == -1){
		if (theDirection == 'Up'){
			slidePos[theID] = parseInt(offset);
		}else if (theDirection == 'Down'){
			slidePos[theID] = 0;
		}else if (theDirection == 'Left' || theDirection == 'Right'){
			slidePos[theID] = startPos;
		}
	}
	
	if (!object.visibility && theDirection == 'Down'){
		object.visibility = 'visible';
	}
	
	if (theDirection == 'Down' || theDirection == 'Right'){
		slidePos[theID] = slidePos[theID] + slideSteps;
	}else if (theDirection == 'Up' || theDirection == 'Left'){
		slidePos[theID] = slidePos[theID] - slideSteps;
	}
	
	if (slidePos[theID] >= offset && theDirection == 'Down'){
		clearInterval(slideDownID[theID]);
		object.height = offset + 'px';
		slidePos[theID] = -1;
		endSlideDown(theID);
	}else if (slidePos[theID] <= 0 && theDirection == 'Up'){
		clearInterval(slideUpID[theID]);
		object.width = '0px';
		slidePos[theID] = -1;
		endSlideUp(theID);
	}else if (slidePos[theID] >= startPos + offset && theDirection == 'Right'){
		clearInterval(slideRightID[theID]);
		object.left = String(startPos + offset) + 'px';
		slidePos[theID] = -1;
		endSlideRight(theID);
	}else if (slidePos[theID] <= startPos - offset && theDirection == 'Left'){
		clearInterval(slideLeftID[theID]);
		object.left = String(startPos - offset) + 'px';
		slidePos[theID] = -1;
		endSlideLeft(theID);
	}else{
		if (theDirection == 'Down' || theDirection == 'Up') {
			object.height = slidePos[theID] + 'px';
		}else{
			object.left = slidePos[theID] + 'px';
		}
	}
}

// **************************** MISC FUNCTIONS ****************************
function getNoPxVal(s){
	if (s.indexOf("px") > -1) {
		return parseInt(s.substring(0,s.length-2));	
	}else{
		return parseInt(s);	
	}
}

// **************************** OVERLAY EFFECTS ****************************
//for homepage SWF overlay...
function overlay() {
	el = document.getElementById("overlay");
	el.style.visibility = (el.style.visibility == "hidden" || el.style.visibility == "") ? "visible" : "hidden";
}


