/*
** Central scriptorium, included into all M&S E-comm 2 Framesets
** All scripts are Copyright © 2000 pres.co, London.
** Licensed for use by Marks & Spencer plc.
**/

// Script to launch fixed size windows
// Written by Owen Blacker and Ian Cillay
// edit by Matt Kerry for the ECOS 3 project

function launch(filename,width,height,winName,isScroll) {
	var undefined;

	var features = "width=" + width + ",height=" + height;
	features += ",menubar=0,toolbar=0,location=0,directories=0,status=0,resizable=0,hotkeys=0";
	if ('' + isScroll == "true")
	{
		features += ",scrollbars=1";
	} else {
		features += ",scrollbars=0";
	}

	void eval(winName + '= window.open("' + filename + '","' + winName + '","' + features + '")');

	if (!(UA.isIE && UA.isMac))
	{
		// Try to focus it
		if (('' + window.focus) != "undefined" && ('' + window.focus) != '') 
		{
				eval(winName + '.focus()');
		}
	}
}

function globalInit() {
	var theBrowser = new Browser();

	//code added to block Mozilla 
	if (theBrowser.isMozl) {
		location.href = "/disallowed2.html";
	} else {
		if (theBrowser.allow) {
			// Cookie Check
			//code inserted by subhir on 16/11/2001 against log no. 61390
			if (document.cookie.toUpperCase().indexOf("IWSESSIONID") < 0) {
				location.href = "/help-access.html";
			}
		} else {
			location.href = "/disallowed.html";
		}
	}
}

// copied this function from include.js
function push(arr, obj) {
	// Just like perl...
	arr[arr.length] = obj;
}

function isDef(variable) {
	variable += '';
	return (variable != '' && variable != "undefined" && variable != "null");
}

function isVal(variable) {
	variable += '';
	return (variable != '' && variable != "undefined" && variable != "null" && !isNaN(parseInt(variable,10)));
}

var UA = new Browser();

function Browser() {
	this.UAstr   = '' + navigator.userAgent;
	this.appVsn  = parseFloat(navigator.appVersion,10);

	this.isMac   =  (this.UAstr.indexOf("Mac")  != -1);

	this.isIE    =  (this.UAstr.indexOf("MSIE") != -1);
	this.isNC    =  (navigator.appName == "Netscape");
	this.isAOL   =  (this.UAstr.indexOf("AOL")  != -1);
	this.AOLvsn  =  (this.isAOL) ? parseFloat(this.UAstr.substring(this.UAstr.indexOf("AOL") + 3),10) : parseInt("X");

	this.isIE4   =  (this.isIE && this.appVsn >= 4);	/* *** NOTE *** These variables specify  */
	this.isIE5   =  (this.isIE && this.appVsn >= 5);	/*  is the UA is (eg) IE4 _or above_     */
	//block this piece of code as to detect NC4 and NC6 a different method for browser sensing will be used
	//this.isNC4   =  (this.isNC && this.appVsn >= 4);	/*  not _solely_ that version. To detect */
	this.isMoz   =  (this.isNC && this.appVsn >= 5);	/*  (eg) IE4 _alone_, then you must test */
	//this.isNC6   =  (this.isNC && this.appVsn >= 5);	/*  for (isIE4 && !isIE5)  Note no isNC5 */

	//Beginning of code to detect Mozilla and Netscape

	this.isNC4   =  (this.isNC && (document.layers)) ? true : false;
	this.isNC6   =  this.isNC && (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

	//this.NCVersn =  parseFloat(this.UAstr.substring(this.UAstr.indexOf("Netscape6") + 10),10);

	this.strtPos =  this.UAstr.indexOf("Netscape6") + 10;
	this.NCVersn =  parseFloat(this.UAstr.substring(this.strtPos,this.UAstr.length),10);

	this.isNC6v2 =  (this.isNC && this.NCVersn >= 6.2);

	this.isMozl  =  this.isNC && this.appVsn >= 5 && !this.isNC6;
	
	//end of code modification

	this.doesCSS =  (this.isIE4 || this.isNC4 || (this.isAOL && this.AOLvsn >= 4));
	this.doesDOM =  (this.isIE4 || this.isMoz);
	this.doesXML = ((this.isIE  || this.isNC) && this.appVsn >= 5);

	var forceAllow = (document.cookie.indexOf("Force_MSEC2_Access") != -1);
        // specifically don't allow version 3 of either browser
	if (this.appVsn > 3 ) {
          this.allow  =  (forceAllow || this.isIE4 || this.isNC6 || (this.isAOL && this.AOLvsn >= 4));
        }
}

// this function changes the nav bar image to distinguish if you are in the personal file or the sign-in.
function changeNavImage(imageName) {
	document.images[imageName].src = '/images/topnav/level0/hi/' + imageName + '.gif';
}

// this function changes the nav bar image to low.
function changeNavImageLow(imageName) {
	document.images[imageName].src = '/images/topnav/level0/low/' + imageName + '.gif';
}

// this function changes the nav bar image to disabled.
function changeNavImageDis(imageName) {
	document.images[imageName].src = '/images/topnav/level0/disabled/' + imageName + '.gif';
}


//previously in product-functions.js and product-functions.js
Number.prototype.formatAsCurrency = Number_formatAsCurrency;
String.prototype.formatAsCurrency = Number_formatAsCurrency;

function Number_formatAsCurrency (symbol, numPlaces, useCommas) {
	var figure   = '' + this;   // Cast to string
	if (figure == '' || figure == "NaN") return '';
	var decimals = '';

	// Split the figure (LHS) from the decimals (RHS)
	if (figure.match(/(\d+)\.(\d+)/)) {
		decimals = RegExp.$2;
		figure   = RegExp.$1;
	} // if (figure.match(/(\d+)\.(\d+)/))
	decimals = (decimals == '') ? '0' : decimals;

	// Pad/truncate the decimals to the requisite number of DPs.
	// AR 02/04/2002 the conditional was >= and caused acceptable decimals to be unnecessarily inspected by this code. The result was removal of leading zeros ie the decimal part of 1.03, 03 became 3 and was then padded to 30 thus incorrectly returning 1.30. The padding was fixed by pre-pending any zeros that may be removed by the rounding function.
	if (decimals.length > numPlaces) {
		var diff = decimals.length - numPlaces;
		if (decimals.substring(0,1) == '0') {
		  decimals = '0' + Math.round(decimals / Math.pow(10,diff)) + '';
		} else {
		  decimals = Math.round(decimals / Math.pow(10,diff)) + '';
		}
	} // if (decimals.length > numPlaces)

	while (decimals.length < numPlaces) {
		decimals += '0';
	} // while (decimals.length < numPlaces)

	if (useCommas == 1) {
  		// Add commas to separate thousands...
		if (figure.length > 3) {
			var temp = '';
			var j = 0;
			for (var i = figure.length - 3; i >= 0; i -= 3) {
				if (i < 0) i = 0;
				temp = ',' + figure.substring(i, i + 3) + temp;
			} // for (i)
			if (figure.length % 3 != 0) {
				temp = ',' + figure.substring(0, (figure.length % 3)) + temp;
			} // if (figure.length % 3 != 0)
			figure = temp.substring(1, temp.length);
		} // if (figure.length > 3)
	}

	figure = symbol + figure + '.' + decimals;
	return figure;
} // public method String formatAsCurrency(String symbol, Integer numPlaces) extends Number


//Script to correct button looping on product pages
var historyInt;
historyInt= -1;
function addHistoryInt(i){
  historyInt = historyInt + i
  //alert(historyInt)
  }

