jQuery(document).ready(function($){
	var page=document.location.href;
	page=page.replace("#","");

		// open the forgot your password form when the link is clicked.  The php function is in the process_request_common.php file
		$(".forgotpasswordjq").live('click', function(){
			var id=$(this).attr('id');
//			var attributes=$(this).attr('data');
			var title=$(this).attr('title');
			var nexttitle=$("#nexttitle").html();
			var message=$('#message').html();
			if(title!==''){$('#dialog').dialog('option', 'title', title);}

	    	$('#dialog').load(page,{
	    		'ajaxrequest':'forgotpasswordjq',
//				'attributes':attributes,
				'nexttitle':nexttitle,
				'message': message
				}).dialog('open').dialog('option','modal',true);

		return false;
		});

		$('#forgotpassjq').live('click', function(){
			var lastname=$('#lastname').val();
			var email=$('#email').val();
  			if(lastname!='' && email!=''){
				$.post(page,{
				   'ajaxrequest':'forgotpassjq',
				   'lastname':lastname,
				   'email':email
				   },
				   function(data){
						$('#dialog').html(data).dialog('open').dialog('option','title','Password Retrieval Results');
				   }
				);
			}
		});

		$('#popupsignin').live('click',function(){
			var username=$('#username').val();
			var password=$('#password').val();
			var rememberme=0;
			if(username=='' || password==''){
				$('#dialog').html('You must enter both a user name and a password.').dialog('open').dialog('option','title','Login Error');
			}
			else{
				if($('#rememberme').is(':checked')){
					rememberme=1;
				}

				$.post(page,{
				   'ajaxrequest':'loginjq',
				   'username':username,
				   'password':password,
				   'rememberme':rememberme
				   },
				   function(data){
					da=data.split('%|%');
					if(da[0]=='success'){
						// this is a successful login, reload the page
						window.location.reload();
					}
					else{
						// this can only be a system failure, show a message that there's a problem
		   				$('#dialog').html(da[1]).dialog('open').dialog('option','title','Login Error');
					}
				   }
				);
			}
		});

});

