var siteObj = new Object();
siteObj["lang"] = "eng";	//default lang set to english

siteObj["getObj"] = new function(obj, lv)
{
	var tabindex = "";
	for (var i=0; i<lv; i++)
		{
			tabindex += " -----";
		}
	for (var item in obj)
		{
			var subS = obj[item];
			if (typeof(subS) == "undefined") continue;
			if (typeof(subS) == "function") continue;
			if (item == "subSections")
				{
					//alert("sub");
				}			
			tempStr += tabindex + item + " : " + subS;
//			tempStr += "\n";
			tempStr += "<BR>";
			
			if (typeof(subS) == "object") tempCheckObj(subS, lv+1);
		}
}

siteObj["getTreeExt"] = new function()
{
	var loc = String(location);
	loc.replace('\\','/');
	var sitePath = loc.split("//")[1];
	var siteSplit = sitePath.split("/");
	var siteSplitIndex = 1;
	if (loc.indexOf("html_web")!=-1) siteSplitIndex = 2;
	this["lang"] = siteSplit[siteSplitIndex];
	var ext = new Array();
	
	var txt = siteSplit[(siteSplit.length-1)].split("#")[0];
	txt = txt.split("_")[1];
	txt = String(txt).replace(".html","");
	txt = String(txt).replace(".htm","");
	ext.push(String(txt));

	return ext;
}

siteObj["getTree"] = new function()
{
	var loc = String(location);
	loc.replace('\\','/');
	var sitePath = loc.split("//")[1];
	var siteSplit = sitePath.split("/");
	var siteSplitIndex = 1;
	if (loc.indexOf("html_web")!=-1) siteSplitIndex = 2;
	this["lang"] = siteSplit[siteSplitIndex];
	var tree = new Array();
	for (var i=(1+siteSplitIndex); 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];
	sitePath=sitePath.split("?")[0];
	var siteSplit = sitePath.split("/");
	var siteSplitIndex = 1;
	if (loc.indexOf("html_web")!=-1) siteSplitIndex = 2;

	this["lang"] = siteSplit[siteSplitIndex];

	var treeIndex = new Array();

	for (var i=(1+siteSplitIndex); i<siteSplit.length; i++)
		{
			var txt = siteSplit[i].split("#")[0];
			txt = txt.split("_")[0];
			txt = String(txt).replace(".html","");
			txt = String(txt).replace(".htm","");
			txt = String(txt).replace(".php","");
			treeIndex.push({index:(i-siteSplitIndex-1), name:String(txt)});
		}
	return treeIndex;
}

siteObj["getLang"] = new function()
{
	return this["languages"];
}

function changeLang(lan)
{
	var link = location.href;
	link = link.replace("/" + getLang() + "/", "/" + lan + "/");
	window.location.href = link;	
}

function flashLinkTo(link)
{
	if (typeof(showLiteBox)!="undefined")
		{
			showLiteBox(link);
		}
	else
		{
			window.location.href = link;
		}
}

function getLang()
{
	var loc = String(location);
	loc.replace('\\','/');
	var sitePath = loc.split("//")[1];
	var siteSplit = sitePath.split("/");
	var siteSplitIndex = 1;
	if (loc.indexOf("html_web")!=-1) siteSplitIndex = 2;
	this["lang"] = siteSplit[siteSplitIndex];
	var langstr = siteSplit[siteSplitIndex];
	
	return this["lang"];
}

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)
				{
					var o = this.subSections[item];
					if (typeof(o) == "undefined") continue;
					if (typeof(o) == "function") continue;
					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)
				{
					var o = this.subSections[item];
					//if (typeof(o) == "undefined") continue;
					//if (typeof(o) == "function") continue;
					i++;
				}
			return i;
		}
		
}