var req = 0

function ahah(url, target) {
  document.getElementById(target).innerHTML = ' Fetching data...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ahahDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function load(name, div) {
	ahah(name,div);
   //return false;
}

function changeContent(c_function)
{
var x;
var y;
	if (c_function == 510) {	
		x=document.getElementById('addTable').rows[5].cells;
		y=document.getElementById('addTable').rows[6].cells;
		y[2].innerHTML="&nbsp;";
		y[3].innerHTML="&nbsp;"; 
		x[2].innerHTML="Grade:";
		x[3].innerHTML="<select name='ComGrade' size='0'><option value='100' label='none' selected></option><option value='0' label='mudan'>0.mudan</option><option value='1' label='shodan'>1.shodan</option><option value='2' label='nidan'>2.nidan</option><option value='3' label='sandan'>3.sandan</option><option value='4' label='yondan'>4.yondan</option><option value='5' label='godan'>5.godan</option><option value='6' label='rokkudan'>6.rokkudan</option></select>";
		x[4].innerHTML="Individuals:";
		x[5].innerHTML="<input type='checkbox' name='Individuals' value='1' checked='checked'>";
		x[6].innerHTML="Team Member:";
		x[7].innerHTML="<input type='checkbox' name='TeamMember' value='1'>";
		x[8].innerHTML="&nbsp;";
	}
	else if (c_function == 520) {
		x=document.getElementById('addTable').rows[5].cells;
		y=document.getElementById('addTable').rows[6].cells;
		y[2].innerHTML="Grade:";
		y[3].innerHTML="<select name='RefGrade' size='0'><option value='200' label='none' selected></option><option value='5' label='rokkudan'>5.godan</option><option value='6' label='rokkudan'>6.rokudan</option><option value='7' label='nanadan'>7.nanadan</option><option value='8' label='hachdan'>8.hachidan</option></select>";
		x[2].innerHTML="&nbsp;";
		x[3].innerHTML="&nbsp;";
		x[4].innerHTML="&nbsp;";
		x[5].innerHTML="&nbsp;";
		x[6].innerHTML="&nbsp;";
		x[7].innerHTML="&nbsp;";
		x[8].innerHTML="&nbsp;";
	}
	else {
		x=document.getElementById('addTable').rows[5].cells;
		y=document.getElementById('addTable').rows[6].cells;
		y[2].innerHTML="&nbsp;";
		y[3].innerHTML="&nbsp;";
		x[2].innerHTML="&nbsp;";
		x[3].innerHTML="&nbsp;";
		x[4].innerHTML="&nbsp;";
		x[5].innerHTML="&nbsp;";
		x[6].innerHTML="&nbsp;";
		x[7].innerHTML="&nbsp;";
		x[8].innerHTML="&nbsp;";
	}
}

function showLunches(c_action)
{
var z;
var y;
	if (c_action == 1) {
		z=document.getElementById('addTable').rows[18].cells;
		y=document.getElementById('addTable').rows[19].cells;
		y[2].innerHTML="<input type='checkbox' name='Lunch1' value='1' checked='checked'>";
		y[3].innerHTML="<input type='checkbox' name='Lunch2' value='1' checked='checked'>"; 
		y[4].innerHTML="<input type='checkbox' name='Lunch3' value='1' checked='checked'>";
		z[2].innerHTML="Monday";
		z[3].innerHTML="Tuesday";
		z[4].innerHTML="Wednesday";
		z[8].innerHTML="&nbsp;";
	} else if (c_action == 2) {
		z=document.getElementById('addTable').rows[18].cells;
		y=document.getElementById('addTable').rows[19].cells;
		y[5].innerHTML="<input type='checkbox' name='Lunch4' value='1' checked='checked'>";
		y[6].innerHTML="<input type='checkbox' name='Lunch5' value='1' checked='checked'>";
		y[7].innerHTML="<input type='checkbox' name='Lunch6' value='1' checked='checked'>";
		z[5].innerHTML="Thursday";
		z[6].innerHTML="Friday";
		z[7].innerHTML="Saturday";
		z[8].innerHTML="&nbsp;";
	}
	else {
		z=document.getElementById('addTable').rows[18].cells;
		y=document.getElementById('addTable').rows[19].cells;
		y[2].innerHTML="&nbsp;";
		y[3].innerHTML="&nbsp;"; 
		y[4].innerHTML="&nbsp;";
		y[5].innerHTML="&nbsp;";
		y[6].innerHTML="&nbsp;";
		y[7].innerHTML="&nbsp;";
		z[2].innerHTML="&nbsp;";
		z[3].innerHTML="&nbsp;";
		z[4].innerHTML="&nbsp;";
		z[5].innerHTML="&nbsp;";
		z[6].innerHTML="&nbsp;";
		z[7].innerHTML="&nbsp;";
		z[8].innerHTML="&nbsp;";
	}
}

function changeExam(c_exam)
{
var w;
	if (c_exam == 1) {	
		w=document.getElementById('addTable').rows[16].cells;
		w[2].innerHTML="Grade:";
		w[3].innerHTML="<select name='GradingFor' size='0'><option value='300' label='none' selected></option><option value='1' label='shodan'>1.shodan</option><option value='2' label='nidan'>2.nidan</option><option value='3' label='sandan'>3.sandan</option><option value='4' label='yondan'>4.yondan</option><option value='5' label='godan'>5.godan</option><option value='6' label='rokkudan'>6.rokkudan</option><option value='7' label='nanadan'>7.nanadan</option></select>";
	}
	else {
		w=document.getElementById('addTable').rows[16].cells;
		w[2].innerHTML="&nbsp;";
		w[3].innerHTML="&nbsp;";
	}
}

function write_help(ihelp)
{
	if (ihelp == 0 ) {
		x=document.getElementById("helpcontent");
		x.innerHTML="$nbsp;";
	} else if (ihelp == 1 ) {
		x=document.getElementById("helpcontent");
		x.innerHTML="The final selection of referees will be decided by the EKF after the pre-entry. For the selected referees the organisation of the Championships will reserve and pay for accommodation (including meals) at the Carlton De Brug hotel.";
	} else if (ihelp == 2 ) {
		x=document.getElementById("helpcontent");
		x.innerHTML="Delegation leader";
	} else if (ihelp == 3 ) {
		x=document.getElementById("helpcontent");
		x.innerHTML="Help 3";
	}

}

function clearButtons(buttonGroup) {
	for (i=0; i < buttonGroup.length; i++) {
	    if (buttonGroup[i].checked == true) {
	    	buttonGroup[i].checked = false;
	    }

	}
	changeContent("550");
} 

