/************************************
     MENU FUNCTIONS
************************************/

/*******************************************************************************/
/*Horizontal Menu - Display functions - Date 15 November 2006 - Author OD*/
/*******************************************************************************/
timer1=setTimeout("",0);
list=new Array('places','account','help','admin');
NS=(document.layers)?1:0;
IE=(document.all)?1:0;
function ctNS(){if(NS==1){ct();}}
function ctIE(){if(IE==1){ct();}}
function ct(){clearTimeout(timer1)}
function init(){
	clearTimeout(timer1);
	for(i in list){
		this.css=est.dom?document.getElementById(list[i]).style:est.ie?document.all[list[i]].style:est.ns?document.layers[list[i]]:0;
		this.css.visibility='hidden';
 	    this.css.display='none';    /* MCH 18/10/2010 +  */      
	}
}

     
function ia(){timer1=setTimeout('init();',2000);}

function iaNS(){if(NS==1){ia();}}
function iaIE(){if(IE==1){ia();}}
function Browser(){
	b=navigator.appName;
	if(b=="Netscape")this.b="ns"; 
	else if(b=="Microsoft Internet Explorer")this.b="ie";
	else this.b=b;
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns"&&this.v>=4);
	this.ie=(this.b=="ie"&&this.v>=4);
	this.dom=((document.createRange&&(document.createRange().createContextualFragment))?true:false);
}
est=new Browser();

/* MCH 22/10/2010 >>>>>  */   
function sh(div,state,pos){
    //alert(pos[0] + " - " + pos[1]);
	clearTimeout(timer1);
	this.css=est.dom?document.getElementById(div).style:est.ie?document.all[div].style:est.ns?document.layers[div]:0;
    this.css.left=pos[0]- 11;
    this.css.top=pos[1] +19;
	this.css.visibility=state;    
    if (state == 'visible') {
 	   this.css.display='inline'; 
    } else {
 	   this.css.display='none'; 
    }       
    /* MCH 22/10/2010 <<<<  */    
}
// ne pas supprimer les deux slash ci dessous sinon cela ne marche pas sous netscape
//-->
function switchClass(id,md) {
	if (id.className != "menuSel") {
		var a = new Array('menu','menuOver'); 
		id.className=a[md];
	}
}

/*******************************************************************************/	 
/*Vertical Menu - Style switcher on rollover - Date 15 November 2006 - Author OD*/
/*******************************************************************************/
function switchClass_menuSide (id,md) {
		var a = new Array('menuSide','menuSideOver','menuSideSelected'); 
		id.className=a[md];
}	 


/* MCh 22/10/2010 >>>>>> */
function getPosition(e)
{
 var left = 0;
 var top = 0;
/* var e = document.getElementById(element); Périmé MCh 22/10/2010 */
 while (e.offsetParent != undefined && e.offsetParent != null)
 {
  /*On ajoute la position de l'élément parent*/
  left += e.offsetLeft + (e.clientLeft != null ? e.clientLeft : 0);
  top += e.offsetTop + (e.clientTop != null ? e.clientTop : 0);
  e = e.offsetParent;
 }
 return new Array(left,top);
}
/* MCh 22/10/2010 <<<<<< */

 
/*******************************************************************************
    MAYETIC FUNCTIONS FROM PREVIOUS VERSION
*******************************************************************************/	 

/************************************
    STYLE SWITCHER FUNCTIONS
************************************/ 
checkStylesheet()
	
function selectStyle (vCookieName, vSelection) {
  makeCookie(vCookieName, vSelection, 90, '/');
  if (vCookieName == 'layout'){
  setActiveStyleSheet(vSelection)
  }else{
    self.location = self.location;
  }
}

function setActiveStyleSheet(pTitle) {
  var vLoop, vLink;
  for(vLoop=0; (vLink = document.getElementsByTagName("link")[vLoop]); vLoop++) {
    if(vLink.getAttribute("rel").indexOf("style") != -1 && vLink.getAttribute("title")) {
      vLink.disabled = true;
      if(vLink.getAttribute("title") == pTitle) vLink.disabled = false;
    }
  }
}

function checkStylesheet(){
  if (document.cookie.indexOf('style=')!=-1) {
    css = readCookie('style');
    //alert("STYLE: " + css);
    document.write('<style type="text/css" media="screen">@import "/stylesheets/' + css + '.css";</' + 'style>\n');
  }else{
    //alert("STYLE: Default");
    document.write('<style type="text/css" media="screen">@import "/stylesheets/notestips-style-original.css";</' + 'style>\n');
  }
  if (document.cookie.indexOf('layout=')!=-1) {
    css = readCookie('layout');  
   // alert("LAYOUT: " + css);
    setActiveStyleSheet(css)
  }else{
   // alert("LAYOUT: Default");
    setActiveStyleSheet("Layout1")
  }
}

/* ***********************************
     COOKIE FUNCTIONS
   *********************************** */

function makeCookie(Name,Value,Expiry,Path,Domain,Secure){
  if (Expiry != null) {
    var datenow = new Date();
    datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry));
    Expiry = datenow.toGMTString();
  }

  Expiry = (Expiry != null) ? '; expires='+Expiry : '';
  Path = (Path != null)?'; path='+Path:'';
  Domain = (Domain != null) ? '; domain='+Domain : '';
  Secure = (Secure != null) ? '; secure' : '';

  document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure;
}

function readCookie(Name) {
  var cookies = document.cookie;
  if (cookies.indexOf(Name + '=') == -1) return null;
  var start = cookies.indexOf(Name + '=') + (Name.length + 1);
  var finish = cookies.substring(start,cookies.length);
  finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');
  return unescape(cookies.substring(start,finish));
}

function cookies(){
  makeCookie('view_cookie',pagename,90,'/');
  makeCookie('database_cookie',database,90,'/');
  x = readCookie('type_cookie');
}

function deleteCookie(name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1000);
  var cval = readCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
/* *********************************** */

// to intercept the onKeyPress event
function abortSubmit (e) {return (false)}

function checkEnter(event){ 	//prevent return key
	var code = 0;	
	if (getBrowserType() == 'N')
		{code = event.which;}
	else
		{code = event.keyCode;}
		//  alert(code);
	if (code==13){
	window.document.forms[0].onsubmit = abortSubmit;
	}
}

//SEARCH FUNCTIONS

// simple search function - to process query parameters
function queryParameters(field, par){
return ("(FIELD+" + field + "+Contains+" + par +")");
}

// search function 
function getSearchResults(val) {

form=window.document.forms[0]; 
var searchString = form.SearchStringItem.value;

	if (searchString == "Rechercher sur le site") 	{
				//alert("Please enter a text string to search.");	
				alert("Veuillez entrer le texte à rechercher.");	
				form.SearchStringItem.focus();
				return;
				}
	else {
				// build search string	
				if(val==1){				
				searchURL = "/" + getPath() + "/viewSearch?SearchView&Query=" + searchString+ "&Start=1&Count=20" ;						window.location.href = searchURL + "&NavMenu=1&SearchOrder=4";
				}
				else{
				searchURL = "/" + getPath() + "/viewSearch?SearchView&Query=" + searchString+ "&Start=1&Count=20" ;						window.location.href = searchURL + "&SearchOrder=4";
				}
	}
 }

// advanced search function - treat NN4 and Mac separately
function getAdvancedSearchResults() {
  
form=window.document.forms[0];

// get field values
	var kw= escape(form.SearchString.value);
	var catg = escape(getListValue(form.WebCategories));
		if (catg=="All%20Categories"){catg=""}
	var forum = escape(getListValue(form.ForumName));
		if (forum=="All%20Forums"){forum=""}

// get checkbox values - if both are checked evaluate a OR operator
var type="";	
var checkType = false;

for (i = 0;  i < form.PostType.length;  i++)
{
	if (form.PostType[i].checked) {
		if (checkType==true){
		type = type + "+OR+"+form.PostType[i].value ;}
		else{
		type = form.PostType[i].value ;
		checkType = true; 
		}
	}
}

if (checkType==false){ type=""}

req="";
flag=true;
link = "+AND+";

    // BUILD SearchString in URL : req= req+  link + " (FIELD " + DocField + Operator + val + ") "
	if (kw !="") {req = "("+ kw + ")" ; flag=false };
	if (req !="" && catg !="" ){ req=req + link};
	if( catg !="" ) {req = req +queryParameters('WebCategories', catg) ; flag=false };
	if (req !="" && forum !="" ){ req=req + link};
	if( forum !="" ) {req = req +queryParameters('ForumName', forum); flag=false };
	if (req !="" && type !=""){ req=req + link};
	if( type !="") {req= req +queryParameters('PostType', type) ; flag=false };

// alert(req);

// if nothing is selected perform a general search to get everything
if (flag==true) {
	req = "*a+OR+*e+OR+*i+OR+*u";
	searchURL = "/" + getPath() + "/viewSearch?SearchView&Query=" + req + "&Start=0&Count=20";
}
else{
	searchURL = "/" + getPath() + "/viewSearch?SearchView&Query=" + req + "&Forum=" + forum + "&Start=0&Count=20";
};

// load url
	window.location.href = searchURL;
 };


// used for help popups
function openMessageBox(url){
	winPopup = window.open(url,"winpopup","width=600, Height=550,alwaysRaised=yes,scrollbars=yes,resizable=yes");winPopup.focus();
}

// compatible N & IE code to open url in a new window 
 function openNewWindow (URL, WinName, Features) { 
        window.open(URL, WinName, Features);
        }

// Return the selected value from a listbox
function getListValue(fieldName) {
	var i, nbSelected = 0;
	for (i = 0; i < fieldName.options.length; i++) {

		if (fieldName.options[i].selected
		  && fieldName.options[i].text != '') {return fieldName.options[i].text;};
	};
	return '';
};

//Select the option evaluated to 'value' of the select type field  'fieldName'
function selectListValue(fieldName,value) {
	var i, nbSelected = 0;
	for (i = 0; i < fieldName.options.length; i++) {
		if (fieldName.options[i].text == value)
		{
			fieldName.options[i].selected = true;
		};
	};
	return '';
}


// Used to altern row colors in view
function altern(docNumber) { 
var lastDocNumber =  docNumber.lastIndexOf('.')>=0? docNumber.slice(docNumber.lastIndexOf('.')+1) : docNumber;
return(lastDocNumber);
} 

// To delete a doc form the web 
 function DeleteEntry(menu){
 form = document.forms[0];
	var strId=form.UniqueId.value;
 		var ok =true
	ok = confirm("Etes-vous sûr(e) de vouloir supprimer ce document ?");
		if (ok) {
		window.status="Suppression du document...";		
			var strURL = "/" + getPath()+ "/DeleteEntry?OpenAgent&Query=" + strId + "&menu=" + menu ;
				window.location = strURL;	
		}	 
}

//to open a selection list window
function LoadWindow(formName, param, winparam){
var newwindow ;
if ((newwindow) && (!newwindow.closed)) {newwindow.close();};
var form=window.document.forms[0];
var path= getPath();
newwindow = window.open( '/'+ path+"/" + formName + "?OpenForm" + param,"", winparam );
newwindow.focus();
}


// on Load initialize MenuTreeRead field (disabled)
function initList(Edit,Read) {
Edit.value = Read.value;
}


// Function to display modal popup window with tree structure from menu
function showList(type) {
   pathVal=getPath();
   var kwStr=showModalDialog("/" + pathVal + "/frmMenuDialog?OpenForm&type=" + type ,"", "dialogWidth:300px; dialogHeight:450px; center:yes");
   form=document.forms[0];
	if(kwStr)
	{
		form.MenuTreeRead.value=kwStr;
             	form.MenuTreeEdit.value=kwStr;
 	     	if(type=="All")
		{
			form.AuthorsEdit.value="";
			form.AuthorsEditEdit.value="";
			form.SendTo.value="";
			form.SendToEdit.value="";
			form.Category.focus(); 
			_doClick('$Refresh', this, '_self', '#_RefreshKW_MasterPage')
		}
					
        }
}

// function to open the listebox url
function loadUrl(v){
var tab=v.split('#')
if (tab[1]=="_self" && tab.length==2) window.location=tab[0]
else window.open( tab[0])
}


// To check the rights of the current user for the selected ecom 
function CheckMember(docId){
var form=window.document.forms[0];
var user = getCurrentUser()
var strURL = "/" + getPath()+ "/CheckEcomMembers?OpenAgent&ecom=" + docId + "&member=" + user;
window.location = strURL;	
}

