//Clears text input boxes
var clearedsearch = false;
function clearsearch(){
	if(!clearedsearch){
		document.getElementById("searchinput").value = "";
		clearedsearch = true;
	}
	else{
		document.getElementById("searchinput").select(); //selects all text in the box
		}
}

//Clears text input boxes
var clearedemailing = false;
function clearmailing(){
	if(!clearedemailing){
		document.getElementById("mailinginput").value = "";
		clearedemail = true;
	}
	else{
		document.getElementById("mailinginput").select(); //selects all text in the box
		}
}



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;
        }
    }
}

function MM_openBrWindow(theURL,winName,features) {
	smallWin=window.open(theURL,winName,features);
}

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');
}


/* MAKE MENUS WORK IN IE */
/* ------------------------------------------------------------------------ */

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;