// 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(num) {
	var i;
	if (typeof(num) != "undefined" && num == 0) {
		MM_showHideLayers('Layer'+num,'','show');
		return;
	}
	for(i=0; i<=10; i++) {
		MM_showHideLayers('Layer'+i,'',(typeof(num) != "undefined" && num == i ? 'show' : 'hide'));
	}
}
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.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}
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 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 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 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;
		} else {
			charleft = maxLength-total;
		}
	}
	
	return(charleft);
}

function showCharsLeft_back(formulaire,champs) {

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

	total = formulaire.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;
		} else {
			charleft = maxLength-total;
		}
	} else {
		charleft = maxLength-total;
	}

	for (i=0; i < formulaire.elements["charsleft"].length; i++) {
		formulaire.elements["charsleft"][i].value=charleft
	}

}
function confirmation(mesg,url) {
if ((url != null) && (url != '') && (mesg != null) && (mesg != ''))
	if (confirm(mesg)) location.href = url;
}
function swapDisplay (id) {
	if (htmlElement = document.getElementById(id)) {
			htmlElement.style.display = (htmlElement.style.display != "" ? "" : "none");
	}
}
function openMP() {
	void(window.open('/mp/','mp','toolbars=no, menubar=no, status=no, scrollbars=yes, menubar=no, width=700, height=420, resizable=yes'));
}
function checkProgramme(){
	type 	 = $("#type").val();
	numero 	 = $("#numero").val();
	ref 	 = $("#ref").val();
	salle 	 = $("#salle").val();
	date_deb = $("#date_deb").val();
	date_fin = $("#date_fin").val();
	titre = tinyMCE.getContent("session_titre") ;
	//titre    = $("#session_titre").val();
	texte = tinyMCE.getContent("session_texte") ;
	
	if(type != '' && numero != '' && ref != '' && salle != '' && date_deb != '' && date_fin != '' && titre != '' && texte != ''){
		return true;
	}else{
		alert('Vous devez renseigner tous les champs obligatoires.');
	}
	
	return false;
}
function checkInscription(){
	if(document.getElementById('action').value == '1'){
		if(document.getElementById('log').value != '' && document.getElementById('password').value != ''){
			return true;
		}else{
			alert('You need to give your email and your password.');
		}
	}else{
		if(document.getElementById('email').value != '' && document.getElementById('first_name').value != '' && document.getElementById('last_name').value != '' && document.getElementById('password1').value != '' && document.getElementById('password2').value != ''){
			if(document.getElementById('password2').value == document.getElementById('password1').value){
				return true;
			}else{
				alert('Wrong password.');
			}
		}else{
			alert('You need to complete your email,your first name, your last name, and create a password.');
		}
	
	}	
	return false;
}
function test_email (my_email) {
	var new_string = new String(my_email);
	if(!new_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')){
		return false;
	}else{
		return true;
	}
}
function checkMail(){
	if(test_email(document.getElementById('email2').value) == true){
		return true;
	}else{
		alert('Invalid email.');
		return false;
	}
	
}
