function XI_obj(n) { 
	var x,d=document;
	if(x=d.getElementById(n)) return x;
	if(d.getElementsByName(n).length>0) return d.getElementsByName(n)[0];
}


function XI_nav(evt) {
	var m, mStr, s, sStr, o, d=document;
	if(!evt) evt=window.event; if(!evt) s=''; else { if(evt.target) s=evt.target.id.substr(3); else s=evt.srcElement.id.substr(3) }
	if(!d.vis) d.vis = new Array();
	while((m=d.vis.pop())&&m!=s.substr(0,m.length)) {
		mStr='mnu'+m; if((o=XI_obj(mStr))!=null) o.className='popH';
		mStr='nav'+m; if((o=XI_obj(mStr))!=null&&o.className.indexOf("CUR")<0) { if(m.split('|').length==2) o.className='btnDES'; else o.className='btnPDES'; }
	}
	if(m) d.vis.push(m);
	if(m!=s) {
		sStr='mnu'+s; 
		if((o=XI_obj(sStr))!=null) {
			o.className='popV';
			sStr='nav'+s; if((o=XI_obj(sStr))!=null&&o.className.indexOf("CUR")<0) { if(s.split('|').length==2) o.className='btnSEL'; else o.className='btnPSEL'; }
			d.vis.push(s);
		}
	}
	if(d.menuTimer) clearTimeout(d.menuTimer);
	else clearTimeout();
}
function XI_nonav() {
	var d=document;
	if(!d.menuTimer) d.menuTimer = new Number();
	d.menuTimer = setTimeout("XI_nav()", 400);
}
function XI_windowOpen(n, w, h, t, l) {
	var winStr, d=document;
	winStr="screenX="+l+",screenY="+t+",left="+l+",top="+t+",width="+w+",height="+h+",resizable=1,scrollbars=1";
	d.popupwin=window.open(n,'profkeyschild',winStr);
	d.popupwin.focus();
}
function XI_popupOpen(n, w, h, t, l) {
  var oStr, popupStr, winStr, f, o, r, d=document;
	if(!t) t=50; if(!l) l=50;
	popupStr="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<html>\r\n";
	popupStr+="<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\r\n";
	popupStr+="<title>ProfKeyS</title>\r\n";
	popupStr+="<link href=\"stylesheets/t1_pg.css\" rel=\"stylesheet\" type=\"text/css\">\r\n";
	popupStr+="</head>";
	popupStr+="<body onUnload=\"self.close()\">\n";
	oStr='PopupFrame'+n;
	if((o=XI_obj(oStr))!=null) popupStr+=o.innerHTML+"\r\n";
	popupStr+="\r\n</body>\r\n</html>";
	winStr="screenX="+l+",screenY="+t+",left="+l+",top="+t+",width="+w+",height="+h+",resizable=1,scrollbars=1";
	d.popupwin=window.open('','profkeyschild',winStr);
	d.popupwin.document.open();
	d.popupwin.document.write(popupStr);
	d.popupwin.document.close();
	d.popupwin.focus();
}
function XI_popupClose() {
	var d=document;
	if(d.popupwin) d.popupwin.close();
}

function XI_UP() {
	var i, j, o, s, pm=-1, m, rm, p, oStr, d=document, t=0;
	if(!d.option) return;
	for(i=0;i<d.option.length;i++) {
		//find out if it is selected
		s=false;
		if(!d.option[i].opt) s=true;
		else { 
			oStr='option'+d.option[i].id;
			if((o=XI_obj(oStr))!=null) { 
				if(o.checked) s=true;
			}
		}
		if(d.option[i].ps) {
			//1. set whether it price is active or not depending on opt
			oStr='price'+d.option[i].id;
			if((o=XI_obj(oStr))!=null) { 
				if(s) o.className='pricesel';
				else o.className='pricenosel';
			}
			//2. then set/record the textbox if there is one depending on mlinked and previous textbox existence
			m=-1;
			oStr='marg'+d.option[i].id;
			if((o=XI_obj(oStr))!=null) { 
				if(pm>=0&&d.option[i].mlinked) { if(o.value!=pm) { if(o.disabled) o.disabled=false; o.value=pm; } o.disabled=true; }
				else { o.disabled=!s; if(s) pm=o.value; }
				m=o.value;
			}
			//3. then set the price
			oStr='price'+d.option[i].id;
			if((o=XI_obj(oStr))!=null) { 
				var sys=d.system[d.option[i].ps];
				if(m<0) {
					if(sys[0].price<0) { o.innerHTML="*"; if(s) t="*"; }
					else { 
						o.innerHTML=sys[0].price.toFixed(2);
						if(t!="*"&&s) t+=sys[0].price;
					}
				}
				else {
					p=0; rm=m;
					for(j=(sys.length-1);j>=0;j--) {
						if(sys[j].q<=rm) {
							if(sys[j].price<0) { p="*"; break; }
							if(sys[j].type==1) { p+=(rm*sys[j].price); break; }
							else { 
								if(sys[j].type==0) { p+=sys[j].price; break; }
								else {
									p+=((rm-sys[j].q+1)*sys[j].price); 
									rm=sys[j].q-1;
								}
							}
						}
					}
					if(p=="*") { o.innerHTML="*"; if(s) t="*"; }
					else {
						o.innerHTML=p.toFixed(2); 
						if(t!="*"&&s) t+=p;
					}
				}
			}
		}
		//4. then add to prodcode string
		if((o=XI_obj('po'))!=null&&s) {
			if(i==0) o.value="";
			o.value=o.value+'|'+d.option[i].id;
			if(m>=0) o.value=o.value+'['+m+']';
		}
	}
	if((o=XI_obj('pricetotal'))!=null) {
		if(t=="*") o.innerHTML=t;
		else o.innerHTML=t.toFixed(2);
	}
}
function XI_PI() {
	var o;
	if((o=XI_obj('pinfodiv'))!=null) { p=o.style; p.height=o.scrollHeight+'px'; p.overflow="visible"; }
	if((o=XI_obj('orderbutton'))!=null) { o.disabled="true"; }
}
function XI_UB(j) {
	var i, o, oStr, e=false, d=document;
	if(!d.pcoption) return e;
	for(i=0;i<d.pcoption.length;i++) {
		if(d.pcoption[i].box!="none") {
			oStr=j+'option'+d.pcoption[i].id+'_'+d.pcoption[i].box;
			if((o=XI_obj(oStr))!=null) {
				oStr=j+'option'+d.pcoption[i].id+'_curfile';
				if(o.value==""&&XI_obj(oStr)==null) {
					if(!d.pcoption[i].opt) e=true;
					else {
						oStr=j+'option'+d.pcoption[i].id;
						if((o=XI_obj(oStr))!=null&&o.checked) { 
							if(o.type=="checkbox") o.checked=false;
							else e=true;
						}
					}
				}
				else {
					if(d.pcoption[i].box=="filebox"&&o.value!=""&&o.value.indexOf("\\")<0&&o.value.indexOf("/")<0) e=true;
					if(d.pcoption[i].opt&&o.value!="") {
						oStr=j+'option'+d.pcoption[i].id;
						if((o=XI_obj(oStr))!=null) { 
							if(o.type=="checkbox") o.checked=true;
						}
					}
				}
			}
		}
	}
	return e;
}
function XI_SP(j, wtext, etext) {
	var i, o, e, oStr, d=document;
	if(XI_UB(j)) {
		alert(wtext);
		return false;
	}
	if(d.pcoption) {
		if(j=='c') {
			e="";
			for(i=0;i<d.pcoption.length;i++) {
				if(d.pcoption[i].email) {
					oStr='coption'+d.pcoption[i].id+'_'+d.pcoption[i].box;
					if((o=XI_obj(oStr))!=null) { 
						if(e=="") e=o.value;
						else { 
							if(e!=o.value) {
								alert(etext);
								return false;
							}
						}
					}
				}
			}
		}
		for(i=0;i<d.pcoption.length;i++) {
			if(d.pcoption[i].box!="none"&&d.pcoption[i].opt) {
				oStr=j+'option'+d.pcoption[i].id;
				if((o=XI_obj(oStr))!=null) { 
					if(!o.checked) {
						oStr=j+'option'+d.pcoption[i].id+'_'+d.pcoption[i].box;
						if((o=XI_obj(oStr))!=null) o.disabled=true;
						oStr=j+'option'+d.pcoption[i].id+'_curfile';
						if((o=XI_obj(oStr))!=null) o.disabled=true;
					}
				}
			}
		}
	}
	if((o=XI_obj('rd'))!=null) o.value=Math.random();
	if((o=XI_obj('cmd_addcartitem'))!=null) o.style.visibility='hidden';
	if((o=XI_obj('cmd_addcheckoutcinfo'))!=null) o.style.visibility='hidden';
	if((o=XI_obj('submitmessage'))!=null) o.style.visibility='visible';
	return true;
}
function XI_SC(f, a) {
	var d=document;
	d.forms.namedItem(f).action=a;
}
function XI_PC(f, a, b) {
	var o, oStr, d=document;
	oStr="payoption1";
	if((o=XI_obj(oStr))!=null&&o.checked) d.forms.namedItem(f).action=a;
	else d.forms.namedItem(f).action=b;	
}
function XI_OT() {     
	// Order Toggle for admin/orders.php
	// this activates input fields when a checkbox is selected, or resets them with default information
	// pass the name/id of the calling checkbox first,
	// then in pairs the name/id of the hidden input containing the default information
	// and the actual input to modify
	var oStr, o, c, h, d=document;
	for(i=0;i<arguments.length;i++) {
		oStr=arguments[i];
		if((o=XI_obj(oStr))!=null||(o=d.forms.namedItem(oStr))!=null) {
			if(i==0) c=o.checked;
			else { 
				if(i%2==1) h=o.value;
				else {
					if(!c) {
						if(o.type=="checkbox") o.checked=(h=="true");
						else o.value=h;
					}
					o.disabled=!c;
				}
			}
		}
	}
}
function XI_DT() {     
	// Delete Toggle for admin/orders.php
	// this disables input fields when a checkbox is selected, reseting them with default information
	// pass the name/id of the calling checkbox first,
	// then the name of the order toggle checkbox,
	// then in pairs the name/id of the hidden input containing the default information
	// and the input itself
	var oStr, o, c, h, d=document;
	for(i=0;i<arguments.length;i++) {
		oStr=arguments[i];
		if((o=XI_obj(oStr))!=null||(o=d.forms.namedItem(oStr))!=null) {
			if(i==0) c=o.checked;
			else {
				if(i==1) { 
					if(c) {
						o.checked=false; 
						o.disabled=true;
					}
					else o.disabled=false;
				}
				else {
					if(i%2==0) h=o.value;
					else {
						if(c) {
							if(o.type=="checkbox") o.checked=(h=="true");
							else o.value=h;
						}
						o.disabled=true;
					}
				}
			}
		}
	}
}
