// -------------------------------------------------------------------
function GoTo(thisURL) {
     //alert(thisURL);
     location = thisURL;
}
// -------------------------------------------------------------------
function OpenWindow(thisURL,x,y) {
     //var x = 300;
     //var y = 300;

     var gWin = window.open(thisURL,'GraphicWindow',
     'width='+x+',height='+y+',resizable=0,scrollbars=0');
}


function popup(img,h,w,title){

    var sWidth = screen.width / 2 - w;

     var win = window.open("","graphics","top=100,left=" + sWidth + ",scrollbars=0,resizable=1");
     win.resizeTo(w,h + 100);
     win.document.open("text/html", "replace");
     win.document.write("<html><head><title>"+title+"</title></head><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>");
     win.document.write("<img src="+img+" width="+w+" height="+h+"><br>");
     win.document.write("<form><div align=center><input type=button name=Close value=\"Close Window\" onclick=window.close()></div></form>");
     win.document.write("</body></html>");
     win.status = "Zoom Image of " + title;
     win.focus();
}


// -------------------------------------------------------------------
function qtyCheck(form){

     var qtySelected = parseInt(0);

     for(i = 0; i < form.elements.length; i++){

          var fieldName = form.elements[i].name;

          if(fieldName.substring(0,8) == "QUANTITY"){
               var fieldValue = parseInt(form.elements[i].value);

               if(fieldValue > 0){
                    qtySelected += parseInt(fieldValue);

                        // Check availability

                    var id = fieldName.substring(9,fieldName.length);
                    var availFld = "available|" + id;
                    var minField = "minimum|" + id;

                    var nameFld = "name|" + id;
                    var productName = form.elements[nameFld].value

                    var pattern = /\s{2,}/g;
                    var pName = productName.replace(pattern,"");


                    if(eval(form.elements[availFld])){
                        var qtyAvailable = parseInt(form.elements[availFld].value);
                        if(fieldValue > qtyAvailable){
                            if(qtyAvailable <= 0){
                                alert("Sorry, the '" + pName + "' is not available at this time.");
                            }
                            else{
                                alert("There are only " + qtyAvailable + " of the '" + pName + "s' available.\n\n" +
                                      "Please reduce the quantity so it is equal to or fewer than " + qtyAvailable + " item(s).");
                            }
                            form.elements[i].value = "";
                            form.elements[i].focus();
                            return false;
                        }
                    }
                    if(eval(form.elements[minField])){
                        var qtyMinimum = parseInt(form.elements[minField].value);
                        if(fieldValue < qtyMinimum){
                            alert("You must purchase a minimum of " + qtyMinimum + " '" + pName + "s'.");
                            form.elements[i].value = "";
                            form.elements[i].focus();
                            return false;
                        }
                    }
               }
          }
     }

     if(qtySelected == 0){
          alert("You have not entered a quantity of an item to add to the cart.");
          return false;
     }

return true;
}






