
var des_empty=" Destination field is empty";
var enter_station_name="Enter station name";
var time_value="Time value entered in row ";
var is_invalid=" is invalid.";
var p_enter_station_name="Please enter Station name ";
var enter_time="Please enter time for Station ";
var invalid_date="Selected date is invalid.";
var message="Do you want to reset the filled up values?";



  /*************************************************date validation***/

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date");
		return false;
	}
return true;
}

  /************************************************/



function rTrim(strVal)
{	
	nNoOfArguments = rTrim.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return 1;
	}
	
	strVal = new String(strVal);	//convert the string to string object
	
	var nLen = strVal.length;
	var nIndex = 0;
	for (nIndex = nLen-1; nIndex >=0; nIndex--)
	{
		if (strVal.charAt(nIndex) ==  " ")
		{
			nLen--;
		}
		else
		{
			break;
		}
	}
	return strVal.substring(0,nLen)
}
				

function lTrim(strVal)
{
	nNoOfArguments = lTrim.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return 1;
	}
	
	strVal = new String(strVal);	//convert the value to a string object

	var nLen = strVal.length // get the length of string
	var nIndex = 0;
	for (nIndex = 0; nIndex < nLen-1; nIndex++)
	{
		if (strVal.charAt(nIndex) !=  " ")
		{
			break;
		}
	}
	return strVal.substring(nIndex,nLen) 
}



function IsValueExist(strVal)
{
	nNoOfArguments = IsValueExist.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return false;
	}
	
	
	
	strVal = new String(strVal);	//convert the value to a string object
	
	if(strVal.length == 0) 
	{
		return false;
	}
	return true;
}

function IsFirstCharBlank(strVal)
{
	nNoOfArguments = IsFirstCharBlank.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return true;
	}
		
	strVal = new String(strVal);	//convert the value to a string object
	
	if (strVal.charAt(0) == " ") 
	{
		return true;
	}
	return false;
}



function IsStringWithSpaces(strVal)
{
	nNoOfArguments = IsStringWithSpaces.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return false;
	}	
	
	var strInValidChars = ' '; //invalid charaters i.e. space in this case
	
	bReturn = strVal.indexOf(strInValidChars);	//check for invalid characters in string
	
	if(bReturn != -1)//if any invalid character found
	{
		return true;
	}
	return false;
}



function IsIdentical(strVal1, strVal2)
{	
	nNoOfArguments = IsIdentical.arguments.length;
	
	if(nNoOfArguments < 2)
	{
		return false;
	}	

	if(strVal1 == strVal2) //if both string are equal
	{
		return true;
	}	
	return false;	
} 


function IsValidAlphaNumValue(strVal)
{
	nNoOfArguments = IsValidAlphaNumValue.arguments.length;

	if(nNoOfArguments < 1)
	{
		return false;
	}
		
	var sValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	strVal = new String(strVal);	//convert the value to a string object
	
	var bReturn = true	
	var i = new Number(0);
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn);	
}


function IsValidAlphabetValue(strVal)
{
	nNoOfArguments = IsValidAlphabetValue.arguments.length;

	if(nNoOfArguments < 1)
	{
		return false;
	}	

	var sValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	strVal = new String(strVal);	//convert the value to a string object
	
	var bReturn = true
	var i = new Number(0);
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)
}


function IsValidNumericValue(strVal)
{
	nNoOfArguments = IsValidNumericValue.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return false;
	}	
	
	var sValidChars = "0123456789";
	
	strVal = new String(strVal);	//convert the value to a string object
	
	var bReturn = true
	var i = new Number(0);
	
	if(0 == parseInt(strVal,10))
	return true;
	
//	if(0 == strVal.charAt(0))
//	return false;
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn);
}


function IsValidFloatValue(strVal)
{
	nNoOfArguments = IsValidFloatValue.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return false;
	}
	if(!IsValueExist(strVal))	
	{
		return false;
	}	
	var sValidChars = "0123456789.";
	
	strVal = new String(strVal);	//convert the value to a string object
	
	var bReturn = true;	
	var i = new Number(0);
	
	if(strVal.indexOf(".") != strVal.lastIndexOf("."))
	return false;
	
	
	if(('0' == strVal.charAt(0)))
	{
		if (!('.' == strVal.charAt(1)))
		{
			return false;
		}
	}	
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++;
    }
	return (bReturn)
}


function IsValidFloatValueWithZero(strVal)
{
	nNoOfArguments = IsValidFloatValueWithZero.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return false;
	}
		
	var sValidChars = "0123456789.";
	
	strVal = new String(strVal);	//convert the value to a string object
	
	var bReturn = true;	
	var i = new Number(0);
	
	if(strVal.indexOf(".") != strVal.lastIndexOf("."))
	return false;
	
	
	if(strVal.length == 0)
	return false;	
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++;
    }
	return (bReturn);
}


function IsValidPhoneFaxNumber(strVal,IsSpecialChar,nMinlen)
{
	
	if(strVal.length < parseInt(nMinlen))
		{
			return false;
		}


	nNoOfArguments = IsValidPhoneFaxNumber.arguments.length;
	if(nNoOfArguments < 1)
	{
		return false;
	}		
	
	if((nNoOfArguments == 1) && (nNoOfArguments < 2))
	{
		IsSpecialChar = 't';
	}
	
	if('f' == IsSpecialChar)
	{
		var sValidChars = "0123456789";
	}
	
	if('t' == IsSpecialChar)
	{
		var sValidChars = "0123456789+-";
	}	
	
	
	var bReturn = true;	
	var i = new Number(0);
	
	strVal = new String(strVal);
	
	if(strVal.indexOf("+") != strVal.lastIndexOf("+"))//if more than one + exist in value
	return false;
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)
}

function IsValidNameValue(strVal)
{
	nNoOfArguments = IsValidNameValue.arguments.length;
	//if no parameter is supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}
		
	//valid character a supplied string can have
	var sValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. ";
	
	var strVal = new String(strVal);
	var bReturn = true
	var i = new Number(0);
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)
}


function IsValidEMail(strValue)
{
	nNoOfArguments = IsValidEMail.arguments.length;
	//if no parameter is supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}	
	
	var strVal	= new String(strValue);
	var bReturn1 = false;
	var bReturn2 = false;
	var bReturn3 = false;
	var bReturn4 = false;
	var bReturn5 = false;
	var bReturn5 = false;
	
	//if '@' comes after first character then true
	bReturn1	=	(strValue.indexOf("@") > 0);							
	
	//if '.' comes after first character then true
	bReturn2	=	(strValue.indexOf(".") > 0);							
	
	//if single '@' exist in string then true
	bReturn3	=	(strValue.indexOf("@") == strValue.lastIndexOf("@"));	
	
	//if '.' exist after @ in string then true
	bReturn4	=	(strValue.indexOf(".",strValue.indexOf("@")) > (strValue.indexOf("@")));		
	
	//if '.' does not comes immediatly after @ then true
	bReturn5	=	(strValue.indexOf(".",strValue.indexOf("@")) != (strValue.indexOf("@")+1));		
	
	//if '.' does not comes immediatly before @ then true
	bReturn6	=	(strValue.lastIndexOf(".",strValue.indexOf("@")) != (strValue.indexOf("@")-1)); 
	
	//if all values are true return true else false.
	return(bReturn1 && bReturn2 && bReturn3 && bReturn4 && bReturn5 && bReturn6);
}

function IsDateValid1(nMonth, nDay, nYear)
{
/*
if(nDay == "08")	   nDay	=8;
if(nDay == "09")	    nDay	=9;
if(nMonth == "08") 	nMonth=8;
if(nMonth == "09") 	nMonth=9;
*/
nYear=parseInt(nYear);
nMonth=parseInt(nMonth,10);
nDay=parseInt(nDay,10);

	nNoOfArguments = IsDateValid.arguments.length;
	
	//if any of the three parameter is not supplied
	if(nNoOfArguments < 3)
	{
		return false;
	}	

	//if month value is not correct i.e. not between 0-11
	if ((nMonth > 12) || (nMonth < 1))
	{
		return false;
	}
	
	//if day value is not correct i.e. not between 1-31
	if ((nDay > 31) || (nDay < 1))
	{
			return false;
	}
	
	
	switch (nMonth)
	{				
		case 1:
		case 3:
		case 5:
		
		case 7:
		case 8:
		case 10:
		case 12:			
			return (true);
			break;
						
		case 4:
		case 6:
		case 9:
		case 11:
			if (nDay > 30)
			{
				return (false);
			}
			return (true);
			break;
						
		case 2 :
			if (nDay <= 28)
			{
				return true;
			}
			if (nDay > 29)
			{
				return false;
			}
			if (nYear % 4 != 0)
			{
				return false;
			}
			else
			{
				if (nYear%100 == 0)
				{
					if (nYear % 400 == 0)
					{
						return true;
					}
					else
					{
						return false;
					}
				}
				else
				{
					return true;
				}
			}
			break;
	}
}








function IsWithinDateValid(nDayWithin, nMonth, nDay, nYear, nHr, nMin, nSec)
{
	nNoOfArguments = IsWithinDateValid.arguments.length;
	
	//if compulsory parameters are not supplied
	if(nNoOfArguments < 4)
	{
		return false;
	}
	
	//if any of optional parameter is supplied
	if(nHr || nMin || nSec)
	{
		//if not all the optional parameters are not supplied
		if(nNoOfArguments < 7)
		{
			return false;
		}
	}	
		
	//create Date objects which contain todays date by default
	dtToday		= new Date();	
	dtValid		= new Date();	
	dtSupplied	= new Date();
	
	nDayCurr	= dtToday.getDate();
	nMonthCurr	= dtToday.getMonth();
	nYearCurr	= dtToday.getFullYear();
	
	//add nDayWithin value to todays' day value
	nValidDay	= nDayCurr + (nDayWithin); 
	nValidMonth	= nMonthCurr;
	nValidYear	= nYearCurr;
	
	//date till which supplied date can be valid
	dtValid.setFullYear(nValidYear,nValidMonth,nValidDay)
	
	nDayWithin	= new Number(nDayWithin);
	nMonth		= new Number(nMonth);
	nDay		= new Number(nDay);
	nYear		= new Number(nYear);
	
	
	//if all sub fields of time i.e. nHr, nMin, nSec are supplied
	if(nNoOfArguments == 7)
	{
		nHr			= new Number(nHr);
		nMin		= new Number(nMin);
		nSec		= new Number(nSec);

		//date supplied to function is
		dtSupplied = new Date(nYear,nMonth,nDay,nHr,nMin,nSec)		
	}	
	else
	{
		//date supplied to function is
		dtSupplied.setFullYear(nYear,nMonth,nDay)
	}
	
	//if nDayWithin is less then 0 i.e. valid date is past date
	if(nDayWithin < 0)
	{
		dtDiff	= dtSupplied - dtValid;
		
		//if supplied date is greater then or equal to valid date and less then or equal to todays date 
		if((dtDiff >= 0) && (dtSupplied <= dtToday))
		{
			return true;
		}
		return false;
	}
	
	//if nDayWithin is equal to 0 i.e. valid date is todays date only
	if(nDayWithin == 0)
	{
		if((nDayCurr == nDay) && (nMonthCurr == nMonth) && (nYearCurr == dtSupplied.getFullYear()))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	//if nDayWithin is greater than 0 i.e. valid date is future date
	if(nDayWithin > 0)
	{
		dtDiff = dtSupplied - dtValid;
		
		//if supplied date is less then or equal to valid date and greater then equal to todays' date
		if((dtDiff <= 0) && (dtSupplied >= dtToday))
		{
			return true;
		}
		return false;
		
	}	
	return false;
}


function IsFutureDateValid(nMonth, nDay, nYear, nHr, nMin, nSec)
{
	nNoOfArguments = IsFutureDateValid.arguments.length;
	
	
	//if any of the three parameter is not supplied
	if(nNoOfArguments < 3)
	{
		return false;
	}	
	

	
	//if any of optional parameter is supplied
	if(nHr || nMin || nSec)
	{
		//if not all the optional parameters are not supplied
		if(nNoOfArguments < 6)
		{
			return false;
		}
	}
	
	//create Date objects which contain todays date by default
	dtToday		= new Date();	
	dtSupplied	= new Date();
		
	nMonth		= new Number(nMonth);
	nDay		= new Number(nDay);
	nYear		= new Number(nYear);
	
	//if all sub fields of time i.e. nHr, nMin, nSec are supplied
	if( nNoOfArguments == 6)
	{
		nHr			= new Number(nHr);
		nMin		= new Number(nMin);
		nSec		= new Number(nSec);
		
		//date supplied to function is
		dtSupplied = new Date(nYear,nMonth,nDay,nHr,nMin,nSec)		
	}	
	else
	{
		//date supplied to function is
		dtSupplied.setFullYear(nYear,nMonth,nDay)
	}
	
	
	//if supplied date is greater then or equal to todays' date
	if(dtSupplied >= dtToday)
	{
		return true;
	}
	return false;
}
function IsPastDateValid(nMonth, nDay, nYear, nHr, nMin, nSec)
{
	nNoOfArguments = IsPastDateValid.arguments.length;
	
	
	//if any of the three parameter is not supplied
	if(nNoOfArguments < 3)
	{
		return false;
	}	
	

	
	//if any of optional parameter is supplied
	if(nHr || nMin || nSec)
	{
		//if not all the optional parameters are not supplied
		if(nNoOfArguments < 6)
		{
			return false;
		}
	}	
	
	//create Date objects which contain todays date by default
	dtToday		= new Date();	
	dtSupplied	= new Date();
		
	nMonth		= new Number(nMonth);
	nDay		= new Number(nDay);
	nYear		= new Number(nYear);
	//if all sub fields of time i.e. nHr, nMin, nSec are supplied
	if( nNoOfArguments == 6)
	{
		nHr			= new Number(nHr);
		nMin		= new Number(nMin);
		nSec		= new Number(nSec);
		
		//date supplied to function is
		dtSupplied = new Date(nYear,nMonth,nDay,nHr,nMin,nSec)		
	}	
	else
	{
		//date supplied to function is
		dtSupplied.setFullYear(nYear,nMonth,nDay)
	}
		
	//if supplied date is less then or equal to todays' date
	if(dtSupplied <= dtToday)
	{
		return true;
	}
	return false;
}
 
function seprateDateString(strVal,chParam,nFormat)
{
	nNoOfArguments = seprateDateString.arguments.length;
	
	if(nNoOfArguments < 2)
	{
		return false;
	}	
	
	//if no format is supplied initialized it with default value 
	if(!nFormat)
	{
		nFormat = 1;
	}	
	
	//if not a valid character supplied to chParam return error
	if(!((chParam == 'd') || (chParam == 'm') || (chParam == 'y')))
	{
		return (1);
	} 
	
	subStr	= null;	
	strDt	= new String(strVal);
	nFormat	= new Number(nFormat);
	
	//if invalid format is supplied return false
	if((nFormat <= 0) || (nFormat > 4))
	{
		return (-1); 
	}
	//check which seperator is used in the date string
	if(strDt.indexOf("/",0) > -1)
	{
		subStr = '/';
	}
	else 
	if(strDt.indexOf(":",0) > -1)
	{
		subStr = ':';
	}
	else 
	if(strDt.indexOf("-",0) > -1)
	{
		subStr = '-';
	}
	
	if(subStr != null)
	{
		if(1 == nFormat)	//if default format i.e. mm/dd/yyyy
		{
			//if chParam is 'm' return month portion from date string
			if(chParam == 'm')
			{
				
				return(strDt.slice(0,strDt.indexOf(subStr)));
			}
		
			//if chParam is 'd' return day portion from date string
			if(chParam == 'd')
			{
				return(strDt.slice(strDt.indexOf(subStr)+1,strDt.lastIndexOf(subStr)));
			}
		
			//if chParam is 'y' return year portion from date string
			if(chParam == 'y')
			{
				return(strDt.slice(strDt.lastIndexOf(subStr)+1,strDt.length));
			}	
		}
		if(2 == nFormat)	//if nFormat is 2 i.e. dd/mm/yyyy
		{
			//if chParam is 'd return date portion from date string
			if(chParam == 'd')
			{
				return(strDt.slice(0,strDt.indexOf(subStr)));
			}
		
			//if chParam is 'm' return month portion from date string
			if(chParam == 'm')
			{
				return(strDt.slice(strDt.indexOf(subStr)+1,strDt.lastIndexOf(subStr)));
			}
		
			//if chParam is 'y' return year portion from date string
			if(chParam == 'y')
			{
				return(strDt.slice(strDt.lastIndexOf(subStr)+1,strDt.length));
			}
		}	
		if(3 == nFormat)	//if nFormat is 3 i.e. yyyy/dd/mm
		{
			//if chParam is 'y' return year portion from date string
			if(chParam == 'y')
			{
				return(strDt.slice(0,strDt.indexOf(subStr)));
			}
		
			//if chParam is 'd' return day portion from date string
			if(chParam == 'd')
			{
				return(strDt.slice(strDt.indexOf(subStr)+1,strDt.lastIndexOf(subStr)));
			}
		
			//if chParam is 'm' return mont portion from date string
			if(chParam == 'm')
			{
				return(strDt.slice(strDt.lastIndexOf(subStr)+1,strDt.length));
			}	
		}
		if(4 == nFormat)	//if nFormat is 4 i.e. yyyy/mm/dd
		{
			//if chParam is 'y' return year portion from date string
			if(chParam == 'y')
			{
				return(strDt.slice(0,strDt.indexOf(subStr)));
			}
		
			//if chParam is 'm' return month portion from date string
			if(chParam == 'm')
			{
				return(strDt.slice(strDt.indexOf(subStr)+1,strDt.lastIndexOf(subStr)));
			}
		
			//if chParam is 'd' return day portion from date string
			if(chParam == 'd')
			{
				return(strDt.slice(strDt.lastIndexOf(subStr)+1,strDt.length));
			}
		}
		
	}	
	else
	return (-1)		
}


function IsTimeValid(nHr,nMin,nSec)
{
	nNoOfArguments = IsTimeValid.arguments.length;
	
	//if if any of the parameter is not supplied
	if(nNoOfArguments < 3)
	{
		return false;
	}
	
	nHr		= new Number(nHr);
	nMin	= new Number(nMin);
	nSec	= new Number(nSec);
	
	if(isNaN(nHr))
	{
		return false;
	}
	
	if(isNaN(nMin))
	{
		return false;
	}

	if(isNaN(nSec))
	{
		return false;
	}

	//if hour is invalid i.e. out of 0-23 range
	if ((nHr > 23) || (nHr < 0))
	{
		return false;
	}
	
	//if minute is invalid i.e. out of 0-59 range
	if ((nMin > 59) || (nMin < 0))
	{
		return false;
	}
	
	//if second is invalid i.e. out of 0-59 range
	if ((nSec > 59) || (nSec < 0))
	{
		return false;
	}
	return true;

}

function seprateTimeString(strVal,chParam)
{	
	nNoOfArguments = seprateTimeString.arguments.length;
	
	//if if any of the parameter is not supplied
	if(nNoOfArguments < 2)
	{
		return false;
	}	
	
	//if not a valid chParam character is supplied
	if(!((chParam == 'h') || (chParam == 'm') || (chParam == 's')))
	{
		return (-1);
	} 

	subStr = null;	
	strTm = new String(strVal)
	
	//check which seperator is used in time string
	if(strTm.indexOf("/",0) > -1)
	{
		subStr = '/';
	}
	else 
	if(strTm.indexOf(":",0) > -1)
	{
		subStr = ':';
	}
	else 
	if(strTm.indexOf("-",0) > -1)
	{
		subStr = '-';
	}
	
	if(subStr != null)
	{
		//if chParam is 'h' return hour portion from time string
		if(chParam == 'h')
		{
			return(strTm.slice(0,strTm.indexOf(subStr)));
		}
		
		//if chParam is 'm' return minute portion from time string
		if(chParam == 'm')
		{
			return(strTm.slice(strTm.indexOf(subStr)+1,strTm.lastIndexOf(subStr)));
		}
		
		//if chParam is 's' return second portion from time string
		if(chParam == 's')
		{
			return(strTm.slice(strTm.lastIndexOf(subStr)+1,strTm.length));
		}	
	}	
	else
	return (-1)		
}

function getSubstring(strVal,chParam)
{	
	nNoOfArguments = getSubstring.arguments.length;
	
	//if if any of the parameter is not supplied
	if(nNoOfArguments < 2)
	{
		return false;
	}		

	subStr = ' ';	
	
	strVal = lTrim(rTrim(strVal)); //trim spaces from left and right of the string
	
	chParam			= new String(chParam);
	strMainString	= new String(strVal);	
	
	//get the position of space in the supplied string as string should be seperated by space
	nPos = strMainString.indexOf(subStr,0) 
		
	//if chParam is '1' return first substring from string
	if(chParam == '1')
	{
		return(strMainString.slice(0,strMainString.indexOf(subStr)));
	}
		
	//if chParam is '2' return second substring from string
	if(chParam == '2')
	{
		return(strMainString.slice(strMainString.lastIndexOf(subStr)+1,strMainString.length));
	}			
	return (-1)
}

function checkUsername(strValue,nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if string value supplied is empty or contains nothing
	if(!IsValueExist(strValue))
	{
		return (1);
	}

	//if the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}
	
	//if string value supplied contain spaces
	if(IsStringWithSpaces(strValue))
	{
		return (3);
	}
	
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) <= 0)
		{		
			return (6);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{	
			return (4);
		}		
		
	}	
	
	//if nMaxlen value supplied then
	if(nMaxlen)
	{
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (6);	
		} 
		//if valid length supplied but string length is greater then nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{		
			return (5);
		}
	}	
	return (0);
}

function checkPassword(strValue, nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//If string value supplied is empty or contains nothing
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
	//If the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}	
	
	//if string value supplied contain spaces
	if(IsStringWithSpaces(strValue))
	{	
		return (3);
	}
		
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) <= 0)
		{		
			return (6);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{
			return (4);
		}		
		
	}
	
	//if nMaxlen value supplied then	
	if(nMaxlen)
	{ 
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (6);	
		}
		//if valid length supplied but string length is greater then nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{
			return (5);
		}
	}
	return (0);
}
function IsIdenticalPassword(strVal1, strVal2)
{	
	//if the two string value supplied are not identical or either of the value is not supplied
	if(!IsIdentical(strVal1,strVal2))
	{	
		return (false);
	}
	return (true);	
} 

function checkPositionCodeField(strValue,nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if String value supplied is empty or contains nothing	
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
	//if the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}
		
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{
			return (3);
		}		
		
	}
	
	//if nMaxlen value supplied then	
	if(nMaxlen)
	{ 
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (6);	
		}
		//if valid length supplied but string length is greater than nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{
			return (5);
		}
	}
	return (0);
}

function checkNameField(strValue,nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if String value supplied is empty or contains nothing	
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
	//if the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}
	
	//if the string value supplied is not a valid Name i.e. it should be of pure alphabets etc.
	if(!IsValidNameValue(strValue))
	{
		return (3);
	}	
	
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) < 0)
		{		
			return (6);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{
			return (4);
		}		
		
	}
	
	//if nMaxlen value supplied then	
	if(nMaxlen)
	{ 
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (6);	
		}
		//if valid length supplied but string length is greater than nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{
			return (5);
		}
	}
	return (0);
}
function checkFieldString(strValue)
{		
	if(!strValue)
	{
		return(1);
	}
//if string value supplied is empty or contains nothing
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
return(0);
}

function checkNumericField(strValue,nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if strValue supplied is empty or contains nothing	
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
		
	//if strValue supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValue))
	{
		return (2);
	}	
	
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{
			return (3);
		}		
		
	}
	
	//if nMaxlen value supplied then	
	if(nMaxlen)
	{ 
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) < 0)
		{	
			return (5);	
		}
		//if valid length supplied but string length is greater then nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{
			return (4);
		}
	}
	return (0);
}

function checkStringField(strValue,nMaxlen,nMinlen)
{

	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if string value supplied is empty or contains nothing
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
	//if the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}			
		
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but the string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{
			return (3);
		}		
		
	}
	
	//if nMaxlen value supplied then	
	if(nMaxlen)
	{ 
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (5);	
		}
		//if valid length supplied but the string length is greater then nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{
			return (4);
		}
	}
	return (0);
}

function checkEmail(strValue,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if email value supplied is emtpy or contains nothing	
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
	//if email value supplied contain spaces
	if(IsStringWithSpaces(strValue))
	{
		return (2);
	}	
	
	//if not a valid email value supplied	
	if(!IsValidEMail(strValue))
	{
		return (3)
	}
	return (0);
}

function checkPhoneFaxNumber(strVal1,strVal2,strVal3,nLen1,nLen2,nLen3)
{

	//if nLen1 is equal to 0 and values i.e. strVal1, strVal2, strVal3 is not supplied return success code
	//else return error code
	if (0 == nLen1)
	{
		//check compulsory fields
		if(!(strVal1 && strVal2 && strVal3))
		{
			return(0);
		}
	}
	else
	{
		//check compulsory fields
		if(!(strVal1 && strVal2 && strVal3))
		{
			return(1);
		}
	}
	
	//check optional parameters
	if((nLen1 || nLen2 || nLen3))
	{
		if(!(nLen1 && nLen2 && nLen3))
		{
			return (6);
		}
	}
	
	//if any of the field value is not supplied or left blank
	if(!(IsValueExist(strVal1) && IsValueExist(strVal2) && IsValueExist(strVal3)))
	{	
		return (1);
	}
	
	//check if any of the value is not a valid numeric number
	if(!(IsValidPhoneFaxNumber(strVal1,'f') && IsValidPhoneFaxNumber(strVal2,'f') && IsValidPhoneFaxNumber(strVal3,'f')))
	{
		return (2);
	}

	//if nLen1 value supplied then
	if(nLen1)
	{
		//if invalid length supplied
		if(isNaN(nLen1) || parseInt(nLen1) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of the value is less then nLen1
		if(strVal1.length < parseInt(nLen1))	
		{
			return (4);
		}				
	}
	
	//if nLen2 value supplied then
	if(nLen2)
	{
		//if invalid length supplied
		if(isNaN(nLen2) || parseInt(nLen2) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of the value is less then nLen2
		if(strVal2.length < parseInt(nLen2))	
		{
			return (4);
		}				
	}
	
	//if nLen3 value supplied then
	if(nLen3)
	{
		//if invalid length supplied
		if(isNaN(nLen3) || parseInt(nLen3) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of the value is less then nLen3 
		if(strVal3.length < parseInt(nLen3))	
		{
			return (4);
		}				
	}
	return (0);
}

function checkPhoneFaxString(strVal,nMinLen,nMaxLen)
{
	//if nMinLen is equal to 0 and value i.e. strVal is not supplied return success code
	//else return error code
	if (0 == nMinLen)
	{
		if(!strVal)
		{
			return(0);
		}
	}
	else
	{
		if(!strVal)
		{
			return(1);
		}
	}
	
	//if Phone or Fax number supplied is empty or contain nothing	
	if(!IsValueExist(strVal))
	{	
		return (1);
	}

	//check if not a valid phone or fax number
	if(!IsValidPhoneFaxNumber(strVal))
	{
		return (2);
	}
	
	//if nMinLen value supplied then
	if(nMinLen)
	{
		//if invalid length supplied
		if(isNaN(nMinLen) || parseInt(nMinLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of the supplied value is less then nMinLen
		if(strVal.length < parseInt(nMinLen))	
		{
			return (4);
		}				
	}
	//if nMaxLen value supplied then
	if(nMaxLen)
	{
		//if invalid length supplied
		if(isNaN(nMaxLen) || parseInt(nMaxLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of the supplied value is greater then nMaxLen
		if(strVal.length > parseInt(nMaxLen))	
		{
			return (4);
		}				
	}
	
	return (0);
}


function checkValidNumZipCode(strVal, nMinLen,nMaxLen)
{	

	//if nMinLen is equal to 0 and value i.e. strVal is not supplied return success code
	//else return error code
	if (0 == nMinLen)
	{
		if(!strVal)
		{
			return(0);
		}
	}
	else
	{
		if(!strVal)
		{
			return(1);
		}
	}

	//if zip value supplied is empty or contains nothing		
	if(!IsValueExist(strVal))
	{	
		return (1);
	}
	
	//if not a valid numeric value
	if(!IsValidNumericValue(strVal))
	{	
		return (0);
	}
	
	//if zip code value contain spaces
	if(IsStringWithSpaces(strVal))
	{
		return (3);
	}
	
	//if nMinLen value supplied then
	if(nMinLen)
	{
		//if invalid length supplied
		if(isNaN(nMinLen) || parseInt(nMinLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of zip code value is less then nMinLen
		if(strVal.length < parseInt(nMinLen))	
		{
			return (4);
		}				
	}
	//if nMaxLen value supplied then
	if(nMaxLen)
	{
		//if invalid length supplied
		if(isNaN(nMaxLen) || parseInt(nMaxLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of zip code value is greater then nMaxLen
		if(strVal.length > parseInt(nMaxLen))	
		{
			return (4);
		}				
	}


	return (0);	
} 


function checkValidAlphNumZipCode(strVal, nMinLen,nMaxLen)
{	
	//if nMinLen is equal to 0 and value i.e. strVal is not supplied return success code
	//else return error code
	if (0 == nMinLen)
	{
		if(!strVal)
		{
			return(0);
		}
	}
	else
	{
		if(!strVal)
		{
			return(1);
		}
	}
	
	//if string value supplied is empty or contains nothing
	if(!IsValueExist(strVal))
	{	
		return (1);
	}
	
	//if zip code value is not a valid alpha numeric zip code
	if(!IsValidAlphNumValue(strVal))
	{	
		return (2);
	}
	
	//if zip code value contain spaces
	if(IsStringWithSpaces(strVal))
	{
		return (3);
	}
	
	//if nMinLen value supplied then
	if(nLen)
	{
		//if invalid length supplied
		if(isNaN(nMinLen) || parseInt(nMinLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of zip code value is less then nMinLen
		if(strVal.length < parseInt(nMinLen))	
		{
			return (4);
		}				
	}
	//if nMaxLen value supplied then
	if(nMaxLen)
	{
		//if invalid length supplied
		if(isNaN(nMaxLen) || parseInt(nMaxLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of zip code value is less then nMaxLen
		if(strVal.length > parseInt(nMaxLen))	
		{
			return (4);
		}				
	}
	
	return (0);	
} 

function checkDate(nFormat,strVal1, strVal2, strVal3)
{	
	strValm = 0;
	strVald = 0;
	strValy = 0;
	
	nFormat = new Number(nFormat);
	//if compulsory parameter is not supplied
	if(!((strVal1) && (nFormat)))
	{
		return (1);
	}
	
	//if value in first parameter supplied is blank or empty 
	if(!IsValueExist(strVal1))
	{
		return (1);
	}
		
	
	//if only first parameter is supplied
	if(!((strVal1) && (strVal2) && (strVal3)))
	{
		strVal1 = new String(strVal1);
				
		if(!(strValm = seprateDateString(strVal1,'m',nFormat))) //get month portion from date string i.e. from strVal1
		{
			return (2);
		}
	
		if(!(strVald = seprateDateString(strVal1,'d',nFormat))) //get day portion from date string i.e. from strVal1
		{
			return (2);
		}
	
		if(!(strValy = seprateDateString(strVal1,'y',nFormat))) //get year portion from date string i.e. from strVal1
		{
			return (2);
		}
	}	
	else
	{		
		//if all three parameters are supplied
		if((strVal1) && (strVal2) && (strVal3))
		{
			strValm = strVal1;
			strVald = strVal2;
			strValy = strVal3;
		}
		else
		{
			return (3);	
		}	
	}
	
	strValm = new String(strValm);
	strVald = new String(strVald);
	strValy = new String(strValy);
	
	if (0 == strValm.charAt(0)) 
	{
		strValm = strValm.slice(1,strValm.length);
	}
		
	if (0 == strVald.charAt(0)) 
	{
		strVald = strVald.slice(1,strVald.length);
	}
		
	if (0 == strValy.charAt(0)) 
	{
		strValy = strValy.slice(1,strValy.length);
	}
		
	//if strValm supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValm))
	{
		return (2);
	}
		
	//if strVald supplied is not a valid numeric value	
	if(!IsValidNumericValue(strVald))
	{
		return (2);
	}
		
	//if strValy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValy))
	{
		return (2);
	}
	
	//as the month starts from 0
	strValm = strValm - 1;
	
	//if the date value supplied is not valid
	if(!IsDateValid(parseInt(strValm,10),parseInt(strVald,10),parseInt(strValy,10)))
	{
		return (2);
	}
	
	return (0);
}


function checkWithinDate(nFormat,nDayWithin,strVal1,strVal2,strVal3)
{
		
	//if nFormat,nDayWithin and strVal1 i.e. date format,time-gap and date string are 
	//not supplied return error code
	if(!((nDayWithin) && (strVal1) && (nFormat)))
	{
		return (1);
	}
	
	//if date string value is blank or left empty
	if(!IsValueExist(strVal1))
	{	
		return (1);
	}
	
	//if nFormat supplied is not a valid numeric value	
	if(!IsValidNumericValue(nFormat))
	{
		return (2);
	}
	
	//if nDayWithin supplied is not a valid numeric value	
	if(isNaN(nDayWithin))
	{
		return (2);
	}
	
	nFormat		= new Number(nFormat);
	nDayWithin	= new Number(nDayWithin);
	
	//if date string is supplied as single string
	if(!((strVal1) && (strVal2) && (strVal3)))
	{
		strVal1 = new String(strVal1);		
		
		if(!(strValm = seprateDateString(strVal1,'m',nFormat))) //get month portion from date string
		{
			return (2);
		}
	
		if(!(strVald = seprateDateString(strVal1,'d',nFormat))) //get day portion from date string
		{
			return (2);
		}
	
		if(!(strValy = seprateDateString(strVal1,'y',nFormat))) //get year portion from date string
		{
			return (2);
		}
	
		
	}	
	else
	{
		//if all fields of date are supplied seperately
		if(strVal1 && strVal2 && strVal3)
		{
			strValm = strVal1;
			strVald = strVal2;
			strValy = strVal3;
		}
		else
		{
			return (4);
		}	
	}

	strValm = new String(strValm);
	strVald = new String(strVald);
	strValy = new String(strValy);
	
	if (0 == strValm.charAt(0)) 
	{
		strValm = strValm.slice(1,strValm.length);
	}
		
	if (0 == strVald.charAt(0)) 
	{
		strVald = strVald.slice(1,strVald.length);
	}
		
	if (0 == strValy.charAt(0)) 
	{
		strValy = strValy.slice(1,strValy.length);
	}
		
	
	//if strValm supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValm))
	{
		return (2);
	}
		
	//if strVald supplied is not a valid numeric value	
	if(!IsValidNumericValue(strVald))
	{
		return (2);
	}
		
	//if strValy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValy))
	{
		return (2);
	}
	
	strValm = strValm - 1 //as month always starts from 0
	
	//if date string value is not a valid date
	if(!(IsDateValid(parseInt(strValm,10),parseInt(strVald,10),parseInt(strValy,10))))
	{
		return (2)
	}
	
	//if date is not within specified time period from today
	if(!IsWithinDateValid(parseInt(nDayWithin),parseInt(strValm),parseInt(strVald),parseInt(strValy)))
	{
		return (3)
	}		
	return (0);
}
function checkFuturePastDate(nFormat,chFuturePast,strVal1,strVal2,strVal3)
{
	//if nFormat,chFuturePast and strVal1 i.e. date formt,time-gap and date string are 
	//not supplied return error code
	if(!((nFormat) && (chFuturePast) && (strVal1)))
	{
		return (1);
	}
	
	//if date string value is blank or left empty
	if(!IsValueExist(strVal1))
	{	
		return (1);
	}
	
	//if nFormat supplied is not a valid numeric value	
	if(!IsValidNumericValue(nFormat))
	{
		return (2);
	}
	
	//if chFuturePast supplied is not a valid character value	
	if(!(('f' == chFuturePast) || ('p' == chFuturePast)))
	{
		return (2);
	}
	
	nFormat		= new Number(nFormat);
	
	//if date string is supplied as single string
	if(!((strVal1) && (strVal2) && (strVal3)))
	{
		strVal1 = new String(strVal1);		
		
		if(!(strValm = seprateDateString(strVal1,'m',nFormat))) //get month portion from date string
		{
			return (2);
		}
	
		if(!(strVald = seprateDateString(strVal1,'d',nFormat))) //get day portion from date string
		{
			return (2);
		}
	
		if(!(strValy = seprateDateString(strVal1,'y',nFormat))) //get year portion from date string
		{
			return (2);
		}
	}	
	else
	{
		//if all fields of date are supplied seperately
		if(strVal1 && strVal2 && strVal3)
		{
			strValm = strVal1;
			strVald = strVal2;
			strValy = strVal3;
		}
		else
		{
			return (4);
		}	
	}

	strValm = new String(strValm);
	strVald = new String(strVald);
	strValy = new String(strValy);
	
	if (0 == strValm.charAt(0)) 
	{
		strValm = strValm.slice(1,strValm.length);
	}
		
	if (0 == strVald.charAt(0)) 
	{
		strVald = strVald.slice(1,strVald.length);
	}
		
	if (0 == strValy.charAt(0)) 
	{
		strValy = strValy.slice(1,strValy.length);
	}
	
	//if strValm supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValm))
	{
		return (2);
	}
		
	//if strVald supplied is not a valid numeric value	
	if(!IsValidNumericValue(strVald))
	{
		return (2);
	}
		
	//if strValy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValy))
	{
		return (2);
	}

	strValm = strValm - 1 //as month always starts from 0
	
	//if date string value is not a valid date
	if(!IsDateValid(parseInt(strValm,10),parseInt(strVald,10),parseInt(strValy,10)))
	{
		return (2);
	}
	
	//if chFuturePast == 'p' check if it is valid past date
	if('p' == chFuturePast)
	{ 
		if(!IsPastDateValid(parseInt(strValm),parseInt(strVald),parseInt(strValy)))
		{
			return (3);
		}
		else
		return (0);		
	}
	//if chFuturePast == 'f' check if it is valid future date
	if('f' == chFuturePast)
	{ 
		if(!IsFutureDateValid(parseInt(strValm),parseInt(strVald),parseInt(strValy)))
		{
			return (3);
		}
		else
		return (0);		
	}
	return (0);
}

function checkTime(strVal1, strVal2, strVal3)
{	
	//if strval1 i.e. first parameter is not supplied return error code
	if(!strVal1)
	{
		return (1);
	}
	
	//if first parameter is blank or contain nothing
	if(!IsValueExist(strVal1))
	{
		return (1);
	}
	
	//if only first substring is supplied i.e. time is supplied as single string
	if(!((strVal1) && (strVal2) && (strVal3)))
	{
		if(!(strValh = seprateTimeString(strVal1,'h'))) //get hour portion from time string
		{
			return (2);
		}
	
		if(!(strValm = seprateTimeString(strVal1,'m'))) //get minute portion from time string
		{
			return (2);
		}
	
		if(!(strVals = seprateTimeString(strVal1,'s'))) //get second portion from time string
		{
			return (2);
		}
	}	
	else
	{
		//if all substrings are supplied i.e. all sub-part of time are supplied
		if(strVal1 && strVal2 && strVal3)
		{
			strValh = strVal1;
			strValm = strVal2;
			strVals = strVal3;
		}
		else
		{
			return (3);
		}	
	}
	
	//if value supplied is not a valid time
	if(!IsTimeValid(strValh,strValm,strVals))
	{
		return (2);
	}
	
	return (0);
}

function checkDateTime(strVal,nFormat)
{	
	//initialize variables
	strValdt	= 0;	//date
	strValtm	= 0;	//time
	strValmt	= 0;	//month
	strValdy	= 0;	//day
	strValyr	= 0;	//year
	strValhr	= 0;	//hour
	strValmin	= 0;	//minute
	strValsec	= 0;	//second
	
	//if compulsory parameters are not supplied
	if(!(strVal))
	{
		return (1);
	}
	
	if(!(nFormat))
	{
		nFormat = 1;
	}
	//if date-string field is left blank or does not contain any value
	if(!IsValueExist(strVal))
	{
		return (1);
	}
	
	//get date portion from datetime string
	if(!(strValdt = getSubstring(strVal,'1'))) 
	{
		return (2);
	}
	//get time portion from datetime string
	if(!(strValtm = getSubstring(strVal,'2'))) 
	{
		return (2);
	}
	
	////Get seprated month day and year value from date portion
	
	//get month portion from date string
	if(!(strValmt = seprateDateString(strValdt,'m',nFormat))) 
	{
		return (3);
	}
	
	//get day portion from date string
	if(!(strValdy = seprateDateString(strValdt,'d',nFormat))) 
	{
		return (3);
	}
	
	//get year portion from date string
	if(!(strValyr = seprateDateString(strValdt,'y',nFormat))) 
	{
		return (3);
	}

	////Get seprated hours minutes and seconds value from time portion
	
	//get hour portion from time string
	if(!(strValhr = seprateTimeString(strValtm,'h'))) 
	{
		return (4);
	}
	
	//get minute portion from time string
	if(!(strValmin = seprateTimeString(strValtm,'m'))) 
	{
		return (4);
	}
	
	//get second portion from time string
	if(!(strValsec = seprateTimeString(strValtm,'s'))) 
	{
		return (4);
	}
	
	strValmt	= new String(strValmt);	//month
	strValdy	= new String(strValdy);	//day
	strValyr	= new String(strValyr);	//year
	strValhr	= new String(strValhr);	//hour
	strValmin	= new String(strValmin);//minute
	strValsec	= new String(strValsec);//second
	
	//truncate if there exist any 0 in front of number and return a decimal number
	strValmt	= parseInt(strValmt,10);
	strValdy	= parseInt(strValdy,10);
	strValyr	= parseInt(strValyr,10);
	strValhr	= parseInt(strValhr,10);
	strValmin	= parseInt(strValmin,10);
	strValsec	= parseInt(strValsec,10);	

		
	//if strValmt supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmt))
	{
		return (2);
	}
		
	//if strValdy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValdy))
	{
		return (2);
	}
	
	//if strValyr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValyr))
	{
		return (2);
	}
		
	//if strValdhr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValhr))
	{
		return (2);
	}	
	
	//if strValmin supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmin))
	{
		return (2);
	}
		
	//if strValsec supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValsec))
	{
		return (2);
	}
	
	strValmt = strValmt-1 //as month always starts from 0
	
	//if date is not a valid date
	if(!IsDateValid(strValmt,strValdy,strValyr))
	{
		return (3)
	}
	
	//if time is not a valid time
	if(!IsTimeValid(strValhr,strValmin,strValsec))
	{
		return (4);
	}	
	return (0);
}


function checkWithinDateTime(strVal,nDayWithin,nFormat)
{	
	//initialize variables
	strValdt	= 0;	//date
	strValtm	= 0;	//time
	strValmt	= 0;	//month
	strValdy	= 0;	//day
	strValyr	= 0;	//year
	strValhr	= 0;	//hour
	strValmin	= 0;	//minute
	strValsec	= 0;	//second
	
	//if compulsory parameters are not supplied
	if(!(nDayWithin && strVal))
	{
		return (1);
	}
	
	if(!(nFormat))
	{
		nFormat = 1;
	}
	//if date-string field is left blank or does not contain any value
	if(!IsValueExist(strVal))
	{
		return (1);
	}
	
	//get date portion from datetime string
	if(!(strValdt = getSubstring(strVal,'1'))) 
	{
		return (2);
	}
	//get time portion from datetime string
	if(!(strValtm = getSubstring(strVal,'2'))) 
	{
		return (2);
	}
	
	////Get seprated month day and year value from date portion
	
	//get month portion from date string
	if(!(strValmt = seprateDateString(strValdt,'m',nFormat))) 
	{
		return (3);
	}
	
	//get day portion from date string
	if(!(strValdy = seprateDateString(strValdt,'d',nFormat))) 
	{
		return (3);
	}
	
	//get year portion from date string
	if(!(strValyr = seprateDateString(strValdt,'y',nFormat))) 
	{
		return (3);
	}

	////Get seprated hours minutes and seconds value from time portion
	
	//get hour portion from time string
	if(!(strValhr = seprateTimeString(strValtm,'h'))) 
	{
		return (4);
	}
	
	//get minute portion from time string
	if(!(strValmin = seprateTimeString(strValtm,'m'))) 
	{
		return (4);
	}
	
	//get second portion from time string
	if(!(strValsec = seprateTimeString(strValtm,'s'))) 
	{
		return (4);
	}
	
	strValmt	= new String(strValmt);	//month
	strValdy	= new String(strValdy);	//day
	strValyr	= new String(strValyr);	//year
	strValhr	= new String(strValhr);	//hour
	strValmin	= new String(strValmin);	//minute
	strValsec	= new String(strValsec);	//second
	//truncate if there exist any 0 in front of number and return a decimal number
	strValmt	= parseInt(strValmt,10);
	strValdy	= parseInt(strValdy,10);
	strValyr	= parseInt(strValyr,10);
	strValhr	= parseInt(strValhr,10);
	strValmin	= parseInt(strValmin,10);
	strValsec	= parseInt(strValsec,10);	

		
	//if strValmt supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmt))
	{
		return (2);
	}
		
	//if strValdy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValdy))
	{
		return (2);
	}
	
	//if strValyr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValyr))
	{
		return (2);
	}
		
	//if strValdhr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValhr))
	{
		return (2);
	}	
	
	//if strValmin supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmin))
	{
		return (2);
	}
		
	//if strValsec supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValsec))
	{
		return (2);
	}
	
	strValmt = strValmt-1 //as month always starts from 0
	
	//if date is not a valid date
	if(!IsDateValid(strValmt,strValdy,strValyr))
	{
		return (3)
	}
	
	//if time is not a valid time
	if(!IsTimeValid(strValhr,strValmin,strValsec))
	{
		return (4);
	}
	//if date-time is not within a specified period
	if(!IsWithinDateValid(nDayWithin,strValmt,strValdy,strValyr,strValhr,strValmin,strValsec))
	{
		return (5)
	}
	return (0);
}



function checkFuturePastDateTime(strVal,chDayWithin,nFormat)
{	
	//initialize variables
	strValdt	= 0;	//date
	strValtm	= 0;	//time
	strValmt	= 0;	//month
	strValdy	= 0;	//day
	strValyr	= 0;	//year
	strValhr	= 0;	//hour
	strValmin	= 0;	//minute
	strValsec	= 0;	//second
	
	//if compulsory parameters are not supplied
	if(!(chDayWithin && strVal))
	{
		return (1);
	}
	
	if(!(nFormat))
	{
		nFormat = 1;
	}
	//if date-string field is left blank or does not contain any value
	if(!IsValueExist(strVal))
	{
		return (1);
	}
	
	//get date portion from datetime string
	if(!(strValdt = getSubstring(strVal,'1'))) 
	{
		return (2);
	}
	//get time portion from datetime string
	if(!(strValtm = getSubstring(strVal,'2'))) 
	{
		return (2);
	}
	////Get seprated month day and year value from date portion
	
	//get month portion from date string
	if(!(strValmt = seprateDateString(strValdt,'m',nFormat))) 
	{
		return (3);
	}
	
	//get day portion from date string
	if(!(strValdy = seprateDateString(strValdt,'d',nFormat))) 
	{
		return (3);
	}
	
	//get year portion from date string
	if(!(strValyr = seprateDateString(strValdt,'y',nFormat))) 
	{
		return (3);
	}

	////Get seprated hours minutes and seconds value from time portion
	
	//get hour portion from time string
	if(!(strValhr = seprateTimeString(strValtm,'h'))) 
	{
		return (4);
	}
	
	//get minute portion from time string
	if(!(strValmin = seprateTimeString(strValtm,'m'))) 
	{
		return (4);
	}
	
	//get second portion from time string
	if(!(strValsec = seprateTimeString(strValtm,'s'))) 
	{
		return (4);
	}
	strValmt	= new String(strValmt);	//month
	strValdy	= new String(strValdy);	//day
	strValyr	= new String(strValyr);	//year
	strValhr	= new String(strValhr);	//hour
	strValmin	= new String(strValmin);	//minute
	strValsec	= new String(strValsec);	//second
	
	//truncate if there exist any 0 in front of number and return a decimal number
	strValmt	= parseInt(strValmt,10);
	strValdy	= parseInt(strValdy,10);
	strValyr	= parseInt(strValyr,10);
	strValhr	= parseInt(strValhr,10);
	strValmin	= parseInt(strValmin,10);
	strValsec	= parseInt(strValsec,10);	
		
	//if strValmt supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmt))
	{
		return (2);
	}
		
	//if strValdy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValdy))
	{
		return (2);
	}
	
	//if strValyr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValyr))
	{
		return (2);
	}
		
	//if strValdhr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValhr))
	{
		return (2);
	}	
	
	//if strValmin supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmin))
	{
		return (2);
	}
		
	//if strValsec supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValsec))
	{
		return (2);
	}
	
	strValmt = strValmt-1 //as month always starts from 0
	
	//if date is not a valid date
	if(!IsDateValid(strValmt,strValdy,strValyr))
	{
		return (3)
	}
	
	//if time is not a valid time
	if(!IsTimeValid(strValhr,strValmin,strValsec))
	{
		return (4);
	}
	
	if ('p' == chDayWithin)
	{
		//if date-time is not valid past date
		if(!IsPastDateValid(strValmt,strValdy,strValyr,strValhr,strValmin,strValsec))
		{
			return (5);
		}
		else
		return (0);
	}	
	if ('f' == chDayWithin)
	{
		//if date-time is not valid past date
		if(!IsFutureDateValid(strValmt,strValdy,strValyr,strValhr,strValmin,strValsec))
		{
			return (5);
		}
		else
		return (0);
	}		
	return (0);
}



function IsValidFederalIDNumber(strVal,nMinlen,nMaxlen)
{
	
	strVal1 = new Array();
	var j=0;
	var i;
	var sValidChars = "0123456789-";
	
	for (i=0;i<strVal.length;i++)
	{
	if (!(strVal.charAt(i) == "-"))
		{
		strVal1[j]=strVal.charAt(i);
		j++;
		}
	}

	if(strVal1.length < parseInt(nMinlen))
		{
			return false;
		}

	if(strVal1.length > parseInt(nMaxlen))
		{
			return false;
		}

	nNoOfArguments = IsValidFederalIDNumber.arguments.length;
	if(nNoOfArguments < 1)
	{
		return false;
	}		
		
	var bReturn = true;	
	var i = new Number(0);
	strVal = new String(strVal);
	
	//if(strVal.indexOf("+") != strVal.lastIndexOf("+"))//if more than one + exist in value
	//return false;
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)

}






function IsValidZip(strVal,nMinlen,nMaxlen)
{
	
	strVal1 = new Array();
	var j=0;
	var i;
	var sValidChars = "0123456789-";
	
	for (i=0;i<strVal.length;i++)
	{
	if (!(strVal.charAt(i) == "-"))
		{
		strVal1[j]=strVal.charAt(i);
		j++;
		}
	else 
		{
		if ((i<5) || (i>5))
		return false;
		}
	}

	if(strVal1.length < parseInt(nMinlen))
		{
			return false;
		}


	if(strVal1.length > parseInt(nMinlen))
		{
		if(strVal1.length != parseInt(nMaxlen))
		{
			return false;
		}
		}

	

	nNoOfArguments = IsValidZip.arguments.length;
	if(nNoOfArguments < 1)
	{
		return false;
	}		
		
	var bReturn = true;	
	var i = new Number(0);
	strVal = new String(strVal);
	
	//if(strVal.indexOf("+") != strVal.lastIndexOf("+"))//if more than one + exist in value
	//return false;
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)

}


function IsValidPhone1(strVal,nMinlen,nMaxlen)
{
	
	strVal1 = new Array();
	var j=0;
	var i;
	var sValidChars = "0123456789-()";
	
	for (i=0;i<strVal.length;i++)
	{
	if (!( (strVal.charAt(i) == "-")||(strVal.charAt(i) == "(")||(strVal.charAt(i) == ")")))
		{
		strVal1[j]=strVal.charAt(i);
		j++;
		}
	}

	if(strVal1.length < parseInt(nMinlen))
		{
			return false;
		}

	if(strVal1.length > parseInt(nMaxlen))
		{
			return false;
		}

	nNoOfArguments = IsValidPhone1.arguments.length;
	if(nNoOfArguments < 1)
	{
		return false;
	}		
		
	var bReturn = true;	
	var i = new Number(0);
	strVal = new String(strVal);
	
	if(strVal.indexOf(")") != strVal.lastIndexOf(")"))//if more than one + exist in value
	return false;

	if(strVal.indexOf("(") != strVal.lastIndexOf("("))//if more than one + exist in value
	return false;
	

	if(strVal.indexOf("(") > strVal.lastIndexOf(")"))//if more than one + exist in value
	return false;


	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)

}







function IsValidPhone(strVal,nMinlen,nMaxlen)
{
	
	var j=0;
	var i;
	var sValidChars = "0123456789";


	if(strVal.length < parseInt(nMinlen))
		{
			return false;
		}

	if(strVal.length > parseInt(nMaxlen))
		{
			return false;
		}

	nNoOfArguments = IsValidPhone.arguments.length;
	if(nNoOfArguments < 1)
	{
		return false;
	}		
		
	var bReturn = true;	
	var i = new Number(0);
	strVal = new String(strVal);
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)

}
