var extranetActive = true;
function pageLoaded() {
	if (extranetActive) {
		setTimeout("pageLoadActions()", 300);
	}
}
function pageLoadActions() {
	// alert("page has loaded");
	var callUrl = urlRoot + "?template=currentUser";
	new Ajax.Request(callUrl, {
		onSuccess: function(transport) {
			checkIfLoggedIn(transport.responseText);
		}
	});
}
function checkIfLoggedIn(responseText) {
	var arr = responseText.split(";");
	userArr = new Array();
	for (var i=0; i < arr.length; i++) {
		userArr[arr[i].substring(0,arr[i].indexOf("="))] = arr[i].substring(arr[i].indexOf("=")+1);
	}
	if (userArr["USER_NAME"] == undefined) {
		// not logged in
		// alert("not logged in");
		notLoggedInAction();
	} else {
		// is logged in
		// alert("Hei " + userArr["USER_NAME"]);
		isLoggedInAction(userArr);
	}
	// alert(responseText);
}
function notLoggedInAction(userArr) {
	document.getElementById("extranetLogin").style.display="block";
}
function isLoggedInAction(userArr) {
	var el = document.getElementById("tabs");
	el.style.display="block";
	el = document.getElementById("extranetLogin");
	var str = "";
	str += '<div class="clearfix"><h3>Medlemsnett</h3><form action="IPS">';
	str += '<div class="userInfoText">'
	str += 'Du er logget inn som<br/><strong>';
	str += userArr["FIRST_NAME"] + ' ' + userArr["LAST_NAME"];
	str += '</strong></div><br/>';
	str += '<input type="hidden" name="module" value="Login"/>';
	str += '<input type="hidden" name="action" value="Logout"/>';
	str += '<input type="hidden" name="template" value="frontpage"/>';
	str += '<input type="submit" class="button" value="Logg ut"/>';
	str += '</form></div>';
	el.innerHTML = str;
	el.style.display="block";
}
if (navigator.userAgent.indexOf("MSIE") != -1) {
	window.attachEvent("onload", pageLoaded);
} else {
	window.addEventListener("load", pageLoaded, false);
}

function fbs_click() {
  u=location.href;
  t=document.title;
  window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
  return false;
}

function facebook_click() {
  u=location.href;
  t=document.title;
  window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
  return false;
}

function twitter_click() {
  u=location.href;
  t=document.title;
  window.open('http://twitter.com/home?status='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=810,height=436');
  return false;
}
