function hideSwatch(id) {
    var swatchID = 'swatchDiv' + id.toString();
    if ($(swatchID) && $(swatchID).visible())
        $(swatchID).fade({ duration: 0.3, delay: 0.7 });
		
}

function showSwatch(id, element) {
    var swatchID = 'swatchDiv' + id.toString();
    if ($(swatchID) && !$(swatchID).visible()) {
        $(swatchID).clonePosition('imgMain', { setWidth: false, setHeight: false, offsetLeft: 200 });
        $(swatchID).appear({ duration: 0.3 });
    }
}

function hideSwatches() 
{ 
 var allPageTags = document.getElementsByTagName("div"); 
 for (i=0; i < allPageTags.length; i++) 
 { 
	 if (allPageTags[i].className=="SwatchDivsPopup") 
	 { 
		$(allPageTags[i].id).fade({ duration: 0.3, delay: 0.7 });
	 } 
 } 
} 

function changeOptionPrice() {
	var groupCount = parseInt(document.getElementById("GroupCount").value);
	var originalPrice = document.getElementById("originalPrice").value;
	var newPrice = parseFloat(originalPrice);
	for (i=1; i<=groupCount; i++)
	{
		var obj = document.getElementById("options_" + i);
		if (obj != null) 
		{
			var id = obj[obj.selectedIndex].value;
			if (id != "") 
			{
				//id=id.replace(/["]{1}/gi,"")
				var myPrice = document.getElementById("price_" + id).value;
				if (myPrice == "") { myPrice = "0"; }
				newPrice += parseFloat(myPrice);
			}
		}
	}
	
	try {
		document.getElementById("gPrice").innerHTML = '$' + formatCurrency(newPrice);
	}
	catch (e) {
		//ignore
	}
}

function formatCurrency(amount) {
    var i = parseFloat(amount);
    if (isNaN(i)) { i = 0.00; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if (s.indexOf('.') < 0) { s += '.00'; }
    if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s;
}

function validateCart() {
	var elements = document.getElementsByTagName('select');
	for (var i=0;i<=elements.length-1;i++) {
		if (elements[i].selectedIndex == 0) {
			alert('This product has options. Please choose your options prior to adding to the shopping cart. Thank you!');
			return(false);
		}
	}
		
	
	return(true);
}

