/* --------------------------------------------------
	Outils divers Javascript

	COSMOSBAY-VECTIS, 2003
*/

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;

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;
	}
}


/* --------------------------------------------------
	Recherche un objet DHTML d'ID donné et le renvoit (ou null si inexistant)
*/
function getObj(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("document.forms[i].id") == id)
			return document.forms[i];
	}

	// sinon on cherche dans les frames
	if (isIE) {
		for(var i=0; i<document.frames.length; i++) {
		if (eval("document.frames[i].id") == id)
			return document.frames[i];
		}
	}

	// sinon on cherche dans les images
	for(var i=0; i<document.images.length; i++) {
		if (eval("document.images[i].id") == id)
			return document.images[i];
	}

	// sinon on cherche dans les liens
	for(var i=0; i<document.anchors.length; i++) {
		if (eval("document.anchors[i].id") == id)
			return document.anchors[i];
	}

	// pas trouvé !!
	return null;
}

/* --------------------------------------------------
	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}
}


/* --------------------------------------------------
	Gestion des actions sur le onload du document
*/
var onLoadActions = new Array();

function addOnLoadAction(action)
{
	if (action!=null && action!="")
		onLoadActions[onLoadActions.length] = action;
}

function executeOnLoadActions()
{
	var i;
	for(i=0; i<onLoadActions.length; i++)
		eval(onLoadActions[i]);
}


/* --------------------------------------------------
	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();
}
