//<[CDATA[
var context = null;
var web = null;
var title = null;
var curHref = null;
var userName = null;
var currentUser = null;
var userObject = null;

function getWebSiteData() {
    if (SP.ClientContext != null && SP.ClientContext != undefined) {
        //alert('Current Client Context is searching');
        this.context = new SP.ClientContext.get_current();
        if (this.context != null && this.context != undefined) {
            //alert('Current Client Context is found');
        }
    }
    this.web = this.context.get_web();
    this.currentUser = web.get_currentUser();    
    this.currentUser.retrieve();
  this.context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethodUser), Function.createDelegate(this, this.onFailureMethodUser));
	this.context.load(this.web);
    this.context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethodTitle), Function.createDelegate(this, this.onFailureMethodTitle));
	this.context.load(this.web);
}

function onSuccessMethodUser(sender, args) {

    // currentUser.get_loginName().indexOf("i:0#.f|") == 0
    // powyższe sprawdzenie ma na celu ustalenie czy użytkownik jest formsowy, w innym przypadku link do AccountDetails nie powinien być widoczny
    try
    {
    	if (currentUser.get_loginName().indexOf("i:0#.f|") == 0)
    	{
			var kdpw_acclink = document.getElementById("ctl00_kdpwYourAcc");
			if (kdpw_acclink != null) 
			{
				kdpw_acclink.setAttribute("href", "/_layouts/Account/AccountDetails.aspx?usrAccount=" + this.currentUser.get_title() + "&lang=" + this.web.get_language());
			}
        	
			var kdpwccp_acclink = document.getElementById("ctl00_KDPWQLNavigation_CCP_kdpwYourAcc");
        	if (kdpwccp_acclink != null) 
			{
			    kdpwccp_acclink.setAttribute("href", "/_layouts/Account/AccountDetails.aspx?usrAccount=" + this.currentUser.get_title() + "&lang=" + this.web.get_language());
			}
        }
		else 
    	{
        	onFailureMethodUser(sender, args);
    	}
    }
    catch(e)
    {
		onFailureMethodUser(sender, args);
    } 
}

function onFailureMethodUser(sender, args) {
    //alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
    $('#ctl00_kdpwYourAcc').css("display", "none");
    $('#ctl00_kdpwYourAcc').next().css("display", "none");
    $('#ctl00_KDPWQLNavigation_CCP_kdpwYourAcc').css("display", "none");
    $('#ctl00_KDPWQLNavigation_CCP_kdpwYourAcc').next().css("display", "none");
}

function onSuccessMethodTitle(sender, args) {
  /*  this.title = this.web.get_title();
    var curHdr = document.getElementById("kdpw_currenttitle");
    if (curHdr != null) {
        var curTitle = document.getElementById("kdpw_currenttitle").getAttribute("title");
        curTitle = this.title;
        curHdr.innerHTML = this.title;
    }*/
}

function onFailureMethodTitle(sender, args) {

}

function getWebSiteLink() {
    var winLoc = window.location.href;
    return winLoc;
}

ExecuteOrDelayUntilScriptLoaded(this.getWebSiteData, "sp.js");

//]]>
