/**
* @Copyright (c) 2006, DM72 S&D
* All rights reserved.
* 部落相册 --- 相册管理
* @filesource:	album.js
* @author      	DM72 www.dm72.net<linrenling>
* @package     	/js/
* @version     	$Id: $
*/

function album_list(group_id)
{
	Query.execute('/sys/json/album_list.php?group_id=' + group_id, 'album_list', 30);
}

var flagk=0;
function checkname(sid)
{
	var filename1=document.getElementById(sid).value;
	var len=filename1.length;
	var filename2=filename1.substr((len-4),4);
	if(filename1!="")
	{
		if((filename2==".jpg")||(filename2==".png")||(filename2==".bmp")||(filename2==".gif")||(filename2==".JPG")||(filename2==".PNG")||(filename2==".BMP")||(filename2==".GIF"))
		{
			return true;
		}
		else
		{
			alert("不合适的图片格式");
			return false;
		}
	}
	else
	{
		alert("你未选择任何照片,请选择后上传");
		return false;
	}
}

var img = null;
function s(fname)
{
	if(!document.all){ return false;}
	flagk=0;
	if(img)img.removeNode(true);
	img=document.createElement("img");
	img.style.position="absolute";
	img.style.display="none";
	img.style.visibility="hidden";
	img.attachEvent("onreadystatechange",orsc);
	document.body.insertAdjacentElement("beforeend",img);
	img.src=document.getElementById(fname).value;
}
function ajust_image(src, xLimit, yLimit)
{
	var image = new	Image();
	var width = height = 200;
	image.src = src;
	if ((xLimit > 0) && (yLimit > 0) &&	(image.width > xLimit) && (image.height > yLimit))
	{
		width = (xLimit < image.width * (yLimit / image.height)) ?
		xLimit : (image.width * (yLimit / image.height));
		height = (yLimit < image.height * (xLimit / image.width)) ?
		yLimit : (image.height * (xLimit / image.width));
	}
	else if ((xLimit > 0) && (image.width > xLimit))
	{
		width = xLimit;
		height = image.height * (xLimit / image.width);
	}
	else if ((yLimit > 0) && (image.height > yLimit))
	{
		height = yLimit;
		width = image.width * (yLimit / image.height);
	}
	else
	{
		width = image.width;
		height = image.height;
	}
	var htm_str = "width='" + width + "' height='" + height + "'";
	return htm_str;
}
function oe()
{
	alert("指定路径图片失败!");
	flagk++;
}
function orsc()
{
	if(img.readyState!="complete")
	{
	}
	else if(img.fileSize>512000)
	{
		alert("图片最大500KB");
		flagk++;
	}
}
function checkfile(fileid)
{
	var ele=$(fileid);
	var len=ele.length;
	if(len!=0)
	{
		if(checkname(fileid)&&(flagk==0))
		{
			return true;
		}
		else
		{

			return false;
		}
	}
}
function showDiv(divid,status)
{
	var curDiv = $(divid);
	if(curDiv)
	{
		if(status==0)
		curDiv.style.display = "none";
		else
		curDiv.style.display = "";
	}
}

function chgdiv(flag)
{
	if(flag==1)
	{
		showDiv("addsever",1);
		showDiv("addseverlink",0);
		showDiv("addlocal",0);
		showDiv("addlocallink",1);
		showDiv("imgaddsever",1);
		showDiv("imgaddlocal",0);

	}
	else if(flag==0)
	{
		showDiv("addsever",0);
		showDiv("addseverlink",1);
		showDiv("addlocal",1);
		showDiv("addlocallink",0);
		showDiv("imgaddsever",0);
		showDiv("imgaddlocal",1);
	}
}
function size_image(width, height, xLimit, yLimit)
{
	if ((xLimit > 0) && (yLimit > 0) &&	(width > xLimit) && (height > yLimit))
	{
		width = (xLimit < width * (yLimit / height)) ?
		xLimit : (width * (yLimit / height));
		height = (yLimit < height * (xLimit / width)) ?
		yLimit : (height * (xLimit / width));
	}
	else if ((xLimit > 0) && (width > xLimit))
	{
		width = xLimit;
		height = height * (xLimit / width);
	}
	else if ((yLimit > 0) && (height > yLimit))
	{
		height = yLimit;
		width = width * (yLimit / height);
	}
	var htm_str = "width='" + width + "' height='" + height + "'";
	return htm_str;
}
function in_img(link_form)
{
	var ajust = div_start = div_end = "";
	if (link_form.small_link[0].checked)
	{
		ajust = ajust_image(link_form.url.value, 200, 200);
	}
	for(i=1; i < 4; i++)
	{
		if(link_form.spImgAlign1[i].checked)
		{
			div_start = "<div align='" + link_form.spImgAlign1[i].value + "'>";
			div_end = "</div>";
			break;
		}
	}
	var img = div_start + "<A href='" + link_form.url.value + "' target='_blank'><img src='" + link_form.url.value + "' border='0' " + ajust + "></a>" + div_end;
	parent.Editor['posteditor'].insertText(img, false);
	top.Dialog.getInstance('up_pic_dlg').close();
}
function after_sub(url, width, height, align, do_ajust)
{
	var ajust = div_start = div_end = "";
	if (do_ajust == "yes")
	{
		ajust = size_image(width, height, 200, 200);
	}
	if(align != "")
	{
		div_start = "<div align='" + align + "'>";
		div_end = "</div>";
	}
	var img = div_start + "<A href='" + url + "' target='_blank'><img src='" + url + "' border='0' " + ajust + "></a>" + div_end;
	top.Editor['posteditor'].insertText(img, false);
	top.Dialog.getInstance('up_pic_dlg').close();
}
