/**
 *	@version 1.0.1
 */

var onLoad=[];

onLoad.run=function()
{
	var r=null;
	while(this.length)
	{
		var func=this.pop();
		if(typeof func=='function')r=func();
	}
	return r;
}

window.onload=function(){return onLoad.run();}


function fixNumber(number)
{
	number=number.replace(/ /g,'').replace(/,/g,'.');
	return number;
}

function formatNumber(number)
{
	number=number.toString().replace(/\./g,',');
	var i=number.indexOf(',');
	if(i<0)i=number.length;
	for(chunk=3;i>0;i--,chunk--)
	{
		if(!chunk)
		{
			number=number.substring(0,i)+' '+number.substring(i);
			chunk=3;
		}
	}
	return number;
}

function isNumeric(str, integer)
{
	var re=integer?/^[+-]?[0-9]+$/:/^[0-9]*([.,][0-9]*)?$/;
	return re.match(str);		
}

function query2object(query)
{
	var obj={};
	var params=query.split('&');

	for(var i=0;i<params.length;i++)
	{
		var tmp=params[i].split('=',2);
		obj[tmp[0]]=tmp[1];
	}

	return obj;
}

function object2query(obj)
{
	var query='';

	for(var i in obj)
	{
		query+=(query?'&':'');
		query+=i+(obj[i]!=undefined?'='+obj[i]:'');
	}

	return query;
}

function address(address)
{
	var tmp;
	var uri=parseUri(address,true);

	// domains
	if(uri.host)
		uri.domains=uri.host.split('.').reverse();
	else uri.domains=[];

	// separate path
	if(uri.path)
	{
		uri.absolute=uri.path[0]=='/';

		tmp=uri.path;
		if(tmp[0]=='/')tmp=tmp.substr(1);
		uri.isDir=tmp[tmp.length-1]=='/';
		if(uri.isDir)
			tmp=tmp.substring(0,uri.length-1);
		uri.paths=tmp.split('/');
	}
	else uri.paths=[];

	// directory
	if(uri.dir)
	{
		if(uri.dir[uri.dir.length-1]=='/')
			uri.dir=uri.dir.substring(0,uri.dir.length-1);

		tmp=uri.dir;
		if(tmp[0]=='/')tmp=tmp.substr(1);
		uri.dirs=tmp.split('/');
	}
	else uri.dirs=[];

	// query string
	if(uri.query)
		uri.args=query2object(uri.query.replace('&amp;','&'));
	else uri.args={};
	delete uri.queryKey;

	// anchor
	if(uri.anchor)
		uri.jsArgs=query2object(uri.anchor.replace('&amp;','&'));
	else uri.jsArgs={};

	return uri;
}

function object2address(uri)
{
	// user info
	if(uri.user)
		uri.userInfo=uri.user+(uri.password?':'+uri.password:'');

	// host
	if(uri.domains)
		uri.host=uri.domains.reverse().join('.');

	// path
	if(uri.paths)
	{
		uri.path=uri.paths.join('/');
		if(uri.absolute)
			uri.path='/'+uri.path;
		if(uri.isDir)
			uri.path+='/';
	}

	// query string
	if(uri.args)
		uri.query=object2query(uri.args);

	// anchor
	if(uri.jsArgs)
		uri.anchor=object2query(uri.jsArgs);

	if(uri.host || uri.port || uri.userInfo)uri.authority='';
	if(uri.host)uri.authority+=uri.host;
	if(uri.port)uri.authority+=':'+uri.port;
	if(uri.userInfo)uri.authority=uri.userInfo+'@'+uri.authority;

	if(uri.path || uri.query || uri.anchor)uri.relativeInfo='';
	if(uri.path)uri.relativeInfo+=uri.path;
	if(uri.query)uri.relativeInfo+='?'+uri.query;
	if(uri.anchor)uri.relativeInfo+='#'+uri.anchor;

	var tmp='';
	if(uri.scheme)tmp+=uri.scheme+'://';
	if(uri.authority)tmp+=uri.authority;
	if(uri.relativeInfo)tmp+=uri.relativeInfo;
	return tmp;
}

function show(id, on, visible, hidden)
{
	if(!hidden)hidden='none';
	if(!visible)visible='block';
	var obj=document.getElementById(id);
	if(!obj)return false;

	obj.style.display=on?visible:hidden;

	return true;
}


