﻿// JScript File


sfHoverSite = function() {
	var sfEls = document.getElementById("siteNav").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", sfHoverSite);

var newwindow = '';

function popItUp(theURL,winName,features) {
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = theURL;
	} else {
		newwindow=window.open(theURL,winName,features);
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

function CheckAddToCart(thisForm)
{
    var tVal
    
    for (var i=0; i<thisForm.elements.length; i++)
    {
        if (thisForm.elements[i].type == "text" &&
            thisForm.elements[i].value != "")
        {
            tVal = parseInt(thisForm.elements[i].value,10)
            if (isNaN(tVal))
            {
                alert("Quantity must be a number greater than 0.")
                return false;
            }else
            {
                if (tVal <= 0)
                {
                    alert("Quantity must be a number greater than 0.")
                    return false;
                 }else
                 {
                    return true;
                 }
            }
        }
    }
    alert('You must specify a quantity value before adding to cart.')
    return false;
}

function CheckAddToCFCart(thisForm)
{
    var tVal
    
    for (var i=0; i<thisForm.elements.length; i++)
    {
        if (thisForm.elements[i].type == "text" &&
            thisForm.elements[i].value != "")
        {
            tVal = parseInt(thisForm.elements[i].value,10)
            if (isNaN(tVal))
            {
                alert("Quantity must be a number greater than 0.")
                return false;
            }else
            {
                if (tVal <= 0)
                {
                    alert("Quantity must be a number greater than 0.")
                    return false;
                 }else
                 {
					document.getElementById("addToCartType").value = "addToWishList";
                    return true;
                 }
            }
        }
    }
    alert('You must specify a quantity value before adding to wish list.')
    return false;
}

function checkAddPaintTocart(thisForm){
	var tVal
    
    for (var i=0; i<thisForm.elements.length; i++)
    {
        if (thisForm.elements[i].type == "select-one" &&
            thisForm.elements[i].value != "0")
        {
            tVal = parseInt(thisForm.elements[i].value,10)
            if (isNaN(tVal))
            {
                alert("Please select a quantity.")
                return false;
            }else
            {
                if (tVal <= 0)
                {
                    alert("Quantity must be a number greater than 0.")
                    return false;
                 } else
                 {
                    return true;
                 }
            }
        }
    }
    alert('Please select the paint you wish to add to cart.')
    return false;
}
