



/*****扩展开发*****/

//获取URL中变量的值
String.prototype.getQuery = function(name) {
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = this.substr(this.indexOf("\?")+1).match(reg);
	if (r!=null) {
　　	var iResult = unescape(r[2]);
　　	return iResult == null ? "" : iResult;
	}  
	return "";
}

String.prototype.trim = function() {return this.replace(/(^\s*)|(\s*$)/g,"");}

String.prototype.ltrim = function() {return this.replace(/(^\s*)/g, "");}

String.prototype.rtrim = function() {return this.replace(/(\s*$)/g, "");}

String.prototype.isNumber = function() {
	return (!isNaN( this ) && "" != this) ? true : false;
}

String.prototype.lengthByte = function() {
	var endvalue = 0;
	var sourcestr = new String(this);
	var tempstr;
	for ( var strposition=0; strposition <= sourcestr.length-1; strposition++ ) {
		tempstr = sourcestr.substr( strposition, 1 );
		endvalue += ( tempstr.charCodeAt(0) > 255 || tempstr.charCodeAt(0) < 0 ) ? 3 : 1;//UTF8，所以是+3而不是+1
	}  
	
	return(endvalue);  
}

//在数组中
Array.prototype.inArray = function( value ) {
	for ( var i=0; i< this.length; i++ ) {
		if ( this[i] == value ) {
			return true;
		}
	}
	return false;
}

//四舍五入（number.toFixed(4);）
if(typeof(Number.prototype.toFixed)!="function") {
	Number.prototype.toFixed = function(d) {
		var s=this+"";if(s.indexOf(".")==-1)s+=".";s+=new Array(d+1).join("0");
		if (new RegExp("^((-|\\+)?\\d+(\\.\\d{0,"+ (d+1) +"})?)\\d*$").test(s)) {
			s="0"+ RegExp.$1, pm=RegExp.$2, a=RegExp.$3.length, b=true;
			if (a==d+2){a=s.match(/\d/g); if (parseInt(a[a.length-1])>4) {
				for(var i=a.length-2; i>=0; i--) {a[i] = parseInt(a[i])+1;
				if(a[i]==10){a[i]=0; b=i!=1;} else break;} //author: meizz
			}
			s=a.join("").replace(new RegExp("(\\d+)(\\d{"+d+"})\\d$"),"$1.$2");
		}
		if(b)s=s.substr(1); return (pm+s).replace(/\.$/, "");} return this+"";
	};
}

/**
*   兼容firefox的 outerHTML 使用以下代码后，firefox可以使用element.outerHTML
**/
if(typeof(HTMLElement)!="undefined" && !window.opera) { 
    HTMLElement.prototype.__defineGetter__("outerHTML",function() { 
        var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++) 
        if(a[i].specified) 
            str+=" "+a[i].name+'="'+a[i].value+'"'; 
        if(!this.canHaveChildren) 
            return str+" />"; 
        return str+">"+this.innerHTML+"</"+this.tagName+">"; 
    }); 
    HTMLElement.prototype.__defineSetter__("outerHTML",function(s) { 
        var r = this.ownerDocument.createRange(); 
        r.setStartBefore(this); 
        var df = r.createContextualFragment(s); 
        this.parentNode.replaceChild(df, this); 
        return s; 
    }); 
    HTMLElement.prototype.__defineGetter__("canHaveChildren",function() { 
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase()); 
    }); 
}


/*****控件处理的封装*****/

/**
 * 复选框根据名称选择/反选
 *
 * @param element $sourceEl 源元素
 * @param string $name 目标元素的名称
 */
function strip_check( sourceEl, name ) {
    var nameEls = document.getElementsByName( name );
    for ( var j = 0; j < nameEls.length; j++ ) {
        nameEls[j].checked = sourceEl.checked;
    }
}

function strip_switch( el, containerTagName, callBackFunction, isToggle ) {
	containerTagName = containerTagName ? containerTagName : 'UL';
	containerTagName = containerTagName.toUpperCase();
	//浏览器兼容代码
	var ulEl = element_parent( el, "tagName", containerTagName );
	var liEl = element_parent( el, "tagName", el.tagName );
	var lis = ulEl.getElementsByTagName(el.tagName);

	for(var i = 0; i < lis.length; i++) {
		if (isToggle && liEl == lis[i]) {
			lis[i].className = (lis[i].className.indexOf('selected') >= 0) ? lis[i].className.replace("selected", "item") : lis[i].className.replace("item", "selected");
		}
		else {
			lis[i].className = lis[i].className.replace("selected", "").replace("item", "");
			lis[i].className += " " + (liEl == lis[i] ?  "selected" : "item");
		}
	}

	if (typeof(callBackFunction) == 'function') { callBackFunction(); }

}

function strip_tab( el, targetId, targetItemTagName, targetToggleTagName ) {
	if (el.className.indexOf('selected') >=0) { return; }
	var cEl = document.all ? el.parentElement : el.parentNode;
	var cEls = cEl.getElementsByTagName(el.tagName);
	var index = -1;
	for (var i = 0; i < cEls.length; i++) {
		if (cEls[i] == el) { index = i; cEls[i].className += " selected"; }
		else { cEls[i].className = cEls[i].className.replace("selected", ""); }
	}
	
	var tEls = document.getElementById(targetId).getElementsByTagName(targetItemTagName);
	var hEls = new Array();
	if (targetToggleTagName) {
		hEls = document.getElementById(targetId).getElementsByTagName(targetToggleTagName);
	}
	for (var i = 0; i < tEls.length; i++) {
		tEls[i].style.display = i == index ? '' : 'none'; 
		if (hEls[i]) { 
			hEls[i].style.display = i == index ? 'none' : ''; 
		}
	}
}


/*****元素操作*****/

/**
 * 元素的展开与折叠
 *
 * @param string id 元素的编号
 * @param bool|null isExpend 是否展开（为空则默认在显示和隐藏间进行切换）
 */
function element_collapse( id, isExpend ) {
    var oEl = F.$( id );
    if ( oEl ) {
        if ( isExpend != 'undefined' && isExpend != undefined ) {
            oEl.style.display = isExpend ? '' : 'none';
        }
        else {
            oEl.style.display = 'none' == oEl.style.display ? '' : 'none';
        }
    }
}

/**
 * 获取父级元素
 *
 * @param element el 源元素
 * @param string type 元素类型
 * @param string value 匹配的值
 * @return element parentElement
 */
function element_parent( el, type, value ) {
	var temp = el;
	while ( ( temp != null ) && ( temp.tagName != "BODY" ) ) {
		if ( eval( "temp." + type ) == value ) {
			return temp;
		}
		temp = document.all ? temp.parentElement : temp.parentNode;
	}
	return null;
}

/**
 * 获取元素内容
 *
 * @param element el 源元素
 * @return string 内容
 */
function element_innerText( el ) {
	try { return document.all ? el.innerText : el.textContent; } catch (e) { return ""; }
}

function element_fireEvent( el, eventName ) {
	if ( document.all ) {
		el.fireEvent( "on" + eventName );
	}
	else {
		var evtObj = document.createEvent( 'HTMLEvents' );
		evtObj.initEvent( eventName, true, true );
		el.dispatchEvent( evtObj );
	}
}

/**
 * 精确获取元素样式
 *
 * @param string id 链接地址所处的控件编号
 * @param string tip 如果打不开弹出的提示内容
 */
function element_style( oEl, name ) {
	if (oEl.style[name]) {
		return oEl.style[name];
	}
	else if (oEl.currentStyle) {
		return oEl.currentStyle[name];
	}
	else if (document.defaultView && document.defaultView.getComputedStyle) {
		name = name.replace(/([A-Z])/g,"-$1");
		name = name.toLowerCase();
		var s = document.defaultView.getComputedStyle(oEl, "");
		return s && s.getPropertyValue(name);   
	}
	else if (oEl[name]) {
		return oEl[name];
	}
	else {   
		return null;
	}
}

/**
 * 弹出目标链接
 *
 * @param string id 链接地址所处的控件编号
 * @param string tip 如果打不开弹出的提示内容
 */
function element_link_view( id, tip ) {
	var oEl = F.$( id );
	if (oEl.value == '') {
		F.msgbox.content(tip, 'empty');
		return;
	}
	window.open(oEl.value);
}

/**
 * 表格行的展开与折叠
 *
 * @param element aEl 触发事件的链接元素
 * @param int depthIndex 表格哪一列记录着深度索引
 * @param bool isDefaultSub 默认第一个操作采用的是否是折起
 * @param string supString 展开表格后链接呈现的文字
 * @param string subString 折起表格后链接呈现的文字
 */
function table_collapse(aEl, depthIndex) {
	var tabEl = element_parent( aEl, 'tagName', 'TABLE' );
	var trEl = element_parent( aEl, 'tagName', 'TR' );
	if ( !tabEl ) { return; }
	
	var depth = -1; 
	var isSub = true;
	for ( var i=0; i < tabEl.rows.length; i++ ) {
		var trDepth = element_innerText( tabEl.rows[i].cells[depthIndex] );
		trDepth = trDepth.isNumber() ? trDepth : 0;

		if ( depth >= 0 ) {
			if ( depth < trDepth ) { tabEl.rows[i].style.display = isSub ? 'none' : ''; } else { break; }
		}
		
		if ( depth < 0 && trEl == tabEl.rows[i] ) {
			depth = trDepth;
			isSub = undefined == tabEl.rows[i].getAttribute('_issub') ? true : tabEl.rows[i].getAttribute('_issub') == 'true';
		}
		
		if ( depth >= 0 ) { tabEl.rows[i].setAttribute('_issub', !isSub); }
	}
}


/**
 * 表格行的选择与取消选择
 *
 * @param element chkEl 触发事件的选择元素
 * @param int depthIndex 表格哪一列记录着深度索引
 */
function table_checked(chkEl, depthIndex) {
	var tabEl = element_parent( chkEl, 'tagName', 'TABLE' );
	var trEl = element_parent( chkEl, 'tagName', 'TR' );
	if ( !tabEl ) { return; }
	
	var depth = -1; 
	var isSub = false;
	for ( var i=0; i < tabEl.rows.length; i++ ) {
		var trDepth = element_innerText( tabEl.rows[i].cells[depthIndex] );
		trDepth = trDepth.isNumber() ? trDepth : 0;

		if ( depth >= 0 ) {
			if ( depth < trDepth ) { 
				var chkEls = tabEl.rows[i].getElementsByTagName('INPUT');
				for (var j=0; j<chkEls.length; j++) {
					if (chkEls[j].type == 'checkbox') { chkEls[j].checked = chkEl.checked; break; }
				}
			} else { break; }
		}
		
		if ( depth < 0 && trEl == tabEl.rows[i] ) {
			depth = trDepth;
			isSub = true;
		}
	}
}

function image_resize( imgEl, width, height ) {
	window.setTimeout(	
		function () {
			var imgObj = new Image();
			imgObj.src = imgEl.src;
			//alert(imgObj.width);
			if (imgObj.width > 0 && imgObj.height > 0) {
				imgEl.style.width = imgObj.height > imgObj.width ? 'auto' : width + 'px';
				imgEl.style.height = imgObj.height > imgObj.width ? height + 'px' : 'auto';
				imgEl.style.marginLeft = imgEl.style.marginRight = imgObj.height > imgObj.width ? ((width - width * imgObj.width / imgObj.height) / 2) + 'px' : '0px';
				imgEl.style.marginTop = imgEl.style.marginBottom = imgObj.height > imgObj.width ? '0px' : ((height - height * imgObj.height / imgObj.width) / 2) + 'px';
			}
			imgObj = null;	//release
		},
		20	
	);
}

function html_carousel_switch( id, imgUrl, imgLink ) {
	F.$( id + '_img' ).src = imgLink;
	F.$( id + '_link' ).href = imgUrl;
}

/**
 * html_explorer支持函数
 *
 * @param element event 事件托管
 * @param element curEl 事件触发者
 */
function html_explorer_onclick ( curEl, event ) {
	var inputEls = curEl.getElementsByTagName('INPUT');
	var inputEl = inputEls[0];
	if ( event.ctrlKey ) {
		inputEl.checked = !inputEl.checked;
	}
	else if (event.shiftKey) {
		var conEl = document.all ? curEl.parentElement : curEl.parentNode;
		var divEls = conEl.getElementsByTagName('DIV');
		var chkEls = conEl.getElementsByTagName('INPUT');
		var chkStart = -1;
		var chkEnd = -1;
		var chkIsCurEl = false;
		for( var i=0; i < chkEls.length; i++ ) {
			if (chkStart >= 0 && (chkIsCurEl ? chkEls[i].checked : divEls[i] == curEl)) { chkEnd = i; break; }
			if (chkStart < 0 && chkEls[i].checked || divEls[i] == curEl) {
				if (chkEls[i].checked && divEls[i] == curEl) {
					chkStart = chkEnd = i; break;
				}
				else {
					chkStart = i; 
					chkIsCurEl = divEls[i] == curEl; 
				}
			}
		}

		for( var i=0; i < chkEls.length; i++ ) {
			chkEls[i].checked = chkStart <= i && chkEnd >= i;
			divEls[i].className = chkEls[i].checked ? "selected" : "";
		}

		inputEl.checked = true;
	}
	else {
		var conEl = document.all ? curEl.parentElement : curEl.parentNode;
		var divEls = conEl.getElementsByTagName('DIV');
		var chkEls = conEl.getElementsByTagName('INPUT');
		for( var i=0; i < chkEls.length; i++ ) { 
			chkEls[i].checked = false; 
			divEls[i].className = "";
		}

		inputEl.checked = true;
	}
	curEl.className = inputEl.checked ? "selected" : "";
}


function html_rating_onmouseout( raid ) {
	var raEl = F.$( raid );
	var valEl = F.$( raid + "_value");
	var hovEl = F.$( raid + "_hover");
	if ( hovEl ) {
		if ( valEl && valEl.value && valEl.value > 0 ) {
			var ra = html_rating_region( raEl );
			hovEl.style.width = ( valEl.value * 100 / ra.region ) + '%';
		}
		else {
			hovEl.style.width = '0%';
		}
	}
}
function html_rating_onmousemove( raid, event ) {
	var raEl = F.$( raid );
	var ra = html_rating_region( raEl );
	if ( !ra.region ) { return; }
	var hovEl = F.$( raid + "_hover" );
	hovEl.style.width = ( Math.ceil( ( event.clientX - F.page.absoluteLeft( raEl ) ) / ra.width ) * 100 / ra.region ) + '%';
}
function html_rating_onclick( raid, event, eventFunction ) {
	var raEl = F.$( raid );
	var ra = html_rating_region( raEl );
	
	var value = Math.ceil( ( event.clientX - F.page.absoluteLeft( raEl ) ) / ra.width );

	if ( eventFunction ) {
		eval(eventFunction + '( raEl, value )');
	}
	else {
		F.$( raid + "_value").value = value;
	}
}

function html_rating_region( raEl ) {
	var result = {
		width: raEl.getAttribute('_width'),
		height: raEl.getAttribute('_height'),
		region: raEl.getAttribute('_region')
	}
	return result;
}

function html_rating_clearevent( raEl ) {
	var eventEl = F.$( raEl.id + '_event' );
	if ( eventEl ) { 
		html_rating_onmouseout( raEl.id );
		raEl.removeChild( eventEl ); 
		raEl.style.cursor = "auto";
	}
}

function html_rating_animation(curEl, value, step) {
	if (step >= 1) {
		curEl.style.width = value + '%';
	}
	else {
		curEl.style.width = (value * step) + '%';
		window.setTimeout( function () { html_rating_animation( curEl, value, step+0.05 ) }, 20 );
	}
}


/**
 * html_rating支持函数
 *
 * @param string id 事件编号
 * @param int current 当前值
 */
function html_rating_onload( id, current, isAnimation ) {
	var raEl = F.$( id );
	var ra = html_rating_region( raEl );
	if (!ra.region) { return; }
	if (isNaN(current)) { current = 0; }
	var curEl = F.$( id + "_current" );
	if ( isAnimation ) {
		html_rating_animation(curEl, current  * 100 / ra.region, 0);
	}
	else {
		curEl.style.width =  ( current  * 100 / ra.region ) + '%';
	}

	var evEl = F.$( id + "_event" );
	if ( evEl ) { raEl.style.cursor = "pointer"; }
	html_rating_onmouseout( id );
}

function html_rating_eval( json, min, max, ratingPrefix, valuePrefix ) {
	var _nums = 0;
	for (var j = min; j <= max; j++) {
		if (json['nos' + j]) { _nums += new Number(json['nos' + j]); }
	}
	for (var j = min; j <= max; j++) {
		var _value = json['nos' + j] ? new Number(json['nos' + j]) : 0;

		if (ratingPrefix) { html_rating_onload( ratingPrefix + j, _value * 100 / _nums, true); }
		if (valuePrefix) { F.$( valuePrefix + j).innerHTML = _value; }
	}
}

function html_rating_values( json, min, max, offset ) {
	//rules:[ 0最小范围, 1最大范围, 2偏移量]
	//return:[0total, 1sums, 2avg]
	
	var _sums = 0;
	var _total = 0;
	for ( var i = min; i <= max; i++ ) {
		if (json['nos' + i]) { 
			_sums += new Number(json['nos' + i]) * (i - offset); 
			_total += new Number(json['nos' + i]);
		}
	}
	if ( 0== _total ) { return 0; }
	return { total:_total, sums:_sums, avg:(_sums / _total) };
}




/*****RPC操作*****/

function ajax_element_select(fromId, toId, toHideId, url, paramName, titleName, valueName, params, isDispatchEvent, rootText) {
	
	var fromEl = F.$( fromId );
	var toEl = F.$( toId );
	var toHideEl = F.$( toHideId );
	
	if ( params == undefined ) { params = new Array(); }
	if (fromEl.selectedIndex < 0 && fromEl.options.length) { fromEl.selectedIndex = 0;}
	if ( document.all ) {
		fromEl.attachEvent( 'onchange', ajax_element_select_from_attach_onchange( fromEl, toEl, toHideEl, url, paramName, titleName, valueName, params, rootText ) );
		toEl.attachEvent( 'onchange', ajax_element_select_to_attach_onchange( toEl, toHideEl ) );
	}
	else {
		fromEl.addEventListener( 'change', ajax_element_select_from_attach_onchange( fromEl, toEl, toHideEl, url, paramName, titleName, valueName, params, rootText ), false );
		toEl.addEventListener( 'change', ajax_element_select_to_attach_onchange( toEl, toHideEl ), false );
	}
	if ( isDispatchEvent ) { ajax_element_select_from_attach_onchange( fromEl, toEl, toHideEl, url, paramName, titleName, valueName, params, rootText )(); }
}

var ajax_element_select_to_attach_onchange = function( toEl, toHideEl ) {
	return function() { toHideEl.value = toEl.value; }
}

var ajax_element_select_from_attach_onchange = function( fromEl, toEl, toHideEl, url, paramName, titleName, valueName, params, rootText ) {
	return function() {
    	params.push( [paramName, fromEl.value] );
    	F.ajax.api(
    		function( json ) {
    			if ( toEl.options.length > 0 ) { toHideEl.value = ''; }
    			toEl.options.length = 0;
    			if (rootText) {
					var optEl = new Option( rootText, '' );
					toEl.options.add( optEl );
    			}
    			for( i = 0; i < json.length; i++ ) {
					var optEl = new Option( json[i][titleName], json[i][valueName] );
					if ( json[i][valueName] == toHideEl.value ) { optEl.selected = true; }
					toEl.options.add( optEl );
				}
				
				if (toEl.selectedIndex < 0 && toEl.options.length > 0) { toEl.selectedIndex = 0;}

				if ( document.all ) {
					toEl.fireEvent( "onchange" );
				}
				else {
					var evtObj = document.createEvent( 'HTMLEvents' );
					evtObj.initEvent( "change", true, true );
					toEl.dispatchEvent( evtObj );
				}
				
				//if (toEl.options.length > 0 && toHideEl.value == '') { 
				//	toHideEl.value = toEl.options[0].value; 
				//}
				
    		}, 
	    	url, 
	    	params
	    );
    }
}

/*************************************ADDON*************************************/

var F={};
F.$=function( id ) { return document.getElementById( id ); }

F.control = {};
F.control.select =function() { return {
		fillJson:function( selEl, json, titleField, valueField ) {
			if (typeof(selEl) != 'object') { selEl = F.$(selEl); }
			for(var i = selEl.options.length - 1; i >= 0; i--) { selEl.options[i] = null; }
			for (var index in json.data) {
				if (json.data[index][titleField] && json.data[index][valueField]) {
					var optEl = document.createElement("OPTION");
					optEl.value = json.data[index][valueField];
					optEl.text = json.data[index][titleField];
					//if (selEl.options.length == 0) { optEl.selected = true; }
					selEl.options.add(optEl);
				}
			}
			if (selEl.options.length) { selEl.selectIndex = 0; }
		},
		insertSelected:function( fromSelEl, toSelEl ) {
			if (typeof(fromSelEl) != 'object') { fromSelEl = F.$(fromSelEl); }
			if (typeof(toSelEl) != 'object') { toSelEl = F.$(toSelEl); }
			
			for(var i = 0; i < fromSelEl.options.length; i++) { 
				if (!fromSelEl.options[i].selected) { continue; }
				
				var flag = false;
				for(var j = 0; j < toSelEl.options.length; j++) {
					if (fromSelEl.options[i].value == toSelEl.options[j].value) { flag = true; break; }
				}
				if (!flag) {
					var optEl = document.createElement("OPTION");
					optEl.value = fromSelEl.options[i].value;
					optEl.text = fromSelEl.options[i].text;
					toSelEl.options.add( optEl );
				}
			}
		},
		deleteSelected:function( fromSelEl ) {
			if (typeof(fromSelEl) != 'object') { fromSelEl = F.$(fromSelEl); }
			for(var i= fromSelEl.options.length-1; i >= 0; i--) {
				if ( fromSelEl.options[i].selected ) { fromSelEl.options[i] = null; }
			}
		},
		selectAll:function( fromSelEl ) {
			if (typeof(fromSelEl) != 'object') { fromSelEl = F.$(fromSelEl); }
			for(var i= fromSelEl.options.length-1; i >= 0; i--) {
				fromSelEl.options[i].selected = true;
			}
		}
}}();

F.relative=function() {
	var p,b,f=0,i=-1;
	return{
		show:function( tEl, event, path, appendString ) {
			if ( !f ) {
				p = document.createElement('div'); p.id='rbox';
				b = document.createElement('table'); b.id='rbox_content';
				document.body.appendChild(p); p.appendChild(b);
				p.style.visibility='hidden'; p.style.display='block'; p.style.zIndex=1000; p.style.position='absolute'; p.style.backgroundColor='#ffffff'; p.style.fontSize='14px';
				b.style.border='#cccccc solid 1px'; b.style.width='100%'; b.style.borderCollapse='collapse'; b.style.cursor='default'; //b.style.borderWidth = '1px'; b.style.borderStyle = 'solid'; b.style.borderColor = '#CCCCCC'; 
				f=1;
			}
			
			var ts = new Array();
			if (appendString) { ts = tEl.value.split(appendString); }
			var realValue = (appendString ? ts.pop() : tEl.value) + '';
			
			if (realValue.trim()) {
				var k = document.all ? event.keyCode : event.which;
				if ( k == 37 || k == 38 || k == 39 || k == 40 ) {
					if (b.rows.length == 0) { return; }
					if (i > (b.rows.length - 1)) { i = b.rows.length - 1; }
					if (i >= 0) { b.rows[i].style.backgroundColor = '#FFFFFF'; }
					if (k == 37 || k == 38) { if (i < 1) { i = 1; } b.rows[i-1].style.backgroundColor = '#EEEEEE'; i--; }
					if (k == 39 || k == 40) { if (i >= (b.rows.length - 1)) { i = b.rows.length - 2; } b.rows[i+1].style.backgroundColor = '#EEEEEE'; i++; }
					tEl.value = (appendString && ts.length > 0 ? ts.join( appendString ) + appendString : '') + element_innerText( b.rows[i] );
				}
				else {
					i = -1;	//重置索引
					F.ajax.api(
						function( json ) {
							var trEls = b.getElementsByTagName('TR');
							for (var j = trEls.length - 1; j >= 0; j--) { 
								if (document.all) { b.deleteRow(j); } else { b.removeChild(trEls[j]); }
							}
							p.style.top = F.page.absoluteTop( tEl ) + tEl.offsetHeight + 'px';
							p.style.left = F.page.absoluteLeft( tEl ) + 'px';
							p.style.width = tEl.offsetWidth + 'px';
							p.style.visibility = 'visible';
							for (var index in json) {
								if (json[index] && typeof(json[index]) == "string") {
									var trEl = document.all ? b.insertRow() : document.createElement("tr");
									var tdEl = document.createElement("td");
									tdEl.innerHTML = json[index];
									trEl.appendChild( tdEl );
									trEl.style.backgroundColor = '#FFFFFF';
									if ( document.all ) {
										trEl.attachEvent( 'onmouseover', F.relative.onmouseover( trEl ) );
										trEl.attachEvent( 'onmouseout', F.relative.onmouseout( trEl ) );
										tdEl.attachEvent( 'onclick', F.relative.onmouseclick( tdEl, tEl, appendString, ts ) );
									}
									else {
										b.appendChild( trEl );
										trEl.addEventListener( 'mouseover', F.relative.onmouseover( trEl ), false );
										trEl.addEventListener( 'mouseout', F.relative.onmouseout( trEl ), false );
										tdEl.addEventListener( 'click', F.relative.onmouseclick( tdEl, tEl, appendString, ts ), false );
									}
								}
							}
						}, path, [['title', realValue.trim()]]
					);
				}
			}
			else {
				F.relative.blur( tEl );
			}
		},
		onmouseclick:function( tdEl, tEl, appendString, ts ) {
			return function() { 
				tEl.value = (appendString && ts.length > 0 ? ts.join( appendString ) + appendString : '') + element_innerText( tdEl ) + (appendString ? appendString : '');
				p.style.visibility = 'hidden'; tEl.focus();
			}
		},
		onmouseover:function( trEl ) {
			return function() { trEl.style.backgroundColor = '#EEEEEE'; }
		},
		onmouseout:function( trEl ) {
			return function() { trEl.style.backgroundColor = '#FFFFFF'; }
		},
		blur:function( tEl ) {
			if (p) { window.setTimeout( function() { p.style.visibility = 'hidden'; }, 300 ); }
		}
	}
}();


F.tip=function() {
	var p,b,ltEl,lsEl,isMouseOver=false,f=0;
	return{
		/*tEl:资源，一般传入this；sEl:目标，传入目标对象；isRight:是否是靠右放置，默认靠下放置*/
		show:function(tEl, sEl, isRight, offsetX) {
			isMouseOver = true;
			if( !f ) {
				p=document.createElement('div'); p.id='pbox';
				b=document.createElement('div'); b.id='pbox_content';
				document.body.appendChild(p); p.appendChild(b);
				p.style.zIndex = 1000;
				p.style.position = 'absolute';
				p.onmouseover = function() { isMouseOver = true; }
				p.onmouseout = function() {
					isMouseOver = false;
					window.setTimeout(
						function() {
							if (!isMouseOver) { 
								if (lsEl) { lsEl.style.display = 'none'; document.body.appendChild(lsEl); }
								ltEl = lsEl = null;
								p.style.display = 'none'; 
							}
						},
						1000 
					);
				}
				f=1;
			}


			if (p.style.display != 'none' && ltEl == tEl) {
				return;
			}
			else {
				if (ltEl) { ltEl.onmouseout = function() {} ; }
				ltEl = tEl;
				if (lsEl) { lsEl.style.display = 'none'; document.body.appendChild(lsEl); }
				lsEl = sEl;
			}
			
			if (!offsetX) {offsetX = 0;}
			if ( isRight ) {
				p.style.top = F.page.absoluteTop( tEl ) + 'px';
				p.style.left = offsetX + F.page.absoluteLeft( tEl ) + tEl.offsetWidth + 'px';
			}
			else {
				p.style.top = F.page.absoluteTop( tEl ) + tEl.offsetHeight + 'px';
				p.style.left = offsetX + F.page.absoluteLeft( tEl ) + 'px';
			}
			b.appendChild( sEl );

			ltEl = tEl;
			lsEl = sEl;
			p.style.display = sEl.style.display = '';

			tEl.onmouseout = function() {
				isMouseOver = false; 
				window.setTimeout( 
					function() { 
						if (!isMouseOver) {
							if (lsEl) { lsEl.style.display = 'none'; document.body.appendChild(lsEl); }
							ltEl = lsEl = null;
							p.style.display = 'none'; 
						} 
					}, 
					1000 
				);
			}
			
		}
	}
}();
			
F.box=function() {
	var p,m,b,fn,ic,iu,iw,ih,ia,f=0;
	return{
		visible:function() {
			return undefined != p && p.style.opacity != 0 ? true : false;
		},
		//第一个是要显示的 AJAX 或 HTML 内容。第二个是设置是否为 AJAX。第三个是宽度，0 为自动。第四个是高度，0 为自动。第五个是是否设置隐藏，第六个则是设置是否自动隐藏的时间
		show:function(c,u,w,h,a,t){
			if(!f){
				p=document.createElement('div'); p.id='fbox';
				m=document.createElement('div'); m.id='fbox_mask';
				b=document.createElement('div'); b.id='fbox_content';
				
				document.body.appendChild(m); document.body.appendChild(p); p.appendChild(b);
				/*m.onclick=F.box.hide;*/ window.onresize=F.box.resize; f=1;
			}
			//if (!w) { w = 400; }/*设置一个默认的宽度，太窄的界面不好看*/
			if(!a&&!u){
				p.style.width=w?w+'px':'auto'; p.style.height=h?h+'px':'auto';
				p.style.backgroundImage='none'; b.innerHTML=c
			}else{
				b.style.display='none'; p.style.width=p.style.height='100px'
			}
			this.mask();
			ic=c; iu=u; iw=w; ih=h; ia=a; this.alpha(m,1,100,3);
			if(t){setTimeout(function(){F.box.hide()},1000*t)}
		},
		fill:function(c,u,w,h,a){
			if(u){
				p.style.backgroundImage='';
				var x=F.ajax.create();
				x.onreadystatechange=function(){
					if(x.readyState==4&&x.status==200){F.box.push(x.responseText,w,h,a)}
				};
				x.open('GET',c,1); x.send(null)
			}else{
				this.push(c,w,h,a)
			}
		},
		push:function(c,w,h,a){
			if(a){
				if(!w||!h) {
					/*var x=p.style.width, y=p.style.height;*/ b.innerHTML=c;
					p.style.width=w?w+'px':''; p.style.height=h?h+'px':'';
					document.body.appendChild(p); b.style.display=''; w=parseInt(b.offsetWidth); h=parseInt(b.offsetHeight);
					/*m.appendChild(p); p.style.width=x; p.style.height=y;*/
				}else{
					b.innerHTML=c;
				}
				this.size(p,w,h);
			}else{
				p.style.backgroundImage='none'
			}
		},
		hide:function(){
			F.box.alpha(p,-1,0,3);
			if (typeof(this.hideCallback) == 'function') { this.hideCallback(); }
		},
		hideCallback:null,
		resize:function(){
			F.box.pos(); F.box.mask()
		},
		mask:function(){
			m.style.height=F.page.total(1)+'px';
			m.style.width=''; m.style.width=F.page.total(0)+'px'
		},
		pos:function(){
			var t=(F.page.height()/3)-(p.offsetHeight/2); t=t<10?10:t;
			p.style.top=(t+F.page.top())+'px';
			p.style.left=(F.page.width()/2)-(p.offsetWidth/2)+'px'
		},
		alpha:function(e,d,a){
			clearInterval(e.ai);
			if(d==1){
				e.style.opacity=0; e.style.filter='alpha(opacity=0)';
				e.style.display='block'; this.pos()
			}
			e.ai=setInterval(function(){F.box.ta(e,a,d)},20)
		},
		ta:function(e,a,d){
			var o=Math.round(e.style.opacity*100);
			if(o==a){
				clearInterval(e.ai);
				if(d==-1){
					e.style.display='none';
					e==p?F.box.alpha(m,-1,0,2):b.innerHTML=p.style.backgroundImage=''
				}else{
					e==m?this.alpha(p,1,100):F.box.fill(ic,iu,iw,ih,ia)
				}
			}else{
				var n=Math.ceil((o+((a-o)*.5))); n=n==1?0:n;
				e.style.opacity=n/100; e.style.filter='alpha(opacity='+n+')'
			}
		},
		size:function(e,w,h){
			if ( e == undefined ) { e=p; w=parseInt(b.offsetWidth); h=parseInt(b.offsetHeight); }
			
			e= typeof e=='object' ? e : F.$(e); clearInterval(e.si);
			var ow=e.offsetWidth, oh=e.offsetHeight, wo=ow-parseInt(e.style.width), ho=oh-parseInt(e.style.height);//TODO:改为正则表达式
			var wd=ow-wo>w?0:1, hd=(oh-ho>h)?0:1;
			e.si=setInterval(function(){F.box.ts(e,w,wo,wd,h,ho,hd)},20)
		},
		ts:function(e,w,wo,wd,h,ho,hd){
			var ow=e.offsetWidth-wo, oh=e.offsetHeight-ho;
			if(ow==w&&oh==h){
				clearInterval(e.si); p.style.backgroundImage='none'; b.style.display='block'
			}else{
				if(ow!=w){var n=ow+((w-ow)*.5); e.style.width=wd?Math.ceil(n)+'px':Math.floor(n)+'px'}
				if(oh!=h){var n=oh+((h-oh)*.5); e.style.height=hd?Math.ceil(n)+'px':Math.floor(n)+'px'}
				this.pos()
			}
		}
	}
}();

F.msgbox=function(){
	var b,x,t,c,f=0;
	return{
		build:function(){
			if(!f){
				b=document.createElement('div'); b.id='mbox';
				c=document.createElement('div'); c.id='mbox_content';
				x=document.createElement('a');
				t=document.createElement('h3');
				b.style.zIndex='1500'; b.style.position='absolute';x.href='JavaScript:;';x.className='close';x,innerHTML='&nbsp;';
				if (document.all) { 
					x.attachEvent('onclick', F.msgbox.hide);
					window.attachEvent('onresize', F.msgbox.onresize());
					window.attachEvent('onscroll', F.msgbox.onresize());
					b.style.styleFloat='left';
				}
				else {
					x.addEventListener('click', F.msgbox.hide, false);
					window.addEventListener('resize', F.msgbox.onresize(), false);
					window.addEventListener('scroll', F.msgbox.onresize(), false);
					b.style.cssFloat='left';
				}
				b.style.display='none';
				document.body.appendChild(b); b.appendChild(x); b.appendChild(t); b.appendChild(c);
				f=1;
			}
		},
		ajax:function(path, title, w, h){
			this.build();
			t.innerHTML = title; t.style.display = x.style.display = title ? '' : 'none';
			b.style.width=w?w+'px':'350px'; b.style.height=h?h+'px':'auto';
			F.ajax.content(path,c,false,function(){ F.msgbox.show(); F.msgbox.move(); }, 'null');
		},
		content:function(content, title, w, h){
			this.build();
			t.innerHTML = title; t.style.display = x.style.display = title ? '' : 'none';
			b.style.width=w?w+'px':'350px'; b.style.height=h?h+'px':'auto';
			c.innerHTML = content; this.show(); this.move();
		},
		move:function(){
			if (b.style.display=='none'){return false;}
			var t=(F.page.height()*2/5)-(F.page.height(b)/2);
			b.style.top=(t+F.page.top())+'px';
			b.style.left=(F.page.width()/2)-(F.page.width(b)/2)+'px';	
		},
		isShow:function(){
			return b.style.display != 'none';
		},
		show:function(callback, w, h){
			b.style.display='';F.msgbox.move();
			if (w) { b.style.width=w+'px'; } if (h) { b.style.height=h+'px'; }
			if (typeof(callback) == 'function') { callback(); }
			else if (typeof(this.showCallback) == 'function') { this.showCallback(); }
		},
		showCallback:null,		
		hide:function(callback){
			b.style.display='none';
			if (typeof(callback) == 'function') { callback(); }
			else if (typeof(this.hideCallback) == 'function') { this.hideCallback(); }
		},
		hideCallback:null,		
		onresize:function() {
			return function() { F.msgbox.move(); }
		}	
	}
}();

F.page=function(){
	return{
		top:function(){return document.documentElement.scrollTop||document.body.scrollTop},
		width:function(oEl){
			if (oEl) {
				if (oEl.style.display != "none") {return oEl.offsetWidth || oEl.clientWidth;}
				else {oEl.style.display = "block"; var w = oEl.offsetWidth || oEl.clientWidth; oEl.style.display = "none"; return w;}
			}
			return self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
		},
		height:function(oEl){
			if (oEl) {
				if (oEl.style.display != "none") {return oEl.offsetHeight || oEl.clientHeight;}
				else {oEl.style.display = "block"; var h = oEl.offsetHeight || oEl.clientHeight; oEl.style.display = "none"; return h;}
			}
			return self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
		},
		getFinalStyle: function(elem, css) {
			if (window.getComputedStyle) { return window.getComputedStyle(elem, null)[css]; } 
			else if (elem.currentStyle) { return elem.currentStyle[css]; } 
			else { return elem.style[css]; }
		},
		total:function(d){
			var b=document.body, e=document.documentElement;
			return d?Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight)):
			Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))
		},
		absoluteLeft:function( oEl ) {
			var x = oEl.offsetLeft;
			while(oEl = oEl.offsetParent) {
				x += oEl.offsetLeft;
			}
			return x;
		},
		absoluteTop:function( oEl ) {
			var y = oEl.offsetTop;
			while( oEl = oEl.offsetParent ) {
				y += oEl.offsetTop;
			}
			return y;
		}
	}
}();

F.browser=function() {
	return {
		/**
		 * 获取浏览器类型
		 *
		 * @return string 反馈的类型有：netscape、opera、konqueror、firefox、ie、unknown
		 */
		type: function() {
			if ( document.layers ) return "netscape";
			if ( document.all ) {
				var agt=navigator.userAgent.toLowerCase();
				var is_opera = ( agt.indexOf( "opera" ) != -1 );
				var is_konq = ( agt.indexOf( "konqueror" ) != -1 );
				if( is_opera ) {
					return "opera";
				} else {
					if( is_konq ) {
						return "konqueror";
					} else {
						return "ie";
					}
				}
			}
			if ( document.getElementById ) { return "firefox"; }
			return "unknown";
		}
	}
}();

F.ajax=function() {
	return {
		/**
		 * 创建RPC对象
		 *
		 * @return object|null RPC对象
		 */
		create: function() {
			var xmlhttp = null;
			try { xmlhttp = new XMLHttpRequest(); } catch (e) {
				try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
					try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { xmlhttp = false; }
				}
			}
			return xmlhttp;
		},
		/**
		 * 把表单数据构造成可以被XmlHttp发送的内容
		 *
		 * @param element formEl 表单元素
		 * @return string url编码结果
		 */
		encode: function( formEl ) {
			var encodeResult = '';
			if ( !formEl ) { return ''; }
			
			var oEls = formEl.getElementsByTagName('INPUT');
			for ( var i=0; i<oEls.length; i++ ) {
				if ( oEls[i].name != '' ) {
					var type = oEls[i].getAttribute("type");
					if ( ( "checkbox" == type || "radio" == type ) && !oEls[i].checked ) { continue; }
					encodeResult += oEls[i].name + "=" + encodeURIComponent(oEls[i].value) + "&";
				}
			}

			var oEls = formEl.getElementsByTagName('TEXTAREA');
			for ( var i=0; i<oEls.length; i++ ) {
				if ( oEls[i].name != '' ) {
					encodeResult += oEls[i].name + "=" + encodeURIComponent(oEls[i].value) + "&";
				}
			}

			var oEls = formEl.getElementsByTagName('SELECT');
			for ( var i=0; i<oEls.length; i++ ) {
				if ( oEls[i].name != '' ) {
					if ( !oEls[i].multiple ) {
						encodeResult += oEls[i].name + "=" + encodeURIComponent(oEls[i].value) + "&";
					}
					else {
						for ( var j=0; j<oEls[i].options.length; j++ ) {
							if ( oEls[i].options[j].selected ) {
								encodeResult += oEls[i].name + "=" + encodeURIComponent(oEls[i].options[j].value) + "&";
							}
						}
					}
				}
			}
			return encodeResult;
		},
		/**
		 * 发起块请求
		 *
		 * @param element oEl 发起请求的对象，一般传入this
		 * @param string|null formId 需要做回发界面处理的表单，不填的话系统会自动找请求者的父级表单
		 * @param bool isAppend 是否采用追加模式
		 * @param function evalCallBack 回发执行的代码函数
		 * @param array encodeForm 编码过的表单
		 */
		block: function( oEl, formId, isAppend, evalCallBack, encodeForm ) {
			var frmEl = formId ? F.$( formId ) : element_parent( oEl, 'tagName', 'FORM' );
			var xmlHttp = F.ajax.create();
			if ( frmEl && xmlHttp ) {

				var action = frmEl.action;
				if (oEl.tagName == 'A' && oEl.href.substr(0, 4).toLowerCase() == 'http') {
					action = oEl.href;
				}
				action += (action.indexOf('?') >= 0 ? '&' : '?') + '_timer='  + new Date().getTime();
				xmlHttp.open( frmEl.method, action, true );
				xmlHttp.onreadystatechange = function() {
					if( xmlHttp.readyState==4 ) {
						//alert(xmlHttp.responseText);
						if ( isAppend ) {
							frmEl.innerHTML += xmlHttp.responseText;
						}
						else {
							frmEl.outerHTML = xmlHttp.responseText;
						}
						
						if (typeof(evalCallBack) == 'function') {
							evalCallBack();
						}
						else if (evalCallBack) {
							eval(evalCallBack + ';');
						}
					}
				}
				xmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
				xmlHttp.send( encodeForm ? encodeForm : F.ajax.encode( frmEl ) );
			}

			return false;
		},
		/**
		 * 发起内容请求
		 *
		 * @param element path 请求路径
		 * @param string targetId 元素的编号
		 * @param bool isAppend 是否采用追加模式
		 * @param function evalCallBack 回发执行的代码函数
		 * @param array encodeForm 编码过的表单
		 */
		content: function(path, targetId, isAppend, evalCallBack, encodeForm ) {
			var frmEl = typeof(targetId)=='object' ? targetId : F.$( targetId );
			var xmlHttp = F.ajax.create();
			if ( frmEl && xmlHttp ) {
				path += (path.indexOf('?') >= 0 ? '&' : '?') + '_timer='  + new Date().getTime();
				xmlHttp.open( 'POST', path, true );
				xmlHttp.onreadystatechange = function() {
					if( xmlHttp.readyState==4 ) {
						frmEl.innerHTML = (isAppend ? frmEl.innerHTML : '') + xmlHttp.responseText;
						if (typeof(evalCallBack) == 'function') {
							evalCallBack();
						}
						else if (evalCallBack) {
							eval(evalCallBack + ';');
						}
					}
				}
				xmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
				xmlHttp.send( encodeForm ? encodeForm : F.ajax.encode( frmEl ) );
			}

			return false;
		},
		/**
		 * 发起API请求
		 *
		 * @param string evalCallBack 回调请求的执行代码，有%s则%s处的内容会被替换，否则API结果会被附带到执行代码的后面
		 * @param string url API全路径
		 * @param array params 二维数组，采用“[['title', 'abcd'],['ids[]', 1],['ids[]', 2]]”的形式构造内容
		 */
		api: function( evalCallBack, url, params ) {
			var encodeResult = '';
			for ( var i=0; i < params.length; i++ ) {
				encodeResult += ('edit[' + params[i][0] + ']').replace('[]]', '][]') + '=' + encodeURIComponent(params[i][1]) + '&';
			}
			var xmlHttp = F.ajax.create();
			if ( xmlHttp ) {
				xmlHttp.open( 'POST', url, true );
				xmlHttp.onreadystatechange = function() {
					if( xmlHttp.readyState==4 ) {
						//alert(xmlHttp.responseText);
						var json;
						try { eval('json = ' + xmlHttp.responseText + ';'); } catch (e) {
							if (e.name == 'SyntaxError') { return false; }
							F.msgbox.content(e.message + "\n\n* sorry, we're in for some trouble *", 'error'); return false;
						}
						if (typeof(evalCallBack) == 'function') {
							evalCallBack( json );
						}
						else {
							if (evalCallBack.indexOf('%s') >= 0) {
								eval(evalCallBack.replace('%s', 'json'));
							}
							else {
								eval(evalCallBack + json + ';');
							}
						}
					}
				}
				xmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
				xmlHttp.send( encodeResult );
			}
			
			return false;
		}
	}
}();