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_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 MM_showHideLayers() { //v6.0
  document.images["imgenlarged"].src = 'images/blank.gif'; 
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function ShowLargeImg(thisimg, thislayer, largeimg) {
				x = s_getStart("x", thisimg);
				y = s_getStart("y", thisimg);
			  	objlayer = MM_findObj(thislayer);
				objlayer.style.left = x-1;
				objlayer.style.top = y-1;
				MM_showHideLayers(thislayer,'','show');
				document.images["imgenlarged"].src = largeimg;
				
}

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_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 SubmitForm(thisform) {
	document.form1.submit();
}


// SAMPLE FUNCTION USED FOR RELATIVE POSITIONING
s_ua=navigator.userAgent.toLowerCase();
s_dl=document.getElementById?1:0;
s_iE=document.all&&!window.innerWidth&&s_ua.indexOf("msie")!=-1?1:0;
s_oP=s_ua.indexOf("opera")!=-1&&document.clear?1:0;
s_oP7=s_oP&&document.appendChild?1:0;
s_oP7m=s_oP&&!s_oP7?1:0;
s_nS=s_dl&&!document.all&&s_ua.indexOf("opera")==-1?1:0;
s_nS4=document.layers?1:0;
s_kNv=s_ua.indexOf("konqueror")!=-1?parseFloat(s_ua.substring(s_ua.indexOf("konqueror/")+10)):0;
s_kN=s_kNv>=2.2?1:0;s_kN3p=s_kNv>=3?1:0;
s_kN31p=s_kNv>=3.1?1:0;s_kN32p=s_kNv>=3.2?1:0;
s_mC=s_ua.indexOf("mac")!=-1?1:0;
s_sF=s_mC&&s_ua.indexOf("safari")!=-1?1:0;
s_iE5M=s_mC&&s_iE&&s_dl?1:0;
s_iE4M=s_mC&&s_iE&&!s_dl?1:0;
s_iE4=!s_mC&&s_iE&&!s_dl?1:0;
s_ct=0;

function s_getStart(a, img){

var bodyStyleMarginTop=0;// specify manually to kill a bug in Opera 5/6

var o=document.images[img];if(!o)return a=="x"?-630:0;

if(s_nS4)return a=="x"?o.x:o.y;
var oP,oC,ieW;oP=o.offsetParent;oC=a=="x"?o.offsetLeft:o.offsetTop;
ieW=s_iE&&!s_mC?1:0;
while(oP){if(ieW&&oP.tagName&&oP.tagName.toLowerCase()=="table"&&oP.border&&oP.border>0)oC++;oC+=a=="x"?oP.offsetLeft:oP.offsetTop;oP=oP.offsetParent};
if(s_kN31p&&!s_kN32p){return a=="x"?(document.body.style&&document.body.style.marginLeft?parseInt(document.body.style.marginLeft)+oC:document.body.marginWidth?parseInt(document.body.marginWidth)+oC:document.body.leftMargin?parseInt(document.body.leftMargin)+oC:oC+10):(document.body.style&&document.body.style.marginTop?parseInt(document.body.style.marginTop)+oC:document.body.marginHeight?parseInt(document.body.marginHeight)+oC:document.body.topMargin?parseInt(document.body.topMargin)+oC:oC+10)};
return s_oP7m?a=="x"?oC:oC+bodyStyleMarginTop:s_iE5M?a=="x"?oC+parseInt(document.body.currentStyle.marginLeft):oC+parseInt(document.body.currentStyle.marginTop):oC};
/*
 All browsers have problems with finding the real position of an
 element on the page in certain cases. I have tried to go round some
 browser bugs with the above function- that's why it's so long & complex.
*/
// SAMPLE FUNCTION USED FOR RELATIVE POSITIONING


//Fuctions to mimmick LTrim,  RTrim, and Trim...
//==================================================================
//LTrim(string) : Returns a copy of a string without leading spaces.
//==================================================================
function LTrim(str)
/*
        PURPOSE: Remove leading blanks from our string.
        IN: str - the string we want to LTrim
*/
{
        var whitespace = new String(" \t\n\r");

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(0)) != -1) {
            // We have a string with leading blank(s)...

            var j=0, i = s.length;

            // Iterate from the far left of string until we
            // don't have any more whitespace...
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                j++;


            // Get the substring from the first non-whitespace
            // character to the end of the string...
            s = s.substring(j, i);
        }

        return s;
}

//==================================================================
//RTrim(string) : Returns a copy of a string without trailing spaces.
//=================================================================//=
function RTrim(str)
/*
        PURPOSE: Remove trailing blanks from our string.
        IN: str - the string we want to RTrim

*/
{
        // We don't want to trip JUST spaces, but also tabs,
        // line feeds, etc.  Add anything else you want to
        // "trim" here in Whitespace
        var whitespace = new String(" \t\n\r");

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            // We have a string with trailing blank(s)...

            var i = s.length - 1;       // Get length of string

            // Iterate from the far right of string until we
            // don't have any more whitespace...
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;


            // Get the substring from the front of the string to
            // where the last non-whitespace character is...
            s = s.substring(0, i+1);
        }

        return s;
}


//=============================================================
//Trim(string) : Returns a copy of a string without leading or trailing spaces
//=============================================================
        function Trim(str)
        /*
                PURPOSE: Remove trailing and leading blanks from our string.
                IN: str - the string we want to Trim

                RETVAL: A Trimmed string!
        */
        {
                return RTrim(LTrim(str));
        }

//######### LockSelected #########/////////////////////
//This function will change the "disabled" status of the field. 
//theform: form object
//fieldprefixstr: a list of field name prefixes separated by comma. 
//Note that "field_1" will match "field1_1", "field_11", "field_123", etc.
//lockstatus: "lock" - disable the fields; "unlock" - enable the fields.
function LockToggle(thisform, fieldprefixstr, lock) {
	var fieldprefixarr = fieldprefixstr.split(",");
	for (m=0; m<fieldprefixarr.length; m++) {
		fieldprefix = Trim(fieldprefixarr[m]);
		for (n=0; n<thisform.elements.length; n++) {
		fieldname = thisform.elements[n].name;
		if (fieldname.indexOf(fieldprefix) == 0) {
			//if (thisform.elements[n].disabled == false) {
			if (lock == true) {
				ClearField(thisform.elements[n]);
				thisform.elements[n].disabled = true;
				}
			else {
				if (fieldname.indexOf("othertext") == -1 ) {
					thisform.elements[n].disabled = false;
					}
				}
			}
		}
	}
}
//######### LockSelected #########/////////////////////

//######### ClearSelected #########/////////////////////
//Will clear the value of multiple fields. 
//fieldprefixstr: a list of field prefixes that will be cleared
//excludefield: field to be excluded from clearing.
function ClearSelected(thisform, fieldprefixstr, excludefield) {
	var fieldprefixarr = fieldprefixstr.split(",");
	for (m=0; m<fieldprefixarr.length; m++) {
		fieldprefix = Trim(fieldprefixarr[m]);
		for (n=0; n<thisform.elements.length; n++) {
			fieldname = thisform.elements[n].name;
			if (fieldname.indexOf(fieldprefix) == 0 && fieldname != excludefield) {
				ClearField(thisform.elements[n]);
				if (fieldname.indexOf("othertext") != -1 ) {
					thisform.elements[n].disabled = true;
					}
			}
		}
	}
}

//######### ClearField #########/////////////////////
function ClearField(thisfield) {
	if (thisfield.type == "text") {
		thisfield.value = "";
	}
	if (thisfield.type == "textarea") {
		thisfield.value = "";
	}
	if (thisfield.type == "checkbox") {
		thisfield.checked = false;
	}
	if (thisfield.type == "radio") {
		thisfield.checked = false;
	}
}

function validEmail(email) {
	 invalidChars = " /:,;"
	
	if (email == "") {	// cannot be empty
	    //alert("Please enter your email address.");
	    return false
         }
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
	badChar = invalidChars.charAt(i)
	if (email.indexOf(badChar,0) > -1) {
	   return false
	}
      }
      atPos = email.indexOf("@",1)	// there must be one "@" symbol
      if (atPos == -1) {
	 return false
      }
      if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
	  return false
      }
      periodPos = email.indexOf(".",atPos)
      if (periodPos == -1) {			// and at least one "." after the "@"
	 return false
      }
      if (periodPos+3 > email.length)	{ // must be at least 2 characters after the "."
	 return false
      }
      return true
}

function IsQty(){
var e = 0;
var w = 0;
var quantity;
if (document.form1.qty.value != "") {
	quantity = parseInt(document.form1.qty.value);
	if (quantity != 0 && !isNaN(parseInt(document.form1.qty.value))) {
		document.form1.qty.value = quantity;
		}
		else { 
		alert("Please enter a valid quantity.");
		document.form1.qty.value = "";
		document.form1.qty.focus();
		}
	}
}

function GetQty() {
var qty;
if (parseInt(document.form1.qty.value) != 0 && !isNaN(parseInt(document.form1.qty.value))) {
	qty = parseInt(document.form1.qty.value);
	}
	else { 
	qty = 0;
	}
return qty;
}

function CalculateSubTotal() {
var qty;
var unitprice, shippingrate;
var subtotal;
qty = GetQty();
unitprice = document.form1.unitprice.value;
shippingrate = document.form1.ShippingRate.value;
subtotal = qty * unitprice;

var a, i, pcc;
a = document.getElementsByName("papercolor");
//a =	document.getElementById("papercolor");
pcc = 0.0;
for (i=0; i<a.length; i++)
{
	//alert(i + ".  " + a[i].name + "\n" + a[i].value.toLowerCase());
	if (a[i].value.toLowerCase() != "white" && a[i].checked)
	{
		pcc = document.form1.PaperColorCharge.value;
		break;
	}
}
a = document.getElementsByName("pickuporder")
var sc = 0.0;
for (i=0; i<a.length; i++)
{
	if (a[i].value == "no" && a[i].checked)
	{
		sc = qty*shippingrate;
		break;
	}
}
subtotal = subtotal*1 + pcc*qty + sc;
if (qty > 0) {
	document.form1.subtotal.value = "$" + FormatNumberAsMoney(subtotal);
	}
	else {
	document.form1.subtotal.value = "";
	}
}

function FormatToHundredths(N)
{
	return Math.floor((parseFloat(N) + 0.005) * 100) / 100
}

function FormatNumberAsMoney(N)
{
	if (parseFloat(N) == 0)
	{
		return "0.00"
	}
	else
	{
		N = (this.FormatToHundredths(N)).toString()
		var index = N.indexOf(".")
		var cents = N.substring(index + 1, N.length)
		if (index == -1) N += ".00"
		else if (cents.length < 2) N += "0" 
		return N
	} 
}

function InfoWin(page) {
		popWindow = window.open(page, 'info', 'width=400,height=550,scrollbars=yes,resizable=yes');
		popWindow.focus();
	}