
/*@document.getElementById的简写*/
var _$ = function(id){
	return document.getElementById(id);
};


/**************************************************
* * ajax应用
* * 2008-6-18
* **************************************************
* * msn:danxinju@hotmail.com
* * author:淡新举
***************************************************/	

var ajax = function(url ,callback ,method ,data){
	var method = method ? method : "get";
	var data = data ? data : null;
	var url = (method == "get") ? (url +"?"+ data) : url;
	var http = window.XMLHttpRequest? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	
	var doGet = function(){
		http.open(method ,url ,false);
		http.setRequestHeader("If-Modified-Since" , "0" );
		http.send(null);
		callback(http.responseText);
	};
	
	var doPost = function(){
		http.open(method ,url ,false);
		http.setRequestHeader("content-length" ,data ?data.length : 0);
		http.setRequestHeader("Content-Type" ,"application/x-www-form-urlencoded");
		http.send(data);
		callback(http.responseText);
	};
	
	if (method == "post")
	{
		doPost();
	}
	else
	{
		doGet();
	}
	http = null;
};


/**************************************************
* * cookie应用
* * 2008-6-22
* **************************************************
* * msn:danxinju@hotmail.com
* * author:淡新举
***************************************************/	
var Cookie = new Object(); 

//设置cookie
Cookie.setCookie = function(name, value, option){ 
    var str = name +'='+ escape(value); 
    if(option){ 
        if(option.expireHours){ 
            var d = new Date(); 
            d.setTime(d.getTime()+option.expireHours*3600*1000); 
            str += '; expires='+d.toGMTString(); 
        } 
        if(option.path) str += '; path='+option.path; 
        if(option.domain) str += '; domain='+option.domain; 
        if(option.secure) str += '; true'; 
    } 
    document.cookie = str; 
}; 

//获取cookie
Cookie.getCookie = function(name){ 
    var arr = document.cookie.split('; '); 
    if(arr.length == 0) return ''; 
    for(var i=0; i <arr.length; i++){ 
        tmp = arr[i].split('='); 
        if(tmp[0] == name) return unescape(tmp[1]); 
    } 
    return ''; 
};

//删除cookie
Cookie.delCookie = function(name){ 
    this.setCookie(name,'',{expireHours:-1}); 
};

//获取cookie个数
Cookie.length = function(){
	return document.cookie.split('; ').length;
};


/**************************************************
* * 根据class属性返回对象
* * 2008-6-22
* **************************************************
* * msn:danxinju@hotmail.com
* * author:淡新举
***************************************************/	
var getElementsByClassName = function(className){
	var alls = document.getElementsByTagName("*");
	var rets = new Array();

	for (var i=0;i<alls.length ; i++)
	{
		if (alls[i].className == className)
		{
			rets.push(alls[i]);
		}
	}

	return rets;
};


/**************************************************
* * 字符串操作类
* * 2008-7-25
* **************************************************
* * msn:danxinju@hotmail.com
* * author:淡新举
***************************************************/	
var StringBuilder = function(){
	this.arr = new Array();
};

//追加字符串
StringBuilder.prototype.add = function(item){
	this.arr.push(item);
};

//清空字符
StringBuilder.prototype.clear = function(){
	this.arr.length = 0;
};

//转换为String
StringBuilder.prototype.toString = function(){
	return this.arr.join("");
};


/**************************************************
* * URl参数处理
* * 2008-7-25
* **************************************************
* * msn:danxinju@hotmail.com
* * author:淡新举
***************************************************/	
var Request = {
	QueryString : function(val) {
		var uri = window.location.search;
		var re = new RegExp("" +val+ "\=([^\&\?]*)", "ig");
		return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
	},
	QueryStrings : function() {
		var uri = window.location.search;
		var re = /\w*\=([^\&\?]*)/ig;
		var retval=[];
		while ((arr = re.exec(uri)) != null)
		retval.push(arr[0]);
		return retval;
	}
};


/**************************************************
* * 注册事件
* * 2008-7-25
* **************************************************
* * msn:danxinju@hotmail.com
* * author:淡新举
***************************************************/	
var addEventHandler = function(oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = fnHandler;
    }
};