/*
	E-commerce site version 4.0.0
	-----------------------------

*/
var _COMMON_VERSION_=4.00;
var _COMMON_INSTANCE=1;

//----------------------- functions ----------------------------
function g(x){ return document.getElementById(x); }
function jsEval(x){
	try{
		eval(x);
	}catch(e){
		var v1=''; var v2=''; var v3=''; var str=''; var descr=false;
		for(j in e){
			if(j=='stack' || j=='number')continue;
			if((j=='message' || j=='description') && descr)continue
			if(j=='description' || j=='message')descr=true;
			str+=(j+': '+e[j])+"\n";
		}
		if(str) alert(str);
	}
	return false;
}
function gCookie(ck){
	var cVal = document.cookie;
	var cStart = cVal.indexOf(" " + ck + "=");
	if(cStart==-1)	cStart = cVal.indexOf(ck + "=");
	if(cStart == -1){
		cVal = null;
	}else{
		cStart = cVal.indexOf("=", cStart) + 1;
		var cEnd = cVal.indexOf(';', cStart);
		if(cEnd==-1) cEnd=cVal.length;
		cVal = unescape(cVal.substring(cStart,cEnd));
	}
	return cVal;
}
function sCookie(cName,cVal,cExp,cPath){
	cVal = escape(cVal);
	if(typeof cExp == 'undefined'){
		var nw = new Date();
		nw.setMonth(nw.getMonth() + 6);
		var expiry= ";expires="+nw.toGMTString();
	}else if(cExp==0){
		var expiry='';
	}else{
		var expiry=';expires='+cExp;
	}
	if(typeof cPath == 'undefined'){
		var path=';Path=/';
	}else{
		var path = ";Path="+cPath;
	}
	//if(testmode==1) alert(cName + "="+cVal + expiry+path);
	document.cookie = cName + "="+cVal + expiry+path;
}
function ow(href,w,p){
	/* v1.00
	 work to do:
	determine if the window is open and if there is unsaved data in it
	indicate in open window that a new url is coming up (gray out over window and text, moving icon pending)
	remember positions only if it works
	*/
	var params;
	if(typeof w=='undefined'){
		//develop - this is a "new" and distinct object
	}
	var reg=/^[0-9]+,[0-9]+$/;
	if(p.match(reg)){
		var a=p.split(',');
		params='width='+a[0]+',height='+a[1]+',resizable,scrollbars,menubar,statusbar';
	}else{
		params=p;
	}
	wins[w]=window.open(href,w,params);
	wins[w].focus();
	return false;
}
function in_array(needle,haystack){//about the same as the function in PHP
	strCase=1; //insensitive (2=sensitive)
	loc=10; //value (11=key)
	for(i=2;i<arguments.length;i++){
		arguments[i]=='sensitive' || arguments[i]==2?strCase=2:'';
		arguments[i]==11 || arguments[i]=='key'?loc=11:'';
	}
	//find the value
	for(j in haystack){
		if(strCase==1){
			if(loc==10 && haystack[j].toLowerCase()==needle.toLowerCase()){
				return true;
			}else if(loc==11 && j.toLowerCase()==needle.toLowerCase()){
				return true;
			}
		}else{
			if((loc==10 && haystack[j]==needle) || (loc==11 && j==needle)){
				return true;
			}
		}
	}
	return false;
}
function delete_element(array, n){//removes an element from an array by key value
  //delete the nth element of array
  var length = array.length;
  if (n >= length || n<0)
    return;
  for (var i=n; i<length-1; i++)
    array[i] = array[i+1];
  array.length--;
}
function sizeof(x){//this gets count of elements in an array
	var f=0;for(var g in x){f++;}return f;}
function unset(val, arrName){
	//both passed values are strings
	var unset_buffer = new Array();
	eval('var arr = '+arrName);
	for(var x in arr){
		if(x.toLowerCase()!==val.toLowerCase()){
			unset_buffer[x]=arr[x];
		}
	}
	eval(arrName+' = new Array();');
	eval(arrName+' = unset_buffer;');
	return false;
}
function addCartVis(ID,qty){
	//try{
	for(i in currentProducts){
		if(currentProducts[i]==ID){
			g('prod'+currentProducts[i]).style.backgroundColor='#E1DDDD';
			g('added'+currentProducts[i]).style.visibility='visible';
		}else{
			g('prod'+currentProducts[i]).style.backgroundColor='none';
			g('added'+currentProducts[i]).style.visibility='hidden';
		}
	}
	//}catch(e){ }
	//g('orderQty').innerHTML=qty;
}


function generate_date(x){
	if(typeof x=='undefined') x=3; //range 0,1,2,3
	var y=new Date();
	var l=(y.getYear().toString().length);
	var s=y.getYear().toString().substr(l-1,1);
	s+=str_pad(y.getMonth()+1,2) + str_pad(y.getDate(),2);
	s+=str_pad(y.getHours(),2) + str_pad(y.getMinutes(),2) + str_pad(y.getSeconds(),2);
	return s;
}
function generate_rand(d){
	if(typeof d=='undefined')d=8;
	var b=10;
	var s=Math.random();
	for(i=1;i<=d-1;i++)b=b*10;
	s=str_pad(parseInt(s*b).toString(),d,0,2);
	return s;
}
function str_pad(str, nbr, pad, posn){
	str=str.toString();
	if(str.length>=nbr)return str;
	if(typeof pad=='undefined')pad='0'; //pad left
	if(typeof posn=='undefined')posn=1; //pad left
	var p='';
	for(i=1; i<=nbr-str.length; i++)p+=pad;
	var o=(posn==1 ? p+''+str : str+''+p);
	return o;
}
/* GetSourceElement: find the source element of given event. */
function GetSourceElement(event){
	//---- version 1.0, by Yahav, last edit 2005-01-10
	if ((typeof event == "undefined") || (!event))
		event = window.event;
	
	if (typeof event.srcElement != "undefined")
		return event.srcElement;
	
	var node = event.target;
	while (node.nodeType != node.ELEMENT_NODE)
		node = node.parentNode;
	
	return node;
}
function GetAbsolutePosition(element, P) {
	//alert(element.nodeName+"\n"+element.offsetLeft+"\n"+element.offsetTop);
	if (typeof P == "undefined")P = new Point(0, 0);
	if (element.nodeName.toLowerCase() == "body") return P;
	if (!((element.nodeName.toLowerCase() == "tr")&&(element.parentNode.nodeName.toLowerCase() == "tbody")))
		P.x += element.offsetLeft;
	if (!((element.nodeName.toLowerCase() == "td")&&(element.parentNode.nodeName.toLowerCase() == "tr")))
		P.y += element.offsetTop;
	return GetAbsolutePosition(element.parentNode, P);
}
function Point(x, y) {
	this.x = x;
	this.y = y;
}



function adminAccessMin(){
	var d=g('amMin').innerHTML;
	if(d=='+'){
		g('amMin').innerHTML='-';
		g('amMin').title='Minimize Admin Toolbar';
		g('amBody').style.display='block';
		sCookie('amBody','block');
	}else{
		g('amMin').innerHTML='+';
		g('amMin').title='Expand Admin Toolbar';
		g('amBody').style.display='none';
		sCookie('amBody','none');
	}
	return false;
}
