








//##################################################################################################################
//## Cookie name constants
//##################################################################################################################

var BRFLOGON_USER  ='BRFLOGON_USER';
var BRFLOGON_HAS_BEEN_LOGGED_ON  ='BRFLOGON_HAS_BEEN_LOGGED_ON';

//##################################################################################################################
//## Global attributes & login functions
//##################################################################################################################

var loginURL		 = '/application/resources/j_security_check';
var glemtPasswordURL = '/application/resources/dialogs/logon/glemtPassword.do';
var opretURL		 = '/application/resources/dialogs/logon/opret.do';
var loginMineLaan = '/tamlogon/dialogs/cbtlogon/logon.do'
var loginBank = '/412568B30049A81F/alldocs/DOCURAN-6Y2H68?OpenDocument'
var loginRaadgiver = '/application/resources/dialogs/logon/logon.do?__actionCommand::visLoginSide=x'
var loginOces 		 = '/tamlogon/dialogs/cbtlogon/ocesLogon.do'
var loginNetId 		 = '/tamlogon/dialogs/cbtlogon/netidLogon.do'
var loginBrugerNavn  = '/application/resources/dialogs/logon/logon.do';
var opretNyBruger    = '/tamlogon/dialogs/cbtlogon/logon.do?__actionCommand::opretBruger=x';

var logoutURL		 = '/application/resources/ibm_security_logout';
var skiftPasswordURL = '/application/resources/dialogs/logon/skiftPassword.do';
var skiftBrugernavnURL = '/application/resources/dialogs/logon/skiftBrugernavn.do';
var indstillingerURL = '/application/minelaan/dialogs/personopl/personopl.do';

function insertLogonMenu() {
	
			//##################################################################################################################
			//## Menu when user is logged out
			//##################################################################################################################
		
			document.writeln('<form method=post action="' + secureUrl(loginURL) + '" name="login" >');
			document.writeln('<input type="hidden" name="j_target_uri" value="' +  document.URL + '">');
			document.writeln('<input type="hidden" name="logoutExitPage" value="' +  document.URL + '">');
			document.writeln('<input type="hidden" name="from_logon" value="true">');
			document.writeln('<table class="mainTdBoxes" cellspacing="0" >');
			// Blank lines between each table row
		
			document.writeln('<tr>');
			document.writeln('<td colspan="3" class="tdLogonTop"></td>');
			document.writeln('</tr>');
		
			document.writeln('<tr class="mainTdBoxes"> ');
			document.writeln('<td class="tdLogonHeader"></td>');
			document.writeln('<td class="tdLogonHeader">');
			document.writeln('<span class="contentBoxHeader"><b>Log ind</b></span>');
			
			document.writeln('</td>');
			document.writeln('<td class="tdLogonHeader marginRight"><img src="/412568AF004881F2/CGUView/icon_laas/$File/icon_laas.gif" alt="" /></td>');
			document.writeln('</tr>');
		
			blankWithColumnMargin();
		
			blankVerSpacingXS();
			
			document.writeln('<tr class="tdLogonContent"> ');
			document.writeln('<td colspan="3">');
			document.writeln('<table class="tdLogonContent" >');
			
			document.writeln('<tr class="tdLogonContent"> ');
			document.writeln('<td class="tdBlankHorSmall"></td>');	
			document.writeln('<td class="tdTop" colspan="3">');
			document.writeln('<table cellspacing="0" ><tr><td class="tdTop contentGoto"></td>');
			writeLink(loginMineLaan, "Mine l&aring;n");
		
			document.writeln('</td></tr></table></td>');
			document.writeln('</tr>');
			
			document.writeln('<tr class="tdLogonContent"> ');
			document.writeln('<td class="tdBlankHorSmall"></td>');	
			document.writeln('<td class="tdTop" colspan="3">');
			document.writeln('<table cellspacing="0" ><tr><td class="tdTop contentGoto"></td>');
			writeLink(loginBank, "BRFnetbank");
			document.writeln('</td></tr></table></td>');
			document.writeln('</tr>');
			
			
			document.writeln('<tr class="tdLogonContent"> ');
			document.writeln('<td class="tdBlankHorSmall"></td>');	
			document.writeln('<td  colspan="3">');
			document.writeln('<table cellspacing="0" ><tr><td class="tdTop contentGoto"></td>');
			writeLink(loginRaadgiver, "Samarbejdspartnere");			
			document.writeln('</tr></table></td>');
			document.writeln('</tr>');	
			
			document.writeln('</table>');
			document.writeln('</td>');
			document.writeln('</tr>');
			
			blankVerSpacingXS();
			blankVerSpacingXS();

			document.writeln('</table>');
			document.writeln('</form>');
	
	document.close();
}

function writeLink(url, text) {
	document.writeln('<td ><span class="contentmenubar"><a href=' + url + ' onclick="disableLinksAndInvokeAsSecure(this)">' + text + '</a></span></td>');
}

function writeLinkBlock(url, text) {
	document.writeln('<tr class="tdLogonContent">');
	document.writeln('<td></td>');
	document.writeln('<td class="tdpadLeft">');
	document.writeln('<table class="tdLogonContent">');
	document.writeln('<tr>');
	document.writeln('<td class="contentGoto"></td>');
	writeLink(url, text);
	document.writeln('</tr>');
	document.writeln('</table>');
	document.writeln('</td>');
	document.writeln('<td></td>');
	document.writeln('</tr>');
}

function blankWithColumnMargin() {
	document.writeln('<tr class="mainTdBoxes">');
	document.writeln('<td class="tdBlankHorSmall"></td>');
	document.writeln('<td></td>');
	document.writeln('<td class="tdBlankHorSmall"></td>');
	document.writeln('</tr>');
}

function blankVerSpacingXS() {
	document.writeln('<tr class="tdLogonContent"> ');
	document.writeln('<td colspan="3" class="tdBlankVerXSmall"></td>');
	document.writeln('</tr>');
}

function blankHorSpacingXS() {
	document.writeln('<tr class="tdLogonContent"> ');
	document.writeln('<td colspan="3" class="tdBlankHorXSmall"></td>');
	document.writeln('</tr>');
}

function loginboxonentersubmit() {
	if (window.event && window.event.keyCode == 13){
		logonActivate();
	}
}

function logoutActivate() {
	deleteCookie(BRFLOGON_USER,'/');
	deleteCookie(BRFLOGON_HAS_BEEN_LOGGED_ON, '/');
	logonActivate();
}

function setWorkingPointer() {
	if (document.all) {
		var list=document.getElementsByTagName("A");
		for (var i = 0; i < list.length; i++) {
			list[i].style.cursor = 'wait';
		}
	}
}

function setDefaultPointer() {
	if (document.all) {
		var list=document.getElementsByTagName("A");
		for (var i = 0; i < list.length; i++) {
			list[i].style.cursor = 'default';
		}
	}
}


function logonActivate() {

	try {
		document.forms["login"].submit();	
		setWorkingPointer();
	}
	catch (e) {
		setDefaultPointer();
	}
}

function addLocationRef() {
	// Strip previous params before adding the j_target_uri
	var URL = document.URL;
	var URLendIndex = URL.indexOf('?');
	if (URLendIndex != -1)
		URL = URL.substring(0, URLendIndex);

	return 'j_target_uri=' + escape(URL);
}
//##################################################################################################################
//## General functions
//##################################################################################################################


function rydfelt(fri) {
	//rydder felt ved klik med musen.
	if (fri.defaultValue==fri.value) {
		fri.value = "";
	}
}

var caution = false;

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie
// (defaults to end of current session)
// [path] - path for which the cookie is valid

// (defaults to path of calling document)
// [domain] - domain for which the cookie is valid
// (defaults to domain of calling document)
// [secure] - Boolean value indicating if
// the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {

	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");

	if (!caution || (name + "=" + escape(value)).length <= 4000) {
		document.cookie = curCookie;
	}
	else {
		if (confirm("Cookie exceeds 4KB and will be cut!")) {
			document.cookie = curCookie;
		}
	}
}

// name - name of the cookie
// * return string containing value
// of specified cookie or null if cookie
// does not exist
function getCookie(name) {
	var prefix = name + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix);

	if (cookieStartIndex == -1) {
		return null;
	}

	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);

	if (cookieEndIndex == -1) {
		cookieEndIndex = document.cookie.length;
	}

	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

// name - name of the cookie
// [path] - path of the cookie
// (must be same as path used to create cookie)
// [domain] - domain of the cookie
// (must be same as domain used to create cookie)
// * path and domain default if assigned
// null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// date - any instance of the Date object
// * you should hand all instances of the
// Date object to this function for "repairs"
// * this function is taken from
// Chapter 14, "Time and Date in JavaScript", in
// "Learn Advanced JavaScript Programming"
function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();

	if (skew > 0) {
		date.setTime(date.getTime() - skew);
	}
}

function secureUrl(url) {
	//<protocol>//<host>[:<port>]/<pathname>[<hash>][<search>]
	if (document.location.protocol != 'HTTPS:') {
		return ('HTTPS://' + document.location.host + url);
	}
	else {
		return (url);
	}
}


function disableALinks() {
	try{
		col=document.getElementsByTagName('A');
		oldClasses = new Array(col.length);
		oldHrefs = new Array(col.length);
		for (i=0; i<col.length; i++){
			oldClasses[i]=col[i].className;
			oldHrefs[i]=col[i].href;
			col[i].removeAttribute('href');
		}
	}
	catch(e){}
}

function disableLinksAndInvokeAsSecure(element) {
	if (element.href) {
		var url = element.href;
		disableALinks();

		redirectFramesetAlways(url);
	}
}

function getQueryDelimiter(url) {
	if (url.indexOf('?') >= 0) {
		return '&';
	} else {
		return '?';
	}
}

function stripProtocol(url) {
	var slashPos = url.indexOf('/');
	return url.substring(slashPos);
}

function stripServer(url) {
	var slashPos = url.indexOf('/');
	slashPos = url.indexOf('/', slashPos + 1);
	slashPos = url.indexOf('/', slashPos + 1);
	
	return url.substring(slashPos);
}

function redirectFramesetAlways(frameUrl) {
	// Skift til secure frameset med uændret dokument-URL
	
	var url = 'https:' + stripProtocol(frameUrl);
	
	url += getQueryDelimiter(frameUrl);
	url += "token=923439877";
	window.top.location.replace(url);
}


