	/**
	* Global js application
	*/
	var Application = function(){
		return {
			popup : function(url, w, h, name) {
				name = name ? name : '';
				window.open(url, name, "width=" + w + ", height=" + h + ", left=150, top=100, resizable=1, scrollbars=1");
			},

			addOnload: function ( f ){
				var old = window.onload;
				if (typeof(old) != "function" && typeof(f) == "function") {
					window.onload = f;
				} else {
					window.onload = function() {
						if (old) old();
						if (typeof(f) == "function") f();
					}
				}
			},

			addOnunload: function ( f ){
				var old = window.onunload;
				if (typeof(old) != "function" && typeof(f) == "function") {
					window.onunload = f;
				} else {
					window.onunload = function() {
						if (old) old();
						if (typeof(f) == "function") f();
					}
				}
			}
		}
	}();

	/**
	* Element handling
	*/
	Application.Element = function() {
		return {
			getById: function (id){
				if(is.NS)
					return document.layers[id]
				else if(is.element)
					return document.getElementById(id)
				else if(is.IE)
					return document.all[id]
				else
					return -1
			},

			addDefaultValue: function(element, defaultValue){
				if ( element.value == '' ) element.value = defaultValue;
			},

			removeDefaultValue: function(element, defaultValue){
				if ( element.value == defaultValue ) element.value = '';
			}
		}
	}();

	Application.Ajax = function(){
		var xmlhttp, bComplete = false;
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				try {
					xmlhttp = new XMLHttpRequest();
				} catch (e) {
					xmlhttp = false;
				}
			}
		}
		if (!xmlhttp) return null;
		this.connect = function(sURL, sMethod, sVars, fnDone) {
			if (!xmlhttp) return false;
			bComplete	= false;
			sMethod		= sMethod.toUpperCase();
			try {
				if (sMethod == "GET") {
					xmlhttp.open(sMethod, sURL+"?"+sVars, true);
					sVars = "";
				} else {
					xmlhttp.open(sMethod, sURL, true);
					xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				}
				xmlhttp.onreadystatechange = function(){
					if (xmlhttp.readyState == 4 && !bComplete) {
						bComplete = true;
						fnDone(xmlhttp);
					}
				};
				xmlhttp.send(sVars);
			} catch(z) {
				return false;
			}
			return true;
		};
		return this;
	}

	var App = Application //prefixing namespace

	/* Short hand */
	function getEle(id){ return Application.Element.getById(id) }


	rankIdea = function(){
		this.ajax = new App.Ajax;
		return {
			rank: function(rankType, ideaId, rank, userId){
				this.loaderShow(rankType, ideaId)
				ajax.connect(
					'/a.php',
					'GET',
					'cmd=idea_rank&idea_id='+ideaId+'&user_id='+userId+'&rank_type='+rankType+'&rank='+rank,
					function(o){
						rankIdea.loaderHide(rankType, ideaId, o.responseText)
					}
				)
			},

			loaderShow: function(rankType, ideaId){
				getEle(rankType + ideaId + 'Loader').style.display = 'block'
				getEle(rankType + ideaId + 'Container').style.display = 'none'
			},

			loaderHide: function(rankType, ideaId, currentRank){
				getEle(rankType + ideaId + 'Loader').style.display = 'none'
				getEle(rankType + ideaId + 'Container').style.display = 'block'
				getEle(rankType + ideaId + 'Current').style.width = currentRank + '%'
			}
		}
	}();

		/* not yet implemented i Application - TODO */
	var is
	is=new browserHandling()
	function browserHandling(){
		this.IE=0
		this.NS=0
		this.element=(document.getElementById) ? 1 : 0
		this.NSapp=(navigator.appName=="Netscape") ? 1 : 0
		this.IEapp=(navigator.appName=="Microsoft Internet Explorer") ? 1 : 0
		var ual=navigator.userAgent.toLowerCase()
		this.OPERAapp=(ual.indexOf("opera") != -1)
		this.MAC=(ual.indexOf("mac") != -1)
		this.WIN=(ual.indexOf("windows") != -1)
		this.appver=navigator.appVersion
		if(this.IEapp)
			this.IE=(document.all) ? 1 : 0
		else if(this.NSapp && !this.element)
			this.NS=(document.layers) ? 1 : 0
		if(this.NSapp)
			this.version=parseFloat(this.appver)
		else
			this.version=parseFloat(this.appver.substr(this.appver.indexOf("MSIE") + 5, 3))
		this.GECKO=(ual.indexOf("gecko") != -1)
		this.FIREBIRD=(ual.indexOf("firebird") != -1)
		this.NS6=(ual.indexOf("netscape6/6") != -1)
		this.MEDIAPLAYER=(this.GECKO && ual.indexOf("(ax") != -1) || (this.IE && this.version >= 5 && !this.OPERAapp)
	}

	
	App.queryUserIdByEmail = function(s){
		$.getJSON(
				"/a.php", 
				{ cmd: "user_fetch_by_email", user_email: s }, 
				function(o){ return o.userId } 
			)
	}