function dateUtils(){
	this.jdString = jdString
	this.makeUTCString = makeUTCString
	this.jdParts = jdParts

	function makeUTCString(ms)
	{
		//a function to convert a date into a string in the format 'YYYY-MM-DD HH:MM UTC'
		if(ms===''){
			theDate = new Date()
		}
		else{
			//theDate = Date(ms);
			theDate = new Date(ms);
		}
		this.utcDate = theDate.getUTCFullYear() + "-" + padString(theDate.getUTCMonth()+1,2) + "-" + padString(theDate.getUTCDate(),2);
		this.utcString = this.utcDate +" "+ padString(theDate.getUTCHours(),2) +":"+ padString(theDate.getUTCMinutes(),2) +" UTC";
		this.utcStringShort = this.utcDate +" "+ padString(theDate.getUTCHours(),2) +":"+ padString(theDate.getUTCMinutes(),2);

		//return theDate
	}

	function jdString(ms, zone, precision)
	{
		//input should be milliseconds, zone is in +/- longitude
		//new Date() returns current jd
		//new Date(2004, 6, 29, 12, 1) returns local date
		//Date.UTC(2004, 6, 29, 12) returns utc date

		prec = Math.pow(10, precision)
		if (zone =='' && typeof(zone) != 'number'){zone = 180}
		localOffset =  (Math.floor((zone - 180)/0.360))/1000

		try{
			ms.setHours(ms.getHours()-localOffset)		//produces 'local' time
			}	
		catch(err){}					//don't care what the error is

		//first, 5 digit decimal
		jdDT = Math.round(ms/864)/100000 + 2440587.5 + localOffset
		jdDay = Math.floor((ms/864/100000) + 2440587.5 + localOffset)
		jdString = String(Math.floor(jdDT*prec)/prec) + '000000'
		this.jdt = jdString.substr(8, precision)
		this.jdString = jdString.substr(0, (8+ precision))
		//return jdString	
	}

	function jdParts(ms, zone) {
		//input should be milliseconds, zone is in +/- longitude

		if (zone ==''){zone = 180}
		localOffset =  (Math.floor((zone - 180)/0.360))/1000

		try{
			ms.setHours(ms.getHours()-localOffset)		//produces 'local' time
		}	catch(err){}					//don't care what the error is

		this.jdDT = Math.round(ms/864)/100000 + 2440587.5 + localOffset
		this.jdDay = Math.floor((ms/864/100000) + 2440587.5 + localOffset)
		this.jdDTString = this.jdDay + "." + Math.round((this.jdDT - this.jdDay) *100000)
	}

	function padString(thenum,thefactor)
	{	//pads a number or string with leading zeros
		pad0s = new String(Math.pow(10,thefactor))
		thepad = pad0s + String(thenum)
		thestring= thepad.substr((-1*thefactor),thefactor)
		return thestring
	}
}

	function utcNowToDarianDates(){
		//calculate current sols
		todayMS = (new Date()).valueOf()			//now UTC in ms
		this.nowUTCObj = new Date(todayMS)			//date object UTC
		this.nowDarEraDate = this.darUnixDateTime + (Math.floor(todayMS/this.marsDaySec)/1000)	//calc sols
		this.nowDarDecTime = (String(this.nowDarEraDate).split(".")[1] + '000').slice(0,5) 	//decimal time
		this.nowDarEraDay = Math.floor(this.nowDarEraDate)	//sols integer
	}
	function utcStrToDarianDates(gregDateStr){
		//calculate darian era date/day based on gregorian date in text form

		gregDateStr = gregDateStr.replace(/:|-|\.| /gi,'/')	//replace -:.or space with slash
		//new Date doesn't work in khtml if i feed it the date in the form '2004/4/4'
		//the result is a very big negative number, so i split it and use the parts
		dateParts = gregDateStr.split('/')			//split on slash
		this.utcDateObj = new Date(dateParts[0], dateParts[1]-1, dateParts[2])
		dateMS = this.utcDateObj.valueOf()			//get date in ms
		this.eraDate = this.darUnixDateTime+(Math.floor(dateMS/this.marsDaySec)/1000)	//calc sols
		this.eraDay = Math.floor(this.darEraDate)		//sols integer
	}

	function darianDateTimeToUTC(darEraDate){ //done
		//given a mars date in sols, create the terrestrial date
		//khtml can't do dates prior to 1901 or after 2038 (32bit limit), gecko/ie/opera are fine
		//this.utcDT = (darEraDate - this.darUnixDateTime)*this.marsDaySec*1000	//UTC date in millisecs
		this.utcDateObj = new Date(this.utcDT)					//UTC date object
		mStr = ('00' + ((this.utcDateObj).getUTCMonth()+1))
		dStr = ('00' + ((this.utcDateObj).getUTCDate()))
		hStr = ('00' + ((this.utcDateObj).getUTCHours()))
		nStr = ('00' + ((this.utcDateObj).getUTCMinutes()))
		//work-around because ie doesn't support neg index in substr
		this.utcDateStr = (this.utcDateObj).getUTCFullYear() + '-' + mStr.substr(mStr.length-2,2) + '-' + dStr.substr(dStr.length-2,2) + ' ' + hStr.substr(hStr.length-2,2) + ':' + nStr.substr(nStr.length-2,2) + ' UTC'
	}

