//pour ancien navigateur
function checkBrowser()
{	
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie55=((this.ver.indexOf("MSIE 5.5")>-1 || this.ie6) && this.dom)?1:0;
	this.ie5=((this.ver.indexOf("MSIE 5")>-1 || this.ie5 || this.ie6) && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.ie4plus=(this.ie6 || this.ie5 || this.ie4);
	this.ie5plus=(this.ie6 || this.ie5)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns5);
	return this;
}
			
bw = new checkBrowser();
			
if (!document.getElementById) 
{
document.getElementById = getObjectById;
}
			
function getObjectById(ID) 
{
	var obj;
	if (bw.dom)
		return document.getElementById(ID);
	else if (bw.ie4)
		return document.all(ID);
	else if (bw.ns4)
		return eval('document.' + ID);
}
			
function getObjectByIdParent(ID) 
{
	var obj;
	if (bw.dom)
		return parent.document.getElementById(ID);
	else if (bw.ie4)
		return parent.document.all(ID);
	else if (bw.ns4)
		return eval('parent.document.' + ID);
}

function cancelBubble(netEvent) 
{
    if (document.all) 
    {
        window.event.cancelBubble = true;
    } 
    else 
    {
        netEvent.cancelBubble = true;
    }
}

function getObjectStyle(obj)
{ 
	if (!getObjectById)
		return;
	if (theObj = getObjectById(obj))
		return theObj.style;	
} 

function hide(obj)
{
	if (!getObjectStyle)
		return;
	if (theObj = getObjectStyle(obj))
		theObj.display = 'none';
}

function show(obj)
{
	if (!getObjectStyle)
		return;
	if (theObj = getObjectStyle(obj))
		theObj.display = 'block';
}

function showhide(obj)
{
	if (!getObjectStyle)
		return;
	if ( !show)
		return;
	if ( !hide)
		return;
	if (theObj = getObjectStyle(obj))
	{
		if (theObj.display == 'none')
			show(obj);
		else
			hide(obj);
	}
}

// Referme le menu deroulant
function hideSsMenu()
{
	hide('ssmenuA');
	hide('ssmenuB');
	hide('ssmenuC');
}

// Boucle de validation
function validateFormNews(form) {
	if (isNotEmpty(form.nom)) {
		if (isNotEmpty(form.prenom)) {
			if (isNotEmpty(form.eMail)) {
                if (isEMailAddr(form.eMail)) {
							return true;
					}
				}
			}
		}
	return false;
}

// Vérifie si un champ a bien été renseigné
function isNotEmpty(elem) {
	var str = elem.value;
    var re = /.+/;
    if(!str.match(re)) {
        alert("Veuillez renseigner les champs obligatoires.");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        return true;
    }
}

// Vérifie si l'adresse e-mail est valide
function isEMailAddr(elem) {
	var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Veuillez vérifier le format de votre adresse e-mail.");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        return true;
    }
}

// Positionne le curseur dans un champ donné
function focusElement(formName, elemName) {
    var elem = document.forms[formName].elements[elemName];
    elem.focus();
    elem.select();
}

//fonction pour choisir l'action 
function submitModif(page,texte) 
{
	var ok;
    ok=confirm(texte); 
    if(ok) {
    	document.form.action = page; 
    	document.form.submit();
    }
} 

function viderDate(elem){
	if(elem.value=="jj/mm/aaaa")
		elem.value="";
}

// Demande de confirmation de validation
function confirmModif(chaine){ 
    var ok;
    ok=confirm(chaine); 
    return ok;
}

// coche tous
var coche = true;
function cocher(form) {
	for(i=0;i<form.length;i++){
		e = form.elements[i];
		if(e.type=='checkbox') e.checked = coche;
	}
	coche = !(coche);
}

// limite la taille d'un textarea et affiche le nombre de caractère restant
function limiteTaille(objetarea,taille,res) {
	
	var nbGras = 0;
	var nbPdf = 0;
	var nbLien = 0;
	
	var tabGras = objetarea.value.match(/\[\/gras\]/g);
	var tabPdf = objetarea.value.match(/\[\/pdf\]/g);
	var tabLien = objetarea.value.match(/\[\/lien\]/g);
	
	if(tabGras!=null)
		var nbGras = tabGras.length;
	if(tabPdf!=null)
		var nbPdf = tabPdf.length;
	if(tabLien!=null)
		var nbLien = tabLien.length;
	
	var tBalise = 13 * nbGras + 11 * nbPdf+ 14 * nbLien;
	
	if( (objetarea.value.length + 1) >= (taille-tBalise))
		  objetarea.value = objetarea.value.substr(0,taille + tBalise - 1);
	res.value = (taille - (objetarea.value.length+1) + tBalise);
return ;
}

//pop-up
function openwindows(page,titre,wdt,hgt) 
{ 
   /*window.open("biographie.php","Said-bahij","width=800,height=600,location=no,status=no,toolbar=no");*/
   window.open(page,titre,"width="+wdt+",height="+hgt);
} 

function openlien(adresse) 
{ 
   /*window.open("biographie.php","Said-bahij","width=800,height=600,location=no,status=no,toolbar=no");*/
   window.open(adresse,"","width=" + screen.width-1 + ",height=" + screen.height-1 + ",location=yes,resizable=yes,status=yes,toolbar=yes");
} 