/*===========================================
	GET plc JAVASCRIPT
	updated 08/11/2005 by stewart orr
---------------------------------------------
	*menus are open by default so if they 
	have js turned off, they can still use
	the menus.
	now changed so that the menus are closed
	using css, instead of trying to close them
	after page is loaded using js - stops 
	flickering.
===========================================*/

// check that it exists, if not, create (prevents errors)
try {
	currentMenu;		
}
catch(e) {
	var currentMenu="";
}
function gID(el) {
	return document.getElementById(el);	
}

function stock_check(frm) {
	if (frm.code.value=="") {
		alert("ERROR:\n\nPlease enter a PRODUCT CODE.");
		frm.code.select();
		return false;
	} else {
		return true;
	}
}

function logout() {
	if (confirm("Are you sure you want to logout?")) {
		return true;
		} else {
		return false;
	}
	
}


function confirm_delete(btn) {
	if (confirm("Are you sure you want to delete these items?")) {
		btn.form.submit()	
	}
}

function checkCatalogue(frm) {
	if (frm.pageno.value.length<1 || isNaN(frm.pageno.value)) {
		alert("ERROR:\n\nPlease enter a valid page number.");
		frm.pageno.select();
		return false;
	} else {
		return true;
	}
}

function checkOrder(frm) {
	var error = false;
	try {
		var finish = frm.finish.options[frm.finish.options.selectedIndex].value;
	}
	catch(e) {
		var finish = 0;		
	}
	if (finish==-1) {
		alert("ERROR:\n\nPlease select a FINISH for this product.");
		frm.finish.focus();
		return false;
	} else	if (frm.txtQty.value.length<1 || isNaN(frm.txtQty.value.length)) {
		alert("ERROR:\n\nPlease enter a VALID quantity.");
		frm.txtQty.select();
		return false;
	}
}

function search_check(frm) {
	var error = "";
	if (frm.searchQuery.value=="") {
		error = "Please enter search keyword or product code into the search field.\n";
	} else if (frm.searchQuery.value.length<2) {
		error = "Your search query must be 2 characters or more.";
	}
	if (error!="") {
		alert("ERROR:\n\n"+error);
		frm.searchQuery.select();
		return false;
	} else {
		return true;
	}
}

// open/close menus
function drop_menu(menu) {
	var m = gID(menu+"_menu");
	var t = gID(menu+"_link");

	if (m.style.display == "block") {
		gID(menu+"_menu").style.display = "none";
		gID(menu+"_link").title="Expand this menu";
		gID(menu+"_link").className="";
	} else {
		m.style.display="block";
		t.title="Collapse this menu";
		t.className="expanded";
	}
}

// change their link from *.html to javascript
// the html link is there for those who dont have js
function resetMenus() {
	if (gID('clipsal_link')) {
		gID("clipsal_link").href="javascript:drop_menu('clipsal')";
	}
	if (gID('tower_link')) {
		gID("tower_link").href="javascript:drop_menu('tower')";
	}
	if (gID('custom_link')) {
		gID("custom_link").href="javascript:drop_menu('custom')";
	}
	if (gID('smarthome_link')) {
		gID("smarthome_link").href="javascript:drop_menu('smarthome')";
	}
	if (gID('wiringaccessories_link')) {
		gID("wiringaccessories_link").href="javascript:drop_menu('wiringaccessories')";
	}
	if (gID('ventilationheating_link')) {
		gID("ventilationheating_link").href="javascript:drop_menu('ventilationheating')";
	}
	if (gID('lighting_link')) {
		gID("lighting_link").href="javascript:drop_menu('lighting')";
	}
}
window.onload = resetMenus;

if (document.getElementById) {	
	document.writeln('<style type="text/css">');
	if (currentMenu!="tower_menu") {
		document.write('ul#tower_menu { display: none; }');
	}
	if (currentMenu!="clipsal_menu") {
		document.write('ul#clipsal_menu { display: none; }');
	}
	if (currentMenu!="custom_menu") {
		document.write('ul#custom_menu { display: none; }');
	}
	if (currentMenu!="smarthome_menu") {
		document.write('ul#smarthome_menu { display: none; }');
	}
	if (currentMenu!="wiringaccessories_menu") {
		document.write('ul#wiringaccessories_menu { display: none; }');
	}
	if (currentMenu!="ventilationheating_menu") {
		document.write('ul#ventilationheating_menu { display: none; }');
	}
	if (currentMenu!="lighting_menu") {
		document.write('ul#lighting_menu { display: none; }');
	}
	document.writeln('</style>');
}