// JavaScript Document

function testDate(year,month,day){
  month = month - 1; // javascript month range : 0- 11
    var tempDate = new Date(year,month,day);
    
    if (!((year == tempDate.getFullYear()) && (month == tempDate.getMonth()) && (day == tempDate.getDate()))){
      return false;
    }
    return true;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  if(selObj.options[selObj.selectedIndex].value != "") {
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function printit(){
if (window.print) {
    window.print() ;  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
}
}
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_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_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];}
}




//Vérifie la syntaxe d'une adresse email
function checkMail(email) {
 	r = email.match(/^[A-Za-z0-9_.-]+@([A-Za-z0-9_-]+\.)+[A-Za-z]{2,4}$/)!=null;
	return r;
}

//Vérifie que la chaine passée finie par .jpg pou .jpeg
function checkJpegExtension(fileName) {
  return fileName.match(/^(.)*(.jpg|.jpeg|.JPG|.JPEG)$/)!=null;
}
function checkDOCExtension(fileName) {
  return fileName.match(/^(.)*(.doc|.DOC)$/)!=null;
}
function checkPDFExtension(fileName) {
  return fileName.match(/^(.)*(.PDF|.pdf)$/)!=null;
}

//popUpImg ouvre une popup pour afficher un screenshot
/*img est l'url de l'image
* width et height la taille du popup a ouvrir
* scrollable booléen pour dire si on peut scroller sur l'image
*/
function popUpImg(img,width,height,scrollable){
	if (screen) {
		leftPos = ((screen.width - width) / 2);
		topPos = ((screen.height - height) / 2);
	}
	if (scrollable) {
		w=open("",'image','weigth=toolbar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left='+leftPos+',top='+topPos);  
	}
	else {
		w=open("",'image','weigth=toolbar=no,scrollbars=no,resizable=yes,width='+width+',height='+height+',left='+leftPos+',top='+topPos);  
	}
	w.document.write("<HTML><BODY onblur=\"window.close();\"><IMG src='"+img+"'>");
  	w.document.write("</BODY></HTML>");
  	w.document.close();
}

//Affiche ou non une zone DIV
function show_hideDiv(divId) { 

  // Booléen reconnaissant le navigateur (vu en partie 2)
  isIE = (document.all) 
  isNN6 = (!isIE) && (document.getElementById)

  // Compatibilité : l'objet DIV est détecté selon le navigateur
  if (isIE) DIV = document.all[divId];
  if (isNN6) DIV = document.getElementById(divId);

  // On affiche ou on cache
  if (DIV.style.display == "none"){
    // Cas ou le tableau est caché
    DIV.style.display = ""
  } else {
    // On le cache
    DIV.style.display = "none"
   }
}

function show_DIV(param){
	 // Booléen reconnaissant le navigateur (vu en partie 2)
  isIE = (document.all) ;
  isNN6 = (!isIE) && (document.getElementById);
  if (isIE) DIV = document.all[param];
  if (isNN6) DIV = document.getElementById(param);	
  DIV.style.display = ""
  return false;
}
function hide_DIV(param){
  
  isIE = (document.all) ;
  isNN6 = (!isIE) && (document.getElementById);
  if (isIE) DIV = document.all[param];
  if (isNN6) DIV = document.getElementById(param);	
  DIV.style.display = "none"
  return false;
}

//Fonction modifiée pour afficher le popup au centre de l'écran
function openCenteredWindow(theURL,winName,width,height,features) { //v2.0
  var top=(screen.height-height)/2;
    var left=(screen.width-width)/2;
  window.open(theURL,winName,"top="+top+",left="+left+",width="+width+",height="+height+","+features);
}


function PCase(STRING){
    /*
    * This code automatically converts the first letter of words to upper case and any other letters to lower case. 
    *  We have included upper casing after full stops and hyphens and also the ability to deal with names such as McCavity. 
    */
    var strReturn_Value = "";
    var iTemp = STRING.length;
    if(iTemp==0){
            return"";
    }
    var UcaseNext = false;
    strReturn_Value += STRING.charAt(0).toUpperCase();
    for(var iCounter=1;iCounter < iTemp;iCounter++){
            if(UcaseNext == true){
                    strReturn_Value += STRING.charAt(iCounter).toUpperCase();
            }
            else{
                    strReturn_Value += STRING.charAt(iCounter).toLowerCase();
            }
            var iChar = STRING.charCodeAt(iCounter);
            if(iChar == 32 || iChar == 45 || iChar == 46){
                    UcaseNext = true;
            }
            else{
                    UcaseNext = false
            }
            if(iChar == 99 || iChar == 67){
                    if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109){
                            UcaseNext = true;
                    }
            }


    } //End For

    return strReturn_Value;
} //End Function

function RTrim(VALUE){
    var w_space = String.fromCharCode(32);
    var v_length = VALUE.length;
    var strTemp = "";

    if(v_length < 0){
        return"";
    }
    var iTemp = v_length -1;
    while(iTemp > -1){
        if(VALUE.charAt(iTemp) == w_space){}
        else{
            strTemp = VALUE.substring(0,iTemp +1);
            break;
        }
        iTemp = iTemp-1;
                }
    return strTemp;
}


function LTrim(VALUE){
    var w_space = String.fromCharCode(32);
    if(v_length < 1){
            return"";
    }
    var v_length = VALUE.length;
    var strTemp = "";
    var iTemp = 0;

    while(iTemp < v_length){
        if(VALUE.charAt(iTemp) == w_space){}

        else{
            strTemp = VALUE.substring(iTemp,v_length);
            break;
        }
        iTemp = iTemp + 1;
    }
    return strTemp;
}

function copier(object){
	object.select();
	var texteACopier = object.createTextRange();   
    texteACopier.execCommand("Copy");   
}
function ucfirst(str) {
   return str.substr(0,1).toUpperCase()+str.substr(1)
}

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, true); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

function remEvent(obj, evType, fn){ 
 if (obj.removeEventListener){ 
   obj.removeEventListener(evType, fn, true); 
   return true; 
 } else if (obj.detachEvent){ 
   var r = obj.detachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

