/* Newer functions2 */

/* Simple AJAX: function, action (url/path), asynchronous (optional) */
SimpleAjax = function(f,ac,as) {
	this.func = f;
	this.action = ac;
	this.async = as;
	
	this.method;
	this.request;
	
	this.text;
	this.xml;
	
	var me = this;
	
	this.setFunction = function( n ) {
		me.func = n;
	}
	
	this.setAction = this.setURL = this.setPath = function( n ) {
		me.action = n;
	}
	
	this.setAsync = function( n ) {
		me.async = n;
	}
	
	this.get = function() {
		me.method='get';
		me.performRequest();
	}
	
	this.post = function() {
		me.method='post';
		me.performRequest();
	}
	
	this.put = function() {
		me.method='put';
		me.performRequest();
	}
	
	this.del = function() {
		me.method='delete';
		me.performRequest();
	}
	
	this.isXML = function() {
		return me.responseIsXML;
	}
	
	this.getResponseText = function() {
		return me.text;
	}
	
	this.getResponseXML = function() {
		return me.xml;
	}
	
	this.performRequest = function() {
		if( !def(me.async) ) me.async = true;
		if( !def(me.method) || !def(me.action) ) return;

		/* if this request is already pending, then cancel it */
		if( def(me.request) ) {		// if a request has been called already
			if( def(me.request.readyState) && me.request.readyState != 0 && me.request.readyState != 4 ) {
				me.request.abort();
			}
			me.request = null;
			me.request = undefined;
		}
		
		me.request = me.getRequest();
		
		var onStateChange;
		if( def( me.func ) ) {

			onStateChange = me.request.onreadystatechange = function() {
				
				if( def(me.request) && 
					me.request.readyState==4 && 
					def(me.request.status) && 
					(me.request.status==200 || me.request.status==0) 
					) 
				{
					if( me.request.responseText.substring(0,5)=='<?xml') {
						me.responseIsXML = true;
					} else {
						me.responseIsXML = false;
					}
					me.text = me.request.responseText;
					me.xml = me.request.responseXML;
					
					me.request = null;
					me.request = undefined;
					
					me.func( me );
				} 
			} // end of onreadystatechange function
		} // end of if def func
		
		//dbg( me.method + ' and '+ me.action + ' and ' +me.async );
		me.request.open( me.method, me.action, me.async );
		me.request.send( null );
		
		// sometimes, some browsers perform the request too quickly, and the onstatechange event fires too quickly -- this calls it explicitly
		if( def(onStateChange) ) {
			onStateChange();
		}
	}
	
	this.getRequest = function() {
		var req;
		try { return new XMLHttpRequest(); }
		catch(error) {
			try{ return new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(error) { return ""; }
		}
	}
}

var req = new Object()
function openreq(func,meth,path,async) {
	if(async==undefined) async=true;
	if(req[path]!=undefined&&req[path]!=null&&req[path].readyState!=0&&req[path].readyState!=4) { // if never, or already, run(ning)
		req[path].abort();
	}
	req[path]=getreq();
	var thisreq = req[path];
	if(func!=undefined) {
		var thisfunc = func;
		var a = thisreq.onreadystatechange = function() {
			var p = path;
			if(thisreq.readyState==4 && req[p]!=undefined ) {
				if((thisreq.status==200||thisreq.status==0)) {
					req[p] = undefined;
					if(thisreq.responseText.substring(0,5)=='<?xml') {
						thisfunc(thisreq.responseXML);
					} else {
						thisfunc(thisreq.responseText);
					}
				}
			}
		}
	}
	req[path].open(meth,path,async);
	thisreq.send(null);
	a();
	
	return req[path];
}

function getreq() {
	var req;
	try { return new XMLHttpRequest(); }
	catch(error) {
		try{ return new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(error) { return ""; }
	}
}	

function div(id) {
   var d = document.getElementById(id);
   return ( d==undefined ? '' : d );
}

function insertAfter(newChild, refChild) { 
	refChild.parentNode.insertBefore(newChild,refChild.nextSibling); 
} 

setupPolls = function() {
	var submit = div('submitPoll');
	if( submit!="" ){
		submit.onclick = function() {
			var form = div('pollForm');
			var accountID = div('account_id').value;
			var pollID = form['pollID'].value;
			var answerIDs = form['answerID'];
			var answerID = 0;
			if( answerIDs!=undefined && answerIDs.length!=undefined ) {
				for(var i=0;i<answerIDs.length;i++) {
					if(answerIDs[i].checked)answerID=answerIDs[i].value;
				}
			}
			
			if( Web.Cookie.get('poll-answered') && Web.Cookie.get('poll-answered')=='1' ) {
				answerID = 0;
			}
			
			var action = "/__webservices/?method=getPollResults&arg1="+accountID+"&arg2="+pollID+"&arg3="+answerID+"&arg4=0";
			//SimpleAjax = function(f,ac,as) {
			
			div('pollComp').style.display='none'; 
			div('pollLoading').style.display=''; 
			
			var aj = new SimpleAjax(
				function( req ) {
					Web.Cookie.set('poll-answered','1',1);
					
					var d = div('pollComp');
					//d.parentNode.removeChild( d );
					d.style.display='none';
					var nav = div('nav_container');
					var newd = document.createElement('div');
					newd.innerHTML = req.getResponseText();
					div('pollLoading').style.display='none'; 
					insertAfter(newd,d);
				},
				action
			);
			aj.get();
		}
	}
}

addLoadEvent( setupPolls );

__rootCreate = crind = function(){
	var a=arguments,o=this;
	for(var i=0;i<a.length;i++) {
		if(o[a[i]]==undefined||!isObject(o[a[i]]))o[a[i]]={};
		o=o[a[i]];
	}
}

__rootCreate('Web');
Web.Cookie =
	{
		get: function(n)
		{
			var nEQ = n + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nEQ) == 0) return c.substring(nEQ.length,c.length);
			}
			return false;
		},
		
		set: function(n,v,d)
		{
			if (d) {
				var date = new Date();
				date.setTime(date.getTime()+(d*24*60*60*1000));
				var ex = "; expires="+date.toGMTString();
			}
			else var ex= "";
			document.cookie = n+"="+v+ex+"; path=/";
		},
		
		remove: function(n)
		{
			Web.Cookie.set(n,"",-1);
		},
		
		del: function(n)
		{
			Web.Cookie.remove(n);
		}
	};

function def(element) {
	return (element==undefined ? false : true);
}


/* Older Function */

var xmlHttpLoadingStatus = false;

function createDropDownBox(paraID, labelTxt, dropBoxName, dropBoxClassName, prevSibID) {

  // create new paragraph element to hold label and dropdown
  var para = document.createElement("p");
  // give the new para an id
  para.setAttribute("id",paraID);
  
  // create label element
  var labelElem = document.createElement("label");
  var labelElemTxt = document.createTextNode(labelTxt);
  // add text to label
  labelElem.appendChild(labelElemTxt);
  // add label to para
  para.appendChild(labelElem);
  
  // create the provinces drob down box
  var dropBox = document.createElement("select");
  // set province drop down attributes
  dropBox.setAttribute("className",dropBoxClassName);
  dropBox.setAttribute("class",dropBoxClassName);
  dropBox.setAttribute("name",dropBoxName);
  highlightInput(dropBox);
  
  para.appendChild(dropBox);
  
  insertAfter(para,prevSibID);
  
  return dropBox;
}

function createTextField(paraID, labelTxt, txtFieldName, txtFieldClassName, txtFieldVal, prevSibID) {
        
  // create region text box
  var para = document.createElement("p");
  para.setAttribute("id",paraID);
  
  // create label
  var labelElem = document.createElement("label");
  var labelElemTxt = document.createTextNode(labelTxt);
  labelElem.appendChild(labelElemTxt);
  
  // create text box
  var txtBox = document.createElement("input");
  txtBox.setAttribute("type","text");
  txtBox.setAttribute("name",txtFieldName);
  txtBox.setAttribute("class",txtFieldClassName);
  txtBox.setAttribute("className",txtFieldClassName);
  txtBox.setAttribute("value",txtFieldVal);
  highlightInput(txtBox);
  
  // append elements to paragraph
  para.appendChild(labelElem);
  para.appendChild(txtBox);
  
  insertAfter(para,prevSibID);
  
  return txtBox;
}

function insertAfter(newNode, siblingID) {
  
  //alert(siblingID);
  
  if(siblingID.nodeType == 1) {
    var sibling = siblingID;
  } else {
    var sibling = document.getElementById(siblingID);
  }
  
  var theNextSibling = sibling.nextSibling;
  var theSiblingsParent = sibling.parentNode;
  
  if(theNextSibling) {
    theSiblingsParent.insertBefore(newNode,theNextSibling);
  } else {
    theSiblingsParent.appendChild(newNode);
  } 
}

function createXMLHttpRequest(){
    
    var xmlHttp;
  
    if (window.ActiveXObject){
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
    
    return xmlHttp;
}

// function to show loading animation when Ajax Loading
function showLoadAnimation(divID) {
  
  if(!xmlHttpLoadingStatus) {
    
    xmlHttpLoadingStatus = true;
    
    var titleBar = document.getElementById("month_view").getElementsByTagName("thead")[0].getElementsByTagName("td")[0];
    
    //var toolTip = document.getElementById(divID);
    
    var ptag = document.createElement("p");
    ptag.setAttribute("id","loading_p");
    ptag.style.margin = "0px";
    
    var loading_text = document.createTextNode("Please wait while loading events...");
    
    ptag.appendChild(loading_text);
    
    //toolTip.appendChild(ptag);
    
    titleBar.appendChild(ptag);
  }
}


// clear loading animation when Ajax call finished loading
function clearLoadAnimation() {
  
  xmlHttpLoadingStatus = false;
  
  var loading_p = document.getElementById("loading_p");
  
  if(loading_p) {
    var contain_form = loading_p.parentNode;
    contain_form.removeChild(loading_p);
  }
}

function XMLRequestParamsURL() {
  var args = arguments;

  var recom = new String();
  
  recom = recom.concat("__webservices/?request=");

  recom = recom.concat("<request>");
  
  recom = recom.concat("<key>wIDZW8Rta7Joo0mNE8GK8g==</key>");
  
  recom = recom.concat("<function>");
  recom = recom.concat("<name>" + args[0] + "</name>");
  
  if(args.length > 1) {
    
    recom = recom.concat("<params>");
    
    for(var i = 1; i < args.length; i++) {
      if (i % 2){ //if odd
        recom = recom.concat("<param><name>" + args[i] + "</name>");
      } else {
        recom = recom.concat("<value>" + args[i] + "</value></param>");
      }
    }
    
    recom = recom.concat("</params>");
  }
  
  recom = recom.concat("</function>");
  
  recom = recom.concat("</request>");
  
  recom = recom.concat("&ts=" + new Date().getTime());
  
  return recom;

}

/* MEDIA RELEASES */

/* HTTP */
HTTP = {};

HTTP.status = function(_status){
    
    var s = _status.toString().split("");
    
    switch(s[0]){
        case "1":
            return this.getInformationalStatus(_status);
            break;
        case "2":
            return this.getSuccessfulStatus(_status);
            break;
        case "3":
            return this.getRedirectStatus(_status);
            break;
        case "4":
            return this.getClientErrorStatus(_status);
            break;
        case "5":
            return this.getServerErrorStatus(_status);
            break;
        default:
            return "An unexpected error has occurred.";
    }
    
}

HTTP.getInformationalStatus = function(_status){
    
    switch(_status){
        case 100:
            return "Continue";
            break;
        case 101:
            return "Switching Protocols";
            break;
        default:
            return "An unexpected error has occured";
    }
    
}

HTTP.getSuccessfulStatus = function(_status){
    
    switch(_status){
        
        case 200:
            return "OK";
            break;
        case 201:
            return "Created";
            break;
        case 202:
            return "Accepted";
            break;
        case 203:
            return "Non-Authoritative Information";
            break;
        case 204:
            return "No Content";
            break;
        case 205:
            return "Reset Content";
            break;
        case 206:
            return "Partial Content";
            break;
        default:
            return "An unexpected error has occurred.";
    }
    
}

HTTP.getRedirectionStatus = function(_status){
    
    switch(_status){
        
        case 300:
            return "Multiple Choices";
            break;
        case 301:
            return "Moved Permanently";
            break;
        case 302:
            return "Found";
            break;
        case 303:
            return "See Other";
            break;
        case 304:
            return "Not Modified";
            break;
        case 305:
            return "Use Proxy";
            break;
        case 307:
            return "Temporary Redirect";
            break;
        default:
            return "An unexpected error has occurred.";
    }
    
}

HTTP.getClientErrorStatus = function(_status){
    
    switch(_status){
        
        case 400:
            return "Bad Request";
            break;
        case 401:
            return "Unauthorized";
            break;
        case 402:
            return "Payment Required";
            break;
        case 403:
            return "Forbidden";
            break;
        case 404:
            return "File not found";
            break;
        case 405:
            return "Method not allowed";
            break;
        case 406:
            return "Not acceptable";
            break;
        case 407:
            return "Proxy Authenticaton Required";
            break;
        case 408:
            return "Request Timeout";
            break;
        case 409:
            return "Conflict";
            break;
        case 410:
            return "Gone";
            break;
        case 411:
            return "Length Required";
            break;
        case 412:
            return "Precondition Failed";
            break;
        case 413:
            return "Request entity too large";
            break;
        case 414:
            return "Request-URI too long";
            break;
        case 415:
            return "Unsupported Media Type";
            break;
        case 416:
            return "Requested Range Not Satisfied";
            break;
        case 417:
            return "Expectation Failed";
            break;
        default:
            return "An unexpected error has occurred.";
    }
    
}

HTTP.getServerErrorStatus = function(_status){
    
    switch(_status){
        
        case 500:
            return "Internal Server Error";
            break;
        case 501:
            return "Not Implemented";
            break;
        case 502:
            return "Bad Gateway";
            break;
        case 503:
            return "Service Unavailable";
            break;
        case 504:
            return "Gateway Timeout";
            break;
        case 505:
            return "HTTP Version not supported";
            break;
        default:
            return "An unexpected error has occurred.";
    }
    
}


/* XMLRequest */
function XMLRequest() {

  this.key = "";
  
  this.func = "";
  
  this.params = new Array();
  
}

XMLRequest.prototype.setKey = function(_key) {
  this.key = _key;
}

XMLRequest.prototype.setFunction= function(_func) {
  this.func = _func;
}

XMLRequest.prototype.addParam = function(_name,_value) {
  this.params[_name] = _value;
}

XMLRequest.prototype.toString = function() {
  return this.buildXML();
}

XMLRequest.prototype.buildXML = function() {

  var str = new String();
  
  str = str.concat("<request>");
  
  str = str.concat("<key>" + this.key + "</key>");
  
  str = str.concat("<function>");
  str = str.concat("<name>" + this.func + "</name>");
    
  str = str.concat("<params>");
  
  for(var j in this.params) {
      str = str.concat("<param><name>" + j + "</name><value>" + this.params[j] + "</value></param>");
  }
  
  str = str.concat("</params>");
  
  str = str.concat("</function>");
  
  str = str.concat("</request>");
  
  return str;
  
}

/* Ajax */
Ajax = {};

Ajax.makeRequest = function (method, url, callbackMethod) {
    this.request = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP");
    this.request.onreadystatechange = callbackMethod;
    this.request.open(method, url, true);
    this.request.send(url);
}

Ajax.checkReadyState = function(_id) {
    
    switch(this.request.readyState){
        case 1:
            //loading
            break;
        case 2:
            //loading
            break;
        case 3:
            //loading
            break;
        case 4:
            AjaxUpdater.isUpdating = false;
            return HTTP.status(this.request.status);
        default:
            // an unexpected error has occured
    }
    
}

Ajax.getResponse = function() {
    
    if (this.request.getResponseHeader('Content-Type').indexOf('xml') != -1){
        return this.request.responseXML.documentElement;
    } else {
        return this.request.responseText;
    }
    
}


/* AjaxUpdater */
AjaxUpdater = {};

AjaxUpdater.initialize = function() {
    AjaxUpdater.isUpdating = false;
    AjaxUpdater.pool = new Array();
    AjaxUpdater.poolIndex = 0;
    AjaxUpdater.interval = null;
    AjaxUpdater.ajaxCallback;
}

AjaxUpdater.initialize();

AjaxUpdater.add = function(method, service, callback) {

    if (callback == undefined || callback == ""){
        callback = AjaxUpdater.onResponse;
    }
     
    var update = new AjaxUpdate(method, service, callback);
    AjaxUpdater.pool.push(update);
    
}

AjaxUpdater.execute = function(){
    
    if (AjaxUpdater.poolIndex >= AjaxUpdater.pool.length) {
        //clearInterval(AjaxUpdater.interval);
        return false;
    }
    
    if (!AjaxUpdater.isUpdating) {
        
        if (AjaxUpdater.pool[AjaxUpdater.poolIndex]) {
            AjaxUpdater.pool[AjaxUpdater.poolIndex].execute();
            AjaxUpdater.poolIndex++;
        }
        
    }
    
}


AjaxUpdater.update = function(method, service, callback) {
    
    if (callback == undefined || callback == ""){
        callback = AjaxUpdater.onResponse;
    }
    
    Ajax.makeRequest(method, service, callback);
    AjaxUpdater.isUpdating = true;
    
}


AjaxUpdater.onResponse = function() {
    
    if (Ajax.checkReadyState('loading') == 200){
        AjaxUpdater.isUpdating = false;
    }
    
}

AjaxUpdater.callback = function() {
  
}


/* AjaxUpdate Object */

//constructor
function AjaxUpdate(method, service, callback){
    this.method = method;
    this.service = service;
    this.callback = callback;
}

AjaxUpdate.prototype.execute = function() {
    Ajax.makeRequest(this.method, this.service, this.callback);
    AjaxUpdater.isUpdating = true;
}


/* MediaRelease */
function MediaRelease(headline, subheadline, abstract, url, date){
    this.headline = headline;
    this.subheadline = subheadline;
    this.abstract = abstract;
    this.url = url;
    this.date = new Date(date.replace(/[-]/g," "));
    this.daynames = {
			'en':
				["Sunday",
       	              "Monday",
              	       "Tuesday",
                     	"Wednesday",
	                     "Thursday",
      		              "Friday",
      	       	       "Saturday"],
			'fr-ca':
				["dimanche",
       	              "lundi",
              	       "mardi",
                     	"mercredi",
	                     "jeudi",
      		              "vendredi",
      	       	       "samedi"]
			};
                     
    this.monthnames = {
			'en':
				["January",
	                       "February",
	                       "March",
	                       "April",
	                       "May",
	                       "June",
	                       "July",
	                       "August",
	                       "September",
	                       "October",
	                       "November",
	                       "December"],
			'fr-ca':
				["janvier",
	                       "fevrier",
	                       "mars",
	                       "avril",
	                       "mai",
	                       "juin",
	                       "juillet",
	                       "aout",
	                       "septembre",
	                       "octobre",
	                       "novembre",
	                       "decembre"]
			};
}

MediaRelease.prototype.display = function(){
  
	var _container = document.createElement("div");
	_container.setAttribute("className","mediaRelease");
	_container.setAttribute("class","mediaRelease");

	if(typeof(this.headline) != "undefined" && this.headline != "") {
		var _headline = document.createElement("a");
		_container.setAttribute("className","headline");
		_container.setAttribute("class","headline");
		
		_headline.setAttribute("href",MediaReleaseManager.baseurl + MediaReleaseManager.pathurl + "?release_id=" + this.url);
		var _headline_text = document.createTextNode(this.headline);
		_headline.appendChild(_headline_text);
		
		_container.appendChild(_headline);
	}


	var _date = document.createElement("p");
	_date.setAttribute("className","date");
	_date.setAttribute("class","date");
	var _date_text = document.createTextNode(this.daynames[lang][this.date.getDay()] + " " +
		this.monthnames[lang][this.date.getMonth()] + " " +
		this.date.getDate() + ", " +
		this.date.getFullYear());

	_date.appendChild(_date_text);
	_container.appendChild(_date);
	
	if( showSubheadline ) {   
		if(typeof(this.subheadline) != "undefined" && this.subheadline != "") {
			var _subheadline = document.createElement("p");
			_subheadline.setAttribute("className","subheadline");
			_subheadline.setAttribute("class","subheadline");
			var _subheadline_text = document.createTextNode(this.subheadline);
			_subheadline.appendChild(_subheadline_text);
			
			_container.appendChild(_subheadline);
		}
	}
	
	if( showAbstract ) {   
		if(typeof(this.abstract) != "undefined" && this.abstract != "") {
			var _abstract = document.createElement("p");
			_abstract.setAttribute("className","abstract");
			_abstract.setAttribute("class","abstract");
			var _abstract_text = document.createTextNode(this.abstract);
			_abstract.appendChild(_abstract_text);
			_container.appendChild(_abstract);
		}
	}
	
	return _container;
}

/* Managers */
function Manager(){
    this.collection = new Array();
}

Manager.prototype.add = function(item){
    this.collection.push(item);
}

Manager.prototype.display = function(_id){
    
    var items = document.getElementById(_id);
    
    while(node = items.lastChild) {
      items.removeChild(items.lastChild);
    }
    
    for(var i = 0; i < this.collection.length; i++){
        var item = this.collection[i];
        items.appendChild(item.display());
    }
    
    // clear media release Manager stack
    MediaReleaseManager.clear();
    
}

Manager.prototype.parse = function(){
}

Manager.prototype.get = function(){
}

Manager.prototype.clear = function() { 
  this.collection = [];
}

MediaReleaseManager = new Manager();
MediaReleaseManager.categories = new Array();

MediaReleaseManager.parse = function() {
  
  if(Ajax.checkReadyState() == "OK") {
    
    var releases = Ajax.getResponse().getElementsByTagName("release");
    
    for(var i = 0; i < releases.length; i++) {
      
      if(Ajax.getResponse().getElementsByTagName("headline")[i].hasChildNodes()) {
        var headline = Ajax.getResponse().getElementsByTagName("headline")[i].firstChild.data;
      } else {
        var headline = "";
      }
      
      if(Ajax.getResponse().getElementsByTagName("subheadline")[i].hasChildNodes()) {
        var subheadline = Ajax.getResponse().getElementsByTagName("subheadline")[i].firstChild.data;
      } else {
        var subheadline = "";
      }
      
      if(Ajax.getResponse().getElementsByTagName("abstract")[i].hasChildNodes()) {
        var abstract = Ajax.getResponse().getElementsByTagName("abstract")[i].firstChild.data;
      } else {
        var abstract = "";
      }
      
      if(Ajax.getResponse().getElementsByTagName("release_id")[i].hasChildNodes()) {
        var headline_link = Ajax.getResponse().getElementsByTagName("release_id")[i].firstChild.data;
      } else {
        var headline_link = "";
      }
      
      if(Ajax.getResponse().getElementsByTagName("publish_date")[i].hasChildNodes()) {
        var publish_date = Ajax.getResponse().getElementsByTagName("publish_date")[i].firstChild.data;
      } else {
        var publish_date = "";
      }
      
      var release = new MediaRelease(headline, subheadline, abstract, headline_link, publish_date);
      
      MediaReleaseManager.add(release);
      
    }
    
    MediaReleaseManager.display("releases");
    
    AjaxUpdater.isUpdating = false;
    
    // continue the function chain
    //AjaxUpdater.execute();
     
  }
  
}

MediaReleaseManager.addCategory = function(_category) {
  this.categories.push(_category);
}

MediaReleaseManager.setLanguage = function(_lang) {
  this.language = _lang;
}

MediaReleaseManager.setLimit = function(_limit) {
  this.limit = _limit;
}

MediaReleaseManager.setBaseURL = function(url) {
  this.baseurl = url;
}

MediaReleaseManager.setMediaReleasePath = function(url) {
  this.pathurl = url;
}

MediaReleaseManager.buildRequest = function() {
  
  _xmlRequestObj = new XMLRequest();
  
  _xmlRequestObj.setKey("wIDZW8Rta7Joo0mNE8GK8g==");
  
  _xmlRequestObj.setFunction("GetMediaReleases");
  
  _xmlRequestObj.addParam("categories",this.categories.join(","));
  
  if(this.language) {
    _xmlRequestObj.addParam("language",this.language);
  }
  
  if(this.limit) {
    _xmlRequestObj.addParam("limit",this.limit);
  }
  
  return _xmlRequestObj.toString();
}

function setParams() {
	try {
		dbg(lang);
		if( lang=='fr' ) lang='fr-ca';
	} catch(e) { 
		__rootCreate('lang');
		lang = 'en'; 	
	}

	try { dbg(categoryId); 	} catch(e) { __rootCreate('categoryId'); categoryId=4; }
	try { dbg(limit); 		} catch(e) { __rootCreate('limit'); limit=5; }
	try { dbg(showSubheadline); 	} catch(e) { __rootCreate('showSubheadline'); showSubheadline=false; }
	try { dbg(showAbstract); 	} catch(e) { __rootCreate('showAbstract'); showAbstract=false; }

	MediaReleaseManager.addCategory( categoryId );
	MediaReleaseManager.setLimit( limit );

	// e.g., http://www.cfs-fcee.ca/html/english/media/mediapage.php?release_id=930

	MediaReleaseManager.setLanguage( lang );
	MediaReleaseManager.setBaseURL( 'http://www.cfs-fcee.ca' );	
	MediaReleaseManager.setMediaReleasePath( '/html/' + ( lang=='fr-ca' ? 'french' : 'english' ) + '/media/mediapage.php' );
}

/* exMediaRelease */
function initMR() {
	
	if( !div('releases') ) return;
	
	setParams();

	if( 0 ) {
		var req = MediaReleaseManager.buildRequest();
		for(var i=0;i<100;i++)
			req=req.replace('><',">\n<");
		alert(MediaReleaseManager.parse);
		return alert( req );
	}
	
	var request = "/__national/?request=" + MediaReleaseManager.buildRequest();
	
	AjaxUpdater.add("GET",request, MediaReleaseManager.parse);
	AjaxUpdater.execute();

	//setInterval("AjaxUpdater.update('GET','" + request + "', MediaReleaseManager.parse)",5000);
	setInterval( AjaxUpdater.update.bind(AjaxUpdater,'GET', request, MediaReleaseManager.parse) , 60000 );
}

addLoadEvent( initMR );
