/******************************************
	URL OBJECT METHODS
/*****************************************/

/**
 * url object constructor.
 * @param url string typicaly "document.url".
 */
function __url(url){
	this.url=unescape(url);

	this.location = '';
	this.vars= new Array(1);
	this.vals= new Array(1);

	// methods
	this.getUrl			= url_getUrl;
	this.getVar			= url_getVar;
	this.getVarIndex= url_getVarIndex;
	this.getVars		= url_getVars;
	this.parse			=	url_parse;
	this.setVar			= url_setVar;

	// init
	this.parse();
}

/**
 * extract location and get vars and add them to the url object.
 */
function url_parse(){
	var a_url = this.url.split('?');

	this.location = a_url[0];
	if(a_url.length==1){ a_url[1]='';}

	var getVars = a_url[1];
	var gvars = getVars.split('&');
	var v;

	for(var i=0;i<gvars.length;i++){
		v=gvars[i].split('=');	
		if(v.length==1){v[1]='';}
		this.setVar(v[0],v[1]);
	}
}

function url_setVar(name,value){
	var l=this.getVarIndex(name);
	if(!l){ l=this.vars.length; }

	this.vars[l]	= name;
	this.vals[l]	= value;
}

function url_getVarIndex(name){
	for(var i=1;i<this.vars.length;i++){
		if(this.vars[i]==name){
			return i;
		}
	}
	return false;
}

function url_getVar(name){
	var index=this.getVarIndex(name);
	if(index){
		return this.vals[index];
	}
	return false;
}

function url_getVars(){
	var vars = new Array();
	for(var i=1;i<this.vars.length;i++){
		vars[vars.length]=escape(this.vars[i])+'='+escape(this.vals[i]);		
	}
	return vars.join('&');
}

function url_getUrl(){
	return this.location+'?'+this.getVars();
}

var pageType=null;

/******************************************
	ONLOAD OBJECT METHODS
/*****************************************/

/**
 * onload object constructor.
 */
function __onload(){
	this.events			= new Array(0);
	this.addEvent		=onload_addEvent;
	this.execEvents	=onload_execEvents;
}

/**
 * add an event to be executed when the page is loaded.
 * @param code string code to be evaluated.
 */
function onload_addEvent(code){
	this.events[this.events.length]	= code;
	return true;
}

/**
 * execute onload events.
 * This method is typicaly called by the "body.onload()" event.
 * (onload="oOnload.execEvents();")
 */
function onload_execEvents(){
	for(var i=0;i<this.events.length;i++){
		eval(this.events[i]);
	}
	return true;
}


/******************************************
 GLOBAL FUNCTIONS	
/*****************************************/

function displayToggle(el_id){
	
	el=document.getElementById(el_id);
	if(!el.style.display || el.style.display=='none'){
		el.style.display='visible';	
	}
	else{
		el.style.display='none';	
	}
}

function loadId(id){
	oUrl.setVar('id',id);
	self.location.href=oUrl.getUrl();
}

function newAdminWin(url, name){
	if(!name){name='cms';}
	window.open(
		url,
		name,
		'height=500,width=500,locationbar=0,personalbar=0,menubar=0,toolbar=0,scrollbar=1,scrollbars=yes'
	);
}
function getWinHeight() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
		return myHeight;
}

function toggleSort(el){
	if(el.href.match('\sasc')){
		el.href = el.href.replace(/\s asc/,' desc');
	}
	else if(el.href.match('\sdesc')){
		el.href = el.href.replace(/\s desc/,' asc');
	}
}

function setMainHeight(){
	document.getElementById('main').style.height = getWinHeight()-100 + 'px';
}

/******************************************
 CREATE OBJECT INSTANCES 
/*****************************************/

var oUrl		= new __url(document.URL);
var oOnload = new __onload(); 

//oOnload.addEvent('setMainHeight()');
window.onresize = function(){
	//setMainHeight();
}


