$(document).ready(function(){
   // reditect url when it try to login
    
   $("#txtLoginIDp").focus(function (){
       $("#divloginmsg").html("");
   });
   $("#txtPasswordp").focus(function (){
       $("#divloginmsg").html("");
   });
    // popup modul trought login    
    $("#btnLoginpop").click(function (){        
        var userid=document.getElementById("txtLoginIDp");
        var password=document.getElementById("txtPasswordp");
        var flag=true;
        if(userid.value==""){
            alert("Please do not leave the field blank -- User Id(email).");
            userid.focus();
            flag=false;
            return false;            
        }        
        if(password.value==""){
            alert("Please do not leave the field blank -- Password.");
            password.focus();
            flag=false;
            return false;
        }
        // check login using ajax
        if(flag==true)
        {
            //$("#loginFirst").fadeTo("fast",0.5);
            $.ajax({       
                   type        : "POST",       
                   url         : websiteurl+"GetData.php",
                   data        : "filter=checkLogin&userid="+userid.value+"&pass="+password.value,
                   success     : function(html)
                              {
                                  //alert(html);
                                  if(html!="Not successful")
                                  {
                                    $("#login").html(html);
                                      var fistwidth = $("#loginFirst").offset();
                                      $("#loginFirst").hide("explode");
                                      var compname = $("#hdCurrentLogin").val();
                                      $("#headerLogout").html(compname+'&nbsp;|&nbsp;<a onclick="logoutIndex()" class="clientContentLogin" style="cursor: pointer;">Logout</a>'); // logout header 
                                      //$("#loginFirst").hide();
                                      //$("#login").append($("#loginSecond"));
                                      $("#loginSecond").show("explode");
                                      $("#myAccountLogin").dialog("close");
                                  }
                                  else 
                                  {
                                      $("#divloginmsg").html("Please enter valid userid and password.");
                                      /*
                                      $("#divnotvaliduser").dialog({
                                        title: "Login Details",
                                        autoOpen: true,
                                        height: 150,
                                        width: 330,
                                        modal: true,
                                        hide:"blind",
                                        draggable: true,
                                        closeOnEscape: false
                                        });*/
                                        //alert(" Not valid");
                                  }                                    
                              }
            });
        }
    });
});

function logoutIndex()
{    
    $.ajax({
           type        : "POST",       
           url         : websiteurl+"GetData.php",
           data        : "filter=logout",
           success     : function(html)
                      {                            
                            $("#LogoutSuccess").dialog({
                                title: "Logout",
                                autoOpen: true,
                                height: 150,
                                width: 330,
                                modal: true,
                                hide:"blind",
                                draggable: true,
                                closeOnEscape: true
                            });
                            
                            $("#LogoutSuccess").dialog({
                                close: function(event, ui){
                                    window.location=websiteurl+"index.php";
                                }
                            });                            
                      }        
           });
}

function checkLoginClient(linkpage)
{            
    //var weburl12="http://localhost:8080/";    
    
    $.ajax({
       type        : "POST",       
       url         : websiteurl+"GetData.php",
       data        : "filter=checkClientLogin",
       success     : function(html)
                  {
                        if(html!="login")
                        {                            
                            $("#myAccountLogin").dialog({
                                title: "Login",
                                autoOpen: true,
                                height: 230,
                                width: 350,
                                modal: true,
                                hide:"blind",
                                draggable: true,
                                closeOnEscape: true
                                });
                            //alert("Kindly login please");
                            
                            $("#myAccountLogin").dialog({
                                close: function()
                                {
                                    if(linkpage=="login")
                                        window.location=websiteurl+"aadityomClient/MyAccount.php";
                                    else if(linkpage=="5")
                                        window.location=websiteurl+"aadityomClient/MyAccount.php?indexLink=5";
                                    else if(linkpage=="6")
                                        window.location=websiteurl+"aadityomClient/MyAccount.php?indexLink=6";
                                    else if(linkpage=="7")
                                        window.location=websiteurl+"aadityomClient/MyAccount.php?indexLink=7";
                                    else if(linkpage=="8")
                                        window.location=websiteurl+"aadityomClient/MyAccount.php?indexLink=8"; 
                                }
                            });
    
                            return false;
                        }
                        else
                        {                                                        
                            if(linkpage=="login")
                                window.location=websiteurl+"aadityomClient/MyAccount.php";
                            else if(linkpage=="5")
                                window.location=websiteurl+"aadityomClient/MyAccount.php?indexLink=5";
                            else if(linkpage=="6")
                                window.location=websiteurl+"aadityomClient/MyAccount.php?indexLink=6";
                            else if(linkpage=="7")
                                window.location=websiteurl+"aadityomClient/MyAccount.php?indexLink=7";
                            else if(linkpage=="8")
                                window.location=websiteurl+"aadityomClient/MyAccount.php?indexLink=8";
                        }                        
                  }        
       });
}


