var total = 0;

// Radio Button Validation
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function validatecheckout(theform, validateradio){
	var tax = theform.TaxID;
	var zip = theform.ZipCode;
	var freeship = theform.FreeShipping;
	var validate = theform.validateShipping;
	var tweight = theform.CartWeight;

	if (freeship!="True"){
		if (tax.selectedIndex==0){
			alert("Please select the appropriate tax from the list.");
			tax.focus();
			return false;
		}

		if (zip.value==""){
			alert("Recipient's zip code cannot be blank.");
			zip.focus();
			return false;
		}

		if (validateradio=="true"){
			if (validate.value=="true"){
				var optship = valButton(theform.optShippingOptionID);
				if (optship==null){
					alert("Please select your preferred shipping method.");
					return false;
				}
			}
			else {
				if (tweight.value>0){
					alert("Cannot proceed to checkout.\n\nPls click [Get Shipping Rates] button then select your preferred shipping method.");
					return false;
				}
			}
		}

	}
}

function validatepromotion(theform){
	var promocode = theform.PromotionCode;

	if (promocode.value==""){
		alert("Coupon code cannot be blank.");
		promocode.focus();
		return false;
	}
}

function validatecharm(theform){
	var charmreq = theform.CharmRequired;
	var giftwrapreq = theform.GiftWrappedRequired;
	var charmid = theform.Charm_ProductsID;
	var chkbox = theform.giftwrap;
	var optgift = theform.optGiftWrap;

	if (charmreq.value=="true"){
		if (charmid.selectedIndex==0){
			alert("Please select a charm from the list.");
			charmid.focus();
			return false;
		}

		if (giftwrapreq.value=="true"){
			if (chkbox.checked){
				if (total == 0){
					alert("Pls select a gift wrap.")
					return false;
				}
			}
		}
	}
}

function show_GiftWrap(theform){
	var chkbox = theform.giftwrap;
	var optgift = theform.optGiftWrap;
	if (chkbox.checked){
		document.getElementById("giftwrapselections").style.visibility = "visible"
	}
	else{
		document.getElementById("giftwrapselections").style.visibility = "hidden"
		optgift[0].checked = false;
		optgift[1].checked = false;
		total = 0;
	}
}

function has_GiftWrap(){
	total++;
}

function switchImage(thisName, thisTitle){
	document.getElementById("imgPic").src="images/press/medium/" + thisName;
	document.getElementById("imgZoom").href="images/press/slides/" + thisName;
	document.getElementById("imgZoom").title=thisTitle;
}