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 = '#0367A5';
	}
	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('label' + vraagNummer[i] + '.style.color = "#0367A5";');
			eval('vraag' + vraagNummer[i] + '.disabled = false;');
		}
	}
}

/**
 * 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() {
	if (IEBrowser.version() == 6) {
		// Ajax call
		showPageTitle({ "onFinish" : function(result) {
			if (result == 0) {
				// If on a form, set the field margins correct if we don't have a page title (IE6 fix)
					try {
						contentBlockFormField = document.getElementById('contentBlockForm');
						contentBlockFormField.style.margin = '60px 0px 0px 0px';
					} catch (e) {
						// No worry, we aren't always on a form
					}
					
					try {
						menuLeftFormField = document.getElementById('menuLeftForm');
						menuLeftFormField.style.margin = '0px';			
					} catch (e) {
						// No worry, we aren't always on a form
					}
				}
			}
			});
	}
}

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);

	/* 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);

	if (number == null || zip == null || street == null || city == null) {
		// We can't perform a postal lookup check if we don't have both fields
		// (happens in case of SME Prijsvergelijkers tool)
		// We also can't lookup steet and city of we don't have those fields (in
		// case of calculator)
		// We can perform an individual check

		if (zip != null) {
			abstractCheck(zipId, 'Zip');
		}
		if (number != null) {
			abstractCheck(numberId, 'Number');
		}

		// Return, because we can't perform postal lookup
		return;
	}

	zipValue = zip.value;
	numberValue = number.value;

	/* 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);
						pageTracker._trackPageview('formulier_foutmelding',
								'Postcode');
					}
				}
				});
	} else {
		/*
		 * If postalcode or number aren't valid, lets empty the street and city,
		 * disable and highlight them
		 */
		 
		 // If the fields aren't mandatory, highlight them as they are correct
			street.value = '';
			city.value = '';
			
			disableField(streetId);
			disableField(cityId);
		 
		// Last we need to check if field is empty and mandatory
		if (isEmpty(zip.value) && !isMandatoryField('label' + zip.id)) {
			highlightField(street.id, street.id, street.id, true);
			highlightField(city.id, city.id, city.id, true);
		} else {
			highlightField(street.id, street.id, street.id, false);
			highlightField(city.id, city.id, city.id, false);
			pageTracker._trackPageview('formulier_foutmelding', 'Postcode');
		}
		 
		// If zip or number field is empty and not mandatory lets highlight them as they are correct
		if (isEmpty(zip.value) && !isMandatoryField('label' + zip.id)) {
			highlightField(zip.id, zip.id, zip.id, true);
		}
		
		if (isEmpty(number.value) && !isMandatoryField('label' + number.id)) {
			highlightField(number.id, number.id, number.id, true);
		}
	}
}

/**
 * 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';
		}
		
		if (fieldCss.indexOf('correct') == -1) {
			field.className = 'correct ' + fieldCss;
		}
		//goodImg.className = 'hidden';
		// errorImg.className = 'hidden';
	} else {
		// Show error		
		if (fieldCss.indexOf('correct') != -1) {
			fieldCss = fieldCss.replace('correct', '');
		}
		
		if (fieldCss.indexOf('errorHighLight') == -1) {
			field.className = 'errorHighLight ' + fieldCss;
		}
		
		label.className = 'error';
		errorspan.className = 'error';
		errorAltspan.className = 'hidden';
	}
}

/**
 * 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');
		
		// Get the alternative javascript selection fields
		altDayField = document.getElementById(prefix + 'DayI');
		altMonthField = document.getElementById(prefix + 'MonthI');
		altYearField = document.getElementById(prefix + 'YearI');

		// Lets get the css from the date fields
		dayCss = dayField.className;
		monthCss = monthField.className;
		yearCss = yearField.className;
		
		altDayCss = altDayField.className;
		altMonthCss = altMonthField.className;
		altYearCss = altYearField.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', '');
			altDayCss = altDayCss.replace('errorHighLight', '');
			dayField.className = dayCss;
			altDayField.className = altDayCss;
		}

		// 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', '');
			altMonthCss = altMonthCss.replace('errorHighLight', '');
			monthField.className = monthCss;
			altMonthField.className = altMonthCss;
		}

		// 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', '');
			altYearCss = altYearCss.replace('errorHighLight', '');
			yearField.className = yearCss;
			altYearField.className = altMonthCss;
		}
	} 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;
		}
		
		if (fieldCss.indexOf('correct') != -1) {
			fieldCss = fieldCss.replace('correct', '');
			field.className = fieldCss;
		}
		
	}

	// Reset label, alternativelabel, error and images
	label = document.getElementById('label' + labelId);
	errorspan = document.getElementById('ajaxerror' + errorId);
	errorAltspan = document.getElementById('ajaxerrorAlternative' + errorId);

	label.className = '';
	errorspan.className = 'hidden';
	errorAltspan.className = 'hidden';
}

/**
 * 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');
		
		// Get the alternative day, month and year fields (javascript checkboxes
		altDayField = document.getElementById(prefix + 'DayI');
		altMonthField = document.getElementById(prefix + 'MonthI');
		altYearField = document.getElementById(prefix + 'YearI');		

		// 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);
			
			highlightField(altDayField.id, prefix + 'Date', prefix + 'Date', true);
			highlightField(altMonthField.id, prefix + 'Date', prefix + 'Date', true);
			highlightField(altYearField.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);
			
			highlightField(altDayField.id, prefix + 'Date', prefix + 'Date', false);
			highlightField(altMonthField.id, prefix + 'Date', prefix + 'Date', false);
			highlightField(altYearField.id, prefix + 'Date', prefix + 'Date', false);
			
			pageTracker._trackPageview('formulier_foutmelding', prefix + 'date');
			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).
			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");
	textBla = document.getElementById("bla");
	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);
			
			// Remove any old contents from the container
			tariffDivField.innerHTML = '';
			
			// Were done, so return false so the form doesn't submit
			return false;
		}

	// 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
	// First split the result so we have the three divs (gas, elec and conditions seperately)
	resultArray = result.split("||");

	// Remove any old contents from the container
	tariffDivField.innerHTML = '';
	
	// Create a new div to wrap around the gas, elec and conditions divs (needed for IE, as innerHTMl gives some strange results otherwise)
	for(i = 0; i < 3; i++) {
		var newdiv = document.createElement("div");
		newdiv.innerHTML = resultArray[i];
		tariffDivField.appendChild(newdiv);
	}

	// Go to the end of the table
	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
	
	// Only if gas or elec is selected
	if (gasValue == 1 || elecValue != 'nee') {
		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;
}

function getCalculatorTariffsFromServer(stylesheet, tariff) {
	// first, make the button disabled
	document.content_form.next.disabled = true;
	
	zipField = document.getElementById('zip');
	numberField = document.getElementById('number');
	addressPermissionField = document.content_form.addressPermission;
	titleField = document.content_form.title;
	nameField = document.getElementById('name');
	gasUsageField = document.getElementById('gasUsage');
	elecTypeField = document.content_form.elecType;
	enkelUsageField = document.getElementById('enkelUsage');
	dubbelPiekUsageField = document.getElementById('dubbelPiekUsage');
	dubbelDalUsageField = document.getElementById('dubbelDalUsage');
	calculationDivField = document.getElementById('calculationDiv');
	householdField = document.content_form.sjv;

	zip = zipField.value;
	number = numberField.value;
	addressPermission = addressPermissionField.checked ? 1 : 0;
	gasUsage = gasUsageField.value;
	elecType = elecTypeField.options[elecTypeField.selectedIndex].value;	
	title = getSelectedValue(titleField);
	name = nameField.value;
	
	if (stylesheet == 'stylesheet_sme.xsl') {
		phoneField = document.getElementById('phone');
		phone = phoneField.value;
	} else {
		phone = '';
	}

	
	if (householdField != null) {
		household = householdField.options[householdField.selectedIndex].value;
	} else {
		household = '';
	}
	enkelUsage = enkelUsageField.value;
	dubbelPiekUsage = dubbelPiekUsageField.value;
	dubbelDalUsage = dubbelDalUsageField.value;

	// Ajax call
	getCalculatorResult(
			zip,
			number,
			addressPermission,
			title,
			name,
			phone,
			household,
			gasUsage,
			elecType,
			enkelUsage,
			dubbelPiekUsage,
			dubbelDalUsage,
			stylesheet,
			tariff,
			{
				'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
					errorFieldsString = result.substr(errorIndex
						+ errorDelemitor.length);
					errorFieldsArray = errorFieldsString.split(';');
				for (count = 0; count < errorFieldsArray.length; count++) {
					id = errorFieldsArray[count];
					
					if (id == 'title') {
						highlightField(id+0, id, id, false);
						highlightField(id+1, id, id, false);
					} else  {
						highlightField(id, id, id, false);
					}
				}

				calculationDivField.innerHTML = result.substring(0, errorIndex);
			} else {
				calculationDivField.innerHTML = result;
			}
			
			// Make the button enabled again
			document.content_form.next.disabled = false;
		}
			});

	// To prohibit the form from submitting (we already got our tariffs via
	// ajax), we return false
	return false;
}

/**
 * This function sets the Standaard Jaarverbruik on the calculator fields. For
 * dubbel tariff, it divides the sjvElec over the piek and dal field (43% piek
 * and 57% dal)
 * 
 * @param sjvGas -
 *            Gas usage standaard jaarverbruik
 * @param sjvElec -
 *            Elec usage standaard jaarverbruik
 */
function setCalculatorSJV(sjvGas, sjvElec) {
	gasUsageField = document.getElementById('gasUsage');
	enkelUsageField = document.getElementById('enkelUsage');
	dubbelPiekUsageField = document.getElementById('dubbelPiekUsage');
	dubbelDalUsageField = document.getElementById('dubbelDalUsage');

	// Set the gasUsage
	gasUsageField.value = sjvGas;

	// Set the elecUsage
	enkelUsageField.value = sjvElec;

	if (sjvElec == '') {
		dubbelPiekUsageField.value = '';
		dubbelDalUsageField.value = '';
	} else {
		// For dubbel tariff we need to divide it (43% piek, 57% dal)
		dubbelPiekUsageField.value = Math.round(sjvElec * 0.43);
		dubbelDalUsageField.value = Math.round(sjvElec * 0.57);
	}

	// (Un)Highlight the usage fields
	if (sjvGas == '') {
		highlightField('gasUsage', 'gasUsage', 'gasUsage', false);
	} else {
		highlightField('gasUsage', 'gasUsage', 'gasUsage', true);
	}

	if (sjvElec == '') {
		highlightField('enkelUsage', 'enkelUsage', 'enkelUsage', false);
		highlightField('dubbelDalUsage', 'dubbelDalUsage', 'dubbelDalUsage',
				false);
		highlightField('dubbelPiekUsage', 'dubbelPiekUsage', 'dubbelPiekUsage',
				false);
	} else {
		highlightField('enkelUsage', 'enkelUsage', 'enkelUsage', true);
		highlightField('dubbelDalUsage', 'dubbelDalUsage', 'dubbelDalUsage',
				true);
		highlightField('dubbelPiekUsage', 'dubbelPiekUsage', 'dubbelPiekUsage',
				true);
	}
}
 
function showHideSignupTariffDiv(doHide) {
	tariffDivField = document.getElementById('tariffDiv');
	
	if (!doHide) {
		show('fade'); 
		tariffDivField.className = 'white_content alwaysShow';
	} else {
		hide('fade'); 
		tariffDivField.className = 'hidden';
	}
}

/**
 * This function can be called lik IEBrowser.version() which returns version
 * number in case of ie and 999 in case of a non ie browser
 */
var IEBrowser = {
	version : function() {
		var version = 999; // we assume a sane browser
		if (navigator.appVersion.indexOf("MSIE") != -1)
			// bah, IE again, lets downgrade version number
			version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		return version;
	}
}

/**
 * This function is used to show the product advice on the productadvice page (500)
 * It uses an ajax call to get the advice from the server
 */
function showProductAdvice() {
	// Get the fields
	prijsField = document.getElementById('prijs');
	milieuField = document.getElementById('milieu');
	zekerheidField = document.getElementById('zekerheid');
	zipField = document.getElementById('zip');
	numberField = document.getElementById('number');
	adviceContainerField = document.getElementById('adviceContainer');
	
	// Get the values from the fields
	prijs = prijsField.value;
	milieu = milieuField.value;
	zekerheid = zekerheidField.value;
	zip = zipField.value;
	number = numberField.value;	
	
	// Make the ajax call to get the advice
	getProductAdvice(zip, number, prijs, milieu, zekerheid,
				{ 'preloader' :'pr', "onFinish" : function(result) 
					{
						errorDelemitor = '__@ERROR@__';
						errorIndex = result.indexOf(errorDelemitor);

						if (errorIndex != -1) {
							// We have an error, so lets mark the incorrect fields red
							errorFieldsString = result.substr(errorIndex + errorDelemitor.length);
							errorFieldsArray = errorFieldsString.split(';');
							for (count = 0; count < errorFieldsArray.length; count++) {
								id = errorFieldsArray[count];
								highlightField(id, id, id, false);
							}
							
							adviceContainerField.innerHTML = '';
						} else {
							// We have no error
							adviceContainerField.innerHTML = result;
						}					
					}
				});
	
	// To prohibit the form from submitting (we already got the advice via
	// ajax), so return false
	return false;
}

function checkGroenVariabel() {
	contractElecField = document.getElementById('contractTypeElectricity');
	elecField = document.content_form.elec;
	errorField = document.getElementById('errormessagecell');
	
	elec = getSelectedValue(elecField);
	contractType = contractElecField.options[contractElecField.selectedIndex].value;	
	
	if (elec == 3 && contractType == 0) {
		// Groen & Variabel, set errormessage
		errorField.innerHTML = 'Bij het product "Groen" is het kiezen van een variabele looptijd niet mogelijk. Kies een ander product of een andere contractvorm.';
		highlightField('contractTypeElectricity', 'contractTypeElectricity', 'contractTypeElectricity', false);
	} else {
		// Remove error message
		errorField.innerHTML = '';
		highlightField('contractTypeElectricity', 'contractTypeElectricity', 'contractTypeElectricity', true);
	}
}