var g_aChks;
function main(){
	makeDeadlines();
	document.getElementById('submit').onclick=fsubmit;
	g_aChks=getElementsByClass(document.getElementById("problems"),"probchk","input");
	setEventListener();
	document.getElementById("txt_name").focus();
	return;
}
function makeDeadlines(){

    // called from window.onload
    // arrDeadlines is global and in the made file

	var ret="";var obj;
	for(key in arrDeadlines){
		for(var i=0;i<arrDeadlines[key].length;++i){
			ret=new Array(ret,String.fromCharCode(arrDeadlines[key][i]-1)).join("");
		}
		obj=document.getElementById(key);
		obj.href=ret;
		if(obj.innerHTML==""){
			obj.innerHTML=ret.substring(7);
		}
		ret="";
	}
	return;
}

function fsubmit(){
	var bolErr=false;
	var msg="";
	var sName=document.getElementById('txt_name').value;
	if(sName.length<2){
		bolErr=true;
		msg="Please enter your name";
	}
	var sEmail=document.getElementById('txt_email').value;
	if(sEmail.length<2){
		bolErr=true;
		msg=new Array(msg,"\nPlease enter your email address.").join("");
	}
	var oClub=document.getElementById('sel_club');
	var sClub=oClub.options[oClub.selectedIndex].value;
	if(sClub=="none"){
		bolErr=true;
		msg=new Array(msg,"\nPlease select a club.").join("");
	}else{
		sClub=sClub.substring(2);
	}
	var probid=getProblem();
	if(probid==""){
		bolErr=true;
		msg=new Array(msg,"\nPlease select a team problem to mentor").join("");
	}else{
		probid=probid.substring(2);
	}
	if(bolErr){
		alert(msg);
	}else{
		var loc=window.location.toString();
		var aLoc=loc.split("?");
		var url="pltw_remote_.php";
		if(aLoc[1]&&aLoc[1]=="v=d"){
			url="pltw_remote_test_.php";
		}
		var data=new Array('mentor=',sName,'&email=',sEmail,'&clubid=',sClub,"&id=",probid).join('');
	}
	postDataReturnText(url,data,fsubmitCallback);
	return;
}

function fsubmitCallback(txt){
	alert(txt);
	if(txt=="Registration Successful"){
		window.location="index.php";
	}
	return;
}

function getProblem(){
	var id="";
	for(var i=0;i<g_aChks.length;++i){
		if(g_aChks[i].checked){
			id=g_aChks[i].id;
			break;
		}
	}
	return id;
}

function clrChecks(oE){
	if(oE.className=="probchk"){
		var id=oE.id;
		for(var i=0;i<g_aChks.length;++i){
			if(g_aChks[i].id!=id){
				g_aChks[i].checked=false;
			}
		}
	}
	return;
}
function getTarget( e ){
	this.e=e?e:window.event;
	this.target=e.target?e.target:e.srcElement;
	clrChecks(this.target);
	return;
}
function setEventListener(){//good to here
	var oE=document.getElementById("problems");
	if(oE.addEventListener){  // Non-IE
		oE.addEventListener ("click",getTarget,false);
	}else if(oE.attachEvent){  //  IE
		oE.attachEvent ("onclick",getTarget);
	}else{ // Older or non compliant browser
		oE.onclick = getTarget;
	}
	return;
}
  //  source: http://www.dustindiaz.com/getelementsbyclass/
  
function getElementsByClass(node,searchClass,tag) {
	var classElements = new Array();
	var els = node.getElementsByTagName(tag); // use "*" for all elements
	var elsLen = els.length;
	var pattern = new RegExp("\\b"+searchClass+"\\b");
	for (i = 0, j = 0; i < elsLen; i++) {
 		if ( pattern.test(els[i].className) ) {
 			classElements[j] = els[i];
 			j++;
 		}
	}
	return classElements;
}
function showFoo() {
	var el = getElementsByClass(document,'foo','*');
	alert(el.length);
}

/*
http://www.dustindiaz.com/basement/getElementsByClass.html
Supply a class name as a string. 
(optional) Supply a node. This can be obtained by getElementById, or simply by just throwing in “document”
	 (it will be document if don’t supply a node)). 
	 It’s mainly useful if you know your parent and you don’t want to loop through the entire D.O.M. 
(optional) Limit your results by adding a tagName.
	 Very useful when you’re toggling checkboxes and etcetera. 
	 You could just supply “input“. 
	 You can use the “*” asterisk as a catch-all (meaning ‘any element). 
*/