﻿function getcookie(cookieName)
{ 
    var theCookie=""+document.cookie;
    var ind=theCookie.indexOf(cookieName);
    if (ind==-1 || cookieName=="") return "";
    var ind1 = theCookie.indexOf(';',ind);
    if (ind1==-1) ind1 = theCookie.length;
    return(theCookie.substring(ind + cookieName.length+1,ind1));    
};

function getCookieItem(itemName, cookie)
{
    var PNNcookie = getcookie("phununet");
    var startInd = PNNcookie.indexOf(itemName);
    if(startInd == -1) return "";
    var endInd = PNNcookie.indexOf('&', startInd);
    if(endInd == -1) endInd = PNNcookie.length;
    return(PNNcookie.substring(startInd + itemName.length + 1, endInd));
}

function SetCookie(cookieName,cookieValue,nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000*24*nDays);
    document.cookie = cookieName+ "=" + escape(cookieValue) + ";domain=.phununet.com;expires=" + expire.toGMTString();	
}

function Exit()
{
    SetCookie("phununet","",-1);
    document.location = document.location;
}

function initAuthenticationSpace()
{	
    var UserID = getCookieItem("UserID");
    var _UserID = parseInt(UserID);    
    if(_UserID > 0)
    {
        var Nick = getCookieItem("Nick");
        var Email = getCookieItem("Email");
        var Avatar = getCookieItem("Avatar");                        
        $('#divNonregistered').css('display','none');   
        
        $('#LoginPNN_ImgAvatar').attr('src', AvatarPath + Avatar);
        $('#LoginPNN_Nick').attr('href', ProfilePath + Nick).text(Nick);
    }    
    else
    {        
        $('#divNonregistered').css('display','block');          
    }
}  
        
