/*
Reusable Javascript functions
First created 22/10/1999 Robert Seber
*/

function initialise_handlers(){
	//Put here to avoid error messages
}

function popUpHelp(){
	// Pops up a help window
	if (!window.helplink) helplink = "nohelpavailable";
	popUpWindow('/help3.asp?filename='+helplink,'helpcenter','width=315,height=400,scrollbars');
}

function popUpContactUs(){
	// Pops up a contact us window
	popUpWindow('/phoneme.asp','callcentre','width=400,height=555,scrollbars');
}

function popUpContactUsHot(){
	popUpWindow('/PhoneMeHot.asp','Hotdeals','width=400,height=560,scrollbars');
}

function popUpWindow(theURL,winName,features) {
	// Behaves just like window.open() but ensures visible child windows
	closePopUpWindow();
	openedWindow = open(theURL,winName,features+",left=0,top=0,screenX=0,screenY=0");
	openedWindow.onunload = confirmClosed;
	onunload = closePopUpWindow;
	windowOpen = true;
	return (openedWindow);
}
function closePopUpWindow(){
	// Closes a window's child window
	if (window.windowOpen){
		openedWindow.close();
		confirmClosed();
	}
}
function confirmClosed(){
	// Used to confirm when the child window is closed
	windowOpen = false;
}

function popUpLiveChat() {
	openedWindow = open("/nameaddresshtml.asp?filename=general.LiveAssistance.index","LiveChat","width=400,height=400,scrollbars=no");
}

function addKeyPressHandler(keyNumber,functionString){
	// Allows multiple keyboard shortcuts in Internet Explorer
	if (!window.keyPressHandlerArray) keyPressHandlerArray = new Array();
	keyPressHandlerArray[keyNumber] = functionString;
	if (navigator.appVersion && navigator.appName){
		if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4){
			document.onkeypress = new Function("eval(keyPressHandlerArray[window.event.keyCode])");
		}
	}
}

function poundFormat(number){
	// Returns a number as a pound formatted string
	var neg = "";
	if (number<0){
		number = -number;
		var neg = "-";
	}
	var pounds = Math.floor(number);
	var pence = Math.round(100*(number - pounds));
	if (pence<10) pencestring = "0"+pence.toString();
	else pencestring = pence.toString()+"0";
	return (neg+"£"+pounds+"."+pencestring.substring(0,2));
}

function getSelectValue(select){
	// Returns the value of a select object
	return select.options[select.selectedIndex].value;
}

function getSelectText(select){
	// Returns the text of a select object
	return select.options[select.selectedIndex].text;
}

function setSelectValue(select,value){
	// Sets the value of a select object
	for (var c=0;c<select.options.length;c++){
		if (select.options[c].value==value){
			select.selectedIndex = c;
		}
	}
}

function validDate(day,month,year){
	// Returns true if the day, month and year are possible (i.e. not 30/2/2000)
	var monthsArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
	if (typeof(month)=="string"){
		month = month.toLowerCase();
		for (var i=0;i<monthsArray.length;i++){
			if (month==monthsArray[i]) month = i;
		}
	}
	else{
		month--;
	}
	var dt = new Date(year,month,day);
	if (dt.getDate()==day && dt.getMonth()==month && dt.getFullYear()==year) return true;
	else return false;
}

function objectExists(objectAsString){
	// Returns true if the object exists
	var ob = window;
	var subob = objectAsString.split(".");
	for (var i=0;i<subob.length;i++){
		ob = ob[subob[i]];
		if (ob==null) return false;
	}
	return true;
}