	function $(id)
	{
		return document.getElementById(id);
	}
	function $v(id)
	{
		return $(id).value;
	}
	String.prototype.trim = function()
	{
		a = this.replace(/^\s+/, '');
		return a.replace(/\s+$/, '');
	};
	String.prototype.isEmail = function()
	{
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/.test(this))
			return true;
		else
			return false;
	};
	String.prototype.isAlphaNumeric = function () {return /^[a-z\A-Z\d]+$/.test (this)}
	function showLabel()
	{
		if($(this.id + '_label'))
			$(this.id + '_label').style.color = '#000000';
	}
	function hideLabel()
	{
		if($(this.id + '_label'))
			$(this.id + '_label').style.color = '#aaaaaa';
	}
	function addEvents(ele)
	{
		var list = ele.getElementsByTagName('input');
		for(var i=0;i<list.length;i++)
			if($(list[i].id + '_label'))
			{
				list[i].onfocus = showLabel;
				list[i].onblur = hideLabel;
				$(list[i].id + '_label').style.color = '#aaaaaa';
			}
		list = ele.getElementsByTagName('textarea');
		for(i=0;i<list.length;i++)
			if($(list[i].id + '_label'))
			{
				list[i].onfocus = showLabel;
				list[i].onblur = hideLabel;
				$(list[i].id + '_label').style.color = '#aaaaaa';
			}
		list = ele.getElementsByTagName('select');
		for(i=0;i<list.length;i++)
			if($(list[i].id + '_label'))
			{
				list[i].onfocus = showLabel;
				list[i].onblur = hideLabel;
				$(list[i].id + '_label').style.color = '#aaaaaa';
			}
	}
	function iError(id)
	{
//		document.getElementById(id + "_label").style.color = "red";
		document.getElementById(id).style.backgroundColor = "pink";
		if($(id + '_label'))
			$(id + '_label').style.color = "red";
	}
	function noError(id)
	{
//		document.getElementById(id + "_label").style.color = "";
		document.getElementById(id).style.backgroundColor = "";
		if($(id + '_label'))
			$(id + '_label').style.color = '#aaaaaa';
	}
	function screen(id,flag)
	{
		if(flag)
		{
			if(document.all)
			{
				var body = document.getElementsByTagName('html')[0];
				body.style.height = '100%';
				body.style.overflow = 'hidden';
			}
			else
				document.body.style.overflow = 'hidden';
			scroll(0,0);
			document.getElementById('screen').style.visibility = "visible";
			document.getElementById(id).style.visibility = "visible";
			curscreen = id;
		}
		else
		{
			if(document.all)
			{
				var body = document.getElementsByTagName('html')[0];
				body.style.height = '';
				body.style.overflow = '';
			}
			else
				document.body.style.overflow = '';
			document.getElementById('screen').style.visibility = "hidden";
			document.getElementById(id).style.visibility = "hidden";
			curscreen = '';
		}
	}
	function login()
	{
		
		var complete = true;
		if(!$v('useremail'))
		{
			$('useremail').style.backgroundColor = 'pink';
			complete = false;
		}
		else
			$('useremail').style.backgroundColor = '';
		if(!$v('userpassword'))
		{
			$('userpassword').style.backgroundColor = 'pink';
			complete = false;
		}
		else
			$('userpassword').style.backgroundColor = '';
		if(complete)
			Spry.Utils.submitForm('formLogin',loginResp,{method:'POST', url:'includes/widgets/users/inc/login.php'});//$('formLogin').submit(); edit here cause i want to ajax the login
	}
	var userid = null;
	function premier(url)
	{
		Spry.Utils.setInnerHTML('msg','Processing...');
		if(userid != 0)
			window.location = './' + url;
		else
		{
			$('loginFrom').value = url;
			centerSize('tblLogin','divlogin');
			screen('divlogin',1);
			$('useremail').focus();
		}
	}
	//Code to resize the gallery image
	function centerSize(div,container)
	{
		var width = parseInt((parseInt($(div).offsetWidth)));
		var height = parseInt((parseInt($(div).offsetHeight)));
		if(document.documentElement && document.documentElement.clientWidth)
			width = parseInt((parseInt(document.documentElement.clientWidth) - width)/2);
		else
			width = parseInt((parseInt(document.body.offsetWidth) - width)/2);
		if(width < 0)
			width = 0;
		if(document.documentElement && document.documentElement.clientHeight)
			height = parseInt((parseInt(document.documentElement.clientHeight) - height)/2);
		else
			height = parseInt((parseInt(document.body.offsetHeight) - height)/2);
		if(height < 0)
			height = 0;
		$(container).style.left = width + 'px';
		$(container).style.top = height + 'px';
	}
	
	function loginResp(req){
		
		//alert(req.xhRequest.responseText);
		var response = Spry.Utils.urlComponentToObject(req.xhRequest.responseText);
		var msg = null;
		if(response.loginError == 'disabled'){
				msg = 'This account has been disabled.';
		}else if(response.loginError == 'password'){
				msg = 'Wrong password.';
		}else if(response.loginError == 'nonexistent'){
				msg = 'This useremail does not exist.';
		}else if(response.loginError == 'unverified'){
				msg = 'This useremail is not verified.';
		}else if (response.login == 'true'){
				msg = '<h2>Welcome...You are Logged in!</h2>';  
				if(response.throwtopage)
				{
					window.location.href = response.throwtopage;
				}
				if($v('from')){
					window.location.href = $v('from');
				}
		}else{ msg = "Error submitting form";}
		
		Spry.Utils.setInnerHTML('msg',msg);
	}
