
/*
find all with class 'pfield', get list if items and send request for prices.
*/
function insertPrices()
    {
    var items = $$('.pfield').pluck('id').toJSON();
    var url = 'http://www.automationdirect.com/ajax?' +
              'fctype=adc.falcon.FormControllers.ProductDisplayFormCtrl&' +
              'cmd=getProductPrices&' +
              'items='+items; 
    new Ajax.CrossSiteRequest ( url, { method:'get' } );
    };

/*
process returned data (insert returned prices into document).
*/
function processPrices ( data )
    {
    data.evalJSON().each ( function(item) {
        $$('.pfield').each ( function(el) {
            if ( el.id == item.code ) {
                var p = item.price.split(/\./);
                el.update ( "<span class='dollar'>" + p[0] + "</span>" +
                            "<span class='cents'>." + p[1] + "</span>" );
                }
            } )
        } );
    }

/*
trigger to start process once the document is loaded.
*/
document.observe ( 'dom:loaded', insertPrices );
