var form_c = function()
{
	this.getIsValidGroup = function(group_i, switch_a)
	{
		for (var index_i = 0; index_i < switch_a.length; index_i++)
			if (switch_a[index_i] == group_i)
				return true;
	};

	this.getObjectCount = function(object_o)
	{
		var count_i = 0;

		for (var index_s in object_o)
			count_i++;

		return count_i;
	};

	this.setGroupSwitch = function(element_o, prefix_s, switch_o)
	{
		var group_o = {};
		var count_i = this.getObjectCount(switch_o);
		var selected_i = element_o.options[element_o.selectedIndex].value;

		for (var index_i = 1; index_i < (count_i + 1); index_i++)
			if (group_o = document.getElementById(prefix_s + index_i))
				group_o.style.display = this.getIsValidGroup(index_i, switch_o['i' + selected_i]) ? '' : 'none';
	};
};

function checkNumeric(objName,minval,maxval,comma,period,hyphen,objPrice,charge1,charge2,charge3)
{
	var numberfield = objName;
	var persons = objName.value;
	var pricefield = objPrice;
	var charge1Str = charge1;
	var charge2Str = charge2;
	var charge3Str = charge3;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	{
		numberfield.value = "0";
		pricefield.value = "€ 0.00";
		numberfield.select();
		return false;
	}
	else
	{
		switch(true){

			case (persons < 31) : subtotalprice = persons * charge1Str; break;

			case ((persons > 30) && (persons < 41)) : subtotalprice = persons * charge2Str; break;

			case (persons > 40) : subtotalprice = persons * charge3Str; break;
		}

		subtotalprice = roundNumber(subtotalprice, 2);

		pricefield.value = "€ " + subtotalprice;

		countTotalprice(numberfield.form);

		return true;
	}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
	var checkOK = "0123456789" + comma + period + hyphen;
	var checkStr = objName;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";

	for (i = 0;  i < checkStr.value.length;  i++)
	{
		ch = checkStr.value.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		if (ch != ",")
		allNum += ch;
	}

	if (!allValid)
	{
		alertsay = "Alleen de karakters \""
		alertsay = alertsay + checkOK + "\" zijn toegestaan in het " + checkStr.id + " veld."
		alert(alertsay);
		return (false);
	}

	// set the minimum and maximum
	var chkVal = allNum;
	var prsVal = parseInt(allNum);
	if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
	{
		alertsay = "Het minimum " + checkStr.id + " is "
		alertsay = alertsay + minval + " en het maximum is "
		alertsay = alertsay + maxval
		alert(alertsay);
		return (false);
	}
}

function getInputValue(input_o) {
	return new Number((typeof input_o != 'undefined') ? input_o.value.replace(new RegExp('[^0-9\.\,\-]', 'g'), '') : 0);
}

function getCheckboxValue(checkbox_o) {
	return new Number(checkbox_o.checked ? checkbox_o.value : 0);
}

function countTotalprice(form_o){

	var total_i = 0;
		total_i += getInputValue(form_o.reservering_vliegeren_prijs);
		total_i += getInputValue(form_o.reservering_strandzeilen_prijs);
		total_i += getInputValue(form_o.reservering_airis_prijs);
		total_i += getInputValue(form_o.reservering_supboarden_prijs);
		total_i += getInputValue(form_o.reservering_nowind1_prijs);
		total_i += getInputValue(form_o.reservering_nowind2_prijs);
		total_i += getInputValue(form_o.reservering_combi_prijs);
		total_i += getInputValue(form_o.reservering_extra_blokart_prijs);
		total_i += getInputValue(form_o.reservering_opwarmer_prijs);
		total_i += getInputValue(form_o.reservering_opwarmer2_prijs);
		total_i += getInputValue(form_o.reservering_vlieger_opdruk_prijs);
		total_i += getInputValue(form_o.reservering_blokartzeil_prijs);

	var btwhoog_i = 0;
		btwhoog_i += (getInputValue(form_o.reservering_vliegeren_prijs))*0.19;
		btwhoog_i += (getInputValue(form_o.reservering_strandzeilen_prijs))*0.19;
		btwhoog_i += (getInputValue(form_o.reservering_airis_prijs))*0.19;
		btwhoog_i += (getInputValue(form_o.reservering_supboarden_prijs))*0.19;
		btwhoog_i += (getInputValue(form_o.reservering_nowind1_prijs))*0.19;
		btwhoog_i += (getInputValue(form_o.reservering_nowind2_prijs))*0.19;
		btwhoog_i += (getInputValue(form_o.reservering_combi_prijs))*0.19;
		btwhoog_i += (getInputValue(form_o.reservering_extra_blokart_prijs))*0.19;
		btwhoog_i += (getInputValue(form_o.reservering_opwarmer_prijs))/11*10*0.19;
		btwhoog_i += (getInputValue(form_o.reservering_opwarmer2_prijs))/11*10*0.19;

	var btwlaag_i = 0;

		btwlaag_i += (getInputValue(form_o.reservering_opwarmer_prijs))/11*0.06;
		btwlaag_i += (getInputValue(form_o.reservering_opwarmer2_prijs))/11*0.06;

	form_o.reservering_totaal_btwhoog.value = "€ " + roundNumber(btwhoog_i,2);
	form_o.reservering_totaal_btwlaag.value = "€ " + roundNumber(btwlaag_i,2);

	form_o.reservering_totaal_prijs.value = "€ " + roundNumber((total_i+btwlaag_i+btwhoog_i),2);
}

function roundNumber(number,decimal_points) {
	if(!decimal_points) return Math.round(number);
	if(number == 0) {
		var decimals = "";
		for(var i=0;i<decimal_points;i++) decimals += "0";
		return "0."+decimals;
	}

	var exponent = Math.pow(10,decimal_points);
	var num = Math.round((number * exponent)).toString();
	if (number < 1) {
		if (number < 0.1) {
			return num.slice(0,-1*decimal_points) + "0.0" + num.slice(-1*decimal_points)
		}
		return "0." + num.slice(-1*decimal_points)
	}
	return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
}

	function formatNumber (number)
	{
	  number = '' + number;
	  numberParts = new Array();
	  numberParts = number.split(".");

	  number = numberParts[0];

	  if (number.length > 3)
	  {
	    var mod = number.length%3;
	    var output = (mod > 0 ? (number.substring(0,mod)) : '');
	    for (i=0 ; i < Math.floor(number.length/3) ; i++)
	    {
	      if ((mod ==0) && (i ==0)) {
	        output+= number.substring(mod+3*i,mod+3*i+3);
	      } else {
	        output+= '.' + number.substring(mod+3*i,mod+3*i+3);
	      }
	    }

	    if (numberParts.length == 2)
	    {
	      output = output + "," + numberParts[1];
	    }
	    return (output);
	  }
	  else
	  {
	    if (numberParts.length == 2)
	    {
	      number = number + "," + numberParts[1];
	    }
	    return number;
	  }
	}
