// JavaScript Document
// my filter library - filters.js
// Joel Hutchins
// 07/13/04
//
//isEmpty
function isEmpty(inputStr) {
  if (inputStr == null || inputStr == "") {
	//alert("isEmpty returning true...");
    return true
  } else {
	//alert("isEmpty returning false...");
    return false
  }
}
//isNotEmpty
function isNotEmpty(inputStr) {
  //alert("inputStr.length: " + inputStr.length);
  if (inputStr == null || inputStr == "") {
	//alert("isNotEmpty returning false...");
    return false
  } else {
	//alert("isNotEmpty returning true...");
    return true
  }
}

//isPosInteger
function isPosInteger(inputVal) {
  inputStr = inputVal.toString();
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
	if (oneChar < "0" || oneChar > "9") {
	  return false
	} 
  } return true
}
//isLetters - letters or spaces only, like a name
function isLetters(inputVal) {
  //alert("isLetters...")
  inputStr = inputVal.toString();
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
	//alert("isLetters checking:" + oneChar);
	if (oneChar == " ") {
	  //alert("oneChar is blank...")
	  continue
	}
	if (oneChar < "A" || oneChar > "z") {
	  //alert("isLetters returning false")
	  return false
	}
  }
  //alert("isLetters returning true")
  return true
}
//isInteger - can accept a leading minus sign
function isInteger(inputVal) {
  //alert("isInteger...")
  inputStr = inputVal.toString()
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
	//alert("isInteger checking -");
	if (i == 0 && oneChar == "-") {
	  continue
	}
	//alert("isInteger checking oneChar");
	if (oneChar < "0" || oneChar > "9") {
	  //alert("isInteger returning false")
	  return false
	}
  }
  //alert("isInteger returning true")
  return true
}

// isNumber - enables any integer or floating-point number
function isNumber(inputVal) {
  oneDecimal = false
  inputStr = inputVal.toString()
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
	if (i == 0 && oneChar == "-") {
	  continue
	}
	if (oneChar == "." && !oneDecimal) {
	  oneDecimal = true;
	  continue
	}
	if (oneChar < "0" || oneChar > "9") {
	  return false
	}
  }
  return true
}

//isHtml - no cross site scripting allowed!
function isNotHtml(inputStr) {
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
	if (oneChar == "<" || oneChar == ">") {
	  //alert ("Please make sure entries do not contain < or > symbols.");
	  return false
	} 
  } 
  return true
}
///////////////////////////////////////////////////////////////
function getFormData() {
  //alert("getFormData");
  var the_form= window.document.sendinfo;
  var returnval = true;
  // just manually go through the form elements and check each one
  // using the appropriate filter functions
  
  //the lastname test
  if (isNotEmpty(the_form.lastname.value)) {
	//alert("isNotEmpty: " + the_form.lastname.value);
	if (isLetters(the_form.lastname.value)) {
      //alert("isLetters: " + the_form.lastname.value);
	} else {
	  returnval = false;
	  alert("lastname is invalid")
	}
  } else {
	  returnval = false;
	  alert("lastname is empty");
  }

 //the firstname test
  if (isNotEmpty(the_form.firstname.value)) {
	//alert("isNotEmpty: " + the_form.firstname.value);
	if (isLetters(the_form.firstname.value)) {
      //alert("isLetters: " + the_form.firstname.value);
	} else {
	  returnval = false;
	  alert("firstname is invalid")
	}
  } else {
	  returnval = false;
	  alert("firstname is empty");
  }
//street address test
  if (isNotEmpty(the_form.address.value)) {
	//alert("isNotEmpty: " + the_form.address.value);	
  } else {
	  returnval = false;
	  alert("street address is empty");
  }
//city test
  if (isNotEmpty(the_form.city.value)) {
	//alert("isNotEmpty: " + the_form.city.value);
	if (isLetters(the_form.city.value)) {
      //alert("isLetters: " + the_form.city.value);
	} else {
	  returnval = false;
	  alert("city is invalid")
	}
  } else {
	  returnval = false;
	  alert("city is empty");
  }
//state test
  if (isNotEmpty(the_form.state.value)) {
	//alert("isNotEmpty: " + the_form.state.value);
	if (isLetters(the_form.state.value)) {
      //alert("isLetters: " + the_form.state.value);
	} else {
	  returnval = false;
	  alert("state is invalid")
	}
  } else {
	  returnval = false;
	  alert("state is empty");
  }
//zip code test
  if (isNotEmpty(the_form.zipcode.value)) {
	//alert("zip code isNotEmpty: " + the_form.zipcode.value);
	if (isPosInteger(the_form.zipcode.value)) {
      //alert("zip code: " + the_form.zipcode.value);
	} else {
	  returnval = false;
	  alert("zip code is invalid")
	}
  } else {
	  returnval = false;
	  alert("zip code is empty");
  }
  
  //comments html test - comments may be empty
  if (isNotEmpty(the_form.comments.value)) {
	//alert("comments isNotEmpty: " + the_form.comments.value);	
	if (isNotHtml(the_form.comments.value)) {
		//alert("comments not html...");
    } else {
	  returnval = false;
	  alert("Comments may not contain any < or > characters.");
	}
  }

////////////////////////////////////////////////////
  //alert("getformdata returning: " + returnval);
  return returnval;
}

///////////////////////////////////////////////////////////////
// nsDetect is called to detect the Netscape browser and alert the user 
// 
// Joel Hutchins 6/9/04
///////////////////////////////////////////////////////////////
function nsDetect() {
  var browser = navigator.appName;
  lcbrowser = browser.toLowerCase();
  //alert(lcbrowser);
  isexp = lcbrowser.indexOf("explorer");
  //alert(isexp);
  isexp2 = lcbrowser.indexOf("ie");
  //alert(isexp2);
  if ((isexp == -1) && (isexp2 == -1))  {
    alert('Some examples only run in Netscape.');
  } else {
    alert("VBScript runs in Internet Explorer.")
  }
}