<!--
/* cabinet page entry routines. Has price grid built in */
/* jcab_server_84x42-a.js used with page computer_cabinet_42deep.htm */
var entry;
var newpartnumber;
var Uselist='Y'  // If Y then use list price variables.

if ( !(Uselist== 'Y') ) {
  var cabinetprice = 598.53;
  var topprices   = Array(0,1572.25,108.71,145.59,16.82,17.47);
  var frontprices = Array(0,132.00,197.35,212.24,0,0);
  var rearprices  = Array(0,126.18,121.00,213.53,0,0);
  var sideprices  = Array(0,75.71,151.41,0,0,0);
  var powerprices = Array(0,65.07,73.09,54.49,45.29,54.00); 

} else {

  // Using list prices below...
//  var NormalDiscount = .75; // Base discount
//  var m  = .75;  // Mark up amount - Normal
//  var d   = .55; // Discount Amount

//  var DiscountPlus   = .80; // 1st Dicount Level Mark Up
//  var DiscountQty    = 2;   // 2nd Discount Level

//  var DiscountQty2  = 4;   // 2nd Discount Level
//  var DiscountPlus2 = .85; // 2nd Discount Level Mark up


  var cabinetprice = 1250.00;
  var topprices  = Array(0,41.00,174.00,265.00,33.00,0);
  var coolprices   = Array(0,0,0,0,0,0);
  var mountprices  = Array(0,0,0,0,0,0);   // Mounting is 1 or 2 no 0... and is same as cabinet price
  var frontprices = Array(0,328.00,376.00,532.00,309.00,217.00);
  var rearprices  = Array(0,376.00,532.00,269.00,328.00,309.00,217.00);
  var sideprices  = Array(0,126.00,252.00,174.00,348.00,0);
  var powerprices = Array(0,0,119.00,103.00,105.50,99.00,120.00); 


  //.................................................................
}

function checknumber(check,quantity) {


var cabinet = 84;
var resultName;
var resultValue;
var resultChecked;
var thecolor;
var thetop;
var themount;
var thecool;
var thesides;
var thefront;
var therear;
var thepowerstrip;
// var thecompartments = '2';
var Uselist='Y'
var maxqty = 4;

  


//thecolor= document.NumberForm.color.value;

  for (var i=0; i < document.NumberForm.length; i++){
       resultName= NumberForm.elements[i].name;
       resultValue=NumberForm.elements[i].value;
       resultChecked = NumberForm.elements[i].checked;

       if(resultChecked){       
       switch (resultName) {
           case "color":
                thecolor = resultValue;
                //alert("color " + thecolor);
                break;
           case "mount":
                themount=resultValue;
                //alert("mount " + themount);
                break;
           case "top":
                thetop=resultValue;
                //alert("top " + thetop);
                break;

//           case "cool":
//                thecool = resultValue;
                //alert("cool " + thecool);
//                break;

           case "side":
                thesides = resultValue;
                //alert("side " + thesides);
                break;
           case "front":
                thefront = resultValue;
                //alert("front " + thefront);
                break;
           case "rear":
                therear = resultValue;
                //alert("rear " + therear);
                break;
           case "power":
                thepowerstrip=resultValue;
                //alert("power " + thepowerstrip);
                break;
           default:
                break;
       }
      }
                
  }

 //window.alert("Items were found")

      
   entry=document.NumberForm.color.value;
  // entry=document.NumberForm.partnumber.value;

//   var themount=document.NumberForm.mount.value;
//   var thecolor=document.NumberForm.color.value;
//   var thetop=document.NumberForm.top.value;
//   var thecool=document.NumberForm.cool.value;
//   var thefront=document.NumberForm.front.value;
//   var therear=document.NumberForm.rear.value;
//   var thesides=document.NumberForm.side.value;
//   var thepowerstrip=document.NumberForm.power.value;

  var NormalDiscount = .72; // Base discount
  var m  = .75;  // Mark up amount - Normal
  var d   = .55; // Discount Amount

  var DiscountPlus   = .75; // 1st Dicount Level Mark Up
  var DiscountQty    = 2;   // 2nd Discount Level

  var DiscountQty2  = 4;   // 2nd Discount Level
  var DiscountPlus2 = .78; // 2nd Discount Level Mark up

  var DiscountQty2  = 6;   // 2nd Discount Level
  var DiscountPlus2 = .79; // 2nd Discount Level Mark up


//   var q1 =document.NumberForm.quantity.value;
     var q1 = 0;

//    window.alert("q1 and quantity =" + q1+ " " + quantity+"...")
//    return; 

   var theprice=1;
   var totalprice=0;
   var thenumber = 0;
   q1 = quantity; 
   m = NormalDiscount;

  //if (entry){
    //    var cabinet = entry.substring(0,2);
    //    var color=entry.substring(2,3);
    //    var mount=entry.substring(3,4); 
    //    var thetop=entry.substring(4,5);
    //    var front=entry.substring(5,6);
    //    var rear=entry.substring(6,7);
    //    var sides=entry.substring(7,8);
    //    var powerstrip=entry.substring(8,9);
    
    //    if ((entry.length > 9) || (entry.length < 9)) {
    //      window.alert("Sorry, incorrect number of digits were entered\nPlease try again to make your part number...")
    //      return;
    //      }

    if (!(cabinet == 84))  {
      window.alert("Please enter correct cabinet Frame Height number!\nThe First two digits on the left...")
      return;
      }


    if ((check == "c") && ((color < 2) || (color > 4)) ) {
      window.alert("Please enter correct COLOR number!\nFrom 1 to 4...")
      return;
      }
      

    if ((check == "m") && ((themount < 1) || (themount.length < 1))) {
      window.alert("Please enter correct MOUNTING SIZE number!\nFrom 1 to 2...")
      return;
      }
 
    if ((check == "t") && ((thetop < 0 ) || (thetop > 5 ) || (thetop.length < 1))) {  
      window.alert("Please enter correct TOP number\nFrom 1 to 5 or 0 for None...")
      return;
      }
     

    if ((check == "f") && ((thefront < 0 ) || (thefront > 3) || (thefront.length < 1)) ) {
      window.alert("Please enter correct FRONT number\nFrom 1 to 3 or 0 for None...")
      return;
      }

    if ((check == "r") && ((therear < 0) || (therear > 3) || (therear.length < 1)) ) {
      window.alert("Please enter correct REAR PANEL number\nFrom 1 to 3 0 for None...")     
      return;
      }

    if ((check == "s") && ((thesides < 0) || (thesides > 2) || (thesides.length < 1)) ) {
       window.alert("Please enter correct SIDES number\nFrom 1 to 2 or 0 for None...")
       return;
       }

    if ((check == "p") && ((thepowerstrip < 0) || (thepowerstrip > 5 ) || (thepowerstrip.length < 1)) ) {
        window.alert("Please enter correct POWER STRIP number!\nfrom 3 to 5 or 0 for None...")
        return;
        }     

     //    if (cabinet == 48){
     //       if ((powerstrip == 1) || (powerstrip == 2)){
     //          window.alert("Power Strip can only be selected from item 3 to 5 or 0 for none!\non 48 Inch cabinet frame height")
     //          return;
     //          }
     //    }    

      if ((check == "q") && (q1 < 1)){
        window.alert("You must enter a quantity greater than 0...");
        return;
      }

      if ( (check == "q") && (q1 > 0) ){
    	  thenumber = ('PEPXUSD84-' + thecolor + themount + thetop + thefront + therear + thesides + thepowerstrip);
      }
      if ( (check == "q") && (q1 >= maxqty) ){
          document.NumberForm.DISPTOTAL.value = 'Call or Email';
          document.NumberForm.DISPNUMBER.value = thenumber;
          document.NumberForm.ORIGINALPRICE.value='Call or Email';
          document.NumberForm.DISPEACH.value = 'Call or Email';
          window.alert("Call or Email for Quantities greater than " + maxqty);
          return;     
      }

       // window.alert("The number entered is: " + thenumber);


	    //thenumber = ('PEPXUS84-' + thecolor + themount + thecool + thefront + therear + thesides + thepowerstrip);
	    //thenumber = ('PEPXSL48-' + color + '1' + thetop + thefront + therear + sides + powerstrip);

      if ( (thenumber.length < 11) || (thenumber.length > 18)) {
         // window.alert("Sorry, incorrect number of digits were entered\nPlease try again to make your part number...");
         window.alert("Sorry, incorrect number of digits were entered\nPlease try again to make your part number...\n " + thenumber.length +"\n" + thenumber);
     	 return;
          }

       document.NumberForm.DISPNUMBER.value = thenumber;
       document.FinalForm.SKU.value  = thenumber;
       document.FinalForm.QTY.value  = q1;
	    
	    
       theprice = cabinetprice + frontprices[thefront] + topprices[thetop] +
       rearprices[therear] + sideprices[thesides] + powerprices[thepowerstrip];

       //theprice = cabinetprice + themount[mountprices] + frontprices[thefront] + topprices[thetop] +
       //rearprices[therear] + sideprices[thesides] + powerprices[thepowerstrip];

       
       //theprice = cabinetprice + mountprices[themount]  + frontprices[thefront] +
       //rearprices[therear] + sideprices[thesides] + powerprices[thepowerstrip];
       
       //theprice = cabinetprice + mountprices[themount] + coolprices[thecool] + frontprices[thefront]+
       //theprice = cabinetprice + mountprices[themount] + coolprices[thecool] + topprices[thetop] + frontprices[thefront]+

     //alert("THE PRICE: " + theprice + " CABINET PRICE: " + cabinetprice + " REAR: " + rearprices[therear] + "\n Sides: " + sideprices[thesides]);
        //....
     if (Uselist=='Y') {
           originalprice = theprice;
           theprice = theprice * d;


         if  ( (DiscountQty >=1)   && (q1 >= DiscountQty)  && ( DiscountQty2 >=1) && (q1 < DiscountQty2) ) {
             m = DiscountPlus;
            // window.alert("First Discount M=" +m);
             
         } else { 
            if ( DiscountQty2 >=1 && q1 >= DiscountQty2) {
                 m = DiscountPlus2;
             //    window.alert("2nd Discount M=" +m);
               }
           }
           
           previousprice = theprice/NormalDiscount;           
           theprice = theprice/m;

           //window.alert("Price: $" + Math.round(originalprice) +  "\n" + " Mark up: %" + m + "\n" +  " Marked Up Price: $ " +  Math.round(theprice) + " \n" +" Discount d =  " + d );
            //return;
      }
       
       
     if (previousprice > theprice) {
         document.NumberForm.ORIGINALPRICE.value = currencyformat(previousprice);
         } 
        else { document.NumberForm.ORIGINALPRICE.value = ' '; }

       document.NumberForm.DISPEACH.value = currencyformat(theprice);
       document.FinalForm.PRICE.value = currencyformat(theprice);
       totalprice = theprice * q1;
       totalprice = currencyformat(totalprice);
       document.NumberForm.DISPTOTAL.value = totalprice;
       //     window.alert("Price: $" + Math.round(theprice) +  " Each. Total: $" + Math.round(totalprice) + " No. " + thenumber);
       return;
      // }
   } 

 function makenumber()  {
   entry2=document.NumberForm.quantity.value
   if ((entry)  && (entry2)){
      var theprice;
      if (entry2 < 1){
        window.alert("You must enter a quantity greater than 0 !")
          return;
      }
		
   }

   else { window.alert("You must enter a part number then a quantity!")
          return;
          }
 }

 function testfunction() {
   entry=document.FinalForm.SKU.value;
   entry2=document.FinalForm.PRICE.value;
   entry3=document.FinalForm.QTY.value;
         window.alert("Test Alert Final Form Function: SKU: " + entry + " PRICE: " + entry2 + " QTY: " + entry3);
          return;
 }

function currencyformat(num)  {
    num = num.toString().replace(/\$|\,/g,'');
    if (isNaN(num)) num = "0";
    cents = Math.floor((num*100+0.5)%100);
    num = Math.floor(num).toString();
    if (cents < 10) cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++);
    //  num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
    num = num.substring(0,num.length-(4*i+3)) + num.substring(num.length-(4*i+3));
    //  window.alert("rounded " + num + "." + cents);

    //  return ("$" + num + "." + cents);
    return (num + '.' + cents); 
}    

// -->
