
/*
 * $Id$
 * $Revision: 3 $
 * $Date: 5/01/07 10:37 $
 */
 
// *** COMMON CROSS-BROWSER COMPATIBILITY CODE ***

var isDOM=document.getElementById?1:0;
var isIE=document.all?1:0;
var isNS4=navigator.appName=='Netscape'&&!isDOM?1:0;
var isIE4=isIE&&!isDOM?1:0;
var isOp=window.opera?1:0;
var isDyn=isDOM||isIE||isNS4;


// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);



function pressOnEnter(elem, btnName)
{
	var i, col, f;
	
	if (elem == null)
	{
		if (event.keyCode != 13) return;
		
		f = document.forms[0];
		
		col = f.children;
		
		for (i = 0 ; i < col.length ; i++)
		{
			if (pressOnEnter(col.item(i), btnName)) return true;
		}
		
		return false;
	}
	else
	{
		if ((""+elem.name).indexOf(btnName) >= 0)
		{
			event.returnValue = false;
			elem.click();
			return true;
		}

		col = elem.children;
		
		for (i = 0 ; i < col.length ; i++)
		{
			if (pressOnEnter(col.item(i), btnName)) return true;
		}
		
		return false;
	}
}



/* --------------------------------------------------
	Population automatique des proprietes d'un objet
*/
function addProps(obj, data, names, addNull) {
	for (var i = 0; i < names.length; i++) if(i < data.length || addNull) obj[names[i]] = data[i];
}




/* --------------------------------------------------
	Recherche un objet DHTML d'ID donnee et le renvoit (ou null si inexistant)
*/
function getObj(id) {
	if (isDOM && document.getElementById(id)!=null) {
		return document.getElementById(id);
	}
	
	// on cherche dans document.layers (Netscape)
	if (document.layers && eval("document."+id)!=null) {
		return eval("document."+id);
	}
	
	// on cherche dans document.all
	if (isIE && eval("typeof(document.all[id])")!="undefined") {
		return document.all[id];
	}

	
	// sinon on cherche dans les formulaires
	for(var i=0; i<document.forms.length; i++) {
		if (eval("typeof(document.forms[i]."+id+")")!="undefined")
			return eval("document.forms[i]."+id);
	}

	// sinon on cherche dans les frames
	if (typeof(document.frames)!="undefined") {
		for(var i=0; i<document.frames.length; i++) {
			if (eval("typeof(document.frames[i]."+id+")")!="undefined")
				return eval("document.frames[i]."+id);
		}
	}

	// sinon on cherche dans les images
	for(var i=0; i<document.images.length; i++) {
		if (eval("typeof(document.images[i]."+id+")")!="undefined")
			return eval("document.images[i]."+id);
	}

	// pas trouve !!
	return null;
}



var displayWaitMessageOnURLChange = false;

/* --------------------------------------------------
	Simule un clic sur un lien
*/
function goToURL(u, targetName)
{
	if (typeof(u)=="undefined" || u==null || u=="")
		return true;

	if (u.indexOf("javascript:")==0)
	{
		var jscode = u.substring(11);
		if (eval(jscode))
			return true;
		else
			return false;
	}

	if (typeof(targetName)!="undefined" && targetName!=null && targetName!=""){
		var w = window.open(u, targetName);
		w.focus();
  }
  else{
  		if (displayWaitMessageOnURLChange)
  			displayWaitMessage();

    	window.location.href=u;
   }
}



/**
 Click a link of a given id
*/
function clickLink(id) {
	var link = getObj(id);
	goToURL(link.href, link.target);
	return false;
}





/* --------------------------------------------------
	Fonction qui renvoie un objet contenant la position (x, y) d'un objet
*/
function getDim(el){
	for (var lx=0,ly=0;el!=null;
		lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
	 return {x:lx,y:ly}
}





var delay = 25;
var Opera = window.opera ? true : false;
var fixedElement, elWidth, elHeight, tid;



function initFixing () {

var id = 'fixed';
  if (document.layers) {
    fixedElement = document[id];
    if ( fixedElement == null) return;
    elWidth = fixedElement.document.width;
    elHeight = fixedElement.document.height;
  }
  else if (document.getElementById && !Opera) {
    fixedElement = document.getElementById(id);
     if ( fixedElement == null) return;
    elWidth = fixedElement.offsetWidth;
    elHeight = fixedElement.offsetHeight;
  }
  else if (document.all && !Opera) {
    fixedElement = document.all[id];
     if ( fixedElement == null) return;
    elWidth = fixedElement.offsetWidth;
    elHeight = fixedElement.offsetHeight;
  }
  else if (Opera) {
    fixedElement = document.getElementById(id);
     if ( fixedElement == null) return;
    elWidth = fixedElement.style.pixelWidth;
    elHeight = fixedElement.style.pixelHeight;
  }


  fixPosition();
  if (document.layers)
    fixedElement.visibility = 'show';
  else
    fixedElement.style.visibility = 'visible';
  if (document.all && !Opera)
    window.onscroll = fixPosition;
  else
    tid = setInterval('fixPosition()', delay);
}






function fixPosition () {
  if (document.layers) {
    fixedElement.left = 
      window.pageXOffset + window.innerWidth - elWidth - 15;
    fixedElement.top =   window.pageYOffset;
  }
  else if (document.all) {
       fixedElement.style.pixelLeft =  getDim(document.getElementById('logoAllize')).x;
        var scrollTop = (document.body.scrollTop==0)? document.documentElement.scrollTop:document.body.scrollTop;
	 
	  if  (getObj('caddy') != null) {
			 if (getDim(getObj('endCaddy')).y > 300 ) {
				 fixedElement.style.pixelTop	=  scrollTop+300 + (getDim(getObj('endCaddy')).y-300);
			}
		 else {
			   fixedElement.style.pixelTop =   scrollTop+300;
		 }
	 }
	 else {
	 	   fixedElement.style.pixelTop =   scrollTop+300;
	 }

  }
  else if (document.getElementById) {
    if (elWidth == 0)  // workaround for bug of NN6 to compute width
	    elWidth = fixedElement.offsetWidth;
	    fixedElement.style.left =     document.getElementById('logoAllize').style.left;
	    if  (getObj('caddy') != null) {
			 if (getObj('caddy').offsetHeight > 170) {
		 	     fixedElement.style.top =   (window.pageYOffset+300 +  (getObj('caddy').offsetHeight-170)) + 'px';
			}
			 else  {
		  	    fixedElement.style.top =   (window.pageYOffset+300) + 'px';
			  }
		 }
		 else
		  {
		  	    fixedElement.style.top =   (window.pageYOffset+300) + 'px';
		  }
  }
}



/* --------------------------------------------------
	Simule un clic sur un lien
*/
function goToURL(u, targetName)
{
	if (typeof(u)=="undefined" || u==null || u=="")
		return true;

	if (u.indexOf("javascript:")==0)
	{
		var jscode = u.substring(11);
		if (eval(jscode))
			return true;
		else
			return false;
	}

	if (typeof(targetName)!="undefined" && targetName!=null){
		var w = window.open(u, targetName);
		w.focus();
  }else{
    	window.location.href=u;
   }
}

// Calendar
function ChooseDate(inputId, allowSat, allowSun)
{
	var obj = document.all(inputId);
	if (obj == null) return;

	var initDate = obj.value;

	var param = initDate + ";;;" + (allowSat ? 1 : 0) + ";" + (allowSun ? 1 : 0);

	var ret = showModalDialog("Modal/calendar.aspx", param, 'dialogWidth:300px;dialogHeight:280px;scrollbars:no;resizable:no;help:no;status:no;location:no;menubar:no;directories:no');

	if (ret != null && ret != '')
		obj.value = ret;
	document.all.item(inputId).focus();
}

function getSelectValue(field) {
	if (field != null) {
		if (field.selectedIndex<0 || field.options.length<1)
			return null;
			
		return field.options[field.selectedIndex].value;
	}
}


function showInPopup(url, target, width, height) {
	if (typeof(width)=="undefined" || width==null)
		width=640;
	if (typeof(height)=="undefined" || height==null)
		height=480;
	window.open(url, target, "height="+height+",width="+width+",toolbar=no,location=no,scrollbars=yes,menubar=no,resizable=yes");
	return false;
}

