function getEnergyTypeAndSubmit() {
	cForm = document.getElementById('content_form');
	// Tab-index 0 en 1 => Elektriciteit Groen (2)
	// Tab-index 2, 3 en 4 => Elektriciteit Grijs (1)
	if (tabPane1.getSelectedIndex() < 2) {
		cForm.productAdvicePartA.value = 2;
	} else {
		cForm.productAdvicePartA.value = 1;
	}
	var contractType = cForm.question3.value;
	switch (contractType) {
	case 0:
		cForm.productAdvicePartB.value = 1
	case 2:
		cForm.productAdvicePartB.value = 3
	case 3:
		cForm.productAdvicePartB.value = 0
	}
	cForm.action = '/productadvies.keuze.php';
	cForm.submit();
}

function checkProductWijzerSelectie() {
	var vraag20 = document.getElementById('question20');
	var vraag21 = document.getElementById('question21');
	var vraag30 = document.getElementById('question30');
	var vraag32 = document.getElementById('question32');
	var vraag33 = document.getElementById('question33');
	var label30 = document.getElementById('question30Label');
	var label31 = document.getElementById('question31Label');
	var label32 = document.getElementById('question32Label');
	var label33 = document.getElementById('question33Label');
	var vraagNummer = new Array(30, 32);
	var blokkeerOptieOnbepaald = vraag20.checked;
	var blokkeerOptieVastePeriode = vraag21.checked;
	if (blokkeerOptieOnbepaald) {
		vraag33.checked = false;
		vraag33.disabled = true;
		label33.style.color = 'gray';
	} else {
		vraag33.disabled = false;
		label33.style.color = '#000';
	}
	if (blokkeerOptieVastePeriode) {
		for ( var i = 0, n = vraagNummer.length; i < n; i++) {
			eval('vraag' + vraagNummer[i] + '.checked = false;');
			eval('vraag' + vraagNummer[i] + '.disabled = true;');
			eval('label' + vraagNummer[i] + '.style.color = "gray";');
		}
		vraag33.checked = true;
	} else {
		for ( var i = 0, n = vraagNummer.length; i < n; i++) {
			eval('vraag' + vraagNummer[i] + '.disabled = false;');
			eval('label' + vraagNummer[i] + '.style.color = "#000";');
		}
	}
}

/**
 * Digitale meterkaart - Gegevens aanpassen onChange textfield event
 */
function changeGasBaseUsage() {
	changeBaseUsage('gasUsage', 'basisverbruikGas');
}

function changeHeatBaseUsage() {
	changeBaseUsage('heatUsage', 'basisverbruikWarmte');
}

function changeBaseUsage(usageId, baseUsageId) {
	var usage = document.getElementById(usageId);
	var baseUsage = document.getElementById(baseUsageId);
	var baseUsageValue = (Math.round((parseInt(usage.value) * .004)))
			.toString();
	baseUsage.innerHTML = (isNaN(baseUsageValue) ? 0 : baseUsageValue);
}

function showMailAddress(isSameAddress) {
	document.getElementById('mailAddress').style.display = 'inline';
	var form = document['content_form'];

	if (isSameAddress) {
		form.numberMailAddress.value = form.numberVisitAddress.value;
		form.postfixMailAddress.value = form.postfixVisitAddress.value;
		form.zipMailAddress.value = form.zipVisitAddress.value;
		if (form.streetMailAddress)
			form.streetMailAddress.value = form.streetVisitAddress.value;
		if (form.cityMailAddress)
			form.cityMailAddress.value = form.cityVisitAddress.value;

	} else {
		form.numberMailAddress.value = '';
		form.postfixMailAddress.value = '';
		form.zipMailAddress.value = '';
		if (form.streetMailAddress)
			form.streetMailAddress.value = '';
		if (form.cityMailAddress)
			form.cityMailAddress.value = '';
	}
	return false;
}

function hideMailAddress() {
	document.getElementById('mailAddress').style.display = 'none';
	var form = document['content_form'];
	form.numberMailAddress.value = '';
	form.postfixMailAddress.value = '';
	form.zipMailAddress.value = '';
	if (form.streetMailAddress)
		form.streetMailAddress.value = '';
	if (form.cityMailAddress)
		form.cityMailAddress.value = '';
	return false;
}

function copyShipmentAddress() {
	var fieldNames = new Array();
	fieldNames[0] = "number";
	fieldNames[1] = "postfix";
	fieldNames[2] = "zip";
	fieldNames[3] = "street";
	fieldNames[4] = "city";
	var fieldElement = null;
	for ( var i = 0; i < fieldNames.length; i++) {
		fieldElement = document.getElementById(fieldNames[i] + "VisitAddress");
		if (fieldElement != null) {
			document.getElementById(fieldNames[i] + "1").value = fieldElement.value;
		}
	}
}

function numberOfShipmentsChangedBzw(num) {
	if (num < 6) {
		s = document.getElementById("shipment6");
		s.style.display = 'none';

		numberOfShipmentsChanged(num);
	} else {
		s = document.getElementById("shipment6");
		s.style.display = 'inline';

		numberOfShipmentsChanged(0);
	}
}

function numberOfShipmentsChanged(num) {
	var fieldNames = new Array();
	fieldNames[0] = "number";
	fieldNames[1] = "postfix";
	fieldNames[2] = "zip";
	fieldNames[3] = "street";
	fieldNames[4] = "city";

	var e;
	for (i = num; i < 5; i++) {
		var shipmentNum = i;
		shipmentNum++;
		for (j = 0; j < fieldNames.length; j++) {
			e = document.getElementsByName(fieldNames[j] + shipmentNum);
			if (e[0]) {
				e[0].value = '';
			}
		}
	}
	for (i = 0; i < 5; i++) {
		k = i;
		k++;
		s = document.getElementById("shipment" + k);
		if (s) {
			if (k <= num)
				s.style.display = 'inline';
			else
				s.style.display = 'none';
		}
	}
}

function setFormAction(action, formname) {
	document[formname].action.value = action;
}

function start() {

}

function setFirstActionClass(className) {
	if (!document.getElementById("firstAction"))
		return;
	var firstAction = document.getElementById("firstAction");
	firstAction.className = className;
}

sfHover = function() {
	var items = new Array();
	items[0] = document.getElementById("navActiveItem");
	items[1] = document.getElementById("topLevel");
	items[2] = document.getElementById("navActiveSection");
	items[3] = document.getElementById("navCockpit");
	items[4] = document.getElementById("navTabbed");

	var elements;
	var sfEls = new Array();
	for ( var i = 0; i < items.length; i++) {
		elements = new Array();
		if (items[i] != null)
			elements = items[i].getElementsByTagName("LI");

		for ( var j = 0; j < elements.length; j++)
			sfEls[sfEls.length] = elements[j];
	}

	for ( var i = 0; i < sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			this.className += " sfhover";
		}
		sfEls[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp(" sfhover\\b"),
					"");
		}
	}
}
// if (window.attachEvent) window.attachEvent("onload", sfHover);

function checkState() {
	if (window.opener.document.readyState == "complete")
		window.focus();
	else
		winFocus();
}

function winFocus() {
	if (window.opener)
		if (window.opener.document.readyState)
			window.opener.document.onReadyStateChange = checkState();
}

function NewWindow(href) {
	window
			.open(
					href,
					"NewWindow",
					"toolbar=yes,location=yes,menubar=yes,status=yes,resizable=yes,titlebar=yes,scrollbars=yes,top=0");
}

function NewFormWindow(href) {
	window.open(href, "NewWindow", "width=420,height=550,scrollbars=yes");
}

function openRWESearch(href) {
	window.open(href, "Search", "width=460,height=550,scrollbars=yes");
}

function confirmSearchUpdate() {
	var agree = confirm("Are you user sure to renew the search database?");
	if (agree) {
		return true;
	} else {
		return false;
	}
}

function confirmImageUpdate() {
	var agree = confirm("Are you sure you whish to renew the image database?");
	if (agree) {
		return true;
	} else {
		return false;
	}
}

function confirmPurgeCache() {
	var agree = confirm("Are you sure you wish purge the entire cache?");
	if (agree) {
		return true;
	} else {
		return false;
	}
}

function printPage() {
	if (window.print) {
		window.print();
	} else {
		alert('De Printen functie werkt niet met uw type en/of versie van uw browser.');
	}
}

function form_validation() {
	// if this array exists we have to use it to check required formfields
	//
	if (typeof FORM_REQUIRED_ARRAY == "object") {
		var field = "";
		var value = "";
		var title = "";
		var regexp = "";
		var submit = 1;
		var correct = "";

		for ( var i = 0; i < FORM_REQUIRED_ARRAY.length; i++) {
			field = FORM_REQUIRED_ARRAY[i][1];
			value = field.value;
			regexp = FORM_REQUIRED_ARRAY[i][2];
			title = FORM_REQUIRED_ARRAY[i][3];

			if (!value.match(regexp)) {
				alert("U heeft het veld " + title
						+ " niet of niet correct ingevuld.");
				field.focus();
				submit = 0;
				return;
			}
		}

		if (submit) {
			// als deze waarde true blijkt is ergeen fout veld gevonden en
			// kunnen
			// we gaan submitten
			form_submit();
		}

	} else {
		// geen validatie voor required velden, dan gaan we meteen submitten
		//
		form_submit();
	}
}

function form_submit() {
	// we have to know which version this is for submitting reasons
	//
	IE50 = ((document.all) && (navigator.appVersion.indexOf("MSIE 5.0") != -1)) ? true
			: false;
	if (IE50) {
		FORM_OLD.submit();
	} else {
		FORM.submit();
	}
	return true;
}

function popUp(url) {
	day = new Date();
	id = day.getTime();
	eval("page"
			+ id
			+ " = window.open(url, '"
			+ id
			+ "', 'toolbar=0,scrollbars=no,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=300,left=200,top=200');");
}

function popUpWide(url, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page"
			+ id
			+ " = window.open(url, '"
			+ id
			+ "', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=0,width="
			+ width + ",height=" + height + ",left=50,top=50');");
}

var InnerMessageText = "";
var TotalWidth = "384px";
var TotalHeight = "15px";
var DefaultScrollSpeed = 1;
var BackgroundColor = "#ffffff";
var Font = "Arial";
var FontSize = "10";
var MessageText = "";
var ScrollSpeed = DefaultScrollSpeed;
var InternetExplorer = document.all || document.getElementById;
var CurrentWidth = ''
var ScrollObjectExplorer, ScrollObjectNS

function ActionTickerHorizonzal(msg) {
	InnerMessageText = msg
	MessageText = '<nobr><div class="ticker">' + InnerMessageText
			+ "</div></nobr>";

	if (InternetExplorer) {
		ScrollObjectExplorer = document.getElementById ? document
				.getElementById("ieScroller") : document.all.ieScroller
		ScrollObjectExplorer.style.left = parseInt(TotalWidth) + 8 + "px"
		ScrollObjectExplorer.innerHTML = MessageText
		CurrentWidth = document.all ? temp.offsetWidth : document
				.getElementById("temp").offsetWidth
		setInterval("ScrollIt()", 25)
	} else if (document.layers) {
		ScrollObjectNS = document.ScrollObjectNS.document.ScrollObjectNS2
		ScrollObjectNS.left = parseInt(TotalWidth) + 8
		ScrollObjectNS.document.write(MessageText)
		ScrollObjectNS.document.close()
		CurrentWidth = ScrollObjectNS.document.width
		setInterval("ScrollIt()", 25)
	}
}

function ScrollIt() {
	if (InternetExplorer) {
		if (parseInt(ScrollObjectExplorer.style.left) < (CurrentWidth * (-1) + 8))
			ScrollObjectExplorer.style.left = parseInt(TotalWidth) + 8 + "px"
		else
			ScrollObjectExplorer.style.left = parseInt(ScrollObjectExplorer.style.left)
					- ScrollSpeed + "px"
	} else if (document.layers) {
		if (ScrollObjectNS.left < (CurrentWidth * (-1) + 8))
			ScrollObjectNS.left = parseInt(TotalWidth) + 8
		else
			ScrollObjectNS.left -= ScrollSpeed
	}
}

function initTicker() {
	if (InternetExplorer)
		document
				.write('<span class="ticker" id="temp" nowrap style="visibility:hidden;position:absolute;top:-100px;left:-9000px">' + MessageText + '</span>')

	if (InternetExplorer || document.layers) {
		if (InternetExplorer) {
			document.write('<div style="position:relative;width:' + TotalWidth
					+ ';height:' + TotalHeight + ';overflow:hidden">')
			document.write('<div style="position:absolute;width:' + TotalWidth
					+ ';height:' + TotalHeight + ';background-color:'
					+ BackgroundColor + '">')
			document
					.write('<div id="ieScroller" style="position:absolute;left:0px;top:0px"></div>')
			document.write('</div></div>')
		} else if (document.layers) {
			document.write('<ilayer width=' + TotalWidth + ' height='
					+ TotalHeight + ' name="ScrollObjectNS" bgColor='
					+ BackgroundColor + '>')
			document
					.write('<layer name="ScrollObjectNS2" left=0 top=0"></layer>')
			document.write('</ilayer>')
		}
	}
}

// Genereer een mailto link dynamisch, om het spambots wat lastiger te maken.
function mailPerson(user, domain, tld, subject) {
	window.location = "mailto:" + user + "@" + domain + "." + tld + "?subject="
			+ subject;
}

function disableFormButtons() {
	window.formbuttons_disabled = 1;
	button = document.getElementById('formbutton-next');
	if (button)
		button.style.color = '#999';
	button = document.getElementById('formbutton-previous');
	if (button)
		button.style.color = '#999';
	setTimeout('enableFormButtons()', 30000);
}

function enableFormButtons() {
	window.formbuttons_disabled = 0;
	button = document.getElementById('formbutton-next');
	if (button)
		button.style.color = '#fff';
	button = document.getElementById('formbutton-previous');
	if (button)
		button.style.color = '#fff';
}

function hideField(arg) {
	var y;
	if (arg == 3) {
		document.getElementById('actionCodeBlock').style.display = 'none';
		document.getElementById('product_selectBlock').style.display = 'block';

		document.content_form.actionCode.selectedIndex = 0;
		document.content_form.actionCode.options[0].selected = true;
	} else if (arg == 2) {
		document.getElementById('actionCodeBlock').style.display = 'block';
		document.getElementById('product_selectBlock').style.display = 'none';
	}
}

/*----------------------------------------------------------------------------\
 |                               Tab Pane 1.02                                 |
 |-----------------------------------------------------------------------------|
 |                         Created by Erik Arvidsson                           |
 |                      For WebFX (http://webfx.eae.net/)                      |
 |----------------------------------------------------------------------------*/

// This function is used to define if the browser supports the needed
// features
function hasSupport() {

	if (typeof hasSupport.support != "undefined")
		return hasSupport.support;

	var ie55 = /msie 5\.[56789]/i.test(navigator.userAgent);

	hasSupport.support = (typeof document.implementation != "undefined"
			&& document.implementation.hasFeature("html", "1.0") || ie55)

	// IE55 has a serious DOM1 bug... Patch it!
	if (ie55) {
		document._getElementsByTagName = document.getElementsByTagName;
		document.getElementsByTagName = function(sTagName) {
			if (sTagName == "*")
				return document.all;
			else
				return document._getElementsByTagName(sTagName);
		};
	}

	return hasSupport.support;
}

// /////////////////////////////////////////////////////////////////////////////////
// The constructor for tab panes
//
// el : HTMLElement The html element used to represent the tab pane
// bUseCookie : Boolean Optional. Default is true. Used to determine whether to
// us
// persistance using cookies or not
//
function WebFXTabPane(el, bUseCookie) {
	if (!hasSupport() || el == null)
		return;

	this.element = el;
	this.element.tabPane = this;
	this.pages = [];
	this.selectedIndex = null;
	this.useCookie = bUseCookie != null ? bUseCookie : true;

	// add class name tag to class name
	this.element.className = this.classNameTag + " " + this.element.className;

	// add tab row
	this.tabRow = document.createElement("div");
	this.tabRow.className = "tab-row";
	el.insertBefore(this.tabRow, el.firstChild);

	var tabIndex = 0;
	if (this.useCookie) {
		tabIndex = Number(WebFXTabPane.getCookie("webfxtab_" + this.element.id));
		if (isNaN(tabIndex))
			tabIndex = 0;
	}
	this.selectedIndex = tabIndex;

	// loop through child nodes and add them
	var cs = el.childNodes;
	var n;
	for ( var i = 0; i < cs.length; i++) {
		if (cs[i].nodeType == 1 && cs[i].className == "tab-page") {
			this.addTabPage(cs[i]);
		}
	}
}

WebFXTabPane.prototype.classNameTag = "dynamic-tab-pane-control";

WebFXTabPane.prototype.setSelectedIndex = function(n) {
	if (this.selectedIndex != n) {
		if (this.selectedIndex != null
				&& this.pages[this.selectedIndex] != null)
			this.pages[this.selectedIndex].hide();
		this.selectedIndex = n;
		this.pages[this.selectedIndex].show();

		if (this.useCookie)
			WebFXTabPane.setCookie("webfxtab_" + this.element.id, n); // session
																		// cookie
	}
};

WebFXTabPane.prototype.setDisabledIndex = function(n) {
	if (this.selectedIndex != n) {
		this.pages[n].disable();
	}
};

WebFXTabPane.prototype.getSelectedIndex = function() {
	return this.selectedIndex;
};

WebFXTabPane.prototype.addTabPage = function(oElement) {
	if (!hasSupport())
		return;

	if (oElement.tabPage == this) // already added
		return oElement.tabPage;

	var n = this.pages.length;
	var tp = this.pages[n] = new WebFXTabPage(oElement, this, n);
	tp.tabPane = this;

	// move the tab out of the box
	this.tabRow.appendChild(tp.tab);

	if (n == this.selectedIndex)
		tp.show();
	else
		tp.hide();

	return tp;
};

WebFXTabPane.prototype.dispose = function() {
	this.element.tabPane = null;
	this.element = null;
	this.tabRow = null;

	for ( var i = 0; i < this.pages.length; i++) {
		this.pages[i].dispose();
		this.pages[i] = null;
	}
	this.pages = null;
};

// Cookie handling
WebFXTabPane.setCookie = function(sName, sValue, nDays) {
	var expires = "";
	if (nDays) {
		var d = new Date();
		d.setTime(d.getTime() + nDays * 24 * 60 * 60 * 1000);
		expires = "; expires=" + d.toGMTString();
	}

	document.cookie = sName + "=" + sValue + expires + "; path=/";
};

WebFXTabPane.getCookie = function(sName) {
	var re = new RegExp("(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)");
	var res = re.exec(document.cookie);
	return res != null ? res[3] : null;
};

WebFXTabPane.removeCookie = function(name) {
	setCookie(name, "", -1);
};

// /////////////////////////////////////////////////////////////////////////////////
// The constructor for tab pages. This one should not be used.
// Use WebFXTabPage.addTabPage instead
//
// el : HTMLElement The html element used to represent the tab pane
// tabPane : WebFXTabPane The parent tab pane
// nindex : Number The index of the page in the parent pane page array
//
function WebFXTabPage(el, tabPane, nIndex) {
	if (!hasSupport() || el == null)
		return;

	this.element = el;
	this.element.tabPage = this;
	this.index = nIndex;

	var cs = el.childNodes;
	for ( var i = 0; i < cs.length; i++) {
		if (cs[i].nodeType == 1 && cs[i].className == "tab") {
			this.tab = cs[i];
			break;
		}
	}

	// insert a tag around content to support keyboard navigation

	var a = document.createElement("A");
	this.aElement = a;
	a.href = "#";
	a.onclick = function() {
		return false;
	};
	a.onfocus = function() {
		a.blur();
	};
	while (this.tab.hasChildNodes())
		a.appendChild(this.tab.firstChild);
	this.tab.appendChild(a);

	// hook up events, using DOM0
	var oThis = this;
	this.tab.onclick = function() {
		oThis.select();
	};
	this.tab.onmouseover = function() {
		WebFXTabPage.tabOver(oThis);
	};
	this.tab.onmouseout = function() {
		WebFXTabPage.tabOut(oThis);
	};
}

WebFXTabPage.prototype.show = function() {
	var el = this.tab;
	var s = el.className + " selected";
	s = s.replace(/ +/g, " ");
	el.className = s;

	this.element.style.display = "block";
};

WebFXTabPage.prototype.hide = function() {
	var el = this.tab;
	var s = el.className;
	s = s.replace(/ selected/g, "");
	el.className = s;

	this.element.style.display = "none";
};

WebFXTabPage.prototype.disable = function() {
	var el = this.tab;
	var s = el.className + " disabled";
	s = s.replace(/ +/g, " ");
	el.className = s;
	el.onclick = null;
	el.onmouseover = null;
	el.onmouseout = null;

	// this.element.style.display = "block";
};

WebFXTabPage.prototype.select = function() {
	this.tabPane.setSelectedIndex(this.index);
};

WebFXTabPage.prototype.dispose = function() {
	this.aElement.onclick = null;
	this.aElement = null;
	this.element.tabPage = null;
	this.tab.onclick = null;
	this.tab.onmouseover = null;
	this.tab.onmouseout = null;
	this.tab = null;
	this.tabPane = null;
	this.element = null;
};

WebFXTabPage.tabOver = function(tabpage) {
	var el = tabpage.tab;
	var s = el.className + " hover";
	s = s.replace(/ +/g, " ");
	el.className = s;
};

WebFXTabPage.tabOut = function(tabpage) {
	var el = tabpage.tab;
	var s = el.className;
	s = s.replace(/ hover/g, "");
	el.className = s;
};

// This function initializes all uninitialized tab panes and tab pages
function setupAllTabs() {
	if (!hasSupport())
		return;

	var all = document.getElementsByTagName("*");
	var l = all.length;
	var tabPaneRe = /tab\-pane/;
	var tabPageRe = /tab\-page/;
	var cn, el;
	var parentTabPane;

	for ( var i = 0; i < l; i++) {
		el = all[i]
		cn = el.className;

		// no className
		if (cn == "")
			continue;

		// uninitiated tab pane
		if (tabPaneRe.test(cn) && !el.tabPane)
			new WebFXTabPane(el);

		// unitiated tab page wit a valid tab pane parent
		else if (tabPageRe.test(cn) && !el.tabPage
				&& tabPaneRe.test(el.parentNode.className)) {
			el.parentNode.tabPane.addTabPage(el);
		}
	}
}

function disposeAllTabs() {
	if (!hasSupport())
		return;

	var all = document.getElementsByTagName("*");
	var l = all.length;
	var tabPaneRe = /tab\-pane/;
	var cn, el;
	var tabPanes = [];

	for ( var i = 0; i < l; i++) {
		el = all[i]
		cn = el.className;

		// no className
		if (cn == "")
			continue;

		// tab pane
		if (tabPaneRe.test(cn) && el.tabPane)
			tabPanes[tabPanes.length] = el.tabPane;
	}

	for ( var i = tabPanes.length - 1; i >= 0; i--) {
		tabPanes[i].dispose();
		tabPanes[i] = null;
	}
}

// initialization hook up

// DOM2
if (typeof window.addEventListener != "undefined")
	window.addEventListener("load", setupAllTabs, false);

// IE
else if (typeof window.attachEvent != "undefined") {
	window.attachEvent("onload", setupAllTabs);
	window.attachEvent("onunload", disposeAllTabs);
}

else {
	if (window.onload != null) {
		var oldOnload = window.onload;
		window.onload = function(e) {
			oldOnload(e);
			setupAllTabs();
		};
	} else
		window.onload = setupAllTabs;
}

/* aanmeld formulier */
function LastYes() {
	if (document.getElementById('flag').value == 'klant') {
		document.getElementById('client0').checked = 'checked';
		hide('debtornumberBlock');
	}

	if (document.getElementById('flag').value == 'verhuizen') {
		document.getElementById('movingSW').checked = 'checked';
		hide('movingDataBlock');
	}

	hide('light');
	hide('fade');
	show('keyDeliveryDateBlock');
}

function ShowHider(elem) {
	if (elem.id == 'client1') {
		for (i = 0; i < document.forms['content_form'].moving.length; i++) {
			if (document.forms['content_form'].moving[i].checked) {
				if (document.forms['content_form'].moving[i].value == 'MI') {
					show('light');
					show('fade');
					hide('keyDeliveryDateBlock');
				} else {
					show('debtornumberBlock');
				}
			}
		}
	} else if (elem.id == 'movingMI') {
		for (i = 0; i < document.forms['content_form'].client.length; i++) {
			if (document.forms['content_form'].client[i].checked) {
				if (document.forms['content_form'].client[i].value == 1) {
					show('light');
					show('fade');
				} else {
					show('movingDataBlock');
				}
			}
		}
	}
}

/* verhuis formulier */
function checkCombination() {
	var keyDeliveryDateKnown;
	var keyReceptionDateKnown;

	for ( var i = 0; i < document.content_form.keyDeliveryDateKnown.length; i++) {
		if (document.content_form.keyDeliveryDateKnown[i].checked) {
			keyDeliveryDateKnown = document.content_form.keyDeliveryDateKnown[i].value;
		}
	}

	for ( var i = 0; i < document.content_form.keyReceptionDateKnown.length; i++) {
		if (document.content_form.keyReceptionDateKnown[i].checked) {
			keyReceptionDateKnown = document.content_form.keyReceptionDateKnown[i].value;
		}
	}

	if (keyDeliveryDateKnown == 1 && keyReceptionDateKnown == 0)
		showPopup('infoText3');
	if (keyDeliveryDateKnown == 0 && keyReceptionDateKnown == 1)
		showPopup('infoText4');
	if (keyDeliveryDateKnown == 0 && keyReceptionDateKnown == 0)
		showPopup('infoText5');
}
/*
 * function checkDateKeyDeliveryDate(){ var year; var month; var day;
 * 
 * selInd = document.content_form.keyDeliveryYear.selectedIndex;
 * 
 * year = document.content_form.keyDeliveryYear.options[selInd].value;
 * 
 * selInd = document.content_form.keyDeliveryMonth.selectedIndex;
 * 
 * month = document.content_form.keyDeliveryMonth.options[selInd].value;
 * 
 * selInd = document.content_form.keyDeliveryDay.selectedIndex;
 * 
 * day = document.content_form.keyDeliveryDay.options[selInd].value;
 * 
 * if(year != '' &#38;&#38; month != '' &#38;&#38; day != '') checkDate(year,
 * month, day); }
 * 
 * function checkDateKeyReceptionDate(){ var year; var month; var day;
 * 
 * selInd = document.content_form.keyReceptionYear.selectedIndex;
 * 
 * year = document.content_form.keyReceptionYear.options[selInd].value;
 * 
 * selInd = document.content_form.keyReceptionMonth.selectedIndex;
 * 
 * month = document.content_form.keyReceptionMonth.options[selInd].value;
 * 
 * selInd = document.content_form.keyReceptionDay.selectedIndex;
 * 
 * day = document.content_form.keyReceptionDay.options[selInd].value;
 * 
 * if( year != '' &#38;&#38; month != '' &#38;&#38; day != '') checkDate(year,
 * month, day); }
 * 
 * function checkDate(year, month, day){ var date = new Date(); var currDay; var
 * currMonth; var currYear;
 * 
 * currYear = date.getFullYear(); currMonth = date.getMonth()+1; currDay =
 * date.getDate();
 * 
 * if(year == currYear &#38;&#38; month &#60;= currMonth &#38;&#38; day &#60;
 * currDay) show('info6'); }
 * 
 *  /* 'general purpose' functies
 */
function hide(id) {
	var elem = document.getElementById(id);

	if (elem != null) {
		elem.style.display = 'none';
	}
}

function checksubject() {
	if (document.forms['content_form'].subject.value == 'termijnbedrag_wijzigen') {
		show('paymentterm');
	} else {
		hide('paymentterm');
	}
}

function hidePopup(id) {
	hide(id);
	hide('fade');
}

function show(id) {
	var elem = document.getElementById(id);
	
	if (elem != null) {
		elem.style.display = 'block';
	}
}

function showInfo(id) {
	var elem = document.getElementById(id);
	
	if (elem != null) {
		elem.style.display = 'inline';
	}
}

function showPopup(id) {
	show(id);
	show('fade');
}

/**
 * This function looks up the street and city belonging to the given zipId and numberId fields. This method also makes sure the
 * checks for the zipfield and number field are called. If these checks fail, the entire postal check will fail. If the zip and number
 * checks complete the street and city is looked up and displayed in the street and city fields on the form.
 * @param zipId - The id of the zipfield
 * @param numberId - the id of the numberfield
 * @author Pascal
 */
function checkPostal(zipId, numberId) {
	/* grabbing the name and values */
	zip = document.getElementById(zipId);
	number = document.getElementById(numberId);
	
	if (zip == null || number == null) {
		// We can't perform a check if we don't have both fields
		// (happens in case of SME Prijsvergelijkers tool
		return false;
	}
	
	zipValue = zip.value;
	numberValue = number.value;
	
	/* determain the id's of the street and city */
	streetId = 'street' + zipId.replace('zip', '');
	cityId = 'city' + zipId.replace('zip', '');
	street = document.getElementById(streetId);
	city = document.getElementById(cityId);
	
	/* getting the labels */
	ziplabel = document.getElementById('label' + zipId);
	numberlabel = document.getElementById('label' + numberId);
	streetlabel = document.getElementById('label' + streetId);
	citylabel = document.getElementById('label' + cityId);
	
	/* getting the errorboxes */
	zipErrorAlternativeSpan = document.getElementById('ajaxerrorAlternative' + zipId);
	numberspan = document.getElementById('ajaxerror' + numberId);
	
	// Check the zip and number individually (regardless of the result of one another, hence the single & sign)
	if (checkZip(zipId) & checkNumber(numberId)) {
		getAddress(zipValue, numberValue, {'preloader':'pr' + zipId,
			"onFinish" : function(result) {
				// Set the field values to the result values
				values = result.split('<__>');
				street.value = values[0];
				city.value = values[1];
				postalError = values[2];
				
				// Highlight the fields (we have a result (not perse the correct result))
				highlightField(zip.id, zip.id, zip.id, true);
				highlightField(number.id, number.id, number.id, true);
				highlightField(street.id, street.id, street.id, true);
				highlightField(city.id, city.id, city.id, true);
				
				// Hide the alternative error (stating that the zip number combination isn't known on the server)
				zipErrorAlternativeSpan.className = 'hidden';
				
				// Lets set the street and city field disabled 
				disableField(streetId);
				disableField(cityId);
				
				if (postalError == 1) {
					// This means the zip number combination was not known on the server, error highlight the street and city 
					highlightField(street.id, street.id, street.id, false);
					highlightField(city.id, city.id, city.id, false);
					
					// Display the alternative error message (stating that the zip number combination isn't known on the server)
					zipErrorAlternativeSpan.className = 'error';
					
					// Enable street and city fields, so user can enter the correct street and city
					enableField(cityId);
					enableField(streetId);
					
				}			}
		});
	} else {
		/* If postalcode or number aren't valid, lets empty the street and city, disable and highlight them*/
		street.value = '';
		city.value = '';
		highlightField(street.id, street.id, street.id, false);
		highlightField(city.id, city.id, city.id, false);
		disableField(streetId);
		disableField(cityId);
		

	}
}

/**
 * This function highlights the given field and label. It also makes sure the error message belonging to the field is made visible and shows
 * an error icon image next to the field.
 * If reverse is set to true, the process is reversed. This means that instead of marking the fields red,
 * it unmarks the field back to normal. Reverse also hides the errormessage, and instead of displaying an icon image, it displays a check
 * (ok) image icon next to the field.
 * 
 * @param fieldId - The id of the field to highlight.
 * @param labelId - The id of the label to highlight.
 * @param errorId - The id of the errorfield to highlight.
 * @param errorMessage - The errormessage to display in the errorfield
 * @param reverse - False -> mark red and set errormessage, true -> set fields back to normal and unset errormessage.
 * @author Pascal
 */
function highlightField(fieldId, labelId, errorId, reverse) {
	field = document.getElementById(fieldId);
	label = document.getElementById('label' + labelId);
	errorspan = document.getElementById('ajaxerror' + errorId);
	errorAltspan = document.getElementById('ajaxerrorAlternative' + errorId);
	fieldCss = field.className;
	goodImg = document.getElementById('goodImage' + errorId);
	errorImg = document.getElementById('errorImage' + errorId);
	
	if (reverse) {
		if (fieldCss.indexOf('errorHighLight') != -1) {
			// Hide error
			fieldCss = fieldCss.replace('errorHighLight', '');
			field.className = fieldCss;
			label.className = '';
			errorspan.className = 'hidden';		
			errorAltspan.className = 'hidden';
		}
		errorspan.style.display = 'none';
		
		goodImg.className = '';
		errorImg.className = 'hidden';
	} else {
		// Show error
		if (fieldCss.indexOf('errorHighLight') == -1) {
			field.className = fieldCss + ' errorHighLight';
		}
		label.className = 'error';
		errorspan.className = 'error';
		errorspan.style.display = 'block';
		errorAltspan.className = 'hidden';
		goodImg.className = 'hidden';
		errorImg.className = '';
	}
}

/**
 * This method resets the field, labelfield and errorfield back to its original state (field and label not marked red, no status 
 * image behind it and no error message behind it).
 *  
 * @param fieldId - The id of the field to reset.
 * @param labelId - The id of the labelfield, belonging to the fieldId, to reset.
 * @param errorId - The id of the errorfield, belonging to the fieldId, to reset.
 * @author Pascal
 */
function resetField(fieldId, labelId, errorId) {	
	
	field = document.getElementById(fieldId);
	 
	if (field == null) {
		// Field is probably a radio button
		return;
	}
	
	// First we need to figure out if the field is a date or not
	if (fieldId.indexOf('Day') != -1 || fieldId.indexOf('Month') != -1 || fieldId.indexOf('Year') != -1) {
		
		// Get the prefix (eg birth)
		prefix = '';
		if (fieldId.indexOf('Day') != -1) {
			prefix = fieldId.substring(0,fieldId.length - 3);
		}
		if (fieldId.indexOf('Month') != -1) {
			prefix = fieldId.substring(0,fieldId.length - 5);
		}
		if (fieldId.indexOf('Year') != -1) {
			prefix = fieldId.substring(0,fieldId.length - 4);
		}

		// Lets get the actual day, month and year fields
		dayField = document.getElementById(prefix + 'Day');
		monthField = document.getElementById(prefix + 'Month');
		yearField = document.getElementById(prefix + 'Year');
		
		// Lets get the css from the date fields
		dayCss = dayField.className;
		monthCss = monthField.className;
		yearCss = yearField.className;
		
		// If the css class contains the error class ('errorHighLight'), remove it so the field is reset to its normal style.
		if (dayCss.indexOf('errorHighLight') != -1) {
			dayCss = dayCss.replace('errorHighLight', '');
			dayField.className = dayCss;		
		}
		
		// If the css class contains the error class ('errorHighLight'), remove it so the field is reset to its normal style.
		if (monthCss.indexOf('errorHighLight') != -1) {
			monthCss = monthCss.replace('errorHighLight', '');
			monthField.className = monthCss;		
		}
		
		// If the css class contains the error class ('errorHighLight'), remove it so the field is reset to its normal style.
		if (yearCss.indexOf('errorHighLight') != -1) {
			yearCss = yearCss.replace('errorHighLight', '');
			yearField.className = yearCss;		
		}
	} else {
		// Field is not a date
		fieldCss = field.className;
		
		// If the css class contains the error class ('errorHighLight'), remove it so the field is reset to its normal style.
		if (fieldCss.indexOf('errorHighLight') != -1) {
			fieldCss = fieldCss.replace('errorHighLight', '');
			field.className = fieldCss;		
		}
	}
	
	// Reset label, alternativelabel, error and images
	label = document.getElementById('label' + labelId);
	errorspan = document.getElementById('ajaxerror' + errorId);
	errorAltspan = document.getElementById('ajaxerrorAlternative' + errorId);
	
	goodImg = document.getElementById('goodImage' + errorId);
	errorImg = document.getElementById('errorImage' + errorId);

	label.className = '';
	errorspan.className = 'hidden';
	errorAltspan.className = 'hidden';
	goodImg.className = 'hidden';
	errorImg.className = 'hidden';
	errorspan.style.display = 'none';

}

/**
 * This method checks if there's  a check method for the fieldToCheckId. If so, that check is executed and the result is returned. 
 * If there isn't such a check, nothing happens and true is returned.
 * 
 * The actual checks this method uses are in /javascript/inputchecker.php
 * 
 * @param fieldToCheckId - The id of the field to perform the check on.
 * @param methodSuffix - The suffix of the check method to call. 
 * @author Pascal
 * @return - boolean, false and only false if the check is successfully executed and check returned false. True otherwise
 */
function abstractCheck(fieldToCheckId, methodSuffix) {
	// First we need to figure out if the fieldToCheckId is a date or not
	if (methodSuffix.indexOf('Day') != -1 || methodSuffix.indexOf('Month') != -1 || methodSuffix.indexOf('Year') != -1) {
		// Get the prefix (eg birth)
		prefix = '';
		if (methodSuffix.indexOf('Day') != -1) {
			prefix = fieldToCheckId.substring(0,fieldToCheckId.length - 3);
		}
		if (methodSuffix.indexOf('Month') != -1) {
			prefix = fieldToCheckId.substring(0,fieldToCheckId.length - 5);
		}
		if (methodSuffix.indexOf('Year') != -1) {
			prefix = fieldToCheckId.substring(0,fieldToCheckId.length - 4);
		}

		// Lets get the actual day, month and year fields
		dayField = document.getElementById(prefix + 'Day');
		monthField = document.getElementById(prefix + 'Month');
		yearField = document.getElementById(prefix + 'Year');
		
		// Lets set the date the user has entered
		dateString = monthField.value + "-" + dayField.value + "-" + yearField.value;
			
		// Call the checkDate method to validate the dateString
		if (checkDate(dateString)) {
			// Correct date
			highlightField(dayField.id, prefix + 'Date', prefix + 'Date', true);
			highlightField(monthField.id, prefix + 'Date', prefix + 'Date', true);
			highlightField(yearField.id, prefix + 'Date', prefix + 'Date', true);
			return true;
		} else {
			// Wrong or non existing date
			highlightField(dayField.id, prefix + 'Date', prefix + 'Date', false);
			highlightField(monthField.id, prefix + 'Date', prefix + 'Date', false);
			highlightField(yearField.id, prefix + 'Date', prefix + 'Date', false);
			return false;
		}
	} else {
		// FieldtoCheckId is not a date, so call the check depending on the methodSuffix
		try{
			var checkSuccessfull;
			var method = "checkSuccessfull = check" + methodSuffix + "('" + fieldToCheckId + "');";
			eval(method);
			
			field = document.getElementById(fieldToCheckId);
			
			// Last we need to check if field is empty and mandatory
			if (isEmpty(field.value) && !isMandatoryField('label' + field.id)) {
				// In this case, field is empty and not mandatory, the field value can be assumed valid
				// Thus highlight the field and return true
				highlightField(field.id, field.id, field.id, true);
				return true;
			}
			return checkSuccessfull;
		} catch (err) {
			// No check for fieldToCheck or fieldToCheck is not an input field at all. {
			//Return true, because it is possible that some fields have no checks, but this isn't wrong (thus return true).
			//alert (err);
			return true;
		}
	}
}

/**
 * This method triggers the checks of all the fields in the form, up to the stopElementId. 
 *  
 * @param stopElementId - The element to stop the checks, or -1 if the entire form should be checked.
 * @author Pascal
 */
function checkAllFields(stopElementId) {
	field = document.getElementById(stopElementId);
	 
	if (field == null && stopElementId != -1) {
		// Field is probably a radio button
		return;
	}
	
	// Iterate through the elements to perform client side checks
	for (var i=0; i < document.content_form.elements.length; i++) {
		   var element = document.content_form.elements[i];
		   var id = element.id;
		   
		   if (id == stopElementId) {
			   break; // Stop the loop, because we're now at the stopElementId field
		   }
		   
		   // Workaround for title radio button, field ids of title are title0 and title1, but to check it, id needs to be just title
		   if (id.indexOf('title') != -1) {
			   id = "title";
		   }
		      
		   var methodSuffix = id.substring(0,1).toUpperCase() + id.substring(1); // Suffix should start with a capitalized letter (the rest of the formatting doesn't matter)
		   
		   abstractCheck(id, methodSuffix);
	}
}

/**
 * This method enables a field. This means that the user is able to edit the field and that the background will be reset (back to white)
 * @param fieldId - The id of the field to enable
 * @author Pascal
 */
function enableField(fieldId) {
	field = document.getElementById(fieldId);
	field.disabled = false;
	fieldCss = field.className;
	
	// If the field has a disabled css class, remove it.
	if (fieldCss.indexOf('disabled') != -1) {
		fieldCss = fieldCss.replace('disabled', '');
		field.className = fieldCss;
	}
}

/**
 * This method disables a field. This means that the user can't edit the field and that the background is painted gray.
 * @param fieldId - The id of the field to disable
 * @author Pascal
 */
function disableField(fieldId) {
	field = document.getElementById(fieldId);
	field.disabled = true;
	fieldCss = field.className;
	
	// If the field doens't already have a disabled css class, add it.
	if (fieldCss.indexOf('disabled') == -1) {
		field.className = fieldCss + ' disabled';
	}	
}

/**
 * This method checks if the field is mandatory. A field is mandatory if the label has an asterix (*) in the text.
 * 
 * @param labelIdOfField - The label of the field to check if it's mandatory.
 * @return boolean - True if the field is mandatory, false otherwise
 * @author Pascal
 */
function isMandatoryField(labelIdOfField) {
	label = document.getElementById(labelIdOfField);
	if (label.innerHTML.indexOf('*') != -1) {
		return true;
	} else {
		return false;
	}
}

function isEmpty(value) {
	// First trim the falue
	
	// check if theres whitespace at the beginning of value and remove it
	value = value.replace(/^\s+/,'');
	// check if theres whitespace at the end of value and remove it
	value = value.replace(/\s+$/,'');
	
	if (value == '') {
		return true;
	} else {
		return false;
	}
}

/**
 * This function gets the tariff table, for the given product and contract, from the server and displays them on the screen in
 * the tariffContainer div.
 * 
 * @param product - gas or elec
 * @param productType - groen or grijs
 * @param contractType - vast or variabel
 * @param stylesheet - The stylesheet used to generate the tariffs (needs to be a valid stylesheet to get tariffs)
 * @return
 */
function getProductCalculatorTariffsFromServer(product, productType, contractType, stylesheet, table, className) {
	tariffDivField = document.getElementById("tariffContainer");
	zipField = document.getElementById("zip");
	regionSpan = document.getElementById('regionInternal');
	zip = zipField.value;
	
	// Ajax call
	getTariffs(productType, contractType, zip, stylesheet, table, className, {'preloader':'pr', "onFinish" : function(result) {
			// Check if we have an error
			errorDelemitor = '__@ERROR@__';
			errorIndex = result.indexOf(errorDelemitor);
			
			if (errorIndex != -1) {
				// Put the error in the region span (because the text inside is displayed in red and next to the zip inputfield
				regionSpan.innerHTML = result.substr(errorIndex + errorDelemitor.length);
				
				// Remove the error from the result
				result = result.substring(0,errorIndex);
			}
		
			// Check if we have a region			
			regionDelemitor = '__@INTERNAL_REGION@__';
			regionIndex = result.indexOf(regionDelemitor);
			
			if (regionIndex != -1) {
				// Put the region in the region span
				regionSpan.innerHTML = result.substr(regionIndex + regionDelemitor.length);
				
				// Remove the region from the result
				result = result.substring(0,regionIndex);
			}

			// Put the remaining result in the tariffsDiv
			tariffDivField.innerHTML = result
			
			window.location = "#tableEnding";
		}
	});
	// To prohibit the form from submitting (we already got our tariffs via ajax), we return false
	return false;
}

/**
 * This functions shows the gas table and hides the elec and condition tables
 * 
 * @return boolean - Always false, so the form won't submit (because we already got our tariffs via Ajax)
 */
function showGasTariffs() {
	hide('tariffsElecDiv');
	hide('conditions');
	show('tariffsGasDiv');
	
	// To prohibit the form from submitting (we already got our tariffs via ajax), we return false
	return false;
}

/**
 * This functions shows the elec table and hides the gas and condition tables
 * 
 * @return boolean - Always false, so the form won't submit (because we already got our tariffs via Ajax)
 */
function showElecTariffs() {
	hide('tariffsGasDiv');
	hide('conditions');
	show('tariffsElecDiv');
	
	// To prohibit the form from submitting (we already got our tariffs via ajax), we return false
	return false;
}

/**
 * This functions shows the conditions table and hides the gas and elec tables
 * 
 * @return boolean - Always false, so the form won't submit (because we already got our tariffs via Ajax)
 */
function showConditions() {
	hide('tariffsGasDiv');
	hide('tariffsElecDiv');
	show('conditions');
	
	// To prohibit the form from submitting (we already got our tariffs via ajax), we return false
	return false;
}

/**
 * This function checks if the suppliers support the given products and shows/hides the appropriate fields. It uses the current form data
 * as input for a server call, which returns the ids of the fields which can be shown.
 */
function checkSupplierTariffsExistenceClient() {
	var radioGasElem = document.content_form.gas;
	var radioElecElem = document.content_form.elec;
	var radioOfferElem = document.content_form.offer;
	var altSupplierTextElem = document.getElementById('altSupplierTexts');
	
	gasValue = getSelectedValue(radioGasElem);
	elecValue = getSelectedValue(radioElecElem);
	offerValue = getSelectedValue(radioOfferElem);
	
	// Lets first hide all text divs
	for(count = 0; count < altSupplierTextElem.childNodes.length; count++) {
		hide(altSupplierTextElem.childNodes[count].id);
	}
	
	// Lets hide the options
	hide('wrappersupplierEssentessent');
	hide('wrappersupplierEnecoeneco');
	hide('wrappersupplierNuonnuon');
	
	// Ajax call, get the ids of the fields which should be shown again
	checkSuppliersTariffsExistence(gasValue, elecValue, offerValue, {'preloader':'prSupplier', "onFinish" : function(result) {
			// Split the results, so the ids will be in an array
			fields = result.split(':');
			// Show the retreived ids
			for(count = 0; count < fields.length; count++) {
				show(fields[count]);
			}
		}
	});
}

/**
 * This function returns the value of the selected/checked item.
 * @param selectionFieldElem - The radio element in a form to retreive a checked value from
 * @return String - value
 */
function getSelectedValue(selectionFieldElem) {
	var checkedValue = '';
	
	// Check which gas radio button is checked (we have 3)
	for (i=0; i < selectionFieldElem.length; i++) {
		if (selectionFieldElem[i].checked) {
			checkedValue = selectionFieldElem[i].value;
			break;
		}
	}
	
	return checkedValue;
}