//alert("aa");
var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

// **********************************************************************************************************
function Extension_Reduction(nObjet, mode) {
		// si mode = true : affiche
		// si mode = false : cache
		// sinon : bascule entre affiche et cache

//alert(" ns4=" + ns4 + " ie4=" + ie4 + " ns6=" + ns6);
//alert(" nObjet1=" + nObjet + " mode0=" + mode);
	if(ie4){ // Internet explorer
		if (mode == "true" || (mode && mode != "false")){ // tester aussi si true existe et diff de false
			//alert ("mode1=" + mode + "' " + document.getElementById(nObjet).style.display);
			eval(nObjet).style.display = 'block';
		}else if(mode == "false" ){
			//alert ("mode2=" + mode + "' " + document.getElementById(nObjet).style.display);
			eval(nObjet).style.display = 'none';
		}else{
			//alert ("mode3=" + mode + "' " + document.getElementById(nObjet).style.display);
		   //divns6[nObjet].style.display = (divns6[nObjet].style.display=='visible'?'hidden':'visible');
			if (eval(nObjet).style.display == 'none'){
				//alert("a1");
				eval(nObjet).style.display = 'block';
			}else{
				//alert("a2");
				eval(nObjet).style.display = 'none';
			}
		}
	}else if(ns4){ // Netscape 4.x
		if (mode == "true"){
			eval(nObjet).style.display = 'show';
		}else if(mode == "false"){
			eval(nObjet).style.display = 'hidden';
		}else{
			eval(nObjet).style.display = (eval(nObjet).style.display=='visible'?'hidden':'visible');
		}
	}else { // Netscape 6 (mozilla)
		if (mode == "true" || (mode && mode != "false")){ // tester aussi si true existe et diff de false
			//alert ("mode1=" + mode + "' " + document.getElementById(nObjet).style.display);
			document.getElementById(nObjet).style.display = 'block';
		}else if(mode == "false" ){
			//alert ("mode2=" + mode + "' " + document.getElementById(nObjet).style.display);
			document.getElementById(nObjet).style.display = 'none';
		}else{
			//alert ("mode3=" + mode + "' " + document.getElementById(nObjet).style.display);
		   //divns6[nObjet].style.display = (divns6[nObjet].style.display=='visible'?'hidden':'visible');
			if (document.getElementById(nObjet).style.display == "none"){
				//alert("a1");
				document.getElementById(nObjet).style.display = "block";
			}else{
				//alert("a2");
				document.getElementById(nObjet).style.display = "none";
			}
		}
	}
}

// **********************************************************************************************************
function Affiche_Cache(nObjet, mode) {
		// si mode = true : affiche
		// si mode = false : cache
		// sinon : bascule entre affiche et cache
//alert(" ns4=" + ns4 + " ie4=" + ie4 + " ns6=" + ns6);
//alert(" nObjet1=" + nObjet + " mode0=" + mode);
	if (nObjet=="DivRepeter") {
		if (document.form_main.RDV_DATE_FIN.value != document.form_main.RDV_DATE.value) {
			alert ("Il est impossible de faire répéter un rdv qui s'étale sur plusieurs jours.");
			document.form_main.RDV_DATE_FIN.value = document.form_main.RDV_DATE.value;
		}

	}
	if(ie4){ // Internet explorer
		if (mode == "true"){
			eval(nObjet).style.visibility = 'visible';
		}else if(mode == "false"){
			eval(nObjet).style.visibility = 'hidden';
		}else{
			eval(nObjet).style.visibility =	(eval(nObjet).style.visibility=='visible'?'hidden':'visible');
		}
	}else if(ns4){ // Netscape 4.x
		if (mode == "true"){
			eval(nObjet).style.visibility = 'show';
		}else if(mode == "false"){
			eval(nObjet).style.visibility = 'hidden';
		}else{
			eval(nObjet).style.visibility =	(eval(nObjet).style.visibility=='visible'?'hidden':'visible');
		}
	}else if(ns6){ // Netscape 6 (mozilla)

		var divns6 = document.getElementsByTagName("div")
		if (mode == "true" || (mode && mode != "false")){ // tester aussi si true existe et diff de false
			//alert ("mode1=" + mode + "' " + document.getElementById(nObjet).style.visibility);
			document.getElementById(nObjet).style.visibility = 'visible';
			//divns6[nObjet].style.visibility = 'visible';
		}else if(mode == "false" ){
			//alert ("mode2=" + mode + "' " + document.getElementById(nObjet).style.visibility);
			document.getElementById(nObjet).style.visibility = 'hidden';
			//divns6[nObjet].style.visibility = 'hidden';
		}else{
			//alert ("mode3=" + mode + "' " + document.getElementById(nObjet).style.visibility);
		   //divns6[nObjet].style.display = (divns6[nObjet].style.display=='visible'?'hidden':'visible');
		   divns6[nObjet].style.visibility = (divns6[nObjet].style.visibility=='visible'?'hidden':'visible');
		}
	}
}

// **********************************************************************************************************
function testvar(theForm) {
	if (theForm.IND_NUMERO.selectedIndex == 0) {
		alert('le champ [CLIENT] doit être renseigné');
		theForm.IND_NUMERO.focus();	
		return (false);
	} else if (theForm.RDV_TYPE.selectedIndex == 0) {
		alert('le champ [TYPE RDV] doit être renseigné');
		theForm.RDV_TYPE.focus();	
		return (false);
	}
	return true;
} // fin function testvar

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array();

// **********************************************************************************************************
function setPointer(theRow, theRowNum, 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;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
	rowCellsCnt = 1;
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
				col = theCells[c].getAttribute('bgcolor');
				if (col == theDefaultColor
					|| col == thePointerColor
					|| col == theMarkColor)
                	theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
				col = theCells[c].style.backgroundColor;
				if (col == theDefaultColor
					|| col == thePointerColor
					|| col == theMarkColor)
                	theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

// **********************************************************************************************************
function mailer (rows){
	var i, j = 0;
	var num_adresse = new Array();

    for (i = 0; i < rows; i++) {
		if (marked_row[i] == true) {
			num_adresse[j++] = i;
		}	
	}
	
	if (num_adresse.length != 0){
		ValAction = "planning_envoi_mail.php?val=" + num_adresse.join(",");
		document.forms.EnvoiMail.action = ValAction;
		return true;
	} else {
		return false;
	}
}

// **********************************************************************************************************
function valider (rows){
	var i, j = 0;
	var num_nom = new Array();

    for (i = 0; i < rows; i++) {
		if (marked_row[i] == true) {
			num_nom[j++] = i;
		}	
	}
	
	if (num_nom.length != 0){
		ValAction = "planning_valid_maj_pref.php?val=" + num_nom.join(",");
		document.forms.ModifPref.action = ValAction;
		return true;
	} else {
		return false;
	}
}

// **********************************************************************************************************
function fadeInfadeOut(objet){
	if(document.getElementById(objet).style.display=='none'){ 
		$("#" + objet).fadeIn("normal");
	}else{
		$("#" + objet).fadeOut("nomal");
	}
}
function slideToggle(objet){
	$("#" + objet).slideToggle("normal");
}


// **********************************************************************************************************
// COOKIES 
function GetCookie(name) {
	deb = document.cookie.indexOf(name + "=")
	if (deb >= 0) {
		deb += name.length + 1
		fin = document.cookie.indexOf(";",deb)
		if (fin < 0) fin = document.cookie.length
		return unescape(document.cookie.substring(deb,fin))
		}
	return ""
} 

//crée le cookie avec la valeur saisie en paramètre
function SetCookie ( name, value ){
	var aujourdhui = new Date() ; // nouvel objet date
	var expdate = new Date() ; // nouvel objet date
	expdate.setTime( aujourdhui.getTime() + ( 365*24*60*60*1000 ) ) ; // plus d'an à partir d'aujourdh'ui le cookie ne s'efface jamais
	var txt = name + "=" + value + ";expires=" + expdate.toGMTString();
	//alert(" SetCookie=" + txt);
	document.cookie =  txt; // creation du cookie de nom name et de valeur saisie en paramètre
}

//document.getElementById('debug').innerHTML += " GetCookie LOGIN_DISPLAY=" + GetCookie("LOGIN_DISPLAY") + "<br>"; 
