/* Function that updates the display in the header of the status of login (register or the name of the logged in user) */

function updateHeaderLoginStatus() {
	if ($.Storage.get("username")) {
		$("#headerLoginStatus").text("Hola, " + $.Storage.get("Name") + ".");
		$("#account-logout").text("¿No eres "+$.Storage.get("Name")+"? ");
		$("#account-logout").append(" <a href='javascript:doLogout();'>Cerrar Sesión</a>");
		$("#account-logout").show();
		if ($.Storage.get("UserApp") == "Admin" && $.Storage.get("browser") != "iphone") {
			$("#menu-admin").show();
		}
		else {
			$("#menu-admin").hide();
		}
	}
	else {
		$("#headerLoginStatus").text("");
		$("#headerLoginStatus").prepend("<a href='/signup.php'>Regístrate</a>");
		$("#menu-admin").hide();
		$("#account-logout").hide();
		
	}
}

function doLogout() {
	$.Storage.remove('username');
	$.Storage.remove('UserApp');
	$.Storage.remove('Name');
	$("#menu-account-management").hide();
	$("#menu-admin").hide();
	updateHeaderLoginStatus();
}

/**
 * Fetches and Display an article
 * @param {Object} id
 */
function getRelatedArticle(id, referrer,topic,keywords) { 
	$.post('/lib/mining/ajx_article_traffic.php', {article_id : id, browser: $.Storage.get('browser'), platform : $.Storage.get('platform'), click_source : referrer}, function(data) {
	window.location.href="/articulos/"+topic+"/"+id+"/"+keywords+""; 
	});}
/**
 * Checks that the user has security clearance to access information
 * @param String $app
 */
function checkCreds($app) {
	if ($.Storage.get('UserApp') != $app) {
		window.location.href="/denied.php"; 
	}
}

function getVendorDetails(id,vertical,name) { 
window.location.href="/especialistas/"+vertical+"/"+id+"/"+name+""; }

/**
 * Initializes and new Tab system if non exists or add a new tab if one is needed
 * @param tabName
 * @param tabId
 */
function initTabs(tabName, tabId) {
	
	if (typeof $("#tabs") !== 'undefined' && $("tabs") !== null) {
		var tabList = $("<ul>").attr('id','tabList').append('<li><a href="#'+tabId+'">'+tabName+'</a></lib>');
		var newTab = $("<div>").attr('id',tabId);
		var tabs = $("<div>").attr('id', 'tabs').append(tabList).append(newTab);
		$("#index-block").append(tabs);
	} else {
		$("#tabList").append('<li><a href="'+tabId+'">'+tabName+'</a></lib>');
		var newTab = $("<div>").attr('id',tabId);
		$("#tabs").append(newTab);
	}
	$("#tabs").tabs();
	
}

