// **********************************************************************************************
// *************************************** POPUP ************************************************
// **********************************************************************************************
function synchrone_popup(url,winname,width,height,scrollbars) 
{
	var toolbar=0;
	var location=0;
	var directories=0;
	var status=0;
	var resizable=0;
	var copy=0;
	var menubar=0;
	var ScreenWidth=window.screen.width;
	var ScreenHeight=window.screen.height;
	var movefromedge=0;
	   
		placementx=(ScreenWidth/2)-((width)/2);
		placementy=(ScreenHeight/2)-((height)/2);

	var base_href = "";
	var theBase = document.getElementsByTagName("base");

	if (theBase[0] != undefined && url.substr(0, 4).toLowerCase() != "http")
	{
		base_href = theBase[0].href+"/";
	}	
	return window.open(base_href+url,"","width="+width+",height="+height+",toolbar="+toolbar+",location="+location+",directories="+directories+",status="+status+",scrollbars="+scrollbars+",menubar="+menubar+",resizable="+resizable+",left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
}


// **********************************************************************************************
// ******************************** Impression d'un contenu *************************************
// **********************************************************************************************
function printStatic()
{
	var browserName = navigator.appName;
	var objectName;

	if(browserName == 'Netscape'){
	  if(document.getElementById('pageRight') == '[object HTMLDivElement]'){
		var transfert = document.getElementById('pageRight').innerHTML;
  		frmPrint.document.getElementById('divPrint').innerHTML = transfert;
  		frmPrint.focus();
  		frmPrint.print();
	  }else{
		window.print();
	  }
	}else{
	  if(document.getElementById('pageRight') == '[object]'){
		var transfert = document.getElementById('pageRight').innerHTML;
  		document.frmPrint.document.getElementById('divPrint').innerHTML = transfert;
  		document.frmPrint.focus();
  		window.print();
	  }else{
		window.print();
	  }
	}
}


// **********************************************************************************************
// ***************************** to Title Cas ***************************************************
// **********************************************************************************************
String.prototype.toTitleCase = function()
{
	var str = this.toLowerCase(),
	newStr = '';

	for ( var i = 0, l = str.length; i < l; i++ )
	{
		newStr += ( i == 0 || ((str.charAt( i - 1 ) == ' ' || str.charAt( i - 1 ) == '-') && !IsPrep(str.substring(i))))?
		str.charAt( i ).toUpperCase():
		str.charAt( i );
	}
	return newStr;
}

function IsPrep(strP)
{
    var preparray = new Array(24);
    preparray[0] = "and ";
    preparray[1] = "the ";
    preparray[2] = "for ";
    preparray[3] = "to ";
    preparray[4] = "in ";
    preparray[5] = "a ";
    preparray[6] = "at ";
    preparray[7] = "from ";
    preparray[8] = "by ";
    preparray[9] = "an ";
    preparray[10] = "or ";
    preparray[11] = "if ";
    preparray[12] = "of ";
    preparray[13] = "up ";
    preparray[14] = "de ";
    preparray[15] = "des ";
    preparray[16] = "du ";
    preparray[17] = "et ";
    preparray[18] = "à ";
    preparray[19] = "le ";
    preparray[20] = "les ";
    preparray[21] = "la ";
    preparray[22] = "au ";
    preparray[23] = "aux ";

    for(i=0;i<preparray.length;i++){
        if(strP.indexOf(preparray[i]) == 0){
            return true;
            break;
        }
    }
    return false;
}

// **********************************************************************************************
// ******************************MENU OUTLOOK ***************************************************
// **********************************************************************************************
function montre(id) {
		
	var d = document.getElementById(id);

	new Effect.toggle(d,'blind', {duration:0.3});
		
}


// **********************************************************************************************
// ***************************** Infobulle ******************************************************
// **********************************************************************************************

var offsetxpoint=40 //Customize x offset of tooltip
var offsetypoint=-30 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false



function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showInfo(thetext){
		if (ns6||ie){
		document.getElementById("infoBulle").innerHTML=thetext;
		enabletip=true
		return false
		}

}

function positiontip(e){
	if (enabletip){
	var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
	var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
	//Find out how close the mouse is to the corner of the window
	var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
	var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

	var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<document.getElementById("infoBulle").offsetWidth)
	//move the horizontal position of the menu to the left by it's width
	document.getElementById("infoBulle").style.left=ie? ietruebody().scrollLeft+event.clientX-document.getElementById("infoBulle").offsetWidth+"px" : window.pageXOffset+e.clientX-document.getElementById("infoBulle").offsetWidth+"px"
	else if (curX<leftedge)
	document.getElementById("infoBulle").style.left="5px"
	else
	//position the horizontal position of the menu where the mouse is positioned
	document.getElementById("infoBulle").style.left=curX+offsetxpoint+"px"

	//same concept with the vertical position
	if (bottomedge<document.getElementById("infoBulle").offsetHeight)
	document.getElementById("infoBulle").style.top=ie? ietruebody().scrollTop+event.clientY-document.getElementById("infoBulle").offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-document.getElementById("infoBulle").offsetHeight-offsetypoint+"px"
	else
	document.getElementById("infoBulle").style.top=curY+offsetypoint+"px"
	document.getElementById("infoBulle").style.visibility="visible"
	}
}

function hideInfo(){


	if (ns6||ie){
		enabletip=false
		document.getElementById("infoBulle").style.visibility="hidden"
		document.getElementById("infoBulle").style.left="-1000px"
		document.getElementById("infoBulle").style.backgroundColor=''
		document.getElementById("infoBulle").style.width=''
		}
}

document.onmousemove=positiontip;

// init rel=ticker

 function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue) {
        var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
        var arrReturnElements = new Array();
        var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
        var oCurrent;
        var oAttribute;
        for(var i=0; i<arrElements.length; i++) {
            oCurrent = arrElements[i];
            oAttribute = oCurrent.getAttribute(strAttributeName);
            if (typeof oAttribute == "string" && oAttribute.length > 0) {
                if (typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
                    arrReturnElements.push(oCurrent);
                }
            }
        }
        return arrReturnElements;
    }



function searchRel(){

		var eltsAvecRel = getElementsByAttribute(document.body, '*', 'rel')
        
		for(i = 0; i < eltsAvecRel.length; i++)
        {		
			if ( eltsAvecRel[i].getAttribute('rel').split(",")[0] == "ticker")
			{ 
		
				if (eltsAvecRel[i].getAttribute('rel').split(",")[1]== "image")
				{
					eltsAvecRel[i].onmouseover= function() {  showInfo("<img src='"+this.getAttribute('rel').split(",")[2]+"'>");  };
				}
				else if (eltsAvecRel[i].getAttribute('rel').split(",")[1]== "text")
				{
					eltsAvecRel[i].onmouseover= function() {  showInfo(this.getAttribute('rel').split(",")[2]);  };
				}
				eltsAvecRel[i].onmouseout= function() {hideInfo()};
			}
		}
}

function initInfobulle (){
	searchRel ();
}

// **********************************************************************************************
// ******************************CALCUL DIMENSIONS ***************************************************
// **********************************************************************************************
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


// **********************************************************************************************
// **********************************************************************************************
// **********************************    GLIDER      ********************************************
// **********************************************************************************************
// **********************************************************************************************

dynObj.holder = {}; 
// constructor
function dynObj(id,x,y,w,h) {
  var el = dynObj.getElemRef(id);
  if (!el) return;  this.id = id; 
  dynObj.holder[this.id] = this; this.animString = "dynObj.holder." + this.id;
  var px = window.opera? 0: "px";
	this.x = x || 0;	if (x) el.style.left = this.x + px;
	this.y = y || 0;	if (y) el.style.top = this.y + px;
	this.w = w || el.offsetWidth || 0;	this.h = h || el.offsetHeight || 0;
	// if w/h passed, set style width/height
	if (w) el.style.width = w + px; if (h) el.style.height = h + px;
}

dynObj.getElemRef = function(id) { 
  var el = document.getElementById? document.getElementById(id): null;
  return el;
} 

dynObj.getInstance = function(id) {
  var obj = dynObj.holder[id];
  if (!obj) obj = new dynObj(id);
  else if (!obj.el) obj.el = dynObj.getElemRef(id);
  return obj;
}

dynObj.prototype.shiftTo = function(x,y) {
  var el = this.el? this.el: dynObj.getElemRef(this.id)? dynObj.getElemRef(this.id): null;
  if (el) {
    if (x != null) el.style.left = (this.x = x) + "px";
    if (y != null) el.style.top = (this.y = y) + "px";
  }
}

dynObj.prototype.shiftBy = function(x,y) { this.shiftTo(this.x+x, this.y+y); }

dynObj.prototype.show = function() { 
  var el = this.el? this.el: dynObj.getElemRef(this.id)? dynObj.getElemRef(this.id): null;
  if (el) el.style.visibility = "visible";
}
dynObj.prototype.hide = function() { 
  var el = this.el? this.el: dynObj.getElemRef(this.id)? dynObj.getElemRef(this.id): null;
  if (el) el.style.visibility = "hidden"; 
}

// for time-based animations
// resources: www.13thparallel.org and www.youngpup.net (accelimation)
var dw_Bezier = {
  B1: function (t) { return t*t*t },
  B2: function (t) { return 3*t*t*(1-t) },
  B3: function (t) { return 3*t*(1-t)*(1-t) },
  B4: function (t) { return (1-t)*(1-t)*(1-t) },
  // returns current value based on percentage of time passed
  getValue: function (percent,startVal,endVal,c1,c2) {
    return endVal * this.B1(percent) + c2 * this.B2(percent) + c1 * this.B3(percent) + startVal * this.B4(percent);
  }
}

// adapted from accelimation.js by Aaron Boodman of www.youngpup.net
dw_Animation = {
  instances: [],
  add: function(fp) {
    this.instances[this.instances.length] = fp;
  	if (this.instances.length == 1) this.timerID = window.setInterval("dw_Animation.control()", 10);
  },
  
  remove: function(fp) {
    for (var i = 0; this.instances[i]; i++) {
  		if (fp == this.instances[i]) {
  			this.instances = this.instances.slice(0,i).concat( this.instances.slice(i+1) );
  			break;
  		}
  	}
  	if (this.instances.length == 0) {
  		window.clearInterval(this.timerID);	this.timerID = null;
  	}
  },
  
  control: function() {
    for (var i = 0; this.instances[i]; i++) {
  		if (typeof this.instances[i] == "function" ) this.instances[i]();
      else eval(this.instances[i]);
    }
  }
}

Glider.holder = [];
function Glider(id,x,y,w,h,d,ac) {
	this.glideDur = d || 1000; this.origX = x; this.origY = y; this.ac = -ac || 0;
	this.baseObj = dynObj;
	this.baseObj(id,x,y,w,h);
  Glider.holder[Glider.holder.length] = this;
  if (!Glider.winHt) Glider.winHt = getWinHeight();
}
Glider.prototype = new dynObj;
Glider.prototype.onGlideInit = function () {}

Glider.prototype.checkGlider = function() {
	var destY = getScrollY() + this.origY;
	if (destY != this.y) {
		if (destY != this.dy) {
			this.dy = destY;
			this.glideInit();
      this.onGlideInit();
		} 
		this.glide();
	}
}

Glider.prototype.glideInit = function() {
	this.gt = new Date().getTime();
	var distY = this.dy - this.y;
	if ( Math.abs(distY) > Glider.winHt ) {	// distance greater than window height?
		this.gsy = (distY > 0)? this.dy - Glider.winHt: this.dy + Glider.winHt;
	} else this.gsy = this.y;
  this.g_yc1 = this.gsy + ( (1+this.ac) * (this.dy - this.gsy)/3 );
	this.g_yc2 = this.gsy + ( (2+this.ac) * (this.dy - this.gsy)/3 );
}

Glider.prototype.glide = function() {
	var elapsed = new Date().getTime() - this.gt;
  if (elapsed < this.glideDur) {
    var y = dw_Bezier.getValue( elapsed/this.glideDur, this.gsy, this.dy, this.g_yc1, this.g_yc2 );
    this.shiftTo(null,y);
  } else this.shiftTo(null,this.dy);
}

Glider.control = function() {
  for (var i=0; Glider.holder[i]; i++) {
    var curObj = Glider.holder[i];
    if (curObj) curObj.checkGlider();
  }
}
//Glider.timer = setInterval("Glider.control()",20);
dw_Animation.add(Glider.control);

// returns height of window
function getWinHeight() {
	var winHt = 0;
	if (window.innerHeight) winHt = window.innerHeight-18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		winHt = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		winHt = document.body.clientHeight;
	return winHt;
}	

// returns amount of vertical scroll
function getScrollY() {
	var sy = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		sy = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		sy = document.body.scrollTop; 
	else if (window.pageYOffset)
		sy = window.pageYOffset;
	else if (window.scrollY)
		sy = window.scrollY;
	return sy;
}

// onresize, get window height
if (window.addEventListener)
  window.addEventListener("resize", function(){ Glider.winHt = getWinHeight(); }, "false");
else if (window.attachEvent)
  window.attachEvent("onresize", function(){ Glider.winHt = getWinHeight(); } );
  



// **********************************************************************************************
// ***************************** SHOW DIV  ******************************************************
// **********************************************************************************************

function showDiv(targetDiv){	

		hideSelects('hidden');
		ShowDivSelects(targetDiv);

		/* ------OVERLAY------------------- */
		var arrayPageSize = getPageSize();

		//alert("page size="+	arrayPageSize[1]);

		var objOverlay = document.getElementById("overlay"); 

		objOverlay.style.backgroundColor="white";
		objOverlay.style.width= document.documentElement.clientWidth+"px"; 
		objOverlay.style.height=arrayPageSize[1]+170+"px";
	
		objOverlay.style.top= "0px"; 
		objOverlay.style.left= "0px";
		objOverlay.style.position= "absolute";  
		objOverlay.style.opacity = 7/10;
		objOverlay.style.filter = "alpha(opacity=70)";

		/* ------DIV------------------- */

		document.getElementById(targetDiv).style.display="block";		
	
		var posX = (document.documentElement.clientWidth/2)-(document.getElementById(targetDiv).offsetWidth/2);				
		
		document.getElementById(targetDiv).style.left=posX+"px";	

		var glideDiv = new Glider(targetDiv,posX,30,null,null,500,-1);
		glideDiv.show();
}

function hideDiv(div){	
	document.getElementById(div).style.display="none";
	
	new Effect.Fade(document.getElementById("overlay"));					
	
	document.getElementById("overlay").style.display = "none";
}

//hide selects 
function hideSelects(action) { 

	if (action!='visible')
		{action='hidden';}
	if (navigator.appName.indexOf("MSIE")) {
		for (var S = 0; S < document.forms.length; S++){
			for (var R = 0; R < document.forms['aspnetForm'].length; R++) {
				if (document.forms['aspnetForm'].elements[R].options) {
					document.forms['aspnetForm'].elements[R].style.visibility = action;
				}
			}
		} 
	}
}


function ShowDivSelects(div) { 	
		var elem=document.getElementById(div).getElementsByTagName('SELECT');	
		

		var m=document.getElementById(div);
		
	
		for (i=0;i<elem.length;i++){
			
				m.getElementsByTagName('SELECT')[i].style.visibility='visible';
				m.getElementsByTagName('SELECT')[i].style.display='block';
		}

}
