 function IsDate(datestr) {
	var arrValue, tmpDate
	
	arrValue = datestr.split("-")
	tmpData = new Date(datestr.replace(/-/g,'/'))
	if(parseInt(arrValue[1]) == (tmpData.getMonth()+1)) {
	   return true
	} else {
	   return false
	}
 }

 function RightDate(datestr,nWay) {
	var arrValue, tmpDate, rtnValue
	var nDiff, arrTemp

	arrValue = datestr.split("-")
	tmpData = new Date(datestr.replace(/-/g,'/'))
	if(parseInt(arrValue[1]) == (tmpData.getMonth()+1)) {
	   rtnValue = datestr
	} else {
       if(nWay==0) {
		  rtnValue = tmpData.getYear() + "-" + (tmpData.getMonth()+1)
		  rtnValue = rtnValue + "-1"
	   } else {
	      nDiff = (-1)*tmpData.getDate()
	      rtnValue = DateAdd(nDiff,datestr)
	   }
	}	

    arrTemp = rtnValue.split("-")
    if(arrTemp[0].length==2) {
	   rtnValue = "19" + rtnValue
	}

	return rtnValue
 }

 function DateDiff(f_date,t_date) {
	var date1, date2, nDiff

    if(!IsDate(f_date) || !IsDate(t_date)) {
	   return 999
	}

	date1 = f_date.replace(/-/g,'/')
	date2 = t_date.replace(/-/g,'/')
	nDiff = (new Date(date2) - new Date(date1)) / (60*60*24*1000)
	return nDiff
 }

 function DateAdd(nAdd,datestr) {
	var tmpDate, newDate, rtnValue

    tmpData = new Date(datestr.replace(/-/g,'/'))
	newDate = new Date(tmpData.getTime() + 60*60*24*1000*nAdd) 
	rtnValue = newDate.getYear() + "-" + (newDate.getMonth()+1)
	rtnValue = rtnValue + "-" + newDate.getDate()

	return rtnValue
 }

 function GetToday() {
	var today, rtnValue

	today = new Date()
    rtnValue = today.getYear() + "-" + (today.getMonth()+1) + "-" + today.getDate()

	return rtnValue
 }