﻿WebEngine.url = '../san_diego_printing_specials/Rectangle_Cut_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 &&  RuanYu.Utility.getEvent().keyCode!=9)
      {
          //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 &&  RuanYu.Utility.getEvent().keyCode!=9)
      {
          //alert( 'Only input number');
          RuanYu.Utility.getEvent().preventDefault();
          return   false;
     } 
    else
    {
      return true;
    }  
   } 
}

WebEngine.bind_Calculat=function()
{
     var w=$("pwidth").value;
     var h=$("pheight").value; 
     var pt=$("paperType").value;
     var qty=$("txtquantity").value;
     var turn=$("turnaround").value; 
    var proof=$("proof").value;  
      if(w!="")
      { 
           if(w<1.75)
          { $("pwidth").value=1.75;w=1.75; } 
          if(w>11)
          {
             w=11;$("pwidth").value=11;
          }
      }
      if(h!="")
      {
           if(h<1.75)
          { $("pheight").value=1.75;h=1.75; } 
          if(h>17)
          {
             h=17;$("pheight").value=17;
          }
      }
     if(w*h=="0")
     {
        WebEngine.num=0;
     } 
     else
     {  
         WebEngine.num=parseInt(187/(w*h)); 
     }   
     if( WebEngine.num==0||qty=="")
        return;
    var tot=0;
    tot=qty/WebEngine.num *2.25
   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=tot+5
     }  
    if(tot<100)
    {
        tot=100; 
    } 
   
 //    WebEngine.showShipping(qty/WebEngine.num);
     WebEngine.CalculatSuccess(tot);
}
WebEngine.showShipping=function(value)
{
     var wei=value*0.049;
     $("printWeightContainer").innerHTML = "Weight:"+wei+"lb";
     $("printWeightValue").value = RuanYu.Utility.numberRound2(wei);
    
    if(Number(wei) > 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:"Rectangle Cut Labels|ProductName@"+$("pwidth").value+" x "+$("pheight").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
    {
        $("pwidth").onchange=WebEngine.bind_Calculat;
        $("pheight").onchange=WebEngine.bind_Calculat;    
        $("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);
    }
}