function login(appName)
{
	var login = document.login["user.account"];
	var pwd   = document.login["user.password"];
	
	if( login.value == '' )
	{
		alert("Veuillez saisir votre identifiant.");
		login.focus();
		return;
	}
	
	if( pwd.value == '' )
	{
		alert("Veuillez saisir votre mot de passe.");
		pwd.focus();
		return;
	}
	
	var data = new PostData();
	
	data.properties["user.account"]  = login.value;
	data.properties["user.password"] = pwd.value;
	data.properties["noRedirect"] = "true";
	data.properties["noGroup"] = "true";
	data.properties["logout.nopersist"] = "true";
	
	var url = "/srt/" + appName + "/common/login";
	var q = Bw.IO.Query.create();
	q.setNoCache();
	q.setHeader("Content-Type", "application/x-www-form-urlencoded");	
	q.post (url, data.toString());
			
	var m = q.getMessage();
	
	if( m.get("data/loginError") == 'true' )
	{
		alert("Identifiant ou mot de passe incorrect");
	}
	else
	{
		document.login.submit();
	}
}

function getHeight(o)
{
	if( o.offsetHeight )
	{
		return (o.offsetHeight);	
	}
	else
	{
		return (o.clientHeight);
	}
};

function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which)
{
	iPos = 0;
	while (elt != null)
	{
		iPos += elt["offset" + which];
		elt = elt.offsetParent;
	}
	return iPos;
};

function PostData ()
{
	this.properties = {};
	this.toString = function ()
	{
		var s = '';
		for (name in this.properties)
		{
			if (s != '') s += '&';
			var value = this.properties[name];
			
			value = '' + value ;
			
			if( typeof value != 'string' )
			{
				continue;
			}	
			
			//value = value.replace(/&/g, "&#38");
			while( value.indexOf('&') > -1 )
			{
				value = value.replace("&", "%26");
			}
			
			s += (name + '=' + value);
		}
		
		return s;
	};
}

/**
 * Launch the callback 'func' when 'bw' is loaded
 */
function launchWhenBWisLoaded( bw, func)
{
	if( typeof bw == 'string' )
	{
		bw = document.getElementById(bw);		
	}
	
	if( !bw.selfclassName )
	{
		setTimeout( function() { launchWhenBWisLoaded( bw, func); }, 1000);
		return;
	}
	
	func();
}

function addEnterEvent(id, func)
{
	var o = document.getElementById(id);
	
	if( o == null )
	{
		return;
	}
	
	if( document.all )
	{
		o.onkeydown = function() { onEnterKeyDown(event, func) };
	}
	else
	{
		o.onkeydown = function(e) { onEnterKeyDown(e, func) };
	}
}


function onEnterKeyDown(e, func)
{
	var c = e.keyCode;
	
	if( c == 13 )
	{
		func();
	}
}
