﻿function show(img)
{
	document.getElementById("showdiv").style.top=document.body.scrollTop;
	document.getElementById("showdiv").style.display='inline';
	document.body.style.overflow='hidden';
	showimg.src=img;
	
	var img2 = new Image();
	img2.onload=function()
	{
		showimg.width=img2.width;
		showimg.height=img2.height;
		showimg.style.border="solid black 1px";
	}
	img2.src=img;

}

function show2()
{
	var img2 = new Image();
	img2.onerror = function()
	{
		alert('讀取錯誤 按右鍵修正圖片');
	}
	img2.onload=function()
	{
		showimg.width=img2.width;
		showimg.height=img2.height;
		showimg.style.border="solid black 1px";
	}
	img2.src=showimg.src;

}

function show3()
{
	window.parent.document.getElementById("showdiv").style.top=document.body.scrollTop;
	window.parent.document.getElementById("showdiv").style.display='inline';	
	window.parent.document.body.style.overflow='hidden';
}


function hidden()
{
	if(window.parent.document.getElementById("showdiv")!=null)
	{
		window.parent.document.getElementById("showdiv").style.display='none';
		window.parent.document.body.style.overflow='auto';
		window.showIf.location.href='blank.htm'
	}
	else
		window.close();
}

function hidden2()
{
	document.getElementById("showdiv").style.display='none';
	document.body.style.overflow='auto';
	window.showIf.location.href='blank.htm'
}

function resize1(img)
{
	img.resized=true; 
	var img2 = new Image();
	img2.onload=function()
	{
		if(img2.width>150 && img2.width>=img2.height)
		{
			img.width=150;
			img.height=img2.height*150/img2.width;
		}
		else if(img2.height>150 && img2.height>=img2.width)
		{
			img.height=150;
			img.width=img2.width*150/img2.height;
		}
		else if(img2.width<50)
		{
			img.width=50;
			img.height=50;
		}
		else
		{
			img.width=img2.width;
			img.height=img2.height;
		}
	}
	img2.src=img.src;
}

function zoomOut(img)
{
	if(img.width>document.body.clientWidth-50 || img.height>document.body.clientHeight-50)
	{
		img.resized=true; 
		var img2 = new Image();
		img2.onload=function()
		{
			for(i=2; img2.width/i>=img.width; i++); 
			img.width=img2.width/i;
			img.height=img2.height/i;
			img.title='- 點右鍵放大圖片\n- 點左鍵縮小\n- 任意鍵或點兩下離開';
			img.style.border="solid red 1px";
		}
		img2.src=img.src;
	}
}

function zoomIn(img)
{
	img.resized=true; 
	var img2 = new Image();
	img2.onload=function()
	{
		for(i=1; (img2.width+1)/(i+2)>img.width; i++);
		img.width=img2.width/i;
		img.height=img2.height/i;
		if(i==1)
			img.style.border="solid black 1px";
	}
	img2.src=img.src;
}

function chkICON()
{
	if(document.update.albumIcon.value!='')
	{
		document.update.upFile.value='';
		alert(document.update.upFile.value);
		var img2 = new Image();
//		alert(img2.width+', '+img2.height+', '+img2.src);
		img2.onerror = function()
		{
			alert('圖片有誤 再確認!! 長:'+img2.width+', 高:'+img2.height);
			return true;
		}
		img2.src=document.update.albumIcon.value;
		if(img2.width>400 || img2.height>75)
		{
			alert('圖片太大!!');
			return true;
		}
	}
	else if(document.update.upFile.value!='')
	{
		var img2 = new Image();
//		alert(img2.width+', '+img2.height+', '+img2.src);
		img2.onerror = function()
		{
			alert('圖片有誤 再確認!! 長:'+img2.width+', 高:'+img2.height);
			return true;
		}
		img2.src=document.update.upFile.value;
		if(img2.fileSize>65536)
		{
			alert('圖片太大: '+(img2.fileSize>>10)+'KB.');
			return true;
		}
		else if(img2.width>400 || img2.height>75)
		{
			alert('圖片太大!!');
			return true;
		}
	}
	
	if(document.update.albumTitle.value=='')
	{
		alert('請輸入相簿名稱!');
		return true;
	}
	return false;
}