﻿// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

document.getElementByTrueId = function (id) {
	var vResult = this.getElementById (id);
	if (vResult) {
    	if (vResult.id != id) {
			// IE gets elements by name, not ID, FUCK !!!!
 			for (i = 0; i < this.all.length; i++) {
 				if (this.all[i].id == id)
 					return this.all[i];
 			}
 			return null;
    	}
		return vResult;
	}
	return null;
}

document.getElementByName = function (name) {
	for (i = 0; i < this.all.length; i++) {
		if (this.all[i].name == name)
			return this.all[i];
	}
 	return null;
}


function fix_accents(in_string) {

	in_string = in_string.replace("&ocirc;", "o");
	in_string = in_string.replace("&ucirc;", "u");
	in_string = in_string.replace("&acirc;", "a");
	in_string = in_string.replace("&nbsp;", " ");
	in_string = in_string.replace("&ecirc;", "e");
	in_string = in_string.replace("&eacute;", "e");
	in_string = in_string.replace("&egrave;", "e");
	in_string = in_string.replace("&euml;", "e");
	in_string = in_string.replace("&agrave;", "a");
	in_string = in_string.replace("&ccedil;", "c");
	in_string = in_string.replace("&ugrave;", "u");
	
	return in_string;
}


function set_page_title_relative(le_titre) {

	// call several times. bouh, not clean
	le_titre = fix_accents(le_titre);
	le_titre = fix_accents(le_titre);
	le_titre = fix_accents(le_titre);
	le_titre = fix_accents(le_titre);
	
	document.title = le_titre + " - universite-des-entrepreneurs.com";
}


function set_page_title_absolute(le_titre) {

	document.title = le_titre;
}

function toggle(iDisplayValue, iWrapper1ID, iWrapper2ID, iIconID, iIcon1, iIcon2)
{
	var obj1 = document.getElementByTrueId (iWrapper1ID);
	if (!obj1)
		return;
	var obj2 = document.getElementByTrueId (iWrapper2ID);
	if (!obj2)
		return;
	var icon = document.getElementByTrueId (iIconID);
	
	if (!obj2.style.display || obj2.style.display == 'none') {
		obj1.style.display = 'none';
		obj2.style.display = iDisplayValue;
		if (icon)
			icon.src = iIcon2;
	} else {
		obj1.style.display = iDisplayValue;
		obj2.style.display = 'none';
		if (icon)
			icon.src = iIcon1;
	}
}

