var initListeners = [];
var loginUrl;
var formUrl;
var messages = {};	
var authRedirect = document.location.href;
var currentUserId = 0;
var isAdmin = "false";

var jq = $.noConflict();

jq(document).ready(init);

function init(){
	Form.forms = Form.init(formUrl);
	for(var i = 0; i < initListeners.length; i++)
		initListeners[i]();
}

function onInit(handler){
	initListeners.push(handler);
}

function getMessage(m){
	return messages[m];
}

function getBodyScrollTop(){
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getClientHeight(){
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function getClientWidth(){
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientCenterY(){
	return parseInt(getClientHeight()/2)+getBodyScrollTop();
}

function getClientCenterX(){
	return parseInt(getClientWidth()/2);
}

function openPopUp(url,w,h){
	if(jq.browser.msie)
    	window.open(url,'_blank','width='+(w + 18)+',height='+h+',copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes');
    else
    	window.open(url,'_blank','width='+(w)+',height='+h+',copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes');
    return false;
}


function openUrl(url, width, height, scroll){
	if(!scroll)
		window.open(url, 'page', 'width=' + width + ',height=' + height + ',copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no');
	else
		window.open(url, 'page', 'width=' + width + ',height=' + height + ',copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes');
}


jq.fn.offsetTop = function() {
	var e = this.get(0);
	if(!e.offsetParent) return e.offsetTop;
	return e.offsetTop + jq(e.offsetParent).offsetTop();
};

jq.fn.offsetLeft = function() {
	var e = this.get(0);
	if(!e.offsetParent) return e.offsetLeft;
	return e.offsetLeft + jq(e.offsetParent).offsetLeft();
};

function callMethod(name){
	var a = [];
	for(var i = 1; i < arguments.length; i++)
		a.push(arguments[i]);
	if(name instanceof Function){
		name.apply(name.instance, a);
		return;
	}
	var target = window;
	var method = name;
	if(name.indexOf('.') > -1){
		var arr = name.split('.');
		target = window[arr[0]];
		method = arr[1];
	}
	if(target == undefined || target[method] == undefined)
		return null;
	return target[method].apply(this, a);
}