var indef;
function $(v_id){return document.getElementById?(document.getElementById(v_id)?document.getElementById(v_id):null):document.all[v_id];}
function $$(v_name){return document.getElementsByTagName;}
$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;

		if (v_add   !=  indef && v_add  ==  "top")
            v_s = v_s + l_obj.innerHTML;

		if (l_obj)
            l_obj.innerHTML = v_s;
	}
}
$p.app={}
$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=document.getElementById("cache");

        $p.app.cache.resize();

		($p.app.cache.obj).style.backgroundColor="#000000";
	},
    resize: function()
    {
		//var l_size=window.getScrollSize();
		($p.app.cache.obj).style.width = $p.navigator.getWidth()+"px";

		($p.app.cache.obj).style.height = $p.navigator.getHeight()+"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();
        if ($('popup') != null)
        {
            $('popup').style.display='none';
        }

		($p.app.cache.obj).style.display = v_status;
	},
	/*
		Function: $p.app.cache.shadow
                                Display the grey cache window (used for popup display)
	*/
	shadow:function()
	{
		//hide all flash objects
		$p.navigator.hideObjects();

		$p.app.cache.init();

		($p.app.cache.obj).style.display = "block";
		($p.app.cache.obj).style.opacity="0.7";
		($p.app.cache.obj).style.filter="alpha(opacity=70)";
	},
	/*
		Function: $p.app.cache.hideShadow
                                hide the grey cache window
	*/
	hideShadow:function()
	{
		($p.app.cache.obj).style.display="none";
		($p.app.cache.obj).style.opacity="0";
		($p.app.cache.obj).style.filter="alpha(opacity=0)";
		//show all flash objects
		$p.navigator.showObjects();
	}
}
$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,
	/*
	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: 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: 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 = window.location.href;
		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;
	},
	/*
		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: 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=document.getElementsByTagName("object");
		for (var i=0;i<l_objs.length;i++)
		{
			l_objs[i].style.visibility='hidden';
		}
		var l_objs=document.getElementsByTagName("embed");
		for (var i=0;i<l_objs.length;i++)
		{
			l_objs[i].style.visibility='hidden';
		}
		var l_objs=document.getElementsByTagName("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=document.getElementsByTagName("object");
		for (var i=0;i<l_objs.length;i++)
		{
			l_objs[i].style.visibility='visible';
		}
		var l_objs=document.getElementsByTagName("embed");
		for (var i=0;i<l_objs.length;i++)
		{
			l_objs[i].style.visibility='visible';
		}
		var l_objs=document.getElementsByTagName("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: 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;
         }   
	}
}
$p.app.popup={
	/*
		$p.app.popup.build : build the popup object
	*/
	build:function(v_width,v_height)
	{
		if ($('popup')==null)
		{
			var l_popup = document.createElement("div");
            l_popup.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" style="padding: 0 8px 0 8px;">'
                                    + '</div>'
                                    + '<div id="boxcontent" style="width: 100%">'
                                    + '<div id="popupcontent">'
                                    + '</div>'
                                    + '</div>'
                                    ,'#fff',
                                    v_width+'px'
        );
        l_popup.innerHTML = l_s;
           
	},
	/*
		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">'
                + '<a href="#" onclick="'+v_closeFct+';$p.app.popup.hide();return false;">'
                + '<img src="http://www.topformation.com/includes/ico_close.gif" width="12" height="11" class="imgmid" />'
                + ' Fermer'
                + '</a> &nbsp'
                + '</div>'
                + ' &nbsp;'+v_title
                + '</div>';
            $p.print('popuptitle',l_s);
		}
	},
	/*
		$p.app.popup.setContent: set popup content
	*/
	setContent:function(v_content)
	{
		($('popupcontent')).innerHTML = v_content;
	},
	/*
		$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
	*/
	show:function(v_content,v_width,v_height,v_title,v_closeBtn,v_closeFct)
	{
		$p.app.popup.hide();
		$p.app.cache.shadow();
		$p.app.popup.build(v_width,v_height);
		$p.app.popup.setTitle(v_title,v_closeBtn,v_closeFct);
		$p.app.popup.setContent(v_content);
        //resize the page if the popup is larger than the page (prevent from blank space)
        $p.app.cache.resize();
	},
	/*
		$p.app.popup.fadein : same that show but with fadein effect
	*/
	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.openUrl :
	*/
	openUrl:function(v_url,v_width,v_height,v_title,v_closeBtn,v_closeFct)
	{
		$p.app.popup.fadein('<iframe src="'+v_url+'" width="'+(v_width-20)+'" height="'+v_height+'" frameborder="no" marginwidth="0" marginheight="0" scrolling="no"></iframe>',v_width,v_height,v_title,v_closeBtn,v_closeFct);
	},
	/*
		$p.app.popup.hide : close popup created with popup function 
	*/
	hide:function()
	{
		if ($('popup') != null)
		{
			document.body.removeChild($('popup'));
			$p.app.cache.hideShadow();
		}
	},
    undisplay:function ()
	{
        $('popup').style.display="none";
        $p.app.cache.hideShadow();
    },
    redisplay: function ()
	{
        $p.app.cache.shadow();
        $('popup').style.display="block";    
    }
}
$p.html={
	/*
		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
	*/
	roundBox: function(v_content,v_bgColor,v_width)
	{
		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" style="background: '+v_bgColor+';"></b>'
			+ '<b class="b2" style="background: '+v_bgColor+';"></b>'
			+ '<b class="b3" style="background: '+v_bgColor+';"></b>'
			+ '<b class="b4" style="background: '+v_bgColor+';"></b>'
			+ '<div class="boxcontent" style="background: '+v_bgColor+';">'
			+ v_content
			+ '</div>'
			+ '<b class="b4b" style="background: '+v_bgColor+';"></b>'
			+ '<b class="b3b" style="background: '+v_bgColor+';"></b>'
			+ '<b class="b2b" style="background: '+v_bgColor+';"></b>'
			+ '<b class="b1b" style="background: '+v_bgColor+';"></b>'
			+ '</div>';
	}
}