/**
 * @author 汤恒杰 Added 2008.11.03
 * 工具相关的功能
 */

 
//去掉空格
function deletedSpace(str)
{
	return str = str.replace(/(^\s*|\s*$)/g,"")
}

function IsNumberOrCharactor(str)
{
	str = deletedSpace(str);
	var pattern = new RegExp("^[0-9a-zA-Z]+$");
	var b = pattern.test(str);
	
	return b;
}

//保存 cookie
function  saveCookie(name,   value,secure)
{  
    var   strCookie   =   name   +   "="   +   value;  
  
	var   curTime   =   new   Date();  
	curTime.setTime(curTime.getTime()   +   24*3*3600*1000);  
	strCookie  +=  ";   expires="   +   curTime.toGMTString();  

	strCookie   = strCookie   +       ";   path=/"; 
	strCookie   = strCookie   +       ";   domain=5173.com";      //将cookie写入固定的域
	strCookie   +=     (secure)   ?   ";   secure"   :   "";  
	document.cookie   =   strCookie;  
  }  
  
//   使用名称参数取得Cookie值,   null表示Cookie不存在  
function   getCookie(name)
{  
        var   strCookies   =   document.cookie;  
        var   cookieName   =   name   +   "="; 
        var   valueBegin,   valueEnd,   value;  
        valueBegin   =   strCookies.indexOf(cookieName);  
        if   (valueBegin   ==   -1)   return   null; 
        valueEnd   =   strCookies.indexOf(";",   valueBegin);  
        if   (valueEnd   ==   -1)  
              valueEnd   =   strCookies.length; 
        value   =   strCookies.substring(valueBegin+cookieName.length,valueEnd);  
        return   value;  
}




//获得Cookie解码后的值
function GetCookieVal(offset)
{
	//document.cookie.domain = '5173.com';
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
		
//设定Cookie值
function SetCookie(name, value)
{
	var expdate = new Date();
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = '/';
	var domain = '5173.com';
	var secure = (argc > 5) ? argv[5] : false;

	expdate.setTime(expdate.getTime() + 24*3*3600*1000);
	document.cookie = name + "=" + escape (value) +((expires != null) ? "" : ("; expires="+ expdate.toGMTString()))
	+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
	+((secure == true) ? "; secure" : "");
}
		
//删除Cookie		
function DelCookie(name)
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
		
//获得Cookie的原始值
function GetCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
		