var siteObj = new Object();
siteObj["lang"] = "eng";	//default lang set to english

siteObj["getTree"] = new function()
{
	var loc = String(location);
	loc.replace('\\','/');
	var sitePath = loc.split("//")[1];
	var siteSplit = sitePath.split("/");
	var siteSplitIndex = 2;
	this["lang"] = siteSplit[2];
	var tree = new Array();
	for (var i=3; i<siteSplit.length; i++)
		{
			var txt = siteSplit[i].split("#")[0];
			txt = txt.split("_")[0];
			txt = String(txt).replace(".html","");
			txt = String(txt).replace(".htm","");
			tree.push(String(txt));
		}
	return tree;
}

siteObj["getIndex"] = new function()
{

	var loc = String(location);
	loc.replace('\\','/');
	var sitePath = loc.split("//")[1];
	var siteSplit = sitePath.split("/");
	var siteSplitIndex = 2;
	this["lang"] = siteSplit[siteSplitIndex];
	var treeIndex = new Array();
	for (var i=3; i<siteSplit.length; i++)
		{
			var txt = siteSplit[i].split("#")[0];
			var txt1 = txt.split("_");
			var ext = "";
			txt = txt1[0];
			txt = String(txt).replace(".html","");
			txt = String(txt).replace(".htm","");
			if (txt1.length>1)
				{
					ext = txt1[1];
					ext = String(ext).replace(".html","");
					ext = String(ext).replace(".htm","");
				}
			treeIndex.push({index:(i-siteSplitIndex-1), name:String(txt), ext:String(ext)});
		}
	return treeIndex;
}

siteObj["getLang"] = new function()
{
	return this["languages"];
}

function GetParam(name)
{
	var loc = String(location);
	var start=loc.indexOf("?"+name+"=");
	if (start<0) start=loc.indexOf("&"+name+"=");
	if (start<0) return '';
	start += name.length+2;
	var end=loc.indexOf("&",start)-1;
	if (end<0) end=loc.length;
	var result=loc.substring(start,end);
	var result='';
	for(var i=start;i<=end;i++)
		{
			var c=loc.charAt(i);
			result=result+(c=='+'?' ':c);
		}
	return unescape(result);
}

function checkObjByID(s, id)
{
	for (var item in s)
		{
			if (item == id) return 1;
		}
	return 0;
}

function isLastObj(s, id)
{
	var i = null;
	for (var item in s)
		{
			i = item;
		}
	return (id == i);
}

// id - the unique id of each section/subsection
// name - the name of each  section/subsection, to be unique
// title - all langs' title, which stored as a object with diff. lang indexing. (e.g. obj["title"]["tc"] for chinese title, obj["title"]["en"] for english title, define for langs r base on the xml)
// path - all langs' path, which stored as a object with diff. lang indexing.(e.g. obj["path"]["tc"] for chinese path, obj["path"]["en"] for english path, define for langs r base on the xml)
// subSections - object for sub sections(sectionObj)
function sectionObj(id, name, title, path, subSections)
{
  this.id = (id)?id:null;	// section group id - the folder struct which relative to the root htm
  this.name = (name)?name:"";	// section name - may be the folder struct which relative to the root htm
	this.title = (title)?title:new Object();	// section name - may be the folder struct which relative to the root htm
  this.path = (path)?path:new Object();	//	section link path
	this.subSections = (subSections)?subSections:new Object();	// sub sections which belongs to this section
	
	this.getTitleByName = function(nam)
		{
			for (var item in this)
				{
					if (this[item].name == nam) return this[item].title;
				}
			return null;
		}
	
	this.getPathByName = function(nam)
		{
			for (var item in this)
				{
					if (this[item].name == nam) return this[item].path;
				}
			return null;
		}

	
	this.getTitleByID = function(id)
		{
			for (var item in this)
				{
					if (item == id) return this[item].title;
				}
			return null;
		}
	
	this.getPathByID = function(id)
		{
			for (var item in this)
				{
					if (item == id) return this[item].path;
				}
			return null;
		}
	
	this.getSubSectionByID = function(id)
		{
			for (var item in this)
				{
					if (item == id) return (this[item].subSections)?this[item].subSections:null;
				}
			return null;
		}
	
  this.checkSubSectionByID = function(id)	// return the size of this section's subsections
		{
			for (var item in this.subSections)
				{
					if (item == id) return 1;
				}
			return 0;
		}
	
  this.subSectionsSize = function()	// return the size of this section's subsections
		{
			var i = 0;
			for (var item in this.subSections)
				{
					i++;
				}
			return i;
		}
		
}