//©2000 Jersey Cow Software Co., Inc.

//Checks the completeness of an input string. 
function ecNeedStringAlert(string, stringName) {
	if (string == ""){
		window.alert ("You did not give us " + stringName 
			+ ". Please try again.");
		return false;
	} else {	
		return true;
	}
}

//Checks the completeness of two input strings. 
function ecNeed2StringsAlert(string1, string2, string1Name, string2Name) {
	if (string1 == "" && string2 == "" ){
		window.alert ("You did not give us " + string1Name 
			+ " and " + string2Name + ". Please try again.");
		return false;
	} else if (string1 == "") {
		window.alert ("You did not give us " + string1Name + ". Please try again.");
		return false;
	} else if (string2 == "") {
		window.alert ("You did not give us " + string2Name + ". Please try again.");
		return false;
	} else {	
		return true;
	}
}

//Checks if two strings are equal.
function ecMatch2Strings(string1, string2, stringNames) {
	if (string1 == string2) 
		return true;
	else {
		window.alert ("Your " + stringNames + " do not match. Please try again.");
		return false;
	}
}

//Checks if a string is composed of the valid characters. 
function ecCheckCharacter(string, stringName) {
	if (string.match(/[^0-9A-Za-z_\-\.]/)) {
		window.alert ("Only letters, numbers, dashes, underscores and dots"
			+ "\nare allowed in " + stringName + ". Please try again.");
		return false;
	}
	else 
		return true;
}

//Trims extra spaces in a string.
function ecLMRTrim(string) {
	newString = string.replace(/^\s+/, "");
	newString = newString.replace(/\s+$/, "");
  return newString.replace(/  /g, " ");
}
function ecTrim(string) {
	newString = string.replace(/^\s+/, "");
	return newString.replace(/\s+$/, "");
}

//Checks if one of the radio buttons is checked.
function radioChecked(button) {
  for (i = 0; i < button.length; i++) {
   if (button[i].checked) return true;
  }
  return false;  // non is checked, so ...
}

//Informs a question should be answered.
function ensureAnswer(question) {
  msg = 'You did not answer the question\n';
  msg = msg + question + '\n';
  msg = msg + 'You must answer all the questions to continue.';
  alert(msg);
  return false; 
}
