function format2Euro(price)
{
	var num = new NumberFormat();
	num.setInputDecimal('.');
	num.setNumber(price);
	num.setPlaces('2', true);
	num.setCurrencyValue('');
	num.setCurrency(false);
	num.setCurrencyPosition(num.LEFT_OUTSIDE);
	num.setNegativeFormat(num.LEFT_DASH);
	num.setNegativeRed(false);
	num.setSeparators(true, '.', ',');
	return num.toFormatted();
}

function format2Normal(price)
{
	var num = new NumberFormat();
	num.setInputDecimal(',');
	num.setNumber(price); 
	num.setPlaces('2', true);
	num.setCurrencyValue('');
	num.setCurrency(false);
	num.setCurrencyPosition(num.LEFT_OUTSIDE);
	num.setNegativeFormat(num.LEFT_DASH);
	num.setNegativeRed(false);
	num.setSeparators(false, ',', ',');
	return num.toFormatted();
}

// THIS FUNCTION CALCULATES AND RETURNS STANDARD COVERAGE COST AND REDUCES 20 EURO IF THE PROMOCODE IS VALID
function calculateStandardCoverage(discount)
{
	var totalCost = format2Normal(document.getElementById("total_cost").value);
	var standardCost = 0.012 * totalCost;
	if(discount>0)
	{
		standardCost = standardCost - 20;
	}
	document.getElementById("sc_cost").value= format2Euro(standardCost);//standardCost.toFixed(2);
	return standardCost;
}

// CALCULATES AND RETURNS THE ACCIDENTS AND LIABILITY COST WHICH IS FIXED AS 40 EURO
function calculateAccCost()
{
	var accidentCost = 0;
	if(document.getElementById("chk_al_calculation").checked == true)
	{
		accidentCost = 40;
		document.getElementById("al_cost").value= format2Euro(accidentCost);
	}
	else
	{
		document.getElementById("al_cost").value= '0';
	}
	return accidentCost;
}

// CALCULATES AND RETURNS THE HONEYMOON COST 
function calculateHoneymoonCost()
{
	var totalCost;
	var honeymoonCost = 0;
	if(document.getElementById("chk_hm_calculation").checked == true)
	{
		totalCost = format2Normal(document.getElementById("total_cost").value);
		honeymoonCost = (0.00275 * totalCost);
		document.getElementById("hm_cost").value= format2Euro(honeymoonCost);
	}
	else
	{
		document.getElementById("hm_cost").value= '0';
	}	
	return honeymoonCost;
}

// CALCULATES AND RETURNS BAD WEATHER COST
function calculateBadWeatherCost()
{
	var totalCost;
	var badweatherCost = 0;
	if(document.getElementById("chk_bw_calculation").checked == true)
	{
		totalCost = format2Normal(document.getElementById("total_cost").value);
		badweatherCost = (0.01 * totalCost);
		document.getElementById("bw_cost").value= format2Euro(badweatherCost);
	}
	else
	{
		document.getElementById("bw_cost").value= '0';
	}	
	return badweatherCost;
}

// THIS FUNCTION CALCULATES ALL THE COSTS AND DISPLAYS IT, THIS FUNCTION SHOULD BE CALLED FOR CALCULATING THE COST
function calculateTotalCost()
{
	var wedding_cost = format2Normal(document.getElementById("total_cost").value);
	var checkRegExp = /^[0-9\,\.]+$/;
	var discount = 0;

	if(!document.getElementById("total_cost").value.match(/^[0-9\.\,]+$/ig))
	{
		alert("Geef een geldig bedrag in aub.");
		wedding_cost = '';
		document.getElementById("total_cost").value = '';
	}
	
	if(wedding_cost > 100000)
	{
		alert('Het te verzekeren bedrag mag niet hoger zijn dan 100.000 EURO');	
		wedding_cost = '';
		document.getElementById("total_cost").value = '';				
	}
	if(document.getElementById("hid_code").value > 0)
	{
		discount = 20;
	}
		
	var coverage_cost = calculateStandardCoverage(discount);	
	var honeymoon_cost = calculateHoneymoonCost();
	var accident_cost = calculateAccCost();
	var badweather_cost = calculateBadWeatherCost();
	var total_price;
	var tax;
	var package_discount;
	var policy_cost = 5;
	
	total_price = coverage_cost + honeymoon_cost + accident_cost + badweather_cost;

	if(document.getElementById("chk_sc_calculation").checked == true && document.getElementById("chk_hm_calculation").checked == true && document.getElementById("chk_al_calculation").checked == true && document.getElementById("chk_bw_calculation").checked == true)
	{
		package_discount = (total_price * 0.1);
		total_price = (total_price - package_discount);
	}
	
	document.getElementById("package_discount").value = format2Euro(package_discount);
	
	/************ THIS PLACES THE MINIMUM AMOUNT VALIDATION FOR THE TOTAL PRICE ************/
	if(document.getElementById("hid_code").value > 0 && total_price<=55)
	{
		document.getElementById("total_price").value = format2Euro(59.13);
		document.getElementById("tax").value = format2Euro(4.13);
		document.getElementById("minpremie").value = 55;
		document.getElementById("minpremieclass").className = 'greyTxtLeftBold';
		document.getElementById("minpremieclassvalue").className = 'valueBold morespace';
		document.getElementById("minpremie").className = 'hidTextBox';
	}
	else if(document.getElementById("hid_code").value == 0 && total_price<=75)
	{
		document.getElementById("total_price").value = format2Euro(80.63);
		document.getElementById("tax").value = format2Euro(5.63);
		document.getElementById("minpremie").value = 75;
		document.getElementById("minpremieclass").className = 'greyTxtLeftBold';
		document.getElementById("minpremieclassvalue").className = 'valueBold morespace';
		document.getElementById("minpremie").className = 'hidTextBox';
	}
	else
	{
		tax = (total_price * 0.097);
		total_price = (total_price + tax);
		document.getElementById("total_price").value = format2Euro(total_price);
		document.getElementById("tax").value = format2Euro(tax);
		document.getElementById("minpremie").value = '';
		document.getElementById("minpremieclass").className = 'greyTxtLeft';
		document.getElementById("minpremieclassvalue").className = 'value morespace';
		document.getElementById("minpremie").className = 'hidTextBox greytext';
	}
	/************ THIS PLACES THE MINIMUM AMOUNT VALIDATION FOR THE TOTAL PRICE ************/
	
	/*if(total_price>999999)
	{
		document.getElementById("total_price").style.width = '90px';
		//document.getElementById("totalValue").style.float = 'left';
	}
	else if(total_price>9999)
	{
		document.getElementById("total_price").style.width = '80px';
		//document.getElementById("totalValue").style.float = 'left';
	}
	else
	{
		document.getElementById("total_price").style.width = '67px';
		//document.getElementById("totalValue").style.float = 'right';
	}*/
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FORM VALIDATION STARTS FROM
function validateFormIV()
{
	document.forms.paymentFrm.submit();
}

function validateContact()
{
	var frm = document.forms['frmContact'];
	if(frm.naam.value == '')
	{
		alert("Gelieve uw naam in te vullen.");
		return false;	
	}
	
	if(frm.emailadres.value != '')
	{
	   if(validateEmail(frm.emailadres.value)==false)
	   {
		   alert("Gelieve een geldig E-mail adres in te geven");
		   return false;
	   }
	}
	else
	{
		alert("Gelieve uw e-mail adres in te vullen");
		return false;
	}	
}


/*function validateEmail( strValue ) 
{
	var objRegExp  = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
	return objRegExp.test(strValue);
}*/

function validateEmail(email)
{
	if(email.length <= 0)
	{
	  return true;
	}
	var splitted = email.match("^(.+)@(.+)$");
	if(splitted == null) return false;
	if(splitted[1] != null )
	{
	  var regexp_user=/^\"?[\w-_\.]*\"?$/;
	  if(splitted[1].match(regexp_user) == null) return false;
	}
	if(splitted[2] != null)
	{
	  var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
	  if(splitted[2].match(regexp_domain) == null) 
	  {
		var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
		if(splitted[2].match(regexp_ip) == null) return false;
	  }// if
	  return true;
	}
	return false;
}

function  validateNumeric( strValue ) 
{
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	return objRegExp.test(strValue);
}

//AGREEMENT POPUP
function refusalInsurance(checkVal)
{
	if(checkVal == '1')
	{
		document.getElementById("insuranceTextbox").style.display = 'block';
	}
	else
	{
		document.getElementById("insuranceTextbox").style.display = 'none';
	}
}

function hasCriminalPast(checkVal)
{
	if(checkVal == '1')
	{
		document.getElementById("criminalTextbox").style.display = 'block';
	}
	else
	{
		document.getElementById("criminalTextbox").style.display = 'none';
	}
}

function validateVerification()
{
	if(document.getElementById("option1jaa").checked == true)
	{
		if(document.getElementById("insuranceRefused").value == '')
		{
			alert("Gelieve de reden in te vullen");
			return false;
		}
	}
	
	if(document.getElementById("option2jaa").checked == true)
	{
		if(document.getElementById("criminalPast").value == '')
		{
			alert("Gelieve de reden in te vullen");
			return false;
		}
	}
	
	if(document.getElementById("agree").checked == false)
	{
		alert("U moet de akkoordverklaring aanvinken om door te kunnen gaan.");
		return false;
	}
}

function getBack(url)
{
	moveto = url+'/index.php?page=home&calc=';
	document.location.href=moveto;
	Lightbox.hideBox();	
}

// CLOSES THE PROMOCODE INFORMATION BOX
function closeBox()
{
	document.getElementById("loading1").style.display = 'none';
}
var loadedobjects="";
var rootdomain="http://"+window.location.hostname;


