var intranet = '/intranet/';
var returnlocation = intranet+"workspace.php";
var workspace = intranet+"workspace.php";

function tMenu(id,state) {
	
	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 displayPageDivs(url) {		
		var u = document.getElementById('current_div_url');
		u.value = url;
		processDocument('101','display');				
}

function updateLayoutZone(block) {
	
	var zone = document.getElementById('zone');
	v = zone.value;
	if(v) {
		var z = document.getElementById(v);
		if(z.value) {
			block = z.value+', '+block;			
		}//if k.value
		z.value = block;		
	} else {
		alert('Vous devez d\'abord sélectionnez une zone en cliquant dessus.');
	}//
}//

function selectLayoutZone(id) {
	
	var zone = document.getElementById(id);
	var cls = zone.className;
	var state = cls.slice(cls.lastIndexOf("_") + 1, (cls.length));
	var z = document.getElementById('zone');
	pz = z.value;
	z.value = id;
	if(state == 'off') {
		zone.className = 'zone_on';
		zone.style.backgroundColor="white";
		zone.style.borderColor="green";
		zone.style.borderStyle="solid";

if(pz) {
			var pzone = document.getElementById(pz);
			pzone.className = 'zone_off';
			pzone.style.backgroundColor="#CCCCCC";			
			pzone.style.borderColor="white";
		}
	} else {
		zone.className = 'zone_off';		
	}//
}//

function displayPageDivs(url) {		
		var u = document.getElementById('current_div_url');
		u.value = url;
		processDocument('101','display');				
}


function displayLayout(l) {
	
	var layout = document.getElementById(l);
	var display = document.getElementById('sp_'+l);
	thislayout = layout.value;
	display.innerHTML = thislayout;
}


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 showNavMenu(id) {
	
	var hs = document.getElementById(id);
	var inti = document.getElementById(id+'-pimg');
	t2 = getLeft(hs);
	tleft = getLeft(inti)-140;
	ttop = getTop(inti)+21;
	var state = hs.className;
	if(state == "off") {
		inti.src = '/ressources/modules/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/off.png';
		hs.style.posLeft=-500;
		hs.style.posTop=-500;
		hs.style.left=-500;
		hs.style.top=-500;
		hs.className="off";
	}
}

function showNavSubMenu(id,s) {
	
	var subm = document.getElementById('nm_1_'+id);
	var nm = document.getElementById('nm_div_2_'+id);
	if(!s) {
		var cls = subm.className;
		var state = cls.slice(cls.lastIndexOf("_") + 1, (cls.length));
	} else {
		state = s;	
	}
	if(state == "off") {
		subm.className="nav-menu_level_1_on";
		nm.className="on";
	} else if(state== "on") {
		subm.className="nav-menu_level_1_off";
		nm.className="off";
	}
}

function mvOnClick(id) {
	
	var v1 = document.getElementById('nm_1_'+id);
	var v2 = document.getElementById('nm_div_2_'+id);
	var cls = v1.className;
	var cls = cls.slice(cls.lastIndexOf("_") + 1, (cls.length));
	if(cls == "off") {
				v1.className ="1_on";
				v2.className  = "2_on";
		}
				else {
				v1.className ="1_off";
				v2.className  = "2_off";
		}//if class != on
}



function selectSid(sid) {
	var w = window.document.location;
	window.document.location = window.location.pathname+'?sid='+sid;
}



// Saving and editing document
function submit(form) {
	
	if(form) {
		document.forms[form].submit();
	}
}


function refreshDocument(field) {		
		var f = document.getElementById('anchor');
		f.value = field;
		processDocument('9','refresh');				
}	

function showWebPageSection(show,id) {
	if(show == 0) {
		var sect = document.getElementById(id);
		sect.className = 'on';	
		var sect = document.getElementById('mainsection');
		sect.className = 'off';	
	}
	if(show == 1) {
		var sect = document.getElementById(id);
		sect.className = 'off';	
		var sect = document.getElementById('mainsection');
		sect.className = 'on';	
	}//
}

function showDiv(id) {
	
	var div = document.getElementById(id);

	if(div.className == 'on') {
		div.className = 'off';	
	} else {
		div.className = 'on';	
	}//
}

function showProjectParticipants(level) {
	var sect = document.getElementById('project_participants');

	if(level == 2 && sect) {
		sect.className = 'on';	
	} else {
		sect.className = 'off';			
	}
}


function printableVersion() {
	
		alert('In preparation / En préparation');	
}


function update_d_title(title) {
		var d_title = document.getElementById('d_title');
		if(d_title) {
			if(title != "") {
				d_title.innerHTML = title;
			} else 
				d_title.innerHTML = "&nbsp;";
			}
}

function updateEventField(f_value,dest_f) {
	/*
	if(f_value) {    case "confirm_archive_deletion_en" :
        return 'Selected archive will be deleted. Do you wish to continue.';
        break;
    case "confirm_directory_deletion_en" :
        return 'Selected directory and all directory files will be deleted. Do you wish to continue.';
        break;

		var dest_field = document.getElementById(dest_f);
		if(dest_field.value == "" || dest_field.value == null) {
			alert(f_value);
			dest_field.options[f_value].selected = true;
		}
	}//if f_value
	*/
	return true;

}

function addToKeywords(key,key_field) {
	//var keywords = document.getElementById('keywords');
	var kk= document.forms[0].elements['keywords'].value;
	var tt = '';
			if(kk) {
				tt = kk+', '+key;			
			} else {
				tt = key;						
			}//if k.value
	document.forms[0].elements['keywords'].value = tt;
}

function addToWorkgroupMembers(member) {
	var smembers = document.getElementById('shown_members');
	if(smembers) {
		if(smembers.value) {
			smembers.value = smembers.value+', '+member;			
		} else {
			smembers.value = member;						
		}//if recipients.value
	}//if recipients
}

function addToRecipients(recipient,wfield) {
	var recipients = document.getElementById(wfield);
	if(recipients) {
		if(recipients.value) {
			recipients.value = recipients.value+', '+recipient;			
		} else {
			recipients.value = recipient;						
		}//if recipients.value
	}//if recipients
}

function appendFilesToMessage(file) {
	var sp_files = document.getElementById('sp_attached_files');
	var nFile = '';
	file = file+'&end';
	if(sp_files) {
			var furl = file.slice(file.indexOf("f_url=") + 6, (file.indexOf("&filename=")));
			var fext = file.slice(file.indexOf("extension=") + 10, (file.indexOf("&end")));
			var fname = file.slice(file.indexOf("filename=") + 9, (file.indexOf("&extension=")));	
			if(furl) {
				nFile = '<img src="/ressources/icons/ic_'+fext+'.gif" style="padding-right:6px;">';	
				nFile = nFile+'<a href="javascript:popShowFile(\''+furl+'\');" class="qmenu_small">';	
				nFile = nFile+fname+'</a><br>';	
				sp_files.innerHTML = sp_files.innerHTML+nFile;
				var fclear = document.getElementById('sp_files_clear');
				fclear.className = 'on';
				//append to attached_files field
				var a_files = document.getElementById('attached_files');
				if(a_files.value) {
					a_files.value = a_files.value+','+file;
					} else {						
					a_files.value = file;
					}

			}
	}//if sp_files
}


function popShowFile(url) {
	
	var w = window.open(url,"","width=600,height=400, toolbar=0, addressbar=0, directories=0, location=0, menubar=0, resizable=0,scrollbars=0,status=0,left=1,top=1");
	w.window.focus();

}

function clearAttachedFiles() {
		
	var sp_files = document.getElementById('sp_attached_files');
	sp_files.innerHTML = '';
	var a_files = document.getElementById('attached_files');
	a_files.value = '';
	var fclear = document.getElementById('sp_files_clear');
	fclear.className = 'off';

	
	
}

function addFilesToMessage(file) {
	var t_files = document.getElementById('attached_files');
	if(t_files) {
		if(t_files.value) {
			t_files.value = t_files.value+', '+file;			
		} else {
			t_files.value = file;						
		}//if recipients.value
	}//if recipients
}
function close_qmenu() {
	var div = window.parent.document.getElementById('qmenu_window');
	div.className = 'qmenu_off';
	div.style.height = 0;
	var ifr = window.parent.document.getElementById('qmenu_iframe');
	ifr.style.height = 0;
	ifr.src = '';
}

function close_wcomment() {
	var wid = document.getElementById('workgroup_id').value;
	window.close();
	window.opener.document.location = '/intranet/workgroups.php?workgroup='+wid+'&show=workgroup_discussion';
}

function newBlankWindow() {
	
	var w = window.open('about:blank',"","width=800,height=600, toolbar=1, addressbar=1, directories=1, location=1, menubar=1, resizable=1,scrollbars=1,status=1,left=1,top=1");
	w.window.focus();

}

function googleSearch(lang) {
	var ug = 'http://www.google.ca/webhp?hl=en';
	if(lang == 'fr') {
		ug = 'http://www.google.ca/webhp?hl=fr';	
	}
	var w = window.open(ug,"","width=800,height=500, toolbar=1, addressbar=1, directories=1, location=1, menubar=1, resizable=1,scrollbars=1,status=1,left=1,top=1");
	w.window.focus();

}


function quickMenu(service,destination) {
	var div = document.getElementById('qmenu_window');

if(div.className == 'qmenu_off') {
		div.className = 'qmenu_on';
		div.style.height = 480;
		var ifr = document.getElementById('qmenu_iframe');
		ifr.style.height = 455;
		ifr.src = destination;
	} else {
		div.className = 'qmenu_off';
		div.style.height = 0;
		var ifr = document.getElementById('qmenu_iframe');
		ifr.style.height = 0;
		ifr.src = '';
	}
	
}

function showSPMenus(id) {
	var sect = document.getElementById("sp_sect_"+id);
	var simg = document.getElementById("sp_img_"+id);
	var sc = sect.className;
	if(sc == 'on') {
		simg.src = "/ressources/startingpage/on.gif";
		sect.className = "off";
	} else {	
		simg.src = "/ressources/startingpage/off.gif";
		sect.className = "on";
	} //if
}

function showWorkgroupsTabs(tab,baseurl) {
	var div0 = document.getElementById('workgroup_presentation');
	if(div0) {div0.className = 'off';}
	var tab0 = document.getElementById('wkgp_tab_presentation');
	if(tab0) {tab0.className = 'workgroup_menu_off';}

	var div1 = document.getElementById('workgroup_discussion');
	if(div1) {div1.className = 'off';}
	var tab1 = document.getElementById('wkgp_tab_discussion');
	if(tab1) {tab1.className = 'workgroup_menu_off';}

	var div2 = document.getElementById('workgroup_tasks');
	if(div2) {div2.className = 'off';}
	var tab2 = document.getElementById('wkgp_tab_tasks');
	if(tab2) {tab2.className = 'workgroup_menu_off';}

	var div3 = document.getElementById('workgroup_files');
	if(div3) {div3.className = 'off';}
	var tab3 = document.getElementById('wkgp_tab_files');
	if(tab3) {tab3.className = 'workgroup_menu_off';}

	var div3 = document.getElementById('workgroup_participants');
	if(div3) {div3.className = 'off';}
	var tab3 = document.getElementById('wkgp_tab_participants');
	if(tab3) {tab3.className = 'workgroup_menu_off';}


	var div = document.getElementById('workgroup_'+tab);
	if(div) {div.className = 'on';} //if

	var tab = document.getElementById('wkgp_tab_'+tab);
	if(tab) {tab.className = 'workgroup_menu_on';} //if

}

function showWorkspaceMenu(tab,bgcolor) {

	var div = document.getElementById(tab);
	var sp = document.getElementById('sp_'+tab);

	var divc = div.className;

	var div0 = document.getElementById('wn_news');
	if(div0) {div0.className = 'off';}
	var sp0 = document.getElementById('sp_wn_news');
	if(sp0) {sp0.innerHTML = '[+]';}

	var div1 = document.getElementById('wn_commun_news');
	if(div1) {div1.className = 'off';}
	var sp1 = document.getElementById('sp_wn_commun_news');
	if(sp1) {sp1.innerHTML = '[+]';}

	var div2 = document.getElementById('wn_intl_news');
	if(div2) {div2.className = 'off';}
	var sp2 = document.getElementById('sp_wn_intl_news');
	if(sp2) {sp2.innerHTML = '[+]';}

	if(divc == 'on') {
		div.className = 'off';
		if(sp) sp.innerHTML = '[+]'; 
		} else { 
			div.className = 'on';
			if(sp) sp.innerHTML = '[-]';
		}

	var colorbar = document.getElementById('wn_color_bar');
	if(colorbar) {colorbar.style.backgroundColor = bgcolor;} //if

}


function showWorkgroupComment() {
	var cz = document.getElementById("comment_zone");
	if(cz) {
		cz.className = "on";
	} //if
}

function wks_central(id,bgcolor) {
	
	var central_span = document.getElementById('central_span');
	var thisspan = document.getElementById('central_'+id);
	var central_block = document.getElementById('tcentral_block');
	if(thisspan) {
		central_span.innerHTML = thisspan.innerHTML;		
	}
	if(central_block) {
		central_block.style.backgroundImage = 'url("/ressources/workspace/'+bgcolor+'_bck.jpg")';				
	}
}


function goNextPage(actualurl) {
	
	var doclimit = document.getElementById('wksp_docs_limit').value;
	var gothispage = document.getElementById('gothispage').value;	
	var currentpage = document.getElementById('s_current_page').value;	
	var allpages = document.getElementById('s_pages').value;
	var selpage = parseInt(gothispage);
	if(currentpage != 1) {
		selpage = selpage+1;	
	}
	var pstart = 1; 
	if(parseInt(gothispage) != parseInt(currentpage)) {
		selpage = parseInt(gothispage);
	}

	if(selpage <= allpages) {
		pstart = (selpage*parseInt(doclimit))+1;

		window.location.href=actualurl+pstart;
		}

}

function goPreviousPage(actualurl) {
	
	var doclimit = document.getElementById('view_docs_limit').value;
	var gothispage = document.getElementById('gothispage').value;	
	var currentpage = document.getElementById('s_current_page').value;	
	var allpages = document.getElementById('s_pages').value;
	var selpage = parseInt(gothispage)-1; 
	var pstart = 1; 
	if(parseInt(gothispage) != parseInt(currentpage)) {
		selpage = parseInt(gothispage);
	}
	
	if(selpage >= 1) {
		pstart = (selpage*parseInt(doclimit))+1;	
		if(selpage == 1) {
			pstart = 1;	
		}
		window.location.href=actualurl+pstart;
		}

}

function goNextPage_v2(a) {
	
	var doclimit = document.getElementById('view_docs_limit').value;
	var gothispage = document.getElementById('gothispage').value;	
	var currentpage = document.getElementById('s_current_page').value;	
	var allpages = document.getElementById('s_pages').value;
	var selpage = parseInt(gothispage);
	if(currentpage != 1) {
		selpage = selpage+1;	
	}
	var pstart = 1; 
	if(parseInt(gothispage) != parseInt(currentpage)) {
		selpage = parseInt(gothispage);
	}

	if(selpage <= allpages) {
		pstart = (selpage*parseInt(doclimit))+1;	
		var a1 = a.slice(0,a.indexOf('start=')+6);
		var a2 = a.slice(a.indexOf('&rows='));
		newa = a1+pstart+a2;
		window.location.href=newa;
		}

}

function goPreviousPage_v2(a) {
	
	var doclimit = document.getElementById('view_docs_limit').value;
	var gothispage = document.getElementById('gothispage').value;	
	var currentpage = document.getElementById('s_current_page').value;	
	var allpages = document.getElementById('s_pages').value;
	var selpage = parseInt(gothispage)-1; 
	var pstart = 1; 
	if(parseInt(gothispage) != parseInt(currentpage)) {
		selpage = parseInt(gothispage);
	}
	
	if(selpage >= 1) {
		pstart = (selpage*parseInt(doclimit))+1;	
		if(selpage == 1) {
			pstart = 1;	
		}
		var a1 = a.slice(0,a.indexOf('start=')+6);
		var a2 = a.slice(a.indexOf('&rows='));
		newa = a1+pstart+a2;
		window.location.href=newa;
		}

}

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 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 == "on") 
			{
			m1.className ="h_menu_off";
			m2.className ="h_menu_off";
			}
			else {
			m1.className="h_menu_on";				
			m2.className="h_menu_on";				
			}
	}//if tsect
}

//Check selected documents in workspace
function add_blog_entry() {
var docs;
var fld;
var sdocs;
sdocs = "";
var table;
var dv;
//Prevent clicking more than once
var selcptr;
selcptr = 0;
docs = document.getElementById('wksp_docs_number').value;
var idd;
for (i=1;i<=docs;i++) {
		idd = 'wksp_docs_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+'@';
			selcptr++;
		}//if document
	} // for
		if(sdocs != "") {
			if(selcptr == 1) { 
				table = document.getElementById('wksp_table_reference').value;
				//strip ending @
				sdocs = sdocs.substring(0, (sdocs.length)-1);
				wsendto = '/blogs/public_post.php?blog='+sdocs;
				window.location.href = wsendto;
			} 
			else 
			{
				get_error_message('too_many_docs_selected');
			} // selcptr == 1		
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function


function checkAll(wfield) {
if(wfield) {
var docs = document.getElementById(wfield).value;
} else {
var docs = document.getElementById('wksp_docs_number').value;	
}
var all_c = document.getElementById('all_checked').value;

var suff = 'wksp_docs';
if(wfield) suff = wfield;

var idd;
for (i=1;i<=docs;i++) {
		idd = suff+'_'+i;
		if(all_c == "0") {
		document.getElementById(idd).checked=true; }
		else {
		document.getElementById(idd).checked=false;	
		}
	} // for		
		if(all_c == 0) {
			document.getElementById('all_checked').value = "1"; }
			else {
			document.getElementById('all_checked').value = "0"; }
}

function hide_window(toclose) {
	
	document.getElementById(toclose).style.visibility = 'hidden';	
	document.getElementById(toclose).style.top = -500;	
	document.getElementById(toclose).style.left = -500;	
	
}

function get_email_addresses(wfield) {
var suff = 'wksp_docs';
if(wfield) suff = wfield;

var docs;
var sdocs;
sdocs = "";
var dv;
//Prevent clicking more than once
var selcptr;
selcptr = 0;
if(wfield) {
docs = document.getElementById(suff).value;
} else {
docs = document.getElementById('wksp_docs_number').value;
}

var idd;
for (i=1;i<=docs;i++) {
		idd = suff+'_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+', ';
			selcptr++;
		}//if document
	} // for
		if(sdocs != "") {
				sdocs = sdocs.substring(0, (sdocs.length)-2);
				var	email_span = document.getElementById('copy_mail');
				email_span.style.top = 275;
				email_span.style.left = 300;
				email_span.style.visibility = 'visible';
				var email_area = document.getElementById('copy_mail_area');
				email_area.value = sdocs;
				document.forms["show_mail"].elements["copy_mail_area"].focus();
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function


//Check selected documents in workspace
function copy_into_new_document() {
var docs;
var fld;
var sdocs;
sdocs = "";
var table;
var dv;
//Prevent clicking more than once
var selcptr;
selcptr = 0;
docs = document.getElementById('wksp_docs_number').value;
var view_url = '';
if(document.getElementById('wksp_view_url')) {
	view_url = document.getElementById('wksp_view_url').value;
}
var idd;
for (i=1;i<=docs;i++) {
		idd = 'wksp_docs_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+'@';
			selcptr++;
		}//if document
	} // for
		if(sdocs != "") {
			if(selcptr == 1) { 
				table = document.getElementById('wksp_table_reference').value;
				//strip ending @
				sdocs = sdocs.substring(0, (sdocs.length)-1);
				wsendto = '/intranet/tools/copy_into_new_document.php?table='+table+'&id='+sdocs+'&view_url='+view_url;
				window.location.href = wsendto;
			} 
			else 
			{
				get_error_message('too_many_docs_selected');
			} // selcptr == 1		
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function


//Check selected documents in workspace
function workspace_preview_document(baseurl) {
var docs;
var fld;
var sdocs;
sdocs = "";
var table;
var dv;
var selcptr;
selcptr = 0;
docs = document.getElementById('wksp_docs_number').value;
var idd;
for (i=1;i<=docs;i++) {
		idd = 'wksp_docs_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+'@';
			selcptr++;
		}//if document
	} // for
		if(sdocs != "") {
			if(selcptr == 1) { 
				//strip ending @
				sdocs = sdocs.substring(0,(sdocs.length)-1);
				wsendto = baseurl+sdocs;
				window.location.href = wsendto;
			} 
			else 
			{
				get_error_message('too_many_docs_selected');
			} // selcptr == 1		
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function


//Check selected documents in workspace
function delete_selected_docs_with_return(return_page) {
var docs;
var fld;
var sdocs;
sdocs = "";
var table;
var dv;
docs = document.getElementById('wksp_docs_number').value;
var idd;
for (i=1;i<=docs;i++) {
		idd = 'wksp_docs_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+'@';
		}//if document
	} // for
		if(sdocs != "") {
				table = document.getElementById('wksp_table_reference').value;
				//strip ending @
				sdocs = sdocs.substring(0, (sdocs.length)-1);
				if(return_page) {
					wsendto = '/intranet/tools/delete_selected_documents.php?table='+table+'&id='+sdocs+'&return='+return_page;					
				}
				if(confirm(showMessages('confirm_deletion'))) { 
						//alert(wsendto);
						window.location.href = wsendto;
						} 
						else 
						{
						alert(showMessages('operation_cancelled'));
						 }//if confirm
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function


//Check selected documents in workspace
function delete_selected_docs(destination) {
var docs;
var fld;
var sdocs;
sdocs = "";
var table;
var dv;
docs = document.getElementById('wksp_docs_number').value;
var idd;
for (i=1;i<=docs;i++) {
		idd = 'wksp_docs_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+'@';
		}//if document
	} // for
		if(sdocs != "") {
				table = document.getElementById('wksp_table_reference').value;
				//strip ending @
				sdocs = sdocs.substring(0, (sdocs.length)-1);
				if(destination) {
					wsendto = destination+'?table='+table+'&id='+sdocs;
				} else {
					wsendto = '/intranet/tools/delete_selected_documents.php?table='+table+'&id='+sdocs;					
				}
				if(confirm(showMessages('confirm_deletion'))) { 
						window.location.href = wsendto;
						} 
						else 
						{
						alert(showMessages('operation_cancelled'));
						 }//if confirm
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function

//Check selected documents in workspace
function delete_selected_docs_v2(destination) {
var docs;
var fld;
var sdocs;
sdocs = "";
var table;
var dv;
view_url = document.getElementById('view_url').value;
docs = document.getElementById('wksp_docs_number').value;
var idd;
for (i=1;i<=docs;i++) {
		idd = 'wksp_docs_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+'@';
		}//if document
	} // for
		if(sdocs != "") {
				table = document.getElementById('wksp_table_reference').value;
				//strip ending @
				sdocs = sdocs.substring(0, (sdocs.length)-1);
				if(destination) {
					wsendto = destination+'?view_url='+view_url+'&id='+sdocs;
				} else {
					wsendto = '/intranet/tools/delete_selected_documents_v2.php?view_url='+view_url+'&id='+sdocs;					
				}
				if(confirm(showMessages('confirm_deletion'))) { 
						window.location.href = wsendto;
						} 
						else 
						{
						alert(showMessages('operation_cancelled'));
						 }//if confirm
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function


//Check selected documents in workspace
function delete_larche_docs(destination) {
var docs;
var fld;
var sdocs;
sdocs = "";
var table;
var dv;
docs = document.getElementById('wksp_docs_number').value;
var idd;
for (i=1;i<=docs;i++) {
		idd = 'wksp_docs_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+'@';
		}//if document
	} // for
		if(sdocs != "") {
				table = document.getElementById('wksp_table_reference').value;
				//strip ending @
				sdocs = sdocs.substring(0, (sdocs.length)-1);
				if(destination) {
					wsendto = destination+'?table='+table+'&id='+sdocs;
				} else {
					wsendto = '/intranet/tools/delete_larche_documents.php?table='+table+'&id='+sdocs;					
				}
				if(confirm(showMessages('confirm_deletion'))) { 
						window.location.href = wsendto;
						} 
						else 
						{
						alert(showMessages('operation_cancelled'));
						 }//if confirm
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function

//Check selected documents in workspace
function delete_workgroup_docs() {
var docs;
var fld;
var sdocs;
sdocs = "";
var table;
var dv;
docs = document.getElementById('wksp_docs_number').value;
var idd;
for (i=1;i<=docs;i++) {
		idd = 'wksp_docs_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+'@';
		}//if document
	} // for
		if(sdocs != "") {
				table = document.getElementById('wksp_table_reference').value;
				//strip ending @
				sdocs = sdocs.substring(0, (sdocs.length)-1);
				wsendto = '/intranet/tools/delete_workgroup_docs.php?table='+table+'&id='+sdocs;					
				if(confirm(showMessages('confirm_deletion'))) { 
						window.location.href = wsendto;
						} 
						else 
						{
						alert(showMessages('operation_cancelled'));
						 }//if confirm
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function


//Check selected documents in workspace
function mark_as_completed() {
var docs;
var fld;
var sdocs;
sdocs = "";
var table;
var dv;
docs = document.getElementById('wksp_docs_number').value;
var idd;
for (i=1;i<=docs;i++) {
		idd = 'wksp_docs_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+'@';
		}//if document
	} // for
		if(sdocs != "") {
				table = document.getElementById('wksp_table_reference').value;
				//strip ending @
				sdocs = sdocs.substring(0, (sdocs.length)-1);
				wsendto = '/intranet/tools/mark_as_completed.php?table='+table+'&id='+sdocs;
						window.location.href = wsendto;
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function





//Has to be revised
function delete_selected_user() {
alert('DOCS'+docs);
var docs;
var fld;
var sdocs;
sdocs = "";
var table;
var dv;
docs = document.getElementById('wksp_docs_number').value;
var idd;
for (i=1;i<=docs;i++) {
		idd = 'wksp_docs_'+i;
		if(document.getElementById(idd).checked==true) {
			dv = document.getElementById(idd).value;
			sdocs = sdocs+dv+'@';
		}//if document
	} // for
		if(sdocs != "") {
				table = document.getElementById('wksp_table_reference').value;
				//strip ending @
				sdocs = sdocs.substring(0, (sdocs.length)-1);
				wsendto = '/intranet/tools/delete_selected_user.php?id='+sdocs;
				if(confirm(showMessages('confirm_deletion'))) { 
						window.location.href = wsendto;
						} 
						else 
						{
						alert(showMessages('operation_cancelled'));
						 }//if confirm
		}//if sdocs
		else
		{
		get_error_message('no_docs_selected');
		}
} // function




function access_show_restricted(fieldvalue) {
	
		return true;	
	
}

function doc_is_being_edited() {
	
		document.getElementById('has_document_being_edited').value == 1;	
	
}


function get_error_message(message) {

	
	var 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 "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 "no_archive_selected_fr" :
        alert('Vous devez sélectionner au moins un document d\'archive.');
        break;
    case "no_archive_selected_en" :
        alert('No archive has been selected.');
        break;
	case "no_dir_selected_fr" :
        alert('Vous devez sélectionner au moins un répertoire pour cette opération.');
        break;
    case "no_dir_selected_en" :
        alert('This operation requires you to select at least 1 directory.');
        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.\nThank for your patience.');
        break;			
	case "not_available_fr" :
        alert('En développement.\nMerci de votre patience.');
        break;		
		
    } //switch
} //function


function showMessages(message) {
	
	var 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 "confirm_save_before_printing_en" :
        return 'If you have made changes to this document, you must save it before printing.';
        break;
   case "confirm_save_before_printing_fr" :
        return 'Si vous avez effectué des changements à ce document, vous devez les enregistrer avant d\'imprimer.';
        break;
   case "confirm_w_topic_deletion_en" :
        return 'Selected directory and all directory files will be deleted. Do you wish to continue.';
        break;
	case "confirm_archive_deletion_en" :
        return 'Selected archive will be deleted. Do you wish to continue.';
        break;
    case "confirm_directory_deletion_en" :
        return 'Selected directory and all directory files will be deleted. Do you wish to continue.';
        break;
	case "confirm_deletion_en" :
        return 'Selected documents will be deleted. Do you wish to continue.';
        break;
	case "confirm_document_not_saved_yet_en" :
        return 'This document has not been saved. Do you wish to continue.';
        break;
	case "confirm_document_not_saved_yet_fr" :
        return 'Ce document n\'a pas encore été enregistré.\n Souhaitez-vous continuer ?';
        break;
	case "confirm_deletion_fr" :
        return 'Les documents sélectionnés vont être supprimés. Souhaitez-vous continuer?';
        break;
	case "confirm_archive_deletion_fr" :
        return 'L\'archive sélectionnée va être supprimée. Souhaitez-vous continuer?';
        break;
	case "confirm_directory_deletion_fr" :
        return 'Le dossier ainsi que tous les fichiers et sous-dossiers \nvont être supprimés. Souhaitez-vous continuer?';
        break;
	case "confirm_w_topic_deletion_fr" :
        return 'Le dossier ainsi que tous les fichiers et sous-dossiers \nvont être supprimés. Souhaitez-vous continuer?';
        break;
case "operation_cancelled_en" :
        return 'Requested operation has been cancelled.';
        break;
	case "operation_cancelled_fr" :
        return 'L\'opération a été annulée.';
        break;
	case "enter_directory_title_en" :
        return 'Enter folder title.';
        break;
	case "enter_directory_title_fr" :
        return 'Entrez le titre du dossier.';
        break;		
	case "enter_topic_title_en" :
        return 'Enter topic title.';
        break;
	case "enter_topic_title_fr" :
        return 'Entrez le titre du sujet.';
        break;		
    } //switch
} //function

function replace_file(status,shownstatus) {
		var docid = document.getElementById('idpermanent').value;	
		var nurl = "/files/replace_file.php?id="+docid;
		window.location.href = nurl; 
	}

function replace_private_file(status,shownstatus) {
		var docid = document.getElementById('idpermanent').value;	
		var nurl = "/private/replace_private_file.php?id="+docid;
		window.location.href = nurl; 
	}

function replace_user_file(status,shownstatus) {
		var docid = document.getElementById('idpermanent').value;	
		var nurl = "/users/replace_user_file.php?id="+docid;
		window.location.href = nurl; 
	}

function replace_workgroup_file(status,shownstatus) {
		var docid = document.getElementById('idpermanent').value;	
		var nurl = "/workgroups/replace_workgroup_file.php?id="+docid;
		window.location.href = nurl; 
	}
	
function replace_image(status,shownstatus) {
	
		docid = document.getElementById('idpermanent').value;
		window.location.href = "/images/replace_image.php?id="+docid;
	}

function community_replace_image(status,shownstatus) {
	
		docid = document.getElementById('idpermanent').value;
		window.location.href = "/community/replace_image.php?id="+docid;
}
function regional_replace_image(status,shownstatus) {
	
		docid = document.getElementById('idpermanent').value;
		window.location.href = "/regional/replace_image.php?id="+docid;
}
function national_replace_image(status,shownstatus) {
	
		docid = document.getElementById('idpermanent').value;
		window.location.href = "/national/replace_image.php?id="+docid;
}
function federation_replace_image(status,shownstatus) {
	
		docid = document.getElementById('idpermanent').value;
		window.location.href = "/federation/replace_image.php?id="+docid;
}



function larche_replace_image(status,shownstatus) {
	
		docid = document.getElementById('idpermanent').value;
		window.location.href = "/larche/lca_replace_image.php?id="+docid;
	}

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

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

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

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

function PopFile(doc)
{
var u = doc;
var w = window.open(u,"","width=600,height=500, toolbar=0, addressbar=0, directories=0, location=0, menubar=0, resizable=1,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();
}

// Saving and editing document
function processDocument(statusnum,statustxt) {

	 var clicks = document.getElementById('user_has_clicked').value;
	 if(clicks == '0') {
	 document.getElementById('user_has_clicked').value == 1;	
	 document.forms[0].status.value = statusnum;
	 document.forms[0].shownstatus.value = statustxt;
	 document.forms[0].submit();
	 }
		else {
		return get_error_message('user_has_already_clicked');
	}
	 
}

// Saving and editing document
function processComment(statusnum) {
	
	// var c_status = document.getElementById('comment_status');
	// c_status.value = statusnum;
	// document.forms['post_comment'].submit();	 
}



function cancel(id,status) {
	 var table = document.getElementById('s_table').value;
	 if(table) {
	 window.location.href = returnlocation+'?type='+table;
	 } else {
	 window.location.href = returnlocation;
	 }
}


function document_cancel(id,status) {
	 var referer_url = '';
	 var return_page = document.getElementById('s_return_page').value;
	 var table = document.getElementById('s_table').value;
	 var s_wks_url = "";
	 if(document.getElementById('referer_url')) {
	 var referer_url = document.getElementById('referer_url').value;
	 }

	if(return_page == '' || return_page == null) {
	var r_page = workspace;
	} else {
	var r_page = intranet+return_page;		
	}
	if(table) {
		if(r_page.indexOf("?")) {
			nurl = r_page;
		} else {
			nurl = r_page+'?type='+table;
		}
	}
	if(referer_url) nurl=referer_url;
	//if(s_wks_url) nurl = return_page+'?'+s_wks_url;
		
	if(confirm(showMessages('confirm_document_not_saved_yet'))) 
					{ 
					window.location.href = nurl;
					}
}

function module_cancel(id,status) {
	 var return_page = document.getElementById('s_return_page').value;
	 var site = document.getElementById('site').value;

	if(return_page == '' || return_page == null) {
		var nurl = '/live/module.php?m=website';
		if(site) nurl = nurl+"&sid="+site;
		} else {
		var nurl = return_page;		
	}	
	var nurl = '/live/module.php?m=website';
	if(site) nurl = nurl+"&sid="+site;
	if(confirm(showMessages('confirm_document_not_saved_yet'))) 
		{ 
			window.location.href = nurl;
		}
}//

function cancel_workgroup_task(id,status) {
	var wid = document.getElementById('wksp_workgroup_id').value;
	if(wid) {
	nurl = '/intranet/workgroups.php?workgroup='+wid+'&show=workgroup_tasks';
	} else {
	nurl = '/intranet/workgroups.php';		
	}
		
	if(confirm(showMessages('confirm_document_not_saved_yet'))) 
					{ 
					window.location.href = nurl;
					}
}

function cancel_workgroup_file(id,status) {
	var wid = document.getElementById('wksp_workgroup_id').value;
	if(wid) {
	nurl = '/intranet/workgroup_files.php?workgroup='+wid;
	} else {
	nurl = '/intranet/workgroups.php';		
	}
		
	if(confirm(showMessages('confirm_document_not_saved_yet'))) 
					{ 
					window.location.href = nurl;
					}
}
function goSelectedPage(url) {
	if(url) {
	 window.location.href = url;
	}
}

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

function reloadPage() {
	 window.reload();
}

function showSectionX(id) {
	
	var tsect = document.getElementById(id);
	var msect = document.getElementById('lpm_'+id);
	if(tsect) {
		if(tsect.className == "on") 
			{
			tsect.className ="off";
			msect.className ="left-pane-section_off";
			}
			else {
			tsect.className="on";				
			msect.className ="left-pane-section_on";
			}
	}//if tsect
}

function showSection(id) {
	
	var tsect = document.getElementById(id);
	var msect = document.getElementById('lpm_'+id);
	var tblsect = document.getElementById('lpm_t_'+id);
	var ssections = document.getElementById('lpm_shown_sections');
	//var lpm = new Array();
	//lpm = explode(ssections.value,',');
	//alert('Longueur:'+lpm.length()));

	if(tsect) {
		if(tsect.className == "section_on") 
			{
			tsect.className ="section_off";
			msect.className ="left-pane-section_off";
			tblsect.className ="t_section_off";
			}
			else {
			tsect.className="section_on";				
			msect.className ="left-pane-section_on";
			tblsect.className ="t_section_on";

			}
	}//if tsect
}

function mh1(id, etat) {
	
	var cemh = document.getElementById('mh1_' + id);
	var cls = cemh.className;
	var cls = cls.slice(cls.lastIndexOf("_") + 1, (cls.length));
	if(cls != 'on') {
	cemh.className = 'mh1_' + etat;
	}
}

function mh2(id, etat) {
	
	var cemh = document.getElementById(id);
	var cls = cemh.className;
	var cls = cls.slice(cls.lastIndexOf("_") + 1, (cls.length));
	if(cls != 'on') {
	cemh.className = 'mh_ss_' + etat;
	}
}



/* IMAGES */
function show_selected_image(img) {
if (img.length > 5) {
document.images.doc_icon.src = img;
document.images.doc_icon.visibility = "visible";
}
else {
document.images.doc_icon.src = '/ressources/e.gif';	
document.images.doc_icon.visibility = "hidden";

return(null);
}
}

function selected_image(id,format) {
	if(!format) {format = 'large';}
	if(id) {
	window.parent.document.getElementById('txtUrl').value= '/images/show_image.php?id='+id+'&format='+format;
	window.parent.UpdatePreview();
	}
}

function selected_image_by_url(img_url) {
	if(img_url) {
		window.parent.document.getElementById('txtUrl').value= img_url;
		window.parent.UpdatePreview();
	}
}

function selected_link(url) {
	if(url) {
	window.parent.document.getElementById('txtUrl').value= url;
	}
}	

function pop_selected_link(title,url,filetype) {
	if(url) {
	window.parent.document.getElementById('txtUrl').value= title;
	var docinfo = 'title@'+title+'%url@'+url+'%filetype@'+filetype;
	window.parent.document.getElementById('linkInfo').value= docinfo;
	}
}	

function pop_selected_link_ok() {
	var ws = window.location.href;
	var field_1 = ws.slice(ws.indexOf('field_1=') +8,ws.indexOf('&field_2='));
	var field_2 = ws.slice(ws.indexOf('field_2=') +8,(ws.length));
	var doctitle = document.getElementById('txtUrl').value;
	if(field_1.length > 1) {
	var f1 = window.opener.document.getElementById(field_1);
	f1.value = doctitle;
	}
	if(field_2.length > 2) {
	var f2 = window.opener.document.getElementById(field_2);
	var docinfo = document.getElementById('linkInfo').value;
	f2.value= docinfo;
	}
	window.close();
}	


function pop_add_image() {
	var uA = navigator.userAgent;
	var gurl = "http://larchecommons.ca/images/pop_add_image.php";
	var ieurl = "http://larchecommons.ca/images/ie_pop_add_image.php";

	if(uA.indexOf('Gecko') > 0) {
		var gurl = "http://larchecommons.ca/images/pop_add_image.php";
		window.parent.location.href = gurl;
	} else {
		PopIEImage(ieurl);
	}
}

function report_image(status,shownstatus) {
		var thisUrl = document.getElementById('image_id').value;
		if(window.opener) {
			var txtUrl = window.opener.document.getElementById('txtUrl');
			txtUrl.value = thisUrl;
			window.opener.UpdatePreview();
		}
		window.close();
}

function pop_add_link() {
	var uA = navigator.userAgent;
	var nurl = '/users/pop_add_user_file.php';
	if(uA.indexOf('Gecko') > 0) {
		window.location.href = nurl;
		} else {
		alert('Not available yet for IExplorer navigators. We\'re trying to fix the bug.');
	}
}


function goIndexMenu(table) {
	if(table) {
	var nurl = '/links/create_link.php?table='+table;
	window.location.href = nurl;
	}
}

function goSearchIndex() {
	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 goIframeSearchIndex() {
	var query = document.getElementById('searchIndex').value;
	var wurl = document.getElementById('selectliens').src;
	//var wurl = document.getElementById('selectliens').contentDocument.location.href;

	if(wurl.indexOf("search=")>0) {
		wurl = wurl.slice(0,wurl.indexOf("?"));
	}
	document.getElementById('selectliens').src = wurl+'?search='+query;
	//document.getElementById('selectliens').contentDocument.location.href = wurl+'?search='+query;
	if(query) {
	var nurl = wurl+pquery+'&search='+query;
	window.location.href = nurl;
	}
}

function goIframeSearchRegistrations() {
	var query = document.getElementById('registration_search').value;
	var main_event = document.getElementById('main_event').value;

	if(query) {
		var isect = document.getElementById('i_participants');
		if(isect) {
			isect.src = '/live/iframes/events_registrations.php?main_event='+main_event+'&search='+query;	
		}
	}
}

function goPopSearchIndex() {
	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 goSearchImageIndex() {
	var query = document.getElementById('searchIndex').value;
	var wurl = window.location.href;
	if(window.location.search) {
		wurl = wurl.substring(0,wurl.indexOf('?'));	
	}
	if(query) {
	var nurl = wurl+'?search='+query;
	window.location.href = nurl;
	}
}
function clearImageIndex() {
	var nurl = '/images/indeximage.php';
	window.location.href = nurl;
}


//V2 function
function goSearchView() {
	var query = document.getElementById('view_search').value;
	var a = window.location.href;
	if(query != "") {
		if(a.indexOf('&search=') > 0) {
			var a1 = a.slice(0,a.indexOf('&search=')+8);
			var a2 = a.slice(a.indexOf('&order='));
			newa = a1+replaceAccents(query)+a2;
			alert('ici');
		} else {
			newa = a+'&search='+replaceAccents(query);			
		}		
		window.location.href=newa;
	}//if query
}
function clearSearchView() {
		window.location.href = wurl;
}




function goSearchWorkspace(table) {
	var query = document.getElementById('wks_search').value;
	var wurl = window.location.href;
	if(query != "") {
		if(window.location.search) {
			wurl = wurl.substring(0,wurl.indexOf('?'));	
		}
		var nurl = wurl+'?type='+table+'&search='+replaceAccents(query);
		window.location.href = nurl;
	}//if query
}
function goSearchWorkgroup(table,wid,input_id) {
	if(input_id) {	
	var query = document.getElementById(input_id).value;
	} else {
	var query = document.getElementById('wks_search').value;		
	}
	var wurl = window.location.href;
	if(query != "") {
		if(window.location.search) {
			wurl = wurl.substring(0,wurl.indexOf('?'));	
		}
		var nurl = '/intranet/'+table+'.php?workgroup='+wid+'&type='+table+'&search='+replaceAccents(query);
		window.location.href = nurl;
	}//if query
}
function clearSearchWorkgroup(table,wid) {
	var wurl = window.location.href;
		var nurl = '/intranet/'+table+'.php?workgroup='+wid;
		window.location.href = nurl;
}

function clearSearchWorkspace(table) {
	var wurl = window.location.href;
		if(window.location.search) {
			wurl = wurl.substring(0,wurl.indexOf('?'));	
		}
		var nurl = wurl+'?type='+table;
		window.location.href = nurl;
}

function goSearchAddressBook(table) {
	var query = document.getElementById('wks_search').value;
	var wurl = window.location.href;
	if(query != "") {
		if(window.location.search) {
			wurl = wurl.substring(0,wurl.indexOf('?'));	
		}
		var nurl = '/intranet/addressbook.php?search=search_index&query='+replaceAccents(query);
		window.location.href = nurl;
	}//if query
}

function clearSearchAddressBook(table) {
	var wurl = window.location.href;
		if(window.location.search) {
			wurl = wurl.substring(0,wurl.indexOf('?'));	
		}
		var nurl = "/intranet/addressbook.php";
		window.location.href = nurl;
}

function goSearchArchives(table) {
	var query = document.getElementById('wks_search').value;
	var wurl = window.location.href;
	if(query != "") {
		if(window.location.search) {
			wurl = wurl.substring(0,wurl.indexOf('?'));	
		}
		var nurl = '/intranet/archives.php?search='+replaceAccents(query);
		window.location.href = nurl;
	}//if query
}

function clearSearchArchives(table) {
	var wurl = window.location.href;
		if(window.location.search) {
			wurl = wurl.substring(0,wurl.indexOf('?'));	
		}
		var nurl = "/intranet/archives.php";
		window.location.href = nurl;
}

function goPopIndexMenu(table) {
	if(table) {
	var nurl = '/links/create_link_pop.php?table='+table;
	window.location.href = nurl;
	}
}

function goPopUserIndex() {
	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 pop_selected_user(user) {
	if(user) {
		var sUser = window.parent.document.getElementById('selected_users');
		if(sUser.value) {
			sUser.value = sUser.value+', '+user;				
		} else {
			sUser.value = user;							
		}
	}
}	

function pop_selected(v) {
	if(v) {
		var sV = window.parent.document.getElementById('return_value');
		if(sV.value) {
			sV.value = sV.value+', '+v;				
		} else {
			sV.value = v;							
		}
	}
}	

function pop_selected_ok(returnfield) {
		var sV = document.getElementById('return_value').value;
		if(returnfield) {
		if(window.opener) {
			var sV1 = window.opener.document.getElementById(returnfield);
			sV1.value = sV;
			}//window.opener
		}//returnfield
		window.close();
}

function PopLinkIndex(field_1,field_2) {
		var url = '/links/pop_create_link.php?field_1='+field_1+'&field_2='+field_2;
		PopFile(url);
}

function cleanLinkInfo(fieldvalue,sfield) {
		if(fieldvalue == "") {
			document.getElementById(sfield).value = "";	
		}
}

function cleanLinkInfoField(field_1,field_2) {
		document.getElementById(field_1).value = "";	
		document.getElementById(field_2).value = "";	
}

function PopExpressionIndex(returnfield) {
		var url = '/admin/pop_expression_index.php?return_field='+returnfield;
		PopIndex(url);
}

function PopUserIndex(returnfield) {
		var url = '/users/pop_user_index.php?return_field='+returnfield;
		PopFile(url);
}
function PopAddUserIndex(returnfield) {
		var url = '/users/pop_add_user.php?return_field='+returnfield;
		PopFile(url);
}
function PopMailUserIndex(returnfield,atype) {
		var url = '/users/pop_user_mail.php?return_field='+returnfield;
		if(atype) {
			url = url+'&type='+atype;
		}
		PopFile(url);
}

function PopWorkgroupComment(wid,idp) {
		var url = '/workgroups/workgroup_comment_edit.php?wid='+wid;
		if(idp) {
			url = url+'&id='+idp;	
		}
		var w = window.open(url,"","width=600,height=700, toolbar=0, addressbar=0, directories=0, location=0, menubar=0, resizable=1,scrollbars=1,status=0,left=1,top=1");
w.window.focus();
}

function pop_user_select_ok(returnfield) {
		var sUsers = document.getElementById('selected_users').value;
		if(returnfield) {
		if(window.opener) {
			var sUsers1 = window.opener.document.getElementById(returnfield);
			sUsers1.value = sUsers;
			}//window.opener
		}//returnfield
		window.close();
}
function pop_add_user(returnfield) {
		var sUsers = document.getElementById('selected_users').value;
		if(returnfield) {
			if(window.opener) {	
				var sUsers1 = window.opener.document.getElementById(returnfield);
				if(sUsers1) {
					if(sUsers1.value) {
						sUsers1.value = sUsers1.value+', '+sUsers;			
					} else {
					sUsers1.value = sUsers;						
				}//if recipients.value
			}//if recipients
			}//window.opener
		}//returnfield
		window.close();
}


function cleanLinkInfo(fieldvalue,sfield) {
		if(fieldvalue == "") {
			document.getElementById(sfield).value = "";	
		}
}


//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;
}


//Accents
function replaceChar(c,c1,c2) {

	while(c.indexOf(c1) != -1) c = c.replace(c1,c2);

return c;
}

function siteUserIndex(returnfield) {
		var url = '/live/pop/pop_user_index.php?return_field='+returnfield;
		PopFile(url);
}