var isOpera = (navigator.userAgent.indexOf('Opera') != -1)? true : false;
var isIE = (document.all && !isOpera && navigator.platform == "Win32")? true : false;
var isIE6 = (navigator.userAgent.indexOf('MSIE 6') != -1)? true : false ;
var isIE7 = (navigator.userAgent.indexOf('MSIE 7') != -1)? true : false ;
var WATPlayer;
var goParticyp = true;

function init(){
	
	if($("navTop")){
		var myNavTop = new NavTop();
	}
	
	hackPng();
	
	//setPlayerWatPause();
}

Event.observe(window, 'load',init);

function loadLayer(obj){
	
	return;
	
	if(!$('maskLay')){
		var divmask = document.createElement("div");
		divmask.id="maskLay";
		divmask.style.visibility = "visible";
		divmask.style.height = $("container").getHeight();
		$("container").appendChild(divmask);
		rescueFrame($('maskLay'));
	}
	
	Event.observe($("maskLay"), 'click',function(){});

	if(!obj.offsetTop){
		obj.style.top = ($("container").getHeight()/2)-(obj.offsetHeight/2)+"px";
	}
	if(!obj.offsetLeft){
		obj.style.left = ($("container").getWidth()/2)-(obj.offsetWidth/2)+"px";
	}
	
	obj.style.visibility = "visible";
	obj.style.zIndex = 20;
}

function closeLayer(obj){
	if($('maskLay')){
		removeRescueFrame($('maskLay'));
		$("container").removeChild($('maskLay'));
	}
	
	obj.style.visibility = "hidden";
}

function swapImg(obj){
	if(!obj) return;
	obj = obj.getElementsByTagName('img')[0];
	var ch = obj.src;
	var finfin=ch.substring(ch.length-3,ch.length);
	var fin=ch.substring(ch.length-5,ch.length-4);
	ch=ch.substring(0,ch.length-5);
	if(fin == "0") obj.src=ch+"1."+finfin;
	else obj.src=ch+"0."+finfin;
}

/*** Permet de voir les png transparent sous ie6 ***/
function hackPng(){
  if (navigator.appVersion.indexOf("MSIE 6")!=-1)
    for (i = 0; i < document.images.length; i++)
      if (document.images[i].src.substring(document.images[i].src.length-3, document.images[i].src.length) == "png") 
      {
        document.images[i].style.height = document.images[i].height + "px";
        document.images[i].style.width = document.images[i].width + "px";
        document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + document.images[i].src + ",sizingMethod='scale')";
        document.images[i].src = "/images/commun/pix.gif";
      }
}

/*** Chargement du scroll Layer ***/
function scrollLoad(omask,oscroll){
	
	
	
	var scroll = $(oscroll);
	scroll.innerHTML += '<div id="scrollbarBg'+omask+'"></div>';
	var scUp = Element.childElements(scroll)[0];
	var scDn = Element.childElements(scroll)[1];
	var sc = Element.childElements(scroll)[2];
	var maskDiv = $(omask);
	var el = Element.down(maskDiv);

	scroll.style.top = maskDiv.offsetTop+"px";
	scroll.style.height = maskDiv.getHeight()-5+"px";
	scDn.style.top = maskDiv.getHeight()-17+"px";
	sc.style.height = $('scrollbarBg'+omask).style.height = maskDiv.getHeight()-34+"px";

	this['Sc'+oscroll] =  new Scroller ("vertical",{
		container:el,
		scrollbar:scroll,
		scrollbarBgV:$('scrollbarBg'+omask),
		mask:maskDiv,
		scUp:scUp,
		scDn:scDn,
		cursorV:sc
	},10,5);
	
	this['Sc'+oscroll].init();

	return this['Sc'+oscroll];
}

/***** rescueFrame *****/
function rescueFrame(obj){
	if(isIE && !isIE7){		
		if(!$('rescueFrame'+obj.id)){
			var rescueObj = document.createElement('iframe');
			var rescueElement = Element.up(obj).appendChild(rescueObj);
			rescueElement.id = 'rescueFrame'+obj.id;
			rescueElement.style.position = 'absolute';
			
			rescueElement.style.top = obj.offsetTop+'px'; 
			rescueElement.style.left = obj.offsetLeft+'px';
			
			rescueElement.style.width = obj.offsetWidth+'px'; 
			rescueElement.style.height = obj.offsetHeight+'px'; 
			//rescueElement.style.visibility = 'hidden';
			rescueElement.style.border = '0';
			rescueElement.style.filter = 'alpha(opacity=0);';
			rescueElement.style.zIndex = 0;
		}
	}
}
function removeRescueFrame(obj){
	if(isIE && !isIE7){
		if($('rescueFrame'+obj.id)){
			Element.up(obj).removeChild($('rescueFrame'+obj.id));
		}
	}
}
/*****************************/



/*******Fiche Personnage********/

function OngletPers(layer, id1, id2, id3, id4, id5, id6){
	if(layer=='1'){
	
	$(id1).style.display = 'block';
	$(id2).style.display = 'none';
	$(id3).className ='on'; 
	$(id4).className = 'off';
		if (id5 && id5 != '') {
			$(id5).style.display = 'none';
			$(id6).className = 'off';
		}
		
	} else if(layer=='2') {
	
	$(id1).style.display = 'none';
	$(id2).style.display = 'inline';
	$(id3).className ='off'; 
	$(id4).className = 'on';
		if (id5 && id5 != '') {
			$(id5).style.display = 'none';
			$(id6).className = 'off';
		}
	
	} else if(id5 && id5 != '') {
	
		if(layer=='3') {
			$(id1).style.display = 'none';
			$(id2).style.display = 'none';
			$(id3).className ='off'; 
			$(id4).className = 'off';
			$(id5).style.display = 'block';
			$(id6).className = 'on';
		}
	}
}

/******************************/


/***Limiteur Nbre caract�res****/

function limiterArea(NbreCaract){
  var iLongueur, iLongueurRestante;
  iLongueur = $('message_comment').value.length;
  if (iLongueur>NbreCaract) {
	    $('message_comment').value = $('message_comment').value.substring(0,NbreCaract);
    iLongueurRestante = 0;
  } else {
    iLongueurRestante = NbreCaract - iLongueur;
  }
  if (iLongueurRestante == NbreCaract)
    $('indic').innerHTML = "Nombre de caract&egrave;res disponibles : <b>" + iLongueurRestante + "</b>";
  else
    $('indic').innerHTML = "Nombre de caract&egrave;res restants : <b>" + iLongueurRestante + "</b>";
}

/*******************************/


/**********DEBUG**************/
function print_r(theObj){
  if(theObj.constructor == Array ||
	 theObj.constructor == Object){
	document.write("<ul>")
	for(var p in theObj){
	  if(theObj[p].constructor == Array||
		 theObj[p].constructor == Object){
			document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
		document.write("<ul>")
		print_r(theObj[p]);
		document.write("</ul>")
	  } else {
		document.write("<li>["+p+"] => "+theObj[p]+"</li>");
	  }
	}
	document.write("</ul>")
  }
}
/*******************************/

var myPopHtml;

function onReadyNewsletterPopup () {
	myCheckNewsletter = new checkNewsletter();	
}
function viewNewsletterRegister () {
	myPopHtml = new Aheuh.PopHtml({
		name:"NewsletterPopup",
		target:$("myHtmlPop"),
		targetHtmlStatic:$("newsletter"),
		onEvent:onReadyNewsletterPopup.bind(this)
	});
}




/****************************************/
/** Fonction de gestion des pubs par la  r�gie **/
/* OAS SETUP begin */

//configuration
OAS_url = 'http://mfr.247realmedia.com/';

if(OAS_QUERY_INFO != '') {
    OAS_query = OAS_QUERY_INFO;
} else {
    OAS_query = '?';
}

if(OAS_TYPE == 1) {
    OAS_listpos = 'Top,Middle,Right,Bottom,Position1';
} else {
    OAS_listpos = 'Top,Middle,Right,Bottom';
}

//end of configuration
OAS_rns = String(Math.random()).substr(2,11);
function OAS_NORMAL(pos) {
    document.write('<a href="' + OAS_url + '5c/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + OAS_query + '" TARGET=_top>');
    document.write('<img src="' + OAS_url + '1/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + OAS_query + '" border=0 alt="Click!"></a>');
}
document.write('<sc' + 'ript type="text/javascript" src="' + OAS_url + '4/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + OAS_query + '"><\/script>');

function OAS_AD(pos) {
    if (typeof (OAS_RICH) != 'undefined')
        OAS_RICH(pos);
    else
        OAS_NORMAL(pos);
}

/* OAS SETUP end */
/*************************************************/

function hideContent() { $("hide_content").style.height = "auto"; $("btn_hide").style.visibility = "hidden"; $("btn_hide").style.display = "none" };


/* Club */
/* function clubMenu(o) {
    var u = o+"Cont";
    var i = o+"On";
    
    document.getElementById("accueilCont").style.display = "none";
    document.getElementById("compteCont").style.display = "none";
    document.getElementById("contributionsCont").style.display = "none";
    document.getElementById("accueilOn").style.display = "none";
    document.getElementById("compteOn").style.display = "none";
    document.getElementById("contributionsOn").style.display = "none";

    document.getElementById(u).style.display = "block";
    document.getElementById(i).style.display = "block";
} */

function afficheContrib() {
    document.getElementById("contributionsCont0").style.display = "none";
    document.getElementById("contributionsCont1").style.display = "block";
}

function afficheConty(o) {
    document.getElementById("contyPar" + o).style.display = "block";
}

function afficheNoty(o) {
    document.getElementById(o).style.display = "inline";
}

function desafficheNoty(o) {
    document.getElementById(o).style.display = "none";
}

function replaceNoty(origin, dest) {
    document.getElementById(dest).innerHTML = document.getElementById(origin).innerHTML;
}

function afficheParticyp(o) {
    if (goParticyp) { document.getElementById(o).style.visibility = "visible"; }
    goParticyp = false;
}

function desafficheParticyp(o) {
    goParticyp = true;
    document.getElementById(o).style.visibility = "hidden";
}

/**** VOTE ****/

function setVote(note,id) {
	new Ajax.Request('/videos/vote.html', {
		method: 'post',
		parameters: {
			note: note,
			id: id
		},
		onComplete: function(transport) {
			if(transport.responseText == 0) msg = 'Une erreur est survenue. Veuillez r&eacute;essayer.';
			else if (transport.responseText.indexOf('<!--new-->') >= 0 ) {
			     msg = 'Votre vote a bien &eacute;t&eacute; pris en compte';
			    $('voteStar').innerHTML = transport.responseText;
			    
			    if ($('nbVotes') && $('nbVotes2')) {
			    
			        var nbVotes             = $('nbVotes').innerHTML;
			        $('nbVotes').innerHTML  = parseInt(nbVotes)+1;
			        $('nbVotes2').innerHTML = 'votes';
			    }
			}
			else {
			   msg = 'Vous avez d&eacute;j&agrave vot&eacute;';
			    $('voteStar').innerHTML = transport.responseText;
			}
			$('messageVote').innerHTML = msg;
		}
	});	
}

function switchVote(oImg, imgProgOn){
	var voteId      = oImg.id;
	var voteRoot    = voteId.split('_')[0];
	var voteIndex   = voteId.split('_')[1];
	var voteSrc     = oImg.src;
	var votePath    = voteSrc.substring(0, voteSrc.lastIndexOf("/"));
	for(var i=0; i<5; i++){
		if((i+1) <= voteIndex){
			$Pi(voteRoot,'img', i).src = votePath+'/'+imgProgOn;
		} else {
			$Pi(voteRoot,'img', i).src = votePath+'/star_off.gif';
		}
	}
}

function restoreVote(oImg, imgProgOn){
    var voteId      = oImg.id;
    var voteRoot    = voteId.split('_')[0];
	var voteIndex   = voteId.split('_')[1];
	var voteSrc     = oImg.src;
	var votePath    = voteSrc.substring(0, voteSrc.lastIndexOf("/"));
	var oldNote     = $Pi(voteRoot).title;
	for(var i=0; i<5; i++){
		if(i <= oldNote-1){
			$Pi(voteRoot,'img',i).src = votePath+'/'+imgProgOn;
		} else {
			$Pi(voteRoot,'img',i).src = votePath+'/star_off.gif';
		}
	}
}

function setTitleVote(oImg){
	var voteId      = oImg.id;
    var voteRoot    = voteId.split('_')[0];
	var voteIndex   = voteId.split('_')[1];
	if($Pi(voteRoot).title == '0'){
		$Pi(voteRoot).title = (parseFloat(voteIndex));
	}
}

/**** CLUB ****/
var myPopHtmlClub;

function viewClubPopup (url, type) {
	
	if (type == 'register') {
		
		if ( document.getElementsByTagName("head")[0].innerHTML.indexOf('coreg.1x12.net') == -1 ) {
			var js_effets = document.createElement("script");
	        js_effets.setAttribute("type", "text/javascript");
	        js_effets.setAttribute("src", "http://coreg.1x12.net/?act=getoffers&pubid=3031");
	        document.getElementsByTagName("head")[0].appendChild(js_effets);
		}
	}
	
	myPopHtmlClub = new Aheuh.PopHtml({
		name:"ClubPopup",
		target:$("myHtmlPop"),
		contentURL:url,
		methodURL:'POST',
		onEvent:onReadyClubPopup.bind(this, type)
	});
}

function onReadyClubPopup (type) {
    if (type == 'passwd')
	    myCheckClubPasswd = new checkClubPasswd();
    else if (type == 'register')
	    myCheckClubRegister = new checkClubRegister();
	else if (type == 'login')
	   myCheckClubLogin = new checkClubLogin();
}

function setPlayerWatPause() {
    if (WATPlayer && WATPlayer.getFlash() && $("FlashPlayer") &&  $("WATPlayerInstance")) WATPlayer.setPause();
}

function $Pi(){
	var returnString = 'document';
	if(arguments.length == 1){
		var ids = arguments[0].split('|');
		if(ids.length > 1){
			var idsTab = new Array();
			for(var i=0; i<ids.length; i++){
				idsTab[idsTab.length] = $Pi(ids[i]);					
			}
			return idsTab;
		} else {
			returnString += '.getElementById(\''+arguments[0]+'\')';
		}
	} else {
		for(var i=0; i<arguments.length; i++){
			var p = i+1;
			if(typeof arguments[p] == 'string' && typeof arguments[i] != 'number' || p > arguments.length){
				returnString += '.getElementById(\''+arguments[i]+'\')';
			} else if(typeof arguments[p] == 'number'){
				returnString += (arguments[p] == -1)? '.getElementsByTagName(\''+arguments[i]+'\')' : '.getElementsByTagName(\''+arguments[i]+'\')['+arguments[p]+']';
			}
		}
	}
	return eval(returnString);
}

/* RECUPERATION COOKIE ET ACCES LOGIN*/
function getClubLogin(club,imgStatic,account,register,deconnect,login){
	 var Connect = getCook('Connection') ;
	 if(Connect == 1) {
		 document.write ("<div class='headerContLeftBox'><a href='"+club+"' title='Le Club TMC'><img src='"+imgStatic+"/images/club/headerClub.gif' width='100' height='21' border='0' alt='Le Club TMC' /></a></div><div class='headerContLeftBox'><div class='logPassCont'><a href='"+account+"'>Mon compte</a><a href='"+deconnect+"' class='logPassContStop'>Se déconnecter</a><div class='clear'></div></div></div><div class='headerContLeftBox'><a href='"+account+"'><img src='"+imgStatic+"/images/club/headerNewsletter.gif' width='100' height='21' border='0' alt='La Newsletter' /></a></div>");
	 } else {
		 document.write ("<div class='headerContLeftBox'><a href='"+club+"' title='Le Club TMC'><img src='"+imgStatic+"/images/club/headerClub.gif' width='100' height='21' border='0' alt='Le Club TMC' /></a></div><div class='headerContLeftBox'><div class='logPassCont'><a href='#0' onclick='viewClubPopup(\""+register+"\",\"register\");'>Créer un compte</a><a href='#0' onclick='viewClubPopup(\""+login+"\",\"login\");' class='logPassContStop'>S\'identifier</a><div class='clear'></div></div></div><div class='headerContLeftBox'><a href='#0' onclick='viewClubPopup(\""+register+"\",\"register\");'><img src='"+imgStatic+"/images/club/headerNewsletter.gif' width='100' height='21' border='0' alt='La Newsletter' /></a></div>");
	 }
}

function getClubLoginGame(account,register){
	 var Connect = getCook('Connection') ;
	 
	 if(Connect == 1) {
		 document.write ("<a href='"+account+"' title='Abonnez-vous à la newsletter'>abonnez-vous à la newsletter de TMC</a>");
	 } else {
		 document.write ("<a href='#0' onclick='viewClubPopup(\""+register+"\",\"register\");' title='Abonnez-vous à la newsletter'>abonnez-vous à la newsletter de TMC</a>");
	 }
}

function getCook(nom) {
    deb = document.cookie.indexOf(nom + "=")
    if (deb >= 0) {
        deb += nom.length + 1
        fin = document.cookie.indexOf(";",deb)
        if (fin < 0) fin = document.cookie.length
          return unescape(document.cookie.substring(deb,fin))
        }
    return ""
}


function setCook( name, value, expires, path, domain, secure )
{
	// set time => milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	var dateExpire = (today.getTime()+(parseInt(expires,10)*1000));
	
	var expires_date = new Date( dateExpire );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function refCookie(name, value, expires, redirect) {
	if(getCook(name) == '') {
		setCook( name, value, expires);
	} else {
		window.location.replace(redirect)
	}
}

/* LOADER TG Programme en ajax */
function TgLoader(TARGET,URL) {
	new Ajax.Updater(TARGET,URL, 
	{
	  method:'GET',
	  evalScripts:true,
	  onComplete: function(evt) {
			this.bindAjax( TARGET );
		}
	}
  );
}

//LSF : These three functions must be included in your page.

//validatePublisherForm() is called before processing offers form.
//This is where you validate data from your own form, and if necessary, returns error.
//If this function returns false, offers won't be processed.
function validatePublisherForm() {
	return true;
}

//submitPublisherForm() is called by the LSF scripts after processing the coreg offers sending data to the LSF server.
//This function must be the only way to submit the form.
function submitPublisherForm() { }