var IE4 = (document.all) ? true : false;

/* Fonction basculant l'affichage vers la page d'accueil */
function goHome() {
	try {
		var domain = currentDomain(location.href);
		
		if (location.href.indexOf('http://www.essec.fr')==0 || location.href.indexOf('http://mba.essec.fr')==0) {
			location.href = 'http://www.essec.fr';
		} else {
			location.href = 'http://www.essec.edu';
		}
	}
	catch (e) {
		location.href='http://www.essec.edu';
	}
}

/* Fonction de bascule des langues */
function switchLangs() {
	var locationHref = location.href;
	try {
		var domain = currentDomain(locationHref);
		var locationToSwitch = domain + "/essec/switch" + locationHref.substring(domain.length, locationHref.length);
		location.href = locationToSwitch;
	}
	catch (e) {
		location.href='http://www.essec.edu';
	}
}

/* Récupération du domaine courant */
function currentDomain(locationHref) {
	var domain;

	try {
		var locationREF = locationHref.substring(7); // 7 = 'http://'.length
		locationREF = locationREF.substring(0, locationREF.indexOf('/'));

		return ('http://' + locationREF);
	}
	catch (e) {
		return 'http://www.essec.edu';
	}
}

/* Génération des adresses mails à la volée */
function ecleaf_mtlight_v1(arg1, arg2) {
	try {
		location.href="mailto:" + arg1 + "@" + arg2;
	}
	catch (e) {}
}

function Lobj(Lname) {
	if (IE4) {
		return document.all.tags('div')[Lname].style;
	}
	else {
		/* MF : 11/05/2004 - Modification pour compatibilité Netscape 6
		if (isNaN(Lname)) {
			for (var i=0; i<document.layers.length; i++) {
				if (document.layers[i].name == Lname) return document.layers[i];
			}
		}
		else return document.layers[Lname];
		*/
		return document.getElementById(Lname).style;
	}
}

function LsetVis(Lname,vis) {
	/*MF : 11/05/2004 - Modification pour compatibilité Netscape 6
	if (IE4) Lobj(Lname).visibility = (vis == 0) ? "hidden" : "visible";
	else Lobj(Lname).visibility = (vis == 0) ? 'hide' : 'show';
	*/
	Lobj(Lname).visibility = (vis == 0) ? 'hidden' : 'visible';
}

/* Inverse la visibilité du block identifié par 'id' */
function switchVisibility(id) {
	if (document.getElementById(id).style.visibility == 'visible') {
		document.getElementById(id).style.visibility='hidden';
		document.getElementById(id).style.display='none';
	} else {
		document.getElementById(id).style.visibility='visible';
		document.getElementById(id).style.display='block';
	}
}

/* Inverse l'affichage d'une image identifiée par 'id' */
function switchImage(id, src1, src2) {
	if (document.getElementById(id).src.indexOf(src1) > 0) {
		document.getElementById(id).src = src2;
	} else {
		document.getElementById(id).src = src1;
	}
}