// JavaScript Document

/*function validateFormOnSubmit(theForm) {
  var error = "";
  focusField = "";
  emptyFields = false;
  emailError = false;

  validateEmpty(theForm.FullName, "eName", 'Name');
  validateEmail(theForm.Email, "eEmail", 'Email');
  fixInterests(theForm);
  
  if (emptyFields) {
	error += "Please fill in all required fields.\n"
  }
  if (emailError) {
	error += "Invalid email address.\n";
  }
  if (error != "") {
    alert(error);
    return false;
  }

  return true;
}*/

function validateEmpty(fld, efld, emptyFiller) {
    if (fld.value == emptyFiller || fld.value == "") {
        emptyFields=true;
		document.getElementById(efld).style.color="#FF0000";
    } else {
		document.getElementById(efld).style.color="#000000";
    }
}

function trim(s){
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld, efld, emptyFiller) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
   	if (fld.value == emptyFiller) {
		 document.getElementById(efld).style.color="#FF0000";
		 emptyFields=true;
	}else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        document.getElementById(efld).style.color="#FF0000";
		 emailError=true;
    } else if (fld.value.match(illegalChars)) {
        document.getElementById(efld).style.color="#FF0000";
		 emailError=true;
    } else {
        document.getElementById(efld).style.color="#000000";
    }
}

function validateNumeric(field, efld, emptyFiller) {
	var check = true;
	var value = field.value; //get characters
	//check that all characters are digits, ., -, or ""
	for(var i=0;i < field.value.length; ++i) {
	   var new_key = value.charAt(i); //cycle through characters
	   if(((new_key < "0") || (new_key > "9")) &&
			!(new_key == ""))
	   {
			check = false;
			break;
	   }
	}
	
	//apply appropriate colour based on value
	if(!check || value == "") {
	   numericError = true;
	   document.getElementById(efld).style.color="#FF0000";
	}
	else {
	   document.getElementById(efld).style.color="#000000";
	}
}


function validateRadio(radioGroup) {
	myOption = -1;
	for (i=radioGroup.length-1; i > -1; i--) {
		if (radioGroup[i].checked) {
			myOption = i; i = -1;
		}
	}
	if (myOption == -1) {
		radioError = true;
	}
}
                  

