/*
ajax 简单封装
window.onload=function(){
	ajax({url:"data.aspx?rnd=asdf",
			method:"get",
			data:{username:"admin",
					password:"admin888",
					imagecode:"4678"},
			datatype:"json",
			cache:false,
			error:function(error){
			alert(error);},
			success:function(data){
				datacache[0]=data;
				//$id("odata").innerHTML=data.msg;
				var tlistcontent=$id("tlist").innerHTML;
				for(var i=0;i<data.length;i++)
				$id("list").innerHTML+=String.eFormat(tlistcontent,data[i].id,data[i].msg,data[i].username,data[i].password);
				
			}
	});
}
*/
/**
  @Author:GOODEON
  @data:2008-11-29
  @version:1.1
  @email:ydyhkjy@163.com
  @功能函数及参数： $ajax({url:urlString,[method:"post"|"get",data:Data object,datatype:"json"|"xml"|"text",cache:true|false,success:function,error:function}])
  @					String.eFormat(strSource ,p1,p2,p3)|String.Format(strSource ,p1,p2,p3)
  @					$id（Stirng domid）|$name(String domname)|$tag(String domtagname)
  @					serlalize(Data object)
 */
function $ajax(o){var r_xmlhttp= null;if(!o.url){alert("必填参数：url地址");return ;}; o.method=o.method?o.method:"post";o.data=o.data?o.data:"";o.datatype=o.datatype?o.datatype:"text";o.cache=o.cache?o.cache:false;o.error=o.error?o.error:function(){};o.success=(typeof(o.success)=="function")?o.success:function(){}; if(typeof XMLHttpRequest=="undefined"){try{xmlhttp=new window.XMLHttpRequest();} catch(e) {var ActiveXName=['MSXML2.XMLHttp.3.0','MSXML2.XMLHttp.4.0','MSXML2.XMLHttp.5.0','Msxml2.XMLHTTP','MSXML.XMLHttp','Microsoft.XMLHTTP','MSXML2.XMLHttp.6.0','MSXML2.XMLHttp.1.0','MSXML2.XMLHttp.2.0'];for(var axn in ActiveXName){try{XMLHttpRequest=function(){return new ActiveXObject(ActiveXName[axn])};break;}catch(e1){continue;}}}} try{if(r_xmlhttp==null) r_xmlhttp=new XMLHttpRequest();} catch(e){o.error(e.message); r_xmlhttp=null;return ;} if(o.method.toLowerCase()=="get"){if(o.url.indexOf('?')>-1&&serlalize(o.data)!=null)o.url+="&"+serlalize(o.data)+(o.cache?'':'&r'+new Date()+"="+new Date());else if(o.url.indexOf('?')==-1&&serlalize(o.data)!=null)o.url+="?"+serlalize(o.data)+(o.cache?'':'&r'+new Date()+"="+new Date());o.data=null; r_xmlhttp.open(o.method,o.url,true);} else if(o.method.toLowerCase()=="post"){ 	r_xmlhttp.open(o.method,o.url,true); 	r_xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); if(r_xmlhttp.overrideMimeType) 	{r_xmlhttp.setRequestHeader("Connection","close")}}else{return ;} 	r_xmlhttp.onreadystatechange=function(){ 		if(r_xmlhttp.readyState==4){ if(Number(r_xmlhttp.status)>=300){r_xmlhttp=null;o.error('error');return null;}if(Number(r_xmlhttp.status)==200){var datas ="";	switch(o.datatype){case "text":datas=r_xmlhttp.responseText;break;case "xml":datas=r_xmlhttp.responseXML;break;case "json":datas=eval("("+r_xmlhttp.responseText+")");break;default:datas=null;break;}(o.success)(datas);r_xmlhttp=null;return null;}} 	}; 	r_xmlhttp.send(serlalize(o.data)+(o.cache?'':'&r'+new Date()+"="+new Date()).replace('&&',''));}String.Format = function() {if(arguments.length == 0)return "";if(arguments.length == 1)return arguments[0];var reg = /{(\d+)?}/g;var args = arguments;var result = arguments[0].replace(reg,function($0, $1) {return  args[parseInt($1)+1];});return result;};String.eFormat = function() {if(arguments.length == 0)return "";if(arguments.length == 1)return arguments[0];var reg = /<!--{(\d+)?}-->/g;var args = arguments;var result = arguments[0].replace(reg,function($0, $1) {return  args[parseInt($1)+1];});return result;};function serlalize(data){if(data==null)return null;var urlp='';if(typeof data=="object"){for(var p in data){if(typeof data[p]=='string')urlp+="&"+p+"="+data[p];}urlp=urlp.replace('&','');}return urlp;} var $id=function(id){return document.getElementById(id);};var  $name=function(name){return document.getElementsByName(id);};var $tag=function(tagname){return document.getElementsByTagName(tagname);};var  $val=function(id){return $id(id)?$id(id).value:"";};var $text=function(id){return $id(id)?$id(id).innerText:"";};var $html=function(id){return $id(id)?$id(id).innerHTML:"";};var $set = function(id,attr,attrvalue){if($id(id)!=null)eval("$id('"+id+"')."+attr+"='"+attrvalue+"'");};
var $get=function(id,attr){return eval("$id('"+id+"')."+attr);};