/*
vrak.js
© 2009 vrak.tv
Minify with jsmin at http://jscompress.com/
*/

document.domain = 'vrak.tv';

function DomCheck(){
return(document.createElement && document.getElementById)
}

function DomCorners(id,bk,h,tries){
var el=document.getElementById(id);
if(el==null){                              // if the element isn't ready in the DOM...
    if(tries==null) tries=200;
    if(tries>0)                            // and there are still tries...
        setTimeout("DomCorners('"+id+"','"+bk+"',"+h+","+(--tries)+")",50);  // back in 50ms
    return;
    }
var c=new Array(4);
for(var i=0;i<4;i++){                      // create the four elements for rounded corners
    c[i]=document.createElement("b");
    c[i].style.display="block";            // with necessary style declarations
    c[i].style.height=h+"px";
    c[i].style.fontSize="1px";
    if(i%2==0)
        c[i].style.background="url("+bk+") no-repeat 0 -"+ i*h + "px";
    else
        c[i].style.background="url("+bk+") no-repeat 100% -"+ i*h + "px";
    }
c[0].appendChild(c[1]);
c[2].appendChild(c[3]);
el.style.padding="0";
el.insertBefore(c[0],el.firstChild);       // add top corners
el.appendChild(c[2]);                      // and bottom ones
}


// Banner adds
var si_site_name = 'sri.vrak';
var si_ord = Math.round(Math.random()*100000000000);
var tile = 0;
function SIWriteAdvert(si_zone, si_pos, si_size) {
	tile++;
	try {
		var dcopt_val = '';
		if (tile == 1) {
			dcopt_val='dcopt=ist;'
		}
		document.write("<sc"+"ript type=\"text/jav"+"ascript\" src=\"http://ad.double"+"click.net/adj/"+si_site_name+"/"+si_zone+";pos="+si_pos+";"+dcopt_val+"tile="+tile+";sz="+si_size+";ord="+si_ord+"?\"></scr"+"ipt>");
	} catch (e) {
		alert('error');
		return;
	}
}

// Browser detect
var browser;
var isIE4 = (document.all) ? true:false;
if (isIE4) {
  if (navigator.userAgent.indexOf('MSIE 6') > 0) {
    browser = 'IE6';
	} else if (navigator.userAgent.indexOf('MSIE 5') > 0) {
    browser = 'IE5';
  } else {
    browser = 'IE4';
  }
} else {
	if (navigator.userAgent.indexOf('Firefox') > 0) {
    browser = 'FFX';
	} else if (navigator.userAgent.indexOf('Netscape/7') > 0) {
    browser = 'NN7';
  } else if (navigator.userAgent.indexOf('Netscape6/6') > 0) {
    browser = 'NN6';
  } else {
    browser = 'NN4';
  }
}


// OS detect
var OS;
if (navigator.appVersion.indexOf("Mac") != -1) {
  OS = 'mac';
} else {
  OS = 'win';
}


// Fireworks rollovers
function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


// Layers
function MM_showHideLayers() { // v3.0
	var i, p, v, obj, args = MM_showHideLayers.arguments;
	for (i = 0; i<(args.length - 2); i += 3) if ((obj=MM_findObj(args[i]))!=null) {
		v = args[i+2];
		if (obj.style) {
			obj = obj.style;
			v = (v == 'show') ? 'visible' : (v='hide') ? 'hidden' : v;
		}
		obj.visibility = v;
	}
}


// Pop-ups centres
function popup(page, nom, w, h, t, l, d, s, m, sc, r) {
	var newleft = (screen.width - w) / 2;
	var newtop = (screen.height - h) / 2;
	var prop1 = "toolbar=" + t + ",location=" + l + ",directories=" + d + ",status=" + s + ",menubar=" + m + ",scrollbars=" + sc + ",resizable=" + r +",";
	var prop2 = "width=" + w + ",height=" + h + ",top=" + newtop + ",left=" + newleft;
	window.open(page, nom, prop1 + prop2);
}


// Print window
function printWindow(){
	bV = parseInt(navigator.appVersion)
	if (bV >= 4) window.print()
}


// Validation email
function checkIfMail(input) {
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(input);
}


// Drop-down box go to function
function goTo(list) {
	location.href = list.options[list.selectedIndex].value;
}


// Form validation
function checkMail(input) {
	var isMailAddressOK = false;
	var filterRegExp =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
	if (filterRegExp.test(input)) isMailAddressOK = true;
	return isMailAddressOK;
}

function getRadioValue(radioElement) {
	var checkedValue = -1;
	for (i=0; i<radioElement.length; i++) {
		if (radioElement[i].checked) {
			checkedValue = radioElement[i].value;
		}
	}
	return checkedValue;
}

function isValidEmail(emailAddress) {
	var isValid = false;
	var filterRegExp =/.(.*)\@(.*)\...(.*)/;
	if (filterRegExp.test(emailAddress)) {
		isValid = true;
	}
	return isValid;
}

function isValidFile(file) {
	var isValid = true;
	var indexJpeg;
	var indexJpg;
	var indexGif;
	indexJpeg = file.toLowerCase().lastIndexOf('.jpeg');
	indexJpg = file.toLowerCase().lastIndexOf('.jpg');
	indexGif = file.toLowerCase().lastIndexOf('.gif');
	if ((indexJpeg == -1) && (indexJpg == -1) && (indexGif == -1)) {
		isValid = false;
	}
	return isValid;
}

function isValidPhotoFile(file) {
	var isValid = true;
	var indexJpeg;
	var indexJpg;
	var indexGif;
	indexJpeg = file.toLowerCase().lastIndexOf('.jpeg');
	indexJpg = file.toLowerCase().lastIndexOf('.jpg');
	indexGif = file.toLowerCase().lastIndexOf('.gif');
	if ((indexJpeg == -1) && (indexJpg == -1) && (indexGif == -1)) {
		isValid = false;
	}
	return isValid;
}

function isValidVideoFile(file) {
	var isValid = true;
	var indexMov;
	var indexMpg;
	var indexWmv;
	var indexAvi;
	indexMov = file.toLowerCase().lastIndexOf('.mov');
	indexMpg = file.toLowerCase().lastIndexOf('.mpg');
	indexWmv = file.toLowerCase().lastIndexOf('.wmv');
	indexAvi = file.toLowerCase().lastIndexOf('.avi');
	if ((indexMov == -1) && (indexMpg == -1) && (indexWmv == -1) && (indexAvi == -1)) {
		isValid = false;
	}
	return isValid;
}

function checkRecr(recrForm) {
	var errorMsg = "Erreur :\n";
	for (var i=0; i<recrForm.length; i++) {
		var element = recrForm.elements[i];
		if ((element.type != "hidden") && (element.type != "submit") && (element.name.indexOf("optionnel") == -1)) {
			// Text
			if (element.type == "text") {
				if (element.value == "") {
					errorMsg += "Veuillez remplir le champ \"" + element.name + "\".\n";
				} else if (element.name.indexOf("Courriel") != -1 || element.name.indexOf("courriel") != -1) {
					if (!isValidEmail(element.value)) {
						errorMsg += "L'adresse de courriel pour \"" + element.name + "\" ne semble pas valide.\n";
					}
				}
			}
			// Textarea
			if (element.type == "textarea") {
				if (element.value == "") {
					errorMsg += "Veuillez remplir le champ \"" + element.name + "\".\n";
				}
			}
			// Radio
			if (element.type == "radio") {
				if (getRadioValue(recrForm.elements[element.name]) == -1) {
					if (errorMsg.indexOf(element.name) == -1) {
						errorMsg += "Veuillez faire votre choix pour \"" + element.name + "\".\n";
					}
				}
			}
			// Checkbox (release - voir www.canalvie.com/emission/monenfant_monheros/recrutement2.jsp)
			if (element.type == "checkbox" && element.name == "Release" && element.checked == false) {
					errorMsg += "\nVeuillez cocher la case \"" + element.value + "\".\nEn soumettant votre témoignage, vous devez accepter que \nLes Chaînes Télé Astral puissent publier votre texte, \nune partie de celui-ci ou encore toute photo \nque vous aurez jointe à votre témoignage.";
				}
			// Checkbox normal
			if (element.type == "checkbox" && element.name != "optionnel" && element.checked == false) {
					errorMsg += "Veuillez cocher la case \"" + element.name + "\".\n";
				}
			// File
			if (element.type == "file") {
				// Obligatoire
				if (element.name.indexOf("optionnel") == -1) {
					// Fichier vidéo
					if (element.name.indexOf("vidéo") != -1 || element.name.indexOf("Vidéo") != -1) {
						if (element.value == "") {
							errorMsg += "Veuillez sélectionner un fichier pour le champ \"" + element.name + "\".\n";
						} else {
							if (!isValidVideoFile(element.value)) {
								errorMsg += "Les seuls fichiers vidéos acceptés sont \".mov\", \".mpg\", \".wmv\" et \".avi\".\n";
							}
						}
					}
					// Fichier photo
					if (element.name.indexOf("photo") != -1 || element.name.indexOf("Photo") != -1) {
						if (element.value == "") {
							errorMsg += "Veuillez sélectionner un fichier pour le champ \"" + element.name + "\".\n";
						} else {
							if (!isValidPhotoFile(element.value)) {
								errorMsg += "Les seuls fichiers photos acceptés sont \".jpeg\", \".jpg\" et \".gif\".\n";
							}
						}
					}
				}
				// Optionnel
				if (element.name.indexOf("optionnel") != -1) {
					// Fichier vidéo
					if (element.name.indexOf("vidéo") != -1) {
						if (element.value != "") {
							if (!isValidVideoFile(element.value)) {
								errorMsg += "Les seuls fichiers vidéos acceptés sont \".mov\", \".mpg\", \".wmv\" et \".avi\".\n";
							}
						}
					}
					// Fichier photo
					if (element.name.indexOf("photo") != -1) {
						if (element.value != "") {
							if (!isValidPhotoFile(element.value)) {
								errorMsg += "Les seuls fichiers photos acceptés sont \".jpeg\", \".jpg\" et \".gif\".\n";
							}
						}
					}
				}
			}
		}
	}
	if (errorMsg != "Erreur :\n") {
		alert(errorMsg);
		return false;
	} else {
		if (recrForm.elements["Go"]) {
			recrForm.elements["Go"].disabled = true;
		}
		return true;
	}
}


// Cookies
function getCookie(cookieName) {
	var results = document.cookie.match (cookieName + '=(.*?)(;|$)');
	if (results) {
		return (unescape(results[1]));
	} else {
		return null;
	}
}

function setCookie(cookieName, cookieValue, cookieDays) {
	if (cookieDays) {
		var date = new Date();
		date.setTime(date.getTime() + (cookieDays*24*60*60*1000));
		var cookieExpires = "; expires=" + date.toGMTString();
	} else {
		var cookieExpires = "";
	}
	document.cookie = cookieName + "=" + cookieValue + cookieExpires + "; path=/";
}

// Function used to include js files. Script must "end" before included script can be active.
function jsInclude(jsFile) {
	document.write('<' + 'script');
	document.write(' language="JavaScript"');
	document.write(' type="text/javascript"');
	document.write(' src="' + jsFile + '">');
	document.write('</' + 'script' + '>');
}

// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004
function correctPNG() {
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}
if (isIE4) {
	window.attachEvent("onload", correctPNG);
}

// Presse - menu déroulant pour Archives
function jumpBox(list) {location.href =list.options[list.selectedIndex].value}
function dropdown() {document.theform.jump.options[0].selected=true}

function jumpBoxBlank(list) {
	url = list.options[list.selectedIndex].value;
	if (url != '') {
		window.open(url);
		}
	}

function wordWrap(){
/******
* wordWrap to firefox for big words
* Creative Commons license * Version: 1.0 - 26/04/2006
* Autor: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br - http://elmicoxcodes.blogspot.com
* Uso: call the function on onload of body element.
* put the class "word-wrap" on elements to wordwrap
*******/
    var larg_total,larg_carac,quant_quebra,pos_quebra;
    var elementos,quem, caracs, texto, display_orig;

    elementos = document.getElementsByTagName("p")

    for(var i=0; i<elementos.length;i++){
        if(elementos[i].className=="word-wrap"){
            quem = elementos[i];

            quem.innerHTML = String(quem.innerHTML).replace(/ /g,"Ø")
            texto = String(quem.innerHTML)

            quem.innerHTML = " "

            display_orig = quem.style.display;
            quem.style.display="block";
            larg_oficial = quem.offsetWidth;
            //alert("oficial: " + larg_oficial)
            //alert("display " + quem.style.display)
            if(!document.all) quem.style.display="table";
            //alert("display " + quem.style.display)
            quem.innerHTML = texto;
            larg_total = quem.offsetWidth;
            //alert("total: " + larg_total)

            pos_quebra = 0;
            caracs = texto.length;
            texto = texto.replace(/Ø/g," ")
            larg_carac = larg_total / caracs
            if(larg_total>larg_oficial){
                quant_quebra = parseInt(larg_oficial/larg_carac)
                quant_quebra = quant_quebra - (parseInt(quant_quebra/6)) //quanto menor o num, maior a garantia;
                quem.innerHTML = ""
                while(pos_quebra<=caracs){
				quem.innerHTML = quem.innerHTML + texto.substring(pos_quebra,pos_quebra + quant_quebra) + "(br /)"
				pos_quebra = pos_quebra + quant_quebra;
				}
            }else{
                quem.innerHTML = texto;
            }//end if do larg_total>larg_oficial
            quem.style.display = display_orig;
        }//end if do word wrap
    }//end for loop dos elementos
}


// Ajouter aux favoris
function favoris(pageName, pageUrl) {
	if ( navigator.appName != 'Microsoft Internet Explorer' ){
		window.sidebar.addPanel(pageName,pageUrl,"");
	} else {
		window.external.AddFavorite(pageUrl, pageName);
	}
}


// ## SWFOBJECT ##

/**
 * SWFObject v1.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 * legal reasons.
 */

if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
	if (!document.createElement || !document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute('version'), useExpressInstall);
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', useExpressInstall);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // Netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "PlugIn");
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "ActiveX");
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// Check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- Detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(reqVer, xiInstall){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			for (var i=3; axo!=null; i++) {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
				PlayerVersion = new deconcept.PlayerVersion([i,0,0]);
			}
		}catch(e){}
		if (reqVer && PlayerVersion.major > reqVer.major) return PlayerVersion; // Version is ok, skip minor detection
		// This only does the minor rev lookup if the user's major version
		// is not 6 or we are checking for a specific minor or revision number
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		if (!reqVer || ((reqVer.minor != 0 || reqVer.rev != 0) && PlayerVersion.major == reqVer.major) || PlayerVersion.major != 6 || xiInstall) {
			try{
				PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
			}catch(e){}
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) != null ? parseInt(arrVersion[0]) : 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}

/* ---- Get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param){
		var q = document.location.search || document.location.hash;
		if(q){
			var startIndex = q.indexOf(param +"=");
			var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
			if (q.length > 1 && startIndex > -1) {
				return q.substring(q.indexOf("=", startIndex)+1, endIndex);
			}
		}
		return "";
	}
}

/* Add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* Add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject;
var SWFObject = deconcept.SWFObject;


// ## VIDEO PLAYERS -- DEPRECATED ##
function videoPlayer(videoUrl, videoId, firstFrameUrl, autoPlay, isCanadaOnly, divId, SWFObject, proxyId, serverUrl, zoneId) {
	SWFObject.addParam("quality", "high");
	SWFObject.addParam("menu", false);
	SWFObject.addParam("wmode", "transparent");
	SWFObject.addParam('swliveconnect', 'true');
	SWFObject.addParam("allowScriptAccess","always");
	if (serverUrl) {
		// Plus utilisé, mais on le garde pour tous les call videoPlayer() dejà sur le site
		SWFObject.addVariable("zoneid", "'" + zoneId + "'");
	}
	SWFObject.addVariable("lcId", proxyId);
	SWFObject.addVariable('videoFirstFrameUrl', firstFrameUrl);
	SWFObject.addVariable("automaticPlay", autoPlay);
	SWFObject.addVariable("isCanadaOnly", isCanadaOnly);
	SWFObject.addVariable('videoUrl', videoUrl);
	SWFObject.addVariable("videoId", videoId);
	SWFObject.addVariable("urlMovie", document.location);
	SWFObject.write(divId);
}

// On print le menu flash
function printMainMenu(is6to12){
	var flashUrl = "";
	if (is6to12) {
		flashUrl = "/_img/header/menu_6_12.swf";
	} else {
		flashUrl = "/_img/header/menu_13_17.swf";
	}

	$("#menu_vrak").flash(
		{ src: flashUrl, width: 792, height: 47, bgcolor: '#f8f8f0', quality: 'high', menu: false, wmode: 'transparent', swliveconnect: 'true', allowScriptAccess: 'always', allowFullScreen: true, flashvars: {
			urlMovie: document.URL
			}
		},
		{ version: 8, update: true, expressInstall: true }
	);
};

// On incrémente le compteur de nouvelles
function incNewsCount(newsId) {
	var ieRant = Math.floor(Math.random()*1000001); // Generate random so that this f***ing IE browser does not cache xml response
	$.ajax({
		type: "GET",
		url: "/_dyn/incNewsCount.jsp",
		data: "newsId=" + newsId + "&ieRant=" + ieRant,
		dataType: "xml",
		success: function(xml) {
			// Do nothing
		}
	});
}

// On incrémente le compteur de bannière concours
function clickThroughDraw(drawId, imageId, statZone) {
	var ieRant = Math.floor(Math.random()*1000001); // Generate random so that this f***ing IE browser does not cache xml response
	$.ajax({
		type: "GET",
		url: "/_dyn/incDrawCount.jsp",
		data: "drawId=" + drawId + "&imageId=" + imageId + "&statZone=" + statZone + "&ieRant=" + ieRant,
		dataType: "xml",
		success: function(xml) {
			var opResult = $(xml).find("opResult").text();
			var opMessage = $(xml).find("opMessage").text();
			var linkUrl = $(xml).find("linkUrl").text();
			if (opResult == 'ok') {
				self.location.href = linkUrl;
			} else {
				alert(opMessage);
			}
		}
	});
}

function numericalOnly(inputStr, replaceOthersWith) {
	var output = inputStr.toLowerCase();

	// Whitelist character verification
	var allowedCharacters = "0123456789";
	var outputWithOnlyAllowedChars = "";

	for (var i=0; i<output.length; i++) {
		if (allowedCharacters.indexOf(output.charAt(i)) != -1) {
			outputWithOnlyAllowedChars += output.charAt(i);
		} else {
			outputWithOnlyAllowedChars += replaceOthersWith;
		}
	}

	return outputWithOnlyAllowedChars;
}

function alphaNumericalOnly(inputStr, replaceOthersWith) {
	var output = inputStr.toLowerCase();

	// Whitelist character verification
	var allowedCharacters = "a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9";
	var outputWithOnlyAllowedChars = "";

	for (var i=0; i<output.length; i++) {
		if (allowedCharacters.indexOf(output.charAt(i)) != -1) {
			outputWithOnlyAllowedChars += output.charAt(i);
		} else {
			outputWithOnlyAllowedChars += replaceOthersWith;
		}
	}

	return outputWithOnlyAllowedChars;
}

// Endswith
function endsWith(str, endStr) {

	// http://www.canalvie.com/ decoration/ : 39
	// decoration/ : 11
	var originalStringWithEndStrInserted = str.substring(0, str.length - endStr.length) + endStr;

	//alert("str.substring(str.length - endStr.length) + endStr : " + str.substring(0, str.length - endStr.length) + endStr);
	//alert("originalStringWithEndStrInserted : " + originalStringWithEndStrInserted);

	if (str == originalStringWithEndStrInserted) {
		return true;
	} else {
		return false;
	}
}

// Removes white space (leading and trailing)
function trim(toTrim) {
	return toTrim.replace(/^\s+/g,'').replace(/\s+$/g,'');
}

// ***************************************************** Ad tag generation script *****************************************************
var BASE_AD_TAG = "http://ad.doubleclick.net/adj/sri.";
var SUBDOMAINS_TO_IGNORE = "preprod, wc1, wc2, noc, dev, www, concours";
var pageTile=0;
var ord = "ord=" + Math.round(Math.random()*100000000000) + "?";

function printAdTag(adSize, position) {

	// Init vars
	// var pageURL = self.location.href; Is this for iframes?
	var pageUrl = document.location + "";
	var zonename = "";
	var keyvaluepair1 = "";
	var keyvaluepair2 = "";

	// Increment tiles
	pageTile++;

	// Dcopt for use with tile 1
	var dcopt = "";
	if (pageTile == 1) {
		dcopt = "dcopt=ist;";
	}

	// Adjust position for usage (valid values : top, bottom / Defaults to top)
	if (position == null) {
		var position = "top";
	}
	var pos = "pos=" + position + ";";

	// Valid sizes : 728x90, 300x250, 160x600
	if (adSize == undefined || adSize == '') return 0;

	// Remove http://subdomain.
	var pageUrlTransit = pageUrl.substring(pageUrl.indexOf(".")+1);

	// Split url on /
	var urlSplitArray = pageUrlTransit.split("/");

	// Add site to base ad tag
	var baseAdTagWithSite = BASE_AD_TAG + urlSplitArray[0].substring(0, (urlSplitArray[0].length-3)) + "/";

	// Add subdomain to array if it's not blacklisted
	// var subdomain = (document.domain + "").substring(0, (document.domain + "").indexOf("."));
	// Can't use this anymore, gotta go back to sub-string

	// var subdomain = (document.domain + "").substring(0, (document.domain + "").indexOf("."));
	// http://karv2010.vrak.tv/

	var subdomain = pageUrl.substring(7, pageUrl.indexOf("."));
	if (SUBDOMAINS_TO_IGNORE.indexOf(subdomain) == -1) {
		urlSplitArray.splice(1, 0, subdomain);
	}

	// Build zonename
	if (urlSplitArray.length >= 2) {
		if (urlSplitArray[1] != "") {
			zonename = alphaNumericalOnly(urlSplitArray[1], "").toLowerCase();
		} else {
			// This is homepage
			zonename = "homepage";
		}
	}

	// Build keyvaluepair1
	if (urlSplitArray.length >= 3) {
		if (urlSplitArray[2] != "") {
			keyvaluepair1 = "ss=" + alphaNumericalOnly(urlSplitArray[2], "").toLowerCase() + ";";
		} else if (zonename != "homepage" && zonename != "") {
			// This is a section's homepage
			keyvaluepair1 = "ss=sectionhome;";
		}
	}

	// Build keyvaluepair2
	if (urlSplitArray.length >= 4) {
		if (urlSplitArray[3] != "") {
			// Don't use value #3, use all the remaining url
			var restOfUrl = pageUrlTransit.substring(pageUrlTransit.indexOf(urlSplitArray[3]));
			keyvaluepair2 = "title=" + numericalOnly(restOfUrl, "").toLowerCase() + ";";
		}
	}

	// Build ad tag src
	var adTagSrc = baseAdTagWithSite + zonename + ";" + keyvaluepair1 + keyvaluepair2 + dcopt + pos + "tile=" + pageTile + ";sz=" + adSize + ";" + ord;

	// Build ad tag to print
	var adTag = "<sc"+"ript type='text/jav"+"ascript' src='" + adTagSrc + "'></scr"+"ipt>";

	// Finally, print it
	document.write(adTag.toLowerCase())

}


// #####################
// ##### GEOGRAPHY #####
// #####################

// Clear selects
function clearSelect(selectId, previousSelectText) {
	$("#" + selectId).removeOption(/./);
	$("#" + selectId).addOption("0", "Choisissez " + previousSelectText + " avant");
}

// Load country select
function loadCountrySelect(selectedCountryId, selectId) {

	// Max characters for option
	var maxChar = 25;

	var ieRant = Math.floor(Math.random()*1000001); // Generate random so that this f***ing IE browser does not cache xml response
	$.ajax({
		type: "GET",
		url:"/_dyn/getCountries.jsp",
		data: "&ieRant=" + ieRant,
		dataType: "xml",
		success: function(xml){

			// Clear the list
			$("#" + selectId).removeOption(/./);

			$(xml).find("country").each(function(){

				// Get values from XML
				var countryId = $(this).attr("id");
				var countryName = $(this).text();
				var countrySelected = false;
				if (countryId == selectedCountryId) {
					countrySelected = true;
				}

				// Truncate name
				if (countryName.length > maxChar) {
					countryName = countryName.substring(0, maxChar) + "...";
				}

				// Add option to select
				$("#" + selectId).addOption(countryId, countryName, countrySelected);

			});
		}
	});

}

// Load province select
function loadProvinceSelect(countryId, selectedProvinceId, selectId) {

	// Max characters for option
	var maxChar = 25;

	if (countryId == 0) {
		clearSelect(selectId, "un pays");
	} else {

		var ieRant = Math.floor(Math.random()*1000001); // Generate random so that this f***ing IE browser does not cache xml response
		$.ajax({
			type: "GET",
			url:"/_dyn/getProvinces.jsp",
			data: "countryId=" + countryId + "&ieRant=" + ieRant,
			dataType: "xml",
			success: function(xml){

				// Clear the list
				$("#" + selectId).removeOption(/./);

				$(xml).find("province").each(function(){

					// Get values from XML
					var provinceId = $(this).attr("id");
					var provinceName = $(this).text();
					var provinceSelected = false;
					if (provinceId == selectedProvinceId) {
						provinceSelected = true;
					}

					// Truncate name
					if (provinceName.length > maxChar) {
						provinceName = provinceName.substring(0, maxChar) + "...";
					}

					// Add option to select
					$("#" + selectId).addOption(provinceId, provinceName, provinceSelected);

				});
			}
		});

	}

}

// Load region select
function loadRegionSelect(provinceId, selectedRegionId, selectId) {

	// Max characters for option
	var maxChar = 25;

	if (provinceId == 0) {
		clearSelect(selectId, "une province");
	} else {

		var ieRant = Math.floor(Math.random()*1000001); // Generate random so that this f***ing IE browser does not cache xml response
		$.ajax({
			type: "GET",
			url:"/_dyn/getRegions.jsp",
			data: "provinceId=" + provinceId + "&ieRant=" + ieRant,
			dataType: "xml",
			success: function(xml){

				// Clear the list
				$("#" + selectId).removeOption(/./);

				$(xml).find("region").each(function(){

					// Get values from XML
					var regionId = $(this).attr("id");
					var regionName = $(this).text();
					var regionSelected = false;
					if (regionId == selectedRegionId) {
						regionSelected = true;
					}

					// Truncate name
					if (regionName.length > maxChar) {
						regionName = regionName.substring(0, maxChar) + "...";
					}

					// Add option to select
					$("#" + selectId).addOption(regionId, regionName, regionSelected);

				});

			}
		});

	}

}

// Load municipality select
function loadMunicipalitySelect(regionId, selectedMunicipalityId, selectId) {

	// Max characters for option
	var maxChar = 25;

	if (regionId == 0) {
		clearSelect(selectId, "une région");
	} else {

		var ieRant = Math.floor(Math.random()*1000001); // Generate random so that this f***ing IE browser does not cache xml response
		$.ajax({
			type: "GET",
			url:"/_dyn/getMunicipalities.jsp",
			data: "regionId=" + regionId + "&ieRant=" + ieRant,
			dataType: "xml",
			success: function(xml){
				// Clear the list
				$("#" + selectId).removeOption(/./);

				$(xml).find("municipality").each(function(){

					// Get values from XML
					var municipalityId = $(this).attr("id");
					var municipalityName = $(this).text();
					var municipalitySelected = false;
					if (municipalityId == selectedMunicipalityId) {
						municipalitySelected = true;
					}

					// Truncate name
					if (municipalityName.length > maxChar) {
						municipalityName = municipalityName.substring(0, maxChar) + "...";
					}

					// Add option to select
					$("#" + selectId).addOption(municipalityId, municipalityName, municipalitySelected);

				});
			}
		});

	}

}

// Load municipality select
function loadBoroughSelect(municipalityId, selectedBoroughId, selectId) {

	// Max characters for option
	var maxChar = 25;

	if (municipalityId == 0) {
		clearSelect(selectId, "une municipalité");
	} else {

		var ieRant = Math.floor(Math.random()*1000001); // Generate random so that this f***ing IE browser does not cache xml response
		$.ajax({
			type: "GET",
			url:"/_dyn/getBoroughs.jsp",
			data: "municipalityId=" + municipalityId + "&ieRant=" + ieRant,
			dataType: "xml",
			success: function(xml){
				// Clear the list
				$("#" + selectId).removeOption(/./);

				$(xml).find("borough").each(function(){

					// Get values from XML
					var boroughId = $(this).attr("id");
					var boroughName = $(this).text();
					var boroughSelected = false;
					if (boroughId == selectedBoroughId) {
						boroughSelected = true;
					}

					// Truncate name
					if (boroughName.length > maxChar) {
						boroughName = boroughName.substring(0, maxChar) + "...";
					}

					// Add option to select
					$("#" + selectId).addOption(boroughId, boroughName, boroughSelected);

				});
			}
		});

	}

}

// ######################
// ##### MEMBERSHIP #####
// ######################

function writeTourism12MinusCookie() {
	$.cookie("tourism", "12Minus", {domain: ".vrak.tv", path: "/"});
}

function writeTourism13PlusCookie() {
	$.cookie("tourism", "13Plus", {domain: ".vrak.tv", path: "/"});
}

function deleteTourismCookie() {
	$.cookie("tourism", null, {path: "/", expires: 0});
}

function deleteMembershipCookie() {
	$.cookie("membership", null, {domain: ".vrak.tv", path: "/", expires: 0});
}

function goTourism12Minus() {
	writeTourism12MinusCookie();
}

function goTourism13Plus() {
	writeTourism13PlusCookie();
}

function logoutTo12Minus() {
	deleteMembershipCookie();
	writeTourism12MinusCookie();
}

function logoutTo13Plus() {
	deleteMembershipCookie();
	writeTourism13PlusCookie();
}

function isUnder13(epochBirth) {

	var birthDate = new Date(epochBirth);

	var thirteenYearsAgoDate = new Date();
	thirteenYearsAgoDate.setFullYear((new Date()).getFullYear()-13);

	if (birthDate >= thirteenYearsAgoDate) {
		return true;
	} else {
		return false;
	}

}

function openAreYouMember() {
	tb_show_membre("Are you member?", "http://www.vrak.tv/membre/overlays/membership-overlay.jsp?from=" + escape(document.location) + "&height=590&width=640&modal=true&TB_iframe=true?", "");
}

function openAreYouMemberForActions(message) {
	tb_show_membre("Are you member?", "http://www.vrak.tv/membre/overlays/membership-overlay.jsp?openBox=areYouMemberActions&message=" + message + "&from=" + escape(document.location) + "&height=550&width=610&modal=false&TB_iframe=true?", "");
}

function openLogin(message) {
	tb_show_membre("So you want to log in?", "http://www.vrak.tv/membre/overlays/membership-overlay.jsp?openBox=login&from=" + escape(document.location) + "&height=550&width=610&modal=false&TB_iframe=true?", message);
}

function openUpdate() {
	tb_show_membre("Update your age!", "http://www.vrak.tv/membre/overlays/membership-overlay.jsp?openBox=update&from=" + escape(document.location) + "&height=590&width=640&modal=true&TB_iframe=true?", "");
}

function openRegister() {
	tb_show_membre("So you want to register?", "http://www.vrak.tv/membre/overlays/membership-overlay.jsp?openBox=register&from=" + escape(document.location) + "&height=550&width=610&modal=false&TB_iframe=true?", "");
}

function openAddToFriend(memberId, memberKey) {
	tb_show_membre("Add to friend!", "http://www.vrak.tv/membre/overlays/add-to-friend-overlay.jsp?memberId=" + memberId + "&memberKey=" + memberKey + "&height=400&width=400&modal=false&TB_iframe=true?", "");
}

function removeFromFriends(memberId) {
	tb_show_membre("Remove from friends!", "http://www.vrak.tv/membre/overlays/remove-from-friends-overlay.jsp?memberId=" + memberId + "&height=400&width=400&modal=false&TB_iframe=true?", "");
}

function acceptFriendRequest(id) {
	tb_show_membre("Accept friend request!", "http://www.vrak.tv/membre/overlays/accept-friend-request-overlay-post.jsp?friendRequestId=" + id + "&height=400&width=400&modal=false&TB_iframe=true?", "");
}

function refuseFriendRequest(id) {
	tb_show_membre("Refuse friend request!", "http://www.vrak.tv/membre/overlays/refuse-friend-request-overlay.jsp?friendRequestId=" + id + "&height=400&width=400&modal=false&TB_iframe=true?", "");
}

function openSendPm() {
	tb_show_membre("Send PM!", "http://www.vrak.tv/membre/overlays/private-message-overlay.jsp?height=500&width=510&modal=false&TB_iframe=true?", "");
}

function openSendPmToFriend(memberId, memberKey) {
	tb_show_membre("Send PM to friend!", "http://www.vrak.tv/membre/overlays/private-message-overlay.jsp?memberId=" + memberId + "&memberKey=" + memberKey + "&height=500&width=510&modal=false&TB_iframe=true?", "");
}

function openReplyToPm(pmId, pmKey) {
	tb_show_membre("Reply to PM", "http://www.vrak.tv/membre/overlays/private-message-overlay.jsp?pmId=" + pmId + "&pmKey=" + pmKey + "&height=500&width=510&modal=false&TB_iframe=true?", "");
}