﻿WebEngine.url = '../san_diego_printing_specials/Sell_Sheet_printing.aspx';

WebEngine.providerId = 41;

WebEngine.bind_paperType = function()
{
    var sizeValue = $F("size");
    
    new Ajax.Request(WebEngine.url, { method:'post' ,parameters: {action: 'bind_paperType',size:sizeValue}, onSuccess:WebEngine.bind_paperType_callback, onFailure:WebEngine.onFailure });

}

WebEngine.bind_paperType_callback = function(transport)
{
    try
    {
        var result = transport.responseText.evalJSON();
        
        var list = result.paperType;
        
        RuanYu.Utility.convert_select_items("paperType",list);
        
        WebEngine.bind_color();
    }
    catch(e)
    {
        alert(e.message);
        //alert(transport.responseText);
    }
}

WebEngine.bind_color = function()
{
    var sizeValue = $F("size");
    
    var paperTypeValue = $F("paperType");
    
    new Ajax.Request(WebEngine.url, { method:'post' ,parameters: {action: 'bind_color',size:sizeValue, paperType:paperTypeValue}, onSuccess:WebEngine.bind_color_callback, onFailure:WebEngine.onFailure });

}

WebEngine.bind_color_callback = function(transport)
{
    try
    {
        var result = transport.responseText.evalJSON();
        
        var list = result.color;
        
        RuanYu.Utility.convert_select_items("color",list);
        
        WebEngine.bind_turnaround();
    }
    catch(e)
    {
        alert(e.message);
        //alert(transport.responseText);
    }
}

WebEngine.bind_pages = function()
{
    var sizeValue = $F("size");
    
    var paperTypeValue = $F("paperType");
    
    var colorValue = $F("color");
    
    new Ajax.Request(WebEngine.url, { method:'post' ,parameters: {action: 'bind_pages',size:sizeValue, paperType:paperTypeValue, color:colorValue}, onSuccess:WebEngine.bind_pages_callback, onFailure:WebEngine.onFailure });

}

WebEngine.bind_pages_callback = function(transport)
{
    try
    {
        var result = transport.responseText.evalJSON();
        
        var list = result.pages;
        
        RuanYu.Utility.convert_select_items("pages",list);
        
        WebEngine.bind_turnaround();
    }
    catch(e)
    {
        alert(e.message);
        //alert(transport.responseText);
    }
}

WebEngine.bind_turnaround = function()
{
    var sizeValue = $F("size");
    
    var paperTypeValue = $F("paperType");
    
    var colorValue = $F("color");
    
    new Ajax.Request(WebEngine.url, { method:'post' ,parameters: {action: 'bind_turnaround',size:sizeValue, paperType:paperTypeValue , color:colorValue}, onSuccess:WebEngine.bind_turnaround_callback, onFailure:WebEngine.onFailure });

}

WebEngine.bind_turnaround_callback = function(transport)
{
    try
    {
        var result = transport.responseText.evalJSON();
        
        var list = result.turnaround;
        
        RuanYu.Utility.convert_select_items("turnaround",list);
        
        WebEngine.bind_quantity();
    }
    catch(e)
    {
        alert(e.message);
        alert(transport.responseText);
    }
}

WebEngine.bind_quantity = function()
{
    var sizeValue = $F("size");
    
    var paperTypeValue = $F("paperType");
    
    var colorValue = $F("color");
    
    var turnaroundValue = $F("turnaround");
    
    new Ajax.Request(WebEngine.url, { method:'post' ,parameters: {action: 'bind_quantity',size:sizeValue, paperType:paperTypeValue , color:colorValue,turnaround:turnaroundValue }, onSuccess:WebEngine.bind_quantity_callback, onFailure:WebEngine.onFailure });

}

WebEngine.bind_quantity_callback = function(transport)
{
    try
    {
        var result = transport.responseText.evalJSON();
        
        var list = result.quantity;
        
        RuanYu.Utility.convert_select_items("quantity",list);
        
        WebEngine.calculate();
    }
    catch(e)
    {
        alert(e.message);
        //alert(transport.responseText);
    }
}

WebEngine.calculate = function()
{   
    var outString = "";

    outString += "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
    outString += "<calculator>";
    outString += "<size>" + $F("size") + "</size>";
    outString += "<quantity>" + $("quantity").value + "</quantity>";
    outString += "<color>" + $F("color") + "</color>";
    outString += "<turnaround>" + $F("turnaround") + "</turnaround>";
    outString += "<proof>" + $F("proof") + "</proof>";
    outString += "<paperType>" + $F("paperType") + "</paperType>";
   outString += "<folding>" + $F("folding") + "</folding>";  
    outString += "</calculator>";
    
    quantityValue = $("quantity").options[$("quantity").selectedIndex].value;

    new Ajax.Request(WebEngine.url, { method:'post' ,parameters: {action: 'calculate',quantity:quantityValue, xml: outString}, onSuccess:WebEngine.onSuccess, onFailure:WebEngine.onFailure });
}
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:"Flyer Offset|ProductName@"+$("size").options[$("size").selectedIndex].text+"|Size@"+$("paperType").options[$("paperType").selectedIndex].text+"|PaperType@"+$("color").options[$("color").selectedIndex].text+"|Color@"+$("folding").options[$("folding").selectedIndex].text+"|Folding@"+$("turnaround").options[$("turnaround").selectedIndex].text+"|Turnaround@"+$("proof").options[$("proof").selectedIndex].text+"|Proof@"+$("quantity").value+"|Quantity@"+ RuanYu.Utility.numberRound2($("printSubtotalValue").value)}, onSuccess:WebEngine.addcar_callback, onFailure:WebEngine.onFailure });
        
    }
} 

window.onload = function()
{
    try
    {
        $("size").onchange = WebEngine.bind_paperType;
        $("paperType").onchange = WebEngine.bind_color; 
        $("color").onchange = WebEngine.bind_turnaround; 
        $("turnaround").onchange = WebEngine.bind_quantity; 
        
        //$("pages").onchange = WebEngine.calculate; 
        
        $("quantity").onchange = WebEngine.calculate; 
        
       $("folding").onchange = WebEngine.calculate; 
        
        //$("stapling").onchange = WebEngine.calculate; 
        
        $("proof").onchange = WebEngine.calculate; 
        WebEngine.SetShowShoppingcart();  
        WebEngine.bind_paperType();
       WebEngine.setTopTab();
       OnLoadMenu(); 
    }
    catch(e)
    {
        alert(e.message);
    }
}
