/**
 增加一个名为 trim 的函数作为
 String 构造函数的原型对象的一个方法。
*/

String.prototype.trim = function()
{
    // 用正则表达式将前后空格
    // 用空字符串替代。
    return this.replace(/(^\s*)|(\s*$)/g, "");
}


function antajax(urlstr1,xml){
	var xmlHttp;
	this.cxht= function(){
		if(window.ActiveXObject){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		else if(window.XMLHttpRequest){
			xmlHttp = new XMLHttpRequest();
		}
	};
	this.cxht();
	xmlHttp.onreadystatechange = function(){
		//alert(xmlHttp.ResponseText);
		if(xmlHttp.readyState ==4){
			if(xmlHttp.status ==200){
				//alert(xmlHttp.ResponseText);
				parseResults(xmlHttp);
			}
		}
	};

	xmlHttp.open("POST",urlstr1,true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
	xmlHttp.send(xml);
}

 function err_close(o){
	 var e = document.getElementById(o.id+'msg');
	 if (e != undefined){
	 document.body.removeChild(e);
	 }
 }

 function getSelectValue(eid){
		var e = document.getElementById(eid);
		for(i = 0 ;i<e.options.length;i++){
			if(e.options[i].selected){
				return e.options[i].value;
			}
		}
		return 0;
}

function getRadioValue(obj){
	var o = document.getElementsByName(obj);
//	alert('o::'+o.length);
	for (i = 0 ;i<o.length;i++){
		if(o[i].checked){
			return o[i].value;
		}
	}
	return -1;
}


function setenable(ct_name){
	var k =document.getElementById(ct_name);
	k.readOnly=false;
	k.focus();
}


function selsearch(o){
		//1.生成一个INPUT，在SELECT之下
		//如果同名INPUT已经存在，则不生成

	try{
		idname = o.id+'input';

		var e = document.getElementById(idname);
		if (e != undefined)
		{
			e.focus();
			return;
		}

		var e = document.createElement('input');
		e.id = idname;



		e.style.position = 'absolute';
		e.style.left = getLeft(o);
		e.style.top = getTop(o)+20;

		e.onblur = function(){
			var skeyo  = document.getElementById(idname);
			document.body.removeChild(skeyo);
		}

		e.onkeyup = function(){
		//修改select中的项目
			var skey  = document.getElementById(idname).value;
			if(window.event.keyCode == 20 || skey.length ==0){
				return;
			}
			for(i =0;i<o.options.length;i++){
				var str = o.options[i].text;
				if (str.indexOf(skey) > -1)
				{
					//保存当前元素的值 te，
					var tv = o.options[i].value;
					var tt = o.options[i].text;
					var tl = o.options[i].label;

					//将元素从0 ~ n-1 替换成 1~n
					for(j = i ;j>0;j--){
						o.options[j].value=o.options[j-1].value;
						o.options[j].text = o.options[j-1].text;
						o.options[j].label = o.options[j-1].label;
					}

					//将元素te 替换 元素0
					o.options[0].value=tv;
					o.options[0].text = tt;
					o.options[0].label = tl;
				}
			}
		}

	
	document.body.appendChild(e);
	e.focus();

	}catch(e){
		alert(e.toString());
	}

}

function getTop(e){
	var offset=e.offsetTop;
	if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
	return offset;
}

	//获取元素的横坐标
function getLeft(e){
	var offset=e.offsetLeft;
	if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
	return offset;
}


function isNumber(oNum)
  {
	if(!oNum) return false;
	var strP=/^\d+(\.\d+)?$/;
	if(!strP.test(oNum)) return false;
	try{
		if(parseFloat(oNum)!=oNum) return false;
		}
	catch(ex)
	{
	  return false;
	}
	return true;
  }


function uploadFile(filetype,eid) { 
        document.getElementById("filepath"+eid).value='';
        document.getElementById("filename"+eid).value='';
        var theform = document.getElementById("form1");
        var msg = document.getElementById("msg"+eid);
        var oldAction = theform.action;
        var oldonSubmit = theform.onSubmit;
        //msgok.style.display = 'none';
        //msg.style.display = '';
        msg.innerHTML = "正在上传中，请您稍等......";

        theform.action = "/upload.php?action="+filetype+"&eid="+eid;
        theform.onSubmit = "";
        theform.target = "hidden_frame";
        theform.submit();
        theform.action = oldAction;
        theform.onSubmit = oldonSubmit;
        theform.target = "";
        return false;
}

 function showmsg(str,id){
 	var o = document.getElementById(id);
 	o.innerHTML = str;
 }
 
 function resize_pic(w){
	 var imgs = document.getElementsByTagName('img');
	 for(i=0;i<imgs.length;i++){
		 	var img = imgs[i];
		 	
		 	if(img.width > w ){
		 		img.style.width=w;
		 	}
	 }
 }
