function selectTh(id){
    divId = "listQ"+id;
    hideAll(tabDivListQ);display(divId);
    tabDivIds.each(function(elmt){
        divThId = "theme"+elmt;
        cmThId = "cm"+elmt;
        $(cmThId).className="clickMenu";
        $(divThId).className="theme";
        });
    divThId = "theme"+id;
    cmThId = "cm"+id;
    if($(divThId)) $(divThId).className="current";
    if($(cmThId)) $(cmThId).className="clickMenu_j";
    if($("curentTheme")) $("curentTheme").value=id;
};
function selectQ(divId,id){
  hideAll(tabDivListChoix);
  for(i=0;i<tabDivListChoix.length;i++){
    idLien = "a"+tabDivListChoix[i] ;
    if($(idLien)) $(idLien).setStyle({fontWeight:"normal"});
  }
  idLien = "a"+divId;
  if($(idLien)){
      $(idLien).setStyle({fontWeight:"bold"});
  };
  display(divId);
//  $("curentQ").value=id;
  if($("divQ")) $("divQ").value=divId;
}
function check(id,isChecked,viewComment){
    chkId="check"+id;
    if(isChecked){
        $(chkId).checked="";
    }else{
        $(chkId).checked="checked";
    }
//    alert($(chkId).checked);
    displayComment(id,!isChecked,viewComment);
};
function displayComment(id,flagDisp,viewComment){
    iconId = "icon"+id;
    if($(id)){
        if(flagDisp && viewComment==1){
            $(id).setStyle({display:"inline",visibility:"visible"});
        }else if(flagDisp && viewComment==2){
            idQ = id;
            commentId = "comment"+id;
            $(id).setStyle({display:"inline"});
            closeComment(idQ,true,commentId);
        }else{
            $(id).setStyle({display:"none",visibility:"hidden"});
            $(iconId).setStyle({visibility:"hidden"});
       }
   }else{
       // pas de commentaire existant
       //alert("coment not created");
       return false;
   }
};
function closeComment(id,flagDisp,idTextArea){
    iconId = "icon"+id;
    if(flagDisp){
        $(id).setStyle({visibility:"hidden"});
        $(iconId).setStyle({visibility:"visible"});
        if($(idTextArea)){$(idTextArea).value="";}
    }else{
        $(id).setStyle({visibility:"visible"});
        $(iconId).setStyle({visibility:"hidden"});
    }
}

function displaylimit(idInput, limit){
    var oInput=$(idInput);
    textLenght = countChar(idInput,limit);
    reste = limit - textLenght;
    newLimit = limit;
    var limit_text = 
        '<div class="limit"><div id="max_'+idInput+'" class="limitNb">'+reste+'</div><div class="limitChar"> caractères maximum</div></div>';
    new Insertion.After(idInput,limit_text);
    oInput.onkeyup = function(event){
        idLimit = "max_"+idInput;
        textLenght = countChar(idInput,limit);
        reste = limit - textLenght;
        $(idLimit).update(reste);
    };
}
function countChar(idInput,limit){
    var oInput=$(idInput);
    textLenght = oInput.value.length;
    if(textLenght<limit){
        newLimit = limit-textLenght;
    }else{
        text = oInput.value;
        oInput.value = text.substr(0,limit);
    }
    return textLenght;
}
function checkNbCheck(listCheckBoxIds,maxCheck,id,viewComment,isCheckBox){
    //debug(Object.toJSON(listCheckBoxIds));
    isChecked  = $("check"+id).checked;
    if(isCheckBox) isChecked  = !isChecked;
    countCheck=0;
    for(ind in listCheckBoxIds){
      //alert(listCheckBoxId[ind]);
      countCheck +=($(listCheckBoxIds[ind]).checked);
    }
    if(!isCheckBox) countCheck ++;
    if(countCheck<=maxCheck || maxCheck==0){ // 0 = pas de limite
        if(isChecked){
            //alert("uncheck");
            check(id,isChecked,viewComment);
        }else{
            //alert("check");
            check(id,isChecked,viewComment);
        };
        if(isCheckBox) return true;
    }else{
        if(isChecked){
            //alert("uncheck");
            check(id,true,viewComment);
        }else{
            if(maxCheck>0){ // 0 = pas de limite
                // alertMaxCheck0 et alertMaxCheck1 sont des messages d'allerte definis en php
                if(maxCheck==1) alert( maxCheck + " " + alertMaxCheck0);
                if(maxCheck>1) alert( maxCheck + " " + alertMaxCheck1);
                if(isCheckBox){
                    $("check"+id).checked = 0;
                    return false;
                };
            };
        };
    }
}
/*

Ne fonctionne pas pour l'instant

function renderComment(Qid,Cid,idRef,idElmt,iconVisible,imgComment,spanDisplay,invite,comment,comment_long){
    spanStyle = "";
    if(spanDisplay) spanStyle = 'style="display:inline;visibility:hidden"';
    if(iconVisible) iconStyle = 'style="visibility:visible"';
    idComment = "icon"+idRef;
    if(!$(idComment)){ //si l'objet n'existe pas on le créé.
        html = 
        '<span iclass="iconComment" id="'+idComment+'" '+iconStyle+'>'+imgComment+'</span>'+
        '<div iclass="commentChoix" id="Q'+idRef+'" '+spanStyle+'>'+
        '<div class="commentBox">'+
        '<div class="closeComment">'+butt->image("closeComment")+'</div>'+
        '<div class="closeComment">'+butt->image("ValidComment")+'</div>'+
        '<div class="inviteComment">'+invite+'</div>'+
        '<textarea rows="5" id="comment'+Cid+'" name="comment'+Qid+'['+Cid+']" >'+comment+'</textarea>'+
        '<div class="limit"><script type="text/javascript">displaylimit("comment'+Cid+'",'+comment_long+')</script></div>'+
        '</div>'+
        '</div>';
        new Insertion.Bottom(idElmt, html);
    }
}
*/
/***********************************************
* Email Validation script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
var emailfilter= /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/i;

function checkmail(e){
    var returnval=emailfilter.exec(e.value)
    if (returnval==null){
        alert("le mail "+e+" ne semble pas correct.")
        e.select()
    }
    return returnval
}
function is_email(sMail)
{
 var re=/^[a-z\d]+((\.|-|_)[a-z\d]+)*@((?![-\d])[a-z\d-]{0,62}[a-z\d]\.){1,4}[a-z]{2,6}$/gi;
 return (sMail.match(re)==sMail)&&(sMail.substr(sMail.lastIndexOf("@")).length<=256);
}

