/* Things that go on all pages go in this .js */

var global = {};

global.ads = {};

global.initAdIframe = function(iframeId,src){
    var el = global.ads[iframeId] = byId(iframeId);
    if (!isNull(el)) {
        try {
            el.setAttribute("src", src);
        } catch (e) {}
    }
}

global.reloadAds = function() {
    for (var i in global.ads) {
        var el = byId(i);
        if (el == null) continue;
        el.src = el.src;
    }
}

global.print = function() {
    window.print();
}

global.printProfile = function(entityId) {
  var url = '/profile/print/'+entityId;
  global.createWindow(url, PRINT_PROFILE_SPEC);
}

global.trackEntity = function(trackingUrl) {
    var track = img( { 'src': trackingUrl + '&t=' + (new Date()).getTime() } );
}

/* XXX: CS_Window Hack */
var CS_Window = false;

/* Windows Methords */
global.windows = {};

global.createWindow = function(src,spec) {
    if (global.windows[spec.name]) {
        global.windows[spec.name].close();
    }
    global.windows[spec.name] = window.open(src,spec.name,this.buildParams(spec));
    return global.windows[spec.name];
}

global.buildParams = function(spec) {
    var params = [];
    for (var name in spec) {
        if(name != 'name') {
            params.push(name+"="+spec[name]);
        }
    }
    return params.join(",");
 }

 /* Window Specs */

var REDEEM_OFFER_SPEC = {
    'name'       : 'redeem_offer',
    'width'      : '500',
    'height'     : '300',
    'toolbar'    : 'no',
    'menubar'    : 'no',
    'location'   : 'no',
    'resizable'  : 'no',
    'scrollbars' : 'no',
    'status'     : 'no'
}

var PROFILE_MENU_SPEC = {
    'name'       : 'menu_pages',
    'width'      : '680',
    'height'     : '597',
    'toolbar'    : 'no',
    'menubar'    : 'no',
    'location'   : 'no',
    'resizable'  : 'yes',
    'scrollbars' : 'no',
    'status'     : 'no'
}

var SERVICEMAGIC_TERMS_CONDITION_SPEC = {
    'name'       : 'servicemagic_terms',
    'width'      : '592',
    'height'     : '600',
    'toolbar'    : 'no',
    'menubar'    : 'no',
    'location'   : 'no',
    'resizable'  : 'yes',
    'scrollbars' : 'yes',
    'status'     : 'no'
}

var DEALSEARCH_COMPARE_RATES_SPEC = {
    'name'       : 'dealsearch_compare_rates',
    'width'      : '160',
    'height'     : '560',
    'toolbar'    : 'no',
    'menubar'    : 'no',
    'location'   : 'no',
    'resizable'  : 'yes',
    'scrollbars' : 'no',
    'status'     : 'no'
}

var GENBOOK_SPEC = {
    'name'       : 'genbook_reservation',
    'width'      : '505',
    'height'     : '462',
    'toolbar'    : 'no',
    'menubar'    : 'no',
    'location'   : 'no',
    'resizable'  : 'no',
    'scrollbars' : 'no',
    'status'     : 'no'
}

var PRINT_PROFILE_SPEC = {
    'name'       : 'print_profile',
    'width'      : '670',
    'height'     : '800',
    'toolbar'    : 'no',
    'menubar'    : 'no',
    'location'   : 'no',
    'resizable'  : 'yes',
    'scrollbars' : 'yes',
    'status'     : 'no'
}

var PRINT_PROFILE_MAP_SPEC = {
    'name'       : 'print_profile_map',
    'width'      : '670',
    'height'     : '800',
    'toolbar'    : 'no',
    'menubar'    : 'no',
    'location'   : 'no',
    'resizable'  : 'yes',
    'scrollbars' : 'yes',
    'status'     : 'no'
}
