
	/**
	 * Popup oauth window...
	 */
	/*function _displayFBLogin() {
		var windowWidth = 820;
		var windowHeight = 450;
		var centerWidth = (window.screen.width - windowWidth) / 2;
		var centerHeight = (window.screen.height - windowHeight) / 2;
		
		//show window...
  	var _window = window.open("facebook.login.php", 'justboughtit_fb_window', 'status=0, menubar=0' + 
  		',width=' + windowWidth + 
      ',height=' + windowHeight + 
      ',left=' + centerWidth + 
      ',top=' + centerHeight);
      
    _window.focus();
	  //set success callback method...
		_window.onclose = function(){alert('here')};
	  window.justboughtit_fb_success = function(){
	  	window.justboughtit_fb_success = null;
	  	
		if(window.location.href == "http://justbought.it" || window.location.href == "http://justbought.it/")
		{
			window.location.href = "tweet";
		}
		else
		{
			window.location.href = window.location.href;
		}
	  };


	
	}*/

	function showFBConnect()
	{
		FB.Connect.showPermissionDialog('offline_access,publish_stream', afterFbConnect)
	}

	function afterFbConnect(result)
	{			
		if(result != null)
		{
			var uid = FB.Facebook.apiClient.get_session().uid;
			var sessionid = FB.Facebook.apiClient.get_session().session_key;
			var fbname = "";
			

			new Ajax.Request('controllers/save_facebook_details.php',
			{
			 method:'get',parameters:"uid=" + uid + "&sessionid=" + sessionid,
			 onSuccess: detailsSaved,
			 onFailure: fbConnectFailed
			});
		}
		else
		{
			alert("In order for justbought.it to update you facebook profile you must allow offline access");
		}
	}

	function detailsSaved(transport)
	{	
		var response = transport.responseText;
		if(response != "")
		{
			alert(response);
		}
		else
		{
			if($('fb_connect_button') != null)
			{
				$('fb_connect_button').style.display = 'none';
			}
			if($('fb_disconnect_button') != null)
			{
				$('fb_disconnect_button').style.display = 'block';
			}
		}
	}

	function fbConnectFailed()
	{
		alert("Could not connect to facebook!");
	}

	function validateForm()
	{
		if($('username').value == '')
		{
			alert("You must enter a username");
			$('username').focus();
			return false;
		}
		if($('username').length < 2)
		{
			alert("Your username ust be at least 2 characters long.");
			$('username').focus();
			return false;
		}

		if($('phash').value.length > 0)
		{
			if($('phash').value.length < 6)
			{						
				alert("Your password must be at least six characters.");
				$('phash').focus();
				return false;
			}
			if($('phash').value != $('phash2').value)
			{
				alert("Your passwords do not match.");
				$('phash').focus();
				return false;
			}
			
		}

		if($('email').value == '')
		{
			alert("You must enter an email address");
			$('email').focus();
			return false;
		}
		
		return true;
	}
