function checkpositivenumber(object_value)
    {
    //Returns true if value is a numberd
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading +.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be +.  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks

		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
    }

function checknumber(object_value)
    {
    //Returns true if value is a numberd
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks

		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
    }

	
	function checkdate(object_value)
    {
    //Returns true if value is a date format or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a date in the mm/dd/yyyy format
	isplit = object_value.indexOf('/');

	if (isplit == -1 || isplit == object_value.length)
		return false;

    sDay = object_value.substring(0, isplit);

	if (sDay.length == 0)
        return false;

	isplit = object_value.indexOf('/', isplit + 1);

	if (isplit == -1 || (isplit + 1 ) == object_value.length)
		return false;

	sMonth = object_value.substring((sDay.length + 1), isplit);

	if (sMonth.length == 0)
        return false;

	sYear = object_value.substring(isplit + 1);

	if (!checkinteger(sMonth)) //check month
		return false;
	else
	if (!checkrange(sMonth, 1, 12)) //check month
		return false;
	else
	if (!checkinteger(sYear)) //check year
		return false;
	else
	if (!checkrange(sYear, 0, 9999)) //check year
		return false;
	else
	if (!checkinteger(sDay)) //check day
		return false;
	else
	if (!checkday(sYear, sMonth, sDay)) // check day
		return false;
	else
		return true;
    }

function checkday(checkYear, checkMonth, checkDay)
    {

	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
			checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else
	if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else
		if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}

	return checkrange(checkDay, 1, maxDay); //check day
    }

function checkinteger(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;
 
    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)

    //Was it a decimal?
    if (check_char < 1)
	return checknumber(object_value);
    else
	return false;
    }

function numberrange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
	{
        if (object_value < min_value)
		return false;
	}

    // check maximum
    if (max_value != null)
	{
	if (object_value > max_value)
		return false;
	}
	
    //All tests passed, so...
    return true;
    }

function checkrange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false

    if (object_value.length == 0)
        return true;

    if (!checknumber(object_value))
	{
	return false;
	}
    else
	{
	return (numberrange((eval(object_value)), min_value, max_value));
	}
	
    //All tests passed, so...
    return true;
    }

function checkDates(element,msg){

	if (element.value != ''){
		
		var tmpVal = validateDate(element.value,'-');
		
		if (tmpVal == false){
		
			//failed the first test, so start again
			tmpVal = validateDate(element.value,'/');
		
			if (tmpVal == false)  {
				//failed the second test, one more case....
				tmpVal = validateDate(element.value,'');
				if (tmpVal == false)  {
					// not a date in any of our formats so display error msg	
					alert(msg);
					element.focus();
					return true;
					}
					else{
					//final case is true
					element.value = tmpVal;
					return false;
					}
			}	
			else{
			element.value = tmpVal;
			return false;
			}
		}
		else {
		element.value = tmpVal;
		return false;
		}
	}
}

function validateDate(object_value,seperator){
//Returns true if value is a date format 
    //otherwise returns false	
 if (seperator != "" )
	{
    if (object_value.length == 0)
        return false;
  
		//Returns true if value is a date in the mm/dd/yyyy format
		isplit = object_value.indexOf(seperator);

		if (isplit == -1 || isplit == object_value.length)
			return false;
	
		//sMonth = object_value.substring(0, isplit);
		sDay = object_value.substring(0, isplit);

		if (sDay.length == 0)
		  return false;

		isplit = object_value.indexOf(seperator, isplit + 1);

		if (isplit == -1 || (isplit + 1 ) == object_value.length)
			return false;

		//sDay = object_value.substring((sMonth.length + 1), isplit);
		sMonth = object_value.substring((sDay.length + 1), isplit);
		
		if (sMonth.length == 0)
		  return false;

		sYear = object_value.substring(isplit + 1);
	
		//convert the mmm into a numeric so that it can be read
		sMonth = convertMonth(sMonth);
		
		// check date not above current date
		// var vCompareDate = new Date(sYear, sMonth-1, sDay);
		// var vToday = new Date();
		
		// if (vCompareDate > vToday)
		//		return false;
				
		
	}
else
	{ 

		//case of dmmyy or ddmmyy
	
		switch (object_value.length)
		{
		case 5:
			sDay = object_value.substring(0,1);
			sMonth = object_value.substring(1,3);
			sYear = object_value.substring(3,5);
			break;	
		case 6:
			sDay = object_value.substring(0,2);
			sMonth = object_value.substring(2,4);
			sYear = object_value.substring(4,6);
			break;
		default:
			return false;
		}
	}	

	//convert the year into four digit year if it isn't
	switch (sYear.length)
	{
		case 1:
			if (sYear > 29){
				sYear = 190 + sYear
			}
			else{
				sYear = 200 + sYear
			}
			break;
		case 2:
			if (sYear > 29){
				sYear = 19 + sYear
			}
			else{
				sYear = 20 + sYear
			}
			break;
		case 3:
			sYear = 2 + sYear;
			break;
	}
	
	if (!checkinteger(sMonth)) //check month
		return false;
	else
	if (!checkrange(sMonth, 1, 12)) //check month
		return false;
	else
	if (!checkinteger(sYear)) //check year
		return false;
	else
	if (!checkrange(sYear, 0, 9999)) //check year
		return false;
	else
	if (!checkinteger(sDay)) //check day
		return false;
	else
	if (!checkday(sYear, sMonth, sDay)) // check day
		return false;
	else

		// check date not above current date
		// var vCompareDate = new Date(sYear, sMonth-1, sDay);
		// var vToday = new Date();
		
		// if (vCompareDate > vToday)
		//	{
		//		return false;
		//	}
		// else
		//	{
				return sDay + '/' + returnTextMonth(sMonth) + '/' + sYear;
		//	}
}

function convertMonth(sMonth){
	switch ((sMonth).toUpperCase()){
		case "JAN":
			sMonth = "1";
			break;
		case "FEB":
			sMonth = "2";
			break;
		case "MAR":
			sMonth = "3";
			break;
		case "APR":
			sMonth = "4";
			break;
		case "MAY":
			sMonth = "5";
			break;
		case "JUN":
			sMonth = "6";
			break;
		case "JUL":
			sMonth = "7";
			break;
		case "AUG":
			sMonth = "8";
			break;
		case "SEP":
			sMonth = "9";
			break;
		case "OCT":
			sMonth = "10";
			break;
		case "NOV":
			sMonth = "11";
			break;
		case "DEC":
			sMonth = "12";
			break;
	}
	return sMonth;
}

function returnTextMonth(sMonth){
	switch (sMonth){
		case "1":
			sMonth = "Jan";
			break;
		case "01":
			sMonth = "Jan";
			break;
		case "2":
			sMonth = "Feb";
			break;
		case "02":
			sMonth = "Feb";
			break;
		case "3":
			sMonth = "Mar";
			break;
		case "03":
			sMonth = "Mar";
			break;
		case "4":
			sMonth = "Apr";
			break;
		case "04":
			sMonth = "Apr";
			break;
		case "5":
			sMonth = "May";
			break;
		case "05":
			sMonth = "May";
			break;
		case "6":
			sMonth = "Jun";
			break;
		case "06":
			sMonth = "Jun";
			break;
		case "7":
			sMonth = "Jul";
			break;
		case "07":
			sMonth = "Jul";
			break;
		case "8":
			sMonth = "Aug";
			break;
		case "08":
			sMonth = "Aug";
			break;
		case "9":
			sMonth = "Sep";
			break;
		case "09":
			sMonth = "Sep";
			break;
		case "10":
			sMonth = "Oct";
			break;
		case "11":
			sMonth = "Nov";
			break;
		case "12":
			sMonth = "Dec";
			break;
	}
	return sMonth;
}

function ResetFields(frmName){
//used to reset all the fields if no key is selected.
var num = document.forms(frmName).elements.length;
 for (i=0;i<num;i++){
	var ename = document.forms(frmName).elements[i].name;
	var etype = document.forms(frmName).elements[i].type;
	//validate depending on what data type it is.
		switch(etype){
			case "select-one":	
			//go to the first selected item
				document.forms(frmName).elements(ename).selectedIndex = 0;
				break;
			case "text":
				document.forms(frmName).elements(ename).value = "";
				break;
			case "textarea":
				document.forms(frmName).elements(ename).value = "";
				break;
			case "checkbox":	
				document.forms(frmName).elements(ename).checked = false;
				break;
			default:
				break;
			}
	}
}

function checkTime(element,msg){
	if (element.value != ''){
		if (element.value.length=4)
		{
			if (element.value.indexOf(':')==-1)
			{
			element.value=element.value.substring(0,2)+':'+element.value.substring(2,4)
			}
		}
		element.value
		sHour = element.value.substring(0,element.value.indexOf(':'));
		sMin = element.value.substring(element.value.indexOf(':')+1,element.value.length);
		if (sMin == '')
		{
			sMin = '0';
		}
		if (sHour == '')
		{
			sHour = '0';
		}
		if (element.value.indexOf(':') == -1)
		{
			alert(msg);
			element.focus();
			return true;
		}	
		if (!checkinteger(sHour)) // Check Hours
		{
			alert(msg);
			element.focus();
			return true;
		}
		else
		{
			if (!checkrange(sHour, 0, 23)) // Check Hours
			{
				alert(msg);
				element.focus();
				return true;
			}
		}
		if (!checkinteger(sMin)) // Check Minutes
		{
			alert(msg);
			element.focus();
			return true;
		}
		else
		{
			if (!checkrange(sMin, 0, 59)) // Check Minutes
			{
				alert(msg);
				element.focus();
				return true;
			}
		}
		
		//Check the Length of hour/minute to avoid eg 3:001
		if (sMin.length > 2 || sHour.length > 2) {
			alert(msg);
			element.focus();
			return true;
		}			
		// Format the Time, just to be nice...
		if (sMin < 10 && sMin.length == 1)
		{
			sMin = '0' + sMin;
		}
		if (sHour < 10 && sHour.length == 1)
		{
			sHour = '0' + sHour;
		}
		element.value = sHour + ":" + sMin;
		return false;
	}
}

function convertdate(vdate)
{  
  var isplit;
  var sDay;
  var sMonth;
  var sYear;
  
	isplit = vdate.indexOf('/');

	if (isplit == -1 || isplit == vdate.length)
		return false;

  sDay = vdate.substring(0, isplit);

	if (sDay.length == 0)
		return false;

	isplit = vdate.indexOf('/', isplit + 1);

	if (isplit == -1 || (isplit + 1 ) == vdate.length)
		return false;

	sMonth = vdate.substring((sDay.length + 1), isplit);

	if (sMonth.length == 0)
		return false;

	sYear = vdate.substring(isplit + 1);

	if (sDay.length == 1)
		sDay = '0' + sDay;
	
	sMonth = convertMonth(sMonth);
	
	if (sMonth.length == 1)
		sMonth = '0' + sMonth;

	return sYear + sMonth + sDay;
	
}

function converttime(vtime)
{  
  var isplit;
  var sHour;
  var sMin;
  
	isplit = vtime.indexOf(':');
	
	if (isplit == -1 || isplit == vtime.length)
		return false;

  sHour = vtime.substring(0, isplit);
	
	if (sHour.length == 0)
		return false;

	sMin = vtime.substring(5, 3);
	
	if (sMin.length == 0)
		return false;
	
	return sHour + sMin;
}

function comparedates(date1,time1,sCompare,date2,time2)
{  
  var sDate1;
  var sDate2;
  var sTime1;
  var sTime2;
  var sReturn;
	
	sReturn = false;
	sDate1 = convertdate(date1);
	
	if (sDate1 == false)
		return false;
	
	sDate2 = convertdate(date2);

	if (sDate2 == false)
		return false;
	
	if (time1==''){time1='00:00'};
	if (time2==''){time2='00:00'};
		
	sTime1 = converttime(time1);
	sTime2 = converttime(time2);
		
	switch(sCompare)
	{
		case ">":	
			if ((sDate1 + sTime1) > (sDate2 + sTime2))
				sReturn = true;
				break;
		case "<":
			if ((sDate1 + sTime1) < (sDate2 + sTime2))
				sReturn = true;
				break;
		case ">=":	
			if ((sDate1 + sTime1) >= (sDate2 + sTime2))
				sReturn = true;
				break;
		case "<=":
			if ((sDate1 + sTime1) <= (sDate2 + sTime2))
				sReturn = true;
				break;
		case "=":
			if ((sDate1 + sTime1) == (sDate2 + sTime2))
				sReturn = true;
				break;
	}
	
	return sReturn;
}
function CompareTime(date1,time1,sCompare,theDay,theMonth,theYear,time2)
{  
	
	var sTime1;
	var sTime2;
	var sDate1;
	var sDate2;
	var sReturn;
	
	sReturn=false;	
	switch(theMonth)
	{
		case 0:
			theMonth='Jan';
			break;
		case 1:
			theMonth='Feb';
			break;
		case 2:
			theMonth='Mar';
			break;
		case 3:
			theMonth='Apr';
			break;
		case 4:
			theMonth='May';
			break;
		case 5:
			theMonth='Jun';
			break;
		case 6:
			theMonth='Jul';
			break;
		case 7:
			theMonth='Aug';
			break;
		case 8:
			theMonth='Sep';
			break;
		case 9:
			theMonth='Oct';
			break;
		case 10:
			theMonth='Nov';
			break;
		case 11:
			theMonth='Dec';
			break;
	}
	sDate2 = theDay+'/'+theMonth+'/'+theYear	
	sDate1 = convertdate(date1);
	sDate2 = convertdate(sDate2);
		
	sTime1 = converttime(time1);
	sTime2 = converttime(time2);
		
	switch(sCompare)
	{
		case ">":
			if ((sDate1+sTime1) > (sDate2+sTime2))
				sReturn = true;
				break;
		case "<":
			if ((sDate1+sTime1) < (sDate2+sTime2))
				sReturn = true;
				break;
		case ">=":	
			if ((sDate1+sTime1) >= (sDate2+sTime2))
				sReturn = true;
				break;
		case "<=":
			if ((sDate1+sTime1) <= (sDate2+sTime2))
				sReturn = true;
				break;
		case "=":
			if ((sDate1+sTime1) == (sDate2+sTime2))
				sReturn = true;
				break;
	}
	return sReturn;
}
function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
    alert("Email address seems incorrect (check @ and .'s)")
    return false
}
var user=matchArray[1]
var domain=matchArray[2]
if (user.match(userPat)==null) {
    alert("The username doesn't seem to be valid.")
    return false
}
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
      for (var i=1;i<=4;i++) {
        if (IPArray[i]>255) {
            alert("Destination IP address is invalid!")
        return false
        }
    }
    return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
    alert("The domain name doesn't seem to be valid.")
    return false
}
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}
return true;
}
