/* CONFIG BLOCK FOR POP-UP SUPPRESSION
  TO DISABLE POP_UPS, UNCOMMENT THE FOLLOWING TWO LINES
*/
//var noArrivalPopFlag = false; // Disables entering pops.
//var noExitingPopFlag = false; // Disables exiting pops.
MAGNET.popups.setArriving(false).setExiting(false).setLayer(true).init();

// import the ELIS class, which calls its exec method once loaded
document.writeln('<scr'+'ipt src="/js/elis.js"></scr'+'ipt>');

// Pass in a query string variable and it returns the value.
function queryString(keyName) {
    var keyValue = "";
    keyName = keyName.toUpperCase() + "=";

    var queryString = location.search;
    if (location.search.indexOf("?") != -1) {
        queryString = location.search.substring(1, queryString.length);
        var searchString = queryString.toUpperCase();
        if (searchString.indexOf(keyName) != -1) {
            var keyValueStart = parseInt(searchString.indexOf(keyName)) + keyName.length;
            var keyValueEnd = searchString.indexOf("&", keyValueStart);
            var keyValueEnd = (keyValueEnd != -1) ? keyValueEnd : searchString.length;
            keyValue = queryString.substring(keyValueStart,keyValueEnd);
        }

        var plusPos = keyValue.indexOf('+');
        while (plusPos != -1) {
            keyValue = keyValue.substring(0, plusPos) + " " + keyValue.substring(plusPos + 1, keyValue.length);
            plusPos = keyValue.indexOf('+');
        }
    }

    return unescape(keyValue);
}

function newsletterSampleClass() {
        this.keys = new Object();
        this.keys["sampleWeekly"] = "/services/sampleWeekly";
    }

    var newsletterSample=new newsletterSampleClass();

    function openpopup() {
        window.open (newsletterSample.keys[this.id],"mywindow","menubar=1,resizable=1,scrollbars=yes,width=750,height=800");
    }

    function assignLinks() {
        for (id in this.keys) {
            if (document.getElementById(id) != null) {
                document.getElementById(id).onclick=openpopup;
            }
        }
    } /* end assignLinks */
newsletterSampleClass.prototype.assign=assignLinks;

/* Window onload functions go here. */
function loadEvents() {
  //SI.ClearChildren.initialize();

  //subscriptions.assign();
  //if (typeof(feedmanager) !='undefined') { feedmanager.assign(); }
  newsletterSample.assign();
}

/* Window onunload functions go here.
 * Make sure you pass the event object (e) to the handler object's method, otherwise
 * Firefox won't see the event object.
 */
function unloadEvents(e) {
}

/* Document click functions go here.
 * Same deal as above. Make sure to pass event object to hander object's method.
 */
function clickEvents(e) {
}

/* toggle visibility of a an element.
 * Pass in the div id and it toggles the display from visible to not visible.
 */
function toggle( targetId ){
  if (document.getElementById){
    target = document.getElementById( targetId );
    if (target.style.display == "none"){
      target.style.display = "";
    } else {
      target.style.display = "none";
    }
  }
}


/* Calls to event manager to attach functions to events. */
//addEvent(window, "load", loadEvents);
//addEvent(window, "unload", unloadEvents);

// Would like to use event manager for this, but when using onclick to pop windows,
// it will still follow the href.
//addEvent(document, "click", clickEvents);
//document.onclick=clickEvents;

try {
  var pluckUser = new Cookie("at");
}
catch (ex) {
  var pluckUser = null;
  }


/**
 * Queues up function calls. Pass it a string of the function name along with an array of
 * args and it will execute those functions when calling the execute() method.
 * Used for Omniture on forums to overcome problems with ordering of script includes.
 * @todo Add support for multiple queues. Any way to remove the eval from this?
 * @param  {mixed}   mixed  The object being tested
 * @return {boolean}        the result
 */
MAGNET.functionQueue = (function($M) {
  var q = [];

  return {
    /**
     * Add functions to a queue to execute later.
     * @param   {string} [f] Function to call
     * @param   {array} [a] Array of args to pass to function.
     * @param {string} [qId] Not implemented but would be used to support multiple queues of functions.
     */
	addToQueue : function (f, a, qId) {
	  var temp = {fName:f, args:a};
	  q.push(temp);
	} ,

	/**
     * Executes functions in the queue.
     * @param   {string} [qId] Note implemented but would execute functions in a specific queue. Would allow for multiple queues.
     */
	execute : function (qId) {
	  var l = q.length, i;
	  var tempF;
	  for (i=0; i<l; i++) {
	    tempF = eval(q[i].fName);
		tempF.apply(tempF, q[i].args);
	  }
	}

	}
})(MAGNET);

/* Microsoft Audience Extension tag - 7/23/09 */
jQuery(function(){
    MSEXT_domain = document.location.host.split('.');
    MSEXT_domain = MSEXT_domain[(MSEXT_domain.length - 2)];
    MSEXT_path = document.location.pathname.split('/');
    MSEXT_request = document.location.protocol + "//view.atdmt.com/action/MSFT_CondeNet_AE_ExtData/v3/atc1." + MSEXT_domain;
    MSEXT_request += (MSEXT_path[1] != '' && MSEXT_path[1] != undefined) ? "/atc2." + MSEXT_path[1] : '';
    MSEXT_request += (MSEXT_path[2] != '' && MSEXT_path[2] != undefined) ? "/atc3." + MSEXT_path[2] : '';
    MSEXT_request += '/';
    jQuery('body').append('<img src="'+MSEXT_request+'" height="1" width="1" border="0" />');
});