
function Page (sPageId, sLang) {
	
	this.pageId = sPageId;
	this.lang = sLang;
	
	this.init ();
	
};


Page.prototype.init = function () {
	
	if (!this.lang)
		this.lang = 'nl';
	
	this.arrayParameters = new Array ();
	// Plaats parameters uit GET in array.

	var arrayParametersTemp = window.location.href.split (/\&/);
	arrayParametersTemp[0] = arrayParametersTemp[0].split (/\?/)[1];
	
	var pattern = /=/;
	
	for (var i = 0; i < arrayParametersTemp.length; i++) {
		
		if (pattern.test(arrayParametersTemp)) {
			
			var arrayParemeter = arrayParametersTemp[i].split (/=/);
			
			this.arrayParameters.push (new Parameter (arrayParemeter[0], arrayParemeter[1]));
			
		}
		
	}
	
};


Page.prototype.getAllParameters = function () {
	
	var sParameters = '';
	
	var arrayTemp = new Array ();
	
	for (var i = 0; i < this.arrayParameters.length; i++) {
		
		if (this.arrayParameters[i].valueLength > 0) {
			
			arrayTemp.push (this.arrayParameters[i]);
			
		}
		
	}
	
	for (var i = 0; i < arrayTemp.length; i++) {
		
		sParameters += arrayTemp[i].name + '=' + arrayTemp[i].value;
			
		if (i < arrayTemp.length - 1)
			sParameters += '&';
		
	}
	
	return sParameters;
	
}


Page.prototype.makeParameter = function (sName, sValue) {
	
	var bParFound = false;
	
	for (var i = 0; i < this.arrayParameters.length; i++) {
		
		if (this.arrayParameters[i].name == sName) {
			
			this.arrayParameters[i].value = sValue;
			bParFound = true;
			
		}
		
	}
	
	if (!bParFound) {
		this.arrayParameters.push (new Parameter (sName, sValue));
	}
	
}


Page.prototype.go = function (sPageId) {
	
	var sUrl = 'parser.aspx?PageID=' + sPageId;
	
	if (this.lang)
		sUrl += '&Lang=' + this.lang;
	
	location.href = sUrl;
	
}


Page.prototype.getParameter = function (sParamName) {
	
	for (var i = 0; i < this.arrayParameters.length; i++) {
		
		if (this.arrayParameters[i].name == sParamName)
			if (this.arrayParameters[i].value.length > 0)
				return decodeURIComponent (this.arrayParameters[i].value);
		
	}
	
}


function Parameter (sName, sValue) {
	
	this.name = String (sName);
	this.value = String (sValue);
	this.valueLength = this.value.length;
	
}

function submitForm(myForm) {
	//window.open("","Afrekenen","width=600,height=450,toolbar=0"); 
	window.open("","Afrekenen","width=1000,height=800,toolbar=0"); 
    myForm.target = "Afrekenen";
	myForm.submit();
}


function writeEmail (sDomain, sAlias, sDisplayText) {

    if (!sDisplayText)
        sDisplayText = sAlias + '\u0040' + sDomain;
	
	document.write ('<a href="mailto:' + sAlias + '\u0040' + sDomain + '">' + sDisplayText + '</a>');
	
}

function ImageFader(sIdImageContainer, iBlendDuration, iPause){
	
	this.imageContainer = document.getElementById(sIdImageContainer);
	this.blendDuration = iBlendDuration / 100;
	this.pause = iPause
	this.images = [];
	this.opacity = [];
	this.count;
	this.oldCount = -1;
	
	this.init();
	
}

ImageFader.prototype.init = function(){
	
	for(var i = 0; i < this.imageContainer.childNodes.length; i++){
		this.images[this.images.length] = this.imageContainer.childNodes[i];
		this.opacity[this.opacity.length] = .99;
	}
	this.count = this.images.length - 1;
	setTimeout(this.fade.bind(this), this.pause);
}


ImageFader.prototype.fade = function(){
	
	this.opacity[this.count] = this.opacity[this.count] - .01;
	
	if(this.oldCount != this.count){
		for(var i = 0; i < this.images.length; i++){
			if(i > this.count || this.oldCount == -1){
				this.images[i].style.opacity = this.opacity[i];
				this.images[i].style.MozOpacity = this.opacity[i];
				this.images[i].style.filter = 'alpha(opacity='+ Math.round(this.opacity[i]*100) +')';
				this.images[i].style.zIndex = this.images.length - i;
				this.images[i].style.visibility = 'visible';
			}
		}
		this.images[this.count].style.zIndex = 100;
	}
	
	if(this.opacity[this.count] > 0){
		this.images[this.count].style.opacity = this.opacity[this.count];
		this.images[this.count].style.MozOpacity = this.opacity[i];
		this.images[this.count].style.filter = 'alpha(opacity='+ Math.round(this.opacity[this.count]*100) +')';
		setTimeout(this.fade.bind(this), this.blendDuration);
	}
	
	this.oldCount = this.count;
	
	if(this.opacity[this.count] < 0){
		this.opacity[this.count] = .99;
		this.count++;
		/** De onderste code uitvoeren als je het plaatje continu wil laten loopen **/
		if(this.count == this.images.length){
			this.count = 0;
		}
		if(this.count == this.images.length - 2){
			this.count = 0;
		}
		else{
			setTimeout(this.fade.bind(this), this.pause);
		}
	}
}

Function.prototype.bind = function(scope) {
		
		var reference = this;
		
		return function() {
			reference.apply(scope, arguments);
		}
	};