$(document).ready(function() {
  $('#login .login-button').click(
    function()
    {
      $('#transbox').toggle('slow');
/*
      if(loginTimeout) clearTimeout(loginTimeout);

      var loginTimeout = setTimeout('$("#transbox").hide("slow")', 15000);
      $('#transbox').hover(
        function() { clearTimeout(loginTimeout); loginTimeout = undefined; },
        function() { var loginTimeout = setTimeout('$("#transbox").hide("slow");$("#fail-login").hide("slow");', 15000); }
      );
*/
    }
  );

  $('a.forgot-password,input.login-button').click(function() { $('#transbox').hide('slow'); });

  if($('input#btnLogin')){
     $('input#btnLogin').bind("click", function(e){
      var status = "";
      var message = "";
	  var gender = "";
      $.ajax({
        type: "POST",
        url: "/member-login.aspx?op=login",
        data: "login="+$('input#txtLogin')[0].value+"&pass="+$('input#txtPass')[0].value,
        success: function(xml){
          var data = "";
          jQuery.each($("message", xml),function(){
            status = $(this).attr("status");
            gender = $(this).attr("gender");
			 message = $(this)[0].firstChild.nodeValue;

            if(status == "1"){
              // $('#lblLoginError').css('display','none');
              // $('#lblLoginError').replaceWith(""); 
			  //alert(gender);
              window.location = window.location;
            }
            else if(status == "-1"){
              // $('#lblLoginError').css('display','block');
              // $('#lblLoginError').text(message);
              // alert("Invalid Login");
              $('#fail-login').show('slow');
            }

          });
        }
      }); 
        
    });
     
     
     
     $('input#txtPass').attr('autocomplete', 'off').keyup(function(event) { 
    
if (event.keyCode == 13) { 
      var status = "";
      var message = "";
	  var gender = "";
      $.ajax({
        type: "POST",
        url: "/member-login.aspx?op=login",
        data: "login="+$('input#txtLogin')[0].value+"&pass="+$('input#txtPass')[0].value,
        success: function(xml){
          var data = "";
          jQuery.each($("message", xml),function(){
            status = $(this).attr("status");
            gender = $(this).attr("gender");
			 message = $(this)[0].firstChild.nodeValue;
            if(status == "1"){
              $('#lblLoginError').css('display','none');
              $('#lblLoginError').replaceWith(""); 
			  //alert(gender);
              window.location = window.location;
            }
            else if(status == "-1"){
              $('#lblLoginError').css('display','block');
              $('#lblLoginError').text(message);
            }
          
          });
        }
      }); 
      }     
    });
  }
  if($('input#btnLogout')){
    $('input#btnLogout').bind("click", function(e){
      var status = "";
      var message = "";
      $.ajax({
        type: "GET",
        url: "/member-login.aspx?op=logout",
        success: function(xml){
          var data = "";
          jQuery.each($("message", xml),function(){
            status = $(this).attr("status");
            message = $(this)[0].firstChild.nodeValue;
            
            if(status == "0"){
              $('#lblLoginError').replaceWith("");
              window.location = "/home.aspx";
            }
             
          });
        }
      });      
    });
  }
});