//Show all our span note elements
function HideElements(sPrefix) {
	var oTags = document.getElementsByTagName("span");
	var iPrefixLength = sPrefix.length;

	//Loop through the entire document looking at each tag
	for (var i = 0; i < oTags.length; i++) {
		//If the current tag supports having an ID, continue
		if ( oTags[i].id ) {
			//If the current tag has an ID, continue
			if ( oTags[i].id.length > iPrefixLength ) {
				//Check to see if the current ID is prefixed with what we are trying to hide
				if ( oTags[i].id.substring(0,iPrefixLength) == sPrefix ) {
					document.getElementById(oTags[i].id).style.display = "none";
				}
			}
		}
	}
}

//Set the alert text and display the hidden item
function ShowAndSet(sName, sText) {
	document.getElementById(sName).innerText		= sText;
	document.getElementById(sName).textContent	= sText; //Hack so that mozilla works
	document.getElementById(sName).style.display = "";
}

//Check for illegal characters in our string
function bCheckIllegalChars (sText) {
	var sIllegalChars = /\W/;

	if (sIllegalChars.test(sText)) {
		return false;
	}

	return true;
}

//Check for a valid date
function IsValidDate(str)
{
      var MonthArr = new Array(12);
      var v_date = str;
      v_split = v_date.indexOf("/");
      v_split2 = v_date.indexOf("/", v_split + 1);
      var v_day = v_date.substring(0, v_date.indexOf("/"));
      var del1 = v_date.substring(v_split, v_split + 1);
      var v_month = v_date.substring(v_split + 1, v_split2);
      var del2 = v_date.substring(v_split2, v_split2 + 1);
      var v_year= v_date.substring(v_split2 + 1, v_date.length);

      // creating array of months 1 - 12
      // Also compensating for leap years
      MonthArr["1"] = 31
      MonthArr["01"] = 31
      if (((v_year % 4 == 0) && (v_year % 100 != 0)) || (v_year % 400 == 0)) {
         MonthArr["2"] = 29
         MonthArr["02"] = 29
      } else {
         MonthArr["2"] = 28
         MonthArr["02"] = 28
      }
      MonthArr["3"] = 31
      MonthArr["03"] = 31
      MonthArr["4"] = 30
      MonthArr["04"] = 30
      MonthArr["5"] = 31
      MonthArr["05"] = 31
      MonthArr["6"] = 30
      MonthArr["06"] = 30
      MonthArr["7"] = 31
      MonthArr["07"] = 31
      MonthArr["8"] = 31
      MonthArr["08"] = 31
      MonthArr["9"] = 30
      MonthArr["09"] = 30
      MonthArr["10"] = 31
      MonthArr["11"] = 30
      MonthArr["12"] = 31

      if (eval(str != '')) {
         if (v_day < 1 || v_day > MonthArr[v_month] || isNaN(v_day)) {
            return false;
         } else {
         if (MonthArr[v_month] == null) {
           return false;
         } else {
            if (isNaN(v_year) || v_year == "" || v_year.length != 4 || v_year < 1899 || v_year > 2099){
            return false;
            }
         }
      }
   }

   return true;
}

//Check for non numeric characters
function bIsNumber (sText) {
	var sIsNumber = /(^-?\d\d*$)/;

	if (sIsNumber.test(sText)) {
		return false;
	}

	return true;
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{1,5}|[0-9]{1,5})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

//Check for valid file types in our filename
function bIsValidFileName (sText, bImage) {
	//Create the regular expressions that we will compare to our filenames
	var sImageTest = new RegExp("(\.jpg$)|(\.jpeg$)|(\.gif$)");
	var sFilesTest = new RegExp("(\.exe$)|(\.bat$)|(\.asp$)|(\.php$)|(\.pif$)|(\.com$)|(\.dll$)");
	var sTemp		= sText;

	sTemp = sTemp.toLowerCase();

	//handle images and files differently
	if ( bImage ) {
		// check the image filename - only allow what we have specified
		if (!sImageTest.test(sTemp)) {
			return false;
		}
	}
	else {
		// check the file upload filename - disallow only what we have specified
		if (sFilesTest.test(sTemp)) {
			return false;
		}
	}
	return true;
}
