	// Translates characters in str using given translation tables  
	function strtr (str, from, to) {
		var fr = '', i = 0, j = 0, lenStr = 0, lenFrom = 0, tmpStrictForIn = false, fromTypeStr = '', toTypeStr = '', istr = '';
		var tmpFrom = [];
		var tmpTo = [];
		var ret = '';
		var match = false;

		// Walk through subject and replace chars when needed
		lenStr  = str.length;
		lenFrom = from.length;
		fromTypeStr = typeof from === 'string';
		toTypeStr = typeof to === 'string';

		for (i = 0; i < lenStr; i++) {
			match = false;
			if (fromTypeStr) {
				istr = str.charAt(i);
				for (j = 0; j < lenFrom; j++) {
					if (istr == from.charAt(j)) {
						match = true;
						break;
					}
				}
			}
			else {
				for (j = 0; j < lenFrom; j++) {
					if (str.substr(i, from[j].length) == from[j]) {
						match = true;
						// Fast forward
						i = (i + from[j].length)-1;
						break;
					}
				}
			}
			if (match) {
				ret += toTypeStr ? to.charAt(j) : to[j];
			} else {
				ret += str.charAt(i);
			}
		}

		return ret;
	}

	function removeAccents(string) {
		string = strtr(string, "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿ","AAAAAAACEEEEIIIIDNOOOOOOUUUUYbsaaaaaaaceeeeiiiidnoooooouuuyyby").replace(/[^a-zA-Z0-9]+/g,'').toLowerCase();  

		return string;
	}

	function querySt(ji) {
		hu = window.location.search.substring(1);
		gy = hu.split("&");
		for (i=0;i<gy.length;i++) {
			ft = gy[i].split("=");
			if (ft[0] == ji) {
				return ft[1];
			}
		}
		return '';
	}

	function objOmniture() { 
		this.zone = '';										// Default Omniture section
		if ((typeof(ei_SiteSection) !== 'undefined') && (ei_SiteSection != '')) this.zone = ei_SiteSection.toLowerCase().replace(' ', '');	// Section provided by Emmis
		if ((typeof(arZoneOverride) !== 'undefined') && (arZoneOverride != '')) this.zone = arZoneOverride.toLowerCase().replace(' ', '');	// Allows the section to be overridden by the webmaster
		s.channel=s.prop2=this.zone;
		s.prop18=s.eVar18=(ei_UserID != "") ? "logged in" : "not logged in";

		this.writeOmniture = function () {
			var s_code = s.t();
			if (s_code) document.write(s_code);
		}
	}

	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g, "");
	}

	function getTitles(type) {
		var titles = document.title.split("::", 3);
		var tLength = titles.length;

		switch(type) {
			case 'defaultTitle':
				return (typeof(titles[0]) != 'undefined') ? trim(titles[0]) : '';
				break;
			case 'dynamicTitle':
				if (tLength == 3)
					return (typeof(titles[1]) != 'undefined') ? trim(titles[1]) : '';
				else
					return '';
				break;
			case 'customTitle':
				if (tLength == 3)
					return (typeof(titles[2]) != 'undefined') ? trim(titles[2]) : '';
				else
					return (typeof(titles[1]) != 'undefined') ? trim(titles[1]) : '';
				break;
		}
	}

	function objDart() {
		this.site = 'sri.remontreal'					// Default site
		this.section = 'ROS';							// Default Dart section
		this.position = 'top';
		this.tile = 1;
		this.size = '728x90';
		this.randNum = Math.random() * 10000000000000000; // do not override this property as it must stay consistant throughout the page
		this.keyvalues = ';ss=' + removeAccents(getTitles('dynamicTitle')) + ';ss=' + removeAccents(getTitles('customTitle'));

		this.writeBanner = function() {
			var keyvalues = this.keyvalues;
			if ((typeof ei_SiteSection !== 'undefined') && (ei_SiteSection != '')) this.section = ei_SiteSection.toLowerCase().replace(' ', ''); // Section provided by Emmis
			if ((typeof arZoneOverride !== 'undefined') && (arZoneOverride != '')) this.section = arZoneOverride.toLowerCase().replace(' ', ''); // Allows the section to be overridden by the webmaster
			var section = this.section;
			if (parseInt(querySt("dartTest")) == 1) { this.site = 'sri.testing'; }	// Activate the Dart test zone via dartTest=1 in querystring (typically used for english sites)
			if (parseInt(querySt("dartTest")) == 2) { this.site = 'sri.testing2'; } // Activate the Dart test zone via dartTest=1 in querystring (typically used for french sites)
			if (this.tile == 1) keyvalues += ';dcopt=ist';							// Enable DHTML for top leaderbaord
			if ((this.tile > 2) && (this.tile != 5)) this.position = 'bottom';		// below the fold, execption for 295x95 for radionrj.ca (tile=5)
			if (this.tile == 3) section = 'lowerdisplaypackage';					// for stations with more than 2 ad units
			document.write("<sc"+"ript type=\"text/jav"+"ascript\" src=\"http://ad.double"+"click.net/adj/"+this.site+"/"+section+keyvalues+";pos="+this.position+";tile="+this.tile+";sz="+this.size+";ord="+this.randNum+"?\"><\/scr"+"ipt>");
		}
	}

	function writeComscore() {
		newImg = new Image(1, 1);
		newImg.id = 'comscorebeacon';
		newImg.src = "http://beacon.scorecardresearch.com/scripts/beacon.dll?C1=2&C2=3000024&C3=3000024&C4=" + escape(window.location.hostname) + escape(window.location.pathname) + "&C5=&C6=&C7=" + escape(window.location.href) + "&C8=" + escape(document.title) + "&C9=" + escape(document.referrer) + "&rn=" + Math.floor(Math.random()*99999999);
	}

function loadScript(url, callback) {
    var script = document.createElement("script")
    script.type = "text/javascript";

    if (script.readyState){  //IE
        script.onreadystatechange = function() {
            if (script.readyState == "loaded" ||
                    script.readyState == "complete"){
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //Others
        script.onload = function(){
            callback();
        };
    }

    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}

function writePlayer(publisherID, playerID, refID, width, height) {
  brightcove.createExperiences();
  $(document).ready( function() {document.getElementById(refID).innerHTML = '<div style="display:none"></div><object id="myExperience" class="BrightcoveExperience"><param name="bgcolor" value="#000000" /><param name="width" value="'+width+'" /><param name="height" value="'+height+'" /><param name="playerID" value="'+playerID+'" /><param name="publisherID" value="'+publisherID+'"/><param name="isAudio" value="true" /><param name="isUI" value="true" /><param name="dynamicStreaming" value="true" /><param name="@audioPlayer" value="ref:'+refID+'" /></object>';} );
}

function writePlayerBurli(refID) {
	writePlayer(85733530001, 593291619001, refID, 300, 20);
}

function writePlayerMusic(refID) {
	writePlayer(85733530001, 109304487001, refID, 25, 25);
}

function writePlayerAudio(publisherID, refID) {
	writePlayer(publisherID, 109304487001, refID, 25, 25);
}

function openMP3player(idmulti, titre, table) {
	if (!table){table = 'multimedia'};	
	player_link = "http://" + getDomain() + "/" + getRegion() + "/musique/playerMP3/?id=" + idmulti + "&titre=" + titre + "&table=" + table + '&dartSite=' + arDart.site.replace("sri.", "");		
	
	sv_window = window.open(player_link, "lecteur", "width=748,height=450,left=100,top=200");
	sv_window.focus();
}

function getRegion() {
	var region = '';
	switch (arDart.site) {
		case 'sri.redrummondville':
			region = 'drummondville';
			break;
		case 'sri.regatineau':
			region = 'gatineau';
			break;
		case 'sri.remontreal':
			region = 'montreal';
			break;
		case 'sri.requebec':
			region = 'quebec';
			break;
		case 'sri.rerimouski':
			region = 'rimouski';
			break;
		case 'sri.rerouyn':
			region = 'rouyn';
			break;
		case 'sri.resaguenay':
			region = 'saguenay';
			break;
		case 'sri.resherbrooke':
			region = 'estrie';
			break;
		case 'sri.retroisrivieres':
			region = 'mauricie';
			break;
		case 'sri.revaldor':
			region = 'valdor';
			break;
		case 'sri.rdamqui':
			region = 'amqui';
			break;
		case 'sri.rddrummondville':
			region = 'drummondville';
			break;
		case 'sri.rdestrie':
			region = 'estrie';
			break;
		case 'sri.rdgatineau':
			region = 'gatineau';
			break;
		case 'sri.rdmauricie':
			region = 'mauricie';
			break;
		case 'sri.rdmontreal':
			region = 'montreal';
			break;
		case 'sri.rdquebec':
			region = 'quebec';
			break;
		case 'sri.rdrimouski':
			region = 'rimouski';
			break;
		case 'sri.rdsaguenay':
			region = 'saguenay';
			break;
	}
	return region;
}

function getDomain() {
	switch (arDart.site.substring(0, 6)) {
	case 'sri.re':
		return 'www.radionrj.ca';
		break;
	case 'sri.rd':
		return 'www.rockdetente.com';
		break;
	case 'sri.bm':
		return 'www.boomfm.com';
		break;
	default:
		var host=/([^\.]+\.)?([^\.]+)(\.[^\\/\\]+\/|\\)?/.exec(location.hostname) || [];
		host = window.location.hostname.split('.');
		return host[host.length - 2]+'.'+host[host.length - 1];
	}
}

function writeHitlistPreview(nb, hitlistID) {
	if (typeof(hitlistID) == 'undefined') hitlistID = '';
	if (typeof(nb) == 'undefined') nb = 1;
	document.write('<div id="retrievedData">&nbsp;</div>');
	$.get("/EI/SharedObjects/Handlers/ProxyHandler.ashx?url=http://www.radionrj.ca/" + getRegion() + "/index/test/id/" + hitlistID + "&nb=" + nb, function(data) {
	$("#retrievedData").html(data);
	});
}
function writeAlbumListener() {
	var albumID = querySt('albumID');
	if (typeof(albumID) == 'undefined') albumID = '';
	var page = querySt('page');
	if (typeof(page) == 'undefined') page = '';
	document.write('<div id="retrievedData">&nbsp;</div>');
	$.get("/EI/SharedObjects/Handlers/ProxyHandler.ashx?url=http://www.radionrj.ca/index/testsalleecoute&albumID=" + albumID + "&page=" + page, function(data) {
	$("#retrievedData").html(data);
	});
}

function writeBurli(limit) {
	var articleID = querySt('articleID');
	if (typeof(articleID) == 'undefined') articleID = '';
	if (typeof(limit) == 'undefined') limit = '';
	if (typeof(retourLink) == 'undefined') retourLink = '';
	document.write('<div id="retrievedData">&nbsp;</div>');
	$.get("/EI/SharedObjects/Handlers/ProxyHandler.ashx?url=http://www.radionrj.ca/index/testnews&articleID=" + articleID + "&dartSite=" + arDart.site + "&limit=" + limit + "&retourLink=" + retourLink, function(data) {
	$("#retrievedData").html(data);
	});
}

function openLivePlayer(URL) {
                day = new Date();
                id = day.getTime();
                eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=750,height=500,left = 0,top = 0');");
}

function debug(string) {
                alert(string);      
}

function open160x80AdWindow() {
                var rando;
                rando = Math.floor(Math.random()*500001);
                document.getElementById('hitlistBanner').innerHTML = '';
                document.getElementById("hitlistBanner").innerHTML = '<a href="http://ad.doubleclick.net/jump/' + arDart.site + '/' + arDart.section + ';pos=top;ss=' + removeAccents(getTitles('customTitle')) + ';tile=6;sz=160x80;ord=' + arDart.randNum + ';cb=' + rando + '?" target="_blank"><img id="dartimg" src="http://ad.doubleclick.net/ad/' + arDart.site + '/' + arDart.section + ';pos=top;ss=' + removeAccents(getTitles('customTitle')) + ';tile=6;sz=160x80;ord=' + arDart.randNum + ';cb=' + rando + '?" width="160" height="80" border="0" alt=""/></a>';
                $("#voting").dialog("open");     
                $("#closeVote").live("click", function() {
                                               $("#voting").dialog("close");
                               });           
}

function openUrlInNewWindow(url) {
                var pageForm = document.getElementById("aspnetForm");
                var currentAction = pageForm.action;

                document.getElementById("__VIEWSTATE").name = "VIEWSTATE";
                document.getElementById("__EVENTTARGET").name = "EVENTTARGET";
                document.getElementById("__EVENTARGUMENT").name = "EVENTARGUMENT";

                pageForm.action = url;
                pageForm.target = '_new';
                pageForm.submit();
                pageForm.action = currentAction;
                pageForm.action = '_self';

                document.getElementById("__VIEWSTATE").name = "__VIEWSTATE";
                document.getElementById("__EVENTTARGET").name = "__EVENTTARGET";
                document.getElementById("__EVENTARGUMENT").name = "__EVENTARGUMENT";
}

function writeHitlist(hitlistID) {
                if (typeof(hitlistID) == 'undefined') hitlistID = '';
                if (!hitlistID)
                {
                               document.write('<link href="http://' + document.domain + '/Other/css/main.css" rel="stylesheet" type="text/css" media="all" /><link href="http://' + document.domain + '/Other/css/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" media="all" />');
                               document.write('<scr' + 'ipt type="text/jav' + 'ascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></scr' + 'ipt>');
                               document.write('<scr' + 'ipt type="text/jav' + 'ascript" src="http://' + document.domain + '/Other/js/jquery.commons.js"></scr' + 'ipt>');              

                               if (flashSupported)
                               {                                             
                                               document.write('<div id="voting"><p>Ton vote a bien été comptabilisé</p><br clear="all" /><div id="hitlistBanner"></div><br clear="all" /><div><input class="" id="closeVote" type="image"  src="http://' + document.domain + '/Pics/img_storage/HitListe/searchGo_btn.gif"/></div></div><br>&nbsp;<div id="hitlistflash" style="width:580px;"></div>');

                                               $(document).ready(function() {
                                                                              var randomnumber = Math.floor(Math.random()*5001);
                                                                              var so = new SWFObject("http://" + document.domain + "/Flash/hitlist.swf?cb=" + randomnumber, "mymovie", "580", "2330", "8", "#FFFFFF");
                                                                              so.addParam("quality", "high");
                                                                              so.addParam("wmode", "transparent");
                                                                              so.addVariable("document_domain", "http://" + document.domain);
                                                                              so.write("hitlistflash");
                                                               });
                               }
                } else {
                               document.write('<div id="retrievedData" style="padding-top:15px">&nbsp;</div>');
                               $.get("/EI/SharedObjects/Handlers/ProxyHandler.ashx?url=http://www.radionrj.ca/index/test/id/" + hitlistID, function(data) {
                               $("#retrievedData").html(data);
                               });
                }
}

function writeMultimediaList(idsection,full,reloadlist) {              
                var fulls = '';
                if (full){fulls = '_full';}
                var subfolder = ''; 
                if (document.domain.match(/radionrj/g)){
                               subfolder = 'RE';
                }
                else if (document.domain.match(/rockdetente/g)) {
                               subfolder = 'RD';
                }
                else if (document.domain.match(/boom/g)){
                               subfolder = 'Boom';
                }
                if (!reloadlist){
                               document.write('<link rel="stylesheet" type="text/css" href="/Other/CSS/audio_section.css" />');
                               document.write('<div id="extrait_audio_' + idsection + '" class="extraitAudio"></div>');
                }
                $.ajax({
                               type: "GET",
                               url: "/EI/SharedObjects/Handlers/ProxyHandler.ashx?url=http://www.radionrj.ca/rss/" + subfolder + "/section/" + idsection + fulls + ".xml",
                               dataType: "xml",
                               success: function (xml){
                                               var html_text = '<ul>';
                                               var i = 1;
                                               if (reloadlist){
                                                               $("#href_voirplus_" + idsection).replaceWith('Plus...');
                                               }              
                                               $(xml).find("item").each(function(){
                                                                              html_text += '<li onclick=\'openMP3player("' + $(this).find("idmulti").text() + '","' + $(this).find("urlencodedtitle").text() + '","multimedia");\'><a href="javascript:">' + $(this).find("title").text() + '</a></li>';
                                                               i++;
                                               });
                                               html_text += '</ul>';                                    
                                               if (!full && i >= 25){
                                                               html_text += '<div id="div_voirplus_' + idsection + '" style="padding-top:10px;"><a id="href_voirplus_' + idsection + '" href="javascript:" onClick="writeMultimediaList(' + idsection + ',1,1)">Voir plus >></a></div>'; 
                                               }              
                                               $("#extrait_audio_" + idsection).append(html_text);
                               }
                });
}