// JavaScript Document
var t=null;

//********************************
var currentTabDiv = 'left';
var currentTab = 'homeTab_left';

function mouseOverTab(thisTab,tab) {
	if (thisTab.id != currentTab) {
		thisTab.style.backgroundColor = '#999999';
		thisTab.style.color = '#ffffff';
	}

}

function mouseOutTab(thisTab,tab) {
	if (thisTab.id != currentTab) {
		thisTab.style.backgroundColor = '#ffffff';
		thisTab.style.color = '#999999';
	}

}

function showChannelDiv(thisTab)
{
	if (thisTab.id != currentTab)
	{
		var thisTabDiv = thisTab.id.split('_');
		thisTabDiv=thisTabDiv[thisTabDiv.length-1];

		document.getElementById(currentTabDiv).style.display='none';
		document.getElementById(currentTabDiv).style.visibility='hidden';
		
		document.getElementById(thisTabDiv).style.display='block';
		document.getElementById(thisTabDiv).style.visibility='visible';
	
		document.getElementById(currentTab).style.backgroundColor = '#ffffff';
		document.getElementById(currentTab).style.color = '#999999';
		
		currentTabDiv=thisTabDiv;
		currentTab=thisTab.id;
	}
}
//********************************

function affiche_heure(){
	var now = new Date();
	var hrs = now.getHours();
	var min = now.getMinutes();
	var sec = now.getSeconds();
	document.heure.h.value=hrs;
	document.heure.m.value=min;
	document.heure.s.value=sec;
}
function start(){
	t=setInterval(affiche_heure,1000);
}
function stop(){
	clearInterval(t);
}				   
function restart(){
	window.location.reload();
}


function ouvrirDiv(id){
   if(document.getElementById(id).style.display == "block") {
    document.getElementById(id).style.display = "none" ;

   } else {
    document.getElementById(id).style.display = "block" ;

   }
   window.status =  document.getElementById(id).style.display;
}
function fermerDiv(id){
   if(document.getElementById(id).style.display == "block") {
    document.getElementById(id).style.display = "none" ;

   } else {
    document.getElementById(id).style.display = "none" ;

   }
   window.status =  document.getElementById(id).style.display;
}
function validInput(evt) {
	var keyCode = evt.which ? evt.which : evt.keyCode;
	//var interdit = '\"<>\\/`\'';
	var interdit = '';
	if (interdit.indexOf(String.fromCharCode(keyCode)) >= 0) {
		return false;
	}
}
function envoiPassword(id_case,id_div){
	if ( document.getElementById(id_case).checked ) {
		document.getElementById(id_div).style.display = "none" ;
	}
	else {
    document.getElementById(id_div).style.display = "block" ;
	}
}
/************************************************************/
function testEmail(adresse_email){
	//adresse_email = document.NomDuForm.NomDuChamps.value;
	arobase = adresse_email.indexOf("@");
	point = adresse_email.indexOf(".",arobase);
	mauvais_endroit_point = arobase+1;
	double_point = adresse_email.indexOf("..",arobase);
	nbre_carac = adresse_email.length - point;
	double_arobase = adresse_email.indexOf("@",arobase+1);
	   
	// dans l'ordre:         
	// si l'arobase est absente ou en 1ere position
	// ou si le . suivant l'arobase est juste derriere ou absent
	// si la longueur de l'adresse est inferieure a 5 (grand minimum -> x@x.x)
	// si il ya pas 2 . qui se suive deriere l'arobase
	// si il y a bien 2 caractere minimum apres le . situe derriere l'arobase
	// si il y a pas une arobase deriere la premiere arobase
	if ( (arobase < 1) ||  
		(point <= mauvais_endroit_point) || 
		(adresse_email.length < 5) || 
		(double_point >= 0) ||
		(nbre_carac < 3) ||
		(double_arobase >= 0) ){
	   		//alert ("l'adresse email est invalide.");
	   		return false;
		}
	return true;
}

//compteur de carac
var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength)
		return false;
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
		var pressedkey=/[a-zA-Z0-9\.\,\/]/ ;
		if (pressedkey.test(String.fromCharCode(e.which)))
			e.stopPropagation();
	}
}

function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder);
	var lengthleft=maxlength-theform.value.length;
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder);
	if (window.event||e.target&&e.target==eval(placeholder)){
		if (lengthleft<0)
			theform.value=theform.value.substring(0,maxlength);
		placeholderobj.innerHTML=lengthleft;
	}
}

function displaylimit(thename, theid, thelimit){
	var theform=theid!=""? document.getElementById(theid) : thename;
	var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b>';
	if (document.all||ns6)
		document.write(limit_text);
	if (document.all){
		eval(theform).onkeypress=function(){ 
			return restrictinput(thelimit,event,theform);
		}
		eval(theform).onkeyup=function(){ 
			countlimit(thelimit,event,theform);
		}
	}
	else if (ns6){
		document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
		document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
	}
}

/***********************************/
function fenetre(nom_fichier, largeur, hauteur, scrll){
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(nom_fichier,'',"top="+top+",left="+left+",width="+largeur+",height="+hauteur+',directories=No,status=No,menubar=No,scrollbars='+scrll+',toolbar=No');
}

function alert_deplacer_mail(){
	if ( confirm('Attention! certain contact n\'a pas d\'adresse MAIL. \n  \t Voulez-vous continuer?'))
		return true;
	return false;
}

/************************************************************/
// Fonction pour le surlignage des lignes des tableaux
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

var showhide_state = 'none';
var previous_elem = '';
// Show Hide
function showhide(layer_ref) { 
	
	if (previous_elem !=  '' && previous_elem != layer_ref) {showhide_state = 'none';}
	
	if (showhide_state == 'block') { showhide_state = 'none'; } else { showhide_state = 'block'; } 

	if (document.layers) { //IS NETSCAPE 4 or below 
		if (previous_elem != '' && previous_elem != layer_ref && showhide_state == 'block') {
			document.layers[previous_elem].display = 'none';
		}
		document.layers[layer_ref].display = showhide_state;
	} 
	
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		if (previous_elem != '' && previous_elem != layer_ref && showhide_state == 'block') {
			document.all[previous_elem].style.display = 'none';
		}
		document.all[layer_ref].style.display = showhide_state; 
	} 

	
	if (document.getElementById &&!document.all) { 
		if (previous_elem != '' && previous_elem != layer_ref && showhide_state == 'block') {
			hza = document.getElementById(previous_elem); 
			hza.style.display = 'none'; 
		}
		hza = document.getElementById(layer_ref); 
		hza.style.display = showhide_state; 
	} 
	
	if (showhide_state == 'block') {previous_elem = layer_ref;}
} 
