

// -------------------------------------------------------------------
function getCookie(name){

     // Simply retreives a cookie

var cname = name + "=";
var dc = document.cookie;
     if (dc.length > 0) {
          begin = dc.indexOf(cname);
          if (begin != -1) {
               begin += cname.length;
               end = dc.indexOf(";", begin);
               if (end == -1) end = dc.length;
               return unescape(dc.substring(begin, end));
          }
     }
return null;
}

// -------------------------------------------------------------------
function GoTo(thisURL) {
     self.location = thisURL;
}

// -------------------------------------------------------------------
function openWindow(url, w, h) {
  var options = "width=" + w + ",height=" + h + ",";
  options += "resizable=yes,scrollbars=yes,status=no,";
  options += "menubar=no,toolbar=no,location=no,directories=no";
  var newWin = window.open(url, 'newWin', options);
  newWin.focus();
}


// -------------------------------------------------------------------
function OpenWindow(thisURL) {
     var x = 465;
     var y = 465;
     var gWin = window.open(thisURL,'GraphicWindow',
     'width='+x+',height='+y+',resizable=0,scrollbars=0');
}

// -------------------------------------------------------------------
function formReset(){
     for(i = 0; i < document.forms[0].elements.length; i++){
          var inType = document.forms[0].elements[i].type;
          if(inType == "text"){
               document.forms[0].elements[i].value = "";
          }
     }
}

// -------------------------------------------------------------------
function qtyCheck(){
var qtySelected = parseInt(0);
var sizeAvailable = false;
var availableQty = parseInt(0);
var setupSet = false;
var Qtyavailable = parseInt(0);

sizen= new Array();
sizeh= new Array();
ik=0;
 for(a = 0; a < document.forms.length; a++){
	   for(i = 0; i < document.forms[a].elements.length; i++){
       
	   var fieldName = document.forms[a].elements[i].name;
	  	
			if(fieldName.substring(0,4) == "SIZE"){
               sizeAvailable = true;
            
			  var sizename=document.forms[a].elements[i].name;
			var	sizeSplit =sizename.split("|");
			 if(!parseInt(document.forms[a].elements[i].value))
				var fieldValue = 0;
			else
				var fieldValue = parseInt(document.forms[a].elements[i].value);
			if(fieldValue > 0){
                    qtySelected += parseInt(fieldValue);
               }
			  szty=sizeSplit[1];
			  //alert(szty);
			  sizen[ik+'siz']=szty;
			  sizen[ik+'val']= fieldValue;
			  ik++;
          }

		  if(fieldName.substring(0,9) == "CHECKSIZE"){
               sizeAvailable = true;
            
			  var sizename=document.forms[a].elements[i].name;
			var	sizeSplit =sizename.split("|");
			 if(!parseInt(document.forms[a].elements[i].value))
				var fieldValue = 0;
			else
				var fieldValue = parseInt(document.forms[a].elements[i].value);
			
			
			   sztyh=sizeSplit[1];
			  sizeh[sztyh]= fieldValue;
          }
		  
          if((fieldName.substring(0,8) == "QUANTITY")&&(!sizeAvailable)){
               var fieldValue = parseInt(document.forms[a].elements[i].value);
               if(fieldValue > 0){
                    qtySelected += parseInt(fieldValue);
               }
          }
          if(fieldName.substring(0,12) == "OPTION|setup"){
               var setupSet = document.forms[a].elements[i].options[1].selected;
               //alert(setupSet);
               //return false;
          }

          if(fieldName == "min_qty"){
               var fieldValue = parseInt(document.forms[a].elements[i].value);
               if(fieldValue > 0){
                    availableQty = parseInt(fieldValue);
               }
          }
		if(fieldName == "qty_available"){
               var fieldValue = parseInt(document.forms[a].elements[i].value);
               if(fieldValue > 0){
                    Qtyavailable = parseInt(fieldValue);
               }
          }
	  }
 }
flg=0;
msg="";
for(jk=0;jk<ik;jk++){
siz=sizen[jk+'siz'];
sizV=sizen[jk+'val'];
sizh=sizeh[siz];
	if(sizh<sizV){
		flg=1;
		msg+="We're sorry but the quantity that you entered for size '"+siz+ "' is incorrect.\n\nThere are only "+sizh+" available in stock.\n\n Please click OK and revise the amount ordered for this size to "+sizh+" or less."
	}
}

if(flg==1){
	alert(msg);
     return false;
}
 if((qtySelected == 0)&&(sizeAvailable)){
     alert("You have not entered a quantity for the size of an item to add to the cart?");
     return false;
 }
 if((qtySelected == 0)&&(!sizeAvailable)){
     alert("You have not entered a quantity for an item to add to the cart?");
     return false;
 }

 if((qtySelected < availableQty)&&(setupSet)){
     alert("You must purchase a minimum quantity of " + availableQty + " for this item");
     return false;
 }
 if(qtySelected < availableQty){
     alert("You must purchase a minimum quantity of " + availableQty + " for this item");
     return false;
 }
  if((qtySelected > Qtyavailable)&&(!sizeAvailable)){
     alert("We're sorry but there are only " + Qtyavailable + " of these items available. \n Please click 'OK' and adjust your quantity accordingly.");
     return false;
 }
 


return true;
}
//-->



