function setMargin() {
	screenWidth = document.documentElement.clientWidth;
	websiteWidth = document.getElementById('main_container').clientWidth;
	margins = (screenWidth - websiteWidth)/2;
	document.getElementById('main_container').style.marginLeft = margins+"px";
}

jQuery('#body').ready(function() {
	setMargin();
	window.onresize = setMargin;
});

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, 72.0, 125, 71.5));
	hmt = Math.round(calcPhcp(ehcp, 72.0, 126, 70.4));
	hft = Math.round(calcPhcp(ehcp, 72.0, 119, 68.6));

	dbt = Math.round(calcPhcp(ehcp, 72.0, 126, 73.4));
	dmt = Math.round(calcPhcp(ehcp, 72.0, 123, 72.3));
	dft = Math.round(calcPhcp(ehcp, 72.0, 120, 70.6));
	

	// 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, 117, 69.8));
	hmt = Math.round(calcPhcp9h(ehcp, 35.0, 118, 68.8));
	hft = Math.round(calcPhcp9h(ehcp, 35.0, 113, 67.3));

	dbt = Math.round(calcPhcp9h(ehcp, 35.0, 116, 71.0));
	dmt = Math.round(calcPhcp9h(ehcp, 35.0, 113, 69.9));
	dft = Math.round(calcPhcp9h(ehcp, 35.0, 113, 68.5));

	// 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, 37.0, 133, 73.2));
	hmt = Math.round(calcPhcp9h(ehcp, 37.0, 133, 72.0));
	hft = Math.round(calcPhcp9h(ehcp, 37.0, 124, 70.0));

	dbt = Math.round(calcPhcp9h(ehcp, 37.0, 136, 75.8));
	dmt = Math.round(calcPhcp9h(ehcp, 37.0, 134, 74.6));
	dft = Math.round(calcPhcp9h(ehcp, 37.0, 127, 72.8));

	// 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;	
}

	$(function(){ 
		// find all the input elements with title attributes
		$('input[title!=\"\"]').hint();
		$('textarea[title!=\"\"]').hint();
	});	
