function SetCheckBoxValue(ValueContainer, CheckBox) {
	ValueContainer.value = (CheckBox.checked ? 1 : 0);
}
function WriteEmail(d, n, v) {
	document.write("<a "+"hre"+"f='mai"+"lto:"+n+"@"+d+"'>");
	if (v == '') {
		document.write(n+"@"+d);
	} else {
		document.write(v);
	}
	document.write("</a>");
}
function SetCaptain(IsCaptainID) {
	var Elements = document.getElementsByTagName("input");
	for (i = 0; i < Elements.length; i++) {
		if (Elements[i].name.indexOf("IsCaptain_") == 0) {
			if (Elements[i].name == "IsCaptain_"+""+IsCaptainID) {
				Elements[i].value = 1;
			} else {
				Elements[i].value = 0;
			}
		}
	}
}
// Finds more selectors with incremented names and sets them to the same value as this one
function CascadeChange(formName, selector, increment) {
	// Name should be in the format of: Name_#
	var frm = document[formName];
	var name = selector.name;
	var pos = name.lastIndexOf("_");
	var indexToSelect = selector.selectedIndex;
	if (pos) {
		var nameprefix = name.slice(0,pos);
		var digit = name.slice(pos+1)*1;
		digit = digit + increment;
		var nextSelector = nameprefix+"_"+digit;
		while (frm[nextSelector]) {
			//alert(nextSelector+" has "+frm[nextSelector].options.length+" options");
			//alert(frm[nextSelector].options[indexToSelect].selected);
			frm[nextSelector].options[indexToSelect].selected = true;
			digit = digit + increment;
			nextSelector = nameprefix+"_"+digit;		
		}
	}
	
}
// Finds all checkboxes with the nameprefix and sets them 
// to the same checked status as the controller.
function CheckController(formName, controller, controlled) {
	var frm = document[formName];
	var CheckedStatus = controller.checked;
	if (frm[controlled]) {
		if (frm[controlled].length) {
			for (i = 0; i < frm[controlled].length; i++) {
				frm[controlled][i].checked = CheckedStatus;
			}
		} else {
			frm[controlled].checked = CheckedStatus;
		}
	}
}

function switchVisibility(SectionToAlter, CurrentStyle) {
	// Get the requested element
	var Section = document.getElementById(SectionToAlter);
	// Reverse it's display
	if (Section.style.display == "" && CurrentStyle != "") Section.style.display = CurrentStyle;
	Section.style.display = (Section.style.display == "none") ? "block" : "none";
}
function FlipSwitch(Switch, Element) {
	switchVisibility(Element);
	switchVisibility(Switch, 'block');
}
function switchPreviousRegistrations(Display) {
	FlipSwitch('PreviousRegistrationsLink', 'PreviousRegistrations');
}

function popWindow(url,name,height,width) {
  window.open(url,name,"toolbar=no,status=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,width="+width+",height="+height);
}

function SubmitForm(FormName, Sender) {
	Sender.disabled = true;
	Sender.value = "Wait";
	document[FormName].submit();
}
function Help(JumpTo) {
	popWindow("../member/help.html#"+JumpTo, "Help", 500, 400);
}



//added by Ken


var currentField, nextField; 
function advance(formName, currentInput, nextInputName, currentLength) { 
    currentField = currentInput;
    nextField = nextInputName;
    currentInput.blur();
    setTimeout("effect('"+formName+"', "+currentLength+")",1);
}

function effect(formName, currentLength) {
   if (currentField.value.length == currentLength) {
      document[formName][nextField].focus();
   } else {
      currentField.focus();
   }
}
/*
 the inputs should then appear like so:
 enter phone number:
 <input type="text" maxlength="3" name="f1" onKeyUp="advance(formName,this,'f2',3)">
 <input type="text" maxlength="3" name="f2" onKeyUp="advance(formName,this,'f2',3)">
 <input type="text" maxlength="4" name="f3">

*/