var l_geslacht, l_ehcp, l_pchp, l_strokes,l_sr,l_cr,l_par;

function getGeslacht()
{
	if (document.bereken.gesl[0].checked) l_geslacht = 0;
	else l_geslacht = 1;
}
		
function getHandicap()
{
	if (document.bereken.ehcp.value=="") l_ehcp=0.0;
	else l_ehcp=parseFloat(document.bereken.ehcp.value,10);
}

function getBaanInfo()
{
	if (l_geslacht == 0)
	{
		l_cr = parseFloat(document.bereken.dcr.value,10);
		l_sr = parseFloat(document.bereken.dsr.value,10);
	}
	else
	{
		l_cr = parseFloat(document.bereken.hcr.value,10);
		l_sr = parseFloat(document.bereken.hsr.value,10);
	}
	
	l_par = parseFloat(document.bereken.par.value,10);
}

function calculatePhcp()
{
	l_phcp = (l_sr / 113);
	l_phcp = l_phcp * l_ehcp;
	l_phcp = l_phcp - l_par;
	l_phcp = l_phcp + l_cr;
	
}

function calculateStrokes()
{
	l_strokes = (l_cr - l_par);
	l_strokes = l_strokes + l_phcp;
}

function showOutput()
{
	document.bereken.phcp.value=Math.round(l_phcp);
	document.bereken.strokes.value=Math.round(l_strokes);
}

function calculate() {
	getGeslacht();
	getHandicap();
	getBaanInfo();
	calculatePhcp();
	calculateStrokes();
	showOutput();
}

function calcPhcp(ehcp, par, sr, cr)
{
	phcp = ehcp * sr / 113 + cr - par;
	return phcp;
}

function calcPhcp9h(ehcp, par, sr, cr)
{
	phcp = (ehcp * sr / 113 + cr - (par * 2)) / 2;
	return phcp;
}

function calculate()
{
	// haal Exact handicap op
	tmp_ehcp = document.getElementById('ehcp').value;
	tmp_s = tmp_ehcp.replace(',','.');
	ehcp = new Number(tmp_s);
	
	// berekenen playing handicap
	// Nieuwe waardes toegevoegd op: 26-03-2009
	
	hbt = Math.round(calcPhcp(ehcp, 70.0, 135, 69.5));
	hmt = Math.round(calcPhcp(ehcp, 70.0, 135, 69.5));
	hft = Math.round(calcPhcp(ehcp, 70.0, 135, 69.5));

	dbt = Math.round(calcPhcp(ehcp, 70.0, 136, 72.3));
	dmt = Math.round(calcPhcp(ehcp, 70.0, 136, 72.3));
	dft = Math.round(calcPhcp(ehcp, 70.0, 136, 72.3));
	

	// vul de velden
	document.getElementById('hbtphcp').value = hbt;
	document.getElementById('hmtphcp').value = hmt;
	document.getElementById('hftphcp').value = hft;
	document.getElementById('dbtphcp').value = dbt;
	document.getElementById('dmtphcp').value = dmt;
	document.getElementById('dftphcp').value = dft;
	
	// 1e 9 holes
	// berekenen playing handicap
	// Nieuwe waardes toegevoegd op: 26-03-2009
	
	hbt = Math.round(calcPhcp9h(ehcp, 35.0, 135, 69.5));
	hmt = Math.round(calcPhcp9h(ehcp, 35.0, 135, 69.5));
	hft = Math.round(calcPhcp9h(ehcp, 35.0, 135, 69.5));

	dbt = Math.round(calcPhcp9h(ehcp, 35.0, 136, 72.3));
	dmt = Math.round(calcPhcp9h(ehcp, 35.0, 136, 72.3));
	dft = Math.round(calcPhcp9h(ehcp, 35.0, 136, 72.3));

	// vul de velden
	document.getElementById('h9-1-hbtphcp').value = hbt;
	document.getElementById('h9-1-hmtphcp').value = hmt;
	document.getElementById('h9-1-hftphcp').value = hft;
	document.getElementById('h9-1-dbtphcp').value = dbt;
	document.getElementById('h9-1-dmtphcp').value = dmt;
	document.getElementById('h9-1-dftphcp').value = dft;
	
	// 2e 9 holes
	// berekenen playing handicap
	// Nieuwe waardes toegevoegd op: 26-03-2009
	
	hbt = Math.round(calcPhcp9h(ehcp, 35.0, 135, 69.5));
	hmt = Math.round(calcPhcp9h(ehcp, 35.0, 135, 69.5));
	hft = Math.round(calcPhcp9h(ehcp, 35.0, 135, 69.5));

	dbt = Math.round(calcPhcp9h(ehcp, 35.0, 136, 72.3));
	dmt = Math.round(calcPhcp9h(ehcp, 35.0, 136, 72.3));
	dft = Math.round(calcPhcp9h(ehcp, 35.0, 136, 72.3));

	// vul de velden
	document.getElementById('h9-2-hbtphcp').value = hbt;
	document.getElementById('h9-2-hmtphcp').value = hmt;
	document.getElementById('h9-2-hftphcp').value = hft;
	document.getElementById('h9-2-dbtphcp').value = dbt;
	document.getElementById('h9-2-dmtphcp').value = dmt;
	document.getElementById('h9-2-dftphcp').value = dft;	
}
