﻿window.addEvent('domready', function() {
    var url = "/inc/webservice/ProductFinder.asmx/GetApplications";
    var pars = "dummy=true";
    new Ajax(url, {postBody:pars, onComplete:DisplayApps}).request();
    
    var url = "/inc/webservice/ProductFinder.asmx/GetGases";
    var pars = "dummy=true";
    new Ajax(url, {postBody:pars, onComplete:DisplayGases}).request();
});

function DisplayApps(sText, oXml) {
    $('ddlApplication').innerHTML = "";
    var opt = new Element('option');
        opt.setProperty("value", "");
        opt.setHTML("--- Choose ---"); 
        $('ddlApplication').adopt(opt);
    var ds = new DataSet(oXml);
    for (i=0; i < ds.rowcount(); i++) {
        var option = new Element('option');
        option.setProperty("value", ds.cell(i, "ApplicationID"));
        option.setHTML(ds.cell(i, "ApplicationLabel")); 
        $('ddlApplication').adopt(option);
    }
}

function DisplayGases(sText, oXml) {
    $('ddlGas').innerHTML = "";
    var opt = new Element('option');
        opt.setProperty("value", "");
        opt.setHTML("--- Choose ---"); 
        $('ddlGas').adopt(opt);
    var ds = new DataSet(oXml);
    for (i=0; i < ds.rowcount(); i++) {
        var option = new Element('option');
        option.setProperty("value", ds.cell(i, "GasID"));
        option.setHTML(ds.cell(i, "GasLabel")); 
        $('ddlGas').adopt(option);
    }
}

function DisplayProdList(sType) {
    var url = "/inc/webservice/ProductFinder.asmx/GetProducts";
    var pars = "strType=" + sType + "&strApplicationID=" + $("ddlApplication").SelectedValue() + "&strGasID=" + $("ddlGas").SelectedValue();
    new Ajax(url, {postBody:pars, onComplete:DisplayProdList2}).request();
}

function DisplayProdList2(sText, oXml) {
    $('ddlProduct').innerHTML = "";
    var ds = new DataSet(oXml);
    for (i=0; i < ds.rowcount(); i++) {
        var option = new Element('option');
        option.setProperty("value", ds.cell(i, "ProductID"));
        option.setHTML(ds.cell(i, "ProductLabel")); 
        $('ddlProduct').adopt(option);
    }
}

function DisplayProduct() {
    var url = "/inc/webservice/ProductFinder.asmx/GetProductInfo";
    var pars = "strProductID=" + $("ddlProduct").SelectedValue();
    new Ajax(url, {postBody:pars, onComplete:DisplayProduct2}).request();
}

function DisplayProduct2(sText, oXml) {
    var ds = new DataSet(oXml);
    $("productName").innerHTML = "<h2><a href='/products/" + ds.cell(0, "SectionPage") + "'>" + ds.cell(0, "ProductLabel") + "</a></h2>";
    $("productImage").innerHTML = "<a href='/products/" + ds.cell(0, "SectionPage") + "'><img src='/img/products/thumb/" + ds.cell(0, "ProductImage") + "' /></a>";
    $("productDescription").innerHTML = ds.cell(0, "ProductDesc");
}