Number.prototype.NaN0=function(){return isNaN(this)?0:this;}
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');}
String.prototype.trimEx=function(){return this.replace(/^[\s　]+|[\s　]+$/g, '');}
String.prototype.count=function(){var tmp=this.replace(/([\u0391-\uFFE5])/ig, "  ");return tmp.length;}
String.prototype.wordcount=function(){var tmp=this.replace(/([\u0391-\uFFE5])/ig, "aa");tmp=tmp.replace(/<[^<>]*?>/ig, '');tmp=tmp.replace(/\s/ig, '');return tmp.length;}
function isset(p) { return typeof(p) != 'undefined'; } // No use for params that syntax error
function empty(p) { return typeof(p)=='undefined' || !p; }
function is_array(p) { return p instanceof Array; }
function is_string(p) { return typeof(p)=='string'; }
if (typeof(Element) == 'undefined' || typeof(Element.extend) == 'undefined') {
	document.write("<script src='/js/common/prototype.js'></script>");
}
function $() {
  var results = [], element;
  for (var i = 0; i < arguments.length; i++) {
    element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    results.push(Element.extend(element));
  }
  return results.length < 2 ? results[0] : results;
}
function _$(obj) { return is_string(obj) ? $(obj) : obj; }
function debug(p,t,y) { var s=''; for (i in p) { s+=(i+":\t"+(typeof(p[i])=='function'?'function(){}':p[i])+"\n"); if (typeof(p[i])=='object'&&t) { for (j in p[i]) { s+=("\t"+j+":\t"+(typeof(p[i][j])=='function'?'function(){}':p[i][j])+"\n"); if (typeof(p[i][j])=='object'&&t) { for (k in p[i][j]) { s+=("\t\t"+k+":\t"+(typeof(p[i][j][k])=='function'?'function(){}':p[i][j][k])+"\n"); } } } } } try { if (empty(y)) { if(typeof(g_win)=='undefined') { g_win = window.open('about:blank', 'debug', 'width=800,height=600,scrollbars=1,resizable,status'); g_win.document.write('<html><head><title>debug output</title></head><body><div id="debugTag"></div></body></html>'); } var cc = ''; if (debug.caller) { cc = debug.caller.toString(); cc = cc.substring(9, cc.indexOf('(')); } g_win.document.getElementById('debugTag').innerHTML += ('<b>'+(new Date()).toLocaleString()+ ('<br>From function '+ cc +'()') +'</b> <pre>' + s + '</pre><hr/>'); } else { throw 1; } } catch(e) { var m = 800; while (s.length > m) { var s1 = s.substr(0,m) + "\n\n...[continue]...\n"; s = s.substr(m); alert(s1); } alert(s); } }
function $t(tagName, container) {
	return (_$(container)||document).getElementsByTagName(tagName);
}
function $n(name, container) {
	var objs = [], tmp = document.getElementsByName(name);
	for(var i=0; i<tmp.length; i++) objs.push(tmp[i]);
	// for div or span etc. cant get in IE
	var allobjs = $t('*', container);
	for(var i=0; i<allobjs.length; i++) {
		if (allobjs[i].name == name) {
			for (var j=0; j<objs.length; j++) {
				if (allobjs[i] == objs[j]) {
					objs[j].name = name; // for div or span etc. cant assoc name in FF.
					break;
				}
			}
			if (j >= objs.length) {
				objs.push(allobjs[i]);
			}
		}
	}
	return objs;
}
function $v(value, container) {
	var objs = [];
	var allobjs = $t('*', container);
	for(var i=0; i<allobjs.length; i++) {
		if (allobjs[i].value && is_string(allobjs[i].value)) {
			if (allobjs[i].value.indexOf(value) != -1) {
				//alert(allobjs[i].outerHTML);
				objs.push(allobjs[i]);
			}
		}
	}
	return objs;
}
function $c(className, container, strict) {
	if (!isset(strict)) strict = false;

	var objs = [];
	var allobjs = $t('*', container);
	for(var i=0; i<allobjs.length; i++) {
		if (strict && allobjs[i].className==className ||
			!strict && (" "+allobjs[i].className+" ").indexOf(" "+className+" ") != -1 ) {
			objs.push(allobjs[i]);
		}
	}
	return objs;
}
function $e() {
	if (window.event) return window.event;
	func = $e.caller;
	while(func!=null) {
		var arg0 = func.arguments[0];
		if( arg0 &&
		 		( (arg0.constructor==Event || arg0.constructor==MouseEvent)
					|| (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation) )
		) {	return arg0; }
		func = func.caller;
	}
	return null;
}
/**
 * 取iframe，或iframe中的obj
 * 只传一个参数，可执行iframe中的函数
 * 传第二个参数，可get/set iframe中obj的属性
 * @参数一: iframe id
 * @参数二: obj id
 * @exp: $i(iframeId).function1();
 *		 $i(iframeId, divId).innerHTML='';
 */
function $i(ifrId) {
	var iframe = $(ifrId);
	var objId = typeof(arguments[1])!='undefined' ? arguments[1] : false;
	if (!objId) return iframe.contentWindow ? iframe.contentWindow : null;
	else {
		var d = null;
		if (iframe.contentDocument) 	d = iframe.contentDocument;
		else if (iframe.contentWindow)  d = iframe.contentWindow.document;
		else if (iframe.document) 		d = iframe.document;
		return d.getElementById(objId);
	}
}
function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]();}
    obj.attachEvent( type, obj[type+fn] );
  } else {
  	obj.addEventListener( type.replace(/^on/i, ''), fn, false );
  }
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( type, obj[type+fn] );
    obj[type+fn] = null;
    obj['e'+type+fn] = null;
  } else {
  	obj.removeEventListener( type.replace(/^on/i, ''), fn, false );
  }
}
function getWindowScroll() {
	if (typeof window.pageYOffset != 'undefined') {
	   return {y:window.pageYOffset, x:window.pageXOffset};
	} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
	   return {y:document.documentElement.scrollTop, x:document.documentElement.scrollLeft};
	} else if (typeof document.body != 'undefined') {
	   return {y:document.body.scrollTop, x:document.body.scrollLeft};
	} else {
		return {y:0, x:0};
	}
}
function getObjPosition(obj) {
	var left=0, top=0;
	while (obj.offsetParent) {
		left 	+= obj.offsetLeft + (obj.currentStyle?(parseInt(obj.currentStyle.borderLeftWidth)).NaN0():0);
		top  	+= obj.offsetTop  + (obj.currentStyle?(parseInt(obj.currentStyle.borderTopWidth)).NaN0():0);
		obj     = obj.offsetParent;
	}
	left += obj.offsetLeft + (obj.currentStyle?(parseInt(obj.currentStyle.borderLeftWidth)).NaN0():0);
	top  += obj.offsetTop  + (obj.currentStyle?(parseInt(obj.currentStyle.borderTopWidth)).NaN0():0);
	return {x:left, y:top};
}
function getMousePosition(ev) {
	if(typeof(ev.pageX) != 'undefined') {
		return {x:ev.pageX, y:ev.pageY};
	} else {
		var ws = getWindowScroll();
		return {
			x:ev.clientX + ws.x,
			y:ev.clientY + ws.y
		};
	}
}
/**
 * t: 鼠标当前激活的Object的坐标及宽高(x, y, w, h);
 * w: 窗口滚动的坐标(x, y);
 * v: 窗口可视范围宽高(w, h);
 * o: 浮动层宽高(w, h);
 * m: 鼠标当前坐标(x, y);
 * position: {'x', 'y', 'autohide', 'mask', 'scroll', 'esc', 'hideselect'}
 */
function followEvent(obj, position, target) {
	if (!isset(position) || position==1) position = {'x': "(t.x+t.w+o.w>w.x+v.w)?((t.x-o.w<w.x)?(w.x+10):(t.x-o.w)):(t.x+t.w)", 'y': '(t.y+o.h>w.y+v.h)?((t.y+t.h-o.h-15<w.y)?(w.y+15):(t.y+t.h-o.h-5)):(t.y+5)', 'autohide': true};
	else if (position==2) position = {'x': "w.x+(v.w-o.w)/2", 'y': 'w.y+(v.h-o.h)/2', 'mask': true, 'scroll': true};

	if (obj.style.display == 'none') obj.style.display = '';
	if (obj.style.visibility == 'hidden') obj.style.visibility = '';
	if (obj.style.position != 'absolute') obj.style.position = 'absolute';

	if (!isset(target)) {
		var e = $e();
		var target = e.target || e.srcElement;
		var m = getMousePosition(e);
	}
	var viewport = (document.compatMode && document.compatMode == 'CSS1Compat') ? document.documentElement : document.body;
	var t = getObjPosition(target);
	t.w = target.offsetWidth;
	t.h = target.offsetHeight;
	var w = getWindowScroll();
	var v = {'w': viewport.clientWidth, 'h': viewport.clientHeight};
	var o = {'w': obj.offsetWidth, 'h': obj.offsetHeight};

	obj.style.left = eval(position.x) + 'px';
	obj.style.top = eval(position.y) + 'px';

	if (!empty(position.scroll) && empty(obj.scroll)) {
		// funcScroll must be global for firefox to addListner correcttly, so dont use var.
		funcScroll = function(){followEvent(obj,position,target);}
		addEvent(window, 'onscroll', funcScroll);
		obj.scroll = true;
	}
	if (!empty(position.esc) && empty(obj.esc)) {
		// funcEsc must be global for firefox to addListner correcttly, so dont use var.
		funcEsc = function(){e=$e();if(e.keyCode==27){obj.hide();}}
		addEvent(document, 'onkeyup', funcEsc);
		obj.esc = true;
	}

	if (!empty(position.mask)) {
		createMask(obj);
		position.hideselect = true; //
	}

	if (!empty(position.hideselect)) {
		var objs = $t('select');
		for (var i=0; i<objs.length; i++) {
			objs[i].saveDisplay = objs[i].style.display;
			objs[i].style.display = 'none';
		}
		obj.hideselect = true;

		// modified 20080204
		if (empty(obj.addiframe)) {
			obj.innerHTML += '<iframe src="javascript:void(0);" style="position:absolute;visibility:inherit;top:0px;left:0px;width:100%;height:100%;z-index:-1;filter=progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);"></iframe>';
			obj.addiframe = true;
		}
	}

	//if (!isset(obj.hide)) {
	if(1){
		if (position.autohide) {
			obj.onmouseover = function() { if (!empty(this.hTime)) clearTimeout(this.hTime); }
			obj.onmouseout = function() { this.hTime = setTimeout(function(){obj.hide();}, 100); }
			if (!target.onmouseout) {
				if (!isset(target.float)) target.float = obj;
				target.onmouseout = function() { if(this.float.onmouseout) this.float.onmouseout(); }
			}
		}
		obj.hide = function() {
			this.style.display = 'none';
			if (!empty(this.mask)) this.mask.hide();
			if (!empty(this.scroll)) {
				removeEvent(window, 'onscroll', funcScroll);
				this.scroll = null;
			}
			if (!empty(this.esc)) {
				removeEvent(document, 'onkeyup', funcEsc);
				this.esc = null;
			}
			if (!empty(this.hideselect)) {
				var objs = $t('select');
				for (var i=0; i<objs.length; i++) {
					if (isset(objs[i].saveDisplay)) {
						objs[i].style.display = objs[i].saveDisplay;
					}
				}
				this.hideselect = null;
			}
		}
	}
}
function createMask(obj, maskColor, opacity, noScroll) {
	if (!isset(obj.mask)) {
		maskColor = isset(maskColor) ? maskColor : '#aaa';
		opacity = isset(opacity) ? opacity : 50;
		var mask = document.createElement("div");
		var firstChild = document.body.firstChild;
		if (firstChild)	document.body.insertBefore(mask, document.body.firstChild);
		else document.body.appendChild(mask);
		mask.innerHTML = "";
		mask.style.cssText = 'z-index:9999; position:absolute; top:0; left:0; -moz-opacity: '+(opacity/100)+'; opacity:'+(opacity/100)+'; filter: alpha(opacity='+(opacity)+'); background-color:'+maskColor+';';
		mask.style.width = document.body.scrollWidth + 'px';
		mask.style.height = document.documentElement.scrollHeight + 'px';
		obj.style.zIndex = parseInt(mask.style.zIndex) + 1;
		noScroll = isset(noScroll) ? true : false;
		mask.noScroll = noScroll;
		mask.hide = function() { this.style.display = 'none'; if (this.noScroll) { $t("html")[0].style.overflow = "";} }
		mask.show = function() { this.style.display = ''; if (this.noScroll) { $t("html")[0].style.overflow = "hidden";} }
		obj.mask = mask;
		if (noScroll) { $t("html")[0].style.overflow = "hidden"; }
	} else {
		obj.mask.show();
	}
}
function initEvent(event) {
	if (!isset(event) || !isset(event.obj)) return false;
	if (!isset(event.begin)) 	event.begin = 'onclick';

	if (isset(event.confirm)) {
		event.func = function () {
			if (confirm(event.confirm)) {
				event.ok.call(this);
			}
		}
	} else if (isset(event.float)) {
		event.func = function () {
			followEvent(this.float, event.position, this);
			event.render.call(this.float, this.getAttribute('params'));
		}
	} else if (isset(event.submit))  {
		event.func = function() {
			if (event.check()) {
				event.submit();
			}
		}
	} else if (!isset(event.func)) {
		event.func = function () {
			alert('test');
		}
	}

	var objs = event.obj;
	if (is_string(objs)) objs = $n(objs);
	else if(!is_array(objs)) objs = [objs];

	for (var i=0; i<objs.length; i++) {
		if (isset(event.float)) {
			var floatDiv = _$(event.float);
			if (!empty(event.distinct)) {
				var newFloatDiv = floatDiv.cloneNode(true);
				floatDiv.parentNode.appendChild(newFloatDiv);
				newFloatDiv.id = floatDiv.id + '_' + i;
				objs[i].float = newFloatDiv;
			} else {
				objs[i].float = floatDiv;
			}
			if (event.position==1 || !empty(event.position.autohide)) {
				objs[i].onmouseout = function() { if(this.float.onmouseout) this.float.onmouseout(); }
			}
		}

		// process cancelBubble of <A>
		if ( objs[i].nodeName.toLowerCase() == 'a' || objs[i].parentNode.nodeName.toLowerCase() == 'a' ) {
			var tmp = objs[i].nodeName.toLowerCase() == 'a' ? objs[i] : objs[i].parentNode;
			tmp.href = '#0';
		}
		if (empty(event.nohand)) objs[i].style.cssText += 'cursor:pointer;';
		addEvent(objs[i], event.begin, event.func);
	}

	// bind cancel
	if (isset(event.float) && isset(event.eobj)) {
		var objs = event.eobj;
		if (is_string(objs)) objs = $n(objs);
		else if(!is_array(objs)) objs = [objs];

		for (var i=0; i<objs.length; i++) {
			if (empty(objs[i].hasBindCancel)) {
				addEvent(objs[i], 'onclick', function(){_$(event.float).hide();});
				objs[i].hasBindCancel = true;
			}
		}
	}
}
function initEvents(events) {
	if (!is_array(events)) events = [events];
	for (var i=0; i<events.length; i++) {
		initEvent(events[i]);
	}
}
function processEvt(evt)
{
	if (!isset(evt.begin)) {
		evt.begin = 'onclick';
	}
	if (isset(evt.confirm)) {
		evt.ok = evt.func;
		evt.func = function () {
			if (confirm(evt.confirm)) {
				evt.ok.call(this);
			}
		}
	} else if (isset(evt.float)) {
		evt.func = function () {
			followEvent(this.float, evt.position, this);
			if (false === evt.render.call(this) ) {
				this.float.hide();
			}
			this.float.params = this.params;
		}
	} else if (isset(evt.submit))  {
		evt.func = function() {
			if (evt.check.call(this)) {
				evt.submit.call(this);
			}
		}
	} else if (!isset(evt.func)) {
		evt.func = function () {
			alert('test');
		}
	}
}
function processEvtEnd(evt)
{
	if (!empty(evt.submit) && empty(evt.submit.regEvented) && !empty(evt.process)) {
		addEvent (evt.submit, 'onclick', function(){if(evt.process.call(_$(evt.float))){_$(evt.float).hide();}});
		evt.submit.regEvented = true;
	}
	if (!empty(evt.cancel) && empty(evt.cancel.regEvented)) {
		addEvent(evt.cancel, 'onclick', function(){_$(evt.float).hide();});
		evt.cancel.regEvented = true;
	}
}
function regEvent(evts)
{
	if (!isset(evts)) return false;
	if (empty(evts.processed)) {
		var evtCount = 0;
		for (var i in evts) {
			evtCount++;
			processEvt(evts[i]);
		}
		if (evtCount==0) return false;
		evts.processed = true;
	}

	objs = [];
	var prefix = "n_";
	var match, reg = new RegExp("^"+prefix);
	var alls = $t('*');
	for (var i=0; i<alls.length; i++) {
		if ( isset(alls[i].name) && is_string(alls[i].name) && alls[i].name.match(reg) ) {
			objs.push(alls[i]);
		} else if (isset(alls[i].id) && is_string(alls[i].id) && alls[i].id.match(reg)) {
			alls[i].name = alls[i].id;
			objs.push(alls[i]);
		}
	}

	if (objs.length==0) return false;

	var reg = new RegExp("^"+prefix+"(.*)$");
	for (var i=0; i<objs.length; i++) {
		if ( (match = reg.exec(objs[i].name)) != null ) {
			var action, actionName = match[1];

			// process objs's args
			eval ('objs.'+actionName+' = objs['+i+']');

			// process action
			eval ('action=evts.'+actionName);
			if (!empty(action)) { // exist this evt, register action for obj

				// process evt's args
				var matchSub, regSub = new RegExp("^"+prefix+actionName+"_(.*)$");
				var args = {};
				for (var j=0; j<objs.length; j++) {
					if ( (matchSub = regSub.exec(objs[j].name)) != null ) {
						//eval('args.'+matchSub[1]+'=objs['+j+']');
						eval('action.'+matchSub[1]+'=objs['+j+']');
					}
				}
				//eval ('objs['+i+'].args = args');

				// process obj's params
				objs[i].params = objs[i].getAttribute('params');

				// process obj's mouse type
				if ( !(objs[i].nodeName.toLowerCase()=='input' && objs[i].type.toLowerCase()=='text')
						&& objs[i].nodeName.toLowerCase() != 'textarea' ) {
					objs[i].style.cursor = 'pointer';
				}

				// process cancelBubble of <A>
				if ( objs[i].nodeName.toLowerCase() == 'a' || objs[i].parentNode.nodeName.toLowerCase() == 'a' ) {
					var tmp = objs[i].nodeName.toLowerCase() == 'a' ? objs[i] : objs[i].parentNode;
					tmp.href = '#0';
				}

				// process float evt
				if (isset(action.float)) {
					var floatDiv = _$(action.float);
					if (!empty(action.distinct)) {
						var newFloatDiv = floatDiv.cloneNode(true);
						floatDiv.parentNode.appendChild(newFloatDiv);
						newFloatDiv.id = floatDiv.id + '_' + i;
						objs[i].float = newFloatDiv;
					} else {
						objs[i].float = floatDiv;
					}
					if (action.position==1 || !empty(action.position.autohide)) {
						objs[i].onmouseout = function() { if(this.float.onmouseout) this.float.onmouseout(); }
					}
				}

				// register evt
				if (empty(objs[i].regEvented)) {
					addEvent (objs[i], action.begin, action.func);
					objs[i].regEvented = true;
				}
			}
		}
	}

	// process process and cancel:
	for (var i in evts) {
		if (!empty(evts[i].float)) {
			processEvtEnd(evts[i]);
		}
	}
}

/**
 * add on 20080821
 */
EventAjax = {
	s : {
		url : document.location.href,
		method : 'post',
		async : true,
		data : null,
		success : function(result) { /*alert(result);*/ },
		fail : function (e) { alert(e.description); }
	},
	//sended : [],
	send : function(pS) {
		var i, s = {};
		for (i in this.s) {s[i]=this.s[i];}
		for (i in pS) {s[i]=pS[i];}
		if (typeof(s.data) != 'string') {
			var tmp = s.data;
			s.data = '';
			for (i in tmp) {
				s.data += (i + "&" + tmp[i]);
			}
		}
		//this.sended.push(s);
		if (s.method == "script") {
			var head = document.getElementsByTagName("head")[0];
			var script = document.createElement("script");
			script.src = s.url;
			var done = false;
			script.onload = script.onreadystatechange = function () {
				if ( !done && (!this.readyState ||
					this.readyState == "loaded" || this.readyState == "complete") ) {
					done = true;
					s.success(null);
					head.removeChild(script);
				}
			}
			head.appendChild(script);
			return;
		}

		try {
			var xhr = (typeof XMLHttpRequest != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
			if (!xhr) { throw {description: "xhr error"}; }
			xhr.open(s.method, s.url, s.async);
		} catch (e) {
			s.fail(e);
			return;
		}

		if (s.method == 'post' && !empty(s.data)) {
			xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		}
		xhr.onreadystatechange = function () {
			if (xhr.readyState != 4) { return; }
			if (xhr.status==200) {
				s.success(xhr.responseText);
			} else {
				s.fail({description: xhr.statusText});
			}
		}
		try {
			xhr.send(s.data);
		} catch (e) {
			s.fail(e);
			return;
		}
	}
};

/**
 * add on 20080828
 */
function setCookie(name, value, expires, path, domain, secure)
{
    var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}
function getCookie(name)
{
	//
}