﻿// 解决 FF 没有 outerHTML
if(window.HTMLElement) {
	HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){
	var r=this.ownerDocument.createRange();
	r.setStartBefore(this);
	var df=r.createContextualFragment(sHTML);
	this.parentNode.replaceChild(df,this);
	return sHTML;
	});

	HTMLElement.prototype.__defineGetter__("outerHTML",function(){
	var attr;
	var attrs=this.attributes;
	var str="<"+this.tagName.toLowerCase();
	for(var i=0;i<attrs.length;i++){
		attr=attrs[i];
		if(attr.specified)
			str+=" "+attr.name+'="'+attr.value+'"';
		}
	if(!this.canHaveChildren)
		return str+">";
	return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
	});

	HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
	switch(this.tagName.toLowerCase()){
		case "area":
		case "base":
		case "basefont":
		case "col":
		case "frame":
		case "hr":
		case "img":
		case "br":
		case "input":
		case "isindex":
		case "link":
		case "meta":
		case "param":
		return false;
	}
	return true;
	});
}

// 弹出中央窗口,示例: <a href="#" onclick="openWinCenter(this.href,'newwin','width=320,height=240,status=no,menubar=no,resize=yes');return false"></a>
function openWinCenter(url, wname, wopt) {
	var newopt = "", wHeight = 0, wWidth = 0;
	if (wopt != undefined) {
		var woptlist = wopt.replace(/ /g, "").split(",");
		for (var i in woptlist) {
			if (woptlist[i].match(/^height=/i)) {
				wHeight = parseInt(woptlist[i].substr(7),10);
				if (!isNaN(wHeight)) newopt += "top=" + Math.floor((screen.availHeight - wHeight) / 2) + ",";
			}
			if (woptlist[i].match(/^width=/i)) {
				wWidth = parseInt(woptlist[i].substr(6),10);
				if (!isNaN(wWidth)) newopt += "left=" + Math.floor((screen.availWidth - wWidth) / 2) + ",";
			}
		}
	}
	return window.open(url, wname, newopt + wopt);
}

// 加载Flash文件,示例: <script type="text/javascript">swf('demo.swf','480','320');</script>
function swf(src,w,h){
	html = '';
	html += '<object type="application/x-shockwave-flash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=10,0.12.36" id="param" width="'+w+'" height="'+h+'">';
	html += '<param name="movie" value="'+src+'">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#FFFFFF">';
	html += '<param name="menu" value="false">';
	html += '<param name="allowFullScreen" value="true">';
	html += '<param name="wmode" value="transparent">';
	html += '<param name="swliveconnect" value="true">';
	html += '<embed src="'+src+'" quality="high" bgcolor="#FFFFFF" menu="false" width="'+w+'" height="'+h+'" swliveconnect="true" id="param" name="param" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
	html += '</object>';
	document.write(html);
}

function ReImgSize(intWidth){
		var imgwidth = intWidth;
		for (i = 0; i < document.images.length; i++)
		{
		var imageWidth;
		var imageHeight;
			if (document.images[i].width > imgwidth)
			{
				imageWidth = document.images[i].width;
				imageHeight = document.images[i].height;

				document.images[i].width = imgwidth;
				try{
					document.images[i].outerHTML="<a href='javascript:void(0)' onclick=openWinCenter('../image-view.aspx?image="+document.images[i].src+"','imageview','width="+imageWidth+",height="+imageHeight+",status=no,menubar=no,resize=yes')" + " title='在新窗口打开图片'>"+document.images[i].outerHTML+"</a>"
				}catch(e){}
			}
		}
	}

function search() {
	if (document.getElementById("txbSearch").value !== "") {
		window.location.href = "/products/?key="+escape(document.getElementById("txbSearch").value)
	} else {
		alert("请输入要查找的产品关键字!")
		document.getElementById("txbSearch").focus()
	}
}
