﻿

function showLogo()
{       
    $("#Khampha").css("backgroundImage","url(" + localPath + "images/Commons/khampha_select.gif)");
    $("#logoTop").css("backgroundImage","url(" + localPath + "images/Logo/logoPNNTop_select.gif)");
    if($("#Khampha").is(":hidden"))
    {                       
        $("#logoTop").show();
    }
    return true;
}

function hiddenLogo()
{
    $("#Khampha").css("backgroundImage","url(" + localPath + "images/Commons/khampha_unselect.gif)");
    $("#logoTop").css("backgroundImage","url(" + localPath + "images/Logo/logoPNNTop_unselect.gif)");
    if($("#Khampha").is(":hidden"))
    {            
        $("#logoTop").show();
    }
    return true;
}

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");                
        $('#LoginPNN_divSignedIn').css('display','block');
        $('#LoginPNN_divNotSignedIn').css('display','none');   
        
        $('#LoginPNN_ImgAvatar').attr('src', AvatarPath + Avatar);
        $('#LoginPNN_Nick').attr('href', ProfilePath + Nick).text(Nick);		
        
        $('#Gocrieng').click(function(){window.location.href = ProfilePath + "home/" + Nick;});
        $('#Trangcanhan').click(function(){window.location.href = ProfilePath + Nick;});
        $('#Banbe').click(function(){window.location.href = ProfilePath + "friends/" + Nick;});
    
        if(window.location.href.toLowerCase().indexOf("/home/")>=0){$("#Gocrieng").attr("class","GocRieng_selected");}
        if(window.location.href.toLowerCase().indexOf("/profile/")>=0){$("#Trangcanhan").attr("class","TrangCaNhan_selected");}
        if(window.location.href.toLowerCase().indexOf("/friends/")>=0){$("#Banbe").attr("class","Banbe_selected");}     
    }    
    else
    {
        $('#LoginPNN_divSignedIn').css('display','none');
        $('#LoginPNN_divNotSignedIn').css('display','block');
        $('#txtFakepass').focus(function(){
		    $('#' + Login_passwordID).css('display','block');
		    $(this).css('display','none');
		    $('#' + Login_passwordID).focus().css('display','block').attr('');
		    $('#' + Login_passwordID).focus();
	    });
		
	    $('#' + Login_passwordID).blur(function()
	    {		
		    if($(this).attr("value")=="")
		    {
			    $(this).css('display','none');
			    $('#txtFakepass').css('display','block');
		    }       
	    });
			
	    $('#' + Login_emailID).focus(function(){
		    $(this).attr("value",$("#hidEmail").attr("value"));   
	    }).blur(function(){
		    if($(this).attr("value")=="")    
		    {
			    $("#hidEmail").attr("value",$(this).attr("value"));
			    $(this).attr("value","Email...");					
		    }
		    else
			    $("#hidEmail").attr("value",$(this).attr("value"));
	    });   
    }
}

$(document).ready(function()
{

    $('#ipTextSearch').focus(function(){
        $(this).attr("value",$("#hidSearch").attr("value"));
    });
    
    $('#ipTextSearch').blur(function(){
        if($(this).attr("value").length==0)
            $(this).attr("value","Tìm kiếm");
    });     
    
    $('#ipTextSearch').bind('keypress', function(e) {
    
    if (window.event.keyCode == 13)
        {
            document.getElementById('btnSearch').focus();
            document.getElementById('btnSearch').click();
        }
    });
    var Url = 
    {

        // public method for URL encoding
        encode : function (string) {
             return escape(this._utf8_encode(string));
        },

        // public method for URL decoding
         decode : function (string) {
            return this._utf8_decode(unescape(string));
        },

        // private method for UTF-8 encoding
        _utf8_encode : function (string) {
            string = string.replace(/rn/g,"n");
            var utftext = "";

            for (var n = 0; n < string.length; n++) {
                var c = string.charCodeAt(n);
                if (c < 128) {
                        utftext += String.fromCharCode(c);
                } else if((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
                } else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
                }
        }

            return utftext;
        },

        // private method for UTF-8 decoding
        _utf8_decode : function (utftext) {
             var string = "";
             var i = 0;
             var c = c1 = c2 = 0;

            while ( i < utftext.length ) {
                 c = utftext.charCodeAt(i);
                if (c < 128) {
                        string += String.fromCharCode(c);
                        i++;
                 } else if((c > 191) && (c < 224)) {
                       c2 = utftext.charCodeAt(i+1);
                        string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                        i += 2;
                 } else {
                       c2 = utftext.charCodeAt(i+1);
                        c3 = utftext.charCodeAt(i+2);
                        string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                     i += 3;
                  }
              }
            return string;
         }
    }           
    $('#' + searchButtonID).click(function()
    {
        if($('#ipTextSearch').attr("value").length==0) return false;
        var param = $('#ipTextSearch').attr('value').replace(/ /g,"+");
        var Browser = 
        {
            Version: function() 
            {
                var version = 999; // we assume a sane browser
                if (navigator.appVersion.indexOf("MSIE") != -1)
                // bah, IE again, lets downgrade version number
                version = parseFloat(navigator.appVersion.split("MSIE")[1]);
                return version;
            }
        }
        if (Browser.Version() < 7) 
        {
            param = Url.encode(param);                
        }
        window.location='http://phununet.com/tim-kiem/' + param + ".html";
        return false;
    });
});
        
