// Copyright (c) Gate17 System www.gate17.net by Marc Krisnanto. All rights reserved.

var thisUser = {};

function getThisUser ()
{
	var u;
	try
	{
		u = Server.get ('/command?a=qGetThisUser');
		u = eval ('[' + u + '][0]');
	}
	catch (err)
	{
		u =
		{
			id: 0,
			ids: 'guest',
			auth: 0,
			name: 'Guest'
		};
	}
	thisUser = u;
}

var CLASSID = {};		// {108: 'AddressBook' ...}
var CLASSTITLEX = {};	// {108: 'Address Book' ... }
var CLASSTITLE = {};	// {'AddressBook': 'Address Book' ... }

var _CLASSDATA =
{
	  1: ["Users"             , 'Users'],

//	108: ["AddressBook"       , 'Address Book'],
//	112: ["Ad"                , 'Ad'],
//	121: ["Agenda"            , 'Agenda'],
//	126: ["Album"             , 'Album'],
	134: ["Article"           , 'Article'],
//	171: ["Blog"              , 'Blog'],
	177: ["Board"             , 'Board'],
	181: ["Book"              , 'Book'],
	184: ["Bug"               , 'Bug'],
	204: ["Category"          , 'Category'],
//	211: ["Classifieds"       , 'Classifieds'],
//	222: ["Conference"        , 'Conference'],
//	238: ["DataSheet"         , 'Data Sheet'],
//	242: ["Diary"             , 'Diary'],
	248: ["Document"          , 'Document'],
//	258: ["Ecard"             , 'Ecard'],
	266: ["Event"             , 'Event'],
//	274: ["Formula"           , 'Formula'],
//	292: ["Job"               , 'Job'],
//	336: ["Mailbox"           , 'Mail Box'],
//	341: ["Mailist"           , 'Mailing List'],
//	346: ["Manual"            , 'Manual'],
//	351: ["Map"               , 'Map'],
	364: ["Media"             , 'Media'],
	381: ["News"              , 'News'],
	409: ["Poll"              , 'Poll'],
	411: ["ProductPage"       , 'Package'],
//	413: ["Project"           , 'Project'],
//	554: ["Regulation"        , 'Regulation'],
	718: ["Todo"              , 'Todo'],
	727: ["Topic"             , 'Topic'],
/*
	8010: ["Galaxy"           , 'Galaxy'],
	8020: ["Planet"           , 'Planet'],
	8030: ["Continent"        , 'Continent'],
	8040: ["Country"          , 'Country'],
	8050: ["Province"         , 'Province'],
	8060: ["Regency"          , 'Regency'],
	8070: ["City"             , 'City'],
	8075: ["District"         , 'District'],
	8080: ["Village"          , 'Village'],
	8090: ["Sea"              , 'Sea'],
	8100: ["Island"           , 'Island'],
	8110: ["Mountain"         , 'Mountain'],
	8120: ["River"            , 'River'],
	8130: ["Lake"             , 'Lake'],
	8140: ["Beach"            , 'Beach'],
	8150: ["Forest"           , 'Forest'],
	8160: ["Waterfall"        , 'Waterfall'],
	8170: ["Cave"             , 'Cave'],

	100820: ["Airline"        , 'Airline'],
	100830: ["Airport"        , 'Airport'],
	101220: ["AmusementPark"  , 'Amusement Park'],
	101500: ["Apartment"      , 'Apartment'],
	110010: ["Bakery"         , 'Bakery'],
	110020: ["Bank"           , 'Bank'],
	110410: ["BeautySalon"    , 'Beauty Salon'],
	110800: ["Bridge"         , 'Bridge'],
	112020: ["Bus"            , 'Bus'],
	112030: ["BusTerminal"    , 'Bus Terminal'],
	120010: ["Cafe"           , 'Cafe'],
	120020: ["Casino"         , 'Casino'],
	120720: ["Church"         , 'Church'],
	121400: ["Coach"          , 'Coach'],
	121410: ["Company"        , 'Company'],
	121420: ["Consulate"      , 'Consulate'],
	121720: ["Cruise"         , 'Cruise'],
	131720: ["DrugStore"      , 'Drug Store'],
	141200: ["Embassy"        , 'Embassy'],
	142310: ["Exhibition"     , 'Exhibition'],
	150820: ["FitnessCenter"  , 'Fitness Center'],
	151420: ["FoodCourt"      , 'Food Court'],
	151440: ["Fortress"       , 'Fortress'],
	160010: ["Gallery"        , 'Gallery'],
	160020: ["Garden"         , 'Garden'],
	160410: ["GeneralStore"   , 'General Store'],
	161430: ["GolfCourse"     , 'Golf Course'],
	162010: ["GuestHouse"     , 'Guest House'],
	170020: ["Harbor"         , 'Harbor'],
	170410: ["Helicopter"     , 'Helicopter'],
	170420: ["Helipad"        , 'Helipad'],
	171430: ["HomeStay"       , 'Home Stay'],
	171440: ["Hospital"       , 'Hospital'],
	171450: ["Hotel"          , 'Hotel'],
	181320: ["Insurance"      , 'Insurance'],
	210100: ["Library"        , 'Library'],
	210620: ["LightHouse"     , 'Light House'],
	220020: ["Marina"         , 'Marina'],
	220400: ["MeetingRoom"    , 'Meeting Room'],
	221410: ["Monument"       , 'Monument'],
	222020: ["Museum"         , 'Museum'],
	230020: ["NationalPark"   , 'National Park'],
	241110: ["OldBuilding"    , 'Old Building'],
	241700: ["Organization"   , 'Organization'],
	250010: ["Palace"         , 'Palace'],
	250020: ["Park"           , 'Park'],
	250420: ["People"         , 'People'],
	251410: ["PoliceStation"  , 'Police Station'],
	251420: ["PostOffice"     , 'Post Office'],
	252000: ["Pub"            , 'Pub'],
	270010: ["Railway"        , 'Railway'],
	270410: ["Rental"         , 'Rental'],
	270420: ["Resort"         , 'Resort'],
	270430: ["Restaurant"     , 'Restaurant'],
	272010: ["Ruins"          , 'Ruins'],
	280210: ["School"         , 'School'],
	280710: ["Ship"           , 'Ship'],
	280730: ["ShoppingCenter" , 'Shopping Center'],
	280740: ["Shuttle"        , 'Shuttle'],
	281900: ["Stadium"        , 'Stadium'],
	282010: ["Supermarket"    , 'Supermarket'],
	290410: ["Temple"         , 'Temple'],
	290420: ["TennisCourt"    , 'Tennis Court'],
	290430: ["Theater"        , 'Theater'],
	292220: ["Tower"          , 'Tower'],
	291700: ["TrainStation"   , 'Train Station'],
	291720: ["TravelAgent"    , 'Travel Agent'],
	301310: ["University"     , 'University'],
	310810: ["Villa"          , 'Villa']
*/
};


var RELATION =
{
	 1: 'Related to',
	 2: 'Child of',
	 3: 'Located in',
	 4: 'Member of',
	 5: 'Near',
	 6: 'Via',
	 7: 'Works at',
	 8: 'Birth place',
	 9: 'Nationality',
	10: 'Chain is',
	11: 'Venue',
	12: 'Organizer',
	13: 'Division',
	14: 'Item of',
	16: 'Category',
	17: 'Applies to'
};

var AUX =
{
	ORI: 'Origin',
	COP: 'Copyright',

	STT: 'Street address',
	EMA: 'Email',
	URL: 'Website',
	PHO: 'Phone',
	FAX: 'Fax',

	BIR: 'Birth date',
	JOD: 'Division',
	JOP: 'Position',
	NAT: 'Nationality',

	PRF: 'Preference',
	DES: 'Description',
	ORG: 'Organization',
	REM: 'Remarks',
	MIS: 'Miscellaneous',
	VEN: 'Venue',

	NOT: 'Note'
};
	

var AUXSORTED =
[
	'ORI', 'COP',
	'STT', 'EMA', 'URL', 'PHO', 'FAX',
	'BIR', 'JOD', 'JOP', 'NAT',
	'PRF', 'DES', 'ORG', 'REM', 'MIS', 'VEN',
	'NOT'
];


function htmlEscape (s, br)
{
	s = s || '';
	s = ("" + s).replace (/&/g, "&amp;").replace (/"/g, "&quot;").replace (/</g, "&lt;").replace (/>/g, "&gt;");
	if (br)
		return s.replace (/\n/g, "<br>");
	return s;
}


Date.WEEK3  = {0:'Sun', 1:'Mon', 2:'Tue', 3:'Wed', 4:'Thu', 5:'Fri', 6:'Sat'};
Date.MONTH3 = {0:'Jan', 1:'Feb', 2:'Mar', 3:'Apr', 4:'May', 5:'Jun', 6:'Jul', 7:'Aug', 8:'Sep', 9:'Oct', 10:'Nov', 11:'Dec'}
Date.MONTHDAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];


Date.qu2js = function (v)
{
	var x = new Date ();
	x.setTime (v * 1000 + 946684800000 + x.getTimezoneOffset() * 60 * 1000);
	return x;
};


Date.prototype.js2qu = function ()
{
	return parseInt (this.getTime () / 1000) - this.getTimezoneOffset() * 60  - 946684800;
};


Date.prototype.format = function (fmt)
{
	var d = this.getDate ();
	var m = this.getMonth ();
	var y = this.getFullYear ();
	var h = this.getHours();
	var n = this.getMinutes ();
	var s = this.getSeconds ();
	var w = Date.WEEK3 [this.getDay()];

	h = (h < 10) ? "0" + h : h;
	n = (n < 10) ? "0" + n : n;
	s = (s < 10) ? "0" + s : s;

	switch (fmt)
	{
		case "E":
		case "e":
			y = y % 100;
			return d + Date.MONTH3 [m] + (y < 10 ? "0" + y : y);

		case "S":
		case "s":
			y = y % 100;
			return d + Date.MONTH3 [m] + (y < 10 ? "0" + y : y) + " " + h + ":" + n;

		case "n":
		case "N":
			y = y % 100;
			return w + " " + d + Date.MONTH3 [m] + (y < 10 ? "0" + y : y) + " " + h + ":" + n;

		case "l":
		case "L":
			return w + ", " + d + "-" + Date.MONTH3 [m] + "-" + y + " " + h + ":" + n + ":" + s;

		case "F":
		case "f":
			return d + "-" + Date.MONTH3 [m] + "-" + y + " " + h + ":" + n;

		case "G":
		case "g":
			y = y % 100;
			return d + "" + Date.MONTH3 [m] + "" + (y < 10 ? "0" + y : y) + " " + h + ":" + n;

		default: // D d
			return d + "-" + Date.MONTH3 [m] + "-" + y;
	}
};


var definitionInit = function ()
{
	for (var i in _CLASSDATA)
	{
		var x = _CLASSDATA [i];
		var s = x [0];
		CLASSID [i] = s;
		CLASSTITLEX [i] = x [1];
		CLASSTITLE [s] = x [1];
	}
}

definitionInit ();
definitionInit = null;
_CLASSDATA = null;

