var currentTab = 'tab1';
var bp_sack = new sack();
var idToggle = new Array();
var addToggle = new Array();
var answerFiller = new Array();
var tempDivID = "";
var optionCount = new Array();
var answerList = new Array();
var memberEmailCount = 2;

answerFiller[0] = 1;

String.prototype.trim = function() 
{
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype._utf8_decode = function () 
{
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;
 
	while ( i < this.length ) 
	{
 		c = this.charCodeAt(i);
 		if (c < 128) 
 		{
			string += String.fromCharCode(c);
			i++;
		}
		else if((c > 191) && (c < 224)) {
			c2 = this.charCodeAt(i+1);
			string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		}
		else {
			c2 = this.charCodeAt(i+1);
			c3 = this.charCodeAt(i+2);
			string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}
	}
	return string;
}

String.prototype.xmldecode = function () 
{
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;
 	
 	string = this.replace("&amp;", "&");
	string = this.replace("&lt;", "<");
	string = this.replace("&gt;", ">");
	string = this.replace("&apos;", "'");
	string = this.replace("&quot;", '"');
	return string;
	
}

function bp_adminTabSwitcher(contentDiv,tabDiv)
{
	$(currentTab).className = 'tab-off';
	$(tabDiv).className = 'tab-on';
	$('bp_contentWellDiv').innerHTML = $(contentDiv).innerHTML;
	currentTab = tabDiv.toString();
}
/*
function bp_simpleAjaxRequest(bp_action,bp_name,bp_value)
{
	var pars = bp_name.toString()."="+ msgID.toString()+"&bp_action="+bp_action.toString();
	var myAjax = new Ajax.Updater(tempDivID,bp_contestAjaxUrl.toString(),{method: 'post', parameters: pars,evalScripts: true});
	
	bp_sack.setVar(bp_name.toString(), msgID.toString());
	bp_sack.setVar("bp_action", bp_action.toString());
	bp_sack.requestFile = bp_contestUrl.toString();
	bp_sack.method = "GET";
	bp_sack.onCompletion = postino_MarkMsg;
	bp_sack.runAJAX();

}
*/
function bp_adder(divID)
{
	if (!addToggle[divID])
	{
		addToggle[divID] = true;
	}
	else
	{
		addToggle[divID] = false;
	}
	if (!addToggle[divID])
	{
		$(divID.toString()+'Add').hide();
	}
	else
	{
		$(divID.toString()+'Add').appear({duration: 1.0,from: 0.0, to: 1.0});
	}
}

function bp_export(myForm,act)
{
	var tempAct = $(myForm).action;
	$('bp_action').value = act.toString();
	$(myForm).target = '_blank';
	$(myForm).action = bp_contestAjaxUrl.toString();
	$(myForm).submit();
	$(myForm).action = tempAct;
	$(myForm).target = '_self';
}

function bp_reportFilterSubmit(myForm,act,sort,dir)
{
	$('adminaction').value = act.toString();
	$('sortSub').value = sort.toString();
	$('sortDir').value = dir.toString();
	$(myForm).submit();
}


function bp_klar(subject,num)
{
	for (var i = 0; i<num; i++)
	{
		$(subject.toString() + '_' + i.toString()).checked = false;
	}
}

function bp_springer(divID)
{
	if (!idToggle[divID])
	{
		idToggle[divID] = true;
	}
	else
	{
		idToggle[divID] = false;
	}
	if (!idToggle[divID])
	{
		Effect.SlideUp(divID.toString()+'Div',{ duration: 0.0 });
		$(divID.toString()+'Img').src = bp_contestUrl.toString() + '/img/png/24x24/folder.png';
		$(divID.toString()+'Href').title = $(divID.toString()+'Href').title.replace("Close", "Open");
		$(divID.toString()+'Table').hide();
	}
	else
	{
		$(divID.toString()+'Href').title = $(divID.toString()+'Href').title.replace("Open", "Close");
		$(divID.toString()+'Img').src = bp_contestUrl.toString() + '/img/png/24x24/open.png';
		$(divID.toString()+'Table').show();
		Effect.SlideDown(divID.toString()+'Div',{ duration: 0.0 });
	}
	
	
}
function bp_validateForm(theForm,inputName,doVowel)
{
	if (theForm.item.value == '')
	{
		grammar = 'a';
		if (doVowel)
			grammar = 'an';
		alert('Please enter ' + grammar.toString() + ' ' + inputName.toString());
		return false;
	}
	return true;
}

function bp_deleteItem(theForm,ID)
{
	theForm.adminaction.value = "delete_item";
	theForm.itemID.value = ID.toString();
	theForm.submit();
}

function bp_deleteJudge(theForm,ID)
{
	theForm.adminaction.value = 'delete_judge';
	theForm.judgeID.value = ID.toString();
	theForm.submit();
}
function bp_deleteInvestor(theForm,ID)
{
	theForm.adminaction.value = 'delete_investor';
	theForm.investorID.value = ID.toString();
	theForm.submit();
}
function bp_deleteContestAdmin(theForm,ID)
{
	theForm.adminaction.value = 'delete_admin';
	theForm.adminID.value = ID.toString();
	theForm.submit();
}
function bp_deleteContestant(theForm,ID)
{
	theForm.adminaction.value = 'delete_contestant';
	theForm.contestantID.value = ID.toString();
	theForm.submit();
}
function bp_deleteAdminTeam(theForm,ID)
{
	theForm.adminaction.value = 'delete_team';
	theForm.teamID.value = ID.toString();
	theForm.submit();
}
function bp_deleteContest(theForm,ID)
{
	theForm.adminaction.value = 'delete_contest';
	theForm.contestID.value = ID.toString();
	theForm.submit();
}
function bp_investorEdit(ID)
{
	divID = 'editInvestor'+ID.toString();
	if (!addToggle[divID])
	{
		addToggle[divID] = true;
	}
	else
	{
		addToggle[divID] = false;
	}
	if (!addToggle[divID])
	{
		$(divID).hide();
	}
	else
	{
		$(divID).appear({duration: 1.0,from: 0.0, to: 1.0});
	}
}

function bp_contestAdminEdit(ID)
{
	divID = 'editContestAdmin'+ID.toString();
	if (!addToggle[divID])
	{
		addToggle[divID] = true;
	}
	else
	{
		addToggle[divID] = false;
	}
	if (!addToggle[divID])
	{
		$(divID).hide();
	}
	else
	{
		$(divID).appear({duration: 1.0,from: 0.0, to: 1.0});
	}
}

function bp_teamEdit(ID)
{
	divID = 'editTeam'+ID.toString();
	if (!addToggle[divID])
	{
		addToggle[divID] = true;
	}
	else
	{
		addToggle[divID] = false;
	}
	if (!addToggle[divID])
	{
		$(divID).hide();
	}
	else
	{
		$(divID).appear({duration: 1.0,from: 0.0, to: 1.0});
	}
}

function bp_contestantEdit(ID)
{
	divID = 'editInvestor'+ID.toString();
	if (!addToggle[divID])
	{
		addToggle[divID] = true;
	}
	else
	{
		addToggle[divID] = false;
	}
	if (!addToggle[divID])
	{
		$(divID).hide();
	}
	else
	{
		$(divID).appear({duration: 1.0,from: 0.0, to: 1.0});
	}
}
function bp_contestEdit(ID)
{
	divID = 'editContest'+ID.toString();
	if (!addToggle[divID])
	{
		addToggle[divID] = true;
	}
	else
	{
		addToggle[divID] = false;
	}
	if (!addToggle[divID])
	{
		$(divID).hide();
	}
	else
	{
		$(divID).appear({duration: 1.0,from: 0.0, to: 1.0});
		tempDivID = 'contestEditDisplayCase'+ID.toString();
		
		var pars = "contestID="+ ID.toString()+"&bp_action=show_contest";
		var myAjax = new Ajax.Updater(tempDivID,bp_contestAjaxUrl.toString(),{method: 'post', parameters: pars,evalScripts: true});
		/*
		bp_sack.setVar("contestID", ID.toString());
		bp_sack.setVar("bp_action", "show_contest");
		bp_sack.requestFile = bp_contestAjaxUrl.toString();
		bp_sack.method = "POST";
		bp_sack.onCompletion = bp_displayContestEdit;
		bp_sack.runAJAX();
		*/
	}
	
}
function bp_displayContestEdit()
{
	var response = bp_sack.response;
	$(tempDivID).innerHTML = response.toString();
}

function bp_contestManage(ID)
{
	divID = 'manageContest'+ID.toString();
	if (!addToggle[divID])
	{
		addToggle[divID] = true;
	}
	else
	{
		addToggle[divID] = false;
	}
	if (!addToggle[divID])
	{
		$(divID).hide();
	}
	else
	{
		$(divID).appear({duration: 1.0,from: 0.0, to: 1.0});
		tempDivID = 'contestManageDisplayCase'+ID.toString();
		bp_tabClick(ID.toString(),bp_activeTab[ID.toString()].toString());
		
	}
	
}
function bp_displayContestManage()
{
	var response = bp_sack2.response;
	$(tempDivID).innerHTML = response.toString();
}

function bp_emailEdit(ID)
{
	divID = 'editEmail'+ID.toString();
	if (!addToggle[divID])
	{
		addToggle[divID] = true;
	}
	else
	{
		addToggle[divID] = false;
	}
	if (!addToggle[divID])
	{
		$(divID).hide();
	}
	else
	{
		$(divID).appear({duration: 1.0,from: 0.0, to: 1.0});
		tempDivID = 'emailDisplayCase'+ID.toString();
		var pars = "emailID="+ ID.toString()+"&bp_action=show_email";
		var myAjax = new Ajax.Updater(tempDivID,bp_contestAjaxUrl.toString(),{method: 'post', parameters: pars,evalScripts: true});
		/*
		bp_sack.setVar("emailID", ID.toString());
		bp_sack.setVar("bp_action", "show_email");
		bp_sack.requestFile = bp_contestAjaxUrl.toString();
		bp_sack.method = "POST";
		bp_sack.onCompletion = bp_displayEmailEdit;
		bp_sack.runAJAX();
		*/
	}
	
}
function bp_displayEmailEdit()
{
	var response = bp_sack.response;
	$(tempDivID).innerHTML = response.toString();
}
function bp_judgeEdit(ID)
{
	divID = 'editJudge'+ID.toString();
	if (!addToggle[divID])
	{
		addToggle[divID] = true;
	}
	else
	{
		addToggle[divID] = false;
	}
	if (!addToggle[divID])
	{
		$(divID).hide();
	}
	else
	{
		$(divID).appear({duration: 1.0,from: 0.0, to: 1.0});
	}
}
function bp_submitInvestorEdit(theForm,ID)
{
	theForm.adminaction.value = "update_investor";
	theForm.investorID.value = ID.toString();
	theForm.submit();
}

function bp_submitContestAdminEdit(theForm,ID)
{
	theForm.adminaction.value = "update_admin";
	theForm.adminID.value = ID.toString();
	theForm.submit();
}

function bp_submitJudgeEdit(theForm,ID)
{
	theForm.adminaction.value = "update_judge";
	theForm.judgeID.value = ID.toString();
	theForm.submit();
}

function bp_submitEmailEdit(theForm,ID)
{
	theForm.adminaction.value = "update_email";
	theForm.emailID.value = ID.toString();
	theForm.submit();
}

function bp_submitContestantEdit(theForm,ID)
{
	theForm.adminaction.value = "update_contestant";
	theForm.contestantID.value = ID.toString();
	theForm.submit();
}
function bp_submitContestEdit(theForm,ID)
{
	theForm.adminaction.value = "update_contest";
	theForm.contestID.value = ID.toString();
	theForm.submit();
}

function bp_submitTeamEdit(theForm,ID)
{
	theForm.adminaction.value = "update_team";
	theForm.teamID.value = ID.toString();
	theForm.submit();
}


function bp_profileTabOver(ID,tab)
{
	if($('tabProfileView'+ ID.toString() + '_' + tab.toString()).className.indexOf('tabInactive')>=0)
	{
		$('tabProfileView'+ ID.toString() + '_' + tab.toString()).className='inactiveTabOver';
		$('tabProfileViewImg'+ ID.toString() + '_' + tab.toString()).src = bp_contestUrl.toString()+'/img/tab_right_over.gif';
	}
}
function bp_profileTabOut(ID,tab)
{
	if($('tabProfileView'+ ID.toString() + '_' + tab.toString()).className ==  'inactiveTabOver')
	{
		$('tabProfileView'+ ID.toString() + '_' + tab.toString()).className='tabInactive';
		$('tabProfileViewImg'+ ID.toString() + '_' + tab.toString()).src = bp_contestUrl.toString()+'/img/tab_right_inactive.gif';
	}
}
function bp_profileTabClick(ID,tab,typeID)
{
	addToggle = [];
	memberEmailCount = 2;
	myTypeID = '2';
	if (typeID != undefined)
		myTypeID = typeID;
	var acts = new Array('show_profile','show_team_panel','show_my_contests','show_judge_entries','show_plan_search','show_team_create','show_member_search','show_final_submit');
	//Make new tab active
	$('tabProfileView'+ ID.toString() + '_' + tab.toString()).className = 'tabActive';
	$('tabProfileViewImg'+ ID.toString() + '_' + tab.toString()).src = bp_contestUrl.toString()+'/img/tab_right_active.gif';
	$('tabProfileContentView'+ ID.toString() + '_' + tab.toString()).innerHTML = '<span style="text-align: center;"><img src="'+bp_contestUrl.toString()+'/img/ajax-loader.gif"></span>';
	if (tab.toString() != bp_activeTab[ID.toString()].toString())
	{
		//Make old tab inactive
		$('tabProfileView'+ ID.toString() + '_' + bp_activeTab[ID.toString()].toString()).className='tabInactive';
		$('tabProfileViewImg'+ ID.toString() + '_' + bp_activeTab[ID.toString()].toString()).src = bp_contestUrl.toString()+'/img/tab_right_inactive.gif';
		//Disable old tab's content div
		$('tabProfileContentView'+ ID.toString() + '_' + bp_activeTab[ID.toString()].toString()).style.display = 'none';
	}
	//Activate new tab's content div
	$('tabProfileContentView'+ ID.toString() + '_' + tab.toString()).style.display = 'block';
	//Record new "active" tab
	bp_activeTab[ID.toString()] = tab.toString();
	var tempDivID = 'tabProfileContentView'+ ID.toString() + '_' + tab.toString();
	var bp_sack2 = new sack();
	bp_sack2.setVar("profileID", ID.toString());
	bp_sack2.setVar("bp_action", acts[tab-1]);
	bp_sack2.setVar("bp_typeID", myTypeID.toString());
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){var response = bp_sack2.response; 
					$(tempDivID).innerHTML = response.toString();
					var scripts = $(tempDivID).getElementsByTagName('script');
					if (scripts.length > 0)
					{
						var script = scripts[0];
						eval(script.text);
					}				
				};
	bp_sack2.runAJAX();
	
}


function bp_tabOver(ID,tab)
{
	if($('tabView'+ ID.toString() + '_' + tab.toString()).className.indexOf('tabInactive')>=0)
	{
		$('tabView'+ ID.toString() + '_' + tab.toString()).className='inactiveTabOver';
		$('tabViewImg'+ ID.toString() + '_' + tab.toString()).src = bp_contestUrl.toString()+'/img/tab_right_over.gif';
	}
}
function bp_tabOut(ID,tab)
{
	if($('tabView'+ ID.toString() + '_' + tab.toString()).className ==  'inactiveTabOver')
	{
		$('tabView'+ ID.toString() + '_' + tab.toString()).className='tabInactive';
		$('tabViewImg'+ ID.toString() + '_' + tab.toString()).src = bp_contestUrl.toString()+'/img/tab_right_inactive.gif';
	}
}
function bp_tabClick(ID,tab)
{
	addToggle = [];
	var acts = new Array('show_contest','show_contest_entries','show_contest_teams','show_judge_questions');
	//Make new tab active
	$('tabView'+ ID.toString() + '_' + tab.toString()).className = 'tabActive';
	$('tabViewImg'+ ID.toString() + '_' + tab.toString()).src = bp_contestUrl.toString()+'/img/tab_right_active.gif';
	
	if (tab.toString() != bp_activeTab[ID.toString()].toString())
	{
		//Make old tab inactive
		$('tabView'+ ID.toString() + '_' + bp_activeTab[ID.toString()].toString()).className='tabInactive';
		$('tabViewImg'+ ID.toString() + '_' + bp_activeTab[ID.toString()].toString()).src = bp_contestUrl.toString()+'/img/tab_right_inactive.gif';
		//Disable old tab's content div
		$('tabContentView'+ ID.toString() + '_' + bp_activeTab[ID.toString()].toString()).style.display = 'none';
	}
	
	//Activate new tab's content div
	$('tabContentView'+ ID.toString() + '_' + tab.toString()).style.display = 'block';
	//Record new "active" tab
	bp_activeTab[ID.toString()] = tab.toString();
	var tempDivID = 'tabContentView'+ ID.toString() + '_' + tab.toString();
	//var bp_sack2 = new sack();
	//bp_sack2.setVar("contestID", ID.toString());
	//bp_sack2.setVar("bp_action", acts[tab-1]);
	//bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	//bp_sack2.method = "POST";
	//bp_sack2.onCompletion = function(){var response = bp_sack2.response; 
	//$(tempDivID).innerHTML = response.toString();};
	//bp_sack2.runAJAX();
	var pars = "contestID="+ID.toString()+"&bp_action="+acts[tab-1].toString();
	var myAjax = new Ajax.Updater(tempDivID,bp_contestAjaxUrl.toString(),{method: 'post', parameters: pars,evalScripts: true});
}





function bp_tabReportOver(tab)
{
	if($('tabReportView' + '_' + tab.toString()).className.indexOf('tabInactive')>=0)
	{
		$('tabReportView' + '_' + tab.toString()).className='inactiveTabOver';
		$('tabReportViewImg' + '_' + tab.toString()).src = bp_contestUrl.toString()+'/img/tab_right_over.gif';
	}
}
function bp_tabReportOut(tab)
{
	if($('tabReportView' + '_' + tab.toString()).className ==  'inactiveTabOver')
	{
		$('tabReportView' + '_' + tab.toString()).className='tabInactive';
		$('tabReportViewImg' + '_' + tab.toString()).src = bp_contestUrl.toString()+'/img/tab_right_inactive.gif';
	}
}
function bp_tabReportClick(tab)
{
	addToggle = [];
	var acts = new Array('user_report','team_report','judge_report');
	$('mainAdminaction').value = acts[tab-1];
	$('mainReportFormDiv').submit();
}



function bp_fillAnswerBox(ID,IDextra)
{
	$(ID.toString()+'Answers'+ IDextra.toString()).show();
	var tempDivID = ID.toString()+'AnswersDiv'+ IDextra.toString();
	var bp_sack2 = new sack();
	bp_sack2.setVar("questionID", IDextra.toString());
	bp_sack2.setVar("answerNum", answerFiller[IDextra.toString()].toString());
	bp_sack2.setVar("bp_action", 'build_answers');
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){var response = bp_sack2.response; divTemp = Builder.node('div',{id:tempDivID.toString()+'answerDiv'+answerFiller[IDextra.toString()].toString()}); divTemp.innerHTML = response.toString(); $(tempDivID).appendChild(divTemp);};
	bp_sack2.runAJAX();
	answerFiller[IDextra.toString()]++;
}
function bp_killAnswerBox(ID,IDextra,which)
{
	var tempDivID = ID.toString()+'AnswersDiv'+ IDextra.toString();
	$(tempDivID).removeChild($(tempDivID.toString()+'answerDiv'+which.toString()));
}
function bp_addOption(qID,aNum)
{
	//alert('Made it!');
	//return false;
	var answerMultChoiceHref = 'answerMult'+qID.toString()+'_'+aNum.toString();
	tableAddition = Builder.node('tr',
					[
						Builder.node('td','Option '+optionCount[qID.toString()+'_'+aNum.toString()].toString()+': '),
						Builder.node('td',Builder.node('input',{id:'answerMultchoice'+optionCount[qID.toString()+'_'+aNum.toString()].toString()+'_'+qID.toString()+'_'+aNum.toString(), name:'answerMultchoice'+qID.toString()+'_'+aNum.toString(), type:'text', size: '20'}))
					]);
	$(answerMultChoiceHref).appendChild(tableAddition);
	optionCount[qID.toString()+'_'+aNum.toString()]++;
}
function bp_changeAnswerType(qID,aNum,ansList)
{
	var answerBoxID = 'answerBox_'+qID.toString()+'_'+aNum.toString();
	var answerTypeID = 'answerType_'+qID.toString()+'_'+aNum.toString();
	var answerTypeSelected = $(answerTypeID).selectedIndex;
	var answerType = $(answerTypeID).options[answerTypeSelected].value;
	if (ansList == undefined)
	{
		ansList = new Array();
	}
	$('answerTypeWords_'+qID.toString()+'_'+aNum.toString()).hide();
	$(answerBoxID).innerHTML = '';
	if (!optionCount[qID.toString()+'_'+aNum.toString()])
		optionCount[qID.toString()+'_'+aNum.toString()] = 1;
	switch(answerType.toString())
	{
		case "1":
			toValue = '';
			fromValue = '';
			if (ansList.length > 0)
			{
				toValue = ansList[ansList.length-1];
				fromValue = ansList[1];
			}
			spanDiv = Builder.node('table', {id: 'answerFromTo'+qID.toString()+'_'+aNum.toString(),style: 'text-align: left; padding: 2px;' },
						[
							Builder.node('tr',
							[
								Builder.node('td','From: '),
								Builder.node('td',Builder.node('input',{id:'answerFrom'+qID.toString()+'_'+aNum.toString(), name:'answerFrom'+qID.toString()+'_'+aNum.toString(), type:'text', size: '5'}))
							]),
							Builder.node('tr',
							[
								Builder.node('td','To: '),
								Builder.node('td',Builder.node('input',{id:'answerTo'+qID.toString()+'_'+aNum.toString(), name:'answerTo'+qID.toString()+'_'+aNum.toString(), type:'text', size: '5'}))
							])
						]);
			$(answerBoxID).appendChild(spanDiv);
			$('answerFrom'+qID.toString()+'_'+aNum.toString()).value = fromValue.toString ();
			$('answerTo'+qID.toString()+'_'+aNum.toString()).value = toValue.toString();
			optionCount[qID.toString()+'_'+aNum.toString()] = 1;
		break;
		case "2":
			$('answerTypeWords_'+qID.toString()+'_'+aNum.toString()).show();
			spanDiv = Builder.node('table', {id: 'answerMult'+qID.toString()+'_'+aNum.toString(),style: 'text-align: left; padding: 2px;' });
			$(answerBoxID).appendChild(spanDiv);
			if (ansList.length == 0)
			{
				tr1 = Builder.node('tr',{id: 'answerMultMainTr'+qID.toString()+'_'+aNum.toString()})
				$('answerMult'+qID.toString()+'_'+aNum.toString()).appendChild(tr1);
				td1 = Builder.node('td','Option '+optionCount[qID.toString()+'_'+aNum.toString()].toString()+': ');
				td2 = Builder.node('td',Builder.node('input',{id:'answerMultchoice'+optionCount[qID.toString()+'_'+aNum.toString()].toString()+'_'+qID.toString()+'_'+aNum.toString(), name:'answerMultchoice'+qID.toString()+'_'+aNum.toString(), type:'text', size: '20'}));  
				$('answerMultMainTr'+qID.toString()+'_'+aNum.toString()).appendChild(td1);
				$('answerMultMainTr'+qID.toString()+'_'+aNum.toString()).appendChild(td2);
				optionCount[qID.toString()+'_'+aNum.toString()]++;
			}
			else
			{
				for(var k=1;k<ansList.length;k++)
				{
					tr1 = Builder.node('tr',{id: 'answerMultMainTr'+k.toString()+'_'+qID.toString()+'_'+aNum.toString()})
					$('answerMult'+qID.toString()+'_'+aNum.toString()).appendChild(tr1);
					td1 = Builder.node('td','Option '+optionCount[qID.toString()+'_'+aNum.toString()].toString()+': ');
					td2 = Builder.node('td',Builder.node('input',{id:'answerMultchoice'+optionCount[qID.toString()+'_'+aNum.toString()].toString()+'_'+qID.toString()+'_'+aNum.toString(), name:'answerMultchoice'+qID.toString()+'_'+aNum.toString(), type:'text', size: '20'}));  
					$('answerMultMainTr'+k.toString()+'_'+qID.toString()+'_'+aNum.toString()).appendChild(td1);
					$('answerMultMainTr'+k.toString()+'_'+qID.toString()+'_'+aNum.toString()).appendChild(td2);
					$('answerMultchoice'+optionCount[qID.toString()+'_'+aNum.toString()].toString()+'_'+qID.toString()+'_'+aNum.toString()).value = ansList[k].toString();
					optionCount[qID.toString()+'_'+aNum.toString()]++;
				}
			}
			
		break;
	}
}
function bp_submitJudgeQuestion(ID,qID,aNum,contestID,tabNum)
{
	var answerBoxID = 'answerBox_'+qID.toString()+'_'+aNum.toString();
	var answerTypeID = 'answerType_'+qID.toString()+'_'+aNum.toString();
	var answerTypeSelected = $(answerTypeID).selectedIndex;
	var answerType = $(answerTypeID).options[answerTypeSelected].value;
	var tempHtmlHolder = $(ID.toString()+'AddButtons').innerHTML.toString();
	if ($('question'+qID.toString()).value.toString() == '')
	{
		alert('Please enter a question.');
		return false;
	}
	if (answerType == '')
	{
		alert('Please select an answer type.');
		return false;
	}
	
	var bp_sack2 = new sack();
	bp_sack2.setVar("questionID", qID.toString());
	bp_sack2.setVar("contestID", contestID.toString());
	bp_sack2.setVar("question", $('question'+qID.toString()).value.toString());
	bp_sack2.setVar("descr", $('descr'+qID.toString()).value.toString());
	bp_sack2.setVar("answer_type",answerType.toString());
	switch(answerType.toString())
	{
		case "1":
			if ($('answerFrom'+qID.toString()+'_'+aNum.toString()).value == '' || $('answerTo'+qID.toString()+'_'+aNum.toString()).value == '')
			{
				alert('Please be sure to enter a range for the rating (ie. from 1 to 5.).');
				return false;
			}
			bp_sack2.setVar("answer_from",$('answerFrom'+qID.toString()+'_'+aNum.toString()).value);
			bp_sack2.setVar("answer_to",$('answerTo'+qID.toString()+'_'+aNum.toString()).value);
		break;
		case "2":
			var theStringCheck = "";
			for (var i=1;i<optionCount[qID.toString()+'_'+aNum.toString()];i++)
			{
				theStringCheck = theStringCheck.toString() + $('answerMultchoice'+i.toString()+'_'+qID.toString()+'_'+aNum.toString()).value;
				bp_sack2.setVar("answer_mult["+i.toString()+"]",$('answerMultchoice'+i.toString()+'_'+qID.toString()+'_'+aNum.toString()).value);
			}
			if (theStringCheck == "")
			{
				alert('Please be sure to enter at least one multiple choice option.');
				return false;
			}
		break
	}
	$(ID.toString()+'AddButtons').innerHTML = '<i>Your question is being added. Please wait ...</i>';
	if (qID > 0)
	{
		theAction = 'update_question';
	}
	else
	{
		theAction = 'add_question';
	}
	bp_sack2.setVar("bp_action", theAction);
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){
		var response = bp_sack2.response; 
		//$('tempData').innerHTML = response;
		if (response != '0')
		{
			$('tempData').innerHTML = 'Your question has been added.';
		}
		else
		{
			$('tempData').innerHTML = 'An error occured while adding a question.  Please try again.';
		}
		$(ID.toString()+'AddButtons').innerHTML = tempHtmlHolder;
		optionCount[qID.toString()+'_'+aNum.toString()] = 0;
		theTr = 'editJudgeQuestion'+qID.toString();
		if (!addToggle[theTr])
		{
			addToggle[theTr] = false;
		}
		else
		{
			addToggle[theTr] = false;
		}
		bp_tabClick(contestID.toString(),tabNum.toString());
	};
	bp_sack2.runAJAX();
	
}

function bp_deleteJudgeQuestion(contestID,tabNum,qID,aNum)
{
	var bp_sack2 = new sack();
	bp_sack2.setVar("questionID", qID.toString());
	bp_sack2.setVar("bp_action", 'delete_question');
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){
		var response = bp_sack2.response; 
		//$('tempData').innerHTML = response;
		if (response != '0')
		{
			bp_tabClick(contestID.toString(),tabNum.toString());
		}
		else
		{
			$('tempData').innerHTML = 'An error occured while adding a question.  Please try again.';
		}
		//$(ID.toString()+'AddButtons').innerHTML = tempHtmlHolder;
	};
	bp_sack2.runAJAX();
}

function bp_judgeQuestionEdit(ID,answerType,contestID)
{
	theTr = 'editJudgeQuestion'+ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		$(theTr).hide();
	}
	else
	{
		theContainer = 'editJudgeQuestionContainer'+ID.toString();
		$(theTr).appear();
		var bp_sack2 = new sack();
		bp_sack2.setVar("contestID", contestID.toString());
		bp_sack2.setVar("questionID", ID.toString());
		bp_sack2.setVar("answerType", answerType.toString());
		bp_sack2.setVar("bp_action", 'edit_question');
		bp_sack2.requestFile = bp_contestAjaxUrl.toString();
		bp_sack2.method = "POST";
		bp_sack2.onCompletion = function(){
			var response = bp_sack2.response; 
			$(theContainer).innerHTML = response;
			var scripts = $(theContainer).getElementsByTagName('script');
			var script = scripts[0];
			eval(script.text);
		};
		bp_sack2.runAJAX();
	}
	
}

function bp_hideStudent(doOrDoNot)
{
	if (doOrDoNot)
	{
		$('collegeYears').hide();
		$('zNum').hide();
		$('college').hide();
		$('educationLevel').show();
		$('expertiseLevel').show();
		$('yearsExp').show();
	}
	else
	{
		$('collegeYears').show();
		$('zNum').show();
		$('college').show();
		$('educationLevel').hide();
		$('expertiseLevel').show();
		$('yearsExp').hide();
	}
}

function bp_contestantViewProfile(ID)
{
	theTr = 'contestantViewer'+ID.toString();
	theTr2 = 'contestantTRViewer'+ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		$(theTr).hide();
		$(theTr2).hide();
	}
	else
	{
		theContainer = 'contestantViewerContainer'+ID.toString();
		$(theTr2).show();
		$(theTr).appear();
		var bp_sack2 = new sack();
		bp_sack2.setVar("profileID", ID.toString());
		bp_sack2.setVar("bp_action", 'show_profile_special');
		bp_sack2.requestFile = bp_contestAjaxUrl.toString();
		bp_sack2.method = "POST";
		bp_sack2.onCompletion = function(){
			var response = bp_sack2.response; 
			$(theContainer).innerHTML = response;
			var scripts = $(theContainer).getElementsByTagName('script');
			var script = scripts[0];
			if (script != undefined)
				eval(script.text);
		};
		bp_sack2.runAJAX();
	}
}

function bp_editProfileContact(ID,toggle)
{
	for(var i=1; i<= 5; i++)
	{
		theHider = 'contactInput';
		theShower = 'contactText';
		if (toggle)
		{
			theHider = 'contactText';
			theShower = 'contactInput';
		}
		$(theShower+ID.toString()+'_'+i.toString()).show();
		$(theHider+ID.toString()+'_'+i.toString()).hide();
	}
	if (toggle)
		$('contactSubmit').show()
	else
		$('contactSubmit').hide()
}
function bp_editProfilePersonal(ID,toggle)
{
	for(var i=1; i<= 5; i++)
	{
		theHider = 'personalInput';
		theShower = 'personalText';
		if (toggle)
		{
			theHider = 'personalText';
			theShower = 'personalInput';
		}
		$(theShower+ID.toString()+'_'+i.toString()).show();
		$(theHider+ID.toString()+'_'+i.toString()).hide();
	}
	if (toggle)
		$('personalSubmit').show()
	else
		$('personalSubmit').hide()
}

function bp_editProfileInterests(ID,toggle)
{
	
	theHider = 'interestInput';
	theShower = 'interestText';
	if (toggle)
	{
		theHider = 'interestText';
		theShower = 'interestInput';
	}
	$(theShower+ID.toString()).show();
	$(theHider+ID.toString()).hide();
	
	if (toggle)
		$('interestSubmit').show()
	else
		$('interestSubmit').hide()
}


function $RF(el, radioGroup) {
    if($(el).type && $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    } else if ($(el).tagName.toLowerCase() != 'form') {
        return false;
    }

    var checked = $(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );
    return (checked) ? $F(checked) : null;
}

function $CF()
{
	var checkboxes = [];
	var checkboxReturn = [];
	var form = $('teamSearchForm');
	checkboxes = form.getInputs('checkbox');
	checkboxes.each(function(e)
		{ 
			if (e.checked) 
			{ 
				if (!checkboxReturn[e.name])
				{
					checkboxReturn[e.name] = [];
				}
				else
				{
					checkboxReturn[e.name]['postData'] = checkboxReturn[e.name]['postData'].toString() + ",";
				}
				if (!checkboxReturn[e.name]['postData'])
					checkboxReturn[e.name]['postData'] = '';
				checkboxReturn[e.name]['postData'] = checkboxReturn[e.name]['postData'] + $F(e.id);
			} 
		});
	return checkboxReturn;
}

function bp_doMemberSearch()
{
	$('teamSearchFormWellOpaque').show();
	$('teamSearchFormWell').hide();
	var student = $RF('teamSearchForm', 'student');
	var checkboxPostVars = [];
	var mystring = '';
	checkboxPostVars = $CF();
	var bp_sack2 = new sack();
	bp_sack2.setVar("student", student);
	bp_sack2.setVar("contest", $('contest').value);
	for (theKey in checkboxPostVars)
	{
		if (checkboxPostVars[theKey]['postData'])
		{
			bp_sack2.setVar(theKey.toString(), checkboxPostVars[theKey]['postData']);
		}
	}
	bp_sack2.setVar("bp_action", 'member_search');
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){
		var response = bp_sack2.response; 
		$('memberSearchResultsWell').appear();
		$('memberSearchResultsWell').innerHTML = response;
		$('teamSearchFormWellOpaque').hide();
	};
	bp_sack2.runAJAX();
}


function bp_showProfileMemSearch(ID)
{
	theTr = 'viewProfileMemberSearch' + ID.toString();
	theSpacer = 'viewProfileMemberSearchSpacer' + ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		//$(theTr).hide();
		Effect.SlideUp(theTr, { duration: 0.5 });
		$(theSpacer).hide();
		
	}
	else
	{
		$(theSpacer).show();
		//$(theTr).appear();
		Effect.SlideDown(theTr, { duration: 0.5 });
		var bp_sack2 = new sack();
		bp_sack2.setVar("profileID", ID.toString());
		bp_sack2.setVar("bp_action", 'show_profile');
		bp_sack2.requestFile = bp_contestAjaxUrl.toString();
		bp_sack2.method = "POST";
		bp_sack2.onCompletion = function(){
			var response = bp_sack2.response; 
			$(theTr).innerHTML = response;
		};
		bp_sack2.runAJAX();
	}
}


function bp_showAddTeamMemSearch(ID)
{
	theDiv = 'addTeamMemberSearch'+ID.toString();
	theSpacer = 'addTeamMemberSearchSpacer'+ID.toString();
	if (!addToggle[theDiv])
	{
		addToggle[theDiv] = true;
	}
	else
	{
		addToggle[theDiv] = false;
	}
	if (!addToggle[theDiv])
	{
		$(theSpacer).hide()
		Effect.SlideUp(theDiv, { duration: 0.5 });
	}
	else
	{
		$(theSpacer).show()
		Effect.SlideDown(theDiv, { duration: 0.5 });
	}
	
}

function bp_doAddTeamMemSearch(ID,theValue)
{
	theDiv = 'addTeamMemberSearch'+ID.toString();
	saveHtml = $(theDiv).innerHTML.toString();
	$(theDiv).innerHTML = '<img src="'+bp_contestUrl.toString()+'/img/ajax-loader.gif"><br>Please wait while we check on this contestant\'s eligibility to join the selected team.';
	var bp_sack2 = new sack();
	bp_sack2.setVar("user_id", ID.toString());
	bp_sack2.setVar("team_id", theValue.toString());
	bp_sack2.setVar("bp_action", 'add_member_to_team');
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){
		var response = bp_sack2.response; 
		if (response == "1")
			$(theDiv).innerHTML = 'This member has been notified that you have requested their membership to your team.';
		else if (response == '2')
			$(theDiv).innerHTML = 'This member has a conflict and was not added to your team.';
		else
			$(theDiv).innerHTML = 'This member has not been added to your team due to an unforseen error.';
	};
	bp_sack2.runAJAX();
}


function bp_sendMsgMemSearch(ID)
{
	var successDiv = 'sendMsgSuccess'+ID.toString();
	var subject = $('subject'+ID.toString()).value;
	var message = $('message'+ID.toString()).value;
	var bp_sack2 = new sack();
	bp_sack2.setVar("user_id", ID.toString());
	bp_sack2.setVar("subject", subject.toString());
	bp_sack2.setVar("message", message.toString());
	bp_sack2.setVar("bp_action", 'send_member_message');
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){
		var response = bp_sack2.response; 
		$(successDiv).appear();
	};
	bp_sack2.runAJAX();
}

function bp_showSendMsgMemSearch(ID)
{
	
	theTr = 'sendMsgMemberSearch' + ID.toString();
	theSpacer = 'sendMsgMemberSearchSpacer' + ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		Effect.SlideUp(theTr, { duration: 0.5 });
		$(theSpacer).hide();
	}
	else
	{
		$(theSpacer).show();
		Effect.SlideDown(theTr, { duration: 0.5 });
	}
}

function bp_showTeamSummary(ID)
{
	
	theTr = 'teamSearchSummary' + ID.toString();
	theSpacer = 'teamSearchSummarySpacer' + ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		Effect.SlideUp(theTr, { duration: 0.5 });
		$(theSpacer).hide();
	}
	else
	{
		$(theSpacer).show();
		Effect.SlideDown(theTr, { duration: 0.5 });
	}
}
function bp_showTeamMemRequest(ID)
{
	
	theTr = 'teamMemRequest' + ID.toString();
	theSpacer = 'teamMemRequestSpacer' + ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		Effect.SlideUp(theTr, { duration: 0.5 });
		$(theSpacer).hide();
	}
	else
	{
		$(theSpacer).show();
		Effect.SlideDown(theTr, { duration: 0.5 });
	}
}

function bp_sendJoinRequest(ID)
{
	$('teamMemRequestSent'+ID.toString()).hide();
	var bp_sack2 = new sack();
	bp_sack2.setVar("team_id", ID.toString());
	bp_sack2.setVar("skill_set", $("skill_set"+ID.toString()).value);
	bp_sack2.setVar("my_pitch", $("my_pitch"+ID.toString()).value);
	bp_sack2.setVar("bp_action", 'member_join_request');
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){
		var response = bp_sack2.response; 
		$('teamMemRequestSent'+ID.toString()).appear();
	};
	bp_sack2.runAJAX();
}

function bp_showTeamEdit(ID)
{
	theTr = 'teamDisplaySummary' + ID.toString();
	theSpacer = 'teamDisplaySummarySpacer' + ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		Effect.SlideUp(theTr, { duration: 0.5 });
		$(theSpacer).hide();
	}
	else
	{
		$(theSpacer).show();
		Effect.SlideDown(theTr, { duration: 0.5 });
	}
}

function bp_updateTeam(ID,uID)
{
	$('sendMsgForm'+ID.toString()).target = 'upload_target';
	return true;
}

function bp_refreshTeam(uID,tID)
{
	bp_profileTabClick(uID,'2');
	setTimeout(function(){
			$('teamSplashWell').hide();
			$('teamDisplayWell').show();
			theTr = 'teamDisplaySummary' + tID.toString();
			theSpacer = 'teamDisplaySummarySpacer' + tID.toString();
			theMessage = 'teamUpdateMessage' + tID.toString();
			if (!addToggle[theTr])
			{
				addToggle[theTr] = true;
			}
			else
			{
				addToggle[theTr] = false;
			}
			if (!addToggle[theTr])
			{
				$(theTr).hide();
				$(theSpacer).hide();
			}
			else
			{
				$(theSpacer).show();
				$(theTr).show();
			}
			$(theMessage).innerHTML = 'Your team information has been updated.'
			$(theMessage).show();
	},900);
	
}
function bp_showTeamUpload(ID)
{
	theTr = 'teamDisplayUpload' + ID.toString();
	theSpacer = 'teamDisplayUploadSpacer' + ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		Effect.SlideUp(theTr, { duration: 0.5 });
		$(theSpacer).hide();
	}
	else
	{
		$(theSpacer).show();
		Effect.SlideDown(theTr, { duration: 0.5 });
	}
}
function bp_uploadEntry(ID,uID)
{
	$('uploadEntryForm'+ID.toString()).target = 'upload_target';
	return true;
}

function bp_refreshTeamUpload(uID,tID)
{
	bp_profileTabClick(uID,'2');
	setTimeout(function(){
			$('teamSplashWell').hide();
			$('teamDisplayWell').show();
			theTr = 'teamDisplayUpload' + tID.toString();
			theSpacer = 'teamDisplayUploadSpacer' + tID.toString();
			theMessage = 'teamDisplayUploadMessage' + tID.toString();
			if (!addToggle[theTr])
			{
				addToggle[theTr] = true;
			}
			else
			{
				addToggle[theTr] = false;
			}
			if (!addToggle[theTr])
			{
				$(theTr).hide();
				$(theSpacer).hide();
			}
			else
			{
				$(theSpacer).show();
				$(theTr).show();
			}
			$(theMessage).innerHTML = 'Thank you for uploading your entry!'
			$(theMessage).show();
	},900);
	
}
function bp_showTeamMemRequestList(ID)
{
	theTr = 'teamDisplayMemRequest' + ID.toString();
	theSpacer = 'teamDisplayMemRequestSpacer' + ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		Effect.SlideUp(theTr, { duration: 0.5 });
		$(theSpacer).hide();
	}
	else
	{
		$(theSpacer).show();
		Effect.SlideDown(theTr, { duration: 0.5 });
	}
}

function bp_showMemReqMsg(ID)
{
	theTr = 'memReqMsg' + ID.toString();
	theSpacer = 'memReqMsgSpacer' + ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		Effect.SlideUp(theTr, { duration: 0.5 });
		$(theSpacer).hide();
	}
	else
	{
		$(theSpacer).show();
		Effect.SlideDown(theTr, { duration: 0.5 });
	}
}
function bp_showMemReqProfile(ID)
{
	theTr = 'memReqProfile' + ID.toString();
	theSpacer = 'memReqProfileSpacer' + ID.toString();
	theWell = 'memReqProfile' + ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		Effect.SlideUp(theTr, { duration: 0.5 });
		$(theSpacer).hide();
	}
	else
	{
		var bp_sack2 = new sack();
		bp_sack2.setVar("profileID", ID.toString());
		bp_sack2.setVar("bp_action", 'show_profile_special');
		bp_sack2.requestFile = bp_contestAjaxUrl.toString();
		bp_sack2.method = "POST";
		bp_sack2.onCompletion = function(){
			var response = bp_sack2.response; 
			$(theWell).innerHTML = response;
		};
		bp_sack2.runAJAX();
		$(theSpacer).show();
		Effect.SlideDown(theTr, { duration: 0.5 });
	}
}

function bp_memReqAction(uID,tID,ID,tuTd)
{
	var answer = (tuTd) ? '1' : '0';
	var bp_sack2 = new sack();
	bp_sack2.setVar("profileID", ID.toString());
	bp_sack2.setVar("teamID", tID.toString());
	bp_sack2.setVar("decision", answer.toString());
	bp_sack2.setVar("bp_action", 'member_request_decision');
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){
		var response = bp_sack2.response; 
		bp_refreshMemReqs(uID,tID, tuTd);
	};
	bp_sack2.runAJAX();
}

function bp_refreshMemReqs(uID,tID, tuTd)
{
	bp_profileTabClick(uID,'2');
	setTimeout(function(){
			$('teamSplashWell').hide();
			$('teamDisplayWell').show();
			theTr = 'teamDisplayMemRequest' + tID.toString();
			theSpacer = 'teamDisplayMemRequestSpacer' + tID.toString();
			theMessage = 'teamDisplayMemRequestMessage' + tID.toString();
			if (!addToggle[theTr])
			{
				addToggle[theTr] = true;
			}
			else
			{
				addToggle[theTr] = false;
			}
			if (!addToggle[theTr])
			{
				$(theTr).hide();
				$(theSpacer).hide();
			}
			else
			{
				$(theSpacer).show();
				$(theTr).show();
			}
			if (tuTd)
				$(theMessage).innerHTML = 'That contestant has been accepted and is now part of the team!';
			else
				$(theMessage).innerHTML = 'That contestant has been rejected for membership.';
			$(theMessage).show();
	},900);
	
}

function bp_addMemberForm(inOut)
{
	var tableName = 'newMemberTable';
	var tbName = 'newMemberEmailTBody'+memberEmailCount.toString();
	var trName = 'newMemberEmail'+memberEmailCount.toString();
	
	if (inOut)
	{
		if (memberEmailCount < 5)
		{
			var tbody = Builder.node('tbody',{id: tbName.toString()});
			var tableAddition = Builder.node('tr',{valign: top, id: trName.toString()},
							[
								Builder.node('td','New Member Email:'),
								Builder.node('td',
									Builder.node('input',{name:'email[]', type:'text', value: ''})
								)
							]);
			tbody.appendChild(tableAddition);
			$(tableName).appendChild(tbody);
			memberEmailCount++;
		}
	}
	else
	{
		if (memberEmailCount > 2)
		{
			memberEmailCount--;
			var tbName = $('newMemberEmailTBody'+memberEmailCount.toString());
			$(tableName).removeChild(tbName);
			//var removed = para.removeChild(boldElm);
		}
	}
}

function bp_insertTeam(uID)
{
	$('createTeamForm'+uID.toString()).target = 'upload_target';
	//return true;
}

function bp_refreshTeamCreate(uID)
{
	bp_profileTabClick(uID,'2');
	setTimeout(function(){
			$('teamSplashWell').hide();
			$('teamDisplayWell').show();
	},900);
	
}


function bp_deleteTeam(ID,uID)
{
	var bp_sack2 = new sack();
	bp_sack2.setVar("teamID", ID.toString());
	bp_sack2.setVar("bp_action", 'delete_team');
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){
		var response = bp_sack2.response; 
		bp_refreshTeamList(uID);
	};
	bp_sack2.runAJAX();
}


function bp_refreshTeamList(uID)
{
	bp_profileTabClick(uID,'2');
	setTimeout(function(){
			$('teamSplashWell').hide();
			$('teamDisplayWell').show();
	},900);
	
}

function bp_removeMember(ID,mID,uID)
{
	if (confirm('You are about to remove this member from your team.\nAre you sure you want to continue?\nPress "OK" to remove team member, "Cancel" to keep team member.'))
	{
		var bp_sack2 = new sack();
		bp_sack2.setVar("teamID", ID.toString());
		bp_sack2.setVar("memberID", mID.toString());
		bp_sack2.setVar("bp_action", 'remove_member');
		bp_sack2.requestFile = bp_contestAjaxUrl.toString();
		bp_sack2.method = "POST";
		bp_sack2.onCompletion = function(){
			var response = bp_sack2.response;
			alert('That team member had been removed.');
			bp_refreshTeamList(uID);
		};
		bp_sack2.runAJAX();
	}
}

function bp_finalizeTeam(ID,uID)
{
	if (confirm('You are about to finalize your team.\nThis means that you will not be able to change any aspect of the team data which includes team members.\nAre you sure you want to continue?  Press "OK" to finalize, "Cancel" to keep team open.'))
	{
		var bp_sack2 = new sack();
		bp_sack2.setVar("teamID", ID.toString());
		bp_sack2.setVar("bp_action", 'finalize_team');
		bp_sack2.requestFile = bp_contestAjaxUrl.toString();
		bp_sack2.method = "POST";
		bp_sack2.onCompletion = function(){
			var response = bp_sack2.response;
			alert('Your team is now locked and finalized.\nYou cannot make any changes to your team and that includes adding/removing team members.');
			bp_refreshTeamList(uID);
		};
		bp_sack2.runAJAX();
	}
}

function bp_updateContest(ID,doConf)
{
	if (doConf)
	{
		if (confirm('If you are uploading a new zip file,\nplease note that your current entry will be deleted\nfrom our system and replaced with the new one.\nPress "Ok" to continue, "Cancel" to keep your current entry.'))
		{
			$('viewEditEntryForm'+ID.toString()).target = 'upload_target';
		}
	}
	else
	{
		$('viewEditEntryForm'+ID.toString()).target = 'upload_target';
	}
}

function bp_enterContest()
{
	$('contestEntryForm').target = 'upload_target';
	//return true;
}

function bp_refreshContestEntry(uID)
{
	bp_profileTabClick(uID,'3');
	
}

function bp_viewContestEntry(ID)
{
	theTr = 'viewEditEntry'+ID.toString();
	theSpacer = 'viewEditEntrySpacer'+ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		$(theTr).hide();
		$(theSpacer).hide();
	}
	else
	{
		$(theSpacer).show();
		$(theTr).appear();
	}
}

function bp_dropOut(cID,uID)
{
	if (confirm('Are you sure you no longer want to participate in this contest?'))
	{
		
		var bp_sack2 = new sack();
		bp_sack2.setVar("contestTeamID", cID.toString());
		bp_sack2.setVar("bp_action", 'contest_dropout');
		bp_sack2.requestFile = bp_contestAjaxUrl.toString();
		bp_sack2.method = "POST";
		bp_sack2.onCompletion = function(){
			var response = bp_sack2.response; 
			bp_refreshContestEntry(uID)
		};
		bp_sack2.runAJAX();
		
	}
}

function bp_contestEntryManage(ID)
{
	theTr = 'manageContestEntry'+ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		$(theTr).hide();
	}
	else
	{
		$(theTr).appear();
		theContainer = 'contestManageEntryDisplayCase'+ID.toString();
		
		var bp_sack2 = new sack();
		bp_sack2.setVar("entryID", ID.toString());
		bp_sack2.setVar("bp_action", 'show_entry');
		bp_sack2.requestFile = bp_contestAjaxUrl.toString();
		bp_sack2.method = "POST";
		bp_sack2.onCompletion = function(){
			var response = bp_sack2.response;
			$(theContainer).innerHTML = response;
		};
		bp_sack2.runAJAX();
	}
}


function bp_contestEntryAorR(ID,accRej,contestID,tabNum)
{
	var bp_act = 'accept_entry';
	if (!accRej)
		bp_act = 'reject_entry';
	var bp_sack2 = new sack();
	bp_sack2.setVar("entryID", ID.toString());
	bp_sack2.setVar("bp_action", bp_act.toString());
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){
		var response = bp_sack2.response; 
		bp_tabClick(contestID.toString(),tabNum.toString());
	};
	bp_sack2.runAJAX();
}

function bp_submitEntryReview(ID,contestID,jc,tabNum)
{
	if ($('entrySummary'+ID.toString()).value.toString() == '')
	{
		alert('Please enter an elevator pitch.');
		return false;
	}
	var judges = "";
	var passed = "0";
	for (var i =1; i < 3; i++)
	{
		if ($('passed'+ID.toString()+'_'+i.toString()).checked)
			passed = $('passed'+ID.toString()+'_'+i.toString()).value;
	}
	theCount = 0;
	for (var i = 0; i < jc; i++)
	{
		if ($('judge'+ID.toString()+'_'+i.toString()).checked)
		{
			if (theCount > 0)
				judges = judges.toString() + ','; 
			judges = judges.toString() + $('judge'+ID.toString()+'_'+i.toString()).value;
			theCount++;
		}
	}
	var bp_sack2 = new sack();
	bp_sack2.setVar("entryID", ID.toString());
	bp_sack2.setVar("entrySummary", $('entrySummary'+ID.toString()).value.toString());
	bp_sack2.setVar("passed", passed.toString());
	bp_sack2.setVar("judges", judges.toString());
	bp_sack2.setVar("bp_action", 'update_entry');
	bp_sack2.requestFile = bp_contestAjaxUrl.toString();
	bp_sack2.method = "POST";
	bp_sack2.onCompletion = function(){
		var response = bp_sack2.response; 
		bp_tabClick(contestID.toString(),tabNum.toString());
	};
	bp_sack2.runAJAX();
	
}

function bp_viewEntryVoting(ID)
{
	theTr = 'viewEntry'+ID.toString();
	theSpacer = 'viewEntrySpacer'+ID.toString();
	if (!addToggle[theTr])
	{
		addToggle[theTr] = true;
	}
	else
	{
		addToggle[theTr] = false;
	}
	if (!addToggle[theTr])
	{
		$(theSpacer).hide();
		$(theTr).hide();
	}
	else
	{
		$(theSpacer).show();
		$(theTr).appear();
	}
}

function $MYRF(ID)
{
	var checkboxes = [];
	var dataReturn = [];
	var qCount = $('questionCount'+ID.toString()).value;
	var entryForm = $('viewEntryForm'+ID.toString());
	elems = [];
	elems = entryForm.getElements();
	elems.each(function(e)
		{ 
			if (!dataReturn[e.name])
			{
				dataReturn[e.name] = [];
			}
			if (!dataReturn[e.name]['postData'])
				dataReturn[e.name]['postData'] = '';
			switch(e.type)
			{
				case "radio":
					if (e.checked) 
					{ 
						dataReturn[e.name]['postData'] = dataReturn[e.name]['postData'] + e.value;
					} 
				break;
				case "checkbox":
					if (dataReturn[e.name]['postData'] != '')
					{
						dataReturn[e.name]['postData'] = dataReturn[e.name]['postData'].toString() + ",";
					}
					if (e.checked) 
					{ 
						dataReturn[e.name]['postData'] = dataReturn[e.name]['postData'] + e.value;
					}
				break;
				default:
					dataReturn[e.name]['postData'] = dataReturn[e.name]['postData'] + e.value;
				break;
			}
		});	
	for (var i = 0; i<qCount; i++)
	{
		if (!dataReturn['question'+i.toString()])
			dataReturn['question'+i.toString()] = [];
		dataReturn['question'+i.toString()]['postData'] = $('question'+i.toString()).value;
	}
	return dataReturn;
}

function bp_submitVote(ID,uID,tab)
{
	if (confirm("You are about to enter your judgment for this contest entry.\nPlease take a minute to review your answers to be sure.\n\nIf you'd like to review/change your answers please click \"Cancel\".\nIf you are sure of your answers click \"OK\"."))
	{
		var myRadios = $MYRF(ID);
		var bp_sack2 = new sack();
		for (theKey in myRadios)
		{
			if (myRadios[theKey]['postData'])
			{
				bp_sack2.setVar(theKey.toString(), myRadios[theKey]['postData']);
			}
		}
		bp_sack2.requestFile = bp_contestAjaxUrl.toString();
		bp_sack2.method = "POST";
		bp_sack2.onCompletion = function(){
			var response = bp_sack2.response; 
			alert('Thank you for your vote!  Your responses have been recorded.');
			bp_profileTabClick(uID,tab);
		};
		bp_sack2.runAJAX();
	}
	else
	{
		return false;
	}
}


function bp_validateSignupForm()
{
	var entryForm = $('bp_signupForm');
	var student = true;
	var errMsg = '';
	if ($('studentN').checked)
		student = false;
	elems = [];
	elems = entryForm.getElements();
	elems.each(function(e)
		{ 
			var patt1=/required/gi;
			var patt2=/[^\d]/gi;
			//document.write(str.match(patt1));
			if (e.className.match(patt1))
			{
				doIt = true;
				znCheck= false;
				instrArray = e.className.split(":");
				if (student)
				{
					if (e.name == 'education' || e.name == 'exp_years')
						doIt = false;
					if (e.name == 'zNumber')
							znCheck= true;
				}
				else 
				{
					if (e.name == 'zNumber' || e.name == 'collegiateYear')
					{
						doIt = false;
					}
				}
				if (doIt)
				{
					if (e.value == '')
					{
						errMsg = errMsg.toString() + '\n' + instrArray[1];
					}
					if (znCheck && e.value != '')
					{
						if (e.value.match(patt2))
							errMsg = errMsg.toString() + '\n' + instrArray[1] + ' must be numeric only.';
					}
				}
				
			}
		});
	intChecked = false;
	buttons = entryForm.getInputs('checkbox')
	buttons.each(function(e)
		{ 
			if (e.checked)
				intChecked = true;
		});
	if (!intChecked)
		errMsg = errMsg.toString() + '\nInterests'
	if (errMsg != '')
	{
		alert('Please be sure that all required information has been filled out.\nThe following required fields are either empty or invalid:'+errMsg.toString());
		return false;
	}
	else
		return true;
}