// ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.

	This file is part of POSH (Portaneo Open Source Homepage) http://sourceforge.net/projects/posh/.

	POSH is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version

	POSH is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Posh.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
*  POSH javascript main file
* 
* JAVASCRIPT main functions are defined on portaneo.com
*/

// Menu variables

var showNewMod    = false;
var showBoxStatus = false;
var showHdr       = false;
var noteSize      = 0;
var newModH;

// Newspaper variables
var searchControl;

var dirOptSelId   = [];
var dirOptSelSec  = [];
var ourSel        = '';
var ourSelSub     = [];
var useMod;
var tab           = [];
var dumtab;
var mDivObj       = null;
var indef;
var pfolder       = '';
var allowSave     = false;
var demoMode	  = false;
var isPortal      = true;
var rand          = Math.ceil(Math.random()*100);
var rssNoCache    = false;
var leftMenuWidth = 290; //left menus width
var leftMenuWidthMin = 10; //left menus decal when closed
var p_version;
var createDivDynamically = true;
var wip_message   = "loading ...";
var _current_date = new Date();
var _current_day  = _current_date.getDate();
var _current_month=_current_date.getMonth();
var _current_year = _current_date.getFullYear();
var widgetDecalY  = 0;
var widgetDecalX  = 0;
var _dirImg       = "../modules/pictures/";
var standaloneMode= false;
var widgetHeight  = 200;
var w_pfid     	  = [];

var language      = "en";
var encryptKey    = "en";
var pageClasses	  = []; 

//var emptyImage = new Image();

//***************************************************************************************************************************************************
//*
//*                                      FRAMEWORK
//*
//***************************************************************************************************************************************************

//******************** GENERIC FUNCTIONS **********************************************************************************************************

/*
    Class: $p

            Generic functions
            
            $p

    file: ajax.js

*/

$p={
    /*
                Function: get
                        $p.get  
                    
                        Get object based on ID
                    
                Parameters:

                        v_id - ID of the object

                Returns:

                        object or null if no object with the ID    
           */
	get: function(v_id)
    {
        return $(v_id);
    },
	/*
	Function: print
                     $p.print
                     
                    Change HTML content of an object
	
           Parameters:

		v_id - ID of the object
		v_s - string to display in the object
		v_add - add v_s to the current content of the object. Top= at the beginning, bottom=at the end
	*/
	print: function(v_id,v_s,v_add)
	{
		var l_obj = $(v_id);

		if (v_add != indef && v_add == "bottom")
		{
            //v_s = l_obj.innerHTML + v_s;
            v_s = l_obj.get('html') + v_s;
		}

		if (v_add != indef && v_add == "top")
            v_s = v_s + l_obj.innerHTML;

		if (l_obj != null)
		{
			l_obj.empty();
			l_obj.set('html', v_s);
		}
	},
	/*
	Function: getPos
                    $p.getPos
    
                    Return the absolute position of a node
	
            Parameters:
		v_node - node
		v_ref - Top=get top position  Left=get left position
                 v_parentRef - indef if position computed based on the page margin, object if position is computed based on this object
	
            Returns:
		Top or Left position of the node or 0 if the node is null
	*/
	getPos: function(v_node,v_ref,v_parentRef)
	{
		var l_ret = 0;
		while(v_node != null && (v_parentRef == indef || v_node != v_parentRef))
		{
			l_ret += v_node["offset"+v_ref];
			v_node = v_node.offsetParent;
		}
		return l_ret
	},
	/*
	Function: setClass 
                    $p.setClass
    
          Change the CSS Class of an object
	
         Parameters:

                    v_id - ID of the object
                    v_class - CSS class to apply to the object
	*/
	setClass: function(v_id,v_class)
	{
		var l_obj = $(v_id);
		if (l_obj)
            l_obj.className = v_class;
	},
	/*
	Function: show 
                    $p.show
                    
                    Show/Hide an object
                    
	Parameters:

		v_id - ID of the object
		v_disp - display value (block, none, inline)
	*/
	show: function(v_id,v_disp)
	{
		var l_obj = $(v_id);
		if (l_obj != null)
		{
			//exceptions
			if (v_disp == 'table-cell' && $p.navigator.IE)
                v_disp = 'block';
	
			l_obj.style.display = v_disp;
		}
	},
	/*
	Function: isShown
                    $p.isShown 
                    
                    Check if object is displayed or not
                    
	Parameters:

                    v_id - ID of the object
	
          Returns:
          
                    boolean, true if object is displayed false if not.
	*/
	isShown: function(v_id)
	{
		var l_obj = $(v_id);
		if (l_obj)
		{
			return (l_obj.style.display == 'block' ? true : false);
		}
		else return false;
	},
    /*
	Function: min
                    $p.min
                    
                    Returns the minimum of two values
                    
	Parameters:

                    v1 - first value
                    v2 -  second value
	
          Returns:
          
                    the minimum value.
	*/
	min: function(v1,v2)
	{
		return Math.min(v1,v2);
	},
    /*
	Function: $p.max                    
                    
                    Returns the maximum of two values
                    
	Parameters:

                    v1 - first value
                    v2 -  second value
	
          Returns:
          
                    the maximum value.
	*/
	max: function(v1,v2)
	{
		return Math.max(v1,v2);
	},
	/*
	Function: $p.addPropertyToClass 

                    Change an object style property
                    
	Parameters:

		v_class - class of the objects which style property is updated
		v_prop - property to be updated
		v_value - new value of the property
	*/
	addPropertyToClass: function(v_class,v_prop,v_value)
	{
		var l_items = _gelstn("*");
		for(var l_item = 0;l_item < l_items.length;l_item ++)
		{
			if(l_items[l_item].className == v_class)
            {
                l_items[l_item].style[v_prop] = v_value;
            }
		}
	},
	/*
	Function:  $p.changeId
                   
                    Change an object ID
                    
	Parameters:

		v_id - current object ID
		v_newId - new ID
	*/
	changeId: function(v_id,v_newId)
	{
		var l_obj = $(v_id);
		if (l_obj)
            l_obj.id = v_newId;
	},
	/*
	Function: $p.setHeight  
                    
                    Define an object height
                    
	Parameters:

		v_id - ID of the object
		v_h - new height
	*/
	setHeight: function(v_id,v_h)
	{
		var l_obj = $(v_id);
		if (l_obj != null)
			l_obj.setStyle("height",v_h+"px");
	},
	/*
	Function: setWidth
                    $p.setWidth  
                    
                    Define an object width
                    
	Parameters:

		v_id - ID of the object
		v_w - new height
	*/
	setWidth: function(v_id,v_w)
	{
		var l_obj = $(v_id);
		if (l_obj != null)
			l_obj.setStyle('width',v_w+"px");
	},
	/*
	Function: img
                    $p.img 
                    
                    Return image HTML script
                    
	Parameters:

		v_file - image URL (optional)
		v_w - width of the image (optional)
		v_h - height of the image (optional)
		v_alt - alternative text of the image (optional)
		v_cl - class of the image (optional)
		v_id - id of the image (optional)
	
	Returns:
    
			 HTML script
	*/
	img: function(v_file,v_w,v_h,v_alt,v_cl,v_id,v_style)
	{
		if (v_file == '-') return '';
		//if (v_file == indef || v_file == '') v_file='s.gif';
		var l_width = v_w ? ' width="'+v_w+'"'
                          : '';
		var l_height = v_h ? ' height="'+v_h+'"'
                           : '';
		if (v_alt==indef) v_alt = '';
		if (v_cl==indef) v_cl = '.';
		if (v_id==indef)
        {
            v_id = '';
        }
        else {
            v_id = ' id="'+v_id+'"';
        }

		if (v_file == indef || v_file == '')
		{
				var l_s = '<div'
					+ l_width
					+ l_height
					+ ' class="'
					+ v_cl+'"'
					+ ' style="width: '+v_w+'px;height: '+v_h+'px;display: inline;padding: 0 '+v_w+'px '+v_h+'px 0;margin: 0px;font-size: 0px;"'
					+ v_id+'></div>';

				return l_s;
		}
		else
		{
			//if (v_file.substr(0,4)!='http'  || v_file.substr(0,2)!='..')
		    if ( !v_file.match(/^(http|\.\.)/)) 
			{
				v_file = pfolder+'../images/'+v_file;
			}
					
			return '<img src="'
					+ v_file
					+ '" alt="'+$p.string.removeCot(v_alt)+'"'
					+ l_width
					+ l_height
					+ ' class="'
					+ v_cl+'"' 
					+ ' style="'+v_style+'"'
					+ v_id+' />';
		}
	},
	/*
	Function: imgObj
                    $p.imgObj 
                    
                    Return an image as a new MooTools extended HTML Element.
                    
	Parameters:

		v_file - image URL (optional)
		v_w - width of the image (optional)
		v_h - height of the image (optional)
		v_alt - alternative text of the image (optional)
		v_cl - class of the image (optional)
		v_id - id of the image (optional)
	
	Returns:
    
			 The image as an element
	*/   
	imgObj: function(v_file,v_w,v_h,v_alt,v_cl,v_id)
	{
		if (v_file==indef || v_file=="") { v_file="s.gif"; }
		if (v_alt==indef) { v_alt="";}
		if (v_cl==indef) { v_cl=".";}
		if (v_id==indef) { v_id="";}
		if (v_file.substr(0,4)!="http")  { v_file=pfolder+"../images/"+v_file; }
		l_img = new Element('img',
			{
				'src':v_file,
				'alt':$p.string.removeCot(v_alt),
				'class':v_cl,
				'id':v_id
			}
		);
		if (v_w) l_img.setProperty('width',v_w);
		if (v_h) l_img.setProperty('height',v_h);

		return l_img;
	},
	/*
		Function: adjustFrameHeight
                                $p.adjustFrameHeight 
                                
                                Define a frame height based on its content
                                
		Parameters:

			l_frm - frame object
	*/
	adjustFrameHeight:function(v_frm,v_doitagain,v_height)
	{
        if (v_doitagain == indef) v_doitagain = true;
		
		var pageHeight = Window.getHeight();
		var moduleDivTopPos = $p.getPos($p.get("modules"),"Top");
		var pageHeightMinusHeader = pageHeight - moduleDivTopPos;
		
		if ((v_frm.src).indexOf('frameheight=') > 0)
		{
			l_args = _args(v_frm.src);
			var height = l_args['frameheight'];
		}
		else
		{
			// if the iframe is a not a local url, the size properties are not accessable
			if ($p.url.isLocal(v_frm.src) && (v_frm.src).indexOf('framenoresize') == -1) {
				if ($p.navigator.FF)  {
					v_frm.style.height = '100px'; // used on FF to force resize
				}			
				var height = v_frm.contentWindow.document.body.scrollHeight + 30;
				
				// if content height too small, enlarge
				if (height < (pageHeightMinusHeader - 30)) height = pageHeightMinusHeader - 30;
				
				if (v_doitagain)
					setTimeout("$p.adjustFrameHeight($('" + v_frm.id + "'),false)",6000);
			}
			else {
				if ($p.navigator.FF)  {
					v_frm.style.height = '100px'; // used on FF to force resize
				}
				var height = pageHeightMinusHeader - 15;
				// l_frm.scrolling = 'auto' > do not work. With IE this property is not changeable after item creation
			}
		}

        v_frm.style.height = height + 'px';
	},
    /*
            Function: $p.changeProtocol
            
            change localfolder protocol (switch from http to https)
            
            return localfolder with new protocol
    */
	changeProtocol: function (v_url) {
       var returned_url = v_url;
       if (v_url.indexOf(__LOCALFOLDER) != -1){
			returned_url = v_url.replace(/http:/,$p.navigator.getProtocol());
       }
       return returned_url;
	}
}
/*
    Class: $p.string
            Strings functions
            
            $p.string
*/

$p.string={
    /*
	Function: $p.string.trim
                   
                    Suppress unused blank space from a string (beginning/end)
                    
                    remove tab, space and eol
                    
	Parameters:

                    v_s - string
	
          Returns:
          
                     string without unused blank space
	*/
	trim: function(v_s)
	{
		if (v_s == indef) v_s = '';
		return v_s.replace(/^[\t\s\n\r]+/g,'').replace(/[\t\s\n\r]+$/g,'');
	},
    /*
                Function: $p.string.removeEOL
                
                        delete all eol character from string
                        
                 Parameters: 
                        v_s - string
                        
                 Returns: 

                        string
    */
    removeEOL: function (v_s) {
        return v_s.replace(/[\n\r]+/g,' ');
    },
	/*
	Function: $p.string.esc
                    
                    encode URL string with encodeURIComponent
                    
	Parameters:

		v_s - string
	
	Returns:
                    
                    encoded string
	*/
	esc: function(v_s)
	{
		return window.encodeURIComponent ? encodeURIComponent(v_s) : escape(v_s);
	},
	/*
            Function: $p.string.unesc
                     
                     decode URL string with decodeURIComponent
                     
                     replace % by url encoding value
                                    
            Parameters:

                     v_s - encoded string
		
	 Returns:
			 
                     decoded string
	*/
	unesc: function(v_s)
	{
		return window.decodeURIComponent ? decodeURIComponent(unescape(v_s).replace(/%/g,'%25')) : unescape(v_s);
	},
	/*
	Function: $p.string.uc
                   
                    uppercase transformation on a string
                    
	Parameters:

		v_s - string
	
	Returns:
                    
                     string
	*/
	uc:function(v_s)
	{
		return v_s.toUpperCase();
	},
	/*
	Function: $p.string.lc

                    lowercase transformation on a string
                    
	Parameters:

		v_s - string
	
	Returns:
                    
                     string
	*/
	lc:function(v_s){
		return v_s.toLowerCase();
	},
	/*
	Function: $p.string.formatForSearch

                    Format the search string
                    
	Parameters:

		v_s - string
	
	Returns:
                    
                     formated search string
	*/
	formatForSearch: function(v_s)
	{
		v_s=$p.string.lc(v_s);
		v_s=v_s.trim();
		v_s=$p.string.removeAccents(v_s);
		v_s=v_s.replace(/\+/gi,",");
		v_s=v_s.replace(/;/gi,",");
		v_s=v_s.replace(/"/gi," ");
		v_s=v_s.replace(/\./gi," ");
		v_s=v_s.replace(/'/gi," ");
		v_s=v_s.replace(/, /gi,",");
		v_s=v_s.replace(/  /gi," ");
		return v_s;
	},
	/*
	Function: $p.string.removeAccents

                    Replace accentuated signs by non accentuated
                    
	Parameters:

		v_s - accenutuated string
	
	Returns:
                    
                     non accuentuated string
	*/
	removeAccents:function(v_s)
	{
		v_s=v_s.replace(/[àâä]/gi,"a");
		v_s=v_s.replace(/[éèêë]/gi,"e");
		v_s=v_s.replace(/[îï]/gi,"i");
		v_s=v_s.replace(/[ôö]/gi,"o");
		v_s=v_s.replace(/[ùûü]/gi,"u");
		v_s=v_s.replace(/[ç]/gi,"c");
		return v_s;
	},
	/*
	Function: removeCot
                    $p.string.removeCot
                    
                    Suppress cots from string
                    
	Parameters:

                    v_s - string to format	
                    v_coteType - cots type ('simple','double','both')
        
	Returns:
                    
                    formatted string
	*/
	removeCot:function(v_s,v_coteType)
	{
		if (v_coteType==indef) v_coteType='both';
		if (v_coteType=='simple' || v_coteType=='both') v_s = v_s.replace(/'/g,"");
		if (v_coteType=='double' || v_coteType=='both') v_s = v_s.replace(/"/g,"");
		return v_s;
	},
	/*
	Function: doubleToSimpleCot
                    $p.string.doubleToSimpleCot
                    
                    Replace double cots by simple cots
                    
	Parameters:

		v_s - string
	
	Returns:
                    
                     string
	*/
	doubleToSimpleCot:function(v_s)
	{
		return v_s.replace(/"/g,"'");
	},
    replaceSpleQuot: function (v_s)
	{
        return v_s.replace(/'/g,"&#39");
    },
	replaceAmpersand: function (v_s)
	{
		return v_s.replace(/&/g,"%26");
    },
    replacePlus: function (v_s)
	{
        return v_s.replace(/\+/g,"%2B");
    },
    replaceEqual: function (v_s)
	{
        return v_s.replace(/\=/g,"%3D");
    },
    SimpleEncoding: function (v_s) {
        v_s = $p.string.replaceAmpersand(v_s);
        v_s = $p.string.replacePlus(v_s);
        v_s = $p.string.replaceEqual(v_s);
        return v_s;
    },
	/*
	Function: $p.string.trunk

                    Truncate string if longer that limit length
                    
	Parameters:

                     v_s - string
                     v_length - limit length
		v_rangeForPoint - (integer) define the range a '.' is searched to trunk until
		v_functionForMore - (string) function called to get the entire string (no link if =undefined)
	
	Returns:
                    
                      truncated string
	*/
	trunk:function(v_s,v_length,v_rangeForPoint,v_functionForMore)
	{
		var l_s=v_s.substr(0,v_length);

		if (v_rangeForPoint!=indef)
		{
			var endPos = (l_s.indexOf('.',(v_length-v_rangeForPoint))) + 1; //get position of (.) starting from maxLength
			if (endPos!="") l_s=l_s.substr(0,endPos); //use shorter description
		}

		if (v_s.length>v_length)
		{
			l_s=l_s
				+(v_functionForMore==indef
					? ' ...'
					: ' <a href="#" onclick=\''+v_functionForMore+'\'>'+lg('readMore')+'...</a>'
				);
		}
		return l_s;
	},
	/*
	Function: getVar
                    $p.string.getVar
                    
                    Get variable value from a string (URL)
                    
	Parameters:

                     v_s - string
                     v_var - variable searched
                     datatype - type of data : int or string  (optional)
	
	Returns:
                    
                     value of the variable
	*/
	getVar:function(v_s,v_var,datatype)
	{
        var l_ret="";
        if (datatype && datatype=='int') {
            l_ret=0;
        }
        if ( typeof(v_s) =='object') {
            return '';
        }
		var reg = new RegExp("&(?!amp;)", "g");
        var l_items=v_s.split(reg);
        for (var i=0;i<l_items.length;i++)
        {
           // var l_arr=l_items[i].split("=");
			var l_arr0 = l_items[i].substr(0,l_items[i].indexOf("="));
			var l_arr1 = l_items[i].substr(l_items[i].indexOf("=")+1,l_items[i].length);
            if (l_arr0==v_var) {
				if (__ENCRYPT_USERPREF) {
					l_arr1 = decodeURIComponent(l_arr1.replace(/\+/g, '%20'))
				}
                l_ret=$p.string.unesc(l_arr1);
            }
        }
        return l_ret;
	},
	/*
	Function: supVar
                    $p.string.supVar
                    
                    Suppress a variable and its value from a string (URL)
                    
	Parameters:

                    v_s - string
                    v_var - variable searched
	
	Returns:
                    
                     string without the variable
	*/
	supVar:function(v_s,v_var)
	{
        if ( typeof(v_s) =='object') {
            return '';
        }    
		var l_items=v_s.split("&");
		for (var i=0;i<l_items.length;i++)
		{
			var l_arr=l_items[i].split("=");
			if (l_arr[0]==v_var) {
				l_items.splice(i,1);
			}
		}
		return l_items.join("&");
	},
	/*
	Function: textToHtml
                    $p.string.textToHtml
                    
                    Transform text to HTML (replace special chars)
                    
	Parameters:

                    v_s - text to transform
	
	Returns:
                    
                    HTML code
	*/
	textToHtml:function(v_s)
	{
		v_s=v_s.replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/  /g,"&nbsp; ").replace(/\r/g,"");
		v_s=($p.navigator.IE)?v_s.replace(/\n/g,"<BR>"):v_s.replace(/\n/g,"<br>");
		return v_s;
	},
	/*
	Function: htmlToText
                    $p.string.htmlToText
                    
                    Transform HTML to text (replace special chars)
                    
	Parameters:

                    v_s - text to transform
	
	Returns:
                    
                    Text equivalent
	*/
	htmlToText:function(v_s)
	{
		v_s=v_s.replace(/\&amp;/g,"&").replace(/\&lt;/g,"<").replace(/&gt;/g,">").replace(/\&nbsp;/g," ").replace(/<BR>/g," ").replace(/<br>/g," ").replace(/<BR \/>/g," ").replace(/<br \/>/g," ");
		return v_s;
	},
	/*
	Function: textToXml
                    $p.string.textToXml
                    
                    Transform text to xml object
                    
	Parameters:

                    v_s - text to transform
	
	Returns:
                    
                    XML object
	*/
	textToXml:function(v_s)
	{
		var l_xml;
		if (document.implementation.createDocument) {
			// Firefox XML object creation 
			var parser = new DOMParser(); 
			l_xml = parser.parseFromString(v_s, "text/xml"); 
		}
		else if (window.ActiveXObject) { 
			// IE XML object creation
			l_xml = new ActiveXObject("Microsoft.XMLDOM"); 
			l_xml.async="false";
			l_xml.loadXML(v_s);
		}
		return l_xml;
	},
	/*
	Function: correctEncoding
                    $p.string.correctEncoding
                    
                    Replace chars encoding in string
                    
	Parameters:

                    v_s - char to decode
	
	Returns:
                    
                    decoded char
	*/
	correctEncoding:function(v_s)
	{
		var l_s=v_s.replace(/\&amp;/g,"&");
		l_s=l_s.replace(/\&#38;/g,"&");
		l_s=l_s.replace(/\&#39;/g,"'");
		l_s=l_s.replace(/\&quot;/g,"'");
		l_s=l_s.replace(/\&apos;/g,"'");
		return l_s;
	},
	escapeAndSign: function(v_s)
	{
		return v_s.replace(/\&/g,'&amp;');
	},
	/*
	Function: parseTextToHtml
                    $p.string.parseTextToHtml
                    
                    Parse text as html (experimental)
                    
	Parameters:

                    v_s - text to transform
	
	Returns:
                    
                    HTML object
	*/
	parseTextToHtml:function(v_s)
	{
		var l_html;
		if (document.implementation.createDocument) {
			// Firefox XML object creation 
			var parser = new DOMParser(); 
			l_html = parser.parseFromString(v_s, "text/html"); 
		}
		else if (window.ActiveXObject)  {
			// IE XML object creation
			l_html = new ActiveXObject("Microsoft.XMLDOM"); 
			l_html.async="false";
			l_html.loadXML(v_s);
		}
		return l_html;
	},
	/*
		Function: simulateGetElementsByTagName
                                $p.string.simulateGetElementsByTagName
                                
                                Reproduce getElementsByTagName action on a text
                        
	         Parameters:

			v_s - text
			v_tag - tags searched in text without '<' and '>' string
		
                    Returns:
                    
			 Array containing an object for each tags found in the text
                         
                    Example:

                                tagTab will contain 1 object. Its properties are accessible like :
                                tagTab[0][color];
                                tagTab[0][size];
                                
                                (start code)

                                    <script>
                                        var tagTab=[];
                                        var myString = 'This is my example concerning the <font color='red' size='6'> tag and it's properties</font>';
                                        tagTab = $p.string.simulateGetElementsByTagName(myString,'font');
                                    </script>

                                (end)          
	*/
	simulateGetElementsByTagName:function(v_s,v_tag)
	{
		var l_lowercaseString=$p.string.lc(v_s);
		v_tag=$p.string.lc(v_tag);
		var l_starttag=0,l_endtag,l_nocontent,l_endprop,l_resArray=[];
		while (l_lowercaseString.indexOf("<"+v_tag,l_starttag)!=-1)
		{
			var l_nocontent=false;
			l_starttag=l_lowercaseString.indexOf("<"+v_tag,l_starttag)+(v_tag.length+1);
			l_endprop=l_lowercaseString.indexOf(">",l_starttag);
			if (l_lowercaseString.substr(l_endprop-1,1)=="/"){l_endprop--;l_nocontent=true;}
			var l_property={};
			//get tag properties
			var l_propStr=v_s.substring(l_starttag,l_endprop);
			//l_propElmt=l_propStr.split(/(["'] )/);
			var l_propElmt=l_propStr.split(/[("|')][ ]/);
			for (var i=0;i<l_propElmt.length;i++)
			{
				var pair=l_propElmt[i].split(/[=][("|')]/);
				if (pair[1]) {
					pair[0]=$p.string.trim(pair[0]);
					pair[1]=$p.string.trim(pair[1]);
					l_property[pair[0]]=(pair[1].slice(-1)=='"' || pair[1].slice(-1)=="'")?pair[1].substr(0,(pair[1].length-1)):pair[1];
				}
			}		
			// get tag content
			if (v_s.indexOf("<",l_endprop)!=-1 && !l_nocontent) {
				l_endtag=v_s.indexOf("<",l_endprop);
				if (v_s.substr(l_endtag,(v_tag.length+2))=="</"+v_tag) {
					l_property["content"]=v_s.substring(l_endprop+1,l_endtag);
				}
				else l_property["content"]="";
			}
			else {
				l_property["content"]="";l_endtag=l_endprop;
			}
			l_resArray.push(l_property);
			l_starttag=l_endtag;
		}
		return l_resArray;
	},
    /*
                Function: $p.string.getLinks
                
                        get link tag in html page
                        
                        used to get alternate rss+xml url in a web page
                        
                   Parameters: 
                       
                       page - string

                      Returns:
                      
                            array containing hash (js Object) one by link
                            
                       See Also:

                                 $p.app.widgets.rss.checkFeedXml 
            */
    getLinks: function (page)
    {
        var xmlList = new Array();
        var regparam=  new RegExp('[^ ]+\=[^ ]+',"img");
        var reg=new RegExp('<link[^>]+>',"img");
        var res = page.match(reg);
        if (res != null)
        {
            for (var i = 0; i< res.length;i++) {
                var link = res[i];
                link = link.replace('\/>','');
                link = link.replace('>','');
                var params = link.match(regparam);
                var rss=false;
                var newlink = new Object();
                for ( var j=0;j < params.length; j++) {
                    if ( link.match(/application\/rss\+xml/i) ) {
                        rss=true;
                    }
                    if (rss && params[j].match(/href\=/i)) {
                        var href=params[j].replace('href=','');
                        href=href.replace(/"/g,'');
                        rss=false;
                        newlink['href'] = href;
                        var ltitle = link.match(/title="[^"]+"/i);
                        var title = ltitle[0];
                        title = title.replace(/title\=/ig,'');
                        title = title.replace(/"/g,'');
                        newlink['title'] = title;
                        newlink['type'] = "application/rss+xml";
                        xmlList.push(newlink);
                        break;
                    }
                }
            }
        }
        return xmlList;
    },
	/*
	Function: removeTags
                    $p.string.removeTags
                    
                    remove tags from a string
                    
	Parameters:

                    v_s - string
	
	Returns:
                    
                    string without tags
	*/
	removeTags:function(v_s)
	{
		return v_s.replace(/<\/?[^>]+(>|$)/g, "");
	},
	/*
	Function: removeStyleTag
                    $p.string.removeStyleTag
                    
                    remove style tags from a string
                    
	Parameters:

                    v_s - string
	
	Returns:
                    
                    string without style tags
	*/
	removeStyleTag:function(v_s)
	{
		return v_s.replace(/\<styl[^?]+\/style\>/g, "");
	},    
	/*
	Function: removeHeadTag
                    $p.string.removeHeadTag
                    
                    remove head tag from a string
                    
	Parameters:

                    v_s - string
	
	Returns:
                    
                    string without head tags
	*/
	removeHeadTag:function(v_s)
	{
		return v_s.replace(/\<head[^?]+\/head\>/g, "");
	},
	/*
	Function: removeScriptTag
                    $p.string.removeScriptTag
                    
                    remove script tags from a string
                    
	Parameters:

                    v_s - string
	
	Returns:
                    
                    string without script tags
	*/
	removeScriptTag:function(v_s)
	{
		return v_s.replace(/\<script[^?]+\/script\>/g, "");
	},
	/*
	Function: randomize
                    $p.string.randomize
                    
                    build a random string
                    
	Parameters:

                    v_length - string length
	
	Returns:
                    
                    random string
	*/
	randomize:function(v_length)
	{
		var l_list = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");
		var l_s='';

		for(i=0;i<v_length;i++)
		{
			l_s+=l_list[Math.floor(Math.random()*l_list.length)];
		}
		return l_s;
	},
	checkNumberInString:function(str){
		var exp = "";
		var chk = false;

		exp = new RegExp("[0-9]+","g");
		chk = exp.test(str);
		
		return chk;
	},
	checkSymbolInString:function(str){
		var exp = "";
		var symbol = "[_<>.+*!:;,§/?µ%&“”„'\"()=+{}~#|`^\\]$£€¤^¨]|[\\\\]|[-]";
		var chk = false;

		exp = new RegExp(symbol);
		chk = exp.test(str);
		
		return chk;
	},
	checkCharacterInString:function(str){
		var exp = "";
		var chk = false;

		exp = new RegExp("[a-zA-Z]+","g");
		chk = exp.test(str);

		return chk;
	},
	/* Build the string alias, without accentuated single, spaces, quotes, ... */
	buildAlias: function(v_s)
	{
		v_s = $p.string.formatForSearch(v_s);
		v_s = v_s.replace(/ /ig,'');
		v_s = $p.string.removeCot(v_s);
		v_s = $p.string.removeTags(v_s);
		return v_s;
	}
}

//******************** ARRAYS FUNCTIONS **************************************************************************************************************
/*
    Class: array
        Arrays functions
        
        $p.array
*/

$p.array={
	/*
	Function: find
                $p.array.find 
                
                search in an array
                
	Parameters:

		v_arr - array
		v_searched - searched string
	
	Returns:
			 result of the search (true or false)

             */
	find:function(v_arr,v_searched)
	{
		for (var i=0;i<v_arr.length;i++)
		{
			if (v_arr[i]==v_searched) return true;
		}
		return false;
	}	
}

//********************************** NAVIGATOR FUNCTIONS ******************************************************************************
/*
    Class: $p.navigator
        Navigator functions
*/
$p.navigator={
	IE:(document.all)?1:0,
	SAF:navigator.userAgent.indexOf("Safari")>=0,
	NS:navigator.userAgent.indexOf('Netscape')>0,
	OP:navigator.userAgent.indexOf('Opera')>0,
	FF:navigator.userAgent.indexOf('Firefox')>0,
    GC:navigator.userAgent.indexOf('Chrome')>0,
	/*
	Function: noinclusion
                    $p.navigator.noinclusion
                    
                    Avoid that the page is included in a frame
	*/
	noinclusion: function()
	{
		if (parent.frames.length != window.frames.length)
            top.location.href = document.location.href;
	},
	/*
	Function: addFav
                    $p.navigator.addFav
                    
                     Add application to the navigator bookmarks
	*/
	addFav:function()
	{
		var l_url=__LOCALFOLDER;
		window.external.addfavorite(l_url,lg("msgFav"));
	},
	/*
	Function: addHome
                    $p.navigator.addHome
                    
                     Add application URL to the navigator home
	*/
	addHome:function()
	{
		var l_url=__LOCALFOLDER;
		document.body.setStyle('behavior','url(#default#homepage)');
		document.body.setHomePage(l_url);
	},
	/*
	Function: changeTitle
                    $p.navigator.changeTitle
                    
                     Update the navigator title
                     
           Parameters: 
           
                      v_title - string
	*/
	changeTitle:function(v_title)
	{
		if (v_title==indef) {
            v_title = $p.app.tabs.currName
                      +(tab[$p.app.tabs.sel].nbUnread==0?""
                      :" ("+tab[$p.app.tabs.sel].nbUnread
                      +")");
        }
        document.title=__APPNAME + ' :: ' + $p.string.removeTags(v_title);
	},
	/*
	Function: getWidth
                    $p.navigator.getWidth
                    
                     Get the width of the navigator window
                     
           Returns: 
           
                      navigator window width
	*/
	getWidth:function()
	{
		if(typeof(window.innerWidth)=='number'){
			return window.innerWidth;
		}
		else if(document.documentElement && document.documentElement.clientWidth){
			return document.documentElement.clientWidth;
		}
		else if(document.body && document.body.clientWidth){
			return document.body.clientWidth;
		}
	},
	/*
	Function: getHeight
                    $p.navigator.getHeight
                    
                     Get the height of the navigator window
                     
           Returns: 
           
                      navigator window height
	*/
	getHeight:function()
	{
		if(typeof(window.innerHeight)=='number'){
			return window.innerHeight;
		}
		else if(document.documentElement && document.documentElement.clientHeight){
			return document.documentElement.clientHeight;
		}
		else if(document.body && document.body.clientHeight){
			return document.body.clientHeight;
		}
	},
	/*
		Function: addCssFile
                                $p.navigator.addCssFile *(deprecated)*
	*/
	addCssFile:function(v_css,v_title,v_rel)
	{
		$p.styles.addCssFile(v_css,v_title,v_rel);
	},
    /*
		Function: setActiveStyleSheet
                                $p.navigator.setActiveStyleSheet *(deprecated)* 
                                
	*/
	setActiveStyleSheet:function(v_css)
	{
		$p.styles.setActiveStyleSheet(v_css);
	},
    /*
		Function: nextstyle
                                $p.navigator.nextstyle *(deprecated)*  
                                
                               Select the next portal style sheet	

                      Deprecated:
                      
                                This function has moved to $p.styles
	*/
	nextstyle:function()
	{
		if ($p.navigator.NS)    {
			$p.app.alert.show(lg("msgOptNS"));
		}
		else    {
			if (tab[$p.app.tabs.sel].style==__themeList.length) tab[$p.app.tabs.sel].style=0;
			tab[$p.app.tabs.sel].style++;
			$p.styles.setActiveStyleSheet(tab[$p.app.tabs.sel].style);
			if (document.forms["option"] && document.forms["option"].selstyle) document.forms["option"].selstyle.value=__themeList[tab[$p.app.tabs.sel].style-1];
		}
	},
    /*
		Function: prevstyle
                                $p.navigator.prevstyle  *(deprecated)*  
                                
                              Select the previous portal style sheet	

                      Deprecated:
                      
                                 This function has moved to $p.styles
	*/
	prevstyle:function()
	{
		if ($p.navigator.NS) {
			$p.app.alert.show(lg("msgOptNS"));
        }
		else    {
			if (tab[$p.app.tabs.sel].style==1) tab[$p.app.tabs.sel].style=__themeList.length+1;
			tab[$p.app.tabs.sel].style--;
			$p.styles.setActiveStyleSheet(tab[$p.app.tabs.sel].style);
			if (document.forms["option"] && document.forms["option"].selstyle) {
                document.forms["option"].selstyle.value=__themeList[tab[$p.app.tabs.sel].style-1];
            }
		}
	},
	/*
		Function: openLink
                                $p.navigator.openLink *(deprecated)* 
                                
                                open an URL
        
		Parameters:

			v_url - url where page is redirected
			v_newpage - is the page opened in a new window ?
			v_uselang - 2 chars for the language of the new page (if applicable)
            
                        Returns:
                        
                                false
            
                        Deprecated:
                        
                                This function has moved to $p.url
	*/
	openLink:function(v_url,v_newpage,v_uselang)
	{
		if (v_url == indef) v_url = $p.navigator.getLocation();
		if (v_uselang) v_url = "../l10n/"+__lang+"/"+v_url;
		if (!$p.url.ishttp(v_url)) v_url = pfolder+v_url;
		if (v_newpage)
			window.open(v_url);
		else
			window.location = v_url;
		return false;
	},
	getLocation: function()
	{
		try {
			var l_location = window.location.href;
		}
		catch(e) {
			var l_location = windowLocationObject.href;
		}
		return l_location;
	},
	getProtocol: function()
	{
		try {
			var l_protocol = window.location.protocol;
		}
		catch(e) {
			var l_protocol = windowLocationObject.protocol;
		}
		return l_protocol;
	},
	/*
		Function: simpleUrl
                                $p.navigator.simpleUrl *(deprecated)* 
                                
                               Get the first part of the URL (before '?' or '#')
        
		Parameters:

			v_url - url where page is redirected
			v_newpage - is the page opened in a new window ?
			v_uselang - 2 chars for the language of the new page (if applicable)
            
                        Returns:
                        
                                first part of the URL
      
                        Deprecated:
                        
                                This function has moved to $p.url
            
	*/
	simpleUrl:function(v_url)
	{
		if (v_url.indexOf("?")>0){  v_url=v_url.substr(0,v_url.indexOf("?"));}
		if (v_url.indexOf("#")>0){v_url=v_url.substr(0,v_url.indexOf("#"));}
		return v_url;
	},
    /*
	Function: getRadioValue
                    $p.navigator.getRadioValue *(deprecated)* 
                    
                    get a radio input value
	
           Parameters:

			 radio elements
	
	Returns:
			 false or the value of the radio button selected
           
           Deprecated:
                
                                 This function has moved in $p.app.tools                   
	*/
	getRadioValue:function(v_element)
	{
		for (var i=0; i<v_element.length;i++)
		{
			if (v_element[i].checked) return v_element[i].value;
		}
		return false;
	},
    /*
	          Function: inputFocus
                                $p.navigator.inputFocus *(deprecated)*
                                
                                 Clear an input on focus	

                     Parameters:
                        
                                v_input - current input value
                                v_def - default input value
                                
                     Deprecated:
    
                     This function has moved in $p.app.tools
	*/
	inputFocus:function(v_input,v_def)
	{
		if (v_input.value==v_def)   {
			v_input.value='';
			v_input.style.color='#000000';
		}
	},
    /*
		Function: inputLostFocus
                                $p.navigator.inputLostFocus *(deprecated)* 
                                
                               Fill an input field with its default value

                     Parameters:
                        
                                v_input - current input value
                                v_def - default input value
                    
                    Deprecated:
                            
                                This function has moved in $p.app.tools
	*/
	inputLostFocus:function(v_input,v_def)
	{
		if (v_input.value=='')  {
			v_input.value=v_def;
			v_input.style.color='#aaaaaa';
		}
	},
	/*
		Function: ishttp
                            $p.navigator.ishttp  *(deprecated)* 
                        
                          Check if the URL contains 'http://' or 'https://'
		
                     Parameters:

			 URL to check
		
                     Returns:
    
			 true or false
            
                     Deprecated:

                                 This function has moved to $p.url
	*/
	ishttp:function(url)
	{
		return (url.substr(0,7)=="http://" || url.substr(0,8)=="https://");
	},
	/*
		Function: setParamInUrl
                            $p.navigator.setParamInUrl *(deprecated)* 
                        
                            Set a parameter in an URL, or replace an existing one
		
                     Parameters:

                            v_url - URL
                            v_param - parameter name
                            v_value - parameter value
		
                     Returns:
    
                            the url with the parameter and its value in it
                            
                     Deprecated:
                     
                             This function has moved to $p.url
	*/
	setParamInUrl:function(v_url,v_param,v_value)
	{
		if (v_url.indexOf("&"+v_param+"=")==-1 && v_url.indexOf("?"+v_param+"=")==-1)   {
			if (v_url.indexOf("?")==-1) {
				return v_url+"?"+v_param+"="+v_value;
			}
			else    {
				return v_url+"&"+v_param+"="+v_value;
			}
		}
		else    {
			var l_oldValue=$p.string.getVar($p.url.getParamFromUrl(v_url),v_var);
			return v_url.replace(v_param+"="+l_oldValue,v_param+"="+v_value);
		}
	},
	/*
		Function: getParamFromUrl
                            $p.navigator.getParamFromUrl  *(deprecated)* 
                        
                           Get parameters of an URL
		
                     Parameters:

                            v_url - URL
		
                     Returns:
    
                            parameters in a string
                            
                     Deprecated:
                     
                            This function has moved to $p.url
	*/    
	getParamFromUrl:function(v_url)
	{
		return v_url.substr(($p.url.simpleUrl(v_url)).length);
	},
    /*
	          Function: hideObjects
                                $p.navigator.hideObjects
                                
                                 hide Flash / activex objects
	*/
	hideObjects:function()
	{
		var l_objs=$$("object");
		for (var i=0;i<l_objs.length;i++)
		{
			l_objs[i].style.visibility='hidden';
		}
		var l_objs=$$("embed");
		for (var i=0;i<l_objs.length;i++)
		{
			l_objs[i].style.visibility='hidden';
		}
		var l_objs=$$("iframe");
		for (var i=0;i<l_objs.length;i++)
		{
			l_objs[i].style.visibility='hidden';
		}
	},
    /*
	          Function: showObjects
                                $p.navigator.showObjects
                                
                                 show Flash / activex objects
	*/
	showObjects:function()
	{
		var l_objs=$$("object");
		for (var i=0;i<l_objs.length;i++)
		{
			l_objs[i].style.visibility='visible';
		}
		var l_objs=$$("embed");
		for (var i=0;i<l_objs.length;i++)
		{
			l_objs[i].style.visibility='visible';
		}
		var l_objs=$$("iframe");
		for (var i=0;i<l_objs.length;i++)
		{
			l_objs[i].style.visibility='visible';
		}
	},
    /*
	          Function: indicatorElement
                                $p.navigator.indicatorElement
                                
                                 Indicate a specific element of the page with an arrow picture
                                 
                    Parameters: 
                    
                                 v_element- element
	*/
	indicatorElement:function(v_element)
	{
		if (v_element==null) return false;
		if ($('indicator')==null)
		{
			l_obj=new Element('img', 
				{
					'src':'../images/indicator.gif',
					'id':'indicator',
					'styles':
					{
						'position':'absolute',
						'z-index':'10002'
					},
					'events':
					{
						'click':function()
						{
							$p.navigator.hideIndicator();
						}
					}
				}
			);
			document.body.appendChild(l_obj)
		}
		$('indicator').style.top=$p.getPos(v_element,"Top")+((v_element)["offsetHeight"]/2)+"px";
		$('indicator').style.left=$p.getPos(v_element,"Left")+((v_element)["offsetWidth"]/2)+"px";
	},
    /*
	          Function: hideIndicator
                                $p.navigator.hideIndicator
                                
                                 hide the arrow picture
	*/
	hideIndicator:function()
	{
		$('indicator').destroy();
	},
    /*
	          Function: sound
                                $p.navigator.sound
                                
                                 Play sound
                     
                     Parameters:
                     
                                 v_soundFile -  (string)  sound file URL
	*/
	sound:function(v_soundFile)
	{
		if (v_soundFile == indef)
            v_soundFile = __LOCALFOLDER+'tools/beep2.swf';

		if ($('sound') == null)
		{
			var obj = new Element('div',
				{
					'id':'sound'
				}
			);
			document.body.appendChild(obj);
		}
		var l_sound = new Swiff(v_soundFile,
			{
                width:1,
                height:1,
				container: $('sound')
			}
		);
	},
	/*
		Function: getScrollX
			$p.navigator.getScrollX : get the current horizontal scrolling position
	*/
	getScrollX: function()
	{
		if (document.all)
		{
			if (!document.documentElement.scrollLeft)
			{
				return document.body.scrollLeft;
			}
			else
			{
				return document.documentElement.scrollLeft;
			}
		}
		else
        {
			return window.pageXOffset;
         }   
	},
	/*
		Function: getScrollY
			$p.navigator.getScrollY : get the current vertical scrolling position
	*/
	getScrollY: function()
	{
		if (document.all)
		{
			if (!document.documentElement.scrollTop)
			{
				return document.body.scrollTop;
			}
			else
			{
				return document.documentElement.scrollTop;
			}
		}
		else
        {
			return window.pageYOffset;
         }   
	},
	/*
	          Function: showClass
                                $p.navigator.showClass
                                
                                 Show objects with selected class
                     
                     Parameters:
                     
                                 v_class -  (string)  Class impacted
	*/
	showClass: function(v_class)
	{
		$p.addPropertyToClass(v_class, 'display', '');
	},
	/*
	          Function: hideClasses
                                $p.navigator.hideClasses
                                
                                 hide objects with selected classes
                     
                     Parameters:
                     
                                 v_classes -  (array)  Classes impacted
	*/
	hideClasses: function(v_classes)
	{
		for (var i = 0; i < v_classes.length; i++)
		{
			$p.addPropertyToClass(v_classes[i], 'display', 'none');
		}
	},
	/*
	          Function: keyPressed
                                $p.navigator.keyPressed
                                
                                 Track key pressed
                     
	*/
	keyPressed: function(v_key)
	{
		var l_key  = (window.event) ? event.keyCode : v_key.keyCode;
		var esc_key = (window.event) ? 27 : v_key.DOM_VK_ESCAPE
		if(l_key == esc_key)
		{
			// hide popup if opened
			$p.app.popup.hide();
		}
	}
}

$p.forms={
    /*
		Function: disableAllButton
                                Disable all button of a form (during ajax saving for example)
        
		Parameters:

			v_form - form object concerned           
	*/
    disableAllButton: function(v_form)
    {
        for (var i = 0; i < v_form.elements.length; i++)
        {
            v_form.elements[i].disabled = true;
        }
    },
    /*
		Function: enableAllButton
                                Enable all button of a form (after ajax saving for example)
        
		Parameters:

			v_form - form object concerned           
	*/
    enableAllButton: function(v_form)
    {
        for (var i = 0; i < v_form.elements.length; i++)
        {
            v_form.elements[i].disabled = false;
        }
    }
}



//********************************** URL FUNCTIONS **********************************************************************************
/*
    Class: $p.url

        Url functions
*/
$p.url={
        /*
		Function: openLink
                                $p.url.openLink
                                
                                Open an URL
        
		Parameters:

			v_url - url where page is redirected
			v_newpage - is the page opened in a new window ?
			v_uselang - 2 chars for the language of the new page (if applicable)
            
                        Returns:
                        
                                false
	*/
	openLink:function(v_url,v_newpage,v_uselang)
	{
		if (v_url==indef) v_url = $p.navigator.getLocation();
		if (v_uselang) v_url = "../l10n/"+__lang+"/"+v_url;
		if (!$p.url.ishttp(v_url)) v_url = pfolder+v_url;
		v_url = $p.string.correctEncoding(v_url);
		if (v_newpage)
		{
			window.open(v_url);
		}
		else
		{
			window.location = v_url;
		}
		return false;
	},
	/*
		Function: simpleUrl
                                $p.url.simpleUrl
                                
                                Get the first part of the URL (before '?' or '#')
        
		Parameters:

			v_url - url where page is redirected
			v_newpage - is the page opened in a new window ?
			v_uselang - 2 chars for the language of the new page (if applicable)
            
                        Returns:
                        
                                first part of the URL
	*/
	simpleUrl:function(v_url)
	{
		if (v_url.indexOf("?")>0){ v_url = v_url.substr(0,v_url.indexOf("?"));}
		if (v_url.indexOf("#")>0){ v_url = v_url.substr(0,v_url.indexOf("#"));}
		return v_url;
	},
    getHost: function(v_url)
    {
        var l_pos = v_url.indexOf('/',9);
        if (l_pos == -1)
        {
            return v_url;
        }
        else
        {
            return v_url.substr(0,l_pos);
        }
    },
	/*
		Function: ishttp
                            $p.url.ishttp 
                        
                            Check if the URL contains 'http://' or 'https://'
		
                     Parameters:

			 URL to check
		
                     Returns:
    
			 true or false
	*/
	ishttp:function(url)
	{
		return (url.substr(0,7)=="http://" || url.substr(0,8)=="https://");
	},
	/*
		Function: relativeToAbsolute
                            $p.url.relativeToAbsolute 
                        
                            replace a relative local url to an absolute one
		
                     Parameters:

                            v_url - URL
		
                     Returns:
    
                            formated url

	*/
	relativeToAbsolute:function(url)
	{
		return url.replace(/\.\.\//g,__LOCALFOLDER);
	},
	/*
		Function: setParamInUrl
                            $p.url.setParamInUrl 
                        
                           Set a parameter in an URL, or replace an existing one
		
                     Parameters:

                            v_url - URL
                            v_param - parameter name
                            v_value - parameter value
		
                     Returns:
    
                            the url with the parameter and its value in it
	*/
	setParamInUrl:function(v_url,v_param,v_value)
	{
		if (v_url.indexOf("&"+v_param+"=") == -1 && v_url.indexOf("?"+v_param+"=") == -1)
        {
			if (v_url.indexOf("?") == -1) {
				return v_url+"?"+v_param+"="+v_value;
			}
			else    {
				return v_url+"&"+v_param+"="+v_value;
			}
		}
		else    {
			var l_oldValue = $p.string.getVar($p.url.getParamFromUrl(v_url),v_var);
			return v_url.replace(v_param+"="+l_oldValue,v_param+"="+v_value);
		}
	},
	/*
		Function: $p.url.getParamFromUrl
                             
                            Get parameters of an URL
		
                     Parameters:

                            v_url - URL
		
                     Returns:
    
                            parameters in a string
	*/    
	getParamFromUrl:function(v_url)
	{
		return v_url.substr(($p.url.simpleUrl(v_url)).length);
	},
	/*
		Function: $p.url.isLocal 
                                Check if the URL is local

                     Parameters:

                                v_url : URL
                                
                    Returns: 
                    
			true : is local
			false : is from other server
	*/
	isLocal: function(l_url)
	{
        var l_poshHost = $p.url.getHost(__LOCALFOLDER);
		var l_check = (l_url+'/').indexOf(l_poshHost);

        if (l_check == -1)
        {
            if (l_url.substr(0,3) == '../' || l_url.substr(0,1) == '/')
                l_check = 1;
        }
        else
        {
            var l_port_check = l_url.indexOf(':', 9);
            if (l_port_check != -1){
                l_check = -1
            }
      }        
		return (l_check == -1 ? false : true);
	},
    /*
		Function: $p.url.goToAnchor 
                                Go to page HTML anchor

                     Parameters:

                                v_anchor : Anchor name
                                
	*/
    goToAnchor: function(v_anchor)
    {
			document.location = '#'+v_anchor;
	},
    /*
            function: $p.url.getAnchorTab
            
                get page id set in anchor 
                
                used in $p.app.initTabs
            
             Returns:
             
                    null/undefined
                    or
                    a string with page id
        */
    getAnchorTab: function () {
    
        var res =  $p.url.getAnchor('tab/(.+)',"tab");
        if (res) {
            return res[1];
        }
        return indef;  
    },
    /*
            Function: $p.url.getAnchor
                    get a string to searchand an index
                
             Parameters:
                    what - string to search
                    index - index to find
                    
               Returns: array     
               
               See also: <$p.url.getAnchorTab>
    */
    getAnchor: function (what,index) {
        var simplifiedLocation = "" + $p.navigator.getLocation();
        if (simplifiedLocation.indexOf(index)!=-1) {
            var re = new RegExp("\#"+what,"im");
           return simplifiedLocation.match(re);
        }
        return indef;
    },
    /*
            function: $p.url.addurlseparator
		Add a separator at the end of the url
	
		see also (test fonctionnel): 
			Format I:
				Check the widget url
				On fifefox : 
				- right click on the widget
				- select "This frame" and  "Information about the frame"
     */
     addurlseparator: function(v_url) {
        if (v_url.slice(-1) == '&' || v_url.slice(-1) == '?') {
            return v_url;
        }
        else {
            if (v_url.indexOf('?') == -1) {
                return v_url + '?';
            }
            else {
                return v_url + '&';
            }
        }
     }
}







//********************************** STYLES FUNCTIONS ******************************************************************************
/*
    Class: $p.styles
        Styles functions
*/
$p.styles={
	/*
		Function: addCssFile
                                $p.styles.addCssFile 
                                
                                add a css file to the page
                                
		Parameters:

			v_css - url of the css file
			v_title - title of the css
			v_rel -  relationship to the linked ressource
	*/
	addCssFile:function(v_css,v_title,v_rel)
	{
		var l_head = document.getElementsByTagName("head")[0];
		if (l_head == indef)
			$p.app.debug("no <head> tag in this page !");
			
		var l_css = new Element('link', 
			{ 
				'href': v_css,
				'rel': v_rel == indef ? "stylesheet" : v_rel,
				'title': v_title == indef ? "css" : v_title,
				'type': "text/css"
			}
		 );				 
		l_head.appendChild(l_css);
	},
	/*
		Function: checkTabAndSetActiveStyleSheet
			$p.styles.checkTabAndSetActiveStyleSheet
			Check if the tab style is already applied, and if not, apply the tab CSS style
	*/
	checkTabAndSetActiveStyleSheet: function(v_tab)
	{
		if (v_tab < 0)
			$p.styles.setActiveStyleSheet(1);
		else
		{
			if (v_tab == $p.app.tabs.sel 
                && $p.app.env != "admin"
				&& ($p.app.style == 0 
				|| $p.app.style != tab[v_tab].style)) {
					$p.styles.setActiveStyleSheet(tab[v_tab].style);
			}
		}
	},
    /*
		Function: setActiveStyleSheet
                                $p.styles.setActiveStyleSheet 
                                
                                Activate a stylesheet
                                
		Parameters:

			v_css - css title	
	*/
	setActiveStyleSheet:function(v_css)
	{
		var l_link;
		for(var i = 0;(l_link = document.getElementsByTagName("link")[i]); i++)
		{	if(l_link.getAttribute("rel"))
		{
				if(  l_link.getAttribute("rel").indexOf("style") != -1 && l_link.getAttribute("title"))
				{
					l_link.disabled = true;
					if (l_link.getAttribute("title") == "style " + v_css)
						l_link.disabled = false;
				}
			}
		}
		$p.app.style = v_css;
		$p.app.menu.config.oldStyle = v_css;
		$p.app.menu.place();
	},
    /*
		Function: nextstyle
                                $p.styles.nextstyle 
                                
                                Select the next portal style sheet	
	*/
	nextstyle:function()
	{
		if ($p.navigator.NS)    {
			$p.app.alert.show(lg("msgOptNS"));
		}
		else    {
			if (tab[$p.app.tabs.sel].style==__themeList.length) tab[$p.app.tabs.sel].style=0;
			tab[$p.app.tabs.sel].style++;
			$p.styles.setActiveStyleSheet(tab[$p.app.tabs.sel].style);
			if (document.forms["option"] && document.forms["option"].selstyle) document.forms["option"].selstyle.value=__themeList[tab[$p.app.tabs.sel].style-1];
		}
	},
    /*
		Function: prevstyle
                                $p.styles.prevstyle 
                                
                                Select the previous portal style sheet	
	*/
	prevstyle:function()
	{
		if ($p.navigator.NS) {
			$p.app.alert.show(lg("msgOptNS"));
        }
		else    {
			if (tab[$p.app.tabs.sel].style==1) tab[$p.app.tabs.sel].style=__themeList.length+1;
			tab[$p.app.tabs.sel].style--;
			$p.styles.setActiveStyleSheet(tab[$p.app.tabs.sel].style);
			if (document.forms["option"] && document.forms["option"].selstyle) {
                document.forms["option"].selstyle.value=__themeList[tab[$p.app.tabs.sel].style-1];
            }
		}
	}

}


//********************************* COOKIES FUNCTIONS ******************************************************************************
/*
    Class: $p.cookie
        Cookies functions
*/
$p.cookie={
	/*
		Function: check
                                $p.cookie.check 
                                
                                Check that cookies are accepted by the navigator
	*/
	check:function()
	{
		if (__showHomeBar > 0 && __defaultmode == 'anonymous')
		{
			if ((__showHomeBar==1 && document.cookie.indexOf("homebar")==-1) || __showHomeBar==2) homebar();
		}
		if (__showHomeBar==1) $p.cookie.write('homebar=1');
		accepteCookies = (navigator.cookieEnabled) ? true : false;
		if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)   {
			$p.cookie.write('homebar=1');
			accepteCookies = (document.cookie.indexOf("homebar")==-1)?false:true;
		}
		if (!accepteCookies) {
            $p.url.openLink("cookies_restriction.html",false,true);
        }
	},
	/*
		Function: write
                                $p.cookie.write 
                                
                                Write in cookie
                      
                      Parameters:

			v_vars (string) - variables to write in cookie
			v_delay (int) - cookie expires delay
	*/
	write: function(v_vars,v_delay)
	{
		var l_date = new Date();
		if (v_delay == indef) v_delay=10;
        
		l_date.setFullYear(l_date.getFullYear() + v_delay);
		document.cookie = v_vars+"; path=/; expires="+l_date.toGMTString()+";";
	},
	/*
		Function: get
                                $p.cookie.get 
                                
                                Get cookie informations
                      
                     Parameters:

			v_name - variable to extract from cookie
            
                     Returns:
                     
			 "" if cookie is not existing else cookie value
	*/    
	get: function(v_name)
	{
		var l_ret = '',
            l_name = v_name + '=';
		if (document.cookie.length > 0)
		{
			var l_arr = document.cookie.split(/;/);
			for (var i = 0; i < l_arr.length; i++)
			{
                var allcookies = l_arr[i].split(/,/);
                for (var j = 0; j < allcookies.length; j++) {
                    var peers = allcookies[j].split(/=/);
                    peers[0] = $p.string.trim(peers[0]);
                    peers[1] = $p.string.trim(peers[1]);
                    if (peers[0] == v_name) {
                        return peers[1];
                    }
                }

			}
		}
		return l_ret;
	}
}

//********************************* DATES FUNCTIONS ******************************************************************************
/*
    Class: $p.date

        Date functions
*/
$p.date={
	/*
            Function: convertFromRss
                    $p.date.convertFromRss
                    
                                 Format rss date
                                 
                                 See rfc 822 about date format allowed in RSS feeds
		
            Parameters:

			 rss extracted date
		
	 Returns:
			 javascript usable date
	*/
	convertFromRss:function(v_date)
	{
		v_date=v_date.trim();
        //bug fix to some rss date format  who set zone like that ++00:00 which is not allowed see RFC 822
        v_date = v_date.replace(/\+\+/,' +');
        v_date = v_date.replace(/\+(\d+):(\d+)/,'+$1$2');
        //end bug fix 
		v_date=v_date.replace("CEST","CST");
		var l_formatedDate,l_try;
		//RFC2822 date is recognize
		l_date=new Date(v_date);
		if (isNaN(l_date)) {l_try=v_date.substr(0,12)+"20"+v_date.substr(12);l_date=new Date(l_try);}
		//short date
		if (isNaN(l_date)) {l_try=v_date.substr(0,7)+"20"+v_date.substr(7);l_date=new Date(l_try);}
		// DB date (long)
		if (isNaN(l_date)) {l_date=new Date(v_date.substr(0,4).toInt(),(parseInt(v_date.substr(5,7),10)-1),v_date.substr(8,10).toInt(),v_date.substr(11,13).toInt(),v_date.substr(14,16).toInt(),0);}
		// DB date (short)
		if (isNaN(l_date)) {l_date=new Date(parseInt(v_date.substr(0,4),10),(parseInt(v_date.substr(5,7),10)-1),v_date.substr(8,10).toInt());}
		if (isNaN(l_date)) {l_date=new Date(v_date.substr(6,10).toInt(),(parseInt(v_date.substr(3,5),10)-1),v_date.substr(0,2).toInt());}
		//if not a valid date, date = yesterday
		if (isNaN(l_date)) {
            var l_nDate=new Date();
            l_formatedDate=new Date(l_nDate.getDate()-7,l_nDate.getMonth(),l_nDate.getYear());
        }
		else {
            l_formatedDate=l_date;
        }
		return l_formatedDate;
	},
	/*
            Function: format
                    $p.date.format
                    
                                 Format a javascript date (mm/dd/yyyy)
		
            Parameters:

			 javascript date object
		
	 Returns:
			javascript usable date. 
                                french : dd/mm/yyyy
                                other : mm/dd/yyyy
	*/
	format:function(v_date)
	{
		if (v_date==indef) return;
		var l_day=v_date.getDate();
		var l_month=v_date.getMonth()+1;
		var l_year=v_date.getFullYear();
		return (__lang=="fr"?l_day+"/"+l_month+"/"+l_year:l_month+"/"+l_day+"/"+l_year);
	},
	/*
            Function: addLeftZeros
                    $p.date.addLeftZeros
                    
                                 Add 0 on the left if necessary
		
            Parameters:

			v_s - input string
			v_length - length of the returned string
		
	 Returns:
			
                                string with new length
	*/
	addLeftZeros:function(v_s,v_length)
	{
		v_s=v_s+'';
		var nbZero = (v_length)-(v_s.length);
		for (var i=0;i<nbZero;i++)
		{
			v_s='0'+v_s;
		}
		return v_s;
	},
	/*
		Function: formatDateShort
                                $p.date.formatDateShort
                            
                                Format a javascript date
		
                    Parameters:
 
			v_date - javascript date object
			v_useTime - display time or not (true or false)
            
                     Returns:
                     
                                javascript date                               
           */
	formatDateShort:function(v_date,v_useTime)
	{
		if (v_date=='') return '';
        var l_date=(__lang=="fr"    ?   $p.date.addLeftZeros(v_date.getDate(),2)
                                    +   "/"
                                    +   $p.date.addLeftZeros((v_date.getMonth()+1),2)
                                    :   $p.date.addLeftZeros((v_date.getMonth()+1),2)
                                    +   "/"
                                    +   $p.date.addLeftZeros(v_date.getDate(),2))
					+   "/"
					+   v_date.getFullYear()
					;
                    
        if (v_useTime 
            && v_date.getHours()!=0 
            && v_date.getMinutes()!=0) {
            l_date+=", "
                  +$p.date.addLeftZeros(v_date.getHours(),2)
                  +"h"
                  +$p.date.addLeftZeros(v_date.getMinutes(),2);
        }
        
		return l_date;
	},
	/*
		Function: formatDateLong
                                $p.date.formatDateLong
                            
                                Format a javascript date (ex: 12 april 2007)
		
                    Parameters:
 
			v_date - javascript date object
			v_useTime - display time or not (true or false)
            
                     Returns:
                     
                                date                               
           */
	formatDateLong:function(v_date,v_useTime)
	{
		if (typeof(v_date)!='object') return '';
		var l_date;
        
		if (v_date.getFullYear()==_current_year 
            && v_date.getMonth()==_current_month 
            && v_date.getDate()==_current_day) {
                l_date=lg("today");
        }
		else
		{
			var yesterday=new Date();
			yesterday.setDate(yesterday.getDate()-1);
			if (v_date.getFullYear()==yesterday.getFullYear()
	           && v_date.getMonth()==yesterday.getMonth() 
	           && v_date.getDate()==yesterday.getDate())  {
	                l_date=lg("yesterday");
	        }
			else
			{
				l_date=v_date.getDate()
	                  +" "
	                  +lg("month"+(v_date.getMonth()+1))
	                  +" "
	                  +v_date.getFullYear();
			}
	    }      
		if (v_useTime 
            && v_date.getHours()!=0 
            && v_date.getMinutes()!=0)  {
                l_date+=" "
                      +lg("at")
                      +" "
                      +$p.date.addLeftZeros(v_date.getHours(),2)
                      +"h"
                      +$p.date.addLeftZeros(v_date.getMinutes(),2);
		}

		return l_date;
	},
	/*
		Function: delayFromNow
                                $p.date.delayFromNow
                                
                                Compute delay between a date and now
		
                      Parameters:

			 javascript date object
		
                     Returns:
                     
			 delay (seconds)
	*/
	delayFromNow: function(v_date)
	{
		if (v_date == indef || v_date == '') return;
		var now = _current_date;
		var l_delai = (now.getTime() - v_date.getTime()) / 1000;
		if (l_delai < -1000) l_delai=0;
		return l_delai;
	},
	/*
		Function: formatDelai
                                $p.date.formatDelai
                                
                                Format delay value
		
                      Parameters:

			 delay (seconds)
		
                      Returns:
                        
			 delay (day, hours, minuts, ...)
	*/
	formatDelai: function(v_t)
	{
		var l_ret = "";
		if (!isNaN(v_t))
		{
			if (v_t <= 60){
                l_ret = lg("lblThereIs",("1 "+lg("lblMinute")));
            }
			else if (v_t <= 3600){
                l_ret = lg("lblThereIs",(Math.floor(v_t/60)+" "+lg("lblMinute")));
            }
			else if (v_t <= 86400){
                l_ret = lg("lblThereIs",(Math.floor(v_t/3600)+" "+lg("lblHour")));
            }
			else {
                l_ret = lg("lblThereIs",(Math.floor(v_t/86400)+" "+lg("lblDay")));
            }
		}
		return l_ret;
	},
	/*
		Function: getDbFormat
                                $p.date.getDbFormat 
                                
                                Convert date to DataBase format (mm-dd-yyyy)
		
                     Parameters:

			 day, month and year
		
                     Returns:
                     
			 DB formated date
	*/
	getDbFormat:function(v_day,v_month,v_year)
	{
		v_month=("00").substr(0,2-v_month.length)+v_month;
		v_day=("00").substr(0,2-v_day.length)+v_day;
		return v_year+"-"+v_month+"-"+v_day;
	},
	/*
                    Function: convertFromDb
                                $p.date.convertFromDb
                                
                                Convert a DataBase date to javascript date object.
		
                    Parameters:

			v_date - date to be formated
		
                    Returns:
                    
			 javascript date object
	*/
	convertFromDb:function(v_date)
	{
		if (v_date == '0000-00-00') return '';
        if (v_date == '0000-00-00 00:00:00') return '';
		if (v_date == indef) return '';
		if (v_date.length < 10) return '';

		var l_month = parseInt(v_date.substr(5,2),10)-1;

		if (v_date.length == 10){
			var l_date = new Date(v_date.substr(0,4),l_month,v_date.substr(8,2));
		}
		else{
			var l_date = new Date(v_date.substr(0,4),l_month,v_date.substr(8,2),v_date.substr(11,2),v_date.substr(14,2),0);
		}
		return l_date;
	},
	/*
                    Function: getTime
                                $p.date.getTime
                                
                                get time from javascript date object.
		
                    Parameters:

			v_date - date to be formated
		
                    Returns:
                    
			 javascript time string
	*/
	getTime:function(v_date)
	{
		var l_date=$p.date.addLeftZeros(v_date.getHours(),2)
			+"h"
			+$p.date.addLeftZeros(v_date.getMinutes(),2);
		return l_date;
	}
}



//********************************* TAG FUNCTIONS ******************************************************************************
/*
    Class: $p.tags

        Tags functions
*/
$p.tags={
	/*
            Function: formatList
                    $p.tags.formatList
                    
                                 Format a tags list
		
            Parameters:

			 v_s - string list of tags
		
	 Returns:
     
			 string list of tags formatted
	*/
	formatList:function(v_s)
	{
		var l_s=$p.string.removeTags($p.string.lc(v_s.trim()));
		while (l_s.indexOf("  ")!=-1) l_s=l_s.replace(/  /g," ");
		l_s=l_s.replace(",,",",");
		l_s=l_s.replace(", ,",",");
		if (l_s.slice(-1)==",") l_s=l_s.substr(0,l_s.length-1);
		if (l_s.substr(0,1)==",") l_s=l_s.substr(1);
		return l_s;
	},
	/*
            Function: separate
                    $p.tags.separate
                    
                                 add spaces between tags
		
            Parameters:

			 v_s - string list of tags
		
	 Returns:
     
			 string list of tags formatted
	*/
	separate:function(v_s)
	{
		return v_s.replace(/,/g,', ');
	}
}



//********************************* TAG AUTOCOMPLETION FUNCTIONS ******************************************************************************
/*
    Class: $p.tags.autocompletion

        Tags autocompletion functions
*/
$p.tags.autocompletion={
	lastTagWithNoResult:"",
	currentInput:"",
	lastAjaxHandle:-1,
	/*
		Function: get
                                $p.tags.autocompletion.get
                                
                                Get autocompletion tags
		
                    Parameters:

			 v_id - input id
			 v_file - xml file called for data displayed in autocompletion
             
                     Ajax:
                     
                                Call the file "xmlautocompletion (php)" to get all the keywords alike in the database
                                The callback function is $p.tags.autocompletion.display
	*/
	get: function(v_id,v_file)
	{
        if (__restrictOnExistingTags == true) return;

		$p.tags.autocompletion.currentInput = v_id;
		var l_input = $(v_id),
            l_inputValue = l_input.value,
            l_pos = 0,
            fileLink = (v_file == indef ? posh["xmlautocompletion"] : v_file);

		//kill the previous ajax autocompletion call
		if ($p.tags.autocompletion.lastAjaxHandle != -1 
            && $p.ajax.xmlhttp[$p.tags.autocompletion.lastAjaxHandle]!=null) {
                $p.ajax.xmlhttp[$p.tags.autocompletion.lastAjaxHandle].abort(); 
        }    
		// get the current word
		while (l_inputValue.indexOf(",",l_pos) != -1)
		{
			l_pos = l_inputValue.indexOf(",",l_pos)+1;
		}
		var l_word = l_inputValue.substr(l_pos);
		l_word = $p.string.formatForSearch(l_word);

		if (l_word.length > 2 
            && ($p.tags.autocompletion.lastTagWithNoResult == "" 
            || l_word.indexOf($p.tags.autocompletion.lastTagWithNoResult) != 0))
        {
                $p.tags.autocompletion.lastTagWithNoResult = "";
                $p.tags.autocompletion.lastAjaxHandle = getXml(
                    fileLink+"?tag="+l_word,
                    $p.tags.autocompletion.display,
                    new Array(v_id,l_word)
                );
		}
		else {
			$p.tags.autocompletion.hide();
		}
	},
	/*
		Function: display
                                $p.tags.autocompletion.display
                                
                                Display tags corresponding in the database
		
                    Parameters:

			 response - Object XML document
                                 vars
	*/
	display: function(response,vars)
	{
		var l_divName = vars[0]+"_autocomp";
		var l_result = response.getElementsByTagName("tag");
		if (l_result.length > 0)
		{
            var l_inputObj = $(vars[0]);
			if ($(l_divName) == null)
			{
				$p.tags.autocompletion.buildBox(l_divName,l_inputObj);
			}
			else
            {
                $p.tags.autocompletion.positionBox(l_divName,l_inputObj);
            }
		
			var l_s = "<table width='100%'>",
                l_label = "";

			for (var i = 0;i < l_result.length;i++)
			{
				l_label = $p.ajax.getVal(l_result[i],"label","str",false,"???");
				l_s += "<tr>"
                    + "<td class='unselected' onmouseout=\"this.className='unselected';\" onmouseover=\"this.className='selected';\" onmousedown=\"$p.tags.autocompletion.select('"+l_label+"')\">"
                    + l_label
                    + "</td>"
                    + "</tr>";
			}
			l_s += "</table>";
            
			//if only one result corresponding to word typed, hide autocompletion
			if (l_result.length == 1 && l_label == vars[1])  {
                $p.tags.autocompletion.hide();
            }
			else   {
                $p.print(l_divName,l_s);
            }
		}
		else if (response.getElementsByTagName("notag")[0])
		{
			$p.tags.autocompletion.lastTagWithNoResult = vars[1];
			$p.tags.autocompletion.hide();
		}
	},
	/*
		Function: select
                                $p.tags.autocompletion.select
                                
                                Select a tag in the autocompletion list
		
                     Parameters:

			v_label - tag label selected
	*/
	select: function(v_label)
	{
		var l_input = $($p.tags.autocompletion.currentInput);
		var l_inputValue = l_input.value;
		var l_pos = 0;
		while (l_inputValue.indexOf(",",l_pos) != -1)
		{
			l_pos = l_inputValue.indexOf(",",l_pos)+1;
		}
		//replace last word with selected one
		($($p.tags.autocompletion.currentInput)).value = l_inputValue.substr(0,l_pos)+v_label;
		$p.tags.autocompletion.hide();
		($($p.tags.autocompletion.currentInput)).focus();
	},
	/*
		Function: hide
                                $p.tags.autocompletion.hide
                                
                                Hide the autocompletion list
	*/
	hide: function()
	{
		$p.show($p.tags.autocompletion.currentInput+"_autocomp","none");
		if ($p.tags.autocompletion.lastAjaxHandle != -1 && $p.ajax.xmlhttp[$p.tags.autocompletion.lastAjaxHandle] != null)
            $p.ajax.xmlhttp[$p.tags.autocompletion.lastAjaxHandle].abort();
		$p.tags.autocompletion.lastAjaxHandle = -1;
	},
	buildBox: function(v_divName,v_inputObj)
	{
		l_obj = new Element('div', 
			{
				'styles': {
							'top': $p.getPos(v_inputObj,"Top")+(v_inputObj)["offsetHeight"]+2+"px",
							'left': $p.getPos(v_inputObj,"Left")+"px",
							'width': (v_inputObj)["offsetWidth"]+"px"
						  },
				'id': v_divName,
				'class': 'autocompletion'
			}
		);
		document.body.appendChild(l_obj);
	},
	positionBox: function(v_divName,v_inputObj)
	{
		$(v_divName).style.top = $p.getPos(v_inputObj,"Top")+(v_inputObj)["offsetHeight"]+2+"px";
		$(v_divName).style.left = $p.getPos(v_inputObj,"Left")+"px";
		$(v_divName).style.width = (v_inputObj)["offsetWidth"]+"px";
		$p.show(v_divName,"block");
	}
}

$p.tags.selectBox={
    /*
		Function: build
                                $p.tags.selectBox.build
                                
                                build the tags select box
                      Parameters:
                                v_inputObj : tags input object
	*/
    build: function(v_inputObj)
    {
        if (__restrictOnExistingTags == false) return;

        var l_size = v_inputObj.style.width;
        if (l_size == '')
            l_size = 400;
        
        var l_inputId = v_inputObj.id;

        var l_s = $p.html.roundBox(
            lg('selectTags')
            + "<br /><br />"
            + "<div class='tagselectbox' id='"+l_inputId+"_tagslist'></div>"
            + "<br /><center><input type='button' onclick=\"$p.tags.selectBox.close('"+l_inputId+"')\" value='"+lg('lblClose')+"'></center><br />",
            '#E9EDF2',
            l_size+'px'
            );
        if ($(l_inputId+'_tagspopup') == null)
        {
            var l_tagspopup = new Element('div',
                {
                    'id':l_inputId+'_tagspopup'
                }
            );
        }
        else
        {
            var l_tagspopup = $(l_inputId+'_tagspopup');
            l_tagspopup.style.display = 'block';
        }
        l_tagspopup.set('html',l_s);

        //insert the tag select box over the input
        v_parentObj = v_inputObj.parentNode;
        v_parentObj.insertBefore(l_tagspopup,v_inputObj);
        v_inputObj.style.display = 'none';
        

        $p.tags.selectBox.input = v_inputObj;
        $p.tags.selectBox.load(l_inputId);
    },
    /*
		Function: load
                                $p.tags.selectBox.load
                                
                                load the tags
                      Parameters:
                                v_divid : ID(unique) of the div container
	*/
    load: function(v_divid)
    {
        $p.ajax.call(posh["xmlautocompletion"]+'?tag=',
            {
                'type':'load',
                'callback':
                {
                    'function':$p.tags.selectBox.display,
                    'variables':
                    {
                        'divid':v_divid
                    }
                }
            }
        );
    },
    display: function(response,vars)
    {
        var l_result = response.getElementsByTagName('tag');
        var l_s = '';
        var l_currentTags = $(vars['divid']).value;
        
        for (var i = 0;i < l_result.length;i++)
        {
            var l_label = $p.ajax.getVal(l_result[i],'label','str','');
            var l_class = (l_currentTags.indexOf(l_label) == -1 ? 'notselected' : 'selected');
            l_s += '<a href="#" class="'+l_class+'" onclick=\'$p.tags.selectBox.select(this,"'+vars['divid']+'");return false;\'>'+l_label+'</a> ';
        }

        $p.print(vars['divid']+'_tagslist',l_s);
    },
    /*
		Function: select
                                $p.tags.selectBox.select
                                
                                select a tag
                      Parameters:
                                v_tagObj : tag item
	*/
    select: function(v_tagObj,v_divid)
    {
        if (v_tagObj.className == 'notselected')
        {
            v_tagObj.className = 'selected';
            $p.tags.selectBox.add(v_tagObj.innerHTML,v_divid);
        }
        else
        {
            v_tagObj.className = 'notselected';
            $p.tags.selectBox.remove(v_tagObj.innerHTML,v_divid);
        }
    },
    /*
		Function: add
                                $p.tags.selectBox.add
                                
                                add a tag
                      Parameters:
                                v_tag : (string) tag added
	*/
    add: function(v_tag,v_divid)
    {
        var inputObj = $(v_divid);
        var l_currentTags = (inputObj.value == lg("keywords") ? '' : inputObj.value);
        
        if (l_currentTags.indexOf(v_tag+',') == -1)
        {
            l_currentTags += v_tag+',';
        }
        inputObj.value = l_currentTags;
    },
    /*
		Function: remove
                                $p.tags.selectBox.remove
                                
                                remove a tag
                      Parameters:
                                v_tag : (string) tag added
	*/
    remove: function(v_tag,v_divid)
    {
        var inputObj = $(v_divid);
        var l_currentTags = inputObj.value;
        l_currentTags = l_currentTags.replace(v_tag+',','');
        inputObj.value = l_currentTags;
    },
    /*
		Function: close
                                $p.tags.selectBox.close
                                
                                close the selectbox
                      Parameters:
                                v_divid : ID(unique) of the div container
	*/
    close: function(v_divid)
    {
        $(v_divid).style.display = 'block';
        $(v_divid+'_tagspopup').empty();
        $(v_divid+'_tagspopup').style.display = 'none';
    }
}


//********************************* EFFECTS FUNCTIONS ******************************************************************************
/*
    Class: $p.effect

        Effect functions
*/
$p.effect={
	obj:{},
	opacity:0,
	timer:0,
	actionTriggered:indef,
	/*
		Function: fadein
                                $p.effect.fadein 
                               
                                Initialise the fadein effect
                           
                      Parameters:
                      
                                 v_obj - Object to make fadein on
                                 v_triggerAction - Javascript function launched while the effect is applying
                                 v_limit - Opacity of the effect
	*/
	fadein:function(v_obj,v_triggerAction,v_limit)
	{
		if($p.effect.timer!=0) clearTimer($p.effect.timer);
		if (v_limit==indef) v_limit=1;
		//if ($p.effect.timer) clearTimeout($p.effect.timer);
		$p.effect.obj=v_obj;
		$p.effect.opacity=0;
		if (v_triggerAction!=indef) $p.effect.actionTriggered=v_triggerAction;
		$p.effect.fadeinaction(v_limit);
		$p.effect.obj.setStyle("display","block");
	},
	/*
		Function: fadeinaction
                                $p.effect.fadeinaction 
                               
                                Apply fadein effect to an object
                           
                      Parameters:
                      
                                 v_obj - Object to make fadein on
                                 v_triggerAction - Javascript function launched while the effect is applying
                                 v_limit - Opacity of the effect
	*/
	fadeinaction:function(v_limit)
	{
		$p.effect.opacity+=0.1;
		$p.effect.obj.setOpacity(""+$p.effect.opacity);
		$p.effect.obj.setStyle("filter","alpha(opacity="+($p.effect.opacity*100)+")");
		if ($p.effect.opacity>=v_limit)  {
			if ($p.effect.actionTriggered!=indef)  {
				if (typeof($p.effect.actionTriggered)=='object')  {
					for (var i=0;i<$p.effect.actionTriggered.length;i++)
					{
						eval($p.effect.actionTriggered[i]);
					}
				}
				else  {
					eval($p.effect.actionTriggered);
				}
				$p.effect.actionTriggered=indef;
			}
			clearTimer($p.effect.timer);
		}
		else  {
			$p.effect.timer=setTimeout("$p.effect.fadeinaction("+v_limit+")",70);
		}
	},
	/*
		Function: fadeout
                                $p.effect.fadeout 
                               
                                Initialise the fadeout effect
                           
                      Parameters:
                      
                                 v_obj - Object to make fadeout on
	*/
	fadeout:function(v_obj)
	{
		if($p.effect.timer!=0) clearTimer($p.effect.timer);
		$p.effect.obj=v_obj;
		$p.effect.opacity=1;
		$p.effect.fadeoutaction();
	},
	/*
		Function: fadeoutaction
                                $p.effect.fadeoutaction 
                               
                                Apply fadeout effect to an object
	*/
	fadeoutaction:function()
	{
		$p.effect.opacity-=0.1;
		$p.effect.obj.setOpacity(""+$p.effect.opacity);
		$p.effect.obj.setStyle("filter","alpha(opacity="+($p.effect.opacity*100)+")");
		if ($p.effect.opacity>0){
			$p.effect.timer=setTimeout("$p.effect.fadeoutaction()",70);
		}
		else{
			$p.effect.obj.setStyle("display","none");
			clearTimer($p.effect.timer);
		}
	}
}    
    
    
//********************************* BASE64 FUNCTIONS ******************************************************************************
/*
    Class: $p.Base64

        Base64 encode
        
        <http://www.webtoolkit.info/>
*/

$p.Base64={
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    /*
		Function: encode
                                $p.Base64.encode 
                               
                                Encode a string in Base64
                           
                      Parameters:
                      
                                 input - string to encode
                      
                      Returns:
                        
                                 encoded string     
	*/    
    encode:function(input)
	{
		if (input=="" || input==":") return "";
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		input = $p.Base64._utf8_encode(input);
		while (i < input.length)
		{
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2))    {
				enc3 = enc4 = 64;
			}
			else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output 
                   + this._keyStr.charAt(enc1) 
                   + this._keyStr.charAt(enc2) 
                   + this._keyStr.charAt(enc3) 
                   + this._keyStr.charAt(enc4);
		}
		return output;
	},
	/*
		Function: _utf8_encode
                                $p.Base64._utf8_encode 
                               
                                Encode a string in utf8
                           
                      Parameters:
                      
                                 string - string to encode
                      
                      Returns:
                        
                                 encoded string     
	*/
	_utf8_encode:function(string)
	{
		string = string.replace(/ /g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++)
		{
			var c = string.charCodeAt(n);
			if (c < 128)    {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048))    {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else    {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	}    
}




//********************************* AJAX FUNCTIONS ******************************************************************************
/*
    Class: $p.ajax

        Ajax functions
*/
$p.ajax={
	requestId:0,
	requests:[],
	_WAITING:0,
	_RUNNING:1,
	xmlhttp_handle:0,
	xmlhttp:[],
	executeRequest_running:false,
	executeRequest_waitingNb:0,
	/*
		Function: $p.ajax.xhr 

                                Create the xmlhttprequest object based on navigator compatibility
                        
                    Returns:
                    
                                XmlHttpRequest object (object) 
	*/
	xhr:function()
	{
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e){}
		try{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){}
		try{
			return new XMLHttpRequest();
		}
		catch(e){}
		$p.app.alert.show(lg("msgXMLnav"));
		return null;
	},
	/*
	         Function: $p.ajax.chooseTunnel
                            
                            Define tunnel script 
		
                    Parameters:

			v_url(string) - url of the file to read
			v_vars(string) - GET/POST varialbes sent to the file to read
			v_type(string) - type of the returned file XML/HTML
                
                    Returns:
                    
                                File to open, containing tunnel file (string).
	*/
	chooseTunnel:function(v_url,v_vars,v_type,pfolder)
	{
		var l_feed;
        
		// if url not on the same domain, use tunnel
		if ($p.url.ishttp(v_url))
		{
			//if file is located on the current server
			if (v_url.substr(v_url.indexOf(':') + 3, (location.hostname).length) == location.hostname) {
				l_feed = v_url;
			}
			else
			{
				if (__useproxy)
				{
					if (__proxypacfile=="")
					{
						if (v_vars==indef 
                            || $p.string.getVar(v_vars,"auth")=="") {
                                l_feed=pfolder+posh["xmltunproxy"]+"?ptyp="+v_type+"&url="+$p.string.esc(v_url);
						}
						else{
							l_feed=pfolder+posh["xmltunproxy"]+"?ptyp="+v_type+"&url="+$p.string.esc(v_url)+"&auth="+$p.string.getVar(v_vars,"auth");
						}
					}
					else
					{
						if (getProxy(v_url)==""){
							l_feed=pfolder+posh["xmltun"]+"?ptyp="+v_type+"&url="+$p.string.esc(v_url);
						}
						else{
							l_feed=pfolder+posh["xmltunproxypac"]+"?ptyp="+v_type+"&url="+$p.string.esc(v_url)+"&proxy="+getProxy(v_url);
						}
					}			
				}
				else
				{
					if (v_vars==indef 
                        || $p.string.getVar(v_vars,"auth")=="") {
                            l_feed=pfolder+posh["xmltun"]+"?ptyp="+v_type+"&url="+$p.string.esc(v_url);
					}
					else
					{
						l_feed=pfolder+posh["xmltunauth"]+"?ptyp="+v_type+"&auth="+$p.string.getVar(v_vars,"auth")+"&url="+$p.string.esc(v_url);
					}
				}
			}
		}
		else    {
			l_feed=v_url.substr(0,3)=="../"?v_url:pfolder+v_url;
		}
		return l_feed;
	},
	/*
	     Function: $p.ajax.call
                            ajax call function
		
                See <$p.ajax.execute > for call with execute type
        
                Parameters:

                            v_url(string) - url of the page called
                            v_param(associative array) - parameters used for this call (refer to the online documentation)
                            
                          >     $p.ajax.call(
                          >                 'server script to execute?param=optional',
                          >                 {
                          >                     'type':'load',       //more current
                          >                     'variables':'param='+'value',
                          >                     'method':'post',        //default method is post
                          >                     'callback':{
                          >                                  'function':*functiontotreatresponse*,
                          >                                 'variables':
                          >                                             {'param':'tosendtocallbackfunction',
                          >                                             'param2':'value2'
                          >                                 }
                          >                     },
                          >                     'source':'xml'  //default xml, but you can use *json* ou *txt* or *html*, json send back a js variable
                          >                 }
                          >     );
                          >    function  functiontotreatresponse (response,vars) {
                          >             response can contains *xml object* if source is not set or set to xml
                          >             response can contains a *js variable* if source = json
                          >             resposne contains a *string* if you give source=hml or source=txt
                          >     }
                            
                Returns:
                
                            error code
	*/
	call:function(v_url,v_param)
	{
		var l_noerror = true,l_msg,l_err;
		var l_type = (v_param['source'] == indef ? "xml" : v_param['source']);
		var l_method = (v_param['method'] == indef ? "GET" : v_param['method']);
		var l_async = (v_param['asynchron'] == indef ? true : v_param['asynchron']);
		if (!pfolder)
            pfolder = "";
		var l_priority = (v_param['priority'] == indef ? 2 : v_param['priority']);
		
		// for https compliancy
		v_url = $p.changeProtocol(v_url);
		
		if (v_param['callback'] == indef)
            v_param['callback'] = "";
		
		if (v_param['type']=='load')    {
			$p.ajax.requests.push(new $p.ajax.request("load",[v_url,v_param['callback']['function'],v_param['callback']['variables'],l_type,v_param['variables'],l_method,v_param['escape'],l_async],l_priority,indef,indef,v_param['caller']));
			$p.ajax.executeRequests();
			return false;
		}
		else
		{
			if (allowSave
                || (v_param['forceExecution'] && !demoMode))   {
                    $p.ajax.requests.push(new $p.ajax.request("execute",[v_url,v_param['variables'],v_param['alarm'],v_param['callback']['function'],l_async,v_param['callback']['variables']],l_priority));
                    $p.ajax.executeRequests();

			}
			if (demoMode)
			{
				$p.app.alert.show(lg('demoMode'));
			}
			var l_feed = pfolder + v_url;
			//debug - display debug even if no error return
			$p.app.debug("execute : "+l_feed+" (variables: "+v_param['variables']+")");
			return;
		}
	},
	/*
	         Function: $p.ajax.request

                            new ajax process object
		
                    Parameters:

                            type(string) -  'execute', 'load'
                            action(string) - 
                            priority(int) - 1=high priority, 2=normal, 3=low priority
                            status(int) - 0=waiting , 1=running,  2=cancelled
                            loop(int) - loop number (process can be launch several times)
                            callerId(string) - ID of the function calling the request
	*/
	request: function(type,action,priority,status,loop,callerId)
	{
        this.handle = 0;
		this.type = type;
		this.uniqId = $p.ajax.requestId;
		$p.ajax.requestId++;
		this.action = action;
		this.priority = (priority == indef ? 2 : priority);
		this.status = (status == indef ? $p.ajax._WAITING : status);
		this.loop = (loop == indef ? 1 : loop);
        this.callerId = (callerId == indef ? '' : callerId);
        this.kill = $p.ajax.kill;
	},
	/*
		Function: $p.ajax.executeRequests 

                                Launch ajax process based on their priority (queue managed)
	*/
	executeRequests:function()
	{
		//avoid that concurrent treads execution function calls runs
		if (!$p.ajax.executeRequest_running)    {
			$p.ajax.executeRequest_waitingNb=0;
		}
		else    {
			$p.ajax.executeRequest_waitingNb++;
			return;
		} 
		$p.ajax.executeRequest_running=true;		
		var l_requests=$p.ajax.requests;
		//sort by status and priority
		l_requests.sort($p.ajax.sortRequests);
		
		//($p.ajax.requests).sort($p.ajax.sortRequests);
		var l_nbRunning=0;
		for (var i=0;i<l_requests.length;i++)
		{
			if (l_requests[i].status==$p.ajax._RUNNING) l_nbRunning++;
			if (l_nbRunning==2) break;
			if (l_requests[i].status==$p.ajax._WAITING) {
				l_requests[i].status=$p.ajax._RUNNING;
				if (l_requests[i].type=="execute")  {
                   //l_requests[i].handle = 0;
					$p.ajax.execute(i);
				}
				else    {
					l_requests[i].handle = $p.ajax.load(i);
				}
			}
		}

		//check if processes are waiting for execution
		$p.ajax.executeRequest_running=false;
		if ($p.ajax.executeRequest_waitingNb!=0) $p.ajax.executeRequests();
	},
	/*
		Function: $p.ajax.sortRequests
                                 
                                Sort ajax processes based on their status, ID and priority
                                
                      Parameters: 
                      
                                 a - Ajax Object
                                 b - Ajax Object
	*/
	sortRequests:function(a,b)
	{
		if (a.status<b.status) return 1;
		if (a.status>b.status) return -1;
		if (a.priority<b.priority) return -1;
		if (a.priority>b.priority) return 1;
		if (a.uniqId<b.uniqId) return -1;
		if (a.uniqId>b.uniqId) return 1; 
	},
	/*
		Function: $p.ajax.execute   

                        Execute script with ajax process
                        
                        >$p.ajax.call(posh["scr_addmodule_othertab"],
                        >   {
                        >        'type':'execute',
                        >        'variables':"src="+tab[$p.app.tabs.sel].id+"&dest="+tab[v_desttab].id+"&tabdest="+v_desttab+"&uniq="+v_uniq,
                        >        'alarm':false,
                        >        'forceExecution':false,
                        >        'callback':
                        >        {
                        >            'function':$p.app.widgets.addInNewTab,
                        >             'variables':{'key':value}
                        >        }
                        >    }
                        >); 
                        > and callback function
                        > addInNewTab:function(v_ret,vars) { .... }
                        >
                        callback function get 2 parameters: 
                        ret : If server script return ret xml tag, this data will be send in ret variable
                        vars: variables added to callback function
                         
                         If there is no ret xml tag , it is possible to add a variable to function, it will be sent as ret parameter
 
                      Parameters:
                      
                                v_id (integer) - id of the ajax request to launch (script execution)
	*/
	execute:function(v_id)
	{
		var l_requestUniqId=$p.ajax.requests[v_id].uniqId;
		var v_scr="";
		if($p.ajax.requests[v_id].action[0]){ v_scr = $p.ajax.requests[v_id].action[0]; }
		var v_vars="";
		if($p.ajax.requests[v_id].action[1]){ v_vars = $p.ajax.requests[v_id].action[1]; }
		var v_alarm="";
		if($p.ajax.requests[v_id].action[2]){ v_alarm = $p.ajax.requests[v_id].action[2]; }
		var fct=$p.ajax.requests[v_id].action[3];
		if($p.ajax.requests[v_id].action[3]){ fct = $p.ajax.requests[v_id].action[3]; }
		var v_async=$p.ajax.requests[v_id].action[4];
		if($p.ajax.requests[v_id].action[4]){ v_async = $p.ajax.requests[v_id].action[4]; }
		var fctvars=$p.ajax.requests[v_id].action[5];
		if($p.ajax.requests[v_id].action[5]){ fctvars = $p.ajax.requests[v_id].action[5]; }

		$p.app.setAsWorking();
		var xmlhttp=null;

		xmlhttp = $p.ajax.xhr();
		if (xmlhttp==null) l_noerror=false;

		if (v_async)
		{
			xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState == 4){
					$p.ajax.endRequest(l_requestUniqId);

					if (xmlhttp.status >= 400){
						$p.app.debug("Xml file not read : "+v_scr,"error");
						$p.app.connection.test();
						l_noerror=false;
					}
					else{
						$p.ajax.callbackExecution(xmlhttp,v_alarm,fct,fctvars,v_scr);
					}
					$p.app.setAsWorking(false);
				}
			}
		}
		var l_feed=pfolder+v_scr;
		xmlhttp.open("POST",l_feed, v_async);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlhttp.send(v_vars);

		if (!v_async){
			$p.ajax.callbackExecution(xmlhttp,v_alarm,fct,fctvars,v_scr);
			$p.ajax.endRequest(l_requestUniqId); // kill ajax process when non asynchron mode
		}
		//$p.app.debug("execute : "+l_feed+" (variables: "+( (v_vars && v_vars.indexOf('pass')==-1) ? v_vars : '***')+")");
	},
 	/*
		Function: $p.ajax.callbackExecution 
                            
                                Execute the callback function
                      
                     Parameters: 
                     
                                xmlhttp - xmlHttp Object
                                v_alarm - display an alarm or not, boolean (true,false)
                                fct - function callled
                                fctvars - parameters of the function
                                v_scr - 
	*/   
	callbackExecution:function(xmlhttp,v_alarm,fct,fctvars,v_scr)
	{
		if(xmlhttp.responseXML != null )
		{
			if (xmlhttp.responseXML.getElementsByTagName("status")[0])
			{
				if (xmlhttp.responseXML.getElementsByTagName("msg")[0]) var l_msg=$p.ajax.getVal(xmlhttp.responseXML,"msg","str",false,lg("msgXMLerror")+"(1)");
				if (xmlhttp.responseXML.getElementsByTagName("err")[0]) var l_err=$p.ajax.getVal(xmlhttp.responseXML,"err","str",false,lg("msgXMLerror")+"(2)");
				if (xmlhttp.responseXML.getElementsByTagName("ret")[0]) var l_ret=xmlhttp.responseXML.getElementsByTagName("ret")[0].firstChild.nodeValue;
				if (v_alarm && l_msg)
				{
					$p.app.alert.show(lg(l_msg),1);
				}
				if (v_alarm && l_err)
				{
					$p.app.alert.show(lg(l_err),3);
				}
				if (fct && !l_err)
				{
					if (l_ret){
						if (fctvars==indef){fct(l_ret);}else{fct(l_ret,fctvars);}
					}
					else{
						if (fctvars==indef){fct();}else{fct(fctvars);}
					}
				}
			}
			else
			{
				$p.app.debug("Xml file not correct : "+v_scr,"error");
				$p.app.debug("Content read or status tag missing : "+xmlhttp.responseText,"error");
				if (xmlhttp.responseXML.getElementsByTagName("disconnected")[0]) return $p.app.connection.errorTest();
				l_noerror=false;
			}
		}
		$p.app.setAsWorking(false);
	},
	/*
		 Function: $p.ajax.load
                                                        
                                Load data with ajax process
                      
                      Parameters:
                                
                                v_id : id of the ajax request
                                
                      Returns: 
                      
                                l_handle
	*/
	load:function(v_id)
	{
		var l_requestUniqId=$p.ajax.requests[v_id].uniqId;

		var v_url=$p.ajax.requests[v_id].action[0];
		var fct=$p.ajax.requests[v_id].action[1];
		var v_fctvars=$p.ajax.requests[v_id].action[2];
		var v_type=$p.ajax.requests[v_id].action[3];
		var v_vars=$p.ajax.requests[v_id].action[4];
		var v_method=$p.ajax.requests[v_id].action[5];
		var v_escapefct=$p.ajax.requests[v_id].action[6];
		var v_async=$p.ajax.requests[v_id].action[7];

		Function: $p.ajax.xmlhttp_handle++;
		var l_handle=$p.ajax.xmlhttp_handle;
		$p.ajax.xmlhttp[l_handle]=null;

		$p.ajax.xmlhttp[l_handle] = $p.ajax.xhr();

		var xhrTimeout = setTimeout(function(l_handle,v_id,v_url,v_escapefct)
		{
			if ($p.ajax.xmlhttp[l_handle]==indef) return;
			$p.ajax.xmlhttp[l_handle].abort();
			$p.ajax.xmlhttp[l_handle].onreadystatechange = function(){};
			
			if ($p.ajax.requests[v_id].loop<3)  {
				//relaunch process with lowest priority
				$p.app.debug("Relaunch : "+v_url,"error");
				$p.ajax.requests[v_id].loop++;
				$p.ajax.requests[v_id].priority=3;
				$p.ajax.requests[v_id].status=$p.ajax._WAITING;
			}
			else    {
				$p.app.debug("Abort xml file reading : "+v_url,"error");
				$p.ajax.endRequest($p.ajax.requests[v_id].uniqId);
				if (v_escapefct!=indef) v_escapefct();
			}
			$p.ajax.executeRequests();
		}, $p.ajax.requests[v_id].loop*10000);

		if (v_async)
		{
			$p.ajax.xmlhttp[l_handle].onreadystatechange = function()
			{
				if ($p.ajax.xmlhttp[l_handle].readyState == 4)
				{
					clearTimeout(xhrTimeout);
					if ($p.ajax.xmlhttp[l_handle].status >= 400)
					{
						$p.app.debug("Xml file not read : "+v_url+" (status "+$p.ajax.xmlhttp[l_handle].status+")","error");
						$p.app.debug("Content read : "+$p.ajax.xmlhttp[l_handle].responseText,"error");
						$p.ajax.xmlhttp[l_handle].onreadystatechange = function(){};
						$p.ajax.xmlhttp[l_handle]=null;
						$p.ajax.endRequest(l_requestUniqId);

						if (v_escapefct!=indef) v_escapefct();
						else $p.app.connection.test();
					}
					else
					{
						$p.ajax.xmlhttp[l_handle].onreadystatechange = function(){};
						$p.ajax.callback(l_requestUniqId,l_handle,fct,v_fctvars,v_type);
					}
				}
			}
		}

		//if rss feed, check proxy settings
		if (v_vars!=indef 
            && $p.string.getVar(v_vars,"rssurl")!="" 
            && __proxypacfile!="")  {
                v_vars+="&proxy="+getProxy($p.string.getVar(v_vars,"rssurl"));
		}
		l_feed=$p.ajax.chooseTunnel(v_url,v_vars,v_type,pfolder);

		$p.ajax.xmlhttp[l_handle].open(v_method,l_feed,v_async);
		if (v_method=="GET")
		{
			$p.ajax.xmlhttp[l_handle].send(null);
		}
		else
		{
			$p.ajax.xmlhttp[l_handle].setRequestHeader('Content-Type','application/x-www-form-urlencoded');

			$p.ajax.xmlhttp[l_handle].send(v_vars);
		}

		if (!v_async) // kill ajax process when non asynchron mode
		{
			$p.ajax.callback(l_requestUniqId,l_handle,fct,v_fctvars,v_type);
			clearTimeout(xhrTimeout);
			$p.ajax.endRequest(l_requestUniqId); 
		}
		//debug (need to activate debug mode)
		$p.app.debug("read "+v_type+" : "+l_feed+" (variables: "+v_vars+")");

		return l_handle;
	},
	/*
		Function: $p.ajax.callback 
                        
                                Call function when ajax loading done
                     
                     Parameters: 
                     
                                 v_requestId - id of the request
                                 v_handle(int) - process uniq number
                                 v_fct - callback functions
                                 v_vars - callback functions parameters
                                 v_type - format XML (default) or json (evaluated) or any string will send txt
	*/
	callback:function(v_requestId,v_handle,v_fct,v_vars,v_type)
	{
		var l_ret=  (v_type=="xml")   ?     $p.ajax.xmlhttp[v_handle].responseXML            :
                    (v_type=="json")   ?     eval('('+$p.ajax.xmlhttp[v_handle].responseText+')')    :
                                            $p.ajax.xmlhttp[v_handle].responseText;
		$p.ajax.xmlhttp[v_handle]=null;
		$p.ajax.endRequest(v_requestId);
		
		if (v_fct 
            && typeof(v_fct)=="function") {
                v_fct(l_ret,v_vars);
		}
		else    {
			$p.app.debug("getXml Error : callback function is not existing !","error");
		}
	},
	/*
		Function: $p.ajax.endRequest
                                                               
                               Remove request
		
                Parameters:

			v_uniqId - uniq ID of the request
	*/
	endRequest:function(v_uniqId)
	{
		for (var i=0;i<$p.ajax.requests.length;i++)
		{
			if ($p.ajax.requests[i].uniqId==v_uniqId)   {
				$p.ajax.requests.splice(i,1);
				break;
			}
		}
		$p.ajax.executeRequests();
	},
    kill: function()
    {
        $p.ajax.xmlhttp[this.handle].abort();
        $p.ajax.endRequest(this.uniqId);
    },
	/*
                   Function: $p.ajax.getprop 

                            Get a property value from an XML object item
		
                   Parameters:

			v_item - xml object item
			v_name - name of the property
			v_type - type of the value of the property (int/str)
			v_required - is this value required (boolean)
			v_default - default return value if the property is missing
		
                   Returns:
    
			 property value
	*/
	getProp:function(v_item,v_name,v_type,v_required,v_default)
	{
		if (v_default==indef) v_default="";
		if (v_required
            &&!v_item.getAttribute(v_name)) {
                $p.app.alert.show(lg("RequiredAttributeMissing") +  " : " + v_name);
                return v_default;
		}
		var l_prop=(v_item.getAttribute(v_name))?v_item.getAttribute(v_name)
                  :v_default;
		
        if (v_type=="int") l_prop=l_prop.toInt();
		return l_prop;
	},
	/*
			Function: $p.ajax.getVal 
                                        
                                        Get a node value from an XML object item
			
                                Parameters:

				v_item - xml object item
				v_name - name of the node
				v_type - type of the value (int/str)
				v_required - is the value required ?
				v_default - default return value if the node is missing
			
                                 Returns:
                                 
                                           Ouput : node value
	*/
	getVal:function(v_item,v_name,v_type,v_required,v_default)
	{
		var l_node = "";
		if (v_default==indef) v_default="";
		if(v_item!=indef) {
			l_node=v_item.getElementsByTagName(v_name)[0];}
		if (!l_node
            ||!l_node.firstChild
            ||!l_node.firstChild.nodeValue) {
                if (v_required) {
                    $p.app.alert.show(lg("RequiredValueMissing") + " : " + v_name);
                }
                return v_default;
		}
		else
		{
			//if there is a space between xml tag and xml value
			var inc=0;
			while (l_node.firstChild!=null
                   &&l_node.firstChild.nodeType==3
                   &&l_node.firstChild.nodeValue.charCodeAt(0)==10
                   &&inc<5) {
                        l_node.removeChild(l_node.firstChild);
                        inc++;
			}
			if (l_node.firstChild==null)    {
				var l_val="";
			}
			else    {
				var l_val=(l_node.firstChild.nodeValue)?l_node.firstChild.nodeValue:v_default;
				if (v_type=="int") {
                    l_val=l_val.toInt();
                }
			}
			return l_val;
		}
	}
    
}



//************************************ PLUGIN FUNCTIONS ******************************************************************************************
/*
    Class: $p.plugin

            Plugin functions
*/
$p.plugin={
	hooks:{},
	shown:false,
    contentDiv:'',
	page:"",
    /*
		Function: init 
                        
                        $p.plugin.init 
                        initialize a plugin
		
                    Parameters:

			v_title - plugin title (written in browser title bar)
			v_id - uniq identifier of the plugin
	*/
	init:function(v_title,v_id,v_prepareBefore)
	{
        //prepare plugin page
        if (v_prepareBefore == indef || v_prepareBefore)
            $p.plugin.prepare();
		//set page name
		if (v_title == indef) v_title = '';
		$p.navigator.changeTitle(v_title);
        
        if (v_id == indef) v_id = 'default';
        
		//init plugin area
		// if ($('plugin_breadcrumb') != null)
			// $('plugin').removeChild($('plugin_breadcrumb'));
		$p.print("plugin",'<div id="pluginmenu"></div><div id="plugin_breadcrumb"></div><div id="plugincontent" style="padding: 8px;"></div>');
		$p.show("plugin","block");
		$p.plugin.shown=true;
		$p.plugin.page='';
		if (v_id!=indef) $p.app.newEnv(v_id);
		//place footer
		$p.app.pages.computeFooterPosition();
	},
	/*
		Function: prepare 
                    
                            $p.plugin.prepare 
                            
                            reset application to open the plugin
                     
                     See also:
                        
                        <init>,<$p.plugin.init>
	*/
	prepare:function()
	{
		//close all menus & other divs
		$p.app.pages.closeAllDiv();
		//close current page
		$p.app.pages.hide();
		//hide loading frame, if opened
		$p.app.checkLoading(false,-1);
		//activate default stylesheet
		if ($p.app.style == 0)
			$p.styles.setActiveStyleSheet($p.app.tabs.defTheme);
		//$p.app.tabs.sel=-1;
		//jspass=="";
		//regenerate tabs
        $p.app.tabs.created[-1] = false;
		$p.app.tabs.create(-1);
        //refresh menu based on new page
        $p.app.menu.refreshConditionalMenus();
	},
	/*
		Function: menu 
        
                        $p.plugin.menu
                        display the plugin menu
		
                    Parameters:

			v_elemts - array of the options of the menu
			v_selected - selection option of the menu
	*/
	menu: function(v_elemts,v_selected)
	{
		var l_elemt = [];
		if (v_elemts == indef) return false;
		for (var i = 0; i < v_elemts.length; i ++)
		{
			l_elemt.push(
				(v_elemts[i]['icon'] == '' ? '' : $p.img(v_elemts[i]['icon'],indef,indef,'','imgmid')+' ')
				+((v_elemts[i]['isLink'] && v_elemts[i]['id']!=v_selected) ? "<a href='#' onclick=\""+v_elemts[i]['fct']+"\">"+lg(v_elemts[i]['title'])+"</a>" : '<span class="selected">'+lg(v_elemts[i]['title'])+'</span>')
			);
		}
		$p.show('pluginmenu','block');
		$p.print('pluginmenu',' &nbsp; '+l_elemt.join(' | '));
	},
	/*
		Function: wait 
                            
                            $p.plugin.wait 
                            
                            call to $p.app.wait('plugincontent');
                            which display loading icon
                            
                            show that application is loading information
            
                    See also:
                    
                            <$p.app.wait>
        */
	wait:function()
	{
		$p.app.wait('plugincontent');
	},
	/*
		Function: content 
        
                            $p.plugin.content 
        
                            display HTML in plugin window
		
                     Parameters:

			 HTML to be displayed
	*/
	content:function(v_content)
	{
		if (v_content==indef) v_content="";
		$p.print("plugincontent",v_content);
	},
	/*
		Function: hide 
        
                            $p.plugin.hide
                            
                            close plugin
	*/
	hide:function()
	{
		$p.print("plugin","");
		$p.show("plugin","none");
		$p.plugin.shown=false;
	},
	/*
		Function: clear 
                        $p.plugin.clear 
                        
                        clear plugin area
	*/
	clear:function()
	{
		$p.print("plugin","");
		$p.plugin.init();
	},
	/*
		Function:  useWidget
        
                             method from $p.plugin.useWidget -> useWidget ($p.plugin.useWidget)
                             
                            a widget can be opened in the plugin page
	*/
	useWidget:function()
	{
		tab[$p.app.tabs.sel]=new $p.app.tabs.object(
                                        -1,     //uniq id of the table
                                        "",     //label - title
                                        "P",    //type of the page
                                        "",     //function linked
                                        0,      // lock    
                                        0,      //tab sequence
                                        0,      //editable
                                        0,      //movable
                                        "",     //icon
                                        0,       //status
                                        false,  //loodstart
                                        indef   //page id
                                        );
		$p.app.tabs.selId=0;
	},
    /*
            Function:open
            
                    $p.plugin.open
                    
                    alias for  $p.plugin.prepare
               
               See also:
               
                    <open>,<$p.plugin.prepare>
        */
	open:function(){return $p.plugin.prepare();},
	/*
	         Function: openInTab
                                $p.plugin.openInTab 
                                
                                Open a plugin function in a tab
		
                    Parameters:

			v_tabId - tab ID (integer)
			v_fct - function called on tab opening (function)
			v_anchor - define if url anchor need to be changed (string)
			v_reload - define if the page is reload each time the tab is clicked (boolean)
	*/
	openInTab:function(v_tabId,v_fct,v_anchor,v_reload)
	{
		//$p.app.banner.option.hide();
		$p.show("box","none");
		$p.app.pages.closeAllDiv();
        //display modules block who contains table with modules
		$p.show("modules","block");

        //change anchor
        if (v_anchor == indef) v_anchor ='';
        $p.url.goToAnchor(v_anchor);

		//$p.app.stopLoading();
		$p.app.tabs.sel=$p.app.tabs.idToPos(v_tabId);
		//change style to default
		$p.styles.setActiveStyleSheet($p.app.tabs.defTheme);
        
        $p.app.newEnv('plugin');

		if (tab[$p.app.tabs.sel].isLoaded)
		{
			$p.show("modules"+v_tabId,"block");
		}
		else
		{
			if ($("modules"+v_tabId)==null)    {
				tab[$p.app.tabs.sel].root=new Element('div', {'id': 'modules'+v_tabId, 'class':'plugin'} );
				($("modules")).appendChild(tab[$p.app.tabs.sel].root);
			}
			else
			{
				$p.show("modules"+v_tabId,"block");
			}
			
            v_fct("modules"+v_tabId);
            tab[$p.app.tabs.sel].isLoaded = ((!v_reload || v_reload == indef) ? true : false);
			
		}

        //refresh menu based on new page
        $p.app.menu.refreshConditionalMenus();
	},
    /*
         Function: openInFrame
                    $p.plugin.openInFrame 
                            
                    Open an URL in a frame inside the page
		
            Parameters:

			v_url - Url (string)
            v_title - title of the page opened in frame
            v_height - height of the frame (integer)
	*/
    openInFrame: function(v_url,v_title,v_height)
    {
        $p.plugin.init(v_title);
		l_height = (v_height == indef ? '' : 'height: '+v_height+'px;');
        $p.plugin.content('<iframe id="pluginframe" src="' + v_url + '" frameborder="no" frameheight="400" style="width: 100%;' + l_height + '">Loading ...</iframe>');
    },
	resizeFrame: function()
	{
		$p.adjustFrameHeight($('pluginframe'));
	},
	/*
	         Function: displayFFModule
                                $p.plugin.displayFFModule 
                                
                                display the firefox plugin tab
	*/
    displayFFModule:function()
    {
        $p.app.tabs.openTempTab(3,"$p.plugin.openInTab(%tabid%,$p.plugin.displayFFModuleContent,'Plugin Firefox')","Plugin",'../images/ico_get_article.gif');
    },
	/*
	         Function: displayFFModuleContent
                                $p.plugin.displayFFModuleContent 
                                
                                display the firefox plugin tab content
	*/
    displayFFModuleContent:function()
    {
        var l_s="";
        $p.plugin.contentDiv='modules'+tab[$p.app.tabs.sel].id;
        $p.print($p.plugin.contentDiv,$p.html.buildTitle(lg("notebookFFPlugin"))+"<div id='plugindiv'></div>");
        //l_s +="<br /><br /><center><a href='../includes/plugins/firefox_module.xpi'>Click here</a></center>";
        $p.print("plugindiv",l_s);   
    },
	displayBreadcrumb:function(v_bc)
	{
		$p.show('plugin_breadcrumb','block');
		$p.print('plugin_breadcrumb',v_bc);
	}
}

/*
    Class: $p.plugin.application
    
       manage plugins
        
*/
$p.plugin.application={
    /*
            Array: item
            
                    array of plugins
                    
                    $p.plugin.application.item
        
        */
	item:[],
    /*
                Function: initMenu
                        
                                $p.plugin.application.initMenu
                                
                                build hash about application menu and push it  in $p.app.menu.options
                                
                                called by $p.app.initMenus()

                   See Also:
                   
                            <$p.app.initMenu()>,<$p.app.menu.options>
            */
	initMenu:function()
	{
		$p.app.menu.options.push(
			{
				"id":"applications",
				"label":lg("yourapplications"),
				"desc":lg("myapplicationsIconDesc"),
				"icon":"ico_menu_myportaneo.gif",
				"seq":60,
				//"action":"$p.plugin.application.menu()",
				"action":'',
				"type":"",
				'opened':false,
				'default_opened':false,
				"subOptions":[]
			}
		);
	},
	/*
		Function:  hideMenu
        
                                    $p.plugin.application.hideMenu
                        
                                    hide the plugin  menu
	
    */
	hideMenu:function()
	{
		var l_posInArray = $p.app.menu.getOptionById('applications');

		//hide application tab
		$p.app.menu.options.splice(l_posInArray,1);
		$p.show('menuopt_applications','none');
	},
	/*
		Function:  obj
        
                                $p.plugin.application.obj 
            
                                set plugin application object

                     Parameters:
                     
                                id - plugin object id
                                
                                title - plugin object title
                                
                                icon - plugin object icon
                                
                                action - plugin object action 
           */
	obj:function(id,title,icon,action)
	{
		this.id=id;
		this.title=title;
		this.icon=icon;
		this.action=action;
	},
	/*
		Function: menu
        
                            $p.plugin.application.menu 
                        
                            open the  plugin application submenu
    */
	menu:function()
	{
		//$p.app.menu.emptyContent();
		var l_posInArray = $p.app.menu.getOptionById('applications');

		for (var i=0;i<$p.plugin.application.item.length;i++)
		{
			$p.app.menu.options[l_posInArray].subOptions[i] = {
				'id':'application_' + i,
				'label':$p.img($p.plugin.application.item[i].icon,indef,indef,"","imgmid")+" "+$p.plugin.application.item[i].title,
				'action':$p.plugin.application.item[i].action,
				'type':'link',
				'opened':false
			};
//			l_s+="<a href='#' onclick=\""+$p.plugin.application.item[i].action+";return false;\">"+$p.img($p.plugin.application.item[i].icon,indef,indef,"","imgmid")+" "+$p.plugin.application.item[i].title+"</a><br />";
		}
		//$p.app.menu.addTitle('listapps_1','ico_menu_myportaneo.gif',lg('yourapplications'));
		//$p.app.menu.addHTML('listapps_1',l_s);		
		//$p.app.menu.addHTML('listapps_1',l_s);		
	},
	/*
		Function: load
        
                            $p.plugin.application.load 
                            
                            load the plugin applications avail for the user
                            
                            load xml file (from database)
                            
                            SELECT a.id,a.title,a.icon,a.action FROM applications...
                     
                     See also:
                     
                            <$p.plugin.application.get>
	*/
	load:function()
	{
		if ($p.app.user.id>0)
		{
			$p.ajax.call(posh["xmlapplications"],
				{
					'type':'load',
					'callback':
					{
						'function':$p.plugin.application.get
					}
				}
			);
		}
		else
		{
            //hide menu if user no authenticated
			$p.plugin.application.hideMenu();
		}
	},
    /*
            Function: get
            
                        $p.plugin.application.get
                        
                        callback from load
    
                        hidemenu if no data
                        
                        push data in $p.plugin.application.item
    
            parameters:
            
                    response - repsonse from load
                    
                    vars - parameters
                    
        */
	get:function(response,vars)
	{
		if (response!=null)
		{
			var l_result=response.getElementsByTagName('application');
			if (l_result.length==0)
			{
				$p.plugin.application.hideMenu();
			}
			else
			{
				for (var i=0;i<l_result.length;i++)
				{
					$p.plugin.application.item.push(
                                        new $p.plugin.application.obj(
                                                $p.ajax.getVal(l_result[i],'id','int',false,0),
                                                $p.ajax.getVal(l_result[i],'title','str',false,''),
                                                $p.ajax.getVal(l_result[i],'icon','str',false,''),
                                                $p.ajax.getVal(l_result[i],'action','str',false,'')
                                                )
                                                );
				}
			}
		}
		
		// feed the menu
		$p.plugin.application.menu();
	}
}
//******************* HOOKS MANAGEMENT********************************************************************************************************
/*
    class: $p.plugin.hook
    
        manage hook in any part of javascript code
        
        Add function to a name
        
        Then function is called when name is called
        
        Sample:
        
            in $p.app.init, you'll find this line
            $p.plugin.hook.launch('app.init.start');
            
            In any part ot your code add
            
            $p.plugin.hook.register('app.init.start',
                                         '',            //deprecated
                                         5,
                                         myfunction,  //without parenthesis
                                         {'param1':'value','param2':'value'}
                                    );

               You can unregister function if you want
                    
                        $p.plugin.hook.unregister('app.init.start',5);


        List of hooks available:
                
                - app.init.start   :  $p.- app.init  add action in init page
                - app.init.end    : add action at end of init page
                - app.initMenus.start : action at beginning of  init menus
                - app.initMenus.end : action at end of init menus
                - app.logout.start : action at begining of  logout function
                - app.logout.end : action at end of logout function
                - app.pageMode.start  : action at begining of load - application
                - app.pageMode.end : add action at end of load - application
                - app.home.start : add action at beginning of homepage building
                - app.home.end : add action at end of homepage building
                - app.loadTabs.start : add action at begining of loading tabs
                - app.loadTabs.end : add action at end of loading tabs (attention to ajax asynchronous call)
                - app.initTabs.start : add action at beginning of init of tabs
                - app.initTabs.end : add action at end of init of tabs
                - app.openHome.start : add action at beginning of home page dispalying
                - app.openHome.end : add action at end of home page dispalying
                - app.loading.start: add action at beginning of loading message
                - app.loading.end : add action at end of loading message
                - app.mainMenu.start : add action at beginning of main menu
                - app.mainMenu.end : add action at end of main menu
                - app.menu.init.start : add action at beginning of init menu function
                - app.menu.init.end : add action at end of init menu function
                - app.menu.show.start : add action at beginning of show menu function
                - app.menu.show.end ; add action at end of show menu function
                - app.menu.widget.addOptions1 : add action in widget menu, options1 - rss ($p.- app.menu.widget.build)
                - app.menu.widget.addOptions3 : add action in widget menu, options3 - explore
                - app.menu.widget.addOptions4 : add action in widget menu, options4  - private widgets
                - app.menu.widget.addOptions5 : add action in widget menu, options5 -  archives widgets
                - app.menu.widget.addOptions6 : add action in widget menu, options6 - before links menus
                - app.menu.widget.addOptions7 : add action at end of widget menu options ($p.- app.menu.widget.build)
                - app.menu.config.addOption1 : add action in config menu (beginning)
                - app.menu.config.addOption2 : add action in config menu - before IE options
                - app.menu.config.addOption3 : add action in config menu (end)
                - app.tabs.init.start : add action at beginning of tabs object creation
                - app.tabs.init.end : add action at end of tabs object creation
                - app.tabs.create.start : add action at beginning of tabs displaying
                - app.tabs.create.end : add action at end of tabs displaying
                - app.tabs.save.start : add action at beginning of save tabs change
                - app.tabs.save.end : add action at end of save tabs change
                - app.pages.change.start :  add action at beginning of save page change
                - app.pages.change.end : add action at end of save page change
                - app.pages.opencreatedtab.start :  add action at beginning of opening of new tab
                - app.pages.opencreatedtab.end :  add action at end of opening of new tab
                - app.pages.newPortal.start : add action at beginning of  popup page creation
                - app.pages.newPortal.end : add action at end of  popup page creation
                - app.pages.suppress.start : add action at beginning of page deletion
                - app.pages.suppress.end : add action at end of page deletion
                - app.pages.load.start : add action at beginning of personalized page content information loading
                - app.pages.load.end : add action at end of personalized page content information loading
                - app.pages.treat.start : add action at beginning of page information  displaying
                - app.pages.treat.end : add action at end of page information displaying
                - app.widgets.create.start : add action at beginning of widget create function
                - app.widgets.create.end : add action at end of widget create function
                - app.widgets.destruct.start : add action at beginning of widget deletion function
                 - app.widgets.destruct.end : add action at end of widget deletion function
                 - app.widgets.refresh.start : add action at beginning of widget refreshing
                 - app.widgets.refresh.end : add action at end of widget refreshing
                 - app.widgets.placeincol.start : add action at beginning of setting of widget in a column
                 - app.widgets.placeincol.end : add action at end of setting of widget in a column
                 - app.widgets.saveChanges.start : add action at beginning of widgat save change
                 - app.widgets.saveChanges.end : add action at end of widgat save change
                 - app.widgets.suppress.start : add action at beginning of widget removing function
                 - app.widgets.suppress.end : add action at end of widget removing function
                 - app.widgets.param.fillEditBox.start : add action at beginning of widget configuration box
                 - app.widgets.param.fillEditBox.end : add action at end of widget configuration box
                 - app.widgets.param.valid.start : add action at beginning of widget saving configuration
                 - app.widgets.param.valid.end : add action at end of widget saving configuration
                 - app.widgets.rss.display.start : add action at beginning of rss display function
                 - app.widgets.rss.display.end : add action at end of rss display function 
                 - app.connection.set.start : add action at beginning of connection function
                 - app.connection.set.end : add action at end of connection function
                 - app.connection.subscribe.start : add action at beginning of subscribe process
                 - app.connection.subscribe.end : add action at end of subscribe process
                 - app.connection.saveMenu.start : add action at beginning of saving menu function
                 - app.connection.saveMenu.end : add action at end of saving menu function
                 - app.reader.open.start : add action at beginning of multimedia files reader opening
                 - app.reader.open.end : add action at end of multimedia files reader opening
                 - app.help.Messages : display help messages in homepage
                 - app.user.myprofile.end : add action in profile popup
                 - network.profile.displayuserdatas.begin : add action at beginning of datas displaying function
                 - network.profile.displayuserdatas.end : add action at end of datas displaying function
                
*/
$p.plugin.hook={
	/*
                Function: launch
                       $p.plugin.hook.launch
                    
                        launch functions linked to hook
                    
                Parameters:

                      v_name -  the hook's name
           */
	launch:function(v_name){
		//check if the hook exists
		if(!$p.plugin.hooks[v_name]){
			return false;
		}
       
		//order by priority 
		//($p.plugin.hooks[v_name]).sort($p.plugin.hook.sortByPriority);to be developed in posh 3.0
		//execute the functions linked to the hook
		for (var key in $p.plugin.hooks[v_name]){
			for(var j=0;j<$p.plugin.hooks[v_name][key].length;j++){
                if ( typeof($p.plugin.hooks[v_name][key][j]) == 'string') {
                    eval( $p.plugin.hooks[v_name][key][j] );
                } else {
                    $p.plugin.hooks[v_name][key][j]['callback'](
                                                    $p.plugin.hooks[v_name][key][j]['params']
                                                                );
                }
			}
		}
	},
	/*
                Function: $p.plugin.hook.sortByPriority
                       $p.plugin.hook.sortByPriority
                    
                        sort the hooks by priority
                    
                Parameters:
		
		(a,b) values to compare
		
	     Returns
		 
		 comparaison value
           */
	sortByPriority:function(a,b){
		if (a<b) return -1;
		if (a>b) return 1;
		return 0;
	},
	 /*
                Function: register
                       $p.plugin.hook.register
                    
                        register a function linked to a hook
                    
                Parameters:
				
		v_name  -  (string) the hook's name
		v_function  -  (string) the function to register sent as a string  (works, but prefer callback)
		v_priority -  (int) the priority of the hook
              callback - (function) function to call ( without parenthesis)
              params -  (string, hash, array) parameters sent to callback function (function must get a hash with 'params' as key, value can be anything)
           */
	register:function(v_name,v_function,v_priority,callback,params) {
		//check if the hook is already existing
		if(!$p.plugin.hooks[v_name]){
			$p.plugin.hooks[v_name]={};
		}
		//check if there is a hook with the same priority
		if(!$p.plugin.hooks[v_name][v_priority]){
			$p.plugin.hooks[v_name][v_priority]=[];
		}
		//set the new hook
        if (v_function == '') {
            $p.plugin.hooks[v_name][v_priority].push({'callback':callback,'params':params});  
        } else {
            $p.plugin.hooks[v_name][v_priority].push(v_function);
        }
	},
    /*
    
            function: $p.plugin.hook.unregister
            
                unregister a function
                
             Parameters:

                    v_name - (string) name of the function
                    v_priority - priority to delete (optional, unless delete v_name)
                    position - pop , remove last item in array of $p.plugin.hooks[v_name][v_priority]
    */
    unregister: function (v_name,v_priority,position) {
        if (position && position == 'pop' ) {
            try {
                $p.plugin.hooks[v_name][v_priority].pop();
            } catch (e) {
                alert("error " + e.msg);
            }
        } else {
            if (v_priority) {
                delete $p.plugin.hooks[v_name][v_priority];
            } else  {
                delete $p.plugin.hooks[v_name];
            }
        }
    }
}

/*

    Class: $p.plugin.tools

*/
$p.plugin.tools={
	fckObject:indef,
	/*
                Function: initializeCKEditor
                       $p.plugin.tools.initializeCKEditor
                    
                        Improve a textarea with CKEditor
                    
                Parameters:
				
		v_textareaName: The textarea id

           */
	initializeCKEditor:function(v_textareaId,v_height)
	{
        if (v_height == indef) v_height = 250;
		CKEDITOR.config.language = __lang;
		CKEDITOR.config.entities_latin = false;
		CKEDITOR.config.width = '98%';
		CKEDITOR.config.height = v_height;

		var instance = CKEDITOR.instances[v_textareaId];
		if(instance)
		{
			CKEDITOR.remove(instance);
		}
		CKEDITOR.replace(v_textareaId,
		{
				customConfig : __LOCALFOLDER+'includes/ckconfig.js'
		});
		/*
		$p.plugin.tools.fckObject = new FCKeditor(v_textareaId);
		sBasePath = __LOCALFOLDER;
        sBasePath = sBasePath.replace(/http:/,$p.navigator.getProtocol());
		$p.plugin.tools.fckObject.BasePath = sBasePath+'tools/fckeditor/';
		$p.plugin.tools.fckObject.Config['CustomConfigurationsPath'] = sBasePath+'includes/fckconfig.js';
		$p.plugin.tools.fckObject.Width = '100%';
		$p.plugin.tools.fckObject.Height = v_height;
		$p.plugin.tools.fckObject.ToolbarSet = 'portaneo';
		$p.plugin.tools.fckObject.ReplaceTextarea();
		*/
	},
	/*
	forceFckEditorSaving:function(v_textareaId)
	{
		var oEditor = FCKeditorAPI.GetInstance(v_textareaId);
		
		oEditor.UpdateLinkedField();
	},
	*/
	/*
		Function: ckEditorSaving
			$p.plugin.tools.ckEditorSaving
                    
			Save description from CKEditor
                    
        Parameters:	
			v_textareaId: The textarea id

	*/
	ckEditorSaving:function(v_textareaId)
	{
		return CKEDITOR.instances[v_textareaId].getData();
	}
}

//**************************************************************************************************************************************************
//*
//*                                      APPLICATION
//*
//**************************************************************************************************************************************************

//******************* APPLICATION INITIALIZATION ************************************************************************************************
/*
    Class: $p.app

        Application initialization

*/
$p.app={
	style:0,
	env:"portal",
	isLoading:false,
	inactivityTime:0,
	/*
		Function: init 
        
                        $p.app.init 
                        
                        init the application
                    
                    See Also:
                    
                        - <$p.app.getVersion>
                        - <$p.app.loadStyles>
                        - <$p.app.initMenus>
                        - <$p.app.mainMenu>
                        - <$p.app.loadTabs>
                        - <$p.plugin.application.load>
                        - <$p.app.footer>
                        - <$p.app.initEvents>
                        - <$p.app.counter.reset>
	*/
	init:function()
	{
		$p.plugin.hook.launch('app.init.start');
        
		// load all themes of the application
		$p.app.getVersion();
		$p.app.loadStyles();
		$p.app.initMenus();
		$p.app.mainMenu();
		$p.app.loadTabs();
		$p.plugin.application.load();
		$p.app.footer();
		$p.app.initEvents();
		$p.app.counter.reset();

		$p.plugin.hook.launch('app.init.end');        
	},
	/*
		Function: initMenus
        
                        $p.app.initMenus
                        
                        init the menus
	*/
	initMenus:function()
	{
		$p.plugin.hook.launch('app.initMenus.start');
		
		// reset menu array
		$p.app.menu.options.length = 0;
		// initialize menus
		//$p.app.pages.initMenu();
		$p.app.widgets.initMenu();
		//if (__useNetwork) $p.network.initMenu();
		//if (__useArchive && $p.app.user.id > 0) $p.article.initMenu();
		//if (__useNotebook) $p.notebook.initMenu();
        //if (__useSharing) $p.app.statistics.initMenu();
		$p.plugin.application.initMenu();

		$p.plugin.hook.launch('app.initMenus.end');
	},
    breadCrumbs: function(v_data)
    {
        return '<div class="breadcrumb">'
            + $p.html.breadCrumbs(v_data)
            + '</div>'
    },
	/*
		Function: logout
        
                                $p.app.logout 
                                
                                logout from Portaneo application
	*/
	logout: function()
	{
		$p.plugin.hook.launch('app.logout.start');
		var response = 1;        
        var cookiesTab=new Array("autoi", "autop", "laststate");
        if ($p.app.user.type=="A") {
            cookiesTab.push("admlaststate");
        }
        
		//the logout confirmation is not applied for admin
		if ( ($p.cookie.get("autoi") != "") && ($p.app.user.id > 0) ) {
			var response = confirm(lg("disconnectCheck"));
		}
		if (response == 1) {
            $p.app.deleteCookies(cookiesTab);
            var localfolder = __LOCALFOLDER;
            localfolder = localfolder.replace(/http:/,$p.navigator.getProtocol());
			$p.url.openLink(localfolder+"portal/"+posh["scr_authentif"]+"?act=logout");
		}

		$p.plugin.hook.launch('app.logout.end');
	},	
    /*
		Function: $p.app.deleteCookies
        
                            delete useless cookies after deconnection
                            
		Parameters:

			 cookiesTab - array of the cookies names
	*/
    deleteCookies:function(cookiesTab)
    {
        var delay=-15;
        for (var i=0;i<cookiesTab.length;i++)
        {
            if ($p.cookie.get(cookiesTab[i]) != "") {
                $p.cookie.write(cookiesTab[i]+"=",delay);
            }
        }
    },
	/*
		Function: $p.app.wait
        
                            display loading icon in object
                            
		Parameters:

			 v_id - ID of the object
	*/
	wait:function(v_id)
	{
		if ($(v_id) != null)
			($(v_id)).set('html',$p.img("ico_waiting.gif",16,16));
	},
	/*
		Function: $p.app.getDebugCookie
        
                            Create the debug cookie
	*/
	getDebugCookie:function()
	{
		$p.cookie.write("debug=Y",7);
		$p.app.alert.show("Cookie installed !");
	},
	/*
		Function: $p.app.debug 
        
                            display debug message in debug window
                            
		Parameters:

			v_msg - debug message
			v_type - debug message type (error or warning or info)
	*/
	debug:function(v_msg,v_type)
	{

		if (__debugmode)
		{
			if ($p.cookie.get('debug')=='Y')
			{
				if ($("debug")!=null)
				{
					l_msg=$p.string.textToHtml(v_msg);
					var l_style="";
					if (v_type==indef) v_type="info"
					switch(v_type)
					{
						case "error":
						l_style="color: #ff0000";
						break;
						case "warning":
						l_style="color: orange";
						break;
					}
					var l_obj=$("debug");
					var l_date=new Date();
					l_obj.setStyle("display","block");
					//l_obj.innerHTML()
					l_obj.set('html',"<table cellpadding='0' cellspacing='0'><tr><td width='80' valign='top'>"+l_date.getHours()+":"+l_date.getMinutes()+":"+l_date.getSeconds()+"></td><td style='"+l_style+"'> "+l_msg+"</td></tr></table>"+l_obj.innerHTML);
				}
			}
		}
	},
    /*
            Function: isCustomPortal
            
                        $p.app.isCustomPortal
                        
                        CustomPortal depends on $p.app.env
                            
                            portal_page_anon
                            
                            portal_page_conn
                            
                            admin
                 
                 Returns: 
                 
                        true or false
    
        */
	isCustomPortal: function()
	{
		if ($p.app.env == 'portal_page_anon' || $p.app.env == 'portal_page_conn' || $p.app.env=='admin')
			return true;

		return false;
	},
	/*
		Function: $p.app.pageMode
                            load application in page mode
                            
                            definie value of allowSave  to know if some datas are save in database or not
                            
                    See Also:
                            <$p.app.init>
                            
                            <$p.app.banner.info.load>
	*/
	pageMode: function()
	{
		$p.plugin.hook.launch('app.pageMode.start');

		//if (v_prof!=indef) $p.app.tabs.selId=v_prof;
		//depending on the user is connected or not
		if ($p.app.user.id == 0)
		{
			allowSave = false;
			$p.app.tabs.sel = 0;
		}
		else
		{
			allowSave = !demoMode;
		}
		useMod = false;
		$p.app.init();
		$p.app.banner.info.load();
        $p.app.incrementNbConnection();

		$p.plugin.hook.launch('app.pageMode.end');
	},
	/*
		Function: $p.app.loadStyles
        
                        load available css (depending on themeNb define in adm_config table)
	*/
	loadStyles:function()
	{
		var newDate = new Date();
		var month = newDate.getMonth()+1;
		var dDay = newDate.getDate();
		var year = newDate.getFullYear();
		var weekyear = $p.app.getWeekNumber( newDate );
		
		month = (month<10)?('0'+month):(''+month);
		dDay = (dDay<10)?('0'+dDay):(''+dDay);
		
		for (var i=1;i<=__themeList.length;i++)
		{
			$p.styles.addCssFile("../styles/main"+i+".css","style "+i,"alternate stylesheet");
			if( __USE_EVENTS_CSS ) {
				// css file or the month
				$p.styles.addCssFile("../styles/main"+i+"_m"+month+year+".css","style "+i,"alternate stylesheet");
				// css file or the week
				$p.styles.addCssFile("../styles/main"+i+"_s"+weekyear+year+".css","style "+i,"alternate stylesheet");
				// css file or the day
				$p.styles.addCssFile("../styles/main"+i+"_j"+dDay+month+year+".css","style "+i,"alternate stylesheet");
			}
		}
	},
	/*
		Function: $p.app.getWeekNumber
        
                        Get week number
	*/
	getWeekNumber:function(newDate) {
		var dDay = newDate.getDay();
		newDate.setDate(newDate.getDate() - (dDay + 6) % 7 + 3); // Nearest Thu
		var ms = newDate.valueOf(); // GMT
		newDate.setMonth(0);
		newDate.setDate(4); // Thu in Week 1
		return Math.round((ms - newDate.valueOf()) / (7 * 864e5)) + 1;
	},
	/*
		Function: $p.app.setState 
        
                            define the page Portaneo have to load when next user connection
                            
                            function called at application opening
                            
                            write javascript in cookie, javascript will be evaluate later (lastate=id)
                            
		Parameters:

			 v_fct - id last page
	*/
	setState: function(v_fct)
	{
		if ($p.app.user.id>0 || $p.app.user.type == 'A') $p.cookie.write("laststate="+v_fct);
	},
	/*
		Function: $p.app.newEnv 
                            define a new environnement
                            
		Parameters:

			 v_env - environnement name
	*/
	newEnv: function(v_env)
	{
		if ($p.app.env != v_env)
		{
			$p.app.env = v_env;
			// add the environment in the pages template list
			if (!$p.array.find(pageClasses,'_' + v_env))
			{
				pageClasses.push('_' + v_env);
			}
		}
		
		// display template objects relative to this environment
		$p.navigator.showClass('_' + v_env);
	},
	/*
		Function: $p.app.home 
        
                            Select page to open, home or latest page or page 0
                            
                            > check if there is anchor and then change page to open
                            > see __loadlatestpageonstart parameter 3 = home page, 2 = latest page
                            > then open home page which can be
                            - home page  -> <$p.app.openHome>
                            - latest opened page, see cookie laststate
                            - first page
	
                    Parameters:

			 v_tabId - page ID
	*/
	home: function(v_tabId)
	{
		$p.plugin.hook.launch('app.home.start');
 
		//if the page name is in anchor, load it
        var anchorTab = indef;
        anchorTab = $p.url.getAnchorTab();
        if (typeof(anchorTab) != "undefined") {
            $p.app.delaytab = true;
            var l_tab = $p.app.tabs.getId(anchorTab);
            if (l_tab != indef && tab[l_tab])
            {
				// EMA - correct issue with loading image for the first tab
				if ($p.app.tabs.sel >= 0 && l_tab != $p.app.tabs.sel)
					tab[$p.app.tabs.sel].isLoaded = indef;
                $p.app.tabs.sel = l_tab;
                v_tabId = tab[l_tab].id;
            }
        }
		// if a notebook is called in the URL, opens it
		if (__useNotebook)
		{
			anchorNotebook = $p.notebook.getAnchor();
			if (anchorNotebook != indef)
			{
				$p.app.isLoading = false;
				
				$p.notebook.open(anchorNotebook[1],
					(anchorNotebook.length > 1 ? anchorNotebook[2] : 'note'),
					indef,
					indef,
					(anchorNotebook.length > 2 ? anchorNotebook[3] : indef)
				);
			}
		}

		// redirect to the default page, based on the Posh configuration
		if ($p.app.tabs.sel == indef || $p.app.tabs.sel == -1 || v_tabId == -1)
		{
        
			//open the latest page opened by the user
			if (__loadlatestpageonstart == 3)
			{
				$p.app.openHome();
			}
			else if (__loadlatestpageonstart == 2 && $p.cookie.get("laststate") != "")
			{
				try
				{
					eval($p.cookie.get("laststate"));
				}
				catch(err)
				{
					$p.app.debug('Issue with the laststate value in the cookie',"error");
					$p.app.openHome();
				}
                
			}
			else
			{
				if (tab.length > 0)
				{
					for (var i = 0; i < tab.length; i++)
					{
						if (!tab[i].temporary)
						{
							$p.app.tabs.open(i);
							break;
						}
					}
				}
			}
		}
        else
		{
			$p.app.tabs.create($p.app.tabs.sel);

			// Removed by EMA for 2.3 - This was calling $p.app.tabs.open twice on app start (anonymous)
			$p.app.tabs.open($p.app.tabs.sel);
		}

		$p.plugin.hook.launch('app.home.end');
	},
	/*
		Function: $p.app.loadTabs 
        
                        load all the tabs for the user
                        
		Parameters:

			v_prof - selected tab ID
			v_locked -
			v_action - action to launch on tab opening
            
                    See Also:
                    
                            callback function - <$p.app.initTabs>
	*/
	loadTabs: function(v_prof,v_locked,v_action,status)
	{
		$p.plugin.hook.launch('app.loadTabs.start');

		v_prof = (v_prof == indef ? $p.app.tabs.selId : v_prof);
	
		if (v_action == indef) v_action = "";
		var l_tabXml = ($p.app.user.id == 0) ? "selections/tabs.xml?nocache="+rand
                                             : posh["xmltabs"];

		if (dumtab!=indef)  
            l_tabXml += "?dumtab="+dumtab.label+"&dumicon="+dumtab.icon;
		//var l_locked=v_locked?true:false; //???

		$p.ajax.call(l_tabXml,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.initTabs,
					'variables':
					{
						'tabid':v_prof,
						'action':v_action
					}
				}
			}
		);

		$p.plugin.hook.launch('app.loadTabs.end');
		

	},
	/*
		Function: $p.app.initTabs 
                            
                        init all the tabs
                
                     >   create tabs objects : $p.app.tabs.init(response);
                     >   create html base tab with <$p.app.tabs.create>
                     >   open page with <$p.app.home> or <$p.app.pages.change> or see cookie laststate (contains call to <$p.app.pages.change>)
                            
		Parameters:

			response - xml object containing tabs information
			vars - variables sent (tab ID,action)
            
        Seee Also:
            
            <$p.app.loadTabs>
	*/
	initTabs: function(response,vars)
	{
		$p.plugin.hook.launch('app.initTabs.start');

		var l_prof = vars['tabid'];
		var l_action = vars['action'];
        //create tabs object
		$p.app.tabs.init(response);

		if ($p.app.tabs.sel == indef) $p.app.tabs.sel = -1;
		//if ($p.app.tabs.sel == indef) $p.app.tabs.sel = 0;
		//if new tab (temporary id = 999, get the id

		if ($p.app.tabs.sel == 999)
		{
			$p.app.tabs.sel = $p.app.tabs.getId(l_prof);
            if ($p.app.tabs.sel == -1)
				$p.app.tabs.sel = 0;
			//$p.app.tabs.create($p.app.tabs.sel);
			//$p.app.menu.open();
			$p.app.pages.change(l_prof,l_action);
            //display help message if custom page & no widgets
            if (tab[$p.app.tabs.sel].type == 1 && tab[$p.app.tabs.sel].module.length == 0)
            {
				if(!$("pageform"+tab[$p.app.tabs.sel].id)) {
					$p.show('message','block');
					$p.app.help.displayNewPortalMessage('message');
				}
               
            }
			
			if (__useSharing) $p.app.addEnterpriseTabs();
		}
		else {
            //define the page to open on
			//$p.app.tabs.create($p.app.tabs.sel);
            //select page to open
			
			if (__useSharing) $p.app.addEnterpriseTabs();
			
            $p.app.home($p.app.tabs.sel);
            //init the menu (needs the tabs to be init too)
            $p.app.menu.init();
		}

	
		//tab name is edited ?
		if (tab.length != 0)
		{
			setTimeout("$p.app.pages.loadOnStart()",2000);
		}
		else
		{
			$p.app.checkLoading(false);
			$p.styles.setActiveStyleSheet(1);
		}
       
		// var anchorTab = indef;
		// anchorTab = $p.url.getAnchorTab();       
		
		if( __OPEN_TAB_BASED_ON_SUBDOMAIN ) {
			var l_tabToOpen = $p.app.tabs.getIdTabByName($p.app.tabs.getTabNameInUrl(windowLocationObject.host));
		
			// EMA - correct issue with loading image for the first tab
			if ($p.app.tabs.sel >= 0 && l_tabToOpen != $p.app.tabs.sel)
				tab[$p.app.tabs.sel].isLoaded = indef;
				
			if (l_tabToOpen > 0)
			{
				$p.app.tabs.open(l_tabToOpen);
			}
		}
	   
        $p.plugin.hook.launch('app.initTabs.end');
	},
    delaytab:0,
	/*
		Function: $p.app.openHome
        
                        define application loaded on the homepage

	*/
	openHome: function()
	{
        
		if (__homeDivs.length > 0)
		{
			//$p.app.tabs.openTempTab(3,"$p.plugin.openInTab(%tabid%,$p.app.displayHome,'home')",lg('home'),'../images/ico_home.gif');
            $p.plugin.init(lg('home'),'home',true);
            
            $p.app.displayHome('plugincontent');
		}
		else
		{
			if ($p.app.user.id == 0 || ($p.app.tabs.sel != -1 && (tab[$p.app.tabs.sel].id == 0 || tab[$p.app.tabs.sel].id >= 1000000000)))
			{
				if ($p.app.tabs.sel == -1 && tab[0]) $p.app.tabs.sel = 0;
                $p.app.tabs.create($p.app.tabs.sel);
				//$p.app.pages.load("selections/page"+$p.app.tabs.selId+".xml");
				$p.app.tabs.open($p.app.tabs.sel);
			}
			else
			{
				//if first tab is already selected > stop
				if ($p.app.tabs.sel == 0) return false;
				if (tab.length == 0) return false;
				//else load the first tab
				if ($p.app.tabs.sel != -1)
                {
                    $p.app.pages.hide();
					$p.app.tabs.sel = 0; // added EMA on 3.0 to load first tab when user click on logo
                }
				else
                {
                    $p.app.tabs.sel = 0;
                }
                $p.app.tabs.create($p.app.tabs.sel);
				$p.app.tabs.open($p.app.tabs.sel);				
			}
		}
	},
    /*
                Function: $p.app.displayHome
                
                    display home page
                    
                 Parameters: 

                        v_container - div where display home page
    */
	displayHome:function(v_container)
	{
		$p.plugin.hook.launch('app.openHome.start');
        $p.app.tabs.created[-1] = false;
		var l_div=[];
		$p.app.setState("$p.app.openHome()");
		$p.app.newEnv('home');
		//action depend on if the user is connected or not 
		if ($p.app.user.id==0 
            || ($p.app.tabs.sel!=-1 
            && (tab[$p.app.tabs.sel].id==0 
                || tab[$p.app.tabs.sel].id>=1000000000))
           )    {
			for (var i=0;i<__homeDivs.length;i++)
			{
				if (__homeDivs[i]["anonymous"])	l_div.push(i);
			}
			if (l_div.length>0) {
				$p.app.displayFeaturedHome(l_div,v_container);
			}
			else {
				if ($p.app.tabs.sel==-1 && tab[0]) $p.app.tabs.sel=0;
				//$p.app.pages.load("selections/page"+$p.app.tabs.selId+".xml");
				$p.app.tabs.open($p.app.tabs.sel);
			}
		}
		else {
			for (var i=0;i<__homeDivs.length;i++)
			{
				if (__homeDivs[i]["connected"] && $p.app.user.type!='N')	l_div.push(i);
			}
			if (l_div.length>0) {
				$p.app.tabs.selId=0;
				$p.app.displayFeaturedHome(l_div,v_container);
			}
			else {
				//if first tab is already selected > stop
				if ($p.app.tabs.sel==0) return false;
				if (tab.length==0) return false;
				//else load the first tab
				if ($p.app.tabs.sel!=-1){$p.app.pages.hide();}
				else {$p.app.tabs.sel=0;}

				$p.app.tabs.open($p.app.tabs.sel);
			}
		}

		$p.plugin.hook.launch('app.openHome.end');

		return false;
	},
	/*
		Function: $p.app.displayFeaturedHome
                                display application homepage
                                
		Parameters:

			 v_div - array containing divs information (divs displayed, ID and content)
	*/
	displayFeaturedHome:function(v_div,v_container)
	{
		var l_s = '<div class="feature">';
        
		$p.plugin.displayBreadcrumb('<div class="feature">'
			+ $p.app.breadCrumbs(
                [
                    {'label':lg('home') + ' - ' + lg('hello') + ' ' + $p.app.user.name,'link':'','fct':''}
                ]
            )
			+ '</div>'
		);
        
        if (__useSharing)
            l_s += '<div id="homeheader" style="padding: 0 8px 4px 8px;"></div>';
        
        l_s += '<div id="intromessage"></div>'
            + '<table cellspacing="8" cellpadding="0" width="100%">'
			+ '<tr>'
			+ '<td valign="top" width="59%">';

		for (var i=0;i<v_div.length;i++)
		{
			if (i>0 && __homeDivs[v_div[i-1]]["col"]!=__homeDivs[v_div[i]]["col"])
            {
                l_s += '</td>'
                    + '<td width="20">&nbsp;</td>'
                    + '<td valign="top" width="39%">';
            }
			l_s += '<div style="padding-bottom: 8px;">'
                + '<div style="padding: 8px;">'
                + '<div id="homediv'+i+'"></div>'
                + '</div>'
                + '</div>';
		}

		l_s += '</td>'
			+ '</tr>'
			+ '</table>'
			+ '</div>';

		$p.print(v_container,l_s);

		$p.app.stopLoading();
		$p.navigator.changeTitle(lg('home'));

		for (var i=0;i<v_div.length;i++)
		{
			eval(__homeDivs[v_div[i]]["fct"]+"('homediv"+i+"')");
		}

        if (__useSharing)
            $p.app.loadHomeHeader();
		$p.app.help.displayDailyMessage('intromessage');
	},
	/*
		Function: $p.app.loading
                        
                        display loading message
	*/
	loading:function()
	{
		$p.plugin.hook.launch('app.loading.start');

		$p.app.popup.show(wip_message,400,300,indef,false);
		$p.app.isLoading = true;

		$p.plugin.hook.launch('app.loading.end');
	},
	/*
		Function: $p.app.startLoading 
                            display personalized page loading information
	*/
	startLoading:function()
	{
		//tab[$p.app.tabs.sel].isLoaded=false;
		$p.app.loading();
		//$p.show("loading","block");
		$p.app.counter.reset();
	},
	/*
		Function: $p.app.stopLoading 
                            hide personalized page loading information
	*/
	stopLoading:function()
	{
		if ($p.app.isLoading)
			$p.app.popup.hide();
		$p.app.isLoading = false;
	},
	/*
		Function: $p.app.footer 
                            display application footer
	*/
	footer:function()
	{
		var l_s = '';

		if (__useNetwork && $p.app.user.id > 0)
			l_s += '<a href="#" onclick="$p.notebook.open(indef,indef,indef,3);$p.network.dashboard.loadDirectory();return false;">' + lg('usersDirectory') + '</a> &nbsp; ';		
		
		l_s += ($p.app.user.type == 'A' ? ' | <a href="../admin/">' + lg('adminInterface') + '</a>' : '');
		
		if (l_s != indef)
			l_s += '<br /><br />';
		
		l_s += __footer;
		
		$('footer').set('html',l_s);
	},
	/*
		Function: $p.app.resetAndReload 
                            reset cookies and reload (used if loading issues)
	*/
	resetAndReload:function()
	{
		//reset cookies
		$p.cookie.write("laststate=");
		//reopen page
		$p.url.openLink();
	},
	/*
		Function: $p.app.setAsWorking  
        
                                inform users that application is running a process
                                
		Parameters:

			 v_status - process status (true=running, false=ended)
	*/
	setAsWorking:function(v_status)
	{
		if (v_status==indef) v_status=true;
		if ($("ajaxwork")==null && v_status) {
			var l_obj = new Element('div', { "id": "ajaxwork" } );	
			document.body.appendChild(l_obj);
			$p.app.wait("ajaxwork");
		}
		$p.show("ajaxwork",(v_status?"block":"none"));
	},
	/*
		Function: $p.app.mainMenu 
                            build main menu
                            
		Parameters:

			 v_locked - is the application locked (password required) or not
	*/
	mainMenu:function(v_locked)
	{
		$p.plugin.hook.launch('app.mainMenu.start');
		$('headlink').empty();
		$('information').empty();
		
		if (v_locked==indef) v_locked=$p.app.tabs.locked;
		var l_label,l_objContainer;
        
        //for administrator : add link to administration
        if ($p.app.user.type == 'A')
        {
            var bAdm = new Element('span',{'id':'admininterfacelink'});
            if ($p.app.user.id == -1)
            {
                bAdm.set('html','&bull; <b><a href="../portal/mypage.php">' 
                                + lg('usersPortal') 
                                + '</a></b> &bull; ');
            }
            else
            {
                bAdm.set('html','&bull; <b><a href="../admin/">' + lg('adminInterface') + '</a></b> &bull; ');
            }
            bAdm.inject($('headlink'));
        }
	    
        for (var i=0;i<__headmenu.length;i++)
        {
			if (( (__headmenu[i]["anonymous"] && $p.app.user.id==0 ) || ($p.app.user.type == 'N' && __headmenu[i]["anonymous"]) ) || (__headmenu[i]["connected"] && $p.app.user.id>0 && $p.app.user.type != 'N' ) || (__headmenu[i]["admin"] && $p.app.user.id==-1 &&  $p.app.user.type != 'N'))
			{
				l_objContainer = $(__headmenu[i]['position'] == 'left' ? 'information' : 'headlink' );
				//l_label=(__headmenu[i]["label"]).replace("%username%",shortName($p.app.user.name));
				l_label = (__headmenu[i]["label"]).replace("%username%",$p.app.user.name);
				switch (__headmenu[i]["type"])
				{
					case "label":
                        var spanObj1 = new Element('span', { 'id':__headmenu[i]["id"],'class':__headmenu[i]["clss"] });
                        spanObj1.set('html',(__headmenu[i]["images"]==''?'':$p.img(__headmenu[i]["images"],false,false,lg(__headmenu[i]["comment"]),"imgmid")+'&nbsp;')+(l_label==''?'':'&nbsp;'+l_label));
                        spanObj1.inject(l_objContainer);
                        var bespace = new Element('span');
                        bespace.set('html','&nbsp;');
                        bespace.inject(l_objContainer);
                        break;
					case "link":
                        var aObj1 = new Element('a', 
                            {
                                'id':__headmenu[i]["id"],
                                'events': {
                                                'click': function()
                                                {
                                                    eval(__headmenu[this.name]["fct"]);
                                                    return false;
                                                },
                                                'mouseover': function(){
                                                $p.app.tabs.showHeadMenu(false);}
                                          },
                                          
                                'class':__headmenu[i]["clss"],
                                'title':lg(__headmenu[i]["comment"]),
                                'href':'#'
                            }
                        );
                        aObj1.name = i;
                        aObj1.set('html',
                            (__headmenu[i]["images"]==''
                                                    ?''
                                                    :'<span style="text-decoration:none">'+$p.img(__headmenu[i]["images"],false,false,lg(__headmenu[i]["comment"]),"imgmid")+'&nbsp;')
                            +(l_label=='</span>'?'':'</span>'+lg(l_label))
                        );	
                        aObj1.inject(l_objContainer);
                        var bespace = new Element('span');
                        bespace.set('html','&nbsp;');
                        bespace.inject(l_objContainer);							
                        break;
					case "menu":
                        var aObj2 = new Element('a', 
                            {
                                'events': {
                                                'click': function(){
                                                $p.app.tabs.initHeadMenu(this,this.name);}
                                          },
                                'class':__headmenu[i]["clss"],
                                'title':lg(__headmenu[i]["comment"]),
                                'href':'#'
                            }
                        );
                        aObj2.name = i;
                        aObj2.set('html',(__headmenu[i]["images"]==''?'':$p.img(__headmenu[i]["images"],false,false,lg(__headmenu[i]["comment"]),"imgmid")+' ')+lg(l_label)+$p.img("puce_down.gif",7,5,"","imgmid"));	
                        aObj2.inject(l_objContainer);
                        var bespace = new Element('span');
                        bespace.set('html','&nbsp;');
                        bespace.inject(l_objContainer);
                        break;
					case "form":
                        var formObj1 = new Element('form', 
                            { 
                                'styles':	{
                                    'margin':'0px',
                                    'padding':'0px',
                                    'display':'inline'
                                    },
                                'events': {
                                    'submit': function(){
                                        eval(this.fct);
                                        return false;
                                        }
                                    },
                                 'class':__headmenu[i]["clss"],
                                 'action':'#'
                             }  
                        );
                        formObj1.fct=__headmenu[i]["fct"];
                        formObj1.set('html',(__headmenu[i]["images"]==''?'':$p.img(__headmenu[i]["images"],false,false,lg(__headmenu[i]["comment"]),"imgmid")+' ')+__headmenu[i]["label"]+'<input name="text" type="text" class="thinbox" style="color:#aaaaaa" onFocus=\'$p.app.tools.inputFocus(this,"'+__headmenu[i]["comment"]+'")\' onBlur=\'$p.app.tools.inputLostFocus(this,"'+__headmenu[i]["comment"]+'")\' value="'+__headmenu[i]["comment"]+'" />'+(__headmenu[i]["options"]==''?'':'&nbsp;<input type="submit" class="btnsmall" value="'+__headmenu[i]["options"]+'" />'));
                        formObj1.inject(l_objContainer);
                        var bespace = new Element('span');
                        bespace.set('html','&nbsp;');
                        bespace.inject(l_objContainer);
                        break;
				}
				(l_objContainer).appendText(' ');
			}
		}
		var endSpace=new Element('span');
		endSpace.set('html','&nbsp; &nbsp; &nbsp;');
		endSpace.inject($('headlink'));

        if (__useChat && $p.chat) $p.chat.displayStatus('span_availability');

		$p.plugin.hook.launch('app.mainMenu.end');
	},
	/*
		Function:  initEvents 
        
                            init page events
	*/
	initEvents:function()
	{
		document.body.onmouseover = function(){
			$p.app.inactivityTime = 0;
			if (__useChat && $p.app.user.status == 'a')
			{
				$p.app.user.status = 'o';
				$p.chat.displayStatus();
			}
				
		}
	},
	/*
		Function: $p.app.checkLoading 
        
                            manage modules loading process
		
                    Parameters:

	:		v_t (boolean) - true=start loading / false=check if loading is ended 
			v_tab - tab sequence ID
	*/
	checkLoading:function(v_t,v_tab)
	{
		if (v_tab==indef) v_tab=$p.app.tabs.sel;
		if (!v_t) {
			if (v_tab!=-1 && v_tab!=indef && tab.length!=0) {
				//only for portals
				if (tab[v_tab].type==1 || tab[v_tab].type==3) {

					if (v_tab == $p.app.tabs.sel && tab[v_tab].root != indef)
						(tab[v_tab].root).setStyle("display","block");

					for (var i=0;i<tab[v_tab].module.length;i++)
                    {
                        if (tab[v_tab].module[i]) tab[v_tab].module[i].show();
                    }
					if (tab[v_tab].showType==1) {
						//Normally, all sources are loaded (showtype=0 on startup) - v1.3.0
						var l_allLoaded=true;
						for (var i=0;i<tab[v_tab].module.length;i++)
						{
							if (tab[v_tab].module[i].format=='R' && !tab[v_tab].module[i].isLoaded)
							{
								l_allLoaded=false;
								//$p.app.widgets.rss.refresh(i); Suppressed with 1.4.2
							}
						}
						if (!l_allLoaded) $p.app.widgets.rss.reader.showArticlesList(true,$p.app.widgets.rss.reader.currSrc);
					}
					additionalMod();
					//check for tab status ( loading or loaded)
					var l_allLoaded=true;
                    
                    
					for (var i=0;i<tab[v_tab].module.length;i++)
					{
						if (    
                                tab[v_tab].module[i]
                                && tab[v_tab].module[i].format=='R' 
                                && !tab[v_tab].module[i].isLoaded)
						{
							l_allLoaded=false;
						}
					}
                    
                    if (l_allLoaded)
					{
						tab[v_tab].isLoaded=true;
						$p.app.tabs.refresh(v_tab);
					}
				}
			}

			if ($p.app.isLoading) $p.app.stopLoading();
		}
	},
	/*
		Function:  $p.app.stats 
        
                            statistics management
	*/
	stats:function()
	{
		if($p.app.tabs.sel != -1 && $p.app.user.id > 0 && $p.app.user.type != 'N') {
			$p.ajax.call(posh["scr_addstats"],
				{
					'type':'execute',
					'variables':"prof="+tab[$p.app.tabs.sel].id+"&id="+$p.app.user.id,
					'alarm':false
				}
			);
		}
	},
	/*
            Function:  $p.app.getVersion 
            
                        define application versoion
            */
	getVersion:function()
	{
		
		p_version = (typeof(__PEEVERSION) == 'undefined' ? __POSHVERSION : __PEEVERSION);
	},
	/*
		Function: $p.app.standalone
        
                        create widget in an HTML page (outside posh)
        
		Parameters:

                                v_rootObj (string) - element ID to print in
			v_columnNumber (integer) - number of columns
			v_widgetAligned (boolean) - define if the widget are aligned
                                v_tabPos - tab position (used in administration to display widget)
	*/
	standalone: function(v_rootObj,v_columnNumber,v_widgetAligned,v_tabPos)
	{
		$p.app.tabs.selId = 0;
        allowSave         = false;
		useMod            = false;
        standaloneMode    = true;

        if (typeof(v_tabPos) == 'undefined') {
            $p.app.tabs.sel = 0;
            tab[$p.app.tabs.sel] = new $p.app.tabs.object(1);
        }
        else {
            $p.app.tabs.sel = v_tabPos;
        }

		//add tab information (even if not physically created)
		if(tab[$p.app.tabs.sel]) {
			tab[$p.app.tabs.sel].root = v_rootObj;
			tab[$p.app.tabs.sel].colnb = v_columnNumber;
			tab[$p.app.tabs.sel].moduleAlign = v_widgetAligned;
			
			// add columns
			//tab[$p.app.tabs.sel].cells = [];
			$p.app.pages.columns.createAll($p.app.tabs.sel);
		}
	},
    /*
		Function: $p.app.loadHomeHeader
        
                        Load the header of the home page
        	*/
    loadHomeHeader: function()
    {
        // $p.ajax.call(pep["xml_user_properties"],
            // {
                // 'type':'load',
                // 'callback':
                // {
                    // 'function':$p.app.displayHomeHeader
                // }
            // }
        // );
        $p.app.displayHomeHeader();
    },
    displayHomeHeader: function(response,vars)
    {
        var l_s = $p.html.buildFeatureHeader({
            'image':($p.app.user.picture == '' ? '../images/nopicture.gif' : $p.app.user.picture),
            'menu':'<div id="homeheader_menu" style="padding-top: 6px;">'
                    + '<form onsubmit=\'return $p.network.profile.updateStatus(this.stat)\'>'
					+ '<div style="background: url(../images/speech.gif) no-repeat;width: 500px;padding: 0px 15px 2 0;">'
                    + '<input name="stat" value=\'' + (__NETWORK_TYPE == 'R' ? lg("myStatus") : lg('myStatusFollowers')) + '\' maxlength="200" style="width: 340px;padding: 0px;border: 0px;height: 18px;color: #aaaaaa;margin: 0px;margin-left: 16px;background: transparent;"  onFocus=\'$p.navigator.inputFocus(this,"' + (__NETWORK_TYPE == 'R' ? lg("myStatus") : lg('myStatusFollowers')) + '")\' onBlur=\'$p.navigator.inputLostFocus(this,"' + (__NETWORK_TYPE == 'R' ? lg("myStatus") : lg('myStatusFollowers')) + '");\'/> &nbsp;'
                    + '&nbsp;<input type="submit" class="btn" value="'+lg("lblBtnSend")+'" />'
					+ '</div>'
                    + '</form>'
                    + '<div style="padding-top: 12px;padding-bottom: 6px;">'
					+ '<a href="#" onclick="$p.notebook.open(indef,indef,indef,1)">' + lg('manageYourPersonalInformation') + '</a>'
                    + (__useNetwork ? ' | <a href="#" onclick="$p.notebook.open(indef,indef,indef,3);return false;">' + lg('manageYourNetwork') + '</a>' : '')
                    + (__useGroup ? ' | <a href="#" onclick="$p.notebook.open(indef,indef,indef,7);return false;">' + lg('manageYourGroups') + '</a>' : '')
                    + (__useNotebook ? ' | <a href="#" onclick="$p.notebook.open()">' + lg('Notebook') + '</a>' : '')
                    + '</div>'
                    + '</div>'
        });
        $p.print('homeheader',l_s);
    },
    /*
		Function: $p.app.incrementNbConnection

                Increment the number of connection to the portal
    */
    incrementNbConnection: function()
    {
        //get previous number of connections
        var l_nbConnection = $p.cookie.get('nbconn');
        
        if (l_nbConnection == '')
        {
            l_nbConnection = 0;
        }
        l_nbConnection = parseInt(l_nbConnection,10) + 1;
        //save new number of connection
        $p.cookie.write('nbconn='+l_nbConnection);
    },
	/*
		Function: $p.app.displayUserProfile

                Display the user profile information in the header
    */
	displayUserProfile: function(v_container)
	{
		var l_s = (($p.app.user.picture == '') ? '' : '<img id="profileimage" src="' + $p.app.user.picture + '" onclick="$p.network.myprofile();">')
			//+ '<div id="profiletitle">' + lg('personalAreaOf') + '</div>\
			+ '<div>'
			+ '<div id="profiledesc" style="display: block;height: 30px;">\
				<div id="profilename"><a href="#" onclick="$p.network.myprofile();">' + $p.app.user.name + '</a></div>\
				<div id="profilechat"></div>\
				<a class="profilelogout" href="#"  title="' + lg('lblDisconnect') + '">\
					<img onclick="$p.app.logout();" src="../images/s.gif" alt="' + lg('lblDisconnect') + '"/>\
				</a>'
			+ ($p.app.user.type == 'A'
				? '<a class="profileadmin" href="../admin/" title="' + lg('adminInterface') + '"><img src="../images/s.gif" alt="' + lg('adminInterface') + '"/></a>'
				: '')
			+ '</div>'
			+ '<div id="profilestatus"></div>'
			+ '</div>';
		$p.print(v_container, l_s);
		
		$p.network.profile.loadStatus();
		
		if (__useChat && $p.chat)
			$p.chat.displayStatus('profilechat');
	}
}


//******************* TOOLS FUNCTIONS ***********************************************************************************************************************
/*
    class: $p.app.tools
*/
$p.app.tools={
    /*
	Function: getRadioValue
                    $p.app.tools.getRadioValue 
                    
                    get a radio input value
	
           Parameters:

                    radio elements
	
	Returns:
			
                    false or the value of the radio button selected            
	*/
	getRadioValue:function(v_element)
	{
		for (var i=0; i<v_element.length;i++)
		{
			if (v_element[i].checked) return v_element[i].value;
		}
		return false;
	},
    setRadioValue: function(v_input,v_value)
    {
        for (var i = 0; i < v_input.length; i++)
        {
            if (v_input[i].value == v_value) v_input[i].checked = true;
        }
    },
    /*
	          Function: inputFocus
                                $p.app.tools.inputFocus 
                                
                                Clear an input on focus	

                     Parameters:
                        
                                v_input - current input value
                                v_def - default input value
	*/
	inputFocus:function(v_input,v_def)
	{
		if (v_input.value==v_def)   {
			v_input.value='';
			v_input.style.color='#000000';
		}
	},
    /*
		Function: inputLostFocus
                                $p.app.tools.inputLostFocus 
                                
                                Fill an input field with its default value

                     Parameters:
                        
                                v_input - current input value
                                v_def - default input value
	*/
	inputLostFocus:function(v_input,v_def)
	{
		if (v_input.value=='')  {
			v_input.value=v_def;
			v_input.style.color='#aaaaaa';
		}
	},
    /*
                Function: buildPreviousLinkIcon
                
                                $p.app.tools.build previous icon
                  
                   Parameters: 
                   
                            jslink - link js to add on an onclick event
                     
                    Returns : HTML
            */
    buildPreviousLinkIcon: function (jslink) {
        return '<a href="#" class="previousIcon" onclick=\''+jslink+';return false;\' >'
               + $p.img('ico_previous3.gif',8,11,lg('previous'),"imgmid")
               +' '
               +lg('previous')
               + '</a>';
    },
    /*
                Function: buildNextLinkIcon
                
                                $p.app.tools.build previous icon
                  
                   Parameters: 
                   
                            jslink - link js to add on an onclick event
                            
                    Returns: HTML
            */    
    buildNextLinkIcon: function (jslink) {
        return '<a href="#" class="nextIcon" onclick=\''+jslink+';return false;\' >'
                +lg('next')
                +' '
               +$p.img('ico_next3.gif',8,11,lg('next'),"imgmid")
               + '</a>';    
    },
    /*
                   Function: checkmail
                
                                $p.app.tools.checkmail 
                                
                                check if an email has valid syntax
                  
                   Parameters: 
                   
                                adress (string) - adress to verify
                            
                   Returns: 
                                
                                true if format correct
            */ 
    checkmail:function(adress)
    {
        var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        if (!adress) return false;
        else {
            if (!filter.test(adress)) { return false; }
            else { return true; }
        }
    },
    /*
                Function: $p.app.tools.getmetaContents
            */
    getmetaContents: function getmetaContents(meta){

      var m = document.getElementsByTagName('meta'); 
      for(var i in m){ 
           if( m[i].name == meta){ 
             return m[i].content; 
           } 
      } 
    },
    /*
	          Function: resizeFrameHeigth
                                $p.app.tools.resizeFrameHeigth 
                                
                                Resize a frame so there is no vertical scrollbar
                                
                     Parameters:
                        
                                frameId - id of the frame
	*/
    resizeFrameHeigth:function(frameId)
    {   
        var the_height=document.getElementById(frameId).contentWindow.document.body.scrollHeight;
        document.getElementById(frameId).height=the_height+10;
    },
    /*
    Function: $p.app.tools.encryptData
                    
                    Encrypt a data with an encryption key
    
           Parameters:

                    v_data - string
                    key - string
    
    Returns:
            
                    String - Encrypted data
    */
    encryptData:function(v_data, key)
    {
		var coordphrase = new Array();
		var coordphrase_cle = new Array();
		var newcoord=new Array();
		var coordData_key=new Array();
		var coordData=new Array();
		var encryptedData = "";
		var dataKey = "";
		var car=0;
		var data = v_data;
		var alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?.;:=+-()/@%$*& ";
		if (data != "" && key != "")
		{
          for (var z=0; z<data.length; z++)
          {
              dataKey += key.charAt(car);
              car++;
              if (car == key.length)
              car=0;
          }
          for (var k=0; k<data.length; k++)
          {
				for (var p=0; p<alpha.length; p++)
				{
					if (data.charAt(k) == alpha.charAt(p))
						coordData[k] = p;
					if (dataKey.charAt(k) == alpha.charAt(p))
						coordData_key[k] = p;
				}
				newcoord[k] = coordData[k]+coordData_key[k];
				if (newcoord[k] > alpha.length-1) {
					newcoord[k] -= alpha.length;
				}
				encryptedData += alpha.charAt(newcoord[k]);
			}
		}
    
      return encryptedData;
    },
    /*
    Function: $p.app.tools.decryptData
                    
                    Decrypt a data with an encryption key
    
           Parameters:

                    v_data - string
                    key - string
    
    Returns:
            
                    String - Data decrypted
    */
    decryptData:function(v_data, key)
    {
		var coordcrypt=new Array();
		var alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?.;:=+-()/@%$*& ";
		var decryptData="";
		var encryptedData="";
		var car=0;
		this.key=key;
		var crypt=v_data;
		if (key != "" && crypt != "")
		{
        for (var i=0; i<crypt.length; i++)
        {
            for (var b=0; b<alpha.length; b++)
            {
            if (crypt.charAt(i)==alpha.charAt(b))
            coordcrypt[i]=b;
            }
        }
        for (var j=0; j<crypt.length; j++)
        {
            encryptedData+=key.charAt(car);
            car++;
            if (car==key.length)
            car=0;
        }
        for (var k=0; k<encryptedData.length; k++)
        {
            for (var u=0; u<alpha.length; u++)
            {
            if (encryptedData.charAt(k)==alpha.charAt(u))
            coordcrypt[k]-=u;
            if (coordcrypt[k] < 0)
            coordcrypt[k]+=alpha.length;
            }
        }
        for (var m=0; m<crypt.length; m++)
        {
            decryptData+=alpha.charAt(coordcrypt[m]);
        }
       }
        
       return decryptData;
    }
}



//******************* USERS FUNCTIONS ***********************************************************************************************************************
/*
    Class: $p.app.user
            User functions
*/
$p.app.user={
    userCriterias:{},
	id:0,
	name:'',
	status:'o',
	stat:'',
    type:'',
    picture:'',
    /*
                Function: init
                         $p.app.user.init
                                        
                         Initialise a user

                 Parameters:
                    
                            id - user id
                            name - user name
                            type - user type
                            status - user status (chat)
                            picture - user picture
                             longname - long name
                            lang - lang (from database)
							email - email address of the user
	*/    
	init: function(id, longname, type, status, picture,username,lang,email)
	{
		$p.app.user.id = id;
		$p.app.user.name = longname;
        $p.app.user.type = type;
        $p.app.user.status = (status == indef ? 'o' : status);
        $p.app.user.picture = (picture == indef || picture == '' ? '../images/nopicture.gif' : picture);
        $p.app.user.username = username;
        $p.app.user.lang = lang;
		$p.app.user.email = email;
        $p.app.user.parameters={
                                'name':{'type':'string','label':'lblName','display':true},
                                'type':{'type':'string','label':'userType','display':false},
                                'picture':{'type':'img','label':'','display':true},
                                'status':{'type':'string','label':'status','display':false},
                                'username':{'type':'string','label':'lblLogin','display':true},
                                'lang':{'type':'string','label':'lblLang','display':true}
                                };
        encryptKey = $p.cookie.get("encrypt_key");
   },
    /*
    
        Function: $p.app.user.updateUser
        
            Add new params to user ($p.app.user class)
            
        Parameters: 
            name - name of parameter
            value - value
    */
    updateUser: function (name,value) {
        $p.app.user[name] = value;
    
    },
    /*
            Function: $p.app.user.myprofile
            
                Posh Portal : Display user profile in a popup 
                
                Hook : app.user.myprofile.end
    */
    myprofile: function () {
    
        var l_s = '<div>'
                + '<div id="myprofile"></div>'
                + '<div id="userdatas"></div>'
                + '<div id="otherCriteria"></div>'
                + '<div id="mypassword"></div>'
                + '<div id="changeuser"></div>'
                + '<div id="userlang"></div>'
                + '<div id="unsubscribelink"></div>';
                +'</div>';
        $p.app.popup.show(l_s,500,indef, $p.app.user.name +' ' + lg('myProfile')  );
        $p.network.loadUserCriteria();
        $p.network.profile.displayUserDatas();
        if (__passwordChangePermission) {
            $p.network.profile.passwordMenu();
        }
        if (__userChangePermission) {
            $p.network.profile.changeUserMenu();
        }
        
        $p.network.profile.changeLang();
         
        if (__defaultmode == "anonymous") {
            $p.network.profile.unsubscribe();
        } 
     
        $p.plugin.hook.launch('app.user.myprofile.end');
    },
    render:function()
    {
      return {
                'name':$p.app.user.name, 
                'id':$p.app.user.id
             };
    }
}


//******************* MENUS FUNCTIONS ***********************************************************************************************************************
/*
    Class: $p.app.menu
            Menu functions
*/
$p.app.menu={
	template:[],
	initialized:false,
	isOpen:indef,
	options:[],
	optionSelected:0,
	subOptSelected:indef,
    optionSelectedId:indef,
    menuOpt:{},
	/*
		Function: init
                                $p.app.menu.init

                                Init a menu
	*/
	init: function()
	{
		$p.plugin.hook.launch('app.menu.init.start');

		//if menu always closed
		if ( __menuDefaultStatus==4 && $p.app.env!="admin")
            return false;
            
        if ($p.app.menu.initialized)
            return false;
		
		if ($p.app.user.id == 0 && __MENU_HIDDEN_IN_ANONYMOUS_PAGES)
			return false;

		$p.app.menu.template['h'] = {
			'container':'hmenu',
			'htmltpl':'<div id="hmenucontent">'
                // + '<div id="menubuttons"></div>'
				+ '<div id="hmenuheader"></div>'
				+ '<table width="100%" cellpadding="0" cellspacing="0">'
				+ '<tr>'
				+ '<td valign="top" id="hmenuoptions">'
				+ '<div id="menuheader"></div>'
				+ '<div id="menuoptions"></div>'
				+ '</td>'
				+ '<td id="menusuboptions"></td>'
				+ '<td id="menucontent"></td>'
				+ '</tr>'
				+ '</table>'
                + '</div>'
                + '<div id="hmenuopen" class="closed" onclick="$p.app.menu.open();" style="cursor: pointer;cursor: hand;">'+$p.img('s.gif',300,14)+'</div>',
			'displayType':'table-cell',
            'controler':'hmenuopen',
			'options':
			{
				'showIcon':true,
				'showLabel':true
			}
		};
		$p.app.menu.template['v'] = {
			'container':'vmenu',
			'htmltpl':'<table cellpadding="0" cellspacing="0" border="0">'
                + '<tr>'
                + '<td valign="top">'
                + '<div id="vmenucontent">'
				+ '<div id="menuheader"></div>'
                + '<div id="menubuttons" style="display: none;"></div>'
                + '<div id="menuoptions"></div>'
				+ '<div id="menusuboptions"></div>'
				+ '<div id="menucontent"></div>'
                + '</div>'
                + '</td>'
                + '<td valign="top">'
                + '<div id="vmenuopen" class="closed" onclick="$p.app.menu.open();" style="cursor: pointer;cursor: hand;">&nbsp;</div>'
                + '</td>'
                + '</tr>'
                + '</table>',
			'displayType':'block',
            'controler':'vmenuopen',
			'options':
			{
				'showIcon':true,
				'showLabel':true
			}
		};

		//build the menu
		$p.print($p.app.menu.template[__menuposition].container,$p.app.menu.template[__menuposition].htmltpl);
        //empty the options and the content of the menu
		$p.app.menu.clean();
		$p.app.menu.closeAllSubMenus();
        //hide the headers
		$p.app.menu.hideOptions();
        $p.app.menu.hide();
        //sort the options
        $p.app.menu.options.sort($p.app.menu.sortOptions);
		//create a close button
        $p.app.menu.displayCloseButton();
		//build the header
		//$p.app.menu.displayHeader();
		$p.app.menu.initialized = true;

		if (__menuDefaultStatus == 3
			|| (__menuDefaultStatus == 2 && $p.cookie.get('showmenu') == 1))
		{
			$p.app.menu.open();
		}
        // hide menu if blocked page
        if (tab[$p.app.tabs.sel] && tab[$p.app.tabs.sel].controls)
        {
            if (tab[$p.app.tabs.sel].controls == 'N') $p.app.menu.hideControl();
        }

		$p.plugin.hook.launch('app.menu.init.end');
	},
	/*
		Function: clean
                                $p.app.menu.clean
                                
                                Clean the menu area
	*/
	clean: function()
	{
		$p.app.menu.emptyOptions();
		$p.app.menu.emptySubOptions();
		$p.app.menu.emptyContent();
	},
    /*
		Function: hideControl
        
                                $p.app.menu.hideControl 
                                
                                hide the control that open the menu
	*/
    hideControl: function()
    {
        if ($p.app.menu.template && $p.app.menu.template[__menuposition])
        {
            $p.show($p.app.menu.template[__menuposition].controler,'none');
			$p.app.menu.hide();
        }
    },
    /*
		Function: displayControl
        
                                $p.app.menu.displayControl 
                                
                                display the control that open the menu
	*/
    displayControl: function()
    {
        if ($p.app.menu.template && $p.app.menu.template[__menuposition])
            $p.show($p.app.menu.template[__menuposition].controler,'block');
    },
    /*
		Function: emptyOptions
        
                                $p.app.menu.emptyOptions 
                                
                                Empty menu options content
	*/
	emptyOptions: function()
	{
		($('menuoptions')).empty();
	},
    /*
		Function: emptySubOptions
        
                                $p.app.menu.emptySubOptions 
                                
                                Empty menu sub options content
	*/
	emptySubOptions: function()
	{
		($('menusuboptions')).empty();
	},
    enableAllMenuLinks:function()
    {
        for (var i in $p.app.menu.menuOpt)
        {
            $p.app.menu.menuOpt[i]=false;
        }
	},
	closeAllSubMenus: function()
	{
		for (var i in $p.app.menu.options)
		{
			for (var j in $p.app.menu.options[i].subOptions)
			{
				$p.app.menu.options[i].subOptions[j].opened = false;
			}
		}
    },    
    enableMenuLinks:function(v_id)
    {
        $p.app.menu.menuOpt[v_id]=true;
        for (var i in $p.app.menu.menuOpt)
        {
            if (i!=v_id) {
                $p.app.menu.menuOpt[i]=false;
            }
        }  
    },
	/*
		Function: emptyContent
                                $p.app.menu.emptyContent 
                                
                                Empty menu content
	*/
	emptyContent:function()
	{
		($('menucontent')).empty();
	},
	/*
		Function: hideOptions
                                $p.app.menu.hideOptions
                                
                                Hide the options (if no options in the menu, the menu remains closed)
	*/
	hideOptions:function()
	{
		$p.show('menuoptions','none');
		$p.show('menusuboptions','none');
	},
	/*
		Function: buildOptions
                                $p.app.menu.buildOptions
                                
                                Display the Options
                                
		Parameters:

			v_option (int) - id of the first level menu options tab 
			v_subOption - id of the second level of options
	*/
	buildOptions:function(v_option,v_subOption)
	{
		$p.app.menu.clean();
		$p.app.menu.closeAllSubMenus();
		$p.app.menu.hideOptions();
		
        //returns the number of the last opened subOption
		var l_someOptions=$p.app.menu.getOptions(v_option,v_subOption);
		eval($p.app.menu.options[$p.app.menu.optionSelected]["action"]);
    },
	showSubOptions:function(v_option)
	{
		if (__menuposition == 'h')
		{
			$p.print('menusuboptions',$p.app.menu.getSubOptions(v_option));
			$p.show('menusuboptions','');
		}
		else
		{
			if ($p.app.menu.options[v_option].opened)
			{
				$p.show('menusubopt_'+$p.app.menu.options[v_option].id,'none');
				$p.app.menu.options[v_option].opened = false;
			}
			else
			{
				if (($('menusubopt_'+$p.app.menu.options[v_option].id)).innerHTML == '')
				{
					$p.print('menusubopt_'+$p.app.menu.options[v_option].id,$p.app.menu.getSubOptions(v_option));
				}
				else
				{
					$p.show('menusubopt_'+$p.app.menu.options[v_option].id,'block');
				}
				$p.app.menu.options[v_option].opened = true;
			}
		}
    },
	/*
		Function: open
                                $p.app.menu.open 
                                
                                Open the menu
                                
		Parameters:

			v_selOption (string) - option selected on menu opening
			v_forceOpen (boolean) - force the menu to open status
	*/
	open: function(v_selOption,v_forceOpen)
	{
		if ( $p.app.menu.isOpen && v_forceOpen == indef ) {
			$p.app.menu.close();
		}
		else {
            if ( !$p.app.menu.initialized && $p.app.env!="admin" ) {
                $p.app.menu.init();
            }
            
            //check if menu must be opened or not
			if ( __menuDefaultStatus == 4 && $p.app.env != "admin" ) {  
                return false; 
            }
            
			$p.app.menu.show();
			//$p.app.menu.getActivateOptions(v_selOption);
            
            $p.app.menu.buildOptions($p.app.menu.optionSelected,$p.app.menu.subOptSelected);
            $p.app.menu.place();
		}
	},
	/*
		Function: show
                        
						$p.app.menu.show
                                
                                Show the menu
	*/
	show: function()
	{
		$p.plugin.hook.launch('app.menu.show.start');

        //Menu horizontal
		if (__menuposition == 'h')
        {
            widgetDecalY = $p.getPos($("area"),"Top")+30;
			$p.app.widgets.place($p.app.tabs.sel);
		}
		else
		{
			if (widgetDecalX != leftMenuWidth)
			{
				widgetDecalX = leftMenuWidth;
                ($("vmenu")).style.width = (leftMenuWidth + 10)+'px';

				// if ($("menus") != null)
				// {  
                    // ($("menus")).style.marginLeft = widgetDecalX+"px";   
                // }
				if($("tabscontent"))
					($("tabscontent")).style.marginLeft = widgetDecalX+"px";
				// if ($("plugin") != null)
				// {
                    // ($("plugin")).style.marginLeft = widgetDecalX+"px"; 
                // }
				// if ($("newspaper") != null)
				// {
                    // ($("newspaper")).style.marginLeft = widgetDecalX+"px"; 
                // }			
				$p.app.menu.place();
				$p.app.widgets.place($p.app.tabs.sel);
			}
		}
		//display the menu
		$p.show($p.app.menu.template[__menuposition].container + 'content','block');
        //$p.show(__menuposition + 'menuopen','none');
		$p.setClass(__menuposition + 'menuopen','opened');
		//define the menu as opened
		$p.app.menu.isOpen = true;
		//save menu open/close status
		$p.cookie.write('showmenu=1');

		$p.plugin.hook.launch('app.menu.show.end');
	},
	/*
		Function: place
                                $p.app.menu.place
        
                                Place the vertical menu
	*/
	place:function()
	{
  
		if (__menuposition == 'v') {
			var l_leftMenuTopPos = $p.getPos($("area"),"Top");
			($("vmenu")).style.top = l_leftMenuTopPos+"px";
		}
        else{
            widgetDecalY = $('hmenu').offsetHeight;
			$p.app.widgets.place($p.app.tabs.sel);
        }
	},
	/*
		Function: displayCloseButton
                                $p.app.menu.displayCloseButton

                                Display the close button in the menu
	*/   
    displayCloseButton:function()
    {
		$p.print('menubuttons',
            '<div id="menuclosebutton" style="float: right;">'
            + '<span style="margin: 5px;">'
            + '<a href="#" onclick="$p.app.menu.close()" style="text-decoration: none;">'
            + '&laquo; '+lg("lblClose")
            + ' </a>'
            + '</span>'
            + '</div>');
    },
	// /*
		// Function: displayHeader
                                // $p.app.menu.displayHeader

                                // Display the menu header
	// */   
    // displayHeader:function()
    // {
		// if ($p.app.user.id > 0 && $p.app.user.type!="N")
		// {
			// var l_s = '\
				// <div id="menuheaderprofile">\
				// <img src="' + $p.app.user.picture + '" style="width: 42px;float: left;margin: 7px;">\
				// <div>\
					// <b>' + $p.app.user.name + '</b><br />\
					// <a href="#" onclick="$p.network.myprofile();return false;" style="font-size: 0.85em;text-decoration: none;">' + lg('modifyProfile') + '</a><br />';
			
			// if (__useNotebook)
				// l_s += '<a href="#" onclick="$p.notebook.open();return false;" style="font-size: 0.85em;text-decoration: none;">' + lg('viewMyNotebook') + '</a><br />';
				
			// if (__useNetwork)
				// l_s += '<a href="#" onclick="$p.network.dashboard.loadDirectory();return false;" style="font-size: 0.85em;text-decoration: none;">' + lg('usersDirectory') + '</a><br />';
			
			// l_s += '</div>'
				// + '<div class="float_correction"></div>'
				// + '</div>';
			
			// $p.print('menuheader',l_s);
		// }
    // },
	/*
		Function: close
                                $p.app.menu.close
                                
                                Close the menu
	*/
	close:function()
	{
        $p.app.menu.initialized = false;
		$p.app.menu.hide();
        //$p.app.menu.enableAllMenuLinks();
	},
	/*
		Function: hide
                                $p.app.menu.hide
                                
                                Hide the menu
	*/
	hide:function()
	{
		$p.app.menu.isOpen = false;
		
		if (__menuposition == "h")    {
			widgetDecalY = 0;
			$p.show("hmenucontent","none");
		} 
		else    {
			if ($("menus") != null)
			{
				widgetDecalX = leftMenuWidthMin;
				$p.show("vmenucontent","none");
                ($("vmenu")).style.width = (leftMenuWidthMin + 10)+'px';
                //$p.show("vmenuopen","block");
				// if ($("menus") != null) {
                    // ($("menus")).setStyle("marginLeft",widgetDecalX+"px"); 
                // }
				if($("tabscontent"))
					($("tabscontent")).setStyle("marginLeft",widgetDecalX+"px");
                //if a plugin is displayed
				// if ($("plugin") != null) {
					// ($("plugin")).setStyle("marginLeft",widgetDecalX+"px");
                // }
                //if the rss reader is opened
				// if ($("newspaper") != null)   {
					// ($("newspaper")).style.marginLeft=widgetDecalX+"px";
					// if ($p.app.env == 'portal_reader') $p.app.widgets.rss.reader.framesSize();
				// }
			}
		}
		
		$p.setClass('vmenuopen','closed');
		
        //redefine the widgets place
		$p.app.widgets.place($p.app.tabs.sel);
		if (__menuposition == "v")    { $p.app.pages.resize(); }
//		if ($p.app.banner.option.shown) {   $p.app.banner.option.hide(); }
		
		$p.cookie.write('showmenu=0');
	},
	/*
		Function: getActivateOption
                                $p.app.menu.getActivateOption 
                                
                                Search the activate option and suboption
                                
		Parameters:

			v_selOption (string) - option selected on menu opening
	*/
    getActivateOptions:function(v_selOption)
    {
        //search the menu option to activate
		if (v_selOption == indef) {
			$p.app.menu.optionSelected = indef;
			$p.app.menu.subOptSelected = indef;
		}
		else    {
			var l_posInArray = $p.app.menu.getOptionById(v_selOption);
			if (l_posInArray)
			{
				$p.app.menu.optionSelected = l_posInArray;
				$p.app.menu.subOptSelected = indef;
                $p.app.menu.optionSelectedId = v_selOption;
			}
		}
    },
	/*
		Function: getOptionById
                                $p.app.menu.getOptionById 
                                
                                Get the option in the array based on its ID
                                
		Parameters:

			v_id (string) - id of the option you want to get
	*/
	getOptionById: function(v_id)
	{
		for (var i = 0;i < $p.app.menu.options.length;i++)
		{
			if ($p.app.menu.options[i]['id'] == v_id)
			{
				return i;
			}
		}
		return false;
	},
	/*
		Function: getOptions
                                $p.app.menu.getOptions
        
                                Get the selected options and Generate the menu options
                                
                      Parameters:
                      
                                v_option - id of the first level menu options tab 
			v_subOption - id of the second level of options
            
                        Returns:
                        
                                The id of the selected subOptions
	*/
	getOptions: function(v_option,v_subOption)
	{
        //unlock menus options and widget explorer
        $p.app.menu.menuOpt['confmenu_1']=false;
        $p.app.menu.menuOpt['addmenu_3']=false;
        
		if ($p.app.menu.options.length == 0) return false;

		var l_s = '';
		$p.app.menu.hideOptions();
		$p.app.menu.emptyContent();
		$p.app.menu.emptySubOptions();

		//tab selection
		if (v_option == indef)    {
			if ($p.app.menu.optionSelected == indef)  {
				$p.app.menu.optionSelected = 0;
			}
		}
		else    {
			$p.app.menu.optionSelected = v_option;
 		}
        
		//sub tab selection
		(v_subOption != indef)	? $p.app.menu.subOptSelected=v_subOption
								: '' ;
		if ($("menuoptions") != null)
		{
			if ($p.app.menu.options.length > 0)
			{
				$p.show("menuoptions",$p.app.menu.template[__menuposition].displayType);
				
				l_s += '<ul class="menulist">'
			}

			var l_hasOptions = false;
			for (var i = 0;i < $p.app.menu.options.length;i++)
			{
				$p.plugin.hook.launch('app.menu.getOptions.createOption');
				
				l_hasOptions = true;
				//if the option is the selected one
				l_s += '<li id="menuopt_'+$p.app.menu.options[i]["id"]+'">'
					+ ($p.app.menu.options[i].type && $p.app.menu.options[i].type == 'label'
						? '' 
						: '<div style="text-align: center;background: #E9E4E8;margin-bottom: 6px;"><a href="#" onclick="$p.app.menu.subOptSelected=indef;'
							+ ($p.app.menu.options[i]["action"] == '' ? '$p.app.menu.showSubOptions('+i+');' : $p.app.menu.options[i]["action"]+';')
							+ 'return false;" title="'+$p.app.menu.options[i]["desc"]+'">');
							
				if ($p.app.menu.template[__menuposition].options.showIcon)
				{
					l_s += $p.img($p.app.menu.options[i]["icon"],16,16,$p.app.menu.options[i]["desc"],"imgmid")+' ';
				}
				if ($p.app.menu.template[__menuposition].options.showLabel)
				{
					l_s += '<b>' + $p.app.menu.options[i].label + '</b>';
				}
				l_s += ($p.app.menu.options[i].type && $p.app.menu.options[i].type == 'label' ? '' : '</a></div>');
				
				if (__menuposition == 'v')
				{
					l_s += '<ul id="menusubopt_' + $p.app.menu.options[i]["id"] + '">'
						+ ($p.app.menu.options[i].opened ? $p.app.menu.getSubOptions(i) : '')
						+ '</ul>';
				}

				l_s	+= '</li>';
			}
			$p.app.menu.emptyOptions();
			
			if ($p.app.menu.options.length > 0)
			{
				l_s += '</ul>';
			}
			$p.print("menuoptions",l_s);
		}
		return l_hasOptions;
	},
	getSubOptions: function(v_optionId)
	{
		var l_subOptions = $p.app.menu.options[v_optionId].subOptions,
			l_s = '';

		for (var i = 0; i < l_subOptions.length; i++)
		{
			$p.plugin.hook.launch('app.menu.getSubOptions.createSubOption');
			
			if (!l_subOptions[i].condition || l_subOptions[i].condition())
			{
				l_s += '<li>'
					+ '<div id="' + l_subOptions[i].id + '" class="menuitem" '
					+ (l_subOptions[i].type && l_subOptions[i].type == 'label' ? '' : ' style="cursor: pointer;cursor: hand;" onclick=\'$p.app.menu.openSubMenu("' + v_optionId + '","' + i + '");\' ')
					+ '>';
			
				if (__menuposition == 'v' && (!l_subOptions[i].type || l_subOptions[i].type == 'submenu'))
				{
					l_s += '<div id="' + l_subOptions[i].id + 'contentbtn" style="float: right;">'
						+ String.fromCharCode(8744)
						+ '</div>';
				}
				
				l_s += l_subOptions[i].label
					+ '</div>'
					+ (__menuposition == 'h' ? '' : '<div id="' + l_subOptions[i].id + 'content" class="menuitemcontent"></div>')
					+ '</li>';
			}
		}

		return l_s;
	},
	/*
	         Function: addTitle
                                $p.app.menu.addTitle 
                                
                                Add a title element
		
                    Parameters:

			v_id(int) - item id
			v_icon(str) - icon
			v_label(str): item label
			v_fct(function) - additional function called on click on title
			
			** DEPRECATED ON 2.2.3 (EMA) **
	*/
	addTitle:function(v_id,v_icon,v_label,v_fct)
	{
		var l_title=new Element('div',
			{
				'id':v_id,
				'class':'menuitem',
				'events':{
					'click':function(){
						$p.app.menu.openSubMenu(this.id);
					}
				}
			}
		);
        //add close button
        if (__menuposition == 'v')
        {
            l_openBtn = new Element('div',
                {
                    'id':v_id+'contentbtn',
                    'styles':
                    {
                        'cursor':'pointer',
                        'cursor':'hand',
                        'float':'right'
                    }
                }
            );
            l_openBtn.appendText(String.fromCharCode(8744));
            l_openBtn.injectInside(l_title);
        }
		l_title.fct = v_fct;
		l_img=new $p.imgObj(v_icon,indef,indef,'','imgmid');
		l_img.injectInside(l_title);
		l_title.appendText(' '+v_label);

		if (__menuposition == 'h')
		{
			$p.show('menusuboptions',$p.app.menu.template[__menuposition].displayType);
			$('menusuboptions').appendChild(l_title);
		}
		else
		{
			l_title.injectInside($('menucontent'));
			//l_title.injectInside($('menusubopt_' + ));
		}
	},
	/*
		Function: addArea
                                $p.app.menu.addArea 
                                
                                Add a title element
		
                    Parameters:

			v_id(int) - title item ID
			v_html(str) - HTML of area
                                v_visible(boolean) - display le element or not 
	*/
	addArea:function(v_id,v_html,v_visible)
	{   
		if (__menuposition == 'h')
		{
			($('menucontent')).set('html',v_html);
		}
		else
		{
			($(v_id + 'content')).set('html',v_html);
		}
		
		return;
		
		
		/* removed on 2.2.3 (EMA)
        if ($(v_id+'content') == null)
        {
            var l_content = new Element('div',
                {
                    'id':v_id+'content',
                    'class':'menuitemcontent'
                }
            );
        }
        else
        {
            l_content = $(v_id+'content');
        }

		l_content.set('html',v_html);
		if (__menuposition == 'h') {
			l_content.injectInside($('menucontent'));
		}
		else {
            if (typeof($p.app.menu.menuOpt[v_id])=='undefined' 
                || $p.app.menu.menuOpt[v_id]==false) {
                    l_content.inject($(v_id),'after');
            }
            $p.app.menu.enableMenuLinks(v_id);
		}
		if (v_visible 
            && __menuposition == 'v') {
                l_content.setStyle('display','block');
        }
        //compute menu placement and size
        $p.app.menu.place();*/
	},
 	/*
		Function: addHTML
                                $p.app.menu.addHTML 
                                
                                Add a HTML element
		
                    Parameters:

			v_id(int) - title item ID
			v_html(str) - HTML of area
			
			** DEPRECATED ON 2.2.3 (EMA) **
	*/   
	addHTML:function(v_id,v_html)
	{
		var l_title=new Element('div',{
			'id':v_id,
            'class':'menuitemcontent'
		});
		l_title.set('html',v_html);
		l_title.injectInside($('menucontent'));
	},
	/*
		Function: sortOptions
                                $p.app.menu.sortOptions
                                
                                Sort header items
                      
                      Parameters: 
                      
                                 v_a - header item elment
                                 v_b - header item element
                      
                      Returns:
                            
                                -1, 1 or 0
	*/
	sortOptions:function(v_a,v_b)
	{
		if (v_a.seq < v_b.seq) return -1;
		if (v_a.seq > v_b.seq) return 1;
		return 0;
	},
	/*
		Function: showItem
                                $p.app.menu.showItem
                                
                                Display a menu item
                                
                     Parameters: 
                     
                                v_itemId - id of the item to display
	*/
	showItem:function(v_itemId)
	{
		if ($(v_itemId+'btn') != null)
		{
			($(v_itemId+'btn')).set('html',String.fromCharCode(8743));
		}
		$p.show(v_itemId,'block');
	},
	/*
		Function: hideItem
                                $p.app.menu.hideItem
                                
                                Hide a menu item
                                
                     Parameters: 
                     
                                v_itemId - id of the item to hide
	*/
	hideItem:function(v_itemId)
	{
		if ($(v_itemId+'btn') != null)
		{
			($(v_itemId+'btn')).set('html',String.fromCharCode(8744));
		}
		$p.show(v_itemId,'none');
	},
	/*
                    Function: openSubMenu
                                $p.app.menu.openSubMenu
                    
                                Display sub menu options
		
                    Parameters:

			v_sMenuId - id of the submenu to display
			v_init - true for menu init
	*/
    
    openSubMenu:function(v_MenuId,v_sMenuId,v_init)
	{
		if (showBoxStatus)
            hideBox();
		
		$p.app.menu.closeSubMenus();
		
		if (__menuposition == 'h')
		{
			$p.app.menu.launchSubMenuAction(v_MenuId,v_sMenuId);
		}
		else
		{
			if ($p.app.menu.options[v_MenuId].subOptions[v_sMenuId].opened)
			{
				$p.app.menu.options[v_MenuId].subOptions[v_sMenuId].opened = false;
				$p.app.menu.hideItem($p.app.menu.options[v_MenuId].subOptions[v_sMenuId].id + 'content');
				
			}
			else
			{
				if ($p.app.menu.options[v_MenuId].subOptions[v_sMenuId].type && $p.app.menu.options[v_MenuId].subOptions[v_sMenuId].type == 'link')
				{
				}
				else
				{
					$p.app.menu.options[v_MenuId].subOptions[v_sMenuId].opened = true;
				}
				if (($($p.app.menu.options[v_MenuId].subOptions[v_sMenuId].id + 'content')).innerHTML == '')
				{
					$p.app.menu.launchSubMenuAction(v_MenuId,v_sMenuId);
				}
				
				if (!$p.app.menu.options[v_MenuId].subOptions[v_sMenuId].type || $p.app.menu.options[v_MenuId].subOptions[v_sMenuId].type == 'submenu')
				{
					$p.app.menu.showItem($p.app.menu.options[v_MenuId].subOptions[v_sMenuId].id + 'content');
				}
			}
		}
		$p.plugin.hook.launch('app.menu.openSubMenu.addsubmenulink');
		/* Removed on 2.2.3 (EMA)
		if (__menuposition == 'h') {
			$p.app.menu.emptyContent();
			if ($(v_sMenuId).fct != indef) 
	            $(v_sMenuId).fct();
			//change buttons display
			var l_subMenus = ($('menusuboptions')).getChildren();
			for (var i = 0;i < l_subMenus.length;i++)
			{
				l_subMenus[i].className = 'menuitem';
			}
			$(v_sMenuId).className = 'menuitemselected';
		}
		else {          
            if ($(v_sMenuId).fct != indef) {
	            $(v_sMenuId).fct();
            }
			var l_subMenus=($('menucontent')).getChildren();
			for (var i = 0;i < l_subMenus.length;i++)
			{
       
				if (l_subMenus[i].getProperty('class') == 'menuitemcontent') {           
                    if (l_subMenus[i].id == v_sMenuId+'content' && $(v_sMenuId+'content').style.display != 'block') {
						$p.app.menu.showItem(l_subMenus[i].id);
					}
					else {
                        
						$p.app.menu.hideItem(l_subMenus[i].id);
	                }
				}
			} 
		}*/
	},
	closeSubMenus: function()
	{
		for (var i in $p.app.menu.options)
		{
			for (var j in $p.app.menu.options[i].subOptions)
			{
				if ($p.app.menu.options[i].subOptions[j].opened)
				{
					$p.app.menu.hideItem($p.app.menu.options[i].subOptions[j].id + 'content');
					$p.app.menu.options[i].subOptions[j].opened = false;
				}
			}
		}
	},
	launchSubMenuAction: function(v_MenuId, v_sMenuId)
	{
		if (!$p.app.menu.options[v_MenuId].subOptions[v_sMenuId].action || $p.app.menu.options[v_MenuId].subOptions[v_sMenuId].action == '')
			return false;
		if (typeof($p.app.menu.options[v_MenuId].subOptions[v_sMenuId].action) == 'string')
		{
			eval($p.app.menu.options[v_MenuId].subOptions[v_sMenuId].action);
		}
		else
		{
			$p.app.menu.options[v_MenuId].subOptions[v_sMenuId].action();
		}
	},
    /*
                   Function: refreshConditionalMenus
                               $p.app.menu.refreshConditionalMenus
                    
                               Refresh the menus which content is based on a contexte (specific page, ...)
	*/
    refreshConditionalMenus: function()
    {
        // if ($p.app.menu.isOpen && $p.app.menu.options[$p.app.menu.optionSelected]["id"] == 'poptions')
        // {
            // $p.app.menu.config.refresh();
        // }
    },
    /*
                    Function: openFirstOptionAvailable
                                $p.app.menu.openFirstOptionAvailable
                    
                                Open the first option available in the menu
                      Parameters:
                                v_menuPrefix - prefix of the name of the menus
		** DEPRECATED v2.2.3 (EMA) **
	*/
    openFirstOptionAvailable: function(v_menuPrefix)
    {
        for (var i = 0;i < 15;i++)
        {
            if ($(v_menuPrefix+i) != null)
            {
                 $p.app.menu.openSubMenu(v_menuPrefix+i,true);
                return true;
            }
        }
        return false;
    },
	openPopup: function()
	{
		$p.app.popup.show('<div id="menupopup"></div>',540,indef,lg('optionsOfThisPage'),indef,indef,0.3);
	},
	addInPopup: function(v_popupContent)
	{
		$p.print('menupopup',v_popupContent);
	},
	addSearchbox: function(v_container)
	{
		var l_s = (__useNotebook 
					? '<form onsubmit="$p.search.shown=false;$p.search.start(indef,this.text.value);return false;">\
					<p>' + lg('Search') + '</p>\
					<div class="searchbox"><input name="text" class="searchboxtext" type="text"/><input class="searchboxbtn" type="image" src="../styles/themes/classic_blue/header_menu_searchbtn.png"/></div>\
				  </form>'
					: '<div style="width: 90px;padding-right: 20px;">&nbsp;</div>');
		$p.print(v_container,l_s);
	},
	addOption: function(v_option, v_container, v_action)
	{
		var l_action;
		switch (v_option)
		{
			case 'notconnectedlabel':
				l_action = lg('userNotConnected');
				break;
			case 'save&login':
				l_action = '<a href="#" onclick="p_connection.saveMenu();return false;">' + lg('lblSave') + '</a>'
					+ ' &nbsp '
					+ '<a href="#" onclick="p_connection.menu();return false;">' + lg('lblConnect') + '</a>';
				break;
			case 'profile':
				l_action = '<a href="#" onclick="$p.network.myprofile();return false;">' + lg('myProfile') + '</a>';
				break;
			case 'contributions':
				if (__useNotebook)
					l_action = '<a href="#" onclick="$p.notebook.open(indef,\'note\',indef,2);return false;">' + lg('myContributions') + '</a>';
				break;
			case 'network':
				if (__useNetwork)
					l_action = '<a href="#" onclick="$p.notebook.open(indef,indef,indef,3);return false;">' + lg('myNetwork') + '</a>';
					//l_action = '<a href="#" onclick="$p.network.dashboard.myNetwork();return false;">' + lg('myNetwork') + '</a>';
				break;
			case 'groups':
				if (__useNetwork)
					l_action = '<a href="#" onclick="$p.notebook.open(indef,indef,indef,7);return false;">' + lg('myGroups') + '</a>';
					//l_action = '<a href="#" onclick="$p.group.buildPage();return false;">' + lg('myGroups') + '</a>';
				break;
			default:
				l_action = v_action;
				break;
		}
		if (l_action != indef)
		{
			$p.show(v_container,'block');
			$p.print(v_container, '<p>' + l_action + '</p>','bottom');
		}
	}
}



//******************* MENUS WIDGETS FUNCTIONS ***********************************************************************************************************************
/*
    Class: $p.app.menu.widget
            Menu widget functions
*/
$p.app.menu.widget={
	leftmenuinit: false,
	locked: false,
    prevExplorerItem: {'id':indef,'lang':indef,'level':indef,'secured':indef},
	widgetAverageRating:[],
	widgetRatingEnabled:[],

	open: function()
	{
		$p.app.menu.open("pwidget",true);
	},
	/*
		Function: $p.app.menu.widget.build
        
                                $p.app.menu.widget.build
                                
                                Initialize widget menu
			Removed on 2.2.3 (EMA)
	build: function()
	{
		if (showBoxStatus)
            hideBox();

        $p.plugin.hook.launch('app.menu.widget.addOptions1');

		if (__showrsscell)
        {
			$p.app.menu.addTitle('addmenu_1','ico_rss2.gif',lg("lblAddRSS"),$p.app.menu.widget.displayRSSForm);
		}
        
        //$p.plugin.hook.launch('app.menu.widget.addOptions2');
		//if (__showModuleSearch)
        //{
		//	$p.app.menu.addTitle('addmenu_2','ico_search.gif',lg("lblSearch"),$p.app.menu.widget.displaySearchForm);
		//}
        
        $p.plugin.hook.launch('app.menu.widget.addOptions3');

		if (__showModuleExpl)
        {
			$p.app.menu.addTitle('addmenu_3','ico_directory.gif',lg("lblExplore"),$p.app.menu.widget.displayExplorerForm);
		}
        
        $p.plugin.hook.launch('app.menu.widget.addOptions4');

		// if (__useGroup 
			// && $p.app.user.id > 0 
			// && __usePrivateModules)
        // {
			// $p.app.menu.addTitle('addmenu_4','ico_directory_lock.gif',lg("privateModules"),$p.app.menu.widget.displaySecureExplorerForm);
		// }        
		
        $p.plugin.hook.launch('app.menu.widget.addOptions5');

		if (__userModuleJs=='I' 
            && $p.app.user.id > 0)
		{
			$p.app.menu.addTitle('addmenu_5','mymodules.gif',lg("lblArchive2"),$p.app.menu.widget.displayMyModule);
		}

        $p.plugin.hook.launch('app.menu.widget.addOptions6');

        if ($p.app.env=="admin") {
          //  $p.app.menu.menuOpt['addmenu_3']=false;
              $p.app.menu.enableAllMenuLinks();
        }
        
		if (__showModuleExpl)
		{
			$p.app.menu.openSubMenu('addmenu_3',true);
		}
		else
		{
			$p.app.menu.openSubMenu('addmenu_1',true);
		}

        $p.plugin.hook.launch('app.menu.widget.addOptions7');
	},
*/
	isRssOptionsDisplayed: function()
	{
		if (__showrsscell){
			if ($p.app.env=="admin") {
			  //  $p.app.menu.menuOpt['addmenu_3']=false;
				  $p.app.menu.enableAllMenuLinks();
			}
			return true;
		}
		return false;
	},
	isExplorerDisplayed: function()
	{
		if (__showModuleExpl)
			return true;
		return false;
	},
	isMyModuleDisplayed: function()
	{
		if (__userModuleJs=='I' 
            && $p.app.user.id > 0
			&& $p.app.user.type != "N")
			return true;
		return false;
	},
	/*
		Function: displayRSSForm
                                $p.app.menu.widget.displayRSSForm
                                
                                Display the rss form

	*/
    displayRSSForm:function()
    {
        var l_s='<form action="#" name="rss" onsubmit="$p.app.widgets.rss.checkFeed();return false;"><br />'
                +lg("enterRssUrl")+' :<br /><br />'
                +'<input class="thinbox" name="vars" type="text" size="25" onFocus=\'$p.app.tools.inputFocus(this,"'+lg("lblRSSFlow")+'")\' onBlur=\'$p.app.tools.inputLostFocus(this,"'+lg("lblRSSFlow")+'")\' value="'+lg("lblRSSFlow")+'" onclick=\'javascript:vars.value="";$p.print("authrss","");\' style="color:#aaaaaa" />'
                +'&nbsp;<input type="submit" name="butr" class="btn" value="Go" /> '+tooltip("msgRSShlp")
                +'<div id="authrss" style="width:190;text-align:left;display:none;"></div>'
                +'</form>';
                
		if ($p.app.user.id>0) {
            l_s+="<br /><a href='#' onclick='return $p.app.widgets.rss.importMenu();'>"+lg("lblImport")+"/"+lg("lblExport")+" (OPML)</a> "+tooltip("msgOpmlhlp");
        }

        $p.app.menu.addArea('addmenu_1',l_s);
    },
	// /*
		// Function: displaySearchForm
                                // $p.app.menu.widget.displaySearchForm : Display the widget search form

	// */
	// displaySearchForm: function()
	// {
        // $p.app.menu.addArea('addmenu_2','<form name="mod__search" onsubmit="$p.app.menu.widget.getSearch(document.mod__search.inputsearchwidget.value,0);return false;"><br />'+lg("searchModuleByKeywords")+' : <br /><br /><input class="thinbox" id="inputsearchwidget" name="inputsearchwidget" type="text" size="25" onFocus=\'$p.app.tools.inputFocus(this,"'+lg("keywords")+'")\' onBlur=\'$p.app.tools.inputLostFocus(this,"'+lg("keywords")+'");$p.tags.autocompletion.hide();\' value="'+lg("keywords")+'" onkeyup=\'$p.tags.autocompletion.get("inputsearchwidget")\' style="color:#aaaaaa" /> <input type="submit" name="buts" class="btn" value="Go" />&nbsp;'+tooltip("helpTags")+'<div id="listmod" style="width:210px;text-align:left;"></div></form>');
    // },
	/*
		Function: displayExplorerForm
                                $p.app.menu.widget.displayExplorerForm : Display the widget explorer

	*/
	displayExplorerForm: function()
	{
        var l_s = '<div id="explorer">'
            + '<div id="exp0">loading ...</div>'
            + '</div>';
        $p.app.menu.addArea('addmenu_3',l_s);
        $p.app.menu.widget.getExplorer(0);
	},
	displaySecureExplorerForm: function()
	{
		var l_s = "<div id='exps0'>loading ...</div>";
		$p.app.menu.addArea('addmenu_4',l_s);
        $p.app.menu.widget.getSecuredExplorer(0);
	},
	/*
		Function: displayMyModule
                                $p.app.menu.widget.displayMyModule : Display the users widgets + create a widget link

	*/
	displayMyModule: function()
	{
		$p.app.menu.addArea('addmenu_5',lg('lblLoading'));
        $p.app.menu.widget.getMyModules();
	},
	/*
		Function: getSearch
                                $p.app.menu.widget.getSearch
                                
                                Search modules
                     
                     Parameters:
                     
 			v_s - search string
			v_page - results page number
	*/
	getSearch:function(v_s,v_page)
	{
		// Open the search results
		v_s = $p.string.formatForSearch($p.tags.formatList(v_s));
		v_s = $p.string.removeCot(v_s);
		$p.setClass("dirlink","optlist");
		$p.setClass("listlink","optlist");
		$p.setClass("sellink","optlist");
		$p.print("listmod",lg("searching"));
		v_s = $p.string.removeCot(v_s);
		$p.ajax.call(posh["xmlsearch"]+"?searchtxt="+$p.string.esc(v_s)+"&p="+v_page,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.menu.widget.displaySearch,
					'variables':
					{
						'searchtxt':v_s,
						'page':v_page
					}
				}
			}
		);
	},
	/*
		Function: $p.app.menu.widget.displaySearch

                                Display module search results
                     
                     Parameters:
                     
 			response - XML object
			vars (array) - variables (optionnal)
	*/
	displaySearch:function(response,vars)
	{
		var l_result,
			l_container = (__menuposition == 'h' ? 'menucontent' : 'listmod');

		if (response.getElementsByTagName("nbres1")[0])
		{
			var l_nbres1 = $p.ajax.getVal(response,"nbres1","int",false,0);
			var l_nbres = l_nbres1;
			
			if (l_nbres1 < 10)
			{
				var l_nbres2 = $p.ajax.getVal(response,"nbres2","int",false,0);
				l_nbres = eval(l_nbres) + eval(l_nbres2);
			}
			
			$(l_container).set('html',lg("lblResultsFor") + " '" + vars['searchtxt'] 
                            + "' <a href='#' onclick=\"$('" + l_container + "').empty();$p.show('" + l_container + "','none');\">"+$p.img('ico_close.gif')+"</a>");
			var divObj1 = new Element('div',
				{
					'styles': {
						'height': '180px'
					},
					'class':'dirdiva'
				}
			);
			var tableObj1 = new Element('table', { 'cellpadding':'0', 'cellspacing':'1' } );
			var tbodyObj1 = new Element('tbody');

			if (response.getElementsByTagName("item")[0])
			{
				for (var i=0;i<10;i++)
				{
					if (response.getElementsByTagName("item")[i])
					{
						l_result=response.getElementsByTagName("item")[i];
						var trObj1 = new Element('tr');
						var tdObj1 = new Element('td');
						v_icon = $p.ajax.getVal(l_result,"icon","str",false,0);
						
						if( v_icon!=0 ) {
							if(v_icon.search("modules/pictures/")<0)
								v_icon = "../modules/pictures/"+v_icon;
							v_icon = $p.img(v_icon+"?rand="+rand,16,16)+'&nbsp;';
						} else {
							v_icon = $p.img(+"box0_"+$p.ajax.getVal(l_result,"id","int",false,0),16,16,"","imgmid")+'&nbsp;';
						}

						tdObj1.set('html',v_icon);
						var aObj1 = new Element('a',
							{ 
								'events': {
									'click': function()
									{
										$p.app.widgets.open(this.widId,
                                                                    indef,
                                                                    indef,
                                                                    (this.secured==0?false:true)
                                                            );
									}
								},
								'class':'menu1',
								'href':'#'
							} 
						);
						aObj1.widId=$p.ajax.getVal(l_result,"id","int",false,0);
						aObj1.secured=$p.ajax.getVal(l_result,"secured","int",false,0);
						aObj1.set('html',$p.ajax.getVal(l_result,"name","str",false,"..."));
                        aObj1.setStyle('vertical-align','top');
						aObj1.inject(tdObj1);
						tdObj1.inject(trObj1);
						trObj1.inject(tbodyObj1);
					}
				}
			}
			else
			{
				var trObj2 = new Element('tr');
				var tdObj2 = new Element('td');
				tdObj2.set('html',lg("lblSrchNoMod"));
				tdObj2.inject(trObj2);
				trObj2.inject(tbodyObj1);	
			}
			tbodyObj1.inject(tableObj1);
			tableObj1.inject(divObj1);
			var tableObj2 = new Element ('table',
				{
					'styles': {
						'width': '90%'
					}
				}
			);
			var tbodyObj2 = new Element ('tbody');
			var trObj3 = new Element ('tr');

			if (vars['page']!=0)
			{
				var tdObj3 = new Element ('td');
				var aObj2 = new Element('a',
					{ 
						'events':
						{
							'click': function()
							{
								$p.app.menu.widget.getSearch(vars['searchtxt']+","+(parseInt(vars['page'])-1));
								return false;
							}
						},
						'href':'#'
					}
				);
				aObj2.set('html',$p.img("ico_previous3.gif",8,11,lg("lblPrevMods"))+" "+lg("previous"));
				aObj2.inject(tdObj3);
				tdObj3.inject(trObj3);
			}
			if (l_nbres==11)
			{
				var tdObj4 = new Element ('td',
					{
						'styles': {
							'text-align': 'right'
						}
					}
				);
				var aObj3 = new Element('a',
					{ 
						'events':
						{
							'click': function()
							{
								$p.app.menu.widget.getSearch(vars['searchtxt']+","+(parseInt(vars['page'])+1));
								return false;
							}												
						},
						'href':'#'
					}
				);
				aObj3.set('html',lg("next")+" "+$p.img("ico_next3.gif",8,11,lg("lblNextMods")));
				aObj3.inject(tdObj4);
				tdObj4.inject(trObj3);
			}
			trObj3.inject(tbodyObj2);
			tbodyObj2.inject(tableObj2);
			tableObj2.inject(divObj1);
			$p.show(l_container,'');
			divObj1.inject($(l_container));
		}
		else
		{
			$(l_container).set('html',"<font style='color:#ff0000'>"+lg("lblSrch3car")+"</font>");
		}
	},
	/*
		Function: clearSearch
                                $p.app.menu.widget.clearSearch
                                
                                Erase search results
                     
                     Returns:
                     
 			false
	*/
	clearSearch:function()
	{
		$p.print("listmod","");
		return false;
	},
	/*
		Function: initDir
                                $p.app.menu.widget.initDir
                                
                                Initialize the modules directory
                     
                     Parameters:
                     
 			v_cat - directory ID
	*/
    /*
	initDir:function(v_cat)
	{
		// Initialize modules directory menu
		var tableObj1 = new Element('table', { 'cellpadding':'0', 'cellspacing':'0', 'border':'0' } );
		var tbodyObj1 = new Element('tbody');	
		var trObj1 = new Element('tr');	
		var tdObj1 = new Element('td');	
		var tableObj2 = new Element('table', 
			{ 
				'cellspacing':'0', 
				'width':'100%' 
			} 
		);
		var tbodyObj2  = new Element('tbody');
		var trObj2 = new Element('tr');	
		var tdObj2 = new Element('td');
		tdObj2.set('html',lg("lblNavDir")+" :" );
		tdObj2.inject(trObj2);
		var tdObj3 = new Element('td', { 'align':'right' } );
		tdObj3.inject(trObj2);
		trObj2.inject(tbodyObj2);
		tbodyObj2.inject(tableObj2);
		tableObj2.inject(tdObj1);
		tdObj1.inject(trObj1);
		trObj1.inject(tbodyObj1);
		
		var trObj3 = new Element('tr');	
		var tdObj4 = new Element('td');	
		var tableObj3 = new Element('table');	
		var tbodyObj3 = new Element('tbody');
		var trObj4 = new Element('tr');	
		var tdObj5 = new Element('td');	
		var divObj1 = new Element('div', 
			{
				'styles': {
					'width': '230px'
				},
				'id':'level1',
				'class':'dirdivi'
			}
		 );
		divObj1.inject(tdObj5);						 
		tdObj5.inject(trObj4);			
		var tdObj6 = new Element('td');	
		var divObj2 = new Element('div', 
			{
				'styles': {
					'width': '200px'
				},
				'id':'level2',
				'class':'dirdivi'
			}
		 );
		divObj2.inject(tdObj6);						 
		tdObj6.inject(trObj4);
		var tdObj7 = new Element('td');	
		var divObj3 = new Element('div', 
			{
				'styles': {
					'width': '200px'
				},
				'id':'level3',
				'class':'dirdivi'
			}
		 );
		divObj3.inject(tdObj7);						 
		tdObj7.inject(trObj4);
		var tdObj8 = new Element('td');	
		var divObj4 = new Element('div', 
			{
				'styles': {
					'width': '170px'
				},
				'id':'level4',
				'class':'dirdivi'
			}
		 );
		divObj4.inject(tdObj8);						 
		tdObj8.inject(trObj4);
		trObj4.inject(tbodyObj3);
		tbodyObj3.inject(tableObj3);
		tableObj3.inject(tdObj4);
		tdObj4.inject(trObj3);
		trObj3.inject(tbodyObj1);
		tbodyObj1.inject(tableObj1);
		$p.show("listmod","block");
		tableObj1.inject($("listmod"));
		$("listexample").set('html',$p.img("",7,7)+"<br />");	
		$p.print("level1","Chargement ...");
		$p.app.menu.widget.getDir(v_cat,1);	
	},
            */
	/*
		Function: getDir
                                $p.app.menu.widget.getDir
                                
                                Get the module of the category
                     
                     Parameters:
                     
 			v_cat - directory ID
                                v_level - level
	*/
    /*
	getDir:function(v_cat,v_level)
	{
		// Open the modules directory
		$p.ajax.call("../cache/cat_"+v_cat+"_"+__lang+".xml?rand="+rand,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.menu.widget.displayDir,
					'variables':
					{
						'level':v_level
					}
				}
			}
		);
	},
            */
	/*
		Function: $p.app.menu.widget.displayDir
                                
                                Display the directory modules
                     
                     Parameters:
                     
 			response - XML object
                                vars (array) - variables (optionnal)
	*/
    /*
	displayDir:function(response,vars)
	{
		var l_s="";
		if (response.getElementsByTagName("parent")[0])
		{
			l_s+="<table cellpadding='0' cellspacing='1' border='12' style='width:90%'>";
			if (response.getElementsByTagName("dir")[0])
			{
				var l_i=0,l_dirid;
				while (response.getElementsByTagName("dir")[l_i])
				{
					var l_result=response.getElementsByTagName("dir")[l_i];
					l_dirid=$p.ajax.getVal(l_result,"dirid","int",false,0);
					l_dirquantity=$p.ajax.getVal(l_result,"quantity","int",false,0);
					if (l_dirquantity!=0) l_s+="<tr><td id='dir"+l_dirid+"' class='catopti' onmouseover='catOptOver(\""+l_dirid+"\")' onmouseout='catOptOut(\""+l_dirid+"\")'>&nbsp;<a href='#' class='menul' onclick='$p.app.menu.widget.getDir("+l_dirid+","+(vars['level']+1)+");catOptSel("+l_dirid+","+vars['level']+");return false;'>"+$p.ajax.getVal(l_result,"dirname","str",false,"...")+" ("+l_dirquantity+")</a></td></tr>";
					l_i++;
				}
			}
			if (response.getElementsByTagName("item")[0])
			{
				var l_i=0,l_itemid;
				while (response.getElementsByTagName("item")[l_i])
				{
					var l_result=response.getElementsByTagName("item")[l_i];
					l_itemid=$p.ajax.getVal(l_result,"id","int",false,0);
					l_s+="<tr><td>"+$p.img(_dirImg+"box0_"+l_itemid,16,16,"","imgmid")+"&nbsp;<a href='#' class='menul' onclick='$p.app.widgets.open("+l_itemid+");return false;'>"+$p.ajax.getVal(l_result,"name","str",false,"...")+"</a></td></tr>";
					l_i++;
				}
			}
			l_s+="</table>";
		}
		else {l_s+=lg("lblDisplayErr");}

		$p.setClass("level"+vars['level'],"dirdiva");
		$p.print("level"+vars['level'],l_s);
		//clear unused div
		for (var i=vars['level']+1;i<5;i++){$p.print("level"+i,"");$p.setClass("level"+i,"dirdivi");}
	},
    */
	/*
		Function: $p.app.menu.widget.getExplorer
                                
                                Load modules directory branches
		
                    Parameters:

			v_cat - directory ID
			v_open - open / close directory branch
			v_lang - widget language
	*/
	getExplorer:function(v_cat,v_open,v_lang,v_secured,v_level)
	{
		if (v_open == indef) v_open = 1;
        if (v_level == indef) v_level = 1;
        if (v_open == 1)
        {
            if ($p.app.menu.widget.prevExplorerItem.id && v_level == $p.app.menu.widget.prevExplorerItem.level)
            {
				// close the previous opened widgets library
				if (!__OPEN_ALL_WIDGET_LIBRARIES_IN_MENU_BY_DEFAULT)
				{
					$p.app.menu.widget.getExplorer($p.app.menu.widget.prevExplorerItem.id,0,$p.app.menu.widget.prevExplorerItem.lang,$p.app.menu.widget.prevExplorerItem.secured,$p.app.menu.widget.prevExplorerItem.level);
				}
            }
            $p.app.menu.widget.prevExplorerItem = {'id':v_cat,'level':v_level,'lang':v_lang,'secured':v_secured}
        }
		if (v_open == 1) $p.app.wait("exp"+v_cat);
        
        // widget group restriction calls xml explorer only for connected users
        if (__GROUP_RESTRICTION_ON_SINGLE_WIDGET && $p.app.user.id != 0) {
            var l_url = posh["xmlexplorer"]+'?dirid='+v_cat+'&pageid='+($p.app.tabs.sel < 0 ? 0 : tab[$p.app.tabs.sel].pageIdDb)+'&rand='+rand;
        }
        else {
            // use xmlexplorer if using notation
            if (v_secured || $p.app.user.id == -1 || __USE_WIDGET_NOTATION) {
                var l_url = posh["xmlexplorer"]+'?dirid='+v_cat+'&pageid='+tab[$p.app.tabs.sel].pageIdDb+'&rand='+rand;
            }
            else {
                // otherwise call cache files
                if ($p.app.tabs.sel<=0 || v_cat != 0) {
                    var l_url = "../cache/cat_"+v_cat+(v_cat == 0 ? "" : "_"+v_lang)+".xml?rand="+rand;
                } else {
                    var l_url = "../cache/cat_"+(tab[$p.app.tabs.sel].pageIdDb || 0)+".xml?rand="+rand;
                }
            }
        }        
        
		$p.ajax.call(l_url,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.menu.widget.displayExplorer,
					'variables':
					{
						'category':v_cat,
						'open':v_open,
						'prefix':'',
						'language':v_lang,
                        'secured':v_secured,
                        'level':v_level
					}
				},
				'escape':$p.app.menu.widget.displayExplorerDefaultCategory
			}
		);

		return false;
	},	
	displayExplorerDefaultCategory: function()
	{
		$p.ajax.call("../cache/cat_0.xml?rand="+rand,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.menu.widget.displayExplorer,
					'variables':
					{
						'category':0,
						'open':1,
						'prefix':'',
						'language':__lang,
                        'secured':0,
                        'level':1
					}
				}
			}
		);
	},
	/*
		Function: $p.app.menu.widget.displayExplorer

                                Display modules directory branch
                                
                     Parameters:
                                
                                response - XML object
                                vars (array) - variables (optional) 
	*/
	displayExplorer:function(response,vars)
	{
        (!$p.app.menu.isOpen) ? $p.app.menu.open() : '';
		if (__menuposition == 'h')
        {
            var l_container = $('explorer');
            l_container.empty();
			var l_pathDiv = new Element('div',
				{
					'id':'explorerpath'
				}
			);
			l_pathDiv.set('html',$p.ajax.getVal(response,"path","str",false,""));
			l_pathDiv.inject(l_container);
			var l_divObj = new Element('div',{
					'id':'exp0'
				}
			);
			l_divObj.inject(l_container);
		}
		else
        {
            if ($("exp"+vars['prefix']+vars['category']) == null)
            {
                //var l_container = new Element('div');
                var l_container = $("exp0");
            }
            else
            {
                var l_container = $("exp"+vars['prefix']+vars['category']);
            }

            l_container.empty();
            var l_divObj = new Element('span'); // keep span instead of div for better display
            l_divObj.inject(l_container);

			if (vars['category'] != 0) {	
				var aObj = new Element('a',
					{
						'events':
						{
							'click': function()
							{
								return $p.app.menu.widget.getExplorer(vars['category'],(vars['open']==0?"1":"0"),vars['language'],vars['secured'],vars['level']);
							}
						},
						'class': 'dirlink',
						'href': '#'
					}
				);
				aObj.set('html',    $p.img((vars['open'] == 1 ? "ico_directory_open.gif" : "ico_directory.gif"),16,13)
                                    + " "+$p.ajax.getVal(response,"dirname","str",true,"--")
                                    + (vars['secured'] == 0 ? "" : " "+$p.img("lock.gif",7,9))
                                    + "<br />");
				aObj.inject(l_divObj);
			}
		}
        
		if (response.getElementsByTagName("parent")[0] && vars['open']==1)
		{
            var l_subDirectoriesExisting = true;

			if (response.getElementsByTagName("dir")[0])
			{
				var l_i=0;

				while (response.getElementsByTagName("dir")[l_i])
				{
					var l_result = response.getElementsByTagName("dir")[l_i];
                    
					var l_dirid = $p.ajax.getVal(l_result,"dirid","int",false,0);
					var l_dirquantity = $p.ajax.getVal(l_result,"quantity","int",false,0);
                    var l_dirSecuredquantity = $p.ajax.getVal(l_result,"secured_quantity","int",false,0);
                    var l_secured = $p.ajax.getVal(l_result,"secured","int",false,0);
					var l_lang = $p.ajax.getVal(l_result,"lang","str",false,"");
                    var l_quantity = l_dirquantity + ($p.app.user.id <= 0 ? 0 : l_dirSecuredquantity);
                    
					if ((l_secured == 0 || (__useGroup && $p.app.user.id > 0 && __usePrivateModules))
                        && (
                            __displayAllLanguageModules 
                            || (!__displayAllLanguageModules && (l_lang=="" || l_lang==__lang))
                            )
                        )
					{
						if (l_quantity != 0 || vars['category'] == 0) 
						{
							var divObj1 = new Element('div', 
								{ 
									'class':'expdir',
									'id':"exp"+vars['prefix']+l_dirid
								}
							);
							var aObj1 = new Element('a',
								{
									'events':
									{
										'click': function()
										{
											return $p.app.menu.widget.getExplorer(this.l_dirid,indef,this.l_lang,this.secured,this.level);
										}
									},
									'class': 'dirlink',
									'href': '#'
								}
							);
							
							aObj1.l_dirid = l_dirid;
							aObj1.l_lang = l_lang;
                            aObj1.secured = l_secured;
                            aObj1.level = vars['level']+1;
							aObj1.set('html',   $p.img("ico_directory.gif",16,13)
                                                + " "+$p.ajax.getVal(l_result,"dirname","str",false,"...")
                                                + " "+((l_quantity<=0)?"":"("+l_quantity+")")+""
                                                + (l_secured == 0 ? "" : " "+$p.img("lock.gif",7,9))
                            );
							aObj1.inject(divObj1);
							divObj1.inject(l_divObj);
							
							if (__OPEN_ALL_WIDGET_LIBRARIES_IN_MENU_BY_DEFAULT)
								$p.app.menu.widget.getExplorer(l_dirid, indef, l_lang, l_secured, vars['level']+1);
						}
					}
					l_i++;
				}
			}
            else
            {
                l_subDirectoriesExisting = false;
            }

			if (response.getElementsByTagName("item")[0]) {
				var l_i=0;
				while (response.getElementsByTagName("item")[l_i]) {
					var l_result = response.getElementsByTagName("item")[l_i];
                        l_itemid = $p.ajax.getVal(l_result,"id","int",false,0);
					
					var divObj3 = new Element('div');
                    
					v_icon = $p.ajax.getVal(l_result,"icon","str",false,0);
                    
					if( v_icon != 0 )
                    {
						v_icon = $p.img(v_icon+"?rand="+rand,16,16,"","imgmid",l_itemid);
					} else {
						v_icon = $p.img(_dirImg+"box0_"+l_itemid,16,16,"","imgmid");
					}		
					divObj3.set('html',v_icon+"&nbsp;");
					divObj3.itemid = l_itemid;
                    divObj3.id='mod2set'+l_itemid;
                    divObj3.usingdrag = false;
                    
					var aObj3 = new Element('a',
						{
							'events':
							{
								'click': function()
								{
									$p.app.widgets.open(this.itemid,indef,indef,this.secured);
								}
							},
							'class': 'modlink',
							'href':'#'
						}
					);
                    aObj3.id="amodule"+l_itemid;
					aObj3.itemid = l_itemid;
                    aObj3.secured = $p.ajax.getVal(l_result,"secured","int",false,0);
					aObj3.set('html',$p.ajax.getVal(l_result,"name","str",false,"..."));
					aObj3.inject(divObj3);
					
					if( __USE_WIDGET_NOTATION ) {
						v_average_rating = parseFloat($p.ajax.getVal(l_result,"average_rating","str",false,0));
						v_total_rating = $p.ajax.getVal(l_result,"total_rating","int",false,0);
						if( $p.app.user.id==0) {
							$p.app.menu.widget.widgetRatingEnabled[l_itemid]  = false;
						} else {
							$p.app.menu.widget.widgetRatingEnabled[l_itemid]  = $p.ajax.getVal(l_result,"enabled","int",false,0);
						}
						if( (($p.app.user.id == 0 || $p.app.user.type == 'N') && v_total_rating > 0) || ($p.app.user.id > 0 && ($p.app.user.type == 'I'|| $p.app.user.type == 'A'))) {
							$p.app.menu.widget.buildRatingElements( l_itemid, v_average_rating, v_total_rating ).inject(divObj3);
						}
					}

					divObj3.inject(l_divObj);
					//initialize items drag
					$p.app.widgets.move.init(divObj3);
					//item drag actions
					divObj3.onDrag=$p.app.menu.widget.explorerOnDrag;
					divObj3.onDragStart=$p.app.menu.widget.explorerOnDragStart;

					l_i++;
				}
			}
            else if (vars['category'] != 0 && !l_subDirectoriesExisting)
            {
                var l_divNoItem = new Element('div');
                l_divNoItem.set('html',lg('lblNoModule'));
                l_divNoItem.inject(l_divObj);
            }
		}
	},
	/*
		Function: $p.app.menu.widget.buildRatingElements

                    Build the list of star for rating
                                
            Parameters:
              
                    l_itemid: widget id
                    v_average_rating: widget average rating
					v_total_rating: widget total rating
	*/
	buildRatingElements:function( l_itemid, v_average_rating, v_total_rating ){
		var divPR=new Element('div',
				{
					'styles':
					{
						'width': '100%',
						'margin-left':'20px'
					},
					'id':'divPR'
				}
			);
		var divPRimg = [];
		var aPRimg = [];

		for(i=0;i<5;i++) {
			aPRimg[i] =new Element('a',
				{
					'href':'#',
					'id':'l_star'+l_itemid+"_"+i
				}
			);
			aPRimg[i].onclick = function (evt) {
									if( $p.app.user.type!='N' ) {
										$p.app.menu.widget.setWidgetsRatings(l_itemid, this.id);
									}
									return false;
									};
			src = ((v_average_rating-1)>=(i))?'../images/star1.gif':'../images/star0.gif';

			if( v_average_rating - parseInt(v_average_rating)!=0 && i==parseInt(v_average_rating) ) {
				src = '../images/star2.gif';
			}
			divPRimg[i] = new Element('img',
				{
					'styles':
					{
						'width': '9px',
						'height': '9px'
					},
					'src':src,
					'id':'star'+l_itemid+"_"+i,
					'name':i
				}
			);
			divPRimg[i].onclick = function (evt) {
									return false;
								};
			$p.app.menu.widget.widgetAverageRating[l_itemid] = v_average_rating;
			divPRimg[i].onmouseover = function (evt) {
										$p.app.menu.widget.changeWidgetsRating(l_itemid,this.name);
									};
			divPRimg[i].onmouseout = function (evt) {
										$p.app.menu.widget.changeWidgetsRating(l_itemid,v_average_rating, $p.app.menu.widget.widgetAverageRating[l_itemid]);
									};
			divPRimg[i].inject(aPRimg[i]);
			aPRimg[i].inject(divPR);
		}

		elTotalRating = new Element('label',
		{
			'text': '  '+v_total_rating+' '+lg('lblrating'),
			'styles':
					{
						'display':(v_total_rating>0)?'inline':'none',
						'color':'#969696'
					},
			'id':'ratingViews'+l_itemid
		});
		elTotalRating.inject(divPR);
		return divPR;
	},
	/*
		Function: $p.app.menu.widget.setWidgetsRatings

                    Rate a widget
                                
            Parameters:
              
                    l_itemid: widget id
                    lstarId: star image id
	*/
	setWidgetsRatings:function(l_itemid, lstarId)
	{
		if( $p.app.menu.widget.widgetRatingEnabled[l_itemid] ) {
			var rating = parseInt(lstarId.charAt(parseInt(lstarId.length)-1))+1;
			$p.ajax.call(posh["xml_setwidgetratings"]+'?itemid='+l_itemid+'&rating='+rating,
				{
					'type':'load',
					'callback':
					{
						'function':$p.app.menu.widget.resetWidgetsRatings,
						'variables':
						{
							'l_itemid':l_itemid,
							'rating':rating
						}
					}
				}
			);
		}
	},
	/*
		Function: $p.app.menu.widget.resetWidgetsRatings

                    Reset the display of widget's stars after saving notation
                
				Parameters:
                            
                            response - XML object
                            vars (array) - variables (optionnal)
	*/
	resetWidgetsRatings:function(response,vars)
	{
		var l_s="";
		var nbratings = 0;
		var l_itemid = 0;
		var average_rating = 0;
		if (response.getElementsByTagName("item")[0])
		{
			var l_i=0,l_itemid;
			var l_result=response.getElementsByTagName("item")[l_i];
			l_itemid = $p.ajax.getVal(l_result,"itemid","int",false,0);
			nbratings = $p.ajax.getVal(l_result,"nbratings","int",false,0);
			average_rating = parseFloat($p.ajax.getVal(l_result,"avg","str",false,0));
		}
		$p.app.menu.widget.widgetAverageRating[vars['l_itemid']] = average_rating;
		$('ratingViews'+l_itemid).innerHTML = '&nbsp;' + nbratings+' '+lg('lblrating');
		$('ratingViews'+l_itemid).style.display = 'inline';
		$p.app.menu.widget.changeWidgetsRating(vars['l_itemid'], average_rating,average_rating);
		$p.app.menu.widget.widgetRatingEnabled[l_itemid] = false;
	},
	/*
		Function: $p.app.menu.widget.changeWidgetsRating

                        Change rating when the mouse is over or out
	*/
	changeWidgetsRating:function(l_itemid, rate, v_average_rating)
	{
		if($p.app.menu.widget.widgetRatingEnabled[l_itemid] && $p.app.user.type!='N') {
			var i=0;
			var imgsrc = "../images/star0.gif";
			var src = "../images/star1.gif";

			var maxId = parseInt(rate)+1;
			
			if(v_average_rating>=0)
				maxId = v_average_rating;

			$('star'+l_itemid+"_0").src = imgsrc;
			$('star'+l_itemid+"_1").src = imgsrc;
			$('star'+l_itemid+"_2").src = imgsrc;
			$('star'+l_itemid+"_3").src = imgsrc;
			$('star'+l_itemid+"_4").src = imgsrc;
			
			while(i<maxId) {
				if( v_average_rating - parseInt(v_average_rating)!=0 && i==parseInt(v_average_rating) ) {
					src = '../images/star2.gif';
				}
				$('star'+l_itemid+"_"+i).src = src;
				i++;
			}
		}
	},
	/*
		Function: $p.app.menu.widget.explorerOnDragStart

                                Display modules directory branch
	*/
	explorerOnDragStart:function()
	{
		this.isDrag='mousedown';
	},
	/*
		Function: $p.app.menu.widget.explorerOnDrag

                                Display modules directory branch
                                
                                Widget id is get from last widget created in page
                                
                     Parameters:
                     
                                v_x: coordonate
                                v_y: coordonate
	*/
	explorerOnDrag:function(v_x,v_y)
	{
		if (this.isDrag=='firstmove')
		{
			//display the widget
			this.isDrag = true;
            this.usingdrag=true;
			$p.app.widgets.open(this.itemid,indef,indef,indef,false,false);
			//initialize widget move, get last widget created in page
			var newWidget = tab[$p.app.tabs.sel].module[tab[$p.app.tabs.sel].module.length-1].uniq;
			$p.app.widgets.move.obj = $('module'+tab[$p.app.tabs.sel].id+'_'+newWidget+'_h');
			$p.app.widgets.move.start($p.navigator.IE ? indef : 0);
			var l_obj=$p.app.widgets.move.shadow();
			//e=$p.app.widgets.move.fixE($p.navigator.IE?indef:e);
			l_obj.setStyle("left",v_x-10+"px");
			l_obj.setStyle("top",v_y-10+"px");
		}

		if (this.isDrag=='mousedown')
			this.isDrag = 'firstmove';
	},
	/*
                Function: getSecuredExplorer
                            $p.app.menu.widget.getSecuredExplorer
                            
                            Load secured modules (group restrictions) directory branches
		
                Returns:

                            false
	*/
	getSecuredExplorer:function()
	{
		$p.ajax.call(posh["xmlexplorer"]+"?rand="+rand,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.menu.widget.displaySecuredExplorer
				}
			}
		);
		return false;		
	},
	/*
		Function: $p.app.menu.widget.displaySecuredExplorer

                                Display modules directory branch
                                
                      Parameters:
                            
                                response - XML object
                                vars (array) - variables (optionnal)
	*/
	displaySecuredExplorer:function(response,vars)
	{
		var l_s="";
		if (response.getElementsByTagName("item")[0])
		{
			var l_i=0,l_itemid;
			while (response.getElementsByTagName("item")[l_i])
			{
				var l_result=response.getElementsByTagName("item")[l_i];
				l_itemid=$p.ajax.getVal(l_result,"id","int",false,0);
				l_s+='<div>'
					+$p.img('../modules/pictures/box0_'+l_itemid,16,16,'','imgmid')
					+'&nbsp;<a href="#" class="modlink" onclick="$p.app.widgets.open('+l_itemid+',indef,indef,true);return false;">'
					+$p.ajax.getVal(l_result,'name','str',false,'...')+'</a>'
					+'</div>';
				l_i++;
			}
		}
		else l_s=lg("lblNoModule");

		//if (vars[0]!=0) $p.setClass("exp"+vars[0],(vars[1]==0?"expdiri":"expdira"));
		$p.print("exps0",l_s);
	},
	/*
    
		Function: 
                                $p.app.menu.widget.getMyModules
                                
                                Load list of the modules I created
	*/
	getMyModules:function()
	{
		$p.ajax.call(posh["xmlmymodules"],
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.menu.widget.displayMyModules
				}
			}
		);
	},
	/*
		Function: $p.app.menu.widget.displayMyModules
                                
                                Display list of the modules I created
                                
                     Parameters:
                     
                                response - XML object
                                vars (array) - variables (optionnal)
	*/
	displayMyModules:function(response,vars)
	{   
		var l_s = '<a href="#" onclick="$p.app.widgets.factory.init();return false;">'
	            + $p.img("mymodules_create.gif",16,16,"","imgmid")
            + ' '
            + lg("createYourModules")
            + '</a>'
            + '<br /><br />';

        var l_result = response.getElementsByTagName("module");

        if (l_result.length == 0)
        {
            l_s += lg("lblNoModule");
        }
        else
        {
    		for (var i = 0;i < l_result.length;i++)
    		{   
    			if ($p.ajax.getVal(l_result[i],"status","str",false,"N")=="O") 
                l_s += '<a href="#" onclick="$p.app.widgets.open('+$p.ajax.getVal(l_result[i],"id","int",false,0)+',indef,indef,'+($p.ajax.getVal(l_result[i],"secured","int",false,0)==0?false:true)+')">'
                    + $p.img("puce.gif",3,5,"","imgmid")
                    + ' '
                    + $p.ajax.getVal(l_result[i],"name","str",false,"???")
                    + '</a><br/>';
    		}
        }
        
		$p.app.menu.addArea('addmenu_5',l_s);
	}
}

//******************** MENUS CONFIG FUNCTIONS ***********************************************************************************************************************
/*
    Class: $p.app.menu.config
            Menu config functions
*/
$p.app.menu.config={
	oldStyle:1,
	leftmenuinit:false,
	tempIcon:"",
	/*
		Function: $p.app.menu.config.build
        
                                Build the config menu              
		Removed with 2.2.3 (EMA)
	
	build:function()
	{
		// Open the "edit" menu
		if (showBoxStatus){hideBox();}

        $p.plugin.hook.launch('app.menu.config.addOption1');

        if ($p.app.env == 'portal_page_conn'
            || $p.app.env == 'portal_page_anon'
            || $p.app.env == 'portal_frame')
        {
            $p.app.menu.config.oldStyle=tab[$p.app.tabs.sel].style;
            
            $p.app.menu.addTitle('confmenu_1','',lg("optionsOfThisPage"),$p.app.menu.config.buildPortalOptions);
        }

        $p.plugin.hook.launch('app.menu.config.addOption2');

		if ($p.app.user.id != 0
            && $p.navigator.IE) {
			$p.app.menu.addTitle('confmenu_2','',lg("optionsOfThePortal"),$p.app.menu.config.buildGeneralOptions);
		}

        $p.plugin.hook.launch('app.menu.config.addOption3');

        $p.app.menu.openFirstOptionAvailable('confmenu_');
        
	},
	*/
	/*
		Function: $p.app.menu.config.open
			Open the configuration menu
	*/
	open: function()
	{
		$p.app.menu.openPopup();
		$p.app.menu.config.buildPortalOptions();
	},
	isPageOptionsDisplayed: function()
	{
		if ($p.app.env == 'portal_page_conn'
            || $p.app.env == 'portal_page_anon'
            || $p.app.env == 'portal_frame')
        {
			return true;
		}

		return false;
	},
	isGeneralOptionsDisplayed: function()
	{
		if ($p.app.user.id != 0
            && $p.navigator.IE)
        {
			return true;
		}
		return false;
	},
	buildPortalOptions: function()
	{
		$p.app.menu.config.oldStyle=tab[$p.app.tabs.sel].style;
		
        if(tab[$p.app.tabs.sel].lock==1 && $p.app.pages.lockPage==1 ) return;
        
		var l_s = '<form name="option">';
        
		if (__menuposition == 'h') {
			l_s += '<table width="100%">'
                + '<tr>';
		}
		
		if ((__columnchange 
             && $p.app.isCustomPortal()
            ) 
                || ($p.app.user.id!=0 
                    && __doubleprotection 
                    && $p.app.isCustomPortal() 
                    && tab[$p.app.tabs.sel].shared==0)
           ) 
        {

			if (__menuposition == 'h')
                l_s+= '<td valign="top" width="30%">';
			l_s += '<div class="title" style="padding-top: 8px;border-bottom: 1px solid #000;">'
                + lg("organisationOptions")
                + '</div>';
			
			if (__USE_WIDGET_PAGE_TEMPLATE && $p.app.isCustomPortal())
			{
				l_s += '<div id="optiontemplate" style="padding: 4px;">'
                    + lg("pageTemplate") + ' :<br />'
					+ $p.app.menu.config.showTemplates()
					+ '</div>';
			}
			
			if (__columnchange && $p.app.isCustomPortal())
            {
                l_s += '<div id="optionMenunbCol" style="padding: 4px;">'
                    + lg("lblColNb")
                    + " &nbsp; "
                    + "<input type='button' value='-' style='width:20px' onclick='$p.app.menu.config.supCols()' /> "
                    + "<input type='text' name='nbcol' value='"+tab[$p.app.tabs.sel].colnb+"' style='text-align: center;width: 20px;border: 0px;border-bottom: 1px solid #c6c3c6;background: #fff;' size='1' disabled /> "
                    + "<input type='button' value='+' style='width:20px' onclick='$p.app.menu.config.addCols()' />"
                    + "</div>";
            }
			if ($p.app.user.id!=0 
				&& __doubleprotection 
				&& $p.app.isCustomPortal()
				&& tab[$p.app.tabs.sel].shared==0)
			{
    			l_s += '<div style="padding: 4px;">'
    			    + '<input type="checkbox" name="usepass"'
                    + ((tab[$p.app.tabs.sel].lock==1)?' checked="checked"':'')
                    + ' /> '+lg("lblSecurity")+' '+tooltip('msgSecurityhlp')
                    + '</div>';
			}

			if (__menuposition == 'h') l_s += '</td>';
		}

		if ((__themeList.length>1 && __displayThemeSelector) || __showtabicon)
		{
			if (__menuposition == 'h')
                l_s += '<td valign="top" width="30%">';
			
			l_s += '<div class="title" style="padding-top: 8px;border-bottom: 1px solid #000;">'
                + lg("graphicalOptions")
                + '</div>';
			if (__themeList.length>1 && __displayThemeSelector) {
                l_s += '<div style="padding: 4px;">'
                    + lg("lblColors")
                    + " &nbsp; <input type='button' value='<' style='width:20px' onclick='$p.styles.prevstyle();' /> "
                    //+ "<span width='120' id='selstyle' style='border-bottom: 1px solid #c6c3c6;text-align: center;width: 120px;overflow: hidden;'>"+__themeList[tab[$p.app.tabs.sel].style-1]+"</span>"
                    + "<input type='text' name='selstyle' value='"+__themeList[tab[$p.app.tabs.sel].style-1]+"' style='text-align: center;width: 100px;border: 0px;border-bottom: 1px solid #c6c3c6;background: #fff;' size='14' disabled /> "
                    + " <input type='button' value='>' style='width:20px' onclick='$p.styles.nextstyle();' />"
                    + "</div>"
                    + "<br />";
            }
            
            if (tab[$p.app.tabs.sel].type==2 
                && tab[$p.app.tabs.sel].removable){
    				l_s += '<div style="padding: 4px;">'
                        + lg("url")+' <input type="text" value="'+tab[$p.app.tabs.sel].param+'" size="25" id="siteurl" name="siteurl" /> '
                        + '</div>'
    					+ '<br />';
			}
            
			if (__showtabicon){
				l_s += '<div class="hightlight" style="padding: 4px;">'
					+ lg("addIconToPage")+' :'
					+ '<div id="pageicons" style="width:100%">'
                    + '</div>'
					+ '</div>';
			}
           
			if (__menuposition == 'h') l_s += '</td>';
		}

		if ((__usereader && $p.app.isCustomPortal()) || (__ctrlhiding && $p.app.isCustomPortal()) || (__moduleAlign && $p.app.isCustomPortal()) || $p.app.isCustomPortal())
		{
			if (__menuposition == 'h') l_s += '<td valign="top" width="30%">';
			l_s += '<div class="title" style="padding-top: 8px;border-bottom: 1px solid #000;">'
                + lg("widgetOptions")
                + '</div>';

			if ($p.app.isCustomPortal())
                l_s += "<div><input type='checkbox' name='loadonstart' "+((tab[$p.app.tabs.sel].loadstart==1)?"checked='checked' ":"")+"/> "+lg("loadOnStart")+" "+tooltip("msgLoadStarthlp")+"</div>";
			if (__usereader && $p.app.isCustomPortal())
                l_s += "<div><input type='checkbox' name='usereader' "+(tab[$p.app.tabs.sel].usereader==1?"checked='checked' ":"")+"/> "+lg("lblUseInternalReader")+" "+tooltip("msgReaderhlp")+"</div>";
			//if (__ctrlhiding && $p.app.isCustomPortal())
            //    l_s += "<div><input type='checkbox' name='controls' "+((tab[$p.app.tabs.sel].controls=='Y')?"checked='checked' ":"")+"/> "+lg("blockThisPage")+"</div>";
			if (__moduleAlign && $p.app.isCustomPortal())
                l_s += "<div><input type='checkbox' name='modulealign' "+((tab[$p.app.tabs.sel].moduleAlign)?"checked='checked' ":"")+"/> "+lg("lblModuleAlign")+" "+tooltip("msgModuleAlign")+"</div>";

			if (__menuposition == 'h') l_s += '</td>';
		}

		if (__menuposition == 'h')
		{
			l_s += '</tr>'
				+ '</table>';
		}
        
		l_s += '<center>'
			+ '<br /><input class="btnbig" type="button" value="'+lg("lblBtnValid")+'" onclick="$p.app.menu.config.save();" /><br />'
			+ '</center>'
			+ '</form>';
            
        if (typeof($p.app.menu.menuOpt['confmenu_1'])=='undefined' 
            || $p.app.menu.menuOpt['confmenu_1']==false) {
                $p.app.menu.addInPopup(l_s);
                if (__showtabicon) {
                    $p.app.menu.config.showIcons();
                    if (tab[$p.app.tabs.sel].icon!=""){
                        $p.app.menu.config.setIcon(indef,tab[$p.app.tabs.sel].icon);
                    }
                    else    {
                        $p.app.menu.config.setIcon(-1);
                    }
                } 
        }
		
		if (__USE_WIDGET_PAGE_TEMPLATE && $p.app.isCustomPortal())
		{
			$p.app.menu.config.selectTemplate(tab[$p.app.tabs.sel].template);
		}
		
        $p.plugin.hook.launch('app.menu.config.buildPortalOptions.end');
	},
	buildGeneralOptions: function()
	{
		$p.app.menu.addArea('confmenu_2',"<br />"+$p.img("ico_home.gif",14,14)+" <a class='menul' href='#' onclick='$p.navigator.addHome();return false;'>"+lg("lblHome",__APPNAME)+"</a><br />"+$p.img("ico_favorite.gif",14,14)+" <a class='menul' href='#' onclick='$p.navigator.addFav();return false;'>"+lg("lblFav",__APPNAME)+"</a>");
	},
	/*
		Function: $p.app.menu.config.showIcons
                                Display icons list for portal personalization             
	*/
	showIcons:function()
	{
		//no icon link
		var aLvl1 = new Element('a', 
			{ 
				'events': {
						'click': function(){
								$p.app.menu.config.setIcon(-1); }
						  },
				'href':'#'
			} 
		);
		aLvl1.set('html',lg("noIcon"));
		aLvl1.inject($("pageicons"));
					
		for (i=0;i<=__nbicons;i++)
		{
			var imgM = "imgLvlMulti"+i;
			var imgM = new Element('img',
				{ 
					'styles':
					{
						'width':'16px',
						'height':'16px',
						'border':'1px solid #ffffff',
						'vertical-align':'middle'
					},
					'events':
					{
						'click': function()
						{
							$p.app.menu.config.setIcon(this.name); 
						}
					},
					'id':'icon'+i,
					'src':_dirImg+'_deficon'+i+'.gif',
					'align':'absmiddle'
				}
			);
			imgM.name = i;
			imgM.injectInside($("pageicons"));	
		}

	},
	/*
		Function: $p.app.menu.config.showTemplates
                                Build the templates selection form             
	*/
	showTemplates: function()
	{
		var l_s = '<input type="hidden" id="templateid" name="templateid" />';
					
		for (var i = 0; i < $p.app.pages.templates.length; i++)
		{
			l_s += '<a href="#" onclick="$p.app.menu.config.selectTemplate(' + i + ',true); return false;" style="margin: 4px;">'
				+ $p.img($p.app.pages.templates[i].image,indef,indef,'','imagenotselected','pagetemplate' + i)
				+ '</a>';
		}
		
		return l_s;
	},
	/*
		Function: $p.app.menu.config.hide
                                Hide edit menu                 
	*/
	hide:function()
	{
		$p.app.menu.close();
		//re-initialize the colors (if not saved)
		if (tab[$p.app.tabs.sel].style!=$p.app.menu.config.oldStyle)    {
			tab[$p.app.tabs.sel].style=$p.app.menu.config.oldStyle;
			$p.styles.setActiveStyleSheet(tab[$p.app.tabs.sel].style);
		}
	},
	/*
		Function: $p.app.menu.config.addCols

                                Increase page column
                                
               See also:
                    <$p.app.menu.config.save>
	*/
	addCols:function()
	{
		l_colnb=parseInt(document.forms["option"].nbcol.value,10);
		if (l_colnb<9)  {
			l_colnb++;
			document.forms["option"].nbcol.value=l_colnb;
		}
	},
	/*
		Function: $p.app.menu.config.supCols
                                Remove page column
	*/
	supCols:function()
	{
		l_colnb=parseInt(document.forms["option"].nbcol.value,10);
		if (l_colnb>1)  {
			l_colnb--;
			document.forms["option"].nbcol.value=l_colnb;
		}
	},
	/*
		Function: $p.app.menu.config.selectTemplate
                                Select a template in the configuration
                                
                     Parameters:
                     
                                v_id: templateid
	*/
	selectTemplate: function (v_id, forceRefresh)
	{
		tab[$p.app.tabs.sel].cells = [];// Clean tab
		$('templateid').value = v_id;
		//document.forms['option'].templateid.value = v_id;
		
		for (var i = 0; i < $p.app.pages.templates.length; i++)
		{
			if (i == v_id)
				$p.setClass('pagetemplate' + i,'imageselected');
			else
				$p.setClass('pagetemplate' + i,'imagenotselected');
		}
		
		//if admin, apply the template immediatly
		if ($p.app.env == 'admin' && forceRefresh)
		{
			tab[$p.app.tabs.sel].template = v_id;
			tab[$p.app.tabs.sel].colnb = $p.app.pages.columns.getNbOfColumn($p.app.tabs.sel, v_id);
			$p.app.pages.columns.reallocate();
			$p.app.pages.refresh();
		}
	},
	/*
		Function: $p.app.menu.config.setIcon
                                Define page icon
                                
                     Parameters:
                     
                                v_id: tab ID
                                v_url: url of the icon
	*/
	setIcon:function(v_id,v_url)
	{
		for (var i=0;i<__nbicons;i++)
		{
			if (v_id==indef)    {
				($("icon"+i)).style.borderColor=(_dirImg+"_deficon"+i+".gif"==v_url?"#ff0000":"#ffffff");
			}
			else    {
				($("icon"+i)).style.borderColor=(i==v_id?"#ff0000":"#ffffff");
			}
		}
		if (v_id==indef)    {
			$p.app.menu.config.tempIcon=v_url;
		}
		else    {
			$p.app.menu.config.tempIcon=(v_id==-1?"":_dirImg+"_deficon"+v_id+".gif");
		}
		//write the icon value in a hidden field to get it with $_post 
		(document.forms[0].hiddenIconValue)?$('hiddenIconValue').value=$p.app.menu.config.tempIcon:'';
	},
	/*
		Function: $p.app.menu.config.save
                                Save page options changes
	*/
	save: function()
	{
        if (tab[$p.app.tabs.sel].controls == 'N')
        {
            $p.app.alert.show(lg('pageBlockedPreventOptionsChange'));
            return false;
        }
		//save the settings
		var l_form = document.forms['option'];
		var l_alarm = true;
        //security
        var l_secu = 0;
        var l_refresh = false;

        if ($p.app.user.id != 0)  {
            if (l_form.usepass) {
                l_secu = (l_form.usepass.checked)     ?   1
                                                      :   0;
            }
        }
		//info banner
		if (l_form.useadvise && $p.app.isCustomPortal())   {
			$p.app.banner.info.requested = (l_form.useadvise.checked)?"Y":"N";
	/*		if ($p.app.banner.info.requested == "Y" 
                && $p.app.banner.info.loaded 
                && $p.app.banner.info.shown) {
                    $p.app.banner.info.load();
            }*/
		}
		//style
		$p.app.menu.config.oldStyle = tab[$p.app.tabs.sel].style;
		//use reader
		var l_usereader = (l_form.usereader && $p.app.isCustomPortal())   ?   (__usereader
                                                                          ?   (l_form.usereader.checked  ?   1 :   0)
                                                                          :   0)
                                                                          :   tab[$p.app.tabs.sel].usereader;
		/*//controls
		var l_controls = (l_form.controls && $p.app.isCustomPortal())     ?       (l_form.controls.checked
                                                                            ?       "Y"
                                                                            :       "N")
                                                                        :       tab[$p.app.tabs.sel].controls;*/
                                            
		var l_moduleAlign = (l_form.modulealign && $p.app.isCustomPortal()) ?       l_form.modulealign.checked
                                                                            :       tab[$p.app.tabs.sel].moduleAlign;
        
		tab[$p.app.tabs.sel].label = $p.app.tabs.currName;
		tab[$p.app.tabs.sel].lock = l_secu;
		//tab[$p.app.tabs.sel].lock=jspass;
		
		//Columns
		l_nbCol = (l_form.nbcol && $p.app.isCustomPortal()) ?       parseInt(l_form.nbcol.value,10)
                                                            :       tab[$p.app.tabs.sel].colnb;
        if ($p.app.isCustomPortal())
        {
    		var l_allowSuppress = $p.app.pages.columns.isEmpty(l_nbCol);
    		if (l_allowSuppress)    {
    			if (l_nbCol>tab[$p.app.tabs.sel].colnb) {
    				$p.app.pages.columns.add(l_nbCol);
    			}
    			else if (l_nbCol<tab[$p.app.tabs.sel].colnb)    {
    				if (!$p.app.pages.columns.sup(l_nbCol))
					{
						// reset column number if column suppression do not work
						l_nbCol = tab[$p.app.tabs.sel].colnb;
					}
					
    			}
                //rename classes
                $p.app.pages.columns.renameClasses(l_nbCol);
    		}
    		else    {
    			l_nbCol = tab[$p.app.tabs.sel].colnb;
    			l_alarm = false;
    		}
			var l_newTemplateId = l_form.templateid.value;
			if (tab[$p.app.tabs.sel].template != l_newTemplateId)
			{
				tab[$p.app.tabs.sel].template = l_newTemplateId;
				// compute the new number of column (it changes based on the template to keep the same number of cells)
				tab[$p.app.tabs.sel].colnb = $p.app.pages.columns.getNbOfColumn($p.app.tabs.sel, l_newTemplateId);
				l_nbCol = tab[$p.app.tabs.sel].colnb;
				$p.app.pages.columns.reallocate();
				$p.app.pages.refresh();
			}
        }
		/*//if (p_area.showType!=l_showType) changeShowType(l_showType);
		if (tab[$p.app.tabs.sel].controls != l_controls && $p.app.isCustomPortal())  {
			$p.app.widgets.switchHdr();
		}*/
		if (tab[$p.app.tabs.sel].moduleAlign != l_moduleAlign && $p.app.isCustomPortal())    {
			$p.app.widgets.align(tab[$p.app.tabs.sel].moduleAlign);
		}
		if (tab[$p.app.tabs.sel].showType == 1
            && l_nbCol != tab[$p.app.tabs.sel].colnb
            && $p.app.isCustomPortal()) {
                $p.app.alert.show(lg("lblColNbErr"));
        }
		
		tab[$p.app.tabs.sel].usereader = l_usereader;
		tab[$p.app.tabs.sel].icon = $p.app.menu.config.tempIcon;
		tab[$p.app.tabs.sel].loadstart = (l_form.loadonstart && $p.app.isCustomPortal())      ?       (l_form.loadonstart.checked
                                                                                              ?       1
                                                                                              :       0)
                                                                                              :       0;
                        
        var l_oldUrl = tab[$p.app.tabs.sel].param;
        if (l_form.siteurl && l_form.siteurl.value!=l_oldUrl)   {
			tab[$p.app.tabs.sel].param = l_form.siteurl.value;
            tab[$p.app.tabs.sel].fct = "$p.app.pages.frame('"+tab[$p.app.tabs.sel].param+"',"+tab[$p.app.tabs.sel].id+")";
            l_refresh = true;
        }
                                                                                                                                                             
		$p.app.tabs.create($p.app.tabs.sel);
        
        if (l_refresh) {
            tab[$p.app.tabs.sel].isLoaded=false;
            eval(tab[$p.app.tabs.sel].fct);
        }

		$p.ajax.call(posh["scr_config_options"],
			{
				'type':'execute',
				'variables':"prof=" + tab[$p.app.tabs.sel].id
                            + "&portstyle=" + tab[$p.app.tabs.sel].style
                            + "&portname=" + $p.string.esc($p.app.tabs.currName)
                            + "&col=" + l_nbCol
                            + "&advise=" + $p.app.banner.info.requested
                            + "&usepass=" + l_secu
                            + "&usereader=" + l_usereader
                            //"&ctrl="+l_controls+
                            + "&align=" + (l_moduleAlign?"Y":"N")
                            + "&icon=" + $p.app.menu.config.tempIcon
							+ "&tpl=" + tab[$p.app.tabs.sel].template
                            + "&load=" + tab[$p.app.tabs.sel].loadstart
                            + "&param=" + $p.string.esc(tab[$p.app.tabs.sel].param),
				'alarm':l_alarm
			}
		);
		//if (l_allowSuppress) $p.app.menu.config.hide();
		$p.app.popup.hide();
	}
	// ,
    // refresh: function()
    // {
        // $p.app.menu.open("poptions",true);
    // }
}


//************************************ TABS FUNCTIONS ***************************************************************************************************************
/*
    Class: $p.app.tabs
    
         Set of functions to manage tabs
         
         Main functions
         
         - <$p.app.tabs.object>
*/
$p.app.tabs={
	isInit:false,
	sel:indef,
	selId:0,
	currName:"",
	overtabid:-1,
	currHeadLink:{},
	locked:false,
	defTheme:indef,
	/*
		Function: $p.app.tabs.object 
                                 *(Constructor)* Object tab, define a tab 
                      
                      Parameters:

                        id - uniq id of the tab
                        label - title written in the tab object
                        type - type of the tab (personalized page, frame, ...)
                        fct - function called when tab is opened
                        lock (boolean) - is the tab locked ?
                        seq - tab sequence (gives order information)
                        editable (boolean) - is the tab editable
                        movable (boolean) - is the tab movable
                        icon - icon displayed in the tab
                        status - is a new page or not
                        loadstart (boolean) - is the tab loaded on application startup (application for personalized pages)
                        pageId - if pageId 1, page linked to 'pages' in the database.
                        removable - is the tab removable ?
                        temporary - is it a temporary tab
                        style - tab style
                        colsnodelist - list of node cols by tab
                    
                    See Also:
                    
                               <$p.plugin.useWidget>, <$p.app.standalone>,<$p.app.tabs.init>,<$p.app.pages.openCreatedTab>
                            
	*/ 
	object: function(id,label,type,fct,lock,seq,editable,
                movable,icon,loadstart,status,param,
                pageId,removable,temporary,style,
                colsnodelist,pageIdDb)
	{
        if (lock == indef) lock="";

		this.pageid = pageIdDb;
		this.id = id;
		this.label = label;
        this.removable = (removable == indef ? 1 : removable);
		this.type = type;
		this.fct = fct;
		this.param = param;
		//lock = the tab is lockable or not ?
		this.lock = lock;
		this.seq = seq;
		this.editable = (editable == indef ? true : editable);
		this.movable = movable;
		this.icon = icon;
		this.loadstart = (loadstart == indef ? 0 : loadstart);
		this.status = status;
		//added 1.4 to manage these information at tab level
		this.isLoaded = indef;
		this.maxUniq = 0;
		this.root = {};
		this.template = 0;
		this.controls = "Y";
        this.showwidgetbar = 1;
		this.moduleAlign = (this.type == 1) ? __moduleAlignDefault : true;
		this.style = (style == indef ? 1 : style);
		this.showType = 0;
		this.newspapernb  =20;
		this.usereader = (__usereader ? 1 : 0);
		this.moveIsInit = false;
		this.nbUnread = 0;
		//locked = current lock status of a tab
		this.locked = false;
		this.temporary = (temporary == indef ? false : temporary);
		this.shared = 0;
        this.currentView = 'home';
		this.module = [];
        this.canvas = [];
        this.RssArticles = new Object();
        this.RssArticles.length = 0;
		this.feeds = new Object();
        //array which contains list of columns, from 1 and not 0
        this.colnb = 3;
		this.modified = false;
		this.cells = [];
        this.widgetsbycol = {};
		this.pageIdDb = pageIdDb;

        if (colsnodelist && colsnodelist.length > 0) {
            for (var i = 0; i < colsnodelist.length; i++) {
                var colnode = colsnodelist.item(i);
                var nb = $p.ajax.getVal(colnode,"nb","int",false,0);
                var cellid = $p.ajax.getVal(colnode,"cellid","int",false,0); //colnode.getAttribute('colid');
                //var colid = $p.ajax.getprop(colnode,'colid','int',false,"");
                this.widgetsbycol[cellid] = {'nb':nb,'byformat':{},'toomany':false};
                
            }
            //this.colnb = colsnodelist.length;
        }
		else
		{
			for (var i = 1; i <= this.colnb; i++) {
				this.widgetsbycol[i] = {'nb':0,'byformat':{},'toomany':false};
			}
		}
        
		this.open = $p.app.tabs.open;
		this.rename = $p.app.tabs.rename;
		this.remove = $p.app.tabs.remove;
	},
	/*
		Function: init
                                $p.app.tabs.init 
                        
                                Create the tabs objects                        
                                
                                Each tab is get from xml request, via $p.app.loadTabs
		
        Parameters:

			response - xml response containing tabs information
            
        See Also:
        
                  <$p.app.loadTabs> and its callback <$p.app.initTabs> which call this function.
                              
	*/
	init:function(response)
	{
		$p.plugin.hook.launch('app.tabs.init.start');

		var i = 0,
            nbTemp = 0,
            anonymousTabs = [],
            result; 

		//do not take temporary tabs in account
		while (nbTemp < tab.length && tab[nbTemp].temporary)
		{
			nbTemp++;
		}
		while (response.getElementsByTagName("tab")[i])
		{
			if (i+nbTemp >= tab.length 
                    || (tab[i+nbTemp].isLoaded == indef && tab[i+nbTemp].module.length == 0))  {

				result=response.getElementsByTagName("tab")[i];

				//get default tabs style = first tab style
				if ($p.app.tabs.defTheme == indef)
					$p.app.tabs.defTheme = $p.ajax.getVal(result,"style","int",false,1);

				var tmp_idpage = 0;
				if( $p.app.user.id == 0 && $p.ajax.getVal(result,"page_id","int",false,0)==0 ){
					tmp_idpage = $p.ajax.getVal(result,"number","int",false,0);
				} else {
					tmp_idpage = $p.ajax.getVal(result,"page_id","int",false,0);
				}
				
				//($p.ajax.getVal(result,"page_id","int",false,0)==0)?$p.ajax.getVal(result,"page_id","int",false,0):$p.ajax.getVal(result,"number","int",false,0)
				var l_type = $p.ajax.getVal(result,"type","str",false,"P");
				var l_number = $p.ajax.getVal(result,"number","int",false,0);
				var l_action = $p.ajax.getVal(result,"action","str",false,"");
				var l_name = $p.ajax.getVal(result,"name","str",false,"...");
				// store name and id tabs
				tab[i+nbTemp]=new $p.app.tabs.object(
										l_number,
										l_name,
										l_type,
										l_action,
										$p.ajax.getVal(result,"locked","int",false,0),
										$p.ajax.getVal(result,"seq","int",false,0),
										$p.ajax.getVal(result,"edit","int",false,0),
										$p.ajax.getVal(result,"move","int",false,0),
										$p.ajax.getVal(result,"icon","str",false,""),
										$p.ajax.getVal(result,"loadstart","int",false,0),
										$p.ajax.getVal(result,"status","int",false,0),
										$p.ajax.getVal(result,"param","str",false,""),
										1,      //page id
                                        $p.ajax.getVal(result,"removable","int",false,1),
                                        false,
                                        $p.ajax.getVal(result,"style","int",false,1),
                                        result.getElementsByTagName("cols"),
										tmp_idpage
										);
				//get the shared information
				tab[i+nbTemp].shared = $p.app.tabs.checkIfShared($p.ajax.getVal(result,"shared","str",false,''));
                tab[i+nbTemp].showwidgetbar = $p.ajax.getVal(result,"showwidgetbar","int",false,1);
                tab[i+nbTemp].controls = $p.ajax.getVal(result,"controls","str",false,'Y');
				var l_template = $p.ajax.getVal(result,"template","int",false,0);
				tab[i+nbTemp].template = l_template;
				tab[i+nbTemp].colnb = $p.ajax.getVal(result,"colnb","int",false,3);
				
				// initialize first tab for widget moving from one tab to this tab
				var cell = result.getElementsByTagName("cells")[0];
				tab[i+nbTemp].cells = new Array();
				tab[i+nbTemp].cells[1] = {
					nbWidgets:{
						'nb':$p.ajax.getVal(cell,"cellid","int",false,-1),
						'max':$p.app.pages.templates[l_template].rows[0].cols[0].maxWidgets,
						'byformat':{}
					}
				};

                //register pages and modules informations in tab array for anonymous portal
                if ( $p.app.user.id == 0 
					|| $p.app.user.type == 'N'
					|| tab[i+nbTemp].id == 0 
                    || tab[i+nbTemp].id >= 1000000000) {

                            tab[i+nbTemp].isLoaded = indef;
                            anonymousTabs.push({
                                                    'page_id':l_number,
													'type':l_type,
                                                    'v_tab':(i+nbTemp),
                                                    'v_action':l_action
                                              });
                }
			}
			i++;
		}

        if (anonymousTabs.length!=0) {
            for (var i=0;i<anonymousTabs.length;i++) {
				if (anonymousTabs[i]['type'] == 1)
				{
					if ($p.app.user.id > 0)
					{
						$p.app.pages.load(posh["xmlmodules"],"id="+anonymousTabs[i]["page_id"],
							anonymousTabs[i]["v_tab"],
							anonymousTabs[i]["v_action"]);
					}
					else
					{
						$p.app.pages.load("selections/page"+anonymousTabs[i]["page_id"]+".xml?nocache="+rand,indef,
									  anonymousTabs[i]["v_tab"],
									  anonymousTabs[i]["v_action"]);
					}
				}
            }
        }
     
		$p.plugin.hook.launch('app.tabs.init.end');
	},
	/*
		Function: $p.app.tabs.open 
        
                                Open a tab
		
                    Parameters:

			v_id -  id of the tab
	*/
	open: function(v_id,v_addAnchor)
	{
        $p.app.widgets.rss.stopAllLoadings();
		if (v_id == indef) {
            v_id = $p.app.tabs.idToPos(this.id);
        }
		
        plug_tabid = v_id;
        $p.plugin.hook.launch('app.tabs.open.begin');
        
		if (tab[v_id].type == 4){
            eval(tab[v_id].fct);
			return;
		}

        //v2.1 : pb with tab id=-1
        if (v_id == -1) v_id = 0;

        
        
        //add page ID in the URL
        if (tab[v_id] && !tab[v_id].temporary && v_addAnchor != false)
		{
            $p.url.goToAnchor('tab/'+tab[v_id].id);

        }
        $p.app.tabs.detectModifiedTab(v_id);

		$p.app.pages.hide();
		//$p.app.tabs.select(v_id);
		$p.app.tabs.sel = v_id;
        //param to obtain delay while loading tab
        //see $p.app.initTabs
        //needed to display tab after F5 refresh when we are on a tab and not home page
        //you need to set    $p.app.delaytab = true;
        //and unset to 0 after display
        //so widgets will be displayed after page is loaded, if not all div are not created
        //and you obtain an error
        if ($p.app.delaytab) {
            setTimeout("eval(tab[$p.app.tabs.sel].fct)",200);
        }  else {
            eval(tab[$p.app.tabs.sel].fct);
        }
        $p.app.delaytab = false;
		
        $p.app.tabs.select(v_id,true);
		$p.show('message','block');
		$p.show('vmenu','block');
		//hide help message
		$p.show('message','none');
		if(tab[$p.app.tabs.sel].status==2) {
			$p.app.pages.createPageForm(tab[$p.app.tabs.sel].id);
			$p.show("pageform"+tab[$p.app.tabs.sel].id,"block");
			// hide menu
			$p.show('vmenu','none');
		}         
	},
	/*
		Function: $p.app.tabs.select 

                                Select a tab 
                                
                                create tabs menu (again)
                                
                                hide other pages
		
                    Parameters:

			v_tab -  id of the tab
	*/
	select:function(v_tab,created)
	{
		if (v_tab==indef)   {   v_tab=$p.app.tabs.sel; }
        
     //   if (!$p.app.tabs.created[v_tab]) {
            $p.app.tabs.create(v_tab);
     //   }
        
        //if ($p.app.env=='admin' && $p.app.user.type=="A") {
          //  $p.admin.tabs.hideUnavailableTabs();
        //}
	},
	/*
		Function: refresh
                                $p.app.tabs.refresh 
                        
                                Refresh the tabs selection
		
                     Parameters:

			v_tab -  id of the tab
	*/
	refresh:function(v_tab)
	{
        $p.app.tabs.created[v_tab]=false;
		$p.app.tabs.create(v_tab);
	},
    /*
		Function: displayScrollTab
                                $p.app.tabs.displayScrollTab 
                        
                                display the left or right tab scroll
		
                    Parameters:
                    
                                position - 'right' or 'left'
        
                     Returns:
                     
                                HTML code
	*/
    displayScrollTab:function(position)
    {   
        var l_s='';
        if (position=='left') {
            l_s += '<td class="endtab">'
    		    + '<a href="#" id="leftTabNav" onmouseover="$p.app.tabs.nav.left();" onmouseout="$p.app.tabs.nav.stop();" onclick="$p.app.tabs.nav.jumpLeft();">'
				+ $p.img('s.gif',indef,indef,indef,'scrollbtnleft')
				+ '</a>'
    		    + '</td>';
        }   
        else if (position=='right') {
            l_s += '<td class="endtab scrollbtn">'
    		    + '<a href="#" id="rightTabNav" onmouseover="$p.app.tabs.nav.right();" onmouseout="$p.app.tabs.nav.stop();" onclick="$p.app.tabs.nav.jumpRight();">'
				+ $p.img('s.gif',indef,indef,indef,'scrollbtnright')
				+ '</a>'
    		    + '</td>';
        }           
        return l_s; 
    },
    /*
		Function: newPageLink
                                $p.app.tabs.newPageLink 
                        
                                display the 'add a new page' link
		
                    Parameters:
                    
                                v_type - (0 =navigator 1 =other)
                                i - tab seq
        
                     Returns:
                     
                                HTML code
	*/
    newPageLink:function(v_type,i)
    {   
        var l_s='';
        if (v_type==indef)  return '';
        if (v_type==0 && i==indef)  return '';
        // if admin configure with no add link
        if (__addPagePermission == 3 || (__addPagePermission == 2 && $p.app.user.id <= 0))
		{
			if (v_type == 0)
			{
				return '<td></td>';
			}
			else
			{
				return '<li></li>';
			}
		}
		
        
        if (v_type==0) {
            //l_s+='<td nowrap="nowrap" class="'+(i==0?'notab':'endtab')+'" style="width:100%">';
			l_s+='<td nowrap="nowrap" class="'+((i==0 || ($p.app.env=='admin'))?'notab':'tabl')+'" style="width:100%">';
			if ($p.app.user.id>=0 
               && __maxPageNb>tab.length) {
    				//l_s+='<a href="#" id="newtablk" onclick="$p.app.pages.newPortal();return false;" style="text-decoration: none;">'+$p.img("ico_tab_add.gif",20,14,"","imgmid")+' '+lg('lblNewpage')+'&nbsp;</a>';
					l_s+='<div  class="addtab"><a href="#" title="'+lg('lblNewpage')+'"  id="newtablk" onclick="$p.app.pages.addNewPage();return false;" style="text-decoration: none;font-weight:bold;font-size: 13pt;">+</a></div>';
				}
    		l_s+='</td>';
			l_s+='<td class="tabr"><table cellspacing="0" cellpadding="0" border="0"><tbody></tbody></table></td>';
        } 
        else {
            l_s+="<li><div nowrap='nowrap' class='endtab'>";
			if ($p.app.user.id>=0 
                && __maxPageNb>tab.length) {
				//l_s+="<a href='#' onclick='$p.app.pages.newPortal();return false;'>+ "+lg("lblNewpage")+"&nbsp;</a></div>";
				l_s+= '<div  class="addtab"><a href="#" title="'+lg('lblNewpage')+'"  onclick="$p.app.pages.addNewPage();return false;" style="font-size: 13pt;">+</a></div>';
			}
			l_s+="</li>";
        }           
        return l_s; 
    },
	/*
        Function: $p.app.tabs.create
        
                Display the tabs
                
                >$p.app.initTabs
                >       <$p.app.tabs.init> : for each page from xml (response) create tab object -> <$p.app.tabs.object>
                >       <$p.app.tabs.create> 
                >                   create base html for tab
		>                    display tab with $p.app.tabs.displayTabContent, add options
        Parameters:
			v_id(int) - tab ID
			v_locked (boolean) - is the tab locked (not movable) ?
			v_stopMove - ???
			v_prof - ??
            
        See also:

            <$p.app.initTabs>    
	*/
	create:function(v_id,v_locked,v_stopMove,v_prof)
	{
        $p.plugin.hook.launch('app.tabs.create.start');
        // Create the pages tab
		if (v_locked == indef)
			v_locked = $p.app.tabs.locked;
		var l_movable = !v_stopMove;
		
		if (v_id != indef)
			$p.styles.checkTabAndSetActiveStyleSheet(v_id);

		//to update with 1.6 : add type lists, and simplify html code
        if (__tabType=="navigator")
		{   
			l_s = '<table id="alltabs" cellpadding="0" cellspacing="0">'
				+ '<tr>'
				+ $p.app.tabs.displayScrollTab('left')
				+ '<td width="100%">'
				+ '<div id="navfixedbox">'
				+ '<div id="navfloatbox">'
				+ '<div id="navmovebox">'
				+ '<table cellpadding="0" cellspacing="0" width="100%">'
                + '<tr>'
                + '<td style="font-size:1px;line-height:0px;">'
				+  $p.img('s.gif','100%',1,'','','navctlimg') //do not change !! 
                + '</td>'
    			+ '</tr>' 
                + '<tr>'
				+ '<td>'
				+ '<table cellpadding="0" cellspacing="0">'
                + '<tr>';
                
			var i = 0,
				firstMovingTab = true;

			while (i < tab.length)
			{
                if (v_id == indef 
                    && v_prof == tab[i].id)
				{
                       v_id = i;
                       $p.app.tabs.sel = i;
            	}
                else 
				{
                    $p.app.tabs.sel = v_id;
                }
                            
                if (firstMovingTab)
				{
					if (i == 0)
					{   
                        l_s += '<td>'
							+ '<table cellpadding="0" cellspacing="0" border="0">'
							+ '<tr'+(tab[i].movable=='1'?' id="tabsframe"':'')+'>';
					}
					else    
                    {
						if (tab[i].movable == 1)
						{
							l_s += '</tr>'
								+ '</table>'
								+ '</td>'
								+ '<td>'
								+ '<table cellpadding="0" cellspacing="0" border="0">'
								+ '<tr id="tabsframe">';
						}
                    }
					if (tab[i].movable == 1)
						firstMovingTab = false;
				}

                //create the tab
                l_s += '<td id="tab' + i + '" class="tab_' + $p.string.buildAlias(tab[i].label) + '" width="1" valign="top">'
					+ $p.app.tabs.displayTabContent(i,v_id,v_locked,l_movable,v_prof)
					+ '</td>'; 

                i++;
    		}
            
            //create the 'new page' link
            l_s += $p.app.tabs.newPageLink(0,i);
            
			if (i > 0)
			{
				l_s += '</tr>'
					+ '</table>'
					+ '</td>';
			}
            
			l_s += '<td class="endtab">&nbsp;</td>'
				+ '</tr>'
				+ '</table>'
				+ '</td>'
				+ '</tr>'
				+ '</table>'
				+ '</div>'
                + '</div>'
				+ '</div>'
				+ '</td>'
                + $p.app.tabs.displayScrollTab('right')
                //add a bloc if scrollbars with FF
				//+ '<td class="endtab">&nbsp;&nbsp;&nbsp;</td>'
				+ '</tr>'
				+ '</table>';
		}
        
        //__tabType != navigator
		else
		{
			l_s = '<ul class="tabnav" id="tabsframe">';
			var i = 0,
				firstMovingTab = true;
			
            while (i < tab.length)
			{
				//if selected tab in not yet defined
				if (v_id == indef 
                    && v_prof == tab[i].id)
				{
					v_id = i;
					$p.app.tabs.sel = i;
            	}
            	else   {    $p.app.tabs.sel = v_id;   }
                		
				l_s += "<li id='tab"+i+"'"+(i==v_id?" class='active'":"")+">"
					+ $p.app.tabs.displayTabContent(i,v_id,v_locked,l_movable,v_prof)
					+ "</li>";
                
				i++;
			}
            
            //display the 'new page' link
            l_s += $p.app.tabs.newPageLink(1,i)
				+ "</ul>";
		}
		$p.print("tabs",l_s);

		$p.app.tabs.isInit = false;

		if (l_movable)
			$p.app.tabs.initMove(v_id);

		if (__tabType == "navigator")
			$p.app.tabs.nav.init();

        $p.app.tabs.created[v_id] = true;
        
        if ($p.app.env == "admin") {
            //tabs restiction
            $p.admin.tabs.hideUnavailableTabs();
        }          
        
		$p.plugin.hook.launch('app.tabs.create.end');
	},
    created:{},
	/*
		Function: displayTabContent
                                $p.app.tabs.displayTabContent 
                        
                                Display active and inactive tabs
		
                     Parameters:

			i - tab seq
                                v_id(int) - tab ID
			v_locked (boolean) - is the tab locked (not movable) ?
			l_movable - ???
			v_prof - ??
	*/
    displayTabContent:function(i,v_id,v_locked,l_movable,v_prof)
    {
        var l_s="";
        
        if (i==v_id)    {  
           l_s+=$p.app.tabs.activeTab(i,v_locked,l_movable); 
           $p.navigator.changeTitle($p.app.tabs.currName);
        }
        else    {   
            l_s+=$p.app.tabs.inactiveTab(i,v_prof); 
        }  
        
        return l_s;
    },
	/*
		Function: activeTab
                                $p.app.tabs.activeTab 
                        
                                Return active tab HTML code
		
                     Parameters:

			v_id(int) - tab ID
			v_locked (boolean) - is the tab locked (not movable) ?
			v_movable - is the tab movable
            
                     Returns:
                     
                                HTML code of the tab
	*/
	activeTab:function(v_id,v_locked,v_movable)
	{            
        var l_s = '';
        
        //close the option banner in case its already opened
		if ($p.app.banner.option.shown) {
			$p.app.banner.option.hide();
		}
		if(tab[v_id].status!=2) {
			$p.app.banner.option.show();
		}
        
        $p.app.tabs.currName = tab[v_id].label;
        //if the tab is movable, display the appropriate cursor
        var td_displayMoveCursor = '<td class="tabal" id="tab'+v_id+'_h"'
                                    +( v_movable 
                                       && tab[v_id].movable
									   && !($p.app.user.id == 0 && __ANONYMOUS_PAGES_ARE_BLOCKED)
																?     ' style="cursor:move"'
                                                                :     '') 
                                    +'>';
		
        //display the number of unread article
        var span_displayUnreadArticles ='<span class="tabextra" id="tabextra'+v_id+'">'
                                         +((tab[v_id].nbUnread==0 || tab[v_id].temporary)  ?     ''
                                                                   :     '('+tab[v_id].nbUnread+')') 
                                         +'</span>'
        //display the tab icon
        var displayTabIcon = ((tab[v_id].isLoaded==false 
                             && tab[v_id].type==1)            ?      $p.img("ico_waiting.gif",16,16,"","imgmid")
                                                              :      ((tab[v_id].icon==""
                                                                     ||tab[v_id].icon==indef
                                                                     ||!__showtabicon)
                                                              ?      ''
                                                              :      "<img src='"+tab[v_id].icon+"' width='16' height='16' align='absmiddle'>"))
  
		l_s += '<table class="taba" cellpadding="0" cellspacing="0">'
			+ '<tr>'
            + td_displayMoveCursor
            //edit the page name
			+ '<a href="#" onmousedown="'
            + (tab[v_id].currentView != 'home'
                ? '$p.app.widgets.homeView()'
                : ( $p.app.user.id < 0
                    ||v_locked
                    ||!tab[v_id].editable
					|| ($p.app.user.id == 0 && __ANONYMOUS_PAGES_ARE_BLOCKED)
												?     ''
                                                :     '$p.app.tabs.edit('+v_id+')')
              )
            + '" style="cursor: hand;cursor: pointer;">'
            + displayTabIcon
            + '&nbsp;<span id="tabsname'+tab[v_id].id+'" >'+tab[v_id].label+'</span>&nbsp;'        
            + span_displayUnreadArticles
            + '</a>'
            //end of 'td' of the variable 'td_displayMoveCursor'
            + '</td>'
            + '<td class="tabar">';

		if ($p.app.user.id >= 0)  {
            l_s += '<table cellpadding="0" cellspacing="0" border="0">'
                + '<tr><td style="padding-right: 7px;height: 1px;"></td></tr>' //used to fix the minimal width
                + $p.app.tabs.buildLockOption(v_id)
			    + $p.app.tabs.buildShareOption(v_id)
                //+ $p.app.tabs.buildEditableOption(v_id,v_locked)
			    + $p.app.tabs.buildRemoveOption(v_id)
                + '</table>';
		}
		else  {  l_s+="&nbsp;"; }

        l_s+='</td>'
           +'<td class="intertaba">'+$p.img('',1,1)+'</td>'
           +'</tr>'
           +'</table>';

		return l_s;
	},
	/*
		Function: buildLockOption
                                $p.app.tabs.buildLockOption 
                        
                                Display the lock icon if the page is locked
		
                     Parameters:

			v_id(int) - tab ID
            
                     Returns:
                     
                                HTML code
	*/
    buildLockOption:function(v_id)
    {
		//if the tab is shared, it can not be locked
		if (tab[v_id].shared!=0) return '';

        var l_s='';
        //tab lock
        if (tab[v_id].lock!=0) {
             l_s+='<tr>'
                +'<td style="font-size:2pt;">'
                +'<a href="#" onclick="$p.app.pages.lock();return false;">'
                +$p.img('lock.gif',7,9,lg('lblSecuActive'),'imgmid')
                +'</a>'
                +'</td>'
                +'</tr>';
        }
        return l_s;
    },
	buildShareOption: function(v_id)
	{
		var l_s = '';
		if (tab[v_id].shared != 0)
		{
			l_s += '<tr>'
                + '<td style="font-size:2pt;">'
				+ '<a href="#" onclick="$p.app.pages.stopSharing('+tab[v_id].id+');return false;" title="'+lg('clickToStopSharing')+'">'
                + $p.img('ico_share_s.gif',13,10,lg('clickToStopSharing'),'imgmid')
				+ '</a>'
                + '</td>'
                + '</tr>';
		}
		return l_s;
	},
	/*
		Function: buildEditableOption
                                $p.app.tabs.buildEditableOption 
                        
                                Display the option (black arrow) to display the page configuration.
		
                     Parameters:

			v_id(int) - tab ID
			v_locked - locked ?
            
                     Returns:
                     
                                HTML code
	*/
    buildEditableOption:function(v_id,v_locked)  
    {
        var l_s='';

        if (tab[v_id].editable 
            && __showTabOptions
            && tab[v_id].controls == 'Y'
			&& !($p.app.user.id == 0 && __ANONYMOUS_PAGES_ARE_BLOCKED)
		)    {
                l_s+='<tr>'
                    +'<td style="font-size:2pt;">'
                    +'<a href="#" title='+lg("lblShowOpt")+' onclick="'
                    +(v_locked             ?               ''
                                           :               'return $p.app.banner.option.show()')
                    +'">'
                    +$p.img('ico_down_arrow_black.gif',11,8,'modify','imgmid')
                    +'</a>'
                    +'</td>'
                    +'</tr>';
        }
        /*else    {
            l_s+='<tr>'
                +'<td style="font-size:2pt;">'
                +$p.img('s.gif',11,8,'imgmid')
                +'</td>'
                +'</tr>';
        }*/
        return l_s;
    },
	/*
		Function: buildRemoveOption
                                $p.app.tabs.buildRemoveOption 
                        
                                Display the removal icon on the tab (for temporary tabs)
		
                     Parameters:

			v_id(int) - tab ID
            
                     Returns:
                     
                                HTML code
	*/
	buildRemoveOption: function(v_id)
	{
		var l_s = '';

		if (tab[v_id].removable != 0
			&& (tab[v_id].temporary || tab[v_id].type == 3)
			&& !($p.app.user.id == 0 && __ANONYMOUS_PAGES_ARE_BLOCKED))
		{
			l_s += '<tr>'
				+ '<td style="font-size:2pt;">'
				+ '<a href="#" onmousedown="tab['+v_id+'].remove(false);return false;">'
				+ $p.img('ico_close.gif',12,11,lg('lblSuppresspage'),'imgmid')
				+ '</a>'
				+ '</td>'
				+ '</tr>';
		}

		return l_s;
	},
	/*
		Function: inactiveTab
                                $p.app.tabs.inactiveTab 
                        
                                Return inactive tab HTML code
		
                     Parameters:

			v_id(int) - tab ID
			v_prof - ???
            
                     Returns:
                     
                                HTML code of the tab
	*/
	inactiveTab: function(v_id,v_prof)
	{    
        var l_s = '';
        //if the tab is movable, display the appropriate cursor
        var td_displayMoveCursor = '<td class="tabl"'
                                 + (tab[v_id].movable   
										|| !($p.app.user.id && __ANONYMOUS_PAGES_ARE_BLOCKED)
														?      ' id="tab'+v_id+'_h" style="cursor:move"'
                                                        :      '')
                                 + '>';
                                 
        // function called when tab is clicked
        var l_onmouseclickFunction = 
			(v_prof == 0) 	? "openPage("+tab[v_id].id+")"
							: (tab[v_id].type == 4 
								&& $p.app.env == "admin")
								?   "window.location='" + tab[v_id].fct + "'" 
                                :   "if (!$p.app.widgets.dragging){$p.app.tabs.open(" + v_id + ");}";
        
        //display the tab icon
        var displayTabIcon=((tab[v_id].isLoaded == false 
                            && tab[v_id].type == 1)
                                                        ?            $p.img("ico_waiting.gif",16,16,"","imgmid")
                                                        :            ((tab[v_id].icon==""
                                                                     ||tab[v_id].icon==indef
                                                                     ||!__showtabicon)
                                                        ?            '' //$p.img('',16,16,"","imgmid")
                                                        :            "<img src='"+tab[v_id].icon+"' width='16' height='16' align='absmiddle'>"))
        //display the number of unread article                  
        var span_displayUnreadArticles = '<span class="tabextra" id="tabextra'+v_id+'">'
                                       + ((tab[v_id].nbUnread==0 || tab[v_id].temporary) ?               ''
                                                                    :               '('+tab[v_id].nbUnread+')')
                                       + '</span>';
        
		l_s += '<table class="tab" cellpadding="0" cellspacing="0"'+(tab[v_id].temporary ?' style="opacity: 0.4;filter: alpha(opacity=40);"' : '')+'  onmouseup="' + l_onmouseclickFunction + '"><tbody>'
			+ '<tr>'
            //Open the TD
            + td_displayMoveCursor
			+ "<a href='#' onclick='return false;' id='tab" + v_id + "_u'>";
			//+ "<a href='#' onclick=\"" + l_onmouseclickFunction + ";return false;\" id='tab" + v_id + "_u'>";

        // l_s += (v_prof == 0) ?    '<a href="#" onclick="openPage('+tab[v_id].id+');return false;" id="tab'+v_id+'_u">'
                             // :    "<a href="+ href +" id='tab"+v_id+"_u'>";
		
		l_s += displayTabIcon
			+ '	 '+tab[v_id].label
            + span_displayUnreadArticles
            + '</a>'
            //Close the TD
			+ '</td>'
			+ '<td class="tabr">'
			+ '<table cellpadding="0" cellspacing="0" border="0"><tbody>';
            + '<tr><td style="padding-right: 3px;height: 1px;"></td></tr>'; //used to fix the minimal width
        
   		if (tab[v_id].lock != 0)  {
            l_s += "<tr><td>"
                + $p.img("lock.gif",7,9,lg("lblSecuActive"),"imgmid")
                + "</td></tr>";
        }
       
        //l_s += $p.app.tabs.buildAlertOrDeleteIcon(v_id)
			//+ $p.app.tabs.buildRemoveOption(v_id)
        l_s += '</tbody></table>'
            + '</td>'
            + '<td class="intertab">'
            + $p.img('',1,1)
            + '</td>'
            + '</tr>'
            + '</tbody></table>';

		return l_s;
	},
	/*
		Function: buildAlertOrDeleteIcon
                                $p.app.tabs.buildAlertOrDeleteIcon 
                        
                                Display delete icon 
                        
                     Parameters:
                     
                                v_id - current Tab ID
                              
                     Returns:
                     
                                HTML code
           */
    buildAlertOrDeleteIcon: function(v_id)
    {
        var l_s = "";
        if (
                tab[v_id].removable != 0
                && (
                    tab[v_id].type == 2 || tab[v_id].type == 4
                )
             && ($p.app.env == "portal_page_conn" 
             || $p.app.env == "portal_page_anon"
			 || $p.app.env == "portal_frame")
			 && !($p.app.user.id == 0 && __ANONYMOUS_PAGES_ARE_BLOCKED)) {
                l_s += "<tr>"
					+ "<td>"
					+ "<a href='#' onmousedown='return $p.app.pages.suppress("+v_id+");'>"
					+ img("ico_close.gif",12,11,lg('lblSuppresspage'),"imgmid")
					+ "</a>"
					+ "</td>"
					+ "</tr>";
        }
  		/*else {
			l_s+="<tr><td style='font-size:2pt;'>"
               +img("s.gif",11,8,"imgmid")
               +"</td></tr>";
        }*/
        
        return l_s;
    },
	/*
		Function: $p.app.tabs.initMove 

                                Init tabs moving processes
                 
                 Parameters:
                    v_id - tab id
           */
	initMove:function(v_id)
	{         
		// Initialize column & modules behaviors, do not initialize the tabs if already done
		if ($p.app.tabs.isInit) return;
		//if no tab existing for user
		if (tab.length==0) return;
		$p.app.tabs.isInit=true;
		var l_tabs=$("tabsframe");
		if (l_tabs!=null)   {
			for (var i=0;i<l_tabs.childNodes.length-1;i++)
			{
				var l_mod=l_tabs.childNodes[i];
                $p.app.widgets.move.set(l_mod,"tab",l_tabs,"horizontal",false);
			}
		}
	},
	/*
		Function: save
                                $p.app.tabs.save 
                        
                                Save tabs changes

                    Parameters:

			 v_movedId - tab ID before moving
           */
	save: function(v_movedId)
	{
		$p.plugin.hook.launch('app.tabs.save.start');

		// Save the tabs changes
		var l_tabs = $("tabsframe");
		var l_prevPlace = 0;
        var l_selectedTabId = 0;
        
        //Move tab from "welcome page" exception. The page is not in the javascript tab array. there is no => tab[$p.app.tabs.sel].id
        if ($p.app.tabs.sel>=0) {
            var l_selectedTabId = tab[$p.app.tabs.sel].id;
            $p.app.tabs.created[$p.app.tabs.sel]=false;
        }
        
		//for all tabs
        var l_currentPlace = 1;
		for (var i = 0;i < l_tabs.childNodes.length-1;i ++)
		{
            if ((l_tabs.childNodes[i].id).indexOf("tab") != -1)
            {
                //get the tab sequence
                l_id = (l_tabs.childNodes[i].id).replace("tab","");
                if (!tab[l_id].temporary)
                {
                    //if object is the tab moved, and if the objet is not placed on the same place
    				if (l_id == v_movedId 
                        && (l_prevPlace+1) != tab[l_id].seq)
                    {
                        $p.ajax.call(posh["scr_movetab"],
                            {
                                'type':'execute',
                                'variables':"id="+tab[l_id].id+"&old="+tab[l_id].seq+"&new="+(l_currentPlace),
                                'alarm':false
                            }
                        );
                    }
    				l_prevPlace = tab[l_id].seq;
                    
                    tab[l_id].seq = l_currentPlace;
                    l_currentPlace ++;
    				//if (l_id==$p.app.tabs.sel) l_newSeq=tab[l_id].seq;
                }
           }     
		}
		//sort tabs based on the new order
		tab.sort($p.app.tabs.sort);
		// v1.4 : if on HTML predefined page, function was not working
		(l_selectedTabId == 0)      ?       $p.app.tabs.create($p.app.tabs.sel)
                                    :       $p.app.tabs.create(indef,false,false,l_selectedTabId);
		

		$p.plugin.hook.launch('app.tabs.save.end');
	},
	/*
		Function: sort
                                $p.app.tabs.sort 
                        
                                Tabs sorting rule

                    Parameters:

			 a - object
                                 b - object
                     
                     Returns:
                                 
                                 -1,1,0
           */
	sort:function(a,b)
	{
		if (a.seq<b.seq) return -1;
		if (a.seq>b.seq) return 1;
		return 0; 
	},
	/*
		Function: edit
                                $p.app.tabs.edit 
                        
                                Edit a tab name

                    Parameters:

			 v_id - tab ID
           */
	edit:function(v_id)
	{
		if (tab[$p.app.tabs.sel].showType == 1)   {
			$p.app.widgets.rss.reader.close();
			return;
		}
		if (!__tabsCanBeRenamed || tab[$p.app.tabs.sel].controls == 'N')
		{
			return;
		}
		// Edit tab name
        $p.app.tabs.created[$p.app.tabs.sel]=false;
		$p.app.tabs.create($p.app.tabs.sel,false,true);
        $p.app.tabs.created[$p.app.tabs.sel]=false;
		var l_tab = $("tab"+v_id+"_h");

		var l_s = "";
		//l_s += "<form name='tabeditform"+v_id+"' id='tabeditform"+v_id+"' onsubmit='return $p.app.tabs.submitNameChange(this.tabinput,"+v_id+");'>";
		l_s += "<input class='thinbox' name='tabinput"+tab[$p.app.tabs.sel].id+"' id='tabinput"+tab[$p.app.tabs.sel].id+"' type='text' size='"+$p.max(10,tab[v_id].label.length)+"' onblur='$p.app.tabs.submitNameChange(this,"+v_id+");' onkeyup='$p.app.pages.changeName("+tab[$p.app.tabs.sel].id+");' maxlength='30' value='"+tab[v_id].label+"' onblur=\"\" /> ";
		//l_s += "<input type='image' class='imgmid' src='../images/ico_accept.gif' border='0' title='"+lg('lblOk')+"' />";
		//l_s += "<a href='#' onclick='$p.app.tabs.create($p.app.tabs.sel);'>"
		//l_s += $p.img("ico_stop.gif",16,16,lg("lblCancel"),"imgmid")+"</a>";
		//l_s += "</form>";
		l_tab.set('html',l_s);
		var l_input = $("tabinput"+tab[$p.app.tabs.sel].id+"");
		l_input.select();
	},
	/*
		Function: rename
                                $p.app.tabs.rename 
                        
                                Save tab name changes

                    Parameters:

                                 v_name - new tab name
                                v_id - tab ID
           */
	rename:function(v_name,v_id)
	{
		(v_id==indef)?v_id=$p.app.tabs.idToPos(this.id):'';
		if (v_name!="" 
            && v_name!=tab[v_id].label) {
    			if ($p.app.tabs.sel==v_id) {
                    $p.app.tabs.currName=v_name;
                }
    			tab[v_id].label=v_name;
    			$p.ajax.call(posh["scr_config_options"],
    				{
    					'type':'execute',
    					'variables':"prof="+tab[v_id].id
                                    +"&portstyle="+tab[v_id].style
                                    +"&portname="+$p.string.esc(tab[v_id].label)
                                    +"&col="+tab[v_id].colnb
                                    +"&advise="+$p.app.banner.info.requested,
    					'alarm':false
    				}
    			);
		}
        $p.app.tabs.created[$p.app.tabs.sel]=false;
		$p.app.tabs.create($p.app.tabs.sel);
		$p.app.widgets.rss.pageUnread();
	},
	/*
		Function: submitNameChange
                                $p.app.tabs.submitNameChange 
                        
                                Format the new tab name

                    Parameters:

                                 v_input - text input object when tab name is typed
			 v_id - tab ID
             
                     Returns:
                     
                                 false
           */
	submitNameChange:function(v_input,v_id)
	{
		var l_name=$p.string.removeTags($p.string.removeCot(v_input.value));
		if(v_id == indef) {
			v_id = this.sel;
		}
		$p.app.tabs.rename(l_name,v_id);
		return false;
	},
	/*
		Function: initHeadMenu
                                $p.app.tabs.initHeadMenu 
                        
                                Generate tab menu

                    Parameters:

			v_obj - div object where menu is generated
			v_id - tab ID
           */
	initHeadMenu:function(v_obj,v_id)
	{
        var l_s="";
		if (v_obj==indef) {
			if ($("headmenu")!=null) {
                $p.app.tabs.showHeadMenu(false);
            }
        }
		else    {
            
			$p.app.tabs.currHeadLink=v_obj;			
			var l_top=($p.app.tabs.currHeadLink.getTop())+15;
			var l_left=($p.app.tabs.currHeadLink.getLeft())-3;
			var l_width=$p.app.tabs.currHeadLink.offsetWidth+6;

			$p.app.tabs.showHeadMenu(true);
			var l_obj=$("headmenu");
			l_obj.setStyle("top",l_top+"px");
			l_obj.setStyle("left",l_left+"px");

			for (var i=0;i<__headmenu[v_id]["options"].length;i++)
			{
				l_s += '<a href="#" onclick="$p.app.tabs.showHeadMenu(false);'
                   +__headmenu[v_id]["options"][i]["fct"]
                   +'" onmouseover="$p.app.tabs.showHeadMenu(true)" style="white-space: nowrap;height: 17px;">'
                   +(__headmenu[v_id]["options"][i]["images"]==""           
                                                                ?               ""
                                                                :               $p.img(__headmenu[v_id]["options"][i]["images"],false,false,"","imgmid")
                                                                +" ")
                   +lg(__headmenu[v_id]["options"][i]["label"])
                   +'</a>';
			}
			l_obj.set('html',l_s);
			l_obj.onmouseout=function(){$p.app.tabs.showHeadMenu(false);}
		}
	},
	/*
		Function: showHeadMenu
                                $p.app.tabs.showHeadMenu 
                        
                                Display tab menu

                    Parameters:

			v_show (boolean) - display the menu or not 
           */
	showHeadMenu:function(v_show)
	{	
		(v_show)    ?     $p.show("headmenu","block")
                    :     $p.show("headmenu","none"); 
	},
	/*
		Function: $p.app.tabs.moduleOver 
                                
                                Define tab behaviour when a module is over
                                
                                $p.app.tabs.overtabid = id of tab

                    Parameters:

			v_id - tab ID
           */
	moduleOver:function(v_id)
	{
		if (tab[v_id].type == 1 
            && __moveWidgetsInTabs
            && tab[v_id].controls == 'Y') {
    			var l_obj = $("tab"+v_id);
    			l_obj.setStyle("border","1px solid #ff0000");
                //define destination tab
    			$p.app.tabs.overtabid = v_id;
		}
	},
	/*
	         Function: $p.app.tabs.moduleOut
                        
                                Define tab behaviour when a module is no more over
                                
                                $p.app.tabs.overtabid = -1

                    Parameters:

			v_id - tab ID
           */
	moduleOut:function(v_id)
	{
		var l_obj=$("tab"+v_id);
		if (l_obj) {  l_obj.setStyle("border","0px");  }
		$p.app.tabs.overtabid=-1;
	},
	/*
	         Function: $p.app.tabs.moduleOutAll

                                Reset all tabs display
           */
	moduleOutAll:function()
	{
		for (var i=0;i<tab.length;i++)
        {
			$p.app.tabs.moduleOut(i);
		}
	},
	/*
		Function: $p.app.tabs.getId

                                Get tab sequence based on its ID
        
                    Parameters:

			 v_id - tab ID
             
                    Returns:
                    
                                the tab sequence
	*/
	getId:function(v_id)
	{
		for (var i = 0;i < tab.length;i++)
		{
            
			if (tab[i].id == v_id) { 
                return i; 
            }
		}
		return -1;
	},
	/*
		Function: $p.app.tabs.selectTab

                                Select a tab based on its ID (used in admininistration)
        
                    Parameters:

			 name - tab ID
			 tabs(array) - the array of tabs
             
                    See Also:
                    
                                tabs.inc.php
	*/
	selectTab:function(v_id,v_tabs)
	{
		this.sel = 0;
		if (v_tabs==indef) v_tabs = tabs;
        for (var i = 0;i < v_tabs.length;i++)
		{
			if (v_tabs[i].id == v_id)   {
				this.sel = i;
                return;
			}
		}
	},
	/*
		Function: selectTabByTitle
                                $p.app.tabs.selectTabByTitle
		
                                Select a tab based on its name
        
                    Parameters:

			 name - tab Name
			 tabs(array) - the array of tabs
             
                    See Also:
                    
                                tabs.inc.php
	*/
	// selectTabByTitle:function(name,v_tabs,v_temporary)
	// {
		// this.sel = 0;
        // if (v_temporary == indef) v_temporary = false;
		// if (v_tabs==indef) v_tabs=tab;
		// for (var i=0;i<v_tabs.length;i++)
		// {
			// if (v_tabs[i].label==name)
			// {
				// this.sel = i;
				// return i;
			// }
		// }
        // return;
	// },
	selectTabByTitle:function(name,v_tabs,v_temporary)
	{
		var l_tab = -1;
        if (v_temporary == indef) v_temporary = false;
		if (v_tabs == indef) v_tabs = tab;
        
		for (var i = 0;i < v_tabs.length;i++)
		{
			if (v_tabs[i].label == name && v_tabs[i].temporary == v_temporary)
			{
                return i;
			}
		}
        return l_tab;
	},
	/*
		Function: openTempLink
                                $p.app.tabs.openTempLink
		
                                Open a temporary tab iframe (URL)
        
                    Parameters:

			 v_title - tab title
			 v_url - url
             
	*/
	openTempLink:function(v_title,v_url)
	{
		$p.app.tabs.openTempTab(2,"$p.app.pages.frame('"+v_url+"',%tabid%)",v_title);
	},
	/*
		Function: openTempTab
                                $p.app.tabs.openTempTab
		
                                Open a temporary tab
        
                    Parameters:

			 v_type -type of the tab (customizable portal, frame, javascripf function)
			 v_action -action triggered when used click on the tab
			 v_title -title of the tab
			 v_icon -url of the icon of the tab
             v_openNow -define if the tab is open after display
	*/
	openTempTab: function(v_type,v_action,v_title,v_icon,v_openNow,v_removable)
	{
        if (v_removable == indef) v_removable = true;
        $p.app.tabs.openNewTab(v_type,v_action,v_title,v_icon,true,v_openNow,v_removable);
    },
    /*
		Function: openFixTab
                                $p.app.tabs.openFixTab
		
                                Open a normal tab
        
                    Parameters:

			 v_type -type of the tab (customizable portal, frame, javascripf function)
			 v_action -action triggered when used click on the tab
			 v_title -title of the tab
			 v_icon -url of the icon of the tab
             v_openNow -define if the tab is open after display
	*/
    openFixTab: function(v_type,v_action,v_title,v_icon,v_openNow)
	{
        $p.app.tabs.openNewTab(v_type,v_action,v_title,v_icon,false,v_openNow,false);
    },
    /*
            Fiunction: $p.app.tabs.openNewTab
    
    */
    openNewTab: function(v_type,v_action,v_title,v_icon,v_temporary,v_openNow,v_removable)
    {
		if (v_openNow == indef) v_openNow = true;
		if (v_openNow) $p.app.pages.hide();
        if (v_removable == indef) v_removable = true;
        
        // get current tab information
        var l_currentTabPos = $p.app.tabs.sel;
        var l_currentTabId = ($p.app.tabs.sel >= 0 ? tab[l_currentTabPos].id : indef);
        
		//select tab number
		var l_tab = $p.app.tabs.selectTabByTitle(v_title,indef,v_temporary);
		if (l_tab == -1) l_tab = 0;
        
        if (v_openNow) $p.app.tabs.sel = l_tab;
            
		//If a temporary tab with same name already exists :
		if (l_tab != 0 || (tab[l_tab].label == v_title && tab[l_tab].temporary))
		{
			l_idTab = tab[l_tab].id;
			// update tab URL
			tab[l_tab].fct = v_action.replace(/%tabid%/g,l_idTab);
			tab[l_tab].type = v_type;
			tab[l_tab].isLoaded = false;
		}
		else
		{
			//generate ID of new tab
			reset_rand();
			var l_idTab = rand + 10000000;
			//create a new tab
			tab.unshift(new $p.app.tabs.object(
                                                l_idTab,        //id of tab for a profile
                                                v_title,        //title
                                                v_type,         //type 1 to 5
                                                v_action.replace(/%tabid%/g,l_idTab), //linked function
                                                0,              //lock
                                                0,              //seq   position in sequence of the portal
                                                0,              //editable
                                                0,              //movable
                                                v_icon,             //icon
                                                0,               //loadstart
                                                indef,          //status
                                                indef,          //param
                                                indef,          //pageId
                                                v_removable,          //removable
                                                v_temporary,   //temporary
                                                indef
                                                )
                        );

            //default cellules for a temp tab
            tab[l_tab].cells = new Array();
            tab[l_tab].cells[1] = {
                nbWidgets:{
                    'nb':-1,
                    'max':1,
                    'byformat':{}
                }
            };
                        
            if (!v_openNow && l_currentTabId != indef)
            {
                // Search the current tab new position (due to tab adding).
                $p.app.tabs.sel = $p.app.tabs.idToPos(l_currentTabId);
            }
		}

		//open new tab
		tab[l_tab].temporary = v_temporary;
		tab[l_tab].icon = v_icon;

        if (v_openNow)
        {
            eval(v_action.replace(/%tabid%/g,l_idTab));
        }
        $p.app.tabs.created[$p.app.tabs.sel]=false;
        $p.app.tabs.select($p.app.tabs.sel,false);
	},
	/*
		Function: idToPos
                                $p.app.tabs.idToPos
		
                                Get tab sequence ID based on its DB ID
        
                    Parameters:

			 v_id - tab DB ID
             
                    Returns:
                    
                                tab sequence ID
	*/
	idToPos:function(v_id)
	{
		if (v_id==-1) {  return -1; }
		if (tab.length==1000) {   return 999;  }
		for (var i=0;i<tab.length;i++)
		{
			if (tab[i].id==v_id) {   return i;  }
		}
		return false;
	},
	/*
		Function: remove
                                $p.app.tabs.remove
		
                                Remove a tab
	*/
	remove:function(v_needConfirmation)
	{
		$p.app.pages.suppress($p.app.tabs.idToPos(this.id),indef,v_needConfirmation);
	},
	/*
		Function: maxId
                                $p.app.tabs.maxId
		
                                Get the maximum ID of all the tabs in tab[]
                                
                      Returns:
                      
                                Maximum ID
	*/
	maxId:function()
	{
		var maximumId=0;
		for (var i=0;i<tab.length;i++)
		{
			if (tab[i].id>maximumId && !tab[i].temporary) {
				maximumId=tab[i].id;
            }
		}
		return maximumId;
	},
	/*
		Function: detectModifiedTab
                                $p.app.tabs.detectModifiedTab
		
                                Change a tab status and display a message to warn the user.
                                
                      Parameters:
                      
                                v_id - id of the tab
	*/
	detectModifiedTab: function(v_id)
	{
        if ($p.app.user.type=="A" || tab[v_id].status==2) { return false; }
        switch (tab[v_id].status)
        {
            case 1:
                $p.app.alert.show(lg("tabAdded",tab[v_id].label));
                break;
            case 2:
                $p.app.alert.show(lg("tabModified",tab[v_id].label));
                break;
            default:
                return false;
                break;
        }
        
        //update the status of the tab in the database
        $p.ajax.call(posh["scr_changetabstatus"],
            {
                'type':'execute',
                'variables':"new=0&tabId="+tab[v_id].id
            }
        );
        //update status in the pages tab
        tab[v_id].status = 0;
	},
	/*
		Function: ckeckIfShared
                                $p.app.tabs.checkIfShared
		
                                Format the shared information to be usable in the javascript
                                
                      Parameters:
                      
                                v_shared : shared string
	*/
	checkIfShared:function(v_shared)
	{
		if (v_shared=="") return 0;
		if (v_shared.length > 1) return 4;
		return v_shared;
	},
	/*
		Function: getIdTabByName
                                $p.app.tabs.getIdTabByName
		
                                Get the id of the tab with the name passed in parameter
                                
                    Parameters:
                      
                                v_tabName : name tab string
                    Returns:
                    
                                v_tabId : tab ID
	*/
	getIdTabByName:function(v_tabName)
	{
		var v_tabId = 0;
		for( var i in tab) {
			if(tab[i].label != indef) {
				if( tab[i].label.toLowerCase().replace(/[^0-9a-zA-Z]/g,"") == v_tabName.toLowerCase() ) {
					v_tabId = i;
					break;
				}
			}
		}
		return v_tabId;
	},
	/*
		Function: getTabNameInUrl
                                $p.app.tabs.getTabNameInUrl
		
                                Get the tab name from the URL passed in parameter
                                
                    Parameters:
                      
                                v_url : page url
                    Returns:
                    
                                v_tabName : tab name
	*/
	getTabNameInUrl:function(v_url)
	{
		var v_tabName = v_url;
		
		if(v_url.substr(0,7)=='http://') {
			var reg = new RegExp(/^[\w]{2,6}:\/\/([\w\d\.\-]+).*$/);
			var m = reg.exec(v_url);
			if (m[1] != null) {
				v_tabName = m[1];
			}
		}
		v_tabName = v_tabName.replace("www.","").split(".")[0];

		return v_tabName;
	}
}


//************************************ TABS NAVIGATION FUNCTIONS ***************************************************************************************************************
/*
    Class: $p.app.tabs.nav
         Tabs navigation functions
*/
$p.app.tabs.nav={
	increment:2,
	timer:0,
	posx:0,
	movedObj:{},
	oversize:0,
	/*
		Function: init
                                $p.app.tabs.nav.init
                                
                                Init tabs navigation
	*/
	init: function()
	{
		this.timer = 0;
		
		this.movedObj = $('navmovebox');
		//reset position to previous one (in case of re-initialization)
		this.movedObj.setStyle("left",this.posx+"px");
		//content size is gotten with image size
		var navWidth = $p.app.tabs.nav.getNavigatorShownSize();
		var l_cntSize = $p.app.tabs.nav.getNavigatorTotalSize();

		this.oversize = l_cntSize - navWidth;
		//hide navigators button if useless
		if (this.posx > -1) ($("leftTabNav")).setStyle("visibility","hidden");
		if (this.oversize+this.posx <= 0) ($("rightTabNav")).setStyle("visibility","hidden");
	},
	getNavigatorShownSize: function()
	{
		var l_obj = $('navfloatbox');
		return (l_obj.offsetWidth     ?              l_obj.offsetWidth
											:       (l_obj.style.clip.width
												?       l_obj.style.clip.width
												:       0));
	},
	getNavigatorTotalSize:function()
	{
		return ($("navctlimg")).width;
	},
	/*
		Function:  left
                                $p.app.tabs.nav.left 
                                
                                Move tabs left
	*/
	left:function()
	{
		// if some tabs are hidden on the left
		if (this.posx < 0)
		{
			this.posx += this.increment;
			this.movedObj.setStyle("left",this.posx+"px");
			this.timer = setTimeout("$p.app.tabs.nav.left()",10);	
			($("rightTabNav")).setStyle("visibility","");
		}
		else
		{
			($("leftTabNav")).setStyle("visibility","hidden");
		}
	},
	/*
		Function:  jumpLeft
                                $p.app.tabs.nav.jumpLeft 
                                
                                Move tabs left (big move)
	*/
	jumpLeft:function()
	{
		//check if navigator is already on the right
		var centerPartSize = this.getNavigatorShownSize();
		if (this.posx < 0)
		{
			//check if the hidden left part is larger than the center part
			if (this.posx + centerPartSize > 0)
			{
				this.posx = 0;
				($("leftTabNav")).setStyle("visibility","hidden");
			}
			else
			{
				this.posx += centerPartSize;
			}
			
			this.movedObj.setStyle("left",this.posx+"px");
			($("rightTabNav")).setStyle("visibility","");
			$p.app.tabs.nav.stop();
		}
		else
		{
			($("leftTabNav")).setStyle("visibility","hidden");
		}
	},
	/*
		Function: right
                                $p.app.tabs.nav.right
                                
                                Move tabs right
	*/
	right: function()
	{
		if (this.posx + this.oversize > 0)
		{
			this.posx -= this.increment;
			this.movedObj.setStyle("left",this.posx+"px");
			this.timer = setTimeout("$p.app.tabs.nav.right()",10);	
			($("leftTabNav")).setStyle("visibility","");
		}
		else
		{
			($("rightTabNav")).setStyle("visibility","hidden");
		}
	},
	/*
		Function:  jumpRight
                                $p.app.tabs.nav.jumpRight 
                                
                                Move tabs right (big move)
	*/
	jumpRight: function()
	{
		//check if navigator is already on the left
		var rightPartSize = this.posx + this.oversize;
		var centerPartSize = this.getNavigatorShownSize();
		if (this.posx+this.oversize > 0)
		{
			//check if the hidden part on the right is bigger than the navigator size
			if (rightPartSize > centerPartSize)
			{
				this.posx -= centerPartSize;
			}
			else
			{
				this.posx -= rightPartSize;
				($("rightTabNav")).setStyle("visibility","hidden");
			}
			this.movedObj.setStyle("left",this.posx+"px");
			($("leftTabNav")).setStyle("visibility","");
			$p.app.tabs.nav.stop();
		}
		else
		{
			($("rightTabNav")).setStyle("visibility","hidden");
		}
	},
	/*
		Function: 
                                $p.app.tabs.nav.stop
                                
                                Stop moving tabs
	*/
	stop: function()
	{
		clearTimer(this.timer);
	}
}



//************************************ PERSONALIZED PAGES FUNCTIONS ***************************************************************************************************************
/*
    Class: $p.app.pages
    
         Personalized pages functions
*/
$p.app.pages={
	def:"N",
    tabId:0,
	lockPage:0,
	sharedTab:[],
	pagesModel:[],
	templates:
		[
			{'id':'simple','nbCells':3,'nbCols':3,'nbRows':1,'nbColsMin':'1','image':'template_simple.png','addCols':true,'rows':
				[
					{'cols':
						[
							{'id':'cell1','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell2','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell3','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false}
						]
					}
				]
			},
			{'id':'newspaper','nbCells':3,'nbCols':2,'nbRows':2,'nbColsMin':'2','image':'template_newspaper.png','addCols':true,'rows':
				[
					{'cols':
						[
							{'id':'cell1','maxWidgets':0,'colspan':2,'rowspan':1,'blocked':false}
						]
					},
					{'cols':
						[
							{'id':'cell2','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell3','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false}
						]
					}
				]
			},
			{'id':'newspaper_reversed','nbCells':3,'nbCols':2,'nbRows':2,'nbColsMin':'2','image':'template_newspaper_reversed.png','addCols':true,'rows':
				[
					{'cols':
						[
							{'id':'cell1','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell2','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false}
						]
					},
					{'cols':
						[
							{'id':'cell3','maxWidgets':0,'colspan':2,'rowspan':1,'blocked':false}
						]
					}
				]
			},
			{'id':'banner','nbCells':4,'nbCols':3,'nbRows':2,'nbColsMin':'3','image':'template_banner.png','addCols':true,'rows':
				[
					{'cols':
						[
							{'id':'cell1','maxWidgets':0,'colspan':3,'rowspan':1,'blocked':false}
						]
					},
					{'cols':
						[
							{'id':'cell2','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell3','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell4','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false}
						]
					}
				]
			},
			{'id':'banner_reversed','nbCells':4,'nbCols':3,'nbRows':2,'nbColsMin':'3','image':'template_banner_reversed.png','addCols':true,'rows':
				[
					{'cols':
						[
							{'id':'cell1','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell2','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell3','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false}
						]
					},
					{'cols':
						[
							{'id':'cell4','maxWidgets':0,'colspan':3,'rowspan':1,'blocked':false}
						]
					}
				]
			},
			{'id':'skycraper','nbCells':4,'nbCols':3,'nbRows':2,'nbColsMin':'3','image':'template_skycraper.png','addCols':true,'rows':
				[
					{'cols':
						[
							{'id':'cell1','maxWidgets':0,'colspan':1,'rowspan':2,'blocked':false},
							{'id':'cell2','maxWidgets':0,'colspan':2,'rowspan':1,'blocked':false}
						]
					},
					{'cols':
						[
							{'id':'cell3','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell4','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false}
						]
					}
				]
			},
			{'id':'skycraper_reversed','nbCells':4,'nbCols':3,'nbRows':2,'nbColsMin':'3','image':'template_skycraper_reversed.png','addCols':true,'rows':
				[
					{'cols':
						[
							{'id':'cell1','maxWidgets':0,'colspan':1,'rowspan':2,'blocked':false},
							{'id':'cell2','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell3','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false}
						]
					},
					{'cols':
						[
							{'id':'cell4','maxWidgets':0,'colspan':2,'rowspan':1,'blocked':false}
						]
					}
				]
			},
			{'id':'retro','nbCells':4,'nbCols':3,'nbRows':2,'nbColsMin':'3','image':'template_retro.png','addCols':true,'rows':
				[
					{'cols':
						[
							{'id':'cell1','maxWidgets':0,'colspan':2,'rowspan':1,'blocked':false},
							{'id':'cell2','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false}
						]
					},
					{'cols':
						[
							{'id':'cell3','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell4','maxWidgets':0,'colspan':2,'rowspan':1,'blocked':false}
						]
					}
				]
			},
			{'id':'retro_reversed','nbCells':4,'nbCols':3,'nbRows':2,'nbColsMin':'3','image':'template_retro_reversed.png','addCols':true,'rows':
				[
					{'cols':
						[
							{'id':'cell1','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false},
							{'id':'cell2','maxWidgets':0,'colspan':2,'rowspan':1,'blocked':false}
						]
					},
					{'cols':
						[
							{'id':'cell3','maxWidgets':0,'colspan':2,'rowspan':1,'blocked':false},
							{'id':'cell4','maxWidgets':0,'colspan':1,'rowspan':1,'blocked':false}
						]
					}
				]
			}
		],
	// /*
		// Function: $p.app.pages.initMenu
       
            // Init the pages menu
            
            
	// */
	// initMenu:function()
	// {
		// $p.app.menu.options.push(
			// {
				// 'id':'poptions',
				// 'label':lg('options'),
				// 'desc':lg('portalIconDesc'),
				// 'icon':'ico_custompage.gif',
				// 'seq':65,
				// 'action':'',
				// 'type':'',
				// 'opened':true,
				// 'default_opened':true,
				// 'subOptions':[
					// {
						// 'id':'confmenu_1',
						// 'label':lg("optionsOfThisPage"),
						// 'action':$p.app.menu.config.open,
						// 'condition':$p.app.menu.config.isPageOptionsDisplayed,
						// 'opened':false,
						// 'type':'link'
					// },
					// {
						// 'id':'confmenu_2',
						// 'label':lg("optionsOfThePortal"),
						// 'action':$p.app.menu.config.buildGeneralOptions,
						// 'condition':$p.app.menu.config.isGeneralOptionsDisplayed,
						// 'opened':false
					// }
				// ]
			// }
        // );
	// },
	/*
		Function: $p.app.pages.change 
                                
                                Open a page
                                
                                - Hook : app.pages.change.start
                                - Display "modules" block
                                - set cookie for selected page
                                - if page has been already loaded, display
                                - if not, load widgets with <$p.app.pages.open>
		
                    Parameters:

			v_prof - tab ID
			v_action - action to launch on page opening
	*/
	change: function(v_prof,v_action)
	{
		$p.plugin.hook.launch('app.pages.change.start');

        //hide the current page 
		$p.app.pages.hide();
        $p.app.menu.hideControl();
		$p.app.pages.closeAllDiv();
		$p.show("modules","block");

		//select the new tab
		$p.app.tabs.selId = v_prof;
		if (tab.length == 0) return;

		if (v_prof != indef)
        {
            $p.app.tabs.sel = $p.app.tabs.getId(v_prof);
            if ($p.app.tabs.sel == -1) $p.app.tabs.sel = 0;
        }
      //  if (!$p.app.tabs.created[$p.app.tabs.sel]) {
            $p.app.tabs.create($p.app.tabs.sel);
      //  }
		//if ($p.app.tabs.sel==indef || $p.app.tabs.sel==-1 || $p.app.tabs.sel>tab.length) $p.app.tabs.sel=$p.app.tabs.getId(v_prof);
        //double check, in case the profile save in cookie is linked to a non existent tab (switch from an account to another)
		v_prof = tab[$p.app.tabs.sel].id; 
		//set the current page as default

		$p.app.setState("$p.app.pages.change("+v_prof+")");
		//$p.app.pages.clean($("modules")); //suppressed with 1.4 because no tabs erase if other items open => hide
		//load page only if not already loaded

        if (tab[$p.app.tabs.sel].isLoaded != indef)   {
			if (tab[$p.app.tabs.sel].style != $p.app.style)
				$p.styles.setActiveStyleSheet(tab[$p.app.tabs.sel].style);
			//if ($p.app.menu.config.oldStyle!=tab[$p.app.tabs.sel].style) setActiveStyleSheet(tab[$p.app.tabs.sel].style);
			$p.show("modules"+tab[$p.app.tabs.sel].id,"block");
            $p.app.pages.refreshWidgetsNotLoaded();
		}
		else if (tab[$p.app.tabs.sel].module.length > 0 && $p.app.user.id == 0) {
			// if the tab is loaded but not displayed (in anonymous mode, all the tabs are loaded on the start of the application)
            $p.app.pages.init($p.app.tabs.sel);
            if (tab[$p.app.tabs.sel].style != $p.app.style)
                $p.styles.setActiveStyleSheet(tab[$p.app.tabs.sel].style);
		}
		else {
            //reload widgets from database
            $p.app.pages.open(v_action);
        }
		
		// display menu control if page is not blocked
        if (tab[$p.app.tabs.sel].controls == 'Y') $p.app.menu.displayControl();
			
		if ($p.app.user.id > 0) {
            $p.app.pages.setCurrent(v_prof);
        }

		//activate menus
		$p.app.menu.widget.locked = false;
		$p.app.newEnv(($p.app.user.id==0) ? 'portal_page_anon' : 'portal_page_conn');

		//define widget place
		$p.app.widgets.place();
		$p.app.pages.computeFooterPosition();

        //refresh menu based on new page
        $p.app.menu.refreshConditionalMenus();

		$p.plugin.hook.launch('app.pages.change.end');
	},
	/*
		Function: redirect
                                $p.app.pages.redirect 
                                
                                Open a redirection page
		
                    Parameters:

			v_url - url of the page
			v_id - tab ID
	*/
	redirect:function(v_url,v_id)
    {
        $p.show("footer","none");
		//$p.app.banner.option.hide();
		$p.show("box","none");
		$p.app.pages.closeAllDiv();
		$p.show("modules","block");
		$p.app.popup.hide();
		$p.app.newEnv('portal_frame');
        
		var l_tab=$p.app.tabs.idToPos(v_id);
        window.open(v_url);

		//lock menus
		$p.app.menu.widget.locked = true;
		//$p.app.tabs.selId=tab[$p.app.tabs.sel].id;
		$p.app.tabs.selId = v_id;
		$p.app.pages.computeFooterPosition();
		//apply style
		$p.styles.checkTabAndSetActiveStyleSheet(l_tab);
        //refresh menu based on new page
        $p.app.menu.refreshConditionalMenus();
    },    
	/*
		Function: $p.app.pages.openCreatedTab
                      
                                Open a new tab
                                
                                Push a new page in tab object
		
                    Parameters:

			v_prof - 0   if it's a new empty page, otherwise contains the url of the page
            
                    Returns:
                    
                                false
                                
        See also:

            <$p.app.pages.newEmpty>, <$p.app.pages.createFromXml>
	*/
	openCreatedTab: function(v_prof,v_param)
	{
		$p.plugin.hook.launch('app.pages.opencreatedtab.start');
		var status = 0;
		var pageformid = v_prof;
		if(v_param)
			status = (v_param['status'] || 0);
			
		//in anonymous portail
		if ($p.app.user.id == 0)
		{
			var lastTabNumber = $p.app.tabs.maxId() + 1,
                lastTabSeq = tab[tab.length-1].seq + 1;
			$p.app.pages.setCurrent(0);
			$p.app.pages.hide();
            
			//if the user created a new empty page
            var l_name = (v_param['pagename'] ? v_param['pagename'] : lg("lblNewpage"));

			if (v_prof == 0)
            {
				tab.push(new $p.app.tabs.object(lastTabNumber,  //id
                                                l_name,     //label
                                                1,          //type
                                                "$p.app.pages.change("+lastTabNumber+")",   //function
                                                0,              //lock
                                                lastTabSeq,     //seq in page
                                                1,                  //editable
                                                1,                  //movable
                                                "",                 //icon
                                                0,                  //loadstart
                                                0,                  //status
                                                "",                 //param
                                                0,                  //pageid
                                                1,                  //removable
                                                indef               //temporary
                                                )
                                                );
				$p.app.tabs.sel = tab.length - 1;
				tab[$p.app.tabs.sel].isLoaded = true;
				$p.app.pages.init();
				v_prof = tab.length ;//+ 1;
				
				// display help message
				$p.app.help.displayNewPortalMessage('message');
			}
			//if the user add a new HTML page v_prof is the url to open in new page
			else
            {
				tab.push(new $p.app.tabs.object(
                                                lastTabNumber, //uniq id of tab
                                                l_name,         //label
                                                2,              //type of tabs
                                                "$p.app.pages.frame('"+v_prof+"',"+lastTabNumber+")", //function to call
                                                0,              //locked or not
                                                lastTabSeq,     //tab sequence
                                                1,              //tab editable or not
                                                1,              //tab movable or not
                                                "",             //icon displayed in tab
                                                0,              //status new page or not
                                                0,              //load start
                                                v_prof,         //page id
                                                0,              //tab is removable
                                                1               //tab temporrary or not
                                                ));
				$p.app.tabs.sel = tab.length - 1;
				            //default cellules for a temp tab
            tab[$p.app.tabs.sel].cells = new Array();
			tab[$p.app.tabs.sel].cells[0] = {
                obj:{
				'childNodes':1
                   }
            };
            tab[$p.app.tabs.sel].cells[1] = {
                nbWidgets:{
                    'nb':-1,
                    'max':1,
                    'byformat':{}
                }
            };
				$p.app.pages.init();
				$p.app.pages.frame(v_prof,lastTabNumber);
				v_prof = tab.length;
			}
			pageformid = tab[$p.app.tabs.sel].id;
		}
		//in connected mode
		else
        {
			if (v_prof != $p.app.tabs.selId)  {
				$p.app.pages.setCurrent(v_prof);
				$p.app.pages.hide();
			}
			$p.app.tabs.sel = 999;
			$p.app.loadTabs(v_prof,indef,"",status);
			pageformid = v_prof;
		}
		$p.plugin.hook.launch('app.pages.opencreatedtab.end');
		if(status == 2) {
			$p.app.pages.createPageForm(pageformid);
		}
	},
	/*
		Function:  $p.app.pages.open
                                
                                Load page information 
                                - posh["xmlmodules"] if connected
                                - selections/page<page id>.xml
                                - xml response -> v_action
                     Parameters: 
                     
                                v_action - ???
                                
                      See also:
                            - <$p.app.pages.unlock>
                            - <$p.app.pages.lock>
                            - <$p.app.pages.change>
                            
                            
	*/
	open: function(v_action)
	{
		if(v_action == 1) {
			$p.app.pages.lockPage=0;
		}

		tab[$p.app.tabs.sel].isLoaded = false;
		//	$p.app.startLoading(); suppressed on 1.4.2, no need when switch from a page to another
		if ($("modules"+tab[$p.app.tabs.sel].id) != null)
		{
			$p.app.pages.clean($("modules"+tab[$p.app.tabs.sel].id));
			$p.show("modules"+tab[$p.app.tabs.sel].id,"block");
		}
        
		if ($p.app.user.id == 0 
            || tab[$p.app.tabs.sel].id == 0 
            || tab[$p.app.tabs.sel].id >= 1000000000) {
                $p.app.pages.init($p.app.tabs.sel);
        }
		else if ($p.app.tabs.selId != 0)
        {
			$p.app.pages.load(posh["xmlmodules"],"id="+tab[$p.app.tabs.sel].id,indef,v_action);
        }
		$p.show('vmenu','block');
		
		if( tab[$p.app.tabs.sel].status==2) {
		
		//	$p.app.pages.createPageForm(tab[$p.app.tabs.sel].id);
			$p.show("pageform"+tab[$p.app.tabs.sel].id,"block");
			//hide help message
			$p.show('message','none');
			// hide menu
			$p.show('vmenu','none');
		}
	},
	/*
		Function:  summary
                                $p.app.pages.summary 
                                
                                Summary of the page articles in the main portal enterprise page
                                
                                Set within the installation of portaneo, see adm_config
                                parameters are set in install/createdb_5_pee_mysql.sql
                                
                                see $p.app.displayfeaturedHome about displaying this summary
                                
                                Others possible items come from application.js (network articles)
                                
                     Parameters: 
                     
                                v_div - element to display the summary 
                                
                      See Also:
                            
                            <$p.app.displayfeaturedHome>,<summaryLoad>
	*/
	summary: function(v_div)
	{ 
		var l_s = '<div id="' + v_div + 'header"></div>'
			+ '<div id="' + v_div + 'content"></div>';

        $p.print(v_div, l_s);
		
		$p.app.pages.displaySummaryMenu('latestArticlesOfMyPages', v_div);

		$p.app.pages.summaryLoad(0, indef, v_div);
	},
	displaySummaryMenu: function(v_type, v_div)
    {
        var l_s =  $p.html.buildTitle(lg(''),
            (v_type == 'latestArticlesOfMyPages' ? '' : '<a href="#" onclick=\'$p.app.pages.summaryLoad(0,indef,"' + v_div + '");return false;\'>')
            + lg('latestArticlesOfMyPages')
            + (v_type == 'latestArticlesOfMyPages' ? '' : '</a>')
            + ' | '
            + (v_type == 'mostReadArticles' ? '' : '<a href="#" onclick=\'$p.app.statistics.loadMostRead(0,"' + v_div + '");return false;\'>')
            + lg('mostReadArticles')
            + (v_type == 'mostReadArticles' ? '' : '</a>')
            );

        $p.print(v_div + 'header',l_s);
    },
	/*
		Function: initSummary
                                $p.app.pages.initSummary 
                                
                                Init the summary of the page articles
	*/
	initSummary:function()
	{
		$p.article.init();
		$p.print($p.article.contentDiv,$p.html.buildTitle(lg('latestArticlesOfMyPages'))+'<div id="featsummarypages"></div>');

		$p.app.pages.summaryLoad(0,indef,'featsummarypages');
	},
	/*
		Function:  summaryLoad
                                $p.app.pages.summaryLoad 
                                
                                 Load the summary pages from database
                                
                     Parameters: 
                     
                                v_page - number of results per page
                                v_filter - user id filter
			v_div - Div ID to place the results on
	*/
	summaryLoad:function(v_page,v_filter,v_div)
	{
		if (v_filter==indef) v_filter=0;
		
		$p.app.pages.displaySummaryMenu('latestArticlesOfMyPages', v_div);
		
		$p.ajax.call(posh["xmlpages_latestnews"]+'?p='+v_page+'&f='+v_filter,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.pages.summaryDisplay,
					'variables':
					{
						'page':v_page,
						'filter':v_filter,
						'div':v_div
					}
				}
			}
		);
	},
	/*
		Function:  summaryDisplay
                                $p.app.pages.summaryDisplay 
                                
                                 Display the summary pages
                                
                     Parameters: 
                     
                                response - xml response
                                vars (array) - variables
	*/
	summaryDisplay:function(response,vars)
	{ 
        //filters
		var l_s = '<p class="linkFilter">'
				+ $p.app.pages.addLinktoReloadAllNews(vars)
        //and rest of filters by page, see array tab in $p.app.tabs
				+ $p.app.pages.LinkstoNewsbyPages(vars)
				+ '</p>';
        //end filters
        //larticles list
        var l_result = response.getElementsByTagName('article');
		l_s += '<div>';
            
        l_s += $p.app.pages.displayListArticles(l_result);
        
		l_s += '</div>';

        //next and previous button
		l_s +='<div style="text-align: right">';
            
        var l_max = response.getElementsByTagName('total');
		var max = $p.ajax.getVal(l_max[0],'max','str',false,'#');    
            
		if (vars['page'] != 0) {
            l_s += $p.app.tools.buildPreviousLinkIcon('$p.app.pages.summaryLoad('+
                                                        (vars['page']-1)
                                                        +','
                                                        +vars['filter'] 
                                                        +',"'
                                                        +vars['div']
                                                        +'")');
		}
        l_s += " &nbsp; ";
        if (    l_result.length == 10
                && (max != (vars['page']+1)*10)
            ) {
                l_s += $p.app.tools.buildNextLinkIcon('$p.app.pages.summaryLoad('+
                                                        (vars['page']+1)
                                                        +','
                                                        +vars['filter'] 
                                                        +',"'
                                                        +vars['div']
                                                        +'")');
        }
		l_s += '</div>';
        //end next and previous button
        
		$p.print(vars['div'] + 'content',l_s);
	},
	//ancre4
	/*
		Function:  summary
                                $p.app.pages.unrated
                                
                                Summary of the unrated page articles in the main portal enterprise page
                                
                     Parameters: 
                     
                                v_div - element to display the summary 
                                
                      See Also:
                            
                            <unratedLoad>
	*/
	unrated:function(v_div)
	{
		if (__useRating)
		{
		var l_s = '<h2>'+$p.img('ico_rss.gif',16,16,'','imgmid')+' '+lg('unratedArticlesOfMyPages')+'</h2><br />'
				+'<div id="homeunratedpages"></div>';

		$p.print(v_div,l_s);

		$p.app.pages.unratedLoad(0,indef,'homeunratedpages');
		}
	},
	/*
		Function:  unratedLoad
                                $p.app.pages.unratedLoad 
                                
                                 Load the unrated summary pages from database
                                
                     Parameters: 
                     
                                v_page - number of results per page
                                v_filter - user id filter
			v_div - Div ID to place the results on
	*/
	unratedLoad:function(v_page,v_filter,v_div)
	{
		if (v_filter==indef) v_filter=0;
		$p.ajax.call(posh["xmlpages_unratedarticles"]+'?p='+v_page+'&f='+v_filter,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.pages.unratedDisplay,
					'variables':
					{
						'page':v_page,
						'filter':v_filter,
						'div':v_div
					}
				}
			}
		);
	},
	/*
                Function: addLinkToReloadAllUnrated
                
                            $p.app.pages.addLinkToReloadAllUnrated
                            
                            addlink to reload all unrated news
                 
                 Parameters:
                 
                            vars - array containing vars['filter']
                            
                  Returns: HTML     

                    See Also:
                    
                            <unratedDisplay>
        */
	addLinkToReloadAllUnrated: function(vars)
    { 
        if ( vars['filter'] == 0  ) { 
            return  lg('all') + '&nbsp;';
        }
        return '<a href="#" onclick=\'$p.app.pages.unratedLoad(0,0,"'+vars['div']+'");return false;\'>'+lg('all')+'</a>&nbsp;';      
    },
	/*
                    Function: LinksToUnratedByPages
                    
                                $p.app.pages.LinksToUnratedByPages
                     
                                 build list of links from list of tabs existing in the personal portal
                                 
                                 take datas from array tab (see $p.app.tabs)

                     Parameters:
                 
                            vars - array containing vars['filter']

                     Returns : HTML
 
                    See Also:
                    
                            <unratedDisplay>
              */
	linksToUnratedByPages: function(vars) 
	{
        var l_s = '';
        //tab is array of tabs (see $p.app.tabs)
		for (var i=0;i<tab.length;i++)
		{
			if (tab[i].type==1)
			{
				if (tab[i].id == vars['filter'])  { 
                    l_s += tab[i].label+' &nbsp; '; 
                }
				else    {   
                    l_s += '<a href="#" onclick=\'$p.app.pages.unratedLoad(0,'+tab[i].id+',"'+vars['div']+'");return false;\'>'+tab[i].label+'</a> &nbsp; ';
                }
            }
		}
        return l_s;
    },
	    /*
                Function: displayUnratedListArticles
                
                                $p.app.pages.displayUnratedListArticles
                                
                                display unrated list articles in rss feed
            
                parameters:
                
                            l_result - result from response in summaryDisplay function
                            
                Returns: HTML

                See Also:
                
                            <unratedDisplay>
                
        */
	displayUnratedListArticles: function(l_result) 
	{
        if (l_result.length==0) 
        { 
            return (lg('lblArchEmpty'));
        }
        var l_s='';
		for (var i=0;i<l_result.length;i++)
		{
			var l_id = $p.ajax.getVal(l_result[i],'id','int',false,0);
			var l_modId = $p.ajax.getVal(l_result[i],'mod_id','int',false,0); 
			var v_tab = $p.ajax.getVal(l_result[i],'tab_id','int',false,0);
			var uniq = $p.ajax.getVal(l_result[i],'uniq','int',false,0); 
			l_s	+= 	'<tr>'
				+	'<td valign="top">'
				+  	$p.img($p.ajax.getVal(l_result[i],'icon','str',false,0),16,16,'','imgmid')
				+  	'</td>'
				+  	'<td valign="top">'
				+  	'<a href="'+$p.ajax.getVal(l_result[i],'link','str',false,'#')
				+ 	'" target="_blank" onclick="$p.app.widgets.rss.saveReadStatus('+l_id+');">'
				+  	$p.ajax.getVal(l_result[i],'title','str',false,'???')
				+ 	'</a>'
				+ 	'<br /><span color="#c6c3c6">'
				+	$p.ajax.getVal(l_result[i],'feed','str',false,'???')
				+	'<span>'
			if (__useRating)
			{ var source = "home";
				$p.app.widgets.rss.loadRating(l_id,uniq-1,'indef',source);  
				$p.app.widgets.rss.loadAverageRating(l_id,uniq-1,'indef',source);
				l_s += 	'<div id="user_rating_home_'+(uniq-1)+'_'+l_id+'"></div>'
					+	'<div id="average_rating_home_'+(uniq-1)+'_'+l_id+'"></div>'
			}
			l_s += '</td>'
				+'</tr>';
		}//ancre5
        return (l_s);
    },
	/*
		Function: unratedDisplay
                                $p.app.pages.unratedDisplay 
                                
                                 Display the unrated pages
                                
                     Parameters: 
                     
                                response - xml response
                                vars (array) - variables
	*/
	unratedDisplay:function(response,vars)
	{
	        //filters
		var l_s = '<p class="linkFilter">';
		l_s += $p.app.pages.addLinkToReloadAllUnrated(vars);
        //and rest of filters by page, see array tab in $p.app.tabs
        l_s += $p.app.pages.linksToUnratedByPages(vars);
        //end filters
        //larticles list
		var l_result = response.getElementsByTagName('article');
		l_s += '<p><div id="unratedportalnews">'
			+ '<table>';
        
        l_s += $p.app.pages.displayUnratedListArticles(l_result);
		
		l_s += '</table>'
			+ '</div>';
                
        //next and previous button
		l_s +='<div style="text-align: right">';
           
        var l_max = response.getElementsByTagName('total');
		var max = $p.ajax.getVal(l_max[0],'max','str',false,'#');    
            
		if (vars['page'] != 0) {
            l_s += $p.app.tools.buildPreviousLinkIcon('$p.app.pages.unratedLoad('+
                                                        (vars['page']-1)
                                                        +','
                                                        +vars['filter'] 
                                                        +',"'
                                                        +vars['div']
                                                        +'")');
		}
		
        l_s += " &nbsp; ";
        if (    l_result.length == 10
                && (max != (vars['page']+1)*10)
            ) {
                l_s += $p.app.tools.buildNextLinkIcon('$p.app.pages.unratedLoad('+
                                                        (vars['page']+1)
                                                        +','
                                                        +vars['filter'] 
                                                        +',"'
                                                        +vars['div']
                                                        +'")');
        }
		l_s += '</div>';
        //end next and previous button
        
		$p.print(vars['div'],l_s);
	},
    /*
                Function: displayListArticles
                
                                $p.app.pages.displayListArticles
                                
                                display list articles in rss feed
            
                parameters:
                
                            l_result - result from response in summaryDisplay function
                            
                Returns: HTML

                See Also:
                
                            <summaryDisplay>
                
        */
    displayListArticles: function (l_result) 
	{
        if (l_result.length==0) 
        { 
            return lg('noArticleInRssFeeds');
        }
        var l_s='';
        //$p.img('../modules/pictures/rss'+$p.ajax.getVal(l_result[i],'feedid','int',false,0)+'.ico',16,16,'','imgmid')
        
		var iconpath = "../modules/pictures/rss.gif";
        
        //icon rss problem
		for (var i=0;i<l_result.length;i++)
		{
            var feedid = $p.ajax.getVal(l_result[i],'feedid','str',false,'');
            var iconid = $p.ajax.getVal(l_result[i],'iconid','str',false,'');
			var l_id=$p.ajax.getVal(l_result[i],'id','int',false,0);
            if (iconid=='') {
                iconpath = "../modules/pictures/rss"+feedid+".ico";
            } else {
                iconpath = iconid;
            }
			l_s += '<div class="homeitem">'
                + '<div style="float: left;padding-right: 5px;">'
				+ $p.img(iconpath,16,16,'','imgmid')
                + '</div>'
                + ' <span color="#c6c3c6">'+$p.ajax.getVal(l_result[i],'feed','str',false,'???')+'</span>  | '
				+ '<a href="'+$p.ajax.getVal(l_result[i],'link','str',false,'#')+'" target="_blank" onclick="$p.app.widgets.rss.saveReadStatus('+l_id+');">'+$p.ajax.getVal(l_result[i],'title','str',false,'???')+'</a>'
				
				+ '</div>';
		}

        return (l_s);
    },
    /*
                Function: addLinktoReloadAllNews
                
                            $p.app.pages.addLinktoReloadAllNews
                            
                            addlink to reload all news
                 
                 Parameters:
                 
                            vars - array containing vars['filter']
                            
                  Returns: HTML     

                    See Also:
                    
                            <summaryDisplay>
        */
    addLinktoReloadAllNews: function(vars)
    {
        if ( vars['filter'] == 0  ) { 
            return  lg('all') + '&nbsp;';
        }
        return '<a href="#" onclick=\'$p.app.pages.summaryLoad(0,0,"'+vars['div']+'");return false;\'>' + lg('all') + '</a>&nbsp;';
    },
    /*
                    Function: LinkstoNewsbyPages
                    
                                $p.app.pages.LinkstoNewsbyPages
                     
                                 build list of links from list of tabs existing in the personal portal
                                 
                                 take datas from array tab (see $p.app.tabs)

                     Parameters:
                 
                            vars - array containing vars['filter']

                     Returns : HTML
 
                    See Also:
                    
                            <summaryDisplay>
              */
    LinkstoNewsbyPages: function (vars)
    {
        var l_s = '';
        //tab is array of tabs (see $p.app.tabs)
		for (var i = 0;i < tab.length;i++)
		{
			if (tab[i].type == 1)
			{
				if (tab[i].id == vars['filter'])  { 
                    l_s += (tab[i].icon == '' ? '' : $p.img(tab[i].icon,16,16,indef,'imgmid')+' ')
                        + tab[i].label
                        +' &nbsp; '; 
                }
				else    {   
                    l_s += '<a href="#" onclick=\'$p.app.pages.summaryLoad(0,'+tab[i].id+',"'+vars['div']+'");return false;\'>'
                        + (tab[i].icon == '' ? '' : $p.img(tab[i].icon,16,16,indef,'imgmid')+' ')
                        + tab[i].label
                        + '</a> &nbsp; ';
                }
            }
		}
        return l_s;
    },
	/*
		Function: setCurrent
                                $p.app.pages.setCurrent
                                
                                Set current tab as the default one (write in cookie)
		
                     Parameters:

			 v_prof - tab ID
	*/
	setCurrent:function(v_prof)
	{
		v_prof = v_prof.toInt();
		$p.app.tabs.selId = v_prof;
		$p.cookie.write("currentpage="+v_prof);
	},
	/*
		Function: $p.app.pages.loadOnStart     
                               
                               Load the pages defined by user on startup
                               And for each page load widgets
	*/
	loadOnStart:function()
	{   
		for (var i=0;i<tab.length;i++)
		{
			if (tab[i].loadstart==1 
                && tab[i].id!=$p.app.tabs.selId 
                && tab[i].isLoaded==indef) {
                    $p.app.pages.load(posh["xmlmodules"],"id="+tab[i].id,i);
            }
		}
	},
	/*
		Function: searchSharedPages
                                $p.app.pages.searchSharedPages 
                                
                                open popup to search a shared page
                                
                                Open a popup
           */
    searchSharedPages:function() {
        var l_options = [];
		var l_s = '<form name="newpage" onsubmit="$p.app.pages.newPortalCreation(this);return false;">'
                + '<table width="450" cellspacing="0" cellpadding="3">';
                
		if ($p.app.user.type != 'N') { 
			l_options.push($p.app.pages.displayFormtoFindSharePages());
        }
        
        l_s += '<tr bgcolor="#efefef">'+ l_options[0]+ '</tr>';
		l_s += '</table>'
            + '<br /><br />'
            + '</form>';

		$p.app.popup.show(l_s,470,indef,'');

		//$p.plugin.hook.launch('app.pages.newPortal.end');        
    },
	/*
		Function: newPortal
                                $p.app.pages.newPortal 
                                
                                open popup to create a new page in the portal
                                
                                 Open a popup
                                 
                                 called from $p.app.tabs.newPageLink
	
                    See Also:
                            
                            <displayFormtoGetPageFromURL>,<displaySharingForm>,<$p.app.tabs.newPageLink>
            */
	/*newPortal:function()
	{
		$p.plugin.hook.launch('app.pages.newPortal.start');

        var l_options = [];

		var l_s = '<form name="newpage" onsubmit="$p.app.pages.newPortalCreation(this);return false;">'
            + '<h2>' + lg('definePageTitle') + '</h2>'
            + '<input type="text" name="pagetitle" class="thinbox" size="50" maxlength="50" /><br /><br />'
            + '<h2>' + lg('definePageType') + '</h2>'
			+ '<table width="450" cellspacing="0" cellpadding="3">';

        l_options.push('<td align="center" width="30"><input type="radio" name="pagetype" value="empty" checked="checked" /></td>'
			+ '<td width="50">' + $p.img('page_blank.gif',34,41,'','imgmid') + '</td>'
			+ '<td><b>' + lg('lblNewEmpty') + '</b></td>');
        
		if ($p.app.user.type != 'N') { 
			l_options.push($p.app.pages.displayFormtoFindSharePages());
        }
        l_options.push($p.app.pages.displayFormtoGetPageFromURL());
        
		if (__displayPublicPages 
            && $p.app.user.id > 0 && $p.app.user.type != 'N') { 
			l_options.push('<td align="center"><input type="radio" name="pagetype" value="selection" /></td>'
				+ '<td>' + $p.img('page_favorite.gif',34,41,'','imgmid') + '</td>'
				+ '<td>'
                + '<b>' + lg('pageSelection') + '</b><br />'
                + '<div id="publicpages" style="padding: 4px;">Loading ...</div>'
                + '<input type="hidden" name="selectionid" value="none"/>'
                + '</td>');
        }
        
        var l_background='#ffffff';
        
        for (var i = 0; i < l_options.length; i++)
        {
            if (l_options[i] != '')
            {
                l_background = (l_background == '#ffffff')
                                ?'#efefef'
                                :'#ffffff';
                l_s += '<tr bgcolor="'+l_background+'"">'
                    + l_options[i]
                    + '</tr>';
            }
        }

		l_s += '</table>'
            + '<br /><br />'
            + '<center><input type="submit" value="' + lg('lblNewTit') + '" class="btn" /></center>'
            + '</form>';

		$p.app.popup.show(l_s,470,indef,'');

		if (__displayPublicPages 
            && $p.app.user.id > 0) {
                $p.app.pages.loadPublicPages();
        }	

		$p.plugin.hook.launch('app.pages.newPortal.end');
	},
	*/
    /*
		Function: $p.app.pages.newPortalCreation
                                
                                Launch new page creation
                                
    */
	newPortalCreation:function(v_form)
    {
        var l_title = "";//v_form.pagetitle.value;
        if (l_title == "") l_title = lg('lblNewpage');

        var l_type  = getRadioValue(v_form.pagetype);

        switch (l_type)
        {
            case 'empty':
                $p.app.pages.newEmpty(l_title);
                break;
            case 'html':
                $p.app.pages.newHtmlPage(v_form.url.value,l_title);
                break;
            case 'selection':
                var l_selectionid = v_form.selectionid.value;
                if (l_selectionid != 'none')
                    $p.app.pages.loadPublicPage(v_form.selectionid.value,l_title);
                break;
        }
    },
    /*
                Function: displayFormtoGetPageFromURL
                
                        $p.app.pages.displayFormtoGetPageFromURL
                        
                        call $p.app.pages.newHtmlPage
                
                 Returns: html 
                 
                 See also:
                 
                 <$p.app.pages.newHtmlPage>
        */
    displayFormtoGetPageFromURL: function (l_background) 
	{
		return '<td align="center"><input type="radio" name="pagetype" value="html" /></td>'
			+ '<td>' + $p.img('page_html.gif',34,41) + '</td>'
			+ '<td><b>' + lg('newPageFromUrl') + '</b><br />'
			+ '<input type="text" name="url" value="http://" style="width: 250px;" class="thinbox" onfocus=\'$p.app.tools.setRadioValue(document.forms["newpage"].pagetype,"html");\' />'
			+ '</td>';
    },
    /*
                    Function: displayFormtoFindSharePages
                
                            $p.app.pages.displayFormtoFindSharePages
                            
                            Form to get pages created by other users
                            
                            use function: $p.app.pages.search 
                            
                      Returns : HTML
                      
                      See also:
                      
                            <$p.app.pages.newHtmlPage>,<$p.app.pages.search>
            */
    displayFormtoFindSharePages: function(l_background) 
	{
        if (!$p.app.user.id  ) return '';
        if (!__useSharing) return  '';

		return '<td align="center"><input type="radio" name="pagetype" value="shared" CHECKED /></td>'
            + '<td>'+$p.img('page_search.gif',34,41,'','imgmid')+'</td>'
            + '<td><b>'+lg('lblNewExample')+'</b><br />'
            + '<input type="text" autocomplete="off" id="inputsearchsharedpage" name="keywords" class="thinbox" '
            + 'style="width: 230px;color: #aaaaaa" '
            + 'onkeyup=\'$p.tags.autocompletion.get("inputsearchsharedpage")\' '
            + 'onFocus=\'$p.app.tools.setRadioValue(document.forms["newpage"].pagetype,"shared");$p.navigator.inputFocus(this,"'+lg("keywords")+'")\' '
            + 'onBlur=\'$p.navigator.inputLostFocus(this,"'+lg("keywords")+'");$p.tags.autocompletion.hide();\' value="'+lg('keywords')+'" />  '
            + '<input type="button" value="'+lg("Search")+'" onclick=\'return $p.app.pages.search(document.forms["newpage"].keywords);\' /> '+tooltip('helpTags')
            + '<br /><div id="listPagesForKeywords"></div>'
            + '</td>';
    },
	/*
		Function: loadPublicPages
                                $p.app.pages.loadPublicPages 
                                
                                Load the public pages
	*/
	loadPublicPages:function()
	{
		$p.ajax.call(posh["xmlpublicpages"],
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.pages.displayPublicPages
				}
			}
		);
	},
	/*
		Function: displayPublicPages
                                $p.app.pages.displayPublicPages 
                                
                                Display the public pages
                                
                     Parameters:
                     
                                response - xml resposne
                                vars (array) - variables
	*/
	displayPublicPages: function(response,vars)
	{
		var l_result = response.getElementsByTagName("page"),
            l_pages = [];
		
		for (var i = 0;i < l_result.length;i ++)
		{
            var desc =  $p.string.removeCot(
                                    $p.string.removeEOL(
                                        $p.string.trim( $p.ajax.getVal(l_result[i],"desc","str",false,""))
                                    )
                                );
            var l_page = '<a href="#" onmouseover=\'mouseBox("'+desc+'",event)\' onclick=\'this.style.fontWeight="bold";$p.app.tools.setRadioValue(document.forms["newpage"].pagetype,"selection");document.forms["newpage"].selectionid.value="'+$p.ajax.getVal(l_result[i],"id","int",false,0)+'";return false;\'>'
                + $p.ajax.getVal(l_result[i],"name","str",false,"")
                + '</a>';

			l_pages.push(l_page);
		}

		$p.print("publicpages",'<div onmouseout=\'mouseBox("")\'>'+l_pages.join(' - ')+'</div>');
	},
	/*
		Function: $p.app.pages.loadPublicPage
                                
                                Load one the public page
                                
                     Parameters:
                     
                                v_id - page id
								v_prof_old - old page id to replace
	*/
	loadPublicPage:function(v_id,v_name,v_prof_old)
	{
		$p.ajax.call(posh["xmlpublicpage"]+'?id='+v_id,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.pages.createFromXml,
					'variables':
					{
						'reload':false,
                        'id':v_id,
                        'pagename':v_name,
						'v_prof_old':v_prof_old
					}
				}
				
			}
		);
	},
	/*
		Function: $p.app.pages.newEmpty
                                
                               Create an empty page
                                
                     Parameters:
                     
                                v_name - page name
                     
                     Returns:
                     
                                false
	*/
	newEmpty:function(v_name,pidold,status)
	{
		var l_style = (__DEFAULT_THEME_FOR_NEW_PAGES == 0
							? ( $p.app.tabs.sel==-1
									? 1
                                    : tab[$p.app.tabs.sel].style)
							: __DEFAULT_THEME_FOR_NEW_PAGES);
		
        v_name==indef ? v_name = lg('lblNewpage') : '';	
		status = (status || 0);
        if ($p.app.user.id == 0)
        {
			$p.app.pages.openCreatedTab(0,{
                    'pagename':v_name,
					'pid':pidold,
					'status':status
                }
            );
        }
		else
		{
			$p.ajax.call(posh["scr_createportal"],
				{
					'type':'execute',
					'variables':'w=3&s=' + l_style + '&n=' + $p.string.esc(v_name) + '&t=0&nb=15&a=Y&pidold='+pidold+'&status='+status,
					'alarm':false,
					'forceExecution':true,
					'callback':
					{
						'function':$p.app.pages.openCreatedTab,
						'variables': {
							'pid':pidold,
							'status':status
						}
					}
				}
			);
		}
		return false;
	},
	/*
		Function: newHtmlPage
                                $p.app.pages.newHtmlPage 
                                
                               Create a new tab with html content in frame
                                
                     Parameters:
                     
                                v_url -  html page URL
                                v_name - page name
                     
                     Returns:
                     
                                false
	*/
	newHtmlPage:function(v_url,v_name,v_prof_old)
	{
		var l_style = $p.app.tabs.sel==-1     ?    1
                                              :    tab[$p.app.tabs.sel].style;
		
        if (v_name==indef) v_name = lg('lblNewpage');
		
		if ($p.app.user.id == 0)
        {
            $p.app.pages.openCreatedTab(v_url,
                {
                    'pagename':v_name
                },
				v_prof_old
            );
        }
		else
		{
			$p.ajax.call(posh["scr_createportal"],
				{
					'type':'execute',
					'variables':"w=1&s=" + l_style + "&n=" + $p.string.esc(v_name) + "&t=0&ty=2&p=" + $p.string.esc(v_url) + "&a=Y&pidold="+v_prof_old,
					'alarm':false,
					'forceExecution':true,
					'callback':
					{
						'function':$p.app.pages.openCreatedTab,
							'variables':
							{
								'pid':v_prof_old
							}
					}
				}
			);
		}
		return false;
	},
	/*
		Function: controlMinimumPage
                                $p.app.pages.controlMinimumPage 
                                
                               Control if the tab can be deleted (to avoid empty portal)
                                
                     Parameters:
                     
			v_tab - tab sequence ID
			v_selectFirst (boolean) - is the first tab selected after removal ? 
			v_needConfirmation (boolean) - define if a confirmation message is displayed before removing the tab
                     
                     Returns:
                     
                                false
	*/
    controlMinimumPage:function()
    {
        var removableTabs=0;
        var numberOfPages = tab.length;
        //if there is only one page, can't delete
        if (numberOfPages == 1) { return false; }
		
        for (var i = 0;i < numberOfPages; i++)
        {
            if (tab[i].removable != indef && !tab[i].temporary) {
                removableTabs++;
            }
        }
        
        return (removableTabs > 1 ? true : false);
    },
	/*
		Function: suppress
                                $p.app.pages.suppress 
                                
                               Remove a tab
                                
                     Parameters:
                     
			v_tab - tab sequence ID
			v_selectFirst (boolean) - is the first tab selected after removal ? 
			v_needConfirmation (boolean) - define if a confirmation message is displayed before removing the tab
                     
                     Returns:
                     
                                false
	*/
	suppress: function(v_tab,v_selectFirst,v_needConfirmation)
	{
        $p.plugin.hook.launch('app.pages.suppress.start');
         
		if (v_tab == indef) { 
            v_tab = $p.app.tabs.sel;
        }
		if (v_selectFirst == indef) {
            v_selectFirst = true;
        }
		if (v_needConfirmation == indef) {
			v_needConfirmation = true;
		}
        if(tab[v_tab].removable != indef && !tab[v_tab].temporary) {
            if (!$p.app.pages.controlMinimumPage()) {
                $p.app.alert.show(lg("msgSuppressNotAllowed"));
                return false;
            }
        }
		// Suppress a portal
		if (v_needConfirmation)
            response = confirm(lg("msgSuppressConfirm"));
   
		if (!v_needConfirmation || response == 1)    {
            if (v_needConfirmation) {
    			$p.ajax.call(posh["scr_suppersonal"],
    				{
    					'type':'execute',
    					'variables':"id="+tab[v_tab].id+"&seq="+tab[v_tab].seq
    				}
    			);
            }

            $p.app.pages.hide();
            $p.app.banner.option.hide();

			//update tabs sequence
			for (var i = 0;i < tab.length;i++)
			{
				if (i > v_tab) tab[i].seq --;
			}
			//delete the tab
			if (tab[v_tab].isLoaded && tab[v_tab].root) {// && !tab[v_tab].temporary) {
                try {
					($("modules")).removeChild(tab[v_tab].root);
				} catch(e) {}
            }
			tab.splice(v_tab,1);

            //refresh tab and choose the first tab
            if ($p.app.tabs.sel>=0) {
                $p.app.tabs.create(0);
            }
            else {
                $p.app.tabs.create();
                $p.app.tabs.sel=-1;
            }
            
            
			if (v_selectFirst == true)    {
				//activate the first tab
				if (tab.length >= 1)  {
                    $p.app.tabs.open(0);
                }
				else    {
					$p.app.tabs.sel = -1;
					$p.app.pages.closeAllDiv();
				}
			}
		}

        //refresh menu based on new page
        $p.app.menu.refreshConditionalMenus();

		$p.plugin.hook.launch('app.pages.suppress.end');

		return false;
	},
	/*
		Function: show
                                $p.app.pages.show
                                
                               Display a saved portal
                                
                     Parameters:
                     
			v_id - tab sequence ID
	*/
	show:function(v_id)
	{
		$p.app.widgets.close();
		hideBox();
		$p.app.pages.load("../cache/portal_"+v_id+".xml");
		$p.app.startLoading();
	},
	/*
		Function: $p.app.pages.hide
                                
                               Hide the current tab
	*/
	hide:function()
	{
		//hide the pages element before swiching to another page
		if ($p.app.tabs.sel!=-1 
            && $p.app.tabs.sel!=999)
		{
            if (tab[$p.app.tabs.sel]) {
                $p.show("modules"+tab[$p.app.tabs.sel].id,"none");
				$p.show("pageform"+tab[$p.app.tabs.sel].id,"none");
                tab[$p.app.tabs.sel].showType=0;
            }
            $p.app.widgets.close();
			//$p.app.menu.config.hide();
			//$p.app.banner.option.hide();
		}
		hideBox();
	},
	/*
		Function: $p.app.pages.isPageExisting
        
                                check if page is existing
                                
                               Load a user's pages
                                
                     Parameters:
                     
		         v_sess - type of user ('user' or 'admin')
	*/
	isPageExisting: function(v_sess)
    {
		if(v_sess =='passwordExpired') {
			$p.app.connection.changePasswordExpired();
		} else {
			if (v_sess != indef)  {
				// if (v_sess == "admin")    {
					// $p.url.openLink(posh["admin_index"]);
				// }
				// else    {
				$p.app.user.id = 'tobeallocated'; // to considere that the user is connected (session created), then id != 0
				
				$p.ajax.call(posh["xmlpages"],
					{
						'type':'load',
						'callback':
						{
							'function':$p.app.pages.createFromXml,
							'variables':
							{
								'session':v_sess,
								'reload':true
							}
						}
					}
				);
				//}
			}
		}
	},
	/*
		Function: closeAllDiv
                                $p.app.pages.closeAllDiv
                                
                               Hide all opened menu, message box, plugins, banners, ....
	*/
	closeAllDiv:function()
	{
		// hide URL page frame
		$p.app.pages.hideFrame();
		
		// hide features pages
		// if (__useArchive)   {
			// if ($p.article.shown) {
                // $p.article.hide();
            // }
		// }
		if ($p.network.shown) $p.network.hide();
		if ($p.app.widgets.factory.shown) $p.app.widgets.factory.hide();
		if ($p.app.banner.option.shown) $p.app.banner.option.hide();
		if ($p.plugin.shown) $p.plugin.hide();

		// hide objects added in the template
		$p.navigator.hideClasses(pageClasses);
		
		$p.show("modules","none");
		$p.show("newmod","none");
        $p.show("message","none");
		$p.app.widgets.rss.reader.hide();
		$p.show("magic","none");//do not suppress !
	},
	/*
	         Function: search
                                $p.app.pages.search
                                
                               Search a page shared by other users

                                called from displayFormtoFindSharePages (in popup to add a new page to portal  $p.app.pages.newPortal)  
                               
                    Parameters:

			v_form - form containing searched string
            
                    Returns:
                    
                                false
	*/
	search:function(v_input)
	{
		$p.app.wait("listPagesForKeywords");	
		var l_keywords = $p.string.formatForSearch($p.tags.formatList(v_input.value));
		if (l_keywords != "")
		{
			$p.ajax.call(posh["xmlpage_search"]+'?search=' + l_keywords,
				{
					'type':'load',
					'callback':
					{
						'function':$p.app.pages.searchResults,
						'variables':
						{
							'keywords':l_keywords
						}
					}
				}
			);
		}
		return false;
	},
	/*
		Function: searchResults
                                $p.app.pages.searchResults
                                
                               Display search results of <search>: lists of pages shared by ohter users for tags wanted
                               
                               links on pages listed call $p.app.pages.loadSharedPortal
                               
                               detail 
                               
                                
                    Parameters:

			response - xml response
                                vars (array) - variables (optional) vars['keywords']
                     
                     See also:
                     
                     <$p.app.pages.loadSharedPortal>
	*/
	searchResults:function(response,vars)
	{
		var l_s="",
		l_result=response.getElementsByTagName("portal");
		if (l_result.length==0) {
			l_s+=lg("noResultForThisSearch");
		}
		else    {
			l_s+=lg("lblResultsFor")+" '"+vars['keywords']+"' :";
			l_s+="<div class='dirdiva' style='height:100px;width:80%;padding:8px;'>";
			for (var i=0;i<l_result.length;i++) {
                var type = $p.ajax.getVal(l_result[i],"type","int",false,0);
                var id = $p.ajax.getVal(l_result[i],"id","int",false,0);
                var name = $p.ajax.getVal(l_result[i],"name","str",false,"");
                var tabid = tab[$p.app.tabs.sel].id;
				l_s+="<a href='#' onclick=\"$p.app.pages.close('newmod');$p.app.pages.loadSharedPortal("+id+","+type+",indef,'',true,"+tabid+")\">"
                   +$p.ajax.getVal(l_result[i],"name","str",false,"--")
                   +"</a><br />";
			}
			l_s+="</div>";
		}
		$p.print("listPagesForKeywords",l_s);
	},
	/*
		Function: $p.app.pages.loadSharedPortal
                                
                               Load public page who can be shared par member of a same network
                               
                               Page must be shared before
                               
                                called from link created after searchResults
                                
                    Parameters:

			v_id - page id
			v_type - page type (public / private)
			v_check - check string for private pages
            
                    See also:
                    
                        <searchResults>
	*/
	loadSharedPortal: function(v_id,v_type,v_check,v_isOverview,v_reload,v_prof_old)
	{
		if(v_prof_old) {
			$p.app.pages.suppress($p.app.tabs.sel,true,false);
		}
		if (v_type != indef 
            && v_type == 2)   {
                var l_url = posh["xmlfriendportal"]+'?id='+v_id+'&chk='+v_check;
		}
		else    {
			var l_url = posh["xmlpage_detail"]+'?id='+v_id;
		}
		$p.ajax.call(l_url,
			{
				'type':'load',
				'callback':
				{
					'function':(v_isOverview ? $p.app.pages.displayOverview
                                             : $p.app.pages.createFromXml),
					'variables':
					{
						'pageid':v_id,
						'type':v_type,
						'check':v_check,
						'reload':v_reload,
						'v_prof_old':v_prof_old
					}
				}
			}
		);
	},
    /*
            Function: $p.app.pages.getPageType
    */
    getPageType: function (vars) {
        var page_type = '';
		if (vars['type']==0)    {
			page_type='<br /><br />'
				+'<center>'
				+'<input class="btnbig" type="button" value="'+lg("lblUseExample")+'" onclick="$p.app.pages.show('+vars['pageid']+')" />'
				+'</center>';
		}
		else    {
			page_type='<br /><br />'	
				+'<center>'
				+ '<input class="btnbig" type="button" value="'+lg('lblCreateFromExample')+'" '
                + 'onclick=\'$p.app.pages.loadSharedPortal('+vars['pageid']+','+vars['type']+',"'+vars['check']+'",false,'+vars['v_prof_old']+')\' />'
				+'</center>';
		}
        return page_type;
    },
    /*
            Function: $p.app.pages.listModules
    */
    listModules: function (response,vars) {
        var l_s='';
		if (response.getElementsByTagName("module")[0])
		{
			var l_i=0;
			l_s+="<table cellpadding='0' cellspacing='0'>";
			while (response.getElementsByTagName("module")[l_i])
			{
				var l_result=response.getElementsByTagName("module")[l_i];
				var l_id=$p.ajax.getVal(l_result,"id","int",false,0);
				l_s+='<tr>'
					+'<td>'
					+$p.img("../modules/pictures/box0_"+l_id,16,16,"","imgmid")
					+'</td>'
					+'<td>'
					+'<a href="#" onclick=\'return $p.app.widgets.open('+l_id+',"'+$p.ajax.getVal(l_result,"vars","str",false,"")+'")\'>'
					+$p.ajax.getVal(l_result,"name","str",false,"-")
					+'</td>'
					+'</tr>';
	
				l_i++;
			}
			l_s+='</table>';
		}
		else
		{
			l_s+=lg("lblNoModule");
		}    
        return l_s;
    },
	/*
		Function: displayOverview
                                $p.app.pages.displayOverview
                                
                               Display detail of  a page shared by another user when somebody want accept the page for his own portal
                               
                               Page visible  after search on tags, page without tags are not accessible
                               
                               calback from loadSharedPortal
                                
                     Parameters:

			response - xml response
                                vars (array) - variables (optionnal) 
                                
                        See also:
                        
                            <loadSharedPortal>
           */
	displayOverview: function(response,vars)
	{
		$p.app.popup.hide();
        var l_tit = $p.ajax.getVal(response,"name","str",false,'');

        //if page is not shared anymore
        if (l_tit == '')
        {
            $p.app.alert.show(lg('itemNotSharedAnymore'));
            return;
        }
        
        var page_description = $p.ajax.getVal(response,"description","str",false,'');

		var l_s = ''
			+ '<table cellpadding="0" cellspacing="1" border="0" width="100%">'
			+ '<tr>';

		if (page_description != '')
		{
			l_s += '<td valign="top">'
                + lg("lblDescription")
                + "&nbsp;:<br />"
                +  page_description
                + '</td>';
		}
		l_s += '<td valign="top">'
			+ lg("lblModules")
			+ '&nbsp;:<br />'
            +  $p.app.pages.listModules(response,vars)
            + '</td>'
			+ '</tr>'
			+ '</table>'
			+ $p.app.pages.getPageType(vars);
		
		if (showNewMod) $p.app.widgets.close();
		
        $p.show("newmod","block");
        $p.print("newmod",box(0,l_tit,"$p.app.pages.close('newmod')",l_s));
	},
    close: function (what) {
        $(what).innerHTML='';
    },
	/*
		Function: $p.app.pages.createFromXmlIfNotExisting
                                
                               Add a new tab based on XML Parameters (only if tab is not yet existing)
                                
                    Parameters:

			response - xml object
                                vars (array) - variables (optionnal) 
           */
	createFromXmlIfNotExisting: function(response,vars)
	{
		$p.app.pages.createFromXml(response,vars,true);
	},
	/*
		Function: $p.app.pages.createFromXml
        
                               Add a new tab based on XML Parameters
                                
                    Parameters:

                    response - xml object
                    vars (array) - variables (optionnal) 
                    checkIfAlreadyExisting - boolean, define if the tab is added even if a tab with the same name is already existing
                    
                    See Also: 
                            - <$p.app.pages.isPageExisting>
                            - <$p.app.pages.loadPublicPage>
                            - <$p.app.pages.loadSharedPortal>
                            - <$p.app.pages.createFromXmlIfNotExisting>
           */
	createFromXml: function(response,vars,checkIfAlreadyExisting)
	{
		$p.app.popup.hide();
		
		// added by CSU : define user ID if not already defined in the template (used during page sharing)
		$p.app.user.id = $p.ajax.getVal(response,"userid","int",false,$p.app.user.id);

        var canCallback = false,
            l_pageid = 0;
		
		if (checkIfAlreadyExisting == indef) checkIfAlreadyExisting = false;

		//if page tag, redirect to this page
		if (response.getElementsByTagName("page")[0])
        {
			$p.url.openLink("../portal/"+$p.ajax.getVal(response.getElementsByTagName("page")[0],"url","str",false,""));
			return;
		}
		v_reload = (vars['reload']==indef ? false : vars['reload']);
        
		// Get modules from XML file for creation of a new portal
		var l_result = response.getElementsByTagName("portal");
		// Get modules from XML file for creation of a new portal
		if (l_result.length != 0)
		{
            //if connected => page saved, if anonymous => page created
            if ($p.app.user.id == 0)
            {
                for (var j = 0;j < l_result.length;j++)
                {
                    var inc = 0,
                        l_x = 100,
                        l_y = 200,
                        l_name=(vars['pagename'] == indef) ? $p.ajax.getVal(l_result[j],"name","str",false,lg("lblNewpage")) : vars['pagename'],
                        l_style=$p.ajax.getVal(l_result[j],"style","int",false,1),
                        l_nbcol=$p.ajax.getVal(l_result[j],"nbcol","int",false,3),
                        l_mode=$p.ajax.getVal(l_result[j],"showtype","int",false,0),
                        l_npnb=$p.ajax.getVal(l_result[j],"npnb","int",false,25),
                        l_type=$p.ajax.getVal(l_result[j],"type","int",false,1),
                        l_param=$p.string.esc($p.ajax.getVal(l_result[j],"param","str",false,"")),
                        l_moduleAlign=$p.ajax.getVal(l_result[j],"modulealign","str",false,"Y"),
                        l_removable=$p.ajax.getVal(l_result[j],"removable","int",false,1),
                        l_showwidgetbar=$p.ajax.getVal(l_result[j],"showwidgetbar","int",false,1),
                        l_controls = $p.ajax.getVal(l_result[j],"ctrl","str",false,'Y'),
                        l_pageid=$p.ajax.getVal(l_result[j],"pageid","int",false,0),
                        colsnodelist = l_result[j].getElementsByTagName("cols");
                    
					//if tab already exist > do not create
					if (checkIfAlreadyExisting)
					{
						var l_tabIsExisting = $p.app.tabs.selectTabByTitle(l_name);
						if (l_tabIsExisting != -1)
						{
							$p.app.tabs.open(l_tabIsExisting);
							return;
						}
					}

					var lastTabNumber = $p.app.tabs.maxId()+1,
                        lastTabSeq = tab[tab.length-1].seq+1;
                    $p.app.pages.setCurrent(0);
                    $p.app.pages.hide();

                    tab.push(new $p.app.tabs.object(
                                    lastTabNumber,
                                    l_name,
                                    l_type,
                                    "$p.app.pages.change("+lastTabNumber+")",
                                    0,
                                    lastTabSeq,
                                    1,
                                    1,
                                    "",
                                    0,
                                    0,
                                    "",
                                    0,      //page id
                                    l_removable,
                                    false,
                                    false,
                                    colsnodelist
                                    ));
                                    
                    var l_tabPos = tab.length - 1;
                    
                    tab[l_tabPos].showwidgetbar = l_showwidgetbar;
                    tab[l_tabPos].controls = l_controls;
					tab[l_tabPos].colnb = l_nbcol;
					tab[l_tabPos].style = l_style;
					tab[l_tabPos].param = l_param;
                    //tab[l_tabPos].isLoaded = true;
                    
                    while (l_result[j].getElementsByTagName("module")[inc])
                    {
                        var l_result2 = l_result[j].getElementsByTagName("module")[inc];
                        var cellid = $p.ajax.getVal(l_result2,"cell","int",false,1);
                        var format = $p.ajax.getVal(l_result2,"format","str",false,'I');
						
                        $p.app.pages.columns.updateNbWidgetByCol(l_tabPos,cellid,1,format);
						
                        tab[l_tabPos].module.push(
                            new $p.app.widgets.object(
                                cellid,
                                $p.ajax.getVal(l_result2,"pos","int",false,inc),
                                $p.ajax.getVal(l_result2,"posj","int",false,inc),
                                $p.ajax.getVal(l_result2,"height","int",false,inc),
                                $p.ajax.getVal(l_result2,"id","int",false,0),
                                $p.ajax.getVal(l_result2,"link","str",false,''),
                                $p.ajax.getVal(l_result2,"name","str",false,''),
                                $p.ajax.getVal(l_result2,"vars","str",false,""),
                                $p.ajax.getVal(l_result2,"minwidth","int",false,300),
                                $p.ajax.getVal(l_result2,"sizable","str",false,''),
                                $p.ajax.getVal(l_result2,"minwidth","int",false,300),
                                $p.ajax.getVal(l_result2,"url","str",false,''),
                                $p.ajax.getVal(l_result2,"x","int",false,l_x),
                                $p.ajax.getVal(l_result2,"y","int",false,l_y),
                                $p.ajax.getVal(l_result2,"uniq","int",false,inc),
                                $p.ajax.getVal(l_result2,"format","str",false,'I'),
                                $p.ajax.getVal(l_result2,"nbvariables","int",false,0),
                                lastTabNumber,
                                $p.ajax.getVal(l_result2,"blocked","int",false,0),
                                $p.ajax.getVal(l_result2,"minimized","int",false,0),
                                1,
                                0,
                                $p.ajax.getVal(l_result2,"icon","str",false,''),
                                false
                            )
                        );
                                
                        inc ++;
                        l_x += 30;
                        l_y += 30;
                    }
                }
                
                $p.app.tabs.sel = tab.length - 1;
				tab[$p.app.tabs.sel].isLoaded = true;
				$p.app.pages.init();
				v_prof = tab[$p.app.tabs.sel].id;
                
                //$p.app.pages.init(l_tabPos);
                //$p.app.pages.change(tab[l_tabPos].id);
                //$p.app.tabs.create(l_tabPos);
            }
            else
            {

                for (var j = 0;j < l_result.length;j++)
                {
                    var i = 0,
                        l_s = "",
                        l_x = 100,
                        l_y = 200,
                        l_name=(vars['pagename'] == indef) ? $p.ajax.getVal(l_result[j],"name","str",false,lg("lblNewpage")) : vars['pagename'],
                        l_style=$p.ajax.getVal(l_result[j],"style","int",false,1),
                        l_nbcol=$p.ajax.getVal(l_result[j],"nbcol","int",false,3),
                        l_mode=$p.ajax.getVal(l_result[j],"showtype","int",false,0),
                        l_npnb=$p.ajax.getVal(l_result[j],"npnb","int",false,25),
                        l_type=$p.ajax.getVal(l_result[j],"type","int",false,1),
                        l_param=$p.string.esc($p.ajax.getVal(l_result[j],"param","str",false,"")),
                        l_moduleAlign=$p.ajax.getVal(l_result[j],"modulealign","str",false,"Y"),
                        l_removable=$p.ajax.getVal(l_result[j],"removable","int",false,1),
                        l_showwidgetbar=$p.ajax.getVal(l_result[j],"showwidgetbar","int",false,1),
						l_template=$p.ajax.getVal(l_result[j],"template","int",false,0),
                        l_controls = $p.ajax.getVal(l_result[j],"ctrl","str",false,'Y'),
                        l_pageid=$p.ajax.getVal(l_result[j],"pageid","int",false,0);
                    
					//if tab already exist > do not create
					if (checkIfAlreadyExisting)
					{
						var l_tabIsExisting = $p.app.tabs.selectTabByTitle(l_name);
						if (l_tabIsExisting != -1)
						{
							$p.app.tabs.open(l_tabIsExisting);
							return;
						}
					}
					
                    while (l_result[j].getElementsByTagName("module")[i])
                    {
                        var l_result2 = l_result[j].getElementsByTagName("module")[i];

                        l_s += "&id"+i+"="+$p.ajax.getVal(l_result2,"id","int",false,0)
                            + "&cell"+i+"="+$p.ajax.getVal(l_result2,"cell","int",false,1)
                            + "&pos"+i+"="+$p.ajax.getVal(l_result2,"pos","int",false,i)
                            + "&posj"+i+"="+$p.ajax.getVal(l_result2,"posj","int",false,i)
                            + "&x"+i+"="+$p.ajax.getVal(l_result2,"x","int",false,l_x)
                            + "&y"+i+"="+$p.ajax.getVal(l_result2,"y","int",false,l_y)
                            + "&var"+i+"="+$p.string.esc($p.ajax.getVal(l_result2,"vars","str",false,""))
                            + "&blocked"+i+"="+$p.ajax.getVal(l_result2,"blocked","int",false,0)
                            + "&minimized"+i+"="+$p.ajax.getVal(l_result2,"minimized","int",false,0);

                        i++;
                        l_x += 30;
                        l_y += 30;
                    }
			
				//if(tab[$p.app.tabs.sel].status==2) {
					v_prof_old = 0;
					if(vars['v_prof_old']) {
						v_prof_old = vars['v_prof_old'];
					}
					l_s += "&status="+0+"&pidold="+v_prof_old;
					
				//}
                    $p.ajax.call(posh["scr_createportal"],
                        {
                            'type':'execute',
                            'variables':    "w=" + l_nbcol
                                            + "&s=" + l_style
                                            + "&a=" + l_moduleAlign
                                            + "&n=" + $p.string.esc(l_name)
                                            + "&t=" + l_mode
                                            + "&nb=25&ty=" + l_type
                                            + "&p=" + l_param
                                            + "&sess=" + vars['session']
                                            + "&pageid=" + l_pageid
                                            + "&removable=" + l_removable
                                            + "&wbar=" + l_showwidgetbar
											+ "&tpl=" + l_template
                                            + "&ctrl=" + l_controls
                                            +l_s,
                            'forceExecution':true,
                            'alarm':false,
                            'callback':{
                                'function':(j < l_result.length - 1
                                                ? null
                                                : v_reload
                                                    ? openPage
                                                    : $p.app.pages.openCreatedTab
                                            ) 
                            },
                            'priority':2,
                            'asynchron':false
                        }
                    );  
                }
            }
        }
	},
	/*
		Function: select
                                $p.app.pages.select
                                
                               Select a page
                                
                    Parameters:

			v_prof - page id
           */
	select:function(v_prof)
	{
		$p.app.pages.change(v_prof);
	},
	/*
		Function: displayLockWindow
        
                                $p.app.pages.displayLockWindow
                                
                                Display connection box for a secured page
	*/
    displayLockWindow:function()
	{
        hideAllBox();
		$p.app.widgets.rss.reader.close();        
        
		var l_s='<div class="protectbox">\
        <div id="loginscreen">\
			<div style="float: left;width: 150px;">\
                <h2 id="lsconnectTitle">'+lg('lblConnect')+'&gt;</h2>\
                <div id="msg_conn">&nbsp;</div>\
                <p><a class="w" id="ls_missingpass" onclick="return $p.app.connection.buildmissingPasswordForm();">'+lg('lblMissingPassword')+'</a></p>\
			</div>\
			<div id="displayPart">\
                 <form name="identif" method="post" onsubmit="return $p.app.pages.unlock(this);">\
                    <strong><label id="ls_lbl_password" for="password">'+lg('lblPassword')+'</label></strong><br />\
                    <input type="password" name="pass" maxlength="32" class="thinbox" style="width: 250px;"/><br /><br />\
                    <input type="checkbox" id="ls_lbl_autoconnect" name="autoconn" />'+lg('lblAutoConnection')+'<br /><br />\
                    <input type="submit" id="ls_btn_connect" class="btn" value="'+lg('lblConnect')+'" />\
                </form>\
			<br/><br/>\
            </div>\
        </div>\
        </div>';
 
        $p.print("modules"+tab[$p.app.tabs.sel].id,l_s);
        
		$p.show("modules","block");
		$p.styles.setActiveStyleSheet($p.app.tabs.defTheme);
	},
	/*
		Function: $p.app.pages.unlock

                                Unlock secured page
		
                     Parameters:

			 Form object where password is typed
             
                     Returns:
                        
                                false
	*/
	unlock:function(v_form)
	{
		$p.ajax.call(posh["scr_unlock"],
			{
				'type':'execute',
				'variables':"id="+tab[$p.app.tabs.sel].id+"&pass="+v_form.pass.value,
				'alarm':true,
				'forceExecution':false,
				'callback':
				{
					'function':$p.app.pages.open
				}
			}
		);
		return false;
	},
	/*
		Function: $p.app.pages.lock
                                
                                
                                Lock a secured page
	*/
	lock:function()
	{
		$p.app.counter.activityStep=0;
		$p.app.pages.lockPage=1;
		$p.ajax.call(posh["scr_protect"],
			{
				'type':'execute',
				'variables':"",
				'alarm':false,
				'forceExecution':false,
				'callback':
				{
					'function':$p.app.pages.open
				}
			}
		);
	},
	/*
		Function: $p.app.pages.load 
        
              Load personalized page content information
		
                    Parameters:

			v_page - xml file containing page information
			v_id - tab ID
			v_tab - tab sequence id
			v_action - action to launch on tab opening
	*/
	load: function(v_page,v_id,v_tab,v_action)
	{
		$p.plugin.hook.launch('app.pages.load.start');

		if (v_tab == indef) v_tab = $p.app.tabs.sel;
		if (v_tab == indef)
            v_tab = $p.app.tabs.idToPos($p.app.tabs.selId);
		if (v_tab == indef || !v_tab) v_tab = 0;

		tab[v_tab].module.length = 0;

		// used to avoid the loading icon in the tabs
        tab[v_tab].isLoaded = ($p.app.user.id == 0)    
					?   (v_tab == $p.app.tabs.sel ? false : indef)
					:   (v_tab == $p.app.tabs.sel ? false : indef);
		
        $p.app.widgets.rss.init(v_tab);
		if (!v_id) v_id = "";
		var l_method = (v_id == "" ? "GET" : "POST");

		//create modules container div
		$p.app.pages.defineWidgetContainer(v_tab);
		
		//change style css if the one to show is not the one already selected
		$p.styles.checkTabAndSetActiveStyleSheet(v_tab);
		
		$p.ajax.call(v_page,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.pages.treat,
					'variables':
					{
						'tab':v_tab,
						'action':v_action
					}
				},
				'source':'xml',
				'variables':v_id,
				'method':l_method,
				'priority':1
			}
		);

		$p.plugin.hook.launch('app.pages.load.end');
	},
	/*
		Function: treat
                                $p.app.pages.treat
                                
                                Treat opened page information
		
                    Parameters:

			response - xml object containing page information
                                vars (array) - variables (optionnal)
	*/
	treat:function(response,vars)
	{
		$p.plugin.hook.launch('app.pages.treat.start');

		var l_tab=vars['tab'];
		var l_action=vars['action'];
		var i=0,result;
		//if page is not existing
		if (response.getElementsByTagName("nopage")[0])
			openPage(tab[0].id);
		//if not yet install
		if (response.getElementsByTagName("install")[0])
			$p.url.openLink(posh["installrequested"]);
		//if connected mode
		//if (response.getElementsByTagName("empty")[0]) $p.url.openLink("../portal/login.php");
		//var l_type=$p.ajax.getVal(response,"type","int",false,1);
		var l_type = tab[l_tab].type;
		
		if (l_type==1)
		{
			widgetHeight = $p.ajax.getVal(response,"height","int",false);
			//if page locked
			if ($p.ajax.getVal(response,"pagelocked","int",false,0)==1)
			{
				$p.app.popup.hide();
				tab[l_tab].locked=true;
				$p.app.newEnv('locked');
				if (l_tab==$p.app.tabs.sel)  $p.app.pages.displayLockWindow();
			}
			else
			{
				$p.app.newEnv(($p.app.user.id==0)?'portal_page_anon':'portal_page_conn');
                
				tab[l_tab].locked=false;
				tab[l_tab].colnb=$p.ajax.getVal(response,"nbcol","int",false,tab[l_tab].colnb);
				tab[l_tab].showType=$p.ajax.getVal(response,"showtype","int",false,tab[l_tab].showType);
				tab[l_tab].newspapernb=$p.ajax.getVal(response,"npnb","int",false,tab[l_tab].newspapernb);
				tab[l_tab].controls=$p.ajax.getVal(response,"ctrl","str",false,tab[l_tab].controls);
				tab[l_tab].moduleAlign=($p.ajax.getVal(response,"modulealign","str",false,(__moduleAlignDefault?"Y":"N"))=="Y"?true:false);
                tab[l_tab].showwidgetbar=$p.ajax.getVal(response,"showwidgetbar","int",false,tab[l_tab].showwidgetbar);
                tab[l_tab].seq=$p.ajax.getVal(response,"seq","int",false,tab[l_tab].seq);
                
				//var oldstyle=tab[$p.app.tabs.sel].style;
				tab[l_tab].style=$p.ajax.getVal(response,"style","int",false,1);
                //jspass=$p.ajax.getVal(response,"usepass","str",false,"");
                tab[l_tab].lock=$p.ajax.getVal(response,"usepass","str",false,0);
                $p.app.banner.info.requested=$p.ajax.getVal(response,"advise","str",false,$p.app.banner.info.requested);

				tab[l_tab].usereader=__usereader?$p.ajax.getVal(response,"usereader","int",false,tab[l_tab].usereader):0;
				$p.app.pages.def=$p.ajax.getVal(response,"default","str",false,$p.app.pages.def);

				while (response.getElementsByTagName("module")[i])
				{
					result=response.getElementsByTagName("module")[i];
					
					var l_vars = $p.ajax.getVal(result,"vars","str",false,"");
					// decrypt the user profs
					if (__ENCRYPT_USERPREF) {
						l_vars = $p.app.tools.decryptData(l_vars,encryptKey);
						l_vars = decodeURIComponent(l_vars.replace(/\+/g, '%20'));
					}

					tab[l_tab].module[i] = new $p.app.widgets.object(
                        $p.ajax.getVal(result,"col","int",true,0),
                        $p.ajax.getVal(result,"pos","int",false,0),
                        $p.ajax.getVal(result,"posj","int",false,0),
                        $p.ajax.getVal(result,"height","int",false,100),
                        $p.ajax.getVal(result,"id","int",false,0),
                        $p.ajax.getVal(result,"site","str",false,"/"),
                        $p.ajax.getVal(result,"name","str",false,"--"),
                        l_vars,
                        $p.ajax.getVal(result,"minmodsize","int",false,180),
                        $p.ajax.getVal(result,"updmodsize","int",false,1),
                        $p.ajax.getVal(result,"minmodsize","int",false,180),
                        $p.ajax.getVal(result,"url","str",false,""),
                        $p.ajax.getVal(result,"x","int",false,0),
                        $p.ajax.getVal(result,"y","int",false,0),
                        $p.ajax.getVal(result,"uniq","int",false,0),
                        $p.ajax.getVal(result,"format","str",false,"I"),
                        $p.ajax.getVal(result,"nbvars","int",false,0),
                        tab[l_tab].id,
                        $p.ajax.getVal(result,"blocked","int",false,0),
                        $p.ajax.getVal(result,"minimized","int",false,0),
                        $p.ajax.getVal(result,"usereader","int",false,1),
                        $p.ajax.getVal(result,"autorefresh","int",false,0),
                        $p.ajax.getVal(result,"icon","str",false,indef),
                        false,
                        '',
                        '',
                        '',
                        $p.ajax.getVal(result,"views","str",false,'home'),
                        $p.ajax.getVal(result,"l10n","str",false,''),
                        $p.ajax.getVal(result,"shared","str",false,""),
                        $p.ajax.getVal(result,"group_access","str",false,"0")
                        );
                        tab[l_tab].module[i].PositioninTab=i;
					i++;
				}
				$p.app.stats();

			}
		}
		else if (l_type==2 
                && l_tab==$p.app.tabs.sel)  {
			eval(tab[l_tab].fct);
			$p.app.checkLoading(false);
		}
		else if (l_type==3 
                && l_tab==$p.app.tabs.sel)  {
			eval($p.ajax.getVal(response,"param","str",false,""));
			$p.app.checkLoading(false);
		}
		//change style css if the one to show is not the one already selected
		$p.styles.checkTabAndSetActiveStyleSheet(l_tab);

        if ( l_tab == $p.app.tabs.sel && tab[l_tab].isLoaded != true) {
            $p.app.pages.init(l_tab);
            $p.app.pages.computeFooterPosition();           
            if (l_action!=indef 
                && l_action!="")    {
                if (l_action=="edittab") $p.app.tabs.edit($p.app.tabs.sel);
            }
        }
		$p.plugin.hook.launch('app.pages.treat.end');
	},
	/*
	         Function: init
                                $p.app.pages.init 
                                
                                Initialize personalized page 
		
                    Parameters:

			 v_tab - tab sequence ID
	*/
	init:function(v_tab)
	{
		//init the page
		if (v_tab==indef) v_tab=$p.app.tabs.sel;
		if (v_tab == $p.app.tabs.sel) { //only if initializing active tab
			$p.app.startLoading();
			if (tab[v_tab].showType==1) $p.app.widgets.rss.reader.close();
			$p.show("modules","block");
			 $p.show("advise","none");
			if ($p.app.banner.option.shown) $p.show("advise","inline");
		}
		tab[v_tab].isLoaded = false;
        // if page not blocked, show menu control
        if (tab[v_tab].controls == 'Y') $p.app.menu.displayControl();
        
		$p.app.pages.defineWidgetContainer(v_tab);
        //create cols if modules are aligned in columns
        //to avoid recreating the widgets container twice in admin when create pages!
        // if ($p.app.env != "admin" 
           // || (tab[$p.app.tabs.sel].module.length == 0
               // && $p.app.env == "admin") ) {
                    $p.app.pages.columns.createAll(v_tab);
        // }

		$p.app.widgets.createAll(v_tab);

		$p.app.widgets.enableMoving(v_tab);
		if (v_tab == $p.app.tabs.sel)//only if initializing active tab
		{
			$p.app.checkLoading(false);
			$p.cookie.check();
			$p.app.mainMenu();
		}
		//prevent cols to be wider than 400px
//		if (p_area.showType==0){for (var i=1;i<=$p.app.pages.columns.nb;i++){cols[i].style.width="400px";};}else {cols[1].style.width="400px";}
	},
	/*
	         Function: $p.app.pages.clean

                                Remove all the objects from the personalized page
		
                    Parameters:

			 v_mainObj - object to be cleaned
	*/
	clean:function(v_mainObj)
	{
		var l_obj=null;
		//suppress all the descendant nodes of mainObj
		if (v_mainObj!=null)
		{
			while (v_mainObj.hasChildNodes())
			{
				l_obj=v_mainObj;
				while (l_obj.hasChildNodes()) l_obj=l_obj.firstChild;
				l_obj=l_obj.parentNode;
				l_obj.removeChild(l_obj.firstChild);
			}
		}
	},
	/*
	         Function: frame
                                $p.app.pages.frame 
                                
                                Open a framed page
		
                    Parameters:

			v_url - url of the page that is opened in the frame
			v_id - tab ID
	*/
	frame:function(v_url,v_id)
	{
		$p.show("footer","none");
		//$p.app.banner.option.hide();
		$p.show("box","none");
		$p.app.pages.closeAllDiv();
		$p.show("modules","block");
		$p.app.stopLoading();
		
		$p.app.newEnv('portal_frame');

		var l_tab=$p.app.tabs.idToPos(v_id);
//		if (l_tab!=$p.app.tabs.sel)  (tab[l_tab].root).setStyle("display","none");

		if (tab[l_tab].isLoaded) {
			$p.show("modules"+v_id,"block");
		} else {
			// frame height calculation
			if ($("modules"+v_id) == null)    {
				tab[l_tab].root = new Element('div', {'id': "modules"+v_id} );
				($("modules")).appendChild(tab[l_tab].root);
			}
			
			// var l_s = "<iframe id='pagefrm"+v_id+"' src='"+v_url+"' frameborder='no' marginwidth='0' marginheight='0' scrolling='auto' style='height:"+(l_endPosition-l_startPosition)+"px;width:100%;z-index:auto;' onload='$p.adjustFrameHeight(this);'></iframe>";
			//var l_s = "<iframe id='pagefrm"+v_id+"' src='"+v_url+"' frameborder='no' marginwidth='0' scrolling='" + (($p.url.isLocal(v_url) && (v_url).indexOf('framenoresize') == -1) ? 'no' : 'auto') + "' marginheight='0' style='height: 800px;width: 99%;z-index: auto;' onload='$p.adjustFrameHeight(this);'></iframe>";
			var l_s = "<iframe class='urlpage' id='pagefrm"+v_id+"' src='"+$p.string.unesc(v_url)+"' frameborder='no' marginwidth='0' scrolling='auto' marginheight='0' style='height: 800px;width: 99%;z-index: auto;' onload='$p.adjustFrameHeight(this);'></iframe>";
			$p.print('modules'+v_id,l_s);
			$p.show('modules'+v_id,'block');
            tab[l_tab].isLoaded = true;
            $p.app.tabs.created[l_tab]=false;
			$p.app.tabs.create(l_tab);
		}

		//lock menus
		$p.app.menu.widget.locked=true;
		//$p.app.tabs.selId=tab[$p.app.tabs.sel].id;
		$p.app.tabs.selId=v_id;
		$p.app.pages.computeFooterPosition();
        //refresh menu based on new page
        $p.app.menu.refreshConditionalMenus();
		//apply style
		$p.styles.checkTabAndSetActiveStyleSheet(l_tab);
		
	},
	/*
	         Function: hideFrame
                                $p.app.pages.hideFrame 
                                
                                Close a framed page
	*/
	hideFrame:function()
	{
		$p.show("footer","block");
	},
	/*
	         Function: computeSizeAndResize
                                $p.app.pages.computeSizeAndResize 
                                
                                Compute page size based on widgets and resize it
		
                    Parameters:

			v_tab - tab sequence ID
	*/
	computeSizeAndResize:function(v_tab)
	{
		if (tab[v_tab].moduleAlign)
		{
			var l_cellWidth=[];
			for (var i=0;i<tab[v_tab].module.length;i++)
			{
				if (l_cellWidth[tab[v_tab].module[i].newcell] == indef 
                    || tab[v_tab].module[i].minModSize > l_cellWidth[tab[v_tab].module[i].newcell]) {
                        l_cellWidth[tab[v_tab].module[i].newcell] = tab[v_tab].module[i].minModSize;
                }
			}
			for (var i=0;i<tab[v_tab].module.length;i++)
			{
				tab[v_tab].module[i].hide();
			}
			var l_screenWidth=($("header")).offsetWidth;
			var l_availWidth=(l_screenWidth-widgetDecalX)-($p.navigator.IE?0:10);
			(tab[v_tab].root).setStyle("width",l_availWidth+"px");
			for (var i=0;i<tab[v_tab].module.length;i++)
			{
				tab[v_tab].module[i].show();
			}
		}
	},
	/*
	         Function: resize
                                $p.app.pages.resize *(unavailable)*
                                
                                Resize a frame page
	*/
	resize:function()
	{
//	$p.app.pages.computeSizeAndResize($p.app.tabs.sel);
	},
	/*
	         Function: $p.app.pages.displayItems

                                Display and initialize objects move of a personalized page
		
                    Parameters:

			v_tab - tab sequence ID
	*/
	displayItems: function(v_tab)
	{
		if (v_tab == indef) v_tab = $p.app.tabs.sel;

		//changeStyle("optmod","display",""); Removed in 1.5 > too long if many opened pages
		//initialise modules move only if allowed and not in newspaper mode
		if (useMod
            && tab[v_tab].showType == 0)  {
			if (!tab[v_tab].moveIsInit) {
				if (tab[v_tab].moduleAlign) {
					$p.app.pages.columns.init(v_tab);
				}
				else    {
					$p.app.widgets.initMove(v_tab);
				}
			}
		}
	},
	/*
	         Function: computeFooterPosition
                                $p.app.pages.computeFooterPosition
                                
                                Place the footer based on the widgets position
	*/
	computeFooterPosition:function()
	{
		var l_footer = $("footer");
		if (l_footer == null) return;
		if ($p.app.tabs.sel == -1 
            || tab[$p.app.tabs.sel].moduleAlign)    {
			l_footer.setStyle("position","relative");
		}
		else    {
			var widgetsBottomPos = 0,
				currWidgetBottomPos;
			for (var i = 0;i<tab[$p.app.tabs.sel].module.length;i++)
			{
				currWidgetBottomPos = tab[$p.app.tabs.sel].module[i].y+tab[$p.app.tabs.sel].module[i].height+widgetDecalY+40;
				if (currWidgetBottomPos > widgetsBottomPos)
					widgetsBottomPos=currWidgetBottomPos;
			}
			l_footer.setStyle("position","absolute");
			l_footer.setStyle("top",widgetsBottomPos+"px");
		}
	},
	/*
	         Function: checkAndSave
                                $p.app.pages.checkAndSave
                                
                                Check the page and save it
	*/
	checkAndSave: function(v_form)
	{
		// Check if some pages are modified
		var pagesModified = false;
		for (var i = 0; i < tab.length; i++)
		{
			if (tab[i].modified)
				pagesModified = true;
		}
		
		// if pages are modified, warn the user that pages can be replaced
		if (pagesModified)
		{
			var response = confirm(lg("pagesWillBeReplaceOnSaving"));
			if (response != 1)
			{
				// if user cancel the operation, stop the funtion
				return false;
			}
		}
		
		$p.app.connection.set(v_form,$p.app.pages.save);

		return false;
	},
	/*
	         Function: save
                                $p.app.pages.save
                                
                                Save current page (for non connected users)
                    
                    Parameters:
                        
                                v_type (string) - type ofuser ('user' or 'admin')
	*/
	save:function(v_type,vars)
	{
        var v_subscribe = vars["subscribe"];
											  
		if (v_type=="user") {	
			// save the page (modules + personalization)
			for (var cpt=0;cpt<tab.length;cpt++)
			{
				if (!tab[cpt].temporary) {
					//var l_ret="pageid="+tab[cpt].pageid+"w="+tab[cpt].colnb+"&s="+tab[cpt].style+"&n="+tab[cpt].label+"&p="+tab[cpt].param+"&t="+tab[cpt].showType+"&ty="+tab[cpt].type+"&nb="+tab[cpt].newspapernb+"&i="+tab[cpt].icon+"&a="+(tab[cpt].moduleAlign?"Y":"N");
					var l_ret="pageid=" + tab[cpt].pageid
						 + "&w=" + tab[cpt].colnb
						 + "&s=" + tab[cpt].style
						 + "&n=" + tab[cpt].label
						 + "&seq=" + tab[cpt].seq
						 + "&p=" + tab[cpt].param
						 + "&t=" + tab[cpt].showType
						 + "&ty=" + tab[cpt].type
						 + "&nb=" + tab[cpt].newspapernb
						 + "&i=" + tab[cpt].icon
						 + "&tpl=" + tab[cpt].template
						 + "&a=" + (tab[cpt].moduleAlign ? "Y" : "N")
						 + "&modif=" + (tab[cpt].modified ? 'Y' : 'N');

                    for (var i=0;i!=tab[cpt].module.length;i++)
					{
						l_ret += "&id" + i + "=" + tab[cpt].module[i].id
							+ "&pos" + i + "=" + tab[cpt].module[i].newpos
							+ "&cell" + i + "=" + tab[cpt].module[i].newcell
							+ "&posj" + i + "=" + tab[cpt].module[i].newposj
							+ "&x" + i + "=" + tab[cpt].module[i].newx
							+ "&y" + i + "=" + tab[cpt].module[i].newy
							+ "&var" + i + "=" + $p.string.esc(tab[cpt].module[i].vars)
							+ "&blocked" + i + "=" + tab[cpt].module[i].blocked
							+ "&minimized" + i + "=" + (tab[cpt].module[i].minimized?"1":"0");
					}	
                    
					$p.ajax.call(posh["scr_createportal"],
						{
							'type':'execute',
							'variables':l_ret,
							'alarm':false,
							'forceExecution':true,
							'method':'post',
							'asynchron':false,
        					'callback':
        					{
        						'function':$p.app.pages.setFirstPageToOpen
        					} 
						}
                        
					);                                     
				}
			}
            if (!v_subscribe) openPage($p.app.pages.firstPageToOpen);
		}
	},
	firstPageToOpen: 0,
	setFirstPageToOpen: function(v_page)
	{
		if ($p.app.pages.firstPageToOpen == 0)
			$p.app.pages.firstPageToOpen = v_page;
	},
	/*
	         Function: $p.app.pages.maxModReached
                                
                                Limit modules number in a page, called from <$p.app.widgets.placeinCol>
                                
                    Returns: 
                 
                                True or false
	*/
	maxModReached:function(v_tab,v_cell)
	{
		var l_ret = false;
        //may control number of widget by col
		if (tab[$p.app.tabs.sel].module.length > __maxModNb)  {
			$p.app.alert.show(lg("msgMaxMod",__maxModNb));
			l_ret = true;
		}
		return l_ret;
	},
	/*
	         Function: $p.app.pages.defineWidgetContainer
                                
                                Define a widget container
                    
                    Parameters:
                        
                                v_tab - tab sequence ID
	*/
	defineWidgetContainer:function(v_tab)
	{
		if ($("modules"+tab[v_tab].id)==null)   {
			tab[v_tab].root = new Element('div', {'id': "modules"+tab[v_tab].id} );		
			
			if (v_tab != $p.app.tabs.sel)    
            {    
                tab[v_tab].root.setStyle('display', 'none');  
            }
			($("modules")).appendChild(tab[v_tab].root);
		}
	},
	/*
	         Function: getPublicWidgets
                                $p.app.pages.getPublicWidgets
                                
                                get a user public widgets
                    
                    Parameters:
                        
                                v_userId - user ID
			v_destDiv - (string) destination div where result will be printed
	*/
	getPublicWidgets:function(v_userId,v_destDiv)
	{
		$p.ajax.call(posh["xml_userpublicwidgets"]+'?id='+v_userId,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.pages.displayPublicWidgets,
					'variables':
					{
						'destdiv':v_destDiv
					}
				}
			}
		);
	},
    /*
            Function: $p.app.pages.displayPublicWidgets
    */
	displayPublicWidgets: function(response,vars)
	{
		var l_result = response.getElementsByTagName('widget');
		var l_s = '<h2>' + lg('sharedWidgets') + '</h2>';
		var l_prevPortname;

		for (var i = 0;i < l_result.length;i++)
		{
			var l_id = $p.ajax.getVal(l_result[i],'id','int',false,0);
			var l_vars = $p.ajax.getVal(l_result[i],'variables','str',false,'');
			var l_widname = $p.string.getVar(l_vars,'ptitl');
			if (l_widname == '')
			{
				l_widname = $p.ajax.getVal(l_result[i],'widname','str',false,'???');
			}
			var l_portname = $p.ajax.getVal(l_result[i],'portname','str',false,'???');

			// if (l_prevPortname != l_portname)
			// {
				// l_s += '<h2>'+l_portname+'</h2>';
				// l_prevPortname = l_portname;
			// }

			l_s += '<img src="../modules/pictures/box0_'+l_id+'" class="imgmid"> '
				+ '<a href="#" onclick=\'$p.app.widgets.open('+l_id+',"'+l_vars+'","uniq")\'>'
				+ l_widname
				+ '</a><br />';
		}
		if (l_result.length == 0) l_s += lg('noSharedWidget');

		$p.print(vars['destdiv'],l_s);
	},
	/*	
	         Function: stopSharing
                                $p.app.pages.stopSharing                                
                                stop sharing a page

	*/
	stopSharing:function(v_tabId)
	{
		var response=confirm(lg("msgUnshareConfirm"));
		if (response==1)
		{
			$p.ajax.call(posh["scr_unsharepage"],
				{
					'type':'execute',
					'variables':"id="+v_tabId,
					'callback':
					{
						'function':$p.app.pages.stopSharingConfirmation
					}
				}
			);
		}
	},
	stopSharingConfirmation:function()
	{
		tab[$p.app.tabs.sel].shared = 0;
		$p.app.tabs.refresh($p.app.tabs.sel);
	},
    /*	
	         Function: refreshWidgetsNotLoaded
                                $p.app.pages.refreshWidgetsNotLoaded                                
                                refresh all widget not loaded of a custom page

	*/
    refreshWidgetsNotLoaded:function(v_tab)
    {
        if (v_tab == indef)
            v_tab = $p.app.tabs.sel;

        for (var i = 0;i < tab[v_tab].module.length;i++)
        {
            if (tab[v_tab].module[i].format == 'R' && !tab[v_tab].module[i].isLoaded)
            {
                tab[v_tab].module[i].refresh();
            }
        }
    },
    /*
		Function: getModifiedPages
                                $p.app.pages.getModifiedPages
                                
                                get and return pages modified by admin
                      return :
                                hash containing modified page information
	*/
    getModifiedPages:function()
    {
        var l_pages = [];

        for (var i = 0;i < tab.length;i++)
        {
            if (tab[i].status == 1)
            {
                l_pages.push({'id':tab[i].id,'title':tab[i].label,'status':tab[i].status});
            }
        }
        return l_pages;
    },
	/*
		Function: refresh
                                $p.app.pages.refresh
                                
                                Refresh the page linked to a tab

	*/
	refresh: function(v_tab)
	{
		if (v_tab == indef) v_tab = $p.app.tabs.sel;

		// remove all objects
		var l_inc = 0;
		
		// remove widgets
		for (var j = 0; j < tab[v_tab].module.length; j ++)
		{
			tab[v_tab].module[j].destruct();
		}
		
		// Remove cells
		while ($("maintr" + tab[v_tab].id + '_' + l_inc) != null)
		{
			var l_obj = $("maintr" + tab[v_tab].id + '_' + l_inc);

			for (var i = 1; i < tab[v_tab].cells.length; i++)
			{
				if (tab[v_tab].cells[i] && tab[v_tab].cells[i].obj && tab[v_tab].cells[i].row == l_inc)
				{
					l_obj.removeChild(tab[v_tab].cells[i].obj);
					delete(tab[v_tab].cells[i].obj);
					delete(tab[v_tab].cells[i].nbWidgets);
				}
			}
			
			l_inc ++;
		}
		// remove the columns table
		(tab[v_tab].root).removeChild($('home' + tab[v_tab].id));

		// recreate all objects
		$p.app.pages.init();
	},
	/*
		Function: addNewPage
                                $p.app.pages.addNewPage
                                
                                Create a new page in the portal

	*/
	addNewPage: function()
	{
		var l_title = ''+lg('lblNewtab');
		var status = 2;

        var l_title = "";
        if (l_title == "") l_title = lg('lblNewpage');
        
		$p.app.pages.newEmpty(l_title,0,2);
		
		return false;
	},
	changeName: function(id)
	{
		if($('pageform'+id)) {
			if($('tabsname'+id)) {
				$p.print('tabsname'+id,$('newtabinput'+id).value);
			} else {
				if($('tabinput'+id))
					$('newtabinput'+id).value = $('tabinput'+id).value;
			}
		}
		
		return false;
	},
	getPagesModel: function(pid)
	{
		$p.ajax.call(posh["xmlpublicpages"]+"?widgets=1",
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.pages.initPagesModel,
					'variables':{
						'pid':pid
					}
				},
				'source':'xml'
			}
		);
		
	},
	initPagesModel: function(response,vars)
	{
		var i = 0;
		var j = 0;
		$p.app.pages.pagesModel[i] = "";
		while (response.getElementsByTagName("page")[i])
		{
			$p.app.pages.pagesModel[i] = {};
			
			var l_result=response.getElementsByTagName("page")[i];
			$p.app.pages.pagesModel[i].id = $p.ajax.getVal(l_result,"id","int",false,0);
			$p.app.pages.pagesModel[i].pagename = $p.ajax.getVal(l_result,"name","str",false,"--");
			$p.app.pages.pagesModel[i].widgets = [];

			widgets = '';
			while (response.getElementsByTagName("widgets"+$p.app.pages.pagesModel[i].id+"")[j])
			{
				var l_wresult=response.getElementsByTagName("widgets"+$p.app.pages.pagesModel[i].id+"")[j];
				
				$p.app.pages.pagesModel[i].widgets[j] = $p.ajax.getVal(l_wresult,"name","str",false,"--");
				widgets += $p.ajax.getVal(l_wresult,"name","str",false,'--')+", ";
				j++;
			}
			if(widgets.length>100) {
				widgets = widgets.substring(0,100);
				widgets = widgets.substring(0,widgets.lastIndexOf(','))+",...";
			}
			tmp = $p.app.pages.pagesModel[i].pagename.charAt(0).toUpperCase();
			tabname = tmp+""+$p.app.pages.pagesModel[i].pagename.substring(1, $p.app.pages.pagesModel[i].pagename.length);
			$p.app.pages.pagesModel[i].data = '<div style="overflow:hidden;"><u>'+tabname+'</u></div>';
			if(widgets!='') {
				$p.app.pages.pagesModel[i].data += '<div style="padding-top:10px;text-align:left;" class="newPagesModules">'+lg('lblModules')+' :</div>';
				$p.app.pages.pagesModel[i].data += '<div style="text-align:left;" class="newPagesModules">'+widgets+'</div>';
			} else {
				$p.app.pages.pagesModel[i].data += '<div style="padding-top:10px;text-align:left;">'+lg('lblModules')+' : '+lg('lblNoModule')+'</div>';
			}
			i++;
		}
		$p.app.pages.selectPagesModel(vars['pid'],0);
		
		return false;
	},
	selectPagesModel: function(pid,m) {
		$p.print("pagesmodel"+pid,'<div style="height:100%;padding-top:25%;"><img src="../images/ico_waiting.gif" /></div>');		
		if($p.app.pages.pagesModel[0].data == "" || $p.app.pages.pagesModel[0].data==indef) {
			$p.print("pagesmodelctn"+pid,'<div style="text-align:center;padding-top:20%;padding-bottom:20%;height:98px;">'+lg('msgNoPagesModel')+'</div></div>');
			
			$p.show('selnewmodelpage'+pid,'none');
			return false;
		}
		inc = $('pagesmodelinc'+pid).value;
		if(m=='previous' && inc>0) {
			inc--;
		}
		if(m=='next' && inc<($p.app.pages.pagesModel.length-1)) {
			inc++;
		}
		if(inc==0)
			$p.show('pagesmodel_arrow_prev'+pid,'none');
		else
			$p.show('pagesmodel_arrow_prev'+pid,'block');
		if(inc==$p.app.pages.sharedTab.length-1)
			$p.show('pagesmodel_arrow_right'+pid,'none');
		else
			$p.show('pagesmodel_arrow_right'+pid,'block');
		$p.print("pagesmodel"+pid,$p.app.pages.pagesModel[inc].data);
		$('pagesmodelinc'+pid).value = inc;
		
		return false;
		
	},
	/*
		Function: getSharedTab
                                $p.app.pages.getSharedTab
                                
                                Get all shared tabs
                     Parameters:
                     
                                pid - tab id
	*/
	getSharedTab: function(pid)
	{
		
		$p.ajax.call(posh["xml_getsharedtab"],
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.pages.initSharedTabData,
					'variables':{
						'pid':pid
					}
				}
			}
		);
		
	},
	/*
		Function: initSharedTabData
                                $p.app.pages.initSharedTabData
                                
                                Initialize shared tab variable
                     Parameters:
                     
                                response - XML object 
                                vars (array) - variables (optionnal)
	*/
	initSharedTabData: function(response,vars) {
		var i=0;
		var j=0;
		$p.app.pages.sharedTab[i] = "";
		
		lblsharedby = lg('sharedBy');
		tmp = lblsharedby.charAt(0).toUpperCase();
		lblsharedby = tmp+""+lblsharedby.substring(1, lblsharedby.length);
		
		while (response.getElementsByTagName("tab")[i])
		{
			
			var l_result=response.getElementsByTagName("tab")[i];
			id = $p.ajax.getVal(l_result,"id","int",false,0);
			
			tabname = $p.ajax.getVal(l_result,"name","str",false,'--');
			userid = $p.ajax.getVal(l_result,"user_id","int",false,0);
			username = $p.ajax.getVal(l_result,"long_name","str",false,'--');
			tabtype = $p.ajax.getVal(l_result,"type","int",false,1);
			tabparam = $p.ajax.getVal(l_result,"param","str",false,"/");
			
			$p.app.pages.sharedTab[i] = {};
			$p.app.pages.sharedTab[i].type = tabtype;
			$p.app.pages.sharedTab[i].id = id;
			$p.app.pages.sharedTab[i].param = tabparam;
			
			j=0;
			widgets = '';
			while (l_result.getElementsByTagName("widgets")[j] && j<11) {
				var l_wresult=l_result.getElementsByTagName("widgets")[j];
				widgets += $p.ajax.getVal(l_wresult,"wname","str",false,'')+", ";
			
				j++;
			}

            if(widgets.length>63) {
				widgets = widgets.substring(0,63);
				widgets = widgets.substring(0,widgets.lastIndexOf(','))+",...";
			}
			
			tmp = tabname.charAt(0).toUpperCase();
			tabname = tmp+""+tabname.substring(1, tabname.length);
			$p.app.pages.sharedTab[i].data = '<div style="overflow:hidden;"><u>'+tabname+'</u></div>';
			$p.app.pages.sharedTab[i].data += '<div style="padding-top:10px;text-align:left;overflow:hidden;"  class="newPagesModules">'+lblsharedby+' '+username+'</div>';
			

			if(widgets!='' && tabtype==1) {
				$p.app.pages.sharedTab[i].data += '<div style="padding-top:10px;text-align:left;" class="newPagesModules">'+lg('lblModules')+' :</div>';
				$p.app.pages.sharedTab[i].data += '<div style="text-align:left;" class="newPagesModules">'+widgets+'</div>';
			}

			if( tabtype == 2 ) {
				$p.app.pages.sharedTab[i].data += '<div style="padding-top:10px;text-align:left;">'+lg('lblWebPage')+' : <a href="'+tabparam+'" target="_blank">'+tabparam+'</a></div>';
			}
			if(widgets == '' && tabtype==1) {
				$p.app.pages.sharedTab[i].data += '<div style="padding-top:10px;text-align:left;">'+lg('lblModules')+' : '+lg('lblNoModule')+'</div>';
			}
	
			i++;
		}
		$p.app.pages.selectSharedTab(vars['pid'],0);
		
		return false;
	},
	/*
		Function: selectSharedTab
                                $p.app.pages.selectSharedTab
                                
                                Select the shared tab into the variable
								
                     Parameters:
                     
                                pid - tab id
                                m - indice
	*/
	selectSharedTab: function(pid,m) {
		$p.print("sharedtab"+pid,'<div style="height:100%;padding-top:25%;"><img src="../images/ico_waiting.gif" /></div>');	
		if($p.app.pages.sharedTab[0].data == "" || $p.app.pages.sharedTab[0].data==indef) {
			$p.print("sharedtabctn"+pid,'<div style="text-align:center;padding-top:20%;padding-bottom:20%;">'+lg('msgNoSharedTabs')+'</div></div>');
			
			$p.show('selnewsharedtabpage'+pid,'none');
			return false;
		}
		inc = $('sharedtabinc'+pid).value;
		if(m=='previous' && inc>0) {
			inc--;
		}
		if(m=='next' && inc<($p.app.pages.sharedTab.length-1)) {
			inc++;
		}
		if(inc==0)
			$p.show('sharedtab_arrow_prev'+pid,'none');
		else
			$p.show('sharedtab_arrow_prev'+pid,'block');
		if(inc==$p.app.pages.sharedTab.length-1)
			$p.show('sharedtab_arrow_right'+pid,'none');
		else
			$p.show('sharedtab_arrow_right'+pid,'block');
		$p.print("sharedtab"+pid,$p.app.pages.sharedTab[inc].data);
		$('sharedtabinc'+pid).value = inc;
		
		return false;
		
	},
	/*
		Function: selectNewPage
                                $p.app.pages.selectNewPage
                                
                                Select new page type
                     Parameters:
                     
                                ptyp - tab type
                                pid - tab id
	*/
	selectNewPage: function(ptyp,pid)
	{
		var typ = 1;
		var l_title = $('newtabinput'+pid).value;
		var param = '';
		var pidold = pid;
		
		$p.show("message","block");
		$p.show("menus","block");
		$p.show("vmenu","block");
		window.location.hash = "#tab/"+pid;
		
		switch(ptyp) {
			case 'empty':
				typ = 1;
				$p.app.pages.suppress($p.app.tabs.sel,true,false);
				$p.app.pages.newEmpty(l_title,pidold);
				break;
			case 'web':
				typ = 2;
				if($('newpageweburl'+pid).value!='http://') {
					$p.app.pages.suppress($p.app.tabs.sel,true,false);
					$p.app.pages.newHtmlPage($('newpageweburl'+pid).value,l_title,pidold);
				}else{
					$p.app.alert.show(lg('linkMissing'),3);
				}
				break;
			case 'shared':
				typ = $p.app.pages.sharedTab[inc].type;
				inc = $('sharedtabinc'+pid).value;
				$p.app.pages.close('newmod');
				$p.app.pages.loadSharedPortal($p.app.pages.sharedTab[inc].id,typ,indef,false,false,pid);
				break;
			case 'model':
				inc = $('pagesmodelinc'+pid).value;
				$p.app.pages.suppress($p.app.tabs.sel,true,false);
				$p.app.pages.loadPublicPage($p.app.pages.pagesModel[inc].id,$p.app.pages.pagesModel[inc].pagename,pid);
				typ = 3;
				break;
			default:break;
		}
	},
	/*
		Function: createPageForm
                                $p.app.pages.createPageForm
                                
                                Generate a form page creation
                     Parameters:
                     
                                response - XML object 
                                vars (array) - variables (optionnal)
	*/
	createPageForm: function(response,vars)
	{
		var l_s = '';
		$p.show("message","none");
		$p.show("advise","none");
		$p.show("vmenu","none");
		if(vars)
			$p.app.pages.openCreatedTab(response,vars);
		if(!$("pageform"+response)) {
			newPageForm = new Element('div', {'id': "pageform"+response, 'class':'createpageform'} );
			$("modules").appendChild(newPageForm);
		}
		 
		var tabName = ($p.app.tabs.sel!=999)?tab[$p.app.tabs.sel].label:lg('lblNewpage');
		l_s += '<div>\
				<div class="btn_cancelnewtab"><img src="../images/arrow_left.png" height="10" width="10" />&nbsp;<a href="#" onclick="$p.app.pages.suppress();return false;" >'+lg("lblCancel").toLowerCase()+'</a></div>\
				<div style="border:0px solid red;width: 24px;height:38px;margin-top:10px;float:left; padding-right: 10px;"><img src="../images/step1.png" alt="1" /></div>'
			 +'<div style="border:0px solid red;width:500px;padding-left:5px;">'
			 +'<div style="float: left; width: 155px;font-size: 15px; font-family: Tahoma,Arial,Verdana,sans-serif;">'+lg('lblNameNewTab')+'&nbsp;:&nbsp;</div>\
				<div style="float:left;margin-top:20px;">\
					<input type="text" value="'+tabName+'" onkeyup="$p.app.pages.changeName('+response+');" onFocus="$p.app.tools.inputFocus(this,\''+lg('lblNewpage')+'\')" onblur="$p.app.tools.inputLostFocus(this,\''+lg("lblNewpage")+'\');$p.app.tabs.submitNameChange(this);" maxlength="30" size="10" id="newtabinput'+response+'" name="newtabinput'+response+'" class="newpagename" />'
			 +'</div></div><div style="clear:left;"></div>\
		</div>';
		
		l_s += '<div style="padding-top:25px;font-size: 15px; font-family: Tahoma,Arial,Verdana,sans-serif;">\
			<div style="float:left;"><img src="../images/step2.png" alt="2"/>&nbsp;&nbsp;</div><div>'+lg('lblTypeNewTab')+'&nbsp:&nbsp;</div>';
		l_s += '</div>';
		
		l_s += '<div style="padding-top:20px;">';
		l_s += '<div style="float:left;">';
		l_s_html = '<div id="newemptypage'+response+'" class="newpagetypectn" >\
				<div class="newpagetitle">'+lg('lblEmptyPage')+'</div>';
				l_s_html += '<div style="width: 100%; border: 0px solid red; text-align: center; padding-top: 20px;height:180px;">';
					l_s_html += '<div><img src="../images/emptypage.png" alt="Empty Page"  width="70" height="70" /></div>';
					
						l_s_html += '<div class="newpagetypechoose"  style="margin-top:68px;"><center>';
							l_s_btn = '<a href="#" onclick="$p.app.pages.selectNewPage(\'empty\','+response+');return false;" name="selemptypage'+response+'" id="selemptypage'+response+'"/>'+lg('lblChoice')+'</a>';
						l_s_html += $p.html.roundBox(   l_s_btn,'#fff','80px','#C9C9C9')
						//l_s_html += '<input type="button"  class="btn_selectnewtab" onclick="$p.app.pages.selectNewPage(\'empty\','+response+');return false;" value="'+lg('lblChoice')+'" name="selemptypage'+response+'" id="selemptypage'+response+'"/>';
						
						l_s_html += '</center></div>';
					
					l_s_html += '</div>';
				l_s_html += '<div style="width:100%;text-align: center;padding-top:10px;font-size: 12px; font-family: Tahoma,Arial,Verdana,sans-serif;">'+lg('lblEmptyPageComment')+'</div>';
			l_s_html += '</div>';
		l_s += $p.html.roundBox(   l_s_html,'#EBEBEB','220px','#C9C9C9');
		
		l_s += '</div>';
			
		l_s += '<div style="border:1px solid white;float:left;height;220px;width:10px;"></div>';
		
		l_s += '<div style="float:left;">';
		l_s_html = '<div id="newpageweb'+response+'" class="newpagetypectn" >\
				<div class="newpagetitle">'+lg('lblWebPage')+'</div>\
					<div style="width: 100%; border: 0px solid red; text-align: center; padding-top: 20px;height:130px;">\
						<div><img src="../images/pageweb.png" alt="Web page"  width="70" height="70" /></div>\
						<div style="text-align:left;padding-left:8px;padding-top: 5px;font-size: 12px; font-family: Tahoma,Arial,Verdana,sans-serif;">&nbsp;'+lg('lblEnterUrl')+'&nbsp;:&nbsp;</div>\
						<div style="padding-left:5px;padding-top:5px;"><input type="text" value="http://" class="newpageweburl" maxlength="100" size="10" id="newpageweburl'+response+'" name="newpageweburl'+response+'" /></div>\
					</div>';
						l_s_html += '<div class="newpagetypechoose" style="margin-top:11px;"><center>';
							l_s_btn = '<a href="#" onclick="$p.app.pages.selectNewPage(\'web\','+response+');return false;" name="selnewpageweb'+response+'" id="selnewpageweb'+response+'"/>'+lg('lblChoice')+'</a>';
						l_s_html += $p.html.roundBox(   l_s_btn,'#fff','80px','#C9C9C9');
						l_s_html += '</center></div>';
						
				l_s_html +='<div style="width:100%;text-align: center;padding-top:28px;font-size: 12px; font-family: Tahoma,Arial,Verdana,sans-serif;">'+lg('lblNewPageWebComment')+'</div>\
			</div>';
		l_s += $p.html.roundBox(   l_s_html,'#EBEBEB','220px','#C9C9C9');
		l_s += '</div>';
			
		l_s += '<div style="border:1px solid white;float:left;height;220px;width:10px;"></div>';
		
		if($p.app.user.id > 0) {
			l_s += '<div style="float:left;">';
				l_s_html = '<div id="newsharedtabpage'+response+'" class="newpagetypectn" >\
					<div class="newpagetitle">'+lg('lblSharedTabs')+'</div>';
					l_s_html += '<div id="sharedtabctn'+response+'" class="newsharedtabselect">';
					l_s_html += '<center>';
							l_s_html += '<div class="arrow_prev" style="height:120px;" onclick="$p.app.pages.selectSharedTab('+response+',\'previous\');return false;" >';
							l_s_html += '<div style="margin-top:55px;"><img src="../images/arrow_left_gray.png" height="10" width="6" id="sharedtab_arrow_prev'+response+'" /></div>';
							l_s_html += '</div>';
							
							l_s_html += '<div style="border:0px solid #C0C0C0;width: 150px;height: 120px;float:left;margin-top:5px;padding-left:10px;padding-right:12px;font-size:15px;" >';
							l_s_btn = '<div id="sharedtab'+response+'" style="width:150px;"><img src="../images/ico_waiting.gif" /></div>';
							l_s_html += $p.html.roundBox(   l_s_btn,'#EBEBEB','160px','#C9C9C9');
							l_s_html += '</div>';
							
							l_s_html += '<div class="arrow_next" onclick="$p.app.pages.selectSharedTab('+response+',\'next\');return false;" style="height:120px;">';
							l_s_html += '<div style="margin-top:55px;"><img src="../images/arrow_right_gray.png" height="10" width="6"  id="sharedtab_arrow_right'+response+'" /></div>';
							l_s_html += '</div>';
                            l_s_html += '<div style="margin-left:-15px;">'+lg('lblor')+'&nbsp;<a href="#" style="font-size:12px;color:black;" onclick="$p.app.pages.searchSharedPages();return false;" />'+lg('lblSearchSharedTab')+'</a></div>';
							l_s_html += '<input type="hidden" id="sharedtabinc'+response+'" value="0"/>';
						l_s_html += '</center><div style="clear:left;"></div>';
						
						l_s_html += '<div class="newpagetypechoose" style="margin-top:20px;"><center>';
							l_s_btn = '<a href="#" onclick="$p.app.pages.selectNewPage(\'shared\','+response+');return false;" name="selnewsharedtabpage'+response+'" id="selnewsharedtabpage'+response+'"/>'+lg('lblChoice')+'</a>';
						l_s_html += $p.html.roundBox(   l_s_btn,'#fff','80px','#C9C9C9');
						l_s_html += '</center></div>';
						
					l_s_html += '</div>';
					l_s_html += '<div style="width:100%;text-align: center;padding-top:53px;font-size: 12px; font-family: Tahoma,Arial,Verdana,sans-serif;">'+lg('lblSharedTabsComment')+'</div>';
				l_s_html += '</div>';		
			l_s += $p.html.roundBox(   l_s_html,'#EBEBEB','220px','#C9C9C9');
			l_s += '</div>';

			l_s += '<div style="border:1px solid white;float:left;height;220px;width:10px;"></div>';
		
			l_s += '<div style="float:left;">';
				l_s_html = '<div id="newmodelpage'+response+'" class="newpagetypectn">\
						<div class="newpagetitle">'+lg('lblPageTemplates')+'</div>\
						<div id="pagesmodelctn'+response+'" style="margin-left:12px;">\
						<center>';
							l_s_html +='<div class="arrow_prev" onclick="$p.app.pages.selectPagesModel('+response+',\'previous\');return false;" >';
							l_s_html += '<div style="margin-top:55px;"><img src="../images/arrow_left_gray.png" height="10" width="6"  id="pagesmodel_arrow_prev'+response+'" /></div>';
							l_s_html += '</div>';
							
							//l_s_html += '<div style="border:1px solid #C0C0C0;width: 150px;height: 150px;float:left;margin-top:5px;padding-left:15px;padding-right:12px;font-size:15px;" id="pagesmodel'+response+'"><img src="../images/ico_waiting.gif" /></div>';
							
							l_s_html += '<div style="border:0px solid #C0C0C0;width: 150px;height: 120px;float:left;margin-top:5px;padding-left:10px;padding-right:12px;font-size:15px;" >';
							l_s_btn = '<div id="pagesmodel'+response+'" style="width:150px;"><img src="../images/ico_waiting.gif" /></div>';
							l_s_html += $p.html.roundBox(   l_s_btn,'#EBEBEB','160px','#C9C9C9');
							l_s_html += '</div>';
							
							l_s_html += '<div class="arrow_next" onclick="$p.app.pages.selectPagesModel('+response+',\'next\');return false;">';
							l_s_html += '<div style="margin-top:55px;"><img src="../images/arrow_right_gray.png" height="10" width="6"  id="pagesmodel_arrow_right'+response+'" /></div>';
							l_s_html += '</div>';
							l_s_html += '<input type="hidden" id="pagesmodelinc'+response+'" value="0"/>';
						l_s_html += '</center><div style="clear:left;"></div>';
													
						l_s_html += '<div class="newpagetypechoose" style="margin-top:4px;"><center>';
							l_s_btn = '<a href="#" onclick="$p.app.pages.selectNewPage(\'model\','+response+');return false;" name="selnewmodelpage'+response+'" id="selnewmodelpage'+response+'"/>'+lg('lblChoice')+'</a>';
						l_s_html += $p.html.roundBox(   l_s_btn,'#fff','80px','#C9C9C9');
						l_s_html += '</center></div>';
					l_s_html += '</div>';
					l_s_html += '<div style="width:100%;text-align: center;padding-top:25px;font-size: 12px; font-family: Tahoma,Arial,Verdana,sans-serif;">'+lg('lblPageTemplatesComment')+'</div></div>';
			l_s += $p.html.roundBox(   l_s_html,'#EBEBEB','220px','#C9C9C9');
			l_s += '</div>';
		}
		l_s += '</div>';
		

		
		
		$p.print("pageform"+response,l_s);
		if($p.app.user.id > 0) {
			$p.app.pages.getSharedTab(response);
			$p.app.pages.getPagesModel(response);
		}
		return false;
	}
}



//************************************ PAGES COLUMNS FUNCTIONS***************************************************************************************************************
/*
    Class: $p.app.pages.columns
    
         Pages columns functions
         
         Page architecture
         
         modules<page id>: id called v_tab or tab_id or $p.app.tabs.sel, used as key in tab hash
         
                home<page id>, html table containing columns
                
                    manintr<page id>, first row where columns are placed
                    
                        col<page id>_<col number> : td element col_number is incremented from 1 to n
                
                                module<page id>_module id : div containing widget
                                
                        In popup, cell0 can be used if there is no more column
                        
                canvas<page id>
                
                    canvas, fullscreen block 
                
*/
$p.app.pages.columns={
	/*
	         Function: $p.app.pages.columns.createAll

                                Create personalized page columns
                    
                    Parameters:
                                v_tab - tab sequence ID
	*/
	createAll:function(v_tab)
	{
		//initialise Cols array, replaced
		//tab[v_tab].cells.length=0;

        tab[v_tab].cells = [];
        var tab_id = tab[v_tab].id;

		//condition suppressed with 1.0.0 : better placement without and reused for version 1.1
		var l_table = new Element('table', 
			{
				'styles': 
				{
					'width': '100%',
					'height': '100%',
					'border': '0'
				},
                'id':'home' + tab_id,
				'cellSpacing': '4'
		    }
		);
        
		var l_tbody = new Element('tbody');
        
		var l_nextColspan = 0,
			l_extraCell = 0,
			l_cellNb = $p.app.pages.templates[tab[v_tab].template].nbCells;

		if (tab[v_tab].showType==0)
        {
			for (var j = 0;j < $p.app.pages.templates[tab[v_tab].template].rows.length; j++)
			{
				var l_tr = new Element('tr',
					{
						'width': '100%',
						'height': '100%'
					}
				);
				l_tr.id = 'maintr' + tab_id + '_' + j;
				
				var l_currentColspan = l_nextColspan,
					l_inc = 0;
				l_nextColspan = 0;

				for (var i = l_currentColspan;i < tab[v_tab].colnb - l_extraCell;i++)
				{
					var l_columnPosition = $p.app.pages.columns.getPosition(i+1,tab[v_tab].colnb);

					// check if the cell is defined in the template
					if ($p.app.pages.templates[tab[v_tab].template].rows[j].cols[l_inc])
					{
						var l_currentCell = $p.app.pages.templates[tab[v_tab].template].rows[j].cols[l_inc];
						l_tr.appendChild($p.app.pages.columns.create(l_currentCell.id, i, v_tab, j, l_columnPosition, l_currentCell.colspan, l_currentCell.rowspan, l_currentCell.maxWidgets));
						
						// increase number of column if colspan is > 1
						if (l_currentCell.colspan > 1)
							i = i + (l_currentCell.colspan - 1);
						
						if (l_currentCell.rowspan > 1)
							l_nextColspan = l_nextColspan + (l_currentCell.rowspan - 1);
						
						l_inc ++;
					}
					else
					{
						l_cellNb ++;
						// cols added on the right are using the whole height
						l_extraCell ++;
						l_tr.appendChild($p.app.pages.columns.create('cell' + l_cellNb, i, v_tab, j, l_columnPosition));
					}
				}
				
				l_tbody.appendChild(l_tr);
			}
        } 
        else
        {
            l_tr.appendChild($p.app.pages.columns.create('cell1', 1, v_tab));
        }
		
        $p.app.pages.columns.size(v_tab);
		l_table.appendChild(l_tbody);
		(tab[v_tab].root).appendChild(l_table);
		
		//Create element canvas
        var l_canvas=new Element('div',
            {
                'styles':
                {
                    'width': '100%',
                    'display':'none'
                },
                'class':'mycanvas',
                'id':'canvas'+tab_id
            }
        );
        (tab[v_tab].root).appendChild(l_canvas); 

        
	},
	/*
	         Function: $p.app.pages.columns.init
                                
                                Initialize move for each widget in a tab
                                
                                Initialize column & modules behaviors
                                
                                do not initialize the columns if already done
                    
                    Parameters:
                        
                                v_tab - tab sequence ID
                                
                     See also: <$p.app.widgets.initMove>           
	*/
	init:function(v_tab)
	{
		if (tab[v_tab].moveIsInit )  return;
		tab[v_tab].moveIsInit = true;
		//check if widget move init is applied on a widget or on a page
        //object operator, you can update if you what you are doing ;)
		var l_cptStart=($('cell0')!=!null && tab[v_tab].cells.length==1 || tab[v_tab].type!=1)  ?   0   :   1;
        var l_cptEnd = (tab[v_tab].type!=1)     ?       tab[v_tab].cells.length-1       :       tab[v_tab].cells.length;

        for (var i=l_cptStart;i<l_cptEnd;i++)
        {
            for(var l_item=0; l_item < (tab[v_tab].cells[i].obj).childNodes.length-1; l_item++)
            {
                var l_mod = (tab[v_tab].cells[i].obj).childNodes[l_item];
                $p.app.widgets.move.set(l_mod,"module",tab[v_tab].cells,"multidim",true,v_tab);
            }
        }
	},
	/*
	         Function: $p.app.pages.columns.create
                                
                                Create a personalized page column
                                
                                This column is added in tab[$p.app.tabs.sel].cells
                                 
                                 used in <$p.app.pages.columns.add>, <$p.app.pages.columns.isEmpty>,<$p.app.pages.columns.sup>
                                
                    Parameters:
                        
			colid - column ID
			v_tab - tab sequence ID
                                v_position - position of the column in the table (first, middle, last)
           
           
                    Returns:
                    
                                td element
                       
                       See also:
                       called from <$p.app.pages.columns.add>
                    
	*/
	create:function(v_cellId, v_col, v_tab, v_row, v_position, v_colspan, v_rowspan, v_maxNbWWidget)
	{
        if (v_position == indef) v_position = 'middle';
		if (v_row == indef) v_row = 0;
		if (v_colspan == indef) v_colspan = 1;
		if (v_rowspan == indef) v_rowspan = $p.app.pages.templates[tab[v_tab].template].nbRows;
		if (v_maxNbWWidget == indef) v_maxNbWWidget = __NBWIDGETBYCOL;

        //tabs id are names in the administration, tab id is the current tab id (integer) in portal
        var tab_id  = ($p.app.env=="admin")     ?       v_tab
                                                :       tab[v_tab].id;

		// get Cell id
		var l_cellId = parseInt(v_cellId.replace('cell',''), 10);

		tab[v_tab].cells[l_cellId] = {
			'obj' : new Element('td', 
			{
				'styles':
				{
					'verticalAlign': 'top',
					'height':'100%'
				},
				'colspan':v_colspan,
				'rowspan':v_rowspan,
                'class':'column' + v_position + ' column',
				'id': v_cellId + '_' + tab_id 
			}),
			'col' : v_col,
			'row' : v_row,
			'colspan' : v_colspan,
			'rowspan' : v_rowspan,
			'nbWidgets' : {'max':v_maxNbWWidget,'nb':0,'byformat':{},'toomany':false}
		};

		return tab[v_tab].cells[l_cellId].obj;
	},
	/*
	         Function: $p.app.pages.columns.size
                                
                                resize width of a column based on columns numbers
                    
                    Parameters:
                        
                                v_tab - tab sequence ID
	*/
	size:function(v_tab)
	{
		//if newspaper mode, the cols are not sized (=> if no module on col1, col1 width=0)
        //compute number of columns in a tab 
		if (tab[v_tab].showType==0)
		{
			for (var i=1;i < tab[v_tab].cells.length;i++)
			{
				// set column size if colspan = 1 (else it would impact the cells with colspan = 1)
				if (tab[v_tab].cells[i] && tab[v_tab].cells[i].colspan == 1)
					(tab[v_tab].cells[i].obj).setStyle("width",((100/tab[v_tab].colnb).toInt())+"%");
			}
		}
	},
	/*
	         Function: $p.app.pages.columns.add

                                Add a new column, tab[$p.app.tabs.sel].colnb gives number of column (init in <$p.app.tabs.object>)
                                
                    
                    Parameters:
                        
                                v_id - column ID
	*/
	add:function(v_id)
	{
		// Add columns (until selected one)
		var l_obj = $('maintr' + tab[$p.app.tabs.sel].id + '_0');
		// add the new cols
		if (tab[$p.app.tabs.sel].showType==0)
		{
            var nbcol = tab[$p.app.tabs.sel].colnb + 1;
			for (var colid = tab[$p.app.tabs.sel].colnb;colid < v_id;colid++)
			{
				// get the id of new cell
				var l_cellId = tab[$p.app.tabs.sel].cells.length;

                //create a td for each col set in hash tab[ $p.app.tabs.sel].cols[i] 
                //then append this html object in maintr document object
                //add a column in table maintr
				l_obj.appendChild( $p.app.pages.columns.create('cell' + l_cellId, colid, $p.app.tabs.sel) );
                //add void div in array object
				(tab[$p.app.tabs.sel].cells[l_cellId].obj).appendChild($p.app.widgets.endList());
				//tab[$p.app.tabs.sel].cells[l_cellId].nbWidgets={'max':__NBWIDGETBYCOL,'nb':0,'byformat':{},'toomany':false};
			}
			$p.app.pages.columns.size($p.app.tabs.sel);
		}
		tab[$p.app.tabs.sel].colnb = v_id;
       
	},
	/*
	         Function: $p.app.pages.columns.sup

                                Remove a column from maintr and hash object 
                    
                    Parameters:
                        
                                v_id - column ID
	*/
	sup: function(v_id)
	{
		// check if template do not prevent the removal of the columns
		if (v_id < $p.app.pages.templates[tab[$p.app.tabs.sel].template].nbColsMin)
		{
			$p.app.alert.show(lg('columnNotRemovable'));
			return false;
		}

		var l_obj = $('maintr' + tab[$p.app.tabs.sel].id + '_0');
		
		if (tab[$p.app.tabs.sel].showType == 0)
		{
			//for (var i = tab[$p.app.tabs.sel].colnb;i > v_id;i--)
			for (var i = 1; i < tab[$p.app.tabs.sel].cells.length; i++)
			{
				if (tab[$p.app.tabs.sel].cells[i].col >= v_id)
				{

					//remove a column in maintr
					l_obj.removeChild(tab[$p.app.tabs.sel].cells[i].obj);
					delete(tab[$p.app.tabs.sel].cells[i].obj);
					delete(tab[$p.app.tabs.sel].cells[i].nbWidgets);
					
					// Caution : this can only work if cells removed are alone in a column
					tab[$p.app.tabs.sel].cells.length -= 1;
					//tab[$p.app.tabs.sel].widgetsbycol.length -= 1;
				}
			}
			$p.app.pages.columns.size($p.app.tabs.sel);
		}
        //how many columns in maintr
		tab[$p.app.tabs.sel].colnb = v_id;
		
		return true;
	},
	/*
	         Function: $p.app.pages.columns.isEmpty
                                
                                Check that a column is empty before removal
                    
                    Parameters:
                        
                                v_id - column ID
                                
                    Returns:
                    
                                true or false
	*/
	isEmpty:function(v_id)
	{
		var l_ret=true;
		if (v_id<tab[$p.app.tabs.sel].colnb)
		{
			for (var i=0;i<tab[$p.app.tabs.sel].module.length;i++)
			{
				if (tab[$p.app.tabs.sel].module[i].cell > v_id)
                {
                    l_ret=false;
                    $p.app.alert.show(lg("msgColSup",tab[$p.app.tabs.sel].module[i].cell));
                    break;
                }
			}
		}
		return l_ret;
	},
    /*
            Function: $p.app.pages.columns.getPosition
                    get classname depending position of the column in page
             
                Parameters: 
                    colid - column id
                    nbcol - number of columns
            
    */
    getPosition: function (colid,nbcol) {
        return l_position = (    colid == 1      ? 'first' : 
                                (colid == nbcol) ? 'last' : 
                                                   'middle'
                            );        
    },
    /*
                Function: $p.app.pages.columns.renameClasses
                
                    rename class in each column
                 
                 Parameters: 
                        l_nbCol - number of columns in page
    */
    renameClasses: function (l_nbCol) {
        var tab_id = $p.app.tabs.sel;
		
        for (var i = 1; i < tab[tab_id].cells.length;i++)
		{
            (tab[tab_id].cells[i].obj).className = 'column' + $p.app.pages.columns.getPosition(tab[tab_id].cells[i].col,l_nbCol);
        }
    },
    /*
            Function: $p.app.pages.columns.analyzeColumns
            
                Analyse each column to cmpute number of widget, call to <$p.app.pages.columns.checkNbWidgetInaCol>
             
              Parameters:
                    celltoUse - col to use by default
                    
               Returns: celltoUse      
    */
    analyzeColumns: function (celltoUse)
	{    
        for (var i = 1; i < tab[$p.app.tabs.sel].cells.length; i++)
		{
			if (tab[$p.app.tabs.sel].cells[i].nbWidgets['max'] > 0)
			{
				//check if number of widget in column is under __NBWIDGETBYCOL
				if ($p.app.pages.columns.checkNbWidgetInaCol( $p.app.tabs.sel, i, false) ) {
					celltoUse = i;
					//change TooManyWidgetsinCol only if __NBWIDGETBYCOL is > 0
					//by default to false, but reset 
					tab[$p.app.tabs.sel].cells[i].nbWidgets['toomany'] = false;
					break;
				}
			}
        } 
        return celltoUse;
    },
    /*
                Function: $p.app.pages.columns.checkNbWidgetInaCol
                
                    Function to use with __NBWIDGETBYCOL, check number of widget in a column
                    return false if number is too big
                    
                    Set hash tab[tabid].widgetsbycol[colid]['nb']
                    
                    return true elsewhere and if __NBWIDGETBYCOL == 0
                    
               Parameters:
                    tabid - id of a page
                    colid - id of a column
                    force - force checking
                
               Returns: true or false
               
               See Also: <$p.app.pages.columns.analyzeColumns>
       */
    checkNbWidgetInaCol: function (tabid,cellid,force)
	{
        if (tab[tabid].cells[cellid].nbWidgets['max'] == 0 && !force) {
            return true;
        }

        tab[tabid].cells[cellid].nbWidgets['toomany'] = true;        
        
        //tabs id are names in the administration, tab id is the current tab id (integer) in portal
        var tab_id  = ($p.app.env=="admin")     ?       tabid
                                                :       tab[tabid].id;
                                                        
        var nbwid = $p.app.pages.columns.getNbWidgetsInACell(tabid, cellid);

        if ( tab[tabid].cells[cellid].nbWidgets) {
             $p.app.pages.columns.setNbWidgetByCol(tabid,cellid,nbwid);
        }
        if (tab[tabid].cells[cellid].nbWidgets['max'] > 0 && nbwid >= tab[tabid].cells[cellid].nbWidgets['max'] ) {
            tab[tabid].cells[cellid].nbWidgets['toomany'] = true;
            return false;
        }
        
        return true;
    },
	getNbWidgetsInACell: function(v_tab, v_cell)
	{
		var widnodes = tab[v_tab].cells[v_cell].obj.childNodes;
        
        var nbwid = 0;
        for (var i = 0; i <= widnodes.length;i++) {
            var node = widnodes[i];
            if (node && node.className && node.className=="module") {
                nbwid++;
            }
        }
		return nbwid;
	},
    /*
                Function: $p.app.pages.columns.checkNbWidgetinAnotherTab
    */
    checkNbWidgetinAnotherTab: function (tabid,cellid,force) {
		// check only if the number of widgets is restricted in the defined cell
        if (tab[tabid].cells[cellid].nbWidgets['max'] == 0 && !force) {
            return true;
        }
		
        var nbwid = tab[tabid].cells[cellid].nbWidgets['nb'];

         if (tab[tabid].cells[cellid].nbWidgets['max'] > 0 && nbwid >= tab[tabid].cells[cellid].nbWidgets['max'] ) {
            tab[tabid].cells[cellid].nbWidgets['toomany'] = true;
            return false;
        }
        return true;
    },
    /*
            Function: $p.app.pages.columns.getNbofWidgetByCol
            
                    returns number of widget in a column
                    
                    from tab[tabid].widgetsbycol[colid]['nb']
               
               Pramaters: 
                tabid - id of page
                colid - id of column
    */
    getNbofWidgetByCol: function (tabid,colid) {
        return tab[tabid].widgetsbycol[colid]['nb'];
    },
    /*
            Function: $p.app.pages.columns.setNbWidgetByCol
            
                        set tab[tabid].widgetsbycol[colid]['nb']
                        
              Parameters:
                        tabid - id of page
                        colid - id of column
                        how - nb of widget in column
    */
    setNbWidgetByCol: function (tabid,cellid,nb) {
        tab[tabid].cells[cellid].nbWidgets['nb'] = nb;
    },
    /*
            Function: $p.app.pages.columns.updateNbWidgetByCol
            
                        update tab[tabid].widgetsbycol[colid] : number of column in a widget
               
               Parameters:
                        tabid - id of page (see $p.app.tabs.sel)
                        colid - id of column
                        how - (integer) 1 to increment, -1 to decrement
    */
    updateNbWidgetByCol: function (tabid,cellid,nb,format)
	{   
        if ($p.app.env != "admin" && tab[tabid].type!=2)
		{
			tab[tabid].cells[cellid].nbWidgets['nb'] += nb;
			tab[tabid].cells[cellid].nbWidgets['byformat'][format] += nb;
		}
    },
	reallocate: function(v_tab)
	{
		if (v_tab == indef) v_tab = $p.app.tabs.sel;
		
		var l_nextColspan = 0,
			l_cellNb = $p.app.pages.templates[tab[v_tab].template].nbCells;
		tab[$p.app.tabs.sel].cells = [];
		for (var j = 0;j < $p.app.pages.templates[tab[v_tab].template].rows.length; j++)
		{
			var l_currentColspan = l_nextColspan,
				l_inc = 0;
			l_nextColspan = 0;
			for (var i = l_currentColspan;i < tab[v_tab].colnb;i++)
			{
				if ($p.app.pages.templates[tab[v_tab].template].rows[j].cols[l_inc])
				{
					var l_currentCell = $p.app.pages.templates[tab[v_tab].template].rows[j].cols[l_inc];
					var l_cellId = parseInt((l_currentCell.id).replace('cell',''), 10);
					if (tab[v_tab].cells[l_cellId])
						tab[v_tab].cells[l_cellId].col = i;
					
					// increase number of column if colspan is > 1
					if (l_currentCell.colspan > 1)
						i = i + (l_currentCell.colspan - 1);
					
					if (l_currentCell.rowspan > 1)
						l_nextColspan = l_nextColspan + (l_currentCell - 1);
					
					l_inc ++;
				}
				else
				{
					l_cellNb ++;
					if (tab[v_tab].cells[l_cellNb])
						tab[v_tab].cells[l_cellNb].col = i;
				}
			}
		}
	},
	getNbOfColumn: function(v_tab,v_templateId)
	{
		if (v_tab == indef) v_tab = $p.app.tabs.sel;
		if (v_templateId == indef) v_templateId = tab[v_tab].template;
		
		// get the latest cell that is containing widgets
		var l_inc = tab[v_tab].cells.length - 1;

		while (l_inc > 0 && $p.app.pages.columns.getNbWidgetsInACell(v_tab, l_inc) == 0)
		{
			l_inc --;
		}
		
		if (l_inc > $p.app.pages.templates[v_templateId].nbCells)
		{
			 return $p.app.pages.templates[v_templateId].nbCols + (l_inc - $p.app.pages.templates[v_templateId].nbCells);
		}
		else
		{
			return $p.app.pages.templates[v_templateId].nbCols;
		}
	},
	highlight: function()
	{
		if ($p.app.tabs.sel >= 0 && tab[$p.app.tabs.sel])
			$p.setClass('home' + tab[$p.app.tabs.sel].id, 'highlight');
	},
	stopHighlight: function()
	{
		if ($p.app.tabs.sel >= 0 && tab[$p.app.tabs.sel])
			$p.setClass('home' + tab[$p.app.tabs.sel].id, '');
	}
}

//************************************ WIDGETS FUNCTIONS ***************************************************************************************************************
/*
    Class: $p.app.widgets
    
         Widgets functions
*/
$p.app.widgets={
	showAdminProperties:false,
	dragging:false,
    rights:[],
	/*
		Function: initMenu
                               $p.app.widgets.initMenu - init the widget menu
                               
                               Modules class
	*/
	initMenu:function()
	{
		$p.app.menu.options.push(
			{
				"id":"pwidget",
				"label":lg("Widgets"),
				"desc":lg("addContentTxt"),
				"icon":"ico_menu_add.gif",
				"seq":20,
				//"action":"$p.app.menu.widget.build()",
				'action':'',
				"type":'',
				'opened':true,
				'default_opened':true,
				'subOptions':[
					{
						'id':'addmenu_2',
						'label':'<form name="mod__search" onsubmit="$p.app.menu.widget.getSearch(document.mod__search.inputsearchwidget.value,0);return false;">'
							+ '<div class="searchbox" style="float: left;">'
							+ '<input class="searchboxtext" autocomplete="off" id="inputsearchwidget" name="inputsearchwidget" type="text" onFocus=\'$p.app.tools.inputFocus(this,"'+lg("searchModuleByKeywords")+'")\' onBlur=\'$p.app.tools.inputLostFocus(this,"'+lg("searchModuleByKeywords")+'");$p.tags.autocompletion.hide();\' value="'+lg("searchModuleByKeywords")+'" onkeyup=\'$p.tags.autocompletion.get("inputsearchwidget")\' style="color:#aaaaaa;font-size: 0.85em;width:180px;" /> '
							+ '<input type="image" name="buts" class="searchboxbtn" src="../styles/themes/classic_blue/header_menu_searchbtn.png" />'
							+ '</div>'
							+ '&nbsp;'+tooltip("helpTags")
							+ '<div class="float_correction"></div>'
							+ '<div id="listmod" style="width:225px;text-align:left;display: none;"></div>'
							+ '</form>',
						'condition':$p.app.menu.widget.isExplorerDisplayed,
						'type':'form',
						'opened':false
					},
					{
						'id':'addmenu_3',
						'label':lg("lblExplore"),
						'action':$p.app.menu.widget.displayExplorerForm,
						'condition':$p.app.menu.widget.isExplorerDisplayed,
						'opened':false
					},
					{
						'id':'addmenu_1',
						'label':lg("lblAddRSS"),
						'action':$p.app.menu.widget.displayRSSForm,
						'condition':$p.app.menu.widget.isRssOptionsDisplayed,
						'opened':false
					},
					{
						'id':'addmenu_5',
						'label':lg("lblArchive2"),
						'action':$p.app.menu.widget.displayMyModule,
						'condition':$p.app.menu.widget.isMyModuleDisplayed,
						'opened':false
					}
				]
			}
		);
	},
	/*
		Function: $p.app.widgets.object
        
                               $p.app.widgets.object *(Constructor)*
                               
                               Modules class
                               
                               Build a new object for each modules
                               with variables, arrays, hash (object) and methods
                               
		
                      Parameters:
       
			colid (int) - column id  where is the module  
			pos (int) - position of the column in a column 
                            posj   (int) -  Position of widget in the page
			height (int) - height of the module (not application for modules with type R & M) 
			id (int) - id of the module (int)
			link (str) - link of the module provider  - data form database is filed site
			name (str) - name of the module - str
                            vars (str) - variables
			minModSize (int) - minimal size of the module 
			sizable (integer)  - is the module resizable? 
			size  (int)  - ? value form database is minmodsize
			url (str) - ?
			x (int) - left position (if not aligned) 
			y (int) - top position (if not aligned) 
			uniq_db (int) - uniq id of the module 
			format (str) - type of the module (R=rss, M=included module, I= framed module,U=Url)
			nbvars (int) - number of users configuration variables used
			tab  (int)  - id of the tab where the module is (int)
			blocked (boolean) - is the module blocked in the page
			minimized (boolean) - display status of the module (true=minimized, false=normal)
			usereader (boolean) - for RSS modules, is the rss reader is used to read articles
			autorefresh (boolean) - is the module refreshed every x minutes ?
			icon (str) - icon of the module
			isLoaded - loading status of the module (indef=not loaded, false=loading, true=loaded)
			header (str) - HTML header of the module
			footer (str) - HTML footer of the module
			auth (str) - for RSS authentified feeds
                                views (str) - views (home or canvas) canvas for full-screen (full-portal)
                                l10n - l10n parameters, lang comma separated
                                sharedmd5key - md5 sharing key parameters,
                                group_access - list of user groups that can see the widget
                        
         See also:

            <$p.app.pages.createFromXml>, <$p.app.widgets.displayMod>
	*/
	object:function(cellid,pos,posj,height,
                        id,link,name,vars,minModSize,sizable,size,
                        url,x,y,uniq_db,format,nbvars,
                        tab,blocked,minimize,usereader,
                        autorefresh,icon,isLoaded,
                        header,footer,auth,views,l10n,sharedmd5key,group_access)
	{
		this.cell=cellid;
        this.newcell=cellid;
		this.pos=pos;
		this.posj=posj;
		this.height=height;
		this.size=size;
		this.id=id;
		this.link=link;
		this.name=name;
		this.vars=vars;
		this.minModSize=minModSize;
		this.updModSize=sizable;
		this.url=url;
		this.y=y;
		this.x=x;
		this.uniq=uniq_db;
		this.format=format;
		this.newpos=pos;
		this.newposj=posj;
		this.newx=x;
		this.newy=y;
		this.nbvars=nbvars;
        this.newWidget=false;
        this.paramNotFound=1;
		this.tab = (tab == indef ? 0 : tab);
		this.blocked = (blocked ? blocked : 0);
		this.minimized=(minimize && minimize==1)?true:false;
		this.usereader=(usereader && usereader==1)?true:false;
		this.autorefresh=(autorefresh && autorefresh==1)?true:false;
		this.icon=(icon==indef || icon=="")	?"box0_"+this.id:icon;
		if( format=="R" && (icon==indef || icon=="") ) {
			this.icon = "box0_"+this.id+".ico";
			var myImage = new Image;
			myImage.src = this.icon;
			myImage.onerror=function() { this.icon = "box0_"+this.id}
		}
        this.sharedmd5key  = sharedmd5key;
        this.group_access  = group_access || 0;
		this.isLoaded=isLoaded;
		this.header=header;
		this.content='';
		this.footer=footer;
		this.nbunread=0;
		this.start=0;
		this.auth=auth;
        this.className="module";
        this.views = {};
        if (!this.currentView) {
            this.currentView='home';
        }
        this.existsView=$p.app.widgets.existsView;
        $p.app.widgets.setViews(this,views);
        this.l10n=l10n;   
		this.create=$p.app.widgets.create;
		this.destruct=$p.app.widgets.destruct;
		this.show=$p.app.widgets.show;
		this.hide=$p.app.widgets.hide;
		this.refresh=$p.app.widgets.refresh;
		this.changeVar=$p.app.widgets.changeVar;
		this.placeinCol=$p.app.widgets.placeinCol;
		this.placeonTop=$p.app.widgets.placeonTop;
		this.placeonBottom=$p.app.widgets.placeonBottom;
		this.placeAfter=$p.app.widgets.placeAfter;
		this.placeBefore=$p.app.widgets.placeBefore;
		this.bringToFront=$p.app.widgets.bringToFront;
		this.setHeight=$p.app.widgets.setHeight;
		this.hdrColor=$p.app.widgets.hdrColor;
		this.getIcon=$p.app.widgets.getIcon;
		this.minimize=$p.app.widgets.reduce;
		this.setName=$p.app.widgets.setName;
		this.setIcon=$p.app.widgets.setIcon;

	},
    /*
                function: $p.app.widgets.setViews
                
                        set views (home or canvas)
            */
    setViews: function (newObject,views) {
            if (!views || views=='') {   return; }
            var reg=new RegExp(",","g");
            var listViews=views.split(reg);
            if (listViews && listViews[0]) {
                for (var i = 0; i < listViews.length;i++) {
                    newObject.views[listViews[i]]=true;
                }
            } else {
                newObject.views[views]=true;
            }  
            
    },
    /*
                    function: $p.app.widgets.existsView
                    
                    return true is view exists for this widget
                    
                    use as method of a widget
            */
    existsView: function (view) {
        if (this.views[view]) {return this.views[view];}
        return false;
    },
	/*
		Function: $p.app.widgets.create
        
                                Create a module object and add it in column
                 
                 Parameters: 
                        wHeight - height
                        celltoUse - column to use when adding a new widget
	*/
	create:function( wHeight, celltoUse,cellid)
	{
        var l_tabPos = $p.app.tabs.idToPos(this.tab),
			l_obj = null;

		celltoUse = (celltoUse == indef) 
			? $p.app.pages.templates[tab[l_tabPos].template].rows[0].cols[0].id 
			: celltoUse;
		
        if( wHeight != indef )
			widgetHeight = wHeight;
            
		$p.plugin.hook.launch('app.widgets.create.start');
            
		//for a new widget without uniq ID
		$p.app.widgets.attributeUniq(this, l_tabPos);

		// create widget object
		l_obj = document.createElement("div");
		l_obj.style.display="none";
		//place new modules
		//use tab.id because it do not change even if the tab is moved
        if (this.currentView == 'canvas') {
            l_obj.id="canvas"+this.tab+"_"+this.uniq;
            l_obj.className="canvas";  
            this.className="canvas";
        } else {
            
            l_obj.id="module"+this.tab+"_"+this.uniq;
            l_obj.className=$p.app.widgets.currentClass;
            this.className=$p.app.widgets.currentClass;
        }

		if (tab[l_tabPos].moduleAlign)  {
			l_obj.style.position = '';
		}
		else    {
			l_obj.style.position="absolute";
			l_obj.style.width=this.minModSize+"px";
			l_obj.style.left=this.x+widgetDecalX+"px";
			l_obj.style.top=this.y+widgetDecalY+"px";
		}
        
		//attach DIV to the corresponding cell. if new module this.col=0 => col[0] need to be created
		if (this.currentView == 'canvas')
        {
            this.canvas.appendChild(l_obj);
        }
        else if (tab[l_tabPos].moduleAlign || l_tabPos == -1)
        {
            //add widget in a column WIDGETCOL
			if (this.cell != -1)
            {
				if ((tab[l_tabPos].showType==0 
                    || this.cell == 1) && this.cell<tab[l_tabPos].cells.length)
                {
                    (tab[l_tabPos].cells[this.cell].obj).appendChild(l_obj);
                    //$p.app.pages.columns.updateNbWidgetByCol(l_tabPos,this.cell,1);
                } 
                else {
                    (tab[l_tabPos].cells[celltoUse.replace('cell','')].obj).appendChild(l_obj);
                    $p.app.pages.columns.updateNbWidgetByCol(l_tabPos,celltoUse,1);
                }
			}
			else    {
                   
                    //tabs id are names in the administration, tab id is the current tab id (integer) in portal
                    var tab_id  = ($p.app.env=="admin")     ?       l_tabPos
                                                            :       tab[l_tabPos].id;
                    ($p.get('cell' + celltoUse + '_' + tab_id)).appendChild(l_obj);
                    $p.app.pages.columns.updateNbWidgetByCol(l_tabPos,celltoUse,1);
			}
		}
		else    {
			(tab[l_tabPos].root).appendChild(l_obj);
		}

		var tableObj1 = new Element('table',
			{
				'id': 'bmod'+this.tab+'_'+this.uniq,
				'class': 'bmod',
				'cellspacing': '0',
				'cellpadding': '0'
			}
		);		   

		var tbodyObj1 = new Element('tbody');
		var trObj1 = new Element('tr');
		var tdObj1 = new Element('td',
			{
				'events':
				{
                    'mouseover': function()
					{
						$p.app.widgets.showOptions(this.uniq,true);			
					},
					'mouseout': function()
					{
                        $p.app.widgets.showOptions(this.uniq,false);																
					}
				},
				'class': 'headmod'
			} 
		);
		tdObj1.uniq=this.uniq;
															
		var tableObj2 = new Element('table',
			{
				'id': 'hmod'+this.tab+'_'+this.uniq,
				'class': 'hmod',
				'cellspacing': '0',
				'cellpadding': '0',
				'width': '100%'
			}
		);
		var tbodyObj2 = new Element('tbody');
		var trObj2 = new Element('tr');
		
		var tdObj2 = new Element('td', 
			{
				'class': 'lefttopcornermod'
			}
		);
		tdObj2.set('html',$p.img('',1,1));
		tdObj2.inject(trObj2);
			
		var tdObj3 = new Element('td', 
			{
				'width': '16px'
			}
		);						
		if (__showicon
               &&  this.currentView != 'canvas') 
		{
			var aObj1 = new Element('a',
				{
					'events':((this.blocked == 1 || !__showModuleMinimize  || tab[l_tabPos].controls == 'N')
						? '' 
						:
							{
								'click': function()
								{
									$p.app.widgets.minimize(this.uniq);
									return false;														
								}
																			
							}),
					'href': '#'		
				} 
			);
			aObj1.icon=this.icon;
			var _src = this.icon;
			if( this.icon.substr(0,2)!=".." ) {
				_src = _dirImg+this.icon;
			}
			aObj1.uniq = this.uniq;
			var iObj1=new Element('img',
				{
					'events':((this.blocked == 1 || !__showModuleMinimize || tab[l_tabPos].controls == 'N')
						? ''
						:
							{
								'mouseover': function()
								{
									if (tab[l_tabPos].module[$p.app.widgets.uniqToId(this.uniq)].minimized) 
									{
										this.src="../images/maximize.gif";
									}
									else
									{
										this.src="../images/minimize.gif";
									}
								},
								'click': function()
								{
									if(this.src==__LOCALFOLDER+"images/minimize.gif"){this.src="../images/maximize.gif";}
									else{this.src="../images/minimize.gif";}
								},
								'mouseout': function()
								{
									$p.app.widgets.changeIcon($p.app.widgets.uniqToId(this.uniq));	
								}
							}),
					'id': 'module' + this.tab + '_' + this.uniq + '_icon',
					'src': _src,
					'width': '16',
					'height': '16',
					'class': 'imgmid'
				}
			);
			iObj1.icon = this.icon;
			iObj1.uniq = this.uniq;
			iObj1.inject(aObj1);												
			aObj1.inject(tdObj3);						
		}
        
		tdObj3.inject(trObj2);

		var tdObj4 = new Element('td', 
			{
				 'width': '100%'
		    }
		);
								
		var divObj1 = new Element('div',
			{
				'id': 'module' + this.tab + '_' + this.uniq + '_h',
				'class': 'titmod'
			}
		 );	
			 
		if(__showModuleTitle)	
        {  
            divObj1.set('html',this.name);   
        }
		else    
        {   
            divObj1.set('html',"");     
        }
		
		divObj1.inject(tdObj4);
		tdObj4.inject(trObj2);
										
		var tdObj5 = new Element('td', 
			{
				'class': 'optmodhide',
				'id': 'module'+this.tab+'_'+this.uniq+'_o'
			}
		);					
		var divObj2 = new Element('div',
			{
				'id': 'module'+this.tab+'_'+this.uniq+'_o',
				'class': 'optmoda',
				'nowrap': 'nowrap'
			}
		 );	

		//display configure button if allowed or useful
		if ((__showModuleConfigure 
            &&  tab[l_tabPos].controls == 'Y'
			&& (this.nbvars>0 || __widgetTitleUpdatable)
            && this.currentView != 'canvas'
            && this.blocked != 1)
            || $p.app.user.id==-1)     {
    			var aObj2 = new Element('a',
    				{
    					'events':
    					{
    						'click': function()
    						{
    							return $p.app.widgets.param.show(this.uniq,this.tab);													
    						}
    					},
    					'href': '#'
    				}
    			);			
    			aObj2.uniq = this.uniq;
    			aObj2.set('html',lg("lblConfigure"));
    			aObj2.inject(divObj2);
    			var bObj2 = new Element('b');
    			bObj2.set('html','&nbsp;');
    			bObj2.inject(divObj2);
		}
												
		if ( $p.app.user.id != 0
             && __useSharing
			 && $p.app.user.type != 'N'
             && this.group_access==0
			 && $p.app.env != "tutorial")     {
    			var aObj3 = new Element('a',
    				{
    					'events': {
    									'click': function()
    									{
    										$p.friends.menu(3,$p.app.widgets.uniqToId(this.uniq));
                                            return false;
    									}
    							  },
    					'href': '#',
    					'title':lg('lblShareModule')
    				} 
    			);
    			aObj3.uniq = this.uniq;
                aObj3.set('html',$p.img('s.gif',13,11,lg("lblShareModule"),'optmod_share'));
    			//aObj3.set('html',$p.img("ico_bar_share.gif",13,11,lg("lblShareModule")));
    			aObj3.inject(divObj2);
    			var bObj3 = new Element('b');
    			bObj3.set('html','&nbsp;');
    			bObj3.inject(divObj2);
		}

		if ((__showModuleRefresh &&  tab[l_tabPos].controls == 'Y') || $p.app.user.id == -1)
		{
			var aObj4 = new Element('a',
				{
					'events':
					{
						'click': function()
						{
							return tab[l_tabPos].module[$p.app.widgets.uniqToId(this.uniq)].refresh(0);		
						}
					},
					'href': '#',
					'title':lg('lblRefresh')
				} 
			);
			aObj4.uniq = this.uniq;
			 
            //aObj4.set('html',$p.img("ico_refresh.gif",12,11,lg("lblRefresh")));
			aObj4.set('html',$p.img('s.gif',12,11,lg("lblRefresh"),'optmod_refresh'));
			aObj4.inject(divObj2);
			var bObj4 = new Element('b');
			bObj4.set('html','&nbsp;');
			bObj4.inject(divObj2);
		}

        //minimize button
		if (    
                (
                    (this.blocked != 1  
                    &&  __showModuleMinimize
                    &&  tab[l_tabPos].controls == 'Y')
                    || $p.app.user.id == -1
                )
                && this.currentView != 'canvas'
            )
		{			
			var aObj5 = new Element('a',
				{
					'events': {
									'click': function()
									{
										$p.app.widgets.minimize(this.uniq);
										return false;							
									}
							  },
					'href': '#',
					'title':lg('minimize')
				} 
			);
			aObj5.uniq = this.uniq;
			//aObj5.set('html',$p.img((this.minimized?"ico_maximize.gif":"ico_minimize.gif"),12,11,"minimize","","imgminimize"+this.uniq));
			aObj5.set('html',$p.img('s.gif',12,11,lg("minimize"),(this.minimized ? 'optmod_maximize' : 'optmod_minimize'),'imgminimize'+this.tab+'_'+this.uniq));
			aObj5.inject(divObj2);
			var bObj5 = new Element('b');
			bObj5.set('html','&nbsp;');
			bObj5.inject(divObj2);
		}
        
        //display button full-screen if view canvas exists
        if (
                this.existsView('canvas')
                && this.currentView != 'canvas'
                && tab[l_tabPos].moduleAlign
            ) 
        {
  
            var this_id = this.id;   
			var aObj6 = new Element('a',
				{
					'events': {
									'click': function()
									{
										return $p.app.widgets.maximize(this.uniq,this_id);				
									}
							  },
					'href': '#',
                    'alt':lg('maximize'),
					'title':lg('maximize')
				} 
			);
			aObj6.uniq = this.uniq;
			//aObj6.set('html',$p.img("ico_view_fullpage.gif",12,11,lg("lblSuppress")));
			aObj6.set('html',$p.img('s.gif',12,11,lg("maximize"),'optmod_viewfullpage'));
			aObj6.inject(divObj2);	
			var bObj6 = new Element('b');
			bObj6.set('html','&nbsp;');
			bObj6.inject(divObj2);		
        }   

		//suppress button					
		if (    (
                    ((this.blocked == 0 || (this.url).indexOf('moddef') != -1)
                    && (__showModuleClose || $p.app.user.id==-1)
                    && tab[l_tabPos].controls == 'Y')
                    || $p.app.user.id == -1
                )
                && this.currentView != 'canvas'
				&& $p.app.env != "tutorial"
           ) 
		{

			var aObj6 = new Element('a',
				{
					'events': {
									'click': function()
									{
										$p.app.widgets.suppress(this.uniq,true);
										return false;						
									}
							  },
					'href': '#',
					'title':lg('lblClose')
				} 
			);
			aObj6.uniq = this.uniq;
			//aObj6.set('html',$p.img("ico_close.gif",12,11,lg("lblSuppress")));
			aObj6.set('html',$p.img('s.gif',12,11,lg("lblSuppress"),'optmod_close'));
			aObj6.inject(divObj2);	
			var bObj6 = new Element('b');
			bObj6.set('html','&nbsp;');
            
                bObj6.inject(divObj2);
		}

        if (this.currentView == 'canvas' ) {
            var this_id = this.ModulePositionId;         
			var aObj6 = new Element('a',
				{
					'events': {
									'click': function()
									{
										$p.app.widgets.homeView(this_id);
										return false;						
									}
							  },
					'href': '#',
                    'alt':'reduce',
					'title':'reduce'
				} 
			);
			aObj6.uniq = this.uniq;

            //aObj6.set('html',$p.img('ico_view_widget.gif',12,11,lg("reduce")));
            aObj6.set('html','&laquo; ' + lg('back'));
            aObj6.inject(divObj2);	

			var bObj6 = new Element('b');
			bObj6.set('html','&nbsp;');
			bObj6.inject(divObj2);				
        }

		var bObj61 = new Element('b');
		bObj61.set('html','&nbsp;');
		bObj61.inject(divObj2);
					
		divObj2.inject(tdObj5);
		tdObj5.inject(trObj2);
		var tdObj6 = new Element('td', 
			{
				'class': 'righttopcornermod'
			}
		);
		tdObj6.set('html',$p.img('',1,1));
		tdObj6.inject(trObj2);
		trObj2.inject(tbodyObj2);
		tbodyObj2.inject(tableObj2);
		tableObj2.inject(tdObj1);
		var divObj3 = new Element('div',
			{
				'id': 'editbar'+this.tab+'_'+this.uniq,
				'class': 'editbox'
			}
		 );
		divObj3.inject(tdObj1);	
		tdObj1.inject(trObj1);
		trObj1.inject(tbodyObj1);
			
		var trObj3 = new Element('tr');
		 tdObj7 = new Element('td',
			{
				'class': 'contentborder'
			}
		);	
		var divObj4 = new Element('div',
			{
				'id': 'module'+this.tab+'_'+this.uniq+'_i',
				'class': 'content',
				'styles':
                        {
							'width': '99%',
							'height': '100%'
                        }
			}
		);				 
		var tableObj3 = new Element('table', 
			{
				'border': '0',
				'cellspacing': '0',
				'cellpadding': '5',
				'align': 'center',
				'width': '100%',
				'height': '100%'
			}
	    );
												   
		var tbodyObj3 = new Element('tbody');
		var trObj4 = new Element('tr', 
			{
				'id': 'moduletr'+this.tab+'_'+this.uniq+'_c'
			}
	    );
		var tdObj8 = new Element('td',
			{
				'id': 'module'+this.tab+'_'+this.uniq+'_c',
				'styles':{
					'display' :(this.minimized?'none':''),
                    'vertical-align': 'top'
				}
			} 
		);

		if (this.format=="I" || this.format=="G") {
            var FrameHeight = this.height+"px";
            var scrollMode = 'no';
            if (this.currentView=='canvas')  {
                scrollMode="auto";
            } else {
                if (this.updModSize == 2 || this.updModSize == 3) {
                    scrollMode = 'auto';
                }
            }

            if (this.format=="I") {
                var scr_url = $p.url.addurlseparator(this.url)+"pid="+$p.app.user.id
                                                              +"&prof="+this.tab
                                                              +"&p="+this.uniq
                                                              +"&view="+this.currentView
                                                              +"&format=I"
                                                              +"&l10n="+this.l10n
                                                              +"&"+this.vars.replace('#','%23')
                                                              +"&sharedmd5key="+this.sharedmd5key;
            }
            if (this.format=="G") {
                var scr_url = $p.url.addurlseparator(this.url)+"pid="+$p.app.user.id
                                                              +"&p="+this.uniq
                                                              +"&view="+this.currentView
                                                              +("&"+this.vars).replace(/&/g,"&up_");
            }
            
            if (this.format=="I" || this.format=="G") {
                var iframeObj1 = new Element('iframe',
                    {
                        'id': 'modfram'+this.tab+'_'+this.uniq,
                        'name': 'modfram'+this.tab+'_'+this.uniq,
                        'src': scr_url,
                        'scrolling':scrollMode,
                        'frameborder':'0',
                        'marginwidth':'0',
                        'marginheight':'0',
                        'height':FrameHeight,
                        'width':'100%',
                        'z-index':'auto',
                        'styles':{
                            'margin':'0',
                            'padding':'0'
                        }
                    } 
                );	
            }

			//iframeObj1.set('html','Issue with module display.');
			var aObj7 = new Element('a',
				{
					'href': posh["contact"],
					'target': '_blank'
				} 
			);				
			aObj7.set('html','Contact us');	

			aObj7.set('html','Contact us');	
			//aObj7.inject(iframeObj1);
			iframeObj1.inject(tdObj8);
			
			var brObj1 = new Element('br');	
			brObj1.inject(tdObj8);				
		}

		if (this.format == "U") {
            // if the domain is out of the website domain, no need to use Posh internal information
            var remoteUrl = this.url;
            remoteUrl = $p.string.trim(remoteUrl);
            var reg = /^http/;
            if ( remoteUrl.match(reg) ) {
                var regdomain = /__LOCALFOLDER/;
                
                if ( remoteUrl.match(regdomain) ) {
					// The parameter of addurlseparator must contain all of the url
                    remoteUrl = $p.url.addurlseparator(remoteUrl)
                        +"pid="+$p.app.user.id
                        +"&prof="+this.tab
                        +"&view="+this.currentView
                        +"&format=U"
                        +"&p="+this.uniq
                        +"&plg="+__lang+"&"+this.vars.replace('#','%23');
                } else {
                    var regPoint = /\?$/;
                    remoteUrl = remoteUrl.replace(regPoint,'');
                }
            } else {
                remoteUrl = $p.url.addurlseparator(remoteUrl)
                        +"pid="+$p.app.user.id
                        +"&prof="+this.tab
                        +"&view="+this.currentView
                        +"&format=U"
                        +"&p="+this.uniq
                        +"&plg="+__lang+"&"+this.vars.replace('#','%23');
            }

            var scrollMode = 'no';
            if (this.currentView=='canvas')  {
                scrollMode="auto";
            } else {
                if (this.updModSize == 2 || this.updModSize == 3) {
                    scrollMode = 'auto';
                }
            }
			var iframeObj2 = new Element('iframe',
				{
					'styles': {
						'height': this.height+"px",
						'width': '100%'
					},
					'id': 'modfram'+this.tab+'_'+this.uniq,
					'name': 'modfram'+this.tab+'_'+this.uniq,
					'src': remoteUrl,
					'frameborder':'no', 
					'marginwidth':'0', 
					'marginheight':'0',
					'scrolling':scrollMode,
					'z-index':'auto'
				  } 
			);
			iframeObj2.inject(tdObj8);
			var brObj2 = new Element('br');	
			brObj2.inject(tdObj8);										
		}
		
		if (this.format=="D") //HTML integrated in Div 
		{
			tdObj8.set('html',this.content);
		}
		
		if (this.format=="H") 
		{
			var iframeObj3 = new Element('iframe',
				{
					'styles': {
									'height': this.height+"px",
									'width': '100%'
							  },
					'id': 'modfram'+this.tab+'_'+this.uniq,
					'name': 'modfram'+this.tab+'_'+this.uniq,
					'src': '',
					'frameborder':'no', 
					'marginwidth':'0', 
					'marginheight':'0', 
					'scrolling':'no',
					'z-index':'auto'
				} 
			);		
			//iframeObj3.set('html','Issue with module display. ');
			var aObj9 = new Element('a',
				{
					'href': posh["contact"],
					'target': '_blank'
				} 
			);
			aObj9.set('html','Contact us');
			aObj9.inject(iframeObj3);
			iframeObj3.inject(tdObj8);
			var brObj3 = new Element('br');	
			brObj3.inject(tdObj8);										
		}

		if (this.format == "R" || this.format == "M") {
			tdObj8.set('html',lg("lblLoading"));
		}
					
		tdObj8.inject(trObj4);
		trObj4.inject(tbodyObj3);
		tbodyObj3.inject(tableObj3);
		tableObj3.inject(divObj4);		
		
		//Div+image used to force minimal width
		var divObj5 = new Element('div',
			{
				'styles':
				{
					'height': '1px'
				}
			} 
		);			 
		divObj5.set('html',$p.img("s.gif",this.minModSize,1,indef,indef,"line"+this.tab+"_"+this.uniq));
		divObj5.inject(divObj4);
		
		divObj4.inject(tdObj7);
				
		if (__useNotation&&$p.app.user.id>0) 
		p_notation.buildBlock(this.uniq);

		tdObj7.inject(trObj3);	
		trObj3.inject(tbodyObj1);

		//Widget footer
		var footer_trContainer=new Element('tr');
		footer_trContainer.inject(tbodyObj1);
		var footer_tdContainer=new Element('td');
		footer_tdContainer.inject(footer_trContainer);
		var footer_table = new Element('table',
			{
				'id': 'fmod'+this.tab+'_'+this.uniq,
				'class': 'fmod',
				'cellspacing': '0',
				'cellpadding': '0',
				'width': '100%'
			}
		);
		footer_table.inject(footer_tdContainer);
		var footer_tbody = new Element('tbody');
		footer_tbody.inject(footer_table);
		var footer_tr = new Element('tr');
		footer_tr.inject(footer_tbody);
		var footer_leftcorner = new Element('td', 
			{
				'class': 'leftbottomcornermod'
			}
		);
		footer_leftcorner.set('html',$p.img('',1,1,'','dot'));
		footer_leftcorner.inject(footer_tr);
		var footer_center = new Element('td', 
			{
				'class': 'bottommod'
			}
		);
		footer_center.set('html',$p.img('',1,1,'','dot'));
		footer_center.inject(footer_tr);
		var footer_rightcorner = new Element('td', 
			{
				'class': 'rightbottomcornermod'
			}
		);
		footer_rightcorner.set('html',$p.img('',1,1,'','dot'));
		footer_rightcorner.inject(footer_tr);

		tbodyObj1.inject(tableObj1);
		tableObj1.inject(l_obj);

		//check if authentified feed or not
		var l_vars = this.vars;
		this.auth = (l_vars.indexOf("auth=") != -1 || (l_vars.indexOf("user=") != -1 && l_vars.indexOf("pass=") != -1)) ? true : false;

		//load the content
		if (this.format == "R") 
        {
            var r_id = $p.app.widgets.uniqToId(this.uniq,l_tabPos);
            $p.app.widgets.rss.refresh(r_id,l_tabPos);
        }    
		if (this.format == "M") {
            $p.app.widgets.refreshContent($p.app.widgets.uniqToId(this.uniq,l_tabPos),l_tabPos,this.sharedmd5key);
        }    
		//if (this.format=="H") refreshHtmlCont($p.app.widgets.uniqToId(this.uniq));

		if (this.format == "I" || this.format == "U" || this.format=="G")   {
			if (this.nbvars>0) {
               $p.app.widgets.param.getModuleParam($p.app.widgets.uniqToId(this.uniq,l_tabPos),l_tabPos);
            }
			else {
				$p.app.widgets.param.fillEditBox(indef,this.uniq,l_tabPos);
			}
		}
		this.hdrColor();
		this.getIcon();
		
		tabga = this.tab;
		uniqga = this.uniq;
		idga = $p.string.esc(this.id);	
        namega = $p.string.esc(this.name);
        formatga = this.format;
        
        if (this.currentView == "canvas") {
            var l_top = $p.getPos($("modules"+this.tab),"Top");
            var newHeight = Window.getHeight()-l_top-70;
            var trobj = $('moduletr'+this.tab+'_'+this.uniq+'_c');
            trobj.setStyle("height",newHeight+"px");
        }        
                
		$p.plugin.hook.launch('add_GA_Tracking');
		
        tdObj7ga = tdObj7;
		$p.plugin.hook.launch('app.widgets.create.end');

	},
	attributeUniq: function(v_widget,v_tab)
	{
		if (v_widget.uniq == 0 || isNaN(v_widget.uniq)) {
			tab[v_tab].maxUniq++;
			v_widget.uniq = tab[v_tab].maxUniq;
			$p.app.widgets.changeUniq($p.app.widgets.uniqToId(v_widget.uniq,v_tab),v_widget.uniq);
		}
	},
	/*
		Function: $p.app.widgets.destruct
                    
                    Destruct a module
	*/
	destruct:function()
	{
		$p.plugin.hook.launch('app.widgets.destruct.start');

		var l_obj = $("module" + this.tab + "_" + this.uniq);
		var l_cell = this.newcell;
			l_tabPos = $p.app.tabs.idToPos(this.tab);
		if (tab[l_tabPos].showType==1 && this.newcell!=0) l_cell=1;
		if (tab[l_tabPos].moduleAlign)  {
            //remove a widget from a column  WIDGETCOL
			if (l_obj != null && tab[l_tabPos].cells && tab[l_tabPos].cells[l_cell] &&tab[l_tabPos].cells[l_cell].obj)
				(tab[l_tabPos].cells[l_cell].obj).removeChild(l_obj);
		}
		else    {
			tab[l_tabPos].root.removeChild(l_obj);
		}

		$p.plugin.hook.launch('app.widgets.destruct.end');
	},
	/*
		Function: $p.app.widgets.refresh
                                Refresh a mdoule
                                
                     Returns:
                                
                                false
	*/
	refresh:function()
	{
		$p.plugin.hook.launch('app.widgets.refresh.start');
		var l_tabPos=$p.app.tabs.idToPos(this.tab);
		var l_id=$p.app.widgets.uniqToId(this.uniq,l_tabPos);
        if ($p.app.tabs.sel != l_tabPos) {
            //don't refresh inactive tabs, set to reload
            tab[l_tabPos].isLoaded = indef;
            return false;
        }
		tab[l_tabPos].module[l_id].isLoaded=false;

		if (this.format=="I" || this.format=="U" || this.format=="G")   {
			var l_obj=$("modfram"+tab[l_tabPos].id+"_"+this.uniq);
			if (this.format=="I")  {
                var l_url = $p.url.addurlseparator(tab[l_tabPos].module[l_id].url)
                            +"pid="+$p.app.user.id
                            +"&prof="+tab[l_tabPos].id
                            +"&format="+this.format
                            +"&view="+this.currentView
                            +"&l10n="+tab[l_tabPos].module[l_id].l10n
                            +"&p="+tab[l_tabPos].module[l_id].uniq
                            +"&plg="+__lang
                            +"&"+tab[l_tabPos].module[l_id].vars.replace('#','%23')
                            +"&sharedmd5key="+this.sharedmd5key;
            }
            else if (this.format=="G") {
                var l_url = $p.url.addurlseparator(tab[l_tabPos].module[l_id].url)
                          +"&view="+this.currentView
                          +"&pid="+$p.app.user.id
                          +"&p="+tab[l_tabPos].module[l_id].uniq
                          +("&"+tab[l_tabPos].module[l_id].vars).replace(/&/g,"&up_");
            }
			else   {
				var l_url = $p.url.addurlseparator(tab[l_tabPos].module[l_id].url);
                                +"pid="+$p.app.user.id
                                +"&prof="+tab[l_tabPos].id
                                +"&format="+this.format
                                +"&view="+this.currentView
                                +"&l10n="+tab[l_tabPos].module[l_id].l10n
                                +"&p="+tab[l_tabPos].module[l_id].uniq
                                +"&plg="+__lang
                                +("&"+tab[l_tabPos].module[l_id].vars).replace(/&/g,"&up_");
            }          
            l_obj.src=l_url;
		}
        
		if (this.format=="R")   {
			$p.app.widgets.rss.refresh(l_id,l_tabPos,true);
		}
		if (this.format=="M")   {
			$p.app.widgets.refreshContent(l_id,l_tabPos,this.sharedmd5key);
		}
        
		$p.plugin.hook.launch('app.widgets.refresh.end');        
        
		return false;
	},
	/*
		Function: $p.app.widgets.placeonTop
                                Place a module on top of a column
	*/
	placeonTop:function()
	{
		//change the position of the modules that are placed in the destination column
		var l_tabPos=$p.app.tabs.idToPos(this.tab);

		for (var i=0;i<tab[l_tabPos].module.length;i++) {
			if (tab[l_tabPos].module[i].newcell == this.newcell)
				tab[l_tabPos].module[i].newpos+=1;
			if (this.format!='R' 
                && tab[l_tabPos].module[i].format!='R') 
                    tab[l_tabPos].module[i].newposj++;
		}
		//set the position of the module added (usefull ?? treated before ??)
		this.newpos=1;
		if (tab[l_tabPos].showType==0)  var l_cell = this.newcell;
		else    var l_cell = 1;
		$p.app.widgets.placeIn(this,l_tabPos,l_cell,false);
	},
	/*
		Function: $p.app.widgets.placeonBottom
                                Place a module on the bottom of a column
                                
                     ATTENTION : the function bugs when it's used to place a widget at the bottom of the first column
                     
	*/
	placeonBottom:function(){
		//change the position of the modules that are placed in the destination column
		var l_tabPos=$p.app.tabs.idToPos(this.tab);
		var nbColumnItem=0;
		for (var i=0;i<tab[l_tabPos].module.length;i++) {
			if (tab[l_tabPos].module[i].newcell==this.newcell) {
                nbColumnItem++;
            }
			if (this.format!='R' 
                && tab[l_tabPos].module[i].format!='R') {
                    tab[l_tabPos].module[i].newposj++;
                    }
		}
		//set the position of the module added (usefull ?? treated before ??)
		this.newpos = nbColumnItem;
			
		if (tab[l_tabPos].showType==0) {
            var l_cell = this.newcell;
        }
		else {
            var l_cell = 1;
        }
        
		$p.app.widgets.placeIn(this,l_tabPos,l_cell,true);
	},
	/*
		Function: $p.app.widgets.placeAfter
                                Place a module after a target module
								
		Inputs: target =>(tab[$p.app.tabs.sel].module[i]) is the targeted module
	*/
	placeAfter:function(target){
		//change the position of the modules that are placed in the destination column
		
		var l_tabPos=$p.app.tabs.idToPos(target.tab);
		for (var i=0;i<tab[l_tabPos].module.length;i++) {
			if (tab[l_tabPos].module[i].newcell == target.newcell && tab[l_tabPos].module[i].newpos>target.newpos){
				tab[l_tabPos].module[i].newpos+=1;
				
			}
			if (this.format!='R' 
                && tab[l_tabPos].module[i].format!='R') 
                    tab[l_tabPos].module[i].newposj++;
		}
		this.newpos = target.newpos++;
		this.newcell = target.newcell;
		
		if (tab[l_tabPos].showType==0)
			var l_cell = target.newcell;
		else
			var l_cell = 1;
        
		$p.app.widgets.placeIn(this,l_tabPos,l_cell,false,target,true);
	},
	/*
	Function: $p.app.widgets.placeBefore
							Place a module before a target module
							
	Inputs: target =>(tab[$p.app.tabs.sel].module[i]) is the targeted module
	*/
	placeBefore:function(target){
		//change the position of the modules that are placed in the destination column
		var l_tabPos=$p.app.tabs.idToPos(target.tab);
		
		for (var i=0;i<tab[l_tabPos].module.length;i++) {
			if (tab[l_tabPos].module[i].newcell==target.newcell && tab[l_tabPos].module[i].newpos>=(target.newpos-1)) tab[l_tabPos].module[i].newpos+=1;
			if (this.format!='R' 
                && tab[l_tabPos].module[i].format!='R') 
                    tab[l_tabPos].module[i].newposj++;
		}
		this.newcell = target.newcell;
		this.newpos = target.newpos;
		
		
		if (tab[l_tabPos].showType==0)
			var l_cell = target.newcell;
		else
			var l_cell = 1;
        
		$p.app.widgets.placeIn(this,l_tabPos,l_cell,false,target,false);
	},
	/*
	Function: $p.app.widgets.placeIn
		Place a module 
        
	Parameters:
                module - ?
                l_tabPos - 
                l_col - 
                last - 
                target - 
                nextSibling -
	*/
	placeIn:function(module,l_tabPos,l_cell,last,target,nextSibling)
	{
		if ($("module"+module.tab+"_"+module.uniq)!=null)
		{
            
			var l_movedMod=$("module"+module.tab+"_"+module.uniq);
			if (tab[l_tabPos].moduleAlign)
			{
				if (last==true)
                {
					var l_inCell = (tab[l_tabPos].cells[l_cell].obj).lastChild;
				}
				else if (target!=indef)
                {
					var l_inCell = $("module"+target.tab+"_"+target.uniq);
				}
				else
                {
					var l_inCell = (tab[l_tabPos].cells[l_cell].obj).firstChild;
				}

				if (tab[l_tabPos].showType==0 || module.format!='R')
				{
					if (nextSibling==true)
                    {
						(tab[l_tabPos].cells[l_cell].obj).insertBefore(l_movedMod,l_inCell.nextSibling);
                        $p.app.pages.columns.updateNbWidgetByCol(l_tabPos,l_cell,1);
					}
					else 
                    {
						(tab[l_tabPos].cells[l_cell].obj).insertBefore(l_movedMod,l_inCell);
                        $p.app.pages.columns.updateNbWidgetByCol(l_tabPos,l_cell,1);
					}
                    $p.app.widgets.move.chosenCol = l_cell;
					$p.app.widgets.move.set(l_movedMod,"module",tab[l_tabPos].cells,"multidim",true,l_tabPos);
				}
				else
					$p.app.widgets.rss.reader.showArticlesList(true);
			}
			else
			{
				tab[l_tabPos].root.appendChild(l_movedMod);
                $p.app.widgets.move.chosenCol = l_cell;
				$p.app.widgets.move.set(l_movedMod,"module",tab[l_tabPos].root,"multidim",true,l_tabPos);
			}
		}
	},	
	/*
		Function: $p.app.widgets.placeinCol
                                Place a module on a column
                                
		Parameters: 
                    v_col - column id
                    v_tab - page id
                    mode -	"top" =>place on the top of a column
						"bottom" => place on the bottom of a column
						"before" => place before the target module
						"after" => place after the target module
                   target - target
	*/
	placeinCol:function(v_cell,v_tab,mode,target)
	{
        $p.plugin.hook.launch('app.widgets.placeincol.start');
		if (v_tab==indef) v_tab=$p.app.tabs.sel;

		if (!$p.app.pages.maxModReached(v_tab,v_cell))
		{
			this.newcell = v_cell;
			if(mode=="bottom"){
				this.placeonBottom();
			}
			else if(mode=="before"){
				this.placeBefore(target);
			}
			else if(mode=="after"){
				this.placeAfter(target);
			}
			else {
				this.placeonTop(); 
			}
            
            $p.app.widgets.currentClass='module';
            this.className= $p.app.widgets.currentClass; 
            this.hdrColor();            
			if (tab[v_tab].showwidgetbar == 1) $p.app.widgets.showHdr(v_tab);
			var l_vars=[];
			l_vars[0] = v_cell;
			$p.app.widgets.saveChanges(l_vars,indef,v_tab);
            
		}
        
        $p.plugin.hook.launch('app.widgets.placeincol.end');
	},
	/*
		Function: $p.app.widgets.bringToFront
                                Bring a widget to front of the page, over the others
	*/
	bringToFront:function()
	{
    
		if (!tab[$p.app.tabs.sel].moduleAlign)  {
			($("module"+tab[$p.app.tabs.sel].id+"_"+this.uniq)).setStyle("zIndex",1000);
		}
	},
	/*
		Function: $p.app.widgets.reduce
                                Minimize a widget
	*/
	reduce:function()
	{
		$p.app.widgets.minimize(this.uniq);
	},
	/*
		Function: $p.app.widgets.minimize
                                Minimize a widget
                     
                     Parameters:
                     
                                v_uniq - module uniq ID
	*/
	minimize:function(v_uniq)
	{
		var l_id = $p.app.widgets.uniqToId(v_uniq);
		if (tab[$p.app.tabs.sel].module[l_id].minimized)
        {
			$p.show("module"+tab[$p.app.tabs.sel].id+"_"+v_uniq+"_c","block");
			$p.show("module"+tab[$p.app.tabs.sel].id+"_"+v_uniq+"_i","block");
            $p.setClass('imgminimize'+tab[$p.app.tabs.sel].id+'_'+v_uniq,'optmod_minimize');

			tab[$p.app.tabs.sel].module[l_id].minimized=false;

			$p.ajax.call(posh["scr_minimize"],
				{
					'type':'execute',
					'variables':"m=0&prof="+tab[$p.app.tabs.sel].id+"&u="+v_uniq
				}
			);
		}
		else
        {
			$p.show("module"+tab[$p.app.tabs.sel].id+"_"+v_uniq+"_c","none");
			$p.show("module"+tab[$p.app.tabs.sel].id+"_"+v_uniq+"_i","none");
            $p.setClass('imgminimize'+tab[$p.app.tabs.sel].id+'_'+v_uniq,'optmod_maximize');

			tab[$p.app.tabs.sel].module[l_id].minimized=true;

			$p.ajax.call(posh["scr_minimize"],
				{
					'type':'execute',
					'variables':"m=1&prof="+tab[$p.app.tabs.sel].id+"&u="+v_uniq
				}
			);
		}
	},
	/*
		Function: $p.app.widgets.setName
                                Set widget title
                     
                     Parameters:
                     
                                v_name - module name
	*/
	setName:function(v_name)
	{
        if (!v_name) {
            v_name=$p.string.getVar(this.vars,"ptitl");
        }
        if (v_name) {
            $p.app.widgets.changeName($p.app.widgets.uniqToId(this.uniq),v_name,$p.app.tabs.idToPos(this.tab));
        }
	},
	/*
		Function: $p.app.widgets.setIcon
                                Set widget icon
                     
                     Parameters:
                     
                                v_icon - module icon
	*/
	setIcon:function(v_icon)
	{
		$p.app.widgets.changeIcon($p.app.widgets.uniqToId(this.uniq),v_icon,$p.app.tabs.idToPos(this.tab));
	},
	/*
		Function: $p.app.widgets.setHeight
                                Define module height
                     
                     Parameters:
                     
                                v_height - height applied
	*/
	setHeight:function(v_height, v_mod)
	{
		if( v_mod==indef ) {
			$p.setHeight("modfram"+this.tab+"_"+this.uniq,v_height);
		} else {
			if( v_mod == "FeedDisplayInfo" )
				$p.setHeight(v_mod,v_height);
			else
				$p.setHeight(v_mod+"_"+this.uniq,v_height);
		}
	},
	/*
		Function: $p.app.widgets.changeVar
                                Change a module parameter
                     
                     Parameters:
                     
			v_var - variable to update
			v_value - new value
	*/
	changeVar:function(v_var,v_value)
	{
        var dbuniq = this.uniq;
        //canvas management, update parent module in database
        var l_id=$p.app.widgets.uniqToId(this.uniq);
        if ( tab[$p.app.tabs.sel].module[l_id] 
                && tab[$p.app.tabs.sel].module[l_id].UniqParent
            ) 
        {
            dbuniq = tab[$p.app.tabs.sel].module[l_id].UniqParent;
            var l_id_parent = tab[$p.app.tabs.sel].module[l_id].DBIdParent;
        }
        //end canvas management
		var l_oldVars=this.vars;
		if (v_var=="")  {
			l_newVars=v_value;
		}
		else    
        {
			var l_oldValue=$p.string.getVar(l_oldVars,v_var);
			var l_newVars=l_oldVars.replace(v_var+"="+l_oldValue+"&","").replace("&"+v_var+"="+l_oldValue,"").replace(v_var+"="+l_oldValue,"");
			l_newVars=(l_newVars=="")   ?   (v_var+"="+v_value) :   
                                            (l_newVars+"&"+v_var+"="+v_value);
		}
		this.vars=l_newVars;
        if (tab[$p.app.tabs.sel].module[l_id] 
                && tab[$p.app.tabs.sel].module[l_id].UniqParent) 
        {
            tab[$p.app.tabs.sel].module[l_id_parent].vars = l_newVars;
        }
		param = "prof="+tab[$p.app.tabs.sel].id
                                    +"&un="+dbuniq
                                    +"&vars="+$p.string.esc(l_newVars)
									+"&id="+tab[$p.app.tabs.sel].module[l_id].id;
		param += (($p.string.getVar(l_newVars,"noteid")!="")?"&noteid="+$p.string.getVar(l_newVars,"noteid"):"")
				+(($p.string.getVar(l_newVars,"calid")!="")?"&calid="+$p.string.getVar(l_newVars,"calid"):"")
				+(($p.string.getVar(l_newVars,"linkid")!="")?"&linkid="+$p.string.getVar(l_newVars,"linkid"):"")
				+(($p.string.getVar(l_newVars,"taskid")!="")?"&taskid="+$p.string.getVar(l_newVars,"taskid"):"")
				+(($p.string.getVar(l_newVars,"addid")!="")?"&addid="+$p.string.getVar(l_newVars,"addid"):"");
		
		//record changes in DB
		if (__ENCRYPT_USERPREF) {
			param = $p.app.tools.encryptData(param,encryptKey);
			param = "param="+$p.string.esc(param)
		}
		
		if (l_oldVars!=l_newVars && $p.app.env!="admin")
		{
			$p.ajax.call(posh["scr_savevar"],
				{
					'type':'execute',
					'variables':param,
									
					'alarm':false
				}
			);
		}
	},
	/*
		Function: $p.app.widgets.show
                                Show a module
                               
                                Widget id can ! canvas or module
                                
                                classname can be: module canvas or tmp_module (widget newly added)
                               
                         parameters:

                                    classname - classname used to place widget, if not using 'module'
	*/
	show:function (usedClass) {
        var currentClassName =  usedClass ? usedClass  :  'module'; 
       // this.className =  currentClassName;                                          
		$p.show(currentClassName+this.tab+"_"+this.uniq,"block");

	},
	/*
		Function: $p.app.widgets.hide
                                Hide a module
	*/
	hide:function (){
        var currentClassName = this.className ? this.className  :
                                                'module';
		$p.show(currentClassName+this.tab+"_"+this.uniq,"none");
	},
	/*
		Function: $p.app.widgets.hdrColor
                                Change module header color
                                
		Parameters:

			v_uniq - uniq ID of the module
			v_style - style to applied to this module
	*/
	hdrColor:function(v_uniq,v_style,classname)
	{
		if (!v_uniq) v_uniq=this.uniq;
        var currentClassName = classname ? classname : 'module';        
		if (!v_style) v_style=$p.string.getVar(this.vars,"bcolor");
        
		var l_obj=$(currentClassName+this.tab+"_"+v_uniq);
		//see color in main.css
        if (l_obj) l_obj.className=$p.app.widgets.currentClass+v_style;
	},
	/*
		Function: $p.app.widgets.getIcon
                                Get icon information for a module
	*/
	getIcon:function()
	{
		if ($p.string.getVar(this.vars,"icon")!="") {
			this.icon=$p.string.getVar(this.vars,"icon");
		}
	},
	/*
		Function: $p.app.widgets.showOptions
                                Show / hide modules options
                                
		Parameters:

			v_uniq - uniq ID of the module
			v_status (boolean) - display status for the options
		
                     BUG: let the function name in lowercase
	*/
	showOptions:function(v_uniq,v_status)
	{
        if ($p.app.tabs.sel == -1) return;
        
		 if (tab[$p.app.tabs.sel].controls == 'N')
			return;

        var currentClassName = this.className ? this.className  :  'module';
        var l_obj = $(currentClassName + tab[$p.app.tabs.sel].id+"_"+v_uniq+"_o");
		if (l_obj) l_obj.className = (v_status ? "optmod" : "optmodhide");
	},
	/*
		Function: $p.app.widgets.changeUniq
                                Change uniq ID of a module
                                
		Parameters:

			v_id - module sequence ID
			v_uniq - new Uniq ID for the module
	*/
	changeUniq:function(v_id,v_uniq)
	{
        if ($p.app.tabs.sel == -1) return;
		if (v_uniq==indef) v_uniq=tab[$p.app.tabs.sel].maxUniq;
		$p.ajax.call(posh["scr_changeuniq"],
			{
				'type':'execute',
				'variables':"uniq="+v_uniq+"&prof="+tab[$p.app.tabs.sel].id+"&x="+tab[$p.app.tabs.sel].module[v_id].newcell+"&y="+tab[$p.app.tabs.sel].module[v_id].newpos
			}
		);
	},
	/*
		Function: $p.app.widgets.uniqToId 
                                Get module sequence ID based on its uniq ID in page
                                
		Parameters:

			v_uniq - module uniq ID
			v_tab - tab sequence ID
		
	Returns:
			 module sequence ID
	*/
	uniqToId: function(v_uniq,v_tab)
	{
		if (v_tab == indef) v_tab = ($p.app.tabs.sel < 0 ? 0 : $p.app.tabs.sel);

		for (var k = 0; k < tab[v_tab].module.length; k ++)
		{
			if ( tab[v_tab].module[k].uniq == v_uniq ) 
            { 
                return k;
            }
		}
		return 0;
	},
	/*
		Function: $p.app.widgets.idToId 
                                Get module sequence ID based on its uniq ID in page
                                
		Parameters:

			v_uniq - module uniq ID
			v_tab - tab sequence ID
		
	Returns:
			 module sequence ID
	*/
	idToId:function(v_id,v_tab)
	{
		if (v_tab==indef) v_tab=$p.app.tabs.sel;
		for (var k=0;k<tab[v_tab].module.length;k++)
		{
			if ( tab[v_tab].module[k].id==v_id ) 
            { 
                return k;
            }
		}
		return 0;
	},
	/*
		Function: $p.app.widgets.getModuleId
                                 Get a module object ID
                                 
		Parameters:

			 module div object
		
                    Returns:
			
                                 module sequence ID
	*/
	getModuleId:function(v_obj)
	{
		var ret=-1;
		var l_objid=v_obj.id;
		if (l_objid.indexOf("module")>=0)   {
			var l_idstr=l_objid.replace("module","");//substr(l_objid.indexOf("_")+1);
			var l_tab=$p.app.tabs.idToPos(l_idstr.substr(0,l_idstr.indexOf("_")));
			var l_uniq=l_idstr.substr(l_idstr.indexOf("_")+1);
			ret=$p.app.widgets.uniqToId(l_uniq,l_tab);
		}
		return ret;
	},
	/*
		Function: $p.app.widgets.saveChanges 
                                Save modules changes
                                
		Parameters:

			v_vars - modules changes array : 0 = col id, 1 = new col (optional)
			v_supid - id of the module removed (if applicable)
			v_tab - tab sequence ID
	*/
	saveChanges: function(v_vars,v_supid,v_tab)
	{
		$p.plugin.hook.launch('app.widgets.saveChanges.start');
		var l_inc = 0,
            l_save = false;
        var l_id=indef;
        //if v_tab is undefined, change is done in same tab
		if (v_tab == indef) v_tab = $p.app.tabs.sel;
        //used if widget in not in a tab
        if (v_tab == -1) v_tab = 0;
        
		var l_s = "prof=" + tab[v_tab].id;
		if (tab[v_tab].moduleAlign)
		{
			//build the saving string (for each column IMPACTED)
            //change inside a tab
			for (var l_var = 0;l_var < v_vars.length;l_var ++)
			{
				for (var l_nod = 0; l_nod < (tab[v_tab].cells[v_vars[l_var]].obj).childNodes.length-1; l_nod++)
				{
					//get the information of the concerned node (only if module one)
					var l_mod = (tab[v_tab].cells[v_vars[l_var]].obj).childNodes[l_nod];
					if ($p.app.widgets.getModuleId(l_mod) != -1)
                    {
						l_id = $p.app.widgets.getModuleId(l_mod);
					}
					else
                    {
						continue;
					}
					if (tab[v_tab].showType == 0)
                    {
						//redefine the position of the modules in the modified columns
						tab[v_tab].module[l_id].newpos = l_nod + 1;
						tab[v_tab].module[l_id].newcell = v_vars[l_var];
					}
					else
                    {
						tab[v_tab].module[l_id].newposj = l_nod+1;
					}
					//if position modified, the saving string is updated
                    if (tab[v_tab].module[l_id].cell != tab[v_tab].module[l_id].newcell 
                        || tab[v_tab].module[l_id].pos != tab[v_tab].module[l_id].newpos 
                        || tab[v_tab].module[l_id].posj != tab[v_tab].module[l_id].newposj)   {
						//check if new module (added) or not
						l_save = true;                      
						if (tab[v_tab].module[l_id].cell < 1)
                        {
							l_s += "&idn=" + tab[v_tab].module[l_id].id 
                                            + "&un=" + tab[v_tab].module[l_id].uniq
                                            +"&pxn="+tab[v_tab].module[l_id].newcell
                                            +"&pyn="+tab[v_tab].module[l_id].newpos
                                            +"&xn="+tab[v_tab].module[l_id].newx
                                            +"&yn="+tab[v_tab].module[l_id].newy
                                            +"&jn="+tab[v_tab].module[l_id].newposj
                                            +"&fn="+$p.string.getVar(tab[v_tab].module[l_id].vars,'pfid')
                                            +"&vn="+$p.string.esc(tab[v_tab].module[l_id].vars);
						}
						else
                        {
							l_inc ++;
							l_s += "&id"+l_inc+"="+tab[v_tab].module[l_id].id
                                            +"&px"+l_inc+"="+tab[v_tab].module[l_id].newcell
                                            +"&py"+l_inc+"="+tab[v_tab].module[l_id].newpos
                                            +"&j"+l_inc+"="+tab[v_tab].module[l_id].newposj
                                            +"&x"+l_inc+"="+tab[v_tab].module[l_id].newx
                                            +"&y"+l_inc+"="+tab[v_tab].module[l_id].newy
                                            +"&u"+l_inc+"="+tab[v_tab].module[l_id].uniq;
						}
                        //change datas in widgets object 
						tab[v_tab].module[l_id].cell = tab[v_tab].module[l_id].newcell;
						tab[v_tab].module[l_id].pos = tab[v_tab].module[l_id].newpos;
						tab[v_tab].module[l_id].posj = tab[v_tab].module[l_id].newposj;
                    }
				}
			}
		}
		else
		{
			//build the saving string (for each column IMPACTED)
			for (var l_nod = 0;l_nod < tab[v_tab].root.childNodes.length;l_nod ++)
			{
				//get the information of the concerned node (only if module one)
				var l_mod = tab[v_tab].root.childNodes[l_nod];
				if ($p.app.widgets.getModuleId(l_mod) != -1)
                {
					l_id = $p.app.widgets.getModuleId(l_mod);
				}
				else
                {
					continue;
				}
				//if position modified, the saving string is updated
				if (tab[v_tab].module[l_id].x != tab[v_tab].module[l_id].newx 
                    || tab[v_tab].module[l_id].y != tab[v_tab].module[l_id].newy) {
    					//check if new module (added) or not
    					l_save = true;
                        if (tab[v_tab].module[l_id].newWidget) {
                        }
    					if (tab[v_tab].module[l_id].cell < 1)  {
    						l_s += "&idn="+tab[v_tab].module[l_id].id
                                    +"&un="+tab[v_tab].module[l_id].uniq
                                    +"&pxn="+tab[v_tab].module[l_id].newcell
                                    +"&pyn="+tab[v_tab].module[l_id].newpos
                                    +"&xn="+tab[v_tab].module[l_id].newx
                                    +"&yn="+tab[v_tab].module[l_id].newy
                                    +"&jn="+tab[v_tab].module[l_id].newposj
                                    +"&fn="+$p.string.getVar(tab[v_tab].module[l_id].vars,'pfid')
                                    +"&vn="+$p.string.esc(tab[v_tab].module[l_id].vars);
                            //after that, not a new widget anymore, reset to false
                            tab[v_tab].module[l_id].newWidget = false;        
    					}
    					else
                        {
    						l_inc ++;
    						l_s += "&id"+l_inc+"="+tab[v_tab].module[l_id].id
                                        +"&px"+l_inc+"="+tab[v_tab].module[l_id].newcell
                                        +"&py"+l_inc+"="+tab[v_tab].module[l_id].newpos
                                        +"&j"+l_inc+"="+tab[v_tab].module[l_id].newposj
                                        +"&x"+l_inc+"="+tab[v_tab].module[l_id].newx
                                        +"&y"+l_inc+"="+tab[v_tab].module[l_id].newy
                                        +"&u"+l_inc+"="+tab[v_tab].module[l_id].uniq;
    					}
    					tab[v_tab].module[l_id].x = tab[v_tab].module[l_id].newx;
    					tab[v_tab].module[l_id].y = tab[v_tab].module[l_id].newy;
				}
			}
		}
		if (v_supid != indef) {
			l_save = true;
			l_s += "&ids="+tab[v_tab].module[v_supid].id+"&us="+tab[v_tab].module[v_supid].uniq;
		}

		//call the XML saving function
		if (l_save && $p.app.user.id > 0)
		{
			$p.ajax.call(posh["scr_config_place"],
				{
					'type':'execute',
					'variables':l_s,
					'alarm':false
				}
			);
		}
        
		// this action restart the protection counter
		if (tab[v_tab].lock != 0){$p.app.counter.reset(4);}
		
		// define that the impacted tab has been modified
		tab[v_tab].modified = true;

		$p.plugin.hook.launch('app.widgets.saveChanges.end');
	},
	/*
		Function: $p.app.widgets.refreshContent
                                Refresh module with "M" format
                                
		Parameters:

			v_id - module sequence ID
			v_tab - tab sequence ID
            
                     Returns:
                        
                                false
	*/
	refreshContent:function(v_id,v_tab,v_sharedmd5key)
	{ 
		if (v_tab==indef) v_tab=$p.app.tabs.sel;
        var l10n = tab[v_tab].module[v_id].l10n;
		$p.ajax.call(tab[v_tab].module[v_id].url,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.widgets.displayContent,
					'variables':
					{
						'widgetpos':v_id,
						'undef':0,
						'widgetid':tab[v_tab].module[v_id].uniq,
						'tabpos':v_tab,
						'tabid':tab[v_tab].id
					}
				},
				'source':'xml',
				'variables':"pid="+$p.app.user.id
                                +"&prof="+tab[v_tab].id
                                +"&p="+tab[v_tab].module[v_id].uniq
                                +"&format=M"
                                +"&plg="+__lang
                                +"&l10n="+l10n
                                +"&"+tab[v_tab].module[v_id].vars
                                +"&sharedmd5key="+v_sharedmd5key
                                +"&widgetid="+tab[v_tab].module[v_id].uniq,
				'method':'POST'
			}
		);
		return false;
	},
	/*
		Function: $p.app.widgets.displayContent
                                Display module with "M" format
                                
                     Parameters:
                     
                                response - XML object 
                                vars (array) - variables (optionnal)
	*/
	displayContent:function(response,vars)
	{
		var l_tab=vars['tabpos'];
		// be carefull : with FF3.0, a bug is noticed because l_tab=indef. workaround : var l_tab=eval(vars['tabpos']);
		if (response.getElementsByTagName("Module")[0])
		{
			var l_mod=response.getElementsByTagName("Module")[0];
			var l_script="";
			//refresh edit box only if current tab
			$p.app.widgets.param.fillEditBox(l_mod,vars['widgetid'],l_tab);
            //length of content
            //list contents
            var modid = vars['widgetpos'];
            var contentNumber=0;
            if ( l_mod.getElementsByTagName("Content").length > 1) {
                for (var i = 0; i< l_mod.getElementsByTagName("Content").length; i++) 
                {
                    var viewprop = $p.ajax.getProp(
                                                l_mod.getElementsByTagName("Content")[i],
                                                'view',
                                                'str',
                                                false,
                                                'home'
                                                );
                    if ( viewprop == tab[l_tab].module[modid].currentView) {
                        contentNumber=i;
                        break;
                    }
                }
            }
            
			if (l_mod.getElementsByTagName("Content")[contentNumber])
			{
				var l_contenttag=response.getElementsByTagName("Content")[contentNumber];
				var l_content=l_contenttag.firstChild.nodeValue;
				l_content=l_content.replace(/__MODULE_ID__/g,vars['widgetid']+"_"+vars['tabid']);
				if (l_content.indexOf("<script>")!=-1 
                        || l_content.indexOf('<script language="text/javascript">')!=-1 
                        || l_content.indexOf("<script language='text/javascript'>")!=-1
                    )
				{
					var l_pos1=l_content.indexOf("<script>");
					if (l_pos1==-1) l_pos1=l_content.indexOf("<script language='text/javascript'>");
					if (l_pos1==-1) l_pos1=l_content.indexOf('<script language="text/javascript">');
					l_pos1=l_content.indexOf(">",l_pos1);
					var l_pos2=l_content.indexOf("</script>",l_pos1);
					var l_script=l_content.substring((l_pos1+1),l_pos2);
				}
				$p.print("module"+tab[l_tab].id+"_"+vars['widgetid']+"_c",l_content);
				//launch script
				if (l_script!="")
				{
					try
					{
						eval(l_script);
					}
					catch(err)
					{
						$p.app.debug("widget script error :"+err.message+" / on script :"+l_script,"error");
					}
				}
			}
		}
	},
    /*$p.app.widgets.currentClass*/
    currentClass:'module',
	/*
		Function: $p.app.widgets.createAll
                                Create all widgets of a personalized page
                                
		Parameters:
 
			v_tab - tab sequence ID
			v_display - set if widgets are displayed once created
	*/
	createAll:function(v_tab,v_display)
	{
		// Create all the modules
		var l_cell = 1;
		var l_ontop = 0;

		// compute the max Uniq ID
		for (var i=0;i<tab[v_tab].module.length;i++)    {
			if (tab[v_tab].module[i].uniq>tab[v_tab].maxUniq)
				tab[v_tab].maxUniq=tab[v_tab].module[i].uniq;
		}
        
		//sort the modules depending on the show type
		if (tab[v_tab].showType==0) {
			tab[v_tab].module.sort(blocSort);
		}
		else    {
			tab[v_tab].module.sort(newspaperSort);
		}
	
        for (var i=0;i<tab[v_tab].module.length;i++)
		{
			while (tab[v_tab].module[i].cell > l_cell) l_cell++;
			if (tab[v_tab].showType==0 || tab[v_tab].module[i].format!='R') 
            {
                tab[v_tab].module[i].create();
            }

			//display modules if not in the active tab
			if (v_tab!=$p.app.tabs.sel || v_display)
			{
				tab[v_tab].module[i].show();
			}
			//if a module is added from outside of Portaneo
			if (tab[v_tab].module[i].pos==99) 
            {
                l_ontop=i;
            }

		}

		if (tab[v_tab].showType==1) {
			$p.app.widgets.rss.reader.init();
			$p.app.widgets.rss.reader.load();
			// if modules are aligned, a dummy div is added on the bottom of the column of widgets
			if (tab[v_tab].moduleAlign) {
                (tab[v_tab].cells[1].obj).appendChild($p.app.widgets.endList());
            }
		}
		else    {
			// if modules are aligned, a dummy div is added on the bottom of each column
			if (tab[v_tab].moduleAlign) {
				for (var i=1;i < tab[v_tab].cells.length;i++)
				{
					  //add a void div in a column WIDGETCOL
					(tab[v_tab].cells[i].obj).appendChild($p.app.widgets.endList());
				}
			}
		}	
		//if a module is not placed, place it on top of first column (only if modules are aligned)
		if (l_ontop!=0 && tab[v_tab].moduleAlign)   {
			tab[v_tab].module[l_ontop].placeonTop();
			var l_var = [];
			l_var[0] = tab[v_tab].module[l_ontop].cell;
			$p.app.widgets.saveChanges(l_var,indef,v_tab);
		}
        //change widget classname to module
        
	},
    /*
            function  : $p.app.widgets.maximize
            
                        maximize the widget, full-screen or full-portal if you prefer
        */
    maximize:function (v_uniq,v_id) {

        var v_tab = $p.app.tabs.sel;
        var modSeqId = $p.app.widgets.uniqToId( v_uniq, v_tab);
        var nextModule = tab[$p.app.tabs.sel].module.length;
        var tab_id = tab[v_tab].id;

        tab[$p.app.tabs.sel].module[nextModule] = cloneObj(tab[$p.app.tabs.sel].module[modSeqId]);
        tab[$p.app.tabs.sel].module[nextModule].UniqParent=v_uniq;
        tab[$p.app.tabs.sel].module[nextModule].DBIdParent=modSeqId;
        tab[$p.app.tabs.sel].module[nextModule].SeqIdParent=v_id;
        tab[$p.app.tabs.sel].module[nextModule].uniq=v_uniq+10000;
        tab[$p.app.tabs.sel].module[nextModule].classname='canvas';
        tab[$p.app.tabs.sel].module[nextModule].ModulePositionId=nextModule;

        tab[$p.app.tabs.sel].module[nextModule].currentView="canvas";
        var modid = tab[$p.app.tabs.sel].module[nextModule].id;
        tab[$p.app.tabs.sel].module[nextModule].canvas = $('canvas'+tab_id);
        if (tab[$p.app.tabs.sel].module[modSeqId].newUrl) {
            tab[$p.app.tabs.sel].module[nextModule].url = tab[$p.app.tabs.sel].module[modSeqId].newUrl;
            delete tab[$p.app.tabs.sel].module[modSeqId].newUrl;
            delete tab[$p.app.tabs.sel].module[nextModule].newUrl;
        }

        if (tab[$p.app.tabs.sel].module[modSeqId].newFormat) {
            tab[$p.app.tabs.sel].module[nextModule].format = tab[$p.app.tabs.sel].module[modSeqId].newFormat;
            delete tab[$p.app.tabs.sel].module[modSeqId].newFormat;
            delete tab[$p.app.tabs.sel].module[nextModule].newFormat;
        }       
         
        if ($('home'+tab_id)) {
            $('home'+tab_id ).style.display="none";
            $('canvas'+tab_id ).style.display="block";
            tab[$p.app.tabs.sel].module[nextModule].create();            
            tab[$p.app.tabs.sel].module[nextModule].show('canvas'); 
            $p.app.widgets.currentClass='canvas';
            tab[$p.app.tabs.sel].module[nextModule].hdrColor(indef,indef,'canvas');
            $p.app.widgets.currentClass='module';
            $p.show("hmod"+tab[v_tab].id+"_"+tab[$p.app.tabs.sel].module[nextModule].uniq,"block");
        }
        
        // set tab current view
        tab[$p.app.tabs.sel].currentView = 'canvas';
		
		// refresh the tabs - used for the link to get back to home mode
        $p.app.tabs.created[$p.app.tabs.sel]=false;
		$p.app.tabs.create($p.app.tabs.sel);

        return false;
    },
    /*
                Function: $p.app.widgets.homeView
                
                        returns to normal view
                        
                  parameters:

                            v_id - id of module
        */
    homeView: function (v_id, v_tab) {
        if (v_tab == indef) v_tab = $p.app.tabs.sel;
        if (v_id == indef)
        {
            // find widget that is not in home view
            for (var i = 0; i < tab[v_tab].module.length; i++)
            {
                if (tab[v_tab].module[i].currentView != 'home')
                    v_id = i;
            }
        }
        
        var tab_id = tab[v_tab].id;
        var ModulePosition = tab[$p.app.tabs.sel].module[v_id].ModulePositionId;
        tab[$p.app.tabs.sel].module[v_id].currentView="home";
        var l_id_parent =$p.app.widgets.uniqToId(tab[v_tab].module[v_id].UniqParent);
        $('canvas'+tab_id).innerHTML='';
        $('canvas'+tab_id).style.display="none";        
        tab[$p.app.tabs.sel].module.pop(); //remove item canvas from module array
     //  tab[$p.app.tabs.sel].module[l_id_parent].create(indef,1);
        tab[$p.app.tabs.sel].module[l_id_parent].refresh();
        $p.app.widgets.currentClass='module';
        tab[$p.app.tabs.sel].module[l_id_parent].hdrColor( indef,indef,'module');
        tab[$p.app.tabs.sel].module[l_id_parent].setName(indef);
        $('home'+tab_id).style.display="";
        // set tab current view
        tab[$p.app.tabs.sel].currentView = 'home';
        
        return false;   
    },
	/*
		Function: $p.app.widgets.suppress
                                Remove a widget
                                
		Parameters:

			v_uniq - module uniq ID
			v_confirm (boolean) - true=ask for module removal confirmation
            
                      Returns :
                      
                                true or false
	*/
	suppress: function(v_uniq,v_confirm)
	{
		$p.plugin.hook.launch('app.widgets.suppress.start');

		var l_id = $p.app.widgets.uniqToId(v_uniq),
            l_ret = false;
		// if module to suppress is not yet included in the page
		if (showNewMod 
            && l_id == (tab[$p.app.tabs.sel].maxUniq)) {
                $p.app.widgets.close();
		}
		else
        {
			var l_response = v_confirm ? confirm(lg("msgModSup")) : 1;
			if (l_response == 1)  {
				// Remove a widget in column
				//suppress linked RSS feeds
				if (tab[$p.app.tabs.sel].module[l_id].format == 'R')
					$p.app.widgets.supFeed(l_id);

                //get the module column
                var modcell = tab[$p.app.tabs.sel].module[l_id].cell;
                
				//virtually change the module position
				for(var i = 0;i < tab[$p.app.tabs.sel].module.length;i++)
				{
					if (tab[$p.app.tabs.sel].module[i].newcell == tab[$p.app.tabs.sel].module[l_id].newcell 
                        && tab[$p.app.tabs.sel].module[i].newpos > tab[$p.app.tabs.sel].module[l_id].newpos){
                            tab[$p.app.tabs.sel].module[i].newpos -= 1;
                    }
					if (tab[$p.app.tabs.sel].module[i].newposj > tab[$p.app.tabs.sel].module[l_id].newposj){
                        tab[$p.app.tabs.sel].module[i].newposj -= 1;
                    }
				}
                //destruct the widget if it is visible on screen
				if (tab[$p.app.tabs.sel].showType == 0 
                    || tab[$p.app.tabs.sel].module[l_id].format != 'R') {
                        tab[$p.app.tabs.sel].module[l_id].destruct();
                }
				//register the suppression
				var l_vars = [];
				if (tab[$p.app.tabs.sel].showType == 0)   {
					l_vars[0] = tab[$p.app.tabs.sel].module[l_id].cell;
                }
                else
                {
                    l_vars[0] = 1;
				}
				$p.app.widgets.saveChanges(l_vars,l_id);

				tab[$p.app.tabs.sel].module.splice(l_id,1);
				l_ret = true;
                //column minus one widget.
                $p.app.pages.columns.updateNbWidgetByCol($p.app.tabs.sel,modcell,-1);
                
			}
		}

		$p.plugin.hook.launch('app.widgets.suppress.end');

		return l_ret;
	},
	/*
		Function: $p.app.widgets.supFeed
                                Remove the feeds information related to a removed RSS module
		
                     Parameters:

			v_uniq - module uniq ID
			v_tab - tab sequence ID
	*/
	supFeed: function(v_uniq,v_tab)
	{
		if (v_tab == indef) v_tab = $p.app.tabs.sel;
		delete tab[v_tab].feeds[v_uniq];
        if (tab[v_tab].feeds.length > 0) {
            tab[v_tab].feeds.length -= 1
        };
        
        /*
        var i=0;
		while (tab[v_tab].feeds[i])
		{
			if (tab[v_tab].feeds[i].modUniq==v_uniq)    {
				tab[v_tab].feeds.splice(i,1);
			}
			else    {
				i++;
			}
		}
        */
	},
	/*
		Function: $p.app.widgets.endList
                                
                                create a hidden element (used at the bottom of each column) added when a column is created, used for moving
                                
                     Returns:
                                
                                Element
	*/
	endList:function()
	{
		var l_obj=null;
		l_obj=new Element('div',{ 'class':'necessary'} );
		// necessary to add an empty column
		l_obj.set('html',$p.img('',180,1));
		l_obj.setStyle('width', '100%'); 
		return l_obj;
	},
	/*
		Function: $p.app.widgets.showHdr
                                Display/hide the modules headers
                                
		Parameters:

			 tab sequence ID
	*/
	showHdr:function(v_tab)
	{
		if (v_tab==indef) v_tab=$p.app.tabs.sel;
        for (var i=0;i<tab[v_tab].module.length;i++)
        {
            $p.show("hmod"+tab[v_tab].id+"_"+tab[v_tab].module[i].uniq,"block");
        }
	},
	/*
		Function: $p.app.widgets.switchHdr
                                Change the modules headers display status
	*/
	switchHdr:function()
	{
		tab[$p.app.tabs.sel].controls = (tab[$p.app.tabs.sel].controls == 'Y') ? 'N' : 'Y';
       
		//$p.app.widgets.showHdr();
	},
	/*
		Function: $p.app.widgets.changeTab
                                Move a module from one tab to another
                                save data in database, don't change other tab
                                
		Parameters:

			v_desttab - destination tab sequence ID
			v_uniq - module uniq ID
	*/
	changeTab:function(v_desttab,v_uniq)
	{
		if(tab[v_desttab].status!=2)
		{
			$p.ajax.call(posh["scr_addmodule_othertab"],
				{
					'type':'execute',
					'variables':"src="+tab[$p.app.tabs.sel].id+"&dest="+tab[v_desttab].id+"&tabdest="+v_desttab+"&uniq="+v_uniq,
					'alarm':false,
					'forceExecution':false,
					'callback':
					{
						'function':$p.app.widgets.addInNewTab
					}
				}
			);
			//update rss unread number (only in source tab, the other is reload)
			var l_modId=$p.app.widgets.uniqToId(v_uniq);
			if (tab[$p.app.tabs.sel].module[l_modId].format=="R")
			{
				tab[$p.app.tabs.sel].module[l_modId].nbunread=0;
				$p.app.widgets.rss.pageUnread($p.app.tabs.sel);
			}
		}
	},
	/*
		Function: $p.app.widgets.insertInTab
                                Insert a new module in a tab
                                
		Parameters:

			v_desttab - destination tab sequence ID
			v_id - module DB ID
                                v_vars - variables
	*/
	insertInTab:function(v_desttab,v_id,v_vars)
	{
		//get feed id
		var l_fid = $p.string.getVar(v_vars,'pfid');
		if (l_fid == '') l_fid = 0;
		$p.ajax.call(posh["scr_addmodule_intab"],
			{
				'type':'execute',
				'variables':"dest="+tab[v_desttab].id+"&tabdest="+v_desttab+"&id="+v_id+"&fid="+l_fid+"&vars="+$p.string.esc(v_vars),
				'alarm':false,
				'forceExecution':false,
				'callback':
				{
					'function':$p.app.widgets.addInNewTab
				}
			}
		);
		$p.app.widgets.close();
	},
	/*
		Function: $p.app.widgets.addInNewTab
                                Reset destination tab when adding a module in another tab
                                
		Parameters:
                      v_ret - string return from xml response in ret tag
	*/
	addInNewTab:function(v_ret,vars)
	{
		if (v_ret == indef) return;
		var v_param = v_ret.split(/_/);
		var tabId = v_param[3];
		var tabPos = $p.app.tabs.idToPos(tabId);
        
		//add module in new tab
		if (tab[tabPos].isLoaded == true) {
			tab[tabPos].isLoaded = indef;
			$p.print("tabextra" + tabPos,"");
			//to be done : create twin module, place on bottom, change nbunread,...
		}
		//suppress module from old tab
		if (v_param[0] != "x") $p.app.widgets.suppress(v_param[0]);
	},
	/*
		Function: $p.app.widgets.changeName
                                Change module name
                                
		Parameters:

			v_id - module sequence ID
			v_name - new module name
			v_tab - tab sequence ID of the module
	*/
	changeName: function(v_id,v_name,v_tab)
	{
		if (v_tab == indef) v_tab = $p.app.tabs.sel;
		
		if (v_name != indef) tab[v_tab].module[v_id].name = v_name;
        
		var l_s = (__showModuleTitle?tab[v_tab].module[v_id].name : "");

		if (tab[v_tab].module[v_id].nbunread != 0)
		{
			l_s = "<a class='rssstatus' title='"+lg('unread')+"' href='#' onmousedown='return $p.app.widgets.rss.readAll("+v_tab+","+v_id+")'>"
				+ "("+tab[v_tab].module[v_id].nbunread+")"
				+ "</a> "
				+ l_s;
		}

		$p.print("module"+tab[v_tab].id+"_"+tab[v_tab].module[v_id].uniq+"_h",l_s);
	},
	/*
		Function: $p.app.widgets.changeIcon
                                Change module Icon
                                
		Parameters:

			v_id - module sequence ID
			v_icon - module icon
			v_tab - tab sequence ID of the module
	*/
	changeIcon:function(v_id,v_icon,v_tab)
	{ 
		var l_icon = "";
      
		if (!__showicon)return false;
		if (v_tab==indef) v_tab=$p.app.tabs.sel;
        
		if (v_icon!=indef)
        { 
			l_icon = v_icon;
		}
		else   
        { 
			if ( tab[v_tab].module[v_id].icon.substr(0,2)==".." )
            {
				l_icon = tab[v_tab].module[v_id].icon;
			} else {
				l_icon = _dirImg+tab[v_tab].module[v_id].icon;
			}
		} 
		$("module"+tab[v_tab].id+"_"+tab[v_tab].module[v_id].uniq+"_icon").src=l_icon;
	},	
	/*
		Function: $p.app.widgets.initMove
                                Init modules move in free page (page without column)
                                
		Parameters:

			 v_tab - tab sequence ID of the modules
             
              See also: <$p.app.pages.columns.init> 
                    <$p.app.pages.displayItems> 
	*/
	initMove:function(v_tab)
	{
		if (tab[v_tab].moveIsInit)
			return;
		tab[v_tab].moveIsInit = true;
		for(var l_item = 0; l_item < tab[v_tab].root.childNodes.length; l_item++)
		{
			var l_mod = tab[v_tab].root.childNodes[l_item];
 			$p.app.widgets.move.set(l_mod,"module",tab[v_tab].root,"multidim",true,v_tab);
		}
	},
	/*
		Function: $p.app.widgets.enableMoving
                                 Display and initialize bars for widget move and configuration
                                 
		Parameters:

			 v_tab - tab array position where widgets are
	*/
	enableMoving:function(v_tab)
	{
		if (v_tab == indef) v_tab = $p.app.tabs.sel;

		if (tab[v_tab].showwidgetbar == 1 || $p.app.user.id == -1) $p.app.widgets.showHdr(v_tab);
        tab[v_tab].moveIsInit = false;
		useMod = true;
		// if (tab[v_tab].controls == 'Y' || $p.app.user.id == -1 || $p.app.user.id == 0 ) // EMA : removed because page blocked for anonymous do not allow to move the widgets
		if (tab[v_tab].controls == 'Y' || $p.app.user.id == -1)
		{
			$p.app.pages.displayItems(v_tab);
		}
	},
	/*
		Function: $p.app.widgets.align
                                Manage modules alignment
                                
		Parameters:

			 v_align (boolean) - true if modules are aligned
	*/
	align:function(v_align)
	{
		var l_var=[];
		if (v_align)    {
			for (var i=0;i<tab[$p.app.tabs.sel].module.length;i++)
			{
                
				tab[$p.app.tabs.sel].module[i].newx=(20+(i*30));
				tab[$p.app.tabs.sel].module[i].newy=(120+(i*30));
			}
		}
		//save new position
		$p.app.widgets.saveChanges(l_var);

		//regenerate the page
		tab[$p.app.tabs.sel].moduleAlign = !v_align;
		//pages.open();
		$p.app.pages.clean(tab[$p.app.tabs.sel].root);
		if (v_align)    {
			for (var i=0;i<tab[$p.app.tabs.sel].module.length;i++)
			{
				tab[$p.app.tabs.sel].module[i].x=tab[$p.app.tabs.sel].module[i].newx;
				tab[$p.app.tabs.sel].module[i].y=tab[$p.app.tabs.sel].module[i].newy;
			}
		}
		$p.app.pages.init($p.app.tabs.sel);
		$p.app.pages.computeFooterPosition();
	},
	/*
		Function: $p.app.widgets.place
                                Place all the modules of the selected tab
                                
		Parameters:

			v_tab : selected tab sequence ID
	*/
	place:function(v_tab)
	{
		if (v_tab==indef) v_tab=$p.app.tabs.sel;
		if (v_tab==-1) return;
		if ( tab[v_tab] && !tab[v_tab].moduleAlign)    {
			for (var i=0;i<tab[v_tab].module.length;i++)
			{
				var l_obj=$("module"+tab[v_tab].id+"_"+tab[v_tab].module[i].uniq);
                if (l_obj != null)
                {
                    l_obj.setStyle("left",(parseInt(tab[v_tab].module[i].x,10)+parseInt(widgetDecalX,10))+"px");
                    l_obj.setStyle("top",(parseInt(tab[v_tab].module[i].y,10)+parseInt(widgetDecalY,10))+"px");
                }
			}
			$p.app.pages.computeFooterPosition();
		}
	},
	/*
		Function: $p.app.widgets.open 
        
                                Load a new module
                                
		Parameters:

			v_id - (required) (int) module DB ID
			v_vars - (optional) (string) module url parameters,  field variables in database
			v_type - (optional) page type (portal,uniq)
			v_secured - (boolean) define if the widget is public / private. if private, no cache file existing
			v_useOverview - (optional)  true = Show widget overview, false = add directly in the page
			v_waitForDisplay - (optional) ???
                        v_position - (optional) 
                        v_target - (optional) 
            
                See also:
                        - <$p.app.menu.widget.displaySearch>
                        - <$p.app.menu.widget.displayDir>
                        - <$p.app.menu.widget.displayExplorer>
                        - <$p.app.menu.widget.explorerOnDrag>
                        - <$p.app.menu.widget.displaySecuredExplorer>
                        - <$p.app.menu.widget.displayMyModules>
                        - <$p.app.pages.listModules>
                        - <Function: $p.app.pages.displayPublicWidgets>
                        - <$p.app.widgets.rss.showmod>
                        - <$p.app.widgets.factory.display>
                        - application <$p.search.module.display >
                        - application <$p.network.information.buildItem>
                        - application <$p.groupbook.displayWidgetList>
                        - application <$p.notebook.addWidget>
                        
                     Returns:
                     
                                false;
	*/
	open:function(v_id,
                    v_vars,
                    v_type,
                    v_secured,
                    v_useOverview,
                    v_waitForDisplay,
                    v_position,
                    v_target)
	{
		if (v_vars==indef) v_vars='';
		if (v_position==indef) v_position='top';
		if (v_type==indef) v_type=($p.app.tabs.sel==-1 || tab[$p.app.tabs.sel].type!=1)?'uniq':'portal';
		if (v_useOverview==indef) v_useOverview=true;
		if (v_waitForDisplay==indef) v_waitForDisplay=true;
        
        if (__GROUP_RESTRICTION_ON_SINGLE_WIDGET) {
            var l_url=posh["xmlitem"]+'?id='+v_id+'&rand='+rand;
        }
        else {
            if (v_secured)  {
                var l_url=posh["xmlitem"]+'?id='+v_id+'&rand='+rand;
            }
            else    {
                var l_url='../cache/item_'+v_id+'.xml?rand='+rand;
            }
        }
        
        if (v_type == 'portal' && tab[$p.app.tabs.sel].controls == 'N' && $p.app.user.id >= 0)
        {
            $p.app.alert.show(lg("pageBlockedPreventWidgetAdding"),3);
            return false;
        }
		
		//hide help message
		$p.show('message','none');
        
		$p.ajax.call(l_url,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.widgets.displayMod,
					'variables':
					{
						'id':v_id,
						'vars':v_vars,
						'type':v_type,
						'useOverview':v_useOverview,
						'position':v_position,
						'target':v_target
					}
				},
				'asynchron':v_waitForDisplay
			}
		);
		return false;
	},
	/*
			Function: $p.app.widgets.displayMod
                                            Display a new module in the page, or its overview
                                            
                                Parameters: 
                                
                                           response - XML object
                                           vars (array) - variables (optionnal)
	*/
	displayMod: function(response,vars)
	{
		var l_s = "",
            l_result,
            l_newId;
            $p.app.widgets.currentClass='module';
		if (response.getElementsByTagName("item")[0])
		{
			l_result = response.getElementsByTagName("item")[0];
			var l_size          = $p.ajax.getVal(l_result,"size","int",false,100);
			var l_minwidth      = $p.ajax.getVal(l_result,"minwidth","int",false,180);
			var l_sizable       = $p.ajax.getVal(l_result,"sizable","int",false,1);
			var l_name          = $p.ajax.getVal(l_result,"name","str",false,"--");
			var l_format        = $p.ajax.getVal(l_result,"format","str",false,"I");
			var l_website       = $p.ajax.getVal(l_result,"website","str",false,"");
			var l_nbvars        = $p.ajax.getVal(l_result,"nbvars","int",false,0);
			var l_usereader     = $p.ajax.getVal(l_result,"usereader","int",false,($p.app.tabs.sel < 0 ? false : tab[$p.app.tabs.sel].usereader));
			var l_editor        = $p.ajax.getVal(l_result,"editor","str",false,"");
			var l_editorid      = $p.ajax.getVal(l_result,"editor_id","int",false,0);
            var l_views         = $p.ajax.getVal(l_result,"views","str",false,'home');
            var l_icon          = $p.ajax.getVal(l_result,"icon","str",false,indef);
            var l_l10n          = $p.ajax.getVal(l_result,"l10n","str",false,'');
            var l_group_access  = $p.ajax.getVal(l_result,"group_access","str",false,'0');

			if (vars['vars'] == '')
                vars['vars'] = $p.ajax.getVal(l_result,"var","str",false,"");

			if (showNewMod) $p.app.widgets.close(vars['type']);

			l_newId = ($p.app.tabs.sel < 0    ?     0
                                              :     tab[$p.app.tabs.sel].module.length);

			var l_url = $p.ajax.getVal(l_result,"url","str",false,"");
			//show overview if configured in admin panel
            //col id attention => cell0
			if (!standaloneMode
                && (vars['type'] == "uniq" 
                    || $p.app.tabs.sel == -1 
    				|| tab[$p.app.tabs.sel].type != 1
                    || (vars['useOverview'] 
                        && __useoverview 
                        && tab[$p.app.tabs.sel].moduleAlign))) 
            {
                var celltoUse = 1;

                if (tab[$p.app.tabs.sel] && tab[$p.app.tabs.sel].cells && tab[$p.app.tabs.sel].cells[celltoUse] && tab[$p.app.tabs.sel].cells[celltoUse].nbWidgets['max'] > 0)
				{
                    celltoUse = $p.app.pages.columns.analyzeColumns(celltoUse);

                    if ( tab[$p.app.tabs.sel].cells[cellToUse].nbWidgets
                            && tab[$p.app.tabs.sel].cells[cellToUse].nbWidgets['toomany']
                            && $p.app.tabs.sel != 0
                            )
					{

						//reinitialize to false
                        tab[$p.app.tabs.sel].cells[cellToUse].nbWidgets['toomany'] = false;
                         $p.app.alert.show( lg('MaxWidgetbyCol')  + " " + tab[$p.app.tabs.sel].cells[cellToUse].nbWidgets['max'],3);
                        return true;
                    }  
                }

				l_s += '<br />'
					+ '<center>'
					+ '<div id="cell0" style="width:'+$p.max(l_minwidth,400)+'px"></div>'
					+ '</center><br />';

				if (vars['type'] == "portal")
				{
					if (tab[$p.app.tabs.sel].controls == 'Y' || $p.app.user.id < 0)
					{
						//check if column is free, if not, don't display popup
						l_s += "<center>"
							+ "<input class='btn' type='button' value='"+lg("lblBtnModAdd")+"' "
							+ " onclick='tab[$p.app.tabs.sel].module[tab[$p.app.tabs.sel].module.length-1].placeinCol(" + celltoUse + ");$p.app.widgets.close();$p.app.popup.hide();' />"
							+ "</center>";
					}
					else
					{
						l_s += lg('pageBlockedPreventOptionsChange');//"This page is blocked, you cannot add a widget here";
					}
				}
				else
				{
					l_s += '<b>'+lg('moveToPlaceInTabs')+'</b>';
				}

				var l_desc = $p.ajax.getVal(l_result,"description","str",false,"");
				if (l_desc != '')
					l_s+='<br /><br /><b>'+lg('description')+'</b><br />'+l_desc;

				if (l_editorid != 0 && vars['id'] != 86 && l_editor != "")
				{
					if (__useSharing)
					{
						l_editor = "<a href='#' onclick='$p.notebook.open("+l_editorid+")'>"+l_editor+"</a>";
					}
					l_s += '<br /><br />'
						+ '<b>'+lg("proposedBy")+'</b> : '
						+ l_editor;
				}
				//l_s+="</td></tr></table></td></tr>";
				//l_s+="</table>";
				//$p.print("newmod",box(0,l_name+$p.img("star_yellow2_"+$p.ajax.getVal(l_result,"nota","int",false,0)+".gif",53,12),"$p.app.widgets.close('"+vars['type']+"')",l_s));

				$p.app.popup.show(l_s,$p.max(l_minwidth+20,500),indef,l_name+$p.img("star_yellow2_"+$p.ajax.getVal(l_result,"nota","int",false,0)+".gif",53,12),true,"$p.app.widgets.close('"+vars['type']+"')");

				//$p.show("newmod","block");
				if ($p.app.tabs.sel >= 0) tab[$p.app.tabs.sel].maxUniq++;

				if (vars['type']=='portal' && (tab[$p.app.tabs.sel].controls == 'Y' || $p.app.user.id == -1))
				{
					tab[$p.app.tabs.sel].cells[0] = {'obj':$('cell0')};
					tab[$p.app.tabs.sel].module[l_newId] = new $p.app.widgets.object(
												0, //cell
												0,  //pos
												0, //position in module array alias posj
												l_size, //height
												vars['id'],
												l_website, //url of website
												l_name,
												vars['vars'],   //variables 
												l_minwidth, //minmodsize
												l_sizable,  //sizable ( 0 1 2 3 )
												400,        //height size
												l_url,      //url of widget : xml_getwidget, p_rss ,external url,..
												150,        //x
												150,        //y
												tab[$p.app.tabs.sel].maxUniq,
												l_format,   // RM I U see docs $p.app.widgets.object
												l_nbvars,   //number of variables
												tab[$p.app.tabs.sel].id,    //tab_id of widget 
												0,          //blocked
												0,          //minimized
												l_usereader, //usereader,
												0,  //autorefresh
												l_icon,     //icon of the moduke
												false, //is loaded status of the module (indef=not loaded, false=loading, true=loaded)
												indef, //header
												indef, //footer
												indef, //auth  for RSS authentified feeds
												l_views,  //views (home or canvas) canvas for full-screen (full-portal)
												l_l10n,    //lang parameters for l10n widgets
												'',
												l_group_access
												);
					tab[$p.app.tabs.sel].module[l_newId].newWidget = true;
					tab[$p.app.tabs.sel].module[l_newId].PositioninTab = l_newId;
					tab[$p.app.tabs.sel].module[l_newId].create(l_size );
					tab[$p.app.tabs.sel].module[l_newId].show();
					if (tab[$p.app.tabs.sel].showwidgetbar == 1 || $p.app.user.id == -1) $p.app.widgets.showHdr();
				}
				else if (vars['type']=="uniq")
				{
					// Workaround : Creating a widget needs to be in a tab page. If not in a tab page > create a dummy tab, just the time to create the widget
					if ($p.app.tabs.sel < 0)
					{
						$p.app.tabs.openTempTab(3,"function(){}",lg('widget'),'',false);
						var l_currTab = 0;
					}
					else
					{
						l_currTab = $p.app.tabs.sel;
					}
				   // tab[l_currTab].cells[0]=$('col'+l_currTab+'_'+'0');
					tab[l_currTab].cells[0] = {'obj':$('cell0')};
					tab[l_currTab].module[l_newId]=new $p.app.widgets.object(
												0,
												1,
												1,
												l_size,
												vars['id'],
												l_website,
												l_name,
												vars['vars'],
												l_minwidth,
												l_sizable, //sizable ( 0 1 2 3 )
												400,
												l_url,
												150,
												150,
												0,
												l_format,
												l_nbvars,
												tab[l_currTab].id,
												0,
												0,          //minimized
												0, //usereader,
												0,  //autorefresh
												l_icon,     //icon of the moduke
												false, //is loaded status of the module (indef=not loaded, false=loading, true=loaded)
												indef, //header
												indef, //footer
												indef, //auth  for RSS authentified feeds
												l_views,  //views (home or canvas) canvas for full-screen (full-portal)             
												l_l10n,    //lang parameters for l10n widgets
												'',
												l_group_access
												);
					tab[l_currTab].module[l_newId].newWidget = true;                            
					tab[l_currTab].module[l_newId].PositioninTab = l_newId;   
					tab[l_currTab].module[l_newId].create( l_size );
					tab[l_currTab].module[l_newId].show();
					(tab[l_currTab].cells[0].obj).appendChild($p.app.widgets.endList());
					if (tab[l_currTab].showwidgetbar == 1 || $p.app.user.id == -1) $p.app.widgets.showHdr(l_currTab);
					tab[l_currTab].moveIsInit=false;
					useMod=true;

					$p.app.pages.displayItems(l_currTab);
				}
				showNewMod=true;
			}
			else
            {
                //widget added by move
                var celltoUse = -1;
                //add a new widget by moving it
                celltoUse = $p.app.pages.columns.analyzeColumns(1);
                if (tab[$p.app.tabs.sel].cells[celltoUse].nbWidgets['max'] > 0) {
                    //reinitialize to false
                    tab[$p.app.tabs.sel].cells[celltoUse].nbWidgets['toomany'] = false;
                    $p.app.alert.show( lg('MaxWidgetbyCol')  + " "+tab[$p.app.tabs.sel].cells[celltoUse].nbWidgets['max'],3);
                    return true;
                }
				tab[$p.app.tabs.sel].maxUniq++;
				tab[$p.app.tabs.sel].module[l_newId]=new $p.app.widgets.object(
                                                        -1, //negative col on temporary widget (see  <$p.app.widgets.create>)
                                                        0,
                                                        0,
                                                        l_size,
                                                        vars['id'],
                                                        l_website,
                                                        l_name,
                                                        vars['vars'],
                                                        l_minwidth,
                                                        l_sizable,
                                                        400,
                                                        l_url,
                                                        150,
                                                        150,
                                                        tab[$p.app.tabs.sel].maxUniq,
                                                        l_format,
                                                        l_nbvars,
                                                        tab[$p.app.tabs.sel].id,
                                                        0,
                                                        0,          //minimized
                                                        0, //usereader,
                                                        0,  //autorefresh
                                                        l_icon,     //icon of the moduke
                                                        false, //is loaded status of the module (indef=not loaded, false=loading, true=loaded)
                                                        indef, //header
                                                        indef, //footer
                                                        indef, //auth  for RSS authentified feeds
                                                        l_views,  //views (home or canvas) canvas for full-screen (full-portal)                  
                                                        l_l10n,    //lang parameters for l10n widgets
                                                        '',
                                                        l_group_access
                                                        );
                tab[$p.app.tabs.sel].module[l_newId].newWidget = true;                                        
                tab[$p.app.tabs.sel].module[l_newId].PositioninTab = l_newId;      
				tab[$p.app.tabs.sel].module[l_newId].create( l_size, celltoUse );
                tab[$p.app.tabs.sel].module[l_newId].show();
                if(vars['target']!=indef)
                {
                    tab[$p.app.tabs.sel].module[l_newId].placeinCol(vars['target'].cell,indef,vars['position'],vars['target']);
                }
                else
                {
                    tab[$p.app.tabs.sel].module[l_newId].placeinCol(celltoUse);
                }

				                
			}
		}
		else    {
			$p.app.debug("Cache is not generated for this module","error");
		}
        $p.app.widgets.currentClass = 'module';
	},
	/*
			Function: $p.app.widgets.close
                                            Destruct module object
                                            
                                Parameters:
                                
                                             v_type -  uniq / portal
	*/
	close:function(v_type)
	{
        var l_tab = ($p.app.tabs.sel == -1 ? 0 : $p.app.tabs.sel);
        
		// if last module created is not placed in the portal
		if (tab[l_tab].module.length == 0) return;
        
		var l_id = tab[l_tab].module.length - 1;
        
		if (tab[l_tab].module[l_id].newcell == 0 || v_type == "uniq")
		{
			$p.app.widgets.supFeed(l_id,l_tab);
			tab[l_tab].module[l_id].destruct();
			delete(tab[l_tab].module[l_id]);
			tab[l_tab].module.length -= 1;
			tab[l_tab].maxUniq --;
		}
        
		//$p.print("newmod","");
		//$p.show("newmod","none");
		showNewMod=false;

        // remove temp tab used when widget is open outside a tab
        if (tab[0].temporary && tab[0].label == 'widget')
        {
            $p.app.pages.suppress(0,false,false);
        }
	},
	/*
			Function: $p.app.widgets.refreshAWidgetInAllPages
						Refresh a widget in all pages
						
			Parameters:
			
						 v_id -  Widget ID (ID of dir_item table)
	*/
	refreshAWidgetInAllPages: function(v_id)
	{
		for (var i = 0; i < tab.length; i++)
		{
			for (var j = 0; j < tab[i].module.length; j++)
			{
				if (tab[i].module[j].id = v_id)
				{
					tab[i].module[j].refresh();
				}
			}
		}
	}
}



//************************************ WIDGETS PARAM FUNCTIONS ***************************************************************************************************************
/*
    Class: $p.app.widgets.param
         Widgets param functions
*/
$p.app.widgets.param={
	/*
		Function: $p.app.widgets.param.show
                                Display module configuration area
                                
		Parameters:

			 v_uniq - module Uniq ID
             
                     Returns :
                     
                                false
	*/
	show:function(v_uniq, v_tab)
	{
		$p.show("embed_"+v_tab+'_'+v_uniq,"none");
		tab[$p.app.tabs.sel].module[$p.app.widgets.uniqToId(v_uniq)].bringToFront();
		if ($p.isShown("editbar"+tab[$p.app.tabs.sel].id+"_"+v_uniq)) 
        {
            $p.app.widgets.param.hide(v_uniq);
        }
		else 
        {
            $p.show("editbar"+tab[$p.app.tabs.sel].id+"_"+v_uniq,"block");
        }
		return false;
	},
	/*
		Function: $p.app.widgets.param.hide
                                 Hide module configuration area
                                 
		Parameters:

			 v_uniq - module Uniq ID
            
                      Returns:
                      
                                false
	*/
	hide:function(v_uniq)
	{
		$p.show("editbar"+tab[$p.app.tabs.sel].id+"_"+v_uniq,"none");
		if( $("embed_"+tab[$p.app.tabs.sel].id+"_"+v_uniq) ) {
			$p.show("embed_"+tab[$p.app.tabs.sel].id+"_"+v_uniq,"none");
		}
		return false;
	},
	/*
		Function: $p.app.widgets.param.displayWidgetTitle
                                 Display the widget title
                                 
		Parameters:

			 ptitle - widget title
            
                      Returns:
                      
                                HTML code
	*/
    displayWidgetTitle:function(ptitl)
    {
		if (__widgetTitleUpdatable) {
			var l_s='<tr>'
				+'<td>'
				+lg("lblModuleTitle")
				+'</td>'
				+'<td>'
				+'<input type="text" name="ptitl" size="18" value="'+$p.string.doubleToSimpleCot(ptitl)+'" />'
				+'</td>'
				+'</tr>';
		}
		else {
			var l_s='<input type="hidden" name="ptitl" value="'+$p.string.doubleToSimpleCot(ptitl)+'" />';
		}
		return l_s;
    },
	/*
		Function: $p.app.widgets.param.displayWidgetBarColors
                                 Display the widget colors
                                 
		Parameters:

			 v_tab - tab sequence ID
			 v_uniq - module Uniq ID
            
                      Returns:
                      
                                HTML code
	*/
    displayWidgetBarColors: function(v_tab,v_uniq)
    {
        var l_s = "";
        if (__barcolnb > 1) 
        {
            l_s += '<tr>'
                + '<td>'
                + lg('lblBarColor')
                + '</td>'
                + '<td>'
                + '<ul style="margin: 0px;padding: 0px;">';

            for (var i = 1;i <= __barcolnb;i++)
            {
                l_s += '<li class="barstyle'+i+' barcoli" onclick="return $p.app.widgets.param.setBColor('+v_uniq+','+i+')" style="margin: 2px;display: block;width: 20px;height: 20px;list-style: none;float: left;font-size: 2px;" id="barcol'+tab[v_tab].id+'_'+v_uniq+'-'+i+'">&nbsp;</li>';
            }
            l_s += '</ul>'
                + '<input type="hidden" name="bcolor" value="" />'
                + '</td>'
                + '</tr>';
                
                l_s += '<tr>'
                + '<td></td>'
                + '<td><ul style="margin: 0px;padding: 0px;">'
                + '<li class="barcoli" onclick="return $p.app.widgets.param.setBColor('+v_uniq+');" style="margin: 2px;display: block;height: 38px;list-style: none;float: left;font-size: 10px;align: center; vertical-align: middle;padding: 4px;white-space: normal;width: 60px;" id="barcol'+tab[v_tab].id+'_'+v_uniq+'-">' + lg('defaultColor') + '</li>'
                + '</ul></td>'
                + '</tr>';                
        } 
        return l_s;
    },
	/*
		Function: $p.app.widgets.param.displayBlockWidget
                                 Display the blocking widget option (for admin)
                                 
		Parameters:

			 v_tab - tab sequence ID
			 v_uniq - module Uniq ID
            
                      Returns:
                      
                                HTML code
	*/
    displayBlockWidget:function(v_tab,l_id)
    {
        if (!$p.app.widgets.showAdminProperties) return '';
        else
        {
            return  '<tr>'
                    + '<td class="tophr">'
					+ lg("lblFixedModule")
                    + '</td>'
                    + '<td class="tophr">'
					+ '<input type="radio" value="0" name="admblocked"'+(tab[v_tab].module[l_id].blocked == 0?' checked="checked"':'')+' />'
					+ lg("no")
					+ '<br />'
					+ '<input type="radio" value="2" name="admblocked"'+(tab[v_tab].module[l_id].blocked == 2?' checked="checked"':'')+' />'
					+ lg("no") + ' (' + lg('notRemovable') + ')'
					+ '<br />'
					+ '<input type="radio" value="1" name="admblocked"'+(tab[v_tab].module[l_id].blocked == 1?' checked="checked"':'')+' />'
					+ lg("yes")
                    + '</td>'
                    + '</tr>';
        }    
    },
	/*
		Function: $p.app.widgets.param.displayButtons
                                 Display submit and close buttons
                                 
		Parameters:

			 v_uniq - module Uniq ID
            
                      Returns:
                      
                                HTML code
	*/
    displayButtons: function(v_uniq)
    {
        return  '<tr>'
                + '<td colspan="2" align="center">'
                + '<br />'
                + '<input class="submit" type="submit" value="'+lg("lblBtnValid")+'" /> '
                + '<input class="btn" type="button" onclick="return $p.app.widgets.param.hide('+v_uniq+');" value="'+lg("lblClose")+'" />'
				+ '</td>'
                + '</tr>';
    },
	/*
		Function: $p.app.widgets.param.displayWidgetOptions
                                 Display widget specific options
                                 
		Parameters:

			response - XML object
			v_tab - tab sequence ID
			v_uniq - module Uniq ID
                                l_id - module id in tab
            
                      Returns:
                      
                                HTML code
	*/
    displayWidgetOptions:function(response,v_tab,l_id,v_uniq)
    {
        var i=0;  
        var l_s="";   
        while (response && response.getElementsByTagName("UserPref")[i])
        {                           
            var parameters = new Array;  
            var key="";
            var resHTML="";
            var l_pref=response.getElementsByTagName("UserPref")[i];
            var l_type=$p.ajax.getProp(l_pref,"datatype","str",false,"string");
            var l_name=$p.ajax.getProp(l_pref,"name","str",true,"");
            var l_selValue=$p.string.getVar(tab[v_tab].module[l_id].vars,l_name);
			if(l_name == "myurl")
				l_selValue = $p.string.unesc($p.ajax.getProp(l_pref,"default_value","str",true,"--"));
            var l_restriction=$p.ajax.getProp(l_pref,"restricted","str",false,"AI");    	
            var l_def=(l_selValue=="")      ?       lg($p.ajax.getProp(l_pref,"default_value","str",false,""))
                                            :       l_selValue;
            
            if ( (l_type!="hidden") 
                 && ((l_restriction=="A" 
                      && $p.app.user.type=="A") 
                 || (l_restriction=="AI")) )    key=lg($p.ajax.getProp(l_pref,"display_name","str",false,"")); 
                 
            parameters = {
                            'type':l_type,
                            'name':l_name,
                            'value':l_def,
                            'id':"editboxinput_"+tab[v_tab].id+"_"+v_uniq+"_"+l_name
                         };

            if ( (l_type=="enum")
                 && ( (l_restriction=="A" && $p.app.user.type=="A") 
                 || (l_restriction=="AI") ) ) {  resHTML=$p.html.form.buildEnum(parameters,l_pref);    }
                
            if ( (l_type=="bool")
                 && ( (l_restriction=="A" && $p.app.user.type=="A") 
                 || (l_restriction=="AI") ) )  {  resHTML=$p.html.form.buildCheckbox(parameters); }
            
            if ( (!(l_type=="enum" || l_type=="bool")) 
                  && ( (l_restriction=="A" && $p.app.user.type=="A") 
                  || (l_restriction=="AI") ) )  {    resHTML=$p.html.form.buildInput(parameters);   }
           
            l_s+="<tr><td>"+key+"</td><td id='inp"+v_uniq+i+"'>"+resHTML+"</td></tr>";
           
            i++;
        }

        // get widget on your website link
        if (__allowGetWidgetOnMySite && tab[v_tab].module[l_id].group_access == 0)
            l_s += '<tr><td></td><td><a href="#" onclick="return $p.app.widgets.param.showCode('+v_uniq+',\''+tab[v_tab].id+'\');">'+lg("Embed")+'</a></td></tr>'
	
        return l_s;
    },
	/*
		Function: $p.app.widgets.param.displayWidgetIcalUrl
                                 Display the icalendar url
                                 
		Parameters:

			 icalurl - icalendar url
            
                      Returns:
                      
                                HTML code
	*/
    displayWidgetIcalUrl:function(icalurl, w_id)
    {
		var l_s=""; 
		if( w_id == 112 )
			l_s = '<tr><td>'+lg("lblICal")+'</td><td><input type="text" id="icalurl" name="icalurl" value="'+icalurl+'" /></a></td></tr>';
		
		return l_s;
	},
	/*
		Function: $p.app.widgets.param.fillEditBox
                                Fill in module configuration area
                                
		Parameters:

			response - configuration options XML response
			v_uniq - module uniq ID
			v_tab - tab sequence ID
             
                     Returns :
                     
                                false
	*/
    fillEditBox: function(response,v_uniq,v_tab)
	{
		$p.plugin.hook.launch('app.widgets.param.fillEditBox.start');
		
		//generate edit box for a module
		if (v_tab == indef) v_tab = $p.app.tabs.sel;

		var l_id = $p.app.widgets.uniqToId(v_uniq,v_tab);
            ptitl = ($p.string.getVar(tab[v_tab].module[l_id].vars,"ptitl")==""    ?    tab[v_tab].module[l_id].name
                                                                      :    $p.string.unesc($p.string.getVar(tab[v_tab].module[l_id].vars,"ptitl")));
		var icalurl = $p.string.unesc($p.string.getVar(tab[v_tab].module[l_id].vars,"icalurl"));

		if (tab[v_tab].module[l_id].format != 'R' || tab[v_tab].showType == 0)
		{
            var localfolder = __LOCALFOLDER;
            localfolder = localfolder.replace(/http:/,$p.navigator.getProtocol());           
            l_s = '<form name="editform'+tab[v_tab].id+'_'+v_uniq+'" onsubmit="return $p.app.widgets.param.valid('+v_uniq+');">'
                + '<table cellpadding="2" cellspacing="0" width="90%">'
                + $p.app.widgets.param.displayWidgetTitle(ptitl)
                + $p.app.widgets.param.displayWidgetBarColors(v_tab,v_uniq)
                + $p.app.widgets.param.displayWidgetOptions(response,v_tab,l_id,v_uniq)
				+ $p.app.widgets.param.displayWidgetIcalUrl(icalurl,tab[v_tab].module[l_id].id)
                + $p.app.widgets.param.displayBlockWidget(v_tab,l_id)
                + $p.app.widgets.param.displayButtons(v_uniq)
                + '<tr>'
                + '<td colspan="2" align="center"><div id="embed_'+tab[v_tab].id+'_'+v_uniq+'" style="display: none;">'
    			+ '<textarea rows="3" cols="70"><iframe id="portaneowidget" src="'+localfolder
					+$p.app.widgets.param.generateSharedUrl(v_tab,l_id)
				+'" width="400" height="300" frameborder="0"></iframe>'
    			+ '</textarea></div>'
                + '</td>'
                + '</tr>'
                + '</table>'
                + '</form>';

			$p.print("editbar"+tab[v_tab].id+"_"+v_uniq,l_s);
			$p.app.widgets.param.setBColor(v_uniq,$p.string.getVar(tab[v_tab].module[l_id].vars,"bcolor"),v_tab);
			$p.app.widgets.changeName(l_id,ptitl,v_tab);
		}

		$p.plugin.hook.launch('app.widgets.param.fillEditBox.end');
	},
	/*
		Function: $p.app.widgets.param.generateSharedUrl
                                 Generate shared url  according to module id
                                 
		Parameters:
			v_tab - tab sequence ID
			 l_id
            
		Relatealso:
			$p.app.widgets.param.fillEditBoxd
			
		See also (test fonctionnel): 
				Check the url to export
				- click on "configuration" in the menu widget
				- click on "View this widget on your site"
				- copy the URL in the fields in a new browser window
                      Returns:
                      
                              shared  url
		
	*/
    generateSharedUrl:function(v_tab,l_id)
    {
		var url = 'portal/widgetforyoursite.php?id='+tab[v_tab].module[l_id].id;
			url += ($p.string.getVar(tab[v_tab].module[l_id].vars,"noteid")!="")
				?'&noteid='+$p.string.getVar(tab[v_tab].module[l_id].vars,"noteid")
				:"";
			if($p.string.getVar(tab[v_tab].module[l_id].vars,"favid")!="") {
				url += '&linkid='+$p.string.getVar(tab[v_tab].module[l_id].vars,"favid")
			}else{
				url += ($p.string.getVar(tab[v_tab].module[l_id].vars,"linkid")!="")
				?'&linkid='+$p.string.getVar(tab[v_tab].module[l_id].vars,"linkid")
				:"";
			}
			/*url += ($p.string.getVar(tab[v_tab].module[l_id].vars,"linkid")!="" && $p.string.getVar(tab[v_tab].module[l_id].vars,"favid")=="")
				?'&linkid='+$p.string.getVar(tab[v_tab].module[l_id].vars,"linkid")
				:"";*/
			url += ($p.string.getVar(tab[v_tab].module[l_id].vars,"calid")!="")
				?'&calid='+$p.string.getVar(tab[v_tab].module[l_id].vars,"calid")
				:"";
			url += ($p.string.getVar(tab[v_tab].module[l_id].vars,"taskid")!="")
				?'&taskid='+$p.string.getVar(tab[v_tab].module[l_id].vars,"taskid")
				:"";
			url += ($p.string.getVar(tab[v_tab].module[l_id].vars,"addid")!="")
				?'&addid='+$p.string.getVar(tab[v_tab].module[l_id].vars,"addid")
				:"";
			url += (tab[v_tab].module[l_id].w_pfid!=indef)
				?'&pfid='+tab[v_tab].module[l_id].w_pfid
				:"";
		url += ($p.string.getVar(tab[v_tab].module[l_id].vars,"sharedkey")!="")
				?'&shareditemkey='+$p.string.getVar(tab[v_tab].module[l_id].vars,"sharedkey")
				:"";
		return url;
	},
	/*
		Function:   $p.app.widgets.param.valid
        
                                 Save configuration changes for a module
                                 
		Parameters:

			 v_uniq - module uniq ID
             
                     Returns:
                     
                                false
	*/
	valid:function(v_uniq)
	{
		$p.plugin.hook.launch('app.widgets.param.valid.start');
        
        var className,
            l_form=document.forms["editform"+tab[$p.app.tabs.sel].id+"_"+v_uniq],
            i = 0,
            l_var,
            l_vars = [],
            l_refreshAll = false,
            l_id = $p.app.widgets.uniqToId(v_uniq);
       
        //canvas part : doesn't exists in base, only the original widget exists and must be updated
        var parent_uniq = 0,
            l_id_parent = 0;

        if ( tab[$p.app.tabs.sel].module[l_id] 
                && tab[$p.app.tabs.sel].module[l_id].UniqParent ) {
            className = 'canvas';
        }
     
		while(l_form.elements[i])
		{
			l_var = "";
			switch($p.string.lc(l_form.elements[i].type))
			{
				case "text":
				case "password":
				case "select-one":
				case "hidden":
					//l_var=l_form.elements[i].name+"="+$p.string.esc(l_form.elements[i].value);break;
					//1.4.3 fix : for url, _esc is required. For titles, _esc is altering accentuated signs
					tmp_l_var = l_form.elements[i].value;
					if (l_form.elements[i].name=="ptitl") {
						tmp_l_var = $p.string.escapeAndSign(tmp_l_var);
					}
					l_var = l_form.elements[i].name + "=" + tmp_l_var;
					break;
				case "checkbox":
				case "radio":
					l_var = (l_form.elements[i].checked?l_form.elements[i].name+"=1":l_form.elements[i].name+"=0");break;
			}
			if ((l_form.elements[i].name).substr(0,3)=="adm")   {
				if (l_form.elements[i].name=="admblocked")  {
					//the entire module needs to be refresh -> only solution: refresh all the modules
					if (l_form.elements[i].checked)
					{
						if (tab[$p.app.tabs.sel].module[l_id].blocked != l_form.elements[i].value) 
							l_refreshAll = true;
						tab[$p.app.tabs.sel].module[l_id].blocked = l_form.elements[i].value;
					}
				}
			}
			else
			{
				if (l_var != "") {
                    //if there is a userpref with URL containing "&", need to encode it !
				    if ( l_var.search(/http:\/\//i) != -1 ) {
						 if (l_var.search(/&amp;/i) == -1 ) {
                            l_var = l_var.replace(/&/g,'&amp;');
                         }
                    }
					// } else {
						// l_var = l_var.replace(/&/g,'');
					// }
					l_vars.push(l_var);
				}
			}
			i++;
		}
		var l_qs = l_vars.join("&");

		//if title has changed or not
		if (tab[$p.app.tabs.sel].module[l_id].name != $p.string.getVar(l_qs,"ptitl")) {
			$p.app.widgets.changeName(l_id,$p.string.getVar(l_qs,"ptitl"));
		}
		//if icon is set, keep it
		if ($p.string.getVar(tab[$p.app.tabs.sel].module[l_id].vars,"icon")!="") 
        {
            l_qs += "&icon="+$p.string.getVar(tab[$p.app.tabs.sel].module[l_id].vars,"icon");
        }
		// //if icalendar url is set, keep it
		// if ( $p.string.getVar(l_qs,"icalurl")!="" ) 
        // {
            // l_qs += "&icalurl=" + $p.string.esc($p.string.getVar(l_qs,"icalurl"));
        // }
        tab[$p.app.tabs.sel].module[l_id].changeVar("",l_qs);
		
		if (l_refreshAll)   {
			$p.app.pages.init($p.app.tabs.sel);
			$p.app.widgets.param.hide(v_uniq);
		}
		else    
        {
			tab[$p.app.tabs.sel].module[l_id].refresh();
            $p.app.widgets.currentClass='module';
			tab[$p.app.tabs.sel].module[l_id].hdrColor(indef,indef,className);
			$p.app.widgets.param.hide(v_uniq);
		}

		// define that the current tab has been modified
		tab[$p.app.tabs.sel].modified = true;
		
		$p.plugin.hook.launch('app.widgets.param.valid.end');

		return false;		
	},
    
	/*
		Function:   $p.app.widgets.param.getModuleParam
                                 Load module configuration
                                 
		Parameters:

			v_id - module sequence ID
			v_tab - tab sequence ID
	*/
	getModuleParam:function(v_id,v_tab)
	{
		if (v_tab==indef) v_tab=$p.app.tabs.sel;    
        var UrlgetXmlCode=indef;
        //not yet in use
        var inactive=1;
        if (inactive==2 && tab[v_tab].module[v_id].url.match(/getsource/)) {
            UrlgetXmlCode = tab[v_tab].module[v_id].url;
            UrlgetXmlCode=UrlgetXmlCode.replace(/getsource/,"getxml");
        }
        var language_param='';
        if ( tab[v_tab].module[v_id] && tab[v_tab].module[v_id].l10n &&  tab[v_tab].module[v_id].l10n.match(__lang)) {
            language_param = "_"+__lang;
        }
        var l_url="../modules/module"+tab[v_tab].module[v_id].id+language_param+"_param.xml";
		switch ($p.app.env)
		{
			case "tutorial":
				l_url="../modules/tmp_module"+tab[v_tab].module[v_id].id+"_param.xml";
                if (UrlgetXmlCode) {
                    l_url=UrlgetXmlCode+"&env=tut";
                }
				break;
			case "portal_page_conn":
				l_url="../modules/module"+tab[v_tab].module[v_id].id+language_param+"_param.xml";
                l_url=l_url.replace(/\?/g,"");
                if (UrlgetXmlCode) {
                    l_url=UrlgetXmlCode;
                } 
				break;
			case "portal":
				l_url="../modules/module"+tab[v_tab].module[v_id].id+language_param+"_param.xml";
                l_url=l_url.replace(/\?/g,"");
                if (UrlgetXmlCode) {
                    l_url=UrlgetXmlCode;
                } 
				break;                
			default:
				l_url="../modules/module"+tab[v_tab].module[v_id].id+language_param+"_param.xml";
				break;
		}
		l_url=l_url.replace(/\?/g,"");
		$p.ajax.call(l_url,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.widgets.param.treatModuleParam,
					'variables':
					{
						'widgetid':tab[v_tab].module[v_id].uniq,
						'tabpos':v_tab,
                        'v_id'  : v_id
					}
				},
				'source':'xml'
			}
		);
	},
	/*
		Function:$p.app.widgets.param.treatModuleParam
                                Initialize module configuration
                               
		Parameters:

			response - XML object
			vars (array) - variables (optionnal)
	*/
	treatModuleParam:function(response,vars)
	{
        if (response.getElementsByTagName("Module")[0])
		{
			var l_mod=response.getElementsByTagName("Module")[0];
            $p.app.widgets.param.fillEditBox(l_mod,vars['widgetid'],vars['tabpos']);
		} else {

        }
	},
	/*
		Function:$p.app.widgets.param.setBColor
                                Define module header color
                                
		Parameters:

			v_uniq - module Uniq ID
			v_color - color number (of CSS file)
			v_tab - tab sequence ID
            
                      Returns:
                      
                               false
	*/     
	setBColor: function(v_uniq,v_color,v_tab)
	{
		//get the new color number in the form
		if (__barcolnb < 2) return false;
		if (v_tab == indef) v_tab = $p.app.tabs.sel;
		if (!v_color) v_color = "";
		if (!document.forms["editform"+tab[v_tab].id+"_"+v_uniq]) return false;
		document.forms["editform"+tab[v_tab].id+"_"+v_uniq].bcolor.value = v_color;
		//change selected image border
        ($("barcol"+tab[v_tab].id+"_"+v_uniq+"-")).className = (($("barcol"+tab[v_tab].id+"_"+v_uniq+"-")).className).replace(/barcolb/g,'barcoli');
        for (var i = 1;i <= __barcolnb;i++)
		{
			($("barcol"+tab[v_tab].id+"_"+v_uniq+"-"+i)).className = (($("barcol"+tab[v_tab].id+"_"+v_uniq+"-"+i)).className).replace(/barcola/g,'barcoli');
		}
        if (v_color == "")
            ($("barcol"+tab[v_tab].id+"_"+v_uniq+"-"+v_color)).className = (($("barcol"+tab[v_tab].id+"_"+v_uniq+"-"+v_color)).className).replace(/barcoli/g,'barcolb');
        else
            ($("barcol"+tab[v_tab].id+"_"+v_uniq+"-"+v_color)).className = (($("barcol"+tab[v_tab].id+"_"+v_uniq+"-"+v_color)).className).replace(/barcoli/g,'barcola');
        
        return false;
	},
	/*
		Function:$p.app.widgets.param.showCode
                                Show module embed code
                                
		Parameters:

			v_uniq - embed code Uniq ID

            
                      Returns:
                      
                               false
	*/  
	showCode:function(v_uniq, v_tab)
	{
		$p.show("embed_"+v_tab+'_'+v_uniq,"block");
		
		return false;
	}
}




//************************************ WIDGETS MOVES FUNCTIONS ***************************************************************************************************************
/*
    Class: $p.app.widgets.move
         Widgets moves functions
*/
$p.app.widgets.move={
	obj: null,
	status: '',
	/*
		Function: $p.app.widgets.move.init
        
                                 Init module move
                                 
		Parameters:

			 mObj - module object
	*/
	init:function(mObj)
	{
		mObj.onmousedown = $p.app.widgets.move.start;
		
		// create the moving widget
		var l_obj = $p.app.widgets.move.shadow();
		
		if(isNaN(l_obj.style.left.toInt())) l_obj.setStyle("left","0px");
		if(isNaN(l_obj.style.top.toInt())) l_obj.setStyle("top","0px");
		mObj.onDragStart = new Function();
		mObj.onDragEnd = new Function();
		mObj.onDrag = new Function();
	},
	/*
		Function: $p.app.widgets.move.start
                                 Start object move
                                 
		Parameters:

			 e - mouse event object
             
                      Returns:
                      
                                 false
	*/
	start:function(e)
	{       
		if (this != indef && this.id != indef)
			$p.app.widgets.move.obj = this;
			
		var mObj = $p.app.widgets.move.obj;
		e = $p.app.widgets.move.fixE(e);
		//change the css style to draw a shadow
		var l_obj = $p.app.widgets.move.shadow();
		
		mObj.onDragStart(l_obj.style.left.toInt(),l_obj.style.top.toInt(),e.clientX,e.clientY);
		//Get mouse position
		mObj.lastMouseX = e.clientX;
		mObj.lastMouseY = e.clientY;
		document.onmousemove = $p.app.widgets.move.drag;
		document.onmouseup = $p.app.widgets.move.end;
		
		//change the obj status
		$p.app.widgets.move.status = "dragging";
		
		if ($p.app.widgets.move.obj.id.substr(0,6) == 'module')
			$p.app.pages.columns.highlight();

		return false;
	}, 
	/*
		Function: $p.app.widgets.move.drag
                                 Manage object move
                                 
		Parameters:

			 e - mouse event object
             
                      Returns:
                      
                                 false
	*/
	drag:function(e)
	{
		//get position
		e = $p.app.widgets.move.fixE(e);
		var mObj = $p.app.widgets.move.obj;
		var mX = e.clientX;
		var mY = e.clientY;
		var posX,posY;
		var l_obj = $p.app.widgets.move.shadow();
		posX = l_obj.style.left.toInt()+mX-mObj.lastMouseX;
		posY = l_obj.style.top.toInt()+mY-mObj.lastMouseY;		
		l_obj.setStyle("left",posX+"px");
		l_obj.setStyle("top",posY+"px");
		mObj.lastMouseX=mX;
		mObj.lastMouseY=mY;

		if ($p.navigator.IE)    {
			mObj.onDrag((mX+document.documentElement.scrollLeft),(mY+document.documentElement.scrollTop));
		}
		else    {
			mObj.onDrag(e.pageX,e.pageY);
		}
		return false;
	}, 
	/*
		Function: $p.app.widgets.move.end
                                 Stop module move
	*/
	end:function()
	{
		document.onmousemove = null;
		document.onmouseup = null;
		var l_obj = $p.app.widgets.move.shadow();
		
		$p.app.widgets.move.obj.onDragEnd(l_obj.style.left.toInt(),l_obj.style.top.toInt());
		$p.app.widgets.move.obj = null;
		
		$p.app.pages.columns.stopHighlight();
		
		$p.app.widgets.move.status = "";
	},
	/*
		Function: $p.app.widgets.move.fixE
                                 No idea => ask ERIC
                                 
		Parameters:

			 e - mouse event object
             
                      Returns:
                      
                                 mouse event object
	*/
	fixE:function(e)
	{
		if(e==indef && window.event) e=window.event;
		if(typeof e.layerX=="undefined")e.layerX=e.offsetX;
		if(typeof e.layerY=="undefined")e.layerY=e.offsetY;
        return e;
	},
	/*
		Function: $p.app.widgets.move.shadow
                                 Create module shadow on move
             
                      Returns:
                      
                                 div element
	*/
	shadow:function()
	{
		if(!mDivObj || mDivObj==null)
		{
			if (createDivDynamically)
			{
				mDivObj = new Element('div',
					{
						'styles':
						{
							'display': 'block',
							'position': 'absolute',
							'cursor': 'move',
							'backgroundColor': '#fff',
							'paddingBottom': '0px',
                            'border-color':'#f00'
						}
					}
				);
				document.body.appendChild(mDivObj);
			}
			else
			{
				mDivObj=$("moveddiv");
			}
		}
		return mDivObj;
	},
	/*
		Function: $p.app.widgets.move.hideShadow
                                 Hide module shadow after move
	*/
	hideShadow:function()
	{
		$p.app.widgets.move.shadow().setStyle("display","none");
		//IE bug : after module move, $p.app.widgets.param.valid was not working any more
		$p.app.pages.clean(mDivObj);
	},
	/*
		Function: $p.app.widgets.move.moveShadow
                                 move module shadow
		Parameters :
			v_moveX : Horizontal move in pixels
			v_moveY : vertical move in pixels
		
	*/
	moveShadow:function(v_moveX,v_moveY)
	{
		var l_obj = $p.app.widgets.move.shadow();
		if (v_moveX != indef && v_moveX != 0)
			l_obj.setStyle("left",((l_obj.style.left).toInt() + v_moveX)+"px");
		if (v_moveY != indef && v_moveY != 0)
			l_obj.setStyle("top",((l_obj.style.top).toInt() + v_moveY)+"px");
	},
	/*
		Function: $p.app.widgets.move.formatShadow
                                 Format the shadow based on the original object                                 
                                
                     Parameters:

			 v_content - original object HTML code
             
                      Returns:
                      
                                content with other events removed
	*/
	formatShadow:function(v_content)
	{
		v_content=$p.string.lc(v_content);
		//* suppress the iframes
		while(v_content.indexOf("<iframe")!=-1)
		{
			var l_p1=v_content.indexOf("<iframe");
			var l_p2=v_content.indexOf("</iframe>")+9;
			v_content=v_content.substr(0,l_p1)+v_content.substr(l_p2,v_content.length);
		}
		//other events during drag could interfert
		v_content=v_content.replace(/onmouseover=/g,"");
		v_content=v_content.replace(/onmouseout=/g,"");
		return v_content;
	},
	/*
		Function: $p.app.widgets.move.set
                                Initialize objects move (modules, tabs, ...)
                                
		Parameters:

			v_obj - object initialized
			v_type - object type value : module or tab
			v_parent - parent object of the moved object
			v_direction - allowed move directions - horizontal / vertical / multidim
			v_usecache - is the cache div initialized on move
			v_extra - extra information, l_tabPos alias $p.app.tabs.sel
            
             See also:
                    - <$p.app.tabs.initMove> init move of a tab
                    - <$p.app.pages.columns.init> init move of all modules in a page
                    - <$p.app.widgets.placeIn> init move on a new module
                    - <$p.app.widgets.initMove> init move of all widgets in a tab
	*/
	set: function(v_obj,v_type,v_parent,v_direction,v_usecache,v_extra)
	{
        var l_obj = $(v_obj.id+"_h");
        //window.location.hash = "#";
        
		// if the node is not recognize as a moving object, go to next node
		if(!l_obj)return;
		if (v_type == "module")
        {
			if (v_extra == indef)
				v_extra = $p.app.tabs.sel;
			//Check that module is movable
			var l_id = $p.app.widgets.getModuleId(v_obj);
			if (tab[v_extra].module[l_id].blocked == 1 && $p.app.user.id!=-1)
				return;
		}
		// move cursor on bar mouseover
		l_obj.setStyle("cursor","move");
		l_obj.objMoved = v_obj;
		$p.app.widgets.move.init(l_obj);
		// manage an url in the object header
		var l_uObj=$(v_obj.id+"_u");  

        // redefine the tab link
		if(l_uObj)
        {
            var l_currentUrl = windowLocationObject.href;
            var l_calledUrl = $p.url.simpleUrl(l_uObj.href);
			// if URL called is on the same domain than the page url (Admin)
            if (l_currentUrl.indexOf(l_calledUrl) == -1)
            {
				//l_uObj.onmousedown=function()
				l_obj.onmousedown = function()
                {
                    window.open(this.href);
                }
			}
			else
            {
				//l_uObj.onmousedown=l_uObj.onclick;
				l_uObj.onmousedown = function(){}
			}
		}
		l_obj.onDragStart=function()
		{	
			var l_selObj=this.objMoved;
			$p.app.widgets.move.setPos(l_selObj,v_parent);
			l_selObj.origNextSibling=l_selObj.nextSibling;
			
			// dragged object building - when the object's beeing dragged, a special style is defined.
			var mDivObj=$p.app.widgets.move.shadow();
			mDivObj.setStyle("zIndex",1000);
			
			mDivObj.style.left=$p.getPos(l_selObj,"Left")+"px";
			mDivObj.style.top=$p.getPos(l_selObj,"Top")+"px";
			
			mDivObj.setStyle("height",l_selObj.offsetHeight+"px");
			mDivObj.setStyle("width",l_selObj.offsetWidth+"px");
			mDivObj.setStyle("display","block");
			mDivObj.setOpacity("0.6");
			mDivObj.setStyle("filter","alpha(opacity=60)");
			mDivObj.set('html',(v_type=="module")?$p.app.widgets.move.formatShadow(l_selObj.innerHTML):l_selObj.innerHTML);
			mDivObj.className=l_selObj.className;

			this.isDrag=false;
			if (v_usecache) $p.app.cache.show("block");
		} ;

		l_obj.onDrag=function(v_x,v_y)
		{        
            // used when the widget is displayed out of a tab
            var l_tab = ($p.app.tabs.sel == -1 ? 0 : $p.app.tabs.sel)

			if (tab[l_tab].moduleAlign)   {
				this.canBeReleased=objMove(this.objMoved,v_x,v_y,v_parent,v_direction,v_type);
			}
			else {
				this.canBeReleased=objFreeMove(this.objMoved,v_x,v_y,v_parent,v_direction,v_type);
			}
			this.isDrag=true;
			$p.app.widgets.dragging = true;
		} ;
		
		l_obj.onDragEnd=function(v_x,v_y)
		{
			$p.app.widgets.move.hideShadow();
			if (!$p.navigator.IE) $p.app.pages.resize();
			if(this.isDrag && this.canBeReleased)
			{        
                $p.app.widgets.currentClass='module';
                var l_tab = ($p.app.tabs.sel < 0 ? 0 : $p.app.tabs.sel);
				var l_uniq = this.objMoved.id.replace(v_type,"");
				if (v_type == "module")
				{
					l_uniq = l_uniq.substr(l_uniq.indexOf("_")+1);
					l_id = $p.app.widgets.uniqToId(l_uniq);
                    if (!tab[l_tab].moduleAlign)  {
                        tab[l_tab].module[l_id].newx = v_x - widgetDecalX;
                        tab[l_tab].module[l_id].newy = v_y - widgetDecalY;
                    }
                    var l_vars = [];
                    //if inside the widget area, or over a tab !
					if (
                        $p.app.tabs.overtabid != -1
                        || tab[l_tab].moduleAlign
                        || (tab[l_tab].module[l_id].newx > 0 
                            && tab[l_tab].module[l_id].newy > 0)
                    )
					{
						//set module position if modules are not aligned
						if (!tab[l_tab].moduleAlign)
                        {
							this.objMoved.setStyle("left",v_x+"px");
							this.objMoved.setStyle("top",v_y+"px");
						}
                        if (tab[l_tab].showType == 0)
                        {
                            //check if widget has changed column
                            var l_old = tab[l_tab].module[l_id].cell;
                            //below is not very good
                            //not at all, but we continue to use cell0 for widget set out of page
                            var l_new = 0;
                            if (this.objMoved.parentNode.id.match(/_/)) {
                                l_new = ((this.objMoved.parentNode.id).replace(/cell/,"")).replace(/_\d+/,"");
                            } else {
                                l_new = this.objMoved.parentNode.id.replace(/cell/,"");
                            }
                            if (l_old == l_new)
                            {
                                l_vars[0] = l_old;
                            }
                            else
                            {
                                l_vars[0] = l_old;
                                l_vars[1] = l_new;
                            }
                        }
                        else
                        {
                            l_vars[0] = 1;
                        } 
                        
						//l_vars  contains the two informations like X,Y x is the source col, Y the destination col
						//l_id       the module id
                        //save change of widget
                    	$p.app.widgets.saveChanges(l_vars); 

						if (tab[l_tab].id == 0 || tab[l_tab].temporary || tab[l_tab].type!=1)
                        {
							if ($p.app.tabs.overtabid!=-1)
                            {
								$p.app.widgets.insertInTab($p.app.tabs.overtabid,tab[l_tab].module[l_id].id,tab[l_tab].module[l_id].vars);
                                //recalculer le nombre de widgets par colonne
							}
                            else if ($p.app.tabs.overtabid==-1 && tab[l_tab].temporary && tab[l_tab].type == 3) {
                                  //close the temporary tab if it's been moved from a popup to nowhere.
                                  $p.app.widgets.close('uniq');
                            }
						}
						else
                        {
                            //add information in database if widget is set in another tab
							if ($p.app.tabs.overtabid != -1)
                            {
                                var oldcellid = tab[$p.app.tabs.sel].module[l_id].cell;
                                $p.app.pages.columns.updateNbWidgetByCol($p.app.tabs.overtabid,1,1,this.format);
                                $p.app.pages.columns.updateNbWidgetByCol(l_tab,oldcellid,-1,this.format);
								$p.app.widgets.changeTab($p.app.tabs.overtabid,l_uniq);
                            }
						}
						$p.app.tabs.moduleOutAll();
						//define modules display order
						if (!tab[l_tab].moduleAlign)
                        {
							for (var i = 0; i < tab[l_tab].module.length; i ++)
							{
								($("module"+tab[l_tab].id+"_"+tab[l_tab].module[i].uniq)).setStyle("zIndex",1);
							}
							this.objMoved.setStyle("zIndex",1000);

							$p.app.pages.computeFooterPosition();
						}
					}
				} 
           
				if (v_type == "tab"){$p.app.tabs.save(l_uniq);}
				if (v_type == "admpage"){$p.admin.pages.save(l_uniq);}
			}
			if (v_usecache) $p.app.cache.show("none");
			this.setStyle("zIndex",1);
			$p.app.widgets.dragging = false;
		}
	},
	/*
		Function: $p.app.widgets.move.setPos
                                Set object position during move
		
                     Parameters:

			v_obj - object moved
			v_parent - parent object
	*/
	setPos:function(v_obj,v_parent)
	{
		var l_lstNb = v_parent.length?v_parent.length:2;

        //exception if widget moved from a popup (only cell0 exists)
        var cpt = (l_lstNb == 2 && tab[$p.app.tabs.sel].type != 1)         ?       0               :       1;
        var cptEnd = (l_lstNb == 2 && tab[$p.app.tabs.sel].type != 1)      ?       l_lstNb-1       :       l_lstNb;
        
        for (var j=cpt;j<cptEnd;j++)
        {
            var l_decalY=0;
            var l_lst = v_parent.length
                ? v_parent[j].obj
                : v_parent;

            for (var i=0;i<l_lst.childNodes.length;i++)
            {
                var l_node=l_lst.childNodes[i];
                //* if the node is the treated div one, the next nodes must be moved up by div height
                if (l_node==v_obj) decalY=l_node.offsetHeight;
                //* set the position of each nodes (use of decalY for modules under the one moved)
                
                l_node.pagePosLeft=$p.getPos(l_node,"Left");
                l_node.pagePosTop=$p.getPos(l_node,"Top")-l_decalY;
            }
        }
	},
    /*
            Function: $p.app.widgets.move.isMovable
            
            
            Returns:    true or false 
    */
    isMovable: function (control,params) {
        return $p.app.widgets.move.controls[control](params);
    },
    chosenCol:0
}

$p.app.widgets.move.controls={
    /*
            Function: $p.app.widgets.move.controls.rowsLimited
            
                 Check if number of widgets in column is limited
                    and if maximum is already full 
    */
    rowsLimited: function (params)
	{
        var tabid = params['tabid'];
        var curcell =  params['currentcellobj'];
		var cells = params['parent'];
        var cellid=  $p.app.widgets.move.chosenCell > 0
			?	$p.app.widgets.move.chosenCell
			:   params['cellid']
				?	params['cellid']
				:   ((curcell.id).replace(/cell/,"")).replace(/_\d+/,"");

        if (tab[tabid].cells[cellid].nbWidgets['max'] == 0)
			return true;

        if (cellid && cellid > 0) {
            var nbwidgets = 0;
            
            if (params['inpage'] == 1) {
                //change in same page
                //-1 because widget is already added in column
                //nbwidgets = cols[colid].childNodes.length - 1;
                //var nbwidgets = tab[tabid].cells[colid].childNodes.length;
                $p.app.pages.columns.checkNbWidgetInaCol(tabid,cellid);
                nbwidgets = $p.app.pages.columns.getNbofWidgetByCol(tabid,cellid);
            } else {
                //change to another tab
                    //compute number of widgets in col
                    $p.app.pages.columns.checkNbWidgetinAnotherTab(tabid,cellid);
                    nbwidgets = $p.app.pages.columns.getNbofWidgetByCol(tabid,cellid);
            }

            if (nbwidgets >= tab[tabid].cells[cellid].nbWidgets['max'] ) {
                return false;
            }
        }
        return true;
    }
}

//************************************ WIDGETS RSS FUNCTIONS ***************************************************************************************************************
/*
    Class: $p.app.widgets.rss
        
            Widgets rss functions
 */        
$p.app.widgets.rss={
    temporaryId:100000,
    sortedFeedTab:[],
	/*
		Function: $p.app.widgets.rss.object  *(Contructor)*
                               RSS articles class
                               
		Parameters:
       
			id - uniq id of the article
			modUniq - uniq ID of the module where the article is
			modName - name of the module
			title - title of the article
			link - link of the article
			image - image of the article (optional)
			date - publication date of the article
			desc - description of the article
			read - read status of the article (true=read, false=not read)
			source - source of the article
            v_modid - module id container in module array
	*/
	//object:function(id,modId,modUniq,modName,title,link,image,date,desc,read,source)
	object:function(id,modUniq,modName,title,link,image,
            date,desc,isRead,source,modId)
	{ 
        this.id=id;
        
		//this.modId=modId;
		this.modUniq=modUniq;
		this.modName=modName;
		this.title=title;
		this.link=link;
		this.image=image;
		this.date=date;
		this.desc=desc;
		this.isRead=(isRead==indef  ?   0   :   isRead);
		this.source=source;
        this.modId = modId;
	},
	/*
		Function: $p.app.widgets.rss.summary 
                                Create top articles div
                               
	*/
	summary:function(){
		var l_s = "<div id='rsstoparticles'></div>";
		$p.print(v_div,l_s);

		$p.app.widgets.rss.getTopArticles();
	},
	opmlfile:"",
	/*
		Function: $p.app.widgets.rss.checkFeed 
                                Check the rss feed
                      
                     Parameters:
                       
                               v_rss - rss feed url
                               v_name - rss feed name
			v_auth - authentication string
                     
                     Returns:
                     
                                false
                      
                        See also:
                        
                            $p.app.widgets.rss.checkFeedXml
                                
	*/
	checkFeed:function(v_rss,v_name,v_auth)
	{
		try {
			v_rss = v_rss==indef  ? document.forms['rss'].vars.value
                                      :  v_rss;
            if (!$p.url.ishttp(v_rss))  
            {
                v_rss = "http://" + v_rss;
            }
			
			var l_rss = $p.string.esc(v_rss);
			var l_auth = (document.forms['rss'] && document.forms['rss'].pass)?$p.Base64.encode(document.forms['rss'].login.value+":"+document.forms['rss'].pass.value):v_auth,
				l_callbackvars = {'rss':l_rss,
					'auth':l_auth,
					'name':v_name,
					'loading':'indirect'
				},
				l_url,
				l_vars,
				l_method = 'POST';
			
			if (v_rss.indexOf(__LOCALFOLDER) == -1)
			{
				// define loading parameters depending on platform configuration
				if (__useproxy)
				{
					if (__proxypacfile == "")	
					{
						l_url = posh["xmlvalidrss"];
						l_vars = "useproxy=1&url="+l_rss+(l_auth==indef?"":"&auth="+l_auth);
					}
					else
					{
						if (getProxy(l_rss) == "")
						{
							if (l_auth == indef)
							{
								l_url = posh["xmlvalidrss"];
								l_vars = "url="+l_rss;
							}
							else
							{
								l_url = posh["xmlvalidrss"];
								l_vars = "url="+l_rss+"&auth="+l_auth;
							}
						}
						else
						{
							l_url = posh["xmlvalidrss"];
							l_vars = "useproxy=1&proxy="+getProxy(l_rss)+"&url="+l_rss+(l_auth==indef?"":"&auth="+l_auth);
						}
					}
				}
				else
				{
					if (l_auth==indef)
					{
						l_url=posh["xmlvalidrss"];
						l_vars="url="+l_rss;
					}

					else
					{	
						l_url=posh["xmlvalidrss"];
						l_vars="auth="+l_auth+"&url="+l_rss;
					}
				}
			}
			else
			{
				l_url = v_rss;
				l_callbackvars['loading'] = 'direct';
			}
            $p.ajax.call(l_url,
                {
                    'type':'load',
                    'callback':
                    {
                        'function':$p.app.widgets.rss.checkFeedXml,
                        'variables':l_callbackvars
                    },
                    'source':'html',
                    'variables':l_vars,
                    'method':l_method
                }
            );

            //rss checks notification
            $p.print("authrss",$p.img("ico_waiting.gif",16,16,"","imgmid")+" "+lg("checkingFeed"));
            $p.show("authrss","block");
        }
        catch(e)
        {
            $p.app.error.display(lg('lblDisplayErr'),'$p.app.widgets.rss.checkFeed',e);
            $p.print("authrss","none");
        }
	},
	/*
		Function: $p.app.widgets.rss.checkFeedXml 
        
                                Analyze feed testing return
                      
                     Parameters:
                       
                              response - XML object
                              vars (array) - variables (optionnal)
                     
                     Returns:
                     
                                false
	*/
	checkFeedXml:function(response,vars)
	{
		if (response.indexOf("<?xml") == -1 && response.indexOf("<rss") == -1)
		{
			if (response=="401")
			{
				$p.app.widgets.rss.authentification();
				return false;
			}
			if (response=="407")
			{
				$p.app.alert.show(lg("proxyRejectConnection"));
				$p.show("authrss","none");
				return false;
			}
			if (response.length==3 && response.substr(0,1)=="4")
			{
				$p.app.alert.show(lg("msgIncorrectFeed")+" ("+response+")");
				$p.show("authrss","none");
				$p.app.debug("HTTP Error code : "+response,"error");
				return false;
			}

			//if HTML page instead of xml, check if HTML page propose rss link
            var l_tags =$p.string.getLinks(response);
			//var l_tags=$p.string.simulateGetElementsByTagName(response,"link");
            var l_links="";
            
			if (l_tags.length>0)
			{
				for (var i=0;i<l_tags.length;i++)
				{
					if (l_tags[i]["type"]=="application/rss+xml")
					{
                        
                        var urlfct = $p.url.ishttp(l_tags[i]["href"])   ?   l_tags[i]["href"]   :
                                                                            document.forms['rss'].vars.value+'/'+l_tags[i]["href"];
                        var limitTitle = 35;
                        var title    = l_tags[i]["title"].length > limitTitle ?     (l_tags[i]["title"]).substr(0,limitTitle) + "...": 
                                                                                    l_tags[i]["title"];                                                 
                        var title = $p.string.trunk(l_tags[i]["title"],limitTitle,true);
 
                        l_links+='<p class="feedslist">'
                                +'<a href="#" onclick="$p.app.widgets.rss.checkFeed(\''+ urlfct +'\')\">'
                                +title+'</a></p>';
					}
				}
				if (l_links!="") l_links="<p>"+lg("availableFeedsForThisSite")+":</p>"+l_links;
	 		}
			if (l_links=="")
			{
				$p.app.alert.show(lg("msgIncorrectFeed"));
				$p.show("authrss","none");
				$p.app.debug("RSS Feed invalid. XML returned : "+response,"error");
			}
			else
			{
				$p.print("authrss",l_links);
				$p.show("authrss","block");
			}
		}
		else
        { 
            //get list of feeds from an html page
            $p.app.widgets.rss.getFeed(vars); 
        }
		
		return false;
	},
	/*
		Function: $p.app.widgets.rss.authentification 
                                Open authentification box to access authentified feed
	*/
	authentification:function()
	{
		$p.print("authrss","<span style='color:#ff0000'>"+lg("lblProtectedFeed")+"</span><br />"
                           +"<table>"
                           +"<tr><td>"
                           +lg("lblLogin")+"</td><td><input name='login' type='text' size='10' /></td></tr><tr><td>"
                           +lg("lblPassword")+"</td><td><input name='pass' type='password' size='10' /></td></tr><tr><td></td>"
                           +"<td><input type='submit' class='btn' value='Go' />"
                           +"</td></tr>"
                           +"</table>");
                           
		$p.show("authrss","block");
	},
	/*
		Function: $p.app.widgets.rss.getFeed 
                                Register feed information in DB
                      
                     Parameters:
                       
			vars - feed information
			v_fct - function called to display module
                     
                     Returns:
                     
                                false
	*/
	getFeed: function(vars,v_fct)
	{
		if (v_fct == indef) v_fct = $p.app.widgets.rss.getFeedXml;
		if (__useproxy)
		{
			if (__proxypacfile == "") {
				getXml(posh["xmlcheckfeed"],v_fct,vars,"xml","useproxy=1&url="+vars['rss'],"POST");
			}
			else
			{
				if (getProxy(vars['rss']) == "")  {
					getXml(posh["xmlcheckfeed"],v_fct,vars,"xml","url="+vars['rss'],"POST");
				}
				else    {
					getXml(posh["xmlcheckfeed"],v_fct,vars,"xml","useproxy=1&proxy="+getProxy(vars['rss'])+"&url="+vars['rss'],"POST");
				}
			}
		}
		else    {
			if (vars['loading'] && vars['loading'] == 'direct')
			{
				$p.app.widgets.rss.showMod(vars['rss'],0,vars['auth'],vars['name'],'');
				//getXml($p.string.unesc(vars['rss']),v_fct,vars,"xml","url="+vars['rss'] ,"POST");
			}
			else
			{
				if (typeof($p.tutorial) != 'undefined') {
					getXml(posh["xmlcheckfeed"],v_fct,vars,"xml","url="+vars['rss']+"&id="+$p.tutorial.widgetParameters['id'] ,"POST");
				} else {
					getXml(posh["xmlcheckfeed"],v_fct,vars,"xml","url="+vars['rss'] ,"POST");
				}
			}
		}
		return false;
	},
	/*
		Function: $p.app.widgets.rss.getFeedXml 
                                Treat checkfeed response
                      
                     Parameters:
                       
			response - XML object
			vars (array) - variables (optionnal)
	*/
	getFeedXml:function(response,vars)
	{
		if (response.getElementsByTagName("error")[0])  {
			$p.app.alert.show(lg("msgIncorrectFeed"));
			$p.show("authrss","none");
		}
		else
        {
			l_id = $p.ajax.getVal(response,"id","int",false,0);
            if (l_id == 0)
            {
                $p.app.error.display(lg('lblDisplayErr'),'$p.app.widgets.rss.getFeedXml','No id return from xmlcheckfeed.php file');
                return;
            }
			if (typeof($p.tutorial)!='undefined') {
				$p.tutorial.widgetParameters['icon'] = $p.ajax.getVal(response,"icon","str",false,0);
            }
			v_icon = $p.ajax.getVal(response,"icon","str",false,0);
			$p.app.widgets.rss.showMod(vars['rss'],l_id,vars['auth'],vars['name'],v_icon);
		}
	},
	/*
		Function: $p.app.widgets.rss.showmod 
                                Open RSS module
                      
                     Parameters:
                       
			v_rss - rss feed url
			v_id - rss feed DB ID
			v_auth - authentification string
			v_icon -  icon url
            
                    Returns:
                    
                                false
	*/
	showMod:function(v_rss,v_id,v_auth,v_name,v_icon)
	{
		//suppress checking feed notification
		$p.show("authrss","none");
		if ($p.app.tabs.sel=="999")
		{
            //$p.url.openLink(posh["rssaddtodirectory_step2"]+"?id="+v_id+(v_auth==indef?"":"&auth="+v_auth));
			$p.tutorial.rss.loadRssAddToDirectory_step2(v_id,v_auth);
		}
		else
		{
			if( v_icon=="" ) {
				v_icon = "rss"+v_id;
			}
			$p.app.widgets.open(86,"pfid="+v_id
                        +"&rssurl="+v_rss
                        +"&icon="+v_icon
                        +(v_auth==indef?"":"&auth="+v_auth)+(v_name==indef?"":"&ptitl="+v_name)
                        );
		}
		return false;
	},
	/*
		Function: $p.app.widgets.rss.refreshAll 
                                Refresh all feeds in all opened page
	*/
	refreshAll:function()
	{
		for (var i=0;i<tab.length;i++)
		{
			if (tab[i].isLoaded==true && !tab[i].temporary)
			{
				if (tab[i].feeds.length>0)  {
					$p.app.widgets.rss.init(i);
					tab[i].isLoaded=false;

                    if ( $p.app.tabs.sel == i ) {
                        $p.app.tabs.refresh($p.app.tabs.sel);
                    }
				}
				if (i==$p.app.tabs.sel && tab[$p.app.tabs.sel].showType==1) {
					$p.app.widgets.rss.reader.refresh();
				}
				else
				{
					for (var j=0;j<tab[i].module.length;j++)
					{
						if (tab[i].module[j].format=='R')   {
							tab[i].module[j].refresh();
						}
						else    {
							if (tab[i].module[j].autorefresh) tab[i].module[j].refresh();
						}
					}
				}
			}
		}
	},
	/*
		Function: $p.app.widgets.rss.reloadAndRefresh 
                                Refresh rss module in the tab selected
                      
                     Parameters:
                       
			v_id - module sequence ID
			v_tab - tab sequence ID
	*/ 
	reloadAndRefresh:function(v_id,v_tab)
	{ 
		$p.app.widgets.rss.refresh(v_id,v_tab,true);
	},
	/*
		Function: $p.app.widgets.rss.refresh  
                                Refresh rss module in the tab selected
                      
                     Parameters:
                       
			v_id (int) - module sequence ID
			v_tab (int) - tab sequence ID
                               v_reloadData (boolean) - reload data or not
            
                    Returns:
                    
                                false
	*/
	refresh: function(v_id,v_tab,v_reloadData)
	{			
		if (v_tab == indef) v_tab = $p.app.tabs.sel;
		$p.app.widgets.changeIcon(v_id,'../images/ico_waiting.gif',v_tab);

		//empty old feeds array
		if (v_reloadData)   
        {
			tab[v_tab].module[v_id].isLoaded = false;
			$p.app.widgets.supFeed(v_id,v_tab);
		}
		var l_oldNb = $p.string.getVar(tab[v_tab].module[v_id].vars,"nb",'int').toInt();
		var l_nb = (l_oldNb == 0 || isNaN(l_oldNb)) ? 5 : l_oldNb;
		//if no cache, add random number
		if (rssNoCache)
        {
			reset_rand();
			tab[v_tab].module[v_id].url += "pnocache="+rand+"&";
		}
		l_ext = $p.string.getVar(tab[v_tab].module[v_id].vars,"pwspecif");
		w_pfid = $p.string.getVar(tab[v_tab].module[v_id].vars,"pfid");
		tab[v_tab].module[v_id].w_pfid = $p.string.getVar(tab[v_tab].module[v_id].vars,"pfid");
		if (__registerfeeds)    {
			if (typeof($p.tutorial) != 'undefined') {
				tab[v_tab].module[v_id].vars = tab[v_tab].module[v_id].vars + "&auth="+$p.tutorial.widgetParameters["v_auth"];
			}
            $p.ajax.call("../portal/xmlfeeds"+l_ext+".php",
                {
                    'type':'load',
                    'variables':"rand="+rand+"&s="+tab[v_tab].module[v_id].start+"&"+tab[v_tab].module[v_id].vars,
                    'method':'POST',
                    'callback':
                    {
                        'function':$p.app.widgets.rss.display,
                        'variables':
                        {
                            'id':v_id,
                            'nb':l_nb,
                            'uniq':tab[v_tab].module[v_id].uniq,
                            'tab':v_tab
                        }
                    },
                    'caller':'getWidgetArticles',
                    'asynchron':false
                }
            );
		}
		else    {
            $p.ajax.call(tab[v_tab].module[v_id].url,
                {
                    'type':'load',
                    'variables':"rand="+rand
                            +"&pid="+$p.app.user.id
                            +"&prof="+tab[v_tab].id
                            +"&p="+tab[v_tab].module[v_id].uniq
                            +"&bar="+tab[v_tab].controls
                            +"&"+tab[v_tab].module[v_id].vars,
                    'method':'POST',
                    'callback':
                    {
                        'function':$p.app.widgets.rss.display,
                        'variables':
                        {
                            'id':v_id,
                            'nb':l_nb,
                            'uniq':tab[v_tab].module[v_id].uniq,
                            'tab':v_tab
                        }
                    },
                    'caller':'getWidgetArticles'
                }
            );
		}
		return false;
	},
	/*
		Function: $p.app.widgets.rss.deleteEntry 
                                Remove an article in an rss module
                      
                     Parameters:
                       
			v_mod - widget  ID
			RssArticleId - RSS article ID
	*/
	deleteEntry:function(v_mod,RssArticleId)
	{
		$p.ajax.call(posh["scr_feed_changestatus"],
			{
				'type':'execute',
				'variables':"delete=1&artId="+RssArticleId+"&v_mod="+v_mod,
				'callback':
				{
					'function':$p.app.widgets.rss.reloadAndRefresh
				}
			}
		);
	},
	/*
		Function: $p.app.widgets.rss.init
                                Init rss modules in selected tab
                      
                     Parameters:
                       
                                v_tab sequence ID
	*/
	init:function(v_tab)
	{
		// initialize feeds
		if (v_tab==indef) v_tab=tabs.sel;
		for (i=0;i<tab[v_tab].module.length;i++)
		{
			tab[v_tab].module[i].isLoaded=false;
		}
		tab[v_tab].feeds.length=0;
	},
	/*
		Function: $p.app.widgets.rss.get  
                                Init rss modules in selected tab
                      
                     Parameters:
                       
			response - rss feed xml object
			v_modId - module sequence ID
			v_nb - number of articles to display
			v_tab - tab sequence ID
            
                    Returns: 
                            
                                true or false
	*/
	get:function(response,v_modId,v_nb,v_tab)
	{ 
        $p.app.widgets.rss.sortedFeedTab = new Array();
		tab[v_tab].feeds[v_modId]=new Object();
		if (v_tab==indef) v_tab=$p.app.tabs.sel;
        //check if the response is empty
        var l_testResponse = response.getElementsByTagName('Module');
        if (l_testResponse.length == 0)
        {
            tab[v_tab].module[v_modId].isLoaded = false;
            return false;
        }

		// get module feeds
		tab[v_tab].module[v_modId].nbunread=indef;//reset nb of unread articles

		//check if the feed is local
		var l_feedUrl = $p.app.widgets.rss.getFeedUrl(tab[v_tab].module[v_modId]);
		
		if (response.getElementsByTagName("error")[0])  {
			$p.app.debug($p.ajax.getVal(response,"error","str",false,"Unknown error"),"error");
		}
		if (response.getElementsByTagName("nbunread")[0])   {
			tab[v_tab].module[v_modId].nbunread
                =(response.getElementsByTagName("nbunread")[0].firstChild.nodeValue).toInt();
		}
		if (response.getElementsByTagName("header")[0]) {
			//if RSS, name is the URL of the RSS feed (only on current tab)
			if (tab[v_tab].module[v_modId].id==86 
                && v_tab==$p.app.tabs.sel)
			{
				if (l_feedUrl!=indef)
				{
					tab[v_tab].module[v_modId].link=l_feedUrl;
					// if new feed in page, update the module title with feed title
					if ($p.string.getVar(tab[v_tab].module[v_modId].vars,"ptitl")=="") tab[v_tab].module[v_modId].changeVar("ptitl",$p.ajax.getVal(response,"ftitle","str",false,"RSS reader"));
					$p.app.widgets.changeName(v_modId,$p.string.getVar(tab[v_tab].module[v_modId].vars,"ptitl"),v_tab);
				}
			}

			tab[v_tab].module[v_modId].header = $p.ajax.getVal(response,"header","str",false,"");
			tab[v_tab].module[v_modId].footer = $p.ajax.getVal(response,"footer","str",false,"");
			tab[v_tab].module[v_modId].isLoaded = true;
			// fill edit box (only for current tab)
			$p.app.widgets.param.fillEditBox(response,tab[v_tab].module[v_modId].uniq,v_tab);
			var i=0,l_item,l_title,l_link,l_image,l_date,l_desc,l_read,l_id,l_source;
			var l_isLocal = $p.url.isLocal(l_feedUrl);
			while (i<v_nb+1 && response.getElementsByTagName("item")[i])
			{
				l_item = response.getElementsByTagName("item")[i];
                
				l_id = $p.ajax.getVal(l_item,"id","str",false,tab[v_tab].RssArticles.length);
                tab[v_tab].RssArticles.length+=1;
				l_title = $p.ajax.getVal(l_item,"title","str",false,"...");
                if (!l_isLocal)
					l_title = $p.app.widgets.rss.secure(l_title);
				l_source = $p.ajax.getVal(l_item,"source","str",false,"");
				//parse Source
				if (l_source.indexOf('<title')!=-1)
				{
					l_sourceArr = ($p.string.simulateGetElementsByTagName(l_source,'title'));
					l_source = l_sourceArr[0]["content"];
				}
				l_source = $p.app.widgets.rss.secure(l_source);
				
				l_desc=$p.app.widgets.rss.secure($p.ajax.getVal(l_item,"content","str",false,"")==""?$p.ajax.getVal(l_item,"desc","str",false,""):$p.ajax.getVal(l_item,"content","str",false,""));
				l_link=$p.ajax.getVal(l_item,"link","str",false,"");
				l_read=$p.ajax.getVal(l_item,"read","int",false,0);
				l_date= (l_item.getElementsByTagName("pubdate")[0] 
                               && l_item.getElementsByTagName("pubdate")[0].firstChild) ?   $p.date.convertFromRss(l_item.getElementsByTagName("pubdate")[0].firstChild.nodeValue)  :   
                                                                                            new Date();
				if (l_title=="") l_title=lg("lblNoTitle");
                
                var l_audio = $p.ajax.getVal(l_item,"audio","str",false,"");
                if (l_audio!="" 
                    && l_item.getElementsByTagName("audio")[0] 
                    && l_item.getElementsByTagName("audio")[0].firstChild) {
                        l_title+=" <a href='#' onclick=\"$p.app.reader.open('"+l_audio+"','a')\">"+$p.img("ico_readmedia.gif",12,12,lg("lblListen"),"imgmid")+"</a>";
                }
                var l_video = $p.ajax.getVal(l_item,"video","str",false,"");
                if (l_video!=""
                    && l_item.getElementsByTagName("video")[0] 
                    && l_item.getElementsByTagName("video")[0].firstChild) {
                        l_title+=" <a href='#' onclick=\"$p.app.reader.open('"+l_video+"','v')\">"+$p.img("ico_readmedia.gif",12,12,lg("lblWatch"),"imgmid")+"</a>";
                }
                
                if (l_item.getElementsByTagName("image")[0] && l_item.getElementsByTagName("image")[0].firstChild)
					l_image=" src='"+$p.ajax.getVal(l_item,"image","str",false,"")+"' "+(($p.ajax.getProp(l_item.getElementsByTagName("image")[0],"width","str",false,"")=="")?"":" width="+$p.ajax.getProp(l_item.getElementsByTagName("image")[0],"width","str",false,""));
				else
					l_image="x";
                //tab[v_tab].feeds.push(new $p.app.widgets.rss.object(l_id,tab[v_tab].module[v_modId].id,tab[v_tab].module[v_modId].uniq,tab[v_tab].module[v_modId].name,l_title,l_link,l_image,l_date,l_desc,l_read,l_source));
				var nf = new $p.app.widgets.rss.object(
                                            l_id,
                                            tab[v_tab].module[v_modId].uniq,
                                            tab[v_tab].module[v_modId].name,
                                            l_title,
                                            l_link,
                                            l_image,
                                            l_date,
                                            l_desc,
                                            l_read,
                                            l_source,
                                            v_modId
                                       );   
                
                $p.app.widgets.rss.sortedFeedTab.push(l_id);
                tab[v_tab].RssArticles[l_id]=nf;   
				tab[v_tab].feeds[v_modId][l_id]=nf;
                tab[v_tab].feeds.length+=1;
                //this.RssArticles.                                              
				i++;
			}
            
			//tab[v_tab].feeds[v_modId].isLastPage=false;
			tab[v_tab].module[v_modId].isLoaded=true;
			$p.app.checkLoading(false,v_tab);
			return true;
		}
		return false;
	},
	/*
		Function: $p.app.widgets.rss.getFeedUrl 
                                Get the feed URL

                     Parameters:

                                v_widget : widget array item
                                
                    Returns: 
                    
			feedURL string
                                indef : is not recognize as a feed
	*/
	getFeedUrl:function(l_widget)
	{
		var l_vars = l_widget.vars;
		var l_p1 = (l_vars.indexOf("rssurl=http://")==-1) ? (l_vars.indexOf("rssurl=https://")+7)
														  : (l_vars.indexOf("rssurl=http://")+7);
		if (l_p1 == -1)
			return indef;
		
		var l_p2 = l_vars.indexOf("/",l_p1+10);
		if (l_p2 == -1) l_p2 = l_vars.indexOf("&",l_p1);
		if (l_p2 == -1) l_p2 = l_vars.length;
		
		return l_vars.substring(l_p1,l_p2);
	},
	//ancre2
	reloadAndRefreshRating:function(response,vars)
	{
	
	},
	/*
		Function: $p.app.widgets.rss.loadRating
			load the user's rating on an article in the database 
		
		Parameters:
		
			RssArticleId - Rss article id
			l_modId - widget  ID
			v_tab - tab sequence ID
			source - origin point of the request (feedRSS, iframe, homepage)
	*/
	loadRating:function(RssArticleId,l_modId,v_tab,source)
	{ 
		if ($p.app.user.id > 0 && __useRating)
		{
			$p.ajax.call(posh["xml_display_article_user_rating"]+"?artId="+RssArticleId,
				{
					'type':'load',
					'callback' : 
					{
						'function' :$p.app.widgets.rss.readRating,
						'variables' : 
						{	
							'RssArticleId' : RssArticleId,
							'l_modId' : l_modId,
							'v_tab' : v_tab,
							'source' : source
						}
					}
				}
			);
		}
	},
	/*
		Function: $p.app.widgets.rss.readRating
			read the user's rating on an article in the database when it exists
		
		Parameters:
		
			response - XML object
			vars - variables
			
		Returns : 
			
			HTML
	*/
	readRating:function(response,vars)
	{ 
		var l_result=response.getElementsByTagName('rating');
		for (var i=0;i<l_result.length;i++)		
		{ 
			var l_rating = $p.ajax.getVal(l_result[i],'user_article_rating','',false,'0');
				
			if (l_rating > 0 )
			{
				$p.ajax.call(posh["xml_display_article_user_rating"]+"?artId="+vars['RssArticleId'],
					{
						'type':'load',
						'callback' : 
						{
							'function' :$p.app.widgets.rss.displayRating,
							'variables' : 
							{	
								'RssArticleId' : vars['RssArticleId'],
								'l_modId' : vars['l_modId'],
								'v_tab' : vars['v_tab'],
								'source' : vars['source']
							}
						}
					}
				);
			}				
			else
			{ 
				$p.ajax.call(posh["xml_display_article_user_rating"]+"?artId="+vars['RssArticleId'],
					{
						'type':'load',
						'callback' : 
						{
							'function' :$p.app.widgets.rss.displayRatingSystem,
							'variables' : 
							{	
								'RssArticleId' : vars['RssArticleId'],
								'l_modId' : vars['l_modId'],
								'v_tab' : vars['v_tab'],
								'source' : vars['source']
							}
						}
					}
				);
			} 
		}
	},
	/*
		Function: $p.app.widgets.rss.getRating
			get the user's rating on an article when he rates it
		
		Parameters:
		
			rating - rating given by the user on an article
			v_mod - widget  ID
			RssArticleId - Rss article id
			v_tab - tab sequence ID
	*/
	getRating:function(rating,v_mod,RssArticleId,v_tab)
	{ 
		if (v_tab!=indef)
		{
			$p.ajax.call(posh["scr_rate_article"],
				{ 
					'type':'execute',
					'variables' : "artId=" + RssArticleId + "&artRating=" + rating,
					'callback' : 
					{
						'function' :$p.app.widgets.rss.reloadAndRefresh(v_mod,v_tab)
					}
				}
			);
		}
		else
		{
		$p.ajax.call(posh["scr_rate_article"],
				{ 
					'type':'execute',
					'variables' : "artId=" + RssArticleId + "&artRating=" + rating
				}
			);
		}
	},
	/*
		Function: $p.app.widgets.rss.displayStars
			display the stars in the rating system
		
		Parameters:
		
			star - number of the star to display
			l_modId - widget  ID
			RssArticleId - Rss article id
			v_tab - tab sequence ID
			
		Returns : 
			
			HTML
	*/
	displayStars:function(star,l_modId,RssArticleId,v_tab)
	{	
		var l_image = $p.img('transparent.gif',14,14,lg('lblEmptyStarInfo'));	
		var l_s = '';
		l_s += "<a href='#' onclick='$p.app.widgets.rss.getRating("+star+","
				+l_modId+","
				+RssArticleId+","
				+v_tab
				+");return false;' class='star"+star+"'>"
				+ l_image
			+ "</a>" ; 
		return l_s;
	},
	/*
		Function: $p.app.widgets.rss.displayRatingSystem
			display the rating system for an article
		
		Parameters:
		
			response - XML object
			vars - variables
			
		Returns : 
			
			HTML
	*/
	displayRatingSystem:function(response,vars)
	{ 
		var l_result=response.getElementsByTagName('rating');
		var l_s = '';
		for (var i=0;i<l_result.length;i++)		
		{ 
			var l_rating = $p.ajax.getVal(l_result[i],'user_article_rating','',false,'0');

			l_s += '<div class="rating">' 
				+'<div class="my_rating">'
				+'<span class="rate">' 
				+lg("lblRate")
				+': <br/>';	
			for (var j=1;j<6;j++)
			l_s +=$p.app.widgets.rss.displayStars(j,vars['l_modId'],vars['RssArticleId'],vars['v_tab']);
			l_s += '</div>' 
				+'</span>' 
				+'</div>'; 
			$p.print('user_rating_'+vars['source']+'_'+vars['l_modId']+'_'+vars['RssArticleId'],l_s);
		}
	},
	/*
		Function: $p.app.widgets.rss.displayRating
			display the user's rating on an article
		
		Parameters:
		
			response - XML object
			vars - variables
			
		Returns : 
			
			HTML code
	*/
	displayRating:function(response,vars)
	{ 
		var l_result=response.getElementsByTagName('rating');
		var l_s = '';
		for (var i=0;i<l_result.length;i++)		
		{ 
			var l_rating = $p.ajax.getVal(l_result[i],'user_article_rating','',false,'0');
			var l_image = $p.img('rating_star_'+l_rating+'.gif',70,14,lg('lblRatingStar'+l_rating+'Info'));
				
			l_s += '<div class="rating">' 
					+'<div class="my_rating">'
					+'<span class="rate">' 
					+lg("lblRate")
					+': <br/>'
					+l_image
					+'</span>' 

			l_s += $p.app.widgets.rss.displayIconDeleteRating(vars['l_modId'],vars['RssArticleId'],vars['v_tab']); 
										
			l_s +='<br />' 
			
				+'</div>';	
			$p.print('user_rating_'+vars['source']+'_'+vars['l_modId']+'_'+vars['RssArticleId'],l_s);
		
		}
	},
	/*
		Function: $p.app.widgets.rss.deleteRating
			Delete the user's rating on an article
		
		Parameters:
			
			v_mod - widget  ID
			RssArticleId - Rss article id
			v_tab - tab sequence ID
	*/
	deleteRating:function(v_mod,RssArticleId,v_tab)
	{
		if (v_tab!=indef)
		{
			$p.ajax.call(posh["scr_delete_rating"],
				{
					'type':'execute',
					'variables': "artId="+ RssArticleId,
					'callback':
					{
						'function':$p.app.widgets.rss.reloadAndRefresh(v_mod,v_tab)
					}
				}
			);
		}
		else
		{
			$p.ajax.call(posh["scr_delete_rating"],
				{
					'type':'execute',
					'variables': "artId="+ RssArticleId
				}
			);
		}
	},
	/*
		Function: $p.app.widgets.rss.loadAverageRating
			Load the average rating of an article
		
		Parameters:
		
			RssArticleId - Rss article id
			l_modId - widget  ID
			v_tab - tab sequence ID
			source - origin point of the request (feedRSS, iframe, homepage)
	*/
	loadAverageRating:function(RssArticleId,l_modId,v_tab,source)
	{	
		if ($p.app.user.id > 0 && __useRating)
		{ 
			$p.ajax.call(posh["scr_article_average_rating"]+"?artId="+RssArticleId,
				{
					'type':'load',
					'callback' : 
					{
						'function' :$p.app.widgets.rss.displayAverageRating,
						'variables' : 
						{
							'RssArticleId' : RssArticleId,
							'l_modId' : l_modId,
							'v_tab' : v_tab,
							'source' : source
						}
					}
				}
			);
		}
	},
	/*
		Function: $p.app.widgets.rss.displayAverageRating
			display the average rating of an article
		
		Parameters:
		
			response - XML object
			vars - variables
			
		Returns : 
			
			HTML code showing the average rating of an article
	*/
	displayAverageRating:function(response,vars)
	{ 
		var l_result=response.getElementsByTagName('rating');
		var l_s = '';
		for (var i=0;i<l_result.length;i++)		
		{ 
			var l_rating = $p.ajax.getVal(l_result[i],'article_average_rating','',false,'0');
			l_round_rating = Math.round(l_rating);
			
			if (l_round_rating!=0)
			{
				var l_counter = $p.ajax.getVal(l_result[i],'counter','',false,'0');
				var l_single_rate = $p.ajax.getVal(l_result[i],'single_rate','',false,'0');
				var l_tofixed_rating = new Number (l_rating);
				l_tofixed_rating.toFixed(1);
				l_image = $p.img('average_rating_stars_'+l_round_rating+'.gif',70,14,lg('lblRatingStar'+l_round_rating+'Info'));
				if (l_single_rate == 0)
				{ 
					var l_plural = 's';
				}
				else
				{ 
					var l_plural = '';
				}
				
				l_s +=  '<span class="average_rating">' 
						+lg("lblAverageRating")
						+': <br />'
						+ l_image
						+ ' (' + l_tofixed_rating + ') '
						+ l_counter + ' note'+l_plural
						+'</span>' 		
				$p.print('average_rating_'+vars['source']+'_'+vars['l_modId']+'_'+vars['RssArticleId'],l_s);	
			}
		}
	},
	/*
		Function: $p.app.widgets.rss.displayIconDeleteRating
			display the icon to cancel the rate of a rated article
		
                     Parameters:

			l_modId - widget  ID
                                RssArticleId - RSS article ID
                                v_tab - tab sequence ID
                                
                    Returns: 
                    
                                HTML
	*/
	displayIconDeleteRating:function(l_modId,RssArticleId,v_tab)
	{ if ($p.app.user.id>0 &&__useRating)
		var l_addedFct="";
			{
			l_addedFct	+= "<a href='#' onclick='$p.app.widgets.rss.deleteRating("
                        + l_modId+","
                        + RssArticleId+","
						+ v_tab+");return false;'>"
						+ $p.img("ico_suppress.gif",7,7,lg("lblDeleteRatingInfo"))
                        + "</a>"
			}
		 return l_addedFct;
	},
	/*
		Function: $p.app.widgets.rss.displayIconSharing
                                Display sharing icon

                     Parameters:

                                l_tab - tab sequence ID
                                RssArticleId - RSS article ID
                                
                    Returns: 
                    
                                HTML
	*/
	displayIconSharing:function(l_tab,RssArticleId)
    {
        var l_addedFct="";
        if ($p.app.user.id>0
            && __useSharing
			&& $p.app.user.type != 'N') {
                l_addedFct += " <a href='#' onclick='$p.friends.menu(2,"
                          + RssArticleId
                          + ");return false;'>"
                          + $p.img("ico_share_s.gif",13,10,lg("lblShareInfo"))
                          + "</a> ";
        }  
        return l_addedFct;
    },
	// /*
		// Function: $p.app.widgets.rss.displayIconArchive
                                // Display archive icon

                     // Parameters:

                                // l_tab - tab sequence ID
                                // RssArticleId - RSS article ID                             
                                
                    // Returns: 
                    
                                // HTML
	// */
	// displayIconArchive:function(l_tab,RssArticleId)
    // {
        // var l_addedFct="";
        // if ($p.app.user.id>0
            // && __useArchive 
			// && $p.app.user.type != 'N') {
                // l_addedFct += " <a href='#' onclick='return $p.article.isArticleSaved("
                          // + RssArticleId+")'>"
                          // + $p.img("ico_disk_s.gif",8,9,lg("lblSave"))
                          // + "</a> ";
        // } 
        // return l_addedFct;
    // },
	/*
		Function: $p.app.widgets.rss.displayIconDelete
                                
                                Display delete icon

                     Parameters:

                                l_tab - tab sequence ID
                                l_modId - 
                                RssArticleId - RSS article ID                                
                                
                    Returns: 
                    
                                HTML
	*/
	displayIconDelete:function(l_tab,l_modId,RssArticleId)
    {   
        var l_addedFct = "";
        if ($p.app.user.id > 0
            &&__useRssDelete) {
                l_addedFct += " <a href='#' onclick='$p.app.widgets.rss.deleteEntry("
                          +l_modId+","
                          +RssArticleId+");return false;'>"
                          +$p.img("ico_suppress.gif",7,7,lg("lblDeleteInfo"))
                          +"</a> ";
        }   
        return l_addedFct;
    },    
    
	/*
		Function: $p.app.widgets.rss.displayFeedImages
                                Display feed images

                     Parameters:

                                l_tab - tab sequence ID
                                RssArticleId - RSS article ID
                                j - number of articles displayed                                    
                                
                    Returns: 
                    
                                HTML
	*/
	displayFeedImages:function(v_tab,RssArticleId,j,v_widgetDisplayPref)
    {
        var l_image = '';

        if (__displayrssimages == 0 
               || (__displayrssimages == 1 && j != 0)
               || v_widgetDisplayPref == 0)
        {
            l_image = '';
        }
        else
        {
            if (tab[v_tab].RssArticles[RssArticleId].image == "x")
            {
                //check if description is containing images
                var l_desc = tab[v_tab].RssArticles[RssArticleId].desc;
                if (l_desc.indexOf('<IMG') != -1 || l_desc.indexOf('<img') != -1)
                {
                    var l_match = l_desc.match(/ src="[^"]+"/i);
                    if (l_match != null && l_match.length > 0) l_image = l_match[0];
                    else {
                        l_match = l_desc.match(/ src='[^']+'/i);
                        if (l_match != null && l_match.length > 0) l_image = l_match[0];
                    }
                }
            }
            else
            {
                l_image = tab[v_tab].RssArticles[RssArticleId].image;
            }         
        }

        if (l_image == '' || l_image.indexOf('http') == -1) return '';
        
        var l_imageScale = (v_widgetDisplayPref == 1 && j == 0) ? 2 : 1;
        
        return '<div style="width: '+(75 * l_imageScale)+'px;height: '+(50 * l_imageScale)+'px;overflow: hidden;float: left;margin-right: 6px;">'
            + '<img'
            + l_image
            + ' style="width:'+(75 * l_imageScale)+'px;" />'
            + '</div>';
    },  
    
	/*
		Function: $p.app.widgets.rss.displayFeedTitle 
                                Display feed title
                    
                    Parameters:
                        
                                l_tab - tab sequence ID
                                vars - variables
                                i - counter
                    
                    Returns: 
                    
                                HTML
	*/
	displayFeedTitle:function(l_tab,vars,RssArticleId,j,v_widgetDisplayPref)
    {
        var l_s = '<span>';
        var v_tab = l_tab;
        var addSource=(__displayrsssource 
                      && tab[v_tab].RssArticles[RssArticleId].source!="" )   ?       '<br /><span class="source">'
                                                            +       tab[v_tab].RssArticles[RssArticleId].source+'</span>'
                                                            :       '';
		

        var l_javascript = tab[v_tab].RssArticles[RssArticleId].link.indexOf('javascript:');
		if (l_javascript == -1) {
			l_s += '<a href="'+tab[v_tab].RssArticles[RssArticleId].link+'" target="npdetailf" '
                +'onclick=\'return $p.app.widgets.rss.linkClicked(this,'+vars['uniq']+','+vars['id']+','+vars['nb']+','+RssArticleId+');\'';
		}
		else {
			l_s += '<a href="#" target="npdetailf" '
                + 'onclick=\'$p.app.widgets.rss.linkClicked(this,'+vars['uniq']+','+vars['id']+','+vars['nb']+','+RssArticleId+');'+tab[v_tab].RssArticles[RssArticleId].link.substr(l_javascript+11)+';return false;\'';
		}
		l_s+=' onmouseover="$p.app.widgets.rss.showOverview('+RssArticleId+',event)" '
                +'onmouseout="$p.app.widgets.rss.hideOverview('+RssArticleId+')">'
                +tab[v_tab].RssArticles[RssArticleId].title+'</a>'

        l_s += addSource
            + '	</a>'
            + '</span>';
        return l_s;
    },
	/*
		Function: $p.app.widgets.rss.displayFeedDate
                                Display feed date
                    
                    Parameters:
                        
                                l_tab - tab sequence ID
                                i - counter
                    
                    Returns: 
                    
                                HTML
	*/
	displayFeedDate:function(v_tab,RssArticleId)
    {
    
		if (!__displayRssDate) {
            return '';
        }
        
        var formatted_date = $p.date.formatDelai(
                                    $p.date.delayFromNow(tab[v_tab].RssArticles[RssArticleId].date)
                            );
        return '<span class="date"> '+
                    formatted_date
                    +'</span>';

    },
	/*
		Function: $p.app.widgets.rss.displayFeedTitleFormat
                                
                                Display feed title format

                     Parameters:
                       
			l_tab - tab sequence ID
			i - counter                             
                                j - number of articles displayed
                               
                    Returns: 
                    
                                HTML
	*/
	displayFeedTitleFormat:function(l_tab,RssArticleId,j)
    {	
		var v_tab = l_tab;
        var l_s = "";
        
        l_s += (__displayrssimages == 0 
              || (__displayrssimages == 1 && (tab[v_tab].RssArticles[RssArticleId].image == "x" || j != 0)) 
              || (__displayrssimages == 2 && tab[v_tab].RssArticles[RssArticleId].image == "x"))                 ?           ''
                                                                                            :           '<br />';     
        return l_s;
    }, 	
	
	/*	$p.app.widgets.rss.lastpage
		Boolean to know if the page in the feed is the last page.
		0 : not the last page
		1 : last page
	*/
	lastpage:0,	
			 
	/*
		Function: $p.app.widgets.rss.displayRSSFeeds
                                Display RSS feeds

                     Parameters:
                       
			l_tab - tab sequence ID
			l_modId -     module id (database id)                    
                                vars (array) - variables
                               
                    Returns: 
                    
                                Array containing the HTML code to display and the value of 'j'
	
        */  

    displayRSSFeeds:function(l_tab,l_modId,vars,l_auth)
    { 
        var j = 0;	
        var returnDatas = [];
        var l_s = "";
        var v_tab = l_tab;
        var l_widgetDisplayPref = getVar(tab[v_tab].module[l_modId].vars,'pdisplay');
        if (l_widgetDisplayPref == '') l_widgetDisplayPref = 0;
        /*
                        array containing list of all articles with database  unique id as key
                        tab[v_tab].RssArticles[v_id]
                        tab[v_tab].RssArticles[RssArticleId]
*/

        //new way to display feed articles (cannot run hash elements because google chrome automatically sort it): see also $p.app.widgets.rss.get 
        for (var cpt=0;cpt<$p.app.widgets.rss.sortedFeedTab.length;cpt++) {
            RssArticleId = $p.app.widgets.rss.sortedFeedTab[cpt];

        //for (var RssArticleId in tab[v_tab].feeds[l_modId]) {
            if ( typeof(tab[v_tab].feeds[l_modId][RssArticleId]) != 'undefined' && j<(vars['nb']+1) ) 
			{
                var l_addedFct = '&nbsp;'
                        + $p.app.widgets.rss.displayIconSharing(v_tab,RssArticleId) //display sharing icon
                        //+ $p.app.widgets.rss.displayIconArchive(v_tab,RssArticleId) //display archive icon
                        + $p.app.widgets.rss.displayIconDelete(v_tab,l_modId,RssArticleId), //display delete icon
                    feedId = "",
                    feedClass = "link";
                //var RssArticleId = tab[l_tab].feeds[i].id;
                feedId = 'feed'+tab[v_tab].id+'_'+vars['uniq']+'_'+RssArticleId;
                if (__registerfeeds && !l_auth)
                {
                    (tab[v_tab].RssArticles[RssArticleId].isRead == 0)      ?       feedClass += 'unread'
                                                                            :       feedClass += 'read';
                }
                else feedClass += '';
                   
				if (j < vars['nb'])
				{
                    l_s += 
                        '<div id="'+feedId+'" class="'+feedClass+'">'
                        + '<div class="articleborder">'
                        + '<div class="article">'
                        + '<div style="float: right;">'+l_addedFct+'</div>'
                        + '<div class="articleDisplayType'+l_widgetDisplayPref+'">'
                        + '<div class="articleDisplayType'+l_widgetDisplayPref+''+j+'">'
                        + $p.app.widgets.rss.displayFeedImages(v_tab,RssArticleId,j,l_widgetDisplayPref)//display feed images
                        + $p.app.widgets.rss.displayFeedTitle(v_tab,vars,RssArticleId,j,l_widgetDisplayPref) //display feed title
                        + $p.app.widgets.rss.displayFeedDate(v_tab,RssArticleId); //display article date
                
          
                //display title format
                //l_s+=$p.app.widgets.rss.displayFeedTitleFormat(l_tab,i,j);

                if (tab[v_tab].RssArticles[RssArticleId].desc != '' 
					&& ((__displayrssimages == 1 && j == 0 && tab[v_tab].RssArticles[RssArticleId].image != 'x') || __displayrssimages==2)
                    && l_widgetDisplayPref != 0
					)
				{
					l_s +='<div class="summary">'+$p.app.widgets.rss.summarize(tab[v_tab].RssArticles[RssArticleId].desc)+'</div>';
				}
                l_s += '</div>'
                    + '</div>'
                    + '<div class="float_correction"></div>'
                    + '</div>';
				if (__useRating)
				{
                    var source = "feed";
					$p.app.widgets.rss.loadRating(RssArticleId,l_modId,v_tab,source);
					$p.app.widgets.rss.loadAverageRating(RssArticleId,l_modId,v_tab,source);
					
					l_s += '<div id="user_rating_feed_'+l_modId+'_'+RssArticleId+'"></div>'
                        + '<div id="average_rating_feed_'+l_modId+'_'+RssArticleId+'"></div>';
					//l_s += '</div>';
				}
				l_s += '</div>'
                    //+ l_addedFct
                    + '</div>';
                }   
                j++;
				
			}
			
        }  
        returnDatas['l_s'] = l_s;
        returnDatas['j'] = j;
		if (j < (vars['nb'] + 1))
		{
            $p.app.widgets.rss.lastpage = 1
		}
        return returnDatas;
    },
	/*
		Function: $p.app.widgets.rss.displayPrevious
                                Display previous arrows
                      
                     Parameters:
                       
			l_tab - tab sequence ID
			l_modId -
                                vars - callback variables
                                j - number of articles displayed
           
                    Returns: 
                    
                                HTML code
	*/    
    displayPreviousLink:function(l_tab,l_modId,vars,j)
    {	var v_tab=l_tab;
        var l_s="";
        if (tab[v_tab].module[l_modId].start>0) {
            l_s+=" <a href='#' onclick='$p.app.widgets.rss.nextPage("+tab[v_tab].module[l_modId].uniq+","+vars['nb']+");return false;'>"
               +$p.img('ico_previous3.gif',8,11,lg('previous'),'imgmid')
               +" "
               +lg('previous')
               +"</a> &nbsp;";
        } 
        return l_s;
    },   
	/*
		Function: $p.app.widgets.rss.displayNext
                                Display next arrow
                      
                     Parameters:
                       
			l_tab - tab sequence ID
			l_modId -
                                vars (array) - variables
                                j - number of articles displayed
           
                    Returns: 
                    
                                HTML code
	*/    
    displayNextLink:function(v_tab,l_modId,vars,j)
    {   var l_s = "";
        if (j>vars['nb']) {
            l_s += " <a href='#' onclick='$p.app.widgets.rss.prevPage("+tab[v_tab].module[l_modId].uniq+","+vars['nb']+");return false;'>"
                + lg('next')
                + " "
                + $p.img('ico_next3.gif',8,11,lg('next'),"imgmid")
                + "</a> &nbsp;";
        }   
        return l_s;
    },          
 	/*
		Function: $p.app.widgets.rss.displayNoRSS 
                                Display next and previous arrows
                      
                     Parameters:
                       
			l_tab - tab sequence ID
			l_modId -
                                vars -        
           
                    Returns: 
                    
                                false
	*/    
    displayNoRSS:function(l_tab,l_modId,vars)
    {  	var v_tab = l_tab;
        var l_s="";
            l_s+='<table cellpadding="0" cellspacing="0" width="100%">'
                +'<tr>'
                +'<td>'
                +'</td>'
                +'</tr>'
                +'<tr>'
                +'<td class="rss">'
                +'<table cellpadding="1" cellspacing="3" width="100%">'
                +'<tr>'
                +'<td>'
                +lg("lblNoArticle")
                +'</td>'
                +'</tr>'
                +'</table>'
                +'</td>'
                +'</tr>'
                +'</table>';
        $p.print('module'+tab[l_tab].id+'_'+vars['uniq']+'_c',l_s);
        return false;
    },
 	/*
		Function: $p.app.widgets.rss.noAuthentification 
                                Authentified feed control
                      
                     Parameters:
                       
			l_tab - tab sequence ID
			l_modId -
                                vars - 
                                
                    Returns: 
                    
                                false / true
	*/   
    noAuthentification:function(l_tab,l_modId,vars)
    {	var v_tab = l_tab;
        var l_s=""  
        if (tab[v_tab].module[l_modId].footer=="auth")  {
            l_s+='<table cellpadding="0" cellspacing="0" width="100%">'
                +'<tr>'
                +'<td>'
                +'<a href="#" onclick="$p.app.widgets.param.show('+tab[v_tab].module[l_modId].uniq+');return false;">'
                +$p.img("lock.gif",7,9,"","imgmid")+' '+lg("authFeed")
                +'</a>'
                +'</td>'
                +'</tr>'
                +'</table>';             
            tab[v_tab].module[l_modId].footer="";  
            
            $p.print('module'+tab[v_tab].id+'_'+vars['uniq']+'_c',l_s);
            return false;
        }
       return true;
    },
	/*
		Function: $p.app.widgets.rss.displayModuleError 
                                rss module loading error
                      
                     Parameters:
                       
			response - rss feed xml object
			vars (array) - variables (optionnal)
	*/    
    displayModuleError:function(l_tab,l_modId,vars)
    {	var v_tab = l_tab;
        var l_s = '<table cellpadding="0" cellspacing="0" width="100%">'
            + '<tr>'
            + '<td>'
            + '</td>'
            + '</tr>'
            + '<tr>'
            + '<td class="rss">'
            + '<table cellpadding="1" cellspacing="3" width="100%">'
            + '<tr>'
            + '<td>'
            + lg("lblModIssue")
            + '</td>'
            + '</tr>'
            + '</table>'
            + '</td>'
            + '</tr>'
            + '</table>';

        //avoid waiting icon to stay
//        tab[l_tab].module[l_modId].isLoaded = true;
        $p.app.tabs.created[l_tab]=false;
        $p.app.tabs.create(l_tab);
        $p.print('module'+tab[v_tab].id+'_'+vars['uniq']+'_c',l_s);
        return false;
    },
	/*
		Function: $p.app.widgets.rss.display 
                                Display rss feed articles
                      
                     Parameters:
                       
			response - rss feed xml object
			vars (array) - variables (optionnal)
            
                     See also:
                     
                            $p.app.widgets.rss.displayAll
                            
                            $p.app.widgets.rss.refresh
                            
                            $p.app.widgets.rss.linkClicked
                            
	*/
	display: function(response,vars)
	{
		$p.plugin.hook.launch('app.widgets.rss.display.start');

		//display rss module content
		var l_tab = (vars['tab'] == indef ? $p.app.tabs.sel : vars['tab']),
            l_s = "",
            l_item,
            l_title,
            l_modId = vars['id'],
            tabDisplayInfos = new Array(),
            j = 0,
            displayGranted = false,
            displayHeader = "";

        if (tab[l_tab].locked) return;		

		//bug correction : if a module is removed during its refresh or other module refresh
		if (!tab[l_tab].module[l_modId]) return;//if (!module[l_modId]) l_modId=$p.app.widgets.uniqToId(vars[2]);
		var l_auth = tab[l_tab].module[l_modId].auth;
		
        if (!tab[l_tab].module[l_modId].isLoaded 
            && response != indef) {
                $p.app.widgets.rss.get(
                                response,
                                l_modId,
                                (vars['nb'] == indef ? 10 : vars['nb']),
                                l_tab
                );
        }
        //Authentification control
        if ($p.app.widgets.rss.noAuthentification(l_tab,l_modId,vars))
        {
     		if (tab[l_tab].module[l_modId] && tab[l_tab].module[l_modId].isLoaded)
    		{			
    			displayHeader = tab[l_tab].module[l_modId].header;
                tabDisplayInfos = $p.app.widgets.rss.displayRSSFeeds(l_tab,l_modId,vars,l_auth); //Display all the feeds
                j = tabDisplayInfos['j']; // Number of article in the page         
                
                /*l_s += '<table cellpadding="0" cellspacing="0" width="100%" class="FeedFrame">'
                    + '<tr>'
                    + '<td  class="FeedDisplayHeader" >'
                    + displayHeader
                    + '</td>'
                    + '</tr>'
                    + '<tr>'
                    + '<td class="rss">'
                    + '<table cellpadding="1" cellspacing="3" width="100%" height="'+widgetHeight+'" id="FeedDisplayInfo" class="FeedDisplayInfo">'
                    + tabDisplayInfos['l_s'];*/
                l_s += '<div class="FeedFrame">'
                    + '<div  class="FeedDisplayHeader" >'
                    + displayHeader
                    + '</div>'
                    + '<div class="rss">'
                    + '<div id="FeedDisplayInfo" class="FeedDisplayInfo">'
                    + tabDisplayInfos['l_s'];

				if (j == 0) {
					l_s += lg("lblNoArticle");
                }
                l_s += '</div>'
                    + "<div style='text-align:right;padding-top: 5px;'>"
                    + $p.app.widgets.rss.displayPreviousLink(l_tab,l_modId,vars,j)
                    + $p.app.widgets.rss.displayNextLink(l_tab,l_modId,vars,j)
                    + '</div>'
                    + '</div>'
                    + '<div>'
                    + tab[l_tab].module[l_modId].footer
                    + '</div>';
            }
            else
            {
                $p.app.widgets.rss.displayModuleError(l_tab,l_modId,vars);
            }
		}
        
		$p.print('module'+tab[l_tab].id+'_'+vars['uniq']+'_c',l_s);
		$p.app.widgets.rss.moduleUnread(vars['uniq'],l_tab,l_modId);
		//reset icon if linked to the feed favicon
		$p.app.widgets.changeIcon(l_modId,indef,l_tab);
		//refresh newpaper mode
		if (l_tab == $p.app.tabs.sel 
            && tab[l_tab].showType == 1) {
                $p.app.widgets.rss.reader.showArticlesList(true,$p.app.widgets.rss.reader.currSrc);
        }

		$p.plugin.hook.launch('app.widgets.rss.display.end');
	},
	/*
		Function: $p.app.widgets.rss.nextPage 
                                Display next articles
                      
                     Parameters:
                       
			v_id - module Uniq ID
                                v_nb - number to start from
	*/
	nextPage:function(v_id,v_nb)
	{
		//if (tab[v_tab].module[v_id].start>=v_nb)
		//{
		var v_tab=$p.app.tabs.sel;
		var l_id=$p.app.widgets.uniqToId(v_id);
		tab[v_tab].module[l_id].start-=v_nb;
		//}
		$p.app.widgets.rss.refresh(l_id,v_tab,true);
	},
	/*
		Function: $p.app.widgets.rss.prevPage
                               Display next articles
                               
                     Parameters:
                       
			v_id - module Uniq ID
                                v_nb - number to start from
	*/
	prevPage:function(v_id,v_nb)
	{
		var v_tab = $p.app.tabs.sel;
		var l_id=$p.app.widgets.uniqToId(v_id);
		tab[v_tab].module[l_id].start+=v_nb;
		$p.app.widgets.rss.refresh(l_id,$p.app.tabs.sel,true);
	},
	/*
		Function: $p.app.widgets.rss.displayAll
        
                                Display articles of all rss modules in current page
	*/
	displayAll:function()
	{
		for (var i=0;i<tab[$p.app.tabs.sel].module.length;i++)
		{
			if (tab[$p.app.tabs.sel].module[i].format=='R')
			{
				$p.app.widgets.rss.display(indef,
                                           new Array(  i,
                                                        ( $p.string.getVar(tab[$p.app.tabs.sel].module[i].vars,"nb")  ?    $p.string.getVar(tab[$p.app.tabs.sel].module[i].vars,"nb") 
                                                          :                                                                5
                                                        ),
                                                        tab[$p.app.tabs.sel].module[i].uniq
                                                      )
                                            );
			}
		}
	},
	/*
		Function: $p.app.widgets.rss.moduleUnread
                               Compute number of unread articles
                               
                     Parameters:
                       
			v_id - module Uniq ID
			v_tab - tab sequence ID
	*/
	moduleUnread:function(v_id,v_tab,l_modId)
	{
		if (v_tab == indef) v_tab = $p.app.tabs.sel;

		var l_id = $p.app.widgets.uniqToId(v_id,v_tab),
            l_content = $("module"+tab[v_tab].id+"_"+v_id+"_c"),
            nbur = 0;

		if (__registerfeeds && !tab[v_tab].module[l_id].auth)
		{
			for (var RssArticleId in tab[v_tab].feeds[l_modId])
			{
				if (tab[v_tab].RssArticles[RssArticleId].isRead == 0) 
                {   
                    nbur++;
                }
			}
		}
		else
		{
			var l_link = l_content.getElementsByTagName("a");
			for (var RssArticleId in l_link)
			{
				var l_node = l_link[RssArticleId];
				if (l_node.target && l_node.target == 'npdetailf')
				{
					if (document.all)   {
						if (l_node.currentStyle.color!="#999999") nbur++;
					}
					else    {
						if (window.getComputedStyle(l_node, null).color!="rgb(153, 153, 153)") nbur++;
					}
				}
			}
		}
        //lastpage must be on the feeds and not on the primary object
		if (tab[v_tab].module[l_id].nbunread == indef && $p.app.widgets.rss.lastpage == 0) 
        {
         //   if (tab[v_tab].module[l_id].nbunread > 0) {
                tab[v_tab].module[l_id].nbunread = (nbur - 1);//nbur-1 because we count an additional article
                if (tab[v_tab].module[l_id].nbunread < 0) {
                    tab[v_tab].module[l_id].nbunread = 0;
                }
           // }
		}
		else if (tab[v_tab].module[l_id].nbunread == indef && $p.app.widgets.rss.lastpage == 1)  
		{
			tab[v_tab].module[l_id].nbunread = nbur;
			$p.app.widgets.rss.lastpage = 0
		}
		$p.app.widgets.changeName(l_id,indef,v_tab);
		$p.app.widgets.rss.pageUnread(v_tab);
	},
	/*
		Function: $p.app.widgets.rss.linkClicked
                               Treat mouse click on article
                               
                     Parameters:
                       
			v_linkobj - link object clicked
			v_id - module Uniq ID
			l_modId - module sequence ID
			v_nbart - number of article displayed for the module
                                RssArticleId - feed sequence ID
	*/
	linkClicked:function(v_linkobj,v_id,l_modId,v_nbart,RssArticleId)
	{
		var l_id = $p.app.widgets.uniqToId(v_id);
        var v_tab = $p.app.tabs.sel;
		$p.app.counter.activityStep = 0; // reset non activity check

		if (__registerfeeds && !tab[v_tab].module[l_id].auth)
		{
			if (tab[v_tab].RssArticles[RssArticleId].isRead==0)
			{
				$p.app.widgets.rss.saveReadStatus(RssArticleId);
                //$p.app.widgets.rss.saveReadStatus(tab[$p.app.tabs.sel].feeds[v_feedId].id);
				//change datas on the two arrays ()new one is RssArticles
                tab[v_tab].RssArticles[RssArticleId].isRead=1;
               /* if (RssArticleId) {
                    tab[v_tab].RssArticles[RssArticleId].isRead=1;
                }  *///$p.setClass("feed"+tab[$p.app.tabs.sel].id+"_"+v_id+"_"+tab[$p.app.tabs.sel].feeds[v_feedId].id,"linkread");
				$p.setClass("feed"+tab[v_tab].id+"_"+v_id+"_"+RssArticleId,"linkread");
				if (tab[v_tab].module[l_id].nbunread > 0)  {
                    tab[v_tab].module[l_id].nbunread--;
				}
                $p.app.widgets.changeName(l_id);
				$p.app.widgets.rss.pageUnread(v_tab);
			}
		}
		else
		{
			//if (tab[$p.app.tabs.sel].showType==0)
			if (v_linkobj != indef)
			{
				var l_newUnread = false;
				if (document.all){
					if (v_linkobj.currentStyle.color!="#999999" && $p.string.lc(v_linkobj.currentStyle.color)!="#c6c3c6") l_newUnread=true;
				}
				else{
					if (window.getComputedStyle(v_linkobj, null).color!="rgb(153, 153, 153)" 
                            && window.getComputedStyle(v_linkobj, null).color!="rgb(156, 0, 0)") 
                           {
                            l_newUnread = true;
                           }
				}
				if (l_newUnread){
					if (tab[v_tab].module[l_id].nbunread > 0) 
                    {    
                        tab[v_tab].module[l_id].nbunread--;
					}
                    $p.app.widgets.changeName(l_id);
					$p.app.widgets.rss.pageUnread();
				}
			}
		}
		//if already in reader mode > no action
		if (tab[v_tab].showType == 0 
                && tab[v_tab].RssArticles[RssArticleId].link.indexOf('javascript:') ==-1)
		{
			// get widget article opening preference
			var l_widgetOpenPref = getVar(tab[v_tab].module[l_id].vars,'popenin');
			if (l_widgetOpenPref == '') l_widgetOpenPref = 0;

			if (tab[v_tab].usereader == 1 
                    && tab[v_tab].module[l_id].usereader 
                    && l_widgetOpenPref == "0")
			{
				//init reader mode
				$p.app.widgets.rss.reader.init();
				//select clicked article
				//$p.app.widgets.rss.reader.showDetail(indef,tab[$p.app.tabs.sel].feeds[v_feedId].id);
                $p.app.widgets.rss.reader.showDetail(indef,RssArticleId);
				//readerarticle"+$p.app.tabs.sel+"_"+v_feedId
				$p.app.widgets.rss.reader.load(l_modId);
				// no page preloading if feeds are managed in the DB (no use for read status update)
				if (__registerfeeds && !tab[v_tab].module[l_id].auth) return false;
				//if no link, do not open destination file
                //if ((tab[$p.app.tabs.sel].feeds[v_feedId].link).indexOf("noplink")!=-1) return false;
				if ((tab[v_tab].RssArticles[RssArticleId].link).indexOf("noplink")!=-1) return false;
                //return (tab[$p.app.tabs.sel].feeds[v_feedId].link==""?false:true);
				return (tab[v_tab].RssArticles[RssArticleId].link==""?false:true);
			}
			else if (l_widgetOpenPref == "2")
			{
                //$p.app.widgets.rss.openInTab(tab[$p.app.tabs.sel].feeds[v_feedId].link,tab[$p.app.tabs.sel].module[l_id].name);
				$p.app.widgets.rss.openInTab(tab[v_tab].RssArticles[RssArticleId].link,tab[v_tab].module[l_id].name);
				return false;
			}
			else
			{
				//if ($p.navigator.IE) return true;
                //$p.url.openLink(tab[$p.app.tabs.sel].feeds[v_feedId].link,true);
				$p.url.openLink(tab[v_tab].RssArticles[RssArticleId].link,true);
				//link visited status is not instantaneous with FF
				if (!__registerfeeds ||  tab[v_tab].module[l_id].auth) 
                {
                    setTimeout("$p.app.widgets.rss.display(indef,new Array("+l_modId+","+v_nbart+","+v_id+"))",1000);
				}
                return false;
			}
		}
	},
	/*
		Function: $p.app.widgets.rss.saveReadStatus
                               Save the status of the article as read
                               
                     Parameters:
                       
			v_id - article ID
	*/
	saveReadStatus:function(v_id)
	{
		$p.ajax.call(posh["scr_feed_changestatus"],
			{
				'type':'execute',
				'variables':"artid0="+v_id+"&s0=1"
			}
		);
	},
	/*
		Function: $p.app.widgets.rss.openInTab
                               Open a rss article in a Posh tab
                               
                     Parameters:
                       
			v_link - link of the article
                                v_tabName -  Title of the page
	*/
	openInTab:function(v_link,v_tabName)
	{
		var l_name=v_tabName.substr(0,20);
		$p.app.tabs.openTempLink(l_name,v_link);
	},
	/*
		Function: $p.app.widgets.rss.readAll
        
                               Set all articles as read for a module
                               
                     Parameters:
                       
			v_tab - tab sequence ID
                                v_modId - 
                                
                     Returns:
                     
                                false
	*/
	readAll:function(v_tab,v_modId,RssArticleId)
	{
		var l_s="",inc=0;
		for (var RssArticleId in tab[v_tab].feeds[v_modId])
		{
            $p.setClass("feed"+tab[v_tab].id+"_"+tab[v_tab].module[v_modId].uniq+"_"+RssArticleId,"linkread");
            l_s+="artid"+inc+"="+RssArticleId+"&s"+inc+"=1&";
            tab[v_tab].RssArticles[RssArticleId].isRead=1;
            inc++;
		}
		$p.ajax.call(posh["scr_feed_changestatus"],
			{
				'type':'execute',
				'variables':l_s
			}
		);
		tab[v_tab].module[v_modId].nbunread=0;
		$p.app.widgets.changeName(v_modId);
		$p.app.widgets.rss.pageUnread();
		return false;
	},
	/*
		Function: $p.app.widgets.rss.pageUnread
                               Compute number of unread articles in the page
                               
                     Parameters:
                       
			v_tab - tab sequence ID
	*/
	pageUnread:function(v_tab)
	{
		if (v_tab==indef) v_tab=$p.app.tabs.sel;
		if ($p.app.user.id==-1) return;
		tab[v_tab].nbUnread=0;
		for (var i=0;i<tab[v_tab].module.length;i++)
		{
			if (tab[v_tab].module[i].nbunread>0) 
            {
                tab[v_tab].nbUnread+=tab[v_tab].module[i].nbunread;
            }
		}
		if (tab[v_tab].nbUnread>0 && !tab[v_tab].temporary)
		{
			$p.print("tabextra"+v_tab,"("+tab[v_tab].nbUnread+")");
		}
        //next condition is not very useful : see some lines
		if (v_tab==$p.app.tabs.sel) $p.navigator.changeTitle();
	},
	/*
		Function: $p.app.widgets.rss.showOverview
                                Display article overview in tooltip
                                
		Parameters:

			v_id - feed sequence ID
			event - mouse event object
	*/
	showOverview:function(v_id,event)
	{
        if ($p.app.tabs.sel == -1) return;

        var v_tab = $p.app.tabs.sel
		//if (tab[$p.app.tabs.sel].feeds[v_id]) 
        if (tab[v_tab].RssArticles[v_id]) 
        {
            mouseBox(result,event);
		}
        //tab[v_tab].RssArticles[v_id].l_desc;
        /*
        var l_desc=
                    (tab[$p.app.tabs.sel].feeds[v_id] ?
                            tab[$p.app.tabs.sel].feeds[v_id].desc   :   ""
                    );
                    
         */           
        var l_desc=
                    (tab[v_tab].RssArticles[v_id] ?
                            tab[v_tab].RssArticles[v_id].desc   :   "" 
                    );	                 
/*
        var result=(tab[$p.app.tabs.sel].feeds[v_id]?
                            "<b>"+tab[$p.app.tabs.sel].feeds[v_id].title+"</b><br />"   :   ""
                    );
*/
        var result=(tab[v_tab].RssArticles[v_id]?
                            "<b>"+tab[v_tab].RssArticles[v_id].title+"</b><br />"   :   ""
                    );                    
                    
		if (__displayrssdesc==1)
		{
			result+=$p.app.widgets.rss.summarize(l_desc);
		}
		else
		{
			result+=l_desc;
		}
        if (tab[v_tab].RssArticles[v_id]) mouseBox(result,event);
		//if (tab[$p.app.tabs.sel].feeds[v_id]) mouseBox(result,event);
	},
	/*
		Function: $p.app.widgets.rss.summarize
                                Summarize an article
		
                     Parameters:
                     
			v_desc (string) - article description to summarize
            
		Returns
        
			(string)  short description
	*/
	summarize:function(v_desc)
	{
		var l_desc=$p.string.removeTags(v_desc);
		return $p.string.trunk(l_desc,100,true);
	},
	/*
		Function: $p.app.widgets.rss.hideOverview
                                Hide article overview
	*/
	hideOverview:function()
	{
		mouseBox("");
	},
	/*
		Function: $p.app.widgets.rss.secure
                                Format RSS article to avoid javascript injection
                                
		Parameters:

			 v_s - rss article string
             
                      Returns:
                      
                                string formatted  
	*/
	secure:function(v_s)
	{
		var l_s=v_s.replace(/&lt;/g,"<");
		l_s=l_s.replace(/&gt;/g,">");
		l_s=$p.string.correctEncoding(l_s);
		l_s=l_s.replace(/<script/g,"<!--");
		l_s=l_s.replace(/<\/script>/g,"-->");
		return l_s;
	},
	/*
		Function: $p.app.widgets.rss.importMenu
                                Import OPML file form
             
                      Returns:
                      
                                false
	*/
	importMenu:function()
	{
		var l_s="<table cellpadding='5' cellspacing='0' width='100%'>";
		l_s+="<tr><td class='bottomhr'><b>"+lg("lblImportOpml")+"</b><br /><br />";
		l_s+="<form enctype='multipart/form-data' method='post' action="+posh["scr_opml_import"]+" target='iopml'>";
		l_s+="<input type='file' name='opml' /> <input type='submit' class='submit' value='"+lg("lblUpload")+"' />";
		l_s+="</form>";
        l_s+="<iframe style='display:none' src='about:blank' id='iopml' name='iopml' onload='$p.app.widgets.rss.importTreat()'></iframe>";
        l_s+="<div id='opmlres'></div>";
        l_s+="</td></tr>\n";
		l_s+="<tr><td><p><b>"+lg("lblExportOpml")+"</b></p>";
		l_s+="<input type='button' value='"+lg("lblExportBtn")+"' onclick='$p.app.widgets.rss.exportOpml()' />";
		l_s+="</td></tr></table>";
		$p.print("box",box(0,lg("lblImport"),"hideBox()",l_s));
		$p.show("box","block");
		return false;
	},
	/*
		Function: $p.app.widgets.rss.importTreat
                                Treat OPML file
	*/
	importTreat:function()
	{
		var i = $("iopml");
        
		if (i.contentDocument)  {   
            var d = i.contentDocument;  
        }
		else if (i.contentWindow)   {
            var d = i.contentWindow.document;   
        }
		else    {   
            var d = window.frames["iopml"].document;    
        }
		if (d.location.href == "about:blank")    return; 
		if (d.body.innerHTML=="")   
        {   
        $p.app.alert.show(lg("msgXMLerror"));   
        }
		else    
        {
			$p.app.widgets.rss.opmlfile=d.body.innerHTML;
			getXml($p.app.widgets.rss.opmlfile,$p.app.widgets.rss.importSelectTab,"");
		}
	},
	/*
		Function: $p.app.widgets.rss.importSelectTab
                                Import selected tab from OPML file
                                
                     Parameters:
                     
                                response - XML object
                                vars - variables
	*/
	importSelectTab:function(response,vars)
	{
		if (response.getElementsByTagName("opml")[0] || response.getElementsByTagName("body")[0])
		{
			var opmlcont=response.getElementsByTagName("body")[0]   ?
                                        response.getElementsByTagName("body")[0]    :
                                        response.getElementsByTagName("opml")[0]
                                        ;
			$("opmlres").set('html','<p>'+lg("lblChooseOpmlTab")+'</p>:');
			for (var i=0;i<opmlcont.childNodes.length;i++)
			{
				var result=opmlcont.childNodes[i];
				if ($p.string.lc(result.nodeName)=="outline") 
				{
					var aLvlOpml = new Element('a', 
						{ 
							'events': {
										'click': function(){
											$p.app.widgets.rss.getImportTab(this.name); 
											}
									  },
							'href':'#'
						} 
					);
					aLvlOpml.name = i;
					aLvlOpml.set('html',$p.ajax.getProp(result,"title","str",false,"empty")+'<br />');
					aLvlOpml.inject($("opmlres"));
				}
			}
			var divOpml = new Element('div', { 'id':'opmlfeeds' } );
			divOpml.inject($("opmlres"));
		}
		if (l_s=="" || l_s==indef) 
		$("opmlres").set('html',lg("msgXMLerror"));	
	},
	/*
		Function: $p.app.widgets.rss.getImportTab
                                Load selected tab in OPML file
                                
                     Parameters:
                     
                                v_id - selected tab ID
	*/
	getImportTab:function(v_id)
	{
		getXml($p.app.widgets.rss.opmlfile,$p.app.widgets.rss.addImportTab,v_id);
	},
	/*
		Function: $p.app.widgets.rss.addImportTab
                                Add new tab based on select tab of OPML file
                                
                     Parameters:
                     
                                response - XML object
                                vars (array) - variables
	*/
	addImportTab:function(response,vars)
	{
		var l_s="<p>"+lg("selectFeedsToImport")+"</p>: ";
		if (response.getElementsByTagName("opml")[0])
		{
			var opmlcont=response.getElementsByTagName("body")[0]   ?
                                    response.getElementsByTagName("body")[0]    :
                                    response.getElementsByTagName("opml")[0]
                                    ;
			var selOutline=opmlcont.childNodes[vars];
			for (var i=0;i<selOutline.childNodes.length;i++)
			{
				var result=selOutline.childNodes[i];
				if ($p.string.lc(result.nodeName)=="outline")   {
					l_s+="<a href='#' "
                            +"onclick=\"$p.app.widgets.rss.checkFeed('"+$p.string.unesc($p.ajax.getProp(result,"xmlUrl","str",false,""))+"');return false;\">"
                            +$p.ajax.getProp(result,"title","str",false,"")+"</a>,<br /> ";	
				}
			}
		}
		$p.print("opmlfeeds",l_s);	
	},
	/*
		Function: $p.app.widgets.rss.exportOpml
                                Generate OPML file from user pages
	*/
	exportOpml:function()
	{
		$p.url.openLink(posh["xmlopmlexport"],true);
	},
	/*
		Function: $p.app.widgets.rss.getId
                                 Get feed sequence ID based on article DB ID
                                 
		Parameters:

			 v_id - article DB ID
		
                     Returns:
                     
			 article sequence ID
	*/
	getId:function(v_id)
	{
        var v_tab = $p.app.tabs.sel;
		for (var i=0;i<tab[v_tab].feeds.length;i++)
		{
			if (tab[v_tab].feeds[i].id==v_id) return i;
		}
		return v_id;
	},
	/*
		Function: $p.app.widgets.rss.getTopArticles
                                 Load top articles
	*/
	getTopArticles:function()
	{
		getXml(posh["xmltoparticles"],$p.app.widgets.rss.displayTopArticles);
	},
	/*
		Function: $p.app.widgets.rss.displayTopArticles
                                 Display top articles
                                 
                     Parameters:
                     
                                 response - XML object
	*/
	displayTopArticles:function(response)
	{
		var l_s="<ul>",l_result=response.getElementsByTagName('article');
		for (var i=0;i<l_result.length;i++)
		{
			l_s+="<li>"+$p.ajax.getVal(l_result[i],'title','str',false,'???')+"</li>";
		}
		l_s+="</ul>";

		$p.print('rsstoparticles',l_s);
	},
    /*
		Function: $p.app.widgets.rss.stopAllLoadings
                                 Stop RSS feeds loading of the page
                                 
                     Parameters:
                     
                                 v_tab : tab concerned
	*/
    stopAllLoadings: function(v_tab)
    {
        if (v_tab == indef)
            v_tab = $p.app.tabs.sel;
        //for all widgets RSS not loaded
        for (var i = 0;i < $p.ajax.requests.length;i++)
        {
            if ($p.ajax.requests[i])
            {
                if ($p.ajax.requests[i] && $p.ajax.requests[i].callerId == 'getWidgetArticles')
                {
                    $p.ajax.requests[i].kill();
                }
            }
        }
    }
}

/*
    Class: $p.app.statistics
*/
$p.app.statistics={
	contentDiv:'',
	/*
		Function: $p.app.statistics.initMenu
                                 Init the statistics menu
	*/
	initMenu:function()
	{
		if ($p.app.user.type!='N')
        {
			$p.app.menu.options.push(
				{
					"id":"info",
					"label":lg("buzz"),
					"desc":'',
					"icon":"ico_favorite.gif",
					"seq":52,
					//"action":"$p.app.statistics.menu()",
					'action':'',
					"type":"",
					'opened':false,
					'default_opened':false,
					'subOptions':[
						{
							'id':'statsmenu_1',
							'label':lg("mostReadArticles"),
							'action':$p.app.statistics.loadMostRead,
							'type':'link',
							'opened':false
						}
					]
				}
			);
		}
	},
	/*
		Function: $p.app.statistics.menu
                                 Build the statistics menu
	Removed with 2.2.3 (EMA)
	menu:function()
	{
        $p.app.menu.addTitle('statsmenu_1','',lg('buzz'));
        var l_s = '';
        
        l_s += '<a href="#" onclick="$p.app.statistics.loadMostRead(0);return false;">'+lg('mostReadArticles')+'</a><br />';

        $p.app.menu.addArea('statsmenu_1',l_s);
        
        $p.app.menu.openSubMenu('statsmenu_1',true);
    },*/
	/*
		$p.app.statistics.init : init statistics pages
	*/
	init:function()
	{
		//$p.app.newEnv('statistics');
		//$p.app.tabs.openTempTab(3,"$p.plugin.openInTab(%tabid%,function(){},'stats')",lg('statistics'),'../images/ico_stat.gif');
        $p.plugin.init(lg('stats'),'statistics',true);
		//$p.app.statistics.contentDiv='modules'+tab[$p.app.tabs.sel].id;
		$p.app.statistics.contentDiv = 'plugincontent';
	},
	/*
		Function: $p.app.statistics.loadMostRead
                                 Load most read articles
                                 
                     Parameters:
                     
                                 v_page - number of article for a page 
								 v_container - id of the div that will contain the results
	*/
	loadMostRead:function(v_page,v_container)
	{
		// $p.app.statistics.init();

		// $p.plugin.displayBreadcrumb('<div class="feature">'
			// + $p.app.breadCrumbs(
				// [
					// {'label':lg('home'),'link':'','fct':'$p.app.openHome();return false;'},
					// {'label':lg('mostReadArticles'),'link':'','fct':''}
				// ]
			// )
			// + '</div>'
		// );
		
		// $p.print($p.app.statistics.contentDiv,
                // '<div class="feature">'
                // + '<hr class="float_correction"></hr>'
                // + '<div id="plugindiv"></div>'
				// + '</div>');
        
		$p.app.pages.displaySummaryMenu('mostReadArticles');
		
		$p.ajax.call(posh["xmlmostread"]+'?p='+v_page,
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.statistics.displayMostRead,
					'variables':
					{
						'page':v_page,
						'container':v_container
					}
				}
			}
		);
	},
	/*
		Function: $p.app.statistics.displayMostRead
                                 Display most read articles
                                 
                     Parameters:
                     
                                 response - XML object
                                 vars (array) - variables
	*/
	displayMostRead:function(response,vars)
	{
		var l_result = response.getElementsByTagName('article'),
            l_s = '';
		if (l_result.length > 0)
		{
			for (var i = 0;i < l_result.length;i++)
			{
				l_s += '<div style="float: left;width: 20px;">'
					+ '<img src="'+_dirImg+'rss'+$p.ajax.getVal(l_result[i],'sourceid','int',false,0)+'" width="16" height="16" />'
					+ '</div>'
					+ '<div style="float: left;">'
					+ '<a href="'+$p.ajax.getVal(l_result[i],'link','str',false,'#')+'" target="_blank">'
					+ $p.ajax.getVal(l_result[i],'title','str',false,'-')
					+ '</a> '
					+ '('+$p.ajax.getVal(l_result[i],'nbread','str',false,'1')+')'
					+ '<br />'
					+ '<span class="source">'+$p.ajax.getVal(l_result[i],'source','str',false,'')+'</span>'
					+ '</div>'
					+ '<div class="float_correction"></div>';
			}
		}
		else
		{
			l_s+=lg("lblArchEmpty");
		}

		$p.print(vars['container'],l_s);
	}
}

//************************************ WIDGETS RSS READER FUNCTIONS ***************************************************************************************************************
/*
    Class: $p.app.widgets.rss.reader
         Widgets rss reader functions
*/
$p.app.widgets.rss.reader={
	selArticle:0,
	readerWidth:0,
	readerHeight:0,
	currSrc:indef,
	paneWidth:300,
	prevEnv:'',
	/*
		Function: $p.app.widgets.rss.reader.init
                                Init rss reader
	*/
	init: function()
	{	
		//hide modules
		$p.show("modules","none");
		$p.show("newspaper","block");
		$p.show("footer","none");
		$p.app.widgets.rss.reader.prevEnv = $p.app.env;
		$p.app.newEnv('portal_reader');
		//hide menus
		hideAllBox();
		$p.app.banner.option.hide();
		mouseBox("");	

        var l_s = '';
		var l_obj = $("newspaper");

		if ((l_obj) && (l_obj.innerHTML != ''))
            l_obj.empty();

		if (!l_obj)
		{
			var l_div = $("modules");
			l_obj = null;
			l_obj = new Element('div', 
				{
					'styles': {
						'display': 'none',
						'verticalAlign': 'top'
					},
					'id': 'newspaper'
				}
			);
			l_div.appendChild(l_obj)
		}
		
		//compute frames width
		$p.app.widgets.rss.reader.computeSize();

        l_s += '<div id="myreader">'
            + '<div class="newspaper">'
            + '<div class="sourcelist" style="float: right;">'
            + '<a href="#" onclick="$p.app.widgets.rss.reader.close();$p.app.widgets.rss.displayAll();">'
            + $p.img("ico_close.gif",12,11,lg("lblClose"),"imgmid")+" "+lg("lblClose")
            + '</a> &nbsp; '
            + '</div>'
            + '<div class="sourcelist" id="sourcelist">'
            + lg('lblLoading')
            + '</div>'
            + '<table cellpadding="0" cellspacing="0">'
            + ' <tbody>'
            + '  <tr>'
            + '   <td style="width: 300px;vertical-align: top;padding-left: 5px;">'
            + '   <div id="nparticles" style="width: 300px;height: '+$p.app.widgets.rss.readerHeight+'px;overflow: auto;vertical-align: top;">'
            + '   </div>'
            + '   </td>'
            + '   <td id="npdetail" class="frame" width="'+$p.app.widgets.rss.readerWidth+'" height="'+$p.app.widgets.rss.readerHeight+'">&nbsp;'
            + '   </td>'
            + '  </tr>'
            + ' </tbody>'
            + '</table>'
            + '</div>'
            + '</div>';

        $p.print('newspaper',l_s);

		tab[$p.app.tabs.sel].showType = 1; // rss reader active		
	},
	/*
		Function: $p.app.widgets.rss.reader.load
                                  Load feeds articles
		
                     Parameters:

			 v_scr - module sequence ID of the feed
	*/
	load: function(v_src)
	{
		var l_inc = 0,l_allLoaded = true;
		for (var i = 0;i < tab[$p.app.tabs.sel].module.length;i++)
		{
			if (tab[$p.app.tabs.sel].module[i].format == 'R' && !tab[$p.app.tabs.sel].module[i].isLoaded)
			{
				l_allLoaded = false;
				$p.app.widgets.rss.refresh(i);
			}
		}
		$p.app.widgets.rss.reader.showArticlesList(true,v_src);
	},
	/*
		Function: $p.app.widgets.rss.reader.refresh
                                Refresh feeds articles
                      
                     Returns:
                        
                                false
	*/
	refresh: function()
	{
		$p.app.widgets.rss.init($p.app.tabs.sel);
		$p.app.widgets.rss.reader.load($p.app.widgets.rss.reader.currSrc);
		return false;
	},
	/*
		Function: $p.app.widgets.rss.reader.chk
                                Display articles list
	*/
	chk:function(response,vars)
	{
		if ($p.app.widgets.rss.get(response,vars[0],vars[1]))
		{
			$p.app.widgets.rss.reader.showArticlesList(true,$p.app.widgets.rss.reader.currSrc);
		}
	},
	/*
		Function: $p.app.widgets.rss.reader.getSrcList
                                Display the reader sources list
	*/
	getSrcList: function()
	{
		//empty the element for a reload
        $p.app.widgets.rss.reader.emptySrcList();

		var srclink = [];
        var l_s = '<b>'+lg('lblSrc')+' : </b>';

		for (var i = 0;i < tab[$p.app.tabs.sel].module.length;i++)
		{
			if (tab[$p.app.tabs.sel].module[i].format == 'R'){
				if (tab[$p.app.tabs.sel].module[i].isLoaded){
					if ($p.app.widgets.rss.reader.currSrc == i){
						srclink.push(" <font class='sourcesel'>"
                                                    +tab[$p.app.tabs.sel].module[i].name+(tab[$p.app.tabs.sel].module[i].nbunread==0    ?
                                                    ""  :
                                                    " <a href='#' title='"+lg("readAll")+"' onclick='$p.app.widgets.rss.readAll("+$p.app.tabs.sel+","+i+");$p.app.widgets.rss.reader.showArticlesList(false,"+$p.app.widgets.rss.reader.currSrc+");'>("+tab[$p.app.tabs.sel].module[i].nbunread+")</a>")+"</font>");
					}
					else{
						srclink.push(" <a href='#' style='font-weight:normal' onclick='return $p.app.widgets.rss.reader.showArticlesList(false,"+i+")'>"+tab[$p.app.tabs.sel].module[i].name+"</a>"+(tab[$p.app.tabs.sel].module[i].nbunread==0?"":" <a href='#' title='"+lg("readAll")+"' onclick='$p.app.widgets.rss.readAll("+$p.app.tabs.sel+","+i+");$p.app.widgets.rss.reader.showArticlesList(false,"+$p.app.widgets.rss.reader.currSrc+");'>("+tab[$p.app.tabs.sel].module[i].nbunread+")</a>"));
					}
				}
				else
				{
					srclink.push(" "+tab[$p.app.tabs.sel].module[i].name+" "+$p.img("ico_wait.gif",9,9,lg("lblSrcLoading"),"imgmid"));
				}
			}
		}

        l_s += srclink.join(" | ");

		if ($p.app.widgets.rss.reader.currSrc != indef && srclink.length > 1) 
		{
            l_s += '&nbsp;&nbsp; | '
                + '<a href="#" onclick="return $p.app.widgets.rss.reader.showArticlesList(false);">'
                + lg("lblSrcAll")
                + '</a>'
		}

        $p.app.widgets.rss.reader.displayInSourceList(l_s);

		if (__useGSearch) 
		{
			var centerObj1 = new Element('center');
			var bObj2 = new Element ('b');
			bObj2.set('html',lg("lblSrcSrch"));
			bObj2.inject(centerObj1);
			var divObj1 = new Element('div', { 'id':'searchform', 'width':'350' } );
			divObj1.inject(centerObj1);
			centerObj1.inject($('sourcelist'));	
			var brObj2 = new Element('br');
			brObj2.inject($('sourcelist'));			
			var tableObj1 = new Element('table', { 'width':'100%' });	
			var tbodyObj1 = new Element('tbody');
			var trObj1 = new Element('tr');
			var tdObj1 = new Element('td', { 'valign':'top', 'width':'100%' } );
			var divObj2 = new Element('div', { 'id':'searchResults', 'width':'600' } );
			divObj2.set('html',lg("lblLoading"));
			divObj2.inject(tdObj1);
			tdObj1.inject(trObj1);
			trObj1.inject(tbodyObj1);
			tbodyObj1.inject(tableObj1);
			tableObj1.inject($('sourcelist'));	
		}
		$p.app.widgets.rss.reader.framesSize();
		
	},
    emptySrcList: function()
    {
        if ($('sourcelist').innerHTML != '')
            $('sourcelist').empty();
    },
    displayInSourceList: function(v_s)
    {
        $p.print('sourcelist',v_s);
    },
	/*
		Function: $p.app.widgets.rss.reader.showArticlesList
                                Display feeds of the selected source or from all sources
                                
		Parameters:

			v_sort - sorting type
			v_src - selected source
            
                     Returns:
                     
                                false
	*/
	showArticlesList:function(v_sort,v_src)
	{	
		var v_tab = $p.app.tabs.sel;
		$p.app.widgets.rss.reader.currSrc = v_src;
        var l_modId = $p.app.widgets.rss.reader.currSrc;
		//if multisources, display only once on the last source loading
		$p.app.widgets.rss.reader.getSrcList();
		//if (v_sort) tab[$p.app.tabs.sel].feeds.sort(sortDate);  //remove temporaly due to bug : when portal refresh and user is in the rss reader, once the reader closed, the feeds are not corresponding to the tooltip description !
		i=0;
        
		var l_s = '<div class="ListArticle">';
        
		//while (i<$p.app.widgets.rss.reader.nb && j<$p.app.widgets.rss.feeds.length){
        if ( v_src != "undefined" && typeof(l_modId) == 'number' && l_modId >= 0)
        {
            var res = $p.app.widgets.rss.reader.displayeachLineFeed(v_tab,l_modId);
            l_s = res[0];
            i = res[1];
        }
        else
        {   
            for (var l_modId in tab[v_tab].feeds)
            {
                if ( typeof(tab[v_tab].feeds[l_modId]) == "object")
                {
                    
                    var res = $p.app.widgets.rss.reader.displayeachLineFeed(v_tab,l_modId);
                    l_s += res[0];
                    i += res[1];
                }
            }
        }
        
		if (i == 0)
		{
			l_s += '<div style="width:100%;height:200px">'+lg("lblSrcMissing")+'</div>';
		}
		l_s += '</div>';
        
		$p.print("nparticles",l_s);
		
		if(__useGSearch) initGSearch(true);
		
		return false;	
	},
    /*
    
            function: $p.app.widgets.rss.reader.displayeachLineFeed
            
            parameters: 
            
                v_tab - id od tab
                
                l__modId - id of the module
                
           returns: html
           
           see: $p.app.widgets.rss.reader.showArticlesList
                
    */
    displayeachLineFeed: function (v_tab,l_modId)
    {
        var l_s='';
        var allArticles = new Array();
		for (var RssArticleId in tab[v_tab].feeds[l_modId])
		{
            
            if (    typeof(tab[v_tab].feeds[l_modId][RssArticleId]) != 'undefined' 
                    &&  typeof(tab[v_tab].RssArticles[RssArticleId]) != "undefined")
            {
				var l_id = $p.app.widgets.uniqToId(tab[v_tab].RssArticles[RssArticleId].modUniq);
                var l_class = (RssArticleId == $p.app.widgets.rss.reader.selArticle    ?   "highlight" :   
                                                                                          "normal" +  ((__registerfeeds && !tab[v_tab].module[l_id].auth)
                                                                                                            ?   (tab[v_tab].RssArticles[RssArticleId].isRead == 0
                                                                                                                        ?   'unread'
                                                                                                                        :   'read')
                                                                                                            :   '')
                                                                                       );
				var article  = '<div id="npart'+RssArticleId+'" class="'+l_class+'" style="padding: 5px 8px 5px 5px;">'
                    + '<img src="'+tab[v_tab].module[l_id].icon+'" width="16" height="16" align="left" valign="absmiddle" /> '
                    + '&nbsp;<a class="title" id="readerarticle'+v_tab+'_'+RssArticleId+'" href="'+tab[v_tab].RssArticles[RssArticleId].link+'" target="npdetailf" onclick="return $p.app.widgets.rss.reader.showDetail(this,'+RssArticleId+')">'+tab[v_tab].RssArticles[RssArticleId].title+'</a>'
                    + '<br />'
                    //display the article source
                    + $p.app.widgets.rss.reader.displaySource(RssArticleId)
                    //format the article date
                    + $p.date.formatDelai($p.date.delayFromNow(tab[v_tab].RssArticles[RssArticleId].date))
                    //display the sharing icon
                    + $p.app.widgets.rss.reader.displayIconSharing(RssArticleId)
                    //display the archive icon
                    //+ $p.app.widgets.rss.reader.displayIconArchive(RssArticleId)
					+'</div>';
                allArticles.push(article);                     
			}
		}
        allArticles.pop();
        for (var i = 0; i < allArticles.length; i++) {
            l_s += allArticles[i];
        }
        return new Array(l_s,i);
    },
     /*
		Function: $p.app.widgets.rss.reader.buildSideBar
                                 Build specific reader sidebar
                                 
		Parameters:

			 v_itemList : array containing items information
                                 
	*/
    buildSideBar: function(v_itemList)
    {
        var l_s = '<div class="ListArticle">',
            l_class;

        for (var i = 0; i < v_itemList.length; i++)
        {
            l_class = (v_itemList[i].id == $p.app.widgets.rss.reader.selArticle ? 'highlight' : 'normal');

            l_s += '<div id="npart'+v_itemList[i].id+'" class="'+l_class+'" style="padding: 5px 8px 5px 5px;">'
                + v_itemList[i].html
                + '</div>';
        }
        l_s += '</div>';
        
        $p.print('nparticles',l_s);
    },
	/*
		Function: $p.app.widgets.rss.reader.displaySource
                                 Display the article source
                                 
		Parameters:

			 j - feed ID in tab
                                 
                     Returns:
                            
                                HTML code
	*/    
	displaySource:function(RssArticleId)
	{   
        return  '<span class="source">'
                +tab[$p.app.tabs.sel].RssArticles[RssArticleId].modName
                +' '
                +((__displayrsssource 
                   && tab[$p.app.tabs.sel].RssArticles[RssArticleId].source!="" )      ?      '| '+tab[$p.app.tabs.sel].RssArticles[RssArticleId].source
                                                                      :      '')+'</span><br />';
    },    
	/*
		Function: $p.app.widgets.rss.reader.displayIconSharing
                                 Display the sharing icon
                                 
		Parameters:

			 j - feed ID in tab
                                 
                     Returns:
                            
                                HTML code
	*/    
	displayIconSharing:function(RssArticleId)
	{   
        if (!($p.app.user.id>0 && __useSharing)) return '';
        else {
              return  " <a href='#' onclick='$p.friends.menu(2,"+tab[$p.app.tabs.sel].RssArticles[RssArticleId].id+")'>"
                        + $p.img("ico_share_s.gif",13,10,lg("lblShareInfo"))
                        + "</a> ";
        }
    },
	// /*
		// Function: $p.app.widgets.rss.reader.displayIconSharing
                                 // Display the sharing icon
                                 
		// Parameters:

			 // j - feed ID in tab
                                 
                     // Returns:
                            
                                // HTML code
	// */  
	// displayIconArchive:function(RssArticleId)
	// {    
        // if (!($p.app.user.id>0 && __useArchive)) return '';
        // else {
             // return " <a href='#' onclick='return $p.article.isArticleSaved("+RssArticleId+")'>"
                    // + $p.img("ico_disk_s.gif",8,9,lg("lblSave"))
                    // + "</a> ";
        // }
    // },
	/*
		Function: $p.app.widgets.rss.reader.showDetail
                                 Show article detail in right panel
                                 
		Parameters:

			 v_objClicked - feed DB 
                                 v_id - ID of article in database
                                 
                     Returns:
                            
                                true or false
	*/
	showDetail:function(v_objClicked,v_id)
	{
		//after newspaper sorting, array id change => getId
        //v_id is unique id of article in database
        //l_id is id of article in web page
		//var l_id=$p.app.widgets.rss.getId(v_id);
        var RssArticleId = v_id;
        //id of page selected
        var v_tab = $p.app.tabs.sel;
        //var l_modId=$p.app.widgets.uniqToId(tab[$p.app.tabs.sel].feeds[l_id].modUniq);
        var l_modId=$p.app.widgets.uniqToId(tab[v_tab].RssArticles[RssArticleId].modUniq);
		
		if ($('npdetail').innerHTML!='')    $('npdetail').empty();
		var divObj1 = new Element('div', { 'id':'npdetailititle' } );
		var l_s='<h2>'+tab[v_tab].RssArticles[RssArticleId].title+'</h2>'
			+'<span class="source">'+tab[v_tab].RssArticles[RssArticleId].modName+'</span>'
			+' | '+$p.date.formatDelai($p.date.delayFromNow(tab[v_tab].RssArticles[RssArticleId].date))+((__displayrsssource && tab[v_tab].RssArticles[RssArticleId].source!="" )?' | '+tab[v_tab].RssArticles[RssArticleId].source:'')+' | ';
		
		if (tab[v_tab].RssArticles[RssArticleId].link!="" 
            && (tab[v_tab].RssArticles[RssArticleId].link).indexOf("noplink")==-1) {
			l_s += '<a id="npshowsumbtn" href="#" disabled="disabled" onclick="return $p.app.widgets.rss.reader.showArticlesListSummary('+RssArticleId+');">'+$p.img('ico_rss2.gif',16,16,'','imgmid')+' '+lg("lblOpenSummary")+'</a>'
				+' | <a id="npshowsitebtn" href="#" onclick=\'return $p.app.widgets.rss.reader.showArticlesListSite("'+tab[v_tab].RssArticles[RssArticleId].link+'");\'>'+$p.img('ico_adm_page.gif',16,16,'','imgmid')+' '+lg('lblOpenInReader')+'</a>'
				+' | <a id="npshowonsitebtn" href="#" onclick=\'return $p.url.openLink("'+tab[v_tab].RssArticles[RssArticleId].link+'",true)\'>'+$p.img('ico_next2.gif',12,11,'','imgmid')+' '+lg('lblOpenInNewPage')+'</a>'
				+' | <a href="#" onclick=\'return $p.app.widgets.rss.reader.maximize();\'>'+lg('maximize')+'/'+lg('minimize')+'</a>'
				if (__useRating)
				{	var source = "iframe";
					$p.app.widgets.rss.loadRating(v_id,l_modId,v_tab,source);
					$p.app.widgets.rss.loadAverageRating(v_id,l_modId,v_tab,source);
					l_s += '<div id="user_rating_iframe_'+l_modId+'_'+v_id+'"></div>'
					+ '<div id="average_rating_iframe_'+l_modId+'_'+v_id+'"></div>';
				}
			divObj1.set('html',l_s)
		}
		//ancre3
		divObj1.inject($('npdetail')); 

		var divObj2 = new Element('div', 
		{
				'styles': {
							'overflow':'auto',
							'width':'100%'
				},
				'id': 'npdetaili'
			}
		);
		var divObj3 = new Element('div', { 'id': 'npdetailidesc' } );
		divObj3.set('html',setExternalLink(tab[v_tab].RssArticles[RssArticleId].desc));
		divObj3.inject(divObj2);
		divObj2.inject($('npdetail'));
		var frameObj1 = new Element('iframe', 
			{
				'styles': {
					'width':'100%',
					'height':($p.app.widgets.rss.readerHeight-(__useSharing?20:0))+"px",
					'display':'none'
				},
				'id': 'npdetailf',
				'name':'npdetailf',
				'src':''
			}
	    );						   
		frameObj1.inject($('npdetail'));

		if (__useSharing)
		{
			var divShare = new Element('div',
				{
					'styles': {
						'overflow':'auto',
						'text-align':'center',
						'width':'100%',
						'background':'#c6c3c6',
                        'padding':'4px'
					},
					'id': 'npdetails'
				}
			);
			var aShare = new Element('a',
				{
					'href':'#',
					'styles':{
						'font-weight':'bold'
					},
					'events':{
						'click':function()
						{
							$p.friends.menu(2,RssArticleId);
						}
					}
				}
			);
			aShare.itemid=v_id;
			aShare.inject(divShare);
			var imgShare=new $p.imgObj('mynetwork.gif',16,16,"","imgmid");
			imgShare.inject(aShare);
			aShare.appendText(" "+lg("articleMayInterest"));
			divShare.inject($('npdetail'));
		}

		//($("npshowsumbtn")).disabled=true;
		//un highlight the previous article
		$p.setClass("npart"+$p.app.widgets.rss.reader.selArticle,((__registerfeeds && !tab[$p.app.tabs.sel].module[l_modId].auth)?"normalread":"read"));
		//highlight the selected article
		$p.setClass("npart"+RssArticleId,"highlight");
		$p.app.widgets.rss.reader.selArticle=RssArticleId;
		if (__registerfeeds)
		{
			$p.app.widgets.rss.linkClicked(
                                        v_objClicked,
                                        tab[v_tab].RssArticles[RssArticleId].modUniq,
                                        $p.app.widgets.uniqToId(tab[v_tab].RssArticles[RssArticleId].modUniq),
                                        indef,
                                        RssArticleId
                                        );
			$p.app.widgets.rss.reader.getSrcList();
			if (!tab[$p.app.tabs.sel].module[l_modId].auth) return false;
		}
		
		$p.app.widgets.rss.reader.getSrcList();
		$p.app.widgets.rss.reader.framesSize();
	
		return (tab[v_tab].RssArticles[RssArticleId].link==""?false:true);
	},
    /*
		Function: $p.app.widgets.rss.reader.displayContent
                                Display reader content
	*/
    displayContent: function(v_s)
    {
        $p.print('npdetail',v_s);
    },
	/*
		Function: $p.app.widgets.rss.reader.maximize
                                Maximize reader
	*/
	maximize:function()
	{
		if ($p.get('nparticles').parentNode.style.display == "none")    {
			$p.get('nparticles').parentNode.style.display = "block" ;
            //$p.show('sourcelist','block');
			$p.app.widgets.rss.reader.paneWidth=300;
		}
		else    {
			$p.get('nparticles').parentNode.style.display = "none" ;
            //$p.show('sourcelist','none');
			$p.app.widgets.rss.reader.paneWidth=0;
		}
		$p.app.widgets.rss.reader.computeSize();
		$p.app.widgets.rss.reader.framesSize();
	},
	/*
		Function: $p.app.widgets.rss.reader.showArticlesListSite
        
                                Display web site linked with the read article (in a frame)
                                
                                check if an article is already displayed
                                
                     Parameters:
                     
                                v_scr - selected source
                               
                     Returns:
                     
                                false
	*/
	showArticlesListSite:function(v_src)
	{
        var simplifiedLocation = windowLocationObject.href;
        if (simplifiedLocation.indexOf('#')!=-1) {
            var anchorPos = simplifiedLocation.indexOf('#');
            simplifiedLocation = simplifiedLocation.substring(0, anchorPos);
        }
        if (    $("npdetailf").src=="" 
                || $("npdetailf").src+"#" == windowLocationObject.href 
                || $("npdetailf").src==simplifiedLocation
                || simplifiedLocation.match($("npdetailf").src)
                ) 
        {
           ($("npdetailf")).src=v_src;
		}
        
        $p.show("npdetaili","none");
		$p.show("npdetailf","block");
		($("npshowsumbtn")).disabled=false;
		($("npshowsitebtn")).disabled=true;
        
		return false;
	},
	/*
		Function: $p.app.widgets.rss.reader.showArticlesListSummary
                            Display article summary loaded from RSS feed
                            
		Parameters:
        
                            v_id - article DB ID
                            
                     Returns:
                     
                            false
	*/
	showArticlesListSummary:function(v_id)
	{
		$p.show("npdetaili","block");
		$p.show("npdetailf","none");
		$p.print("npdetailidesc","<br />"+setExternalLink(tab[$p.app.tabs.sel].RssArticles[v_id].desc));
		($("npshowsumbtn")).disabled=true;
		($("npshowsitebtn")).disabled=false;
		return false;
	},
	/*
		Function: $p.app.widgets.rss.reader.close
                                Close rss reader
	*/
	close:function()
	{
		$p.app.widgets.rss.reader.hide();
		$p.show("modules","block");
		$p.show("footer","block");
		$p.app.banner.option.show();
		$p.app.newEnv($p.app.widgets.rss.reader.prevEnv);
	},
	/*
		Function: $p.app.widgets.rss.reader.hide
                                Hide rss reader
	*/
	hide:function()
	{
		$p.show('newspaper','none');
		$p.print('npdetail','');
		if ($p.app.tabs.sel!=-1) tab[$p.app.tabs.sel].showType=0;
	},
	/*
		Function: $p.app.widgets.rss.reader.supSrc
                                Remove a rss feed from the reader
                                
		Parameters:

			 v_id - linked module sequence ID
	*/
	supSrc:function(v_id)
	{
		if ($p.app.widgets.suppress(tab[$p.app.tabs.sel].module[v_id].uniq,true))
			$p.app.widgets.rss.reader.showArticlesList(false);
	},
	/*
		Function: $p.app.widgets.rss.reader.computeSize
                                 Compute the rss reader size
	*/
	computeSize:function()
	{
		var l_left=$p.getPos($('newspaper'),"Left");
		var l_top=$p.getPos($('newspaper'),"Top");
		$p.app.widgets.rss.readerWidth=Window.getWidth()-l_left-$p.app.widgets.rss.reader.paneWidth-10;
		$p.app.widgets.rss.readerHeight=Window.getHeight()-l_top-70;
	},
	/*
		Function: $p.app.widgets.rss.reader.framesSize
                                Refresh article pane height
	*/
	framesSize:function()
	{
		$p.app.widgets.rss.reader.computeSize();
		var l_pageHeight=Window.getHeight();
		var l_readerTop=$p.getPos(($("nparticles")),"Top");
		var l_detailTop=$p.getPos(($("npdetaili")),"Top");
		var l_readerHeight=((l_pageHeight-l_readerTop)-8)+"px";
		$("nparticles").setStyle("height",l_readerHeight);
		var l_detailHeight=((l_pageHeight-l_detailTop)-26)+"px";
		if ($("npdetaili")!=null)($("npdetaili")).setStyle("height",l_detailHeight);
		if ($("npdetailf")!=null)($("npdetailf")).setStyle("height",l_detailHeight);
		if ($("npdetail")!=null)($("npdetail")).setStyle("height",l_readerHeight);
		$("npdetail").setStyle("width",$p.app.widgets.rss.readerWidth);
	}
}



//*************************************** WIDGETS FACTORY FUCNTIONS *************************************************************************************
/*
    Class: $p.app.widgets.factory
            Widget factory functions
*/
$p.app.widgets.factory={
	shown:false,
	items:[],
	waitItems:[],
    /*
    		Function: object 
                               $p.app.widgets.factory.object  *(Contructor)*
                               
                               Widget factory class
           */
	object:function(id,name,typ,secured)
	{
		this.id=id;
		this.name=name;
		this.typ=typ;
		this.secured=secured;
	},
	menu:new Array({"id":1,"title":"lblArchive2","icon":"mymodules.gif","fct":"$p.app.widgets.factory.display(0,0)","isLink":true},{"id":2,"title":"lblCreateYourMod","icon":"mymodules_create.gif","fct":"$p.app.widgets.factory.createModuleMenu()","isLink":true}),
	/*
		$p.app.widgets.factory.init : init module factory plugin
	*/
	init:function()
	{
        $p.app.menu.close();
		//$p.plugin.open();
		$p.plugin.init(lg("lblArchive2"),'factory',true);
		$p.app.widgets.factory.load();
		$p.app.setState("$p.app.widgets.factory.init()");
		$p.plugin.useWidget();
		return false;
	},
	/*
		$p.app.widgets.factory.load : load the list of the modules I created
	*/
	load:function()
	{
		$p.ajax.call(posh["xmlmymodules"],
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.widgets.factory.get
				}
			}
		);
	},
	/*
		$p.app.widgets.factory.get : treat the list of the modules I created
	*/
	get:function(response,vars)
	{ 
		var i=0;
		$p.app.widgets.factory.items.length=0;
		$p.app.widgets.factory.waitItems.length=0;
		while (response.getElementsByTagName("module")[i])
		{
			var l_result=response.getElementsByTagName("module")[i];
			if ($p.ajax.getVal(l_result,"status","str",false,"")=="O"){
				$p.app.widgets.factory.items.push(new $p.app.widgets.factory.object($p.ajax.getVal(l_result,"id","int",false,0),$p.ajax.getVal(l_result,"name","str",false,"=="),$p.ajax.getVal(l_result,"typ","str",false,""),$p.ajax.getVal(l_result,"secured","int",false,0)));
			}
			else{
				$p.app.widgets.factory.waitItems.push(new $p.app.widgets.factory.object($p.ajax.getVal(l_result,"id","int",false,0),$p.ajax.getVal(l_result,"name","str",false,"=="),$p.ajax.getVal(l_result,"typ","str",false,""),0));
			}
			i++;
		}
		$p.app.widgets.factory.display(0,0);
	},
	/*
		Function: $p.app.widgets.factory.display 
        
                    display the list of the widgets I have created
		
        Parameters:

			v_page - page of the list
			v_pageVal - ??
	*/
	display:function(v_page,v_pageVal)
	{
		var l_s=$p.html.buildTitle(lg('lblArchive2'))
			+'<table width="100%" cellspacing="10">'
			+'<tr>'
			+'<td width="250" id="factoryaddmenu" valign="top">'
			+'</td>'
			+'<td valign="top">'
			+'<div class="subtitle">'+lg("mymodulesVal")+'</div>'
			+'<table>';

		var l_start=v_page*10;
		var l_end=l_start+10;
		for (var i=l_start;i<l_end;i++)
		{
			if (i<$p.app.widgets.factory.items.length)
			{
				l_s+='<tr>'
					+'<td>'
					+'<img src="'+_dirImg+'/box0_'+$p.app.widgets.factory.items[i].id+'" align="absmiddle" width="16" height="16" />'
					+'</td>'
					+'<td>'
					+'<a href="#" onclick=\'$p.app.widgets.open('+$p.app.widgets.factory.items[i].id+',"","uniq",'+($p.app.widgets.factory.items[i].secured==0?false:true)+')\'><b>'+$p.app.widgets.factory.items[i].name+'</b></a>'
					+'</td>'
					+'</tr>';
                    
				if ($p.app.widgets.factory.items[i].typ=="R") {
                    l_s+="<tr><td></td><td>[<a href='"+posh["redactor_article_modify_add"]+"'?mid="
                       +$p.app.widgets.factory.items[i].id
                       +"'>"
                       +lg("addArticle")
                       +"</a>] [<a href="+posh["redactor_feed"]+"'?mid="
                       +$p.app.widgets.factory.items[i].id
                       +"'>"
                       +lg("feedDetail")
                       +"</a>]</td></tr>";
                }
			}
		}
		l_s+='</table>'
			+($p.app.widgets.factory.items.length==0 ? "<i>"+lg("mymodulesValNone")+"</i>" : '')
			+$p.html.buildPageNavigator('previous',(v_page==0 ? '' : "$p.app.widgets.factory.display("+(v_page-1)+","+v_pageVal+")"),'','next',($p.app.widgets.factory.items.length<=i ? '' : "$p.app.widgets.factory.display("+(v_page+1)+","+v_pageVal+")"))
			+'<div class="subtitle">'+lg("mymodulesWait")+'</div>'
			+'<table>';
		var l_startVal=v_pageVal*10;
		var l_endVal=l_start+10;
		for (var i=l_startVal;i<l_endVal;i++)
		{
			if (i<$p.app.widgets.factory.waitItems.length)
			{
				l_s+='<tr>'
					+'<td>'
					+'<img src="../modules/quarantine/icon'+$p.app.widgets.factory.waitItems[i].id+'" align="absmiddle" width="16" height="16" />'
					+'</td>'
					+'<td>'
					+'<b>'+$p.app.widgets.factory.waitItems[i].name+'</b>'
					+'</td>'
					+'</tr>';
			}
		}
		l_s+='</table>'
			+($p.app.widgets.factory.waitItems.length==0 ? "<i>"+lg("mymodulesWaitNone")+"</i>" : '')
			+$p.html.buildPageNavigator('previous',(v_pageVal==0 ? '' : "$p.app.widgets.factory.display("+v_page+","+(v_pageVal-1)+")"),'','next',($p.app.widgets.factory.waitItems.length<=i ? '' : "$p.app.widgets.factory.display("+v_page+","+(v_pageVal+1)+")"))
			+'</td>'
			+'</tr>'
			+'</table>';

		$p.plugin.content(l_s);
		$p.app.widgets.factory.shown=true;
        
		$p.app.widgets.factory.createModuleMenu();
	},
    displayTutorial:function()
    {
        $p.print("plugincontent",'<iframe src="'+posh["tutorial"]+'" width="100%" height="800" frameborder="no" marginwidth="0" marginheight="0" scrolling="auto"></iframe>');
    },
	/*
		$p.app.widgets.factory.createModuleMenu : display modules factory options
	*/
	createModuleMenu:function()
	{
        var l_s='';
        l_s+='<img src="../images/ico_moduleandrss.gif" align="absmiddle" />\
              <span><a href="#" onclick="$p.app.widgets.factory.displayTutorial();return false;">'+lg("createYourModules")+'</a></span>';   
        $p.print("factoryaddmenu",l_s);
  
        /*
		var divLvl1 = new Element('b');
		divLvl1.set('html',lg("addRssFeed")+ " :<br /><br />");
		divLvl1.inject($("factoryaddmenu"));
				
		var aLvl1 = new Element('a', { 'href':posh["rssaddtodirectory"], 'target':'_createmodule' } );
		var imgLvl1 = new Element('img', { 'src':'../images/ico_rsstomodule.gif', 'align':'absmiddle' } );
		var bLvl1 = new Element('span');
		bLvl1.set('html',lg("addRssFeedToDirectory")+"<br /><br />");
		imgLvl1.injectInside(aLvl1);
		bLvl1.injectInside(aLvl1);
		aLvl1.inject($("factoryaddmenu"));

		var divLvl2 = new Element('b');
		divLvl2.set('html',lg("createYourModules")+ " :<br /><br />");
		divLvl2.inject($("factoryaddmenu"));
		
		if (__allowredactor) 
		{
			var aLvl2 = new Element('a', { 'href':posh["createrss"], 'target':'_createmodule' } );
			var imgLvl2 = new Element('img', { 'src':'../images/ico_moduleandrss.gif', 'align':'absmiddle' } );
			var bLvl2 = new Element('span');
			bLvl2.set('html',lg("createRssFeed")+"<br /><br />");
			imgLvl2.injectInside(aLvl2);
			bLvl2.injectInside(aLvl2);
			aLvl2.inject($("factoryaddmenu"));			
		}		
			
		var aLvl3 = new Element('a', { 'href':posh["expert"], 'target':'_createmodule' } );
		var imgLvl3 = new Element('img', { 'src':'../images/ico_expertmodule.gif', 'align':'absmiddle' } );
		var bLvl3 = new Element('span');
		bLvl3.set('html',lg("createExpertModule")+"<br /><br />");
		imgLvl3.injectInside(aLvl3);
		bLvl3.injectInside(aLvl3);
		aLvl3.inject($("factoryaddmenu"));	
        */

		$p.app.widgets.factory.shown=true;	
	},
	/*
		$p.app.widgets.factory.hide : close modules factory
	*/
	hide:function()
	{
		$p.plugin.hide();
		$p.app.widgets.factory.shown=false;
	}
}
/*
    Class: $p.app.connection
*/
$p.app.connection={
	active:true,
    oldvalues:{},
	/*
		$p.app.connection.changePass : change user password
	*/
	changePass:function()
	{
		// Change user password
		document.forms["newpass"].pass1.value=$p.string.trim(document.forms["newpass"].pass1.value);
		document.forms["newpass"].pass2.value=$p.string.trim(document.forms["newpass"].pass2.value);
		l_pass1=document.forms["newpass"].pass1.value;
		l_pass2=document.forms["newpass"].pass2.value;
        if( __CONNECTION_SECURITY_LEVEL<2 && l_pass1.length<6 ) {
			$p.app.alert.show(""+lg("msgSubPassToShort"));
            return false;
		} else if ( ( (l_pass1.length<8) || (l_pass2.length<8) ) && __CONNECTION_SECURITY_LEVEL>=2) {
			$p.app.alert.show(""+lg("msgSubPassToShort8"));
        } 
		else if (l_pass1!=l_pass2) {
			$p.app.alert.show(lg("msgSubPassDiff"));
        }
		else {
			if (l_pass1==l_pass2) {
				$p.ajax.call(posh["scr_changepwd"],
					{
						'type':'execute',
						'variables':"oldpass="+$p.string.esc(document.forms["newpass"].oldpass.value)+"&pass1="+$p.string.esc(l_pass1),
						'alarm':true
					}
				);
			}
		}	
	},
	changePasswordExpired:function() {

		var l_s = '<hr /><div style="color:red;height:25px;">\
						'+lg('lblErrPassExpired')+'\
					</div>\
					<div style="height:25px;">\
						<div style="float:left;width:150px;">'+lg('lblNewPassword')+' :</div>\
						<div><input type="password" id="exppassword" class="thinbox" name="exppassword" maxlength="64" style="width: 175px;" /></div>\
					</div>\
					<div style="height:25px;">\
						<div style="float:left;width:150px;">'+lg('lblNewPasswordConfirm')+' :</div>\
						<div><input type="password" name="exppasswordconf" class="thinbox" maxlength="32" style="width: 175px;" /></div>\
					</div><div style="clear:left;"></div><hr />';
		$('exppass').innerHTML =  l_s;
	},
	/*
		Function: set
                            $p.app.connection.set : connect user
		Parameters:

			v_form - form used to get user connection information
			v_function - function called when connected
			v_type - connection type
	*/
	set:function(v_form,v_function,v_type,v_md5key)
	{
		$p.plugin.hook.launch('app.connection.set.start');
        var username = v_form.username.value;
        username = $p.string.replacePlus(username);

		// connect to profile
		var l_connStr = "u="+username+"&pass="+$p.string.esc(v_form.password.value);

		if(v_form.exppassword) {
			var newpass = v_form.exppassword.value;
			var newpassconf = v_form.exppasswordconf.value;
			l_connStr += "&newpass="+$p.string.esc(newpass)+"&newpassconf="+$p.string.esc(newpassconf);
		}
		
		if (v_form.autoconn && v_form.autoconn.checked)
            l_connStr+="&auto=1";

		if (v_type) l_connStr+="&rtype=1";
		if (username=="")
            $p.app.alert.show(lg("lblEmailChk")+". ");
		else
        {
			   
			$p.ajax.call(posh["scr_connect"],
				{
					'type':'execute',
					'variables':l_connStr,
					'alarm':true,
					'forceExecution':true,
					'callback':
					{
						'function':v_function,
                        'variables':
                        {
                            'md5key':(typeof(v_md5key)=='undefined')?'':v_md5key,
                            'subscribe':false
                        }
					}
                    
				}
			);
		}

		$p.plugin.hook.launch('app.connection.set.end');

		return false;
	},
	/*
		Function: closeRelogin
                            $p.app.connection.closeRelogin : close  relogin
	*/
	closeRelogin:function()
	{
	},
	hide:function(){
		$p.print("messages","");
	},
	/*
		$p.app.connection.subscribe : application subscription process
		Parameters:

			v_form - subscription form object
			v_function - function called with user is registrered and connected
	*/
	subscribe:function(v_form,v_function)
	{
		$p.plugin.hook.launch('app.connection.subscribe.start');

		// subscribe to application
		var l_e="";
		var l_a="";
		var n = v_form.length;
		var i=0;
		var minicount=0;
		var tabRadio=[];
		var oldname="";
		var temp;
		
		v_form.pass.value = $p.string.trim(v_form.pass.value);
		v_form.confpass.value = $p.string.trim(v_form.confpass.value);
		
		if (v_form.username.value=="") {
			l_e+=lg("msgSubEmailMiss")+"<br />";
		}
		if (v_form.pass.value=="") {
		    l_e+=lg("msgSubPassMiss")+"<br />";
		} else {
			if ( v_form.pass.value.search(""+v_form.username.value) != -1){
			     l_e+=lg("msgUsrInPass")+"<br />";
			}
			if (__accountType=="mail" && !checkEmail(v_form.username.value)) {l_e+=lg("msgSubEmailValid")+"<br />";}
			
			if( (
				 !$p.string.checkCharacterInString(v_form.pass.value) || 
				 !$p.string.checkNumberInString(v_form.pass.value) || 
				 !$p.string.checkSymbolInString(v_form.pass.value)
				 )  && __CONNECTION_SECURITY_LEVEL>=3
			 ) {
				l_e += lg("msgErrPasswordMix")+"<br />";
			}

		}
		if( v_form.pass.value.search(""+v_form.longname.value) != -1 && v_form.longname.value!="") {
			l_e+=lg("msgNameInPass")+"<br />";
		}
		
		if( __CONNECTION_SECURITY_LEVEL<2 && v_form.pass.value.length<6) {
			l_e+=""+lg("msgSubPassToShort")+"<br />";
		}else if ( ( (v_form.pass.value.length<8) || (v_form.confpass.value.length<8) )  && __CONNECTION_SECURITY_LEVEL>=2 ) {
			l_e+=""+lg("msgSubPassToShort8")+"<br />";
		}
		
		if (__accountType=="mail" && v_form.username.value!=v_form.username2.value){l_e+=lg("msgSubEmaildiff")+"<br />";}
		if (v_form.pass.value!=v_form.confpass.value){l_e+=lg("msgSubPassDiff")+"<br />";}
		if(__useConditions&&!v_form.conditions.checked){l_e+=lg("msgSubCond")+"<br />";}
		
		var l_email = (__accountType == 'mail' ? v_form.username.value : v_form.email.value);
		
		var l_connStr = 'u=' + v_form.username.value
			+ '&p=' + $p.string.esc(v_form.pass.value)
			+ '&e=' + l_email
			+ ((__useNewsletter&&v_form.newsletter.checked) ? '&n=1' : '')
			+ '&l=' + v_form.longname.value
			+ '&nbSpecificFields=' + v_form.nbSpecificFields.value;
		
		for (i=6;i<n;i++)
		{
			switch (v_form.elements[i].type)
			{
				case 'text':
					//is the field mandatory and is it filled with something
					var mandatory = v_form.elements[i].getAttribute("mandatory");
					if (mandatory==1 && v_form.elements[i].value=="")   l_a=lg("errorEmptyFieldForm");
					else    l_connStr+="&"+v_form.elements[i].name+"="+v_form.elements[i].value+"&criteria";							
				break;
				case 'select-one':
					l_connStr+="&"+v_form.elements[i].name+"="+v_form.elements[i].value;	
				break;
				case 'textarea':
					//is the field mandatory and is it filled with something
					var mandatory = v_form.elements[i].getAttribute("mandatory");
					if (mandatory==1 && v_form.elements[i].value=="") {
						l_a=lg("errorEmptyFieldForm");
					}
					else {
                        l_connStr+="&"+v_form.elements[i].name+"="+v_form.elements[i].value;	
                    }
				break;	
				case 'radio':
					var maxIndex=tabRadio.length;
					var escap=0;						
					var currentName = v_form.elements[i].name;
					var mandatory = v_form.elements[i].getAttribute("mandatory");
                    if (maxIndex>0) {
                        for (var j=0;j<maxIndex;j++)
                        {
                            if (tabRadio[j]==currentName)  { escap=1; }
                            else  {  tabRadio[maxIndex]=currentName;	}
                        }
                    }
                    else   {
                        tabRadio[0]=currentName;
                    }
                    
                    if (escap==0)   {
                        var cpt=i;
                        var correct=0;
                        //if the first element isn't checked						
                        if (v_form.elements[cpt].checked!=true) {
                                //we scan the others
                                while (v_form.elements[cpt+1].name==currentName)
                                {
                                    if (v_form.elements[cpt+1].checked==true)   {
                                            correct=1;
                                            l_connStr+="&"+v_form.elements[cpt+1].name+"="+v_form.elements[cpt+1].value;
                                    }	
                                    cpt++;
                                }
                        }												
                        else    {
                            correct=1;
                            l_connStr+="&"+v_form.elements[cpt].name+"="+v_form.elements[cpt].value;	
                        }
                        if (mandatory==1)   {	
                            if (correct!=1)   {
                                l_a=lg("errorEmptyFieldForm");	
                            }
                        }
                    }
                break;
				case 'checkbox':								
					var mycurrentName = v_form.elements[i].name;
					var passage=0;
					var c_result="";
					
					if (oldname=="")    {
						oldname=mycurrentName;
						passage=1;
						minicount=0;
						temp=0;
					}
					else if (oldname!=mycurrentName)    {
						oldname=mycurrentName;
						passage=1;
						minicount=0;
						temp=0;
					}
					else  {  passage=0; }
								
					//If the field is mandatory, verify that at least one checkbox is checked
					var mandatory = v_form.elements[i].getAttribute("mandatory");
					var cpt=i;
					if (passage==1) {
						if (v_form.elements[i].checked!=true) {  minicount++; }
						else
							c_result+=v_form.elements[i].value+';';
							while (v_form.elements[cpt+1].name==mycurrentName)
							{
								temp = v_form.elements[cpt+1].value;
								if (v_form.elements[cpt+1].checked!=true) {
									minicount++;
                                }
								else {
									c_result+=temp+';';
                                }
								cpt++;
							}	
							if (mandatory==1)   {	
								if (minicount==temp)  { l_a=lg("errorEmptyFieldForm"); }
							}
							
						if (c_result!=""){	
							var taille=c_result.length;
							var variable=c_result.substr(0,taille-1); 
							c_result=variable;
						}
						l_connStr+="&"+v_form.elements[i].name+"="+c_result;
					}
                break;
            }
        }

		if (l_a!="")  {
            l_e+=l_a;
        }
		if (l_e=="") {
			var nbCriterias=v_form.nbSpecificFields.value;
			for (var j=1;j<=nbCriterias;j++)
			{
				var idName="c_id"+j;
				var idValue=v_form.elements[idName].value;
				l_connStr+="&"+idName+"="+idValue;
			}
            
			$p.ajax.call(posh["scr_subscribe"],
				{
					'type':'execute',
					'variables':l_connStr,
					'alarm':true,
					'forceExecution':true,
					'method':'post',
					'callback':
					{
						'function':v_function
					}
				}
			);
		}
		else {
			$p.app.alert.show(l_e);
		}

		$p.plugin.hook.launch('app.connection.subscribe.end');

		return false;
	},	
	/*
		Function: $p.app.connection.test
                        test connection to the server
	*/
	test:function()
	{
		if ($p.app.connection.active && $p.app.user.id != 0 && $p.app.user.id != 'N') {
			$p.ajax.call(__LOCALFOLDER+'portal/'+posh["xmlcheckuserconnection"],
				{
					'type':'load',
					'callback':
					{
						'function':$p.app.connection.testTreatment,
						'variables':
						{
							'function':$p.app.connection.errorTest
						}
					},
					'escape':$p.app.connection.errorTest,
					'source':'xml',
					'method':'GET'
				}
			);
		}
	},
	/*
		$p.app.connection.testTreatment : treat server response on server testing
	*/
	testTreatment:function(response,vars)
	{
		var l_check=$p.ajax.getVal(response,"userid","str",false,0);
		if (l_check==0)  {
            $p.app.connection.errorTest();
        }
	},
	/*
		$p.app.connection.errorTest : treat connection issue
	*/
	errorTest:function()
	{
//		if (!$p.app.connection.active) return;
        
//		$p.app.connection.active=false;
        
//		var l_response=confirm(lg("youHaveBeenDisconnected"));
//		if (l_response==1) $p.url.openLink();
        window.location.reload();
	},
	/*
		Function: saveMenu
        
                                    $p.app.connection.saveMenu 
                                        
                                    display page saving options (when user is not connected)
	
                                    use fadein to display page
    */
	saveMenu:function ()
	{
		$p.plugin.hook.launch('app.connection.saveMenu.start');
        var lblusername = __accountType=='mail'?lg('lblEmail'):lg('lblLogin');
		var l_s='\
    <div id="loginscreen">\
        <h2 id="lsconnectTitle">'+lg('lblAlreadyMember')+'</h2>\
		<div id="displayPart">\
			<div id="msg_conn">&nbsp;</div>\
			<form name="form2" method="post" onsubmit="return $p.app.pages.checkAndSave(this);">\
				<table cellspacing="6">\
					<tr>\
						<td class="label"><label id="ls_lbl_username" for="username">'+lblusername+' :</label></td>\
						<td><input type="text" id="username" class="thinbox" name="username" maxlength="64" style="width: 240px;" /></td>\
					</tr>\
					<tr>\
						<td></td><td></td>\
					</tr>\
					<tr>\
						<td class="label"><label id="ls_lbl_password" for="password">'+lg('lblPassword')+' :</label></td>\
						<td><input type="password" name="password" class="thinbox" maxlength="32" style="width: 240px;" /></td>\
					</tr>\
					<tr>\
						<td></td>\
						<td align="right">\
							<a href="#" id="ls_missingpass" onclick="return $p.app.connection.buildmissingPasswordForm();return false;">'+lg('lblMissingPassword')+'</a>\
						</td>\
					</tr>\
					<tr>\
						<td>&nbsp;</td><td></td>\
					</tr>\
					<tr>\
						<td></td>\
						<td>\
							<div style="float: right;"><input type="submit" class="btn" value="'+lg('lblSavePage')+'" /></div>\
							<div style="padding-top: 3px"><input type="checkbox" id="ls_lbl_autoconnect" name="autoconn" />'+lg('lblAutoConnection')+'</div>\
						</td>\
					</tr>\
				</table>\
			</form>\
			' + __conditionComment + '\
            </div><br /><hr />\
            <h2>'+lg('notAMemberYet')+' ?</h2>\
			<a href="#" onclick="$p.app.connection.subscribeMenu();return false;">'+lg('lblAccountCreation')+'</a><br /><br />\
            </div>';
        
		$p.app.popup.fadein(l_s,420,indef,$p.img("ico_menu_disk.gif",14,14,"","imgmid")+" "+lg("lblSavePage"),true);
		$p.plugin.hook.launch('app.connection.saveMenu.end');
	},
	subscribeMenu:function()
	{
		var code = $p.app.captcha.generate_code();
		var captcha_call='',account_call='';
		if(__captcha) {
			captcha_call='return $p.app.captcha.verif_code(this);';
        }
		else {
			captcha_call='return $p.app.connection.subscribe(this,$p.app.connection.subscribeConfirmation);';
        }
		account_call=__accountType=="mail"?lg("lblEmail"):lg("lblLogin");

		var  type_account = "";
		if (__accountType=="mail")	{
			type_account = '<tr>'
					+ '<td class="label">' + lg("lblEmailConfirmation")+' :</td>'
					+ '<td><input class="thinbox" name="username2" type="text" maxlength="64" style="width: 180px" />'
					+ '&nbsp;<font color="red">*</font></td>'
					+ '</tr>';
		}
		var  emailInput = "";
		if (__accountType != "mail")	{
			emailInput = '<tr>'
					+ '<td class="label">' + lg("lblEmail")+' :</td>'
					+ '<td><input class="thinbox" name="email" type="text" maxlength="64" style="width: 180px" />'
					+ '&nbsp;<font color="red">*</font></td>'
					+ '</tr>';
		}
		var l_s='\
			<div id="loginscreen">\
			<form name="form1" method="post" onsubmit="'+captcha_call+'">\
				<table>\
					<tr>\
						<td class="label">' + account_call + ' :</td>\
						<td><input class="thinbox" name="username" type="text" maxlength="64" style="width: 180px" />&nbsp;<font color="red">*</font></td>\
					</tr>\
					' + type_account + '\
					<tr>\
						<td class="label">' + lg("lblPassword") + ' :</td>\
						<td><input class="thinbox" type="password" name="pass" maxlength="16" style="width: 180px" />&nbsp;<font color="red">*</font></td>\
					</tr>\
					<tr>\
						<td class="label">' + lg("lblPasswordConfirmation")+' :</td>\
						<td><input class="thinbox" type="password" name="confpass" maxlength="16" style="width: 180px" />&nbsp;<font color="red">*</font></td>\
					</tr>\
					' + emailInput + '\
					<tr>\
						<td class="label">' + lg("lblName") + ' :</td>\
						<td><input class="thinbox" name="longname" type="text" maxlength="99" style="width: 180px" /></td>\
					</tr>';

		if (__captcha){
			l_s += '<tr>'
				+ '<td class="label">' + lg("captchaUse")+' </td>'
				+ '<td>'
				+ '<img name="imgCaptcha" src="'+__LOCALFOLDER+'tools/securimage/'+posh["securimage_show"]+'?rand='+ code +'" id="imgCaptcha" align="absmiddle" style="cursor:pointer" onclick="$p.app.captcha.updatePage(document.forms[\'form1\'])" />'
				+ '<input id="code" type="hidden" name="code" value="'+code+'" />'
				+ '<input id="txtCaptcha" type="text" name="txtCaptcha" value="" maxlength="10" size="32" />'
				+ '</td>'
				+ '</tr>';
		}
		l_s += '</table>'
			+ '<div id="specificMenu">'
			+ '</div>'
			+ '<div style="margin-left: 100px;">';
		
		// anonymous user portal
		if (__SAVE_ANONYMOUS_PORTAL){
			l_s += '<input type="checkbox" checked name="saveanonymoususerportal" />'
				+ lg("saveanonymoususerportal")+'<br />';
		}
		//+'<label><input type="checkbox" name="autoconn" />'+lg("lblAutoConnection")+'</label><br />';
		if (__useNewsletter) l_s+='<label><input type="checkbox" name="newsletter" />'+lg('lblNewsletterRequired')+'</label> '+__APPNAME+'.<br />';
		if (__useConditions) l_s+='<input type="checkbox" name="conditions" />'+lg('lblConditionsStr','&nbsp;<a href="#" onclick=\'return $p.url.openLink("conditions.html",true,true);\'>'+lg('lblConditions')+'</a>')+'.<br />';
		l_s += '<br /><input type="submit" class="submit" name="'+lg("lblOk")+'" value="'+lg("lblSave")+'" />'
			+ '</div>'
			+ '</form>'
			+ '<br />'
			+ '</div>';

		$p.app.popup.show(l_s,420,indef,$p.img("ico_menu_disk.gif",14,14,"","imgmid")+" "+lg("lblAccountCreation"),true);

		$p.app.connection.loadMenuCriterias();
	},
	/*
		$p.app.connection.subscribeConfirmation : message to confirm user subscription
	*/
	subscribeConfirmation:function()
	{
        var vars = [];
        vars["subscribe"] = true;
        $p.app.pages.save('user',vars);
		$p.app.popup.show(lg('accountToValidate')+'<br /><br /><a href="#" onclick="$p.app.popup.hide()">'+lg('lblClose')+'</a>',500,indef,$p.img("ico_menu_disk.gif",14,14,"","imgmid")+" "+lg("lblAccountCreation"),true);
	},
	/*
		$p.app.connection.loadMenuCriterias : call menu criterias
	*/
	loadMenuCriterias:function()
	{
        //'source':'html'
		$p.ajax.call(posh["xmldisplayhtmlcriteria"],
			{
				'type':'load',
				'callback':
				{
					'function':$p.app.connection.displayAllCriterias
				}
			}
		);		
	},
	/*
		$p.app.connection.displayAllCriterias : display all criterias
	*/
	displayAllCriterias:function(response,vars)
	{ 
        var i=0;
        var l_s="";
        var info="";
        var total=1;
        var nb=$p.ajax.getVal(response,"nbcriterias","int",false,0);
        l_s += '<input type="hidden" name="nbSpecificFields" value="'+nb+'" />'
			+ '<table>';
        
		while (response.getElementsByTagName("criteria")[i])
		{
			var result=response.getElementsByTagName("criteria")[i];
			var infoID=$p.ajax.getVal(result,"id","int",false,0);
			var type=$p.ajax.getVal(result,"type","str",false,"");
			var label=$p.ajax.getVal(result,"label","str",false,"");
			var options=$p.ajax.getVal(result,"options","str",false,"");
			var mandatory=$p.ajax.getVal(result,"mandatory","int",false,0);
            info = (mandatory==1)     ?     '&nbsp;<font color="red">*</font>'  
                                      :     '';                             
            //uniq id of the criteria
            l_s += '<tr>'
				+ '<input type="hidden" name="c_id'+total+'" value="'+infoID+'" />'; 
      
            switch (type)
            {
                //TEXT
                case '1':
                    l_s += '<td class="label">' + label + ' :</td><td><input type="text" class="thinbox" name="userinfo'+total+'" style="width: 180px" mandatory="'+mandatory+'" />'+info+'</td>';
                break;
                //LIST
                case '2':
                    var tabOptions=options.split(';');
                    l_s += '<td class="label">' + label+' '+info+': </td><td><select name="userinfo'+total+'" mandatory="'+mandatory+'" >';  
                    for(var j=0;j<tabOptions.length;j++)
                    {
                        l_s+='<option value="'+(j+1)+'">'+tabOptions[j]+'</option>';
                    }
                    l_s += '</select></td>';
                break;
                //CHECKBOX
                case '3':
                    l_s += '<td class="label">' + label + ' ' + info + ' : </td><td>';
                    var tabOptions=options.split(';');
                    for(var j=0;j<tabOptions.length;j++)
                    {
                        l_s += '<input type="checkbox" name="userinfo'+total+'[]" value="'+tabOptions[j]+'" mandatory="'+mandatory+'" >'+tabOptions[j] + '<br />';
                    }
					l_s += '</td>';
                break;
                //RADIO
                case '4':
                    var tabOptions=options.split(';');
                    l_s += '<td class="label">' + label + ' ' + info + '</td><td>';
                    for(var j=0;j<tabOptions.length;j++)
                    {
                        l_s += '<input type="radio" name="userinfo'+total+'" value="'+tabOptions[j]+'" mandatory="'+mandatory+'" >'+tabOptions[j]+'<br />';
                    }
					l_s += '</td>'
                break;
                //TEXTAREA
                case '5':
                    l_s += '<td class="label">' + label + '</td>';
						+ '<td><textarea style="width: 180px;" rows="5" name="userinfo'+total+'" mandatory="'+mandatory+'"></textarea>'+info + '</td>';
                break;
                //LINK
                case '6':
                    l_s += '<td class="label">' + label + ' :</td><td><input type="text" class="thinbox" name="userinfo'+total+'" style="width: 180px" mandatory="'+mandatory+'" />'+info+'</td>';
                break;
            }
            total++;
			i++;
		}
       
        $p.print("specificMenu",l_s);
	},
    link2MissingPassword: function () {
        var url = '<a href="#" class="w" id="ls_missingpass" onclick="return $p.app.connection.buildmissingPasswordForm();">'
                +lg('lblMissingPassword')
                +'</a>';
        return url;
    },
	/*
		Function: menu
        
                                        $p.app.connection.menu 
                                        
                                        display connection box
            
                                           and fadein rest of the page
            */
	menu:function()
	{
        var lblusername = __accountType=='mail'?lg('lblEmail'):lg('lblLogin');
        var l_s = $p.app.connection.displayLoginForm();
        $p.app.popup.fadein(l_s,500,indef,lg("lblConnectToYourPortal"));
	},
    /*
                Function: displayLoginForm
                
                                $p.app.connection.displayLoginForm
                                
                                display html login form, whatever it can be done with it afterwards, displaying in html page or in popup or 
            */
    displayLoginForm:function () 
    {
        var lblusername = (__accountType == "mail" ? lg("email") : lg("login"));
		
		var l_s = '\
		<div id="loginscreen">\
			<div id="displayPart">\
				<div id="msg_conn"></div>\
				<form name="conBox" method="post" onsubmit="return $p.app.connection.set(this,$p.app.pages.isPageExisting)">\
				<table cellspacing="6">\
					<tr>\
						<td class="label"><label id="ls_lbl_username" for="username">' + lblusername + ' :</label></td>\
						<td><input type="text" id="connectionname" class="thinbox" name="username" maxlength="64" style="width: 220px;" /></td>\
					</tr>\
					<tr>\
						<td></td><td></td>\
					</tr>\
					<tr>\
						<td class="label"><label id="ls_lbl_password" for="password">' + lg('lblPassword') + ' :</label></td>\
						<td><input type="password" name="password" class="thinbox" maxlength="32" style="width: 220px;" /></td>\
					</tr>\
					<tr>\
						<td></td>\
						<td align="right">\
							<a href="#" id="ls_missingpass" onclick="return $p.app.connection.buildmissingPasswordForm();return false;">'+lg('lblMissingPassword')+'</a>\
						</td>\
					</tr>\
					<tr>\
						<td colspan="2"  id="exppass"></td><td></td>\
					</tr>\
					<tr>\
						<td>&nbsp;</td><td></td>\
					</tr>\
					<tr>\
						<td></td>\
						<td>\
							<div style="float: right;"><input type="submit" class="btn" value="'+lg('lblConnect')+'" /></div>\
							<div style="padding-top: 3px"><input type="checkbox" id="ls_lbl_autoconnect" name="autoconn" />'+lg('lblAutoConnection')+'</div>\
						</td>\
					</tr>\
				</table>\
                </form>\
				</div>';
        if (__defaultmode == "anonymous")
        {
            l_s += '<br /><hr /><h2>'+lg('notAMemberYet')+' ?</h2>'
                + '<a href="#" onclick="$p.app.connection.subscribeMenu();return false;">'+lg('lblAccountCreation')+'</a><br /><br />';
        }
        l_s += '</div>';
        return l_s;
    },    
    back: function (part) {
        $p.print(part,$p.app.connection.oldvalues[part]);
        if (typeof('ls_missingpass')!='undefined') {
            $('ls_missingpass').style.display="block";
        }
        delete $p.app.connection.oldvalues[part];
    },
    buildmissingPasswordForm: function ()
	{
		// if not already in the connection popup, open it
		if ($('displayPart') == null) {		
			$p.app.connection.callPasswordMissingPopup();
			return false;
		}
			
        if ($('ls_missingpass') != null) {
            $('ls_missingpass').style.display="none";
        }
        var l_s = '\
        <div id="missingScreen">\
			<form name="help" onsubmit="return $p.app.connection.askForANewPassword(this);">\
			<h2 id="help_mis_pass"></h2>\
			<p id="lbl_set_NewPassword_Missing"></p>\
			<p align="center"><label id="help_email_conn"></label>: <input type="text" name="emaillost" size="30" maxlength="64" value="" />\
            <input type="submit" class="btn"  id="btn_conn" value="OK" />\
			</p>\
			</form>\
			<br />\
			<script type="text/javascript">\
				document.forms["help"].emaillost.focus();\
			</script>\
		</div>\
		<div>\
        <a href="#" id="help_screen_conn" onclick="return $p.app.connection.back(\'displayPart\');">back to the login screen</a>\
		</div>\
		';
    
        $p.app.connection.oldvalues['displayPart'] = $('displayPart').innerHTML;
        //onclick="return $p.app.connection.askForANewPassword();"
        $p.print('displayPart',l_s);
        
        $('btn_conn').value=lg('lblBtnSend');
        $p.print('msg_conn','');
        $p.print('help_mis_pass',lg('lblMissingPassword'));
        $p.print('help_screen_conn','&laquo; ' + lg('backScreenConn'));
        $p.print('lbl_set_NewPassword_Missing',lg('lblsetNewPasswordMissing'));
        $p.print('help_email_conn',lg('email'));
        
        return false;
        
    },
    response_askPasswd: function (response,vars) {
        
        if (response && response.getElementsByTagName('email').length > 0) {
       
            part = vars['part'];
            $p.app.connection.back(part);
            $p.print('msg_conn','<p class="warningok">'+lg('msgRenewPassTxt')+'</p>');
            $('displayPart').style.height='200px';
                
        } else {
            $p.print('msg_conn','<p class="warning">'+lg('lblUnknownUser')+'</p>');             
        }   
        
        
        return false;
    },
    askForANewPassword:function (v_form) {
       // $p.print('msg_conn','<p class="warning">Veuillez controler votre messagerie.<br>Vous allez recevoir un message vous permettant de recr&eacute;er un noueau mot de passe.</p>');
        //$p.app.connection.responseaskPasswd('displayPart');
        var username = $p.string.replacePlus(v_form.emaillost.value);
        $p.ajax.call(posh["scr_sendmd5"],
				{
					'type':'load',
					'variables':'username='+username,
					'alarm':false,
					'forceExecution':true,
                    'method':'POST',
					'callback':
					{
						'function':$p.app.connection.response_askPasswd,
                        'variables':
                        {
                            'part':'displayPart'
                        }            
					}
                   
				}
			);
        //$p.app.connection.backandWait('displayPart');
        return false;   
    },
	module_ff:function()
	{
		document.location.href = "../portal/moduleff.php";
	},
	callPasswordMissingPopup: function()
	{
		$p.app.popup.openUrl(posh["password_missing"],400,300,lg('lblMissingPassword'));
	}
}
//******************** CAPTCHA************************************************************************************************
$p.app.captcha={
	//$p.app.captcha.updatePage
	//for change the captcha image
	updatePage:function(form)
	{
		$p.ajax.call(posh["scr_captcha_erase"],
			{
				'type':'execute',
				'variables':"code="+form.code.value,
				'forceExecution':true
			}
		);
	  //generate a new code
	  var code= $p.app.captcha.generate_code();
	  //Change the image
	  form.imgCaptcha.src = __LOCALFOLDER+'tools/securimage/'+posh["securimage_show"]+'?rand='+code;
	  //change the idden code
	  form.code.value=code;
	  
	},
	//$p.app.captcha.generate_code
	//generate the code
	generate_code:function()
	{
		var code = "";
		var charset=["A","B","C","D","E","F","G","H","K","L","M","N","P","R","S","T","U","V","W","Y","Z","2","3","4","5","6","7","8","9"];
		
		//length of charset:
		var cslen = 29;
		
		var i;
		for(i=1 ; i <= 5; i++) {
			code +=  charset[Math.floor(Math.random()*(cslen-1))] ;
		}
		return code;
	},
	//$p.app.captcha.verif_code
	verif_code:function(form)
	{
		var code_gen=form.code.value;
		var code_ent=form.txtCaptcha.value;
		$p.ajax.call(posh["xmlcaptcha"]+'?code_gen='+code_gen+'&code_ent='+code_ent,
				{
					'type':'load',
					'callback':
					{
						'function':$p.app.captcha.get_captcha_result,
						'variables':{
									'form':form
									}
					}
					
				}
			);
		return false;
	},
	//$p.app.captcha.get_captcha_result
	get_captcha_result:function(response,vars)
	{
		var test=$p.ajax.getVal(response,"resulta","int",false,-1);
		if(test==1){
			$p.app.connection.subscribe(vars['form'],$p.app.connection.subscribeConfirmation);
		}
		else{
			$p.app.alert.show(lg("BadCaptcha"));
		}
		$p.app.captcha.updatePage(vars['form']);
	}
}
//******************** BANNERS ************************************************************************************************

/*
    Class: Manage the information in the portal banner
            void
*/
$p.app.banner={};

/*
    Class: $p.app.banner.option
*/
$p.app.banner.option={

	shown: true,
	/*
		$p.app.banner.option.show : display tab options banner
	*/
	show:function()
	{
		//no access to options if page locked
		if (tab[$p.app.tabs.sel].locked) return false;
		// if ($p.app.banner.option.shown) {
			// $p.app.banner.option.hide();
		// }
		if (tab[$p.app.tabs.sel].editable 
            && __showTabOptions
            && tab[$p.app.tabs.sel].controls == 'Y'
			&& !($p.app.user.id == 0 && __ANONYMOUS_PAGES_ARE_BLOCKED)
		)    {
			//display the options in the banner
			var l_s='<div class="advise">';
			if (__menuDefaultStatus != 4 && $p.app.env!="admin")
			{
				l_s += (tab[$p.app.tabs.sel].type==1?'<a class="blackbtn" href="#" onclick=\'$p.app.menu.open("pwidget",true)\'><span>'+lg('lblAddContent')+'</span></a>':'')
					+ '<a class="blackbtn" href="#" onclick=\'$p.app.menu.config.open()\'><span>'+lg('options')+'</span></a>';
			}

			for (var i=0;i<__option.length;i++)
			{
				if ( (__option[i]["anonymous"]&&$p.app.user.id<=0)||(__option[i]["connected"]&&$p.app.user.id>0) && $p.app.user.type!='N')
					l_s+="<a class='blackbtn' href='#' id='"+__option[i]["id"]+"' onclick='return "+__option[i]["fct"]+"'><span>"+$p.img(__option[i]["img"],16,16,__option[i]["comment"],"imgmid")+" "+__option[i]["label"]+"</span></a>";
			}

			if (__tabsCanBeRenamed && tab[$p.app.tabs.sel].controls == 'Y')
			{
				l_s+='<a class="blackbtn" href="#" onclick="return $p.app.tabs.edit('+$p.app.tabs.sel+');"><span>'+lg('renameThisPage')+'</span></a>';
			}
            
			if ($p.app.user.id>=0 && tab[$p.app.tabs.sel].removable != 0) {
				l_s+='<a class="blackbtn" href="#" onclick="return $p.app.pages.suppress();"><span>'+lg('lblSuppress')+'</span></a>';
            }
            
            //redirection open HTML tab URL in new browser page
            if (tab[$p.app.tabs.sel].type==2) {
                l_s+='<a class="blackbtn" href="#" onclick="window.open(tab[$p.app.tabs.sel].param);return false;"><span>'+$p.img('ico_popup.gif',14,14,'','imgmid')+' '+lg('openSite')+'</span></a>';
            }
			
			l_s+='</div>';

			$p.print("advise",l_s);
			$p.show("advise","inline");
			$p.app.banner.option.shown=true;
			$p.app.banner.info.shown=false;
		}
		return false;
	},
	/*
		$p.app.banner.option.hide : hide tab options banner
	*/
	hide:function()
	{
		$p.show("advise","none");
		$p.app.banner.info.load();
		$p.app.banner.option.shown = false;
	}
}

/*
    Class: $p.app.banner.info
*/
$p.app.banner.info={
	shown:true,
	requested:'Y',
	loaded:false,
	item:[],
	itemid:0,
	currentMessage:'',
	init: function()
	{
		if ($('adminmessage') == null)
		{
			var l_obj = new Element('div',
				{
					'id':'adminmessage'
				}
			);
			document.body.appendChild(l_obj);

			navPrint('adminmessage','<div id="adminmessage_content"></div>');
		}
		else
		{
			navShow('adminmessage','block');
		}
	},
	/*
		$p.app.banner.info.load : load information for the information banner
	*/
	load: function()
	{
        if ($p.app.user.id <= 0)
            return;

		if (__bartype == 1 && __bartexthtml != "" && $p.app.banner.info.shown != false)
		{
			if ($p.cookie.get('hidemessage') != __bartexthtml)
			{
				var l_s = __bartexthtml
					+ " <a href='#' style='float: right;margin-right: 15px;' onclick='return $p.app.banner.info.hide()'>"+$p.img("ico_close.gif",12,11)+" " + lg('lblClose') + "</a>";
				
				$p.app.banner.info.currentMessage = __bartexthtml;

				$p.app.banner.info.init();
				$p.print('adminmessage_content',l_s);
				$p.app.banner.info.show();
			}
		}
		//if ($p.app.banner.info.requested=="Y"&&__rssinfo!=""){
		if (__bartype == 2 && __rssinfo != "")
		{
            $p.app.banner.info.init();
			$p.app.banner.info.show();
			$p.ajax.call(__rssinfo,
				{
					'type':'load',
					'callback':
					{
						'function':$p.app.banner.info.displayRss
					}
 				}
			);
            
			$p.app.banner.info.loaded=true;
		}
	},
	/*
		$p.app.banner.info.displayRSS : display RSS information in banner
	*/
	displayRss: function(response,vars)
	{
		var i = 0, l_s = '';
		while (response.getElementsByTagName("item")[i])
		{
			var result = response.getElementsByTagName("item")[i];
			if ($p.ajax.getVal(result,"link","str",false,"") == "")
            {
				l_s = $p.ajax.getVal(result,"title","str",false,"...");
            }
			else
            {
				l_s = "<a target='_blank' href='"+$p.ajax.getVal(result,"link","str",false,"#")+"'>"+$p.ajax.getVal(result,"title","str",false,"...")+"</a>";
			}
            l_s += " <a href='#' onclick='return $p.app.banner.info.hide()'>"+$p.img("ico_close.gif",12,11)+"</a>";

            $p.app.banner.info.item.push(l_s);
			i++;
		}
		$p.app.banner.info.roll();
	},
	/*
		$p.app.banner.info.roll : roll over RSS articles
	*/
	roll: function()
	{
		if ($p.app.banner.info.item.length > 0 && $p.app.banner.info.shown)
		{
			var l_s = "";
			if ($p.app.banner.info.itemid==$p.app.banner.info.item.length)
                $p.app.banner.info.itemid = 0;

			l_s += $p.app.banner.info.item[$p.app.banner.info.itemid];
			$p.app.banner.info.itemid++;
            $p.print('adminmessage_content',l_s);
			//$p.print('message',l_s);
		}
	},
	/*
		$p.app.banner.info.show : display information banner
	*/
	show:function()
	{
		$p.show('adminmessage',"block");
		$p.app.banner.info.shown=true;
	},
	/*
		$p.app.banner.info.hide : hide information banner
	*/
	hide:function()
	{
		$p.show('adminmessage',"none");
		$p.app.banner.info.shown=false;
		//use cookies to avoid the same message appear again
		$p.cookie.write('hidemessage=' + $p.app.banner.info.currentMessage);
	}
}

//******************** POPUP MANAGEMENT **********************************************************************************************************************
/*
    Class: $p.app.popup
    
        function to manage popup
        
*/
$p.app.popup={
	isOpened: false,
	tabs:[],
	seltab:0,
	/*
		Function: $p.app.popup.build 
        
                build the popup object
               
               Parameters:
               
                    v_width - width of popup
                    v_height - height of widget 
	*/
	build:function(v_width,v_height)
	{
		if ($('popup')==null)
		{
			var l_popup=new Element('div', {'id':'popup'} );
			document.body.appendChild(l_popup);
		}
		else
			var l_popup=$('popup');

		if (v_width==indef) v_width=500;
		if (v_height==indef) v_height=200;

		l_popup.style.width = v_width+"px";
		l_popup.style.height = v_height+"px";
		l_popup.style.marginLeft = "-"+(v_width/2)+"px";
		l_popup.style.top = ($p.navigator.getScrollY()+30)+"px";

        var l_s = $p.html.roundBox(   '<div id="popuptitle">'
                                    + '</div>'
									+ '<div id="useraccountlink" class="useraccountlink">'
										+ '<a href="#" onclick="$p.notebook.myprofile();">'+lg('myaccountparam')+'</a>'
									+ '</div>'
									+ '<div id="popupmenu" class="popupmenu"></div>'
									+ '<div id="boxcontent" style="width: 100%;margin-top:5px;">'
                                    + '<div id="popupcontent">'
                                    + '</div>'
                                    + '</div>'
                                    ,'#fff',
                                    v_width+'px'
        );
        l_popup.set('html',l_s);
           
	},
	/*
		Function: $p.app.popup.createTabs 
        
                build the popup oabs
               
               Parameters:
               
                    v_tab - tabs datas
                    seltab - select tab id
	*/
	createTabs: function(v_tab,seltab)
	{
		var l_s = '';
		
		l_s+='<div style="float: left;">'
		+'<table cellspacing="0" cellpadding="0"><tbody><tr><td style="font-size: 1px; line-height: 0px;">'
		+'<img height="1" width="100%" src="../images/s.gif" alt="" class="">'
		+'</td></tr><tr><td><table cellspacing="0" cellpadding="0"><tbody><tr><td><table cellspacing="0" cellpadding="0" border="0"><tbody><tr>';
		for(var i=0;i<v_tab.length;i++) {
			if( v_tab[i].id == seltab  ) {
				$p.app.popup.seltab = i;
				l_s+='<td width="1" valign="top" id="tab'+i+'">'
				+'<table cellspacing="0" cellpadding="0" class="taba"><tbody><tr>'
				+'<td class="tabal tabpp" id="tab'+i+'_h">'
				+'	<a href="#" onclick="'+v_tab[i].fct+'">&nbsp;'+v_tab[i].label+'</a>'
				+'</td><td class="tabar"></td><td class="intertaba">'
				+'	<div width="1" height="1" class="." style="width: 1px; height: 1px; display: inline; padding: 0pt 1px 1px 0pt; margin: 0px; font-size: 0px;"></div>'
				+'</td></tr></tbody></table></td>';
			} else {
				l_s+='<td width="1" valign="top" id="tab'+i+'">'
				+'<table cellspacing="0" cellpadding="0" class="tab"><tbody><tr>'
				+'<td class="tabl tabpp" id="tab'+i+'_h">'
				+'	<a href="#" id="tab'+i+'_u" onclick="'+v_tab[i].fct+'">	 '+v_tab[i].label+'</a></td><td class="tabr"><table cellspacing="0" cellpadding="0" border="0"><tbody></tbody></table>'
				+'</td>'
				+'<td class="intertab">'
				+'	<div width="1" height="1" class="." style="width: 1px; height: 1px; display: inline; padding: 0pt 1px 1px 0pt; margin: 0px; font-size: 0px;"></div>'
				+'</td></tr></tbody></table></td>';
			}
		}
		l_s+='</tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div>';
		
		return l_s;
	},
	/*
		Function: setTitle
                    set the popup title
		
            Parameters:

			v_title - popup title
			v_closeBtn - define if close button is shown or not
			v_closeFct - function called on width close
	*/
	setTitle: function(v_title,v_closeBtn,v_closeFct)
	{
		if (v_closeBtn == indef) v_closeBtn = true;
        if (v_closeFct == indef) v_closeFct = '';
        
		if (v_title != indef)
		{
            var l_s = '<div class="popuphdr">'
                + '<div style="float: right">'
                + '<span href="#" class="popupclosebtn" onclick="$p.app.popup.hide();'+v_closeFct+';return false;">'
                + img('ico_close.gif',12,11,'','imgmid')
                + ' <u>'+lg('lblClose')+'</u>'
                + '</span> &nbsp'
                + '</div>'
                + '<div style="margin-left: 15px;" id="popuptitle'+$p.app.user.id+'_breadcrumb"> &nbsp;'+v_title+'</div>'
                + '</div>';
            $p.print('popuptitle',l_s);
		}
	},
	/*
		Function :$p.app.popup.setContent
        
                    set popup content
            
                Parameters: 
                
                    v_content - (string) popup content
        */
	setContent:function(v_content)
	{
		($('popupcontent')).set('html',v_content);
	},
	/*
		Function: $p.app.popup.show 
                        Display popup in the middle of the page
		
              Parameters:

			v_content (string) - HTML content of the popup
			v_width (integer) - popup width
			v_height (integer) - popup height
			v_title (string) - title displayed in the popup header
			v_closeBtn (boolean) - define if close button is displayed or not
			v_closeFct (string) - function called when popup is closed
			v_opacity (float) - opacity percentage of the background
	*/
	show:function(v_content,v_width,v_height,v_title,v_closeBtn,v_closeFct,v_opacity)
	{
		if ($p.app.popup.isOpened)
		{
			$p.app.popup.hide();
		}
		$p.app.cache.shadow(v_opacity);
		$p.app.popup.build(v_width,v_height);
		$p.app.popup.setTitle(v_title,v_closeBtn,v_closeFct);
		$p.app.popup.setContent(v_content);
		$p.app.popup.isOpened = true;
		
        //resize the page if the popup is larger than the page (prevent from blank space)
        $p.app.cache.resize();
	},
	/*
		Function: $p.app.popup.fadein
        
                    same that show but with fadein effect
                    
               Parameters:

                    v_url   - url to display
                    v_width - width of popup
                    v_heightv_title - tuitle of popup
                    v_closeBtn - close button,
                    v_closeFct  - function to call when close popup
                    v_scrolling - scrolling or not (yes or no) 
 
	*/
	fadein:function(v_content,v_width,v_height,v_title,v_closeBtn,v_openFct,v_closeFct)
	{
		$p.app.cache.init();
		var l_openFct=["$p.app.popup.show('"+$p.string.removeCot(v_content,'simple')+"',"+v_width+","+v_height+",'"+v_title+"',"+v_closeBtn+","+v_closeFct+")"];
		if (v_openFct!=indef) l_openFct.push(v_openFct);
		$p.effect.fadein($('cache'),l_openFct,0.7);
		$p.app.popup.isOpened = true;
	},
	/*
		Function :$p.app.popup.openUrl
        
                    open an url in an fadein popup
                    
               Parameters:

                    v_url   - url to display
                    v_width - width of popup
                    v_heightv_title - tuitle of popup
                    v_closeBtn - close button,
                    v_closeFct  - function to call when close popup
                    v_scrolling - scrolling or not (yes or no)
	*/
	openUrl:function(v_url,v_width,v_height,v_title,v_closeBtn,v_closeFct,v_scrolling)
	{
        var l_scrolling = (v_scrolling == indef ? 'auto' : (v_scrolling ? 'yes' : 'no'));
		$p.app.popup.fadein('<iframe src="'+v_url+'" width="'+(v_width-20)+'" height="'+v_height+'" '
                            +'frameborder="no" marginwidth="0" marginheight="0" '
                            +'scrolling="' + l_scrolling + '"></iframe>',
                            v_width,
                            v_height,
                            v_title,
                            v_closeBtn,
                            v_closeFct);
	},
	/*
		Function: $p.app.popup.hide
                        close popup created with popup function 
               
                        removechild popup
	*/
	hide:function()
	{
		if ($('popup') != null)
		{
			$p.show('popupmenu','none');
			document.body.removeChild($('popup'));
			$p.app.cache.hideShadow();
            try {
                window.focus(this.window);
            } catch(error) {
                var inputEl = document.getElementsByTagName("input");
                inputEl[0].focus();
            }               
		}
		$p.app.popup.isOpened = false;
	},
    /*
            Function: $p.app.popup.hideRelogin
            
                    hide popup
    */
	hideRelogin:function()
	{
		if (parent.$('popup') != null)
		{
			parent.$p.app.cache.obj.setStyle("display","none");
			//$p.app.cache.obj.setStyle("backgroundColor","#ffffff");
			parent.$p.app.cache.obj.setOpacity("0");
			parent.$p.app.cache.obj.setStyle("filter","alpha(opacity=0)");
			//show all flash objects
			parent.$p.navigator.showObjects();
			parent.document.body.removeChild(parent.$('popup'));
		}
	},
    /*
            Function: $p.app.popup.undisplay
            
                    undisplay  popup
    */
	undisplay:function ()
	{
		$('popup').style.display="none";
		$p.app.cache.hideShadow();
	},
    /*
            function: $p.app.popup.redisplay

                    display popup
        */
	redisplay: function ()
	{
		$p.app.cache.shadow();
		$('popup').style.display="block";    
	}
}

/*	
	Function: tooltip 
    
                generate tool tip link
	
        Parameters:

			 v_msg - message displayed in tooltip on mouse over
	
	Returns:
			 tooltip HTML code
*/

function tooltip(v_msg,nolg)
{
    if (typeof(nolg)!="undefined") 
    	return "<a href='#' onclick='return false' onmouseover=\"parent.mouseBox('"+v_msg+"',event)\" onmouseout=\"parent.mouseBox('')\">"+$p.img("ico_help_s.gif",12,12,"","imgmid")+"</a>";
    else
        return "<a href='#' onclick='return false' onmouseover=\"mouseBox(lg('"+v_msg+"'),event)\" onmouseout=\"mouseBox('')\">"+$p.img("ico_help_s.gif",12,12,"","imgmid")+"</a>";
}
/*
	Function: mousebox 
                Display text in tooltip box, next to mouse pointer
	
        Parameters:

		v_s (string) - text to display
		e(event) - event object
*/
function mouseBox(v_s,e)
{
	if (__displayrssdesc)
	{
		if (v_s=="")
		{
			$p.show("mousebox","none");
		}
		else
		{
			if ($("mousebox")==null)
			{	
				var l_div = new Element('div', { 'id': "mousebox" } );
				document.body.appendChild(l_div);	
			} else l_div=$("mousebox");
			$p.print("mousebox",v_s);

			if (e==indef && window.event) e=window.event;
			//if(typeof e.layerX=="undefined")e.layerX=e.offsetX;
			//if(typeof e.layerY=="undefined")e.layerY=e.offsetY;
			//var e=window.event;
			var posLeft=($p.navigator.IE?(e.clientX + document.documentElement.scrollLeft):e.pageX+10);
			var posTop=($p.navigator.IE?(e.clientY + document.documentElement.scrollTop):e.pageY+10);

			l_div.setStyle("left",posLeft+"px");
			l_div.setStyle("top",posTop+"px");

			$p.show("mousebox","block");
			var l_boxWidth=l_div.offsetWidth;
			var l_boxHeight=l_div.offsetHeight;
			// if a part of the box is outside the screen
			var l_outScreen=0;
			if (posLeft > (Window.getWidth()+document.documentElement.scrollLeft-l_boxWidth)) l_outScreen++;
			if (posTop > (Window.getHeight() + document.documentElement.scrollTop-l_boxHeight)) l_outScreen+=2;
			if (l_outScreen==1){l_div.setStyle("left",(Window.getWidth()+document.documentElement.scrollLeft-l_boxWidth-20)+"px");}
			if (l_outScreen==2){l_div.setStyle("top",(Window.getHeight()+document.documentElement.scrollTop-l_boxHeight-20)+"px");}
			if (l_outScreen==3)
			{
				l_div.setStyle("left",(Window.getWidth()+document.documentElement.scrollLeft-l_boxWidth-20)+"px");
				l_div.setStyle("top",(posTop-l_boxHeight-15)+"px");
			}
		}
	}
}


/*
	validKeys : Valid the search area input value
	Parameters:

			 form containing searchtxt input

function validKeys(v_form)
{
	var l_value=v_form.searchtxt.value;
	if (l_value.substr(0,3)=='ex:' || l_value=='')
	{
		$p.app.alert.show(lg("msgKWInput"));return false;
	}
	else
	{
		var i=0,l_pos=0,l_newpos;
		while (l_value.indexOf(',',l_pos)!=-1)
		{
			l_newpos=l_value.indexOf(',',l_pos);
			if (l_value.substring(l_pos,l_newpos)!='' && l_value.substring(l_pos,l_newpos)!=' '){i++;}
			l_pos=l_newpos+1;
		}
		if (l_value.substr(l_pos)!='' && l_value.substr(l_pos)!=' '){i++;}
		if (i<5){
			$p.app.alert.show(lg("msgKWError"));return false;
		}
		else
		{
			v_form.searchtxt.value=$p.string.formatForSearch(l_value);
			return true;
		}
	}
}
	Display help messages

function help(v_id)
{
	var msg;
	switch(v_id)
	{
		case 1:msg=lg("msgHelp1");break;
	}
	$p.app.alert.show(msg);
	return false;
}
// open help box - Not used anymore
function openHelp()
{
	$p.url.openLink("firstusage.html",true,true);
	return false;
}
function errorMsg(v_id)
{
	return lg("msgError"+v_id);
}
*/


/*
	Function: openPage 
                open a personalizable Portaneo page
	
        Parameters:

			 page id
*/
function openPage(v_p)
{
	if (v_p)
	{
		$p.app.pages.setCurrent(v_p);
		$p.url.openLink(posh["mypage"]+"?s="+v_p);
	}
}


//******************** ALERTS MANAGEMENT **********************************************************************************************************************
/*
    Class: $p.app.alert
        Alerts management
*/
$p.app.alert={
	shown:false,
	timer:0,
	/*
	** $p.app.alert.show : Display message
	** Parameters:

			
	** - v_msg - message to display
	** - v_type - message type 1:information 2:help 3:alert/error
	*/
	show:function(v_msg,v_type)
	{
		var l_img;
		switch (v_type)
		{
			case indef:
			case 1:
				l_img="ico_info.gif";
				break;
			case 2:
				l_img="ico_help2.gif";
				break;
			case 3:
				l_img="ico_alert.gif";
				break;
		}
		if ($("errordiv")==null)
		{
			var l_obj=null;
			l_obj = new Element('div', { "id": "errordiv", "class": "errordiv" } );	
			document.body.appendChild(l_obj);
		}
		else
		{
			l_obj=$("errordiv");
		}
		l_obj.setStyle("top",(document.all)?document.documentElement.scrollTop+"px":window.pageYOffset+"px");
		var l_msg = "<img src='../images/"+l_img+"' align='absmiddle' /> "+v_msg;
		if ($p.app.alert.shown)
		{
			$p.print("errormsg",l_msg+"<br />","top");
		}
		else
		{
			$('errordiv').set('html',"<table width='100%'><tr><td align='center' id='errormsg' onclick='return $p.app.alert.hide()'>"+l_msg+"</td><td width='13' align='center'><a href='#' onclick='return $p.app.alert.hide()'>"+$p.img("ico_close.gif",12,11)+"</a></td></tr></table>");
		}
		//avoid that the message remain in the middle of the page
		window.onscroll = $p.app.alert.hide;
		$p.effect.fadein(l_obj);
		$p.app.alert.shown=true;
		//hide after x seconds
		if ($p.app.alert.timer == 0)
		{
			$p.app.alert.timer=setTimeout("$p.app.alert.hide()",7000);
		}
		else
		{
			clearTimer($p.app.alert.timer);
			$p.app.alert.timer=setTimeout("$p.app.alert.hide()",7000);
		}
		return false;
	},
	hide:function()
	{
		if ($p.app.alert.shown == true)
		{
			$p.app.alert.shown = false;
			$p.effect.fadeout($("errordiv"));
			window.onscroll = null;
			$p.app.alert.timer = 0;
		}
		return false;
	}
}

//******************** TIMER MANAGEMENT **********************************************************************************************************************
/*
    Class: $p.app.counter
        Timer management
*/
$p.app.counter={
	timer:0,
	step:0,
	activityStep:0,
	/*
		Function: $p.app.counter.reset
        
                                reset application counter
                                
                                Load from
                                - <$p.app.init>
                                - <$p.app.startLoading>
                                - <$p.app.widgets.saveChanges>
                                
		Parameters:

			 v_step - starting step (10seconds = 1 step)
             
             See also:
                <$p.app.counter.action>,<$p.app.init>,<$p.app.startLoading>,<$p.app.widgets.saveChanges>
	*/
	reset:function(v_step)
	{
		if ($p.app.counter.timer) $p.app.counter.stop();
		$p.app.counter.step=v_step?v_step:0;
		$p.app.counter.timer=setInterval("$p.app.counter.action()",10000);
	},
	/*
		Function: $p.app.counter.action
        
                                manage actions triggers on defined step
               
               See also:
                    <$p.app.counter.action>
	*/
	action: function()
	{
		if ($p.app.counter.step == 1) $p.app.checkLoading(false);
		// other action are launched when user is connected
		if ($p.app.user.id > 0) {
//			if ($p.app.counter.step==1&&__useSharing) $p.msg.getNb();
			//if security applied on portal, lock after inactivity
			if ($p.app.counter.activityStep == 90
                && tab[$p.app.tabs.sel].lock != 0) { 
                    $p.app.pages.lock();
            }

			//refresh modules that need to be refreshed periodically (RSS, mails, ...)
			if (__rssrefreshdelay != 0
				&& $p.app.counter.step%__rssrefreshdelay == (__rssrefreshdelay-1)) {
				$p.app.widgets.rss.refreshAll();
			}
			//check connection to DB
			$p.app.inactivityTime++;
			//relogin
            /*$p.ajax.call(posh["scr_check_connexion"],{'type':'load','callback':{'function':$p.network.checkConnexion}}); */
			if (__useChat && $p.app.user.status != 'x')
			{
				if ($p.app.connection.active)
				{
					//delay activity check if no connection
					$p.chat.checkActivity();
				}
				else
				{
					if ($p.app.counter.step%6==5) $p.chat.checkActivity();
				}
			}
			else
			{
				if ($p.app.counter.step%60==59) $p.app.connection.test();
			}
		}
		if ($p.app.counter.step%2==1 && __bartype==2) $p.app.banner.info.roll();
		$p.app.counter.step++;
		$p.app.counter.activityStep++;
	},
	/*
		Function: $p.app.counter.stop
                                stop counter
	*/
	stop:function()
	{
		clearTimer($p.app.counter.timer);
	}
}

//******************** MULTIMEDIA READER **********************************************************************************************************************
/*
    Class: $p.app.reader
        Multimedia reader
*/
$p.app.reader={
	/*
		Function: $p.app.reader.open
                                open multimedia files reader
		
                     Parameters:

			v_src - url of the multimedia file
			v_type - type of the file (a=audio, v=video)
	*/
	open:function(v_src,v_type)
	{
		$p.plugin.hook.launch('app.reader.open.start');

		// Open media inside Portaneo
		var l_s=''
			+'<table width="100%" cellpadding="0" cellspacing="0">'
			+'<tr>'
			+'<td class="advise" align="center">'
			+'<table cellpadding="3" cellspacing="0">'
			+'<tr>'
			+'<td>';
		//if ($('audio').innerHTML!='')
			//$('audio').empty();
		
		if (v_type=="a") 
		{
			l_s+="		<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width='400' height='18' id='mp3player' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'><param name='movie' value='"+pfolder+"../tools/mp3player.swf'><param name='flashvars' value='file="+$p.string.esc(v_src)+"&autostart=true'><param name='wmode' value='transparent' /><embed src='"+pfolder+"../tools/mp3player.swf' wmode='transparent' width='400' height='18' flashvars='file="+$p.string.esc(v_src)+"&autostart=true' name='mp3player' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
		}
		if (v_type=="v") l_s+="		<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width='320' height='250' codebase='http://www.apple.com/qtactivex/qtplugin.cab'><param name='controller' value='TRUE'><param name='type' value='video/quicktime'><param name='autoplay' value='true'><param name='target' value='myself'><param name='src' value='"+v_src+"'><param name='pluginspage' value='http://www.apple.com/quicktime/download/'><embed controller='TRUE' target='myself'  width='320' height='250' src='"+v_src+"' qtsrc='"+v_src+"' type='video/quicktime' bgcolor='black' border='0' loop='false' autoplay='true' pluginspage='http://www.apple.com/quicktime/download/'></embed></object><br /><br />"+lg("lblVideoWarning");
		l_s+='</td>'
			+'<td valign="top">'
			+'<a href="#" onclick="$p.app.reader.hide();return false;">'
			+$p.img("ico_close.gif",12,11)
			+'</a>'
			+'</td>'
			+'</tr>'
			+'</table>'
			+'</td>'
			+'</tr>'
			+'</table>';
		$p.show("audio","block");
		$p.print("audio",l_s);

		$p.plugin.hook.launch('app.reader.open.end');
	},
	/*
		Function: $p.app.reader.hide
                            close multimedia files reader
	*/
	hide:function()
	{
		$p.app.pages.clean($("audio"));$p.show("audio","none");
	}
}

// initialize the hidding window (for drag action)
/*
    Class: $p.app.cache
        initialize the hidding window (for drag action)
*/
$p.app.cache={
	isInit:false,
	obj:indef,
	/*
		Function: $p.app.cache.init
                            init the page cache window (for menu move)
	*/
	init: function()
	{
		if ($p.app.cache.obj == indef)
			$p.app.cache.obj = $('cache');

        $p.app.cache.resize();

		//$p.app.cache.obj.setStyle("backgroundColor","#000000");
		$p.app.cache.obj.className = 'cachedark';
	},
    resize: function()
    {
		var l_size = window.getScrollSize();

		$p.app.cache.obj.setStyle("width",l_size.x + "px");

		$p.app.cache.obj.setStyle("height",l_size.y + "px");
    },
	/*
		Function: $p.app.cache.show
                                display the cache window
                      
                      Parameters:
                      
                                v_status - none or block
	*/
	show:function(v_status)
	{
		$p.app.cache.init();

		//hide popup if opened
		$p.app.cache.hideShadow();
		navShow('popup','none');

		$p.app.cache.obj.setStyle("display",v_status);
	},
	/*
		Function: $p.app.cache.shadow
                                Display the grey cache window (used for popup display)
	*/
	shadow:function(v_opacity)
	{
		if (v_opacity == indef) v_opacity = 0.7;
		//hide all flash objects
		$p.navigator.hideObjects();

		$p.app.cache.init();

		$p.app.cache.obj.setStyle('display','block');
		$p.app.cache.obj.setOpacity('' + v_opacity);
		$p.app.cache.obj.setStyle('filter','alpha(opacity=' + (v_opacity*100) + ')');
	},
	/*
		Function: $p.app.cache.hideShadow
                                hide the grey cache window
	*/
	hideShadow:function()
	{
		$p.app.cache.obj.setStyle("display","none");
		//$p.app.cache.obj.setStyle("backgroundColor","#ffffff");
		$p.app.cache.obj.setOpacity("0");
		$p.app.cache.obj.setStyle("filter","alpha(opacity=0)");
		//show all flash objects
		$p.navigator.showObjects();
	}
}
/*
    Class: $p.app.help
*/
$p.app.help={
	// /*  
	// Function: $p.app.help.enableIntro
                    // Enable the introduction message
	// */
	// enableIntro: function()
	// {
		// $p.cookie.write('intro'+$p.app.user.id+'=1');
		// $p.app.help.loadIntro();
	// },
	// /*  
	// Function: $p.app.help.loadIntro
    
                     // Load the introduction message
                     // no parameters
                     
                     // get message in l10n/<lang>/intromessage.html
                     
	// */
	// loadIntro: function()
	// {
        // $p.app.help.displayMessage('intromessage','help',lg('welcome'),lg('welcomemsg'));
		// var l_showIntro = $p.cookie.get('intro'+$p.app.user.id);
		// if (l_showIntro == '' || l_showIntro == 1)
		// {
			// $p.ajax.call(__LOCALFOLDER+'l10n/'+__lang+'/intromessage.html',
				// {
					// 'type':'load',
					// 'source':'html',
					// 'callback':
					// {
						// 'function':$p.app.help.displayIntro
					// }
				// }
			// );
		// }
	// },
	/*  
	Function: $p.app.help.displayIntro
                        Display the introduction message
	
    Parameters:
		 response (string) : html response
	*/
	// displayIntro:function(response)
	// {
		// var l_s = $p.html.roundBox('<div style="padding: 8px;color: #fff;">'
            // + response
			// + '<div style="text-align:right;">'
			// + '<input type="checkbox" id="donotdisplayintro" />'+lg('doNotDisplayThisMessage')+'&nbsp;'
			// + '<input type="button" value="'+lg('lblClose')+'" onclick="$p.app.help.hideIntro()"><br />'
			// + '</div>'
            // + '</div>',
            // '#0E679A',
            // '100%');

		// $p.print('intromessage',l_s);
        // $p.show($('intromessage'),"block");
	// },
	// /*  
	// Function: $p.app.help.disableIntro : Disable the introduction message
	// Parameters:
		// None
	// output : 
		// None
	// */
	// disableIntro:function()
	// {
		// $p.cookie.write('intro'+$p.app.user.id+'=0');
	// },
	// /*  
	// Function: $p.app.help.hideIntro : Hide the introduction message
	// Parameters:
		// None
	// output : 
		// None
	// */
	// hideIntro:function()
	// {
		// if ($('donotdisplayintro').checked) $p.app.help.disableIntro();
		// $p.show('intromessage','none');
        // ($('indicator')!=null)?$p.navigator.hideIndicator():'';
	// },
    build: function(v_content,v_color,v_width)
    {
        return v_content;
    },
    /*  
        Function: $p.app.help.displayMessage : display a message
        Parameters:
            v_container : message container
            v_type : type of the message ('help', 'warning', ...)
            v_title : title of the message
            v_message : message
        output : 
            None
	*/
    displayMessage: function(v_container, v_type, v_title, v_message)
    {
        if (v_type == indef) v_type = 'help';

        $p.print(v_container, '<table cellpadding="8" cellspacing="0">\
			<tr>\
				<td valign="top">\
				<img src="../images/help_'+v_type+'.gif" />\
				</td>\
				<td class="helpmessage">\
				<p class="title">\
				' + v_title + '\
				</p>\
				<p>\
				' + v_message + '\
				</p>\
				</td>\
			</tr>\
		</table>');
		
		$p.show(v_container,'');
    },
    /*  
        Function: $p.app.help.displayNewPortalMessage : display a message when user add a new page
        Parameters:
            v_container : message container
        output : 
            None
	*/
    displayNewPortalMessage: function(v_container)
    {
        $p.app.help.displayMessage(v_container, 'help', lg('lblNewpage'), lg('newPageHelpMsg') + '. <a href="#" style="text-decoration: underline;" onclick=\'$p.show("' + v_container + '","none");$p.app.menu.widget.open();return false;\'>' + lg('lblAddContent') + '</a>.');
    },
        /*
                    Function: $p.app.help.displayDailyMessage
                    
                    Parameters:
                    
                        v_container - location where displaying message
                        
                        
        */    
    displayDailyMessage: function(v_container)
    {
        // get the number of connections to the portal of the user
        var l_nbConnection = parseInt($p.cookie.get('nbconn'),10),
            l_messageTitle = '',
            l_messageBody = '';

        //contextual messages
        if (l_nbConnection < 4)
        {
            l_messageTitle = lg('welcomeOn') + ' ' + __APPNAME;
            l_messageBody = lg('welcomemsg');
        }

        if (l_messageTitle == '')
        {
            l_messageTitle = lg('didYouKnowThis');
            
			$p.app.help.loadDefaultMessages();
			$p.plugin.hook.launch('app.help.Messages');
            var rand = $random(0,$p.app.help.l_messageArray.length - 1).toInt();
            l_messageBody = lg($p.app.help.l_messageArray[rand]);
        }

        //display message
        $p.app.help.displayMessage(v_container, 'help', l_messageTitle, l_messageBody);
    },
    /*
            Array: $p.app.help.l_messageArray
            
                contains random message displayed in homepage
    
    */
    l_messageArray:[],
    /*
            Function: $p.app.help.AddHomeMessages
            
            Parameters:
            
                Message - string with your message (label or any text you want)
    */
    AddHomeMessages: function (message) {
        $p.app.help.l_messageArray.push(message);
    },
    /*
                Function: $p.app.help.RemoveAllMessages
    
                Delete all messages in $p.app.help.l_messageArray
    */
    RemoveAllMessages: function () {
        $p.app.help.l_messageArray = [];
    },
    /*
                Function: $p.app.help.loadDefaultMessages
                
                        Add several help messages displayed in home page
    
    */
	loadDefaultMessages: function ()
	{
		$p.app.help.AddHomeMessages('helpRssWithProviderUrlMsg');
        $p.app.help.AddHomeMessages('helpChangeNbColumnsMsg');	
		$p.app.help.AddHomeMessages($p.app.help.addLink('helpAddWidgetWithDragAndDrop','#','$p.app.menu.widget.open()'));
		$p.app.help.AddHomeMessages($p.app.help.addLink('helpFollowMostReadArticles','#','$p.app.statistics.loadMostRead(0)'));
		$p.app.help.AddHomeMessages($p.app.help.addLink('helpChooseAutoloadWidgets','#','$p.app.menu.config.build()'));
		$p.app.help.AddHomeMessages('helpClickOnLogo');
		$p.app.help.AddHomeMessages('helpMoveWidgetDragAndDrop');
		$p.app.help.AddHomeMessages('helpRenameTabsEasily');
		$p.app.help.AddHomeMessages('helpRemoveActiveTab');
		$p.app.help.AddHomeMessages('helpChangeHTMLPageUrl');

		if (__useNetwork)
		{
			$p.app.help.AddHomeMessages('helpNetworkFollowNetworkActivity');
			$p.app.help.AddHomeMessages($p.app.help.addLink('helpGetNewContacts','#','$p.network.dashboard.loadRecommended()'));
			$p.app.help.AddHomeMessages($p.app.help.addLink('helpKnowWhoAddMeInHisNetwork','#','$p.network.dashboard.loadFollowers()'));
			$p.app.help.AddHomeMessages($p.app.help.addLink('helpGetNewContactsFromDirectory','#','$p.network.dashboard.loadDirectory()'));
			$p.app.help.AddHomeMessages('helpFindPeopleInfoWithSearch');
		}

		if (__useGroup)
		{
			$p.app.help.AddHomeMessages('helpCreateNewGroup');
			$p.app.help.AddHomeMessages('helpTwoKindOfGroups');
			$p.app.help.AddHomeMessages('helpFindInterestingGroups');
		}

		if (__useNotebook)
		{
			$p.app.help.AddHomeMessages('helpShareTabAndWidgets');
			$p.app.help.AddHomeMessages('helpShareWidget');
			$p.app.help.AddHomeMessages('helpShareRSSArticle');
			$p.app.help.AddHomeMessages('helpFollowLatestCommentsWithWidget');
		}

		if (__useChat)
		{
			$p.app.help.AddHomeMessages($p.app.help.addLink('helpDiscussWithChat','#','$p.chat.buildPage()'));
			$p.app.help.AddHomeMessages($p.app.help.addLink('helpGetChatArchive','#','$p.chat.archive()'));
		}

		if (__menuposition == 'v')
		{
			$p.app.help.AddHomeMessages('helpVerticalMenu');
		}
		else
		{
			$p.app.help.AddHomeMessages('helpHorizontalMenu');
		}

		if (__moveWidgetsInTabs)
		{
			$p.app.help.AddHomeMessages('helpMoveWidgetFromTabToTab');
		}

		if (__userModuleJs == 'I')
		{
			$p.app.help.AddHomeMessages($p.app.help.addLink('helpUserCanCreateWidgets','#','$p.app.widgets.factory.init()'));
		}

		if (__useArchive)
		{
			$p.app.help.AddHomeMessages('helpUseArchiveToSave');
		}
		
		if (__columnchange)
		{
			$p.app.help.AddHomeMessages($p.app.help.addLink('helpAddNewColumnsInPages','#','$p.app.menu.config.build()'));
		}
		
		if (__themeList.length>1 && __displayThemeSelector)
		{
			$p.app.help.AddHomeMessages('helpChangeTheme');
			$p.app.help.AddHomeMessages('helpEachPageWithATheme');
		}

		if (__usereader)
		{
			$p.app.help.AddHomeMessages($p.app.help.addLink('helpUseReaderByDefault','#','$p.app.menu.config.build()'));
		}

		if (__moduleAlign)
		{
			$p.app.help.AddHomeMessages($p.app.help.addLink('helpDoNotAlignWidgets','#','$p.app.menu.config.build()'));
		}

		if (__showtabicon)
		{
			$p.app.help.AddHomeMessages('helpAddAnIconToATab');
		}

		if (__addPagePermission != 3)
		{
		//	$p.app.help.AddHomeMessages($p.app.help.addLink('helpAddNewPage','#','$p.app.pages.newPortal()'));
			$p.app.help.AddHomeMessages($p.app.help.addLink('helpAddNewPage','#','$p.app.pages.addNewPage()'));
		}

		if (__showModuleConfigure)
		{
			$p.app.help.AddHomeMessages('helpConfigureYourWidget');
		}
		
		if (__showModuleRefresh)
		{
			$p.app.help.AddHomeMessages('helpRefreshAWidget');
		}

		if (__showModuleMinimize)
		{
			$p.app.help.AddHomeMessages('helpMinimizeAWidget');
		}

		if (__showModuleClose)
		{
			$p.app.help.AddHomeMessages('helpRemoveAWidget');
		}
	},
    /*
                Function: $p.app.help.addLink
                
                        Add href and onclick function on links in label
                        
                 Parameters:
                            v_label - label
                            v_link  - link to add
                            v_fct - function to add as onclick, function added must have a return false command
    
    */
	addLink: function(v_label, v_link, v_fct)
	{
		v_label = lg(v_label);
		v_label = v_label.replace(/<a>/i,'<a href="' + v_link + '" onclick="' + v_fct + ';">');

		return v_label;
	}
}

/*
    Class: $p.network

*/
$p.network={
	shown: false,
	/*
		Function: $p.network.init
        
                        init profile plugin
	*/
	init: function()
	{
		$p.app.popup.show('<div id="networkdiv"></div>',1060,indef, lg('Communities')  );
        //$p.plugin.init(lg('Communities'),'network',true);

		$p.network.buildPage('networkdiv');
	},
	/*
		Function: $p.network.buildPage
                    build network main page
	*/
	buildPage: function(v_container)
	{
		var l_s='<div class="feature">'
			+ $p.html.buildFeatureHeader({
				'image':'../images/bigicon_network.gif',
				'title':(__useNetwork ? '<div style="float: right">'
						+ '<form onsubmit="$p.tags.autocompletion.hide();return $p.network.add.search(this)">'
                        +$p.img("ico_friend_add.gif",16,16,"","imgmid")
                        + ' <span style="font-size: 11px">'+lg("searchForPeople")+' &nbsp;</span>'
                        + ' <input type="text" autocomplete="off" name="searchtxt" id="searchauser_2" class="thinbox" style="width: 226px;color: #aaaaaa;font-size: 9pt;" '
                        + 'onFocus=\'$p.app.tools.inputFocus(this,"'+lg("inputEmailOrNameOrTag")+'")\' '
						+ 'onkeyup=\'$p.network.autocompletion.get("searchauser_2")\' '
                        + 'onBlur=\'$p.tags.autocompletion.hide();$p.app.tools.inputLostFocus(this,"'+lg("inputEmailOrNameOrTag")+'");\' value="'+lg("inputEmailOrNameOrTag")+'" />'
                        + '&nbsp;<input type="submit" class="submit" value="'+lg("ok")+'" style="width:22px" />'
                        + ' </form>'
                        + '</div>'+lg('Communities') : lg('myAccount')),
                'menu':'<div id="network_menu"></div>'
                    +'<div id="network_submenu"></div>'
			})
			+ '<div id="network_content" class="content"></div>'
			+ '</div>';

		$p.print(v_container,l_s);
	},
	buildPageMenu:function(v_id,v_subOption,v_userId)
	{
		var l_h=[];
		//l_h.push({'id':1,'fct':'$p.network.myprofile();','icon':'ico_myaccount.gif','label':lg('myAccount')});
		if (__useNetwork)
		{
			l_h.push({'id':2,'fct':'$p.network.dashboard.myNetwork()','icon':'','label':lg('network')});
			l_h.push({'id':4,'fct':'$p.group.buildPage('+v_userId+')','icon':'','label':lg('Groups')});
			if (__useChat) l_h.push({'id':5,'fct':'$p.chat.buildPage()','icon':'ico_chat.gif','label':lg('chat')});
		}

		$p.print('network_menu',$p.html.buildFeatureMenu(v_id,l_h));
        $p.network.buildPageSubMenu(v_id,v_subOption,v_userId);
	},
    buildPageSubMenu:function(v_selOption,v_selSubOption,v_userId)
	{
		var l_s = '';
        
        switch (v_selOption)
        {
            case 2:
                l_s += '<div style="float:left;"><div style="float:left;">'
					+ '<a href="#"'+(v_selSubOption == 'network' ? ' class="selected"' : '')+' onclick="$p.network.dashboard.myNetwork();">' + (__NETWORK_TYPE == 'R' ? lg('myNetwork') : lg('peopleIAmFollowing')) + '</a> | '
                    //+ '<a href="#"'+(v_selSubOption == 'news' ? ' class="selected"' : '')+' onclick="$p.network.dashboard.initNetworkNews();">' + lg('News') + '</a> | '
                    + '<a href="#"'+(v_selSubOption == 'recommended' ? ' class="selected"' : '')+' onclick="$p.network.dashboard.loadRecommended();">'+lg('recommendedUsers')+'</a> | '
                    + '<a href="#"'+(v_selSubOption == 'followers' ? ' class="selected"' : '')+' onclick="$p.network.dashboard.loadFollowers();">' + (__NETWORK_TYPE == 'R' ? lg('addedinNetwork') : lg('theyFollowYou'))+'</a> | '
                    + '<a href="#"'+(v_selSubOption == 'directory' ? ' class="selected"' : '')+' onclick="$p.network.dashboard.loadDirectory();">'+lg('usersDirectory')+'</a>'
					+ ' | &nbsp;</div><div style="float:left;">'
						+ '<form onsubmit="$p.tags.autocompletion.hide();return $p.network.add.search(this)">'
                        +'<div style="float:left;">'+$p.img("ico_friend_add.gif",16,16,"","imgmid")+'&nbsp;</div>'
						+ '<div style="border:1px solid #c6c3c6;float:left;margin-top:-3px;"><input type="text" autocomplete="off" name="searchtxt" id="searchauser_2" class="searchboxtext2"  '
						+ 'onFocus=\'$p.app.tools.inputFocus(this,"'+lg("searchForPeople")+'")\' '
						+ 'onkeyup=\'$p.network.autocompletion.get("searchauser_2")\' '
                        + 'onBlur=\'$p.tags.autocompletion.hide();$p.app.tools.inputLostFocus(this,"'+lg("searchForPeople")+'");\' value="'+lg("searchForPeople")+'"'
						+' /><input class="searchboxbtn2" type="image" src="../styles/themes/classic_blue/header_menu_searchbtn.png"/></div>'
                        + ' '
						+'</form>'
                        + '</div></div>';
                break;
            case 4:
                l_s += ''
					+ '<div style="float:left;">'
					+ '<form onsubmit="return $p.group.search(this)">'
					+ '<div style="float:left;">'
                    + '<a href="#"'+(v_selSubOption == 'workinggroup' ? ' class="selected"' : '')+' onclick="$p.group.buildPage('+v_userId+');return false;">'+lg("myGroups")+'</a> | '
					+ '<a href="#"'+(v_selSubOption == 'allgroups' ? ' class="selected"' : '')+' onclick="$p.group.displayAllGroups();return false;">'+lg("allTheGroups")+'</a> | '
                    + '<a href="#" onclick="$p.groupbook.add.form();return false;">'
                    + $p.img('ico_group_add.gif',16,16,'','imgmid')
                    + ' ' + lg('addGroup') + '</a> | &nbsp;'
                    + '</div><div style="float:left;"><div style="border:1px solid #c6c3c6;float:left;margin-top:-5px;"><input type="text" id="groupsearchtxt" name="groupsearchtxt" class="searchboxtext2" '
					+ 'onFocus=\'$p.app.tools.inputFocus(this,"'+lg("joinAGroup")+'")\' '
					+ 'onkeyup=\'$p.network.autocompletion.get("groupsearchtxt")\' '
                    + 'onBlur=\'$p.tags.autocompletion.hide();$p.app.tools.inputLostFocus(this,"'+lg("joinAGroup")+'");\' value="'+lg("joinAGroup")+'"'
					+ '/>'
                    + '&nbsp;<input class="searchboxbtn2" type="image" src="../styles/themes/classic_blue/header_menu_searchbtn.png"/>'
					+ '</div>'
					// remove corporate groups with 2.2.3 - make confusion with other groups
					//+ ' | <a href="#"'+(v_selSubOption == 'corporategroup' ? ' class="selected"' : '')+' onclick="$p.network.dashboard.getUserCorporateGroups();return false;">'+lg("myCorporateGroups")+'</a>'
                    + '</div></form></div>'
				break;
			default:
				l_s += '&nbsp;';
		}

		$p.show('network_submenu','block');
        $p.print('network_submenu',$p.html.buildFeatureSubMenu(l_s));
	},
	/*
		$p.network.attribLangvalue : input = lang to set ( change the current language ('fr,''en'..) )
	*/
	attribLangValue:function(lgValue) 
	{ 
		var langValue=(lgValue==indef?_lang:lgValue);
		$p.ajax.call(posh["scr_changelang"],
			{
				'type':'execute',
				'variables':'lang='+langValue,
				'alarm':true,
				'forceExecution':false,
				'callback':
				{
					'function':$p.network.refreshLang
				}
			}
		);		
	},
	/*
		$p.network.refreshLang : refresh current page
	*/
	refreshLang: function() 
	{
		$p.url.openLink(posh["mypage"],false);
	},
	/*
            Function: $p.network.loadUserCriteria
                Load the user's criteria (to display)
	*/
	loadUserCriteria:function()
	{
		$p.ajax.call(posh["xmldisplaycriteria"],
			{
				'type':'load',
				'callback':
				{
					'function':$p.network.displayUserCriteria
				}
			}
		);
	},
	/*
	$p.network.displayUserCriteria
	display user's informations (criteria)
	*/
	displayUserCriteria: function(response,vars)
	{
		var l_s = "";
		var l_result = response.getElementsByTagName("criteria");
		var l_resultSize = l_result.length;      
		l_s += '<div style="padding-top: 15px;">';

	   	for (var i = 0;i < l_resultSize;i ++)
		{            
			//gets the values
         var id = $p.ajax.getVal(l_result[i],'id','int',false,0);
			var label = $p.ajax.getVal(l_result[i],'label','str',false,'');
			var type = $p.ajax.getVal(l_result[i],"type","int",false,0);
			var options = $p.ajax.getVal(l_result[i],'options','str',false,'');
			var editable = $p.ajax.getVal(l_result[i],'editable','int',false,1);
			var parameters = $p.ajax.getVal(l_result[i],'parameters','str',false,'indef');
            if (parameters=="indef")
				parameters = '';
				//parameters=lg("noCriteria");

            $p.app.user.userCriterias[id]={
                                            'options':options,
                                            'parameters':parameters
                                          }; 
            if (type!=6)
                l_s += '<div class="plabel" style="padding-top:3px;">'+label+'</div><div style="color:#1E4487;padding-top:4px;">';

			switch (type)
			{
				case 6 :
					if (parameters == '')
						l_s += '<div  class="plabel" >' + label + '</div>';
					else
						l_s +='<div><a href="'+parameters+'" target="_blank" />'+label+'</a></div>';
                break;
				case 1 :
                    l_s +='<div><span>'+parameters+'</span></div>';
                break;
                case 4 :   
                	var tableau = options.split(";");
					l_s += tableau[parameters-1];
                break;
                case 5 :
					l_s +=parameters;
                break;
				case 2 :
					var tableau = options.split(";");
					l_s += tableau[parameters-1];
				break;   
				case 3 :
					var tabParameters = parameters.split(",");
					for (var a = 0;a < tabParameters.length;a ++)
					{
                        l_s += tabParameters[a]+" - ";
					}
				break;                       
			}
			l_s += '</div>';
            l_s += (editable == 1 ? '<div class="pbutton atleft" style="padding-top:7px;padding-bottom:12px;">'
					+ $p.html.buildButton('$p.network.modifyCriteria();return false;', lg('lblModify'))
					+'</div><br /><br />' : '')
                + '</div>'
                + '<div class="float_correction"></div>';
		}		
        l_s += '</div><br /><br />';

		$p.print("otherCriteria",l_s);
	},
	/*
		Function: $p.network.modifyCriteria
        
                        profile criterias modifications
                        
                        get datas about users to update it
                        
               See also:
               
                    Posh server  script:  xmldisplayhtmlcriteria
                    <$p.network.displayModifyForm>
        
	*/
	modifyCriteria:function()
	{
        $p.ajax.call(posh["xmldisplayhtmlcriteria"],
			{
				'type':'load',
				'callback':
				{
					'function':$p.network.displayModifyForm
				}
			}
		);
	},
    /*
    
            Function: $p.network.displayModifyForm
            
                display form to update user info (criterias)
                
              See also:

                    called from $p.network.modifyCriteria
    */
    displayModifyForm:function(response,vars)
    {
        var l_s='';
        var i=0;
        var l_s="";
        var info="";
        var total=1;
        var nb=$p.ajax.getVal(response,"nbcriterias","int",false,0);
        l_s+='<br /><form name="updateCriterias">\
              <input type="hidden" name="nbSpecificFields" value="'+nb+'" />';
		while (response.getElementsByTagName("criteria")[i])
		{
			var result=response.getElementsByTagName("criteria")[i];
			var infoID=$p.ajax.getVal(result,"id","int",false,0);
			var type=$p.ajax.getVal(result,"type","str",false,"");
			var label=$p.ajax.getVal(result,"label","str",false,"");
			var options=$p.ajax.getVal(result,"options","str",false,"");
			var mandatory=$p.ajax.getVal(result,"mandatory","int",false,0);
            info=(mandatory==1)?'&nbsp;<font color="red">*</font>':'';
		
            switch (type)
            {
                //TEXT
                case '1':
                    $p.app.user.userCriterias[infoID]['parameters'] = $p.app.user.userCriterias[infoID]['parameters'].replace("'", "\""); 
                    l_s+='<div class="plabel" >'+label+'\
                          <input type="hidden" name="uniq_id'+total+'" value="'+infoID+'" />\
                          <input type="hidden" name="type'+total+'" value="'+type+'" />\
						  </div>\
                          <div style="padding-top:4px;">\
						  <input type="text" name="userinfo'+total+'" size="25" mandatory="'+mandatory+'" value="'+$p.app.user.userCriterias[infoID]['parameters']+'" />\
						  '+info+'</div><br />';
                break;
                //LIST
                case '2':
                    var tabOptions=options.split(';');
                    l_s+='<div class="plabel" >'+label+'\
                    <input type="hidden" name="uniq_id'+total+'" value="'+infoID+'" />\
                    <input type="hidden" name="type'+total+'" value="'+type+'" />\
					</div>\
                    <div style="padding-top:4px;"><select name="userinfo'+total+'" mandatory="'+mandatory+'" >';
                    for(var j=0;j<tabOptions.length;j++)
                    {
                        var selected="";
						if($p.app.user.userCriterias[infoID]) {
							if ((j+1)==$p.app.user.userCriterias[infoID]['parameters']) {
								selected="selected=selected";
							}
						}
                        l_s+='<option value="'+(j+1)+'" '+selected+'>'+tabOptions[j]+'</option>';
                    }
                    l_s+='</select></div><br />';
                break;
                //CHECKBOX
                case '3':
                    var tabOptions=options.split(';');
                    var tabParameters='';
					if($p.app.user.userCriterias[infoID])
						tabParameters = $p.app.user.userCriterias[infoID]['parameters'].split(',');  
                    l_s+='<div class="plabel">'+label+'\
                          <input type="hidden" name="uniq_id'+total+'" value="'+infoID+'" >\
                          <input type="hidden" name="type'+total+'" value="'+type+'" /></div>\
						  <div style="padding-top:4px;">';
                    for(var j=0;j<tabOptions.length;j++)
                    {
                        var selected="";
                        if (tabParameters.contains(tabOptions[j])) { selected="checked=checked"; }    
                        l_s+='<INPUT type="checkbox" name="userinfo'+total+'[]" id="check'+tabOptions[j]+'" value="'+(j+1)+'" mandatory="'+mandatory+'" '+selected+'>'+tabOptions[j];
                        l_s+=(j==0)?info+'<br />':'<br />';
                    }
                    l_s+='</div><br />';
                break; 
                //RADIO
                case '4':
                    var tabOptions=options.split(';');
                    l_s+='<div class="plabel">'+label+'\
                    <input type="hidden" name="uniq_id'+total+'" value="'+infoID+'" />\
                    <input type="hidden" name="type'+total+'" value="'+type+'" /></div>\
					<div style="padding-top:4px;">';
                    for(var j=0;j<tabOptions.length;j++)
                    {
                        var selected="";
						if($p.app.user.userCriterias[infoID]) {
							if (tabOptions[j]==$p.app.user.userCriterias[infoID]['parameters']) {
								selected="checked=checked";
							}
						}
                        l_s+='<INPUT type="radio" name="userinfo'+total+'" id="radio'+tabOptions[j]+'" value="'+tabOptions[j]+'" mandatory="'+mandatory+'" '+selected+'>'+tabOptions[j];
                        l_s+=(j==0)?info+'<br />':'<br />';
                    }  
                    l_s+='</div><br />';
                break;
                //TEXTAREA
                case '5':
					tmp = '';
					if($p.app.user.userCriterias[infoID]) {
						tmp = $p.app.user.userCriterias[infoID]['parameters'];
					}
                    l_s+='<div class="plabel">'+label+'\
                         <input type="hidden" name="uniq_id'+total+'" value="'+infoID+'" />\
                         <input type="hidden" name="type'+total+'" value="'+type+'" /></div>\
						 <div style="padding-top:4px;">\
                         <textarea cols="30" rows="5" name="userinfo'+total+'" mandatory="'+mandatory+'">'+tmp+'</textarea>'+info+'\
						 </div><br />';
                break;
                //TEXT
                case '6':
                    $p.app.user.userCriterias[infoID]['parameters'] = $p.app.user.userCriterias[infoID]['parameters'].replace("'", "\""); 
                    l_s+='<div class="plabel">'+label+'\
                          <input type="hidden" name="uniq_id'+total+'" value="'+infoID+'" />\
                          <input type="hidden" name="type'+total+'" value="'+type+'" />\
						  </div>\
                          <div style="padding-top:4px;">\
						  <input type="text" name="userinfo'+total+'" size="25" mandatory="'+mandatory+'" value="'+$p.app.user.userCriterias[infoID]['parameters']+'" />\
						  '+info+'</div><br />';
                break;
            }
            total++;
			i++;
		}
      
        l_s+='<div><input type="button" class="btn" value="'+lg("lblModify")+'" onclick="$p.network.updateMyCriterias();reset_rand();$p.network.myprofile();">&nbsp;&nbsp;\
              <input type="button" class="btn" value="'+lg("lblCancel")+'" onclick="$p.notebook.open(indef,indef,indef,1);reset_rand();$p.network.myprofile();">\
              </div>\
              </form>';
              
		//$p.app.popup.fadein(l_s,510,indef,lg("lblInfosAdd"),false);
		$p.print("otherCriteria",l_s);
    },
    updateMyCriterias:function()
    {
        var formElements=document.forms['updateCriterias'].elements.length;
        if ($p.network.controlMandatoryFields(formElements,'updateCriterias')) {
            
            var nbSpecificFields=document.forms['updateCriterias'].nbSpecificFields.value;
            var criteriasList="";
            var parametersList="";
 
            //get criterias
            for (var i=1;i<=nbSpecificFields;i++)
            {
                var uniq_id=document.forms['updateCriterias'].elements['uniq_id'+i].value;
                var type=document.forms['updateCriterias'].elements['type'+i].value;
                var id='&uniq_id'+i+'='+uniq_id;
				var options=($p.app.user.userCriterias[uniq_id])?$p.app.user.userCriterias[uniq_id]['options']:'';
                if (type=='3') {
                    var selectList=new Array();
                    
                    var tabOptions=options.split(';');
                    for(var j=0;j<tabOptions.length;j++)
                    {
						if (document.forms['updateCriterias'].elements['check'+tabOptions[j]])
                        if (document.forms['updateCriterias'].elements['check'+tabOptions[j]].checked==1) {
                            selectList.push(tabOptions[j]);
                        }
                    }
                    criteriasList+="userinfo"+i+"="+selectList+id+"&";
                }
                else if (type=='4') {
                    var tabOptions=options.split(';');
                    for(var j=0;j<tabOptions.length;j++)
                    {
                        if (document.forms['updateCriterias'].elements['radio'+tabOptions[j]].checked==1) {
                           criteriasList+="userinfo"+i+"="+tabOptions[j]+id+"&";
                        }
                    }
                }
                else if (type=='1' || type=='5') {  
                    var textVal=document.forms['updateCriterias'].elements['userinfo'+i].value;
                    textVal = $p.string.formatForSearch(textVal);
                    textVal=textVal.replace(/\&/gi,"%26"); 
                    textVal=textVal.replace(/\+/gi,"%2b");
                    textVal=textVal.replace(/\</gi,"");
                    textVal=textVal.replace(/\>/gi,"");
                    criteriasList+="userinfo"+i+"="+textVal+id+"&";
                }
                else if (type == '6') {
                    var textVal=document.forms['updateCriterias'].elements['userinfo'+i].value;
                    textVal=textVal.replace(/\&/gi,"%26"); 
                    textVal=textVal.replace(/\+/gi,"%2b");
                    textVal=textVal.replace(/\?/gi,"%3F");
                    textVal=textVal.replace(/\"/gi,"");
                    textVal=textVal.replace(/\'/gi,"");
                    textVal=textVal.replace(/\</gi,"");
                    textVal=textVal.replace(/\>/gi,"");
                    criteriasList+="userinfo"+i+"="+textVal+id+"&";
                }
                else {
                    criteriasList+="userinfo"+i+"="+document.forms['updateCriterias'].elements['userinfo'+i].value+id+"&";
                }     
            }
                        
            parametersList+="nbSpecificFields="+nbSpecificFields
                          +"&"+criteriasList;
  
            //add user in the database
            $p.ajax.call(posh["scr_update_criterias"],
                {
                    'type':'execute',
                    'variables':parametersList,
                    'forceExecution':true,
                    'callback':
                    {
                        'function':$p.network.loadUserCriteria
                    }
                }
            );
        }
    },
	/*
		$p.network.hide : close profile plugin
	*/
	hide: function()
	{
		$p.plugin.hide();
		$p.network.shown = false;
	},
	buildBreadcrumb: function(v_bc)
	{
		$p.plugin.displayBreadcrumb('<div class="feature">'
			+ v_bc
			+ '</div>'
		);
		$p.show('plugin_breadcrumb','block');
	},
	/*
		$p.network.controlMandatoryFields : controls that the mandatory fields are filled.
			Parameters:

				n: number of form's elements
	*/
	controlMandatoryFields:function(n,formname,indice)
	{	
        var i=0;
        var total=0; //numbers of unfilled fields
        var minicount=0;
        var tabRadio=[];
        var oldname="";
        var temp;
        if (typeof(indice)=="undefined") {
            indice=0;
        }
        
        for (i=indice;i<n;i++)
        {
            switch (document.forms[formname].elements[i].type)
            {
                case 'text':
                {
                    //is the field mandatory and is it filled with something
                    var mandatory = document.forms[formname].elements[i].getAttribute("mandatory");
                    if (mandatory==1 && document.forms[formname].elements[i].value=="")
                        total++;
                        
                    break;
                }
            
                case 'textarea':
                {
                    //is the field mandatory and is it filled with something
                    var mandatory = document.forms[formname].elements[i].getAttribute("mandatory");
                    if (mandatory==1 && document.forms[formname].elements[i].value=="")
                        total++;
                        
                    break;
                }		
                
                case 'radio':
                {
                    var maxIndex=tabRadio.length;
                    var escap=0;						
                    var currentName = document.forms[formname].elements[i].name;
                    var mandatory = document.forms[formname].elements[i].getAttribute("mandatory");
                    if (mandatory==1)
                    {
                    
                        if (maxIndex>0)
                        {
                            for (var j=0;j<maxIndex;j++)
                            {
                                if (tabRadio[j]==currentName)
                                    escap=1;
                                else
                                    tabRadio[maxIndex]=currentName;							
                            }
                        }
                        else
                        tabRadio[0]=currentName;
                        
                        if (escap==0)
                        {
                            var cpt=i;
                            var correct=0;
                            //if the first element isn't checked						
                                if (document.forms[formname].elements[cpt].checked!=true) {
                                        //we scan the others
                                        while (document.forms[formname].elements[cpt+1].name==currentName)
                                        {
                                            if (document.forms[formname].elements[cpt+1].checked==true) {
                                                correct=1;
                                            }  
                                            cpt++;
                                        }
                                }												
                                else
                                {correct=1;}
                            
                            if (correct!=1)
                                total++;		
                        }
                    }
                    break;
                }
                
                case 'checkbox':
                {										
                    var mycurrentName = document.forms[formname].elements[i].name;
                    var passage=0;
                    
                    if (oldname=="")
                    {
                        oldname=mycurrentName;
                        passage=1;
                        minicount=0;
                        temp=0;
                    }
                    else if (oldname!=mycurrentName)
                    {
                        oldname=mycurrentName;
                        passage=1;
                        minicount=0;
                        temp=0;
                    }
                            
                    //If the field is mandatory, verify that at least one checkbox is checked
                    var mandatory = document.forms[formname].elements[i].getAttribute("mandatory");
                    if (mandatory==1)
                    {
                        var cpt=i;

                        if (passage==1)
                        {
                                if (document.forms[formname].elements[i].checked!=true)
                                    minicount++;
                                
                                    while (document.forms[formname].elements[cpt+1].name==mycurrentName)
                                    {
                                        temp = document.forms[formname].elements[cpt+1].value;
                                        if (document.forms[formname].elements[cpt+1].checked!=true)
                                            minicount++;
                                        
                                        cpt++;
                                    }	
                                    if (minicount==temp)
                                        total++;
                        }
                    }
                    break;	
                } //end case
            } //end switch
        } // end for
                        
        if (total!=0)
            {$p.app.alert.show(lg("errorEmptyFieldForm"),3);
            return false;}
        else	
        return true;
	},
	/*
		function: $p.network.checkConnexion
        
		Check session
	*/
	checkConnexion: function(response,vars)
	{
		if( response == null && $('popup') == null ) {
            var localfolder = __LOCALFOLDER;
            localfolder = localfolder.replace(/http:/,$p.navigator.getProtocol());    
			$p.app.popup.show('<iframe width="650" height="500" frameborder="0" src="'+localfolder+'/portal/login_reconnexion.php"></iframe>',800,indef,'Login',true);
		}
	},
    /*
            Function: $p.network.myprofile
            
                call function to display user depending of type of portal, simple or with collaborative suite
                
    */
    myprofile: function()
    {
        if (__useNotebook)
        {	if($p.app.user.type == 'A' && $p.app.env == "admin")
				return false;
			else
				$p.notebook.open(indef,indef,indef,1);
        }
        else
        {
            $p.app.user.myprofile();
        }
    }
}

/*
    Class: $p.network.profile
*/
$p.network.profile={
	/*
		Function: $p.network.profile.load 
                    load my profile
                
               See Also:

                    <$p.network.profile.display>
	*/
	load:function()
	{
        if (__useNetwork)   {
			$p.app.wait('myprofile');
			getXml(posh["xmlnetwork_myprofile"],$p.network.profile.display);
		}
	},
	/*
		Function: $p.network.profile.display 
        
                        display my profile
		
            Parameters:
                    response - xml response
                    vars - variables 
			 
	*/
	display:function(response,vars)
	{
        //var l_picture = $p.ajax.getVal(response,"picture","str",false,"");
		var l_s = //'<div style="width: 150px;float: left">'
			//+ '<img src="'+(l_picture==""?"../images/nopicture.gif":$p.url.setParamInUrl(l_picture,"nocache",rand))+'" width="64" height="64" class="picture" />'
            //+ '<br /><a href="#" onclick="$p.network.profile.modify()">'+lg('modify')+'</a>'
            //+ '</div>'
			//+ '<div><b>'+$p.ajax.getVal(response,"longname","str",false,"---")+'</b><br /><br />'
            //+ lg("myStatus")+' '+tooltip("myStatusHelp")+' :'
            //+ '<form onsubmit=\'return $p.network.profile.updateStatus(this)\'>'
			//+ '<input class="thinbox" type="text" name="stat" value=\''+$p.ajax.getVal(response,"stat","str",false,"")+'\' maxlength="200" style="width: 400px;"/> '
			//+ '<input type="submit" class="btn" value="'+lg("lblBtnSend")+'" />'
			//+ '</form>'
            //+ '</div>'
            '<div class="float_correction" style="padding-top: 15px;"></div>'
            + '<div style="width: 150px;float: left;">'
            + lg("keywords")+' :'
            + '</div>'
			+ '<div>'
            + $p.tags.separate(response.getElementsByTagName("keyword")[0].firstChild.nodeValue)
            + ' <a href="#" onclick="$p.network.profile.modify()">'+lg('modify')+'</a>'
            + '</div>'
            + '<div class="float_correction"></div>'
			+ '<div style="width: 150px;float: left">'
            +lg("description")+' :'
            + '</div>'
			+ '<div style="float: left;">'
            + $p.ajax.getVal(response,"desc","str",false,lg("noDescription"))
            + '<br /><a href="#" onclick="$p.network.profile.modify()">'+lg('modify')+'</a>'
            + '</div>'
            + '<div class="float_correction"></div>';

		$p.print("myprofile",l_s);
	},
    /*
            Function: $p.network.profile.displayUserDatas
            ;
                    Display user datas found in $p.app.user class
                    
                    Hash to know how display datas
                    
                    $p.app.user.parameters : see details in <$p.app.user.init>
                
                    JS hook : network.profile.displayuserdatas
                    
                    Display datas in tag with id  -> userdatas 
                    
                    Hook :  
                        - network.profile.displayuserdatas.begin 
                        - network.profile.displayuserdatas.end
    */
    displayUserDatas: function () {
        $p.plugin.hook.launch('network.profile.displayuserdatas.begin');
        if ($p.app.user.picture) {
            l_s += '<img src="'+$p.app.user.picture+'" border="0">';
        }
        var l_s = '<div id="userdatas">'
        for (var param in $p.app.user.parameters) {
            if ( $p.app.user.parameters[param].display) {
                if ($p.app.user.parameters[param].type == 'string') {
                    l_s += 
                        '<div class="fieldmiddle">'
                        + lg( $p.app.user.parameters[param].label )+' : '
                        + '</div>'
                        + '<div >'
                        +  $p.app.user[param]
                        + '</div>'

                    + '<div class="float_correction"></div>';
                }
            }
        }
        l_s += '</div>'
            + '<div class="float_correction"></div>';
        $p.print("userdatas",l_s);
        $p.plugin.hook.launch('network.profile.displayuserdatas.end'); 
    },
	/*
		Function: $p.network.profile.passwordMenu
        
                        display the change password menu
	*/
	passwordMenu:function()
	{
		var l_s = '<div>' + $p.html.buildTitle(lg('lblModifyPassword')) + '</div>'
            + '<div class="content">'
			+ '<form name="newpass">'
			+ '<div style="width: 150px;float: left;">' + lg('lblOldPassword') + '</div><div><input class="thinbox" type="password" name="oldpass" maxlength="16" /></div>'
			+ '<div style="width: 150px;float: left;">' + lg('lblNewPassword') + '</div><div><input class="thinbox" type="password" name="pass1" maxlength="16" /></div>'
			+ '<div style="width: 150px;float: left;">' + lg('lblRetypeNewPassword')+'</div><div><input class="thinbox" type="password" name="pass2" maxlength="16" /></div>'
			+ '<div class="float_correction"></div><div style="width: 150px;float: left;">&nbsp;</div><div><input onClick="$p.app.connection.changePass();" class="btn" type="button" value="'+lg("lblModify")+'" /></div>'
			+ '</form>'
            + '</div>';

		$p.print('mypassword',l_s);
	},
	/*
		Function: $p.network.profile.changeUserMenu 
                        
                                changeUserMenu
                        
                                change user
	*/
	changeUserMenu:function()
	{
        var missingPassword = $p.app.connection.link2MissingPassword();
        var lblusername = __accountType=='mail'?lg('lblEmail'):lg('lblLogin');
		var fct = "function(){window.location.reload();}"
		var l_s = '<div>' + $p.html.buildTitle(lg('lblChangeUser')) + '</div>'
            + '<div class="content">'
			+ '<span id="msg_conn"></span>'
            + '<form method="post" name="conBox" onSubmit="return $p.app.connection.set(this,'+fct+',true);">'
			+ '<div style="width: 150px;float: left;">' + lblusername + '</div>'
            + '<div><input class="thinbox" type="text" name="username" maxlength="64" size="30" /></div>'
			+ '<div style="width: 150px;float: left;">' + lg("lblPassword") + '</div>'
            + '<div><input class="thinbox" type="password" name="password" maxlength="16" size="30" /></div>'
			+ '<div style="width: 150px;float: left;">&nbsp;</div><div><input type="checkbox" name="autoconn" />' + lg('lblAutoConnection') + '</div>'
            + '<br />'
			+ '<div style="width: 150px;float: left;">&nbsp;</div><div><input type="submit" class="btn" value="'+lg('lblOk')+'" />&nbsp;<a class="w" id="ls_missingpass" onclick="return $p.app.connection.buildmissingPasswordForm();">'+lg('lblMissingPassword')+'</a></div>'
			+ '</form>'
            + '</div>';

		$p.print('changeuser',l_s);
	},
    /*
            Function: $p.network.profile.changeLang
            
                    display form to change lang
               
               See also: 
                    <$p.network.attribLangValue>
                        
    */
	changeLang:function()
	{
        var l_s = '<div>' + $p.html.buildTitle(lg('lblModifyLang')) + '</div>'
            + '<div class="content">'
			+ '<form name="changeLang">'
			+ '<div style="width: 150px;float: left;">&nbsp;</div>'
            + '<div>'
            + '<select id="langList" name="langList" size="1" onChange="$p.network.attribLangValue(this.value);">';
            
            for (var i=0;i<__AVLANGS.length;i++)
            { 									
                (__lang==__AVLANGS[i])?selected='selected=selected':selected='';             
                l_s+="<option value='"+__AVLANGS[i]+"' "+selected+" >"+__AVLANGS[i]+"</option>";                 
            }
            
            l_s +='</select></div>'
            + '</form>'
            + '</div>';
		$p.print('userlang',l_s);
	},
	/*
		Function: $p.network.profile.modify
                        profile modification popup
	*/
	modify:function()
	{
		var l_s = '<br />'
			+ '<iframe src="'+posh["frm_network_updateprofile"]+'" width="500" height="350" frameborder="no" marginwidth="0" marginheight="0" scrolling="auto"></iframe>';
			//+'<br /><br /><input type="button" onclick="$p.app.popup.hide();reset_rand();$p.network.myprofile();" value="'+lg("lblClose")+'" />';

		$p.app.popup.show(l_s,510,indef,lg("modifyProfile"),true, 'reset_rand();$p.network.myprofile();');
	},
	loadStatus: function()
	{
		$p.ajax.call(posh["xmlnetwork_myprofile"],
			{
				'type':'load',
				'callback':
				{
					'function':$p.network.profile.buildStatus
				}
			}
		);
	},
	buildStatus: function(v_response)
	{
		if (v_response != indef)
			$p.app.user.stat = $p.ajax.getVal(v_response,"stat","str",false,'');
		
		var l_s = '<a href="#" onclick="$p.network.profile.updateStatusForm();">'
			+ ($p.app.user.stat == '' ? lg('clickHereToUpdateYourStatus') : $p.app.user.stat)
			+ '</a>';
		
		$p.print('profilestatus', l_s);
	},
	updateStatusForm: function()
	{
		var l_s = '<form id="profilestatutform" onsubmit=\'return $p.network.profile.updateStatus(this.stat)\' style="margin: 0px; padding: 0px;">'
			+ '<input name="stat" value=\'\' maxlength="200" style="width: 220px;" class="thinbox"  onFocus=\'\' onBlur=\'$p.network.profile.updateStatus(this);\'/> &nbsp;'
            + '</form>';
		$p.print('profilestatus', l_s);
		
		document.forms['profilestatutform'].stat.focus();
	},
	/*
		Function:  $p.network.profile.updateStatus 
                        update my status
                        
		Parameters:

			 v_form - (string) form containing status information
	*/
	updateStatus:function(v_input)
	{
		if ($p.app.user.stat != v_input.value && v_input.value != '')
		{
			$p.app.user.stat = v_input.value;
			executescr(posh["scr_network_updatemyprofile"],"stat="+$p.string.esc($p.app.user.stat),false,false,$p.network.profile.updateStatusSuccess);
		}
		else
		{
			$p.network.profile.buildStatus();
		}
		return false;
	},
	/*
		Function: $p.network.profile.updateStatusSuccess 
                    action when my status is updated
	*/
	updateStatusSuccess:function()
	{
		$p.app.alert.show(lg("yourStatusIsUpdated"));
		$p.network.profile.buildStatus();
	},
	/*
		Function:  $p.network.profile.unsubscribe
                        display the HTML to unsubscribe a user
	*/
    unsubscribe:function() {
        var l_s = "<br /><a href='#' onclick='$p.network.profile.confirmUnsubscribe();return false;' >"+lg("lblUnsubscribeMe",__APPNAME)+"</a>";
        $('unsubscribelink').innerHTML = l_s;
        return false;
    },
	/*
		Function:  $p.network.profile.confirmUnsubscribe
                        display a confirmation message
	*/
    confirmUnsubscribe:function() {
        if (confirm(lg("lblConfirmUnsubscribe",__APPNAME))) {
            var cookiesTab=new Array("autoi", "autop", "laststate");
            var localfolder = __LOCALFOLDER;
            $p.app.deleteCookies(cookiesTab);
            localfolder = localfolder.replace(/http:/,$p.navigator.getProtocol());
            $p.url.openLink(localfolder+"portal/"+posh["login"]+"?action=unsubscribe");
        }
        return false;
    }
}

//===============================================================================================================
//					OTHER OBJECTS MANAGEMENT
//===============================================================================================================

//Old functions (compatibility
function _gel(v_id) {return $p.get(v_id);}
function navPrint(v_id,v_s,v_add){$p.print(v_id,v_s,v_add);}
function getPos(v_node,v_ref){return $p.getPos(v_node,v_ref);}
function _trim(v_s){return $p.string.trim(v_s);}
function inArray(v_arr,v_searched){return $p.array.find(v_arr,v_searched);}
function MyMooToolsDebug(){}
function _gelstn(v_t){return $$(v_t);}
function navClass(v_id,v_class){return $p.setClass(v_id,v_class);}
function navShow(v_id,v_disp){return $p.show(v_id,v_disp);}
function navIsShown(v_id){return $p.isShown(v_id);}
function navWait(v_id){return $p.app.wait(v_id);}
function _esc(v_s){return $p.string.esc(v_s);}
function _unesc(v_s){return $p.string.unesc(v_s);}
function _uc(v_s){return $p.string.uc(v_s);}
function _lc(v_s){return $p.string.lc(v_s);}
function _min(v1,v2){return $p.min(v1,v2);}
function _max(v1,v2){return $p.max(v1,v2);}
function navId(v_id,v_newId){return $p.changeId(v_id,v_newId);}
function navHeight(v_id,v_h){return $p.setHeight(v_id,v_h);}
function navWidth(v_id,v_w){return $p.setWidth(v_id,v_w);}
function img(v_file,v_w,v_h,v_alt,v_cl,v_id){return $p.img(v_file,v_w,v_h,v_alt,v_cl,v_id);}
function p_img(v_file,v_w,v_h,v_alt,v_cl,v_id){return $p.imgObj(v_file,v_w,v_h,v_alt,v_cl,v_id);}
var p_nav={IE:$p.navigator.IE,noinclusion:function(){return $p.navigator.noinclusion();},changeTitle:function(v_title){return $p.navigator.changeTitle(v_title);}}
var p_popup={show:function(v_content,v_width,v_height,v_title,v_closeBtn){return $p.app.popup.show(v_content,v_width,v_height,v_title,v_closeBtn);}}
function formatSearch(v_s){return $p.string.formatForSearch(v_s);}
function getVar(v_s,v_var){return $p.string.getVar(v_s,v_var);}
function correctCharEncoding(v_s){return $p.string.correctEncoding(v_s);}
function removeTags(v_s){return $p.string.removeTags(v_s);}
function _hesc(v_s){return $p.string.htmlToText(v_s);}
/*
	Function: _args 
                transform URL variables to an array of these variables
	
        Parameters:

			 URL
	
	Returns:
			 array of variables
*/
function _args(v_s)
{
	v_s=(v_s ? v_s : windowLocationObject.search);
	if (v_s.substr(0,1)=='&'||v_s.substr(0,1)=='?') v_s=v_s.substr(1);
	var l_arr=v_s.split('&');
	var l_ret=[];
	for (var i=0;i<l_arr.length;i++)
	{
		var pair=l_arr[i].split('=');
		l_ret[pair[0]]=pair[1];
	}
	return l_ret;
}
/*
	Function: setExternalLink 
                all links are opened in an external window
	
        Parameters:

			 HTML string with hyperlinks
	
	Returns:
			 HTML string with all hyperlinks opening in a new window
*/
function setExternalLink(v_s)
{
	return v_s.replace(/<a /g,"<a target='_blank' ");
}
/*
	Function: checkEmail 
                check email validity
	
        Parameters:

			 email
	
	Returns:
			 true / false
*/
function checkEmail(v_email)
{
	var l_ret=true;
	var l_reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;
	if (l_reg.exec(v_email)==null){l_ret=false;}
	return l_ret;
}
/*
	Function:  sortDate 
                Sort by dates rule
*/
function sortDate(a,b)
{
	if (a.date>b.date) return -1;
	if (a.date<b.date) return 1;
	return 0;
}
/*
	Function:  sortId 
                sort by ID rule
*/
function sortId(a,b)
{
	if (a.id>b.id) return -1;
	if (a.id<b.id) return 1;
	return 0;
}
// Sorting function for bloc showing type
function blocSort(v_a,v_b)
{
	if (v_a.newcell<v_b.newcell) return -1;
	if (v_a.newcell>v_b.newcell) return 1;
	if (v_a.newpos<v_b.newpos) return -1;
	if (v_a.newpos>v_b.newpos) return 1;
	return 0;
}
// Sorting function for newspaper showing type
function newspaperSort(v_a,v_b)
{
	if (v_a.posj<v_b.posj) return -1;
	if (v_a.posj>v_b.posj) return 1;
	return 0;
}
function link(v_url,v_newpage,v_uselang){return $p.url.openLink(v_url,v_newpage,v_uselang);}
/*
	homebar : display application help for a new user
*/
function homebar()
{
	var l_s = '<div style="float: right">'
        + '<a href="#" onclick=\'$p.show("box","none");return false;\'>' + $p.img('ico_close.gif',11,12) + '</a> &nbsp;'
        + '</div>'
        + "<table cellpadding='0' cellspacing='0' width='100%'><tr>"
        + "<td valign='top' width='33%'><b>1/ "+lg("lblAddMenu")+"</b><br /><br /><center>"+$p.img("homebar_1.gif")+"</center></td>"
        + "<td class='lefthr' valign='top' width='33%'><b>2/ "+lg("lblEditMenu")+"</b><br /><br /><center>"+$p.img("homebar_2.gif")+"</center></td>"
        + "<td class='lefthr' valign='top'><b>3/ "+lg("lblSave")+"</b><br /><br /><center>"+$p.img("homebar_3.gif")+"</center></td>"
        + "</tr></table>";
    
    $p.print('box','<div style="padding: 8px">'
        + $p.html.roundBox(l_s,
            '#fff',
            '100%',
            '#c6c3c6')
        + '</div>'
    );
	//$p.print("box",box(0,lg("lblBeginningWith")+__APPNAME,"hideBox()",l_s));
	$p.show("box","block");
}
function formatDateShort(v_date,v_useTime){return $p.date.formatDateShort(v_date,v_useTime);}
function logout(){return $p.app.logout();}
/*
	goIndex : open Portaneo homepage
*/
function goIndex()
{
	$p.app.widgets.factory.init();
	return false;
}
/*
	shortName : Get user short name for better display in page
	Parameters:

			 user long name
	
	Returns:
			 user short name
*/
function shortName(v_n)
{
	if (v_n.indexOf("@")>0) {v_n=v_n.substr(0,(v_n.indexOf("@")));}
	return v_n;
}
function getRadioValue(v_element){return $p.app.tools.getRadioValue(v_element);}
function debug(v_msg,v_type){return $p.app.debug(v_msg,v_type);}
var p_alert={show:function(v_msg,v_type){return $p.app.alert(v_msg,v_type);}}


/*

    Class: html
    
            tools for building html 
            
            $p.html

*/
$p.html={
    /* Function: link
    
                    build new link
                    
                    $p.html.link
                
                Parameters:
                
                        text - link text
                        href - link
                       Parameters- hash {params : {}, styles:{}, events:{}}
    
            */
    link: function(text,href,parameters) {
        
        var l_s = "<a href=\""
                +  href
                + '" ';
        l_s +=  this._paramsValues(parameters['params']);       
        l_s +=  this._paramsStyles(parameters['styles']); 
        l_s +=  this._paramsValues(parameters['events']);        
        l_s += '>' + text + "</a>";
        
        return l_s;
    },
    /*
                Function: table
                
                             begin table

                             $p.html.table
                  
                   Parameters:
                   
                        params - parameters (hash)
                        styles -    styles (hash)
                        events - events (hash)
           */
    table:function (parameters) {
        var l_s =  '<table'
        l_s +=  this._paramsValues(parameters['params']);
        l_s +=  this._paramsStyles(parameters['styles']);
        l_s +=  this._paramsValues(parameters['events']);
        l_s += ">";
        
        return l_s;
    },
    /*
                Function: row
                    
                        build row
                        
                        $p.html.row
        */
    row:function (tr) {
        
    },
    /*
            Function: _paramsValues
            
                            build html tags parameters
            
             Parameters:
             
                            params - hash
        */
    _paramsValues:function (params) {
        var l_s = '';
        for (var p in params) {
            l_s += p + '="'+ params[p] +'"';
        }
        return l_s;
    },
    /*
                Function: _paramsStyles
                
                        build styles parameters for a tag style
                        
                  Parameters:

                            styles - hash
            */
    _paramsStyles:function (styles) {
         var l_s = ' style="'; 
        for ( var s in styles) {
            l_s += s + ":" + styles[s] + ";";
        }
        l_s += '" ' ; 
        return l_s;
    },
	/*
                Function: buildTitle
                
                        build title div
                        
                  Parameters:

                            v_title - title (string)
                            v_options - options displayed  on the right of the title bar (string)
            */
    buildTitle: function (v_title,v_options)
	{
        var l_s = (v_options==indef ? '' : '<div class="feature_title_options">'+v_options+'</div>')
			+ '<div class="feature_title">'
			+ '<span>'+v_title+'</span>'
			+ '</div>';

		return l_s;
    },
	/*
                Function: buildPageNavigator
                
                        build page navigator
                        
                  Parameters:

			v_leftButtonLabel - Left button label
			v_leftButtonCode - left button code
			v_middleLabel - label displayed between buttons
			v_rightButtonLabel - Right button label
			v_rightButtonCode - right button code
            */
	buildPageNavigator: function(v_leftButtonLabel,v_leftButtonCode,v_middleLabel,v_rightButtonLabel,v_rightButtonCode)
	{
		var l_s='';
		if(v_leftButtonCode!='' || v_rightButtonCode!='' )
			l_s+='<div style="clear: both;float: none;text-align: center;background: #c6c3c6;height: 22px;margin-top: 15px;padding-top: 3px;">';
		if (v_leftButtonCode!='')
		{
			l_s+='<a href="#" onclick=\''+v_leftButtonCode+'\'>'+$p.img('ico_previous3.gif',8,11,'','imgmid')+' '+lg(v_leftButtonLabel)+'</a> &nbsp; ';
		}
		if (v_middleLabel!='')
		{
			l_s+=v_middleLabel;
		}
		if (v_rightButtonCode!='')
		{
			l_s+=' &nbsp; <a href="#" onclick=\''+v_rightButtonCode+'\'>'+lg(v_rightButtonLabel)+' '+$p.img('ico_next3.gif',8,11,'','imgmid')+'</a>';
		}
		l_s+='</div>';

		return l_s;
	},
	/*
		Function: $p.html.buildFeatureHeader
                                 Build the header of a feature page
                                 
		Parameters:

			 v_content : hash of parameters
	*/
	buildFeatureHeader: function(v_content)
	{
		var l_s = $p.html.roundBox('<table cellpadding="5" cellspacing="0" width="100%" class="header">'
			+ '<tr>'
			+ ((v_content['image']=='' || v_content['image']==indef) ? ''
                                                                     : '<td rowspan="2" width="80" valign="top">'
                                                                        + '<div class="picture_image_big">'
                                                                        + '<img src="'+v_content['image']+'" ' + (v_content['imageId'] ? 'id="' + v_content['imageId'] + '"' : '') + ' />'
                                                                        + '</div>'
                                                                        + '<div class="picture_frame_white_big"> '
                                                                        + (v_content['imageOption'] && v_content['imageOption'] != '' ? v_content['imageOption'] : '')
                                                                        + '</div>'
                                                                        + '</td>'
            )
			+ '<td valign="top">'
			+ (v_content['title'] ? '<h2>' + v_content['title'] + '</h2>' : '')
            + (v_content['menu'] == indef ? '' : v_content['menu'])
            + '</td>'
			+ '</tr>'
			+ '</table>'
            ,'#fff'
            ,'100%'
            ,'#1A607C');
			
		return l_s;
	},
	/*
		Function: $p.html.buildFeatureMenu
                                 Build the menu of a feature page
                                 
		Parameters:

			 v_selOption : ID of the selected option
			 v_options : hash of the options
	*/
	buildFeatureMenu: function(v_selOption,v_options)
	{
		var l_s='<div class="menu">'
			+'<ul id="featureMenu">';
		for (var i=0;i<v_options.length;i++)
		{
			l_s+='<li class='+(v_selOption==v_options[i].id ? '"selected"' : '"notselected" onclick="'+v_options[i].fct+'"')+'>'
			+((v_options[i].icon==indef || v_options[i].icon=='') ? '' : $p.img(v_options[i].icon,indef,indef,'','imgmid'))
			+' '+v_options[i].label
			+'</li>';
		}
		l_s+='</ul>'
			+'</div>';

		return l_s;
	},
    buildFeatureSubMenu: function(l_content)
	{
		var l_s='<div class="submenu">'
			+ l_content
			+'</div>';

		return l_s;
	},
	/*
		Function: $p.html.roundBox
                                 Build a rounded box
                                 
		Parameters:

			 v_content : content of the box
			 v_bgColor : background color of the box
			 v_width : width of the box
             v_borderColor: border color (optional)
	*/
	roundBox: function(v_content,v_bgColor,v_width,v_borderColor)
	{
		if (v_bgColor == indef)
			v_bgColor = '#fff';
        if (v_width == indef)
        {
            v_width = '400px';
        }

		return '<div class="raised" style="width: '+v_width+';">'
			+ '<b class="b1"'+(v_borderColor == indef ? '' : ' style="background: '+v_borderColor+';"')+'></b>'
			+ '<b class="b2" style="background: '+v_bgColor+';'+(v_borderColor == indef ? '' : 'border-color: '+v_borderColor+';')+'"></b>'
			+ '<b class="b3" style="background: '+v_bgColor+';'+(v_borderColor == indef ? '' : 'border-color: '+v_borderColor+';')+'"></b>'
			+ '<b class="b4" style="background: '+v_bgColor+';'+(v_borderColor == indef ? '' : 'border-color: '+v_borderColor+';')+'"></b>'
			+ '<div class="boxcontent" style="background: '+v_bgColor+';'+(v_borderColor == indef ? '' : 'border-color: '+v_borderColor+';')+'">'
			+ v_content
			+ '</div>'
			+ '<b class="b4b" style="background: '+v_bgColor+';'+(v_borderColor == indef ? '' : 'border-color: '+v_borderColor+';')+'"></b>'
			+ '<b class="b3b" style="background: '+v_bgColor+';'+(v_borderColor == indef ? '' : 'border-color: '+v_borderColor+';')+'"></b>'
			+ '<b class="b2b" style="background: '+v_bgColor+';'+(v_borderColor == indef ? '' : 'border-color: '+v_borderColor+';')+'"></b>'
			+ '<b class="b1b"'+(v_borderColor == indef ? '' : ' style="background: '+v_borderColor+';"')+'></b>'
			+ '</div>';
	},
    /*
                Function: $p.html.breadCrumbs
                
                  parameters:
                  
                            v_items - 
        */
	breadCrumbs: function(v_items)
	{
		var l_s = '';
		for (var i = 0;i < v_items.length;i++)
		{
			if (  v_items[i].link == '' && v_items[i].fct == '') {
				l_s+= v_items[i].label + ' ';
			}
			else 
            {
				l_s+= '<a';
				if (v_items[i].link == '') {
					l_s+= ' href="#"';
				}
				else {
					l_s+= ' href="'+v_items[i].link+'"';
				}
				if (v_items[i].fct != '') {
					l_s+= ' onclick="'+v_items[i].fct+'"';
				}
				if (v_items[i].id != '') {
					l_s+= ' id="'+v_items[i].id+'"';
				}
				l_s+= '>'
					+ v_items[i].label
					+ '</a> ';
			}
			if (i < (v_items.length - 1)) {
				l_s+= '> ';
			}
		}

		return l_s;
	},
	buildButton: function(v_action, v_label)
	{
		var l_s = ''
			+ '<a class="whitebtn" href="#" onclick="' + v_action + '">'
			+ '<span>'
			+ v_label
			+ '</span>'
			+ '</a>';
			//$p.html.roundBox('<a href="#" onclick="' + v_action + '">' + v_label + '</a>','#fff','70px','#C9C9C9');
		
		return l_s;
	},
	contextualMenuTimer: 0,
	/*
		Function: $p.html.buildContextualMenu
                                 Build the contextual menu
                                 
		Parameters:

				e : event object
				v_options : array containing the options displayed in the menu
		
		Example :
			$p.html.buildContextualMenu(e,[
					{'title':'user id','fct':"alert($p.app.user.id)"},
					{'title':'user name','fct':"alert($p.app.user.name)"}
				]
			);
	*/
	buildContextualMenu: function(e,v_options)
	{
		if (v_options == indef || v_options == '')
			$p.show('contextual_menu', 'none');
		else
		{
			if ($('contextual_menu') == null)
			{	
				var l_div = new Element('div', { 'id': 'contextual_menu' } );
				document.body.appendChild(l_div);	
			}
			else l_div = $('contextual_menu');
			
			var l_s = '';
			// build the contextual menu options
			for (var i = 0; i < v_options.length; i++)
			{
				l_s += '<a href="' + (v_options[i].href || '#') + '" onclick="$p.html.buildContextualMenu();' + v_options[i].fct + '">'
					+ v_options[i].title
					+ '</a>';
			}
			$p.print('contextual_menu', l_s);
	
			if (e==indef && window.event) e=window.event;
			var posLeft=($p.navigator.IE?(e.clientX + document.documentElement.scrollLeft)-20:e.pageX-10);
			var posTop=($p.navigator.IE?(e.clientY + document.documentElement.scrollTop)-20:e.pageY-10);

			l_div.setStyle("left",posLeft+"px");
			l_div.setStyle("top",posTop+"px");

			$p.show('contextual_menu',"block");
			var l_boxWidth=l_div.offsetWidth;
			var l_boxHeight=l_div.offsetHeight;
			// if a part of the box is outside the screen
			var l_outScreen=0;
			if (posLeft > (Window.getWidth()+document.documentElement.scrollLeft-l_boxWidth)) l_outScreen++;
			if (posTop > (Window.getHeight() + document.documentElement.scrollTop-l_boxHeight)) l_outScreen+=2;
			if (l_outScreen==1){l_div.setStyle("left",(Window.getWidth()+document.documentElement.scrollLeft-l_boxWidth-20)+"px");}
			if (l_outScreen==2){l_div.setStyle("top",(Window.getHeight()+document.documentElement.scrollTop-l_boxHeight-20)+"px");}
			if (l_outScreen==3)
			{
				l_div.setStyle("left",(Window.getWidth()+document.documentElement.scrollLeft-l_boxWidth-20)+"px");
				l_div.setStyle("top",(posTop-l_boxHeight-15)+"px");
			}
			
			// reset the closure timer
			$p.html.resetContextualMenuTimer();
		}
	},
	resetContextualMenuTimer: function()
	{
		clearTimer($p.html.contextualMenuTimer);
		$p.html.contextualMenuTimer = setTimeout("$p.html.buildContextualMenu()",3500);	
	}
}


//************************************ HTML FORM FUNCTIONS ***************************************************************************************************************
/*
    Class: $p.app.html.form
         HTML form functions
*/
$p.html.form={
	/*
		Function: $p.app.html.form.buildEnum
                                 Build the enum field
                                 
		Parameters:

			 parameters (array) -  type, name, def(value), i('inp'+i = td id to inject)
                                 l_pref - XML object
	*/
    buildEnum:function(parameters,l_pref)
    {
        var inputField="";
        var j=0;
  
        inputField="<select id='"+parameters["id"]+"' name='"+parameters["name"]+"'>";
        while(l_pref.getElementsByTagName("EnumValue")[j])
        {
            var l_opt=l_pref.getElementsByTagName("EnumValue")[j];
            var l_optValue=$p.ajax.getProp(l_opt,"value","str",false,"");
           
            inputField+="<option value='"+l_optValue+"'"+((l_optValue==parameters["value"])?" selected='selected'":"")+">"+lg($p.ajax.getProp(l_opt,"display_value","str",false,l_optValue))+"</option>";
            j++;
        }
        inputField+="</select>";
        return inputField;
        
    },
	/*
		Function: $p.app.html.form.buildInput
                                 Build the input field
                                 
		Parameters:

			 parameters (array) -  type, name, value, id('inp'+i = td id to inject)
	*/   
    buildInput:function(parameters)
    {
        var sizefield = 24;
		var inputField="";
        var readOnlyCondition="";
        var boolCondition= "";
        var type="text";
        
        if (parameters["type"]=='password' ) type="password";       
        if (parameters["type"]=='hidden' ) type="hidden";       
        if (parameters["type"]=='readonly') readOnlyCondition = ($p.navigator.IE?" disabled='disabled'":"");

        if (parameters["type"] == "string") {
            var reg=/"/g;
            parameters["value"] = parameters["value"].replace(reg, "'");
        }
        inputField="<input type='"+type+"' id='"+parameters["id"]+"' name='"+parameters["name"]+"' value=\""+parameters["value"]+"\" size='"+sizefield+"' "+readOnlyCondition+" />";

        return inputField;
    },
	/*
		Function: $p.app.html.form.buildCheckbox
                                 Build the checkbox
                                 
		Parameters:

			 parameters (array) -  type, name, value, id('inp'+i = td id to inject)
	*/   
    buildCheckbox:function(parameters)
    {        
		var inputField,readOnlyCondition,boolCondition="";
        var type="checkbox";
        var boolCondition = ((parameters["value"]==1)?" checked='checked'":"");
        //build the input field to inject
        inputField="<input type='"+type+"' id='"+parameters["id"]+"' name='"+parameters["name"]+"' "+boolCondition+" />";
        //injection
        return inputField;
        //$(id).innerHTML+=inputField;
    }       
}



/*
    Class: p_table
*/

var p_table={
	name:"default",
	title:"",
	headers:[],
	rows:[],
	footer:"",
	container:"",
	order:0,
	asc:false,
	filter:[],
	width:"100%",
	saveincookie:false,
	/*
		p_table.headerObj : create a column header
		Parameters:

			name - database field name
			label - header label (writen in the header)
			filtered - define if the column can be filtered true/false
	*/
	headerObj:function(name,label,filtered,width,sorted)
	{
		this.name=name;
		this.label=label;
		this.filtered=filtered;
		this.width=(width==indef)?"":width;
		this.sorted=(sorted==indef)?true:sorted;
	},
	/*
		p_table.row : create a new row 
	*/
	row:function()
	{
		this.columns=[];
	},
	/*
		p_table.cell : create a new cell
		Parameters:

			val - cell value (extracted from DB)
			label - label displayed in the cell
	*/
	cell:function(val,label)
	{
		this.val=val;
		this.label=(label==indef?val:label);
	},
	refresh:indef,
	/*
		p_table.reset : reset the table 
	*/
	reset:function()
	{
		p_table.headers.length=0;
		p_table.rows.length=0;
		p_table.filter.length=0;
		p_table.order=0;
		p_table.asc=false;
	},
	/*
		p_table.init : init the table 
	*/
	init:function()
	{
		if (p_table.saveincookie)
		{
			if ($p.cookie.get(p_table.name+"order")!="") p_table.order=$p.cookie.get(p_table.name+"order");
			if ($p.cookie.get(p_table.name+"asc")!="") p_table.asc=($p.cookie.get(p_table.name+"asc")==1?true:false);
			if ($p.cookie.get(p_table.name+"filter")!="") p_table.filter=($p.cookie.get(p_table.name+"filter")).split(" AND ");
		}
	},

	/*
		p_table.show : display the table 
	*/
	show:function(v_start,v_count)
	{
		if (v_start==indef) v_start=0;
		if (v_count==indef) v_count=p_table.rows.length-v_start;
		//limit to the items loaded
		var l_nbToDisplay=$p.min(p_table.rows.length-v_start,v_count);

		var l_s='<table cellpadding="3" cellspacing="0" border="1" bordercolor="#c6c3c6" width="'+p_table.width+'">';
		if (p_table.title!="") l_s+="<tr><td colspan='"+p_table.headers.length+"' bgcolor='#c6c3c6'>"+p_table.title+"</td></tr>";
		l_s+="<tr>";
		for (var i=0;i<p_table.headers.length;i++)
		{
			l_s+="<th bgcolor='#c6c3c6'"+(p_table.headers[i].width==""?"":" width='"+p_table.headers[i].width+"'")+">";
			if (p_table.headers[i].sorted) l_s+="<a href='#' onclick='p_table.sortAndRefresh("+i+","+((p_table.order==i && !p_table.asc)?"true":"false")+")'>";
			l_s+=p_table.headers[i].label+(p_table.headers[i].sorted?" "+(p_table.order==i?(p_table.asc?$p.img("ico_up_arrow.gif"):$p.img("ico_down_arrow.gif")):""):"");
			if (p_table.headers[i].sorted) l_s+="</a>";
			l_s+="</th>";
		}
		l_s+="</tr>";

		for (var i=v_start;i<v_start+l_nbToDisplay;i++)
		{
			l_s+="<tr>";
			for (var j=0;j<p_table.rows[i].columns.length;j++)
			{
				l_s+="<td>"+p_table.rows[i].columns[j].label+"</td>";
			}
			l_s+="</tr>";
		}
		l_s+="<tr><td colspan='"+p_table.headers.length+"' bgcolor='#c6c3c6'><center>";
		if (v_start>0) l_s+="<a href='#' onclick='p_table.show("+$p.max(0,(v_start-v_count))+","+v_count+");'>"+$p.img("ico_previous3.gif",indef,indef,"","imgmid")+" "+lg("previous")+"</a> &nbsp; ";
		if (v_start+v_count<p_table.rows.length) l_s+=" &nbsp; <a href='#' onclick='p_table.show("+$p.min(p_table.rows.length,(v_start+v_count))+","+v_count+");'>"+lg("next")+" "+$p.img("ico_next3.gif",indef,indef,"","imgmid")+"</a>";
		l_s+="</center></td></tr>"
		if (p_table.footer!="") l_s+="<tr><td colspan='"+p_table.headers.length+"' bgcolor='#c6c3c6'>"+p_table.footer+"</td></tr>";
		$p.print(p_table.container,l_s);
	},
	/*
		p_table.sortAndRefresh : sort the table
		Parameters:

			v_order - id of the column to sort
			v_asc - true=ascendant order
			v_start - beginning of the display
			v_count - number of items to display
	*/
	sortAndRefresh:function(v_order,v_asc,v_start,v_count)
	{
		if (v_order!=indef) p_table.order=v_order;
		if (v_asc!=indef) p_table.asc=v_asc?true:false;
		p_table.rows.sort(p_table.sortrule);
		p_table.show(v_start,v_count);
		$p.cookie.write(p_table.name+"order="+p_table.order)
		$p.cookie.write(p_table.name+"asc="+(p_table.asc?1:0));
	},
	sortrule:function(v_a,v_b)
	{
		var v_reverse=p_table.asc?-1:1;
		if ($p.string.lc($p.string.removeTags(v_a.columns[p_table.order].label))<$p.string.lc($p.string.removeTags(v_b.columns[p_table.order].label))) return -1*v_reverse;
		if ($p.string.lc($p.string.removeTags(v_a.columns[p_table.order].label))>$p.string.lc($p.string.removeTags(v_b.columns[p_table.order].label))) return 1*v_reverse;
		return 0; 
	},
	
	/*
		p_table.displayFitler : display the column data filter
		Parameters:

			 container div id
	*/
	displayFilter:function(v_div)
	{
		var l_s="";
		for (var i=0;i<p_table.filter.length;i++)
		{
			l_s+=p_table.filter[i]+" <a href='#' onclick='p_table.remFilter("+i+");return false;'>"+$p.img("ico_close.gif",12,11,lg("suppress"),"imgmid")+"</a> &nbsp;";
		}
		l_s+="<br /><form name='filter' onsubmit='p_table.addFilter(this);return false;'><select name='field' onchange='p_table.fillFilter(this.value)'>";
		var l_firstFiltered;
		for (var i=0;i<p_table.headers.length;i++)
		{
			if (p_table.headers[i].filtered)
			{
				l_s+="<option value=\""+i+"\">"+p_table.headers[i].label+"</option>";
				if (l_firstFiltered==indef) l_firstFiltered=i;
			}
		}
		l_s+="</select>";
		l_s+=" <select name='comparator'><option value='='>egal à</option><option value='!='>différent de</option><option value='<'><</option><option value='>'>></option><option value='<='><=</option><option value='>='>>=</option></select>";
		l_s+=" <select name='val'></select> <input type='submit' value='Ajouter ce filtre' /></form>";
		$p.print(v_div,l_s);
		p_table.fillFilter(l_firstFiltered);
	},
	/*
		p_table.fillFilter : fill filter input 
	*/
	fillFilter:function(v_id)
	{
		document.forms.filter.val.options.length=0;
		var l_options=[],l_optionsLabel=[];
		for (var i=0;i<p_table.rows.length;i++)
		{	
			if (!$p.array.find(l_options,p_table.rows[i].columns[v_id].val))
			{
				l_options.include(p_table.rows[i].columns[v_id].val);
				l_optionsLabel.push($p.string.removeTags(p_table.rows[i].columns[v_id].label));
			}	
		}
		for (var i=0;i<l_options.length;i++)
		{
			document.forms.filter.val.options[document.forms.filter.val.options.length] = new Option(l_optionsLabel[i],l_options[i]);
		}
	},
	/*
		p_table.addFilter : add a new filter for table information
		Parameters:

			 v_form - form containing filter value
	*/
	addFilter:function(v_form)
	{
		p_table.filter.push(p_table.headers[v_form.field.value].name+" "+v_form.comparator.value+" '"+v_form.val.value+"'");
		$p.cookie.write(p_table.name+"filter="+p_table.filter.join(" AND "));
		p_table.refresh();
	},
	/*
		p_table.remFilter : remove a filter 
	*/
	remFilter:function(v_i)
	{
		p_table.filter.splice(v_i,1);
		$p.cookie.write(p_table.name+"filter="+p_table.filter.join(" AND "));
		p_table.refresh();
	}
}





/*
	Function: correctMailEncoding 
    
                correct emails content encoding chars
	
            Parameters:

			 email content (! need to be lower case)
	
	Returns:
			 corrected content
*/
function correctMailEncoding(v_s,v_convertHTML)
{
	if (v_s.indexOf("?utf-8?") != -1)
	{
		v_s=v_s.replace(/\=\?utf\-8\?q\?/g,"");
		//v_s=v_s.replace(/\=\?UTF\-8\?Q\?/g,"");
		v_s=v_s.replace(/\?\= /g,"");
		v_s=v_s.replace(/\_/g," ");
		v_s=v_s.replace(/\?\=/g,"");
	}
	else if (v_s.indexOf("-8859-1?") != -1)
	{
		//v_s=v_s.replace(/\=\?ISO-8859-1\?Q\?/g,"");
		v_s=v_s.replace(/\=\?iso-8859-1\?q\?/g,"");
		v_s=v_s.replace(/\?\= /g,"");
		v_s=v_s.replace(/\_/g," ");
		v_s=v_s.replace(/\?\=/g,"");
	}
	v_s=v_s.replace(/\=e9/g,"é");
	v_s=v_s.replace(/\=e0/g,"à");
	v_s=v_s.replace(/\=e8/g,"è");
	v_s=v_s.replace(/\=e7/g,"ç");
	v_s=v_s.replace(/\=f9/g,"ù");
	v_s=v_s.replace(/\=ea/g,"ê");
	v_s=v_s.replace(/\=e2/g,"â");
	v_s=v_s.replace(/\=f4/g,"ô");
	v_s=v_s.replace(/\=ee/g,"î");
	v_s=v_s.replace(/\=fb/g,"û");
	v_s=v_s.replace(/\=f6/g,"ö");
	v_s=v_s.replace(/\=fc/g,"ü");
	v_s=v_s.replace(/\=ef/g,"ï");
	v_s=v_s.replace(/\=e4/g,"ä");
	v_s=v_s.replace(/\=eb/g,"ë");
	v_s=v_s.replace(/\=28/g,"(");
	v_s=v_s.replace(/\=29/g,")");
	v_s=v_s.replace(/\=20/g," ");
    v_s=v_s.replace(/\=2d/g,"-");
	v_s=v_s.replace(/\=3a/g,":");
	v_s=v_s.replace(/\=25/g,"€");
	v_s=v_s.replace(/\=ba/g,"°");
	v_s=v_s.replace(/=c3=a9/g,"é");
	v_s=v_s.replace(/=c3=a8/g,"è");
	v_s=v_s.replace(/=c3=a0/g,"à");
	v_s=v_s.replace(/=c3=a2/g,"â");
	v_s=v_s.replace(/=c3=aa/g,"ê");
	v_s=v_s.replace(/=c3=ae/g,"î");
	v_s=v_s.replace(/=c3=b4/g,"ô");
	v_s=v_s.replace(/=c3=bb/g,"û");
	v_s=v_s.replace(/=c3=b9/g,"ù");
	v_s=v_s.replace(/=c3=bc/g,"ü");
	v_s=v_s.replace(/=c3=a7/g,"ç");
	v_s=v_s.replace(/=09/g," ");
	v_s=v_s.replace(/\=\n/g,"");
	while (v_s.indexOf("  ") != -1) v_s=v_s.replace(/  /g," ");
	v_s=v_s.replace(/\n /g,"\n");
	while (v_s.indexOf("\n\n") != -1) v_s=v_s.replace(/\n\n/g,"\n");
	if (v_convertHTML) v_s=v_s.replace(/\n/g,"<br />");
	v_s=v_s.replace(/\r/g,"");
	return v_s;
}

/*
	Function: notifyByEmail 
                send email to user
	
            Parameters:

		v_address - email addresses (string or array)
		v_title - email title
		v_description - email message
		v_from (optional) - sender email
		v_decode - define if an UTF8 decode needs to be done
*/
function notifyByEmail(v_address,v_title,v_description,v_from)
{
	var l_address="";
	if (typeof(v_address)=="string" && v_address!="")
	{
		l_address="em0="+v_address+"&";
	}
	else
	{
		for (var i=0;i<v_address.length;i++)
		{
			l_address+="em"+i+"="+v_address[i]+"&";
		}
	}
	if (l_address!="")
	{
		$p.ajax.call(posh["scr_sendemail"],
			{
				'type':'execute',
				'variables': l_address 
							+ "title=" + $p.string.esc(v_title)
							+ "&desc="+$p.string.esc(v_description)
							+ "&from=" + $p.string.esc((v_from==indef ? $p.app.user.email : v_from)),
				'alarm':true
			}
		);
	}
	return false;
}
/*
	reset_rand : reset the rand variable
*/
function reset_rand()
{
	rand=$random(0,10000).toInt();
}
function getXMLprop(v_item,v_name,v_type,v_required,v_default){return $p.ajax.getProp(v_item,v_name,v_type,v_required,v_default);}
function getXMLval(v_item,v_name,v_type,v_required,v_default){return $p.ajax.getVal(v_item,v_name,v_type,v_required,v_default);}
var p_plugin={open:function(){return $p.plugin.open();},init:function(v_title,v_id){return $p.plugin.init(v_title,v_id);},menu:function(v_elemts,v_selected){return $p.plugin.menu(v_elemts,v_selected);},wait:function(){return $p.plugin.wait();},content:function(v_content){return $p.plugin.content(v_content);},hide:function(){return $p.plugin.hide();},clear:function(){return $p.plugin.clear();},useWidget:function(){return $p.plugin.useWidget();}}
var p_app={openHome:function(v_prof){return $p.app.openHome(v_prof);}}
/*
	_IG_AdjustIFrameHeight : update module height based on its content
*/
function _IG_AdjustIFrameHeight()
{
    //function desactivated for opera
    if (!Browser.Engine.presto)
    {
    	var l_height;
    	if (document.height){
    		l_height=document.height;
    	}
    	else if (document.all){
    		if (document.compatMode && document.compatMode != 'BackCompat'){
    			l_height=document.documentElement.scrollHeight + 5;
    		}
    		else{
    			l_height = document.body.scrollHeight + 5;
    		}
    	} 
    	if (navigator.appName=="Netscape"){
    		top.outerHeight=l_height;
    	}
    	else top.resizeTo(400,l_height);
    }
}
/*
	Function: _IG_SetTitle 
                change widget title
	
        Parameters:

			 widget new title
*/
function _IG_SetTitle(title)
{
}
/*
	_IG_Prefs : manage Modules preferences
	Parameters:

			 uniq ID of the module
*/
function _IG_Prefs(uniq)
{
	if (uniq != indef && uniq.indexOf('_') != -1)
	{
		uniq = uniq.split("_")[0];
	}
	this.uniq=uniq;
	this.id=$p.app.widgets.uniqToId(uniq);
	this.vars=tab[$p.app.tabs.sel].module[this.id].vars;
	this.getString=getString;
	this.getInt=getInt;
	this.getBool=getBool;
	this.set=setPrefVal;
	this.open=openPref;
}
/*
	getString : get string value of a module parameter
	Parameters:

			 v_var - 
*/
function getString(v_var)
{
	return $p.string.getVar(this.vars,v_var);
}
/*
	getInt : get integer value of a module parameter
	Parameters:

			 v_var -
*/
function getInt(v_var)
{
	return ($p.string.getVar(this.vars,v_var)).toInt();
}
/*
	getBool : get boolean value of a module paramter
	Parameters:

			 v_var -
*/
function getBool(v_var)
{
	return ($p.string.getVar(this.vars,v_var)==1?true:false);
}
/*
	setPrefVal : define parameter value
	Parameters:

		v_var -   
		v_value - new value for this parameter
*/
function setPrefVal(v_var,v_value)
{
	tab[$p.app.tabs.sel].module[this.id].changeVar(v_var,v_value);
	//avoid this process in testmodule
	if ((windowLocationObject.href).indexOf(posh["testmodule"]) == -1)
        $p.app.widgets.param.getModuleParam(this.id);
}
function openPref(){}
/*
	_IG_Tabs : tabs management in modules
	Parameters:

		v_id - module ID
		v_selTab - selected tab
*/
function _IG_Tabs(v_id,v_selTab)
{
	this.moduleId=v_id;
	this.selTab=v_selTab;
	this.addTab=addTab;
	this.addDynamicTab=addDynamicTab;
	this.setSelectedTab=setSelectedTab;
	this.moveTab=moveTab;
	this.tabsContainer=null;
	this.ulObj=null;
}
/*
	addTab : add a new tab in module
	Parameters:

		v_name - name of the tab
		v_divId - ID of the div containing tab information
		v_fct - function called on tab opening
*/
function addTab(v_name,v_divId,v_fct)
{
	//define default tab if not already defined
	if (this.selTab==indef) this.selTab=v_name;
	//create tabs div if not already existing
	if (this.tabsContainer==null)
	{
		this.tabsContainer = new Element('div', { 'id': 'tabsdiv' } );	 
		document.body.appendChild(this.tabsContainer);
	}
	//create content div if not already existing
	if (v_divId==indef) v_divId="contentdiv";
	if ($(v_divId)==null)
	{
		l_obj = new Element('div', { 'id': v_divId } );	 
		document.body.appendChild(l_obj);
	}
	else
	{
		var l_obj=$(v_divId);
	}
	//create ul obj if not already existing
	if (this.ulObj==null)
	{
		this.ulObj = new Element('ul', { "class": "tablist" } );	
		this.tabsContainer.appendChild(this.ulObj);
	}
	//add the new tab
	var l_liObj = new Element('li', { "class": (this.selTab==v_name)?"tabsel":"tab", "id": v_name } );			  
	var l_aObj = new Element('a', 
		{
			'events': {
					'mouseup': function(){
					changeSelectedTab(this.title,this.main);
					this.fct(this.selDiv);}
					  },
			'href': 'javascript:void(null);',
			'main': this
		}
	);
	l_aObj.fct = v_fct;
	l_aObj.selDiv = v_divId;
	l_aObj.title = v_name;
	l_aObj.main = this;
    l_aObj.appendChild(document.createTextNode(v_name));			
	l_liObj.appendChild(l_aObj);
	this.ulObj.appendChild(l_liObj);
	if (this.selTab==v_name) v_fct(v_divId);
	
	return l_obj;
}
/*
	addDynamicTab
*/
function addDynamicTab(v_name,v_fct)
{
	addTab(v_name,indef,v_fct);
}
/*
	setSelectedTab : select a tab
	Parameters:

			 ID of the tab selected
*/
function setSelectedTab(v_index)
{
	//define selected tab
	for (var i=0;i<this.ulObj.childNodes.length;i++)
	{
		var l_node=this.ulObj.childNodes[i];
		l_node.className=(i==v_index?"tabsel":"tab");
	}
}
function changeSelectedTab(v_name,v_obj)
{
	v_obj.selTab=v_name;
	for (var i=0;i<v_obj.ulObj.childNodes.length;i++)
	{
		var l_node=v_obj.ulObj.childNodes[i];
		if (l_node.id==v_name) v_obj.setSelectedTab(i);
	}
}
function moveTab(){}

/*
	_IG_Callback : module callback function
*/
function _IG_Callback(v_fct,v1,v2,v3,v4,v5)
{
	var args=arguments;
	return function()
	{
		var l_vars=[];
		for(var i=0;i<arguments.length;i++)
		{
			l_vars[l_vars.length]=arguments[i];
		}
		for(var i=1;i<args.length;i++)
		{
			l_vars[l_vars.length]=args[i];
		}
		v_fct.apply(null,l_vars);
	}
}
/*
	createMyModule : link to modules tutorial tool
*/
function createMyModule()
{
	if ($p.app.user.id==0)  {
		$p.app.alert.show(lg("msgTutorialConn"));
	}
	else    {
		$p.url.openLink("../tutorial/");
	}
	return false;
}
/*
	dirOptxxxx : manage modules directory selections
	Parameters:

		v_id - directory ID
		v_level - directory depth level
*/
function dirOptOver(v_id)
{
	if ($("dir"+v_id)&&($("dir"+v_id)).className=="diropti") $p.setClass("dir"+v_id,"diropta");
}
function dirOptOut(v_id)
{
	if ($("dir"+v_id)&&($("dir"+v_id)).className=="diropta") $p.setClass("dir"+v_id,"diropti");
}
function dirOptSel(v_id,v_level)
{
	$p.setClass("dir"+v_id,"diropts");
	if (dirOptSelId[v_level]!=indef && dirOptSelId[v_level]!=v_id){$p.setClass("dir"+dirOptSelId[v_level],"diropti");}
	dirOptSelId[v_level]=v_id;
}
function catOptOver(v_id,v_secured,v_prefix)
{
	if (v_prefix == indef) v_prefix = '';
	
	if ($(v_prefix + 'dir' + v_id)&&($(v_prefix + 'dir' + v_id)).className=="catopt"+(v_secured==1?"s":"")+"i")
		$p.setClass(v_prefix + 'dir' + v_id,"catopt"+(v_secured==1?"s":"")+"a");
}
function catOptOut(v_id,v_secured,v_prefix)
{
	if (v_prefix == indef) v_prefix = '';
	
	if ($(v_prefix + 'dir' + v_id)&&($(v_prefix + 'dir' + v_id)).className=="catopt"+(v_secured==1?"s":"")+"a")
		$p.setClass(v_prefix + 'dir' + v_id,"catopt"+(v_secured==1?"s":"")+"i");
}
function catOptSel(v_id,v_level,v_secured,v_prefix)
{
	if (v_prefix == indef)
	{
		v_prefix = '';
	}
	
	$p.setClass(v_prefix + "dir" + v_id,"catopt"+(v_secured==1?"s":"")+"s");
	if (dirOptSelId[v_prefix + v_level]!=indef && dirOptSelId[v_prefix + v_level]!=v_id)
		$p.setClass(v_prefix + "dir" + dirOptSelId[v_prefix + v_level],"catopt"+(dirOptSelSec[v_prefix + v_level]==1?"s":"")+"i");
		
	dirOptSelId[v_prefix + v_level] = v_id;
	dirOptSelSec[v_prefix + v_level] = v_secured;
}
/*
	hideBox : hide horizontal menu box
*/
function hideBox()
{
	$p.print("box","");
	$p.show("box","none");
	//widgetDecalY=0;
	showBoxStatus=false;
	$p.app.widgets.place($p.app.tabs.sel);
}
/*
	hideAllBox : hide all menus
*/
function hideAllBox()
{
	hideBox();
	//if (__menuposition=="v"){$p.app.menu.hide();}
}
function openmod(v_id,v_vars,v_type,v_secured){return $p.app.widgets.open(v_id,v_vars,v_type,v_secured);}
function closeNewMod(v_type){return $p.app.widgets.close(v_type);}
/*
	additionalMod : check if an aditional module needs to be displayed
*/
function additionalMod()
{
	if ($p.string.getVar(windowLocationObject.search.substring(1),"open"))
	{
		var l_vars=($p.string.getVar(windowLocationObject.search.substring(1),"vars"))?$p.string.getVar(windowLocationObject.search.substring(1),"vars"):"";
		$p.app.widgets.open($p.string.getVar(windowLocationObject.search.substring(1),"open"),l_vars);
	}
}
function _IG_Analytics(){}
/*
	_IG_RegisterOnloadHandler : manage modules onload event
	Parameters:

			 function called when module is loaded
*/
function _IG_RegisterOnloadHandler(v_fct)
{
	window.onload=v_fct;
}
/*
	_IG_FetchContent : load HTML content from a file
	Parameters:

		v_url - file loaded
		v_fct - function called when file is loaded
*/
function _IG_FetchContent(v_url,v_fct)
{
	$p.ajax.call(v_url,
		{
			'type':'load',
			'callback':
			{
				'function':v_fct
			},
			'source':'html',
			'method':'GET'
		}
	);
}
function _IG_FetchXmlContent(v_url,v_fct)
{
	$p.ajax.call(v_url,
		{
			'type':'load',
			'callback':
			{
				'function':v_fct
			},
			'source':'xml',
			'method':'GET'
		}
	);
}
function _IG_FetchFeedAsJSON(v_url,v_fct,v_entries,v_summaries)
{
	if (v_entries==indef) v_entries=5;
	if (v_summaries==indef) v_summaries=false;
	$p.ajax.call(v_url,
		{
			'type':'load',
			'callback':
			{
				'function':getRssFromXml,
				'variables':
				{
					'function':v_fct,
					'entries':v_entries,
					'summary':v_summaries
				}
			},
			'source':'xml',
			'method':'GET'
		}
	);
}
function _toggle(v_el)
{
	if (v_el.style.display=='block')
	{
		v_el.style.display='none';
	}
	else
	{
		v_el.style.display='block';
	}
}
function _IG_GetImage(v_url)
{
	return v_url;
}
function _IG_GetCachedUrl(v_url)
{
	return v_url;
}
function _IG_EmbedFlash(swf_url, swf_container, opt_params)
{
	var so = new SWFObject(swf_url, "flash", "100%", "100%", "6");
	for(opt_param in opt_params)
	{
		so.addParam(opt_param,opt_params[opt_param]);
	}
    so.write(swf_container);
}
function _IG_GetFlashMajorVersion(){}
function getRssFromXml(response,vars)
{
	var feed={};
	feed.Title=$p.ajax.getVal(response,"title","str",false,"no title");
	feed.Link=$p.ajax.getVal(response,"link","str",false,"");
	feed.Author=$p.ajax.getVal(response,"author","str",false,"");
	feed.Description=$p.ajax.getVal(response,"description","str",false,"");
	feed.Entry=[];
	var i=0;
	while (response.getElementsByTagName("item")[i] && i<vars[1])
	{
		var result=response.getElementsByTagName("item")[i];
		feed.Entry[i]={};
		feed.Entry[i].Title=$p.ajax.getVal(result,"title","str",false,"no title");
		feed.Entry[i].Link=$p.ajax.getVal(result,"link","str",false,"");
		feed.Entry[i].Summary=($p.ajax.getVal(result,"description","str",false,"")).substr(0,200);
		feed.Entry[i].Date=$p.ajax.getVal(result,"pubdate","str",false,"");
		i++;
	}
	vars[0](feed);
}
/*
	getConfig : Save portal configuration in cookie
*/
function getConfig()
{
	var l_ret="w="+tab[$p.app.tabs.sel].colnb+"&s="+tab[$p.app.tabs.sel].style+"&n="+$p.string.esc($p.app.tabs.currName)+"&t="+tab[$p.app.tabs.sel].showType+"&nb="+tab[$p.app.tabs.sel].newspapernb+"&i="+tab[$p.app.tabs.sel].icon+"&a="+(tab[$p.app.tabs.sel].moduleAlign?"Y":"N");
	for (var i=0;i!=tab[$p.app.tabs.sel].module.length;i++)
	{
		l_ret+="&id"+i+"="+tab[$p.app.tabs.sel].module[i].id+"&pos"+i+"="+tab[$p.app.tabs.sel].module[i].newpos+"&col"+i+"="+tab[$p.app.tabs.sel].module[i].newcell+"&posj"+i+"="+tab[$p.app.tabs.sel].module[i].newposj+"&x"+i+"="+tab[$p.app.tabs.sel].module[i].newx+"&y"+i+"="+tab[$p.app.tabs.sel].module[i].newy+"&var"+i+"="+$p.string.esc(tab[$p.app.tabs.sel].module[i].vars)+"&blocked"+i+"="+tab[$p.app.tabs.sel].module[i].blocked+"&minimized"+i+"="+(tab[$p.app.tabs.sel].module[i].minimized?"1":"0");
	}
	return l_ret;
}
/*
	getAvailPortals : get pages list for a user
*/
function getAvailPortals(v_sess,md5key)
{
    if (typeof(md5key['md5key'])=="undefined") {
        md5key['md5key']='';
    }
	if (v_sess)
	{
		$p.ajax.call(posh["xmltabs"],
			{
				'type':'load',
				'callback':
				{
					'function':showAvailPortals,
                    'variables':
                    {
                        'md5key':md5key['md5key']
                    }
				}
			}
		);
	}
}
/*
	showAvailPortals : display available pages for a user
*/
function showAvailPortals(response,vars)
{
	var l_s="<b>"+lg("selectThePortalDestination")+"</b> :<br />",l_result=response.getElementsByTagName("tab");
	for (var i=0;i<l_result.length;i++)
	{
		if ($p.ajax.getVal(l_result[i],"type","int",false,0)==3 || $p.ajax.getVal(l_result[i],"type","int",false,0)==1)
		{
			l_s+="<br />"+$p.img("ico_right_arrow.gif",6,9)+" <a href='#' onclick='addModToAvailPortal("+$p.ajax.getVal(l_result[i],"number","int",false,1)+",\""+vars['md5key']+"\");'>"+$p.ajax.getVal(l_result[i],"name","str",false,"- ? -")+"<a>";
		}
	}
	$p.print("connectiondiv",l_s+"<br /><br />");
}
/*
	addModToAvailPortals : add a new module for a user page (stored in cookie)
	Parameters:

			 tab DB ID where the module is added
*/
function addModToAvailPortal(v_prof,md5key)
{
    var md5Parameter="";
    if ( typeof(md5key)!="undefined" && md5key!='' ) {
        md5Parameter="&md5="+md5key;
    }
    
	//set current page as the one selected
	$p.cookie.write("currentpage="+v_prof);
	//get feed id for an rss widget
	var l_fid=(tab[$p.app.tabs.sel].module[0].format=='R')?$p.string.getVar(tab[$p.app.tabs.sel].module[0].vars,'pfid'):0;
	$p.url.openLink(posh["scr_config_updateportal"]+"?prof="+v_prof+"&modid="+tab[$p.app.tabs.sel].module[0].id+"&f="+l_fid+"&v="+$p.string.esc(tab[$p.app.tabs.sel].module[0].vars)+md5Parameter);
    $p.url.openLink(posh["mypage"],false);

}
var p_connection={set:function(v_form,v_function,v_type){return $p.app.connection.set(v_form,v_function,v_type);},subscribe:function(v_form,v_function){return $p.app.connection.subscribe(v_form,v_function);},saveMenu:function(){return $p.app.connection.saveMenu();},menu:function(){return $p.app.connection.menu();}}
/*
	MODULE_ID_to_id : get the module array id from the __MODULE_ID__ variable in a 'M' module
	Parameters:

			 __MODULE_ID__
*/
function MODULE_ID_to_id(v_id,v_tab)
{
	var parts=v_id.split("_");
	return $p.app.widgets.uniqToId(parts[0],v_tab);
}
/*
	hideParent : hide parent object of an object
	Parameters:

			 object
*/
function hideParent(v_obj)
{
	v_obj.parentNode.setStyle("display","none");
	v_obj.parentNode.setStyle("display","");
}
/*
	Function: objMove 
                define object position / action during move
                
                initalize : this.canBeReleased on any object
                
	Parameters:
		v_obj - object moved
		v_x - horizontal position of the mouse
		v_y - vertical position of the mouse
		v_parent - parent object if module = tab[v_tab].cols or tab[v_tab].root or if tab = $("tabsframe")
		v_direction - allowed movements - vertical / horizontal / multidim
		v_type : object type (module/tab)
        
        See also:
            <$p.app.widgets.move.set>
*/
function objMove(v_obj,v_x,v_y,v_parent,v_direction,v_type)
{
	var l_nextMod=null;
	var l_x,l_y,l_w,l_h,l_treated=false;
	var l_pond=(v_direction=="multidim")?40:v_obj.offsetHeight;
	var l_lstNb=v_parent.length?v_parent.length:2;
	//is object moving over an existing one
    var params = {'x':v_x,'y':v_y,'parent':v_parent,'direction':v_direction,'type':v_type};
    var cannotBeReleased = false;
    var curcellid = ((v_obj.parentNode.id).replace(/cell/,"")).replace(/_\d+/,"");
    
    //exception if widget moved from a popup (only cell0 exists)
    var cpt = (l_lstNb == 2 && tab[$p.app.tabs.sel].type != 1)         ?       0               :       1;
    var cptEnd = (l_lstNb == 2 && tab[$p.app.tabs.sel].type != 1)      ?       l_lstNb-1       :       l_lstNb;    

	for(var j=cpt;j<cptEnd;j++)
	{
		var l_lst=v_parent.length?v_parent[j].obj:v_parent;
		for(var i=0;i<l_lst.childNodes.length;i++)
		{
			var l_node=l_lst.childNodes[i];
			l_x=l_node.pagePosLeft;
			l_y=l_node.pagePosTop;
			l_w=l_node.offsetWidth;
			l_h=l_node.offsetHeight;
			if (v_x>l_x && v_x<(l_x + l_w) && v_y>l_y && v_y<(l_y + l_h))
			{
				l_treated=true;
				if (v_y < (l_y + l_pond))
				{
					if (l_node == v_obj.nextSibling && l_node.nextSibling)
					{
						l_nextMod = l_node.nextSibling;
						break;
					}
					else
					{
						l_nextMod = l_node;
						break;
					}
				}
			}
		}
	}
	//if module over a tab WIDGETMOVETOOTHERCOL
	if (!l_treated 
            && v_type=="module" 
            && $p.app.user.id > 0
        )
	{
		var l_id = $p.app.widgets.getModuleId(v_obj);
		if ($p.app.tabs.sel == -1 || tab[$p.app.tabs.sel].module[l_id].blocked == 0)
		{
			var l_tabs=$("tabsframe");
			if (l_tabs!=null)
			for(var i=0;i<l_tabs.childNodes.length;i++)
			{
				var l_node=l_tabs.childNodes[i];
				if (l_node.id=="") continue;
				var l_id=l_node.id.replace(/tab/,"");
				if (l_id==$p.app.tabs.sel) continue;
				//l_x=l_node.pagePosLeft;
				l_x=$p.getPos(l_node,"Left");
				l_y=$p.getPos(l_node,"Top");
				//l_x=l_node.getLeft();
				//l_y=l_node.getTop();
				
				l_w=l_node.offsetWidth;
				l_h=l_node.offsetHeight;
				if (v_x>l_x && v_x<(l_x+l_w) && v_y>l_y && v_y<(l_y+l_h))
				{
					l_treated = true;
					$p.app.tabs.moduleOver(l_id);
					$p.app.widgets.move.chosenCell = 0;
					params['currentcellobj'] = l_node.parentNode;
					params['cellid'] = 1;
					params['tabid'] = l_id;
					params['inpage']=0;

					if ( !$p.app.widgets.move.isMovable('rowsLimited',params) ) {
						$p.app.tabs.moduleOut(l_id);                    
						//display message to warn it is not authorized ?
						cannotBeReleased = true;
					} else {
						cannotBeReleased = false;
					}
					
					if (cannotBeReleased) {
						return false;
					} else {
						return true;
					}
				}
				else
				{
					$p.app.tabs.moduleOut(l_id);
				}
			}
		}
	}
//	//is object out of selection (under first row)
//	if (!l_treated&&v_direction=="multidim"){
//		for(var j=1;j<l_lstNb;j++){
//			var l_lst=v_parent.length?v_parent[j]:v_parent;
//			var l_node=l_lst.childNodes[0];
//			l_x=l_node.pagePosLeft;
//			l_y=l_node.pagePosTop;
//			l_w=l_node.offsetWidth;
//			l_h=l_node.offsetHeight;
//			if (v_x>l_x&&v_y<=l_y) {l_nextMod=l_node;break;}
//		}
//	}
	//is object out of selection (aside the first col)
    //if allowed l_nextMod must contains new node
	if (!l_treated&&v_direction=="multidim")
	{
		var l_lst = v_parent.length
			? (v_parent[0]==indef
				? v_parent[1].obj
				: v_parent[0].obj)
			: v_parent;

		for(var i=0;i<l_lst.childNodes.length;i++)
		{
			var l_node=l_lst.childNodes[i];
			l_x=l_node.pagePosLeft;
			l_y=l_node.pagePosTop;
			l_w=l_node.offsetWidth;
			l_h=l_node.offsetHeight;
			if (v_x<=l_x&&v_y<=l_y) {
                l_nextMod=l_node;
                break;
            }
		}
	}
	//is the module below the "necessary" boxes
    //if allowed l_nextMod must contains new node
	if (!l_treated&&v_direction=="multidim")
	{
        //exception if widget moved from a popup (only cell0 exists)
        var l_cpt = (l_lstNb == 2 && tab[$p.app.tabs.sel].type != 1)         ?       0               :       1;
        var l_cptEnd = (l_lstNb == 2 && tab[$p.app.tabs.sel].type != 1)      ?       l_lstNb-1       :       l_lstNb;
    
		for(var j=l_cpt;j<l_cptEnd;j++)
		{
			var l_lst = v_parent.length
				? v_parent[j].obj
				: v_parent;

			for(var i=0;i<l_lst.childNodes.length;i++)
			{
				var l_node=l_lst.childNodes[i];
				if (l_node.className=="necessary")
				{
					l_x=l_node.pagePosLeft;
					l_y=l_node.pagePosTop;
					l_w=l_node.offsetWidth;
					if (v_x>l_x && v_x<(l_x+l_w) && v_y>l_y)
					{
						l_treated = true;
						l_nextMod = l_node;
                        break;
					}
				}
			}
		}
	}
	// if object on the top of the page, move the page up
	var l_scrollY = $p.navigator.getScrollY();
	if (v_y < l_scrollY + 10 && l_scrollY > 0)
	{
		window.scrollBy(0,-20);
		$p.app.widgets.move.moveShadow(0,-20);
	}
	if (v_y > l_scrollY + $p.navigator.getHeight() - 20)
	{
		window.scrollBy(0,20);
		$p.app.widgets.move.moveShadow(0,20);
	}
	
    //if widget can be moved, l_nextMod is not null and contains new node where must set the module
    //other condition: l_nextMod must be different from current node
	if (l_nextMod!=null
        && v_obj!=l_nextMod
        )
	{
        var insertobj = true;
		if (v_type=="module")
		{
			var l_id=$p.app.widgets.getModuleId(l_nextMod);
			if (l_id != -1 && tab[$p.app.tabs.sel].module[l_id].blocked == 1) return true;
            //v_parent - parent object if module = tab[v_tab].cells or tab[v_tab].root or if tab = $("tabsframe")
            $p.app.widgets.move.chosenCell=0;
            
            params['tabid'] = $p.app.tabs.sel;
            params['currentcellobj'] = l_nextMod.parentNode;
            params['inpage']=1;
            
            //Do not check the row limit of the page is not a customizable page
            if (tab[$p.app.tabs.sel].type != 1) return false;            
            if ( !$p.app.widgets.move.isMovable('rowsLimited',params) ) {
                return false;
            }
		}
        //add widget in column
        l_nextMod.parentNode.insertBefore(v_obj,l_nextMod);
		$p.app.widgets.move.setPos(v_obj,v_parent);
		
		if (v_type=="module")
		{
			var cellid = ((l_nextMod.parentNode.id).replace(/cell/,"")).replace(/_\d+/,"");

			$p.app.pages.columns.updateNbWidgetByCol($p.app.tabs.sel,cellid,1);
			$p.app.pages.columns.updateNbWidgetByCol($p.app.tabs.sel,curcellid,-1);
		}
		
        //only for IE (Is causing a displaying issue with FF on newspaper mode : the col1 is moving under the newspaper div)
        if ($p.navigator.IE) hideParent(v_obj);
	}
	return true;
}
/*
	objFreeMove : Manage module free movements (if modules are not aligned)
	Parameters:

		v_obj - object moved
		v_x - horizontal position of the mouse
		v_y - vertival position of the mouse
		v_parent - parent object
		v_direction - allowed movements : vertical / horizontal / multidim
		v_type - object type (module/tab)
*/
function objFreeMove(v_obj,v_x,v_y,v_parent,v_direction,v_type)
{
	var l_x,l_y,l_treated=false;

	//if module over a tab
	if (v_type=="module" && $p.app.user.id>0)
	{
		var l_tabs=$("tabsframe");
		if (l_tabs!=null)
		for (var i=0;i<l_tabs.childNodes.length;i++)
		{
			var l_node=l_tabs.childNodes[i];
			if (l_node.id=="") continue;
			var l_id=l_node.id.replace(/tab/,"");
			if (l_id==$p.app.tabs.sel) continue;
			//l_x=l_node.pagePosLeft;
			l_x=$p.getPos(l_node,"Left");
			l_y=$p.getPos(l_node,"Top");
			//l_x=l_node.getLeft();
			//l_y=l_node.getTop();
			l_w=l_node.offsetWidth;
			l_h=l_node.offsetHeight;
			if (v_x>l_x && v_x<(l_x+l_w) && v_y>l_y && v_y<(l_y+l_h))
			{
				l_treated=true;
				$p.app.tabs.moduleOver(l_id);
				//v_obj.style.display="none";
				return true;
			}
			else
			{
				$p.app.tabs.moduleOut(l_id);
			}
		}
	}
	//is object out of selection (under first row)
	if (!l_treated&&v_direction=="multidim")
	{
		l_y=$p.getPos(v_parent,"Top");
		if (v_y<=l_y)
			return false;
		if (v_obj.style.left.toInt()<widgetDecalX)
			return false;
	}

	return true;
}
/*
	_bringToFront : bring widget to front
	Parameters:

			 uniq ID of the widget
*/
function _bringToFront(v_uniq)
{
	parent.tab[$p.app.tabs.sel].module[$p.app.widgets.uniqToId(v_uniq)].bringToFront();
}
function idToPos(v_id){return $p.app.tabs.idToPos(v_id);}
function uniqToId(v_uniq,v_tab){return $p.app.widgets.uniqToId(v_uniq,v_tab);}
/*
	box : Generate an horizontal menu
	Parameters:
 
		v_h - height of the menu (optional)
		v_title - title displayed on top of the menu 
		hideFct - function that close the menu (optional). If undefined, close button is not displayed
		v_content - HTML content of the menu
		v_hdr - HTML header of the menu (optional)
	
	Returns:
			 HTML code of the menu
*/
function box(v_h,v_title,hideFct,v_content,v_hdr)
{
	var l_s = (v_hdr==indef ? '' : v_hdr)
		+ '<table cellpadding="10" cellspacing="0" width="100%">'
		+ '<tr>'
		+ '<td'+(v_h > 0 ? ' height="'+v_h+'"' : '')+ '>'
		+ '<table class="pbox" cellpadding="0" cellspacing="0" border="0" width="100%">'
		+ '<tr>'
		+ '<td class="pboxheader">'
		+ '<table width="100%">'
		+ '<tr>'
		+ '<td style="color: #000;font-size: 1em;width: 100%">'
		+ '<b>'+v_title+'</b>'
		+ '</td>'
		+ (hideFct == '' ? '' : '<td style="text-align: right;white-space: nowrap;background: url(../images/ico_close.gif) no-repeat left center;"><a class="w" href="#" onclick="'+hideFct+';return false;">'+$p.img('',13,13,lg("lblClose"),"imgmid")+' '+lg("lblClose")+'</a></td>')
		+ '</tr>'
		+ '</table>'
		+ '</td>'
		+ '</tr>'
		+ '<tr>'
		+ '<td valign="top" class="pboxcontent">'
		+ v_content
		+ '</td>'
		+ '</tr>'
		+ '</table>'
		+ '</td>'
		+ '</tr>'
		+ '</table>';
	return l_s;
}
/*
	clearTimer : close a timer object
	Parameters:

			 timer name
*/
function clearTimer(v_timer)
{
	clearTimeout(v_timer);
	v_timer=0;
}
// Sort by module min width
function widthSort(a,b)
{
	if (a.minModSize>b.minModSize) return -1;
	if (a.minModSize<b.minModSize) return 1;
	return 0; 
}


//******************************** OLD FUNCTIONS (kept for compatibility reasons) ***********************************************************************

/* 
    Function: getXml
        Get XML results

        ** Parameters:
**
**      v_url (string) - url of the XML page containing data to retrieve
**      fct(function) - callback function that will treat the results. responseXML and fct_vars are the arguments sent to this function.
**      v_fctvars (string) - arguments sent to the callback function
**      v_type (string) - "xml"=return xml, "html"=return text
**      v_vars(string) - variables sent to the xml page
**      v_method (string) - "post"=send v_vars as post variables, "get" ...
**      v_escapefct (function) - function called if XML page loading does not work

** Returns : error number
*/
function getXml(v_url,fct,v_fctvars,v_type,v_vars,v_method,v_escapefct,v_async,v_priority)
{
	if (v_type==indef) v_type="xml";
	if (v_method==indef) v_method="GET";
	if (v_async==indef) v_async=true;
	if (!pfolder) {pfolder="";}
	if (v_priority==indef) v_priority=2;
	var l_action=[v_url,fct,v_fctvars,v_type,v_vars,v_method,v_escapefct,v_async];
	
	$p.ajax.requests.push(new $p.ajax.request("load",l_action,v_priority));
	$p.ajax.executeRequests();

	return false;
}
/* 
    Function: executescr
        Execute PHP script with XML file
 
** Parameters:
**
**      v_scr (string) - php script (located by default on /portal folder
**      v_vars (string) - post variables sent to the scripts
**      v_alarm(boolean) - define if the alert return by script is displayed in the user page
**      v_forced (boolean) - define if the script is executed when user is not connected
**      fct (function) - callback function, called at the end of the script processing
**      fctvars (string or array) - vars sent directly to the callback function

** Returns : error number
*/
function executescr(v_scr,v_vars,v_alarm,v_forced,fct,v_priority,v_async,fctvars)
{
	var l_noerror=true,l_msg,l_err;

	if (allowSave||v_forced)
	{
		if (v_priority==indef) v_priority=2;
		if (v_async==indef) v_async=true;
		var l_action=new Array(v_scr,v_vars,v_alarm,fct,v_async,fctvars);

		$p.ajax.requests.push(new $p.ajax.request("execute",l_action,v_priority));
		
		$p.ajax.executeRequests();

		return;
	}
	else
	{
		if (demoMode)
		{
			$p.app.alert.show(lg('demoMode'));
		}
		var l_feed=pfolder+v_scr;
	}
	//debug
	$p.app.debug("execute : "+l_feed+" (variables: "+v_vars+")");
	return l_noerror;
}
/*
    Function: cloneObj
    
                            cloneObj
                            
                            Clone an object
*/
function cloneObj(o) {
     if(typeof(o) != "object") return o;
     if(o == null) return o;
   
     var newO = new Object();
   
     for(var i in o) newO[i] = cloneObj(o[i]);
      return newO;
}

/*
        Class: $p.app.error
*/
$p.app.error={
    /*
		Function: $p.app.error.display 
                                display user error message and write technical error message in debugger
                      
                     Parameters:
                       
                               v_msg (string) - error message displayed for users
                               v_function (string) - function impacted
                               v_err (object or string) - error thrown
    */
    display: function(v_msg, v_function,v_err)
    {
        $p.app.alert.show(v_msg,3);
        if (typeof (v_err) == 'string')
        {
            $p.app.debug(v_function + ' : ' + v_err);
        }
        else
        {
            $p.app.debug(v_function + ' : ' + v_err.number + ' | ' + v_err.name + ' | ' + v_err.description);
        }
    },
    addNewError: function (env,msgerror,where) {
        var ct = new Date();
        $p.app.error.errors[env].push( {'date':ct,'msg':msgerror,'where':where});
    },
    voidErrors: function (env) {
        $p.app.error.errors[env] = new Array();
    },
    getLastError: function (env) {
        return $p.app.error.errors[env][0];
    },
    displayLastError: function (env) {
        var lastError = $p.app.error.getLastError(env);
        if (lastError) {
            $p.app.alert.show(lastError['msg'] + " " + lastError['msg']['where'] ,3);
            $p.app.error.voidErrors(env);
        }    
    },
    errors:{'admin':new Array(),'portal':new Array(),'tutorial':new Array()}
}

// get window.location information, since they are no more accessible with IE once document.domain is set
var windowLocationObject = {
	'search':window.location.search,
	'href':window.location.href,
	'protocol':window.location.protocol,
	'host':window.location.host
};

if (typeof(gadgets)=='undefined') gadgets = {};
if (typeof(gadgets.window)=='undefined') gadgets.window = {};
gadgets.window.adjustHeight = function(v_height,uniqid) {
    if (uniqid == -1 ||uniqid == 0) return false;
    for (var i=0;i<tab[$p.app.tabs.sel].module.length;i++) {
        if (tab[$p.app.tabs.sel].module[i].uniq == uniqid) {
            tab[$p.app.tabs.sel].module[i].setHeight(v_height);
        }
    }
};