 // O.BOISARD

var initValueRecherche
initValueRecherche = 'Rechercher';

$(function(){
/* Action lorsqu'on click sur in input *************************************************************************************************************************/
	$("#rechercher").click
	( 
		function()
		{ 
			if(this.value=='Rechercher') 
			{ 
				this.value = '';
			} 
		} 
	);
	$("#RechercheSynomia").click
	( 
		function()
		{ 
			if(this.value=='Rechercher') 
			{ 
				this.value = '';
			} 
		} 
	);
	$("#header_popin p").click
	( 
		function()
		{ 
			document.getElementById('popin_concours').style.display='none';
			document.getElementById('ecran').style.display='none';
			window.clearInterval(boucle);
			$('#playerVideo').removeClass('noflash');
		} 
	);
/* Action lorsqu'on enleve le focus d'un input *************************************************************************************************************************/
	$("#rechercher").blur( 
		function()
		{  
			if(this.value=='') 
			{ 
				this.value = initValueRecherche;
			} 
			else 
			{ 
				initValueRecherche = this.value; 
			} 
		} 
	);
	$("#RechercheSynomia").blur( 
		function()
		{  
			if(this.value=='') 
			{ 
				this.value = initValueRecherche;
			} 
			else 
			{ 
				initValueRecherche = this.value; 
			} 
		} 
	);
/* Action lorsqu'on envoie le formulaire : si le mot clé est "Rechercher", on l'efface ********************************************************************************************/
	$("#formRechercher").submit
	( 
		function()
		{ 
			var obj = document.getElementById('rechercher')
			if(obj)
			{
				if(obj.value=='Rechercher') 
				{ 
					//return false; /* pour annuler l'envoie du formulaire */
					obj.value='';
				}
			}
		} 
	);

	$("form .vide_value").focus(function(){this.value = '';} );
	
	treatMoveWindow();
	
	Cpt = 3;
	var Ech = new Array("70%", "80%", "90%", "100%", "110%", "120%", "130%");
	
	$("#dec-font").click(function(){
		var Div = document.getElementById("content").getElementsByTagName("div");
		for(i=0; i<Div.length; i++) {
			if(Div[i].className == "contenu") {
				if(Cpt > 0) {
					Cpt--;
					Div[i].style.fontSize = Ech[Cpt];
				}
				break;
			}
		}
	});
	
	$("#inc-font").click(function(){
		var Div = document.getElementById("content").getElementsByTagName("div");
		for(i=0; i<Div.length; i++) {
			if(Div[i].className == "contenu") {
				if(Cpt < (Ech.length-1)) {
					Cpt++;
					Div[i].style.fontSize = Ech[Cpt];
				}
				break;
			}
		}
		
		
	});
});

function affichage_popup(page){
	var dessus=(screen.height/2)-(650/2);
	var gauche=(screen.width/2)-(700/2);
	var features='height=650, width=700, top='+dessus+',left='+gauche;
	/*window.open(page, 'fenetre','width=700, height=650, scrollbars=no');*/
	window.open(page,'',features);
	return false;
}
function popupCentre(url, largeur, hauteur) {
	var dessus=(screen.height/2)-(hauteur/2);
	var gauche=(screen.width/2)-(largeur/2);
	var features='height='+hauteur+',width='+largeur+',top='+dessus+',left='+gauche;
	window.open(url,'popup',features);
}
function popup() {
	window.open('fullscreen.html','SPTPopup','width=200,height=200,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes');
}



// **********************************************************************************************************************************
// **********************************************************************************************************************************
//                       CopyText                                       ***************************************************************************************
// **********************************************************************************************************************************
// **********************************************************************************************************************************

if(!window.clipboardData) 
{
    window.clipboardData = {
        setData : function(mode,content) {

            var clipboard = document.body;
            var flashclipboard = clipboard.flashclipboard;
            var encoded = encodeURIComponent(content).split('%5Cn').join('%0A');
            if(flashclipboard == null)
            {
                flashclipboard = document.createElement('div');
                clipboard.flashclipboard = flashclipboard;
                clipboard.appendChild(flashclipboard);
            }
            flashclipboard.innerHTML = '<object width="0" height="0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">' 
                               + '<param name="movie" value="/securite-routiere-france/Images/clipboard_tcm1752-782073.swf" />'
                               + '<param name="flashvars" value="clipboard='+encoded+'" />'
                               + '<embed src="/securite-routiere-france/Images/clipboard_tcm1752-782073.swf" FlashVars="clipboard='+encoded+'" width="0" height="0" type="application/x-shockwave-flash"></embed>'
                       + '</object>';

        }
    }
}
function CopyText(id)
{
	var objCopy = document.getElementById(id);
	if(!objCopy) return false;
	var code = objCopy.innerHTML;
	code = code.replace(/<.*?>/g,"");
	code = code.replace(/&lt;/g,"<");
	code = code.replace(/&gt;/g,">");
	return window.clipboardData.setData("text",code);
}
// **********************************************************************************************************************************
// **********************************************************************************************************************************


function twWindow()
{
this.width = screen.width;
this.height = screen.height;
this.availWidth = screen.availWidth;
this.availheight = screen.availHeight;
this.left = (document.all?window.screenLeft:window.screenX);
this.top = (document.all?window.screenTop:window.screenY);
this.innerwidth = (document.all?document.body.offsetWidth:window.innerWidth);
this.innerheight = (document.all?document.body.offsetHeight:window.innerHeight);
}

document.onmouseover = treatMoveWindow
function treatMoveWindow()
{
	var l = document.getElementById("top-Page");
	if(l)
	{
		l.style.visibility = ((document.all?document.documentElement.offsetHeight-document.body.offsetHeight:window.innerHeight-document.body.offsetHeight)<0)? "visible" : "hidden";
	}
}

function selection_pays(pays){
	if(pays.options[pays.options.selectedIndex].value!=""){
		window.open(pays.options[pays.options.selectedIndex].value, 'popup', '');
		pays.options.selectedIndex = 0;
	}
}

function InsertFormRechercheSynomia() {
	var obj, str
	obj = document.getElementById("q_old");
	if(obj)	str = obj.value;
	if(!str) str = 'Rechercher';
	obj = document.getElementById("RechercheSynomia");
	if(obj)	obj.value = str;
	InsertFormRecherche(str)
}

function InsertFormRecherche(mot) {
	var obj
	obj = document.getElementById("Rechercher");
	if(obj) obj.value = mot;
}

// **********************************************************************************************************************************
// **************************************** FONCTION UTILISE PAR LE FLASH PROPOSANT LES JEUX EN LIGNE **********************************
// **********************************************************************************************************************************

function start_game(game){
	//alert("game : " + game);
	switch(game)
	{
		case "rue":
			url = "jeu_larue/jeularue.htm"
			break;
		case "anniv":
			url = "jeu_martin/jeumartin.htm"
			break;
		case "erreur":
			url = "jeu_erreur/questions.htm"
			break;
		case "vacances":
			url = "jeu_voiture/jeuvoiture.htm"
			break;
		case "roller":
			url = "jeu_velo/jeuroller.htm"
			break;
		case "velo":
			url = "jeu_velo/jeuvelo.htm"
			break;
		default:
			url = ""
			break;
	}
	if(url) popupCentre('/securite-routiere-france/modules/'+url, 725, 500) //window.open( + url);
}
function tag_call(flashTag)
{
	//alert("flashTag : " + flashTag);
	var tag = "";
	switch(flashTag)
	{
		case "rue":
			tag = ".la_rue.accueil";
			break;
		case "anniv": 
			tag = ".l_anniversaire_de_martin.accueil";
			break;
		case "erreur": 
			tag = ".trouve_l_erreur.accueil";
			break;
		case "vacances": 
			tag = ".tous_en_vacances.accueil";
			break;
		case "roller":
			tag = ".velo_roller.accueil"; 
			break;
		case "home": 
		default:
			tag = ""; 
			break;
	}
	document.ns_flashp.src = "http://fr.sitestat.com/renault-group/securite/s?renaultsptfrance.fr.enfants.joue" + tag;
	//alert(document.ns_flashp);
	//alert(document.ns_flashp.src);
}

// **********************************************************************************************************************************
// **************************************** FONCTION UTILISE PAR LE BLOC SONDAGE *****************************************************
// **********************************************************************************************************************************

var ns4=(document.layers)? true:false;        		//NS 4
var ie4=(document.all)? true:false;         		//IE 4
var dom=(document.getElementById)? true:false;   	//NS 6 ou IE 5
function SetContent(ID,Content)
{
  if (dom) { document.getElementById(ID).innerHTML = Content; return true; }
  if (ie4) { document.all[ID].innerHTML=Content; return true; }
  if (ns4) { with (eval('document.'+ID+'.document')) { open(); write(Content); close(); } return true; }
}
function AjustPourcent(nb)
{
	setTimeout("AjustPourcentTimer(" + nb + ");",100);
}
function AjustPourcentTimer(nb)
{
	var total, pourcentage
	var obj
	//Calcul du total
	total=0;
	for(i=0;i<nb;i++)
	{
		obj = document.getElementById('inputpourcent_'+i);
		if(obj)
		{
			total += parseInt(obj.value);
		}
	}
	//alert('total : ' + total);
	//recalcul de chaque pourcentage
	for(i=0;i<nb;i++)
	{
		obj = document.getElementById('inputpourcent_'+i);
		if(obj)
		{
			pourcentage = parseInt(obj.value);
			if(total>100 && pourcentage>0 && pourcentage<100) { pourcentage -= 1; total -= 1 }
			else if(total<100 && pourcentage>0 && pourcentage<100) { pourcentage += 1; total += 1 }
			//alert(document.getElementById('res_'+parseFloat(i)).innerHTML);
			//setTimeout("SetContent('res_'+parseFloat(i),parseFloat(pourcentage) + '%');",20);
			SetContent('res_'+parseFloat(i),parseFloat(pourcentage) + '%');
		}
	}
}

// **********************************************************************************************************************************
// **************************************** RECUPERE LES PARAMETRE PASSES DANS l'URL *************************************************
// **********************************************************************************************************************************

function PrmUrl()
{
 var prm = new Array();
 var tmp = unescape(window.location.search).substr(1).split("&");
 var inter;
 for ( i=0; i<tmp.length; i++)
 {
  inter=tmp[i].indexOf("=");
  if ( inter>=0 )
    {
     prm[tmp[i].substr(0,inter)]=tmp[i].substr(inter+1)
    }
  else {
     prm[tmp[i]]="";
    }
 }
 return prm;
}
// **********************************************************************************************************************************
// **************************************** CAS DU QUESTIONNAIRE *************************************************
// **********************************************************************************************************************************

$(function()
{
	if($("#questionnaire").length)
	{
		cb = document.getElementById('bt_accord');
		if(cb) cb.checked = false;
		cb = document.getElementById('bt_hidden');
		if(cb) cb.checked = true;
		$("#questionnaire .jeu_bt_valid a").attr('class','off');
		$("#questionnaire .jeu_bt_valid a").click(function(){ if($(this).attr('class') == 'off') return false; else return true; });
		$("#questionnaire #bt_accord").click
		( 
			function()
			{ 
				$("#questionnaire .jeu_bt_valid a").attr('class','on');
			} 
		);
	}
});

// **********************************************************************************************************************************
// **************************************** SITESTAT *************************************************
// **********************************************************************************************************************************
function sitestat(ns_l)
{
	ns_l+="&ns__t="+new Date().getTime();
	ns_pixelUrl = ns_l;
	// referrer part
	var ns_0=location.search.substring(1);
	var ns_1=ns_0.indexOf("ns_or=");
	if(ns_1>-1) ns_0=unescape(ns_0.substring(ns_1+6,ns_0.length)); else ns_0="";
	if(ns_0.length==0) ns_0=document.referrer;
	ns_0=(ns_0.lastIndexOf("/")==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf("/"),0):ns_0;
	if(ns_0.length>0) ns_l+="&ns_referrer="+escape(ns_0);
	//end referrer part
	if(document.images){ ns_1=new Image();ns_1.src=ns_l; } else { document.write("<img src="+ns_l+" width=1 height=1 />"); }
	//if(jQuery.browser.mozilla) console.log("Sitestat : %s", ns_l);
}
function ns_flashcounter(ns_flashn) 
{
	var ns_flash = "http://fr.sitestat.com/renault-group/securite/s?video."+ns_flashn+"&ns_type=flash"+"&ns__t="+(new Date()).getTime();
	document.ns_flashp.src=ns_flash;
	//if(jQuery.browser.mozilla) console.log("ns_flashcounter : %s", ns_flash);
}
// **********************************************************************************************************************************
// **************************************** INITIALISATION *************************************************
// **********************************************************************************************************************************
function initSPT(ns_l)
{
	var pUrl=PrmUrl();
	if(pUrl['id'])
	{
		ns_l+= "."+pUrl['id'];
	}
	if(ns_l) sitestat(ns_l);
	menu();
	if(document.getElementById('ecran'))
	{
		$('#playerVideo').addClass('noflash');
		gestion_ecran();
	}
}
function initActuSPT(ns_l)
{
	var strIDNews="";
	var parametre=PrmUrl();
	if(parametre['id'])
	{
		strIDNews= "."+parametre['id'];
	}
	initSPT(ns_l+strIDNews);
}

// **********************************************************************************************************************************
// **************************************** LANCEMENT  DU SWFOBJECT  *************************************************
// **********************************************************************************************************************************

var boolSwfobject = false;

function playMediaFlash(idElem,pathMedia,l,h)
{
	if($('#'+idElem).length)
	{
		var so = new SWFObject(pathMedia,"flash",l,h,"8","#FFFFFF");
		so.addVariable("langue","fr");
		so.write(idElem);
		boolSwfobject = true;
	}
	else
	{
		if(!boolSwfobject)
			setTimeout('playMediaFlash("'+idElem+'","'+pathMedia+'","'+l+'","'+h+'");', 25);
	}
}

function playMediaVideo(idElem,pathMedia,urlStat)
{
	if($('#'+idElem).length)
	{
		var so = new SWFObject("/securite-routiere-france/Images/index_tcm1752-649654.swf","video","327","300","8.0.69.0","#ebecee");
		so.setAttribute("redirectUrl","http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash");
		so.addParam("allowScriptAccess", "sameDomain");
		so.addParam("quality", "high");
		so.addVariable("langue","fr");
		so.addVariable("video", pathMedia);
		so.addVariable("url_stat", urlStat);
		so.write(idElem);
		boolSwfobject = true;
	}
	else
	{
		if(!boolSwfobject)
			setTimeout('playMediaVideo("'+idElem+'","'+pathMedia+'","'+urlStat+'");', 25);
	}
}

/*   ******          Pour les Master Page   *****************        */

function playMasterPageVideo(idElem,pathMedia,urlStat,l,h)
{
	if($('#'+idElem).length)
	{
		var so = new SWFObject("/securite-routiere-france/Images/player_flv_tcm1752-814564.swf","video",l,h,"8.0.69.0","#ebecee");
		so.setAttribute("redirectUrl","http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash");
		so.addParam("allowScriptAccess", "sameDomain");
		so.addParam("quality", "high");
		so.addVariable("movie", "/securite-routiere-france/Images/player_flv_tcm1752-814564.swf");
		so.addVariable("flv", pathMedia);
		so.addVariable("width", l);
		so.addVariable("height", h);
		so.addVariable("bgcolor", "969696");
		so.addVariable("playercolor", "373d40");
		so.addVariable("bgcolor1", "373d40");
		so.addVariable("bgcolor2", "373d40");
		so.addVariable("buttoncolor", "dddddd");
		so.addVariable("buttonovercolor", "fac932");
		so.addVariable("slidercolor1", "dddddd");
		so.addVariable("slidercolor2", "cccccc");
		so.addVariable("sliderovercolor", "fac932");
		so.addVariable("showstop", "1");
		so.addVariable("showvolume", "1");
		so.addVariable("showtime", "1");
		so.addVariable("showfullscreen", "1");
		so.addVariable("srt", "0");
		//so.addVariable("configxml", "/securite-routiere-france/inc/configFlv.aspx?movie=" + pathMedia + "&amp;width=" + l + "&amp;height" + h + "" );
		so.write(idElem);

		$("div.masterpage #center .contenu").css('margin-right','0px');
		$("div.masterpage #center .contenu .content .videoflv").css('width', l + 'px');

		boolSwfobject = true;
	}
	else
	{
		if(!boolSwfobject)
			setTimeout('playMasterPageVideo("'+idElem+'","'+pathMedia+'","'+urlStat+'","'+l+'","'+h+'");', 25);
	}
}

// ************************************************************************************************
// *************************************      PLAYER         ********************************************
// ************************************************************************************************

$(function(){
	$(".player a").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");	
	});
});