// JavaScript Document
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function hideAllLayers() {
	var i;
	for(i=0; i<=10; i++) {
		MM_showHideLayers('Layer'+i,'','hide');
	}
}
function showLayer() {
	var args=showLayer.arguments;
	var i,j;
	
	num = args[0];
	
	// gestion de l'affichage de layer 0 (désactivation de tous les calques)
	if (typeof(num) != "undefined" && num == 0) {
		MM_showHideLayers('ml'+num,'','show');
		return;
	}
	
	/*
	// Affichage du sous-menu
	
	if (typeof(args[1]) != "undefined" && num != 0) {
		MM_showHideLayers('ml'+num+'-'+args[1],'','show');
	}
	*/

	for(i=0; i<=10; i++) {
		if (typeof(num) != "undefined" && num == i) {
			MM_showHideLayers('ml'+i,'','show');
			if (typeof(args[1]) != "undefined") {
				for(j=1; j<=10; j++) {
					MM_showHideLayers('ml'+i+'-'+j,'',(args[1] == j ? 'show' : 'hide'));
				}
			}
		} else {
			MM_showHideLayers('ml'+i,'','hide');
			for(j=1; j<=10; j++) {
				MM_showHideLayers('ml'+i+'-'+j,'','hide');
			}
		}
	}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function openBrowserWin(url) {
	//wSubmitEmail = new window();
	wSubmitEmail = window.open(url, "wSubmitEmail", "width=200,height=100,status=no,toolbar=no,menubar=no,location=no,favorites=no,scrollbars=no,resizable=no");
	if (typeof(wSubmitEmail) != "undefined") {
		return(true);
	} else {
		return(false);
	}
}
function jumpTo(url) {
	if (typeof(url) != 'undefined' && url != null && url != '') {
		location.href = url;
	}
}
function clearmsg(){
	document.sms.abstractbody.value="";
	document.sms.charsleft.value="2000";
	document.sms.abstractbody.focus();
}
function confirmation(mesg,url) {
if ((url != null) && (url != '') && (mesg != null) && (mesg != ''))
	if (confirm(mesg)) location.href = url;
}
// ****************************************************************************
function checkMail(email, msg) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
		return(true);
	} else {
		if (msg != "" && msg != null) {
			alert(msg);
		}
		return(false);
	}
}
// ****************************************************************************
function nlSubmit() {
	
	var i;
	var email = $F('newsletter_email');
	var cat;
	
	var error_bad_email = $F('newsletter_error_bad_email');
	var error_empty_cat = $F('newsletter_error_empty_cat');
	
	var catCheck = false;
	var catInputs = Form.getInputs('newsletter_form','radio','newsletter_cat');
	
	for (i=0; i<catInputs.length; i++) {
		if (catInputs[i].checked == true) {
			catCheck = true;
			cat = catInputs[i].value;
			break;
		}
	}
	
	if (!catCheck) {
		alert(error_empty_cat);
	} else if (!checkMail(email)) {
		alert(error_bad_email);
	} else {
		// var oToEmailAjx = this;
		$('newsletter_form').hide();
		$('newsletter_registration_wait').show();
		var oAjxRqst = new Ajax.Request('ajx_newsletter.php',
			{
				method: 'post',
				// encoding: 'ISO-8859-1',
				requestHeaders: ["Cache-Control", "no-cache", "Pragma", "no-cache"],
				parameters:{newsletter_email:email, newsletter_cat:cat},
				onSuccess: function(transport){
						nlResponse(transport.responseText);
				},
				onFailure: function(){
						alert('Something went wrong...')
				}
			}
		);
	}
}
// ****************************************************************************
function nlResponse(response) {
	if (response != '' && response == '1') {
		// alert('Response:'+response);
		$('newsletter_form').hide();
		$('newsletter_registration_wait').hide();
		$('newsletter_registration_ok').show();
	}
}
// ****************************************************************************


Event.observe(window, 'load', function() {
	Event.observe('newsletter_form', 'submit', nlSubmit);
});

function showCharsLeft(champs,limit) {

	// if(navigator.appName!="Netscape") {
	var maxLength = limit;
	var toRemove, i, charleft;

	total = champs.form.elements["descriptif"].value.length;

	if (typeof(champs) != "undefined") {
		if (total > maxLength) {
			toRemove = total - maxLength;
			
			champs.value = champs.value.substring(0,champs.value.length - toRemove);
			charleft = 0;
			alert("Merci de saisir un texte < à " + maxLength +" caractères.");
		} else {
			charleft = maxLength-total;
		}
	}
	
	return(charleft);
}



function valider_over()
{
	document.getElementById("img_valider").src = "/images/mark_over.gif";
}
function valider_out()
{
	document.getElementById("img_valider").src = "/images/mark.gif";
}

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}
