function TesDat(CodDat,Sep,Typ)
{
var One = '';
var Due = '';
var Tre = '';
var strDay = '';
var strMon = '';
var strYea = '';
var arrDat = Typ.split(Sep);
arrDate[0]='';arrDate[1]='';arrDate[2]='';
if (CodDat.length == 6 || CodDat.length == 8 || CodDat.length == 10) 
	{
	//We have 01/01/01
	if (CodDat.length == 8 && CodDat.indexOf(Sep) == 2)
		{
		One = CodDat.substr(0,2);
		Due = CodDat.substr(3,2);
		Tre = CodDat.substr(6,2);
		}
	//we have 010101
	if (CodDat.length == 6 && CodDat.indexOf(Sep) == -1)
		{
		One = CodDat.substr(0,2);
		Due = CodDat.substr(2,2);
		Tre = CodDat.substr(4,2);
		}
	//we have 01012001
	if (CodDat.length == 8 && CodDat.indexOf(Sep) == -1)
		{
		One = CodDat.substr(0,2);
		Due = CodDat.substr(2,2);
		Tre = CodDat.substr(4,4);
		}
	//We have 01/01/2001
	if (CodDat.length == 10 && CodDat.indexOf(Sep) == 2)
		{
		One = CodDat.substr(0,2);
		Due = CodDat.substr(3,2);
		Tre = CodDat.substr(6,4);
		}
	//test if user fill date in some good format
	if (One != '' && Due != '' && Tre != '') 
		{
		//test what is first
		if (arrDat[0].indexOf('D') != -1) {strDay = One}	
		if (arrDat[0].indexOf('M') != -1) {strMon = One}
		if (arrDat[0].indexOf('Y') != -1) {strYea = One}
		//test what is second
		if (arrDat[1].indexOf('D') != -1) {strDay = Due}	
		if (arrDat[1].indexOf('M') != -1) {strMon = Due}
		if (arrDat[1].indexOf('Y') != -1) {strYea = Due}
		//test what is third
		if (arrDat[2].indexOf('D') != -1) {strDay = Tre}	
		if (arrDat[2].indexOf('M') != -1) {strMon = Tre}
		if (arrDat[2].indexOf('Y') != -1) {strYea = Tre}
		
		if (strYea.length == 2)
			{
			if (strYea.substr(0,1) == '9')
				{strYea = '19' + strYea}
			else
				{strYea = '20' + strYea}
			}
		var DatDat = strMon + '/' + strDay + '/' + strYea
		var k = isValidDate(DatDat);
		if (k==0) {arrDate[0]=strYea; arrDate[1]=strMon; arrDate[2]=strDay; return(1);} //{alert('OK');}
		if (k==1) {return(0);} //{alert('WRONG FORMAT');}
		if (k==2) {return(0);} //{alert('WRONG');}
		}
	else
		{return(0);}
	}
else
	{
	return(0);
	}
}

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;
}  

