

function isValidDate(date2check){
  // dgk-10/07/00
  // determines if the date string passed represents a valid date.
  // returns 0 if the date is valid
  // returns 1 if the date is not in the format of mm/dd/ccyy, mm-dd-ccyy, or mmddccyy
  //      m/d/ccyy & m-d-ccyy are also acceptable
  // returns 2 if the date is not a legal date (i.e. 02/30/1999)
  var retval = 0
  var aMMDDCCYY
  var dtest
  // use a regular expression pattern match to determine if the date format is valid
  if (/^(\d\d?-\d\d?-\d{4})|(\d\d?\/\d\d?\/\d{4})|(\d{8})$/.test(date2check)){
    dtest = new Date(date2check);
    if (/\//.test(date2check)){
      aMMDDCCYY = date2check.split("/");
    }else{
      if (/-/.test(date2check)){
        aMMDDCCYY = date2check.split("-");
      }else{
        aMMDDCCYY = Array(date2check.substr(0,2), date2check.substr(2,2), date2check.substr(4,4))
        dtest = new Date(aMMDDCCYY[0] + "/" + aMMDDCCYY[1] + "/" + aMMDDCCYY[2]);
      }
    }
    if (dtest.getMonth() + 1 != aMMDDCCYY[0] || dtest.getDate() != aMMDDCCYY[1] || dtest.getFullYear() != aMMDDCCYY[2]){
      retval = 2
    }
  }else{
    retval = 1
  }
  return retval
}

function StdDateFormat(strDate){
  // dgk-10/07/00
  // receives a date string in the format of mm/dd/ccyy, mm-dd-ccyy, or mmddccyy
  // returns a date string in the standard format: mm/dd/ccyy.
  var retval = ""
  var aMMDDCCYY
  if (isValidDate(strDate) == 0){
     if (/\//.test(strDate)){
             retval = strDate;
     }else{
        if (/-/.test(strDate)){
           aMMDDCCYY = strDate.split("-");
        }else{
           aMMDDCCYY = Array(strDate.substr(0,2), strDate.substr(2,2), strDate.substr(4,4));
        }
        retval = (aMMDDCCYY[0] + "/" + aMMDDCCYY[1] + "/" + aMMDDCCYY[2]);
     }
  }
  return retval;
}               

function DateMdy(strDob)
//  Author               : surya (K.S.V.A.NAIDU)
// Return's date in mm/dd/yyyy
{
	var d1;
	var m1;
	var y1;
	var strDate;

	d1=strDob.charAt(0);
	if (isInteger(strDob.charAt(1)))
	{
		d1=d1 + strDob.charAt(1);
		m1=strDob.charAt(3);
		if (isInteger(strDob.charAt(4)))
		{
			m1=m1 + strDob.charAt(4);
			y1=strDob.substring(6,10);
		}
		else
		{
			y1=strDob.substring(5,9);
			
		}
	}
	else
	{
		m1=strDob.charAt(2);
		if (isInteger(strDob.charAt(3)))
		{
			m1=m1 + strDob.charAt(3);
			y1=strDob.substring(5,9);
		}
		else
		{
			y1=strDob.substring(4,8);
			
		}
	}
					
	strDate=m1 + "/" + d1 + "/" + y1;
	return strDate;
}

function rptFormatDate(StrDate)
//  Author               : K.S.MALLIKARJUN
{
			
	if(isInteger(StrDate.charAt(1)))  
		{
			if (isInteger(StrDate.charAt(4)))
			{
				var strTodate=StrDate.substring(6,10);
				strMon=StrDate.substring(3,5);
				strDay=StrDate.substring(0,2);
				strTodate=strTodate+strMon+strDay;
				
			 }
		
			 else
				{
					var strTodate=StrDate.substring(5,9);
					strMon=StrDate.substring(3,4);
					strDay=StrDate.substring(0,2);
					strTodate=strTodate+0+strMon+strDay;
					
				}

			}
			else
				{
					
					if (isInteger(StrDate.charAt(3)))
					{
					var strTodate=StrDate.substring(5,9);
					strMon=StrDate.substring(2,4);
					strDay=StrDate.substring(0,1);
					strTodate=strTodate+strMon+0+strDay;
					
					}
		
					else
					{
						var strTodate=StrDate.substring(4,8);
						strMon=StrDate.substring(2,3);
						strDay=StrDate.substring(0,1);
						strTodate=strTodate+0+strMon+0+strDay;
					}
				}
			return strTodate;
		}


function DateOracle(strDob)
		//  Author               : surya (K.S.V.A.NAIDU)
		// Return's date in dd-MMM-yyyy format
{
	var d1;
	var m1;
	var y1;
	var strDate;
	var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

	d1=strDob.charAt(0);
	if (isInteger(strDob.charAt(1)))
	{
		d1=d1 + strDob.charAt(1);
		m1=strDob.charAt(3);
		if (isInteger(strDob.charAt(4)))
		{
			m1=m1 + strDob.charAt(4);
			y1=strDob.substring(6,10);
		}
		else
		{
			y1=strDob.substring(5,9);
			
		}
	}
	else
	{
		m1=strDob.charAt(2);
		if (isInteger(strDob.charAt(3)))
		{
			m1=m1 + strDob.charAt(3);
			y1=strDob.substring(5,9);
		}
		else
		{
			y1=strDob.substring(4,8);
			
		}
	}
	strDate=d1 + "-" + monthname[m1-1] + "-" + y1;				
	
	return strDate;
}
