// Fix the .toFixed bug for rounding
function Stretch(Q,L,c){var S=Q;if(c.length>0)while(S.length<L){S=c+S}return S}
function StrU(X,M,N){var T,S=new String(Math.round(X*Number("1e"+N)));if(S.search && S.search(/\D/)!=-1){return ''+X};with(new String(Stretch(S,M+N,'0')))return substring(0,T=(length-N))+'.'+substring(T);}
function Sign(X){return X<0 ? '-':'';}
function StrS(X,M,N){return Sign(X)+StrU(Math.abs(X),M,N)}
Number.prototype.toFixed=new Function('n','return StrS(this,1,n)')


var pageisloaded = false;
var openbox      = null;
var opennav      = null;
var timer        = null;
var mot=0;
var mol=0;
if (document.getElementById){
	scriptsrc=document.getElementsByTagName('script')[0].src;
	mot=parseInt(scriptsrc.substring(scriptsrc.indexOf('mot')+4,scriptsrc.indexOf('&')));
	mol=parseInt(scriptsrc.substring(scriptsrc.indexOf('mol')+4));
}

function initwindow(){checkJS();externalLinks();pageisloaded=true;}
function resizewindow(){checkZoom();}
function checkZoom() {
	if(document.getElementById('zoom')){
		document.getElementById('zoom').style.top=(getTop(document.getElementById('zoomlink'))-416)+'px';
		document.getElementById('zoom').style.left=(getLeft(document.getElementById('zoomlink'))-403)+'px';
		document.getElementById('zoom_shadow').style.top=(getTop(document.getElementById('zoomlink'))-410)+'px';
		document.getElementById('zoom_shadow').style.left=(getLeft(document.getElementById('zoomlink'))-397)+'px';
	}
}
// Change the hidden field's value (will only work if js is enabled)
function checkJS(){
	if (document.form1){
		if (document.form1.jsenabled){
			document.form1.jsenabled.value = 'yes';
		}
	}
	if(document.getElementById('priceyoupay')){
		yourprice(1);
	}
}
function tlen(t,l){if(t.value.length>l){t.value=t.value.substring(0,l);}}


function rotate(len,dir){
	test = 0;
	for(i=1;i<=len;i++){
		if(document.getElementById('img_catalog'+i).style.display == 'block'){
			document.getElementById('img_catalog'+i).style.display = 'none';
			document.getElementById('img_large'+i).style.display = 'none';
			if(i==len && dir == 1){
				document.getElementById('img_catalog1').style.display='block';
				document.getElementById('img_large1').style.display='block';
				document.getElementById('pd_imagecaption').lastChild.nodeValue='';
				document.getElementById('pd_imagecaption').appendChild(document.createTextNode(document.getElementById('img_caption1').value));
				document.getElementById('zoom_caption').lastChild.nodeValue='';
				document.getElementById('zoom_caption').appendChild(document.createTextNode(document.getElementById('img_caption1').value));
			}
			else if(i==1 && dir == -1){
				document.getElementById('img_catalog'+len).style.display='block';
				document.getElementById('img_large'+len).style.display='block';
				document.getElementById('pd_imagecaption').lastChild.nodeValue='';
				document.getElementById('pd_imagecaption').appendChild(document.createTextNode(document.getElementById('img_caption'+(len)).value));
				document.getElementById('zoom_caption').lastChild.nodeValue='';
				document.getElementById('zoom_caption').appendChild(document.createTextNode(document.getElementById('img_caption'+(len)).value));
			}
			else{
				document.getElementById('img_catalog'+(i+dir)).style.display='block';
				document.getElementById('img_large'+(i+dir)).style.display='block';
				document.getElementById('pd_imagecaption').lastChild.nodeValue='';
				document.getElementById('pd_imagecaption').appendChild(document.createTextNode(document.getElementById('img_caption'+(i+dir)).value));
				document.getElementById('zoom_caption').lastChild.nodeValue='';
				document.getElementById('zoom_caption').appendChild(document.createTextNode(document.getElementById('img_caption'+(i+dir)).value));
			}
			test=1;
			break;
		}
	}
	if(test==0){
		for(i=1;i<=len;i++){
			document.getElementById('img_catalog'+i).style.display = 'none';
			document.getElementById('img_large'+i).style.display = 'none';
		}
		if(dir == 1){
			document.getElementById('img_catalog'+2).style.display = 'block';
			document.getElementById('img_large'+2).style.display = 'block';
			document.getElementById('pd_imagecaption').lastChild.nodeValue='';
			document.getElementById('pd_imagecaption').appendChild(document.createTextNode(document.getElementById('img_caption'+2).value));
			document.getElementById('zoom_caption').lastChild.nodeValue='';
			document.getElementById('zoom_caption').appendChild(document.createTextNode(document.getElementById('img_caption'+2).value));
		}else{
			document.getElementById('img_catalog'+len).style.display = 'block';
			document.getElementById('img_large'+len).style.display = 'block';
			document.getElementById('pd_imagecaption').lastChild.nodeValue='';
			document.getElementById('pd_imagecaption').appendChild(document.createTextNode(document.getElementById('img_caption'+len).value));
			document.getElementById('zoom_caption').lastChild.nodeValue='';
			document.getElementById('zoom_caption').appendChild(document.createTextNode(document.getElementById('img_caption'+len).value));
		}
	}
}
function getTop(el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}
function getLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
}

function roll(obj,sta,lay){
  iSrc=document[obj];
  if(document.layers && lay){iSrc=document.layers[lay].document[obj];}
  if(sta.length>1){iSrc.src="img"+sta;return;}
  iSrc.src=iSrc.src.substring(0,iSrc.src.lastIndexOf('_')+1)+sta+".gif";
}
function showme(alink){
	if(pageisloaded){
		if (timer != null){clearTimeout(timer);}
		if(alink.substring(0,4) == 'link'){
			linkbox = "cat" + alink.substring(4);
		}else{
			linkbox = 'con' + alink.substring(4);
		}
		document.getElementById(alink).className='on';
		hidelast(linkbox);
		document.getElementById(linkbox).style.top=getAnchorPosition(alink).y + getAnchorPosition(alink).h + mot + "px";
		var newoffset = (getAnchorPosition(alink).x+getAnchorPosition(linkbox).w)-(getAnchorPosition('row1').x+getAnchorPosition('row1').w);
		if (newoffset < 0){newoffset=0};
		document.getElementById(linkbox).style.left=getAnchorPosition(alink).x - newoffset + mol + "px";
		openbox = linkbox;
		opennav = alink;
	}else{
		return false;
	}
}
function hidelast(linkbox){
	if(opennav != null && openbox != null && openbox != linkbox){
		document.getElementById(openbox).style.left= -500 + "px";
		document.getElementById(openbox).style.top=-1000 + "px";
		document.getElementById(opennav).className='';
	}
}
function hideme(linkbox,alink){
	document.getElementById(linkbox).style.left= -500 + "px";
	document.getElementById(linkbox).style.top=-1000 + "px";
	document.getElementById(alink).className='';
}
function hidemeslowly(alink){
	if(pageisloaded){
		if(alink.substring(0,4) == 'link'){
			linkbox = "cat" + alink.substring(4);
		}else{
			linkbox = 'con' + alink.substring(4);
		}
		timer = setTimeout('hideme(\''+linkbox+'\',\''+alink+'\')',300);
	}
	else{
		return false;
	}
}
// find element, namely anchors, position for dynamic menu navigation
function getAnchorPosition(anchorname){
	var coords=new Object(),ol=0,ot=0,ow=0,oh=0;
	if(document.getElementById || document.all){
		if(document.getElementById && document.all){var el=document.all[anchorname];}
		else if(document.getElementById){var el=document.getElementById(anchorname);}
		else if(document.all){var el=document.all[anchorname];}
		ol=el.offsetLeft;ot=el.offsetTop;ow=el.offsetWidth,oh=el.offsetHeight;		
		while((el=el.offsetParent)!=null){ol+=el.offsetLeft;ot+=el.offsetTop;}		
	}
	coords.x=ol;coords.y=ot,coords.w=ow,coords.h=oh;return coords;
}
	
var duplicatesubmit = false;

function trim(string){return(string.replace(/^\s*|\s*$/g,""));}

function CheckEmail(obj){
	var pos,atpos,lastatpos,lastperiodpos;
	var emailAddr = obj.value;
	var temp = trim(emailAddr);
	if(temp=='')return true;
	atpos=emailAddr.indexOf("@");	
  lastatpos=emailAddr.lastIndexOf("@");
	if(atpos==-1){alert("E-mail address must contain @");return false;}
	else if(atpos==0){alert("@ cannot be in first position of e-mail address");return false;}
	else if(atpos==emailAddr.length-1){alert("@ cannot be in last position of e-mail address");return false;}
	if(atpos!=lastatpos){alert("E-mail address cannot contain more than one @");return false;}
	pos=emailAddr.indexOf(".");
	lastperiodpos=emailAddr.lastIndexOf(".");
	if(atpos>lastperiodpos){alert("E-mail address must contain a period somewhere after the @");return false;}
	else if(pos==0){alert("Period cannot be in first position of e-mail address");return false;}
	else if(lastperiodpos==emailAddr.length-1){alert("Period cannot be in last position of e-mail address");return false;}
	else pos = emailAddr.indexOf("..");
	if(pos>=0){alert("E-mail address cannot contain two periods in a row");return false;}
	else pos = emailAddr.indexOf("@.");
	if(pos>=0){alert("Period cannot immediately follow @ in e-mail address");return false;}
	else pos = emailAddr.indexOf(".@");
	if(pos>=0){alert("@ cannot immediately follow period in e-mail address");return false;}
	else pos = temp.indexOf(" ");
	if(pos>=0){alert("E-mail address cannot contain spaces");return false;}
	return true;
}
function checkPostalCode(label,string){
	postalcodeok=false;
	if(string.search(/^([A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9]$)/) != -1){postalcodeok=true;}
	if(string.search(/^([A-Za-z][0-9][A-Za-z]-[0-9][A-Za-z][0-9]$)/) != -1){postalcodeok=true;}	
	if(string.search(/^([A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9]$)/) != -1){postalcodeok = true;}	
	if(!postalcodeok){alert("For "+label+", please enter a valid Canadian Postal Code of the form M5M5M5, or M5M-5M5 or M5M 5M5. Be careful not to mix up the numbers 0 (zero) and 1 (one) with the letters O (oh) and l (el).");return false;}
	return true;
}
function checkZIP(label,string){
	if(string.search(/^(\d{5}$)/) != -1){return true;}
	if(string.search(/^(\d{5}-\d{4}$)/) != -1){return true;}
	alert("For "+label+", please enter a valid US Zip Code of the form #####, or #####-####. Be careful not to mix up the numbers 0 (zero) and 1 (one) with the letters O (oh) and l (el).");
	return false;
} 

function validateaccount(){
	var fel=document.getElementById('form1');
	var alertstr='';
	if(trim(fel.firstname.value)==''){var alertstr=alertstr+'First Name is a required field.\n';}
	if(trim(fel.lastname.value)==''){var alertstr=alertstr+'Last Name is a required field.\n';}
	if(trim(fel.emailaddr.value)==''){var alertstr=alertstr+'Email Address is a required field.\n';}
	if(trim(fel.username.value)==''){var alertstr=alertstr+'Username is a required field.\n';}
	if(trim(fel.emailaddrorg.value)=='' || trim(fel.password.value)!=''){
		var digitpattern = /(\d)/g;
		var alphapattern = /([a-zA-Z])/g;
		if(trim(fel.password.value)==''){var alertstr=alertstr+'Password is a required field.\n';}
		else if(trim(fel.password.value).length < 6){var alertstr=alertstr+'Your Password must be at least 6 characters long.\n';}
		else if(trim(fel.password.value).match(digitpattern)==null
		     || trim(fel.password.value).match(alphapattern)==null){var alertstr=alertstr+'Your Password must contain at least one digit and one letter.\n';}
		else if(trim(fel.password.value) != trim(fel.confirmpassword.value)){var alertstr=alertstr+'Your password and Confirm Password do not match.\n';}
	}
	if(duplicatesubmit){var alertstr='Your transaction is being processed.\n\nPlease wait.';}
	if(!CheckEmail(fel.emailaddr)){return false;}
	if(alertstr.length > 0){alert(alertstr);return false;}
	duplicatesubmit=true;
	return true;
}

function validateaddress(){
	var fel=document.getElementById('form1');
	var alertstr='';
	if(trim(fel.shipnickname.value)==''){var alertstr=alertstr+'Address Nickname is a required field.\n';}
	if(trim(fel.shipfirstname.value)==''){var alertstr=alertstr+'First Name is a required field.\n';}
	if(trim(fel.shiplastname.value)==''){var alertstr=alertstr+'Last Name is a required field.\n';}
	if(trim(fel.shipaddress1.value)==''){var alertstr=alertstr+'Address is a required field.\n';}
	if(trim(fel.shipcity.value)==''){var alertstr=alertstr+'City is a required field.\n';}
	if(trim(fel.shipphone.value).length < 10){var alertstr=alertstr+'Phone is a required field and must contain at least 10 characters.\n';}
	if(fel.shipcountrycode.options[fel.shipcountrycode.selectedIndex].value==''){var alertstr=alertstr+'Country is a required field.\n';}
	else if(fel.shipcountrycode.options[fel.shipcountrycode.selectedIndex].value=='US' &&
	       ( "AB,BC,MB,NB,NF,NT,NS,NT,NU,ON,PE,QC,SK,YT".indexOf(fel.shipstatecode.options[fel.shipstatecode.selectedIndex].value)>=0 ||
					fel.shipstatecode.options[fel.shipstatecode.selectedIndex].value=='')){var alertstr=alertstr+'Since you selected a Country of US, please select a US state for State or Province.\n';}
	else if(fel.shipcountrycode.options[fel.shipcountrycode.selectedIndex].value=='CA' &&
	       "AB,BC,MB,NB,NF,NT,NS,NT,NU,ON,PE,QC,SK,YT".indexOf(fel.shipstatecode.options[fel.shipstatecode.selectedIndex].value)<0){var alertstr=alertstr+'Since you selected a Country of Canada, please select a Canadian province for State or Province.\n';}
	else if("US,CA".indexOf(fel.shipcountrycode.options[fel.shipcountrycode.selectedIndex].value)<0){var alertstr=alertstr+'Please choose "No Selection" for State or Province (the first choice in the list), since you did not select a Country of US or Canada.\n';}
	if(duplicatesubmit){var alertstr='Your transaction is being processed.\n\nPlease wait.';}
	if(fel.shipcountrycode.options[fel.shipcountrycode.selectedIndex].value=='US' && !checkZIP('ZIP or Postal Code',trim(fel.shipzip.value))){return false;}
	if(fel.shipcountrycode.options[fel.shipcountrycode.selectedIndex].value=='CA' && !checkPostalCode('ZIP or Postal Code',trim(fel.shipzip.value))){return false;}
	if(alertstr.length > 0){alert(alertstr);return false;}
	duplicatesubmit=true;
	return true;
}

function searchEvents(){
	var fel=document.getElementById('eventsearch');
	var alertstr='';
	if(trim(fel.q.value)==''){var alertstr=alertstr+'Please enter a search Keyword.\n';}
	if(alertstr.length > 0){alert(alertstr);return false;}
	else{document.location.href='/public.events.cfm/q/'+fel.q.value;return false;}
}

function yourprice(formtype,formel) {
	var startprice=parseFloat(document.getElementById('startprice').value);
	var form=document.getElementById('pd_form');
	for(i=0;i<form.elements.length;i++){
		if(form.elements[i].tagName.toLowerCase()=='select' && form.elements[i].value!=0){
			startprice=startprice+parseFloat(document.getElementById("optionprices"+form.elements[i].value).value);
		}
	}
	document.getElementById('priceyoupay').removeChild(document.getElementById('priceyoupay').childNodes[1]);
	document.getElementById('priceyoupay').appendChild(document.createElement("span").appendChild(document.createTextNode(startprice.toFixed(2))));
}
function validateoptions() {
	var form=document.getElementById('pd_form');
	for(i=0;i<form.elements.length;i++){
		if(form.elements[i].name.indexOf("optionschoiceid_")>=0){
			if(form.elements[i].options[form.elements[i].selectedIndex].value==0){alert("Please select a choice for each Product Option");return false;}
		}
	}
	return true;
}
function externalLinks() {
 if(!document.getElementsByTagName) return;
 var anchors=document.getElementsByTagName("a");
 for(var i=0;i<anchors.length;i++){var anchor=anchors[i];if(anchor.getAttribute("href") && anchor.getAttribute("rel")=="external"){anchor.target="_blank";}}
}
window.onload = initwindow;
window.onresize = resizewindow;