//使用onload=DrawImage(this,长,宽);<img src="#" onload="DrawImage(this,60,60)" 
function DrawImage(ImgD,w,h){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= w/h){
if(image.width>w){
ImgD.width=w;
ImgD.height=(image.height*w)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
//ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>h){
ImgD.height=h;
ImgD.width=(image.width*h)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
//ImgD.alt=image.width+"×"+image.height;
}
}
}

//自动调整图片大小，超过限制则自动按比例缩小。
//例子：
// <img src="demo.jpg" width="0" height="0" onload="imgAutoSize(this,50,50)" onerror="this.src='nopic.gif'" style='display:none;' /> 
// <img src="demo.jpg" width="0" height="0" onload="imgAutoSize(this,50,50,'block')" onerror="this.src='nopic.gif'" style='display:none;' /> 自定义display 方式
function imgAutoSize(elemImg, MaxWidth, MaxHeight,display)
{
    var img = new Image();
	img.src = elemImg.src;
	var w = MaxWidth;
	var h = MaxHeight;
	var w2 = img.width;
	var h2 =  img.height;
	var scale = w2 / h2;
	if(w2 < w && h2 < h){
		elemImg.style.display = 'inline';
		return;
	}
	if(w2 >= w){
		w2 = w;
		h2 = w2 / scale;
	}
	if(h2 >= h){
		h2 = h;
		w2 = h2 * scale;
	}
	
	elemImg.style.display = display ? display : 'inline';
	elemImg.width = Math.round(w2);
	elemImg.height = Math.round(h2);
}


// flashWrite(flash路径,宽度,高度,ID,背景色,变量,是否为背景flash)
//<script>flashWrite('top.swf','600','40','TOP','#FFFFFF','','transparent')</script>

function flashWrite(url,w,h,id,bg,vars,win){
 var flashStr=
 "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
 "<param name='allowScriptAccess' value='always' />"+
 "<param name='movie' value='"+url+"' />"+
 "<param name='FlashVars' value='"+vars+"' />"+
 "<param name='wmode' value='"+win+"' />"+
 "<param name='menu' value='false' />"+
 "<param name='quality' value='high' />"+
 "<param name='bgcolor' value='"+bg+"' />"+
 "<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
 "</object>";
 document.write(flashStr);
}

// 选项卡
function allTabs(obj){
	this.obj = obj;
}
allTabs.prototype.init = function(){
	var $para = this.obj;
	var t1 = document.getElementById($para.id).getElementsByTagName($para.tag1);
	var t2 = document.getElementById($para.id).getElementsByTagName($para.tag2);
	this.$event = "on" + $para.eventType;
	t1[0].className = "current";
	t2[0].style.display = "block";
	for(var i=0;i<t1.length;i++){
		t1[i][this.$event] = (function(index){
			return function(){
				for(var j=0;j<t1.length;j++){
					t1[j].className = "";
					t2[j].style.display = "";
				}
				this.className = "current";
				t2[index].style.display = "block";
			}
		})(i);
	}
}



function unselectall()
{
    if(document.add.chkAll.checked){document.add.chkAll.checked = document.add.chkAll.checked&0; }
}

function CheckAll(form)
{
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.Name != "chkAll")
       e.checked = form.chkAll.checked;
    }
}

function CopyUrl(target)
{ 
	target.value=get_c.value; 
	target.select();   
	js=get_c.createTextRange();   
	js.execCommand("Copy"); 
	alert("复制成功!"); 
} 

function Display(ID){
	if ($(ID).style.display == "none"){
		$(ID).style.display="block";
	}else{
	    $(ID).style.display="none";
	}
}


function wrapTag(num)
{
  for(var id = 1;id<=4;id++)
  {
	  var Tag="cont"+id;
	  var Css = "on" + id;
	  if(id==num)
	  {
		  document.getElementById(Tag).style.display="block";
		  document.getElementById(Css).className = "now";
	  }
	  else
	  {
		  document.getElementById(Tag).style.display="none";
		  document.getElementById(Css).className = "";
	  }
  }
}

// 菜单
stuHover = function() {
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++)
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
			{
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") != -1)
			{
				 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
				document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
			}
		}
	var getElm = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<getElm.length; i++) {
		getElm[i].onmouseover=function() {
			this.className+=" iehover";
		}
		getElm[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", stuHover);
