//函数名：isSecure
//功能介绍：检查是用户名是否符含有非法字符
//参数说明：要检查的字符串
//返回值：true:是；false不是
function isSecure(str)
{ 
	var re = /^(\w|[\u4E00-\u9FA5])*$/;
	return str = str.match(re) ? true : false;
} 

//函数名：isNumeric
//功能介绍：检查是否是数字
//参数说明：要检查的字符串
//返回值：true：是; false：不是
function isNumeric(s)
{
	var r,re;
	re = /\d*/i;
	r = s.match(re);
	return (r == s) ? true : false;
}

//函数名：isEmail
//功能介绍：检查是否是合法的E-mail
//参数说明：要检查的字符串
//返回值：true：是; false：不是
function isEmail(str) {
    var re = /^[-_A-Za-z0-9]+@([-_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/;
	return re.test(str) ? true : false;
}

// 获取cookie
function getCookie(name) {
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
        return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ";", len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}

// 设置cookie
function setCookie( name, value, expires, path, domain, secure ) {
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name+"="+escape( value ) +
        ( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
}

// 删除cookie    
function deleteCookie( name, path, domain ) {
    if ( getCookie( name ) ) document.cookie = name + "=" +
            ( ( path ) ? ";path=" + path : "") +
            ( ( domain ) ? ";domain=" + domain : "" ) +
            ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// 加为收藏
function AddFavorite(sTitle, sUrl){
	if (document.all) {
		window.external.addFavorite(sUrl, sTitle);
	} else if (window.sidebar) {
		window.sidebar.addPanel(sTitle, sUrl,"");
	}
}

// 设为首页
function SetHomepage(sUrl) {
	if (document.all) {
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(sUrl);
	} else if (window.sidebar) {
		if(window.netscape) {
			try {  
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			} catch (e) {
				alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config, 然后将项 signed.applets.codebase_principal_support 值该为true");
			}
		}
	var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
	prefs.setCharPref('browser.startup.homepage', sUrl);
	}
}

//检查URL格式
function isUrl(url) {
    var strRegex = "^((https|http|ftp|rtsp|mms)?://)" 
    + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@ 
    + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 
    + "|" // 允许IP和DOMAIN
    + "([0-9a-z_!~*'()-]+\.)*" // 域名- www. 
    + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 
    + "[a-z]{2,6})" // first level domain- .com or .museum 
    + "(:[0-9]{1,4})?" // 端口- :80 
    + "((/?)|" // a slash isn't required if there is no file name 
    + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; 
    var re = new RegExp(strRegex); // re.test()
    if(re.test(url)) {
        return true;
    } else {
        return false;
    }
}

//电话传真检查函数
function isTel(s) {
    var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    if (!patrn.exec(s)) return false;
	return true
}

// 检查邮政编码
function isPostalcode(str) {
    var re = /^\d{6}$/;
	return re.test(str) ? true : false;
}

// 插入Flash
function parseFlash(swf, swf_width, swf_height) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ swf_width +'" height="'+ swf_height +'"> ');
	document.write('<param name="movie" value="'+ swf +'"> ');
	document.write('<param name="quality" value="high"> ');
	document.write('<param name="wmode" value="transparent"> ');
	document.write('<embed src="'+ swf +'" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ swf_width +'" height="'+ swf_height +'"></embed> ');
	document.write('</object>');
}
