function $$(tid){return (document.getElementById(tid)).value; }

function radioVal(tname){
	var	_inputs	= document.getElementsByTagName('input');
	for(var i=0; i<_inputs.length; i++){
		if(_inputs[i].type=='radio' && _inputs[i].checked==true){
			return _inputs[i].value;
		}
	}
	return null;
}

String.prototype.trim	= function(){
	return this.replace(/(^\s*)|(\s*$)/g, '');
};

function isFunction(obj){
	return obj!=null && (typeof obj=='function') && obj.constructor==Function;
}

function URLEncode(val){
	return encodeURIComponent(encodeURIComponent(val));
}

function JSRequest(_url){
    this.url	= document.URL;
    if(_url){ this.url	= _url; }

    this.reg	= new RegExp("(http|https|ftp)://([-a-z0-9_.]+)(/[-a-z0-9_.!/@&=\+,.~%\$\?]*)","gmi");
    this.reg.test(this.url);

    this.HostName=RegExp.$2; //域名
    this.Protocal=RegExp.$1; //url协议
    this.PathAndQuery=RegExp.$3; //路径和查询参数
    this.Path=this.url.indexOf('?')>0?RegExp.$3.substring(0,RegExp.$3.indexOf('?')):RegExp.$3; //路径
    this.QueryString=this.url.indexOf('?')>0?RegExp.$3.substring(RegExp.$3.indexOf('?')+1):''; //查询参数
}
JSRequest.prototype.getParameter = function (name){
	if(/\?(.+)$/.test(this.url)){
		var ta=RegExp.$1;
		var r = new RegExp(name+"=([^&]+)","gmi");
		if(r.test(ta)){
			return unescape(RegExp.$1);
		}else{
			return '';
		}
	}else{
		return '';
	}
}
/**********************************************************\
 * 闪烁的文本框
 *---------------------------------------------------------
 * 使文本框在鼠标进入和移出时分别显示不同的颜色
 * 
\**********************************************************/
function BLINK_BORDER(cMouseOver, cMouseOut){
	var	objs	= document.getElementsByTagName("input");
	for(var i=0; i<objs.length; i++){
		if(objs[i].type=="text" || objs[i].type=="password"){
			objs[i].style.border	= "1px solid "+cMouseOut;
			objs[i].style.width	= 160;
			objs[i].onmouseover	= function(){
				this.style.border	= "1px solid "+cMouseOver;
			};
			objs[i].onmouseout	= function(){
				this.style.border	= "1px solid "+cMouseOut;
			};
		}
	}
}

/**
 * 向head中添加一个style标签
 * 
 * @param cssStr	css样式
 * @return
 */
function addStyle(cssStr){
	try{//IE
		var	style	= document.createStyleSheet();
		style.cssText = cssStr;
	}catch(e){	//Firefox,Opera,Safari,Chrome
		var	style	= document.createElement("style");
		style.type	= "text/css";
		style.textContent	= cssStr;
		var	_head_	= document.getElementsByTagName("HEAD");
		_head_.item(0).appendChild(style);
	}
}

/**********************************************************************\
 * __☆★| 锁屏功能 |★☆__
 *---------------------------------------------------------------------
 * 说明:
 *      当要执行摸个操作时先调用 lock() 方法, 束时时在调用 unlock() 方法.
 *      LOCK_IMGAGE_URL 为loading图片的位置,可根据实际情况更改
 * 作者: Shine Chiu
 * 时间: 2008-11-13 14:51
\**********************************************************************/
var	LOCK_IMGAGE_URL	= "http://image.guayou520.com/cmn/clz.gif";
function FF_lock(){

	var	oImg	= document.createElement("img");
	oImg.setAttribute("src", LOCK_IMGAGE_URL);
	oImg.setAttribute("id", "_close");

	var	oInfo	= document.createElement("div");
	oInfo.setAttribute("id", "_lock_info_div");
	oInfo.setAttribute("style", "border: 0px solid #369; width:100px; height:100px; background:transparent; z-index:1000; position:absolute; display:none;");
	oInfo.style.display		= "block";
	oInfo.style.position	= "absolute";
	oInfo.style.top			= "50%";
	oInfo.style.left		= "50%";
	oInfo.style.marginTop	= "-100px";
	oInfo.style.marginLeft	= "-50px";
	
	var	oWall = document.createElement("div");
		
	oWall.setAttribute("id","_lock_wall_div");
	oWall.style.background	= "black";
	oWall.style.position	= "absolute";
	oWall.style.left		= (window).scrollX+'px';
	oWall.style.top			= (window).scrollY+'px';
	oWall.style.width		= window.outerWidth+"px";
	oWall.style.height		= window.outerHeight+"px";
	oWall.style.zIndex		= "999";
	oWall.style.opacity		= "0.618";
	document.body.style.overflow = "hidden";
	
	oInfo.appendChild(oImg);
	oWall.appendChild(oInfo);
	document.body.appendChild(oWall);
}

function IE_lock(){

	var	oImg	= document.createElement("img");
	oImg.setAttribute("src", LOCK_IMGAGE_URL);
	oImg.setAttribute("id", "_close");

	var	oInfo	= document.createElement("div");
	oInfo.setAttribute("id", "_lock_info_div");
	oInfo.setAttribute("style", "border: 0px solid #369; width:100px; height:100px; background:transparent; z-index:1000; position:absolute; display:none;");
	oInfo.style.display		= "block";
	oInfo.style.position	= "absolute";
	oInfo.style.top			= "50%";
	oInfo.style.left		= "50%";
	oInfo.style.marginTop	= "-50px";
	oInfo.style.marginLeft	= "-50px";
	
	var	oWall = document.createElement("div");
		
	oWall.setAttribute("id","_lock_wall_div");
	oWall.style.background	= "black";
	oWall.style.position	= "absolute";
	oWall.style.left		= '0px';
	oWall.style.top			= '0px';
	//var	vScrollLeft	= document.body.scrollLeft | document.documentElement.scrollLeft;
	var	vScrollTop	= document.body.scrollTop | (document.documentElement).scrollTop;
	oInfo.style.top			= (vScrollTop+ (document.documentElement).offsetHeight/2 - 50)+'px';
	
	oWall.style.width		= (document.body.offsetWidth+100)+"px";
	oWall.style.height		= (document.body.offsetHeight+100)+"px";
	oWall.style.zIndex		= "999";
	oWall.style.filter = "Alpha(opacity=38.2)";
	
	oInfo.appendChild(oImg);
	oWall.appendChild(oInfo);
	
	document.body.appendChild(oWall);
}

function lock(){
	/* 如果是IE6将采取其他方式处理高度 */
	if(navigator.appVersion.search("MSIE")>=0){
		IE_lock();
	}else{
		FF_lock();
	}
}

function unlock(){
	document.body.removeChild(document.getElementById('_lock_wall_div'));
	if(navigator.appVersion.search("MSIE")>=0){
		//
	}else{
		document.body.style.overflow = "auto";
	}
}
//-- 锁屏功能结束 ---------------------------------------------------------


/**
 * 将null或undefined转换为空字符串
 * @param val
 * @return
 */
function ne(val){
	return (val==null || val==undefined) ? "" : val;
}

 


/**
 * 一个简单的Map实现
 * 
 * @return
 */
function Map(){
	this.entrys	= new Array();
	
	this.size	= function(){ return this.entrys.length; };
	
	this.keys	= function(){
		var	_keys	= new Array();
		for(var i=0; i<this.entrys.length; i++){
			_keys.push(this.entrys[i].key);
		}
		return _keys;
	};
	
	this.put	= function(key, value){
		for(var i=0; i<this.entrys.length; i++){
			if(key === this.entrys[i].key){
				return;
			}
		}
		this.entrys.push({"key":key, "value":value});
	};
	
	this.get	= function (key){
		for(var i=0; i<this.entrys.length; i++){
			if(key === this.entrys[i].key){
				return this.entrys[i].value;
			}
		}
		return null;
	};
	
	this.remove	= function (key){
		for(var i=0; i<this.entrys.length; i++){
			if(key === this.entrys[i].key){
				for(var j=i; j<this.entrys.length-1; j++){
					this.entrys[j]	= this.entrys[j+1];
				}
				this.entrys.length	= this.entrys.length-1;
			}
		}
	};
}

/**
 * 数据处理器配置函数
 * 
 * @return
 */
function DataProcessor(){
	this._field_processor_	= new Map();
	this._value_processor_	= new Map();
	
	/**
	 * 添加字段处理器
	 * 
	 * @param _field_		字段名称
	 * @param _processor_	值处理器对象,值处理器接受一个待处理的值对象作为参数 
	 */
	this.addFieldProcessor	= function(_field_, _processor_){
		if(isFunction(_processor_))
			this._field_processor_.put(_field_, _processor_);
	};
	
	/**
	 * 添加特殊值处理器
	 * 
	 * @param _regexp_		正则表达式字符串,用于匹配要处理的特殊值
	 * @param _processor_	值处理器对象,值处理器接受一个待处理的值对象作为参数
	 */
	this.addValueProcessor	= function(_regexp_, _processor_){
		if(isFunction(_processor_))
			this._value_processor_.put(_regexp_, _processor_);
	};
	
	/**
	 * 调用处理器处理要输入的数据
	 * 
	 * @param _field_	待处理字段
	 * @param _value_	待处理值
	 */
	this.process	= function(_field_, _value_){
		var	tresult	= _value_;
		var	_t_fp_value	= this._field_processor_.get(_field_);
		if(_t_fp_value!=null && isFunction(_t_fp_value)){
			tresult	= _t_fp_value(tresult);
		}
		
		var	_vp_keys	= this._value_processor_.keys();
		for(var i=0; i<_vp_keys.length; i++){
			var	tregexp	= new RegExp(_vp_keys[i]);
			if(tregexp.test(tresult)){
				var	tfunction	= this._value_processor_.get(_vp_keys[i]);
				if(isFunction(tfunction)){
					tresult	= tfunction(tresult);
					continue;
				}
			}
		}
		return tresult;
	};
}

/**
 * 一个简单的对象填充函数,可以按对象中的字段将值填充到模板中
 * 
 * @param obj		要填充的对象
 * @param tmplate	模板字符串
 * @param dp		DataProcessor对象
 * @return	填充数据后的字符串
 */
function rplc(obj, tmplate, dp){
	for(var i in obj){
		if(i!=undefined && i!=""){
			if(dp && dp.process){
				tmplate	= tmplate.replace(new RegExp("\\{\\$"+i+"}", 'g'), dp.process(i, obj[i]));
			}else{
				tmplate	= tmplate.replace(new RegExp("\\{\\$"+i+"}", 'g'), obj[i]);
			}
		}
	}
	return tmplate;
}

/**
 * 使用指定的字符串覆盖原始串中的部分字符
 * 
 * @param tstr	原始串
 * @param tstart	开始字符,从0开始
 * @param tend	结束字符,不能超过tstr.length
 * @param tchar	用于做掩盖用的字符串
 * @return	覆盖后的字符串
 */
function mask(tstr, tstart, tend, tchar){
	var	rs	= '';
	for(var i=0; i<tstr.length; i++){
		rs	+= (tstart<=i && i<tend) ? tchar : tstr.charAt(i);
	}
	return rs;
}


/**
 * 同步加在一个文件
 */
function load(turl){
	var	rs	= null;
	$.ajax({async: false,type: 'post',url: turl,success: function(res){return rs=res;}});
	return rs;
}

/**
 * 加载一个类似view_[tname].html的文件
 * 
 * @param tname	加载文件的内容
 * @return
 */
function view(tname){
	var	rs	= null;
	$.ajax({async: false,type: 'post',url: 'view_'+tname+'.html',success: function(res){return rs = res;}});
	return rs;
}

function rmbBox(tid){
	var	oBox	= document.getElementById(tid);
	var	_int	= /^[1-9](\d{1,2})?$/;
	var	_float	= /^\d{1,3}(.\d{1,2})?$/;
	
	function tmp(){
		var	strRMB	= oBox.value;
		var	cRMB	= parseFloat(strRMB);
		var	ok		= !isNaN(cRMB) && cRMB>0 && cRMB<=500 && _int.test(strRMB);
		if(ok){
			oBox.style.backgroundColor	= "white";
		}else{
			oBox.style.backgroundColor	= "#fee";
		}
	}
	
	oBox.onclick	= tmp;
	oBox.onkeyup	= tmp;
	oBox.onkeydown	= tmp;
}

