/*#################################################################################*\
'# © Copyright 2008 Netfactors Limited (www.netfactors.co.uk). All rights reserved. #
'#----------------------------------------------------------------------------------#
'# This library of routines has been developed by Netfactors Limited and is         #
'# partially customised for use on the BuzzPixels (www.buzzpixels.com) website.     #
'# Copyright of the library and any routines therein remains the property           #
'# Netfactors Limited. In the event of any amendments by third parties, this        #
'# copyright notice must be kept intact, with comments added to indicate such       #
'# amendments.                                                                      #
\*#################################################################################*/

var allowPrint = false;
addEvent(window, 'load', textAreasInitialise);
var tempImage = new Image();
tempImage.src = '/images/menuactivebg.gif';

function addEvent(eventListener, eventType, eventFunction, useCapture) {
	if (eventListener.addEventListener) {
		eventListener.addEventListener(eventType, eventFunction, useCapture);
		return true;
	} else if (eventListener.attachEvent) {
		return eventListener.attachEvent("on"+eventType, eventFunction);
	}
}

function textAreasInitialise() {
	var objectSelection = document.getElementsByTagName("textarea");
	var objectIndex;
	var currentObject;
	for (var i=0; i<objectSelection.length; i++) {
		currentObject = objectSelection[i];
		if (currentObject.getAttribute('maxlength')) {
			currentObject.onkeyup = forceMaxLength;
			currentObject.onpaste = forceMaxLength;
		}
	}
}

function forceMaxLength() {
	var maxLength = parseInt(this.getAttribute('maxlength'));
	if (this.value.length > maxLength) {
		this.value = this.value.substring(0,maxLength);
	}
}

function addThousandsSeparator(value) {
	var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
	while (sRegExp.test(value)) {
		value = value.replace(sRegExp,'$1,$2');
	}
	return value; 
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if (typeof( window.pageYOffset ) == 'number') {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX,scrOfY];
}

function showInfoBox(windowEvent, sourceInfoBox) {
	if ((document.getElementById('infobox')) && (document.getElementById(sourceInfoBox))){
		if (!windowEvent) {
			var windowEvent = window.event;
		}
		var infoBox = document.getElementById('infobox');
		var mainBox = document.getElementById('pixeladgridouter');
		infoBox.innerHTML = '<table style="background-color:#FFFFFF;border:1px solid #557299"><tr><td style="padding-left:10px;padding-right:10px;padding-top:14px;padding-bottom:19px;white-space:nowrap">' + document.getElementById(sourceInfoBox).innerHTML + '</td></tr></table>';
		if (windowEvent.clientX + getScrollXY()[0] - mainBox.offsetLeft - 16 - infoBox.clientWidth > 0) {
			infoBox.style.left = (windowEvent.clientX + getScrollXY()[0] - mainBox.offsetLeft - 16 - infoBox.clientWidth) + 'px';
		} else {
			infoBox.style.left = (windowEvent.clientX + getScrollXY()[0] - mainBox.offsetLeft + 16) + 'px';
		}
		//alert(getScrollXY());
		infoBox.style.top = (windowEvent.clientY + getScrollXY()[1] - mainBox.offsetTop + 16) + 'px';
		infoBox.style.display = 'block';
	}
}

function hideInfoBox(e) {
	if (document.getElementById('infobox')) {
		document.getElementById('infobox').style.display = 'none';
	}
}

function popupOrderDetailsWin() {
	window.open('','orderdetailswin','width=700,height=600,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=no');
}

function printPage() {
	if (allowPrint) {
		window.print();
	}
}

function closeWindow() {
	window.close();
}

function selectAndCopy(textAreaItem) {
	textAreaItem.select();
	//window.clipboardData.setData('Text',textAreaItem.value);
}