/**
 * Persoon object, for usage with custom cb scripts.
 */
Persoon = function(r, v, t, a, p, h, tv, s, w, f, vl, e, al, sp) {
	this.attributes = new Array();
	this.set("relatienummer", r);
	this.set("voornaam", v);
	this.set("tussenvoegsel", t);
	this.set("achternaam", a);
	this.set("postcode", p);
	this.set("huisnummer", h);
	this.set("toevoeging", tv);
	this.set("straat", s);
	this.set("woonplaats", w);
	this.set("volledigenaam", f);
	this.set("voorletters", vl);
	this.set("email", e);
	this.set("accesslevel", al);
	this.set("showprofile", sp);
}

/**
 * Persoon prototype.
 */
Persoon.prototype = {
	/**
	 * Returns the value of the attribute.
	 */
	get: function(name){return this.attributes[name];},

	/**
	 * Sets the value of the attribute.
	 */
	set: function(name, value){this.attributes[name] = value;}
}

/**
 * The persoon object.
 */
var persoon;
if (persoon == null) persoon = new Persoon('','','','','','','','','','','','','',0);

/**
 * Returns the relatie nummer of the persoon.
 */
function getRelatieNummer() { return persoon.get("relatienummer"); }



var loginDivEl = document.getElementById("loginBoxJS");
var loginto = null;
var userLoggedIn = true;
var varDoLogin = true;
if (loginDivEl) {
	doLogin();
} else {
	showLogin();
}

function doLogin() {
	var xmlHttp;
	try {
	    xmlHttp=new XMLHttpRequest();
    } catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
	    	    return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if (xmlHttp.responseText != null && xmlHttp.responseText.length > 0)
			{
				$("#login").html(xmlHttp.responseText);
				loginto = window.setTimeout(createPersoon, 100);
			} else {
				showLogin();
			}
		}
	}
	xmlHttp.open("GET","/algemeen/pvlogin",true);
	xmlHttp.send(null);
}

function showLogin() {
	if (varDoLogin) {
		try {
			$("#loginBox").css("visibility", "visible").css("display", "block");
		} catch (e) {}
	}
	$(document).ready(function(){
		// only execute the omniture script if it is present
		/*if (typeof window.doOmniture == 'function') {
			doOmniture();
		}*/
		createPersoon();
	});
}

function hideDossierHomepageLoginButtons()
{
	var buttonsDiv = document.getElementById("DossierHomepageLoginButtons");
	if (buttonsDiv) buttonsDiv.style.visibility = "hidden";
	try {
		$('div.tests .right-col .wordlid').toggle();
	} catch (e) {}
}

function createPersoon() {
	window.clearTimeout(loginto);
	try {
		str = stripCommentTags(document.getElementById("persoon").innerHTML);
		eval(str);
		document.getElementById("persoon").innerHTML = '';
		hideDossierHomepageLoginButtons();
	} catch (e) {}
	/*try {
		doOmniture();
	} catch (e) {
		loginto = window.setTimeout(createPersoon, 100);
	}*/
	try {
		if (onPersoon) onPersoon();
	} catch (e) {}
}



function stripCommentTags(str) {
	return str.substring(4, str.length-3);
}

jQuery(document).ready(function(){
	if(persoon != null && persoon.get('showprofile') == 1) {
		$('#myProfileLink').show();
	}
});
