﻿//function KillError() 
//{ 
//return false; 
//} 
//window.onerror=KillError;

//转到第几页
//PageUrl -- 跳转地址
//TotalPage -- 总页数
function TurnToPage(PageUrl,TotalPage) {
	var pagenum = parseInt(document.getElementById("page").value);
	if(pagenum > TotalPage){pagenum = TotalPage;};
	for(i=0;i<10;i++){ PageUrl = PageUrl.replace("[page]",pagenum); };
	window.location.href=PageUrl;
}

//批量图片等比缩放
//pid -- 图片所在层的ID
//maxwidth -- 图片最大宽度
//maxheight -- 图片最大高度
//title -- 图片提示信息
function ResizeImages(pid,maxwidth,maxheight,showimg,title){
	var imgObj
	if(pid){imgObj = document.getElementById(pid).getElementsByTagName("img");
	}else{imgObj  = document.getElementsByTagName("img");};
	if(!maxwidth){maxwidth = 500;};
	if(!showimg){showimg = 0;};
	if(!title){title = "查看原图";};
	for(i=0;i <imgObj.length;i++){
		if( imgObj[i].width>0 || imgObj[i].height>0 ){
			if(!maxheight){
				if( imgObj[i].width > maxwidth ){
					if(showimg==1){imgObj[i].onclick = function(){window.open(this.src);};imgObj[i].style.cursor = "pointer";}
					if(title != "null"){imgObj[i].title = title;};
					imgObj[i].height = imgObj[i].height * (maxwidth/imgObj[i].width);
					imgObj[i].width = maxwidth;
				};
			}else{
				if( imgObj[i].width > maxwidth || imgObj[i].height > maxheight ){
					if(showimg==1){imgObj[i].onclick = function(){window.open(this.src);};imgObj[i].style.cursor = "pointer";}
					if(title != "null"){imgObj[i].title = title;};
					if((imgObj[i].width/imgObj[i].height) > (maxwidth/maxheight)){
						imgObj[i].height = imgObj[i].height * (maxwidth/imgObj[i].width);
						imgObj[i].width = maxwidth;
					}else{
						imgObj[i].width = imgObj[i].width * (maxheight/imgObj[i].height);
						imgObj[i].height = maxheight;
					};
				};
			};
		};
	};
};

//显示图片并等比缩放
//pid -- 图片所在层的ID
//maxwidth -- 图片最大宽度
//maxheight -- 图片最大高度
//title -- 图片提示信息
function showPicture(purl,maxwidth,maxheight,title){
	if(purl.length>0){
		document.getElementById('pictureimg').innerHTML='<a href='+purl+' target=_blank><img src=' + purl + ' height=95 width=150 border=0 onload=javascript:ResizeImage(this,150,95)></a>';
	}else{document.getElementById('pictureimg').innerHTML='<img src=../uploadfiles/nophoto.jpg height=95 width=150 />';};
};

//单个图片等比缩放
//pid -- 图片ID
//maxwidth -- 图片最大宽度
//maxheight -- 图片最大高度
//title -- 图片提示信息
function ResizeImage(pid,maxwidth,maxheight,showimg,title){
	var imgObj=new Image();
	imgObj.src=pid.src;
	if(!maxwidth){maxwidth = 500;};
	if(!showimg){showimg = 0;};
	if(!title){title = "查看原图";};
	if( imgObj.width>0 || imgObj.height>0 ){
		if(!maxheight){
			if( imgObj.width > maxwidth ){
				if(showimg==1){pid.onclick = function(){window.open(this.src);};pid.style.cursor = "pointer";}
				if(title != "null"){pid.title = title;};
				pid.height = imgObj.height * (maxwidth/imgObj.width);
				pid.width = maxwidth;
			};
		}else{
			if( imgObj.width > maxwidth || imgObj.height > maxheight ){
				if(showimg==1){pid.onclick = function(){window.open(this.src);};pid.style.cursor = "pointer";}
				if(title != "null"){pid.title = title;};
				if((imgObj.width/imgObj.height) > (maxwidth/maxheight)){
					pid.height = imgObj.height * (maxwidth/imgObj.width);
					pid.width = maxwidth;
				}else{
					pid.width = imgObj.width * (maxheight/imgObj.height);
					pid.height = maxheight;
				};
			};
		};
	};
};


//获得图片尺寸
//purl -- 图片地址
//pid -- 信息显示位置ID
function getPictureSize(purl,pid){
	var imgObj = new Image();
	if(!purl) return false;
	if(!pid) {pid = "picturesize";};
	imgObj.src = purl;
	document.getElementById(pid).innerHTML='[ '+ imgObj.width + '*' + imgObj.height + ' ]';
};


function switchTab(tabid,id){
	for(var i=1;i< 5;i++){
		var x = document.getElementById('class' + i);	
		x.style.display = "display:none";
	}	
	document.getElementById(tabid).className = "Selected";
}

function classTab(tabid){
	for(var i=1;i< 5;i++){
		document.getElementById('class' + i).style.display = "none";
		document.getElementById('Tab' + i).className = "mousehand";
	};
	document.getElementById('class' + tabid).style.display = "";
	document.getElementById('Tab' + tabid).className = "Selected";
	ResizeImages('class' + tabid,120,100,0,'null');
}