﻿/* environment detection
	1. cookie is used to store the language information
 */
var Cookie =
{
	Set: function(sName, sValue, expDate)
	{
		document.cookie = document.cookie + ";" + sName + "=" + sValue + ";expires=" + (expDate ? expDate : new Date(2021, 10, 4).toGMTString());
	},
	Read: function(ck)
	{
		var value = ""; var reg = new RegExp("\b" + ck + "=([^;]+);");
		var r = reg.exec(document.cookie); if (r != null) return r[1];
		return null;
	}
};
function SetBrowserInfo()
{
	this.IsIE = false; this.IsFF = false; this.IsSF = false;this.Lang = 'en-us'; this.Version = "0.0.0.0";
	var info=navigator.userAgent;
	var r=new RegExp("MSIE ([0-9.]+)").exec(info);
	if(r!=null) {this.IsIE=true; this.Version=r[1];}
	else 
	{
		r = new RegExp("Firefox/([0-9.]+)").exec(info);
		if(r!=null) {this.IsFF=true; this.Version=r[1];}
		else
		{
			r = new RegExp("Safari/([0-9.]+)").exec(info);
			if(r!=null) {this.IsSF=true; this.Version=r[1];}
		}
	}
	var l = Cookie.Read("Lang");
	if (l) this.Lang = l;
	else
	{
		if (this.IsIE) this.Lang = navigator.userLanguage;
		else this.Lang = navigator.language;
		this.Lang = this.Lang.toLowerCase();
	}
}
var Bi = new SetBrowserInfo();//browser info

/* commonly used basic functions */
function GetParam(ParamName)
{
	var match=new RegExp("[&]|[?]"+ParamName+"=([\d\w]+)").exec(window.location.href);
	return match?match[1]:null;
}
function GBNs(parent,name)//get element by name
{
	if (Bi.IsIE) 
	{
		 var r=new Array();
	     var es=parent.all; var l=es.length;
	     for(var i=0;i<l;i++)
	     {
	    	 if(es[i].getAttribute("name")==name) r.push(es[i]);
	     }
	     return r;
	}
	else
	{
		return Xml.SN(parent,".//*[@name='"+name+"']");
	}
}
function $get(id) { return document.getElementById(id); }
function EE(e){return e.srcElement?e.srcElement:e.target;}
function MousePosition(e)
{
	if (Bi.IsIE) 
	{
	      x = e.clientX + document.documentElement.scrollLeft+ document.body.scrollLeft;
	      y = e.clientY + document.documentElement.scrollTop+ document.body.scrollTop;
	}
	else
	{
	      x = e.clientX + window.scrollX;
	      y = e.clientY + window.scrollY;
	}
	return [x,y];
}
function MaxWindow()
{
	top.window.moveTo(0,0);
	if (Bi.IsIE) 
	{
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers) 
	{
		top.window.outerHeight = screen.availHeight;
		top.window.outerWidth = screen.availWidth;
	}
}
/* example to use this function:
* var r = HttpRequest(page.AspnetPath+"XmlService.aspx", "C="+encodeURIComponent(h));alert(r);
	function state_Change(request)
	{
		if (request.readyState==4)// 4 = "loaded"
		{
		  	if (request.status==200)
		    {
		    
		    }
		  	else
		    {
		    	alert("Problem retrieving XML data");
		    }
		}
	} 
* */
function HttpRequest(url, parameters, XhttpHandler,async) 
{
	if(!async) async=false;//sync
	var http_request;
	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{// set type accordingly to anticipated content type
			http_request.overrideMimeType('text/xml');
		}
	} 
	else if (window.ActiveXObject) 
	{ // IE
		try 
		{
			http_request = new ActiveXObject("MSXML2.XMLHTTP.3.0");
		} 
		catch (e) 
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{alert("cannot create http request object for IE"); return false;}
		}
	}	
	if (!http_request) 
	{
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	if(async)
	{
		http_request.onreadystatechange = function(){XhttpHandler(http_request)};
	}
	var sendstring = url;//alert("sendstring: "+sendstring);//+'?'+parameters;//
	http_request.open('POST', sendstring, async);//set to false means syc
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Connection", "close");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.send(parameters);
	if(!async) 
	{//alert('sync');//alert(http_request.getAllResponseHeaders());alert(http_request.responseText);
		var text=http_request.responseText;//document.write("reponsetext: "+text);
		return text;
	}
}
function FlashPlayer(width, height, back, src, ParentID)
{
	var code;
	if (Bi.IsIE)
	{
		code = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"myMovieName\"><param name=\"movie\" value=\"" + src + "\" /><param name=\"quality\" value=\"high\"/><param name=\"bgcolor\" value=\"" + (back ? back : "#000000") + "\"/></object>";
	}
	else
	{
		code = "<embed src=\"" + src + "\" quality=\"high\" bgcolor=\"" + (back ? back : "#000000") + "\" width=\"" + width + "\" height=\"" + height + "\" name=\"myMovieName\" align=\"\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>";
	}
	$get(ParentID).innerHTML = code;
}

var SizingObjects = new Object();
function ShowSize(id, width, height, zindex,container,left,top)
{//status += 't';
	var SizingObject = new Object(); 
	if (SizingObjects.hasOwnProperty(id)) SizingObject = SizingObjects[id]; else { SizingObjects[id] = SizingObject; }
	if (SizingObject && SizingObject.timer) { window.clearInterval(SizingObject.timer); SizingObject.timer = null; }
	SizingObject.LocationReached = false; SizingObject.SizeReached = false;
	
	var target = $get(id);
	var p = target.parentNode;
	target.style.zIndex = zindex;
	p.style.zIndex = zindex;
	
	SizingObject.target = target;
	SizingObject.p = p;
	SizingObject.w = width;SizingObject.h = height;
	if (width > String.GetIntWithPX(target.style.width)) { SizingObject.stepw = 0.5; } else { SizingObject.stepw = -0.5; }
	if (container)
	{
		container = $get(container); SizingObject.container = container;
		SizingObject.l = left; SizingObject.t = top;//status +='left0='+ target.style.left;
		if (left > String.GetIntWithPX(container.style.left)) { SizingObject.stepl = 0.2; } else { SizingObject.stepl = -0.2; }
		if (top > String.GetIntWithPX(container.style.top)) { SizingObject.stept = 0.2; } else { SizingObject.stept = -0.2; }
	}
	SizingObject.timer = window.setInterval(function(){ShowSizeAStep(id);}, 100);
}
function ShowSizeAStep(id)
{//status += "s";
	var SizingObject = SizingObjects[id]; 
	var target = SizingObject.target; var container = null; if (SizingObject.container) container = SizingObject.container;
	var wc = String.GetIntWithPX(target.style.width) ; wc+= SizingObject.stepw;
	var hc = wc * SizingObject.h / SizingObject.w; //alert(SizingObject.hc);
	var lc, tc;
	if (container)
	{//status += 'con';
		lc = String.GetIntWithPX(container.style.left); lc += SizingObject.stepl; //status += '(' + SizingObject.stepl + ',' + lc + ')';
		tc = String.GetIntWithPX(container.style.top); tc += SizingObject.stept;
	}
	
	if ((SizingObject.stepw > 0 && wc > SizingObject.w) || (SizingObject.stepw < 0 && wc < SizingObject.w))
	{
		wc = SizingObject.w; hc = SizingObject.h;SizingObject.SizeReached = true;
		if (SizingObject.LocationReached) { window.clearInterval(SizingObject.timer); SizingObject.timer = null; }
	}
	else SizingObject.stepw *= 2;
	
	if (container)
	{
		if ((SizingObject.stepl > 0 && lc > SizingObject.l)||(SizingObject.stepl < 0 && lc < SizingObject.l) || (SizingObject.stept> 0 && tc > SizingObject.t) || (SizingObject.stept< 0 && tc < SizingObject.t))
		{//status += 'step1>0';
				lc = SizingObject.l; tc = SizingObject.t; SizingObject.LocationReached = true;
				if (SizingObject.SizeReached) { window.clearInterval(SizingObject.timer); SizingObject.timer = null; }
		} 
		else SizingObject.stepl *= 2;
	}
	
	target.style.width = wc+"px";
	target.style.height = hc + "px";
	SizingObject.p.style.width = target.style.width;
	if (container) { container.style.left = lc + "px"; container.style.top = tc + "px"; }
}
function Direction(id, e)
{
	var p = MousePosition(e);
	var ex = new CTRL.C(id); var w = ex.C.parentNode.clientWidth;
	var p0 = ex.Position(); p[0] -= p0[0]; p[1] -= p0[1];
	if (p[0] > w / 2) return 'next';
	else return 'previous';
}
function ChangeImage(images, id, type)
{//var Game1Images = ['images/products/',0,'1.png','2.png','3.png'];
	if (type == 'next')
	{
		images[1] += 1; if (images[1] > images.length - 3) images[1] = images.length - 3;
	}
	else
	{
		images[1] -= 1; if (images[1] < 0) images[1] = 0;
	}
	var i = $get(id); //alert(images[1]);
	i.src = images[0] + images[images[1] + 2]; //alert(i.src);
}
/* end of commonly used basic functions */

/* Xml Object */
if (!document.ELEMENT_NODE) 
{
	  document.ELEMENT_NODE = 1;
	  document.ATTRIBUTE_NODE = 2;
	  document.TEXT_NODE = 3;
	  document.CDATA_SECTION_NODE = 4;
	  document.ENTITY_REFERENCE_NODE = 5;
	  document.ENTITY_NODE = 6;
	  document.PROCESSING_INSTRUCTION_NODE = 7;
	  document.COMMENT_NODE = 8;
	  document.DOCUMENT_NODE = 9;
	  document.DOCUMENT_TYPE_NODE = 10;
	  document.DOCUMENT_FRAGMENT_NODE = 11;
	  document.NOTATION_NODE = 12;
}
var XmlDoms = new Object();//store xml doms got by url, used as cache
var Xml =
{
	ImportNode: function(node, allChildren, targetDoc)
	{//create the new node, waiting to be inserted to its right place
		if (!targetDoc) targetDoc = document;
		switch (node.nodeType)
		{
			case document.ELEMENT_NODE:
				var attrs = node.attributes;
				var nodes = node.childNodes;
				var newNode = targetDoc.createElement(node.nodeName);
				var i, il;
				if (attrs && attrs.length > 0)
				{
					for (i = 0, il = attrs.length; i < il; i++)
						newNode.setAttribute(attrs[i].nodeName, node.getAttribute(attrs[i].nodeName));
				}
				if (allChildren && nodes && nodes.length > 0)
				{
					for (i = 0, il = nodes.length; i < il; i++)
						newNode.appendChild(Xml.ImportNode(nodes[i], allChildren, targetDoc));
				}
				return newNode;
			case document.TEXT_NODE:
			case document.CDATA_SECTION_NODE:
			case document.COMMENT_NODE:
				return targetDoc.createTextNode(node.nodeValue);
		}
	},
	SD: function(XmlString)
	{		
		var doc=null;
		if (Bi.IsIE)
		{
			doc = new ActiveXObject("MSXML2.DomDocument.3.0");
		}
		else
		{
			doc = document.implementation.createDocument("", "test", null);
		}
		doc.async = false;
		try
		{
			if (Bi.IsIE)
				doc.loadXML(url);
			else
			{
				var Parser = new DOMParser();
				doc = Parser.parseFromString(url, 'text/xml');
			}
		}
		catch (ex)
		{alert('Input Xml String is not valid for xml dom parsing.');}
		return doc;
	},
	/*	 without path, url can be
	* (1) XmlDom
	* (2) xml document string
	* (3) full path with format http://....
	* (4) short path with extension and language
	* (5) short path without extension and language 
	* with path, url is a string of <xml content>, path is the path of it for caching
	* 
	SD: function(url, path)
	{
	if (typeof (url) != 'string') return url; //the url is already xmldom
	url = String.Trim(url);
	if (url == "") return null;

	//create xml object to store the content
	var doc;
	if (Bi.IsIE)
	{
	if (String.EndsWith(url, ".xsl"))
	{
	doc = new ActiveXObject("MSXML2.FreeThreadedDomDocument.3.0");
	}
	else
	{
	doc = new ActiveXObject("MSXML2.DomDocument.3.0");
	}
	doc.setProperty('SelectionLanguage', 'XPath');
	doc.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
	}
	else
	{
	doc = document.implementation.createDocument("", "test", null);
	}
	doc.async = false;

	var FullPathWithoutDatetime;
	if (path || url.substring(0, 1) != '<') FullPathWithoutDatetime = Website.FullPathWithoutDatetime(url);

	if (url.substring(0, 1) == '<')//load dom by string of xml
	{
	if (Bi.IsIE)
	doc.loadXML(url);
	else
	{
	var Parser = new DOMParser();
	doc = Parser.parseFromString(url, 'text/xml');
	}
	}
	else//load dom by its url
	{
	var fullpath = Website.FullPath(url);
	var cacheresult = XmlDoms.Get(FullPathWithoutDatetime);
	if (cacheresult)
	{
	doc = cacheresult; //alert("get from cache : "+FullPathWithoutDatetime);
	return doc;
	}
	else
	{
	doc.load(fullpath); //alert(fullpath);
	}
	}
	//process the override and references in data files
	if (!String.EndsWith(url, ".xsl")) doc = Xml.CheckOverride(doc);
	if (FullPathWithoutDatetime) page.XmlDoms.Push([FullPathWithoutDatetime, doc]);
	return doc;
	},*/
	//check override and references
	CheckOverride: function(doc)
	{
		var refs, ref, i, refed, l, copy;

		var de = doc.documentElement;
		if (de.nodeName == "D" && de.getAttribute("T"))
		{
			var t = de.getAttribute("T");
			t = Xml.SD(t);
			t = Xml.SD(Xml.TS(t)); //not affect the template dom

			//replace language info 
			var Os = Xml.SN(de, "O"); l = Os.length;
			for (i = 0; i < l; i++)
			{
				var O = Os[i];
				var id = O.getAttribute("i");
				var es = Xml.SN(t, "//*[@i='" + id + "']"); var l2 = es.length;
				var AttributeName = O.getAttribute("an");
				for (var j = 0; j < l2; j++)
				{
					var e = es[j];
					if (AttributeName) // to change value of attribute
					{
						e.setAttribute(AttributeName, O.firstChild.nodeValue);
					}
					else // to change the text of the element
						e.firstChild.nodeValue = O.firstChild.nodeValue;
				}
			}

			doc = t;
		}

		//expand references of refi
		refs = Xml.SN(doc, "//*[@refi]"); l = refs.length;
		for (i = 0; i < l; i++)
		{
			ref = refs[i]; var refi = ref.getAttribute('refi');
			refed = Xml.SSN(doc, "//*[@i=" + refi + "]");
			if (refed)
			{
				copy = Xml.ImportNode(refed, true, doc);
				if (ref.getAttribute("i")) copy.setAttribute("i", ref.getAttribute("i"));
				copy.setAttribute("refi", refi);
				ref.parentNode.insertBefore(copy, ref);
				ref.parentNode.removeChild(ref);
			}
		} //if(refl>0) alert(Xml.TS(doc).substr(1000));

		//expand references of RefCommon
		refs = Xml.SN(doc, ".//*[@RefCommon]"); l = refs.length;
		for (i = 0; i < l; i++)
		{
			ref = refs[i];
			var path = ref.getAttribute("RefCommon");
			var common = page.ControlXml();
			refed = Xml.SSN(common, "/*/" + path);
			copy = Xml.ImportNode(refed, true, doc.ownerDocument ? doc.ownerDocument : doc);
			ref.parentNode.insertBefore(copy, ref);
			ref.parentNode.removeChild(ref);
		} //if(l>0) alert(Xml.TS(this.CXml));

		return doc;
	},
	TS: function(XmlNode)
	{
		if (Bi.IsIE)
		{
			return XmlNode.xml;
		}
		else
		{//alert(XmlNode);
			var s = new XMLSerializer();
			return s.serializeToString(XmlNode);
		}
	},
	Transfer: function(doc, xsl, aryParams, returnDom, mode)
	{//alert(Xml.TS(xsl).substring(500));
		if (doc == undefined || doc == null) { alert('XML Document is undefined or null'); alert(returnDom); return; }
		if (xsl == undefined || xsl == null) { alert('XSLT is undefined or null'); return; }

		var processor; //alert("imported");
		if (Bi.IsIE)
		{
			var template = new ActiveXObject("MSXML2.XSLTemplate");
			template.stylesheet = xsl;
			processor = template.createProcessor();
		}
		else
		{
			processor = new XSLTProcessor(); //alert(Xml.TS(xsl));//alert(Xml.TS(doc));
			processor.importStylesheet(xsl); //alert("imported");     
		}

		//set parameters
		if (aryParams)
		{
			for (var i = 0; i < aryParams.length; i++)
			{
				if (Bi.IsIE)
					processor.addParameter(aryParams[i][0], aryParams[i][1]);
				else
					processor.setParameter(null, aryParams[i][0], aryParams[i][1]);
			}
		}
		if (mode)
		{
			if (Bi.IsIE)
				processor.addParameter("Mode", mode);
			else
				processor.setParameter(null, "Mode", mode);
		}

		var newDocument;
		if (Bi.IsIE)
		{
			processor.input = doc;
			processor.transform();
			newDocument = processor.output; //alert(newDocument);
		}
		else
			newDocument = processor.transformToDocument(doc); //alert(Xml.TS(newDocument));

		if (Bi.IsIE)
		{
			if (returnDom) return Xml.SD(newDocument);
			else return newDocument;
		}
		else
		{
			if (returnDom) return newDocument;
			else return Xml.TS(newDocument);
		}
	},
	SSN: function(XmlNode, xpath)
	{
		if (Bi.IsIE)
		{
			return XmlNode.selectSingleNode(xpath);
		}
		else
		{
			var r = Xml.SN(XmlNode, xpath);
			if (r == null || r.length == 0) return null;
			else
			{//alert(Xml.TS(r[0]));
				return r[0];
			}
		}
	},
	SN: function(XmlNode, xpath)
	{
		if (Bi.IsIE)
		{
			return XmlNode.selectNodes(xpath);
		}
		else
		{
			var XmlDom = XmlNode.ownerDocument ? XmlNode.ownerDocument : XmlNode;
			var result = XmlDom.evaluate(xpath, XmlNode, Xml.NamespaceResolver, XPathResult.ANY_TYPE, null);
			var found = [];
			var res;
			while (res = result.iterateNext())
			{
				found.push(res);
			} //alert(found.length);
			return found;
		}
	},
	NamespaceResolver: function(prefix)
	{
		if (prefix == 'xsl')
		{
			return 'http://www.w3.org/1999/XSL/Transform';
		}
		else
		{
			alert("no namespace resolver provided for " + prefix);
			return null;
		}
	}

};


var Event=
{
	  AddEventHandler: function(element,eventName,handler)
	  {//alert("enter add event hander");
	      if(Bi.IsIE)
	      {
	      	element.attachEvent(eventName, handler);            
	      }
	      else
	      {
	      	if(eventName.substring(0,2).toLowerCase()=="on")
	      		eventName=eventName.substring(2);
	      	element.addEventListener(eventName, handler, false);            
	      }
	  },
	  Cancel: function(e)
	  {
		if (e.stopPropagation) 
		{//e.stopPropagation works only in Firefox.
			e.stopPropagation();
			e.preventDefault();
		}
		else
		{//e.cancelBubble is supported by IE - this will kill the bubbling process.
			e.cancelBubble = true;
			e.returnValue = false;
		}
	  }
};

var String = 
{
	ExeJs:function(temp)
	{//exe javascript in the doc
	      var myregexp = new  RegExp("(?:<script[^>]*>)(.*?)(?:</script>)", "ig");
	      var myArray;
	      while ((myArray = myregexp.exec(temp)) != null)
	      {//alert(myArray[1]);
	      	eval(myArray[1]);
	      }
	},
	 Ltrim:function(str, chars) 
	 {
		if(chars) chars = chars || "\\s";
		else chars="\\s";
		return str.replace(new RegExp("^[" + chars + "]+","g"), "");
	},
	Rtrim:function(str, chars) 
	{
		if(chars) chars = chars || "\\s";
		else chars="\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	},
	Trim: function(str, chars) 
	{
		return String.ltrim(String.rtrim(str, chars), chars);
	},
	EndsWith:function(str,ends)
	{
		var l=ends.length;
		return str.substr(str.length-l,l)==ends;			
	},
	StartsWith:function(str,start)
	{
		var l=start.length;
		return str.substr(0,l)==start;			
	},
	YearPre: new Date().getUTCFullYear().toString().substring(0,2),
	GetIntWithPX: function (px)
	{//alert('start getintwithpx');
			if(!px || px=="" ) return 0;
		    var l=px.length;
		    return parseInt(px.substring(0,l-2));
	},
	Radom: function (Max)
	{//return an int
		return Math.ceil(Math.random()*Max);
	},
	GetSixNumberFromDate: function(DateObj)
	{
		var y=DateObj.getFullYear().toString().substring(2,2);
		
		var m=DateObj.getMonth()+1;
		m=m.toString();
		if(m.length==1) m='0'+m;
		
		var d=DateObj.getDate().toString();
		if(d.length==1) d='0'+d;
		
		return y+m+d;
	},
	GetCommonFormatFromDate: function(DateObj)
	{
		var y=DateObj.getFullYear().toString();
		
		var m=DateObj.getMonth()+1;
		m=m.toString();
		
		var d=DateObj.getDate().toString();
		if(d.length==1) d='0'+d;
		
		return m+'/'+d+'/'+y;
	},
	GetDateFromSixNumber: function(SixNumber)
	{
		var Year=parseInt(YearPre+SixNumber.substring(0,2));
		var Month1=SixNumber.substring(2,4);
		if(Month1.substring(0,1)=='0') Month1=Month1.substring(1,2);
		var Month=parseInt(Month1)-1;
		var Day1=SixNumber.substring(4,6);
		if(Day1.substring(0,1)=='0') Day1=Day1.substring(1,2);
		return new Date(Year, Month, parseInt(Day1));
	}
};


var Css=
{
  GetStyleRule: function(type, ClassName,StyleIndex)
  {
  	  var Style = document.styleSheets(StyleIndex?StyleIndex:0);
      var rules=Style.rules;
      var count=rules.length;//alert(count);
      for(i=0;i<count;i++)
      {//alert(rules(i).selectorText);
          	if(rules(i).selectorText==ClassName) {return rules(i);}
      }        
  }
};



var Website=
{
	/* in order to make the code clean, params passed to functions in the short path form
	 * to transform the short form path into full path form, use the function*/
	FullPath:function(url)
	{
		if(!String.endswith(url,'.xml') && !String.endswith(url,'.xsl'))
		{
			url=url+"_"+page.Lang+".xml";
		}
		if(url.substring(0,7)!='http://') url=page.RootPath + url;
		url=url+ "?" +(new Date().getTime());//avoid caching
		return url;
	},
	FullPathWithoutDatetime:function(url)
	{
		if(!String.endswith(url,'.xml') && !String.endswith(url,'.xsl'))
		{
			url=url+"_"+page.Lang+".xml";
		}
		if(url.substring(0,7)!='http://') url=page.RootPath + url;
		return url;
	}
};

var KeyCodes=new Object();
KeyCodes.Enter=13;
KeyCodes.Up=38;
KeyCodes.Down=40;
KeyCodes.F5=116;

/*control.js*/
var CTRL=new Object();
/*three modes of the constructor
 * (1) to create the control: Parent+ControlXsl+XmlData+mode
 * (2) to load the control from existing document object: ID
 * (3) to load the control from parent loadjscontrols: ID+ControlXsl+XmlData, where controlxsl is the CXml
 * (4) to load the control from existing CXml, where  XmlData is the CXml
Parent is the parent of the container of the created element <Parent><div id="container"><div id="id">,
after the control is inited, this.Parent becomes the container DIV
XmlData is various data, for each language, it has sub string like Menu_zh.xml, Menu_en.xml
ControlXsl is changable xsl to transform XmlData into standard control xml data, must has mode
or ControlXsl is the stardard control xml data directly got from parent CXml, must has no mode
*/
CTRL.C=function(ID,Parent,ControlXsl,XmlData,mode)
{
	/*!!this line is used by child controls to invoke base functin, donot misunderstand it!!*/
	if(!ID && !ControlXsl && !XmlData) {return;}
	
	if(!ID && Parent && ControlXsl && XmlData && mode)//mode(1)
	{
		this.Parent=Parent;
		this.Parameters=[];
		this.Xml=Xml.SD(XmlData);//alert(Xml.TS(this.Xml));
		this.ControlXsl=ControlXsl;
		this.CXsl=Xml.SD(ControlXsl);//alert(Xml.TS(this.CXsl));
		this.CXml =Xml.Transfer(this.Xml,this.CXsl,[['Mode',mode]],true);
		this.ID=Xml.SSN(this.CXml,"/*[1]/@id").nodeValue;
	}
	else if(ID  && !Parent && !ControlXsl && !XmlData && !mode)//mode(2)
	{
		this.ID=ID;
	}
	else if(ID  && !Parent && ControlXsl && XmlData && !mode)//mode(3)
	{
		this.ID=ID;
		this.Xml=XmlData;
		this.CXml=ControlXsl;
	}
	else if(!ID  && Parent && !ControlXsl && XmlData && !mode)//mode(4)
	{
		this.Parent=Parent;
		this.CXml=XmlData;//alert(this.CXml.nodeType);//alert(Xml.TS(Xml.SSN(this.CXml,"@id")));
		if(this.CXml.ownerDocument)
			this.ID=Xml.SSN(this.CXml,"@id").nodeValue;
		else this.ID=Xml.SSN(this.CXml,"/*[1]/@id").nodeValue;//if(this.ID=="TopicMusic") alert("parent:"+this.Parent.outerHTML);
	}
	else
	{
		alert("unknown mode for construct a CTRL.C, data="+XmlData+", parent="+this.Parent);
		alert("data:"+Xml.TS(XmlData));
		alert("parent:"+this.Parent.outerHTML);
		return;
	}//if(this.ID=="StarThreadMenu")alert(Xml.TS(this.CXml));
	this.FirstInit=true;
	//even when it's to create the control, exe it to check whether the control has already there
	this.GetExist();//load the object from existing html controls
};
CTRL.C.prototype=
{
    GetExist:function()
    {//alert("try to get this.id: "+this.ID);
		this.C=$get(this.ID);
		if(this.C)
		{//alert("geten this.id: "+this.ID);
			this.Parent=this.C.parentNode;
			this.CC=$get(this.ID+"_ContentContainer");
			if(this.AfterGetExist)//exe child additional actions to get more information
				this.AfterGetExist();
   		}
    },        
    Init:function()
    {	
    	if(this.BeforeInit) this.BeforeInit();
    	
		//do transform to get CXml
    	//if(this.ID=="DishEditionWindow") alert(Xml.TS(this.Xsl));
	    this.Xsl = page.Xsl;//Xml.SD(StaticXslPath);//alert(Xml.TS(this.Xsl));
    	this.HtmlDom =Xml.Transfer(this.CXml,this.Xsl,this.Parameters,true); 
    	//if(this.ID=="TaskList") {var data=Xml.SSN(this.HtmlDom,"//div[@id='TaskList_Data']");alert(Xml.TS(data));}
    	if(this.AfterInit) this.AfterInit();
    	var outerHTML=Xml.TS(this.HtmlDom);
		if(this.C) 
		{
			this.Parent.removeChild(this.C);//alert("removed existing control");
		}
		else if(this.FirstInit) 
		{
			var container=document.createElement("DIV");
			this.Parent.appendChild(container);
			this.Parent=container;//if(this.ID=="StarThreadMenu")alert(this.Parent.innerHTML);
		}
		this.Parent.innerHTML = outerHTML;//if(this.ID=="TaskList") alert($get("TaskList_Data").innerHTML);
		String.ExeJs(outerHTML);
		
		//load the object
		page.CS[this.ID] = this; //if(this.ID=="StarThreadMenu") alert(page.CS.StarThreadMenu);
		this.LoadJsControls();//it doesn't contain the control itself
		this.GetExist();
		this.FirstInit=false;
		
    }, 
	LoadJsControls: function()
	{//alert("CTRL.Page.prototype.LoadPageControls");
		var ChildControlXmls=this.CXml.ownerDocument?Xml.SN(this.CXml, './/*[@id]'):Xml.SN(this.CXml, '/*[1]//*[@id]');
		var l=ChildControlXmls.length; //if(this.ID=="DishEditionWindow") alert(l);
		for(var i=0; i<l; i++)
		{
			var ChildControlXml=ChildControlXmls[i];
			var ChildID=ChildControlXml.getAttribute("id");
			if(!$get(ChildID)) continue; //some element in CXml with id, but will not render at initial
			var ChildControlName = ChildControlXml.nodeName;
			//build the object
			eval("page.CS[ChildID]=new CTRL."+ ChildControlName + "(ChildID,null,ChildControlXml,this.Xml);");
		}
	},
    GCA:function(attributeName)//get the attribute value of the CXml
    {
         return this.CXml.getAttribute(attributeName);
    },
    SetContent:function(htmlString)
    {
         $get(this.ID+"_Output").innerHTML = htmlString;
    },
    FillWithDoc:function(HtmlFragUrl,path)//a file path in xml format with html content
    {//alert(HtmlFragUrl);//alert(Xml.TS(Xml.SD(HtmlFragUrl)));  
    	var doc=Xml.SD(HtmlFragUrl,path);
        page.CurrentBlockDom=doc;
        
        var data=Xml.SSN(doc,"//Data");var p;//remove the Data elements before insert as html
        if(data){p=data.parentNode;p.removeChild(data);}
    	var temp=Xml.TS(doc); //the html
        if(data) //restores the Data elements after the html has been created
        {p.appendChild(data);}
        page.Content.scrollTop=0;
        this.C.innerHTML = temp;//alert(temp);
        String.ExeJs(temp);//alert("after exejs");
    },
    AppendChildDiv:function(id)
    {
		this.CC.innerHTML+="<div id='" + id + "'></div>";
		return $get(id);
    },
    //set the cursor at the end of the input box
    SetCaretPosition: function(elemId, caretPos) 
    {
		var elem; if(elemId) elem= $get(elemId); else elem=this.C;
		if(!caretPos) caretPos=elem.value.length;
		if(elem.createTextRange) 
		{
			var range = elem.createTextRange();
			range.move('character', caretPos);
			range.select();
		}
		else 
		{
			if(elem.selectionStart) 
			{
				elem.focus();
				elem.setSelectionRange(caretPos, caretPos);
			}
			else
				elem.focus();
		}
	},
	ChildIndex: function(Child)
	{
		var siblings=this.C.childNodes; var l=siblings.length;
		for(var i=0;i<l;i++)
		{
			if(siblings[i]==Child) return i;
		}
		return -1;
	},
	/* the position relative to HTML
	 * the difference between IE and gecok is their elements have different offsetParent
	 * for gecok, static elements have body as the offsetParent
	 * for IE, static elements have parentNode as the offsetParent
	 * The consistence of them are they are placed by the offsetParents and left,top settings
	 * so we can get position of both of them by searching offsetParents*/
	Position: function()
	{//alert(this.ID);
		var obj = this.C;
		var curleft =0;var curtop = 0;
		do 
		{
			if(!obj.offsetParent) break;
			//alert(obj.tagName+": "+obj.innerHTML);
			curleft += obj.offsetLeft;
			curleft -= obj.scrollLeft; 
			curtop += obj.offsetTop;
			curtop -= obj.scrollTop; 
		} 
		while (obj = obj.offsetParent);
		//alert([curleft,curtop]);
		return [curleft,curtop];
	},
	/* when setting position, follow this way so that the offsetParents of the element can be properly dealt with*/
	SetPosition: function(NewPosition)
	{//alert("set position, new pos="+ NewPosition);
		var NowPosition=this.Position();
		var nowleft=String.GetIntWithPX(this.C.style.left);
		this.C.style.left = (nowleft + NewPosition[0]-NowPosition[0])+"px"; 
		var nowtop=String.GetIntWithPX(this.C.style.top);
		this.C.style.top = (nowtop + NewPosition[1]-NowPosition[1])+"px";
		//alert([this.C.style.left,this.C.style.top]);
	},
	/* this function is assumed that the Helper and Main are in the same parent node
	 * for gecok, both the main and help are with offsetParent BODY, so get the position directly
	 * for IE, absolute positioned elements are with offsetParent HTML, 
	 * 			default(static) positioned elements are with offsetParent of parentNode.
	 * so for IE, we need to get the main positon relative to HTML, then give the position to help
	 * and for nested absolute positioned elements, we need to count the parent absolute elements*/
	DisplayHelper:function(HelperID)
	{//alert('enter DisplayHelper');
		this.Help=new CTRL.C(HelperID);	
		this.Help.C.style.display="block";
		var p=this.Position();//position of main
		var p2;
		p2=[p[0],p[1]+this.C.offsetHeight];
		this.Help.SetPosition(p2);
	},
	DisplayRightHelper:function(HelperID,StaticDisplay)
	{//alert('good');
		this.Help=new CTRL.C(HelperID);	
		this.Help.C.style.display=StaticDisplay;	
		var p=this.Position();//position of main
		var p2=[p[0]+this.C.offsetWidth , p[1]]; //alert(p2);
		this.Help.SetPosition(p2);
	},
	ExpandCollapse: function()
	{
		var e=this.C;//alert(e.outerHTML);
		var SmallSize=this.SmallSize;
		var BigSize=this.BigSize;
		if(e.style.display=="inline")
		{
			e.style.display="block";
			e.style.width=BigSize[0]+"px";
			e.style.height=BigSize[1]+"px";
		}
		else
		{
			e.style.display="inline";
			e.style.width=SmallSize[0]+"px";
			e.style.height=SmallSize[1]+"px";
		}
	},
	Hide: function()
	{
		this.C.style.display='none';
	},
	Display: function()
	{
		this.C.style.display='block';
	},
	Zoom: function()
	{//alert(this.Object.style.height);return;//this.ShowProperties("test");return;
		try{clearTimeout(this.Timer);}catch(e){}
		try{clearInterval(this.Timer);}catch(e){}
		var h=String.GetIntWithPX(this.C.style.height);
		page[this.ID]=this;
		if(h==this.maxHeight) 
		{
			//this.Object.style.height='26px';
			eval("this.Timer=setInterval(function(){page."+this.ID+".ZoomStep(-10)},100);");
			this.Resizer.src="../Images/zoom-in.png";
		} 
		else if(h==this.minHeight) 
		{
			eval("this.Timer=setInterval(function(){page."+this.ID+".ZoomStep(10)},100);");
			this.Resizer.src="../Images/zoom-out.png";
		}
	},
	ZoomStep: function(size)
	{
		var h=String.GetIntWithPX(this.C.style.height);h+=size;
		if((size>0 && h<=this.maxHeight)||(size<0 && h>=this.minHeight)) this.C.style.height=h+"px";
		else clearInterval(this.Timer);
	},
	HideDisplay: function(ControllerID,OpenImage,CloseImage)//open is +, close is -
	{
		var Controller=$get(ControllerID);//this.ShowProperties("test");return;
		if(this.C.style && this.C.style.display=="none") 
		{
			this.C.style.display="block";
			Controller.src="../Images/"+CloseImage;
		} 
		else 
		{
			this.C.style.display="none";
			Controller.src="../Images/"+OpenImage;
		}
	},
	//whether a child element of the specified parent
	IsChildOf: function(parent)
	{//alert('IsChildInParent');
		var child=this.C;
		var count=0;
		while(child.tagName!='BODY' && count<100)
		{
			if(child==parent) return true;
			child=child.parentNode;
			if(child==null) return false;
			count++;
		}
		return false;
	},
	IsParentOf: function(child)
	{//alert('IsChildInParent');
		if(child==null) return false;
		
		var parent=this.C;
		var count=0;
		while(child.tagName!='BODY' && count<100)
		{
			if(child==parent) return true;
			child=child.parentNode;
			if(child==null) return false;
			count++;
		}
		return false;
	},
	IsChildInParentStyle: function(child,ParentStyleClassName)
	{//alert('IsChildInParent');
		var count=0;
		while(child.tagName!='BODY' && count<100)
		{
			if(child.className.indexOf(ParentStyleClassName)>-1) return true;
			child=child.parentNode;
			count++;
		}
		return false;
	},
	GetParentByStyle: function(child,ParentStyleClassName)
	{//alert('IsChildInParent');
		var count=0;
		while(child.tagName!='BODY' && count<100)
		{
			if(child.className.indexOf(ParentStyleClassName)>-1) return child;
			child=child.parentNode;
			count++;
		}
		return null;
	},
	SetDrag: function(MouseMoveHandler)//attach event handler to mousedown event, event handler must be abc(e) of this object
	{//alert("SetDragMove: "+this.ID);
		var functionstring="function(event){page.CS['"+this.ID+"'].MouseDown(event,'"+MouseMoveHandler+"');}";
		eval("Event.AddEventHandler(this.C,'onmousedown', "+functionstring+");");
	},
	MouseDown: function(e,MouseMoveHandler) 
	{
		Event.Cancel(e);
		this.CursorStart =MousePosition(e);
		if(!this.DragEventsAttached)
		{
		    var functionstring="function(event){page.CS['"+this.ID+"'].MouseMove(event,'"+MouseMoveHandler+"');}";
		  	eval("Event.AddEventHandler(document,'onmousemove', "+functionstring+");");
		  	functionstring="function(event){page.CS['"+this.ID+"'].MouseUp();}";
			eval("Event.AddEventHandler(document,'onmouseup', "+functionstring+");");
			this.DragEventsAttached=true;
		}
		this.DragMoveEnabled=true;//document.title+="true ";//capture the mousemove event
	},
	MouseMove: function(e, MouseMoveCaseHandler)//mouse move handler
	{//alert("SetDragMove: "+this.ID);
		Event.Cancel(e);
		if(!this.DragMoveEnabled) return;//after mousup, the event handler cannot be removed, so use this flag		
		if(this.MoveLock) return;this.MoveLock=true;//if the previous handler haven't completed, ignore the event
		var CurrentMousePosition=MousePosition(e);
		this.MoveX=CurrentMousePosition[0] - this.CursorStart[0];
		this.MoveY=CurrentMousePosition[1] - this.CursorStart[1];
		eval("this."+MouseMoveCaseHandler+"();");
		this.CursorStart=CurrentMousePosition;
		this.MoveLock=false;//release the lock
	},
	MouseUp: function() 
	{//document.title+="false ";
		this.DragMoveEnabled=false;
	},
	SetDragMove: function(ElementToMove)//attach event handler to mousedown event
	{//alert("SetDragMove: "+this.ID);
		this.MoveControl=ElementToMove;//alert(ElementToMove.C.innerHTML);function(){}
		var functionstring="function(event){page.CS."+this.ID+".DragStart(event);}";
		eval("Event.AddEventHandler(this.C,'onmousedown', "+functionstring+");");
	},
	ResizePage: function()//attach event handler to mousedown event
	{
		page.SetSize(page.Left.offsetWidth+this.MoveX);
	},
	DragStart: function(e) 
	{//alert("DragStart");// Save starting positions of cursor and element.
		Event.Cancel(e);
		this.MoveLock=false;
		this.CursorStart =MousePosition(e);
	    //alert(this.CursorStart[0]+" "+this.CursorStart[1]);
	    this.StartPosition=this.MoveControl.Position();
	    //alert(this.StartPosition[0]+" "+this.StartPosition[1]);
	    var zIndex=this.MoveControl.C.style.zIndex? this.MoveControl.C.style.zIndex: 0;
	    this.MoveControl.C.style.zIndex = ++zIndex;
	    // Capture mousemove and mouseup events on the page.
	    this.DragMoveEnabled=true;
	    var functionstring="function(event){page.CS."+this.ID+".DragGo(event);}";
	  	eval("Event.AddEventHandler(document,'onmousemove', "+functionstring+");");
	  	functionstring="function(){page.CS."+this.ID+".DragStop();}";
		eval("Event.AddEventHandler(document,'onmouseup', "+functionstring+");");
	},
	DragGo: function(e) 
	{//alert("GragGo");
		Event.Cancel(e);
		if(this.MoveLock) return;
		this.MoveLock=true;
		if(!this.DragMoveEnabled)return;
		var CurrentMousePosition=MousePosition(e);
		// Move drag element by the same amount the cursor has moved.
		var left=this.StartPosition[0] + CurrentMousePosition[0] - this.CursorStart[0];
		//left=left>(page.WholeWidth-this.C.clientWidth)? (page.WholeWidth-this.C.clientWidth):left;	
		this.MoveControl.C.style.left = left + "px";
		var top=this.StartPosition[1] + CurrentMousePosition[1] - this.CursorStart[1];
		//top=top>(page.WholeHeight-this.C.clientHeight)? (page.WholeHeight-this.C.clientHeight):top;  
		//alert("offsetheight:"+this.C.offsetHeight);//alert(top+":"+(page.WholeHeight-this.C.offsetHeight));	
		this.MoveControl.C.style.top  = top + "px";
		page.SetSize();
		this.MoveLock=false;
	},
	DragStop: function(e) 
	{// Stop capturing mousemove and mouseup events.
		this.DragMoveEnabled=false;
	}
};


CTRL.Pairs=function()
{
	this.Content=new Array();
};
CTRL.Pairs.prototype=
{
    Push:function(object)
    {
		this.Content.push(object);
    },
    Get:function(first)
    {
		var l=this.Content.length;
		for(var i=0;i<l;i++)
		{
			if(this.Content[i][0]==first) 
			{
				return this.Content[i][1];
			}
			//else{alert(this.Content[i][0]+":"+first);}
		}
		return null;
    }
}


/*controls.js*/
CTRL.Text = function(ID,Parent,ControlXsl,XmlData,mode)
{//alert("new window");//return;
	CTRL.C.call(this, ID,Parent,ControlXsl,XmlData,mode);
};
CTRL.Text.prototype = new CTRL.C();
CTRL.Text.prototype.constructor = CTRL.Text;


CTRL.PhotoPlayer = function(ImgID,ParentPath,Photos)
{
	this.Photos=Photos;
	this.CurrentIndex=0;
	this.Image=$get(ImgID);
	this.ImageParentPath=ParentPath; 
	if(page.PhotoPlayers[ImgID]) clearInterval(page.PhotoPlayers[ImgID].Timer);
	page.PhotoPlayers[ImgID]=this;
	this.Timer = setInterval(function() { page.PhotoPlayers[ImgID].DisplayPhoto(); }, 3000); 
};
CTRL.PhotoPlayer.prototype.DisplayPhoto=function()
{//alert(this.CurrentIndex);
	this.Image.src=this.ImageParentPath+this.Photos[this.CurrentIndex];
	this.CurrentIndex++;
	if(this.CurrentIndex>=this.Photos.length) this.CurrentIndex=0;
};



CTRL.MediaPlayer=function(ID,Parent,ControlXsl,XmlData,mode)
{//alert("new window");//return;
	CTRL.C.call(this, ID,Parent,ControlXsl,XmlData,mode);
};
CTRL.MediaPlayer.CreatePlayer=function(ListID,PlayerID,ParentID)
{
	var data;
	if(ListID) data=Xml.SSN(page.CS[ListID].CXml,"//*[@id='"+PlayerID+"']");
	else 
	{
		data=Xml.SD(page.Blocks[page.CurrentBlockID]);//falert(Xml.TS(data));
		data=Xml.SSN(data,"//*[@id='"+PlayerID+"']");
		
	}
	var p=$get(ParentID);
	var TopMusic=new CTRL.MediaPlayer(null,p,null,data); 
	TopMusic.Init();//alert(TopMusic.C.innerHTML);
};
CTRL.MediaPlayer.prototype = new CTRL.C();
CTRL.MediaPlayer.prototype.constructor = CTRL.MediaPlayer;
CTRL.MediaPlayer.prototype.AfterInit= function()
{
	if(Bi.IsIE)
	{
		var o=Xml.SSN(this.HtmlDom,".//OBJECT");
		o.setAttribute('classid',"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6");
		o.removeAttribute('data');
		o.removeAttribute('type');
		var pu=this.HtmlDom.createElement("param");
		o.appendChild(pu);
		pu.setAttribute("name","url");
		pu.setAttribute("value",Xml.SSN(this.CXml,"@mediaPath").nodeValue);
	}
};
CTRL.MediaPlayer.prototype.AfterGetExist = function()
{//alert("window AfterGetExist this.ID= "+this.ID);
	//this.Controller=$get(this.ID+"_C");
	this.Object=$get(this.ID+"_Object");
	this.Resizer=$get(this.ID+"_Shape");
	//eval("this.Timer=setTimeout(function(){page.CS."+this.ID+".Zoom()},10000);");
};
CTRL.MediaPlayer.prototype.ControlDisplay=function(ControllerID)//control whether to display
{
	this.Controller=$get(ControllerID);//this.ShowProperties("test");return;
	if(String.endswith(this.Controller.src,'zoom-in.png')) 
	{
		this.C.style.visibility='visible';
		this.C.style.height='auto';
		this.Controller.src="../Images/zoom-out.png";
	} 
	else 
	{
		this.C.style.visibility='hidden';
		this.C.style.height='1px';
		this.Controller.src="../Images/zoom-in.png";
	}
};
CTRL.MediaPlayer.prototype.ControlPlay=function(ControllerID)//control whether to display
{//alert("control play");
	this.Controller=$get(ControllerID);//this.ShowProperties("test");return;
	if(String.endswith(this.Controller.src,'audio-volume-medium.png')) 
	{//alert("to play");
		this.Controller.src="../Images/window-close.png";
		try{this.Object.play();}catch(e)//movie player
		{
			try{this.Object.object.controls.play();}catch(e)//media player
			{
				this.Init();//media player in firefox
			}
		}
		
	} 
	else 
	{//alert("to stop "+this.Controller.src);
		this.Controller.src="../Images/audio-volume-medium.png";
		try{this.Object.pause();}catch(e)//movie player
		{
			try{this.Object.object.controls.pause();}catch(e)//media player
			{
				this.Object.parentNode.removeChild(this.Object);//media player in firefox
			}
		}
		
	}
};
CTRL.MediaPlayer.prototype.ShowProperties=function(displayId)
{
	var ps='';var o=this.Object;
	for(var p in o)
	{
		try
		{
			ps+="<span style='color:red'>"+p+"</span>:"+o[p]+"<br/>";
		}
		catch(e)
		{
			//ps+="<span style='color:green'>"+p+"</span>:"+e+"<br/>";
		}
	}
	var test=$get(displayId);
	test.innerHTML=ps;return;
};

CTRL.Window = function(ID,Parent,ControlXsl,XmlData,mode)
{//alert("new window");//return;
	CTRL.C.call(this, ID,Parent,ControlXsl,XmlData,mode);
	this.Closed=false;
};
CTRL.Window.prototype = new CTRL.C();
CTRL.Window.prototype.constructor = CTRL.Window;
CTRL.Window.prototype.AfterGetExist = function()
{//alert("window AfterGetExist this.ID= "+this.ID);
	this.Output = $get(this.ID+"_Output");
	this.TitleBar = new CTRL.C(this.ID+"_Title");
	//alert("this.TitleBar.innerHTML: "+this.TitleBar.innerHTML);
	page.CS[this.TitleBar.ID]=this.TitleBar;//alert(this.C.innerHTML);
	this.TitleBar.SetDragMove(this);	
};
CTRL.Window.prototype.Close = function()
{//alert("after init");
	this.Parent.removeChild(this.C);	
	this.Closed=true;
};



CTRL.List = function(ID,Parent,ControlXsl,XmlData,mode)
{//alert("new window");//return;
	CTRL.C.call(this, ID,Parent,ControlXsl,XmlData,mode);//	alert(Xml.TS(this.CXml));
	
	/*this.ListHeight=this.C.offsetHeight;
	this.CurrentY=0;
	this.MaxHeigth = 200;
	this.ItemHeight=22;*/
};
CTRL.List.prototype = new CTRL.C();
CTRL.List.prototype.constructor = CTRL.List;
CTRL.List.prototype.BeforeInit = function()
{
	if(!this.FirstInit && this.Mode=="Complex")
	{
		var s=this.SearchToolBar;
		var SelectedNames=this.Category.GetSelectedNames();//alert(SelectedNames);
		var keys=s.Input.value.replace(' ','|')+'|';//alert(keys);
		this.Parameters=this.Parameters.concat([['Key',keys],['SortColumnName',s.SortName],['SortOrder',s.SortOrder],
		                        ['Types',SelectedNames],['SortType',s.SortType]]);
		//alert(this.Parameters);
	}
};
CTRL.List.prototype.AfterGetExist = function()
{
	if(this.FirstInit)
	{//alert("after get exist on first init");
		if(Xml.SSN(this.CXml,"/List/Menu/@id")) 
			this.Category=page.CS[Xml.SSN(this.CXml,"/List/Menu/@id").nodeValue];
		if(Xml.SSN(this.CXml,"/List/SearchToolBar/@id")) 
		{	
			this.SearchToolBar=page.CS[Xml.SSN(this.CXml,"/List/SearchToolBar/@id").nodeValue];
			//alert(Xml.SSN(this.CXml,"/List/SearchToolBar/@id").nodeValue);
		}
		if(this.Category && this.SearchToolBar)
		{
			this.Mode="Complex";
			if(Xml.SSN(this.CXml,"/List/@MultiView"))
			{
				this.MultiView=true;
				this.View="简明视图";
				this.ShortView(true);
			}
		}
		else 
		{
			this.Mode="Simple";
		}
	}
	this.Right=$get(this.ID+"_Right");
	this.Data=$get(this.ID+"_Data");
};
CTRL.List.prototype.SetHeight=function()
{
	if(this.C.childNodes.length * this.ItemHeight < this.MaxHeigth) 
		this.C.style.height=(this.C.childNodes.length * this.ItemHeight)+"px";
	else this.C.style.height = "200px";
};
//ListID can be null when it's self
CTRL.List.prototype.Select=function(event)
{//alert("CTRL.List.prototype.Select");
	if(this.C.childNodes.length == 0) return;
	if(!this.SelectedItem) 
	{//alert("no selecteditem");
		this.SelectedItem=this.C.childNodes[0];
	}
	else
	{//alert(event.keyCode);
		this.SelectedItem.className="UnSelectedListItem";
		if(event.keyCode==KeyCodes.Up || event.keyCode==KeyCodes.Down)//keyboard
		{
			if(event.keyCode==KeyCodes.Up && this.SelectedItem.previousSibling)
			{
				this.SelectedItem=this.SelectedItem.previousSibling;
			}	
			else if(event.keyCode==KeyCodes.Down && this.SelectedItem.nextSibling)
			{
				this.SelectedItem=this.SelectedItem.nextSibling;
			}	
			this.CurrentY=this.ChildIndex(this.SelectedItem) * this.ItemHeight;
			if(this.CurrentY>70)
				this.C.scrollTop=this.CurrentY - 4*this.ItemHeight;
		}
		else if(EventElement(event).parentElement==this.C)//mouseover
		{
			this.SelectedItem=EventElement(event);
		}	
	}
	this.SelectedItem.className="SelectedListItem";
};
CTRL.List.prototype.Sort = function(SortColumnName, SortType, e)
{//alert(e);
	var s=this.SearchToolBar; var img=s.SortImage;//alert(EE(e).nextSibling);
	if(EE(e).nextSibling!=img)
	{//alert("different sort column");
		s.SortOrder="ascending";
		EE(e).parentNode.insertBefore(img,EE(e).nextSibling);
	}
	else
	{//alert("same sort column");
	    if(img.src.indexOf('up.png')>-1)
        {
	    	s.SortOrder='descending';                                               
        }
        else
        {
        	s.SortOrder="ascending";                      
        } 
    }
	if(s.SortOrder=='descending')
	{
		img.src=img.src.replace('up.png','down.png');
	}
	else 
		img.src=img.src.replace('down.png','up.png');
	
	s.SortName = SortColumnName;
	s.SortType = SortType;//return;
	this.RefreshList();
};
CTRL.List.prototype.RefreshList=function()
{
	this.Parameters=[];
	this.Parameters.push(["Mode","List"]);
	this.BeforeInit();
	var outerHTML =Xml.Transfer(this.CXml,this.Xsl,this.Parameters); //alert(outerHTML);
	this.Data.innerHTML=outerHTML;
	String.ExeJs(outerHTML);
};
/*when both params are null, it means select all or deselect all
 * position is the index in the category 
 * when it's adding additional checkbox, multipleTypes is true*/
CTRL.List.prototype.SelectByCategoryNames = function(position, multipleTypes,e)
{
	this.SearchToolBar.Input.value="";
	if(position || multipleTypes)
	{
		if(!multipleTypes)
		{
			this.Category.CheckAll(true,false);//uncheck all
			this.Category.CheckBoxs[position-1].checked = true;//check the one
			this.Category.SelectAll.checked = false;//uncheck select all box
		}
	}
	else 
		this.Category.CheckAll();//select all or deselect all
	this.RefreshList();
	if(e) e.stopPropagation();
};
CTRL.List.prototype.Search = function()
{//alert("search");
	//this.Category.CheckAll(true,true);
	this.RefreshList();
};
//when user click the + of a item, Image is set, without set
//when user click view, Image and set are both set
//when added a new item, ItemID is set
CTRL.List.prototype.Expand = function(Image,set)
{//alert("Expand");
	var Item=Image.parentNode.parentNode;
	if((set && set=="open") || (!set && Image.src.indexOf("list-add")>-1)) 
	{
		Image.src=Image.src.replace("list-add","list-remove");
		Item.childNodes[1].style.display='';
		Item.style.padding="";
	}
	else if((set && set=="close") || (!set && Image.src.indexOf("list-remove")>-1)) 
	{
		Image.src=Image.src.replace("list-remove","list-add");
		Item.childNodes[1].style.display='none';
		Item.style.paddingBottom="0";
		Item.style.paddingTop="0";
	}	
};
CTRL.List.prototype.ShortView = function(keep)
{//alert("shortview");
	if(!keep) this.View=this.SearchToolBar.ViewSpan.innerHTML;
	var ts=this.C.childNodes; var c=ts.length;//alert(c);
	if(this.View=="简明视图") 
	{
		this.SearchToolBar.ViewSpan.innerHTML="详细视图";
		for(var i=0;i<c;i++)
		{
			if(this.IsFirst && i==0){this.IsFirst=false;continue;}
			this.Expand(ts[i].firstChild.firstChild,'close');
		}
	}
	else 
	{
		this.SearchToolBar.ViewSpan.innerHTML="简明视图";
		for(var i=0;i<c;i++)
		{
			this.Expand(ts[i].firstChild.firstChild,'open');
		}
	}
	
};
CTRL.List.prototype.ShowNewItem = function(NewItemDataID)
{
	this.Init();//refresh list 
	var ItemID=this.ID+"_"+NewItemDataID;
	this.C.insertBefore($get(ItemID),this.C.firstChild);
	//alert(Xml.TS(DishList.C.firstChild));alert(Xml.TS(DishList.C.firstChild.firstChild));
	this.Expand(this.C.firstChild.firstChild.firstChild,"open");
};


CTRL.Menu = function(ID,Parent,ControlXsl,XmlData,mode)
{//alert("Edition");//return;
	CTRL.C.call(this, ID,Parent,ControlXsl,XmlData,mode);
	this.IsThread=Xml.SSN(this.CXml,"/Menu/@thread")?true:false;//alert(this.IsThread);
	var ListID=Xml.SSN(this.CXml,"@ListID");if(ListID) {this.ListID=ListID.nodeValue;}//else{alert(Xml.TS(this.CXml));}
};
CTRL.Menu.prototype = new CTRL.C();
CTRL.Menu.prototype.constructor = CTRL.Menu;
CTRL.Menu.prototype.AfterGetExist=function()
{
	this.Body=$get(this.ID+"_Body");
	if(this.Body) this.CheckBoxs=this.Body.getElementsByTagName("INPUT");
	this.SelectAll=$get(this.ID+"_SelectAll");
};
CTRL.Menu.prototype.MenuClick=function(args)
{//alert(args);
	if(this.ListID)	page.CS[this.ListID].SelectByCategoryNames(args[0]);
};
CTRL.Menu.prototype.CheckAll=function(set,setvalue)
{
	var value=set?setvalue:this.SelectAll.checked;//it can be used to set also	
	var c=this.CheckBoxs.length;
	for(var i=0;i<c;i++)
	{
		var Input=this.CheckBoxs[i];
		Input.checked=value;
	}	
	if(set) this.SelectAll.checked=setvalue;
};
CTRL.Menu.prototype.GetSelectedNames = function()
{
	var c=this.CheckBoxs.length;
	var Names="";
	for(var i=0; i<	c; i++)
	{
		var b=this.CheckBoxs[i];
		if(!b.checked) continue;
		var t=b.previousSibling;
		if(!t.tagName) t=t.previousSibling;
		Names = Names + t.innerHTML + "|";
	}
	return Names;
};
CTRL.Menu.prototype.GetMenuItemText = function(MenuItemID)
{
	return Xml.SSN(this.Xml,"//*[@i='"+MenuItemID+"']/@t").nodeValue+"[MenuItemID="+MenuItemID+"]";
};
CTRL.Menu.prototype.DropDown=function(HelperID,NotCheckOn,CurrentItemID)
{
	this.CurrentItem=$get(CurrentItemID);
	if(!NotCheckOn)
	{if(!this.On) return;}
	this.SetSelectedObjects(HelperID);
	this.On=true;
};
CTRL.Menu.prototype.RightPop=function(HelperID,CurrentItemID)
{
	this.CurrentItem=$get(CurrentItemID);
	this.SetSelectedObjects(HelperID);
};
/* CurrentItemID is the block on which the click event is fired
 * CurrentMenuID is the menu for CurrentItem, CurrentMenuID is null if CurrentItem is leaf
 * CheckOn is null when CurrentItem is not top menus */
CTRL.Menu.prototype.SelectItem=function(CurrentItemID,CurrentMenuID, CheckOn)
{//alert("menu SelectItem");
	if(CheckOn && !this.On) {return;}
	this.Close();//alert("closed");
	
	//set new pathes
	this.SelectedMenus=new Array();
	this.SelectedItems=new Array();
	if(CurrentMenuID && $get(CurrentMenuID)) 
		this.SelectedMenus.push($get(CurrentMenuID));//the first menu is the menu of the item onclick
	else this.SelectedMenus.push(null);//when the item onclick if the leaf, the menu is null
	this.CurrentItem=$get(CurrentItemID);
	this.SelectedItems.push(this.CurrentItem);//the first item is the one onclick
	var Temp=this.CurrentItem; var c=0;
	while(Temp.parentNode.id!=this.Body.id && c<100)
	{
		Temp=Temp.parentNode;
		this.SelectedMenus.push(Temp);
		this.SelectedItems.push(Temp.previousSibling);
	}if(c>=100) alert("SelectItem c ="+c);
	
	//display menus
	var l=this.SelectedItems.length;
	var MainID=this.SelectedItems[l-1].id;//the top menu item;
	var main=new CTRL.C(MainID);
	if(this.SelectedMenus[l-1])
	{
		var HelperID=this.SelectedMenus[l-1].id;//top menu item's menu
		main.DisplayHelper(HelperID); //alert(main.C.innerHTML);//return;	
		for(var i=l-2;i>=0;i--)
		{
			MainID=this.SelectedItems[i].id;
			if(this.SelectedMenus[i])
			{
				HelperID=this.SelectedMenus[i].id;
				main=new CTRL.C(MainID);
				main.DisplayRightHelper(HelperID,"block");
			}
		}
	}//alert("menu displayed");
	//display items
	for(var i=0;i<l;i++)
	{//alert("this.SelectedItems[i].className: "+this.SelectedItems[i].className);
		var si=this.SelectedItems[i];
		si.className=si.className.replace("UnSelectedMenuItem","SelectedMenuItem");
	}//alert("items displayed");
	
	this.On=true;//alert("end of selectitem");
};
/* hide all the sub menus, and unselect all the menu items*/
CTRL.Menu.prototype.Close=function(CheckNext,CheckMouseStatus)
{//alert("enter close");
	if(CheckMouseStatus){if(this.MouseStatus!='out')return;}
	if(CheckNext)
	{ //document.title=this.MouseStatus;return;(), clearTimeout()
		if(this.TimerClose) clearTimeout(this.TimerClose);
		eval("this.TimerClose = setTimeout(function(){page.CS."+this.ID+".Close(false,true);}, 500); ");
		return;
	}
	if(this.SelectedMenus)
	{
		var sm=this.SelectedMenus;
		var l=sm.length;
		for(var i=0;i<l;i++)
		{
			if(sm[i]) sm[i].style.display="none";
		}
	}
	if(this.SelectedItems)
	{
		var si=this.SelectedItems;
		var l=si.length;
		for(var i=0;i<l;i++)
		{
			si[i].className=si[i].className.replace(/\bSelectedMenuItem\b/,"UnSelectedMenuItem");
		}
	}
	this.On=false;
};
CTRL.Menu.prototype.DisplayThreadMenu=function(MenuItemID)
{//alert("enter display thread menu");
	if(!MenuItemID) MenuItemID=page.CurrentMenuItemID;
	var newdoc=Xml.Transfer(this.CXml,this.CXsl,[['Mode','thread'],['SelectedItemID',MenuItemID]],true);
	this.ThreadMenu=new CTRL.Menu(null,page.Top,null,newdoc);
	this.ThreadMenu.Init();
};
 


CTRL.SearchToolBar = function(ID,Parent,ControlXsl,XmlData,mode)
{//alert("SearchToolBar");//return;
	CTRL.C.call(this, ID,Parent,ControlXsl,XmlData,mode);
};
CTRL.SearchToolBar.prototype = new CTRL.C();
CTRL.SearchToolBar.prototype.constructor = CTRL.SearchToolBar;
CTRL.SearchToolBar.prototype.AfterGetExist=function()
{//alert("SearchToolBar aftergetexist");
	this.Input=$get(this.ID+"_Input");
	this.ViewSpan=$get(this.ID+"_View");
	this.SortImage=$get(this.ID+"_SortImage");
	this.SortName=Xml.SSN(this.CXml, "Sort[1]/@name").nodeValue;
	this.SortType=Xml.SSN(this.CXml, "Sort[1]/@type").nodeValue;
	this.SortOrder="ascending";
};



    
    /***************************
            Table
    ****************************/
    //function(doccolumns,doc,divcontainers,titleName,e,tableWidth)
    CTRL.Table = function(ID,Parent,XmlPath)
    {//alert(Parent);return;
		CTRL.C.call(this, ID,Parent,XmlPath);
		
	        this.Columns = Xml.SD(Xml.TS(Xml.SSN(this.XmlDom, '/Table/Columns'))); //alert(this.docColumns.xml); return;
	        this.Data = Xml.SD(Xml.TS(Xml.SSN(this.XmlDom, '/Table/Data/*[1]'))); //alert(this.doc.xml); return;
	        this.SortName= Xml.SSN(this.Columns, '/Columns/Column[1]/@path').value;     
	        this.SortOrder="ascending";  
	        this.PageIndex=1;
	        this.Filters=new Object();
	        this.Filters.ColumnNames=new Array();
	        this.Filters.Values=new Array();  
    }
    CTRL.Table.prototype = new CTRL.C();
    CTRL.Table.prototype.constructor = CTRL.Table;
    CTRL.Table.prototype.Refresh = function()
    {
            this.Parameters =([['SortOrder',this.SortOrder],['Refresh','true'],['SortColumnName',this.SortName],['PageIndex',this.PageIndex],['FilterColumnName',this.Filters.ColumnNames.join("|")+"|"],['Filter',this.Filters.Values.join("|")+"|"]]); 
            //alert("filter cols: "+this.Filters.ColumnNames.join("|")+"|"+"; texts: " + this.Filters.Values.join("|")+"|");//return;  
		this.Initialization(true); 
		
		var i=this.Filters.ColumnNames.length; var j;
		for(j=0;j<i;j++)
		{
			if(this.Filters.ColumnNames[j]!="")
			{
				var filterTextbox=$get('txt'+this.Filters.ColumnNames[j]);
				filterTextbox.value=this.Filters.Values[j];
			} 
		}
		this.SetCaretPosition(this.LastSortTextBoxId);
    };
        //-----------Filter the xml document---------------------
      CTRL.Table.prototype.FilterDoc = function(e)
      {
			this.LastSortTextBoxId=e.id;
			var CurrentColumnName = e.id.substr(3);
			var IsIn=false;
			var i=this.Filters.ColumnNames.length; var j;
			for(j=0;j<i;j++)
			{
				if(this.Filters.ColumnNames[j]==CurrentColumnName)
				{
					this.Filters.Values[j]=e.value;
					IsIn=true;
				} 
			}
			if(!IsIn)
			{
				this.Filters.ColumnNames.push(CurrentColumnName);
				this.Filters.Values.push(e.value);
			}
			this.Refresh();
        };
    //----------Sort the xml document----------------------
    CTRL.Table.prototype.SortDoc = function(e)
    {//alert('enter sortdoc');return;
		if(e!=this.SortName) {this.SortOrder="ascending"; }
		else
		{
			    var sortImage = $get(this.ID+'_SortImage')
		            var updown = sortImage.src.substr(sortImage.src.lastIndexOf('/')+1,3); //alert(updown);
		            if(updown=='des')
		            {
		                this.SortOrder='descending';                                               
		            }
		            else
		            {
		                this.SortOrder="ascending";                      
		            } 
	         }
	         this.SortName=e;
	         this.PageIndex = 1;
		 this.Refresh();  
    };
        //---------- show pager
     CTRL.Table.prototype.ShowPage = function(pageIndex)
     {
			this.PageIndex=pageIndex;
			this.Refresh();
     };
     
     
     
     
     

/*** class Tab ***/
CTRL.Tabs = function(ID,Parent,XmlPath)
{//alert(XmlPath);return;
	CTRL.C.call(this,ID,Parent,XmlPath);
	if(this.C)
	{
		this.HeaderContainer=$get(this.ID+'_HeaderContainer');
		this.SelectedName=Xml.SSN(this.XmlDom, "/Tabs/Tab[1]/@id").value;
		this.SelectedContent=$get(this.SelectedName);
	}
}
CTRL.Tabs.prototype = new CTRL.C();
CTRL.Tabs.prototype.constructor = CTRL.Tabs;
/**setup the selected selected item, when selectedName is null, 
 * we choose the first tab as the selected one**/
CTRL.Tabs.prototype.LoadSelectedContent=function(SelectedName)
{//alert("enter loadSelectedContent for "+(selectedName?selectedName:"nothing"));//return;
	this.SelectedContent.style.display="none";	
	this.SelectedName=SelectedName;
	//fresh the header
	this.Parameters=[['SelectedName',this.SelectedName]];
	var NewHeader=Xml.Transfer(this.XmlDom,this.Xsl,this.Parameters,"Header");//alert(NewHeader);
	this.HeaderContainer.innerHTML=NewHeader;
	//set properties
	this.SelectedContent=$get(this.SelectedName);
	if(this.SelectedContent)
	{
		this.SelectedContent.style.display="block";//alert(this.selectedContent.loaded);
	}
	else
	{
		var SelectedTabXml = Xml.SD(Xml.SSN(this.XmlDom, 
				"/Tabs/Tab[@id='" + this.SelectedName + "']").xml);
		this.Parameters=[['ContentContainerId',this.CC.id]
		                  ,['SelectedName',this.SelectedName]];
		//alert(selectedTabXml.xml);
		this.CC.innerHTML += Xml.Transfer(SelectedTabXml,this.Xsl,this.Parameters);
		this.SelectedContent=$get(this.SelectedName);
	}
};

CTRL.Tabs.prototype.AppendChildDivInSelected = function(ID)
    {
		this.SelectedContent.innerHTML += "<div id='"+ID+"'></div>";
		return $get(ID);
    };

CTRL.Tabs.prototype.tabClick=function(selectedName)
{//alert("enter tab_click");return;
		this.LoadSelectedContent(selectedName);
};

 

/*** class Tab ***/
CTRL.Tab = function(ID,Parent,XmlPath)
{//alert(XmlPath);return;
	CTRL.C.call(this,ID,Parent,XmlPath);
}
CTRL.Tab.prototype = new CTRL.C();
CTRL.Tab.prototype.constructor = CTRL.Tab;   
 
    
    
/*****************************
            Group Box
 ******************************/
CTRL.GroupBox=function(ID,Parent,XmlPath)
{
		CTRL.C.call(this, ID,Parent,XmlPath);
};
CTRL.GroupBox.prototype = new CTRL.C();
CTRL.GroupBox.prototype.constructor = CTRL.GroupBox; 
    
    
    
CTRL.DropDown=function(ID,Parent,XmlPath)
{//alert(Parent);return;
	CTRL.C.call(this, ID,Parent);
};
CTRL.DropDown.prototype = new CTRL.C();
CTRL.DropDown.prototype.constructor = CTRL.DropDown;        
CTRL.DropDown.prototype.NextDropListItem=function()
{
	var dl=this.C;
	if(dl.selectedIndex==dl.length-1) dl.selectedIndex=0;
	else dl.selectedIndex=dl.selectedIndex+1;
	this.AfterResetDropList();
};
CTRL.DropDown.prototype.PreviousDropListItem=function()
{
	var dl=this.C;
	if(dl.selectedIndex==0) dl.selectedIndex=dl.length-1;
	else dl.selectedIndex=dl.selectedIndex-1;
	AfterResetDropList();
};
CTRL.DropDown.prototype.AfterResetDropList=function()
{
	//window.location.href="/id/"+ThisId+"?cat="+ComicsCat+"&d="+dropdownlist.value;
};

/*checkboxlist
<asp:RadioButtonList id="FillClearRadioButtonList" runat="server" 
				RepeatDirection="Horizontal" Width="128px"
				onclick="FillClearCheckBoxList(CardTypeCheckBoxList)">
				<asp:ListItem Value="1" Selected="True">Select All</asp:ListItem>
				<asp:ListItem Value="0">Clear</asp:ListItem>
</asp:RadioButtonList>*/
CTRL.Grid=function(ID,Parent,XmlPath)
{//alert(Parent);return;
	CTRL.C.call(this, ID,Parent);
};
CTRL.Grid.prototype = new CTRL.C();
CTRL.Grid.prototype.constructor = CTRL.Grid;        
CTRL.Grid.prototype.GetAndCancelAll=function()
{		
	    var datagrid = this.C;
	    var IsChk = document.all.CheckAll.checked;
	    for(var i=1;i<datagrid.rows.length;i++)
	    {
		    if(typeof(datagrid.rows(i).cells(0).children(0)) == 'object')
		    {
			    datagrid.rows(i).cells(0).children(0).checked = IsChk;
		    }
	    }
};
CTRL.Grid.prototype.CheckIfSelect=function()
{
	    var datagrid =  this.C;
	    var IfChecked = false;
	    for(var i=0;i<datagrid.rows.length;i++)
	    {
		    if(datagrid.rows(i).cells(0).children(0).checked==true)
		    {
			    IfChecked = true;
			    break;
		    }
	    }
	    if(IfChecked==false)
	    {
		    alert('Please select at least 1 record, then click delete!');
	    }
	    return IfChecked;
};
CTRL.Grid.prototype.FillClearCheckBoxList=function(e)
{
	    if(EventElement(e).tagName=='INPUT')
	    {
		    	var v=EventElement(e).value=='0' ? '' : 'checked'
		        var rows=this.C.rows;
		        var l=rows.length;
		        for(var j=0;j<l;j++)
		        {
			            var cells=rows[j].cells;
			            var cl=cells.length;
			            for(var i=0;i<cl;i++)
			            {
			              	 cells[i].children[0].checked=v;
			            }
		        }
	    }
};

/*used in my buddha or other document architecture*/
CTRL.Article=function(ID,Parent,XmlPath)
{//alert(Parent);return;
	CTRL.C.call(this, ID,Parent);
};
CTRL.Article.prototype = new CTRL.C();
CTRL.Article.prototype.constructor = CTRL.Article;        
CTRL.Article.prototype.HideDisplay= function(HideID,ContentID)
{
        if($get(HideID).innerHTML=="隱藏本部分")
        {
            $get(HideID).innerHTML="顯示本部分"
            $get(ContentID).style.display="none";
        }  
        else
        {
            $get(HideID).innerHTML="隱藏本部分"
            $get(ContentID).style.display="block";        
        }  
};
CTRL.Article.prototype.DisplayFoucs=function()
{
        if($get("DisplayFocus").innerHTML=="显示重点")
        {
            var FocusClass=GetStyleRule('.focus');
            FocusClass.style.textDecoration="underline";
            FocusClass.style.cursor="pointer";            
            $get("DisplayFocus").innerHTML="取消显示重点";
        }
        else
        {
            var FocusClass=GetStyleRule('.focus');
            FocusClass.style.textDecoration="";
            FocusClass.style.cursor="";            
            $get("DisplayFocus").innerHTML="显示重点";
        }
};
CTRL.Article.prototype.DisplayExplanation=function(evt,ExplainID)
{//alert($get(ExplainID).style.display);
        GetMouseXY(evt);        //alert(CursorXY.x+" "+CursorXY.y);
        var Explain=$get(ExplainID);//alert(Explain.outerHTML);alert(Explain.style.left);
        Explain.style.display="block"; // alert(CursorXY.x);
        if(CursorXY.x>520) CursorXY.x-=500;
        CursorXY.y+=5;        //alert(CursorXY.x);
        Explain.style.left=CursorXY.x+"px";
        Explain.style.top= CursorXY.y+"px";        //alert(Explain.outerHTML);    
};
CTRL.Article.prototype.DisplaySection=function(SectionTitleID)
{//alert("displaysecton");
	if(page.LastDisplayedSection)
		page.LastDisplayedSection.style.display='none';
	else
	{
		var s1s=$get('InnerContent').childNodes;//Xml.SN($get('InnerContent'),"div[@class='s1']");
		var l=s1s.length;
		for(var i=0;i<l;i++)
		{var s1=s1s[i]; if(s1.tagName && s1.tagName.toLowerCase()=='div') s1.style.display='none';}
	}
	var s1=$get(SectionTitleID).parentNode;
	s1.style.display='block';//alert(Xml.TS($get(SectionTitleID).parentNode));
	page.LastDisplayedSection=s1;
};
CTRL.Article.prototype.CreateDirectory=function()
{
	var di=$get("InnerDirectory");
	var s1s=$get('InnerContent').childNodes;//var s1s=Xml.SN($get('InnerContent'),".//div[@class='st1']");
	var l=s1s.length;//alert(l);return;
	for(var i=0;i<l;i++)//<a onclick="page.d('a001');">彻悟禅师念佛伽陀教义百偈</a>
	{
		var s1=s1s[i];
		if(s1.tagName && s1.tagName.toLowerCase()=='div') 
		{
			var st1=s1.childNodes[0];
			if(!st1.tagName || st1.tagName.toLowerCase()!='div') st1=s1.childNodes[1];
			var div=document.createElement("div");
			di.appendChild(div);
			var a=document.createElement("a");div.appendChild(a);
			a.setAttribute("href","javascript:page.d('"+st1.getAttribute("id")+"');")
			var title=st1.getElementsByTagName("span")[0].innerHTML;
			a.appendChild(document.createTextNode(title));
		}
	}
	page.LastDisplayedSection=null;
	page.d=function(id){CTRL.Article.prototype.DisplaySection(id);};
};

/*used in my buddha or other document architecture*/
CTRL.Stars=function(ID,Parent,XmlPath)
{//alert(Parent);return;
	CTRL.C.call(this, ID,Parent);
};
CTRL.Stars.prototype = new CTRL.C();
CTRL.Stars.prototype.constructor = CTRL.Stars;     
//移动的物体ID，最大距离，活动范围长度，宽度，边缘距离   
CTRL.Stars.prototype.MoveRandom=function(ObjectID,MaxInt,MaxWidth,MaxHeight,Edge)
{//alert('ss');
        var img=$get(ObjectID);//alert('2');
        var newtop=MakeInEdge(String.GetIntWithPX(img.style.top)+Math.ceil(Math.random()*MaxInt-MaxInt/2),MaxHeight,Edge);
        var newleft=MakeInEdge(String.GetIntWithPX(img.style.left)+Math.ceil(Math.random()*MaxInt-MaxInt/2),MaxWidth,Edge);
        //alert(newtop+' '+newleft);
        img.style.top=newtop+'px';
        img.style.left=newleft+'px';
};
//给定一个坐标，最大值和边距置，得出在边距内的值
CTRL.Stars.prototype.MakeInEdge=function(position,Max,Edge)
{
	    if(position<Edge) position=Max-Edge;
	    else if(position>Max-Edge) position=Edge;
	    return position;
};
CTRL.Stars.prototype.FlashStar=function(ObjectID)
{//alert('ss');
        var img=$get(ObjectID);//alert('2');
        if(img.style.visibility=='hidden') img.style.visibility='visible';
        else img.style.visibility='hidden';
};
//圆心x,y,半径r,速度v(度)，时间间隔t,
CTRL.Stars.prototype.MoveStepInCircle=function(ObjectID,x,y,r,v)
{//alert('s');
	     var obj=$get(ObjectID);//alert(obj.outerHTML);return;
	    c=parseFloat(obj.CurrentPosition);
	    c+=v;//alert(c);return;
	    obj.CurrentPosition=c;//alert(obj.outerHTML);return;
	    obj.style.left=Math.ceil(Math.sin(c)*r)+x;//8+6alert(obj.style.x);return;
	    obj.style.top=Math.ceil(Math.cos(c)*r)+y;
};



//message controls
function Message(ArticleID)
{
	if(!$get('MessageContainer')) 
	{
		var c=document.createElement("DIV");
		page.Content.appendChild(c);
		c.setAttribute('id',"MessageContainer");
	}
	
	if(DisplayMessages(ArticleID)) LeaveMessage(ArticleID);
}

// This is the javascript file for leaving a message
function DisplayMessages(ArticleID)
{/*var poststr = "MessageFile=" + encodeURI(MessageFile);*/
	var container=$get("MessageContainer");
	if(!$get('MessageSeparator'))
	{
		var title=document.createElement("div"); container.appendChild(title);title.setAttribute("id","MessageSeparator");
		title.className="MessageSep";
		var text=document.createElement("span");title.appendChild(text);
		var words;if(page.Lang=='en') words="Following contents are messages from friends and welcome to leave a message here";
		else words="以下内容是朋友的留言，并欢迎您在此留言";
		text.appendChild(document.createTextNode(words));
	}
	var r = HttpRequest(page.AspnetPath+"XmlService.aspx", "C=<R><M>GetArticleMessages</M><T>"+new Date().getTime()+"</T><C>"+ArticleID+"</C></R>");
	//if(console) console.log("messages:"+r);
	if(!String.startswith(r,"<Messages")){if(window.console) console.log(r);return false;}
	var Data=Xml.SD(r);

	var MessageList=new CTRL.List(null,container,"CXslt/LeaveMessage.xsl",Data,"display"); 	
	MessageList.Init();
	return true;
}

function LeaveMessage(ArticleID)
{
	var New=Xml.SD("Xml/LeaveMessage");
	New=Xml.SD(Xml.TS(New));
	var Data=Xml.SSN(New,"/LeaveMessage/Data");
	var message=New.createElement("Message");
	Data.appendChild(message);
	var ArticleIDElement=New.createElement("ArticleID");
	message.appendChild(ArticleIDElement);
	var ArticleIDText=New.createTextNode(ArticleID);
	ArticleIDElement.appendChild(ArticleIDText);
	//alert(Xml.TS(New));//return;
	//Xml.SSN(Xml.SD("<Message><ArticleID>"+ArticleID+"</ArticleID></Message>"),"/Message");
	var EditionWindow = new CTRL.Window(null,$get("MessageContainer"),"CXslt/LeaveMessage.xsl",New,"new");
	EditionWindow.Init();

	page.CS.MessageEdition.AfterSaveSuccess=function()
	{
		Message(ArticleID);
		page.RecordVisit("Leave Message");
	};
}

/*end of controls.js*/

/*edition.js*/
/*CTRL.Edition should always be created as a child control of CTRL.Window
 * so there is no parent, mode for the constructor
 * */
CTRL.Edition = function(ID,Parent,ControlXsl,XmlData,mode)
{//alert("Edition");//return;
	CTRL.C.call(this, ID,Parent,ControlXsl,XmlData,mode);
	
	this.Xml=Xml.SSN(XmlData,this.GCA("DataPath"));
	this.Items=[];//Items are EditionItems
	this.SaveControl=$get(this.ID+"_Save");//the save button
	this.Mode=this.GCA("saveMode");
	if(this.Mode=="update")
	{
		this.DataID=Xml.SSN(this.Xml,"I/text()").nodeValue;
	}
};
CTRL.Edition.prototype = new CTRL.C();
CTRL.Edition.prototype.constructor = CTRL.Edition;
CTRL.Edition.prototype.Save = function()
{//alert("edition save");
	//check input
	var c = this.Items.length;
	for(var i=0; i<c; i++)
	{
		if(!this.Items[i].IsValid()) 
		{//alert("invalid item");
			return;
		}
	}
	
	//fill in data
	var h;//the request to send to server
	if(this.Mode=="new")//new a object
	{
		//fill in the new object xml data with children xml data, for list type item, no this
		for(var i=0; i<c; i++)
		{//alert(this.Items[i].ID);
			this.Items[i].AddXmlNode();
		}//alert(Xml.TS(this.XmlNode));
		
		//write the data into database by server
		//R: a request
		//F: the file path
		//T: the table name
		//M: mode or command
		//P: parent xpath
		//C: content
		h=Xml.SD("<R></R>");
		var DE=h.documentElement;
		var T=h.createElement("T");	
		DE.appendChild(T);
		T.appendChild(h.createTextNode(this.GCA("saveTableName")));
		var M=h.createElement("M");	
		DE.appendChild(M);	
		M.appendChild(h.createTextNode("new"));
		var C=h.createElement("C");	
		DE.appendChild(C);	
		C.appendChild(h.createTextNode(Xml.TS(this.Xml)));
		h=Xml.TS(h);
	}
	else if(this.Mode=="update")//new a object
	{
		//fill in the object xml data with new children xml data
		for(var i=0; i<c; i++)
		{
			this.Items[i].AddXmlNode();
		}//alert(Xml.TS(this.XmlNode));
		
		h="<R><F>"+page.HardRootPath+"Eat/Dishes.xml</F><M>update</M><P>/Dishes/Dish[I='"+this.DataID+"']</P><C>"
				+Xml.TS(this.Xml)
				+"</C></R>";
	}
	//alert(h);//return;
	//encodeURI/escape replace escape
	var r = HttpRequest(page.AspnetPath+"XmlService.aspx", "C="+encodeURIComponent(h));//alert(r);
	if(r=="<R>已成功保存</R>") 
	{
		if(this.Output)
		{
			this.Output.innerHTML=(this.GCA("saveSuccessText"));
			this.DataID=Xml.SSN(this.Xml,"I/text()").nodeValue;
		}
		if(this.AfterSaveSuccess) this.AfterSaveSuccess();
	}	//alert("已保存");
	else alert(r);
};



CTRL.EditItem = function(ID,Parent,ControlXsl,XmlData,mode)
{//alert(Parent);return;
	CTRL.C.call(this, ID,Parent,ControlXsl,XmlData,mode);
	this.type = this.GCA("type");	
	this.required = this.GCA("required")=='true'? true:false;	
	this.Edition = page.CS[this.CXml.parentNode.getAttribute("id")];
	this.PXml=this.Edition.Xml;
	this.Edition.Items.push(this);//alert(this.ID);//alert(this.Edition.ID);//alert(Xml.TS(this.CXml.parentNode));
	this.xpath = this.GCA("xpath");//alert(xpath);
	
	//get sub controls info
	if(this.type=="list") return;	
	this.Input=$get(this.ID+"_Input");	
	//get checkboxes
	this.CheckBoxs=[];
	this.CheckBoxCount=0;
	var inputs = this.C.getElementsByTagName("INPUT");
	var c=inputs.length;
	for(var i=0;i<c;i++)
	{
		if(inputs[i].type=="checkbox") 
		{this.CheckBoxs.push(inputs[i]);this.CheckBoxCount++;}		
	}
	/*if(this.C && Xml.SSN(this.XmlDom, '/EditItem/@type').value=="string")
	{
		this.Input=new CTRL.C(ID+"_Input");
		this.Help=new CTRL.List(ID+"_Help");
		if(Xml.SSN(this.XmlDom, '/EditItem/@StartCharCount'))
			this.StartCharCount=
			Xml.SSN(this.XmlDom, '/EditItem/@StartCharCount').value;
		else this.StartCharCount = 0;
		this.OptionsInputValue = "";
		this.LastValue = "";
		this.FirstDisplayed = false;
		this.OptionsLoaded=false;
	}*/
};
CTRL.EditItem.prototype = new CTRL.C();
CTRL.EditItem.prototype.constructor = CTRL.EditItem;
CTRL.EditItem.prototype.ClearFirst = function()
{//alert("clear first");
	if(this.ClearFirsted) 
	{//alert(this.Input.value);
		return;
	}
	if(this.Input.value==" ") {this.Input.value="";this.ClearFirsted=true;}
};

//when e, it's when a checkbox is changed
//when no e, it's when the text in input box is changed
CTRL.EditItem.prototype.Select = function(e)
{//alert(e.target.checked);
	//when deselect a checkbox, no action taken
	if(e && !EE(e).checked) return;//alert(this.CheckBoxCount);
	
	//clear all checkbox when one is selected, or text is input into textbox
	//when it's text input, the InputChanged has garenteed that there is value in Input
	for(var i=0;i<this.CheckBoxCount;i++)
	{
		this.CheckBoxs[i].checked=false;		
	}
	
	//when it's checked a textbox
	if(e)
	{
		EE(e).checked=true; 
		this.Input.value=""; 
	}
};
//check the input to change the status if needed, and give better user reminder
CTRL.EditItem.prototype.InputChanged=function(e)
{
	if(!this.IsValid()) return;
	if(String.trim(EE(e).value)!="") this.Select();
};
//after exed IsValid() = true, fill the data into parent data
CTRL.EditItem.prototype.AddXmlNode=function()
{
	if(this.Type=="list") return;//for list, the content is already there
	
	var value =this.GetValue(); //alert(value);
	
	//when value is empty
	if(value=="") 
	{
		if(this.Edition.Mode=="new" || Xml.SSN(this.PXml, xpath)==null) return;//not create it
		else {this.PXml.removeChild(Xml.SSN(this.PXml, xpath));return;}//remove existing
	}
	
	//when value is not empty, create the element if needed
	var pathes = this.xpath.split("/"); var c=pathes.length;
	var temp=this.PXml;
	for(var i=0; i<c; i++)
	{
		var no=Xml.SSN(temp, pathes[i]);
		if(!no)  
		{
			no = temp.ownerDocument.createElement(pathes[i]);
			temp.appendChild(no);
		}
		temp = no;
	}
	//create the textelement or update the existing textelement
	if(!temp.firstChild)
	{temp.appendChild(temp.ownerDocument.createTextNode(value));}
	else temp.firstChild.nodeValue=value;
	this.Xml=temp;
	//alert(Xml.TS(parent));
};
//after exed IsValid() = true
CTRL.EditItem.prototype.GetValue=function()
{
	if(this.type=="list") return;
	//alert(this.Input.id + " " + $get(this.Input.id).value);
	//this.Input=$get(this.Input.id);
	if(this.type=="bigstring") 
	{
		if(this.Input.value!=" " && this.Input.value!="") 
		{
			return this.Input.value;
		}
		else 
		{
			return "";
		}
	}
	var input = String.trim(this.Input.value);
	if(input!="") return input;
	else if(this.CheckBoxCount>0)
	{
		for(var i=0;i<this.CheckBoxCount;i++)
		{
			if(this.CheckBoxs[i].checked) 
				return this.CheckBoxs[i].nextSibling.nodeValue;//alert(this.Value);;		
		}
		return "";//when none of checkboxes is checked and the input is also empty
	}
	else return "";
};
CTRL.EditItem.prototype.IsValid=function()
{
	var ItemName=this.GCA("name");//alert(ItemName);
	
	//check required
	if(this.required)
	{
		var r=true;//the result is assumed to be valid at first
		if(this.type=="bigstring") 
		{
			if(this.Input.value==" " || String.trim(this.Input.value)=="") 
			{
				r=false;
			}
		}
		else if(this.CheckBoxCount>0)
		{
			var checked=false;
			for(var i=0;i<this.CheckBoxCount;i++)
			{
				if(this.CheckBoxs[i].checked) checked=true;		
			}
			if(!checked && String.trim(this.Input.value)=="") r=false;
		}
		else if(this.type=="list")
		{//alert(Xml.SN(this.Data,"Item").length);return false;
			if(Xml.SN(this.Xml,"Item").length==0) r=false;
		}
		else
		{
			if(String.trim(this.Input.value)=="") r=false;
		}
		if(!r) 
		{
			//this.Edition.Output.innerHTML=(this.GCA("requiredText"));
			alert(this.GCA("requiredText"));
			return false;
		}
	}
	
	if(this.type=="number")
	{//alert(parseFloat(String.trim(e.target.value)));
		var r=/^[0-9]+[.]?[0-9]*$/;
		if(!r.test(String.trim(this.Input.value)))
		{	
			//this.Edition.Output.innerHTML=("请在"+ItemName+"中输入正确的数字");
			alert("请在"+ItemName+"中输入正确的数字");
			return false;
		}
		//else this.Edition.Output.innerHTML=("");
	}
	return true;
};
CTRL.EditItem.prototype.AddItem=function(id,name,price)
{//alert("add item, this.Editon.ID="+this.Edition.ID);
	if(!this.Xml)
	{
		this.Xml = this.PXml.ownerDocument.createElement(this.xpath);//the name of the new object
		this.PXml.appendChild(this.Xml);
	}
	var doc=this.Xml.ownerDocument; 
	var newitem = doc.createElement("Item");
	this.Xml.appendChild(newitem);
	var newid = doc.createAttribute("I");
	newid.nodeValue=id;
	newitem.setAttributeNode(newid);
	var newname = doc.createAttribute("N");
	newname.nodeValue=name;
	newitem.setAttributeNode(newname);
	var newprice = doc.createAttribute("P");
	newprice.nodeValue=price;
	newitem.setAttributeNode(newprice);
	//this.Edition.Init();alert(Xml.TS(this.Xml));//alert(this.Edition.CXsl);
	this.Refresh();//alert(Xml.TS(this.Xml));alert(Xml.TS(this.Edition.Xml));
};
CTRL.EditItem.prototype.RemoveItem=function(id)
{
	this.Xml.removeChild(Xml.SSN(this.Xml,"Item[@I='"+id+"']"));
	this.Refresh();
};
CTRL.EditItem.prototype.Refresh=function()
{
	//alert(Xml.TS(this.Xml));
	var ListItem = Xml.Transfer(this.Xml.parentNode,this.Edition.CXsl,null,true,'list');
	//alert(Xml.TS(ListItem));alert(Xml.TS(this.Edition.Xsl));
	var html=Xml.Transfer(ListItem,this.Edition.Xsl,null,true);
	html=Xml.TS(html.firstChild.firstChild.firstChild);//alert(html);return;
	this.C.innerHTML=html;//alert(html);
	this.Edition.SaveControl.style.display="block";
};

//old
CTRL.EditItem.prototype.InputFocus=function(event)
{
	if(!this.FirstDisplayed)
	{
		if(this.StartCharCount == 0) this.LoadHelper();
	}
	else
	{
		this.Help.Display();
	}
};
CTRL.EditItem.prototype.InputBlur=function(event)
{
	//this.Help.Hide();
};
CTRL.EditItem.prototype.LoadHelper=function(UseLocalData)
{
	//get data from database
	if(!UseLocalData)
	{
		var XmlString= "<Options>\
					<Item>ghkg</Item>\
					<Item>t86986</Item>\
					<Item>e45ew</Item>\
					<Item>dgjd</Item>\
				</Options>";
		var temp=Xml.SSN(this.XmlDom, '/EditItem');
		temp.appendChild(Xml.SD(XmlString).documentElement.cloneNode(true));
		this.OptionsInputValue = this.Input.C.value;
		this.Options=Xml.SSN(this.XmlDom, '/EditItem/Options');
		//alert(Xml.TS(this.Options));
	}
	
	//filter data and load into html
	var params=[['Filter',this.Input.C.value]];
	var temp=Xml.SD(Xml.TS(this.Options));
	this.Help.C.innerHTML = Xml.Transfer(temp,this.Xsl,params); //alert(this.Help.innerHTML);
	this.Help=new CTRL.List(this.ID+"_Help");
	if(this.Help.C.childNodes.length > 0)
	{
		this.Help.SetHeight();
		this.OptionsLoaded=true; //alert("this.OptionsLoaded is true");
		this.Input.DisplayHelper(this.ID+"_Help","block");
		this.FirstDisplayed = true;
		var Pairs=new Object();
		Pairs.ToHide = this.Help;
		Pairs.Scope = this;
		page.HideOnElseClickPairs.push(Pairs);
	}
	else
	{
		this.Help.Hide();
		this.OptionsLoaded=false;
	}
};
CTRL.EditItem.prototype.InputKeyup=function(event)
{
	var input = this.Input.C.value;
	var iv=this.OptionsInputValue;
	if(input == this.LastValue)
	{
		if(event.keyCode==KeyCodes.Up || event.keyCode==KeyCodes.Down)
			this.Help.Select(event);
		else if(event.keyCode==KeyCodes.Enter)
			this.Confirm(event);
	}
	else if(input.length > iv.length && input.substring(0, iv.length) == iv)
	{
		this.LoadHelper(true);
	}
	else
	{
		this.LoadHelper();
	}//alert(Xml.TS(this.XmlDom));
	this.LastValue = input;
};
CTRL.EditItem.prototype.HelpMouseover=function(event)
{
	this.Help.Select(event);
};
CTRL.EditItem.prototype.HelpClick=function(event)
{
	this.Confirm(event);
};
//EditItemID can be null when it's self
CTRL.EditItem.prototype.Confirm=function(event)
{//alert("CTRL.List.prototype.Select");
	if(event.keyCode==KeyCodes.Enter) 
	{
		 if(this.Help.SelectedItem)	this.Input.C.value=this.Help.SelectedItem.innerHTML;
	}
	else this.Input.C.value=EventElement(event).innerHTML;
	this.Help.Hide();
};

/*page.js*///alert("page.js");
/* this is the Page class, it setup page vars and sizes of each parts*/
function Page(TopHeight,BottomHeight)
{
	this.TopHeight=TopHeight;//26;
	this.BottomHeight=BottomHeight;//28;
}

Page.prototype.Init=function()
{
	//init general variables the page shoud holds
	this.FullPath=document.location.href; //alert(this.FullPath);
	this.HardRootPath="/root/MyLife/Mono/LifeOS/";
	this.RootPath = "http://"+document.location.host+"/web/";
	this.AspnetPath = "http://"+document.location.host+"/web/";
	this.ImagePath=this.RootPath+"Images/";// /Nygard/Images	
	if(browser.lang.indexOf('zh')>-1) this.Lang='zh';else this.Lang="en";
	var Lang=GetParam("Lang");if(Lang) this.Lang=Lang;	
	this.CS = new Object();
	this.PhotoPlayers=new Array();
	this.HideOnElseClickPairs=new Array();
	this.XmlDoms=new CTRL.Pairs();//caching loaded xml doms, each element is ['url',Dom]
	this.Xsl=Xml.SD("Xslt/Common.xsl");//alert(Xml.ToString(this.Xsl));
	this.ControlXml=function(){return Xml.SD("Xml/Common");}
	var r=Xml.SD("Website/Blocks.xml"); //alert(Xml.ToString(r));
	var blocks=Xml.SN(r.documentElement,"Block");//alert(blocks.length);
	this.Blocks=new Array();var bl=blocks.length;
	for(var i=0;i<bl;i++)
	{//alert(Xml.SSN(block,"I/text()").nodeValue);//break;
		var block=blocks[i];
		var id=Xml.SSN(block,"I/text()");
		var path=Xml.SSN(block,"Data/text()");
		this.Blocks[id.nodeValue]=path.nodeValue;  //	alert(page.Blocks[id.nodeValue]);
	}
	
	//setup the html controls for the page
	document.body.scroll='auto';
	this.Page=$get("Page"); 
	if(!this.Page) {this.Enabled=false; return;}
	else{this.Enabled=true;}
	this.Top=$get("PageTop");
	this.SiteTitle=$get("SiteTitle");
	this.Content=$get("PageContent");//the right part of pagemain
	this.ContentO=new CTRL.C("PageContent");
	this.Left=$get("PageLeft");
	if(this.Left)
	{
		this.Main=$get("PageMain");//pagemain contains pageleft and pagecontent
		this.WidthAdjuster=$get("WidthAdjuster");
		this.CS.WidthAdjuster=new CTRL.C("WidthAdjuster");
		
		if(this.LeftTree=$get("LeftTree"))
		{
			this.LeftGift=$get("LeftGift");
		}
	}
	this.Bottom=$get("PageBottom");
	this.SetSize();//setup size of each part
	LoadPage("PageLoad");//load controls into each part of the page	
	
	//add event handlers for the page
	Event.AddEventHandler(document,"onclick", function(event){page.Click(event);});
	Event.AddEventHandler(window,"onresize",function(){page.SetSize();});
};

/*1. when init page 2. when resize window 3. when switch language 4. when move seperater*/
Page.prototype.SetSize=function(LeftWidth)
{	//alert("setsize");
	if(!this.Enabled) return;//alert("enter setsize");//return;
	var WholeWidth=this.Page.clientWidth;
	var WholeHeight=this.Page.clientHeight;//alert(WholeWidth+"X"+WholeHeight);
	this.WholeWidth=WholeWidth;
	this.WholeHeight=WholeHeight;
	this.Top.style.height=(this.TopHeight-1)+"px";
	this.Bottom.style.height=(this.BottomHeight-1)+"px";
	var MainHeight = WholeHeight-this.BottomHeight-this.TopHeight-6;// 6 is a general reserve
	this.Main.style.height=MainHeight+"px";
	if(this.Left)
	{
		this.CS.WidthAdjuster.SetDrag('ResizePage');
		//5 is the width of width adjuster
		if(LeftWidth){this.Left.style.width=LeftWidth+"px";}
		else 
		{	
			if(Bi.IsIE && !this.IELeftWidthAdded) //ie take more width when display text
			{this.Left.style.width=(this.Left.offsetWidth+18)+"px";this.IELeftWidthAdded=true;}
			//if(this.Lang=='zh' &&(!this.LastLang || this.LastLang=='en')) this.Left.style.width=(this.Left.offsetWidth-35)+"px";
			//else if(this.LastLang=='zh') this.Left.style.width=(this.Left.offsetWidth+35)+"px";
		}
		this.ContentWidth = WholeWidth - this.Left.offsetWidth-this.CS.WidthAdjuster.C.offsetWidth;
		this.Content.style.width = this.ContentWidth + "px";
		this.LeftTree.style.height=(this.Left.offsetHeight-(this.LeftGift?this.LeftGift.offsetHeight:0))+"px";
		this.LeftTreeInner=$get('LeftTreeInner');
		if(Bi.IsIE) this.LeftTreeInner.style.width=(this.Left.offsetWidth-18)+"px";
	}
	if(SetListContentWidth) SetListContentWidth();
};
Page.prototype.ShowCache=function()
{	//alert("setsize");
	var Doms=page.XmlDoms.Content;
	var l=Doms.length;
	for(var i=0;i<l;i++)
	{
		alert(Doms[i][0]+":"+Xml.TS(Doms[i][1]));
	}
};
Page.prototype.RecordVisit=function(action)
{
	var r=Xml.SD("<R><M>RecordVisit</M><Action></Action></R>");
	var R=Xml.SSN(r,"/R");
	Xml.SSN(R,"Action").appendChild(r.createTextNode(action));
	if(page.VisitID) 
	{
		var v=r.createElement("VisitID");
		R.appendChild(v);
		v.appendChild(r.createTextNode(page.VisitID));
	}
	else
	{
		var u=r.createElement("Url");
		R.appendChild(u);
		u.appendChild(r.createTextNode(page.FullPath));
	}
	HttpRequest(page.AspnetPath+"XmlService.aspx", "C="+encodeURIComponent(Xml.TS(r)),page.RecordVisitBack,true);
};
Page.prototype.RecordVisitBack=function(request)
{
	if (request.readyState==4)//0Uninitialised 1Loading 2Loaded 3Interactive 4Completed 
  	{
	  	if(request.status==200)
	    {if(window.console) console.log(request.responseText);
	    	if(page.VisitID) return;//no feed back needed when it's a single action
	    	else//get visitid
	    	{
		  		var r=Xml.SD(request.responseText);
		  		var V=Xml.SSN(r,"/VisitID/text()");
		  		if(V)page.VisitID=V.nodeValue;//if(console) console.log("visit id set as "+page.VisitID);
	    	}
	    }//else{alert("Problem recording visit");}
  	}
};
Page.prototype.Click=function(e)
{//alert("enter pageclick");
	var ee=EE(e);
	var l2=page.HideOnElseClickPairs.length;
	for(var i=0;i<l2;i++)
	{		
		var Pairs=page.HideOnElseClickPairs[i];
		if(!Pairs.Scope.IsParentOf(ee))
			Pairs.ToHide.Hide();
	}
};

//function FocusItem(Focuser,ImageSrc,left, top,SourceID)
//{
//	var image = $get(Focuser);
//	var a = image.parentNode;
//	var div = a.parentNode;
//	image.src = ImageSrc;
//	div.style.display = "block";
//	div.style.left = left + "px";
//	div.style.top = top + "px";
//	a.href = $get(SourceID).href;
//}

function Dide(Focuser)
{
	$get(Focuser).style.display = 'none';
}