// JavaScript Document
function PopupCentrer(page,largeur,hauteur,options) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
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];}}
}
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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

///////////////////


// JavaScript Document
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
	{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
  catch (e)
	{
	// Internet Explorer
	try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	catch (e)
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}
  return xmlHttp;
}

function updateEmailNewsletter(email){
	//alert('ok');
	var xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null){
		alert("Votre fureteur ne supporte pas ajax.");
		return;
	}
		
	var url = "newsletter.php?email="+email;
	alert("newsletter.php?email="+email);
	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState == 4 && xmlHttp.responseText!=""){			
			alert(xmlHttp.responseText);//'Merci de votre inscription' or 'error'
		}
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function checkRegisterNewsletter() {
	register = document.forms["newsletter-form"];	
	error = false;
	errormail = false;
	email = new RegExp ( "^\\w[\\w+\.\-]*@[\\w\-]+\.\\w[\\w+\.\-]*\\w$", "gi" ) ;
	if ( !register.email.value ) {
		error = true;	
	}
	if ( register.email.value.search(email) == -1 ) {
		errormail = true;
	}
	if ( error ) {
		alert("Vous devez renseigner tous les champs.");
		register.email.focus();
		return false;
	}
	else if ( errormail ) {
		alert("Merci d'indiquer une adresse e-mail valide.");
		register.email.focus();
		return false;
	}
	
	updateEmailNewsletter(register.email.value);
	return false;
}


function valideEmail(str) {
	parob = str.indexOf('@');
		if (parob!=-1) {
			if (str.lastIndexOf('.') < parob) {
				return false;
			}
		} else {
			return false;
		}
	return true;
}

function checkFields() {
	register = document.forms["newsletter-form"];
	//alert("totot"+register.email.value);
	if (!valideEmail(register.email.value)){
		alert('Merci de saisir une adresse e-mail valide.');
		register.email.focus();
		register.email.value='Votre e-mail';
		return false;
	}
}



function viewVideo(docId){
	var div_obj=document.getElementById('media_video');
	var div_slide=document.getElementById('media_image');	
	
	var div_btn_video=document.getElementById('btn_video');
	var div_btn_close_video=document.getElementById('btn_close_video');	
	
	if(div_obj.style.display==''){
		div_obj.innerHTML='';
		div_obj.style.display='none';
		div_btn_video.style.display='';
		div_btn_close_video.style.display='none';

		div_slide.style.display='';

	}else{
		
		var content='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="654" height="360">';
		content+='<param name="movie" value="swf/videoModule.swf?doc_id='+docId+'" />';
		content+='<param name="quality" value="high" />';
		content+='<embed src="swf/videoModule.swf?doc_id='+docId+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="654" height="360"></embed>';
	    content+='</object>';
		
		div_obj.innerHTML=content;
		div_obj.style.display='';

		div_btn_video.style.display='none';
		div_btn_close_video.style.display='';

		div_slide.style.display='none';
	}		
}

function hideVideo(){
	viewVideo(0);
}



function viewSound(docId){
	var div_obj=document.getElementById('media_sound');
	//var div_slide=document.getElementById('media_image');	
	
	var div_btn_sound=document.getElementById('btn_sound');
	var div_btn_close_sound=document.getElementById('btn_close_sound');	
	
	if(div_obj.style.display==''){
		div_obj.innerHTML='';
		div_obj.style.display='none';
		div_btn_sound.style.display='';
		div_btn_close_sound.style.display='none';

		//div_slide.style.display='';

	}else{
		
		var content='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="654" height="37">';
		  content+='<param name="movie" value="swf/soundModule.swf?doc_id='+docId+'" />';
		  content+='<param name="quality" value="high" />';
		  content+='<embed src="swf/soundModule.swf?doc_id='+docId+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="654" height="37"></embed>';
		content+='</object>';

		div_obj.innerHTML=content;
		div_obj.style.display='';

		div_btn_sound.style.display='none';
		div_btn_close_sound.style.display='';

		//div_slide.style.display='none';
	}		
}

function hideSound(){
	viewSound(0);
}


function setCookieBookmarks(val_id)
{
	//Delete_Cookie("str_bookmark",'','');
	var value_bm = getCookieBookmarks("str_bookmark");
	//alert ("before > "+value_bm);
	if(value_bm!=null){
		if(notExistBookmark(val_id,value_bm) && val_id != '0') value_bm = value_bm+","+val_id;
	}else{
		if(val_id != '0')
		{
			value_bm = val_id;
		}
	}
	
	
	//alert ("after > "+value_bm);
	
	if(value_bm!=null){
		var arr_bm_id = value_bm.split(",");
		if(document.getElementById("num_bookmark")){
			document.getElementById("num_bookmark").value = arr_bm_id.length;
		}
		document.cookie = "str_bookmark=" +escape(value_bm);
	}
	return false;		
}

function notExistBookmark(val_id,val_bm){
	var arr_bm = val_bm.split(",");
	for(i = 0 ; i < arr_bm.length ; i++){
		if(arr_bm[i] == val_id){
			return false;
		}
	}
	return true;
}

function Delete_Cookie( name ,path , domain) 
{
	if ( getCookieBookmarks( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function getCookieBookmarks(name)
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function gotoBookmarks()
{
	window.open("http://mutualise.artishoc.com/iddac/commande/index.php?contentPanier="+getCookieBookmarks("str_bookmark"));
}

function sendmail(docId,rubId,ssRubId,sssRubId)
{
	window.open("send_mail.php?rub="+rubId+"&ssRub="+ssRubId+"&sssRub="+sssRubId+"&docId="+docId,"mail","top=300px, left=300px, width=500px, height=200px, toolbar=no, resizable=no");
}

function sendmailRessources(dossId,rubId,ssRubId,sssRubId)
{
	window.open("send_mail.php?rub="+rubId+"&ssRub="+ssRubId+"&sssRub="+sssRubId+"&dossId="+dossId,"mail","top=300px, left=300px, width=500px, height=200px, toolbar=no, resizable=no");
}


///// AFFICHAGE DU MENU PRO
function showMenuEspace(type){
	if(type==0){
		var obj = document.getElementById('pro_sub');
	}else{
		var obj = document.getElementById('pro_sub1');
	}
	if(obj.style.display == 'none'){
		obj.style.display = 'block';
	}else{
		obj.style.display = 'none';
	}
}


function showSousMenuEspace(type){
	if(type==0){
		var obj = document.getElementById('pro_sub');
	}else{
		var obj = document.getElementById('pro_sub4');
	}
	if(obj.style.display == 'none'){
		obj.style.display = 'block';
	}else{
		obj.style.display = 'none';
	}
}
			
function hideSousMenu(){
	var obj = document.getElementById('pro_sub4');
	obj.style.display = 'none';
}

function isEmailAddress(strValue){
	var j,strTemp;
	strTemp = strValue;
	if (strTemp != ''){
		var nCountC = 0;
		for ( j = 0; j< strTemp.length; j++ ){
			c = strTemp.charAt(j);
			if ( !( c>='0' && c<='9' || c>='a' && c<='z' || c>='A' && c<='Z' || c == '@' || c == '.' || c =='_' || c =='-') )
				return false;
			if (c == '@') nCountC  = nCountC + 1;
		}// End for
		if (nCountC != 1)return false;
		if (strTemp.charAt(strTemp.length - 1) == '@' || strTemp.charAt(0) == '@' || strTemp.charAt(strTemp.length - 1) == '.' || strTemp.charAt(0) == '.')
			return false;
		var arr_tmp = strTemp.split("@");
		var arr_tmp1 = arr_tmp[1].split(".");
		if (arr_tmp1.length < 2) return false;
	}
	return true;
}

