﻿WebEngine.url = '../san_diego_printing_specials/booklet-digital-printing.aspx';

WebEngine.providerId =29;

WebEngine.bind_pages = function()
{
    var sizeValue = $F("size");
    
    new Ajax.Request(WebEngine.url, { method:'post' ,parameters: {action: 'bind_pages',size:sizeValue}, 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_quantity();
    }
    catch(e)
    {
        alert(e.message);
        //alert(transport.responseText);
    }
}

WebEngine.bind_quantity = function()
{
    var sizeValue = $F("size");
    
    var pagesValue = $F("pages");
    
    new Ajax.Request(WebEngine.url, { method:'post' ,parameters: {action: 'bind_quantity',size:sizeValue, pages:pagesValue}, 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 += "<pages>" + $F("pages") + "</pages>";
    outString += "<color>" + $F("color") + "</color>";
    outString += "<turnaround>" + $F("turnaround") + "</turnaround>";
    outString += "<paperType>" + $F("paperType") + "</paperType>";
    outString += "<proof>" + $F("proof") + "</proof>";
    outString += "<quantity>" + $F("quantity") + "</quantity>";
    outString += "</calculator>";
    
    quantityValue = $("quantity").options[$("quantity").selectedIndex].text;

    new Ajax.Request(WebEngine.url, { method:'post' ,parameters: {action: 'calculate',quantity:quantityValue, xml: outString}, onSuccess:WebEngine.onSuccess, onFailure:WebEngine.onFailure });
}

WebEngine.get_url = function(value)
{
    if(value == "one color")
        location.href = "manual-60lb-calculator.aspx";
}

window.onload = function()
{
    try
    {
        $("size").onchange = WebEngine.bind_pages;
        $("pages").onchange = WebEngine.bind_quantity; 
        
        $("quantity").onchange = WebEngine.calculate; 
        
        $("color").onchange = WebEngine.calculate; 
        
        $("turnaround").onchange = WebEngine.calculate; 
        $("proof").onchange = WebEngine.calculate; 
        $("paperType").onchange = WebEngine.calculate; 
        WebEngine.SetShowShoppingcart();  
        WebEngine.bind_pages();
       WebEngine.setTopTab();
         OnLoadMenu(); 
    }
    catch(e)
    {
        alert(e.message);
    }
}


