var xmlHttp8;

function fillCoaches(){
	xmlHttp8 = GetXmlHttpObject();
	if(xmlHttp8 == null)
 	{
 		alert ("Browser does not support HTTP Request");
 	}
	 	
	var url = "ofphp/coachlist.php";
	url += "?sid=" + Math.random();
	url += "&usage=coachpage"
			
	xmlHttp8.open("GET", url, true);
	xmlHttp8.onreadystatechange = stateChanged8;
	xmlHttp8.send("");			
}

function stateChanged8(){ 
	if(xmlHttp8.readyState==4 || xmlHttp8.readyState=="complete"){
		var coaches = xmlHttp8.responseText.split("~~~");

		for(var i = 0; i < coaches.length - 1; i++){
			var coachItem = coaches[i].split("***");
			
			var tbl = document.getElementById("coachlist");
			var row = tbl.insertRow(tbl.rows.length);

			if(isEven(i))
				row.style.backgroundColor="#eee";
			else
				row.style.backgroundColor="#ccc";
			
			var cell0 = row.insertCell(0);//picture
			cell0.innerHTML = "<img style='display: block' src='" + coachItem[3] + "'>";
			cell0.style.display = "block";
			cell0.style.width = "75px";			
			cell0.style.height = "90px";			
			cell0.style.borderRight = "1px solid #fe7115"			
			cell0.style.borderBottom = "1px solid #000";			
			
			var cell1 = row.insertCell(1);//name, position and contact info
			if(coachItem[0] == "1"){
				cell1.innerHTML = "<b><div style='font-size: 14px'>" + coachItem[1] + "</div></b>" + coachItem[2] + "<br><img src='images/email.png'>";
				cell1.setAttribute("onclick", "openEmailDlg('" + coachItem[1] + "');");
			}
			else{
				cell1.innerHTML = "<b><div style='font-size: 14px'>" + coachItem[1] + "</div></b>" + coachItem[2];
//				cell1.setAttribute("onclick", "openEmailDlg('" + coachItem[1] + "');");
			}
			cell1.style.cursor = "pointer";
			cell1.style.padding = "3px";
			cell1.style.width = "140px";
			cell1.style.verticalAlign = "top";
			cell1.style.borderRight = "1px solid #000";
			cell1.style.borderBottom = "1px solid #000";
			
			var cell2 = row.insertCell(2);//bio
			cell2.innerHTML = "<div style='height:80px; overflow:auto'>" + coachItem[4] + "</div>";
			cell2.style.padding = "3px";
			cell2.style.fontSize = "11px";
			cell2.style.borderBottom = "1px solid #000";
		}
		dojo.byId("emailDialog").style.visibility = "visible";
	}	
}
