

var yui = YAHOO.util;
var ec;
if (!ec) { ec = new Object(); }

ec.EC_URL = '/ecapi/';
ec.cookie_name = 'imaging'; // Please override


// Globals:
//   ec.cart
//   ec.session_id
//   ec.cookie_name

/***********************************
 *  Session ID detection
 *
 **********************************/
ec.getSessionID = function() {
    var doughball = new Object();
    var cookies = document.cookie.split(/;\s*/);
    cookies.foreach(function(c) {
        var nv = c.split('=');
        doughball[unescape(nv[0])] = unescape(nv[1]);
    });
    // TODO - HARDCODE imaging cookie name
    return (doughball[ec.cookie_name] ? doughball[ec.cookie_name].session_id : undefined);
};

ec.session_id = ec.getSessionID();


/***********************************
 *  Localization support
 *
 **********************************/
// TODO more than dollars
ec.formatCurrency = function(n) {
    // TODO
    return '$' + Number(n).toFixed(2).toLocaleString();
};

ec.formatAddress = function(addy) {
    return addy.as_string;
};


/***********************************
 *  Error Handling
 *
 **********************************/
ec.criticalAjaxFailure = function(o) {
    alert('AJAX failure: \n' + o.statusText);
};
