//test l'origine de l include du js
var path='';
if (window.location.toString().indexOf("forms")==-1)
	path='forms/';

document.write('<script type="text/javascript" src="./'+path+'js/cookies.js"></script>');
document.write('<script type="text/javascript" src="./'+path+'js/jquery-1.3.js"></script>');



 var isAkamai ="";
 var akamaiPub ="";
 var akamaiTimeStamp="";
 var akamaiRacine ="";

//Fonction pour récupérer un paramètre de l'URL du document
function getParameter(nomParam){
    // On enlève le ?
    param = window.location.search.slice(1,window.location.search.length);

    first = param.split("&");

    for(i=0;i<first.length;i++){
        second = first[i].split("=");
        if (second[0]==nomParam){
        	return second[1];
        }
    }
}

//Fonction pour récupérer un paramètre de l'URL de la page mère du document
function getParameterTop(nomParam){
    // On enlève le ?
    param = window.top.location.search.slice(1,window.top.location.search.length);

    first = param.split("&");

    for(i=0;i<first.length;i++){
        second = first[i].split("=");
        if (second[0]==nomParam){
        	return second[1];
        }
    }
}

//Fonction pour pemettre le grisage du bouton valider quand on choisit "Autre" dans la liste des pays. 
function selectPays(fieldPays, libelleAutrePays)
{
	if (document.getElementById(fieldPays).value== libelleAutrePays){
		document.frm.frm_button_valid.className  = "frm_img_btn_valid_grise";
		document.frm.frm_button_valid.disabled=true;		
		document.getElementById('frm_msg_contact').style.display='block';		
		document.getElementById('frm_id_btn_valid').style.display='none';
		
		// on retourne false si le formulaire n'est pas validable
		return false;
	}else{
		document.frm.frm_button_valid.className  = "frm_img_btn_valid";
		document.frm.frm_button_valid.disabled=false;
		document.getElementById('frm_msg_contact').style.display='none';		
		document.getElementById('frm_id_btn_valid').style.display='block';	
		
		// on retourne true si le formulaire est validable
		return true;
	}
}

// Fonction permettant d'effacer le message "Pour recevoir..." du champs Email quand on click dedans.
function erase_msg_email(FieldEmail)
{
  document.getElementById(FieldEmail).value="";
}

function addJSessionId(pOldSrc,pLocation){

	
	//Si session ajout
	var indexSession = pLocation.indexOf(";jsessionid");
	var indexLocationInter = pLocation.indexOf("?");
	var indexPointInter = pOldSrc.indexOf("?");
	var newSrcJsessionId = "";
	if (indexSession!=-1){
		if (indexPointInter!=-1){
			 newSrcJsessionId = new String(pOldSrc.substring(0,indexPointInter));//avant le point d'interrogation
			 newSrcJsessionId = newSrcJsessionId + pLocation.substring(indexSession);//ajout de la session et de la suite
			 if (indexLocationInter ==-1){
				 newSrcJsessionId = newSrcJsessionId + "?";
			 }
			 newSrcJsessionId = newSrcJsessionId + "&"+pOldSrc.substring(indexPointInter+1);//ajout des paramètres
		}
		else{
			 newSrcJsessionId = new String(pOldSrc);
			 newSrcJsessionId = newSrcJsessionId + pLocation.substring(indexSession);
			 if (indexLocationInter ==-1){
				 newSrcJsessionId = newSrcJsessionId + "?";
			 }
		}
	}
	else{
		newSrcJsessionId = new String(pOldSrc);
		if (indexPointInter==-1 && indexLocationInter ==-1){
			 newSrcJsessionId = newSrcJsessionId + "?";
		}
	}
	
	return  newSrcJsessionId;
}

//Permet de récupérer la configuration akamai en base de donnée
function initAkamai(){
	var urlGetAkamai = "/placements/forms/GetAkamai.jsp";
	jQuery.ajax({ 
 	type: "GET", 
 	url: urlGetAkamai,
 	async: false,   
 	success: function(doc){
		isAkamai = doc.getElementsByTagName('isAkamai').item(0).firstChild.data;
		akamaiPub = doc.getElementsByTagName('akamaiPub').item(0).firstChild.data;
		akamaiTimeStamp = doc.getElementsByTagName('akamaiTimeStamp').item(0).firstChild.data;
		akamaiRacine = doc.getElementsByTagName('akamaiRacine').item(0).firstChild.data;
	}})
}

function getAkamai(){

	//Chargement des constanets akamai si pas déjà fait
	if (isAkamai==""){
		initAkamai();
	}
    var pathAkamai = "";
    if (isAkamai=="true"){
            pathAkamai = akamaiPub + akamaiTimeStamp + akamaiRacine + "/";
            //pathAkamai = "http://a3.g.akamai.net/7/3/5552/" +"20090911" + "/www.fortuneo.fr" + "/placements/";
    }
    return pathAkamai;
}


function chargeIframe(){
	var oldSrc = document.getElementById('iframe').src;
	var location=window.top.location.href;
	var newSrc="";
	newSrc = addJSessionId(oldSrc,location);
	var allNameFile="";
	if (location.indexOf("?")!=-1){
		allNameFile = location.substring(location.lastIndexOf("/")+1,location.indexOf("?"));
	}else{
		allNameFile = location.substring(location.lastIndexOf("/")+1);
	}
	var nameFile = allNameFile.substring(0,allNameFile.indexOf("."));
	newSrc = newSrc + "&namePage="+ allNameFile;
	newSrc = newSrc + "&cssPathName=" + nameFile;
	document.getElementById('iframe').src = newSrc;

}


function getImage(value){
	//Modif akamai si les images commencent par commun
	if (value.indexOf("commun")==0)
		return " <img src='"+getAkamai() + value+"'/>";
	else
		return " <img src='"+ value+"'/>";
}

function getFlash(width,height,movie,quality,wmode,widthEmbed,heightEmbed){
    var akamaiMovie = getAkamai() + movie;
	var flashHtml = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
	flashHtml= flashHtml+" data='"+akamaiMovie +"'"; 
	flashHtml= flashHtml+" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'";
	flashHtml= flashHtml+" width='"+width+"' height='"+height+"'>";
	flashHtml= flashHtml+" <param name='allowscriptaccess' value='always'>";	
	flashHtml= flashHtml+" <param name='movie' value='"+akamaiMovie+"'>";
	flashHtml= flashHtml+" <param name='quality' value='"+quality+"' />";
	flashHtml= flashHtml+" <param name='wmode' value='"+wmode+"'/>";
	//flashHtml= flashHtml+" <a href='"+lien+"' "+getImage(img)+"</a>";
	flashHtml= flashHtml+" <embed  AllowScriptAccess='always'  src= '"+akamaiMovie+"'  quality='"+quality+"'";
	flashHtml= flashHtml+" pluginspage='http://www.macromedia.com/go/getflashplayer'";
	flashHtml= flashHtml+" type='application/x-shockwave-flash' width='"+widthEmbed+"' height='"+heightEmbed+"'>";		
	flashHtml= flashHtml+" </embed>";
	flashHtml= flashHtml+" </object>";
	return flashHtml;	
}


