<!--
/* cabinet page entry routines. Has price grid built in */
/* jserver_datadeep34.js used with page rack_34deep.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 {

   //Array Position 0=48High, 1=72High, 2=78High, 3=84High...
   var cabinetpricegroup = Array (0,849.75,866.23,888.89);
   
   //var cabinetpricegroup = Array (924.00,1063.00,1085.00,1113.00);
   
   var cabinetnumbergroup = Array (' ','PXD72','PXD78','PXD84');   
   
   var ItemNameGroup = Array('48 Inch High', '72 Inch High','78 Inch High','84 Inch High');   
   
   var topprice48  = Array(0,0,192.61,174.00,265.00,33.00,27.00);
   
   var topprice72  = Array(0,0,192.61,292.52,381.10,36.05,0,0);
   
   var topprice78  = Array(0,0,192.61,292.52,381.10,36.05,0,0);
   
   var topprice84  = Array(0,0,192.61,292.52,381.10,36.05,0,0);
   
   
   
   
   var mountingprices48 = Array(0,0,0,119.00,0,0,0,0);
   
   var mountingprices72 = Array(0,299.73,299.73,319.30,0,0,0,0,0);
   
   var mountingprices78 = Array(0,273.94,306.94,315.18,0,0,0,0,0);
   
   var mountingprices84 = Array(0,354.32,315.18,394.49,0,0,0,0,0);
   



   var frontprice48 = Array(0,172.00,254.00,274.00,262.00,0,0,0,0);
   var frontprice72 = Array(0,221.45,329.60,362.56,0,0,0,0,0);
   var frontprice78 = Array(0,230.72,349.17,373.89,0,0,0,0,0);
   var frontprice84 = Array(0,235.87,355.35,381.11,0,0,0,0,0);
   
   var rearprice48  = Array(0,187.00,160.00,346.00,0,0,0,0,0);
   
   var rearprice72  = Array(0,221,45,362.56,329.60,0,0,0,0,0);
   
   var rearprice78  = Array(0,230.72,373.89,349.17,0,0,0,0,0);
   
   var rearprice84  = Array(0,235.87,381.10,355.35,0,0,0,0,0);
   
   
   var sideprice48  = Array(0,91.00,183.00,172.00,344.00,0,0,0,0);
   var sideprice72  = Array(0,116.39,232.78,0,0,0,0,0,0);
   var sideprice78  = Array(0,124.63,216.26,0,0,0,0,0,0);
   var sideprice84  = Array(0,133.75,258.53,0,0,0,0,0,0);
   
   
   
   var powerprices48 = Array(0,0,119.00,103.00,105.00,99.00,120.00);
   var powerprices72 = Array(0,0,115,45,111.24,114.33,110.88,1133.75,126.31,219.53);
   var powerprices78 = Array(0,0,115,45,111.24,114.33,110.88,1133.75,126.31,219.53);
   var powerprices84 = Array(0,0,115,45,111.24,114.33,110.88,1133.75,126.31,219.53);


  //.................................................................
}

function checknumber(check,quantity) {


var cabinet = 78;
var resultName;
var resultValue;
var resultChecked;
var theheight;
var thecolor;
var thetop;
var themount;
var thecool;
var thesides;
var thefront;
var therear;
var them6squarenut;
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 "height":
                theheight=resultValue;
                //alert("height " + theheight);
                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;
           case "m6squarenut":
                them6squarenut=resultValue;
                //alert("height " + theheight);
                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 m  = NormalDiscount;  // 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 == 78))  {
    //  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 = (cabinetnumbergroup[theheight] + thecolor + themount + thetop + thefront + therear + thesides + thepowerstrip);
     	  //thenumber = ('PSXL72' + thecolor + themount + thetop + thefront + therear + thesides + thepowerstrip);

          if (theheight==48){
    	     thenumber = (cabinetnumbergroup[theheight] + thecolor + themount + thetop + thefront + therear + thesides + thepowerstrip);
    	     //thenumber = (cabinet48number + thecolor + themount + thetop + thefront + therear + thesides + thepowerstrip);
    	  }
    	  if (theheight==72) {
    	     thenumber = (cabinetnumbergroup[theheight] + thecolor + themount + thetop + thefront + therear + thesides + thepowerstrip);
    	     //thenumber = (cabinet72number + thecolor + themount + thetop + thefront + therear + thesides + thepowerstrip);
    	  }
    	  if (theheight==78) {
    	     thenumber = (cabinetnumbergroup[theheight] + thecolor + themount + thetop + thefront + therear + thesides + thepowerstrip);
    	     thenumber = (cabinet78number + thecolor + themount + thetop + thefront + therear + thesides + thepowerstrip);
    	  }
    	  if (theheight==84) {
    	     thenumber = (cabinetnumbergroup[theheight] + thecolor + themount + thetop + thefront + therear + thesides + thepowerstrip);
    	     thenumber = (cabinet78number + 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 > 25)) {
         // 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;
       
       var display_thecabinetname = 'Server Rack-Cabinet ' + ItemNameGroup[theheight] + ' by 29Wide x 34 Deep-PepXM';
	   document.FinalForm.ITEMNAME.value = display_thecabinetname; 
       
       cabinetprice = cabinetpricegroup[theheight];
       
       //theprice = cabinetpricegroup[theheight] + mountingprices[themount] + frontprice72[thefront] + topprice72[thetop] +
       //rearprice72[therear] + sideprice72[thesides] + powerprices[thepowerstrip];



      // theprice = cabinetprice +  frontprices[thefront] + topprices[thetop] +
      // rearprices[therear] + sideprices[thesides] + powerprices[thepowerstrip];


	  if (theheight == 0) {   
       theprice = cabinetprice + mountingprices48[themount] + frontprice48[thefront] + topprice48[thetop] +
       rearprice48[therear] + sideprice48[thesides] + powerprices48[thepowerstrip];
       } 

	  if (theheight == 1) {   
       theprice = cabinetprice + mountingprices72[themount] + frontprice72[thefront] + topprice72[thetop] +
       rearprice72[therear] + sideprice72[thesides] + powerprices72[thepowerstrip];

       //theprice = cabinetprice72 +  frontprice72[thefront] + topprice72[thetop] +
       //rearprice72[therear] + sideprice72[thesides] + powerprices[thepowerstrip];


       } 

      if (theheight == 2) {
       theprice = cabinetprice + mountingprices78[themount] + frontprice78[thefront] + topprice78[thetop] +
       rearprice78[therear] + sideprice78[thesides] + powerprices78[thepowerstrip];
       }

      if (theheight == 3) {
       theprice = cabinetprice + mountingprices84[themount] + frontprice84[thefront] + topprice84[thetop] +
       rearprice84[therear] + sideprice84[thesides] + powerprices84[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); 
}    

// -->