﻿WebEngine.url = '../san_diego_printing_specials/Rectangle_DieCut_labels.aspx';

WebEngine.providerId = 16;
WebEngine.num=0;
WebEngine.numerics=function()
{
     
     if(RuanYu.Utility.isIE())
    { 
      if((event.keyCode <48||event.keyCode> 57) && event.keyCode!=46)
      {
          //alert( 'Only input number');
          event.returnValue=false;
          return   false;
     } 
    else
    {
      return true;
    }  
   }
   else
   {
      //alert(RuanYu.Utility.getEvent().charCode);
      if((RuanYu.Utility.getEvent().charCode <48||RuanYu.Utility.getEvent().charCode> 57) && RuanYu.Utility.getEvent().charCode!=46 &&  RuanYu.Utility.getEvent().keyCode!=8)
      {
          //alert( 'Only input number');
          RuanYu.Utility.getEvent().preventDefault();
          return   false;
     } 
    else
    {
     // alert($("pwidth").value +charCodeAt(RuanYu.Utility.getEvent().charCode)); 
      return true;
    }  
   } 
}
WebEngine.checkInt=function()
{
     if(RuanYu.Utility.isIE())
    { 
      if(event.keyCode <48||event.keyCode> 57)
      {
          //alert( 'Only input number');
          event.returnValue=false;
          return   false;
     } 
    else
    {
      return true;
    }  
   }
   else
   {
      //alert(RuanYu.Utility.getEvent().charCode);
      if((RuanYu.Utility.getEvent().charCode <48||RuanYu.Utility.getEvent().charCode> 57)  &&  RuanYu.Utility.getEvent().keyCode!=8)
      {
          //alert( 'Only input number');
          RuanYu.Utility.getEvent().preventDefault();
          return   false;
     } 
    else
    {
      return true;
    }  
   } 
}

WebEngine.bind_Calculat=function()
{
    var s=$("size").value;
    var qty=$("txtquantity").value; 
   var turn=$("turnaround").value; 
   var proof=$("proof").value;  
    var num=0; 
     switch (s)
    {
        case  "8.5x11" :
             num=1;
             break;
        case "3-1/3 x 4" :
            num=6;
            break;
        case "2x4" :
            num=10;
            break;
       case "1 x 2-5/8" :
            num=30;
            break;
       case "2-3/4 x 4-1/4" :
            num=8;
            break;
       case "4x5" :
            num=4;
            break;
       case "1x2.83" :
            num=33;
            break;
       case "2-1/2 x 4" :
            num=8;
            break;   
       case "3-1/3 x 4-1/4" :
            num=6;
            break;
       case "3x5" :
            num=4;
            break;
      case "1x4" :
            num=20;
            break;
      case "1-1/3 x 4" :
            num=14;
            break;       
      case "4-1/4 x 5-1/2" :
            num=4;
            break;
       case "1/2 x 1-3/4" :
            num=80;
            break;
       case "3-1/2 x 5" :
            num=4;
            break;
      case "7/8 x 7/8" :
            num=88;
            break;
      case "1 x 1-1/2" :
            num=50;
            break;
      case "1-1/2 x 4" :
            num=12;
            break;
      case "3/4 diameter" :
            num=120;
            break;
      case "1 diameter" :
            num=80;
            break;
      case "1-2/3 diameter" :
            num=24;
            break;
      case "2 diameter" :
            num=20;
            break;  
       case "2-1/2 diameter" :
            num=12;
            break;  
       case "CD Labels 4-5/8 Diameter" :
            num=2;
            break;               
    }  
    if( qty==""||qty=="0")
    {
        return;
    } 
   else
   { 
            var tot=RuanYu.Utility.numberRound2(qty/num*1.5);
           if(tot>=500 &&tot<1000)
           {
              tot=tot-tot*0.10;
           }
           if(tot>=1000 &&tot<2500)
           {
              tot=tot-tot*0.15
           }  
          if(tot>=2500 )
           {
              tot=tot-tot*0.25
           }   
           if( turn=="2 day")
            {
               tot=tot*1.2
            } 
            if( turn=="Next day")
            {tot=tot*1.3} 
            if( turn=="Same day")
            {tot=tot*1.5}   
           if  (proof=="Paper Proof")
           {
                tot=parseFloat(tot)+parseFloat("5")
           } 
            if(tot<100)
            {
                tot=100; 
            } 
 //            WebEngine.showShipping(qty/num);
             WebEngine.CalculatSuccess(tot);
    } 
}
WebEngine.showShipping=function(val)
{
     var vei= RuanYu.Utility.numberRound2(val*0.049);
     $("printWeightContainer").innerHTML = "Weight:"+vei+"lb";
    $("printWeightValue").value = vei;
    
    if(Number(vei) > 0)
    {
        $("shippingCalculator").className = "";
        
        if($F("zipCode") == "" )    
            $("zipCode").value = RuanYu.Cookies.prototype.get_cookie("zipcode");
        
        if($F("city") == "")
            $("city").value = RuanYu.Cookies.prototype.get_cookie("city");
       WebEngine.shipping_calculate(); 
    }
    else
    {
        $("shippingCalculator").className = "hidden";
    }
 } 
WebEngine.CalculatSuccess=function(val)
{
        var key=RuanYu.Utility.numberRound2(val);
        if( key== "0.00" ||$("txtquantity").value==""||$("txtquantity").value=="0")
        {   
//            $("printSubtotalContainer").innerHTML = "Subtotal: $0.00";
            $("printSubtotalValue").value = "0" ;
            
            $("printWeightContainer").innerHTML = "Weight:0lb";
            $("printWeightValue").value = "0";
            
           $("unitpriceContainer").innerHTML="Subtotal: $0.00"; 
           $("unitpriceValue").value="0";
           
            $("calculateResult").innerHTML = "";
            $("calculateResultView").innerHTML = "" ;
            
            $("shippingCalculator").className = "hidden";
        }
        else
        {
            // result.eachPrice
           // alert(result.totalPrice);
//            $("printSubtotalContainer").innerHTML = "Subtotal: $" +key ;
            $("printSubtotalValue").value = key ;
           
          $("unitpriceContainer").innerHTML="Unit Price: $"+RuanYu.Utility.numberRound2(key/$("txtquantity").value); 
           $("unitpriceValue").value=RuanYu.Utility.numberRound2(key/$("txtquantity").value);  
            
            //$("calculateResult").innerHTML = "Total:" + result.totalPrice + "<br /><span class='small-text gray-text'>(Each:" + result.eachPrice + ")</span>";
            //$("calculateResult").innerHTML = "Total: $" + RuanYu.Utility.numberRound2(Number($("printSubtotalValue").value) + Number($("shippingSubtotalValue").value)) + "<br /><span class='small-text gray-text'>(Print:$" + $("printSubtotalValue").value + " | Shipping:$" + RuanYu.Utility.numberRound2($("shippingSubtotalValue").value) + ")</span>";
            $("calculateResultNoShipping").innerHTML = "Total: $" + RuanYu.Utility.numberRound2(Number($("printSubtotalValue").value));
            $("calculateResultViewNoShipping").innerHTML = "$" + RuanYu.Utility.numberRound2(Number($("printSubtotalValue").value)) ;
            
        }
  }  
 WebEngine.addcar_product = function()
{
    //if(!(WebEngine.check_zipcode() && WebEngine.check_city())) return;
//    if(!WebEngine.check_zipcode()) return;
    
//   if($("shippingSubtotalValue").value=="0.00")
//   {return;}
    var pay = $("calculateResultViewNoShipping").innerHTML.replace("$","");
    
//    var zipCodeValue = $F("zipCode");
        
//    var cityValue = $F("city");
    
    if(Number(pay))
    {
 //       $("shoppingcartContainer").innerHTML="<div style=\"background-color:White\"><img src=\"../shoppingcar/images/52.gif\" /> Loading...</div>";
       // $("txtinfo").style.display="block";
        var today = new Date();
        
        var expires = new Date();
        
        expires.setTime(today.getTime() + 1000*60*60*365); //  one year;
        
//        RuanYu.Cookies.prototype.add_cookie("zipcode", zipCodeValue, expires);
        
//        RuanYu.Cookies.prototype.add_cookie("city", cityValue, expires);
        new Ajax.Request("../calculator/addcar.aspx", { method:'post' ,parameters: {op: 'add', pay:pay,other:"Die-cut Labels|ProductName@"+$("size").value+"|Size@"+$("paperType").value+"|PaperType@"+$("color").options[$("color").selectedIndex].text+"|Color@"+$("turnaround").options[$("turnaround").selectedIndex].text+"|Turnaround@"+$("proof").options[$("proof").selectedIndex].text+"|Proof@"+$("txtquantity").value+"|Quantity@"+ RuanYu.Utility.numberRound2($("printSubtotalValue").value)}, onSuccess:WebEngine.addcar_callback, onFailure:WebEngine.onFailure });
        
    }
} 
window.onload = function()
{
    try
    {
        $("txtquantity").onchange=WebEngine.bind_Calculat;  
        $("turnaround").onchange=WebEngine.bind_Calculat;   
        $("proof").onchange=WebEngine.bind_Calculat;    
        WebEngine.SetShowShoppingcart();  
       WebEngine.setTopTab();  
        OnLoadMenu();  
    }
    catch(e)
    {
        alert(e.message);
    }
}