var returnlocation = "/intranet/workspace.php"

function mH(id) {
	
	var m1 = document.getElementById('hm_'+id);
	//var m2 = document.getElementById('hml_'+id);
	var cls = m1.className;
	var cls = cls.slice(cls.lastIndexOf('_')+1,cls.length);
	if(cls) {
			if(cls == "off") 
				{
				m1.className ="h_menu_on";
				//m2.className ="h_menu_hover";
				}
				else {
				m1.className="h_menu_off";				
				//m2.className="h_menu_off";				
				}
	}//if tsect
}

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 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)+5;
	ttop = getTop(inti)+26;
	if(state == "on") {
		hs.className="h_sub_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_sub_off";
	}
}



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

	var	czone = document.getElementById('comment_zone');
	czone.style.visibility = 'visible';
	window.location.href = '#comment';
	document.forms["post_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 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;
}


// Saving and editing document
function doSearch(start) {

	 document.forms[0].start.value = start;
	 document.forms[0].submit();	 
}


function codeSearchRequest(c) {

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

while(c.indexOf("\u00E0") != -1) c = c.replace("\u00E0","%a1;");
while(c.indexOf("\u00E2") != -1) c = c.replace("\u00E2","%a2");
while(c.indexOf("\u00E4") != -1) c = c.replace("\u00E4","%a3");
while(c.indexOf("\u00C0") != -1) c = c.replace("\u00C0","%A11");
while(c.indexOf("\u00C2") != -1) c = c.replace("\u00C2","%A12");
while(c.indexOf("\u00C4") != -1) c = c.replace("\u00C4","%A13");

while(c.indexOf("\u00E7") != -1) c = c.replace("\u00E7","%c1");
while(c.indexOf("\u00C7") != -1) c = c.replace("\u00C7","%C11");

while(c.indexOf("\u00E9") != -1) c = c.replace("\u00E9","%e1");
while(c.indexOf("\u00E8") != -1) c = c.replace("\u00E8","%e2");
while(c.indexOf("\u00EA") != -1) c = c.replace("\u00EA","%e3");
while(c.indexOf("\u00EB") != -1) c = c.replace("\u00EB","%e4");
while(c.indexOf("\u00C9") != -1) c = c.replace("\u00C9","%E11");
while(c.indexOf("\u00CA") != -1) c = c.replace("\u00CA","%E12");


while(c.indexOf("\u00CB") != -1) c = c.replace("\u00CB","%E13");
while(c.indexOf("\u00C8") != -1) c = c.replace("\u00C8","%E14");

while(c.indexOf("\u00EE") != -1) c = c.replace("\u00EE","%i1");
while(c.indexOf("\u00EF") != -1) c = c.replace("\u00EF","%i2");
while(c.indexOf("\u00CE") != -1) c = c.replace("\u00CE","%I11");
while(c.indexOf("\u00CF") != -1) c = c.replace("\u00CF","%I12");

while(c.indexOf("\u00F4") != -1) c = c.replace("\u00F4","%o1");
while(c.indexOf("\u00F6") != -1) c = c.replace("\u00F6","%o2");
while(c.indexOf("\u00D4") != -1) c = c.replace("\u00D4","%O11");
while(c.indexOf("\u00D6") != -1) c = c.replace("\u00D6","%O12");

while(c.indexOf("\u00F9") != -1) c = c.replace("\u00F9","%u1");
while(c.indexOf("\u00FC") != -1) c = c.replace("\u00FC","%u2");
while(c.indexOf("\u00FB") != -1) c = c.replace("\u00FB","%u3");
while(c.indexOf("\u00D9") != -1) c = c.replace("\u00D9","%U11");
while(c.indexOf("\u00DC") != -1) c = c.replace("\u00DC","%U12");
while(c.indexOf("\u00DB") != -1) c = c.replace("\u00DB","%U13");

return c;
}



//Check selected documents in workspace
function voteFor(id,table) {
//Position image

if(id) {
	var v = document.getElementById('postboard_h_vote');
	var p = document.getElementById('v_'+id);
	
	var tid = document.getElementById('vote_item');
	var ttable = document.getElementById('vote_table');
	tid.value = id;
	ttable.value = table;

	tleft = getLeft(p)+200;
	ttop = getTop(p)-70;
	v.style.posLeft=tleft;
	v.style.posTop=ttop;
	v.style.left=tleft;
	v.style.top=ttop;
	v.className = "vote_on";
}//
} // function

//Check selected documents in workspace
function cancelVote() {
//Position image
	var v = document.getElementById('postboard_h_vote');
	
	var id = document.getElementById('vote_item');
	var table = document.getElementById('vote_table');
	id.value = '';
	table.value = '';
	
	v.style.posLeft=-500;
	v.style.posTop=-500;
	v.style.left=-500;
	v.style.top=-500;
	v.className = "vote_off";
} // function

//Check selected documents in workspace
function doVote(url) {
//Position image
	var pid = document.getElementById("pid").value;
	var id = document.getElementById("vote_item").value;
	var table = document.getElementById("vote_table").value;
	var target = url+'#'+id;
	window.location.href = '/surveys/vote.php?pid='+pid+'&id='+id+'&table='+table+'&target='+target;

} // function