//	first we add to some prototypes.

//	All prototypes come from the f(m) Base Class Library, (c) Thomas R. Trenka, Ph.D. under the GPL.

//	see http://fm.dept-z.com for details.

Date.FormatTypes = { ShortDate:0, LongDate:1, ShortEuroDate:2, LongEuroDate:3, Numeric:4, NumericEuro:5, Time:6, TimeMilitary:7, ODBC:8, XSD:9 } ; 

Date.prototype.GetDayOfWeekName = function() { return ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][this.getDay()] ; }

Date.prototype.GetDayOfWeekShortName = function() { return ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][this.getDay()] ; }

Date.prototype.GetMonthName = function() { return ["January","February","March","April","May","June","July","August", "September","October","November","December"][this.getMonth()] ; } ;

Date.prototype.GetMonthShortName = function() { return ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug", "Sep","Oct","Nov","Dec"][this.getMonth()] ; } ;

Date.prototype.GetHumanDateString = function() { return this.GetMonthName() + " " + this.getDate() + ", " + this.getFullYear() ; } ;

Date.prototype.GetShortHumanDateString = function(delim) { 

	if (!delim) var delim = "-" ; 

	return this.GetMonthShortName() + delim + this.getDate() + delim + this.getFullYear() ; 

} ;

Date.prototype.GetShortDateString = function(delim) {

	if (!delim) var delim = "-" ; 

	return (this.getMonth()+1) + delim + this.getDate() + delim + this.getFullYear() ; 

} ;

Date.prototype.GetHumanTimeString = function() {

	var h = this.getHours() ;

	var m = "00" + this.getMinutes() ;

	var t = h >= 12 ? "pm" : "am" ;

	if (h == 0) h = 24 ;

	if (h > 12) h -= 12 ;

	return h + ":" + m.substr(-2,2) + " " + t ;

} ;

Date.prototype.Format = function(FormatType) {

	switch (FormatType) {

		case Date.FormatTypes.ShortDate : return this.GetShortHumanDateString() ;

		case Date.FormatTypes.LongDate : return this.GetHumanDateString() ;

		case Date.FormatTypes.ShortEuroDate : return this.getDate() + "-" + this.GetMonthShortName() + "-" + this.getYear() ;

		case Date.FormatTypes.LongEuroDate : return this.getDate() + " " + this.GetMonthName() + " " + this.getFullYear() ;

		case Date.FormatTypes.Numeric : return (this.getMonth()+1) + "-" + this.getDate() + "-" + this.getYear() ;

		case Date.FormatTypes.NumericEuro : return this.getDate() + "-" + (this.getMonth()+1) + "-" + this.getYear() ;

		case Date.FormatTypes.Time : return this.GetHumanTimeString() ;

		case Date.FormatTypes.TimeMilitary : {

			var h = '00' + this.getHours() ;

			var m = '00' + this.getMinutes() ;

			return h.substr(-2,2) + ':' + m.substr(-2,2) ;

		}

		case Date.FormatTypes.ODBC : {

			var m = '00' + (this.getMonth() + 1) ;

			var d = '00' + this.getDate() ;

			var h = '00' + this.getHours() ;

			var mn = '00' + this.getMinutes() ;

			var s = '00' + this.getSeconds() ;

			return this.getFullYear() + '-' + m.substr(-2,2) + '-' + d.substr(-2,2) + ' ' + h.substr(-2,2) + ':' + mn.substr(-2,2) + ':' + s.substr(-2,2) ;

		}

		case Date.FormatTypes.XSD : {

			var m = '00' + (this.getUTCMonth() + 1) ;

			var d = '00' + this.getUTCDate() ;

			var h = '00' + this.getUTCHours() ;

			var mn = '00' + this.getUTCMinutes() ;

			var s = '00' + this.getUTCSeconds() ;

			return this.getUTCFullYear() + '-' + m.substr(-2,2) + '-' + d.substr(-2,2) + ' ' + h.substr(-2,2) + ':' + mn.substr(-2,2) + ':' + s.substr(-2,2) + 'Z' ;

		} 

		default : return this.toString() ;

	}

} ;



strIsIn = function(str, arr) {

	for (var i = 0; i < arr.length; i++) {

		if (str == arr[i]) return true ;

	}

	return false ;

} ;



function inspectObject(o) {

	var a = [] ;

	for (var p in o) a.push(p) ;

	return a ;

}



function getParentOfObjectByType(obj, parentType) {

	if (obj.parent) {

		if (obj.parent.constructor == parentType) return obj.parent;

		var p = obj.parent ;

		while (p.parent) {

			if (p.parent.constructor == parentType) return p.parent ;

			p = p.parent ;

		}

	}

	return null;

}



//	Translations library

if (!SixApart) var SixApart = {} ;



//	Because of the way the translation deal works, we need to go back after

//	all the translations are done and reset the classid for the translated

//	tags, so that we get the right inspectors to show up.

SixApart.fixClassIdForTranslation = function(){

	if (document.type != "markup") return ;

	//	try setting the class id of one of the agl:translated tags.

	var elmRegExp = new RegExp("<\\u0024(MT[^\\u0024>/ ]*)([^\\u0024>]*)\\u0024>") ;

	var elms = document.documentElement.getElementsByTagName("agl:translated");

	for (var i = 0; i < elms.length; i++) {

		var orig = unescape(elms[i].orig) ;

		var match = elmRegExp.exec(orig) ;

		if (match) elms[i].classid = match[1] ;	//	this should be the tagname.

	}

} ;

			

SixApart.GetAttributesForTranslation = function(unparsed) {

	var attr = [] ;

	if (unparsed && unparsed.length > 0) {

		var attrRegExp = new RegExp('([^= ]*)="([^"]*)"', "g") ;

		var match ;

		var stop = 25 ;

		var i = 1;

		while ((match = attrRegExp.exec(unparsed)) != null) {

			attr.push({

				AttributeName : match[1] ,

				AttributeValue : match[2]

			});

		}

	}

	return attr ;

} ;



/************************************************************

	Usage:

	To define the replacement for ANY MT translated tag 

	(meaning any tag written with <$MT... $>),

	all you need to do is add a property to the following

	object.



	Each property must have the following signature:



	"Property" : function(m){

		return [string];

	}



	"m" is an unparsed attribute string; see MTEntryDate

	below to see how to use it in conjunction with 

	SixApart.GetAttributesForTranslation(m).



	While Adobe says you can insert any kind of HTML you

	want as part of the return string, there seem to be

	some issues with it, so I'd suggest a straight-up

	string, if possible.



	If there is a jsxtranslator tag defined with no matching

	property here, it will default to the tag name itself.

*************************************************************/

SixApart.Translations = {

	MTEntryBody : function(m) {

		return "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum." ;

	} ,

	MTEntryPermalink : function(m) {

		return "aYear/aMonth/aDate/somesortoftitle.html" ;

	} ,

	MTEntryTrackbackData : function(m) {

		return "All of the Trackback Data will be displayed here." ;

	} ,

	MTEntryDate : function(m) {

		var attr = SixApart.GetAttributesForTranslation(m) ;

		if (attr.length > 0) {

			var attrs = [];

			for (var i = 0; i < attr.length; i++) attrs.push(attr[i].AttributeName + "=" + attr[i].AttributeValue);

			return new Date().Format(Date.FormatTypes.ShortDate) + " (" + attrs.join(",") + ")" ;

		} else {

			return new Date().Format(Date.FormatTypes.LongDate) ;

		}

	}

} ;

