﻿    document.write('<script type="text/javascript" src="' + KobiDomain + 'D/islogin.js?' + Date() + '"></script>');
    //$(document).ready(function() {
        //run_islogin();        
    //}
    function run_unload(){
        //alert('run_unload');
        //debugger;
    }
    $(document).ready(function() {
        //$('#frmLogin')[0].action=KobiDomain + 'login.get';
        //alert(KobiDomain + 'login.get');
/*
        //KobiOzel e gore link duzeltmece
        if(document.getElementById('KobiPageType')==null 
            || document.getElementById('KobiPageType').value=='KobiOzel'){
            xurl=KobiDomain + 'isLogin.get?';
            $('#frmLogin')[0].action=KobiDomain + 'login.get';
            $('#frmArama')[0].action=KobiDomain + 'arama?psize=10&pnum=1&type=1';

//            $('#menuTopLink1')[0].href='Anasayfa';
//            $('#menuTopLink2')[0].href='hakkimizda';
//            $('#menuTopLink3')[0].href='sss';
//            $('#menuTopLink4')[0].href='iletisim';
//            $('#menuTopLink5')[0].href='davetet';

            $('#cmpLogin_link1')[0].href=KobiDomain + 'Aktivasyon';
            $('#cmpLogin_link2')[0].href=KobiDomain + 'SifremiUnuttum';
            $('#cmpLogin_link3')[0].href=KobiDomain + 'Uyelik?IsKobi=1';
        }else{
            xurl=KobiDomain + 'isLogin.get?';
            $('#frmLogin')[0].action=KobiDomain + 'login.get';
            $('#frmArama')[0].action=KobiDomain + 'arama?psize=10&pnum=1&type=1';

//            $('#menuTopLink1')[0].href='Anasayfa';
//            $('#menuTopLink2')[0].href='hakkimizda';
//            $('#menuTopLink3')[0].href='sss';
//            $('#menuTopLink4')[0].href='iletisim';
//            $('#menuTopLink5')[0].href='davetet';

            $('#cmpLogin_link1')[0].href=KobiDomain + 'Aktivasyon';
            $('#cmpLogin_link2')[0].href=KobiDomain + 'SifremiUnuttum';
            $('#cmpLogin_link3')[0].href=KobiDomain + 'Uyelik?IsKobi=1';
        }
        
        //Login almaca
        alert(xurl + Date());
        xurl='isLogin.get?';
        alert(xurl + Date());
        $.getJSON(xurl + Date(),function(resp){
            //alert(resp.IsLogin);
            if(resp.IsLogin=='1'){
                if(resp.IsKobi=='1'){
                    $('#cmpLogin_loginUser').hide();
                    $('#cmpLogin_loginPass').hide();
                    $('#cmpLogin_loginWelcome').show();
                    $('#cmpLogin_LoggedUserName')[0].innerHTML = resp.UserName;
                    $('#cmpLogin_Password')[0].value='';

                    $('#cmpLogin_link1')[0].innerHTML='Yönetim sayfam';
                    $('#cmpLogin_link2')[0].innerHTML='Mesajlarım';
                    $('#cmpLogin_link3')[0].innerHTML='Özel sayfam';

                    if(document.getElementById('KobiPageType')==null 
                        || document.getElementById('KobiPageType').value=='KobiOzel')
                    {
                        $('#cmpLogin_LoggedUserName')[0].href='ProfilDuzenleme';
                        
                        $('#cmpLogin_link1')[0].href='ProfilDuzenleme';
                        $('#cmpLogin_link2')[0].href='GelenMesajlar?pnum=1';
                        $('#cmpLogin_link3')[0].href='KobiOzel';
                    }else{
                        $('#cmpLogin_LoggedUserName')[0].href='ProfilDuzenleme';
                        
                        $('#cmpLogin_link1')[0].href='ProfilDuzenleme';
                        $('#cmpLogin_link2')[0].href='GelenMesajlar?pnum=1';
                        $('#cmpLogin_link3')[0].href='KobiOzel';
                    }

                    if($('#frmHaberListemeEkle')[0]!=null){
                        $('#frmHaberListemeEkle').show();
                    }
                    startTimer();                    
                }else{
                    $('#cmpLogin_loginUser').hide();
                    $('#cmpLogin_loginPass').hide();
                    $('#cmpLogin_loginWelcome').show();
                    
                    $('#cmpLogin_LoggedUserName')[0].innerHTML = resp.UserName;
                    $('#cmpLogin_Password')[0].value='';

                    $('#cmpLogin_link1')[0].innerHTML='';
                    $('#cmpLogin_link2')[0].innerHTML='';
                    $('#cmpLogin_link3')[0].innerHTML='';
                    
                    if(document.getElementById('KobiPageType')==null 
                        || document.getElementById('KobiPageType').value=='KobiOzel')
                    {
                        $('#cmpLogin_LoggedUserName')[0].href='Uyelik';
                        
                        $('#cmpLogin_link1')[0].href='#';
                        $('#cmpLogin_link2')[0].href='#';
                        $('#cmpLogin_link3')[0].href='#';
                    }else{
                        $('#cmpLogin_LoggedUserName')[0].href='Uyelik';
                        
                        $('#cmpLogin_link1')[0].href='#';
                        $('#cmpLogin_link2')[0].href='#';
                        $('#cmpLogin_link3')[0].href='#';
                    }
                }
            }else{
                //login degilse degisiklige gerek yok
            }
        });
*/
        
        $('#frmLogin').ajaxForm(function(resp){
        //if($.validate())  
        //{
            
            var data = JSON.parse(resp);
            //alert(data.msg);             
            if(data.IsLogin=='1')
            {
                var url=new String(document.location);
                if(url.indexOf(KobiDomain)==-1){
                    location.href= KobiDomain + 'Login.aspx?Email='+$('#cmpLogin_Username')[0].value+'&AuthCode='+data.AuthCode+'&ReturnUrl='+document.location;
                }else{
                    $('#valPassword')[0].value='';
                    if(data.IsKobi=='1'){
                        $('#cmpLogin_loginUser').hide();
                        $('#cmpLogin_loginPass').hide();
                        $('#cmpLogin_loginWelcome').show();
                        
                        $('#cmpLogin_LoggedUserName')[0].innerHTML = data.UserName;
                        $('#cmpLogin_Password')[0].value='';

                        $('#cmpLogin_link1')[0].innerHTML='Yönetim sayfam';
                        $('#cmpLogin_link2')[0].innerHTML='Mesajlarım';
                        $('#cmpLogin_link3')[0].innerHTML='Özel sayfam';

                        if(document.getElementById('KobiPageType')==null 
                            || document.getElementById('KobiPageType').value=='KobiOzel')
                        {
                            
                            $('#cmpLogin_LoggedUserName')[0].href='ProfilDuzenleme';
                            
                            $('#cmpLogin_link1')[0].href='ProfilDuzenleme';
                            $('#cmpLogin_link2')[0].href='GelenMesajlar?pnum=1';
                            $('#cmpLogin_link3')[0].href='KobiOzel';
                        }else{
                            
                            $('#cmpLogin_LoggedUserName')[0].href='ProfilDuzenleme';
                            
                            $('#cmpLogin_link1')[0].href='ProfilDuzenleme';
                            $('#cmpLogin_link2')[0].href='GelenMesajlar?pnum=1';
                            $('#cmpLogin_link3')[0].href='KobiOzel';
                        }

                        if($('#frmHaberListemeEkle')[0]!=null){
                            $('#frmHaberListemeEkle').show();
                        }
                        startTimer();
                    }else{
                        $('#cmpLogin_loginUser').hide();
                        $('#cmpLogin_loginPass').hide();
                        $('#cmpLogin_loginWelcome').show();
                        
                        $('#cmpLogin_LoggedUserName')[0].innerHTML = data.UserName;
                        $('#cmpLogin_Password')[0].value='';

                        $('#cmpLogin_link1')[0].innerHTML='';
                        $('#cmpLogin_link2')[0].innerHTML='';
                        $('#cmpLogin_link3')[0].innerHTML='';

                        if(document.getElementById('KobiPageType')==null 
                            || document.getElementById('KobiPageType').value=='KobiOzel')
                        {
                            $('#cmpLogin_LoggedUserName')[0].href='ProfilDuzenleme';
                            
                            $('#cmpLogin_link1')[0].href='#';
                            $('#cmpLogin_link2')[0].href='#';
                            $('#cmpLogin_link3')[0].href='#';
                        }else{
                            $('#cmpLogin_LoggedUserName')[0].href='ProfilDuzenleme';
                            
                            $('#cmpLogin_link1')[0].href='#';
                            $('#cmpLogin_link2')[0].href='#';
                            $('#cmpLogin_link3')[0].href='#';
                        }
                        stopTimer();
                    }
                }

            }else{
                alert('Yanlış kullanıcı adı veya parola');
                $('#cmpLogin_Password')[0].value='';
                $('#cmpLogin_Password')[0].focus();
                stopTimer();
            }
        //} 
        });

        $('#frmLogout').ajaxForm(function(resp){
        if($.validate())  
        {
            var data = JSON.parse(resp);
            alert(data.msg);             
        } 
        });

    });
    function Logout()
    {
        //if(document.getElementById('KobiPageType')==null || document.getElementById('KobiPageType').value=='KobiOzel'){xurl='logout.set?';}else{xurl='logout.set?';}
        xurl = 'logout.set?';
        $.getJSON(xurl+ Date(),function(resp){
            if(resp.error == 'null')
            {
                var url=new String(document.location);
                if(url.indexOf(KobiDomain)==-1){
                    location.href= KobiDomain + 'Login.aspx?IsLogout=1&ReturnUrl='+document.location;
                }else{
                    $('#cmpLogin_loginUser').show();
                    $('#cmpLogin_loginPass').show();
                    $('#cmpLogin_loginWelcome').hide();

                    $('#cmpLogin_link1')[0].innerHTML='Aktivasyon maili gönder';
                    $('#cmpLogin_link2')[0].innerHTML='Şifremi unuttum';
                    $('#cmpLogin_link3')[0].innerHTML='Üye olmak istiyorum';

                    $('#cmpLogin_link1')[0].href=KobiDomain + 'Aktivasyon';
                    $('#cmpLogin_link2')[0].href=KobiDomain + 'SifremiUnuttum';
                    $('#cmpLogin_link3')[0].href=KobiDomain + 'Uyelik?IsKobi=1';

                    if($('#frmHaberListemeEkle')[0]!=null){
                        $('#frmHaberListemeEkle').hide();
                    }
                    stopTimer();
                }
            }
        });
    }

    //Session sonrası Anasayfa yönlendirme
    var timerRunning = false; // boolean flag
    var myTimer = null;

    function myFunction() { 
        // whenever the timer 'awakes' set the flag to false: 
        timerRunning = false; 
        // insert your code here...
        //alert('Süre sonu');
        
        if(document.getElementById('KobiPageType')==null 
            || document.getElementById('KobiPageType').value=='KobiOzel'){
            location.href='Anasayfa';
        }else{
            location.href='Anasayfa';
        }
    } 

    function startTimer() {
        myTimer = setTimeout('myFunction()',(61*60*1000)-(10*1000)); // myTimer holds the id of the timer
        timerRunning = true; // whenever you start a timer set the timerRunning flag to true 
    }

    function stopTimer() {
        if (timerRunning)
            clearTimeout(myTimer); 
    }
    //Session sonrası Anasayfa yönlendirme

    function funLogin(){
        if($('#cmpLogin_Username')[0].value.length>0 && $('#cmpLogin_Password')[0].value.length>0){
            $('#valEmailUser')[0].value=$('#cmpLogin_Username')[0].value;
            $('#valPassword')[0].value=$('#cmpLogin_Password')[0].value;
            $('#frmLogin').submit();
        }else{
            alert('E-Posta ve Şifre alanlarını boş bırakmayın');
            if($('#cmpLogin_Username')[0].value.length==0){
                $('#cmpLogin_Username')[0].focus();
            }else{
                $('#cmpLogin_Password')[0].focus();
            }
        }
    }
    function funLogout(){
        Logout();
    }
    function UserNameFocus(){
        $('#cmpLogin_Username')[0].style.backgroundImage='';
    }    
    function UserNameBlur(){
        if($('#cmpLogin_Username')[0].value==''){
            $('#cmpLogin_Username')[0].style.backgroundImage='url(d/i/EPosta_bg.png)';
        }else{
            $('#cmpLogin_Username')[0].style.backgroundImage='';
        }
    }
    function PasswordFocus(){
        $('#cmpLogin_Password')[0].style.backgroundImage='';
    }    
    function PasswordBlur(){
        if($('#cmpLogin_Password')[0].value==''){
            $('#cmpLogin_Password')[0].style.backgroundImage='url(d/i/Sifre_bg.png)';            
        }else{
            $('#cmpLogin_Password')[0].style.backgroundImage='';
        }
    }
