/***** form field checking standard methods *****/

	function textCheck(fieldName){
		var textField = document.getElementById(fieldName);
		var textFieldMarker = document.getElementById("r_" + fieldName);
		if (textField.value == ""){
			if (textFieldMarker) textFieldMarker.style.visibility = 'visible';
			errors++;
			return false;
		}else{
			if (textFieldMarker) textFieldMarker.style.visibility = 'hidden';
			return true;
		}
	}
	function emailCheck(fieldName){
		var emailField = document.getElementById(fieldName);
		var emailMarker = document.getElementById("r_" + fieldName);		
		var ampers=0;
		var dots=0;
		if (emailField.value.length > 4){	
			for (i=0; i<(emailField.value.length); i++){
				if (emailField.value.substring(i,(i+1))=="@") ampers++;
				if (emailField.value.substring(i,(i+1))==".") dots++;
			}			
		}
		if ((emailField.value.length < 5)||(ampers != 1)||(dots == 0)){
			if (emailMarker) emailMarker.style.visibility = 'visible';
			errors++;
			return false;
		}else{
			if (emailMarker) emailMarker.style.visibility = 'hidden';
			return true;
		}
	}
	function dropdownCheck(fieldName){
		var dropdownField = document.getElementById(fieldName);
		var dropdownMarker = document.getElementById("r_" + fieldName);
		if (dropdownField.options[dropdownField.selectedIndex].value == ""){
			if (dropdownMarker) dropdownMarker.style.visibility = 'visible';
			errors++;
			return false;
		}else{
			if (dropdownMarker) dropdownMarker.style.visibility = 'hidden';
			return true;
		}
	}
	function radioSetCheck(fieldName){
		var radioMarker = document.getElementById("r_" + fieldName);
		var radiosChecked = 0;
		var optionCount = eval("document.Form1." + fieldName + ".length");
		for (i=0; i<optionCount; i++){
			if (eval("document.Form1." + fieldName + "[" + i + "].checked")){
				radiosChecked++;
			}
		}
		if (radiosChecked == 0) {
			if (radioMarker) radioMarker.style.visibility = 'visible';
			errors++;
			return false;
		}else{
			if (radioMarker) radioMarker.style.visibility = 'hidden';
			return true;
		}
	}
	function checkboxCheck(fieldName){
		var checkboxField = document.getElementById(fieldName);
		var checkboxMarker = document.getElementById("r_" + fieldName);
		if (checkboxField.checked == false){
			if (checkboxMarker) checkboxMarker.style.visibility = 'visible';
			errors++;
			return false;
		}else{
			if (checkboxMarker) checkboxMarker.style.visibility = 'hidden';
			return true;
		}
	}
	
/***** form element status detection and manipulation methods *****/	
	function radioCheckboxDetect(fieldName){
		if (document.getElementById(fieldName).checked != true){
			return false;
		}else{
			return true;
		}
	}
	function clearRadioSet(fieldName){
		var formField = eval("document.Form1." + fieldName);
		var fieldCount = formField.length;
		for (i=0; i<fieldCount; i++){
			eval("document.Form1." + fieldName + "[" + i + "].checked = false");
		}
		var radioMarker = document.getElementById("r_" + fieldName);
		if (radioMarker) radioMarker.style.visibility = 'hidden';
	}
	function selectRadioCheckbox(fieldName){
		document.getElementById(fieldName).checked = true;		
	}
	function dropdownChoice(fieldName){
		var dropdownField = document.getElementById(fieldName);
		return dropdownField.options[dropdownField.selectedIndex].value;
	}
	function dropdownChoiceIndex(fieldName){
		var dropdownField = document.getElementById(fieldName);
		return dropdownField.selectedIndex;
	}
	function radioSetChoice(fieldName,tocheck){
		var optionCount = eval("document.Form1." + fieldName + ".length");
		var chosenID;
		for (i=0; i<optionCount; i++){
			if (eval("document.Form1." + fieldName + "[" + i + "].checked")){
				chosenID = eval("document.Form1." + fieldName + "[" + i + "].id");
			}
		}
		if (tocheck == chosenID) return true;
	}
	function checkedCheckboxesCount(fieldName){
		var formField = eval("document.Form1." + fieldName);
		var fieldCount = formField.length;
		var checkedCount = 0;
		for (i=0; i<fieldCount; i++){
			if (eval("document.Form1." + fieldName + "[" + i + "].checked == true")) checkedCount++;
		}
		return checkedCount;
	}
	
	function resetForm(){
//		resetAllTextfields();
//		resetAllDropdowns();
		resetAllRadios();
		resetAllCheckboxes();
	}
	
	var inputFields = document.getElementsByTagName("input");
	function resetAllTextfields(){		
		for (i=0; i<inputFields.length; i++){
			if (inputFields[i].type == "text"){
				inputFields[i].value = "";
			}
		}
	}
	function resetDropdown(fieldName){
		var dropdown = document.getElementById(fieldName);
		dropdown.selectedIndex = 0;
	}
	function resetAllDropdowns(){
		var selectFields = document.getElementsByTagName("select");
		for (i=0; i<selectFields.length; i++){
			selectFields[i].selectedIndex = 0;
		}
	}	
	function resetAllRadios(){
		for (i=0; i<inputFields.length; i++){
			if (inputFields[i].type == "radio"){
				inputFields[i].checked = false;
			}
		}		
	}
	function resetAllCheckboxes(){
		for (i=0; i<inputFields.length; i++){
			if (inputFields[i].type == "checkbox"){
				inputFields[i].checked = false;
			}
		}		
	}

/*
	function resetTextfieldsSet(setID){
		alert(setID);
		var inputFieldsSet = document.getElementById(setID).getElementsByTagName("input");
		alert(inputFieldsSet.length);
		for (i=0; i<inputFieldsSet.length; i++){
			if (inputFieldsSet[i].type == "text"){
				inputFieldsSet[i].value = "";
			}
		}
	}
*/
	
// round off amount to pounds and pence
	function formatAsMoney(mnt) {
		mnt -= 0;
		mnt = (Math.round(mnt*100))/100;
		return (mnt == Math.floor(mnt)) ? mnt + '.00' : ( (mnt*10 == Math.floor(mnt*10)) ? mnt + '0' : mnt);
	}
	
/***** Array indexOf browser implementation workaround *****/
if (!Array.prototype.indexOf){
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

	// check that a character is an integer
	function validateInt(character){
		switch (isInteger(character)){
			case true:
				return true;
			case false:
				return false;
		}
	}
	function isInteger (s){
		  var i;
	
		  if (isEmpty(s))
		  if (isInteger.arguments.length == 1) return 0;
		  else return (isInteger.arguments[1] == true);
	
		  for (i = 0; i < s.length; i++){
			 var c = s.charAt(i);
	
			 if (!isDigit(c)) return false;
		  }	
		  return true;
	}
	function isEmpty(s){
		  return ((s == null) || (s.length == 0))
	}
	function isDigit (c){
		  return ((c >= "0") && (c <= "9"))
	}
