<!--
/* cabinet page entry routines. Has price grid built in */
/* jcabine_server_48.js used with page Server_cabinet_84_inch.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 =2703.75;
   var mountprices 	= Array(0,0,0,0,0,0,0,0,0);   // Mounting is 1 or 2 no 0... and is same as cabinet price
   var coolprices  	= Array(0,3572.73,4196.87,0,0,0,0,0,0);
   var topprices  	= Array(0,0,0,0,0,0,0,0,0);    // No top on this nema 84
   var frontprices 	= Array(0,0,172.01,82.40,525.30,0,0,0,0);
   var rearprices  	= Array(0,0,172.03,824.00,0,0,0,0,0);
   var sideprices  	= Array(0,0,147.29,0,0,0,0,0,0);
   var powerprices 	= Array(0,0,155.45,111.24,114.33,110.99,133.75,126.31,269.53);

  //.................................................................
}

function checknumber(check,quantity) {

var resultName;
var resultValue;
var resultChecked;
var thecolor;
var thetop;
var themount;
var thecool;
var thesides;
var thefront;
var therear;
var thepowerstrip;
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 "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;
       }
      }
                
  }


      
   entry=document.NumberForm.color.value;
  // entry=document.NumberForm.partnumber.value;
   var cabinet = 84;
  //var mount   = 1;

//   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 = .70; // Base discount
  var m  = .70;  // Mark up amount - Normal
  var d   = .55; // Discount Amount


 var priceincrease 		= .91;		// Factory increase in price just add to this when you know percentage;

  var DiscountPlus   = .78; // 1st Dicount Level Mark Up
  var DiscountQty    = 2;   // 2nd Discount Level

  var DiscountQty2  = 4;   // 2nd Discount Level
  var DiscountPlus2 = .80; // 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;
      }

/* Color not being use with Nema cabinet only comes in black..
    if ((check == "c") && ((color < 1) || (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 = ('PXNM84-' + thecolor + themount + thecool + 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;     
      }

      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 + mountprices[themount] + coolprices[thecool] + frontprices[thefront] + rearprices[therear] + sideprices[thesides] + powerprices[thepowerstrip];

       //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);
               }
           }

		//.. Now finalize the price...........................

		// add any factory price increase to the price before the calculation...
		theprice = theprice/priceincrease;

           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); 
}    

// -->