function cC(ident, colour){
	if (testIsValidObject(document.getElementById(ident))) {
		var elm = document.getElementById(ident);
		elm.style.backgroundColor = colour;
	}
}

function cS(msg) {
	self.status = msg;
	return true;
}

// added 30/08/06 mpc
function setStatus() {
  var i = Math.round(4*Math.random());
  var status_message = new Array()
  status_message[0] = "Spend £75 for FREE Next Working Day Delivery";
  status_message[1] = "Check out our great knife offers starting from Any 5 for £39.95 plus a FREE Block";
  status_message[2] = "Great 7 Piece Pro Stainless Steel Cookware Set just £129.95";
  status_message[3] = "Order before 2pm and have the items by Tomorrow";
  status_message[4] = "30 Day Money Back Guarantee";
  
  window.defaultStatus = status_message[i];
}


var WindowObjectReference;
function openCenteredWindow(url, height, width, name, parms) {
	if (WindowObjectReference == null || WindowObjectReference.closed) {
	} else {
		WindowObjectReference.close();
	}

	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
	var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
	if (parms) winParms += "," + parms;

	WindowObjectReference = window.open(url, name, winParms);

	if (parseInt(navigator.appVersion) >= 4) { WindowObjectReference.window.focus(); }
	//return WindowObjectReference;
}

function tableWin(code) {
	openCenteredWindow('/messages.html?code='+code+'&mainWin=1', 500, 620, 'MessageWindow', 'scrollbars=1');
}
function imgWin(code,h,w) {
	openCenteredWindow('/messages.html?closeUp='+code, h, w, 'MessageWindow', 'scrollbars=1');
}

function update(data) {
   
	frames['updateBox'].location.href = data;
	
	return false;
}

function chQty(obj, val) {
    var sign = val;
	if (testIsValidObject(obj)) {
		if (isNaN(parseInt(this.document.getElementById(obj).value))) {
			val = val;
		} else {
			if (val == 0) {
				val = '';
			} else {
				val = parseInt(this.document.getElementById(obj).value) + val;
			}
		}
		if (val < 1) val = '';

		this.document.getElementById(obj).value = val;

		update('/messages.html?Quick=1&i='+getUID(this.document.getElementById(obj).name)+'&q='+val+'&sign='+sign);
	}
}

function chQtyD(obj) {
	if (testIsValidObject(obj)) {
		var newVal = parseInt(this.document.getElementById(obj).value);

		if (isNaN(newVal)) {
			val = '';
		} else {
			if (newVal == 0) {
				val = '';
			} else {
				val = newVal;
			}
		}
		if (val < 1) val = '';

		this.document.getElementById(obj).value = val;
		update('/messages.html?Quick=1&i='+getUID(this.document.getElementById(obj).name)+'&q='+val+'&blur=1');
	}
}

function quickAdd(i) {
	update('/messages.html?Quick=1&i='+i+'&q=1');
}

function getUID(str) {
	if (str) {
		var reg = /customerQty\[(.*)\]/i;
		var uid = reg.exec(str);
		if (uid[1].length == 11) return uid[1];
	}
	return false;
}

function testIsValidObject(objToTest) {
	if (null == objToTest) return false;
	if ("undefined" == typeof(objToTest) ) return false;
	return true;
}

// gift list functions

function chGlQty(spa_code, qty_ordered,ugl_uid, obj, val) {

	if (testIsValidObject(obj)) {
		if (isNaN(parseInt(this.document.getElementById(obj).value))) {
			val = val;
		} else {
			if (val == 0) {
				val = '';
			} else {
				val = parseInt(this.document.getElementById(obj).value) + val;
			}
		}
		if (val < 1) val = '';
        if (qty_ordered > val) val = qty_ordered;
		this.document.getElementById(obj).value = val;

		if (val < 1) {
		  var tr = document.getElementById(spa_code);
	      tr.className = 'visHide';
		}


		update('/messages.html?QuickGl=1&qty_ordered='+qty_ordered+'&ugl_uid='+ugl_uid+'&i='+getUID(this.document.getElementById(obj).name)+'&q='+val);
	}
}

function chGlQtyD(spa_code, qty_ordered, ugl_uid, obj) {

	if (testIsValidObject(obj)) {
		var newVal = parseInt(this.document.getElementById(obj).value);

		if (isNaN(newVal)) {
			val = '';
		} else {
			if (newVal == 0) {
				val = '';
			} else {
				val = newVal;
			}
		}
		if (val < 1) val = '';
        if (qty_ordered > val) val = qty_ordered;

		if (val < 1) {
		  var tr = document.getElementById(spa_code);
	      tr.className = 'visHide';
		}

		this.document.getElementById(obj).value = val;
		update('/messages.html?QuickGl=1&qty_ordered='+qty_ordered+'&ugl_uid='+ugl_uid+'&i='+getUID(this.document.getElementById(obj).name)+'&q='+val);
	}
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
	
	    document.getElementById('countdown').innerHTML=limitNum - limitField.value.length;
	}
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();




function clearValue(id) {
  document.getElementById(id).value = "";
}
