﻿
WebEngine.url = '../san_diego_printing_specials/signs_banners_printing.aspx';

WebEngine.providerId = 13;

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);
      //var tt=RuanYu.Utility.getEvent().keyCode;
      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
    {
       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_mount=function()
{
    var key=$("mount").value;
    if(key.toLowerCase()=="laminating")
    {
         RuanYu.Utility.clear_select_items("mountoption");
         RuanYu.Utility.add_select_item("mountoption","3mil Gloss","3mil Gloss");
         RuanYu.Utility.add_select_item("mountoption","5mil Gloss","5mil Gloss");
         RuanYu.Utility.add_select_item("mountoption","5mil Matte UV","5mil Matte UV");  
         RuanYu.Utility.add_select_item("mountoption","10mil Gloss","10mil Gloss");   
    } 
    else if( key.toLowerCase()=="mounting")
   {
        RuanYu.Utility.clear_select_items("mountoption");
         RuanYu.Utility.add_select_item("mountoption","3/16” Foam Board(Black or White)","3/16” Foam Board(Black or White)");
         RuanYu.Utility.add_select_item("mountoption","1/2” Gatorboard(Black only)","1/2” Gatorboard(Black only)");
   }
   else if( key.toLowerCase()=="mount & laminate")
   {
         RuanYu.Utility.clear_select_items("mountoption");
         RuanYu.Utility.add_select_item("mountoption","3/16\" Foam Board w/ Gloss Lamination","3/16” Foam Board w/ Gloss Lamination");
         RuanYu.Utility.add_select_item("mountoption","3/16\" Foam Board w/ Matte UV Lamination","3/16” Foam Board w/ Matte UV Lamination");
        RuanYu.Utility.add_select_item("mountoption","1/2\" Gatorboard w/ Gloss Lamination","1/2” Gatorboard w/ Gloss Lamination"); 
       RuanYu.Utility.add_select_item("mountoption","1/2\" Gatorboard w/ Matte UV Lamination","1/2” Gatorboard w/ Matte UV Lamination"); 
   }
   else if(key.toLowerCase()=="none")
   {
         RuanYu.Utility.clear_select_items("mountoption");
         RuanYu.Utility.add_select_item("mountoption","None","None");
   }
   WebEngine.bind_Calculat();
}
WebEngine.bind_Calculat=function()
{
     var w=$("pwidth").value;
     var h=$("pheight").value; 
     var pt=$("paperType").value;
     var ml=$("mount").value; 
     var mlo=$("mountoption").value;
     var qty=$("txtquantity").value;
     var turn=$("turnaround").value; 
    var proof=$("proof").value;  
     var area=WebEngine.Nodecimals(w*h/144);
     var areain= WebEngine.Nodecimals(w*h);
     var result=0; 
     if(qty=="")
    {qty=0;} 
     if(w.toString().indexOf(".")>=0)
    {
       w="0"+w+"0"; 
    }  
    if(h.toString().indexOf(".")>=0)
    {
       h="0"+h+"0"; 
    }   
   if(w>60&&h>60)
   {
       w=60;$("pwidth").value=60;
   } 
//    if(h>60)
//   {
//       h=60;$("pheight").value=60;
//   } 
   if(qty>100)
   {
       qty=100;$("txtquantity").value=100;
   }
     switch (pt)
    {
          case "48lb Heavyweight Bond":
                result=area*5;
                break; 
          case "Premium Satin Photo Paper":
                result=area*7;
                break; 
          case "Opaque Scrim (Deluxe Vinyl)":
                result=area*10;
                break;  
         case "Premium Vivid Color Backlit Film":
                result=area*12;
                break;  
        case "Artist Matte Canvas":
                result=area*15;
                break;    
    }   
    switch (mlo)
    {
          case "3mil Gloss":
                result+=areain*0.024;
                break; 
          case "5mil Gloss":
                result+=areain*0.034;
                break; 
          case "5mil Matte UV":
                result+=areain*0.044;
                break;  
         case "10mil Gloss":
                result+=areain*0.044;
                break;  
    }    
      switch (mlo)
    {
          case "3/16” Foam Board(Black or White)":
                result+=areain*0.04;
                break; 
          case "1/2” Gatorboard(Black only)":
                result+=areain*0.07;
                break; 
    }   
    switch (mlo)
    {
          case "3/16” Foam Board w/ Gloss Lamination":
                result+=areain*0.075;
                break; 
          case "3/16” Foam Board w/ Matte UV Lamination":
                result+=areain*0.085;
                break; 
          case "1/2” Gatorboard w/ Gloss Lamination":
                result+=areain*0.10;
                break;  
         case "1/2” Gatorboard w/ Matte UV Lamination":
                result+=areain*0.12;
                break;  
    }    
    result=result* qty;
    if(result<100)
    {
          result=100.00;
    } 
    if(result>=500&& result<1000)
    {
        result=result-result*0.1
     } 
     if(result>=1000&& result<2500)
    {
        result=result-result*0.2
     }  
    if(result>=2500)
    {
        result=result-result*0.3
     }
    if( turn==4)
    {
         result=result*1.2;
    } 
   if(proof==1)
   {
        if(area*10<50)
         {
            result=result+50;
         } 
         else
        {
            result=result+area*10;
        }  
   } 
   else
   {
       result=result+10;
   }
    if (areain>0 && qty>0)
    { 
//     WebEngine.showShipping(areain);
     WebEngine.CalculatSuccess(result);
    } 
}
WebEngine.showShipping=function(area)
{
     var heights=0;
     var pt=$("paperType").value; 
    var qty=$("txtquantity").value; 
    switch (pt)
    {
          case "48lb Heavyweight Bond":
                heights=area/200*qty;
                break; 
          case "Premium Satin Photo Paper":
                heights=area/150*qty;
                break; 
          case "Opaque Scrim (Deluxe Vinyl)":
                heights=area/125*qty;
                break;  
         case "Premium Vivid Color Backlit Film":
                 heights=area/125*qty;
                break;  
        case "Artist Matte Canvas":
                heights=area/150*qty;
                break;    
    }   
     $("printWeightContainer").innerHTML = "Weight:"+heights+"lb";
    $("printWeightValue").value = RuanYu.Utility.numberRound2(heights);
    
    if(Number(heights) > 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.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:"Sign & Banner Printing|ProductName@"+$("pwidth").value+" x "+$("pheight").value+"|Size@"+$("paperType").value+"|PaperType@"+$("mountoption").value+"|MountLaminateMedia@"+$("color").options[$("color").selectedIndex].text+"|Color@"+$("turnaround").options[$("turnaround").selectedIndex].text+"|Turnaround@"+$("proof").options[$("proof").selectedIndex].text+"|Proof@"+$("mount").options[$("mount").selectedIndex].text+"|MountLaminate@"+$("txtquantity").value+"|Quantity@"+  RuanYu.Utility.numberRound2($("printSubtotalValue").value)}, onSuccess:WebEngine.addcar_callback, onFailure:WebEngine.onFailure });
       
    }
}
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";
           
            $("calculateResultNoShipping").innerHTML = "";
            $("calculateResultViewNoShipping").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.Nodecimals=function(val)
{
   return Math.round  (val*Math.pow(10,0))/Math.pow(10,0)
}
WebEngine.Twodecimals=function(val)
{
   return Math.round  (val*Math.pow(10,2))/Math.pow(10,2)
}
window.onload = function()
{
    try
    {
//         $("pwidth").onkeyup=WebEngine.bind_Calculat;
//         $("pheight").onkeyup=WebEngine.bind_Calculat;   
//         $("txtquantity").onkeyup=WebEngine.bind_Calculat;  
         $("pwidth").onchange=WebEngine.bind_Calculat;
         $("pheight").onchange=WebEngine.bind_Calculat;   
         $("txtquantity").onchange=WebEngine.bind_Calculat; 
         $("paperType").onchange=WebEngine.bind_Calculat;  
         $("mountoption").onchange=WebEngine.bind_Calculat;  
         $("mount").onchange = WebEngine.bind_mount;
        //$("paperType").onchange = WebEngine.bind_turnaround; 
        //$("color").onchange = WebEngine.bind_turnaround; 
         $("turnaround").onchange = WebEngine.bind_Calculat;   
        
        //$("quantity").onchange = WebEngine.calculate; 
        $("proof").onchange = WebEngine.bind_Calculat;   
        WebEngine.SetShowShoppingcart(); 
        //WebEngine.bind_paperType();
        
       OnLoadMenu(); 
    }
    catch(e)
    {
        alert(e.message);
    }
}
