var celebrationUpdater;
var orientationUpdater;

function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	
	return true;

}

function initPage() {
	celebrationUpdater = new celebrationUpdater();
	orientationUpdater = new orientationUpdater();
	ajaxEngine.registerRequest( 'getCelebrationDates', 'getCelebrationDates.jsp' );
	ajaxEngine.registerRequest( 'getOrientationDates', 'getOrientationDates.jsp' );
	ajaxEngine.registerAjaxObject( 'celebrationUpdater', celebrationUpdater );
	ajaxEngine.registerAjaxObject( 'orientationUpdater', orientationUpdater );
	celebrationUpdater.reset();
	orientationUpdater.reset();
	
	
    var flag = false;
    qsParm['campus'] = null;
	qs();
	
	if (qsParm['campus'] == 'np'){
		document.form1["fhscol_CampusID"].selectedIndex = 0;
	}
	if (qsParm['campus'] == 'bc'){
		document.form1["fhscol_CampusID"].selectedIndex = 1;
	}
	if (qsParm['campus'] == 'bb'){
		document.form1["fhscol_CampusID"].selectedIndex = 2;
	}

	
	//document.form1["fhscol_FirstName"].value = "";
	//document.form1["fhscol_SpouseName"].value = "";
	//document.form1["fhscol_srchgrouptype"].value = "";
	//document.form1["fhscol_GroupType"].value = "";
	//document.form1["HusbandName"].value = "";
	//document.form1["WifeName"].value = "";
	//document.form1["SingleName"].value = "";
}

function updateCampus(selectBox) {
   
   if ( selectBox.value == "" ){
      celebrationUpdater.reset();
	  orientationUpdater.reset();
   }
   else {
      setTimeout("ajaxEngine.sendRequest( 'getCelebrationDates','campusId=" + selectBox.value + "' )",400);
      setTimeout("ajaxEngine.sendRequest( 'getOrientationDates','campusId=" + selectBox.value + "' )",400);
   }
   
   document.form1["fhscol_CelebrationID"].value = "";
   document.form1["fhscol_OrientationID"].value = "";
}



function addCelebrationDate(id, cDate, slotsAvailable, selected) {
	//alert('addCelebrationDate');
  	var d = document.getElementById('celebrationDates');
	var lastRow = d.rows.length;
	var newRow = d.insertRow(lastRow);
	newRow.setAttribute('id','cd' + id);
	
	var newCell = newRow.insertCell(0);
	newCell.setAttribute('align','left');
	newCell.setAttribute('valign','top');
	var clickCode = 'updateCelebrationDate("' + id + '","' + cDate + '");';
	if (slotsAvailable > 0) {
		newCell.innerHTML = "<input id='cdRadio' name='cdRadio' type='radio' value='" + id + "' onclick='" + clickCode + "'> ";
	} else {
		newCell.innerHTML = "<input id='cdRadio' name='cdRadio' type='radio' value='" + id + "' style='display: none;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	}
	
	newCell.innerHTML = newCell.innerHTML + cDate;
	
	if (slotsAvailable <= 0) {
		newCell.innerHTML = newCell.innerHTML + " - <b>FULL</b>";
	}
}

function removeCelebrationDate(id) {
	var d = document.getElementById('celebrationDates');
	if (d.rows.length > 1) {
		for ( var i = 0 ; i < d.rows.length ; i++ ) {
			if (d.rows[i].id == "cd" + id)
				d.deleteRow(i);
		}
	} else {
		d.deleteRow(0);
	}
}

function updateCelebrationDate(id,cDate) {
	document.form1["fhscol_CelebrationID"].value = id;
	document.form1["fhscol_CelebrationDate"].value = cDate;
}


function addOrientationDate(id, oDate, slotsAvailable, selected) {
	//alert('addOrientationDate');
  	var d = document.getElementById('orientationDates');
	var lastRow = d.rows.length;
	var newRow = d.insertRow(lastRow);
	newRow.setAttribute('id','od' + id);
	
	var newCell = newRow.insertCell(0);
	newCell.setAttribute('align','left');
	newCell.setAttribute('valign','top');
	var clickCode = 'updateOrientationDate("' + id + '","' + oDate + '");';
	if (slotsAvailable > 0) {
		newCell.innerHTML = "<input id='odRadio' name='odRadio' type='radio' value='" + id + "' onclick='" + clickCode + "'> ";
	} else {
		newCell.innerHTML = "<input id='odRadio' name='odRadio' type='radio' value='" + id + "' style='display: none;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	}
	
	newCell.innerHTML = newCell.innerHTML + oDate;
	
	if (slotsAvailable <= 0) {
		newCell.innerHTML = newCell.innerHTML + " - <b>FULL</b>";
	}
}

function removeOrientationDate(id) {
	var d = document.getElementById('orientationDates');
	if (d.rows.length > 1) {
		for ( var i = 0 ; i < d.rows.length ; i++ ) {
			if (d.rows[i].id == "od" + id)
				d.deleteRow(i);
		}
	} else {
		d.deleteRow(0);
	}
}

function updateOrientationDate(id, oDate) {
	document.form1["fhscol_OrientationID"].value = id;
	document.form1["fhscol_OrientationDate"].value = oDate;
}


function addOption(selectbox,text,value){
	selectbox[selectbox.length] = new Option(text,value);
}

function clearList(selectbox){
	for (i=selectbox.length-1; i > 0; i--){
		selectbox[i] = null;
	}
}

function hideElement (elementId) {
	  var element;
	  if (document.all)
			element = document.all[elementId];
	  else if (document.getElementById)
			element = document.getElementById(elementId);
	  if (element && element.style)
			element.style.display = 'none';
 }
 function showElement (elementId) {
	  var element;
	  if (document.all)
			element = document.all[elementId];
	  else if (document.getElementById)
			element = document.getElementById(elementId);
	  if (element && element.style)
			element.style.display = '';
 }

var qsParm = new Array();
function qs() {
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}
}

function updateInvolvement(){
	if (document.form1["Member"].checked)
		document.form1["fhscol_Involvement_Member"].value = "Yes";
	else
		document.form1["fhscol_Involvement_Member"].value = "No";
	
	if (document.form1["Serving"].checked)
		document.form1["fhscol_Involvement_Serving"].value = "Yes";
	else
		document.form1["fhscol_Involvement_Serving"].value = "No";
		
	if (document.form1["Community_Group"].checked)
		document.form1["fhscol_Involvement_Community_Group"].value = "Yes";
	else
		document.form1["fhscol_Involvement_Community_Group"].value = "No";
}

function updateDateOfBirth(){
	document.form1["fhscol_DateOfBirth"].value = document.form1["BirthMonth"].value + "/" + document.form1["BirthDay"].value + "/" + document.form1["BirthYear"].value;
}

function formCheck(){
	message = "";
	
	
	//if (document.form1["fhscol_CampusID"].selectedIndex == 0){message += "  -- Campus\n";}
	if (document.form1["fhscol_Father_First_Name"].value == ""){message += "  -- Father's First Name\n";}
	if (document.form1["fhscol_Father_Last_Name"].value == ""){message += "  -- Father's Last Name\n";}
	if (document.form1["fhscol_Mother_First_Name"].value == ""){message += "  -- Mother's First Name\n";}
	if (document.form1["fhscol_Mother_Last_Name"].value == ""){message += "  -- Mother's Last Name\n";}
	if (document.form1["fhscol_Child_First_Name"].value == ""){message += "  -- Child's First Name\n";}
	if (document.form1["fhscol_Child_Middle_Name"].value == ""){message += "  -- Child's Middle Name\n";}
	if (document.form1["fhscol_Child_Last_Name"].value == ""){message += "  -- Child's Last Name\n";}
	if (document.form1["fhscol_Bible_Name"].value == ""){message += "  -- Child's Name to be printed on Bible\n";}
	if (document.form1["fhscol_DateOfBirth"].value == ""){message += "  -- Date of Birth\n";}
	
	//if (document.form1["BirthMonth"].selectedIndex == 0 || document.form1["BirthDay"].selectedIndex == 0 || document.form1["BirthYear"].selectedIndex == 0){message += "  -- Date of Birth\n";}
	
	if (document.form1["fhscol_Gender"].selectedIndex == 0){message += "  -- Gender\n";flag = false;}
	
	if (document.form1["fhscol_Phone"].value == ""){message += "  -- Phone Number\n";}
	if (document.form1["fhscol_Address"].value == ""){message += "  -- Address\n";}
	if (document.form1["fhscol_City"].value == ""){message += "  -- City\n";}
	if (document.form1["fhscol_State"].value == ""){message += "  -- State\n";}
	if (document.form1["fhscol_Zip"].value == ""){message += "  -- Zip\n";}
	if (document.form1["fhscol_Email"].value == ""){message += "  -- Email\n";}
	
	if (document.form1["fhscol_CelebrationID"].value == ""){
		message += "  -- Celebration Date\n";
	}
	if (document.form1["fhscol_OrientationID"].value == ""){
		message += "  -- Orientation Date\n";
	}
	
	
		
			
	if (message != ""){
		message = "You must enter the following information:\n\n" + message + "\nPlease click OK, enter the required information,\nand re-submit your request.";
		alert(message);
		return false;
	}
	
	switch(document.form1["fhscol_CampusID"].selectedIndex)
	 {
		case 0 : //NPCC
			document.form1["fhs_return_url"].value = "http://www.northpoint.org/babyD/page/reg_success";
			document.form1["fhs_sender"].value = "laura.flanagan@northpoint.org";
			document.form1["fhscol_Campus"].value = "North Point Community Church";
			break;
	   
		case 1 : //BC
			document.form1["fhs_return_url"].value = "http://www.buckheadchurch.org/babyD/page/reg_success";
			document.form1["fhs_sender"].value = "courtney.fitzgerald@buckheadchurch.org";
			document.form1["fhscol_Campus"].value = "Buckhead Church";
			break;
	   
		case 2 : //BB
			document.form1["fhs_return_url"].value = "http://www.brownsbridge.org/babyd/success.html";
			document.form1["fhs_sender"].value = "tracy.stonecheck@brownsbridge.org";
			document.form1["fhscol_Campus"].value = "Browns Bridge Community Church";
			break;
	 }
	 
	 document.form1["fhs_recipients"].value = document.form1["fhscol_Email"].value;
	
	//setFields();
			//alert(document.form1["fhs_recipients"].value);
			//return false;
	
	//submitForm(document.form1);
	//document.form1.submit();
	//return false;
	
}




