//**** Object contructors ****//
function URLArgument()
// URL Argument contructor to parse and return arguments in the page URL
/* Properties
	 		URLArgument.arguments[<name>]
	 Methods
	 		URLArgument.getArgument;
	 		URLArgument.setArgument;
 	 		URLArgument.removeArgument;
*/
{
	// Create methods
	this.getArgument = _getArg;
	this.setArgument = _setArg;
	this.removeArgument = _removeArg;
	this.toString  = _toString;
	// Create properties
	this.arguments   = new Array();

	// Initiation
	var separator = "&";
	var equalsign = "=";
	var infoArray = new Array();
	var cnt, tmp, urlstr;

	// Parse and create the argument list
	urlstr = window.location;
	urlstr = urlstr.search.replace(/%20/g, " ");
	tmp = urlstr.indexOf("?");
	if (tmp != -1) {
		urlstr = urlstr.substring(tmp+1,urlstr.length);
		infoArray = urlstr.split(separator);
	}
	for (cnt=0; cnt<infoArray.length; cnt++) {
		tmp = infoArray[cnt].split(equalsign);
		if (tmp[0] != "")
			this.setArgument(tmp[0],tmp[1]);
	}
	// replace the toString method
	function _toString() {
		var wrkstr = "";
		var once = true;
		for (cnt in this.arguments) {
			if (once) {
				wrkstr += "?";
				once = false;
			}
			wrkstr += this.arguments[cnt].name;
			wrkstr += equalsign;
			wrkstr += this.arguments[cnt].value;
			wrkstr += separator;
		}
		return wrkstr.replace(/ /g, "%20");
	}
	// Defn the getArgument method
	function _getArg(name) {
		if(name in this.arguments)
			return this.arguments[name].value;
		else
			return(null);
	}
	//Defn the setArgument method
	function _setArg(name,value) {
		if(name in this.arguments)
			this.arguments[name].value = value;
		else{
			this.arguments[name] = new Object()
			this.arguments[name].name = name;
			this.arguments[name].value = value;
		 }
	}
	//Defn the removeArgument menthod
	function _removeArg(name) {
		if(name in this.arguments)  this.arguments[name] = null;
	}
	//Return reference to the object
	return this;
} // URLArgument contructor



//**** Functions ****//
function propertyById(id,property,value)
// Replace the image content by id
{
	htmlobj = document.getElementById(id);
  htmlobj.property = value;
}  // propertyById

function mail(element,username,subject)
// create mail details dynamically
{
	domain = "tmmifoundation.org"
	subject = subject.replace(/ /g, "%20");
	linkobj = document.getElementById(element);
	if(subject="")
    linkobj.href = "mailto:" + username + "@" + domain;
	else
    linkobj.href = "mailto:" + username + "@" + domain + "?subject=" + subject;
} //mail

function pg_lastupdate(id,prefixtxt,suffixtxt)
// Get, format and write the file update info - optionally adding prefix & suffix text
{
	//Define and init variables
	var days = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	var mnth = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

	dateObj = new Date(document.lastModified);
	if(dateObj.getYear() < 2000) year = dateObj.getYear()+1900; else year = dateObj.getYear();
	datestr = days[dateObj.getDay()]+" "+dateObj.getDate()+" "+ mnth[dateObj.getMonth()]+" "+year;
	// Insert the page with the file update info
	writeById(id,prefixtxt+datestr+suffixtxt);
}  // pg_lastupdate

function pg_menu_over(id)
// Set the menu "hover" style
{
	htmlobj = document.getElementById(id);
 	htmlobj.style.backgroundColor = "#0099ff";
	htmlobj.style.border = "1px #0000ff solid";
}  // pg_menu_over

function pg_menu_out(id)
// Set the menu "hover" style
{
	htmlobj = document.getElementById(id);
 	htmlobj.style.backgroundColor = "";
	htmlobj.style.border = "";
}  // pg_menu_out

function pg_pagename(id)
// Get, format and write the file update info - optionally adding prefix & suffix text
{
	var pgargs = new URLArgument;
	if(pgargs.getArgument(id) != null && pgargs.getArgument(id) != "")  writeById(id,pgargs.getArgument(id));
}  // pg_lastupdate

function styleById(id,stylename,value)
// Replace the image content by id
{
	htmlobj = document.getElementById(id);
	switch(stylename) {
		case "background-color":
			htmlobj.style.backgroundColor = value;
		case "border":
			htmlobj.style.border = value;
	 }
}  // styleById

function writeById(id,HTMLcontent)
// Write to document replacing the HMTL content by id
{
	htmlobj = document.getElementById(id);
  htmlobj.innerHTML = HTMLcontent;
}  // writeById
