function cmsuser(f){
    if(f){
        var oldOnLoad = window.onload;
        window.onload = function(){
		if(typeof(oldOnLoad)!="undefined" && oldOnLoad!=null)
			oldOnLoad();
        var q = new cmsuser(0);
        q.init();
        }
    }
}

cmsuser.prototype.init = function()
{
    if(typeof(GearJsAuth) == "undefined" || !GearJsAuth)
    {
        this.IsInit = false;
        return;
    }
    else
    {
        this.getMyinfo();
        this.showMyinfo('user-name-href');
        this.IsInit = true;
    }
}

cmsuser.prototype.getMyinfo = function()
{
    var http = this.ajax();
    var url = '/cls/call?cls=Agents&fun=GetMyInfo&fmt=2';
    var par = "";
    http.open('POST', url, false);
    //Send the proper header information along with the request
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", par.length);
    http.setRequestHeader("Connection", "close");
    http.send(par);
    this.user  = eval(http.responseText);

}

cmsuser.prototype.showMyinfo = function(id)
{

    var el = document.getElementById(id);
    if(typeof(this.user[0])!="undefined"){
        el.innerHTML = this.user[0].FULL_NAME;//["FULL_NAME"];
        el.title = this.user[0].FULL_NAME;
    }
    else
    {
        el.innerHTML = "";
        el.title = "";
    }
    document.getElementById('authorized').style.display="";

}

cmsuser.prototype.ajax = function(){
    var xmlHttp = false;
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        xmlHttp = false;
      }
    }
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}
