//IE中输出透明的PNG格式
function correctPNG() {
	for(var i = 0; i<document.images.length; i++) {
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText 
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle  
			var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}
window.attachEvent("onload", correctPNG);

//IE中去除超级链接的虚线框
window.onload=function() {
	for(var ii=0; ii<document.links.length; ii++)
	document.links[ii].onfocus = function() {
		this.blur()
	}
}

//开启背景图片在浏览器中的缓存
try {
	document.execCommand("BackgroundImageCache",false,true);
}
catch (e) {
}

//兼容FireFox的收藏
function AddFavorite(sURL, sTitle) {
	try {
		window.external.addFavorite(sURL, sTitle);
	}
	catch (e) {
		try {
			window.sidebar.addPanel(sTitle, sURL, "");
		}
		catch (e) {
			alert("加入收藏失败，请使用Ctrl+D进行添加。");
		}
	}
}

//兼容FireFox的设为首页
function SetHome(obj,vrl) {
	try {
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
	}
	catch(e) {
		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',vrl);
		}
	}
}

//搜索表单效果处理
function iKeyword(obj,type) {
	var init="请输入搜索关键字..";
	switch(type) {
		case 1:
			if(obj.value==init) {
				obj.value="";
			}
			obj.style.cssText="color:black";
			break;
		case 2:
			if(obj.value=="") {
				obj.value=init;
				obj.style.cssText="";
			}
			else {
				obj.style.cssText="color:black";
			}
			break;
	}
}

//检测搜索表单内输入的数据
function checkKeyword(f) {
	var k=f.elements["keyword"].value;
	if("请输入搜索关键字.."==k||""==k) {
		alert("您必须输入一个搜索关键字。");
		return false;
	}
	return true;
}

//Ajax异步提交检测用户名是否注册
function chkuser() {
	var user=document.theform.username.value;
	var xmlhttp;
	try {
		xmlhttp=new xmlhttprequest();
	} catch (e) {
		xmlhttp=new ActiveXObject("microsoft.xmlhttp");
	}
	xmlhttp.onreadystatechange=function() {
		if (4==xmlhttp.readystate) {
			if (200==xmlhttp.status) {
				if (user=="") {
					userinf.innerHTML="用户名只能使用字符a-z、0-9，长度为3-14位。";
				} else {
					userinf.innerHTML=xmlhttp.responsetext;
				}
			} else {
				alert("异步提交数据时发生一个错误。");
			}
		}
	}
	xmlhttp.open("post","chkuser.asp",true);
	xmlhttp.setrequestheader('content-type','application/x-www-form-urlencoded');
	xmlhttp.send("user="+escape(user));
}

//限制发布输入字符数
function textcounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0,maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

function newpage2(htmlurl) {
var newwin=window.open(htmlurl,"newWin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=100,left=200,width=300,height=210");
newwin.focus();
return false;
}

function newpage1(htmlurl) {
var newwin=window.open(htmlurl,"newWin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=100,left=200,width=380,height=360");
newwin.focus();
return false;
}
