// browser detect -- standard variables...
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 isNetscape6 = (!document.all && !document.layers && navigator.appName == "Netscape" && 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;
//next line shows all the states of the browser detect variables for debugging
//alert('isFlashNS:'+isFlashNS+'\n'+'isMoz2:'+isMoz2+'\n'+'isIE:'+isIE+'\n'+'isNetscape6:'+isNetscape6+'\n'+'isDOM:'+isDOM+'\n'+'isIE4:'+isIE4+'\n'+'isIE45:'+isIE45+'\n'+'isIE5:'+isIE5+'\n'+'isIE6:'+isIE6+'\n'+'isMac:'+isMac+'\n'+'isMacIE4:'+isMacIE4+'\n'+'isMacIE45:'+isMacIE45+'\n'+'isMacIE5:'+isMacIE5+'\n'+'isOpera:'+isOpera+'\n'+'isOpera3:'+isOpera3+'\n'+'isOpera4:'+isOpera4+'\n'+'isNetscape:'+isNetscape+'\n'+'isNS3:'+isNS3+'\n'+'isNSDIV:'+isNSDIV+'\n'+'isWin2k:'+isWin2k+'\n');

//migration of business masthead
var newBiz = 0;

// Determine cookiedomain and host
// this needs to go here before any refs!
var orangehost;
if (document.URL.indexOf(".analyst.") != -1) {
	orangehost = "orange.analyst.co.uk";
} else if ((document.URL.indexOf(".akqa.") != -1) || (document.URL.indexOf(".localnet") != -1) || (document.URL.indexOf("file://") != -1)) {
	if (document.URL.indexOf("business.orange.akqa.co.uk") != -1) {
		orangehost = 'business.orange.akqa.co.uk';
	} else if (document.URL.indexOf("orangebusiness.akqa.co.uk") != -1) {
		orangehost = 'orangebusiness.akqa.co.uk';
	} else if (document.URL.indexOf("orange2.akqa.co.uk") != -1) {
		orangehost = "orange2.akqa.co.uk";
	} else {
		orangehost = "orange.akqa.co.uk";
	}
} else if (document.URL.indexOf(".orange-today.") != -1) {
	if (document.URL.indexOf("oraweb1") != -1) {
		orangehost = "oraweb1.orange-today.co.uk";
	} else {
		orangehost = "www1.orange.co.uk";
	}
} else {
	orangehost = "www1.orange.co.uk";
}
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 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";
}


var openmenu;
var openitem;
var closewindows;

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

var image_cache_arr = new Array();
var FlashLayers = new Array();
var count = 0;

var cleargif = new Image();
cleargif.src = "http://"+orangehost+"/images/clear.gif";
var personal = new Image();
personal.src = "http://"+orangehost+"/images/personal.gif";
var business = new Image();
business.src = "http://"+orangehost+"/images/business.gif";
var logo = new Image();
logo.src = "http://"+orangehost+"/images/logo.gif";
var line = new Image();
line.src = "http://"+orangehost+"/images/left.gif";
var leftarr = new Image();
leftarr.src = "http://"+orangehost+"/images/left_tri.gif";
var rightarr = new Image();
rightarr.src = "http://"+orangehost+"/images/right_tri.gif";

// telling browser that Business Refresh is the currently selected version of Business
var busURL = "http://"+orangehost+"/business/";
var newBusiness = false;
if (document.location.href.indexOf(busURL) > 0) {
	var newBusiness = true;
}

// 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;
//Set BizSize by URL
if (document.URL.indexOf('/business/small/') != -1 || document.URL.indexOf('smallbiz') != -1 || document.URL.indexOf('context=upgrade') != -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';
    			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+";";
    		}
    		break;
    	}
    }
    if (BizSize == 'small' || BizSize == 'corporate') {
    	navBizSize = BizSize;
    } else {
        navBizSize = 'corporate';
    }
}
// Set BizSize to match nav
BizSize = navBizSize;
// Set the cookie
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+";";

// Load the appropriate nav file
document.writeln('<SCRIPT LANGUAGE="JavaScript" SRC="http://'+orangehost+'/javascript/business_nav_'+navBizSize+'.js"></SCRIPT>');

//Change the biz size cookie - called from the HTML generated by
//BizSizer
function ChangeSize(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';
	}

}

//Build the HTML table for displaying the business size choices
function BizSizer (width, spacer, exclude, doReturn) {
    width = (!width) ? 560 : width;
    spacer = (!spacer) ? 60 : spacer;
	exclude = "";

    var SizeLinksArray = new Array();
	var strOut = '';

	SizeLinksArray[SizeLinksArray.length] = checkSizes("small", exclude);
	SizeLinksArray[SizeLinksArray.length] = checkSizes("corporate", exclude);

	var SizeLinks = SizeLinksArray.join(" &nbsp;|&nbsp; ");

	strOut += '<TABLE CELLSPACING="0" WIDTH="'+width+'">';
	strOut += (spacer > 0) ? '<TR><TD HEIGHT="'+spacer+'"></TD></TR>' : '';
	strOut += '<TR><TD CLASS="BizSizer">';

	if (navBizSize != 'small') {
		strOut += addLink(0, true);
		strOut += addLink(1, true);
		strOut += addLink(2);
	} else {
		strOut += addLink(0, true);
		strOut += addLink(1);
	}
	strOut += '</TD></TR>';
    if (exclude.indexOf("none") == -1) {
		strOut += '<TR><TD HEIGHT="10"></TD></TR>';
		strOut += '<TR><TD CLASS="BizSizer"><B>business size:</B>&nbsp;&nbsp;';
		strOut += SizeLinks;
		strOut += '</TD></TR>';
    }
	strOut += (spacer > 0) ? '<TR><TD HEIGHT="'+spacer+'"></TD></TR>' : '';
	strOut += '</TABLE>';

	function addLink(item, addSpacer) {
		var aLinks = new Array();

		var bizModifier = (BizSize == 'small' || BizSize == 'corporate') ? BizSize+'/' : 'corporate/';
		if (BizSize != 'small') {
			aLinks[0] = new Array('about Orange','http://'+orangehost+'/business/'+bizModifier+'about/');
			aLinks[1] = new Array('privacy policy','http://'+orangehost+'/business/'+bizModifier+'privacy.html');
			aLinks[2] = new Array('terms and conditions','http://'+orangehost+'/business/'+bizModifier+'terms.html');
		} else {
			aLinks[0] = new Array('terms and conditions','http://'+orangehost+'/business/'+bizModifier+'terms.html');
			aLinks[1] = new Array('privacy policy','http://'+orangehost+'/business/'+bizModifier+'privacy.html');
		}

		var retStr = '';
		retStr += '<A HREF="'+aLinks[item][1]+'" OnMouseOver="window.status=\''+aLinks[item][0]+'\'; return true;"';
		retStr += ' OnMouseOut="window.status=\'\'; return true;">';
		retStr += aLinks[item][0].replace(/and/,'&amp;');
		retStr += '</A>';
		retStr += (addSpacer) ? ' &nbsp;|&nbsp; ' : '';

		return retStr;
	}
	function checkSizes(size, exclude) {
		var sizes = new Array();
		sizes['small'] = "1-49 employees";
		sizes['corporate'] = "50+ employees";

		if(navBizSize == size) {
			return sizes[size];
		} else {
			if(exclude.indexOf(size) != -1) {
				return '<FONT CLASS="BizSizerExclude">'+sizes[size]+'</FONT>';
			} else {
				var retStr = '';
				retStr += '<A CLASS="BizSizerLink" OnMouseOver="window.status=\'information for business with '+sizes[size]+'\'; return true;"';
				retStr += ' OnMouseOut="window.status=\'\'; return true;"';
				retStr += ' OnClick="ChangeSize('+size+'); return true;"';
				retStr += ' HREF="http://'+orangehost+'/business/'+size+'/">'+sizes[size]+'</A>';
			}
		}
		return retStr;
	}

	if(doReturn) return strOut
	else document.write( strOut );
}

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

function ora_navLink(num) { ora_navTrackLink(num, orangehost+TopNavLinks[num]); }
function ora_navTrackLink(num, strURL, strText) {
	var strURL = (num != -1) ? TopNavLinks[num] : unescape(strURL);
	if(strURL.indexOf(":") == -1) {
		strURL = (location.protocol == 'file:')  ? 'http:' : location.protocol;
		strURL += "//" + orangehost + strURL;
	}
	location.href = strURL;
}
// Added for compatibility with XML nav - will ultimately replace ora_navTrackLink
function ora_newNavLink(num) { ora_newNavTrackLink(num, newNavLinks[num]); }
function ora_newNavTrackLink(num, strURL, strText) {}
function ora_navGetImage(num) {
	var imgURL = TopNavNames[num].toLowerCase();
	imgURL = imgURL.replace(/and/g,'&');
	imgURL = imgURL.replace(/ /g,'');
	imgURL = imgURL.replace(/\./g,'');
	return imgURL;
}
function ora_navGetName(num) {
	var strName = TopNavNames[num];
	strName = strName.replace(/and/g,'&amp;');
	return strName;
}

function ora_openWindow(URL,Dimensions,name) {
	var redirectStr = "/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);
}

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');
}
