/**********
Copyright (c) 2001 Peugeot.pays
all rights reserved.
File Name : FontionClientObjet.js
Directory : /include/
Date : January, 2001
Developer : Bruno LERAY / Peugeot.pays

Functional Description : 
This File allows to simply create cross-browser
and cross-platform DTHML

Modified by :
Date :
Description :
***********/

var browserName = navigator.appName; 
var browserVer = parseInt(navigator.appVersion); 
var ns = (browserName == "Netscape" && browserVer <6);
var ie4 = (browserName == "Microsoft Internet Explorer") && navigator.appVersion.indexOf('MSIE 4')>0;
var ie5 = (browserName == "Microsoft Internet Explorer") && navigator.appVersion.indexOf('MSIE 5')>0;
var ie = (browserName == "Microsoft Internet Explorer");

function interrogate(what) {
    var output = 'Req: ';
    for (var i in what)
        output += i+ ' -   - ';
    alert(output);
}

//This funtion is used by links edited with the Wysiwyg editor
function linkFunction(URL){
	if(URL.indexOf("http://")>=0){
		window.open(URL);
	}else{
		document.location.href = URL;
	}
}

//This object allows to pre-load an image for rollover
function ObjPreload(ImgOn, ImgOff){
	this.ImgOn = new Image();
	this.ImgOff = new Image();	
	this.ImgOn.src = ImgOn;
	this.ImgOff.src = ImgOff;
}

//This object allows to change an image to an other
function ObjImg(LayerName, ImgName, ObjPreload){
	this.ImgName = ImgName;
	this.RollOn = RollOn;	
	this.RollOff = RollOff;	
	if (LayerName != null){
		if (ns){
			this.LayerRoll = document.layers[LayerName];
			this.RollOn = RollOnN;
			this.RollOff = RollOffN;
		}
	}
	this.ObjPreload = ObjPreload;
}

//RollOnN Method of ObjImg
function RollOnN(){
     this.LayerRoll.document[this.ImgName].src = this.ObjPreload.ImgOn.src;
}

//RollOn Method of ObjImg
function RollOn(){
     document[this.ImgName].src = this.ObjPreload.ImgOn.src;
}

//RollOffN Method of ObjImg
function RollOffN(){
     this.LayerRoll.document[this.ImgName].src = this.ObjPreload.ImgOff.src;
}

//RollOff Method of ObjImg
function RollOff(){
     document[this.ImgName].src = this.ObjPreload.ImgOff.src;
}

//Allows to create a layer object
function CreateLayer(id, Nested){
// Properties
	if (ie){
		this.LeLayer = document.all[id].style;
		this.doc = document.all[id];
		this.LayerEvt = this.doc;
		this.ParentNested = document.all[Nested];
		this.x = this.LeLayer.pixelLeft;
		this.y = this.LeLayer.pixelTop;
		this.h = this.LeLayer.pixelHeight;
		this.w = this.LeLayer.pixelWidth;
	}else if (document.getElementById(id)){
		this.LeLayer = document.getElementById(id).style;
		this.doc = document.getElementById(id);
		this.LayerEvt = this.doc;
		this.ParentNested = document.getElementById(Nested);
	    this.x = this.LeLayer.left;
		this.y = this.LeLayer.top;
		this.h = this.LeLayer.height;
		this.w = this.LeLayer.width;	
	}
	else if(ns){
		this.LeLayer = (Nested != null)? document.layers[Nested].document.layers[id] : document.layers[id];
		this.doc = this.LeLayer.document;
		this.LayerEvt = this.LeLayer;
		this.ParentNested = document.layers[Nested];
		this.x = this.LeLayer.left;
		this.y = this.LeLayer.top;
		this.h = this.LeLayer.clip.height;
		this.w = this.LeLayer.clip.width;
	}
		this.id = id;
		this.EtatVisibility = this.LeLayer.visibility;
		this.Obj = "Layer"+id;
		this.cibleY = 0;
		this.vitesseY = 0;
		this.cibleX = 0;
		this.vitesseX = 0;
		this.SlideActive = false;
// Methods
		this.Show = ShowLayer;
		this.Hide = HideLayer;
		this.Write = WriteinLayer;
		this.Slide = SetSlideActive;
		this.SlideStart = SlideStart;
		this.SlideStop = SlideStop;
		this.Move = MoveLayer;
		this.InfoBulle = AffBulle;
		this.SlideFinished = SlideStop;
		this.SetPosSlide = SetPosSlide;
		this.ScrollUp = ScrollUp;
		this.ScrollDown = ScrollDown;
		this.ScrollStop = SlideStop;
		this.moveTo = moveTo;
}

//This object allows to Slide a layer with return to his initial position 
function CreateBandeau(Children, positionX1, positionX2, vitesseX, positionY1, positionY2, vitesseY){
		this.Children = Children;
		this.PosArrayX = new Array();
		this.PosArrayX[-1] = positionX1;
		this.PosArrayX[1]  = positionX2;
		this.PosArrayY = new Array();
		this.PosArrayY[-1] = positionY1;
		this.PosArrayY[1]  = positionY2;
		this.Flag = 1;
		this.positionY1 = positionY1;
		this.positionY2 = positionY2;
		this.vitesseX = vitesseX;
		this.vitesseY = vitesseY;
		this.Children.cibleX = this.PosArrayX[1];
		this.Children.cibleY = this.PosArrayY[1];
		this.Children.vitesseX = this.vitesseX;
		this.Children.vitesseY = this.vitesseY;
		this.Children.SlideFinished = SlideBack;
		this.Children.Parent = this;
		this.SlideBandeau = SlideBandeau;
}

//Method of CreateLayer
function moveTo(x,y){
	if(x!=null){
		this.x = x;
		if(ns){this.LeLayer.left = this.x;
		}else this.LeLayer.pixelLeft = this.x;
	}
	if(y!=null){
		this.y = y;
		if(ns){this.LeLayer.top = this.y;
		}else this.LeLayer.pixelTop = this.y;
	}
}

function ShowLayer(){
	this.LeLayer.visibility = "visible";
}

function HideLayer(){
	this.LeLayer.visibility = "hidden";
}

function WriteinLayer(text) {
 if (ns) {
  this.doc.open()
  this.doc.write(text)
  this.doc.close()
 }
 else if (ie) this.doc.innerHTML = text
}

var Time;
//Slide method
function MoveLayer(positionX,vitesseX,positionY,vitesseY){
this.ypos = parseInt(this.LeLayer.top);
this.xpos = parseInt(this.LeLayer.left);
  if (this.SlideActive){
      if ((this.xpos * vitesseX) <= (positionX * vitesseX) && (this.ypos * vitesseY) <= (positionY * vitesseY)) {
		this.ypos += vitesseY;
		this.LeLayer.top = this.ypos;
		this.xpos += vitesseX;
		this.LeLayer.left = this.xpos;
		this.Time = setTimeout(this.Obj+'.SlideStart()',30);
  	  }else{
	    clearTimeout(this.Time);
		this.SlideFinished();
	  }
  }
} 

function SlideStop(){
	this.SlideActive = false;
}

function SetSlideActive(){
	this.SlideActive = true;
	this.SlideStart();
}

function SlideStart(){
	this.Move(this.cibleX,this.vitesseX,this.cibleY,this.vitesseY);
}

function SlideBandeau(){
	this.Children.Slide();
}

function SlideBack(){
		this.Parent.Flag = -1 * this.Parent.Flag;
		var Flag = this.Parent.Flag;
	  	this.cibleX = this.Parent.PosArrayX[Flag];
		this.cibleY = this.Parent.PosArrayY[Flag];
		this.vitesseX = -1 * this.vitesseX;
		this.vitesseY = -1 * this.vitesseY;
		this.Slide();
}

//Update Slide properties and Slide Method of CreateLayer Object
function SetPosSlide(cibleX,vitesseX,cibleY,vitesseY){
	this.cibleY = cibleY;
	this.cibleX = cibleX;
	this.vitesseY = vitesseY;
	this.vitesseX = vitesseX;
	this.Slide();
}

//InfoBulle method of CreateLayer Object
if (ns){
	var x;
	var y;
	document.captureEvents(Event.MOUSEOVER);
	document.onmouseover=mouseOver;
}

function AffBulle(texte) {
contenu="<TABLE border=0 cellspacing=0 cellpadding=1><TR bgcolor=#000000><TD><TABLE border=0 cellpadding=2 cellspacing=0 bgcolor=#FFFFCC><TR><TD><FONT size='-1' face='arial' color=#000000>"+texte+"</FONT></TD></TR></TABLE></TD></TR></TABLE></TD></TR></TABLE>";
	if (ns) {
		this.LeLayer.top = y + 10;
		this.LeLayer.left = x - 10;
	}
	else if (ie) {
		var f=window.event;
		if (ie5 && mac){
		    this.LeLayer.top = f.y + 10 + document.body.scrollTop;
		}else{
		    this.LeLayer.top = f.clientY + 10 + document.body.scrollTop;
		}
	        this.LeLayer.left = f.x - 10;
	}
    this.Write(contenu);
    this.Show();
}

function mouseOver(e) {
	x=e.pageX;y=e.pageY;
	routeEvent(e)
}

//ScrollUp Method of CreateLayer Object
function ScrollUp(){
	this.ContentHeight = (ns)? this.doc.height : this.doc.offsetHeight;
	this.ContainerHeight = (ns)? this.ParentNested.document.height : this.ParentNested.offsetHeight;;
	this.ScrollPos = this.ContentHeight - this.ContainerHeight;
	this.SetPosSlide(0,0,this.ScrollPos * -1,-5);
}

//ScrollDown Method of CreateLayer Object
function ScrollDown(){
	this.SetPosSlide(0,0,0,5);
}

/***Open PopUp Function***/
var yy = new Object();
function popupWindow(FileName,WindowName,WindowWidth,WindowHeight,PositionLeft,PositionTop,scroll){
  yy = window.open(FileName,WindowName,'resizable=no,scrollbars='+scroll+',toolbar=no,menubar=no,personalbar=no,status=no,screenX='+PositionLeft+',screenY='+PositionTop+',top='+PositionTop+',left='+PositionLeft+',width='+WindowWidth+',height='+WindowHeight);
	
}
/***Open PopUp ResizeFunction***/
function popupWindowResize(FileName,WindowName,WindowWidth,WindowHeight,PositionLeft,PositionTop,scroll,resize){
  window.open(FileName,WindowName,'resizable='+resize+',scrollbars='+scroll+',toolbar=no,menubar=no,personalbar=no,status=no,screenX='+PositionLeft+',screenY='+PositionTop+',top='+PositionTop+',left='+PositionLeft+',width='+WindowWidth+',height='+WindowHeight);
}

//Function calls new window to display the content
function PopUpWindowFull(strWindowName, strItemName){
	var newWindow=null;
	newWindow = window.open(strWindowName, "newWin");
}//END FUNCTION PopUpWindow()

/***allows to print page ***/
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function PrintPage(){
  if (pr && !mac){
	  window.print();
	}
  else if ( browserName == "Microsoft Internet Explorer" && browserVer <= 4 && !mac ){
	  vbPrintPage();
	}
  else if (mac){
      if (da){
	    alert("Pour imprimer cette page,\n veuillez utiliser le menu fichier - imprimer\n de votre navigateur.");
      }else{
            window.print();
      }
	}
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

function targetopenerlink(mylink, closeme, closeonly, outsidelink)
{
	if (! (window.focus && window.opener))return true;
	window.opener.focus();
	if (! closeonly){
		if (outsidelink)
		{
			window.opener.location.href=mylink;
		}
		else
		{
			window.opener.location.href=mylink.href;
		}
	}
	if (closeme)window.close();
	return false;
}




//Fonction detect Flash plugin
//if ( detectFlash (pathSWF,  heightSWF, widthSWF)  
  function Is ()
   {
     var agt=navigator.userAgent.toLowerCase()

     this.major = parseInt(navigator.appVersion)
     this.minor = parseFloat(navigator.appVersion)			
     this.nav = ((agt.indexOf('mozilla')!=-1)&&((agt.indexOf('spoofer')==-1)&&(agt.indexOf('compatible')==-1)))
     this.ie  = (agt.indexOf('msie')!=-1)			
     this.win = ((agt.indexOf('win')!=-1)||(agt.indexOf('16bit')!=-1))
     this.mac = ((agt.indexOf('mac')!=-1))
   }


  function detectFlash (pathSWF,  heightSWF, widthSWF)
   {
     var is;
     var isIE3Mac = false;
     var detectflash = false;
     var useflash = false;
     var didntuse = true;
     if ((navigator.appVersion.indexOf("Mac")!=-1)&&(navigator.userAgent.indexOf("MSIE")!=-1&&parseInt(navigator.appVersion)==3)) 
  	isIE3Mac = true;
     else 
  	is = new Is();
     if(is.mac && is.ie) { 
  	useflash=1;
     } 
  else {
       if ( (! isIE3Mac ) && ( is.win || is.mac ) && ( is.nav || is.ie ) && ( is.minor >= 3.01 )) {
         detectflash = true;
         if ( is.mac && is.ie ) detectflash = false;
         if ( is.win && is.ie && is.major < 4 ) detectlash = false;
       }
       if (detectflash) {
         if (is.nav && navigator.plugins["Shockwave Flash"]) useflash = true;
         if (is.ie) {
           document.writeln('<script language="VBScript">');
           document.writeln('useflashIE = false');
           document.writeln('On error resume next');
           document.writeln('useflashIE = not isNull(createObject("ShockwaveFlash.ShockwaveFlash.3"))');
           document.write('</scr');
           document.writeln('ipt>');
           useflash = useflashIE;
         }
       }
     }

     return useflash
   }
   
   
//FE AOD-000005
// Fonction de chargement d'une image par défaut
  function defaultImageLoading(strImageName,strImageSrc)
  {
     // strImageName : Nom de l'image du document à remplacer
     // strImageSrc : URL de l'image par défaut à charger
  //document.images['tc_1pt1_wp'].src = '../../../pppweb2fr/2000/2200/2201/default_color.gif';
  document.images[strImageName].src = strImageSrc;
  }

  
  //Fonction qui permet de créer un favori
  function createBookmark(strUrl, strBookmarkName, strBrowser)
  {
    //strUrl : adresse mise en favori
	//strBookmarkName : nom du favori ds le navigateur
	//strBrowser : message si on n'utilise pas IE
    if (window.external)
	{//ne fonctionne que pr IE
	   window.external.addfavorite(strUrl, strBookmarkName);
	}
	else
	{
	   alert(strBrowser);
	} 
  }

  //Fonction qui permet de créer un favori
  function createToolBarBookmark(strUrl, strBookmarkName)
  {
		  var BrowserDetect = {
			init: function () {
				this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
				this.version = this.searchVersion(navigator.userAgent)
					|| this.searchVersion(navigator.appVersion)
					|| "an unknown version";
				this.OS = this.searchString(this.dataOS) || "an unknown OS";
			},
			searchString: function (data) {
				for (var i=0;i<data.length;i++)	{
					var dataString = data[i].string;
					var dataProp = data[i].prop;
					this.versionSearchString = data[i].versionSearch || data[i].identity;
					if (dataString) {
						if (dataString.indexOf(data[i].subString) != -1)
							return data[i].identity;
					}
					else if (dataProp)
						return data[i].identity;
				}
			},
			searchVersion: function (dataString) {
				var index = dataString.indexOf(this.versionSearchString);
				if (index == -1) return;
				return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
			},
			dataBrowser: [
				{
					string: navigator.vendor,
					subString: "Apple",
					identity: "Safari"
				},
				{
					prop: window.opera,
					identity: "Opera"
				},
				{
					string: navigator.vendor,
					subString: "iCab",
					identity: "iCab"
				},
				{
					string: navigator.vendor,
					subString: "KDE",
					identity: "Konqueror"
				},
				{
					string: navigator.userAgent,
					subString: "Firefox",
					identity: "Firefox"
				},
				{	// for newer Netscapes (6+)
					string: navigator.userAgent,
					subString: "Netscape",
					identity: "Netscape"
				},
				{
					string: navigator.userAgent,
					subString: "MSIE",
					identity: "Explorer",
					versionSearch: "MSIE"
				},
				{
					string: navigator.userAgent,
					subString: "Gecko",
					identity: "Mozilla",
					versionSearch: "rv"
				},
				{ 	// for older Netscapes (4-)
					string: navigator.userAgent,
					subString: "Mozilla",
					identity: "Netscape",
					versionSearch: "Mozilla"
				}
			],
			dataOS : [
				{
					string: navigator.platform,
					subString: "Win",
					identity: "Windows"
				},
				{
					string: navigator.platform,
					subString: "Mac",
					identity: "Mac"
				},
				{
					string: navigator.platform,
					subString: "Linux",
					identity: "Linux"
				}
			]
		
		};
		BrowserDetect.init();

		var browserName = navigator.appName;
		if (browserName == "Microsoft Internet Explorer")
		{
			window.external.AddFavorite(strUrl,strBookmarkName);

		}
		else if (browserName == "Netscape") 
		{
			
			if (BrowserDetect.browser == "Safari") 
			{
     			 alert("Cette fonction n\'est pas réalisable sur Macintosh.\n\nUtilisez plutôt la combinaison de touches \"Pomme-D\"");
			}
			else 
			{
				window.sidebar.addPanel(strBookmarkName,strUrl,'');
			}
		}
  }
