function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function pop(h, w, p, n, s, r){
	var theHeight=h;
	var theWidth=w;
	var theTop=(screen.height/2)-(theHeight/2)
	var theLeft=(screen.width/2)-(theWidth/2)
	var	features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;
	var winPop = window.open(p,"PopUp","scrollbars="+s+","+features+",resizable="+r+"");
	if (winPop){
		winPop.focus();
	}else{
		alert("This site makes use of pop up windows.\nPlease enable pop ups for our site.\nNo pop up advertising is ever used on our site.");
	}
}

function PrintIt(idno, what){
	pop(545, 650, "pop_print.asp?ref_idno="+idno+"&tablename="+what, "WindowPrint", "yes", "yes");
}


function processKey(f) {
    var keyvalue = window.event.keyCode;
    if (keyvalue==13) f.submit();
}


function product(product_idno, cat_idno){
	pop(545, 650, "pop_product.asp?NoBack=Y&cat_idno="+cat_idno+"&product_idno="+product_idno, "ProductWindow", "yes", "no");
}


function FormatNumber(Number,Decimals,Separator)
{
 Number += ""          // Force argument to string.
 Decimals += ""        // Force argument to string.
 Separator += ""       // Force argument to string.
 if((Separator == "") || (Separator.length > 1))
  Separator = "."
 if(Number.length == 0)
  Number = "0"
 var OriginalNumber = Number  // Save for number too large.
 var Sign = 1
 var Pad = ""
 var Count = 0
 // If no number passed, force number to 0.
 if(parseFloat(Number)){
  Number = parseFloat(Number)} else {
  Number = 0}
 // If no decimals passed, default decimals to 2.
 if((parseInt(Decimals,10)) || (parseInt(Decimals,10) == 0)){
  Decimals = parseInt(Decimals,10)} else {
  Decimals = 2}
 if(Number < 0)
 {
  Sign = -1         // Remember sign of Number.
  Number *= Sign    // Force absolute value of Number.
 }
 if(Decimals < 0)
  Decimals *= -1    // Force absolute value of Decimals.
 // Next, convert number to rounded integer and force to string value.
 // (Number contains 1 extra digit used to force rounding)
 Number = "" + Math.floor(Number * Math.pow(10,Decimals + 1) + 5)
 if((Number.substring(1,2) == '.')||((Number + '')=='NaN'))
  return(OriginalNumber) // Number too large to format as specified.
 // If length of Number is less than number of decimals requested +1,
 // pad with zeros to requested length.
 if(Number.length < Decimals +1) // Construct pad string.
 {
  for(Count = Number.length; Count <= Decimals; Count++)
   Pad += "0"
 }
 Number = Pad + Number // Pad number as needed.
 if(Decimals == 0){
  // Drop extra digit -- Decimal portion is formatted.
  Number = Number.substring(0, Number.length -1)} else {
  // Or, format number with decimal point and drop extra decimal digit.
 Number = Number.substring(0,Number.length - Decimals -1) +
          Separator +
          Number.substring(Number.length - Decimals -1,
          Number.length -1)}
 if((Number == "") || (parseFloat(Number) < 1))
  Number="0"+Number // Force leading 0 for |Number| less than 1.
 if(Sign == -1)
  Number = "-" + Number  // Set sign of number.
 return(Number)
}

function newWindow(oPage, oW, oH, oScroll){
	xpos 								= (screen.width) ? (screen.width - oW)/2 : 0;
	ypos 								= (screen.height) ? (screen.height - oH)/2 : 0;
	
	if (oScroll == 'Y')
		window.open(oPage,"newWin","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+oW+",height="+oH+",left="+xpos+",top="+ypos);
	else
		window.open(oPage,"newWin","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+oW+",height="+oH+",left="+xpos+",top="+ypos);
}

function addCart(oID) {
	var f;

	if (document.all) {
		// old IE
		f = document.TheForm;
	} else {
		// standards compliant
		f = document.getElementById('TheForm');
	}

	if (f.color) {
		if (f.color.options[f.color.selectedIndex].value == "") {
			alert("This product requires that you make a choice among its options. Please use the drop-down selector to make your choice before continuing");
			f.color.focus();
			return false;
		} else {
			var col = f.color.options[f.color.selectedIndex].value;
		}
	}
		
	if (f.size) {
		if (f.size.options[f.size.selectedIndex].value == "") {
			alert("This product requires that you make a choice among its options. Please use the drop-down selector to make your choice before continuing");
			f.size.focus();
			return false;
		} else {
			var siz = f.size.options[f.size.selectedIndex].value;
		}
	}

	f.submit();
	return true;
}

function ship_check(oBox, oForm) {
	if (oBox.checked == true) {
		oForm.ship_fname.value 				= oForm.fname.value;
		oForm.ship_lname.value 				= oForm.lname.value;
		oForm.ship_address1.value 			= oForm.bill_address1.value;
		oForm.ship_address2.value 			= oForm.bill_address2.value;
		oForm.ship_city.value 				= oForm.bill_city.value;
		oForm.ship_state.selectedIndex		= oForm.bill_state.selectedIndex;
		oForm.ship_zip.value 				= oForm.bill_zip.value;
		oForm.ship_phone.value 				= oForm.bill_phone.value;
	}
}

function valLoginForm(oForm) {
	if (oForm.email.value.search("@") == -1 || oForm.email.value.search("[.*]") == -1){
		formError('Please enter a valid E-mail Address.', oForm.email)
		return;
	}
	if (oForm.password.value == ""){
		formError('Please enter your Password.', oForm.password)
		return;
	}
	oForm.submit();
}	


function valAccForm(oForm) {
	if (oForm.fname.value == ""){
		formError('Please enter your Billing First Name.', oForm.fname)
		return;
	}
	if (oForm.lname.value == ""){
		formError('Please enter your Billing Last Name.', oForm.lname)
		return;
	}
	if (oForm.bill_address1.value == ""){
		formError('Please enter your Billing Address.', oForm.bill_address1)
		return;
	}
	if (oForm.bill_city.value == ""){
		formError('Please enter your Billing City.', oForm.bill_city)
		return;
	}
	if (oForm.bill_state.options[oForm.bill_state.selectedIndex].value == ""){
		formError('Please select your Billing State.', oForm.bill_state)
		return;
	}
	if (oForm.bill_zip.value == ""){
		formError('Please enter your Billing Zip.', oForm.bill_zip)
		return;
	}
	if (oForm.bill_phone.value == ""){
		formError('Please enter your Billing Phone.', oForm.bill_phone)
		return;
	}
	if (oForm.ship_fname.value == ""){
		formError('Please enter your Shipping First Name.', oForm.ship_fname)
		return;
	}
	if (oForm.ship_lname.value == ""){
		formError('Please enter your Shipping Last Name.', oForm.ship_lname)
		return;
	}
	if (oForm.ship_address1.value == ""){
		formError('Please enter your Shipping Address.', oForm.ship_address1)
		return;
	}
	if (oForm.ship_city.value == ""){
		formError('Please enter your Shipping City.', oForm.ship_city)
		return;
	}
	if (oForm.ship_state.options[oForm.ship_state.selectedIndex].value == ""){
		formError('Please select your Shipping State.', oForm.ship_state)
		return;
	}
	if (oForm.ship_zip.value == ""){
		formError('Please enter your Shipping Zip.', oForm.ship_zip)
		return;
	}
	if (oForm.ship_phone.value == ""){
		formError('Please enter your Shipping Phone.', oForm.ship_phone)
		return;
	}
	if (oForm.email.value.search("@") == -1 || oForm.email.value.search("[.*]") == -1){
		formError('Please enter a valid E-mail Address.', oForm.email)
		return;
	}
	if (oForm.pass1.value == "" || oForm.pass1.value != oForm.pass2.value){
		formError('Please enter matching passwords.', oForm.pass1)
		return;
	}
	
	oForm.submit();
}


function valCCForm(oForm) {
	if (oForm.cc_type.options[oForm.cc_type.selectedIndex].value == ""){
		formError('Please select your Card Type.', oForm.cc_type)
		return;
	}
	if (oForm.cc_number.value == ""){
		formError('Please enter your Card Number.', oForm.cc_number)
		return;
	}
	if (oForm.cc_number.value.length < 8){
		formError('Please enter your Card Number.', oForm.cc_number)
		return;
	}
	if (oForm.cc_expm.options[oForm.cc_expm.selectedIndex].value == ""){
		formError('Please select your Expiration Month.', oForm.cc_expm)
		return;
	}
	if (oForm.cc_expy.options[oForm.cc_expy.selectedIndex].value == ""){
		formError('Please select your Expiration Year.', oForm.cc_expy)
		return;
	}
	
	oForm.submit();
}


function formError(oMsg, oField) {
	alert(oMsg);
	oField.focus();
}