var returnlocation = "/intranet/workspace.php"

function subscribe_to_newsletter() {
	
	var a = document.getElementById('action').value;	
	var e = document.getElementById('email').value;	

	if(a) {
		if(e && a) {
			if(e.indexOf('@')>0) {
				document.forms["subscribe"].submit();
			} else {
				alert('L\'adresse de courrier indiquée n\'est pas valide.');				
				document.getElementById('action').value = "";	
			}//
		} else {
			alert('Veuillez inscrire votre adresse de courriel\n ou sélectionner une action');	
		 }//
	} else {
		alert('Veuillez sélectionner une action.');		
	}//
}



function send_to_a_friend(site,page)
{
var u = '/public/send.php?sid='+site+'&url='+page;
var w = window.open(u,"","width=400,height=600, toolbar=0, addressbar=0, directories=0, location=0, menubar=0, resizable=1,scrollbars=1,status=0,left=1,top=1");
w.window.focus();
}

function printDocument(page)
{
var u = page;
var w = window.open(u,"","width=750,height=600, toolbar=0, addressbar=0, directories=0, location=0, menubar=0, resizable=1,scrollbars=1,status=0,left=1,top=1");
w.window.focus();
}

function getPrintableArea() {
//Opener window print area
var opa = window.opener.document.getElementById('printable_area');
var pa = document.getElementById("printable_area");
pa.innerHTML = opa.innerHTML;
var print_zone = document.getElementById("print");
print_zone.innerHTML = "";
}

function onoff(id) {
	
	var m1 = document.getElementById(id);
	//var m2 = document.getElementById('hml_'+id);
	var cls = m1.className;
	var bcls = cls.substring(0,cls.lastIndexOf('_')+1);
	var cls = cls.slice(cls.lastIndexOf('_')+1,cls.length);
	if(cls != "high") {
		if(cls == "off") 
			{
				m1.className = bcls+"on";
			} else {
				m1.className=  bcls+"off";				
			}
	}//
}

function showToolsMenu(id) {
	
	var hs = document.getElementById(id);
	var inti = document.getElementById(id+'-pimg');
	t2 = getLeft(hs);
	tleft = getLeft(inti)-100;
	ttop = getTop(inti)+21;
	var state = hs.className;
	if(state == "off") {
		inti.src = '/ressources/modules/w_on.png';
		hs.className="on";
		hs.style.posLeft=tleft;
		hs.style.posTop=ttop;
		hs.style.left=tleft;
		hs.style.top=ttop;
	} else if(state== "on") {
		inti.src = '/ressources/modules/w_off.png';
		hs.style.posLeft=-500;
		hs.style.posTop=-500;
		hs.style.left=-500;
		hs.style.top=-500;
		hs.className="off";
	}
}

function mH(id) {
	
	var m1 = document.getElementById('hm_'+id);
	//var m2 = document.getElementById('hml_'+id);
	var cls = m1.className;
	var bcls = cls.substring(0,cls.lastIndexOf('_')+1);
	var cls = cls.slice(cls.lastIndexOf('_')+1,cls.length);
	if(cls != "high") {
		if(cls == "off") 
			{
				m1.className = bcls+"on";
			} else {
			m1.className=  bcls+"off";				
			}
	}//
}

function getLeft(MyObject)
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetLeft + getLeft(MyObject.offsetParent));
    else
        return (MyObject.offsetLeft);
    }
function getTop(MyObject)
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetTop + getTop(MyObject.offsetParent));
    else
        return (MyObject.offsetTop);
    }

function tMenu(id) {
	
	var hs = document.getElementById("tm_sub_"+id);
	var inti = document.getElementById('tm_i_'+id);
	tleft = getLeft(inti)+1;
	ttop = getTop(inti)+36;
	var cls = hs.className;
	var state = cls.substring(cls.lastIndexOf('_')+1,cls.length);
	var bcls = cls.substring(0,cls.lastIndexOf('_')+1);	
	if(state == "off") {
		hs.className=cls+"_on";
		hs.style.posLeft=tleft;
		hs.style.posTop=ttop;
		hs.style.left=tleft;
		hs.style.top=ttop;
		hs.className=bcls+"on";
} else if(state == "on") {
		hs.style.posLeft=-500;
		hs.style.posTop=-500;
		hs.style.left=-500;
		hs.style.top=-500;
		hs.className=bcls+"off";
	}
}


function hmSubmenu(id,state) {
	
	//mH(id);
	var hs = document.getElementById("hm_sub_"+id);
	//var h2 = document.getElementById("h2_sub_"+id);
	var inti = document.getElementById('hm_i_'+id);
	t2 = getLeft(hs);
	tleft = getLeft(inti)+1;
	ttop = getTop(inti)+36;
	var cls = hs.className;
	var cls = cls.slice(cls.lastIndexOf('_')+1,cls.length);
	if(state == "on") {
		hs.className="h_submenu_on";
		hs.style.posLeft=tleft;
		hs.style.posTop=ttop;
		hs.style.left=tleft;
		hs.style.top=ttop;
	} else if(state == "off") {
		hs.style.posLeft=-500;
		hs.style.posTop=-500;
		hs.style.left=-500;
		hs.style.top=-500;
		hs.className="h_submenu_off";
	}
}

function hmSubmenu1(id,state) {
	
	mH(id);
	hmSubmenu(id,state);
}

function hmSubmenu2(id,state) {
	
	var m1 = document.getElementById('hm_'+id);
	var cls = m1.className;
	var bcls = cls.substring(0,cls.lastIndexOf('_')+1);
	var cls = cls.slice(cls.lastIndexOf('_')+1,cls.length);

	if(cls != "high") {
		if(state == "on") {
			m1.className = bcls+"on";
		} else if(state == "off") {
			m1.className = bcls+"off";		
		}
	}//
	
	hmSubmenu(id,state);
}


function vmSubmenu(id) {

	var vs = document.getElementById("vm_sub_"+id);
	var cls = vs.className;
	var state = cls.slice(cls.lastIndexOf('_')+1,cls.length);

	if(state == "on") {
		vs.className="v_submenu_off";
	} else if(state== "off") {
		vs.className="v_submenu_on";
	}

	var v = document.getElementById("vm_"+id);
	var cls = v.className;
	var state = cls.slice(cls.lastIndexOf('_')+1,cls.length);

	if(state == "on") {
		v.className="v_menu_off";
	} else if(state== "off") {
		v.className="v_menu_on";
	}

}

function vSubmenu3(id) {
	
	var vs = document.getElementById("v_sub3_"+id);
	var li = document.getElementById("v_li_3_"+id);
//var h2 = document.getElementById("h2_sub_"+id);
	var cls = vs.className;
	var state = cls.slice(cls.lastIndexOf('_')+1,cls.length);

	if(state == "on") {
		vs.className="v_sub3_off";
	} else if(state== "off") {
		vs.className="v_sub3_on";
	}

	var cli = li.className;
	var state = cli.slice(cli.lastIndexOf('_')+1,cli.length);

	if(state == "1") {
		li.className="v_submenu_2";
	} else {
		li.className="v_submenu_1";
	}


}

function vSubmenu3x(id) {
	
	var vs = document.getElementById("v_sub3_"+id);
	//var h2 = document.getElementById("h2_sub_"+id);
	var inti = document.getElementById('pos_'+id);
	t2 = getLeft(vs);
	tleft = getLeft(inti)+180;
	ttop = getTop(inti)+1;
	var cls = vs.className;
	var state = cls.slice(cls.lastIndexOf('_')+1,cls.length);

if(state == "off") {
		vs.className="v_sub3_on";
		vs.style.posLeft=tleft;
		vs.style.posTop=ttop;
		vs.style.left=tleft;
		vs.style.top=ttop;
		alert(vs.style.top=ttop);
} else if(state== "on") {
		vs.style.posLeft=-500;
		vs.style.posTop=-500;
		vs.style.left=-500;
		vs.style.top=-500;
		vs.className="v_sub3_off";
	}
}

function post_comment(blogid,postid) {
	var fblogid = document.getElementById('top_node_id');
	fblogid.value = blogid;
	var fpostid = document.getElementById('reference_id');
	fpostid.value = postid;

	var	czone = document.getElementById('comment_zone');
	czone.style.visibility = 'visible';
	window.location.href = '#comment';
	document.forms["comment"].elements["title"].focus();
} //  

function post_general_comment(id,table) {
	var rid = document.getElementById('reference_id');
	rid.value = id;
	var tid = document.getElementById('reference_table');
	tid.value = table;

	var	czone = document.getElementById('comment_zone');
	czone.style.visibility = 'visible';
	window.location.href = '#comment';
	document.forms["comment"].elements["title"].focus();
} // 



function Popup(doc)
{
var u = doc;
var w = window.open(u,"","width=800,height=600, toolbar=0, addressbar=1, directories=1, location=1, menubar=1, resizable=1,scrollbars=1,status=0,left=1,top=1");
w.window.focus();
}

function printDocument(page)
{
var u = page;
var w = window.open(u,"","width=750,height=600, toolbar=0, addressbar=0, directories=0, location=0, menubar=0, resizable=1,scrollbars=1,status=0,left=1,top=1");
w.window.focus();
}

function getPrintableArea() {
//Opener window print area
var opa = window.opener.document.getElementById('printable_area');
var pa = document.getElementById("printable_area");
pa.innerHTML = opa.innerHTML;
var print_zone = document.getElementById("print");
print_zone.innerHTML = "";
}


function PopFile(doc)
{
var u = doc;
var w = window.open(u,"","width=600,height=450, toolbar=0, addressbar=0, directories=0, location=0, menubar=0, resizable=0,scrollbars=0,status=0,left=200,top=200");
w.window.focus();
}

function PopAudio(doc)
{
var u = doc;
var w = window.open(u,"","width=300,height=200, toolbar=0, addressbar=1, directories=1, location=1, menubar=1, resizable=1,scrollbars=1,status=0,left=1,top=1");
w.window.focus();
}

function close_window(v1,v2)
{
window.close();
}

function showSection(id) {
	
	var tsect = document.getElementById(id);
	if(tsect) {
		if(tsect.className == "on") 
			{
			tsect.className ="off";
			}
			else {
			tsect.className="on";				
			}
	}//if tsect
}

function goSelectedPage(url) {
	if(url) {
	 window.location.href = url;
	}
}

function recherche(source) {
	
	if(source == 1) {
		var q1 = document.getElementById('search1').value;
		var q2 = document.getElementById('search2').value;
		var nurl = '/recherche/'+q1;
		if(q2) nurl = nurl+'/'+q2;
	} else {
		var q = document.getElementById('search').value;
		var nurl = '/recherche/'+replaceAccents(q);		
	}
	
	window.location.href = nurl;
}

function doSearch(p) {
	var query = document.getElementById('base_search').value;
	var nurl = query+p;
	window.location.href = nurl;
}


function goSearch() {
	var query = document.getElementById('searchIndex').value;
	var wurl = window.location.href;
	var pquery = '?';
	if(window.location.search) {
		pquery = '';	
	}
	if(query) {
	var nurl = wurl+pquery+'&search='+query;
	window.location.href = nurl;
	}
}

function get_error_message(message,lang) {
	
	var lang;
	if(!lang) {
		if(document.getElementById('wksp_language')) {
			lang = document.getElementById('wksp_language').value;
		} else {
		lang = document.getElementById('s_user_language').value;
		}
	}
	message = message+'_'+lang;
	switch(message)
    {
	case "logged_in_to_access_en" :
        alert('You must be logged in to have access to this section.');
        break;			
	case "logged_in_to_access_fr" :
        alert('Vous devez ouvrir une session pour accéder à cette section.');
        break;		
		
	case "logged_in_to_comment_en" :
        alert('You must be logged in to post a comment.');
        break;			
	case "logged_in_to_comment_fr" :
        alert('Vous devez avoir ouvert une session pour ajouter un commentaire.');
        break;				
	case "logged_in_to_post_event_en" :
        alert('You must be logged in to add an event.');
        break;			
	case "logged_in_to_post_event_fr" :
        alert('Vous devez avoir ouvert une session pour ajouter un événement.');
        break;				
	case "user_has_already_clicked_en" :
        alert('Operation already in progress and should resume in a few seconds.');
        break;			
	case "user_has_already_clicked_fr" :
        alert('Opération en cours. Veuillez patienter quelques instants.');
        break;		
	case "file_not_saved_yet_fr" :
        alert('Vous devez enregistrer ce document avant de visualiser le fichier.');
        break;	
	case "file_not_saved_yet_en" :
        alert('You must save your document before viewing this file.');
        break;	
    case "too_many_docs_selected_fr" :
        alert('Vous ne pouvez sélectionner qu\'un document pour cette opération.');
        break;
    case "too_many_docs_selected_en" :
        alert('This operation requires you to select only 1 document.');
        break;
	case "no_docs_selected_fr" :
        alert('Vous devez sélectionner au moins un document pour cette opération.');
        break;
    case "no_docs_selected_en" :
        alert('This operation requires you to select at least 1 document.');
        break;
	case "user_not_authorized_en" :
        alert('You are not authorized to access the page you requested.');
        break;		
	case "user_not_authorized_fr" :
        alert('Vous n\'êtes pas autorisé à accéder à la page demandée.');
        break;
	case "not_available_en" :
        alert('Not available at this time.\n Thanks for your patience.');
        break;		
	
	case "not_available_fr" :
        alert('En développement.\n Merci de votre patience.');
        break;		
		
    } //switch
} //function




//Accents
function replaceAccents(c) {

while(c.indexOf(" ") != -1) c = c.replace(" ","+");

while(c.indexOf("à") != -1) c = c.replace("à","a");
while(c.indexOf("â") != -1) c = c.replace("â","a");
while(c.indexOf("ä") != -1) c = c.replace("ä","a");
while(c.indexOf("À") != -1) c = c.replace("À","A");
while(c.indexOf("Â") != -1) c = c.replace("Â","A");
while(c.indexOf("Ä") != -1) c = c.replace("Ä","A");

while(c.indexOf("ç") != -1) c = c.replace("ç","c");
while(c.indexOf("Ç") != -1) c = c.replace("Ç","c");

while(c.indexOf("é") != -1) c = c.replace("é","e");
while(c.indexOf("è") != -1) c = c.replace("è","e");
while(c.indexOf("ê") != -1) c = c.replace("ê","e");
while(c.indexOf("ë") != -1) c = c.replace("ë","e");
while(c.indexOf("É") != -1) c = c.replace("É","E");
while(c.indexOf("Ê") != -1) c = c.replace("Ê","E");


while(c.indexOf("Ë") != -1) c = c.replace("Ë","E");
while(c.indexOf("È") != -1) c = c.replace("È","E");

while(c.indexOf("î") != -1) c = c.replace("î","i");
while(c.indexOf("ï") != -1) c = c.replace("ï","i");
while(c.indexOf("Î") != -1) c = c.replace("Î","i");
while(c.indexOf("Ï") != -1) c = c.replace("Ï","i");

while(c.indexOf("ô") != -1) c = c.replace("ô","o");
while(c.indexOf("ö") != -1) c = c.replace("ö","o");
while(c.indexOf("Ô") != -1) c = c.replace("Ô","O");
while(c.indexOf("Ö") != -1) c = c.replace("Ö","O");

while(c.indexOf("ù") != -1) c = c.replace("ù","u");
while(c.indexOf("ü") != -1) c = c.replace("ü","u");
while(c.indexOf("û") != -1) c = c.replace("û","u");
while(c.indexOf("Ù") != -1) c = c.replace("Ù","U");
while(c.indexOf("Ü") != -1) c = c.replace("Ü","U");
while(c.indexOf("Û") != -1) c = c.replace("Û","U");

return c;
}
