/*************************************************************************************
Program Name	:	checkfields.js
Description	    :	This page has all the javascript validation and Include functions.
					
Created By		:	Arun Elluru - 08/20/03
					
Modified By	:	
***************************************************************************************/



/**********************************************************************************
Function	: funTrim(sFieldValue)
Description	: This function to Trim the spaces out of a string
Arguments	: String
Returns		: A string that has spaces trimed or an empty string
Modified	:
***********************************************************************************/

function funTrim(sFieldValue) 
{
		// Used for trim the given value
		   
		var nLeft;
		var nRight;
		var nLength;
		
		if (sFieldValue.length==0) 
			{
				return sFieldValue;
			}
		else
			{
				nLeft=0;
				nLength=sFieldValue.length;
				while ( (sFieldValue.charAt(nLeft)==" ") && (nLeft < nLength))
				{
					nLeft=nLeft+1;
				}
				if (nLeft !=nLength) 
				{
					nRight=nLength-1;
					while ((sFieldValue.charAt(nRight)==" ") && (nRight > 0 ))
					{
						nRight=nRight-1;
					}
					if (nRight > nLeft) 
					{
						nLength=nRight-nLeft+1;
						sFieldValue=sFieldValue.substr(nLeft,nLength);
					}
				}
				else
				{
				sFieldValue="";
				}
				//alert("***"+sFieldValue+nLeft)
				return sFieldValue;
			}
} // end of funTrim

/**********************************************************************************
Function	: funChecknull(sFieldValue)
Description	: This function to Null values in a string
Arguments	: String
Returns		: Boolean
Modified	:
***********************************************************************************/

function funChecknull(sFieldValue)
{
	var indLeft
	var indRight
	len=sFieldValue.length
	if(len==0)
	return true;
	for(i=0;i<len;i++)
	{
	  		if(sFieldValue.charAt(i)!=" ")
				break;
	}
	indLeft=i
		for(j=len-1;j>=0;j--)
	{
		if(sFieldValue.charAt(j)!=" ")
				break;
	}
	indRight=j+1
	
	if(indRight==0)
		return true;
	else
		//return sFieldValue.substring(indLeft,indRight)
		return false;
	
}

/**********************************************************************************
Function	: funCheckMail(sFieldValue)
Description	: This function to check if eMail is valid a email or not.
Arguments	: String
Returns		: Boolean
Modified	:
***********************************************************************************/

function funCheckMail(sFieldValue) 
{
	
	 // cheking for Mail
		 
	var nAtPosition=0;            
    var nDotPosition=0;
    var nLength;
    var bValidFlag=false;
    var nLessPos=0;
      
	sFieldValue=funTrim(sFieldValue);
	if (sFieldValue.indexOf("<") != -1)
	{
		return true;
	}
	if (sFieldValue.indexOf(">") != -1)
	{
		return true;
	}	
	if (sFieldValue.indexOf(" ") != -1)
	{
		bValidFlag=true;
	}
	else
	{  
		if (sFieldValue.length<3) 
		{
			bValidFlag=true; 
		}
		else
		{
			nAtPosition=sFieldValue.indexOf("@");
			nDotPosition=sFieldValue.indexOf(".",nAtPosition);
                          
			if ((nAtPosition < 1) || (nDotPosition <=nAtPosition+1)|| (nDotPosition==sFieldValue.length-1)) 
			{
				bValidFlag=true; 
			}
		}
	}               
    return bValidFlag;
         
} // end of funCheckMail

/**********************************************************************************
Function	: fnPageClose(thePath,Msg,theFrame)
Description	: This function is used to alert a Confirm box before Exiting the page
Arguments	: path of the page to be redirected to, Msg - Check to display Confirm Msg or not
				theFrame - to check if the page has frames.
Returns		: 
Modified	:
***********************************************************************************/

function fnPageClose(thePath,Msg,theFrame){
 if (theFrame == 'Y')
 {
		if (Msg == 'Y')
		 {
			if (confirm("All the data that was not saved will be lost.\n        Would you like to continue?"))
			{
				parent.document.location.href=thePath;
				
			}
		}
		else
		{
			parent.document.location.href=thePath;
		}
 
 }
 else
 {
		 if (Msg == 'Y')
		 {
			if (confirm("All the data that was not saved will be lost.\n        Would you like to continue?"))
			{
				location.href=thePath;
				
			}
		}
		else
		{
			location.href=thePath;
		}
}		
		return false;			
}





/**********************************************************************************
Function	: fnExit(thePath)
Description	: This function is used to alert a Confirm box before Exiting the site
Arguments	: path of the Logout page 
Returns		: 
Modified	:
***********************************************************************************/

function fnExit(thePath){
			if (confirm("All the data that was not saved will be lost.\n        Would you like to continue?"))
			{
				location.href=thePath;
			}
			
		}

/**********************************************************************************
Function	: fnExitNoalert(thePath)
Description	: This function is used to alert a Confirm box before Exiting the site
Arguments	: path of the Logout page 
Returns		: 
Modified	:
***********************************************************************************/

function fnExitNoalert(thePath){
				location.href=thePath;
			}

/**********************************************************************************
Function	: isPrice(strChkPriceVal)
Description	: This function checks to see if the strChkPriceVal is a valid price
Arguments	: strChkPriceVal
Returns		: true or false
Modified	:
***********************************************************************************/	
function isPrice(strChkPriceVal){
	
	
	if (strChkPriceVal.substring(0,1) == "$"){
		strChkPriceVal = strChkPriceVal.substring(1,strChkPriceVal.length);
	}	
	else{
		strChkPriceVal = strChkPriceVal;
	}
	

	if(!(isPosInteger(strChkPriceVal.substring(0,1))))
	{	
		if (!((strChkPriceVal.substring(0,1) == "-") || (strChkPriceVal.substring(0,1) == ".")) )
		{
			
			return false;
		}	
					
	}	

	
	//Check if there are any numbers after - sign
	if ((strChkPriceVal.substring(0,1) == "-") && (strChkPriceVal.length == "1"))
	{
		return false;
	}
	
	
	//Get only the Integer Part	with out sign if any
	if (strChkPriceVal.substring(0,1) == "-"){
		strChkPrice = (strChkPriceVal.substring(1,strChkPriceVal.length));
	}	
	else{
		strChkPrice = strChkPriceVal;
	}
	
	
	strChkPrice = strChkPrice.toString();
	for (var i=0; i < strChkPrice.length; i++){
		var chkChar = strChkPrice.charAt(i);
		if (chkChar != ".")
		{
			if (chkChar < "0" || chkChar > "9")
			{		
				return false;
			}
		}
	}
	
	if (strChkPriceVal.indexOf(".")!=-1) 
	{		
		if ((strChkPriceVal.indexOf(".")==((strChkPriceVal.length)-1)) || (strChkPriceVal.substring(strChkPriceVal.indexOf(".")+1,strChkPriceVal.length).length > 2))		
		{
		
			return false;
		}
	}
		
	return true;
}
/**********************************************************************************
Function	: isPosInteger(inputVal)
Description	: This function checks to see if the inputVal is a positive integer
Arguments	: inputVal
Returns		: true or false
Modified	:
***********************************************************************************/	
	function isPosInteger(inputVal){
		inputStr = inputVal.toString();
		for (var i = 0; i < inputStr.length; i++){
			var oneChar = inputStr.charAt(i);
			if (oneChar < "0" || oneChar > "9"){
				return false;
			}
		}
		return true;
	}

/**********************************************************************************
Function	: LTrim(String)
Description	: This function is used to Trim the Left spaces from a String.
Arguments	: String
Returns		: A string that has the left spaces trimed or an empty string
Modified	:
***********************************************************************************/	
	function LTrim(String){
		String += "";		// Force argument to string.
		if(String.length == 0){
			return(String);
		}
		var Count = 0;
		for(Count = 0;Count < String.length;Count++){
			if(!(String.charAt(Count) == " ")){
				return(String.substring(Count,String.length));
			}
		}
		return("");
	}

/**********************************************************************************
Function	: RTrim(String)
Description	: This function is used to Trim the Right spaces from a String.
Arguments	: String
Returns		: A string that has the Right spaces trimed or an empty string
Modified	:
***********************************************************************************/	
	function RTrim(String){
		String += "";		// Force argument to string.
		if(String.length == 0){
			return(String);
		}
		var Count = 0
		for(Count = String.length -1;Count >= 0;Count--){
			if(!(String.charAt(Count) == " ")){
				return(String.substring(0,Count + 1));
			}
		}
		return("");
	}

/**********************************************************************************
Function	: Trim(String)
Description	: This function uses LTrim() and RTrim Functions to Trim the spaces out
				of a string
Arguments	: String
Returns		: A string that has spaces trimed or an empty string
Modified	:
***********************************************************************************/	
	function Trim(String){
		String += "";		// Force argument to string.
		return(RTrim(LTrim(String)));
	}


/**********************************************************************************
Function	: DateComparision(strDate1, strDate2)
Description	: This function takes two string in the mm/dd/yy(yy) format and checks
				to see if that the first Date is less than or equal to the second
				Date.
Arguments	: strDate1, strDate2
Returns		: true or false
Modified	:
***********************************************************************************/	
	function DateComparision(strDate1, strDate2){	
		var intDelimiter11 = strDate1.indexOf("/")
		var intDelimiter12 = strDate1.lastIndexOf("/")
		var intMonth1 = parseInt(strDate1.substring(0, intDelimiter11), 10);
		var intDay1 = parseInt(strDate1.substring(intDelimiter11 + 1, intDelimiter12), 10);
		var intYear1 = parseInt(strDate1.substring(intDelimiter12 + 1, strDate1.length), 10);
		
		var intDelimiter21 = strDate2.indexOf("/")
		var intDelimiter22 = strDate2.lastIndexOf("/")
		var intMonth2 = parseInt(strDate2.substring(0, intDelimiter21), 10);
		var intDay2 = parseInt(strDate2.substring(intDelimiter21 + 1, intDelimiter22), 10);
		var intYear2 = parseInt(strDate2.substring(intDelimiter22 + 1, strDate2.length), 10);
		
		if(intYear1 < 100){
			if (intYear1 >= 30){
				intYear1 += 1900
			}else{
				intYear1 += 2000
			}
		}
		
		if(intYear2 < 100){
			if (intYear2 >= 30){
				intYear2 += 1900
			}else{
				intYear2 += 2000
			}
		}
		
		if(intYear1 <= intYear2){
			if(intYear1 == intYear2){
				if(intMonth1 <= intMonth2){
					if(intMonth1 == intMonth2){
						if(intDay1 <= intDay2){
							return true;				
						}else{
							return false;
						}
					}else{
						return true;
					}
				}else{
					return false;
				}
			}else{
				return true;
			}
		}else{
			return false;
		}
	}



/**********************************************************************************
Function	: fnCheckAreaMaxLen(theForm,Leng)
Description	: This function is used check that the Max Length of Textarea
Arguments	: Form Name, Max Length of Textarea.
Returns		: True or False
Modified	:
***********************************************************************************/	
	function fnCheckAreaMaxLen(theForm,Leng) {
		if (funTrim(theForm) != "")
		{
			
			if (theForm.length > Leng) {			
				return true;
			}
			return false;	
		}	
		return false;	
	}	

/**********************************************************************************
Function	: fnCheckTab(theVariable,item)
Description	: This function is used to create blank spaces when tab is pressed in a
				textarea. 
Arguments	: theVariable - Field Name, item - reference of the Field.
Returns		: True or False
Modified	:
***********************************************************************************/	

function fnCheckTab(theVariable,item){
    
    if(event.keyCode==9){
      theVariable.focus();    
      
      space = "      "; //tab space
      
      item.selection=document.selection.createRange(); //cursor location
      item.selection.text=space; //insert at cursor location
      
      event.returnValue = false;  
    }  
  }
  
/**********************************************************************************
Function	: isDate(txtField)
Description	: This function is used check that the string in the text field is in
				mm/dd/yy(yy) format and that it is a valid date.
Arguments	: txtField (a reference to a text field in a form)
Returns		: true or false
Modified	:
***********************************************************************************/	
	function isDate(txtField){
		
		if(txtField.value != ""){
			var strFieldValue = txtField.value;
			var intDelimiter1 = strFieldValue.indexOf("/")
			var intDelimiter2 = strFieldValue.lastIndexOf("/")
			
			if(intDelimiter1 != -1 && intDelimiter1 == intDelimiter2){
				alert("The date entry in is not in acceptable format.\n\nThe date must be entered in the MM/DD/YY format.");
				txtField.focus();
				txtField.select();
				return false;
			}
				
			if(intDelimiter1 != -1){
				
				var intMonth = parseInt(strFieldValue.substring(0, intDelimiter1), 10);
				var intDay = parseInt(strFieldValue.substring(intDelimiter1 + 1, intDelimiter2), 10);
				var intYear = parseInt(strFieldValue.substring(intDelimiter2 + 1, strFieldValue.length), 10);
				
				
				if(isNaN(intMonth) || isNaN(intDay) || isNaN(intYear)){
					alert("The date entry is not in acceptable format.\n\nThe date must be entered in the MM/DD/YY format.");
					txtField.focus();
					txtField.select();
					return false;
				}
				
				if ((intDelimiter1 != 2) || (intDelimiter2 != 5)){
					alert("The date entry is not in acceptable format.\n\nThe date must be entered in the MM/DD/YY format.");
					txtField.focus();
					txtField.select();
					return false;
				}
			
				
				if(intMonth < 1 || intMonth > 12){
					alert("Months must be entered between the range of 01 (January) and 12 (December).");
					txtField.focus();
					txtField.select();
					return false;
				}
				
				if(intDay < 1 || intDay > 31){
					alert("Days must be entered between the range of 01 and a maximum of 31 (depending on the month and year).");
					txtField.focus();
					txtField.select();
					return false;
				}
				
				if(intYear < 100){
					if (intYear >= 30){
						intYear += 1900
					}else{
						intYear += 2000
					}
				}
				
				if(!checkMonthLengthDate(intMonth, intDay)){
					txtField.focus();
					txtField.select();
					return false;
				}
				
				if(intMonth == 2){
					if(!checkLeapMonthDate(intMonth, intDay, intYear)){
						txtField.focus();
						txtField.select();
						return false;
					}
				}
				
				return true;
				
			}else{
				alert("The date entry is not in acceptable format.\n\nThe date must be entered in the MM/DD/YY format.");
				txtField.focus();
				txtField.select();
				return false;
			}
		}else{
			return true;
		}
	}


/**********************************************************************************
Function	: checkMonthLengthDate(mm,dd)
Description	: This function is used check that the number of days in a month is
				correct
Arguments	: mm, dd
Returns		: A string containg the error message or an empty string
Modified	:
***********************************************************************************/	
	function checkMonthLengthDate(mm,dd) {
		var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December");
		if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30) {
			return ("    - " + months[mm] + " has only 30 days.\n");
		} else if (dd > 31) {
			return ("    - " + months[mm] + " has only 31 days.\n");
		}
		return true;
	}
	
/**********************************************************************************
Function	: checkLeapMonthDate(mm,dd,yyyy)
Description	: This function is used check that the number of days in February is
				correct
Arguments	: mm, dd, yyyy
Returns		: A string containg the error message or an empty string
Modified	:
***********************************************************************************/	
	function checkLeapMonthDate(mm,dd,yyyy) {
		if (yyyy % 4 > 0 && dd > 28) {
			return ("    - February of " + yyyy + " has only 28 days.\n");
		} else if (dd > 29) {
			return ("    - February of " + yyyy + " has only 29 days.\n");
		}
		return true;
	}


/**********************************************************************************
Function	: fnGetMonthName(MonthNumber)
Description	: This function is used to return the month name 
				
Arguments	: MonthNumber
Returns		: A string containg the month name
Modified	:
***********************************************************************************/		
	
function fnGetMonthName(MonthNumber) {

	if (MonthNumber  == 1){
		return "January"
	}
	else if (MonthNumber  == 2){
		return "February"
	} 
	else if (MonthNumber  == 3){
		return "March"
	}
	else if (MonthNumber  == 4){
		return "April"
	} 
	else if (MonthNumber  == 5){
		return "May"
	}
	else if (MonthNumber  == 6){
		return "June"
	} 
	else if (MonthNumber  == 7){
		return "July"
	}
	else if (MonthNumber  == 8){
		return "August"
	} 
	else if (MonthNumber  == 9){
		return "September"
	}
	else if (MonthNumber  == 10){
		return "October"
	} 
	else if (MonthNumber  == 11){
		return "November"
	}
	else if (MonthNumber  == 12){
		return "December"
    } 
 
}


/**********************************************************************************
Function	: fnCompDateTime(Date1,Date2)
Description	: This function is used to compare two Date and Times. Dates must be in
				'January 2, 2000 23:50' Format.
				
Arguments	: Two Dates to be compared
Returns		: true or false
Modified	:
***********************************************************************************/		

function fnCompDateTime(Date1,Date2)
{    
     Date1 = new Date(Date1);
     Date2 = new Date(Date2);
     Date1=Date1.getTime();
     Date2=Date2.getTime();  
     DateMainDiff=Date2-Date1; 
     
     DateMainDiff=DateMainDiff/1000;
     if(DateMainDiff>0) 
     { 
		DtSecond=DateMainDiff; 
		DtHour=DtSecond/3600;  
		DtDay=DtHour/24; 
		var hDtDay=Math.floor(DtDay);
		var DtHour=(DtDay-hDtDay)*24; 
		var hDtHour=Math.floor(DtHour);  
		var DtMinute=(DtHour-hDtHour)*60;  
		var hDtMinute=Math.floor(DtMinute);  
		DtSecond=(DtMinute-hDtMinute)*60;  
		var hDtSecond=Math.floor(DtSecond); 
     } 
     else  
     {  
		hDtDay=0; 
		hDtHour=0;  
		hDtMinute=0; 
		hDtSecond=0; 
		
     }  
     
     
     if (hDtDay > 0)
     {
		return true;
     }
     else if (hDtHour > 0)
     {
		return true;
     }
     else if (hDtMinute > 0)
     {
		return true;
     }
     else
     {
		return false;
     }
}	



/**********************************************************************************
Function	: isAlphaNumeric(val)
Description	: This function is used to check that all values in the string contains
				Alpha Numeric values.
				
Arguments	: string to be checked.
Returns		: true or false
Modified	:
***********************************************************************************/		

function isAlphaNumeric(val)
{
	if (val.match(/^[a-zA-Z0-9]+$/))
	{
		return true;
	}
	else
	{
		return false;
	}	
}

/**********************************************************************************
Function	: isAlpha(val)
Description	: This function is used to check that all values in the string contains
				only Alphabets.
				
Arguments	: string to be checked.
Returns		: true or false
Modified	:
***********************************************************************************/		

function isAlpha(val)
{
	if (val.match(/^[a-zA-Z]+$/))
	{
		return true;
	}
	else
	{
		return false;
	}	
}

/**********************************************************************************
Function	: validateURL(strURL)
Description	: This function is used to validate URL . some valid URL's are
				ex 1 : (http(s)://www.test.org/test)
				ex 2 : (http(s)://2ww.test.org)
				ex 3 : (http(s)://test.co)
				
Arguments	: URL to be validated.
Returns		: true or false
Modified	:
***********************************************************************************/


function validateURL(strURL)
{

	var strChk;
	strChk      = 0;
	strURL = funTrim(strURL);
	strURL = strURL.toUpperCase();
	//Check if url is not null
	
	
	if (strURL.length == 0){
		return true;
	}
	if (strURL == "HTTP://"){
		return true;
	}
	
	var strhttp;
			var strhttps;			
			var strDomain;	
			
			strhttp		= strURL.substr(0,7);
			strhttps	= strURL.substr(0,8);			
			
			//Check if len of URL is less than 8 or if value is not http:// or https:// .
			if (strURL.length < 8){
				strChk = 1;							
			}
			else if (!((strhttp == "HTTP://") || (strhttps == "HTTPS://") )){			
				strChk = 1;									
			}
			
			//If above are valid then check for the remaining URL (URL-protocol)
			if (strChk != 1){
				if (strhttp == "HTTP://") strDomain = (strURL.substr(strhttp.length,strURL.length));
				if (strhttps == "HTTPS://") strDomain = (strURL.substr(strhttps.length,strURL.length));
				
				//Check if first character is alpha numberic or not
				if (!(isAlphaNumeric(strDomain.substr(0,1)))) strChk = 1;
				
				//Check if / is ther in URL if present then get string before /.
				if ((strDomain.indexOf("/")) != "-1") strDomain = strDomain.substr(0,strDomain.indexOf("/"))
			
				//Check if . is there in the string.
				if ((strDomain.indexOf(".")) == "-1") strChk = 1;
				
				//Check to see if characters are present between . and /
				
				
				strDomChk = strDomain.substr(0,strDomain.lastIndexOf("."));
				strDotChk = strDomain.substr(strDomain.lastIndexOf(".")+1, strDomain.length);
				
				
				//Check to see if there are less than 1 characters bet start of the string and .				
				if (strDomChk.length < 1) strChk = 1;				
			
				//Check to see if there are less than 2 characters bet start of the . and end of string.
				if (strDotChk.length < 2) strChk = 1;
				
				//to check the last characters of string after last . to be only characters (com, in, net, org ...)	
				if (!(isAlpha(strDotChk))) strChk = 1;				
			}
			
			if (strChk == 1){			
				return false;
			}
			else
			{				
				return true;				
			}



	
}

  
  
/**********************************************************************************
Function	: fnChkNumber(strChkNum)
Description	: This function is used to check the price format.
				ex 1 : if number is $.23 returns $0.23
				ex 2 : if number is 23.45 returns $23.45
				ex 3 : if number is -.23 returns $0.23
				
Arguments	: 
Returns		: the formateed number.
Modified	:
***********************************************************************************/  

function fnChkNumber(strChkNum) {
	
	var strNegative = 0;
	strChkNum = strChkNum.toString();	
	if (strChkNum.substring(0,1) == "$"){
		strChkNum = strChkNum.substring(1,strChkNum.length);
	}
	if (strChkNum.substring(0,1) == "-"){
		strChkNum = strChkNum.substring(1,strChkNum.length);
		strNegative = 1;
	}	

	if (strChkNum.substring(0,1) == "."){	
			strChkNum = "0" + strChkNum;	
	}

	if (strNegative == 1) {
		strChkNum = "$-" + strChkNum;
	}
	else {
		strChkNum = "$" + strChkNum;
	}
	 
	return strChkNum;
}  




/**********************************************************************************
Function	: checkMonthLength(mm,dd)
Description	: This function is used check that the number of days in a month is
				correct
Arguments	: mm, dd
Returns		: A string containg the error message or an empty string
Modified	:
***********************************************************************************/	
	function checkMonthLength(mm,dd) {
		var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December");
		if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30) {
			return ("    - " + months[mm] + " has only 30 days.\n");
		} else if (dd > 31) {
			return ("    - " + months[mm] + " has only 31 days.\n");
		}
		return ("");
	}

/**********************************************************************************
Function	: checkLeapMonth(mm,dd,yyyy)
Description	: This function is used check that the number of days in February is
				correct
Arguments	: mm, dd, yyyy
Returns		: A string containg the error message or an empty string
Modified	:
***********************************************************************************/	
	function checkLeapMonth(mm,dd,yyyy) {
		if (yyyy % 4 > 0 && dd > 28) {
			return ("    - February of " + yyyy + " has only 28 days.\n");
		} else if (dd > 29) {
			return ("    - February of " + yyyy + " has only 29 days.\n");
		}
		return ("");
	}



function isDate(strDate, strFormat, blnTodayOrMore){
		strDate = Trim(strDate);
		if(strDate == '') return '';
		
		//Check for valid Format Argument
		switch(strFormat){
			case 'mm/dd/yyyy':
				break;
			case 'mm/yyyy':
				break;
			default:
				return 'Invalid Date Format Argument';
		}
		
		//Check that the last char is a number
		if(isNaN(strDate.charAt(strDate.length - 1))){
			return 'Date must be in ' + strFormat + ' format';
		}
		
		var intDelimiter1 = strDate.indexOf('/');
		var intDelimiter2 = strDate.lastIndexOf('/');
		
		//Check that the first / is at char pos 1 (0 based) or greater
		if(intDelimiter1 < 1){
			return 'Date must be in ' + strFormat + ' format';
		}
		
		//For mm/yyyy there can be only one /
		if(strFormat == 'mm/yyyy' && intDelimiter1 != intDelimiter2){
			return 'Date must be in ' + strFormat + ' format';
		}
		
		//For mm/dd/yyyy there must be 2 /
		if(strFormat == 'mm/dd/yyyy' && intDelimiter1 == intDelimiter2){
			return 'Date must be in ' + strFormat + ' format';
		}
		
		//Separate Date into month, year and day
		var intMonth = strDate.substring(0, intDelimiter1);
		var intYear = strDate.substring(intDelimiter2 + 1, strDate.length);
		if(strFormat == 'mm/dd/yyyy'){
			var intDay = strDate.substring(intDelimiter1 + 1, intDelimiter2);
		} else {
			var intDay = '1';
		}
		
		//Check that all parts of the date is a number
		if(isNaN(intMonth) || isNaN(intDay) || isNaN(intYear)){
			return 'Date must be in ' + strFormat + ' format';
		}
		
		//Parse values as integer
		intMonth = parseInt(intMonth, 10);
		intDay = parseInt(intDay, 10);
		intYear = parseInt(intYear, 10);

		//Check that the month is within range
		if(intMonth < 1 || intMonth > 12){
			return 'Month must be between 1 (January) and 12 (December)';
		}
		
		//Check that the day is within range
		if(intDay < 1 || intDay > 31){
			return 'Day must be between 1 and a maximum of 31';
		}
		
		//Check that Year is within range
		if(intYear < 1900 || intYear > 2078){
			if(intYear < 1000) return 'Date must be in ' + strFormat + ' format';
			if(intYear < 1900) return 'Dates earlier than 1/1/1900 is not allowed';
			if(intYear > 2078) return 'Dates later than 12/31/2078 is not allowed';
		}
		
		//Check for right number of days in month
		var arrMonths = new Array('','January','February','March','April','May','June','July','August','September','October','November','December');
		if((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && intDay > 30){
			return arrMonths[intMonth] + ' has only 30 days';
		}
		if(intMonth == 2){
			if (intYear % 4 > 0 && intDay > 28) {
				return 'February of ' + intYear + ' has only 28 days';
			} else if (intDay > 29) {
				return 'February of ' + intYear + ' has only 29 days';
			}
		}

		//Check that the date is greater than or equal to today
		if(blnTodayOrMore){
			var objToday = new Date(), objDate = new Date();
			objToday.setHours(0, 0, 0, 0);
			objDate.setTime(Date.parse(intMonth + '/' + intDay + '/' +  intYear));
			if(strFormat == 'mm/yyyy'){
				objToday.setMonth(objToday.getMonth() + 1);
				objToday.setDate(0);
				objDate.setMonth(objDate.getMonth() + 1);
				objDate.setDate(0);
			}
			if(objDate.getTime() < objToday.getTime()){
				return 'Date cannot be less that today\'s date';
			}
		}

		return '';
	}

//*******************************************************************************************


	function TodaysDate(){
		var objDate = new Date();
		var strTodaysDate = (((objDate.getMonth() + 1) + '').length == 1) 
			? '0' + (objDate.getMonth() + 1) : '' + (objDate.getMonth() + 1);
		strTodaysDate += ((objDate.getDate() + '').length == 1)
			? '/0' + objDate.getDate() : '/' + objDate.getDate();
		strTodaysDate += '/' + objDate.getFullYear();
		return strTodaysDate;
	}

//*******************************************************************************************

	function LTrim(String){
		String += '';
		if(String.length == 0){
			return String;
		}
		for(var Count = 0; Count < String.length; Count++){
			if(!(String.charAt(Count) == ' ')){
				return String.substring(Count, String.length);
			}
		}
		return '';
	}

//*******************************************************************************************

	function RTrim(String){
		String += '';
		if(String.length == 0){
			return String;
		}
		for(var Count = String.length -1; Count >= 0; Count--){
			if(!(String.charAt(Count) == ' ')){
				return String.substring(0, Count + 1);
			}
		}
		return '';
	}

//*******************************************************************************************

	function Trim(String){
		String += '';
		return RTrim(LTrim(String));
	}

