// portal.js

$(document).ready(function ()
{
    var serverRelativeUrl = _spPageContextInfo.siteServerRelativeUrl;	
    if (serverRelativeUrl == "/")
    {
        serverRelativeUrl = "";
    }

    ExecuteOrDelayUntilScriptLoaded(function () { initPortalData() }, "sp.js");
	
    $(".overview-items-anywhere365 a, #oldportal a").click(function () {
        var redirectUrl = GetMenuLinkUrl($(this).html());
        if (redirectUrl != "#") {
            window.location.href = redirectUrl;
        }
    });
	
	$( "#arrow-up" ).click(function() {
	  $( "#infographics" ).slideUp( "slow", function() {
		var arrowup = document.getElementById("arrow-up");
		arrowup.style.display = "none";
		var arrowdown = document.getElementById("arrow-down");
		arrowdown.style.display = "block";
	  });
	});

	$( "#arrow-down" ).click(function() {
	  $( "#infographics" ).slideDown( "slow", function() {
		var arrowdown = document.getElementById("arrow-down");
		arrowdown.style.display = "none";
		var arrowup = document.getElementById("arrow-up");
		arrowup.style.display = "block";
		arrowup.style.padding = "31px 23px 8px 11px";
	  });
	});
	

	  
	/* User Role */
	$( "#userrole-ucc" ).hover(
	  function() {
		
		$('#item-header-userrole').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/user_role_header_active.svg")');
		$("#item-header-userrole").css({"background-repeat":"no-repeat"});
		$("#item-header-userrole").css({"background-position":"4% 50%"});
		$("#item-header-userrole").css({"background-size":"40px 40px"});
		$("#item-header-userrole").css({"background-color":"#91be25"});

	  }, function() {
		$("#item-header-userrole").css("background-color", "#0e3349");
		$("#item-header-userrole").css({'background-image':'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/user_role_header.svg")'});
		$("#item-header-userrole").css({"background-repeat":"no-repeat"});
		$("#item-header-userrole").css({"background-position":"4% 50%"});
		$("#item-header-userrole").css({"background-size":"40px 40px"});
	  }
	);
	
	
	/* User Input */
	$( "#userinput-ucc" ).hover(
	  function() {
		  
		$('#item-header-userinput').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/user_input_header_active.svg")');
		$("#item-header-userinput").css({"background-repeat":"no-repeat"});
		$("#item-header-userinput").css({"background-position":"4% 50%"});
		$("#item-header-userinput").css({"background-size":"40px 40px"});		  
		$("#item-header-userinput").css({"background-color":"#f5b819"});
	  }, function() {
		$('#item-header-userinput').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/user_input_header.svg")');
		$("#item-header-userinput").css({"background-repeat":"no-repeat"});
		$("#item-header-userinput").css({"background-position":"4% 50%"});
		$("#item-header-userinput").css({"background-size":"40px 40px"});
		$("#item-header-userinput").css("background-color", "#0e3349");
	  }
	);
	
	/* Dialogue Intelligence */
	$( "#dialogueintelligence-ucc" ).hover(
	  function() {
		$('#item-header-dialogueintelligence').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/dialogue_intelligence_header_active.svg")');
		$("#item-header-dialogueintelligence").css({"background-repeat":"no-repeat"});
		$("#item-header-dialogueintelligence").css({"background-position":"4% 50%"});
		$("#item-header-dialogueintelligence").css({"background-size":"40px 40px"});	
		$("#item-header-dialogueintelligence").css({"background-color":"#2573b7"});
	  }, function() {
		$('#item-header-dialogueintelligence').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/dialogue_intelligence_header.svg")');
		$("#item-header-dialogueintelligence").css({"background-repeat":"no-repeat"});
		$("#item-header-dialogueintelligence").css({"background-position":"4% 50%"});
		$("#item-header-dialogueintelligence").css({"background-size":"40px 40px"});	
		$("#item-header-dialogueintelligence").css("background-color", "#0e3349");
	  }
	);

	/* UCC Config */
	$( "#uccconfig-ucc" ).hover(
	  function() {
		$('#item-header-uccconfig').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/ucc_config_header_active.svg")');
		$("#item-header-uccconfig").css({"background-repeat":"no-repeat"});
		$("#item-header-uccconfig").css({"background-position":"4% 50%"});
		$("#item-header-uccconfig").css({"background-size":"40px 40px"});  
		$("#item-header-uccconfig").css({"background-color":"#e95928"});
	  }, function() {
		$('#item-header-uccconfig').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/ucc_config_header.svg")');
		$("#item-header-uccconfig").css({"background-repeat":"no-repeat"});
		$("#item-header-uccconfig").css({"background-position":"4% 50%"});
		$("#item-header-uccconfig").css({"background-size":"40px 40px"});  
		$("#item-header-uccconfig").css("background-color", "#0e3349");
	  }
	);

	/* UCC General */
	$( "#uccgeneral-ucc" ).hover(
	  function() {

		$('#item-header-uccgeneral').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/ucc_general_header_active.svg")');
		$("#item-header-uccgeneral").css({"background-repeat":"no-repeat"});
		$("#item-header-uccgeneral").css({"background-position":"4% 50%"});
		$("#item-header-uccgeneral").css({"background-size":"40px 40px"}); 
		$("#item-header-uccgeneral").css({"background-color":"#35a6de"});
	  }, function() {

		$('#item-header-uccgeneral').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/ucc_general_header.svg")');
		$("#item-header-uccgeneral").css({"background-repeat":"no-repeat"});
		$("#item-header-uccgeneral").css({"background-position":"4% 50%"});
		$("#item-header-uccgeneral").css({"background-size":"40px 40px"}); 
		$("#item-header-uccgeneral").css("background-color", "#0e3349");
	  }
	);

	/* Actions */
	$( "#actions-ucc" ).hover(
	  function() {

		$('#item-header-actions').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/actions_header_active.svg")');
		$("#item-header-actions").css({"background-repeat":"no-repeat"});
		$("#item-header-actions").css({"background-position":"4% 50%"});
		$("#item-header-actions").css({"background-size":"40px 40px"}); 
		$("#item-header-actions").css({"background-color":"#1b98aa"});
	  }, function() {
		  
		$('#item-header-actions').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/actions_header.svg")');
		$("#item-header-actions").css({"background-repeat":"no-repeat"});
		$("#item-header-actions").css({"background-position":"4% 50%"});
		$("#item-header-actions").css({"background-size":"40px 40px"}); 
		$("#item-header-actions").css("background-color", "#0e3349");
	  }
	);

	/* Dialogue Management */
	$( "#dialoguemanagement-ucc" ).hover(
	  function() {

		$('#item-header-dialoguemanagement').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/dialogue_management_header_active.svg")');
		$("#item-header-dialoguemanagement").css({"background-repeat":"no-repeat"});
		$("#item-header-dialoguemanagement").css({"background-position":"4% 50%"});
		$("#item-header-dialoguemanagement").css({"background-size":"40px 40px"}); 
		$("#item-header-dialoguemanagement").css({"background-color":"#e62485"});
	  }, function() {

		$('#item-header-dialoguemanagement').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/dialogue_management_header.svg")');
		$("#item-header-dialoguemanagement").css({"background-repeat":"no-repeat"});
		$("#item-header-dialoguemanagement").css({"background-position":"4% 50%"});
		$("#item-header-dialoguemanagement").css({"background-size":"40px 40px"}); 
		$("#item-header-dialoguemanagement").css("background-color", "#0e3349");
	  }
	);

	/* Content Management */
	$( "#contentmanagement-ucc" ).hover(
	  function() {

		$('#item-header-contentmanagement').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/content_management_header_active.svg")');
		$("#item-header-contentmanagement").css({"background-repeat":"no-repeat"});
		$("#item-header-contentmanagement").css({"background-position":"4% 50%"});
		$("#item-header-contentmanagement").css({"background-size":"40px 40px"}); 
		$("#item-header-contentmanagement").css({"background-color":"#eb7819"});
	  }, function() {

		$('#item-header-contentmanagement').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/content_management_header.svg")');
		$("#item-header-contentmanagement").css({"background-repeat":"no-repeat"});
		$("#item-header-contentmanagement").css({"background-position":"4% 50%"});
		$("#item-header-contentmanagement").css({"background-size":"40px 40px"}); 
		$("#item-header-contentmanagement").css("background-color", "#0e3349");
	  }
	);

});




$( "#userrole-arrow-up" ).click(function() {

		var $userrole = $("#userrole-ucc");
		$userrole.css("height", $userrole.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $userrole.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowup = document.getElementById("userrole-arrow-up");
		arrowup.style.display = "none";
		var arrowdown = document.getElementById("userrole-arrow-down");
		arrowdown.style.display = "block";

});

$( "#userrole-arrow-down" ).click(function() {
	
		var $userrole = $("#userrole-ucc");
		$userrole.css("height", $userrole.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $userrole.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowdown = document.getElementById("userrole-arrow-down");
		arrowdown.style.display = "none";
		var arrowup = document.getElementById("userrole-arrow-up");
		arrowup.style.display = "block";
});

$( "#userinput-arrow-up" ).click(function() {

		var $userinput = $("#userinput-ucc");
		$userinput.css("height", $userinput.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $userinput.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowup = document.getElementById("userinput-arrow-up");
		arrowup.style.display = "none";
		var arrowdown = document.getElementById("userinput-arrow-down");
		arrowdown.style.display = "block";

});

$( "#userinput-arrow-down" ).click(function() {
	
		var $userinput = $("#userinput-ucc");
		$userinput.css("height", $userinput.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $userinput.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowdown = document.getElementById("userinput-arrow-down");
		arrowdown.style.display = "none";
		var arrowup = document.getElementById("userinput-arrow-up");
		arrowup.style.display = "block";
});

$( "#dialogueintelligence-arrow-up" ).click(function() {

		var $dialogueintelligence = $("#dialogueintelligence-ucc");
		$dialogueintelligence.css("height", $dialogueintelligence.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $dialogueintelligence.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowup = document.getElementById("dialogueintelligence-arrow-up");
		arrowup.style.display = "none";
		var arrowdown = document.getElementById("dialogueintelligence-arrow-down");
		arrowdown.style.display = "block";

});

$( "#dialogueintelligence-arrow-down" ).click(function() {
	
		var $dialogueintelligence = $("#dialogueintelligence-ucc");
		$dialogueintelligence.css("height", $dialogueintelligence.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $dialogueintelligence.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowdown = document.getElementById("dialogueintelligence-arrow-down");
		arrowdown.style.display = "none";
		var arrowup = document.getElementById("dialogueintelligence-arrow-up");
		arrowup.style.display = "block";
});

$( "#uccconfig-arrow-up" ).click(function() {

		var $uccconfig = $("#uccconfig-ucc");
		$uccconfig.css("height", $uccconfig.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $uccconfig.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowup = document.getElementById("uccconfig-arrow-up");
		arrowup.style.display = "none";
		var arrowdown = document.getElementById("uccconfig-arrow-down");
		arrowdown.style.display = "block";

});

$( "#uccconfig-arrow-down" ).click(function() {
	
		var $uccconfig = $("#uccconfig-ucc");
		$uccconfig.css("height", $uccconfig.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $uccconfig.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowdown = document.getElementById("uccconfig-arrow-down");
		arrowdown.style.display = "none";
		var arrowup = document.getElementById("uccconfig-arrow-up");
		arrowup.style.display = "block";
});

$( "#uccgeneral-arrow-up" ).click(function() {

		var $uccgeneral = $("#uccgeneral-ucc");
		$uccgeneral.css("height", $uccgeneral.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $uccgeneral.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowup = document.getElementById("uccgeneral-arrow-up");
		arrowup.style.display = "none";
		var arrowdown = document.getElementById("uccgeneral-arrow-down");
		arrowdown.style.display = "block";

});

$( "#uccgeneral-arrow-down" ).click(function() {
	
		var $uccgeneral = $("#uccgeneral-ucc");
		$uccgeneral.css("height", $uccgeneral.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $uccgeneral.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowdown = document.getElementById("uccgeneral-arrow-down");
		arrowdown.style.display = "none";
		var arrowup = document.getElementById("uccgeneral-arrow-up");
		arrowup.style.display = "block";
});

$( "#actions-arrow-up" ).click(function() {

		var $actions = $("#actions-ucc");
		$actions.css("height", $actions.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $actions.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowup = document.getElementById("actions-arrow-up");
		arrowup.style.display = "none";
		var arrowdown = document.getElementById("actions-arrow-down");
		arrowdown.style.display = "block";

});

$( "#actions-arrow-down" ).click(function() {
	
		var $actions = $("#actions-ucc");
		$actions.css("height", $actions.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $actions.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowdown = document.getElementById("actions-arrow-down");
		arrowdown.style.display = "none";
		var arrowup = document.getElementById("actions-arrow-up");
		arrowup.style.display = "block";
});

$( "#dialoguemanagement-arrow-up" ).click(function() {

		var $dialoguemanagement = $("#dialoguemanagement-ucc");
		$dialoguemanagement.css("height", $dialoguemanagement.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $dialoguemanagement.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowup = document.getElementById("dialoguemanagement-arrow-up");
		arrowup.style.display = "none";
		var arrowdown = document.getElementById("dialoguemanagement-arrow-down");
		arrowdown.style.display = "block";

});

$( "#dialoguemanagement-arrow-down" ).click(function() {
	
		var $dialoguemanagement = $("#dialoguemanagement-ucc");
		$dialoguemanagement.css("height", $dialoguemanagement.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $dialoguemanagement.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowdown = document.getElementById("dialoguemanagement-arrow-down");
		arrowdown.style.display = "none";
		var arrowup = document.getElementById("dialoguemanagement-arrow-up");
		arrowup.style.display = "block";
});

$( "#contentmanagement-arrow-up" ).click(function() {

		var $contentmanagement = $("#contentmanagement-ucc");
		$contentmanagement.css("height", $contentmanagement.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $contentmanagement.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowup = document.getElementById("contentmanagement-arrow-up");
		arrowup.style.display = "none";
		var arrowdown = document.getElementById("contentmanagement-arrow-down");
		arrowdown.style.display = "block";

});

$( "#contentmanagement-arrow-down" ).click(function() {
	
		var $contentmanagement = $("#contentmanagement-ucc");
		$contentmanagement.css("height", $contentmanagement.css("height") === '50px' ? '' : '50px');
		var $userroleLi = $contentmanagement.find('div').not('.item-header');
		$userroleLi.css("display", $userroleLi.css("display") === 'none' ? '' : 'none');
		
		var arrowdown = document.getElementById("contentmanagement-arrow-down");
		arrowdown.style.display = "none";
		var arrowup = document.getElementById("contentmanagement-arrow-up");
		arrowup.style.display = "block";
});



function checkMediaQuery(x) {
		if (x.matches) { 
		
		var $userrole = $("#userrole-ucc");
		$userrole.css({"height":"300px"});
		var $userroleLi = $userrole.find('div').not('.item-header');
		$userroleLi.css({"display":"block"});

		var $userinput = $("#userinput-ucc");
		$userinput.css({"height":"300px"});
		var $userinputLi = $userinput.find('div').not('.item-header');
		$userinputLi.css({"display":"block"});

		var $dialogueintelligence = $("#dialogueintelligence-ucc");
		$dialogueintelligence.css({"height":"300px"});
		var $dialogueintelligenceLi = $dialogueintelligence.find('div').not('.item-header');
		$dialogueintelligenceLi.css({"display":"block"});

		var $uccconfig = $("#uccconfig-ucc");
		$uccconfig.css({"height":"300px"});
		var $uccconfigLi = $uccconfig.find('div').not('.item-header');
		$uccconfigLi.css({"display":"block"});

		var $actions = $("#actions-ucc");
		$actions.css({"height":"621px"});
		var $actionsLi = $actions.find('div').not('.item-header');
		$actionsLi.css({"display":"block"});

		var $uccgeneral = $("#uccgeneral-ucc");
		$uccgeneral.css({"height":"621px"});
		var $uccgeneralLi = $uccgeneral.find('div').not('.item-header');
		$uccgeneralLi.css({"display":"block"});

		var $dialoguemanagement = $("#dialoguemanagement-ucc");
		$dialoguemanagement.css({"height":"621px"});
		var $dialoguemanagementLi = $dialoguemanagement.find('div').not('.item-header');
		$dialoguemanagementLi.css({"display":"block"});
		
		var $contentmanagement = $("#contentmanagement-ucc");
		$contentmanagement.css({"height":"621px"});
		var $contentmanagementLi = $contentmanagement.find('div').not('.item-header');
		$contentmanagementLi.css({"display":"block"});
				
		}else {
			
		}
}


var x = window.matchMedia("(min-width: 480px)")
checkMediaQuery(x) // Call listener function at run time
x.addListener(checkMediaQuery) // Attach listener function on state changes



function checkMediaQueryy(y) {
		if (y.matches) { 

		var $contentmanagement = $("#contentmanagement-ucc");
		$contentmanagement.css({"height":"auto"});
		
		var $userrole = $("#userrole-ucc");
		$userrole.css({"height":"auto"});

		var $userinput = $("#userinput-ucc");
		$userinput.css({"height":"auto"});

		var $dialogueintelligence = $("#dialogueintelligence-ucc");
		$dialogueintelligence.css({"height":"auto"});

		var $uccconfig = $("#uccconfig-ucc");
		$uccconfig.css({"height":"auto"});

		var $actions = $("#actions-ucc");
		$actions.css({"height":"auto"});

		var $uccgeneral = $("#uccgeneral-ucc");
		$uccgeneral.css({"height":"auto"});

		var $dialoguemanagement = $("#dialoguemanagement-ucc");
		$dialoguemanagement.css({"height":"auto"});
				
		}else {
			
		}
}


var y = window.matchMedia("(max-width: 479px)")
checkMediaQueryy(y) // Call listener function at run time
y.addListener(checkMediaQueryy) // Attach listener function on state changes



function checkMediaOnLandingMin1366(y) {
		if (y.matches) { 
		
		var $userrole = $("#userrole-ucc");
		$userrole.css({"height":"300px"});

		var $userinput = $("#userinput-ucc");
		$userinput.css({"height":"300px"});

		var $dialogueintelligence = $("#dialogueintelligence-ucc");
		$dialogueintelligence.css({"height":"300px"});

		var $uccconfig = $("#uccconfig-ucc");
		$uccconfig.css({"height":"300px"});

		var $actions = $("#actions-ucc");
		$actions.css({"height":"500px"});

		var $uccgeneral = $("#uccgeneral-ucc");
		$uccgeneral.css({"height":"500px"});

		var $dialoguemanagement = $("#dialoguemanagement-ucc");
		$dialoguemanagement.css({"height":"500px"});
		
		var $contentmanagement = $("#contentmanagement-ucc");
		$contentmanagement.css({"height":"500px"});
				
		}else {
			
		}
}

var y = window.matchMedia("(min-width: 1366px)")
checkMediaOnLandingMin1366(y) // Call listener function at run time
y.addListener(checkMediaOnLandingMin1366) // Attach listener function on state changes


function checkMediaOnLandingMin1920(y) {
		if (y.matches) { 
		
		var $userrole = $("#userrole-ucc");
		$userrole.css({"height":"300px"});

		var $userinput = $("#userinput-ucc");
		$userinput.css({"height":"300px"});

		var $dialogueintelligence = $("#dialogueintelligence-ucc");
		$dialogueintelligence.css({"height":"300px"});

		var $uccconfig = $("#uccconfig-ucc");
		$uccconfig.css({"height":"300px"});

		var $actions = $("#actions-ucc");
		$actions.css({"height":"621px"});

		var $uccgeneral = $("#uccgeneral-ucc");
		$uccgeneral.css({"height":"621px"});

		var $dialoguemanagement = $("#dialoguemanagement-ucc");
		$dialoguemanagement.css({"height":"621px"});
		
		var $contentmanagement = $("#contentmanagement-ucc");
		$contentmanagement.css({"height":"621px"});
				
		}else {
			
		}
}

var y = window.matchMedia("(min-width: 1920px)")
checkMediaOnLandingMin1920(y) // Call listener function at run time
y.addListener(checkMediaOnLandingMin1920) // Attach listener function on state changes


	

function activateHover(menuElement, elementId) {
    $("#sidebar li").removeClass("active");
    $(".overview-items ul li.item-header").removeClass("hover");
    if (menuElement != false) {
        $(menuElement).toggleClass("active");
    }
    $(".overview-items ul." + elementId + " li.item-header").toggleClass("hover");
}

function scrollToElement(elementId) {
    var topValue = 0;
    if (elementId == "uccgeneral" || elementId == "actions" || elementId == "dialoguemanagement" || elementId == "contentmanagement") {
        topValue = 1000;
    }
    $("#s4-workspace").animate({ scrollTop: topValue }, "2000");
}

function FillCircle(targetId, percentage) {
    var targetElementId = $("#circles-" + targetId).attr("ID");
    var circleImage = $("#circles-" + targetId).html();
    circle = Circles.create({
        id: targetElementId,
        value: percentage,
        maxValue: 100,
        text: circleImage,
        wrpClass: 'circles-wrp',
        textClass: 'circles-text',
        styleText: true,
        styleWrapper: true,
        radius: 50,
        width: 10,
        colors: ['#f2f2f2', '#91be25']
    });
}

function CreateCanvas(divId) {
    var divElement = $("#" + divId);
    var canvas = document.createElement("canvas");
    divElement.append(canvas);
    if (typeof G_vmlCanvasManager != "undefined") {
        canvas = G_vmlCanvasManager.initElement(canvas);
    }
    var ctx = canvas.getContext("2d");
    return ctx;
}

function CreateGraph(targetId, inputArray) {
    var ctx = CreateCanvas("ig-columnChart-" + targetId);
    var graph = new BarGraph(ctx);
    graph.maxValue = ArrayMinMaxValue(inputArray).MaxValue;
    graph.margin = 2;
    graph.colors = ["#ec1b89"];
    graph.height = 40;

    setInterval(function () {
        graph.update([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
        graph.update(inputArray);
    }, 0);
}

function CreateChart(targetId, doughnutData, percentageInnerCutoutValue) {
    if (typeof percentageInnerCutoutValue == "undefined" || percentageInnerCutoutValue == null) {
        percentageInnerCutoutValue = 50;
    }

    var ctx = document.getElementById("chart-area" + targetId).getContext("2d");
    new Chart(ctx).Doughnut(doughnutData, { responsive: true, segmentShowStroke: false, percentageInnerCutout: percentageInnerCutoutValue, showTooltips: true, tooltipFontSize: 9 });

    for (var i = 0; i < doughnutData.length; i++) {
		
        var outputElementId = "chart-label" + targetId + "-" + i;
     /* var outputHtml = "<li id='" + outputElementId + "'><div></div><label>" + doughnutData[i].label + "</label><span>" + doughnutData[i].value + "</span></li>"; */
		var outputHtml = "<li id='" + outputElementId + "'><div></div><label>" + doughnutData[i].value + "</label><span>" + doughnutData[i].label + "</span></li>";
        $("#chart-label" + targetId).append(outputHtml);
        $("#" + outputElementId + " div").css("background-color", doughnutData[i].color);
		$("#" + outputElementId + " > label").css("color", doughnutData[i].color);
    }
}

function CreateEmptyChart(targetId, doughnutData, percentageInnerCutoutValue) {
    if (typeof percentageInnerCutoutValue == "undefined" || percentageInnerCutoutValue == null) {
        percentageInnerCutoutValue = 50;
    }

    var ctx = document.getElementById("chart-area" + targetId).getContext("2d");
    new Chart(ctx).Doughnut(doughnutData, { responsive: true, segmentShowStroke: false, percentageInnerCutout: percentageInnerCutoutValue, showTooltips: true, tooltipFontSize: 9 });

    for (var i = 0; i < doughnutData.length; i++) {
	    var outputElementId = "chart-label" + targetId + "-" + i;
		var outputHtml = "<li id='" + outputElementId + "'><div></div><span>" + doughnutData[i].label + "</span></li>";
        $("#chart-label" + targetId).append(outputHtml);
        $("#" + outputElementId + " div").css("background-color", doughnutData[i].color);
		$("#" + outputElementId + " > label").css("color", doughnutData[i].color);	
    }
}

function PrepDoughnutData1() {
    var doughnutData = [];
 /* var colorArray = ["#0d77b0", "#35a6de", "#f7bb00", "#1b98aa", "#91be25"]; */
	var colorArray = ["#0e3349", "#2573b7", "#f5b819", "#35a6de", "#91be25"];

	if(agentCount === 0 && supervisorCount === 0 && trainerCount === 0 && traineeCount === 0)
	{
		var newObj = { value: "1", color: "#d0d0e1", label: "No data" };
		doughnutData.push(newObj);
		
		CreateEmptyChart("1", doughnutData, 77);
		
	}else{
		var newObj = { value: agentCount, color: colorArray[0], label: resource_portal_label_Agents };
		doughnutData.push(newObj);
		newObj = { value: supervisorCount, color: colorArray[2], label: resource_portal_label_Supervisors };
		doughnutData.push(newObj);
		//newObj = { value: trainerCount, color: colorArray[3], label: resource_portal_label_Trainers };
		//doughnutData.push(newObj);
		//newObj = { value: traineeCount, color: colorArray[1], label: resource_portal_label_Trainees };
		//doughnutData.push(newObj);
		
		CreateChart("1", doughnutData, 77);
	}
}

function PrepDoughnutData2() {
    var doughnutData = [];
 /* var colorArray = ["#0d77b0", "#35a6de", "#f5b819", "#1b98aa", "#91be25"]; */
	var colorArray = ["#bebcbc", "#0e3349", "#2573b7", "#1b98aa", "#91be25"];
	
	if(pendingCount === 0 && acceptedCount === 0 && failedCount === 0)
		{
			var newObj = { value: "1", color: "#d0d0e1", label: "No data" };
			doughnutData.push(newObj);
			
			CreateEmptyChart("2", doughnutData, 77);
			
		}else{
			var newObj = { value: pendingCount, color: colorArray[2], label: resource_portal_label_Pending };
			doughnutData.push(newObj);
			newObj = { value: acceptedCount, color: colorArray[1], label: resource_portal_label_Accepted };
			doughnutData.push(newObj);
			newObj = { value: failedCount, color: colorArray[0], label: resource_portal_label_Failed };
			doughnutData.push(newObj);

			CreateChart("2", doughnutData, 77);
		}
}


function PrepDoughnutData3() {
   
	var doughnutData = [];
	var colorArray = ["#0d77b0", "#35a6de", "#f7bb00", "#1b98aa", "#91be25"];
		
	if(skillsPerAgentCount === 0){
			var newObj = { value: "1", color: "#d0d0e1", label: "No data" };
			doughnutData.push(newObj);
			
			CreateEmptyChart("3", doughnutData, 77);
	}else{

		var i = 0;
		$.each(skillsData, function (key, obj) {
        if (i < 5 && obj.ContentType != "ChatSkill" && obj.ContentType != "ChatForwardSkill") {
            var skill = obj.Skill;
            if (skill.length > 15) {
                skill = skill.substring(0, 12);
                skill = skill + "...";
            }

            var newObj = { value: obj.AgentCount, color: colorArray[i], label: skill };
            doughnutData.push(newObj);
            i++;
        }
		});
		CreateChart("3", doughnutData, 77);
	}
}

function GetMenuLinkUrl(menuItemTitle) {
    var returnValue = "#";
	var siteCollectionUrl;
	siteCollectionUrl = _spPageContextInfo.webAbsoluteUrl;

    if (menuItemTitle != null && menuItemTitle != "") {
        var requestUrl = document.URL;
        menuItemTitle = menuItemTitle.toLowerCase();
        menuItemTitle = menuItemTitle.replace(/\s/g, "");
        menuItemTitle = menuItemTitle.replace("/", "");

        var result = $.grep(menuData, function (e) { return e.SearchTitle == menuItemTitle; });
        if (result != null && result.length == 1) {
            var tmpUrl = result[0].URL;
            if (tmpUrl != null && tmpUrl != "") {
                var pos0 = tmpUrl.toLowerCase().indexOf("http");
                if (pos0 == -1) {
                    tmpUrl = tmpUrl.substring(pos0);
                    var urlPrefix = "..";
                    var tmpRequestUrl = requestUrl.toLowerCase();
                    var pos1 = tmpRequestUrl.indexOf("/pages/");
                    var pos2 = tmpRequestUrl.indexOf("/paginas/");
                    var pos3 = tmpRequestUrl.indexOf("/seiten/");
                    var pos4 = tmpRequestUrl.indexOf("/pagine/");
                    var pos5 = tmpRequestUrl.indexOf("/sayfalar/");
                    var pos6 = tmpRequestUrl.indexOf("/sidor/");
                    var pos7 = tmpRequestUrl.indexOf("/sider/");

                    if (pos1 == -1 && pos2 == -1 && pos3 == -1 && pos4 == -1 && pos5 == -1 && pos6 == -1 && pos7 == -1) {
                        urlPrefix = ".";
                    }
                    tmpUrl = siteCollectionUrl + tmpUrl;
                    returnValue = tmpUrl;
                }
                else {
                    returnValue = tmpUrl;
                }
            }
        }
    }

    return returnValue;
}

function DisplayBusinessHours() {
    var htmlOutput = "";

    if (businessHoursData != null && businessHoursData.length > 0) {
        var outputValue = { State: resource_portal_label_Closed, Till: "", Remaining: "" };
        var current = ParseCurrentTime();
        var tmpStartTime = { DisplayTime: null, ParsedTime: null };
        var tmpEndTime = { DisplayTime: null, ParsedTime: null };

        var result = $.grep(businessHoursData, function (e) { return e.DayCode == current.Day; });
        $.each(result, function (key, value) {
            if (value.AllDay == true) {
                outputValue.State = resource_portal_label_Open;
                outputValue.Till = " " + resource_portal_label_AllDay;
                return false;
            }
            else {
                var start = ParseTime(value.Start);
                var end = ParseTime(value.End);

                // Skip if start time is not before end time
                if (start.ParsedTime >= end.ParsedTime) {
                    return true;
                }

                if (current.ParsedTime >= start.ParsedTime && current.ParsedTime < end.ParsedTime) {
                    // Within the current section
                    outputValue.State = resource_portal_label_Open;
                    tmpEndTime = end;
                    outputValue = GetOutputValue(outputValue, end);
                }
                else if (current.ParsedTime < start.ParsedTime) {
                    // Future section: Only update if it's closer than previously found start time
                    if (tmpStartTime.ParsedTime == null || start.ParsedTime < tmpStartTime.ParsedTime) {
                        tmpStartTime = start;
                        // Update 'Till' only if the business is closed
                        if (outputValue.State === resource_portal_label_Closed) {
                            outputValue = GetOutputValue(outputValue, start);
                        }
                    }
                }
            }
        });

        htmlOutput = outputValue.State + outputValue.Till + outputValue.Remaining;
    } else {
        htmlOutput = resource_portal_label_NotConfigured;
    }
	
    $("#businesshours").html(htmlOutput).css({
        "background-color": "#91be25",
        "color": "white",
        "border-radius": "15px",
        "padding": "2px 7px 2px 7px",
        "display": "inline-block",
        "list-style-type": "none"
    });
}

function DisplayHolidays() {
    var htmlOutput = "";
	var htmlOutput2 = "";

    if (holidaysData != null && holidaysData.length > 0) {
        htmlOutput += "<ul>";
        var currentFormattedDate = currentDate.format("YYYYMMDDHHmm");
        var result = $.grep(holidaysData, function (e) { return e.FormattedStartDate >= currentFormattedDate || (e.FormattedStartDate < currentFormattedDate && e.FormattedEndDate > currentFormattedDate) });
        $.each(result, function (key, value) {
            var displayDate = "";
            var remaining = "";
            if (value.FormattedStartDate >= currentFormattedDate) {
				var displayDate = moment.utc(value.FormattedStartDate, "YYYYMMDDHHmm").utcOffset(utcOffset).format(localizedStrings[lcid][2].toUpperCase());
				
                if (value.FormattedStartDate == currentFormattedDate) {
                    displayDate = resource_portal_label_Today;
                }
                else {
                    var d = value.MomentStartDate.diff(currentDate, "days");
                    if (d == 0) {
                        remaining = " - 1 " + resource_portal_label_Day + " " + resource_portal_label_Remaining;
                    }
                    else {
                        d = d + 1;
                        remaining = " - " + d + " " + resource_portal_label_Days + " " + resource_portal_label_Remaining;
                    }
                }
            }
            else if (value.FormattedStartDate < currentFormattedDate && value.FormattedEndDate > currentFormattedDate) {
                displayDate = resource_portal_label_Today;
            }			
			
            /* htmlOutput += "<li>" + subject + " (" + displayDate + remaining + ")</li>"; */
			
			htmlOutput += "<li>" + value.Holiday + "</li>"
			htmlOutput2 += "<li>" + displayDate + remaining + "</li>";
			 
        });
        htmlOutput += "</ul>";
    }
    else {
        htmlOutput = resource_portal_label_NoHolidays;
    }

	$("#holidays").html(htmlOutput).css({"border-radius":"15px","background":"#2573b7","padding":"2px 7px 2px 7px","height": "auto","color":"white","list-style-type": "none !important"});
	$("#daysRemaining").html(htmlOutput2);
}

function DisplaySettings()
{
    var serverRelativeUrl = _spPageContextInfo.siteServerRelativeUrl;
    if (serverRelativeUrl == "/")
    {
        serverRelativeUrl = "";
    }
	
    $("#callRecording").html(resource_portal_label_NotConfigured);
	$('#callRecording').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/header_no_check.svg")');
	$("#callRecording").css({"color":"#e74b17","background-repeat": "no-repeat", "background-position": "8px center", "text-align": "center", "background-size": "15px"});
	
	//$("#callRecording").css({"color":"#ec781b","background": "url('Style Library/Anywhere365/Images/portal/SVG/header_no_check.svg')","background-repeat": "no-repeat", "background-position": "8px center", "text-align": "center"});
    $("#inboundCallRecording").html(resource_portal_label_NotConfigured);
	$('#inboundCallRecording').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/header_no_check.svg")');
	$("#inboundCallRecording").css({"color":"#e74b17","background-repeat": "no-repeat", "background-position": "8px center", "text-align": "center", "background-size": "15px"});
   
    $("#outboundCallRecording").html(resource_portal_label_NotConfigured);
	$('#outboundCallRecording').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/header_no_check.svg")');
    $("#outboundCallRecording").css({"color":"#e74b17","background-repeat": "no-repeat", "background-position": "8px center", "text-align": "center", "background-size": "15px"});
 
    $("#internalCallRecording").html(resource_portal_label_NotConfigured);
	$('#internalCallRecording').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/header_no_check.svg")');
    $("#internalCallRecording").css({"color":"#e74b17","background-repeat": "no-repeat", "background-position": "8px center", "text-align": "center", "background-size": "15px"});

	if (settingsData != null && settingsData.length > 0) {
        var result1 = $.grep(settingsData, function (e) { return e.Key == "UseAudioRecording"; });
        if (result1 != null && result1.length == 1) {
            if (result1[0].Value == "true") {
                $("#callRecording").html(resource_portal_label_Active);
                $("#callRecording").css("color", "#91be25");
				$('#callRecording').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/header_check.svg")');
				$("#callRecording").css({"color":"#91be25","background-repeat": "no-repeat", "background-position": "8px center", "text-align": "center", "background-size": "15px"});
            }
            else {
                $("#callRecording").html(resource_portal_label_Disabled);
                $("#callRecording").css("color", "#e74b17");
            }
        }
        var result2 = $.grep(settingsData, function (e) { return e.Key == "EnableInboundInterception"; });
        if (result2 != null && result2.length == 1) {
            if (result2[0].Value == "true") {
                $("#inboundCallRecording").html(resource_portal_label_Active);
				$('#inboundCallRecording').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/header_check.svg")');
				$("#inboundCallRecording").css({"color":"#91be25","background-repeat": "no-repeat", "background-position": "8px center", "text-align": "center", "background-size": "15px"});
            }
            else {
                $("#inboundCallRecording").html(resource_portal_label_Disabled);
                $("#inboundCallRecording").css("color", "#e74b17");
            }
        }
        var result3 = $.grep(settingsData, function (e) { return e.Key == "EnableOutboundInterception"; });
        if (result3 != null && result3.length == 1) {
            if (result3[0].Value == "true") {
                $("#outboundCallRecording").html(resource_portal_label_Active);
				$('#outboundCallRecording').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/header_check.svg")');
				$("#outboundCallRecording").css({"color":"#91be25","background-repeat": "no-repeat", "background-position": "8px center", "text-align": "center", "background-size": "15px"});
            }
            else {
                $("#outboundCallRecording").html(resource_portal_label_Disabled);
                $("#outboundCallRecording").css("color", "#e74b17");
            }
        }
        var result4 = $.grep(settingsData, function (e) { return e.Key == "InterUserRecordingDisabled"; });
        if (result4 != null && result4.length == 1) {
            if (result4[0].Value == "false") {
                $("#internalCallRecording").html(resource_portal_label_Active);
				$('#internalCallRecording').css('background-image', 'url("'+ serverRelativeUrl +'/Style Library/Anywhere365/Images/portal/SVG/header_check.svg")');
				$("#internalCallRecording").css({"color":"#91be25","background-repeat": "no-repeat", "background-position": "8px center", "text-align": "center", "background-size": "15px"});
				
            }
            else {
                $("#internalCallRecording").html(resource_portal_label_Disabled);
                $("#internalCallRecording").css("color", "#e74b17");
            }
        }
    }
}

function CalulateTimeDifference(inputTime) {
    var a = moment().utc().utcOffset(utcOffset);
    var b = moment().utc().utcOffset(utcOffset).hour(inputTime.substring(0, 2)).minute(inputTime.substring(3));
    var h = b.diff(a, "hours");
    var m = b.diff(a, "minute");
    m = m % 60;

    return { Hour: h, Minute: m }
}

function ParseTime(inputTime) {
    var parsedTime = inputTime.replace(":", "");
    var parsedTime = parseInt(parsedTime);

    return { DisplayTime: inputTime, ParsedTime: parsedTime }
}

function ParseCurrentTime() {
    var currentDay = currentDate.isoWeekday();
    var currentHour = currentDate.hours();
    if (parseInt(currentHour) < 10) {
        currentHour = "0" + currentHour;
    }
    var currentMinute = currentDate.minutes();
    if (parseInt(currentMinute) < 10) {
        currentMinute = "0" + currentMinute;
    }
    var tmpTimeParse = ParseTime(currentHour + "" + currentMinute);

    return { Day: currentDay, ParsedTime: tmpTimeParse.ParsedTime }
}

function GetOutputValue(outputValue, inputTime) {
    outputValue.Till = " " + resource_portal_label_Till + " " + inputTime.DisplayTime;
    var calulatedTimeDiff = CalulateTimeDifference(inputTime.DisplayTime);
    outputValue.Remaining = " (" + calulatedTimeDiff.Hour + "h, " + calulatedTimeDiff.Minute + "m " + resource_portal_label_Remaining + ")";

    return outputValue;
}

function ArrayMinMaxValue(inputArray) {
    var minValue = 0;
    var maxValue = 0;

    if (inputArray != null && inputArray.length > 0) {
        $.each(inputArray, function (key, value) {
            if (key == 0) {
                minValue = value;
            }
            else {
                if (value < minValue) {
                    minValue = value;
                }
            }

            if (value > maxValue) {
                maxValue = value;
            }
        });
    }

    return { MinValue: minValue, MaxValue: maxValue }
}
