
var error_msg = "You must select an option!";
var error_nothing = "You must enter a quantity to continue!";

/* CHECK OPTIONS */
/* ------------------------------------------------------------------------ */

function form_submit(form) {
    ok = 0;
    for (var i = 0; i < form.elements.length; i++) {
        r = form.elements[i].name.match(/^vwitem(\d+)/);
        if (r != null) {
            q = form.elements['vwquantity' + r[1]];
            if (q && (n = parseInt(q.value)) != NaN && n > 0) {
                if (!check_options(form, r[1])) {
                    alert(error_msg);
                    return false;
                } else {
                    ok++;
                }
            }
        }
    } 
    if (!ok) {
        alert(error_nothing);
        return false;
    } 
    return true;
}

function check_options(form, idx) {
    re = new RegExp('^vwattr' + idx);
    for (var i = 0; i < form.elements.length; i++) {
        e = form.elements[i];
        if (re.test(e.name) && e.tagName == 'SELECT') {
            if (e.selectedIndex == 0) {
                return false;
            }
        }
    }
    return true;
}

function select_changed(select) {
    r = select.name.match(/^vwattr(\d+)_/);
    if (r != null) {
        q = select.form.elements['vwquantity' + r[1]];
        if (q && (n = parseInt(q.value)) != NaN && n == 0) {
            q.value = 1;
        }
    }
}

/* MAKE MENUS WORK IN IE */
/* YES, THERE SHOULD BE TWO SETS! */ 
/* ------------------------------------------------------------------------ */

sfHover = function() {
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

startList = function() {
    if (document.all&&document.getElementById) {
        navRoot = document.getElementById("nav");
        for (i=0; i<navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI") {
                node.onmouseover=function() {
                    this.className+=" over";
                }
                node.onmouseout=function() {
                    this.className=this.className.replace(" over", "");
                }
            }
        }
    }
}

window.onload=startList;

/*

sfHover = function() {
    var sfEls = document.getElementById("mfg").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

startList = function() {
    if (document.all&&document.getElementById) {
        navRoot = document.getElementById("mfg");
        for (i=0; i<navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI") {
                node.onmouseover=function() {
                    this.className+=" over";
                }
                node.onmouseout=function() {
                    this.className=this.className.replace(" over", "");
                }
            }
        }
    }
}

window.onload=startList;

*/

/* OPEN NAVIGATION POPUPS */
/* ------------------------------------------------------------------------ */

function productZoom(imageName) {
	window.open('/images/product-zoom.html?'+imageName+'"','','toolbar=no, width=550, height=550, resizable=1, scrollbars=1'); void('');
}

function finishZoom(imageName) {
	if (imageName.match(/\.html$/)) {
		url = imageName;
		
	} else if (imageName.match(/\.swf$/)) {
		url = imageName;
	
	} else {
		url = '/images/finish-zoom.html?' + imageName + '"';
	}
	window.open(url,'','toolbar=no, width=550, height=550, resizable=1, scrollbars=1'); 
	void('');
}

function tellAFriend () {
	var href = document.location.href;
	var baseRef = href.substring(href.lastIndexOf("/") + 1);
	baseRef = baseRef.substring(0, baseRef.lastIndexOf("."));
	var URL = "/tellafriend.html?item=" + baseRef;
	MM_openBrWindow(URL,'tellAFriend','scrollbars=no,resizable=yes,width=453,height=447,left=200,top=50');
}

function wishlistAdd() {
	var url = '/cgi-local/wishlist.pl?action=add';
	if (form_submit(document.cart)) {
        document.cart.action = url;
		document.cart.submit();
	}
}

/* ROLLOVERS */
/* ------------------------------------------------------------------------ */

function swapOnText(name, txt) {
    if(txt && txt != ''){
        document.getElementById('rolloverText').innerHTML = txt;
    }

    MM_swapImage(name,'',PATH + name + '-on.gif',1);
}

function swapOffText(name){
    var r = document.getElementById('rolloverText').innerHTML = '&nbsp;';
    MM_swapImage(name,'',PATH + name + '-off.gif',1);
}

function swapOff(name, id){
    if(id=="") id = name;
    var item = document.getElementById(id);
    if(item != null)
        item.src = PATH + name + '-off.gif';

    //MM_swapImage(name,'',PATH + name + '-off.gif',1);
}

function swapOn(name, id) {
    if(id=="") id = name;
    var item = document.getElementById(id);
    if(item != null){
        item.src = PATH + name + '-on.gif';
    }
    //MM_swapImage(name,'',PATH + name + '-on.gif',1);
}

/* SUPPORT FUNCTIONS */
/* ------------------------------------------------------------------------ */

function MM_findObj(n, d) { //v4.0
    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 && document.getElementById) x=document.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_openBrWindow(theURL,winName,features) {
	smallWin=window.open(theURL,winName,features);
}

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_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;
}

/* ------------------------------------------------------------------------ */



