var popUp;

function PopWin(url, newWidth, newHeight) {
    var heightValue = 500;
    var widthValue = 700;

    if (popUp && !popUp.closed) {
        popUp.close();
    }

    if (newHeight != null && newHeight != "") {
        heightValue = newHeight;
    }

    if (newWidth != null && newWidth != "") {
        widthValue = newWidth;
    }

    popUp=window.open(url,"PopUp","scrollbars=1,resizable=1,width="+widthValue+",height="+heightValue+",left=0,top=0");
}


function displayImage(imageUrl, newWidth, newHeight) 
{
    var heightValue = 500;
    var widthValue = 700;

    if (newHeight != null && newHeight != "") {
        heightValue = newHeight;
    }

    if (newWidth != null && newWidth != "") {
        widthValue = newWidth;
    }

    var imageWin=window.open("","ImageWin","scrollbars=1,resizable=1,width="+widthValue+",height="+heightValue+",left=0,top=0");

    imageWin.document.writeln("<html><head>");
    imageWin.document.writeln("<title>Product Photo</title>");
    imageWin.document.writeln("<link rel='stylesheet' href='/go2main.css'>");
    imageWin.document.writeln("</head><body bgcolor='white' onLoad='window.focus()'>");
    imageWin.document.writeln("<p><a href='javascript:window.close()'>Close Window</a></p>");
    imageWin.document.writeln("<p><img src='"+imageUrl+"'></p>");
    imageWin.document.writeln("</body></html>");
    imageWin.document.close();

    imageWin.focus();
}

var ev;
function evWin(url) {
    if (ev && !ev.closed) {
	ev.close();
    }

    ev=window.open(url,"PopUp","scrollbars=1,resizable=1,width=773,height=500,left=0,top=0");
}

function reloadCart() {
    if (parent.barge != null)
	parent.barge.location.reload();
}

function backLink() {
    if (window.document.referrer)
	document.write("<a href=\"" + window.document.referrer + "\">Back</a>");
}

/*
 * Wheel Mouse Thumbwheel Dropdown List Scrolling Selecton Solution
 * ----------------------------------------------------------------
 *
 * This set of JavaScript functions solves the problem in 
 * MS Internet Explorer where the user accidently changes a selection in
 * a drop down list when scrolling using the thumbwheel after selecting
 * an element in the list.
 *
 * To use, set the event handlers in the <SELECT> HTML tag to: 
 *   onBlur="mouseUpCount=0;"
 *   onClick="processSelectOnClick(this);"
 *   onFocus="mouseUpCount=0;"
 *   onMouseUp="processSelectOnMouseUp();"
 *   onMouseOver="mouseOverControl=true;"
 *   onMouseOut="processSelectOnMouseOut(this);"
 */
var mouseUpCount = 0;
var mouseOverControl = false;

function processSelectOnMouseOut(element) {

    mouseOverControl = false;

    if (mouseUpCount == 2) {
        clearSelectFocus(element);
    }
}

function processSelectOnClick(element) {

    if (! mouseOverControl) {
        clearSelectFocus(element);
    }
}


function clearSelectFocus(element) {

    // Only remove the focus on Internet Explorer browsers.
    //
    if (navigator.appName == "Microsoft Internet Explorer") {
        if (mouseUpCount > 0) {
            element.blur();
            window.focus();
        }
    }
}

function processSelectOnMouseUp() {

    mouseUpCount++;

    if (mouseUpCount > 2) {
        mouseUpCount = 1;
    }
}

//  Swapping images and preloading images script
//  Created July 14, 2005 Charlene 



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 addEventSimple(obj, evt, fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt, fn, false);
	else if (obj.attachEvent)
		obj.attachEvent('on' + evt, fn);
}

function removeEventSimple(obj, evt, fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt, fn, false);
	else if (obj.detachEvent)
		obj.detachEvent('on' + evt, fn);
}

function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g, '');
}

function isAlpha(aChar) {
	return ((aChar >= 'a' && aChar <= 'z') || (aChar >= 'A' && aChar <= 'Z'));

}
/**
 * Validates name values only if they were set.
 *
 * The first letter of each name must be an alphabet character.
 *
 * Returns: 0 = OK, 1 = firstName bad, 2 = lastName bad, 3 = both bad.
 */
function validateCustomerNames(firstName, lastName) {
			// Make sure the first and last names start with an alphabet character.
		var firstNameOk = true;
		var lastNameOk = true;

		if (firstName != null) {
			firstName = trim(firstName);

			firstNameOk  = isAlpha(firstName.charAt(0));
		}

		if (lastName != null) {
			lastName = trim(lastName);

			lastNameOk  = isAlpha(lastName.charAt(0));
		}

		if (firstNameOk && lastNameOk)
			return 0;
		else if (!firstNameOk && !lastNameOk)
			return 3
		else if (!firstNameOk)
			return 1;
		else
			return 2;
}