
function checkForm(theForm) 
{
  var defaultValue = theForm.wcproduct.value; // extra value to fix strange back button bug where the value gets duplicated upon adding to cart
  // Assemble options and add to product string  
  var out = '';
  var theOptions = new Array();
  var pTags = false;
  for (var i=0; i<theForm.length; i++) {
    if (theForm[i].name == 'options[]') {
      if (theForm[i].value != '') {
        var theLabel = (theForm[i-1].name == 'labels[]') ? theForm[i-1].value + ' ' : '';
        theOptions[theOptions.length] = theLabel + theForm[i].value;
      }
    }
  }
  out += '('+theForm.scode.value+') ';
  out += defaultValue+'{br}';
  out += theOptions.join(", ");
  theForm.product.value = out;
  // Check for minimum quantity
  if (theForm.ptags) {
  		if (theForm.ptags.checked) {
    		var min = 24;
    		var num = parseFloat(theForm.qty.value);
    		if ( num < min || isNaN(num)) {
    			alert("You have selected Personal Tags. A minimum quantity of "+min+" favors is required to order Personalized Tags.");
    			return false;
    		}
    	}
   }
  return true;
}

function togglePTags(cost) 
{
  if (isNaN(cost)) cost = 0;
  var theForm = document.forms.prod_form;
  var total;
  if (theForm.ptags) {
  		if (theForm.ptags.checked) {
    		total = parseFloat(theForm.price.value) + cost;
    	} else {
    		total = parseFloat(theForm.price.value) - cost;
    	}
    	if (total.toFixed) total = total.toFixed(2);
    	theForm.price.value = total;
		if (document.getElementById("price_display")) {
			document.getElementById("price_display").childNodes[0].nodeValue = '$'+total;
		}
    }
    showHide('ptags_form');
}

// Toggle an element's display.
function showHide(id) 
{
  if (document.getElementById) {
  	var el = document.getElementById(id);
  	el.style.display = (el.style.display == 'none') ? 'block' : 'none';
  }
}
