﻿
WebEngine.url = '../san_diego_printing_specials/Doorhangers.aspx';

WebEngine.providerId = 8;

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.pages;
        
        RuanYu.Utility.convert_select_items("pages",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 += "<quantity>" + $F("quantity") + "</quantity>";
    outString += "<color>" + $F("color") + "</color>";
    outString += "<turnaround>" + $F("turnaround") + "</turnaround>";
    outString += "<proof>" + $F("proof") + "</proof>";
    outString += "<paperType>" + $F("paperType") + "</paperType>";
    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 });
}

window.onload = function()
{
    try
    {
        $("size").onchange = WebEngine.bind_papertype;
        
        $("pages").onchange = WebEngine.calculate; 
        $("quantity").onchange = WebEngine.calculate; 
        $("color").onchange = WebEngine.calculate; 
        $("turnaround").onchange = WebEngine.calculate; 
        $("paperType").onchange = WebEngine.calculate; 
        
        $("proof").onchange = WebEngine.calculate; 
        WebEngine.SetShowShoppingcart();  
        WebEngine.calculate();
       
       OnLoadMenu();  
    }
    catch(e)
    {
        alert(e.message);
    }
}