 function validate(value, type){
	//alert(value+ " \n "+ type)
	switch(type)
	{
	case "required":
		return isNotEmpty(value);
		break;    
	case "int":
		return isInt(value);
		break;
	case "email":
		return isEmail(value);
		break;  
	default:
		//unknown type
	} 
 }
 function validate_output(f, valid, msg){
	if(!valid){
		var validationSummary = document.getElementById("validationSummary");
		//alert((!validationSummary) + " : "+(validationSummary == null))
		if(!validationSummary || validationSummary == null){
			
			validationSummary = document.createElement('div');
			validationSummary.setAttribute("id","validationSummary");
			validationSummary = f.appendChild(validationSummary);
			//alert(document.getElementById("validationSummary"));
		}
		//var text=document.createTextNode(msg+"<br/>");
		//validationSummary.appendChild(text);
		validationSummary.innerHTML += "<a name='validationSummary'></a>";
		validationSummary.innerHTML += msg+"<br/>";
		//alert(validationSummary.innerHTML)
		//alert(msg);
	}
 }
  function validate_clear(f){
	var validationSummary = document.getElementById("validationSummary");
	if(validationSummary && validationSummary != null){
		validationSummary.innerHTML = "";
	}

 }
 
	//returns an array of length 3; EXAMPLE: the URL "www.idynamix.org/cms/index.asp?userid=111000111&func=1" would return an array with ARRAY[0]="path to the current page" (i.e., www.idynamix.org/cms/), ARRAY[1]="the current page" (i.e., index.asp), and ARRAY[2]="the current query string" (i.e., userid=111000111&func=1)
    function URLParse(){
      var url = document.location
      var locString = new String(document.location);
      var locArray = locString.split("/");
      var currentPage = locArray[locArray.length-1].split("?")[0]; //gets the current page
      var currentQueryString = locArray[locArray.length-1].split("?")[1] //gets the set of querystrings currently displayed (if any)
      var currentPath = locString.split(currentPage)[0]; //gets the path to the current page

      //alert(currentPage + "\n" + currentPath + "\n" + currentQueryString);
      return new Array (currentPath, currentPage, currentQueryString)
    }

    


    //checks if parameter "str" (a string) is a valid integer; returns true or false
    function isInt (str) {
      if (str){
      //Use parseInt to convert str, the input string, to an integer. This results in i being set to either an integer or NaN ("Not a Number").
      //UPDATED: 2004/10/7 -- NOW USES PARSEFLOAT
      //NOTE: THIS FUNCTION WILL NOT ACCEPT "000000000" OR "0000000009" OR ANY NUMBER THAT BEGINS WITH ZEROS BECAUSE IT CHECKS LENGTH (WHEN "0000009" IS PARSED IT RETURNS "9" WHICH HAS A DIFFERENT LENGTH)
      var i = parseFloat(str);//I know parse int would be more appropriate, but right now this works fine :)

      //Determine if i is NaN. If it is, then the input string must not have been an integer. In this case, return false.
      if (isNaN (i))
        return false;
    
      //If we've reached this point, then we know that the input string begins with an integer, but now we would like to verify that no extraneous characters are attached to the end of the integer.  To do this, just convert the integer back into a string and see if it matches the original input string. If it doesn't, then there are extraneous characters in the input string, and we should return false.
      i = i.toString ();
      if (i != str)
        return false;

      //If we've made it this far, then the input string has passed all the tests. It contains "an integer, the whole integer, and nothing but the integer!"
      return true;
      }else{
        return true;
      }
    }
 
    //checks if parameter "str" (a string) is a valid email; returns true or false
    function isEmail(str) {

	
      if (str){
        //var emailregex = /^[\w\_\-\.]+@[\w\_\-\.]+\.\w+$/;
		var emailregex = /^[\w\_\-\.0-9a-zA-Z]+@[\w\_\-\.0-9a-zA-Z]+\.[\w0-9a-zA-Z]+$/;
        var emailresult = str.match(emailregex)
        if (emailresult == null) {
	  return false;
        }else {
          return true;
        }
      }else{
        return true;
      }
    }

    //checks if parameter "str" (a string) is a valid date; returns true or false
    function isDate(str) {
      //if (str){
      //  var dateregex = [19|20]\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01]);
      //  var dateresult = str.match(dateregex)
      //  if (dateresult == null) {
      //  return false;
      //  }else {
      //    return true;
      //  }
      //}else{
        return true;
      //}
    }

    //checks if parameter "str" (a string) is a valid string; returns true or false
    function isString(str) {
      //if (str) {
        return true;
      //}else {
      //  return false;
      //}
    }

//(value==null||value=="")
    function isNotEmpty(str){
      if (str && !(str==null || str=="")) {
        return true;
      }else {
        return false;
      }      
    }

    function validLength(maxlength, strForm, fieldID) {
      var numChars = (document.getElementById(fieldID).value).length
      if(numChars >= maxlength) {
        alert("This field can handle "+ maxlength +" characters or less. There are currently "+ numChars +" characters. Please trim this text.");
        document.getElementById(fieldID).focus();
        return false;
      } else {
        return true;
      }
    }
    


    //IF a field contains valid content THEN does nothing, ELSE highlights the field in red
    function displayFormError(theFieldCheck, theFieldObj, theErrorMessage) {
      if (theFieldCheck) {
        theFieldObj.style.backgroundColor = '#FFFFFF';
        return true;
      }else {
        theFieldObj.style.backgroundColor = '#FFEEEE';
        alert(theErrorMessage);
        return false;
      }
    }
