// JavaScript Document
function $(arg) {
	var obj = document.getElementById(arg);
	return obj;
}
function $n(arg) {
    var obj = document.getElementsByName(arg);
	return obj;
}
function ajax() {
	var http;
	try {
		http = new ActiveXObject("Microsoft.XMLHTTP"); //IE高版本的浏览器(5.5+)
	}
	catch (e) {
		try {
			http = new ActiveXObject("Msxml2.XMLHTTP"); //IE低版本的浏览器
		}
		catch (e) {
			try {
				http = new XMLHttpRequest(); //Firefox,opera,Safari浏览器
			}
			catch (e2) {
				http = false;  //所有浏览器都报错，则http为false
			}
		}
	}
	if (!http) {
		alert("Your computer cannot support the Ajax!");
		return false;
	}
	return http;
}
function ajax_returnresponse(http) {
	var state = http.readyState;
	if (state < 4) {
		return false;
	}
	if (state == 4 && http.status == 200) {
		return true;
	}
}
function urlDecode(str)
{ 
	var ret=""; 
	for(var i=0;i<str.length;i++)
	{ 
		var chr = str.charAt(i); 
		if(chr == "+")
		{
			ret+=" "; 
		}else if(chr=="%")
		{ 
			var asc = str.substring(i+1,i+3); 
	 		if(parseInt("0x"+asc)>0x7f)
			{ 
	  		ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
	  		i+=5; 
	 		}else
			{
				ret+=asc2str(parseInt("0x"+asc)); 
	  			i+=2; 
	 		} 
			}else
			{ 
	  			ret+= chr; 
			} 
	} 
  	return ret; 
}
function autoSize(obj,x,y)
{
	var img=new Image();
	img.src=obj.src;
	var maxWidth=x;
	var maxHeight=y;
	var imgWidth=img.width;
	var imgHeight=img.height;
	var mwh=maxWidth/maxHeight;
	var wh=imgWidth/imgHeight;
	if(wh>=mwh)
	{
		obj.width=maxWidth;
	}
	if(wh<mwh)
	{
		obj.height=maxHeight;
	}
}
function addOption(s_sel,o_value,o_text)
{
	s_sel.options[s_sel.length]=new Option(o_text,o_value);
}
function regempty(str)
{
	reg=/^\s*$/;
	return str.replace(reg,"");
}
function formatemail(e)
{
	var ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.+@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(var i=0; i<e.length; i++){
		if (ok.indexOf(e.charAt(i))<0) {
			return false;
		}
	}
	if(e.indexOf("@")<=0){
		return false;
	}
	if(e.indexOf(".")<=0){
		return false;
	}	
	if(e.indexOf("@")>e.lastIndexOf(".")){
	    return false;
	}
	return true;
}