var maxWidth=250;
var maxHeight=250;
function getPosXY(a,offset) {
       var p=offset?offset.slice(0):[0,0],tn;
       while(a) {
           tn=a.tagName.toUpperCase();
           if(tn=='IMG') {
              a=a.offsetParent;continue;
           }
          p[0]+=a.offsetLeft-(tn=="DIV"&&a.scrollLeft?a.scrollLeft:0);
          p[1]+=a.offsetTop-(tn=="DIV"&&a.scrollTop?a.scrollTop:0);
          if(tn=="BODY")
                break;
          a=a.offsetParent;
      }
      return p;
}
function checkComplete() {
     if(checkComplete.__img&&checkComplete.__img.complete)
              checkComplete.__onload();
}
checkComplete.__onload=function() {
         clearInterval(checkComplete.__timeId);
         var w=checkComplete.__img.width;
         var h=checkComplete.__img.height;
         if(w>=h&&w>maxWidth) {
              previewImage.style.width=maxWidth+'px';
         }
        else if(h>=w&&h>maxHeight) {
              previewImage.style.height=maxHeight+'px';
        }
        else {
              previewImage.style.width=previewImage.style.height='';
        }
       previewImage.src=checkComplete.__img.src;previewUrl.href=checkComplete.href;checkComplete.__img=null;
}
function showPreview(e,pid) {
         hidePreview (e);
         previewFrom=e.target||e.srcElement;
         previewImage.src=loadingImg;
         previewImage.style.width=previewImage.style.height='';
         previewTimeoutId=setTimeout('_showPreview('+pid+')',500);
         checkComplete.__img=null;
}
function hidePreview(e,pid) {
        if(e) {
            var toElement=e.relatedTarget||e.toElement;
            while(toElement) {
                  if(toElement.id=='PreviewBox')
                          return;
                  toElement=toElement.parentNode;
            }
       }
       try {
            clearInterval(checkComplete.__timeId);
            checkComplete.__img=null;
            previewImage.src=null;
       }
       catch(e) {}
       clearTimeout(previewTimeoutId);
       previewBox.style.display='none';
}
function _showPreview(pid) {
        checkComplete.__img=new Image();
		var ppath=document.getElementById("ppath_"+pid).getAttribute("imgsrc")
        var largeSrc=ppath;
        var picLink=ppath;
        if(!largeSrc)
             return;
        else {
             checkComplete.__img.src=largeSrc;
             checkComplete.href=picLink;
             checkComplete.__timeId=setInterval("checkComplete()",20);
             var pos=getPosXY(previewFrom,[106,26]);
             previewBox.style.left=pos[0]+'px';
             previewBox.style.top=pos[1]+'px';
             previewBox.style.display='block';
        }
}

        function copyUrl(getid,user){
			location.href="html/?Id="+getid+"&User="+user+"&.html";
        }
        function copyUrl2(url,getid){
			var content='';
			window.clipboardData.setData("Text",url);
			alert("链接地址复制成功，请粘贴到你的QQ/MSN上推荐给你的好友");
		}
        function copyGetId(url){
			var content='';
			window.clipboardData.setData("Text",url);
			alert("提取码复制成功.");
		}

		function viewnone(e){
			e.style.display=(e.style.display=="none")?"":"none";
		}

		function editCat(url)
		{
			var pop=new Popup({ contentType:1, isReloadOnClose:false, width:400, height:200 });
			pop.setContent("title","修改文件");
			pop.setContent("contentUrl",url);
			pop.build();
			pop.show();
			return false;
		}

		function download(url)
		{
			var pop=new Popup({ contentType:1, isReloadOnClose:false, width:400, height:150 });
			pop.setContent("title","下载文件");
			pop.setContent("contentUrl",url);
			pop.build();
			pop.show();
			return false;
		}

		function isNumeric(val,id,msg){
			if(val!=""){
				try{
					if(parseInt(val)==val)
					{
						return true;
					}else{
						alert(msg+"请输入数字");
						document.getElementById(id).value="";
						return false;
					}
				}catch(e){
					document.getElementById(id).value="";
					alert(msg+"请输入数字");
					return false;
				}
			}
		}
		
		
function trim(str) {
	return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
}

function openSearchBar(){
	document.getElementById("openSearchBar").style.display="none";
	document.getElementById("closeSearchBar").style.display="block";
	document.getElementById("SearchBar").style.display="block";
}

function closeSearchBar(){
	document.getElementById("openSearchBar").style.display="block";
	document.getElementById("closeSearchBar").style.display="none";
	document.getElementById("SearchBar").style.display="none";
}


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;
	}

	}
	}
}


