

// initialisation de variable pour les sous menus
var sm_timing;

tmp_title=document.title; // corection bug Flash IE

/*POUR LA TRANSITION DE LA PUB UTILSEE DANS INDEX.HTML ATTENTION D INCLURE LES BON HTML
$(document).ready(function() {
	// TRANSITION PUBS
	if($("#ad_728x90").size() > 0 ) {
		var state = 0;
		$.timer(5000, function (timer) {
			if(state == 0) {
				$("#ad_728x90").html('<a target="_blank"  href="http://www.moncontratsante.com/offre.html"><img src="/img/ads/728x90/pub.gif" /></a>');
				state = 1;
			}
			else {
				$("#ad_728x90").html('<a href="#"><img src="/img/ads/728x90/pub.png" /></a>');
				state = 0;
			}
		});
	}

// END OF jQuery(document).ready()
});*/

// Positionnement en haut de la page
function go_top(){
 scrollTo(0,0);
 }


// cache le masque affiché durant le chargement de la page
function hide_loading_mask(){
	document.getElementById("loading_mask").style.display="none";
	}

// roll over (inclue un filtre blend trans si IE
function roll(id){
	
	// version du navigateur
	if(navigator.appName=="Microsoft Internet Explorer"){
		tmp=navigator.appVersion.split("MSIE ");
		tmp=tmp[1].split(".");
		version_navigateur=tmp[0];
		}
	
	var tmp=document.getElementById(id);

	if(tmp.src.indexOf("_c.gif")==-1){

		if(tmp.src.indexOf("_a.gif")==-1){
			
			if(navigator.appName=="Microsoft Internet Explorer"){tmp.filters.blendTrans.apply()}
			tmp.src=tmp.src.replace("_b.gif","_a.gif");
			if(navigator.appName=="Microsoft Internet Explorer"){tmp.filters.blendTrans.play()}	
			
			}
			else{
				if(navigator.appName=="Microsoft Internet Explorer"){tmp.filters.blendTrans.apply()}
				tmp.src=tmp.src.replace("_a.gif","_b.gif");
				if(navigator.appName=="Microsoft Internet Explorer"){tmp.filters.blendTrans.play()}	
				}
		
		}

}


function show_sous_menu(num){ // affiche un menu (num de 2 à 7)
 	var obj = document.getElementById('select_conseillers')
 	//alert("test");
	//alert("rajout test sur l obj chat" + obj)

	// si navigateur inférieur à ie7 et si le menu dérounat survole le select du conseiller (si il existe)
	if (null!=obj)
	{
		if(document.getElementById('select_conseillers') && navigator.appName=='Microsoft Internet Explorer' && num>5 && version_navigateur<7){
			document.getElementById("select_conseillers").style.visibility="hidden";
		}
		else{
			document.getElementById("select_conseillers").style.visibility="visible";
		}
	}
	clearTimeout(sm_timing);
	hide_all_sous_menu();
	var tmp=document.getElementById("sous_menu_"+num);
	if(navigator.appName=="Microsoft Internet Explorer"){tmp.filters[0].apply();}
	tmp.style.display="block";
	if(navigator.appName=="Microsoft Internet Explorer"){tmp.filters[0].play();}
	}
	
	
function hide_all_sous_menu(){ // masque tous les sous menus
	clearTimeout(sm_timing);
	for(i=2;i<8;i++){
		document.getElementById("sous_menu_"+i).style.display="none";
		}
}


function sous_menu_keep_alive(){ // maintient un sous menu en vie
	clearTimeout(sm_timing);
	}


function sous_menu_prepare_to_hide(){ // prépare la disparition d'un sous menu
	//alert("test");
	//alert(document.getElementById('select_conseillers'))
	sm_timing=setTimeout("hide_all_sous_menu();if(null != document.getElementById('select_conseillers')){document.getElementById('select_conseillers').style.visibility='visible';}",300);
	}




/////////<!--// Function to load dynamicly th e subcontent-->>>>>>>>>>
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""


function loadAjaxPage(url, containerId) {
	
	if (bustcachevar) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
		
	$("#" + containerId).load(url+bustcacheparameter);
}

function ajaxpage(url, containerid){
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false

	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid);
	}
	
	if (bustcachevar) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
		
	page_request.open('GET', url+bustcacheparameter, true);
	page_request.send(null);
}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
	if (!document.getElementById)
		return
			
	for (i=0; i<arguments.length; i++){
		var file=arguments[i]
		var fileref=""
		if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script');
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link");
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
	
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
}


/////////<!--FUNCTION TO OPEN THE CHAT WINDOW-->>>>>>>>>>
function loadContactLink(radio) {
	$("#contactLink").attr("href", radio.value);
	$("#contactLink").attr("onclick", "");

	if(radio.id == "contactChatRadio") {
		$("#contactLink").bind('click', runChat);
		$("#contactLink").unbind('click', runContactMail);
		$("#contactLink").unbind('click', runContactPhone);
	}
	else if(radio.id == "contactMailRadio") {
		$("#contactLink").bind('click', runContactMail);
		$("#contactLink").unbind('click', runChat);
		$("#contactLink").unbind('click', runContactPhone);
	}
	else if(radio.id == "contactTelRadio") {
		$("#contactLink").bind('click', runContactPhone);
		$("#contactLink").unbind('click', runChat);
		$("#contactLink").unbind('click', runContactMail);
	}
	else {
		$("#contactLink").unbind('click', runChat);
		$("#contactLink").unbind('click', runContactPhone);
		$("#contactLink").unbind('click', runContactMail);
	}
}

function openPopup(name, html, w, h, scollabal) {

	var x = (screen.width-w)/2;
	var y = (screen.height-h)/2;
	var win = window.open(html, name,
					"height="+h+",width="+w+",menubar=no,scrollbars="+scollabal+ ",resizable=no,location=no,directories=no,status=no");

	return win;
}

function runChat() {
	
	openPopup("LiveChat","/KPI_retraite/sendRequest?servicename=checkEmail&tr_customer_email="+$("#email_input").attr("value"),
			800, 600, "no");
	return false;
}

function runContactMail() {

	openPopup("ContactezMoi","/KPI_retraite/sendRequest?servicename=inputQuestionMailWithFaq&tr_customer_email="+$("#email_input").attr("value"),
			1200, 800, "yes");
	return false;
}

function runContactPhone() {

	openPopup("AppellezMoi","/KPI_retraite/sendRequest?servicename=inputQuestionPhone&tr_customer_email="+$("#email_input").attr("value"),
			1200, 800, "yes");
	return false;
}



// Init

$().ready(function() {
	
	// menu
	$(".menu_button").mouseenter(function() {
		// Get the submenu's id to show
		$(this).siblings('.lastover').removeClass('lastover');
		$(this).addClass('lastover');
		submenuId = $(this).attr("id").split('_')[0] + "_submenu";
		
		$("#submenu").find("div:visible").hide();
		
		// No fade effect for IE
		if(jQuery.support.opacity == true) {
			$("#submenu > #"+submenuId).fadeIn(400);
		}
		else {
			$("#submenu > #"+submenuId).show();
		}
		
	});
	
	
	// Video 
	
	
	// Add videdo popup if there's a video link on the page
	if($(".video_link").attr("class") != undefined) {
	
		// Insert video hidden dialog
		dialogHtml = '<div id="video_dialog" title="Presentation"><object type="application/x-shockwave-flash" data="/player/player_flv.swf" width="309" height="313"><param name="movie" value="/player/player_flv.swf" /><param name="FlashVars" value="flv=/flv/demo2.flv&amp;bgcolor=#FFFFF&amp;autoload=1&amp;autoplay=1&amp;width=309&amp;height=313" /><param name="loop" value="false"><param name="wmode" value="transparent"></object></div>';
		$("body").append(dialogHtml);
		
		// Video dialog
		$("#video_dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			width: 335,
			height: 360,
			draggable: false,
			resizable: false
		});
		
		
		$(".video_link").click(function() {
			$("#video_dialog").dialog('open');
			return false;
		});
	}
	
	
});



