// add the current page to favourites page title unless a substitute is supplied
function addToFavorite( favTitle ){
   if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
      ft = (favTitle) ? favTitle : document.title;
      window.external.AddFavorite(location.href, unescape(ft));
   }
}

// call from the onsubmit event to display the contents of the form in an alert box, returning false unless true is specified
// e.g. onsubmit="return showFormElements( this )"
function showFormElements( oForm ){
	els = oForm.elements;
	txt = 'FORM ' + oForm.name + " (" + els.length + " element" + ((els.length>1) ? "s" : "") + ")\n\n";
	for (var x=0; x<els.length; x++){
		txt += els[x].name + " = " + els[x].value + "\n";
		}
  txt += "\nClicking OK to submit form, CANCEL to, well, cancel";

	return confirm(txt);
}

// this lot will allow a field to be cleared when it it receives the focus for the first time (ONLY!)
var rClearOnFirstClick = new Array();

function clearOnFirstClick(thisfield) {
	if (!rClearOnFirstClick[thisfield.id]) {
		thisfield.value = "";
		rClearOnFirstClick[thisfield.id]=1;
	}
}

function countChecked( oField ) {
	count = 0;

	if (oField.length == undefined) {
		count += (oField.checked);
	}
	else
		for (ii=0; ii<oField.length; ii++) {
			count += (oField[ii].checked);
		}
	return count;
}


//##################################################     T R I M     F U N C T I O N S     #############################
// remove trailing spaces from a string
function rTrim( strText ) {
strTemp = strText;
while( strTemp.length > 0 && strTemp.charAt(strTemp.length-1)==" " ) {
	strTemp = strTemp.substring(0,strTemp.length-1);
}
return strTemp;
}

// remove leading spaces from a string
function lTrim( strText ) {
strTemp = strText;
while( strTemp.length > 0 && strTemp.charAt(0)==" " ) {
	strTemp = strTemp.substring(1,strTemp.length-1);
}
return strTemp;
}

// remove leading & trailing spaces from a string
function Trim( strText ) {
return lTrim( rTrim( strText ) );
}

//##################################################     T R I M     M E T H O D S     #############################
// http://www.developingskills.com/ds.php?article=jstrim&page=1
function strltrim() {
	//Match spaces at beginning of text and replace with a null string
	return this.replace(/^\s+/,'');
}

function strrtrim() {
	//Match spaces at end of text and replace with a null string
	return this.replace(/\s+$/,'');
}

function strtrim() {
	//Match spaces at beginning and end of text and replace with null strings
	//return this.replace(/^\s+/,'').replace(/\s+$/,'');
	return this.ltrim().rtrim();
}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim  = strtrim;
                  

//##############################################      F O R M     V A L I D A T I O N      ################################

function validateForm( oForm, tMsg ) {
//  alert( oForm.elements.length );
	ok = true;
	str = "";
	if (!tMsg) tMsg = 'Errors must be corrected before you can update this record';
	
	// this loop basically checks to see that all required fields have a value in
	for (ii=0;ii<oForm.elements.length;ii++) {
		xx = oForm.elements[ii];

		// this bit changes the class on any description fields for images/thumbs/supers
		if (xx.name && (prefix=xx.name.substr(0,5).toLowerCase()))
			if (prefix == 'image' || prefix == 'thumb' || prefix == 'super') {
				// getting the prefix allows for image10..image999 etc.
				prefix = (pos = xx.name.indexOf('_')) ? xx.name.substr(0,pos) : xx.name;
				if (desc = eval("oForm." + prefix + "Desc"))	{		// e.g. Image1Desc
					desc.className = xx.value ? 'required' : '';
//					alert( desc.name + " class changed to : " + desc.className );
					window.status = desc.name + " class changed to : " + desc.className;
				}
			}
		fldName = (xx.title) ? xx.title : (xx.name) ? xx.name : xx.id;		// use Title, else Name, else Id for alert box
		
		// if field classname says it's a required field
		if (xx.className.substr(0,8) == "required") {
			switch( xx.type ) {
				case "radio":
					break;
				case "checkbox":
					if (!xx.checked) {
						str += fldName + "\n";
						if (ok) oField = xx;    		// identify first field in error
						ok = false;
					}
					break;
				default:
					xx.value = xx.value.trim();		// remove leading and trailing spaces
					if (xx.value == "") {
						str += fldName + "\n";
						if (ok) oField = xx;    		// identify first field in error
						ok = false;
		//				alert( fldName + " classname=" + xx.classname + " type=" + xx.type +  " value=" + xx.value + " result=" + ok);
					}
			} // switch
		}	// required
	}	// for
		 
	// if all required fields have a value, check to see that it's of the required (!) type
	if (ok) {
		for (ii=0;ii<oForm.elements.length;ii++) {
			xx = oForm.elements[ii];
			fldName = (xx.title) ? xx.title : (xx.name) ? xx.name : xx.id;
			if (xx.value != '') {
				valType = (xx.className.substr(8)).toLowerCase();		// drop off 'required' or 'optional'
				switch( valType ) {
					case "n" :
						xx.value = xx.value.replace("%","");					// handle percentages
//						xx.value = eval(xx.value.replace(",",""));		// remove commas from numbers
						xx.value = xx.value.replace(",","");		// remove commas from numbers
						
						if (xx.value.match(/^\d*$/)==null) {	// zero or more digits only
							str += fldName + " must be a valid integer\n";
							window.status = xx.value + " must be a valid integer";
							if (ok) oField = xx;    		// identify first field in error
							ok = false;
						}
						break;
					case "email":
						var exclude = /[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
						var check = /@[\w\-]+\./;
						var checkend = /\.[a-zA-Z]{2,6}$/;
//						alert( xx.value.search(exclude) + "\n" + xx.value.search(check) + "\n" + xx.value.search(checkend) );
						if(((xx.value.search(exclude) != -1) || (xx.value.search(check)) == -1) || (xx.value.search(checkend) == -1)) {
							str += fldName + " must be a valid email address\n";
							window.status = xx.value + " is not a valid email address";
							if (ok) oField = xx;    		// identify first field in error
							ok = false;
						}
						break;
					case "price" :
						xx.value = xx.value.replace("£","");					// remove pound signs
						xx.value = eval(xx.value.replace(",",""));		// remove commas from numbers
						// match pounds only or pounds and 2 decimal pence
						if (xx.value.match(/^\d+(\.\d{2})?$/) == null) {
							str += fldName + " must be a valid price\n";
							if (ok) oField = xx;    		// identify first field in error
							ok = false;
						}
						break;
					case "file" :
//					allow colons and back slashes through as they'll go during the POST process.
						if (xx.value.match(/^([\w]|[-]|[ ]|[:]|[\\])+\./) == null) {
							str += fldName + " - filename can only contain letters, digits, space, hyphen or underscore\n";
							if (ok) oField = xx;    		// identify first field in error
							ok = false;
						}
						// must END with one of specified document types
						if (xx.value.match(/\.(doc|csv|mdb|pdf|ppt|sfi|xls|zip)+$/) == null) {
							str += fldName + " - file can only be of the following types : .doc, .csv, .mdb, .pdf, .ppt, .sfi, .xls, .zip\n";
							if (ok) oField = xx;    		// identify first field in error
							ok = false;
						}
						break;
					case "image" :
//					allow colons and back slashes through as they'll go during the POST process.
						imgname = xx.value.split('\\');
												
						if (imgname[imgname.length-1].match(/^([\w]|[-]|[:]|[\\])+\./) == null) {
							str += fldName + " - filename can only contain letters, digits, hyphen or underscore\n";
							if (ok) oField = xx;    		// identify first field in error
							ok = false;
						}
						// must END with one of specified image types
						if ((xx.value.toLowerCase()).match(/\.(gif|jpeg|jpg|wmf)+$/) == null) {
							str += fldName + " - file can only be of the following types : .gif, .jpeg, .jpg, .wmf\n";
							if (ok) oField = xx;    		// identify first field in error
							ok = false;
						}
						break;
					case "date" :
					case "datetime" :
						// match dates in 1900-2099, no checks on days in month though
						// match 1-9, 01-09 or 10-29, or 30-31, then /, then 1-9, 01-09, or 10-12, then /, then 20, or null, then 00-99
						if (valType == "date")
							dtArr = xx.value.match(/^([0]?[1-9]|[1-2][0-9]|[3][0-1])(\/)([0]?[1-9]|[1][0-2])(\/)((19|20)?[0-9][0-9])$/);
						else {
							// this works for datetime values, but they're not nice to enter on a form for a user
							dtArr = xx.value.match(/^([0]?[1-9]|[1-2][0-9]|[3][0-1])(\/)([0]?[1-9]|[1][0-2])(\/)((19|20)?[0-9][0-9])?(( )+([0-1][0-9]|[2][0-3])(:)([0-5][0-9]))?$/);
//							alert(xx.value + " = " + dtArr);
							}


						if ((dtArr) != null) {
							dt = new Date();
							if ((dtYear = dtArr[5]).length == 2) dtYear = dt.getFullYear().toString().substr(0,2) + dtYear;	// prefix yy years with current cc (20 I guess!)
							dtLeap = (dtYear % 4 == 0) && (dtYear % 400 != 0); 
	//						window.status = xx.value + " = " + dtArr + " " + dtLeap;
							switch ( dtArr[3] * 1 ) {		// month entered
								case 4:	case 6: case 9: case 11:
									if (dtArr[1]*1 > 30) {
										str += fldName + " must be a valid date\n";
										window.status = xx.value + " is not a valid date [2]";
										if (ok) oField = xx;    		// identify first field in error
										ok = false;
									}
									break;
								case 2:
									if (dtArr[1]*1 > (28+dtLeap)) {
										str += fldName + " must be a valid date\n";
										window.status = xx.value + " is not a valid date [3]";
										if (ok) oField = xx;    		// identify first field in error
										ok = false;
									}
									break;
								default:
							} // switch							
						}
						else {
							str += fldName + " must be a valid date\n";
							window.status = xx.value + " is not a valid date [1]";
							if (ok) oField = xx;    		// identify first field in error
							ok = false;
						}
						break;
					case "date2" :
						// match dates in 2003-9, no checks on days in month though
						// match 1-9, 01-09 or 10-29, or 30-31, then /, then 1-9, 01-09, or 10-12, then /, then 20, or null, then 00-99
						window.status = xx.value + " = " + 
							(xx.value.match(/^([0]?[1-9]|[1-2][0-9]|[3][0-1])(\/)([0]?[1-9]|[1][0-2])(\/)((20)?[0-9][0-9])?$/));
						break;
					case "time" :
						if (xx.value.match(/^([0-1][0-9]|[2][0-3])(:)([0-5][0-9])$/) == null) {
							str += fldName + " must be a valid time\n";
							window.status = xx.value + " is not a valid time";
							if (ok) oField = xx;    		// identify first field in error
							ok = false;
						}
						break;
					default :
				}		// switch
			}
		}	// for
		if (!ok) {
			alert( str += "\n" + tMsg );
			if (oField.type != "hidden")
				oField.focus();   // set focus on first field in error
		}
	}
	else {
		alert( str += "\n" + tMsg );
		if (oField.type != "hidden")
			oField.focus();   // set focus on first field in error
	}

	window.status = "final value WOULD have been : " + ok;
	setTimeout("window.status=''", 1500);
	if (oForm.debug && oForm.debug.value.toLowerCase()=='y')			// if debugging is 'on'
		ok = ok && showFormElements(oForm);		// do whatever user wants to do, if OK

	return ok;											// go ahead and submit
}


function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
coutesy of 4 guys from rolla... fixed by JPN!!!!!!!!!!!

IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
//	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// this FIX added by JPN 19 March 2004 to stop errors by division and conversion to binary
	if (decimalNum>0)
		tmpNumStr = tmpNumStr.substring(0,tmpNumStr.length-decimalNum) + '.' + tmpNumStr.substring(tmpNumStr.length-decimalNum);
	else
		tmpNum /= Math.pow(10,decimalNum);		// originally higher up!


	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

// BEGIN DECIMAL POINT WORKER
	function just(here)
	{
	string = "" + here;
	number = string.length - string.indexOf('.');
	if (string.indexOf('.') == -1)
		return string + '.00';
	if (number == 1)
		return string + '.00';
	if (number == 2)
		return string + '0';
	if (number > 3)
		return string.substring(0,string.length-number+3); return string;
	}
// END DECIMAL POINT WORKER


function validateForm2( oForm ) {
	els = oForm.elements;

	ok = validateForm( oForm );

	for (x=0; x<els.length; x++) {
		fld = els[x];
		if ((fld.id) && fld.id == 'qtyfreegift')
			if (fld.value != '0' && fld.value != '1') {
				ok = false;
				alert('Free gift quantity must be 0 or 1');
			}
	}

	return ok;
}


function do_remove(nn) {
	//Action is called from an Image Submit and we set the row qty to zero
	var sel = document.getElementById("x"+nn);
	sel.value = ('0');
	//alert("Alison:" + sel.value);
}


// FOR UD__Cart.asp increments the order quantity and submits the 
// form to update itself, needs UD__cartUpdate.asp
// thisAction == down || up
// oQTY the quanity field it needs to talk to
function doQuantity(thisAction, oQTY ) {
		var myqty = document.getElementById(oQTY);
		val = myqty.value
		if(thisAction=="down") {
		myqty.value = (parseFloat(val) - 1)
			}
		if(thisAction=="up") {
		myqty.value = (parseFloat(val) + 1)
			}
		document.updateAHScart.submit()
	}


function initialise(geoCodes, show) {
	var i = geoCodes.split(",");
	if (GBrowserIsCompatible()) {
		if(eval(document.getElementById("mapping"))) {
			var map = new GMap2(document.getElementById("mapping"));
			map.setCenter(new GLatLng(i[0], i[1]), 15);
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			var locationIcon = new GIcon(G_DEFAULT_ICON);
			var point = new GLatLng(i[0], i[1]);
			map.addOverlay(new GMarker(point, locationIcon));
		}
	}
}
	
//<input type="text" name="mytext" onKeyPress="return disableCtrlKeyCombination(event);" onKeyDown="return disableCtrlKeyCombination(event);">
//You can also add oncut="return false;" oncopy="return false;" onpaste="return false;"
function disableCtrlKeyCombination(e)
{
	//list all CTRL + key combinations you want to disable
	//var forbiddenKeys = new Array('a', 'n', 'c', 'x', 'v', 'j'); //Defaults
	var forbiddenKeys = new Array('a', 'c', 'x', 'v');
	var key;
	var isCtrl;
	
	if(window.event)
	{
		key = window.event.keyCode; //IE
		if(window.event.ctrlKey)
			isCtrl = true;
		else
			isCtrl = false;
	} else {
		key = e.which; //firefox
		if(e.ctrlKey)
			isCtrl = true;
		else
			isCtrl = false;
	}
	
	//if ctrl is pressed check if other key is in forbidenKeys array
	if(isCtrl)
	{
		for(i=0; i<forbiddenKeys .length; i++)
		{
			//case-insensitive comparation
			if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
			{
				return false;
			}
		}
	}
	return true;
}

function popUp(URL, WindowWidth, WindowHeight) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width='+WindowWidth+',height='+WindowWidth);");
}

function isPostcodeRequired(selectedCountryIndex) {
	if(selectedCountryIndex >= 1 && selectedCountryIndex <= 4) {
		document.getElementById('shpc').style.display = 'inline';
	} else {
		document.getElementById('shpc').style.display = 'none';
	}
}


	// After the Ajax Is done we need to release the qty
	// select menu from it's disabaled state
	function releaseQty( objValue ) {
		var tempStr = objValue;
		var stockValue = tempStr.split("~");
		document.getElementById("quantity").disabled = (stockValue[0]!=0) ? false : true;
	}

	// Toggles the Product Info and Delivery Onfo 
	// on the Main Product Page
	function toggleTab(toggle) {
		//1. Swap the image
		//2. Swap the layers below
		
		// Toggle image here
		var tab = document.getElementById("tab");
		var cell1 = document.getElementById("productDescription");
		var cell2 = document.getElementById("deliveryDescription");
		var tempTab = tab.src
		//alert(tempTab);
		tempTab = tempTab.split('/');
		
		tab.src = ( tempTab[5] == 'jolliman_producttab_ProductInfo_ON.jpg' ) ? '/images/skinV5/jolliman_producttab_DeliveryInfo_ON.jpg' : '/images/skinV5/jolliman_producttab_ProductInfo_ON.jpg' ;;
		cell1.style.display = ( toggle == 'deliveryDescription' ) ? 'none' : 'block' ;;
		cell2.style.display = ( toggle == 'productDescription' ) ? 'none' : 'block' ;;
	}

	function checkAllFieldsareValidThenShowBasketImage() {
		var revealAddToBasket = true;
		if( ! eval(document.getElementById("FirstSize")) == null ) {
			if( document.getElementById("FirstSize").value == "" ) { revealAddToBasket = false; alert(" Please select a size option ") }
		}
		if( ! eval(document.getElementById("SecondSize")) == null ) {
			if( document.getElementById("SecondSize").value == "" ) { revealAddToBasket = false; alert(" Please select a size option ") }
		}
		if( ! eval(document.getElementById("colours")) == null ) {
			if( document.getElementById("colours").value == "" ) { revealAddToBasket = false; alert(" Please select a colour option ") }
		}
		if( ! eval(document.getElementById("qty")) == null ) {
			if( document.getElementById("qty").value == "" ) { revealAddToBasket = false; alert(" Please select how many you need") }
		}

			document.getElementById("TempBasketButton").style.display = revealAddToBasket ? 'none' : 'block';
			document.getElementById("LiveBasketButton").style.display = revealAddToBasket ? 'block' : 'none';

		return revealAddToBasket

	}
	
	//From the thumbnail pages
	function aLink(url) { window.location.href = url; }
	
	//STOP FIREFOX AUTO FILL - MAY be?
	function stopFireFoxAutoFill(layer) {
	var div = document.getElementById(layer)
			var allTags = document.body.getElementsByTagName('input');
			var ids = [];
			for (var tg = 0; tg< allTags.length; tg++) {
			var tag = allTags[tg];
			if (tag.id) {
			//document.JollimanAddtoBasket[tag.id].selectedIndex = 0;
			//document.getElementById(tag.id).disabled = (tag.id!="colours") ? true : false ;
			ids.push(tag.id);
			}
			}
	}






	// ############# ################ ############## ################ ######

	// THIS SCRIPT POPS THE SMALL LAYER OPEN AND WHICH FADES THE BACK GROUND
	//(C) Stephen Daly
	// www.stephendaly.org
	// Date: 11/3/2008

	var X = 0;
	var Y = 250;
		
	function backgroundFilter()
	{
		var div;
		
		if(document.getElementById)
		// Standard way to get element
		div = document.getElementById('backgroundFilter'); 
		else if(document.all) 
		// Get the element in old IE's 
		div = document.all['backgroundFilter']; 
		
		// if the style.display value is blank we try to check it out here 
		if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
		{
			div.style.display = (div.offsetWidth!=0&&div.offsetHeight!=0)?'block':'none'; 
		}
		div.style.height=getPageSize()[1]+'px';
		
		// If the background is hidden ('none') then it will display it ('block').
		// If the background is displayed ('block') then it will hide it ('none').
		div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
	}
		
	function popUp2() {
		var div;
		
		if(document.getElementById)
		// Standard way to get element
		div = document.getElementById('popupWindow'); 
		else if(document.all) 
		// Get the element in old IE's 
		div = document.all['popupWindow']; 
		
		// if the style.display value is blank we try to check it out here 
		if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
		{
			div.style.display = (div.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; 
		}
		
		// If the PopUp is hidden ('none') then it will display it ('block').
		// If the PopUp is displayed ('block') then it will hide it ('none').
		div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
		
		// Sets the position of the DIV
		div.style.left = X+'px';
		div.style.top = Y+'px';
	}

	//For the background Container To Show pass in the Element Name
	function showContainer(element) {
		var div;
		if(document.getElementById)
		div = document.getElementById(element); 
		else if(document.all) 
		div = document.all[element]; 
			if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
			{ div.style.display = (div.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; }
			div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
			div.style.left = X+'px';
			div.style.top = Y+'px';
	}

	//For the Supr Image Only
	function showSuperImage() {
		var div;
		if(document.getElementById)
		div = document.getElementById('superImageContainer'); 
		else if(document.all) 
		div = document.all['superImageContainer']; 
			if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
			{ div.style.display = (div.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; }
			div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
			div.style.left = X+'px';
			div.style.top = Y+'px';
	}

		
	function getPageSize() {
		var xScroll, yScroll;
		 
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
		
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
		
		return [pageWidth,pageHeight];
	}

	// THIS SCRIPT POPS THE SMALL LAYER OPEN AND WHICH FADES THE BACK GROUND

	// ****************************************************************************
	

	// ****************************************************************************
	// OPEN AND CLOSES THE PRODUCT NAVIGATION
	function openLayer( layer, parentCount, countingParents ) { 
		for ( var i=1; i <= countingParents; i++ ) {
			document.getElementById('_child' + i).style.display = 'none';
			document.getElementById( 'ParentOf' + i ).className = '_parent'; 
		}

		document.getElementById('_child' + parentCount).style.display = 'block';
		document.getElementById( 'ParentOf' + parentCount ).className = '_parenton'; 

	}
	// ****************************************************************************


	// ****************************************************************************
	// Open and closes the layers at the footer
	function showMore( obj ) {
	
		var objDiv = document.getElementById("divinnertext" + obj)
		var objMore = document.getElementById("more" + obj)

		for(i=1;i<=4&&i!=obj;i++) { 	//Close all the tabs except the new one
			document.getElementById("divinnertext" + i).style.overflow = "hidden"; // Close all the divs first
			document.getElementById("divinnertext" + i).style.height = "70px"; // Reset the height
			document.getElementById("more" + i).innerHTML = "more..."; //reset the link to more
		}	
		
		objMore.innerHTML = (objDiv.style.overflow == "visible") ? "more..." : "close..."; //set the link to close
		objDiv.style.height = (objDiv.style.overflow == "visible") ? "70px" : "auto";	// Reset the height to auto. =- works in IE6 and Above and FireFox
		objDiv.style.overflow = (objDiv.style.overflow == "visible") ? "hidden" : "visible" ;	// Make the layer visible or Hidden

	}
	// ****************************************************************************


	// ****************************************************************************
	// Registration on __incRegister.asp
	function checkStep() {
		var oForm = document.customerdetails;
		var check = true;
		if( oForm.email2.value != oForm.email.value ) { check = false; alert("Your email addresses do not match"); oForm.email2.focus(); }
		if( oForm.password2.value != oForm.password.value ) { check = false; alert("Your passwords do not match"); oForm.password2.focus(); }
		if( oForm.country.value == "" ) { check = false; alert("You've not selected a country"); oForm.country.focus(); }
		if( check ) { check = validateForm( oForm ); }
		return check;
	}
	// ****************************************************************************
		

	// ****************************************************************************
	// TAKEN FROM includes __incMain.asp
	function gURL( name ) {
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		if( results == null )
			return "";
		else
			return results[1];
	}
	function showMatrix(oVal) {
		document.getElementById('pColour').value = 'WAIT';
		window.location.href = 'index.asp?display=main&category=' + gURL('category') + '&productCode=<' + gURL('productCode') + '&color=' + oVal;
	}
	function addOption(obj) {
		if(document.getElementById('pColour').value != 'WAIT') {
			document.JollimanAddtoBasket.sizeoptions.value = obj;	document.JollimanAddtoBasket.submit();
		} else {
			alert('Please wait for the page to reload before adding items to your basket.');
		}
	}
	function swapImage( code, color ) {
		//alert(color!=""); 
		//background-image: url(http://images.jolliman.co.uk/JA13_main1.jpg);
		var i = document.getElementById("MainImage");
		var p = "http://images.jolliman.co.uk/";
		
		if(color!=""){
			var rColor = color.replace(" ","")
			i.style.backgroundImage = "url(" + p + code + "_" + rColor + "_main1.jpg" + ")";
			//alert("url(" + p + code + "_" + color + "_main1.jpg)"); 
		}else{
			i.style.backgroundImage = "url(" + p + code + "_main1.jpg)";
			//alert("url(" + p + code + "_main1.jpg)"); 
		}
	}

	function zoomin( icode ) {	
	//window.open('/images/web/index.asp?code=' + icode, 'imagezoomwindow', 'height=500, width=790, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no')	
	return false;
	}
	// ****************************************************************************


	// ****************************************************************************
	// taken from shop/udcart.asp
		// <![CDATA[
		function toggleEmail(field, defaultvalue, focusing) {
			if(focusing == 1) {
				if(document.getElementById(field).value == defaultvalue) {
					document.getElementById(field).value = '';
				}
			} else {
				if(document.getElementById(field).value == '') {
					document.getElementById(field).value = defaultvalue;
				}
			}
		}
		function togglePassword(field1, field2) {
			document.getElementById(field2).style.display = 'none';
			document.getElementById(field1).style.display = 'inline';
			document.getElementById(field1).focus();
		}
		// ]]>
	// ****************************************************************************


		function validForm( oForm ) {
			var correct = true;
			if(!oForm.terms.checked) { correct = false; alert("You must agree to our terms before you can place your order.");	}
			return correct
		}


		// JIM MEAD REWROTE THIS  - why it could be used with the normal one who knows!!!
		function validateForm3( oForm ) {
			ok = validateForm( oForm, 'Please correct the errors shown above before clicking submit' );
			
			if (ok) {
				ok = (oForm.email.value + oForm.telephone.value + oForm.faxnumber.value) != '';
				if (!ok)
					alert('please provide at least one method with which we can contact you');
			}
			return ok;
		}
