
//转义，反转义html
function unescapeHTML(html) {
	return $("<div />").html(html).text();
}
function escapeHTML(html) {
	return $("<div />").text(html).html();
}

//字符串检查
function v_isEmpty(str){
	var isN;
	if (str == "" || str == null){
        isN = true;
    } else {
        isN = false;
    }
	return isN;
}

//字符串连接  用此比 字符串相加快几十倍
function StringBuffer(str){
    this.tmp = new Array();
}
StringBuffer.prototype.append= function(value){
    this.tmp.push(value);
    return this;
}
StringBuffer.prototype.clear = function(){
    tmp.length=1;
}
StringBuffer.prototype.toString = function(){
    return this.tmp.join('');
}

//获得对象的状态 //
function getPosition(e){
	e=$.ensure(e);
	var p=e.position();
	return {left:p.left,top:p.top,width:e.width(),height:e.height()};
}


//========================获取url连接字符串===============================    //

if (typeof Poly9 == 'undefined') {
	var Poly9 = {};
}

Poly9.URLParser = function(url) {
	this._fields = {
		'Username' : 4,
		'Password' : 5,
		'Port' : 7,
		'Protocol' : 2,
		'Host' : 6,
		'Pathname' : 8,
		'URL' : 0,
		'Querystring' : 9,
		'Fragment' : 10
	};

	this._values = {};
	this._regex = null;
	this.version = 0.1;
	this._regex = /^((\w+):\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/;

	for ( var f in this._fields) {
		this['get' + f] = this._makeGetter(f);
	}

	if (typeof url != 'undefined') {
		this._parse(url);
	}
}

Poly9.URLParser.prototype.setURL = function(url) {
	this._parse(url);
}

Poly9.URLParser.prototype._initValues = function() {
	for ( var f in this._fields) {
		this._values[f] = '';
	}
}

Poly9.URLParser.prototype._parse = function(url) {
	this._initValues();
	var r = this._regex.exec(url);
	if (!r)
		throw "DPURLParser::_parse -> Invalid URL";

	for ( var f in this._fields)
		if (typeof r[this._fields[f]] != 'undefined') {
			this._values[f] = r[this._fields[f]];
		}
}

Poly9.URLParser.prototype._makeGetter = function(field) {
	return function() {
		return this._values[field];
	}
}

/*-----------------------------------------------------------
 * 
 *-----------------------------------------------------------*/
function dwrGetRealPageNO(pageNO){
    var i = 1;
    //空的参数 页面直接刷新//
    if (pageNO==undefined){
        var p = new Poly9.URLParser(window.location.href);
        i = p.getFragment();
        i = $.trim(i);
        if (i=="") {
            i = 1;
        } else {
            i = replaceStr(i,"p","");
        }
    } else {
        i = pageNO;
    }
    return i;
}


/*-----------------------------------------------------------------
 * 柱状图
------------------------------------------------------------------*/

(function($) {
	$.fn.horizontalBarGraph = function(options) {
	
		var opts = $.extend({}, $.fn.horizontalBarGraph.defaults, options);
		
		for(var i=0;i<opts.data.length;i++){
			var row=opts.data[i];
			//alert("width="+ row[1]);
			var c1=$("<span>"+row[0]+"</span>");
			var c2=$("<span>&nbsp;</span>");
			var txt="";
			var r3=row[3];
			if((r3 == null) || (r3==undefined)){
				txt=row[1];
			}else{
				txt=r3;
			}
			var c3=$("<span/>").html(txt+opts.unit);
			
			c2.css({display:'inline-block',width:row[1],'background-color':row[2]});
			
			var div=$("<div/>");
			div.append(c1).append(c2).append(c3);
			this.append(div);
		}
		return this;
	};
	

	$.fn.horizontalBarGraph.defaults = {
		animated: false,
		unit:''
	};
	
})(jQuery);

