/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var canSee=false;
$(document).ready(function(){
    $('#loginBtn').click(function(){
        //alert('yayy');
        if(canSee==false){
            $('#loginDiv').slideDown('slow',function() {
                // Animation complete.
                canSee=true;
                $('#loginTbl').show();
            });
        }

        if(canSee==true){
            $('#loginDiv').slideUp('slow');
            $('#loginTbl').hide();
            canSee=false;
        }
        //alert($('#loginDiv'));
        //$('#loginDiv').toggle();
        
        $('#invalidLogin').hide();
    //    if(document.getElementById('loginTbl')).style.display=='table'){
    //        document.getElementById('loginTbl')).style.display='none';
    //    }
    })

    $('#cancelBtn').click(function(){
        $('#loginDiv').fadeOut();
        $('#loginTbl').hide();
        canSee=false;
    
    })

    $('#submitLogin').click(function(){
        login();
    })



})


function login(){
    var email=$('#email').val();
    var password=$('#password').val();
    $.post('login.php',{
        'email':email,
        'password':password
    },function(data){
        //alert(data);
        if(data==-1){
            $('#invalidLogin').show();
            $('#email').val('');
            $('#password').val('');
        }else{
            $('#invalidLogin').hide();
            $('#logoutBtn').show();
            $('#loginBtn').hide();
            $('#login').fadeOut();
            window.location="index.php";
        }
        
    })
}

function submitViaEnter(evt) {
    evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    var form = target.form;
    var charCode = (evt.charCode) ? evt.charCode :
    ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13) {
        login();
    }

}
