var absPath="/people_test/";
var isRedirect=0;
/*function banUser(user_id)
{
	if(confirm("Забанить юзера номер "+user_id+" ?"))
	{
		j.post('ajax/ajaxBanUser.php', 
				{    user_id:user_id
					
					}, function(data){ 
						
						location.href=location.href;
				});
	}
}
*/
function auth(usernameIn, passwordIn)
{  
    auth_check_username(usernameIn,passwordIn);
}

function auth_check_username(usernameIn,passwordIn)
{
  var username=usernameIn.value;
 
  
  var ajaxGetMoCities = new Ajax.Request(absPath+'ajax/ajaxAuthCheckUsername.php',
  {
    method:'post',
    parameters: {ajax_username:username},
    onSuccess: function(transport){
      response = transport.responseText || "no response text";
      //alert(response);
      auth_check_username_process(response,usernameIn,passwordIn);
    },
    onFailure: function(){ alert('Ajax ajaxAuthCheckUsername error!') }
  });
}

function auth_check_username_process(response,usernameIn,passwordIn)
{  
   if(response=='true')
   {
       auth_check_password(usernameIn,passwordIn);
   }
   else
   {
	   location.href=absPath+"index.php?o=auth_message";
       //usernameIn.style.border='1px solid red';
       //такого имени нету
   }
}

function auth_check_password(usernameIn,passwordIn)
{
  var username=usernameIn.value,
      password=passwordIn.value;
  
  var ajaxGetMoCities = new Ajax.Request(absPath+'ajax/ajaxAuthCheckPassword.php',
  {
    method:'post',
    parameters: {ajax_username:username, ajax_password:password},
    onSuccess: function(transport){
      response = transport.responseText || "no response text";
     //alert(response);  
      auth_check_password_process(response,usernameIn,passwordIn);
    },
    onFailure: function(){ alert('Ajax ajaxAuthCheckUsername error!') }
  });
}

function auth_check_password_process(response,usernameIn,passwordIn)
{
   if(response=='true')
   {
      //location = 'index.php';
      //alert(location.href);
	  //if(location.href=='http://')
	  // alert('123');
		if((isRedirect==0)||(lockRedirect=='{LOCK}'))
	  {
		  var lloc=location.href;
			 // alert(lloc);  
			  lloc=lloc.replace("?d=exit","");
			  lloc=lloc.replace("?o=register","");
			  lloc=lloc.replace("?o=auth_message","");
			  
			  //alert(lloc);
		      location.href=lloc;
		      
	  }
	  else
	  {
		 //var docRef = document.referrer;
		 location.href=absPath+"index.php";
		 //if(docRef.indexOf('onfit')>-1)
		 //{
		//	 location.href=docRef;
		 //}
	  }
	  
   }
   else
   {
	  location.href=absPath+"index.php?o=auth_message";
   	  //passwordIn.style.border='1px solid red'; 	
   }
}
