// Orange nav v3.0
//
// written by Roy Stilling
// after Stephen Brown
// AKQA
//
// 10th April 2003

var esaleshost = (document.URL.indexOf(".analyst.") != -1 || document.URL.indexOf(".akqa.") != -1 || document.URL.indexOf("uk.localnet") != -1) ?
	"shop.orange.co.uk" : "shop.orange.co.uk";
var coveragehost = (document.URL.indexOf(".analyst.") != -1 || document.URL.indexOf(".akqa.") != -1 || document.URL.indexOf("uk.localnet") != -1) ?
	"coverage.orange.co.uk" : "coverage.orange.co.uk";
var orangehost = (document.URL.indexOf("oraweb1") != -1 || document.URL.indexOf("staging.") != -1) ? "oraweb1.orange-today.co.uk" :
	(document.URL.indexOf("orangenav") != -1) ? "orangenav.akqa.co.uk" :
	(document.URL.indexOf(".analyst.") != -1) ? "orange.analyst.co.uk" :
	(document.URL.indexOf("orange2.akqa") != -1) ? "orange2.akqa.co.uk" :
	(document.URL.indexOf(".akqa.") != -1 || document.URL.indexOf("uk.localnet") != -1) ? "orange.akqa.co.uk" :
	"www1.orange.co.uk";
var cookiedomain;
if (document.URL.indexOf(".analyst.") != -1) {
	cookiedomain = "analyst.co.uk";
} else if ((document.URL.indexOf(".akqa.") != -1) || (document.URL.indexOf(".localnet") != -1) || (document.URL.indexOf("file://") != -1)) {
	cookiedomain = 'akqa.co.uk';
} else if (document.URL.indexOf(".orange-today.") != -1) {
	cookiedomain = "orange-today.co.uk";
} else if (document.URL.indexOf(".local") != -1) {
	cookiedomain = "local";
} else {
	cookiedomain = "orange.co.uk";
}

// Get the decide which nav to use
// Formerly this was governed by the business size cookie
// As of 20030902 we now determine by page URL and only use the cookie if
// we can't work it out that way
var BizSize = 'corporate';
var navBizSize = BizSize;
var newBusiness = true;
var currentDate = new Date();
var expireYear = currentDate.getYear();
expireYear++;
expireYear = (expireYear < 1900) ? expireYear+1900 : expireYear;
//Set BizSize by URL
if (document.URL.indexOf('/business/small/') != -1 || document.URL.indexOf('smallbiz') != -1) {
    navBizSize = 'small';
} else if (document.URL.indexOf('/business/corporate/') != -1 || document.URL.indexOf('corpbiz') != -1) {
    navBizSize = 'corporate';
} else {
    //try by cookie
    var cookies = document.cookie.split("; ");
    for (loop = 0;loop < cookies.length; ++loop) {
    	cookie = cookies[loop].split("=");
    	if (cookie[0].match("BizSize")) {
    		BizSize = cookie[1];
    		if (BizSize == 'medium' || BizSize == 'large') {
    			// legacy cookie - replace with new size
    			BizSize = 'corporate';
    			document.cookie="BizSize="+BizSize+"; expires=Friday 31-Dec-"+expireYear+" 23:59:59 GMT; path=/; domain="+cookiedomain+";";
    		}
    		break;
    	}
    }
    if (BizSize == 'small' || BizSize == 'corporate') {
    	navBizSize = BizSize;
    } else {
        navBizSize = 'corporate';
    }
}
// Set BizSize to match nav
BizSize = navBizSize;
// Set the cookie
document.cookie="BizSize="+BizSize+"; expires=Friday 31-Dec-"+expireYear+" 23:59:59 GMT; path=/; domain="+cookiedomain+";";

/////////////////////////
// Determining Browser //
/////////////////////////
var isFlashNS = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)?true:false;
var isMoz2 = (navigator.userAgent.indexOf("Mozilla/2") != -1)?true:false;
var isIE = (navigator.appName == "Microsoft Internet Explorer")?true:false;
var isGecko = (navigator.userAgent.indexOf("Gecko") != -1)?true:false;
var isNetscape6 = (isGecko && parseInt(navigator.appVersion) >= 5)?true:false;
var isDOM = (document.getElementById) ? true : false;
var isIE4 = (navigator.userAgent.indexOf("MSIE 4.0") != -1)?true:false;
var isIE45 = (navigator.userAgent.indexOf("MSIE 4.5") != -1)?true:false;
var isIE5 = (navigator.userAgent.indexOf("MSIE 5.0") != -1)?true:false;
var isIE6 = (navigator.userAgent.indexOf("MSIE 6.0") != -1)?true:false;
var isMac = (navigator.userAgent.indexOf("Mac") != -1)?true:false;
var isMacIE4 = (isMac && isIE4) ? true : false;
var isMacIE45 = (isMac && isIE45) ? true : false;
var isMacIE5 = (isMac && isIE5) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1)?true:false;
var isOpera3 = (navigator.userAgent.indexOf("Opera 3.")!= -1)?true:false;
var isOpera4 = (navigator.userAgent.indexOf("Opera 4.")!= -1)?true:false;
var isNetscape = (!isOpera && (navigator.appName.indexOf("Netscape") != -1 && navigator.userAgent.indexOf("4.") != -1))?true:false;
var isNS3 = (!isOpera && (navigator.userAgent.indexOf("Netscape") != -1 && navigator.userAgent.indexOf("3.") != -1)) ? true : false;
var isNSDIV = (!isOpera && (isNetscape && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("4.")+2)) > 5)) ? true : false;
var isWin2k = (navigator.userAgent.indexOf("Windows NT") != -1) ? true : false;

var openmenu;
var openitem;
var closewindows;
var FlashLayers = new Array();
var image_cache_arr = new Array();

// for use with layer visibility
var showEle = (document.layers) ? "show" : "visible";
var hideEle = (document.layers) ? "hide" : "hidden";

// for use with Netscape6 only
var EnableNavigation;
// for use with Netscape4 only
var AllNavsPointRight;

// for Flash implementation
var flashlayers=0;
var CurrentFlashFiles = new Array();
var count = 0;

//Legacy functions
function DisableNavigation() {}
function DisableLeftDropdowns() {}
function hide_all(flash) {}
function insert_hand() {}
function insertBasket() {}

///////////////////////////////////////
// caching images for the navigation //
///////////////////////////////////////

// CLEAR.GIF
var cleargif = new Image();
cleargif.src = "http://"+orangehost+"/images/clear.gif";

// LOGO.GIF
var logo = new Image();
logo.src = "http://"+orangehost+"/images/logo.gif";

// do Nothing functions
function doNothing() {}

// These are the main functions that can be amended when ONLOAD and ONUNLOAD
// are to be changed for global site
function ora_doc_onload() {}
function ora_body_onload() {
	ora_doc_onload(); // DO NOT REMOVE
}
function ora_doc_onunload() {}
function ora_body_onunload() {
	ora_doc_onunload(); // DO NOT REMOVE
}

// Cookie Management Functions
function getCookie(name) {
	var cookies = new Array();
	cookies = document.cookie.split(';');
	var value = false;
	for(i=0; i<cookies.length; i++) {
		var cookie = new Array();
		cookie = cookies[i];
		cookie = cookie.split('=');
		if(cookie[0].match(name)) {
			value = cookie[1];
		}
	}
	return value;
}

function setCookie(name, value) {
	var cookieSet = false;
	var cookies = new Array();
	cookies = document.cookie.split(';');
	for(i=0; i<cookies.length; i++) {
		var thisC = new Array();
		thisC = cookies[i];
		thisC = thisC.split('=');
		if(thisC[0] == name) {
			cookies[i] = name+"="+value;
			cookieSet = true;
		}
	}
	var returnCookie="";
	if(cookieSet == false) {
		returnCookie = name+"="+value+";";
	} else {
		for(i=0; i<cookies.length; i++) {
			returnCookie+= cookies[i]+";";
		}
	}
	document.cookie = returnCookie;
}

//////////////////////////////////////////////////////////////////////////////////////////////
// functions used by all dHTML browsers
// MouseOver
// MouseOut
// ImageCache

// netscape / IE 3 and less detect
// nsie3_det

// write_standard_nav
// SetHomeCookie


function getFileExtension(fileSource) {
	var newSource = '';
	if (fileSource.lastIndexOf(".") != -1) {
		newSource = fileSource.substring(fileSource.lastIndexOf("."));
	}
	return newSource;
}

// Mouse Rollover function
function MouseOver(image, nest, nest2) {
	var nestedImage = getNestedLayer(nest, nest2);
	if(nestedImage.images && nestedImage.images[image] && nestedImage.images[image].src.indexOf("-over") == -1) {
		var imageExt = getFileExtension(nestedImage.images[image].src);
		nestedImage.images[image].src = nestedImage.images[image].src.substring(0,nestedImage.images[image].src.indexOf(imageExt)) + "-over"+imageExt;
	}
}

// Mouse Rollout function
function MouseOut(image, nest, nest2) {
	var nestedImage = getNestedLayer(nest, nest2);
	if (nestedImage.images && nestedImage.images[image] && nestedImage.images[image].src.indexOf("-over") >=0) {
		var imageExt = getFileExtension(nestedImage.images[image].src);
		nestedImage.images[image].src = nestedImage.images[image].src.substring(0,nestedImage.images[image].src.indexOf("-over"+imageExt)) + imageExt;
	}
}

// Returns a nested Layer or a document object
function getNestedLayer(nest1, nest2) {
	return (document.layers) ? (nest1) ? (nest2) ? document.layers[nest1].layers[nest2].document : document.layers[nest1].document : document : document;
}

// function to cache images on a web page
// To use the Image Caching function, use the following syntax:
//	image_cache_arr[num] = new Array(imagepath, state "-over" etc... , extension, images);
// Ex:	image_cache_arr[0] = new Array("/services/images", "yes", "gif", "international", "additional");
//
// Once you have set-up the array, you can call ImageCache(); to cache the images.
//
var showImagesCached = false;
var imageCache = "";
function ImageCache() {
	if(document.images) {
		for(i=0; i<image_cache_arr.length; i++) {
			var imagepath = image_cache_arr[i][0];
			var mouseoverimages = new Array(image_cache_arr[i].length-1);
			var numofoverstates=(ImageCache.arguments[i]) ? ImageCache.arguments[i] : 0;
			var overstate = new Array();
			for(os=1; os<numofoverstates+1; os++) {
				overstate[os] = image_cache_arr[i][os];
			}
			var ext = "." + image_cache_arr[i][numofoverstates+1];

			for(j=(numofoverstates+2); j<image_cache_arr[i].length; j++) {
				if(image_cache_arr[i][j].indexOf('"') == -1 && image_cache_arr[i][j].indexOf(',') == -1) {
					mouseoverimages[image_cache_arr[i][j]] = new Image();
					if(isNSDIV || isIE || isNetscape6) {
						mouseoverimages[image_cache_arr[i][j]].name = image_cache_arr[i][j];
					}
					mouseoverimages[image_cache_arr[i][j]].src = imagepath + image_cache_arr[i][j] + ext;
					imageCache+=mouseoverimages[image_cache_arr[i][j]].src+"\n";
					for(os=1; os<numofoverstates+1; os++) {
						mouseoverimages[image_cache_arr[i][j]].src = imagepath + image_cache_arr[i][j] + overstate[os] + ext;
						imageCache+=mouseoverimages[image_cache_arr[i][j]].src+"\n";
					}
				}
			}
		}
	}
	if (showImagesCached == true) { alert(imageCache); }
}

// Netscape 3 detection function
function nsie3_det() {
	var gotolocation=false;

	if(navigator.appName == "Netscape") {
		if(parseInt(navigator.appVersion) <= 3) {
			gotolocation=true;
		}
	}
	if(navigator.appName.match("Internet Explorer")) {
		if(parseInt(navigator.appVersion) <= 3) {
			gotolocation=true;
		}
	}
	if(gotolocation) {
		var currentURL=document.URL;
		for(i=0;i<3;i++) {
			currentURL=currentURL.substring(currentURL.indexOf("/")+1);
		}
		if(currentURL == "index.html" || currentURL == "default.htm" || currentURL == "") {
			window.open("http://"+orangehost+"/ns3.html","Orange","height=375,width=600");
			document.location.href="old_home.html";
		}
	}
}
nsie3_det();

function SetHomeCookie() {
	var cookies = document.cookie.split("; ");
	for (i=0; i<cookies.length; ++i) {
		cookie=cookies[i].split("=");
		if(cookie[0].match("visited")) {
			return cookie[1];
		}
	}
	document.cookie="visited=1";
	return 0;
}

var DateObj = new Date();
var thisDay = DateObj.getDate();
var thisMonth = DateObj.getMonth();
var thisYear = DateObj.getYear();
var RandNum = Math.floor(Math.random() * 901) + 100;
var thisDate = thisDay + '-' + thisMonth + '-' + thisYear;

//eSales redirect form and functions

var esalesAnalyst = new Array();
esalesAnalyst[0] = '24DA61DE2A4911D58C0F00902798A974'; // Buy online
esalesAnalyst[1] = '24DA61B72A4911D58C0F00902798A974'; // Browse & buy
esalesAnalyst[2] = '24DA61BF2A4911D58C0F00902798A974'; // Quick buy
esalesAnalyst[3] = '24DA61C72A4911D58C0F00902798A974'; // Offers
esalesAnalyst[4] = '24DA61CE2A4911D58C0F00902798A974'; // Other ways to buy
esalesAnalyst[5] = '24DA61D62A4911D58C0F00902798A974'; // How to shop online
var esalesNames = new Array('indexpage','browse','buynow','offers','other_channels','how_to_shop');
function esalesRedirect(redirectType, mapRef, values, target) {
    var strURL = "http://"+esaleshost+"/shop/index";
	if(target) {
		var newWin = window.open(strURL,target);
    } else {
    	document.location.href = strURL;
    }
}

function submitSearch(handle, searchType, searchValue, LeftNavigation) {
    var strURL = "http://"+esaleshost+"/shop/index";
	document.location.href = strURL;
}

function esalesOffer(offerType, offerID) {
	var strURL = "http://"+esaleshost+"/shops";
    if (offerID) {
        strURL += '/offer/'+offerID;
    } else {
        strURL += '/offers'
    }
	document.location.href = strURL;
}

document.write('<SCRIPT LANGUAGE="Javascript" SRC="http://'+orangehost+'/javascript/ora_sitetracking.js"></SCRIPT>');

function ora_openWindow(URL,Dimensions,name) {
	var redirectStr = "http://"+orangehost+"/cgi-bin/redirect/";
	if(isNetscape && URL.indexOf(redirectStr) != -1) {
		URL = URL.substring(redirectStr.length);
	}
	if(!name) name = "_blank";
	if(!Dimensions) Dimensions = '';
	window.open(URL,name,Dimensions);
}

// Old functions, left in to stop broken functions when file is missing
// function to facilitate tracking
function logClick(add, url) {}
// start writing flash dHTML layer
function startFlash(top,left,flashfile,flashwidth,flashheight,giffile,gifwidth,gifheight,wmodeEnabled,wmodeReplacementImage) {
	if(isMac || !isIE || isWin2k || (typeof wmodeEnabled == "undefined")) {
		wmodeEnabled = false;
	}
	left = (left=="none") ? left="" : left;
	left = (isNetscape) ? left + parseInt(left/50) : left;
	top = (!top || top == "") ? 98 : top;
	top = (isMac) ? top+1 : top;
	start_layer(flashlayers,top,left,flashwidth,wmodeEnabled);
	gifwidth=(gifwidth)?gifwidth:flashwidth;
	gifheight=(gifheight)?gifheight:flashheight;
	ID=flashfile;
	for(i=0; i<ID.length; i++) {
		if(ID.substring(i,i+1) == "/") ID=ID.substring(0,i) + ID.substring(i+1);
		if(ID.substring(i,i+1) == ".") ID=ID.substring(0,i) + ID.substring(i+1);
	}

	var wmode = "";
	if(wmodeEnabled) {
		wmode = ' wmode="transparent"';
	}
	if((isIE || isFlashNS || isDOM) && !isNetscape6) {
		if(flashfile.indexOf("?") == -1) {
			flashfile = flashfile + "?" + thisDate;
		}

		document.write('<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="'+flashwidth+'" HEIGHT="'+flashheight+'" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">');
		document.write('<PARAM NAME="MOVIE" VALUE="'+flashfile+'">');
		document.write('<PARAM NAME="PLAY" VALUE="true">');
		document.write('<PARAM NAME="LOOP" VALUE="true">');
		document.write('<PARAM NAME="QUALITY" VALUE="best">');
		if(wmode != "") {
			document.write('<PARAM NAME="WMODE" VALUE="transparent">');
		}

		document.write('<EMBED NAME="'+ID+'" ID="'+ID+'" SRC="'+flashfile+'" WIDTH="'+flashwidth+'" HEIGHT="'+flashheight+'" MENU="false" loop="true" QUALITY="BEST" BORDER="0" ALIGN="TOP" swliveConnect=true'+wmode+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>');

		document.write('</OBJECT>');
	}
	end_layer();
	CurrentFlashFiles[flashlayers] = new Array(top,left,flashfile,flashwidth,flashheight,giffile,gifwidth,gifheight,ID,wmodeEnabled,wmodeReplacementImage);
	flashlayers++;
}

// finish writing flash dHTML layer
function endFlash(thislayer) {
	if(isNetscape6) {
		var flashfile = CurrentFlashFiles[thislayer][2];
		var flashwidth = CurrentFlashFiles[thislayer][3];
		var flashheight = CurrentFlashFiles[thislayer][4];
		var wmodeEnabled = CurrentFlashFiles[thislayer][9];
		var wmode = (wmodeEnabled) ? ' wmode="transparent"' : '';

		document.write('<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="'+flashwidth+'" HEIGHT="'+flashheight+'" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">');
		document.write('<PARAM NAME="MOVIE" VALUE="'+flashfile+'">');
		document.write('<PARAM NAME="PLAY" VALUE="true">');
		document.write('<PARAM NAME="LOOP" VALUE="true">');
		document.write('<PARAM NAME="QUALITY" VALUE="best">');
		if(wmode != "") {
			document.write('<PARAM NAME="WMODE" VALUE="transparent">');
		}
		document.write('<EMBED SRC="'+flashfile+'" WIDTH="'+flashwidth+'" HEIGHT="'+flashheight+'" MENU="false" loop="true" QUALITY="BEST" BORDER="0" ALIGN="TOP" swliveConnect=true'+wmode+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>');
		document.write('</OBJECT>');

	} else if(document.all || document.layers || isMoz2) {
		if(CurrentFlashFiles[thislayer][9] == false) {
			document.write('<IMG SRC="'+CurrentFlashFiles[thislayer][5]+'" WIDTH="'+CurrentFlashFiles[thislayer][6]+'" HEIGHT="'+CurrentFlashFiles[thislayer][7]+'" BORDER="0"><BR>');
		} else {
			document.write('<IMG SRC="'+CurrentFlashFiles[thislayer][10]+'" WIDTH="'+CurrentFlashFiles[thislayer][6]+'" HEIGHT="'+CurrentFlashFiles[thislayer][7]+'" BORDER="0"><BR>');
		}
	}
}

function ora_navLink(num) { ora_newNavTrackLink(num, newNavLinks[num]); }
function ora_newNavLink(num) { ora_newNavTrackLink(num, newNavLinks[num]); }
function ora_newNavTrackLink(num, strURL, strText) {}
function ora_navGetImage(num) {}
function ora_navGetName(num) {}

// start flash layer
function start_layer(layername,top,left,width,wmodeEnabled) {
	if(wmodeEnabled) {
		layername = "HomeSWF"+layername;
	} else {
		layername="Flash"+layername;
	}
	if(document.layers) {
		top = " TOP=\""+top+"\"";
		if(left) { left = " LEFT=\""+left+"\""; } else { left = " LEFT=\"0\""; }
		document.write('<LAYER ID="'+layername+'" Z-INDEX="50" POSITION="absolute" '+top+left+' WIDTH='+width+'>');
	} else {
		if(!left) { left = 0; }
		document.write('<DIV ID="'+layername+'" STYLE="z-index:50; position:absolute; top:'+top+'; left:'+left+'; width:'+width+';">');
	}
}

// end flash layer
function end_layer() {
	if(document.layers) {
		document.write('</LAYER>');
	} else {
		document.write('</DIV>');
	}
}

//Change the biz size cookie
function changeBizSize(BizSize) {
	var currentDate = new Date();
	var expireYear = currentDate.getYear();
	expireYear++;
    expireYear = (expireYear < 1900) ? expireYear+1900 : expireYear;
	document.cookie="BizSize="+BizSize+"; expires=Friday 31-Dec-"+expireYear+" 23:59:59 GMT;; path=/; domain="+cookiedomain+";";
	if (BizSize == 'small') {
		document.location.href = "http://"+orangehost+"/business/small/index.html";
	} else {
		document.location.href = "http://"+orangehost+"/business/corporate/index.html";
	}
}

function NavOpenDontMissOut() {
	window.open('http://'+orangehost+'/dontmissout/?global_nav','dontmissout','scrollbars=no,toolbar=no,menubar=no,location=no,status=no,resizable=no,width=617,height=385');
}

function validateMe() {
	var valWin = window.open('http://validator.w3.org/check?uri='+escape(document.location.href)+'&outline=1','_val','left=25,top=25,width=800,height=600,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
}
