// -----Trace.js-----
function _g_isDebug() {
	try {
		if (Debug) return true;
		else return false;
	} catch (e) {
		return false;
	}
}

function Trace(obj, iflag) {
	if (!_g_isDebug()) return;
		
	var e = $("_trace_div");
	if (!e) {
		e = document.createElement("DIV");
		e.id = "_trace_div";
		e.style.backgroundColor = "white";
		e.style.color = "black";
		e.style.display = "block";
		e.style.clear = "both";
		e.style.overflow = "auto";
		e.style.height = "200px";
		e.style.textAlign = "left";
		document.getElementsByTagName("body")[0].appendChild(e);
	}
	
	var txt = ("" + obj).replace(/</gm, '&lt;');
	txt = iflag ? "<span style='color: red'>" + txt + "</span>" : txt;
	e.innerHTML += "<br/>" + txt;
	e.scrollTop = e.scrollHeight - e.clientHeight;
}

function Assert(exp, thisObj) {
	if (!_g_isDebug()) return;
	var f = new Function("return (" + exp + ");\n");
	f = f.bind(thisObj);
	
	var res;
	try {
		res = f();
	} catch (e) {
		Trace("Assertion fail: exp=" + exp + "&nbsp;&nbsp;&nbsp;message: " + e.message, true);
		//Trace("Stack: " + e.stack, true);
		return;
	}
	
	if (!res) Trace("Assertion fail: exp=" + exp, true);	
}

// -----myExtention.js-----
Object.extend(Number.prototype, {
	ToString : function(Digits) {
		var val = Math.round(this * Math.pow(10, Digits)) /
							 Math.pow(10, Digits);
		var retStr = val.toString();
		
		var pos = retStr.indexOf('.');
		if (pos < 0) pos = retStr.length;
		
		var digits = Digits - retStr.substr(pos + 1).length;
		if (digits > 0) {
			if (digits == Digits) retStr += '.';
			for (i = 0; i < digits; i++) retStr += '0';
		}
		
		return retStr;
	}
});

Object.extend(String, {
	Format : function() {
		if (arguments.length == 0) return null;
		
		var str = arguments[0];
		
		for (var i = 1; i < arguments.length; i++) {
			var reg = new RegExp('\\{' + (i-1) + '\\}','gm');
			str = str.replace(reg, arguments[i]);
			
		    reg = new RegExp('\\{' + (i-1) + '\\:F(\\d+)\\}', 'gm');
        	try {
			    var tmp = str;
			    var matches;
			    while (((matches = reg.exec(tmp)) != undefined)) {
				    var digits = matches[1];
				    str = str.replace(matches[0], arguments[i].ToString(digits));
			    }
			} catch (e) {
    			str = str.replace(reg, arguments[i]);
			}
		}

		return str;
	}
});

// -----Controls.js-----
var YTWeb = new Object();

YTWeb.Controls = {
	Initialized: false,
	_items: new Object(),
	_reg: new Object(),
	
	initialize: function() {
		var elements = document.getElementsByTagName("*");
		for (var i = 0; i < elements.length; i++) {
			var e = elements[i];
			if (e.id == "" || !e.id) continue;
			
			try {
				var cls = this._reg[$ATTR(e, "ObjType")];
				if (cls) this._items[e.id] = new cls(e);
			} catch(err) {
				Trace(err.message, true);
			}
		}
		this.Initialized = true;
	},
	
	Find: function(id) {
		return this._items[id];
	},
	
	Reg: function(objType, controlClass) {
		this._reg[objType] = controlClass;
	}
}

function $C(id) {
	return YTWeb.Controls.Find(id);
}

function $ATTR(element, attributeName) {
	var e = $(element);
	var attr = e.attributes[attributeName];
	
	if (!attr) return null;
	return attr.nodeValue;
}

YTWeb.InitItem = function(e) {
	e = $(e);
	
	this.Id = e.id;
	this.Dom = e;
}

YTWeb.PageRequest = function() {
	try {
		var urlParts = document.URL.split('?');
		var parmsParts = urlParts[1].split('&');
		for (var i = 0; i < parmsParts.length; i++) {
			var pair = parmsParts[i].split('=');
			try { this[pair[0]] = pair[1]; }
			catch(e) { this[pair[0]] = ''; }
		}		
	} catch(e) {
	}
}
YTWeb.Request = new YTWeb.PageRequest();

// -----HttpPush.js-----
YTWeb.HttpPush = Class.create();
YTWeb.HttpPush.prototype = {
	_p: null,
	
	initialize: function(callback, ieUrl, fxUrl) {
		var isIE = navigator.userAgent.toLowerCase().indexOf("msie") >= 0;
		if (isIE) this._p = new YTWeb.IEHttpPush(callback, ieUrl);
		else this._p = new YTWeb.FxHttpPush(callback, fxUrl);
	},
	
	send: function(domainFlag) {
		this._p.send(domainFlag);
	},
	
	abort: function() {
		this._p.abort();
	}
}

YTWeb.FxHttpPush = Class.create();
YTWeb.FxHttpPush.prototype = {
	_url: null,
	_cb: null,
	_req: null,
	
	initialize: function(callback, url) {
		this._url = url;
		this._cb = callback;
	},
	
	send: function() {
		this._req = new XMLHttpRequest();
		this._req.multipart = true;
		this._req.open("GET", this._url, true);
		this._req.onload = this._onReqLoad.bind(this);
		this._req.send(null);
	},
	
	abort: function() {
		this._req.abort();
	},
	
	_onReqLoad: function() {
		var txt = this._req.responseText;
		this._cb(eval("("+txt+")"));
	}
}

YTWeb.IEHttpPush = Class.create();
YTWeb.IEHttpPush.prototype = {
	_url: null,
	_cb: null,
	_doc: null,
	_e: null,
	
	initialize: function(callback, url) {
		this._url = url;
		this._cb = callback;
	},
	
	send: function(domainFlag) {
		if (this._e == null) {
			this._doc = new ActiveXObject("htmlfile");
	
			var txt = "<html>";
			if (domainFlag) txt += "<script>document.domain=" + document.domain + "</script>";
			txt += "</html>";
			
		    this._doc.open();
		    this._doc.write(txt);
		    this._doc.close();
		    
		    var cb = this._cb;
		    this._doc.parentWindow.onPush = function(data) {
		    	cb(data);
		    }
		    
		    this._e = this._doc.createElement("DIV");
		    this._doc.appendChild(this._e);
		    
		    this._e.innerHTML = '<IFRAME src="' + this._url + '"></IFRAME>';
		}
		else {
			this._e.innerHTML = "";
			this._e.innerHTML = '<IFRAME src="' + this._url + '"></IFRAME>';
		}
	},
	
	abort: function() {
		if (this._e) this._e.innerHTML = "";
	}
}

// -----Dialog.js-----

// -----Tab.js-----
YTWeb.TabView = Class.create();
YTWeb.Controls.Reg("TabView", YTWeb.TabView);

YTWeb.TabView.prototype = {
	initialize: function(e) {
		YTWeb.InitItem.bind(this)(e);
		
		e.innerHTML = "<div ObjType='TabNav'></div><br style='clear: both;' />" + e.innerHTML;
		
		this.Tabs = new Array();
		var chidren = e.getElementsByTagName("div");
		for (var i = 0; i < chidren.length; i++) {
			var ot = $ATTR(chidren[i], "ObjType");
			if (ot == "TabNav") this._nav = chidren[i];
			if (ot == "TabItem") this._addTab(new YTWeb.TabItem(chidren[i], this));
			if (ot == "TabCommon") this.TabCommon = chidren[i];
		}
		this._setNav(this.Tabs[0]);
		this._nav.className = $ATTR(e, "NavClass");
		
		if (eval($ATTR(e, "Round"))) {
			for (var i = 0; i < this.Tabs.length; i++) {
				 Rico.Corner.round(this.Tabs[i].Lnk, {corners:'top'} );
			}
		}
	},
	
	_addTab: function(tabItem) {
		this._nav.appendChild(tabItem.getNav());
		this.Tabs.push(tabItem);
	},
	
	_setNav: function(tabItem) {
		if (this.CurrentTab == tabItem) return false;
		if (this.CurrentTab) {
			this.CurrentTab.isActive = false;
			this.CurrentTab._hide();
		}
		this.CurrentTab = tabItem;
		tabItem.isActive = true;
		tabItem._show();
		return true;
	}
}

YTWeb.TabItem = Class.create();
YTWeb.TabItem.prototype = {
	initialize: function(e, tab) {
		YTWeb.InitItem.bind(this)(e);
		
		this.Tab = tab;
		this.TabName = $ATTR(e, "TabName");
		this.Round = eval($ATTR(e, "Round"));

		this.getNav();
		this._hide();
		this.isActive = false;
	},
	
	getNav: function() {
		if (this.Lnk) return this.Lnk;
		var e = this.Dom;
		
		var a = document.createElement('a');
		a.className = this.isActive ? $ATTR(e, "SelectedClass") : $ATTR(e, "UnselectedClass");
		a.style.display = "block";
		a.style.textAlign = "center";
		a.style.cssFloat = "left";
		a.style.styleFloat = "left";
		a.innerHTML = this.TabName;
		a.href = $ATTR(e, "TabAction") ? $ATTR(e, "TabAction") : "#";
		
		var me = this;
		Event.observe(a, "click", (function() { return me.Tab._setNav(me); }).bind(me.Tab), false);
		
		this.Lnk = a;
		return a;
	},
	
	_hide: function() {
		this.Dom.style.display = "none";
		this.Lnk.className = $ATTR(this.Dom, "UnselectedClass");
	},
	
	_show: function() {
		this.Dom.style.display = "";
		this.Lnk.className = $ATTR(this.Dom, "SelectedClass");
	}
}

// -----TreeView.js-----
YTWeb.TreeView = Class.create();
YTWeb.Controls.Reg("TreeView", YTWeb.TreeView);

YTWeb.TreeView.prototype = {
	Nodes: [],
	_indent: 10,
	_selectClass: null,
	
	initialize: function(e) {
		YTWeb.InitItem.bind(this)(e);
		
		this._selectClass = $ATTR(e, "SelectClass");
		var indent = parseInt($ATTR(e, "Indent"));
		this._indent = isNaN(indent) ? 10 : indent;
		
		for (var i = 0; i < e.childNodes.length; i++) {
			var c = e.childNodes[i];
			if (c.tagName) if ($ATTR(c, "ObjType") == "TreeNode") this.appendNode(new YTWeb.TreeNode(c, null, this));
		}

		if (eval($ATTR(this.Dom, "ExpandAll"))) {
			this.Nodes.each(function(node) { node.expand(); });
		} else {
			this.Nodes.each(function(node) { node.collapse(); });
		}
	},
	
	appendNode: function(node) {
		this.Nodes.push(node);
		return node;
	},
	
	createNode: function(id, icon, iconA, text, value, action, parentNode) {
		var nn = document.createElement('div');
		var n = parentNode || this;
		n.Dom.appendChild(nn);

		nn = $(nn);
		if (id) nn.id = id;
		if (icon) nn.setAttribute("Icon", icon);
		if (iconA) nn.setAttribute("IconA", iconA);
		nn.setAttribute("Text", text);
		if (value) nn.setAttribute("Value", value);
		if (action) nn.setAttribute("Action", action);

		Trace($ATTR(nn, "Text"));
		return n.appendNode(new YTWeb.TreeNode(nn, parentNode, this));
	},
	
	load: function(nodes, parentNode) {
		var me = this;
		nodes.each(function(node) {
			var n = me.createNode(node.Id, node.Icon, node.IconA, node.Text,
								node.Value, node.Action, parentNode);
			n.Nodes.each(function(sub) {
				me.load(sub, n);
			});
		});
	}
}

YTWeb.TreeNode = Class.create();
YTWeb.TreeNode.prototype = {
	Text: "",
	Value: "",
	_tree: null,
	_parent: null,
	
	initialize: function(e, parentNode, tree) {
		YTWeb.InitItem.bind(this)(e);
		
		this._tree = tree;
		this._parent = parentNode;
		this._selectClass = $ATTR(e, "SelectClass");
		
		this.Value = $ATTR(e, "Value");
		
		var txt = $ATTR(e, "Text");
		var img = $ATTR(e, "Icon");
		
		var t = "";
		if (img) t += "<img src='" + img + "' />";
		t += "<a href='#'>" + txt + "</a>";
		e.innerHTML = t + e.innerHTML;
		
		this.Text = txt;
		this.Img = img;
		this.ImgA = $ATTR(e, "IconA");
		
		this._setIndent();
		
		this.Children = [];
		for (var i = 0; i < e.childNodes.length; i++) {
			var c = e.childNodes[i];
			if (c.tagName) {
				if ($ATTR(c, "ObjType") == "TreeNode") this.appendNode(new YTWeb.TreeNode(c, this, this._tree));
				if (c.tagName == "A") this.Lnk = c;
				if (c.tagName == "IMG") this.Icon = c;
			}
		}

		if (this.Icon) Event.observe(this.Icon, "click", this.toggle.bind(this), false);
		var action = $ATTR(e, "Action");
		if (this.Lnk) {
			var a = null;
			if (action) a = this[action];
			if (!a) {
				if (this.Icon) {
					a = this.select;
				} else {
					a = this.selectAndToggle;
				}				
			}
			
			Event.observe(this.Lnk, "click", a.bind(this), false);
		}
		
		this._isExpanded = false;
	},
		
	toggle: function() {
		if (this.Children.length == 0) return;
		this.Children.each(function(node) { node._toggleVisible(); });
		this._isExpanded = !this._isExpanded;
		if (this.Icon && this.ImgA) {
			this.Icon.src = this._isExpanded ? this.ImgA : this.Img;
		}
	},
	
	select: function() {
		if (this._tree.Current) {
			var cur = this._tree.Current;
			if (cur._selectClass || cur._tree._selectClass) {
				Element.removeClassName(cur.Lnk, cur._selectClass || cur._tree._selectClass);
			} else {
				cur.Lnk.style.backgroundColor = "";
				cur.Lnk.style.color = "";
			}
		}
		this._tree.Current = this;
		if (this._selectClass || this._tree._selectClass) {
			Element.addClassName(this.Lnk, this._selectClass || this._tree._selectClass);
		} else {
			this.Lnk.style.backgroundColor = "#0A246A";
			this.Lnk.style.color = "#FFFFFF";
		}
		
		if (this._tree.onselect) this._tree.onselect(this);
	},
	
	selectAndToggle: function() {
		this.toggle(); this.select();
	},
	
	expand: function() {
		if (this.Children.length == 0) return;
		this.Children.each(function(node) { node._show(); });
		this._isExpanded = true;
	},
	
	collapse: function() {
		if (this.Children.length == 0) return;
		this.Children.each(function(node) { node._hide(); });
		this._isExpanded = false;
	},
		
	appendNode: function(node) {
		this.Children.push(node);
		return node;
	},
	
	_toggleVisible: function() {
		Toggle.display(this.Dom);
	},
	
	_show: function() {
		Element.show(this.Dom);
	},
	
	_hide: function() {
		Element.hide(this.Dom);
	},
	
	_setIndent: function() {
		if (!this._parent) {
			this.Level = 0;
		} else {
			this.Level = this._parent.Level + 1;
			this.Dom.style.paddingLeft = (this._tree._indent * this.Level) + "px";
		}		
	}
}

// -----GridView.js-----
YTWeb.GridView = Class.create();
YTWeb.Controls.Reg("GridView", YTWeb.GridView);

YTWeb.getFields = function(ele) {
	var fields = [];
	var children = ele.getElementsByTagName("*");
	for (var i = 0; i < children.length; i++) {
		var f = YTWeb.getField(children[i]);
		if (f) fields.push(f);
	}
	return fields;
}

// ----------------------------------------------
// GridView
// ----------------------------------------------
YTWeb.GridView.prototype = {
	Rows: [],
	DataList: null,
	Keys: [],
	_columns: [],
	_rowClass: "",
	_altRowClass: "",
	_tbody: null,
	
	initialize: function(e) {
		YTWeb.InitItem.bind(this)(e);
		
		this._tbody = e.getElementsByTagName('tbody')[0];
		
		this._rowClass = $ATTR(e, "RowClass");
		if (!this._rowClass) this._rowClass = "";
		
		this._altRowClass = $ATTR(e, "AltRowClass");
		this._columns = YTWeb.getFields(e);
		
		this.Keys = _splitParam($ATTR(e, "Keys"));
	},
	
	bindData: function(dataList) {
		try {
			this._tbody.innerHTML = ''; // ie
		} catch (e) {
			this._tbody.innerText = ''; // fx
		}
		
		this.Rows = [];
		for (var i = 0; i < dataList.length; i++) {
			var row = document.createElement('tr');
			var gdRow = new YTWeb.GridRow(row, this, i);
			gdRow.bindData(dataList[i]);
			
			this._tbody.appendChild(row);
			this.Rows.push(gdRow);
		}
	},
	
	refresh: function(dataItem, isNew) {
		for (var i = 0; i < this.Rows.length; i++) {
			if (this.Rows[i].hasSameKey(dataItem)) {
				this.Rows[i].bindData(dataItem, isNew);
			}
		}
	},
	
	getRowStyle: function(rowNum) {
		if (rowNum % 2 == 0) return this._rowClass;
		if (this._altRowClass) return this._altRowClass;
		return this._rowClass;
	}
}

YTWeb.BoundItem = function() { }
YTWeb.BoundItem.prototype = {
	Keys: [],
	Data: null,
	LastUpdate: new Date(),
	_oldData: null,
	_columns: null,
	
	hasSameKey: function(data) {
		if (!this.Data) return false;
		for (var i = 0; i < this.Keys.length; i++) {
			if (data[this.Keys[i]] != this.Data[this.Keys[i]]) return false;
		}
		return true;
	}
}

// ----------------------------------------------
// GridRow
// ----------------------------------------------
YTWeb.GridRow = Class.create();
YTWeb.GridRow.prototype = {
	_grid: null,
	_rowClass: "",
	
	initialize: function(e, grid, rowNum) {
		YTWeb.InitItem.bind(this)(e);
		
		this._grid = grid;
		this._rowClass = grid.getRowStyle(rowNum);
		this._columns = grid._columns;
		this.Keys = grid.Keys;
	},
	
	bindData: function(data, isNew) {
		this.LastUpdate = new Date();
		this._oldData = this.Data;
		this.Data = data;
		
		try {
			this.Dom.innerHTML = '';
		} catch(e) {
			this.Dom.innerText = '';
		}
		
		for (var i = 0; i < this._columns.length; i++) {
			var cell = document.createElement('td');
			var e = this._columns[i].bindData(this, isNew);
			cell.appendChild(e);
			this.Dom.appendChild(cell);
		}
	},
	
	getCssClass: function() {
		return this._rowClass;
	}
}
Object.extend(YTWeb.GridRow.prototype, YTWeb.BoundItem.prototype);

// ----------------------------------------------
// BoundTable
// ----------------------------------------------
YTWeb.BoundTable = Class.create();
YTWeb.Controls.Reg("BoundTable", YTWeb.BoundTable);



// -----GridColumn.js-----
function _splitParam(str) {
	if (!str) return null;
	str = str.replace(/\s+/gm, "");
	return str.split(',');
}

YTWeb.getField = function(ele) {
	var objType = $ATTR(ele, "ObjType");
	if (objType == "BoundField") return new YTWeb.BoundField(ele);
	if (objType == "ComparedField") return new YTWeb.ComparedField(ele);
	return null;
}

// ----------------------------------------------
// BoundField
// ----------------------------------------------
YTWeb.BoundField = Class.create();
YTWeb.BoundField.prototype = {
	_formatStr: "",
	_dataFields: [],
	
	initialize: function(e) {
		YTWeb.InitItem.bind(this)(e);
		
		this._formatStr = $ATTR(e, "FormatString");
		
		this._dataFields = _splitParam($ATTR(e, "DataFields"));
		if (!this._dataFields) this._dataFields = [];
	},
	
	bindData: function(container) {
		var data = container.Data;
		var e = document.createElement("span");
		
		var args = "";
		for (var i = 0; i < this._dataFields.length; i++) {
			args += String.Format(", data[this._dataFields[{0}]]", i);
		}
		var cmd = "String.Format(this._formatStr" + args + ")";
		e.innerHTML = eval(cmd);
		e.className = container.getCssClass();
		
		return e;
	}
}

// ----------------------------------------------
// ComparedField
// ----------------------------------------------
YTWeb.ComparedField = Class.create();
YTWeb.ComparedField.prototype = {
	_base: null,
	_greaterClass: "",
	_lessClass: "",
	_dataClass: "",
	_compareWith: null,
	_valueField: null,
	
	initialize: function(e) {
		YTWeb.InitItem.bind(this)(e);
		this._base = new YTWeb.BoundField(e);
		
		this._greaterClass = $ATTR(e, "GreaterClass");
		if (!this._greaterClass) this._greaterClass = '';
		
		this._lessClass = $ATTR(e, "LessClass");
		if (!this._lessClass) this._lessClass = '';
		
		this._dataClass = $ATTR(e, "DatComingClass");
		
		this._compareWith = $ATTR(e, "CompareWith");
		
		this._valueField = $ATTR(e, "ValueField");
	},
	
	bindData: function(container, isNew) {
		var e = this._base.bindData(container);
		e.className = e.className + this.getComparedClass(container, isNew);
		return e;
	},
	
	getComparedClass: function(container, isNew) {
		if (!container._oldData && !this._compareWith) return '';
		
		var cur = container.Data[this._valueField];

		var old = 0;
		if (container._oldData) old = container._oldData[this._valueField];
		
		var compareWith = 0;
		if (this._compareWith) {
			compareWith = parseFloat(this._compareWith);
			if (isNaN(compareWith)) compareWith = container.Data[this._compareWith];
		}
		else compareWith = old;

		
		var dc = (cur != old) && this._dataClass && isNew ? ' ' + this._dataClass + ' ' : ' ';
		if (cur > compareWith) return dc + this._greaterClass;
		if (cur < compareWith) return dc + this._lessClass;
		return dc;
	}
}

// -----Pager.js-----
YTWeb.Pager = Class.create();
YTWeb.Controls.Reg("Pager", YTWeb.Pager);

YTWeb.Pager.prototype = {
	PageSize: 0,
	CurrentPage: 1,
	TotalPages: 0,
	_onPageChanging: null,
	_txtNext: "",
	_txtPre: "",
	_formatString: "",
	_noDataString: "",
		
	initialize: function(e) {
		YTWeb.InitItem.bind(this)(e);
		
		this._onPageChanging = $ATTR(e, "onChange");
		
		this.PageSize = parseInt($ATTR(e, "PageSize"));
		if (isNaN(this.PageSize)) this.PageSize = 10;
		
		this._txtNext = $ATTR(e, "TextNext");
		this._txtPre = $ATTR(e, "TextPre");
		this._formatString = $ATTR(e, "FormatString");
		this._noDataString = $ATTR(e, "NoDataString");
	},
	
	display: function() {
		if (this.TotalPages == 0) {
			this.Dom.innerHTML = this._noDataString;
			return;
		}
		
		this.Dom.innerHTML = '';
		
		var me = this;
		
		var pre = document.createElement('a');
		pre.innerHTML = this._txtPre;
		pre.href = '#';
		pre.onclick = function() { me._setPage(me.CurrentPage-1); return false; }
		
		var next = document.createElement('a');
		next.innerHTML = this._txtNext;
		next.href = '#';
		next.onclick = function() { me._setPage(me.CurrentPage+1); return false; }
		
		var info = document.createElement('span');
		info.innerHTML = String.Format(this._formatString, this.CurrentPage, this.TotalPages);
		
		if (this.CurrentPage != 1) this.Dom.appendChild(pre);
		this.Dom.appendChild(info);
		if (this.CurrentPage != this.TotalPages) this.Dom.appendChild(next);
	},
	
	_setPage: function(pageNum) {
		this.CurrentPage = pageNum;
		if (this._onPageChanging) eval(this._onPageChanging);
	}
}

// -----TextboxPlus.js-----
YTWeb.TextboxPlus = Class.create();
YTWeb.Controls.Reg("Textbox", YTWeb.TextboxPlus);

YTWeb.TextboxPlus.prototype = {
	_title: null,
	_input: null,
	_cancel: null,
	_interval: 150,
	_onChange: null,
	_size: 10,
	OnChange: null,
	_isWaiting: false,
	_text: "",
	
	initialize: function(e)  {
		YTWeb.InitItem.bind(this)(e);
		
		var interval = parseInt($ATTR(e, "Interval"));
		if (!isNaN(interval)) this._interval = interval;
		
		this._title = $ATTR(e,"TitleText");
		this._cancel = $ATTR(e, "CancelText");
		this._onChange = $ATTR(e, "OnTextChange");

		var size = parseInt($ATTR(e, "Size"));
		if (!isNaN(size)) this._size = size;
		
		this._createElement();
	},
	
	getText: function() {
		return this._text; // $F(this._input);
	},
	
	setText: function(text) {
		if (text != this.getText()) {
			this._input.value = text;
			this._cb();
		}
	},
	
	clear: function() {
		this.setText('');
		return false;
	},
	
	_createElement: function() {
		var html = "{0}<input id='{1}_input' type='text' size={2} /><a id='{1}_cancel' href='#''>{3}</a>";
		this.Dom.innerHTML = String.Format(html, this._title, this.Id, this._size, this._cancel);
		this._input = $(this.Id + "_input");
		this._cancel = $(this.Id + "_cancel");
		this._input.onkeydown = this._onKey.bind(this);
		this._cancel.onclick = this.clear.bind(this);
	},

	_onKey: function(evt) {
		evt = evt || event;
		if (evt.which == 13) {
			return false;
		}
		
		if (!this._isWaiting) {
			this._isWaiting = true;
			window.setTimeout(this._cb.bind(this), this._interval);
		}
	},
	
	_cb: function() {
		this._isWaiting = false;
		
		var text = $F(this._input);
		if (this._text != text) {
			this._text = text;
			if (this.OnChange) return this.OnChange();
			return eval(this._onChange);
		}
	}
}

// -----URL.js-----
YTWeb.Page = Class.create();
YTWeb.Page.prototype = {
	_domain: "",
	_path: "",
	
	initialize: function(url) {
		var reg = /http:\/\/([^\/]*)(\/.*)/;
		var matches  = reg.exec(url);
		this._domain = matches[1];
		this._path   = matches[2];
		
		try {
			var querystring = url.split('?')[1];
			var args = querystring.split('&');
			for (var i = 0; i < args.length; i++) {
				var arg = args[i].split("=");
				this[arg[0]] = arg[1];
			}
		} catch(e) { }
	},
	
	getDomain: function() {
		return this._domain;
	},
	
	getPath: function() {
		return this._path;
	},
	
	isSubDomain:function(domain) {
		var reg = new RegExp(domain + '$', "i");
		if (reg.exec(this._domain)) return true;
		else return false;
	}
}


