function doBlink()
{
	var blink = document.all.tags("BLINK");
	for (var i=0; i<blink.length; i++)
	{
		blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : ""
	}
}

function startBlink()
{
	if (document.all) setInterval("doBlink()",750)
}
window.onload = startBlink;

function fncCheckSearch(){
	
		if(checkdate(document.SearchForm.SDate,0)==false){
			alert("Incorrect Format For Start Date.\n\nPlease Correct Or Leave Blank.")
			document.SearchForm.SDate.focus();
			document.SearchForm.SDate.select();
			return false;
		}
		
		if(checkdate(document.SearchForm.EDate,0)==false){
			alert("Incorrect Format For End Date.\n\nPlease Correct Or Leave Blank.")
			document.SearchForm.EDate.focus();
			document.SearchForm.EDate.select();
			return false;
		}
		
		
		if(chkDateRange(document.SearchForm.SDate,document.SearchForm.EDate)==false){
			alert("End Date Must Be After Start Date.")
			document.SearchForm.EDate.focus();
			document.SearchForm.EDate.select();
			return false;
		}
				
		return true;

}


//VALIDATE THAT EMAIL IN CORRECT FORMAT
function ValidateEmail(str){
	var resultStr = str.replace(/ /gi, "");	
	var atIndex = resultStr.indexOf("@");
	var dotIndex = resultStr.lastIndexOf(".");
	if( resultStr == "" || !isASCII(resultStr) || dotIndex == -1)	
	return "";
	if ( resultStr.lastIndexOf("@") != atIndex || resultStr.charAt(atIndex+1) == ".")
	return "";
	if ( atIndex <= 0 || dotIndex < atIndex || dotIndex >= resultStr.length-1)	
	return "";
	return resultStr;	
}
	
function isValidEmailAddress(s) {
	var temp = s.replace(/\s/g, "")
	
	return (temp.match(/^[\w\.\-]+\x40[\w\.\-]+\.\w{5}$/) || temp.match(/^[\w\.\-]+\x40[\w\.\-]+\.\w{4}$/) || temp.match(/^[\w\.\-]+\x40[\w\.\-]+\.\w{3}$/) || temp.match(/^[\w\.\-]+\x40[\w\.\-]+\.\w{2}$/)) && 
			temp.charAt(0) != "." && !(temp.match(/\.\./))
}	
		
//VALIDATE DOMAIN OF EMAIL ADDRESS
function ValidateDomain(str){
	var resultStr = str.replace(/ /gi, "");
	var atIndex = resultStr.indexOf("@");
	var dotIndex = resultStr.lastIndexOf(".");
	if( resultStr=="" || !isASCII(resultStr) || dotIndex == -1)
	return "";
	if ( atIndex > 0 || resultStr.charAt(atIndex+1) == "." || dotIndex >= resultStr.length-1 )	
	return "";
	return resultStr.replace(/@/i, "");	
}

//VALDIATE EMAIL
function isEmail(str) {
	var pass = 0;
	if (window.RegExp) {
	var tempStr = "a";
	var tempReg = new RegExp(tempStr);
	if (tempReg.test(tempStr)) pass = 1;
	}
	if (!pass) 
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]*[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}


//CHECK IF ALPHABETIC CHARACTERS
function IsAlpha( str )
{
   var isValid = true;

   str += "";
	for (i = 0; i < str.length; i++)
      {
      // Alpha must be between "A"-"Z", or "a"-"z"
      if ( !( ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
               ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ) )
               {
                     isValid = false;
                     break;
               }
      }   
   return isValid;
}


//CHECK IF ALPHANUMERIC
function IsAlphaNum( str )
{
   var i = 0;
   var isValid = false;
   
   str += "";   
      for (i = 0; i < str.length; i++)
      {
      // Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
            if ( ((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
               ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
               ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) )
                  isValid = true;
      }    
      return isValid;
} 


//CHECK IF ALPHANUMERIC OR UNDERSCORE
function IsAlphaNumOrUnderscore( str )
{
   var i = 0;
   var isValid = true;

    str += "";
    for (i = 0; i < str.length; i++)
      {
      // Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
            if ( !( ((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
               ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
               ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ||
               (str.charAt(i) == "_") ) )
               {
               isValid = false;
                     break;
               }
		}   
   return isValid;
} 


//CHECK IF FIELD IS BLANK
function isBlank(s) {
	var blankCharacters = [" ", "&nbsp;", "&#032;"];
	for (var i = 0; i < blankCharacters.length; i++) {
		s = s.replace(eval("/" + blankCharacters[i] + "/gi"), "");
	}
	return (s == "") ? true:false;
}

//CHECK IF FIELD IS A NUMBER
function IsNum( numstr )
{
   var IsValid = true;

   numstr += "";   
   for (i = 0; i < numstr.length; i++)
     {
       if (! ((numstr.charAt(i) >= "0") && 
             (numstr.charAt(i) <= "9")) ) {
          IsValid = false;
          break;
      }
   }   
   return IsValid;
} 

//FUNCTION TO CHECK IF A POSITIVE INTEGER
function IsPositiveInteger(objName,intMin){
	if((objName.value < intMin)||(objName.value.indexOf(".") > -1)){
		return false;
	}
	return true;
}


//FUNCTION TO CHECK VALIDITY OF DATE IN TEXTBOX
// isBlank = 0 if object doesn't have to have a value

function checkdate(objName,isBlank) {
	var datefield = objName;
	
	if (chkdate(objName,isBlank) == false) {
		datefield.select();
			return false;
		}
	else {
		return true;
		}
	}
	
function chkdate(objName,isBlank) {
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var datefield = objName;
	var strSeparator = "/";
	var intElementNr;
	var err = 0;

	strDate = datefield.value;

	if (strDate.length < 1) {
		if (isBlank == 1){
			return false;
				}
		else{
			return true;
			}
		}

	strDateArray = strDate.split(strSeparator);
	if (strDateArray.length != 3) {
		err = 1;
		return false;
		}
	else {
		strDay = strDateArray[1];
		strMonth = strDateArray[0];
		strYear = strDateArray[2];
		}
	
	if (strYear.length == 1) {
		strYear = '200' + strYear;
		}
	
	if (strYear.length > 4) {
		return false;
		}
		
	if (strYear.length == 2) {
		if(parseInt(strYear) > 30)
			strYear = '19' + strYear;
		else
			strYear = '20' + strYear;
		}

	if (isNaN(strDay)) {
		err = 2;
		return false;
		}
	intday = strDay;
	
	if (isNaN(strMonth)) {
		 err = 3;
		 return false;
		}
	intMonth = strMonth;
	
	if (isNaN(strYear)) {
		err = 4;
		return false;
		}
	intYear = strYear;

	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
		}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
		}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
		}
	
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			return false;
			}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
				}
			}
		else {
			if (intday > 28) {
				err = 10;
				return false;
				}
			}
		}

	if(strMonth.length == 1){
		intMonth = '0'+intMonth;
		}
	if(strDay.length == 1){
		intday = '0'+intday;
		}
		
	datefield.value = intMonth+"/"+intday+"/"+intYear;
			
	return true;
}
	
function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
		}
	else {
		if ((intYear % 4) == 0) { return true; }
		}
	return false;
}


//FUNCTION TO MAKE SURE TWO DATE VALUES ARE IN ORDER
function chkDateRange(objFirstDate,objSecondDate){
		if (isBlank(objFirstDate.value)||isBlank(objSecondDate.value)){
				return true;
			}
		else{
			if (Date.parse(objFirstDate.value) <= Date.parse(objSecondDate.value)){
				return true;
			}
			else {
				return false;
				}
			}
		}