// test for object model
if(document.layers) {
	mLay = true;
	mDOM = false;
} else if(document.getElementById) {
	mLay = false;
	mDOM = true;
} else {
	mLay = false;
	mDOM = false;
}

if(document.images) {
	var imgsOff = new Array();
	var imgsOn = new Array();
	imgsOff[0] = new Image(18, 27); imgsOff[0].src = 'assets/osymb_off.jpg';
	imgsOn[0] = new Image(18, 27); imgsOn[0].src = 'assets/osymb_on.jpg';
}

/************************* DHTML STUFF */

var mnuOn = '#ff9900';
var mnuOff = '#ffcc33';

function mnu_off(no) {
	hiLite(getElem(('smnua-'+no)), mnuOff);
	hiLite(getElem(('smnub-'+no)), mnuOff);
	resetImg(('img'+no), 0)
}

function mnu_on(no) {
	hiLite(getElem(('smnua-'+no)), mnuOn);
	hiLite(getElem(('smnub-'+no)), mnuOn);
	swapImg(('img'+no), 0)
}

function hiLite(objMnu, bg) {
	var obj;
	if(!mLay)
		obj = objMnu.style;
	else
		obj = objMnu;
	obj.backgroundColor=bg;
}

function openLink(slink) {
	var sUrl;
	var l = getLink(slink);
	sUrl = l.href;
	document.location.href=sUrl;
}

function getElem(id) {
	if(mDOM)
		return document.getElementById(id);
	else
		return eval('document.all.'+id);
}

function getLink(lnk) {
	return getElem(('lnk'+lnk));
}


/************************* IMAGE STUFF */

function swapImg(imgId, imgNo) { document.images[imgId].src = imgsOn[imgNo].src; }
function resetImg(imgId, imgNo) { document.images[imgId].src = imgsOff[imgNo].src; }


/***************************************************** SUPPORT STUFF */

function trim(sVal) {
	while(sVal.charAt(sVal.length-1)==' ')
		sVal=sVal.substring(0,sVal.length-1);
	while(sVal.charAt(0)==' ')
		sVal=sVal.substring(1,sVal.length);
	return sVal;
}

// check for a valid email address
function isEmailFormatCorrect(strAddr) { 
	var ptn = /^[\w\d._%-]+@[\w\d._%-]+\.[\w\d._%-]{2,4}$/;
	return ptn.test(strAddr);
}

function popProductWindow(pid, cat, scat, pg) {
	window.open(('prodshow.asp?id='+pid+'&cat='+cat+'&scat='+scat+'&pg='+pg), 'prodshowwin', 'directories=no,hotkeys=no,location=no,resizable=yes,menubar=no,toolbar=no,scrollbars=yes,status=yes,width=640,height=500');
}

function round(num, places) {
	places = (!places ? 2 : places);
	return Math.round(num*Math.pow(10,places))/Math.pow(10,places);
}


function popWin(sUrl, w, h) {
	window.open(sUrl, '', 'directories=no,hotkeys=no,location=no,resizable=yes,menubar=no,toolbar=no,scrollbars=yes,status=yes,width='+w+',height='+h); 
}

// pops a new browser window for external websites - suppresses href by returning false
function popsite(surl) {
	window.open(surl, 'newsite', ''); 
	return false;
}
