// xobjectjs , adapted from (C) Shelley Powers, YASD, 1998 - 2000
// Each DOM gets its own object, with similar interfaces but differing implementations
//
// 28fev03 - Removed the clipping stuff, added timer attribute

// The W3C DOM Object

function dom_object(obj) {
	this.css2 = obj;
	this.name = obj.id;
	this.objResizeBy = domResizeBy;
	this.objHide = domHide;
	this.objShow = domShow;
	this.objDisplay = domDisplay;
	this.objGetLeft = domGetLeft;
	this.objGetTop = domGetTop;
	this.objSetTop = domSetTop;
	this.objSetLeft = domSetLeft;
	this.objMoveAbsolute = domMoveAbsolute;
	this.objMoveRelative = domMoveRelative;
	this.objGetWidth = domGetWidth;
	this.objGetHeight = domGetHeight;
	this.objSetHeight = domSetHeight;
	this.objSetWidth = domSetWidth;
	this.objSetZIndex = domSetZIndex;
	this.objGetZIndex = domGetZIndex;
	this.replace_html = domReplaceHTML;
	this.objReplaceHTML = domParamReplaceHTML;
	this.objReplaceText = domReplaceText;
	this.objGetVisibility = domGetVisibility;
	this.objTimer = null;
}

// The IE 4.x, 5.x, and  6.x DOM Object
function ie_object(obj) {
	this.css2 = obj;
	this.name = obj.id;
	this.objResizeBy = domResizeBy;
	this.objHide = domHide;
	this.objShow = domShow;
	this.objDisplay = domDisplay;
	this.objGetLeft = domGetLeft;
	this.objGetTop = domGetTop;
	this.objSetTop = domSetTop;
	this.objSetLeft = domSetLeft;
	this.objMoveAbsolute = domMoveAbsolute;
	this.objMoveRelative = domMoveRelative;
	this.objGetWidth = domGetWidth;
	this.objGetHeight = domGetHeight;
	this.objSetHeight = domSetHeight;
	this.objSetWidth = domSetWidth;
	this.objSetZIndex = domSetZIndex;
	this.objGetZIndex = domGetZIndex;
	this.replace_html = domReplaceHTML;
	this.objReplaceHTML = domParamReplaceHTML;
	this.objReplaceText = domReplaceText;
	this.objGetVisibility = domGetVisibility;
	this.objTimer = null;
}

// The Navigator DOM Object
function ns_object(obj) {
	this.css2 = obj;
	this.name = obj.name;
	this.objResizeBy = domResizeBy;
	this.objHide = nsobjHide;
	this.objShow = nsobjShow;
	this.objDisplay = nsobjDisplay;
	this.objGetLeft = nsobjGetLeft;
	this.objGetTop = nsobjGetTop;
	this.objSetTop = nsobjSetTop;
	this.objSetLeft = nsobjSetLeft;
	this.objMoveAbsolute = domMoveAbsolute;
	this.objMoveRelative = domMoveRelative;
	this.objGetWidth = nsobjGetWidth;
	this.objGetHeight = nsobjGetHeight;
	this.objSetHeight = nsobjSetHeight;
	this.objSetWidth = nsobjSetWidth;
	this.objSetZIndex = nsobjSetZIndex;
	this.objGetZIndex = nsobjGetZIndex;
	this.replace_html = nsreplace_html;
	this.objReplaceHTML = nsParamReplaceHTML;
	this.objReplaceText = nsReplaceText;
	this.objGetVisibility = nsVisibility;
	this.objTimer = null;
}

//*************************************************************************************
//
// The implementations
//
//*************************************************************************************


// The DOM Object Implementations
//
//*************************************************************************************
// rezise
function domResizeBy(wincr,hincr) {
   var wdth = this.objGetWidth();
   wdth += wincr;
   this.objSetWidth(wdth);
   
   var ht = this.objGetHeight();
   ht += hincr;
   this.objSetHeight(ht);
}
// element's left position
function domGetLeft() {
        var lt = parseInt(this.css2.style.left);
	return lt;
}
// element's top position
function domGetTop () {
        var tp = parseInt(this.css2.style.top);
	return tp;
}
// set element's top position
function domSetTop (top) {
	this.css2.style.top = top + "px";
}
// set element's left position
function domSetLeft(left) {
	this.css2.style.left = left + "px";
}
// get element's width
function domGetWidth() {
    var wd = parseInt(this.css2.style.width);
	return wd;
}
// get element's height
function domGetHeight() {
    var ht = parseInt(this.css2.style.height);
	return ht;
}
// set element's height
function domSetHeight(height) {
	this.css2.style.height = height + "px";
}
// set element's width
function domSetWidth(width) {
	this.css2.style.width = width + "px";
}
// hide element
function domHide() {
   this.css2.style.visibility = "hidden";
}
// show element
function domShow() {
   this.css2.style.visibility = "visible";
}
// display element
function domDisplay(type) {
   this.css2.style.display = type;
}
// make absolute move
function domMoveAbsolute(newleft, newtop) {
   this.objSetLeft(newleft);
   this.objSetTop(newtop);
}
// move relative to current location
function domMoveRelative(left, top) {
   this.objSetLeft(left + this.objGetLeft());
   this.objSetTop(top + this.objGetTop());    
}
// set element's zindex order
function domSetZIndex(zindex) {
   this.css2.style.zIndex = zindex;
}
// get element's current zindex order
function domGetZIndex(zindex) {
   return this.css2.style.zIndex;
}
// replace text (equivalent to innerText)
function domReplaceText(txt_string) {
   var nodes = this.css2.childNodes;
   var node = nodes.item(0);
   node.replaceData(0,node.length,txt_string);   
}
// replace html (innerHTML)
function domReplaceHTML(html_string) {
	this.css2.innerHTML = html_string;
} 
// replace HTML -- replace contents with specific object
function domParamReplaceHTML(tag,clss,id,contents) {
    this.objHide();
    var r = this.css2.ownerDocument.createRange();
    r.selectNodeContents(this.css2);
    r.deleteContents();

    var elem = document.createElement(tag);
    elem.setAttribute("id",id);
    elem.setAttribute("className",clss);
    var txt = document.createTextNode(contents);
    elem.appendChild(txt);
    this.css2.appendChild(elem); 
    this.objShow();
  }
// return visibility
function domGetVisibility() {
    return this.css2.style.visibility;
}

// The IE Object Implementations
//
//*****************************************************************************

// replace html (with specific element)
function ieParamReplaceHTML(tag, clss, id, contents) {
    var strng = "<" + tag + " class='" + clss + "' id='" + id + "'>";
    strng = strng + contents;
    strng = strng + "</" + tag +  ">";
    this.css2.innerHTML = strng;
     }

// The Navigator 4.x Object Implementations
//
//*****************************************************************************

// hide element
function nsobjHide() {
	this.css2.visibility = "hidden";
}
// show element
function nsobjShow() {
	this.css2.visibility = "inherit";
}
// element display
function nsobjDisplay(type) {
   if (type == "none")
       this.objHide();
   else
       this.objShow();
}
// element's left position
function nsobjGetLeft() {
	return this.css2.left;
}
// element's top position
function nsobjGetTop () {
	return this.css2.top;
}
// set element's top position
function nsobjSetTop(top) {
	this.css2.top = top;
}
// set element's left position
function nsobjSetLeft(left) {
	this.css2.left = left;
}
// get element's width
function nsobjGetWidth() {
	return this.css2.clip.width;
}
// get element's height
function nsobjGetHeight() {
	return this.css2.clip.height;
}
// set element's width
function nsobjSetWidth(width) {
	this.css2.clip.width = width;
}
// set element's height
function nsobjSetHeight(height) {
	this.css2.clip.height = height;
}
// set element's zindex order
function nsobjSetZIndex(zindex) {
	this.css2.zIndex = zindex;
}
// get element's current zindex order
function nsobjGetZIndex() {
	return this.css2.zIndex;
}
// replace html (navigator)
function nsreplace_html(html_string) {
	this.css2.document.write(html_string);
	this.css2.document.close();
}
// Param replace
function nsParamReplaceHTML(tag, clss, id, contents) {
    var strng = "<" + tag + " class='" + clss + "' id='" + id + "'>";
    strng = strng + contents;
    strng = strng + "</" + tag + ">";
    this.css2.document.write(strng);
    this.css2.document.close();
    }
function nsReplaceText(text_string) {
  // this function not implemented
}
function nsVisibility() {
   return this.css2.visibility;
}


//****************************************************************************************
//
// Create the objects
//
// The result is an array of dom object
//****************************************************************************************


// For IE 4.x, pull all DIV blocks into object array
function create_ie_objects() {
   theelements = document.all.tags("DIV");
   theobjs = new Array();
   for (i = 0; i < theelements.length; i++){
      if (theelements[i].id != "") {
	   theobjs[theelements[i].id] = new ie_object(theelements[i]);
	   }
      }
}

// For Navigator 4.x, pull all DIV blocks into object array
function create_ns_objects(newarray) {
   theobjs = new Array();
   for (i = 0; i < document.layers.length; i++){
     if (document.layers[i].name != "") 
   	 theobjs[document.layers[i].name] = new ns_object(document.layers[i]);
     }
}

// For W3C DOM (Navigator 6.x, Mozilla, IE 6.x), 
// pull all named DIV blocks into an array
function create_dom_objects() {
  theelements = document.getElementsByTagName("DIV");
  //alert("theelements : "+theelements+" --------------> "+theelements.length);
  theobjs = new Array();
  for (i = 0; i < theelements.length; i++) {
      var obj = theelements[i];
	  //alert("objid : "+obj.id);
	  if (obj.id != "")
         theobjs[obj.id] = new dom_object(obj);
      }
}

function create_objects() {
    if (navigator.appName == "Microsoft Internet Explorer")
	    create_ie_objects();
    else 
        //if (navigator.appName == "Mozilla" || navigator.appName == "Netscape")
		if (navigator.appName == "Mozilla" || navigator.appName == "Netscape"  || navigator.appName == "Konqueror")
           if (navigator.appVersion.indexOf("4.") == -1)
	      create_dom_objects();
           else 
  	      //create_ns_objects();
		   create_dom_objects();
}

//*****************************************************************************
//Helper function
//
//*****************************************************************************

// convert string to value
function convert(strng) {
    var i = parseInt(strng);
    return i;
}

function Is() {
    var agent   = navigator.userAgent.toLowerCase();
    this.major  = parseInt(navigator.appVersion);
    this.minor  = parseFloat(navigator.appVersion);
    this.ns     = ((agent.indexOf('mozilla')   != -1) &&
                  (agent.indexOf('spoofer')    == -1) &&
                  (agent.indexOf('compatible') == -1) &&
                  (agent.indexOf('opera')      == -1) &&
                  (agent.indexOf('webtv')      == -1));
    this.ns4    = (this.ns && (this.major      ==  4));
    this.ns6    = (this.ns && (this.major      >=  5));
    this.ie     = (agent.indexOf("msie")       != -1);
    this.ie3    = (this.ie && (this.major      <   4));
    this.ie4  	= (this.ie && (this.major >= 4));
    this.ie5    = (this.ie && (this.major      ==  4) &&
                  (agent.indexOf("msie 5.0")   != -1));
    this.ie6    = (this.ie && (this.major      ==  4) &&
                  (agent.indexOf("msie 6.0")   != -1));
    this.ieX    = (this.ie && !this.ie3 && !this.ie4);
}
// some vars
var is = new Is();
var selmenu;

// Hide all the popmenu
function HideLayers() { 
	theobjs["presentation"].objHide();
	theobjs["CORAP"].objHide();
	theobjs["reseau"].objHide();
	theobjs["applicatifs"].objHide();
	theobjs["supervision"].objHide();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popvideo(page, i, largeur, hauteur){
	//grand format 400-600, petit format 330-500
	var win = window.open(page,"_blank","width="+largeur+",height="+hauteur+",location=no,hotkeys=no,directories=no,menubar=no,scrollbar=auto,toolbar=no,status=no,resizable=yes");
}

function show(id)
{
//alert("id : "+id);
//alert("idShow : "+theobjs[id]);
	theobjs[id].objShow();
}

function hide(id)
{
	theobjs[id].objHide();
}

function smenuHide(id)
{
	//eventSrcId=(event.srcElement)?event.srcElement.id:"undifined";
	//eventType = "-"+event.type;
	//alert(eventSrcId + eventType);
	//menuHide(id);
	theobjs[id].objTimer = setTimeout("hide('"+id +"')",200);
}

function smenuShow(id)
{
	if ( theobjs[id].objTimer != null)
	{
		clearTimeout(theobjs[id].objTimer);
		theobjs[id].objTimer = null;
	}
	show(id);
}

function menuHide(id)
{
	if(!is.ns4) {
	theobjs[id].objTimer = setTimeout("hide('"+id +"')",200);
	}
}

function menuShow(id)
{ 
	if(is.ns4) {
		HideLayers();
	}
	else {
		if ( theobjs[id].objTimer != null) {
			clearTimeout(theobjs[id].objTimer);
			theobjs[id].objTimer = null;
		}
	}
	//alert("id : "+id);
	show(id);
}

function itemclick(event)
{
	event.cancelBubble=true;
	return false;
}

function center() {
	resolution=screen.width;
	//alert (resolution);
	if (resolution < 1000) moins=22; else moins=0;
	
	hauteurUtilisateur=0;
	largeur=0;
	if (navigator.appName == "Microsoft Internet Explorer") {
		if (navigator.userAgent.indexOf("Opera")>0) {
			//alert("opera");
			hauteur=73+hauteurUtilisateur;
			largeur=0;
		} else if (navigator.userAgent.indexOf("Konqueror")>0) {
			//alert("Konqueror");
			hauteur=100+hauteurUtilisateur;
			largeur=25;
		} else {
			//alert("ie");
			hauteur=66+hauteurUtilisateur;
		}
	} else {
		if (navigator.userAgent.indexOf("Firefox")>0) {
			//alert("Firefox");
			hauteur=65+hauteurUtilisateur;
		} else {
			//alert("safari-google chrome");
			hauteur=65+hauteurUtilisateur;
		}
	}
	theobjs["presentation"].objMoveAbsolute (240, hauteur);
	theobjs["CORAP"].objMoveAbsolute (332, hauteur);
	theobjs["reseau"].objMoveAbsolute (386, hauteur);
	theobjs["applicatifs"].objMoveAbsolute (448, hauteur);
	theobjs["supervision"].objMoveAbsolute (528, hauteur);
}

function initBody() {
	create_objects();
	center();
}

addEvent( window, 'load', initBody, false );