function SubmitForm(theForm, whatbutton){
     if (whatbutton=="WishList")
          theForm.action = "wishlist_display.asp"
     else if (whatbutton=="EmailProduct")
         	theForm.action = "product_email.asp?PID="+theForm.ProductID.value+"&OID="+theForm.ImageOptionID.value+"&CID="+theForm.CategoryID.value
	else
          theForm.action = "cart_display.asp"
}

function Validate(theForm)
{
	if (theForm.action=="wishlist_display.asp" || theForm.action=="cart_display.asp"){
	     var formlength = theForm.elements.length
	     for (i=0;i<formlength;i++){
	          switch (theForm.elements[i].type){
	               case "select-one":
	                    if (theForm.elements[i].selectedIndex==0){
	                         alert ("Please select a value.");
	                         theForm.elements[i].focus();
	                         return false;
	                    }
	                    break;
	               case "radio":
	                    var el = theForm.elements;
	                    var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
	                    var itemchecked = false;
	                    for(var j = 0 ; j < radiogroup.length ; ++j) {
	                         if(radiogroup[j].checked) {
	                              itemchecked = true;
	                              break;
	                         }
	                    }
	                    if(!itemchecked) {
	                         alert("Please select a value.");
	                         if(el[i].focus)
	                              el[i].focus();
	                         return false;
	                    }
	               default:
	                    break;
	          }
	     }
	
	     if (theForm.MultipleBoxes.value=="True"){
	          for (i=0;i<formlength;i++){
	//               alert (theForm.elements[i].name + "=" + theForm.elements[i].value);
	               RE = new RegExp(".*Value.*")
	//               alert (RE.test(theForm.elements[i].name));
	               if (RE.test(theForm.elements[i].name)){
	                    if (theForm.elements[i].value==""){
	                         alert ("Please Enter a quantity to purchase.");
	                         theForm.elements[i].focus();
	                         return false;
	                    }else{
	                         var checkOK = "0123456789";
	                         var checkStr = theForm.elements[i].value;
	                         var allValid = true;
	                         var decPoints = 0;
	                         var allNum = "";
	                         for (x = 0;  x < checkStr.length;  x++){
	                              ch = checkStr.charAt(x);
	                              for (j = 0;  j < checkOK.length;  j++)
	                                   if (ch == checkOK.charAt(j))
	                                        break;
	                              if (j == checkOK.length){
	                                   allValid = false;
	                                   break;
	                              }
	                              if (ch != ",")
	                                   allNum += ch;
	                         }
	                         if (!allValid){
	                              alert("Please enter only digit characters in the Quantity field.");
	                              theForm.elements[i].focus();
	                              return (false);
	                         }
	                    }
	               }
	          }
	     }else{
	          if (theForm.Quantity.value == ""){
	               alert("Please enter a quantity to purchase.");
	               theForm.Quantity.focus();
	               return (false);
	          }
	
	          var checkOK = "0123456789";
	          var checkStr = theForm.Quantity.value;
	          var allValid = true;
	          var decPoints = 0;
	          var allNum = "";
	          for (i = 0;  i < checkStr.length;  i++){
	               ch = checkStr.charAt(i);
	               for (j = 0;  j < checkOK.length;  j++)
	                    if (ch == checkOK.charAt(j))
	                         break;
	               if (j == checkOK.length){
	                    allValid = false;
	                    break;
	               }
	               if (ch != ",")
	                    allNum += ch;
	          }
	          if (!allValid){
	               alert("Please enter only digit characters in the Quantity field.");
	               theForm.Quantity.focus();
	               return (false);
	          }
	     }
	}
  return (true);
}

function LaunchWindow(ID, OID){
     window.open("product_display_image.asp?PID="+ID+"&OID="+OID,"newwindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=520,height=620")
}

