String.prototype.Trim = function()
{
  var tmp = this.replace(/(^\s*)|(\s*$)/g, "");
  return tmp.replace(/(^\2005-9-28*)|(\　*$)/g,"");
}

function _getId(a)
{
  return document.getElementById ? document.getElementById(a) : null;
}

String.prototype.IsNumber = function()
{
	var myReg = /^[0-9]+$/;
	if(!myReg.test(this)) return false;
	ActRd=parseInt(this)	
	return true;
}

String.prototype.IsFloat = function()
{
	var myReg = /^[0-9.]+$/;
	if(!myReg.test(this)) return false;
	var pos=this.indexOf('.')
	if(pos==-1) return false;
	if(pos!=this.lastIndexOf('.')) return false;
	if(pos==0 || (pos+1)==this.length) return false;
	ActRd=parseFloat(this)
	return true;
}

String.prototype.IsEmail = function()
{
	var myReg = /[\u4e00-\u9fa5]/;
	if(!myReg.test(this)){
		myReg = /^[_a-zA-Z0-9][-._a-zA-Z0-9]*@[-_a-zA-Z0-9]+\.[-._a-zA-Z0-9]+(\.[-._a-zA-Z])*$/;
		if (myReg.test(this)) return true;
	}else{
		myReg = /^[_a-zA-Z0-9\u4e00-\u9fa5][-_.a-zA-Z0-9\u4e00-\u9fa5]*@[-._a-zA-Z0-9\u4e00-\u9fa5]+(\.[-._0-9a-zA-Z\u4e00-\u9fa5]+)*$/;
		if (myReg.test(this)) return true;
	}
	return false;
}

String.prototype.IsUser = function()
{
    var myReg = /^[0-9a-zA-Z_]+$/;
    if(myReg.test(this)) return true;
    return false;
}

function add_fav(title,url)
{
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
}

function SetCookie(name,value)
{
    var Days = 1; 
    var exp  = new Date();   
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function getCookie(name)      
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

function valueInArray(needle,searchArray)
{
	for (var i=0;i<searchArray.length ;i++ )
	{
		if (needle==searchArray[i])
		{
			return i;
		}
	}
	return -1;
}

function addOption(objId,optionValue,optionText)
{
	var obj=document.getElementById(objId);
	obj.options.add(new Option(optionText,optionValue));
}

function removeAll(objId)
{
  var obj=document.getElementById(objId);
  obj.options.length=0;
}

function changeDiv(divName)
{
	if (_getId(divName).style.display=='none')
	{
		_getId(divName).style.display='block';
	}else
	{
		_getId(divName).style.display='none';
	}
}

function addFav(url,uname)
{
	window.external.AddFavorite(url, uname);
}

function memberLogin()
{
	if (_getId("username").value.Trim()=="")
	{
		alert("请填写会员账号");
		_getId("username").focus();
		return false;
	}

	if (_getId("userpass").value.Trim()=="")
	{
		alert("请填写会员密码");
		_getId("userpass").focus();
		return false;
	}
	return true;
}

function checkAll(id)
{
	var nowState=_getId("ckAll").checked;
	var sonObj=document.getElementsByName(id);
	if (sonObj)
	{
		for (var i=0;i<sonObj.length ;i++ )
		{
			sonObj[i].checked=nowState;
		}
	}
}

function getIdStr(id)
{
	var sonObj=document.getElementsByName(id);
	var ids="";
	if (sonObj)
	{
		for (var i=0;i<sonObj.length ;i++ )
		{
			if (sonObj[i].checked)
			{
			  ids+=","+sonObj[i].value;	
			}
		}
	}
	if (ids!="")
	{
		ids=ids.substr(1);
	}
	return ids;
}
   
function limitImage(ImgD,standWidth,standHeight)
{       
	var image=new Image();    
	image.src=ImgD.src;
	var newWidth=standWidth;
	var newHeight=standHeight;
	if(image.width>standWidth || image.height>standHeight)
	{
		if (image.width/standWidth>image.height/standHeight)
		{
			newHeight=parseInt(image.height/(image.width/standWidth));
		}else if(image.width/standWidth<image.height/standHeight)
		{
			newWidth=parseInt(image.width/(image.height/standHeight));
		}
		ImgD.width=newWidth;
		ImgD.height=newHeight;
	}    
}
