var gnDeltaSize = 20;

function ShowSubMenu(IDList,NameList,MySex,Sex) {
	var IDSplit = IDList.split("$$");
	var NameSplit = NameList.split("$$");
	var i,j,HTMLStr,TempStr,TempShopID,isCurrent;
	var ChildIDSplit,ChildNameSplit;
	var isSearched = ((parseInt(IDSplit[0]) % 100) == 95);
	var ThisShopID = (self.location.href.toLowerCase().indexOf("plus_avatar_center.asp") >= 0 || self.location.href.toLowerCase().indexOf("plus_avatar_photo.asp") >= 0 ? document.CurShopID : parent.document.CurShopID);
	var ThisSeqNo = (self.location.href.toLowerCase().indexOf("plus_avatar_center.asp") >= 0 || self.location.href.toLowerCase().indexOf("plus_avatar_photo.asp") >= 0 ? document.CurSeqNo : parent.document.CurSeqNo);
	
	if(isSearched)
		var ThisSearchURL = (self.location.href.toLowerCase().indexOf("plus_avatar_center.asp") >= 0 || self.location.href.toLowerCase().indexOf("plus_avatar_photo.asp") >= 0 ? document.SearchURL : parent.document.SearchURL);
	
	if(window.event != null) {
		var toElement = (event.toElement ? event.toElement : event.relatedTarget);
		if(toElement != null)	while (toElement.nodeType != 1) toElement = toElement.parentNode;
		if(toElement != null && toElement.nodeType == 1)	
			if(toElement.attributes.getNamedItem("class") != null)
				if(toElement.attributes.getNamedItem("class").nodeValue == "menuskin") return;
	}
	if(isSearched)
		HTMLStr = "<b>排序对象：</b>";
	else
		HTMLStr = "";
	for(i = 0; i < NameSplit.length; i ++) {
		TempShopID = IDSplit[i];
		if(HTMLStr != "") HTMLStr = HTMLStr + "&nbsp;";
		ChildIDSplit = IDSplit[i].split("||");
		ChildNameSplit = NameSplit[i].split("||");
		if(ChildIDSplit.length > 1) {
			isCurrent = false;
			for(j = 0; j < ChildIDSplit.length; j ++)
				isCurrent = (isCurrent || (ChildIDSplit[j] == Math.abs(ThisShopID)));
		} else
			isCurrent = (TempShopID == Math.abs(ThisShopID));
		if(isCurrent) {
			if(self.location.href.toLowerCase().indexOf("plus_avatar_center.asp") >= 0 || self.location.href.toLowerCase().indexOf("plus_avatar_photo.asp") >= 0)
				var MenuRowObj = document.getElementById("MenuRow");
			else
				var MenuRowObj = parent.document.getElementById("MenuRow");
			var n;
			for(j = 0; j < MenuRowObj.children.length; j ++) {
				n = MenuRowObj.children[j];
				if(j == ThisSeqNo - 1)
					n.children[0].color = 'red';
				else
					n.children[0].color = '';
			}
			if(isSearched) {
				TempStr = '<font face="wingdings" style="font-size:16px" color="blue">&#151;</font><a hideFocus="false" href=javascript:RefreshAvatarFrame("shopid=';
				if(ThisShopID < 0)
					TempStr = TempStr + TempShopID;
				else
					TempStr = TempStr + '-' + TempShopID;
				TempStr = TempStr + '&mysex=' + MySex + ThisSearchURL + '")><font color="red">';
				if(ThisShopID > 0)
					TempStr = TempStr + NameSplit[i] + '↑';
				else
					TempStr = TempStr + NameSplit[i] + '↓';
				TempStr = TempStr + '</font></a><font face="wingdings" style="font-size:16px" color="blue">&#150;</font>';
			} else {
				if(ChildIDSplit.length <= 1)
					if(Sex != '')
						TempStr = '<font face="wingdings" style="font-size:16px" color="blue">&#151;</font><a hideFocus="false" href=javascript:RefreshAvatarFrame("shopid=' + TempShopID + '&mysex=' + MySex + '&sex=' + Sex + '")><font color="red">' + NameSplit[i] + '</font></a><font face="wingdings" style="font-size:16px" color="blue">&#150;</font>';
					else
						TempStr = '<font face="wingdings" style="font-size:16px" color="blue">&#151;</font><a hideFocus="false" href=javascript:RefreshAvatarFrame("shopid=' + TempShopID + '&mysex=' + MySex + '")><font color="red">' + NameSplit[i] + '</font></a><font face="wingdings" style="font-size:16px" color="blue">&#150;</font>';
				else
					if(Sex != '')
						TempStr = '<font face="wingdings" style="font-size:16px" color="blue">&#151;</font><a hideFocus="false" href=javascript:RefreshAvatarFrame("shopid=' + ChildIDSplit[0] + '&mysex=' + MySex + '&sex=' + Sex + '") onmouseover=ShowDvbbsMenu(event,' + ThisShopID + ',"' + IDSplit[i] + '","' + NameSplit[i] + '","' + MySex + '","' + Sex+ '") onmouseout="delayhidemenu()" class="ImgOnclick"><font color="red">' + ChildNameSplit[0] + '</font></a><font face="wingdings" style="font-size:16px" color="blue">&#150;</font>';
					else
						TempStr = '<font face="wingdings" style="font-size:16px" color="blue">&#151;</font><a hideFocus="false" href=javascript:RefreshAvatarFrame("shopid=' + ChildIDSplit[0] + '&mysex=' + MySex + '") onmouseover=ShowDvbbsMenu(event,' + ThisShopID + ',"' + IDSplit[i] + '","' + NameSplit[i] + '","' + MySex + '","' + Sex+ '") onmouseout="delayhidemenu()" class="ImgOnclick"><font color="red">' + ChildNameSplit[0] + '</font></a><font face="wingdings" style="font-size:16px" color="blue">&#150;</font>';
			}
		} else {
			if(isSearched) {
				TempStr = '<a hideFocus="false" href=javascript:RefreshAvatarFrame("shopid=' + TempShopID + '&mysex=' + MySex + ThisSearchURL + '")>' + NameSplit[i] + '</a>';
			} else {
				if(ChildIDSplit.length <= 1) 
					if(Sex != '')
						TempStr = '<a hideFocus="false" href=javascript:RefreshAvatarFrame("shopid=' + TempShopID + '&mysex=' + MySex + '&sex=' + Sex + '")>' + NameSplit[i] + '</a>';
					else
						TempStr = '<a hideFocus="false" href=javascript:RefreshAvatarFrame("shopid=' + TempShopID + '&mysex=' + MySex + '")>' + NameSplit[i] + '</a>';
				else
					if(Sex != '')
						TempStr = '<a hideFocus="false" href=javascript:RefreshAvatarFrame("shopid=' + ChildIDSplit[0] + '&mysex=' + MySex + '&sex=' + Sex + '") onmouseover=ShowDvbbsMenu(event,' + ThisShopID + ',"' + IDSplit[i] + '","' + NameSplit[i] + '","' + MySex + '","' + Sex+ '") onmouseout="delayhidemenu()" class="ImgOnclick">' + ChildNameSplit[0] + '</a>';
					else
						TempStr = '<a hideFocus="false" href=javascript:RefreshAvatarFrame("shopid=' + ChildIDSplit[0] + '&mysex=' + MySex + '") onmouseover=ShowDvbbsMenu(event,' + ThisShopID + ',"' + IDSplit[i] + '","' + NameSplit[i] + '","' + MySex + '","' + Sex+ '") onmouseout="delayhidemenu()" class="ImgOnclick">' + ChildNameSplit[0] + '</a>';
			}
		}
		HTMLStr = HTMLStr + TempStr;
	}
	if(self.location.href.toLowerCase().indexOf("plus_avatar_center.asp") >= 0 || self.location.href.toLowerCase().indexOf("plus_avatar_photo.asp") >= 0)
		document.getElementById("AvatarSubType").innerHTML = HTMLStr;
	else
		parent.document.getElementById("AvatarSubType").innerHTML = HTMLStr;
}

function SubmitAvatarSearch() {
	var FormObj = document.getElementById("AvatarFrame").contentWindow.document.getElementById("AvatarSearch");
	
	FormObj.search_str.value = document.getElementById("AvatarSearch").search_str.value;
	FormObj.selgender.value = document.getElementById("AvatarSearch").selgender.value;
	FormObj.selPrice_L.value = document.getElementById("AvatarSearch").selPrice_L.value;
	FormObj.selPrice_H.value = document.getElementById("AvatarSearch").selPrice_H.value;
	FormObj.selPeriod_L.value = document.getElementById("AvatarSearch").selPeriod_L.value;
	FormObj.selPeriod_H.value = document.getElementById("AvatarSearch").selPeriod_H.value;
	FormObj.selflag.value = document.getElementById("AvatarSearch").selflag.value;
	//document.getElementById("AvatarSearch").reset();
	FormObj.submit();
	return false;
}

function SubmitPhotoSearch() {
	var FormObj = document.getElementById("PhotoFrame").contentWindow.document.getElementById("PhotoSearch");
	
	FormObj.search_Sponsor.value = document.getElementById("PhotoSearch").search_Sponsor.value;
	FormObj.selUserCount_L.value = document.getElementById("PhotoSearch").selUserCount_L.value;
	FormObj.selUserCount_H.value = document.getElementById("PhotoSearch").selUserCount_H.value;
	FormObj.selURL.value = document.getElementById("PhotoSearch").selURL.value;
	FormObj.selUpload.value = document.getElementById("PhotoSearch").selUpload.value;
	//document.getElementById("PhotoSearch").reset();
	FormObj.submit();
	return false;
}

function ShowDvbbsMenu(event, ShopID, IDList, NameList, MySex, Sex) {
	var IDSplit,NameSplit,vMenu,i;
	
	IDSplit = IDList.split("||");
	NameSplit = NameList.split("||");
	if(IDSplit.length > 1) {
		vMenu = "<div class='menuitems'>";
		for(i = 0; i < IDSplit.length; i ++) {
			if(i > 0) vMenu = vMenu + "<br>";
			vMenu = vMenu + "<a href=javascript:RefreshAvatarFrame('shopid=" + IDSplit[i] + "&mysex=" + MySex;
			if(Sex != '')
				vMenu = vMenu + "&sex=" + Sex + "')>";
			else
				vMenu = vMenu + "')>";
			if(ShopID == IDSplit[i]) vMenu = vMenu + "<font color='red'>";
			if(i == 0)
				vMenu = vMenu + "全部";
			else
				vMenu = vMenu + NameSplit[i];
			if(ShopID == IDSplit[i]) vMenu = vMenu + "</font>";
			vMenu = vMenu + "</a>";
		}
		vMenu = vMenu + "</div>";
		return showmenu(event,vMenu);
	}
}

function RefreshAvatarFrame(QueryString) {
	if(document.getElementById("AvatarSearch")) document.getElementById("AvatarSearch").reset();
	if(document.getElementById("AvatarFrame")) document.getElementById("AvatarFrame").src="Plus_Avatar_Items.asp?" + QueryString;
	if(document.getElementById("PhotoFrame")) document.getElementById("PhotoFrame").src="Plus_Avatar_PhotoDetail.asp?" + QueryString;
}

function TakeOffTool(UserID, UserSex, ItemID, ItemLayer) {
	var CookieData, AvatarSplit, i;

	CookieData = getCookie("MyAvatar_" + UserID);
	if(IsAvatarString(CookieData)) {
		AvatarSplit = CookieData.split("|");
		if(ItemLayer.indexOf("_") < 0)
			TakeOffSingleTool(AvatarSplit, ItemID, ItemLayer, UserSex);
		else	
			TakeOffMultiTool(AvatarSplit, ItemID, ItemLayer, UserSex);
		CookieData = "";
		for(i = 0; i < AvatarSplit.length; i ++) {
			if(i > 0) CookieData += "|";
			CookieData += AvatarSplit[i];
		}
		setCookie("MyAvatar_" + UserID, CookieData);
	}
}

function TakeOffSingleTool(AvatarSplit, ItemID, ItemLayer, UserSex) {
	if(AvatarSplit[parseInt(ItemLayer) - 1] == ItemID)
		SetGenderLayer(AvatarSplit, ItemLayer, UserSex);
}

function TakeOffMultiTool(AvatarSplit, ItemID, ItemLayer, UserSex) {
	var LayerArray, i;
	
	LayerArray = ItemLayer.split("_");
	for(i = 0; i < LayerArray.length; i ++)
		TakeOffSingleTool(AvatarSplit, ItemID, LayerArray[i], UserSex);
}

function SetGenderLayer(AvatarSplit, ItemLayer, UserSex) {
	TakeAvatar(AvatarSplit, ItemLayer, GetGenderItemID(ItemLayer, UserSex))
}

function TakeAvatar(AvatarSplit, ItemLayer, ItemID) {
	if(ItemID == -1)
		AvatarSplit[parseInt(ItemLayer) - 1] = "";
	else
		AvatarSplit[parseInt(ItemLayer) - 1] = ItemID;
}

function GetClipboardAvatar(URLStr) {
	var ClipboardData = window.clipboardData.getData('text');
	if(IsAvatarString(ClipboardData)) {
		URLStr = URLStr.replace(/\$\$UserAvaSetting\$\$/gi, ClipboardData);
		PlusOpen(URLStr, 500, 400);
	} else {
		alert("剪贴板中没有虚拟形象信息，无法粘贴形象！");
	}
	return false;
}

function GetCookieAvatar(URLStr) {
	CookieData = document.getElementById("AvatarShow").GetAvatar();
	if(IsAvatarString(CookieData)) {
		URLStr = URLStr.replace(/\$\$UserAvaSetting\$\$/gi,CookieData);
		PlusOpen(URLStr, 500, 400);
	} else {
		alert("没有可供复制的虚拟形象信息，无法复制形象！");
	}
	return false;
}

function RestoreAvatar(UserID, UserSex, CurSex) {
	if(UserSex != CurSex) {
		alert('对不起，异性状态，无法恢复形象，可切换为同性状态后恢复！');
		return ;
	}
	if(UserID == '0')
		document.cookie = "MyAvatar_" + UserSex + "_" + UserID + "=" + escape("");
	else
		document.cookie = "MyAvatar_" + UserID + "=" + escape("");
	location.reload();
}

function DeleteAvatar(UserID, UserSex, CurSex) {
	if(UserID == '0')
		if(CurSex == 1)
			document.cookie = "MyAvatar_1_" + UserID + "=" + escape('||||||14|13|12||11||10|9||||8|||||||');
		else
			document.cookie = "MyAvatar_0_" + UserID + "=" + escape('||||||7|6|5||4||3|2||||1|||||||');
	else
		if(UserSex == CurSex)
			if(CurSex == 1)
				document.cookie = "MyAvatar_" + UserID + "=" + escape('||||||14|13|12||11||10|9||||8|||||||');
			else
				document.cookie = "MyAvatar_" + UserID + "=" + escape('||||||7|6|5||4||3|2||||1|||||||');
	location.reload();
}

function ConfirmPhotoMe(PhotoPrice, MyMoney, UserID, UserSex, CurSex) {
	if(UserSex != CurSex) {
		if(confirm('对不起，性别不符，无法照相！是否切换回同性别？'))
			document.location="Plus_Avatar_Center.asp?mysex=" + UserSex + "&shopid=" + CurShopID;
		return false;
	}
	if(UserID == '0') {
		alert("游客无法进行个人写真！");
		return false;
	}
	if(confirm('个人写真的费用是 ' + PhotoPrice + ' 元，您现在有现金 ' + MyMoney + ' 元，是否确认拍照？')) {
		var URLStr = 'Plus_Avatar_PhotoSave.asp?action=PhotoMyself';
		var CookieData = getCookie("MyAvatar_" + UserID);
		if(IsAvatarString(CookieData)) {
			URLStr = URLStr + '&fromavatar=' + CookieData;
		}
		document.location=URLStr;
	}
	return false;
}

function ConfirmPhotoGroup(UserID, UserSex, CurSex) {
	if(UserSex != CurSex) {
		if(confirm('对不起，性别不符，无法照相！是否切换回同性别？'))
			document.location="Plus_Avatar_Center.asp?mysex=" + UserSex + "&shopid=" + CurShopID;
		return false;
	}
	if(UserID == '0') {
		alert("游客无法发出合影请求！");
		return false;
	}
	document.location='Plus_Avatar_Photo.asp?shopid=197';
	return true;
}

function IsAvatarString(pString) {
	if(!pString) return false;
	if(pString.match(/[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*\|[\d\._]*/i)!=null) return true;
	return false;
}
	
function setOrgimg(emotion,sex,EmotLayerStr) {
	document.getElementById("origin").layerno = EmotLayerStr;
	document.getElementById("origin").itemgender = sex;
	if(emotion != '')
		document.getElementById("origin").itemno = emotion;
	AvatarShow.clickDress();
}

function AvatarDesign(UserID,MyAvatar,MySex,CurSex,LocalPic,PicPath,AvatarWidth,AvatarHeight,BoyEmotXiItemNo,BoyEmotNuItemNo,BoyEmotAiItemNo,BoyEmotLeItemNo,GirlEmotXiItemNo,GirlEmotNuItemNo,GirlEmotAiItemNo,GirlEmotLeItemNo,EmotLayerStr) {
	var CurLayerStr;
	var i,CurAvatar,CurAvatarSplit,CurEmotion;
	
	if(UserID=='0')
		CurAvatar = getCookie("MyAvatar_" + MySex + "_" + UserID);
	else
		if(MySex == CurSex)
			CurAvatar = getCookie("MyAvatar_" + UserID);
		else
			CurAvatar = "";
	if(CurAvatar == "")
		if(MySex == CurSex)
			CurAvatar = MyAvatar;
		else
			if(CurSex == "1")
				CurAvatar = "||||||14.7|13.8|12.9||11.11||10.13|9.14||||8.18|||||||"
			else
				CurAvatar = "||||||7.7|6.8|5.9||4.11||3.13|2.14||||1.18|||||||"
	CurAvatarSplit = CurAvatar.split("|");
	CurLayerStr = GetLayerStr(CurAvatarSplit);
	if(CurAvatarSplit.length < 10)
		CurEmotion = "";
	else
		CurEmotion = CurAvatarSplit[10];
	document.write("<table border=0 cellspacing=0 cellpadding=0 style='width:" + AvatarWidth + "' align=center>");
	document.write("<tr><td align=center width=100%>");
	document.write("<table border=0 cellspacing=1 cellpadding=1 class=tableborder1 style='width:100%' align=center>");
	document.write("<tr>")
	document.write("<td oncontextmenu='return false;' align=center class=tablebody1 width=100% height=" + AvatarHeight + " id=AvatarShow ImagePath='" + PicPath + "' enableLayers='" + CurLayerStr + "' usergender='" + CurSex + "' oriusergender='" + MySex + "' baseName='Dv_Plus/Avatar/Pic/blank.gif' ");
	for(i = 0; i < CurAvatarSplit.length; i ++)
		if(CurAvatarSplit[i] != "")
			document.write("layer" + (i + 1) + "=" + CurAvatarSplit[i] + " ");
	document.write("style=behavior:url(Dv_Plus/Avatar/Plus_Avatar_Design.htc) cookies='document.cookie' setCookies='document.cookie=this.cookies' userid=" + UserID + " localpic=" + LocalPic + "></td>");
	document.write("</tr>");
	document.write("</table></td></tr>");
	document.write("<tr><td>");
	document.write("<table height=" + Math.floor(AvatarWidth / 5) + " border=0 cellspacing=1 cellpadding=1 class=tableborder1 style='width:100%' id=AvatarEmotion>");
	document.write("<tr>");
	if(CurSex == 1) {
		if(CurEmotion != BoyEmotXiItemNo && CurEmotion != BoyEmotNuItemNo && CurEmotion != BoyEmotAiItemNo && CurEmotion != BoyEmotLeItemNo)
			document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=origin src=Dv_Plus/Avatar/Pic/man_origin.gif width=24 height=22 border=0 onclick=setOrgimg(''," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
		else
			document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=origin src=Dv_Plus/Avatar/Pic/man_origin.gif width=24 height=22 border=0 itemno=" + CurEmotion + " onclick=setOrgimg(''," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
		document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=xi src=Dv_Plus/Avatar/Pic/man_xi.gif alt=喜 width=24 height=22 border=0 itemgender=" + CurSex + " itemno=" + BoyEmotXiItemNo + " layerno=" + EmotLayerStr + " onclick=setOrgimg(this.itemno," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
		document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=nu src=Dv_Plus/Avatar/Pic/man_nu.gif alt=怒 width=24 height=22 border=0 itemgender=" + CurSex + " itemno=" + BoyEmotNuItemNo + " layerno=" + EmotLayerStr + " onclick=setOrgimg(this.itemno," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
		document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=ai src=Dv_Plus/Avatar/Pic/man_ai.gif alt=哀 width=24 height=22 border=0 itemgender=" + CurSex + " itemno=" + BoyEmotAiItemNo + " layerno=" + EmotLayerStr + " onclick=setOrgimg(this.itemno," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
		document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=le src=Dv_Plus/Avatar/Pic/man_le.gif alt=乐 width=24 height=22 border=0 itemgender=" + CurSex + " itemno=" + BoyEmotLeItemNo + " layerno=" + EmotLayerStr + " onclick=setOrgimg(this.itemno," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
	} else {
		if(CurEmotion != GirlEmotXiItemNo && CurEmotion != GirlEmotNuItemNo && CurEmotion != GirlEmotAiItemNo && CurEmotion != GirlEmotLeItemNo)
			document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=origin src=Dv_Plus/Avatar/Pic/woman_origin.gif width=24 height=22 border=0 onclick=setOrgimg(''," + CurSex + ",'" + EmotLayerStr + "') style='cursor:pointer'></td>");
		else
			document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=origin src=Dv_Plus/Avatar/Pic/woman_origin.gif width=24 height=22 border=0 itemno=" + CurEmotion + " onclick=setOrgimg(''," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
		document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=xi src=Dv_Plus/Avatar/Pic/woman_xi.gif alt=喜 width=24 height=22 border=0 itemgender=" + CurSex + " itemno=" + GirlEmotXiItemNo + " layerno=" + EmotLayerStr + " onclick=setOrgimg(this.itemno," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
		document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=nu src=Dv_Plus/Avatar/Pic/woman_nu.gif alt=怒 width=24 height=22 border=0 itemgender=" + CurSex + " itemno=" + GirlEmotNuItemNo + " layerno=" + EmotLayerStr + " onclick=setOrgimg(this.itemno," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
		document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=ai src=Dv_Plus/Avatar/Pic/woman_ai.gif alt=哀 width=24 height=22 border=0 itemgender=" + CurSex + " itemno=" + GirlEmotAiItemNo + " layerno=" + EmotLayerStr + " onclick=setOrgimg(this.itemno," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
		document.write("<td align=center class=tablebody1 width=" + Math.floor(AvatarWidth / 5) + " oncontextmenu='return false'><img id=le src=Dv_Plus/Avatar/Pic/woman_le.gif alt=乐 width=24 height=22 border=0 itemgender=" + CurSex + " itemno=" + GirlEmotLeItemNo + " layerno=" + EmotLayerStr + " onclick=setOrgimg(this.itemno," + CurSex + ",'" + EmotLayerStr + "') style=cursor:pointer></td>");
	}
	document.write("</tr>");
	document.write("</table>");
	document.write("</td></tr>");
	document.write("<tr><td>");
	document.write("<table border=0 cellspacing=0 cellpadding=1 class=tableborder1 style='width:100%'>");
	document.write("<tr height=25 id='takeonrecordTr'>");
	document.write("<td width=100%>");
	document.write("<table width=100% border=0 cellspacing=0 cellpadding=0><tr height=25>");
	document.write("<td width='*' class=tablebody2><input type='button' id='AvatarButton1' value='试穿'");
	if(RecFlag == 1) document.write(" disabled='true'");
	document.write(" onclick=ToggleButton('" + UserID + "','" + MySex + "',1)><input type='button' id='AvatarButton2' value='物品'");
	if(RecFlag == 0) document.write(" disabled='true'");
	document.write(" onclick=ToggleButton('" + UserID + "','" + MySex + "',0)></td>");
	document.write("<td name=btnMoveLeft width=15 valign=middle align=center class=tablebody2><img src='Dv_Plus/Avatar/Pic/left.gif' style='cursor:pointer;display:none'></td>");
	document.write("<td name=btnMoveRight width=15 valign=middle align=center class=tablebody2><img src='Dv_Plus/Avatar/Pic/right.gif' style='cursor:pointer;display:none'></td>");
	document.write("</tr>");
	document.write("</table>");
	document.write("<table name=takeonrecord align=center border=0 cellpadding=1 cellspacing=1 class=tableborder1 style='width:100%'>");
	document.write("<tr>");
	document.write("<td width=" + Math.floor(AvatarWidth / 2) + " align=center class=tablebody1 oncontextmenu='return false'><img style=cursor:pointer height=" + Math.floor(AvatarWidth / 2) + " name='IMG' src='Dv_Plus/Avatar/Pic/blank.gif' width=" + Math.floor(AvatarWidth / 2) + " border=0 itemgender=" + CurSex + "></td>");
	document.write("<td width=" + Math.floor(AvatarWidth / 2) + " align=center class=tablebody1 oncontextmenu='return false'><img style=cursor:pointer height=" + Math.floor(AvatarWidth / 2) + " name='IMG' src='Dv_Plus/Avatar/Pic/blank.gif' width=" + Math.floor(AvatarWidth / 2) + " border=0 itemgender=" + CurSex + "></td>");
	document.write("</tr>");
	document.write("</table>");
	document.write("</td>");
	document.write("</table>");
	document.write("</td></tr>");
	document.write("</tr>");
	document.write("</table>");
}

function GetLayerStr(AvatarSplit) {
	var i,LayerStr;
	
	LayerStr = "";
	for(i = 0; i < AvatarSplit.length; i ++)
		if(AvatarSplit[i] != "") {
			if(LayerStr != "") LayerStr = LayerStr + "_";
			LayerStr = LayerStr + (i + 1);
		}
	return LayerStr;
}

function getCookie(name) {
  var search,offset,end;
  var cookies = document.cookie;
  
	if(!cookies || cookies == "") return "";
  search = name + "=";
  offset = cookies.indexOf(search);
  if (offset != -1) {
    offset += search.length ;
    end = cookies.indexOf(";", offset) ;
    if (end == -1) end = cookies.length;
    return unescape(cookies.substring(offset, end));
  } else return "";
}

function setCookie(name, value) {
  document.cookie = name + "=" + escape(value);
}

function ShowItemPic(ImgObj,LocalPic,PicPath,ItemNo) {
	ImgObj.src = PicPath + GetPicURL(LocalPic, "0", ItemNo);
}

function GetPicURL(LocalPic, ItemLayer, ItemNo) {
	if(LocalPic == 0)
		var RetURL = ItemNo + "/" + ItemLayer + "/00/";
	else
		var RetURL = ItemLayer + "/" + ItemNo + ".Gif";
	return  RetURL
}

function ShowAvatarPhoto(ObjTD, LocalPic, PicPath, PhotoPath, IsDesigning, PhotoUserCount, CurShopID, NormalPhotoWidth, SmallPhotoWidth, VarPrefix, isShowBorder) {
	var i, IsPhotoMyself = (parseInt(CurShopID) >= 497 && parseInt(PhotoUserCount) == 1);
	var bgWidth = parseInt(document.getElementById("BgWidth" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	var bgHeight = parseInt(document.getElementById("BgHeight" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	var UploadFile = document.getElementById("bgfname" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoBg = document.getElementById("PhotoBg" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoBodyBack = document.getElementById("PhotoBodyBack" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoBodyFore = document.getElementById("PhotoBodyFore" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoFg = document.getElementById("PhotoFg" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoName = document.getElementById("PhotoName" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoNameLeft = parseInt(document.getElementById("PhotoNameLeft" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	var PhotoNameWidth = parseInt(document.getElementById("PhotoNameWidth" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	var PhotoNameTop = parseInt(document.getElementById("PhotoNameTop" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	var PhotoNameFont = document.getElementById("PhotoNameFont" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoNameSize = document.getElementById("PhotoNameSize" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoNameBold = document.getElementById("PhotoNameBold" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoNameItalic = document.getElementById("PhotoNameItalic" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoNameColor = document.getElementById("PhotoNameColor" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoNameDirection = document.getElementById("PhotoNameDirection" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoDate = document.getElementById("PhotoDate" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoDateLeft = parseInt(document.getElementById("PhotoDateLeft" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	var PhotoDateWidth = parseInt(document.getElementById("PhotoDateWidth" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	var PhotoDateTop = parseInt(document.getElementById("PhotoDateTop" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	var PhotoDateFont = document.getElementById("PhotoDateFont" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoDateSize = document.getElementById("PhotoDateSize" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoDateBold = document.getElementById("PhotoDateBold" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoDateItalic = document.getElementById("PhotoDateItalic" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoDateColor = document.getElementById("PhotoDateColor" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var PhotoDateDirection = document.getElementById("PhotoDateDirection" + (VarPrefix == "" ? "" : "_" + VarPrefix)).value;
	var ResultStr = "";
	
	if(isShowBorder == '1') {
		var PhotoWidth = bgWidth + 14;
		var PhotoHeight = bgHeight + 14;
	} else {
		var PhotoWidth = bgWidth + 2;
		var PhotoHeight = bgHeight + 2;
	}
	ResultStr = ResultStr + '<DIV id="ThePhotoBorder" style="left:0;top:0;width:' + PhotoWidth + ';height:' + PhotoHeight + ';position:relative;overflow:hidden;';
	if(isShowBorder != '1')
		ResultStr = ResultStr + 'border:1px dashed black;padding:1px;';
	else
		ResultStr = ResultStr + 'padding:7px;';
	ResultStr = ResultStr + '" unselectable="on" oncontextmenu="return false">';
	ResultStr = ResultStr + '<DIV id="ThePhoto" unselectable="on"';
	if(IsDesigning == '1')
		ResultStr = ResultStr + ' onmousedown="ProcessMouseDown(' + PhotoUserCount + ')" onmousemove="ProcessMouseMove()" onmouseup="ProcessMouseUp()"';	
	ResultStr = ResultStr + ' oncontextmenu="return false" ondragstart="return false" ondrag="return false" ondragend="return false" style="left:0;top:0;width:' + bgWidth + ';height:' + bgHeight + ';overflow:hidden;position:relative">';
	if(UploadFile != '')
		ResultStr = ResultStr + '<img src="' + PhotoPath + UploadFile + '" style="padding:0;position:absolute;top:0;left:0;width:' + bgWidth + ';height:' + bgHeight + ';z-index:1;display:inline;"';
	else
		if(PhotoBg != '') 
			ResultStr = ResultStr + '<img src="' + GetItemPicURL(LocalPic, PicPath, PhotoBg, '1') + '" style="padding:0;position:absolute;top:0;left:0;width:' + bgWidth + ';height:' + bgHeight + ';z-index:1;display:inline;"';
		else
			ResultStr = ResultStr + '<img src="about:blank" style="padding:0;position:absolute;top:0;left:0;width:' + bgWidth + ';height:' + bgHeight + ';z-index:1;display:none;"';
	ResultStr = ResultStr + ' id="photo_bg">';
	if(parseInt(bgWidth) == parseInt(NormalPhotoWidth)) {
		if(PhotoBodyBack != '')
			ResultStr = ResultStr + '<img src="' + GetItemPicURL(LocalPic, PicPath, PhotoBodyBack, '2') + '" style="padding:0;position:absolute;top:0;left:0;width:' + bgWidth + ';height:' + bgHeight + ';z-index:2;display:inline;"';
		else
			ResultStr = ResultStr + '<img src="about:blank" style="padding:0;position:absolute;top:0;left:0;width:' + bgWidth + ';height:' + bgHeight + ';z-index:2;display:none;"';
		ResultStr = ResultStr + ' id="photo_bodyback">';
	}
	for(i = 1; i <= 3; i ++)
		ResultStr = ResultStr + GetAccoutermentDiv(LocalPic, PicPath, 
			document.getElementById("AccoutermentSeqNo_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value, 
			document.getElementById("AccoutermentItemID_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value, 
			(i - 1) * 2 + 3,
			parseInt(document.getElementById("AccoutermentOuterLeft_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentOuterTop_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentOuterWidth_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentOuterHeight_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentInnerLeft_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentInnerTop_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentInnerWidth_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentInnerHeight_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			document.getElementById("AccoutermentDirection_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	for(i = 1; i <= PhotoUserCount; i ++)
		ResultStr = ResultStr + GetAvatarDiv(LocalPic, PicPath, i, 
			document.getElementById("UserAvaSetting_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value, 
			document.getElementById("LayerNo_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value,
			parseInt(document.getElementById("AvatarOuterLeft_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AvatarOuterTop_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AvatarOuterWidth_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AvatarOuterHeight_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AvatarInnerLeft_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AvatarInnerTop_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AvatarInnerWidth_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AvatarInnerHeight_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			document.getElementById("AvatarDirection_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value,
			IsPhotoMyself);
	for(i = 4; i <= 6; i ++)
		ResultStr = ResultStr + GetAccoutermentDiv(LocalPic, PicPath, 
			document.getElementById("AccoutermentSeqNo_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value, 
			document.getElementById("AccoutermentItemID_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value, 
			PhotoUserCount * 31 + 10,
			parseInt(document.getElementById("AccoutermentOuterLeft_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentOuterTop_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentOuterWidth_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentOuterHeight_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentInnerLeft_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentInnerTop_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentInnerWidth_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("AccoutermentInnerHeight_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			document.getElementById("AccoutermentDirection_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	if(parseInt(bgWidth) == parseInt(NormalPhotoWidth)) {
		if(PhotoBodyFore != "")
			ResultStr = ResultStr + '<img src="' + GetItemPicURL(LocalPic, PicPath, PhotoBodyFore, '24') + '" style="padding:0;position:absolute;top:0;left:0;width:' + bgWidth + ';height:' + bgHeight + ';z-index:' + (PhotoUserCount * 31 + 16) + ';display:inline;"';
		else
			ResultStr = ResultStr + '<img src="about:blank" style="padding:0;position:absolute;top:0;left:0;width:' + bgWidth + ';height:' + bgHeight + ';z-index:' + (PhotoUserCount * 31 + 16) + ';display:none;"';
		ResultStr = ResultStr + (' id="photo_bodyfore">');
		if(PhotoFg != "")
			ResultStr = ResultStr + '<img src="' + GetItemPicURL(LocalPic, PicPath, PhotoFg, '25') + '" style="padding:0;position:absolute;top:0;left:0;width:' + bgWidth + ';height:' + bgHeight + ';z-index:' + (PhotoUserCount * 31 + 17) + ';display:inline;"';
		else
			ResultStr = ResultStr + '<img src="about:blank" style="padding:0;position:absolute;top:0;left:0;width:' + bgWidth + ';height:' + bgHeight + ';z-index:' + (PhotoUserCount * 31 + 17) + ';display:none;"';
		ResultStr = ResultStr + ' id="photo_fg">';
	}
	for(i = 1; i <= PhotoUserCount; i ++)
		ResultStr = ResultStr + GetTextDiv(
			document.getElementById("UserName_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value,
			"UserNameBorder_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix),
			PhotoUserCount * 30 + 10 + i - 1, 
			parseInt(document.getElementById("UserNameLeft_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			parseInt(document.getElementById("UserNameTop_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value),
			document.getElementById("UserNameFont_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value,
			document.getElementById("UserNameSize_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value,
			document.getElementById("UserNameBold_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value,
			document.getElementById("UserNameItalic_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value,
			document.getElementById("UserNameColor_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value,
			document.getElementById("UserNameDirection_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value,
			document.getElementById("UserNameWidth_" + i + (VarPrefix == "" ? "" : "_" + VarPrefix)).value);
	ResultStr = ResultStr + GetTextDiv(PhotoName, "PhotoNameBorder", (PhotoUserCount * 31 + 18), PhotoNameLeft, PhotoNameTop, PhotoNameFont, PhotoNameSize, PhotoNameBold, PhotoNameItalic, PhotoNameColor, PhotoNameDirection, PhotoNameWidth);
	ResultStr = ResultStr + GetTextDiv(PhotoDate, "PhotoDateBorder", (PhotoUserCount * 31 + 19), PhotoDateLeft, PhotoDateTop, PhotoDateFont, PhotoDateSize, PhotoDateBold, PhotoDateItalic, PhotoDateColor, PhotoDateDirection, PhotoDateWidth);
	ResultStr = ResultStr + '</DIV>';
	if(isShowBorder == '1') {
		if(parseInt(bgWidth) == parseInt(SmallPhotoWidth))
			ResultStr = ResultStr + '<img src="Dv_Plus/Avatar/Pic/PhotoBorder_s.gif" style="padding:0;position:absolute;top:0;left:0;width:' + PhotoWidth + ';height:' + PhotoHeight + ';z-index:' + (PhotoUserCount * 31 + 21) + ';display:inline;">';
		else
			ResultStr = ResultStr + '<img src="Dv_Plus/Avatar/Pic/PhotoBorder.gif" style="padding:0;position:absolute;top:0;left:0;width:' + PhotoWidth + ';height:' + PhotoHeight + ';z-index:' + (PhotoUserCount * 31 + 21) + ';display:inline;">';
	}
	ResultStr = ResultStr + '</DIV>';
	if(ObjTD)
		ObjTD.innerHTML = ResultStr;
	else
		document.write(ResultStr);
}

function GetItemPicURL(LocalPic, PicPath, ItemID, DefaultLayerNo) {
	var ItemSplit, LayerSplit;
	
	ItemSplit = ItemID.split('.');
	LayerSplit = (ItemSplit.length > 1 ? ItemSplit[1].split('_') : DefaultLayerNo.split('_'));
	return PicPath + GetPicURL(LocalPic,LayerSplit[0],ItemSplit[0]);
}

function GetAccoutermentDiv(LocalPic, PicPath, SeqNo, ItemID, ZIndex, OuterLeft, OuterTop, OuterWidth, OuterHeight, InnerLeft, InnerTop, InnerWidth, InnerHeight, Direction) {
	var Result, CurRotate, CurFlip;
	
	CurRotate = Direction % 4;
	CurFlip = Math.floor(Direction / 4);
	Result = '<DIV id="AccoutermentBorder_' + SeqNo + '" style="overflow:hidden;z-index:' + ZIndex + ';left:' + OuterLeft + ';width:' + OuterWidth + ';position:absolute;top:' + OuterTop + ';height:' + OuterHeight + ';';
	if(ItemID != '')
		Result = Result + 'display:inline;';
	else
		Result = Result + 'display:none;';
	Result = Result + 'filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=' + CurRotate + ',mirror=0)';
	if(CurFlip == 1 || CurFlip == 3)
		Result = Result + ' fliph(enabled=true)';
	else	
		Result = Result + ' fliph(enabled=false)';
	if(CurFlip == 2 || CurFlip == 3)
		Result = Result + ' flipv(enabled=true)';
	else	
		Result = Result + ' flipv(enabled=false)';
	Result = Result + '">';
	Result = Result + '<IMG src="';
	if(ItemID != '')
		Result = Result + GetItemPicURL(LocalPic, PicPath, ItemID, '23')
	else
		Result = Result + 'about:blank';
	Result = Result + '" style="padding:0;z-index:' + (ZIndex + 1) + ';left:' + InnerLeft + ';width:' + InnerWidth + ';position:absolute;top:' + InnerTop + ';height:' + InnerHeight + ';';
	Result = Result + '"></DIV>';
	return Result;
}

function GetAvatarDiv(LocalPic, PicPath, SeqNo, UserAvatar, ZIndex, OuterLeft, OuterTop, OuterWidth, OuterHeight, InnerLeft, InnerTop, InnerWidth, InnerHeight, Direction, isPhotoMe) {
	var AvatarSplit, TempSplit, i, j;
	var Result, CurRotate, CurFlip;
	
	CurRotate = Direction % 4;
	CurFlip = Math.floor(Direction / 4);
	AvatarSplit = UserAvatar.split('|');
	if(AvatarSplit.length != 25) return '';
	Result = '<DIV id="AvatarBorder_' + SeqNo + '" style="overflow:hidden;z-index:' + ZIndex + ';left:' + OuterLeft + ';width:' + OuterWidth + ';position:absolute;top:' + OuterTop + ';height:' + OuterHeight + ';filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=' + CurRotate + ',mirror=0)';
	if(CurFlip == 1 || CurFlip == 3)
		Result = Result + ' fliph(enabled=true)';
	else	
		Result = Result + ' fliph(enabled=false)';
	if(CurFlip == 2 || CurFlip == 3)
		Result = Result + ' flipv(enabled=true)';
	else	
		Result = Result + ' flipv(enabled=false)';
	Result = Result + '"><DIV id="AvatarCont_' + SeqNo + '" style="z-index:' + (ZIndex + 1) + ';left:' + InnerLeft + ';width:' + InnerWidth + ';position:absolute;top:' + InnerTop + ';height:' + InnerHeight + ';">';
	j = 0;
	for(i = 0; i < AvatarSplit.length; i ++)
		if((i >= 4 && i <= 20) || (isPhotoMe && i >= 2 && i <= 23))
			if(AvatarSplit[i] != '') {
				TempSplit = AvatarSplit[i].split('.');
				Result = Result + '<img src="' + PicPath + GetPicURL(LocalPic, i + 1, TempSplit[0]) + '" style="padding:0;position:absolute;top:0;left:0;width:' + InnerWidth + ';height:' + InnerHeight + ';z-index:' + (ZIndex + j + 2) + ';" id="photo_' + SeqNo + '">';
				j = j + 1
			}
	Result = Result + '<img src="Dv_Plus/Avatar/Pic/blank.gif" style="padding:0;position:absolute;top:0;left:0;width:' + InnerWidth + ';height:' + InnerHeight + ';z-index:' + (ZIndex + j + 2) + ';" id="photo_' + SeqNo + '">';
	Result = Result + '</DIV></DIV>';
	return Result;
}

function GetTextDiv(strText, DivID, ZIndex, TextLeft, TextTop, TextFont, TextSize, TextBold, TextItalic, TextColor, TextDirection, TextWidth) {
	var Result, CurRotate, CurFlip;
	
	CurRotate = TextDirection % 4;
	CurFlip = Math.floor(TextDirection / 4);
	Result = '<DIV id="' + DivID + '" style="position:absolute;overflow:hidden;z-index:' + ZIndex + ';left:' + (parseInt(TextLeft) - 3) + ';top:' + (parseInt(TextTop) - 3) + ';width:' + (parseInt(TextWidth) + 6) + ';height:' + (parseInt(TextSize) + 6) + ';padding-top:3px;padding-left:3px;padding-bottom:3px;padding-right:3px;text-align:left;word-break:keep-all;line-height:' + TextSize + 'px;'
	if(TextBold == '1')
		Result = Result + 'font-weight:bolder;';
	else
		Result = Result + 'font-weight:normal;';
	if(TextItalic == '1')
		Result = Result + 'font-style:italic;';
	else
		Result = Result + 'font-style:normal;';
	Result = Result + 'font-family:' + TextFont + ';';
	if(TextColor == '')
		Result = Result + 'display:none;color:#ffffff;';
	else
		Result = Result + 'display:inline;color:' + TextColor + ';';
	Result = Result + 'font-size:' + TextSize + 'px;filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=' + CurRotate + ',mirror=0)';
	if(CurFlip == 1 || CurFlip == 3)
		Result = Result + ' fliph(enabled=true)';
	else	
		Result = Result + ' fliph(enabled=false)';
	if(CurFlip == 2 || CurFlip == 3)
		Result = Result + ' flipv(enabled=true)';
	else	
		Result = Result + ' flipv(enabled=false)';
	Result = Result + ' progid:DXImageTransform.Microsoft.dropShadow(Color=black,offX=1,offY=1,positive=true);cursor:default" unselectable="on">' + strText + '</div>';
	return Result;
}

function selBg(LocalPic, PicPath, PhotoPath, selValue, NormalPhotoWidth, SmallPhotoWidth, MyAvatar) {
	if(selValue != '') {
		if(selValue != '0') {
			document.getElementById("ThePhotoBorder").style.pixelWidth = parseInt(NormalPhotoWidth) + 2;
			document.getElementById("ThePhoto").style.pixelWidth = NormalPhotoWidth;
			document.getElementById("photo_bg").style.pixelWidth = NormalPhotoWidth;
			document.getElementById("BgWidth").value = NormalPhotoWidth;
			document.getElementById("PhotoBodyBack").disabled = false;
			document.getElementById("PhotoBodyFore").disabled = false;
			document.getElementById("PhotoFg").disabled = false;
			document.getElementById("AvatarBorder_1").style.pixelLeft = Math.floor((NormalPhotoWidth - SmallPhotoWidth) / 2);
			document.getElementById("UserNameBorder_1").style.pixelLeft = document.getElementById("AvatarBorder_1").style.pixelLeft + Math.floor(SmallPhotoWidth / 4);
			if(selValue == '-1' && document.getElementById("bgfname").value == '') {
				document.getElementById("photo_bg").src = 'about:blank';
				document.getElementById("photo_bg").style.display = 'none';
			} else {
				if(selValue != '-1')
					document.getElementById("photo_bg").src = GetItemPicURL(LocalPic, PicPath, selValue, '1')
				else
					document.getElementById("photo_bg").src = PhotoPath + document.getElementById("bgfname").value;
				document.getElementById("photo_bg").style.display = 'inline';
			}
		} else {
			document.getElementById("ThePhotoBorder").style.pixelWidth = parseInt(SmallPhotoWidth) + 2;
			document.getElementById("ThePhoto").style.pixelWidth = SmallPhotoWidth;
			document.getElementById("photo_bg").style.pixelWidth = SmallPhotoWidth;
			if(document.getElementById("PhotoBodyBack").selectedIndex != 0) {
				document.getElementById("PhotoBodyBack").selectedIndex = 0;
				document.getElementById("PhotoBodyBack").fireEvent('onchange');
			}
			document.getElementById("PhotoBodyBack").disabled = true;
			if(document.getElementById("PhotoBodyFore").selectedIndex != 0) {
				document.getElementById("PhotoBodyFore").selectedIndex = 0;
				document.getElementById("PhotoBodyFore").fireEvent('onchange');
			}
			document.getElementById("PhotoBodyFore").disabled = true;
			if(document.getElementById("PhotoFg").selectedIndex != 0) {
				document.getElementById("PhotoFg").selectedIndex = 0;
				document.getElementById("PhotoFg").fireEvent('onchange');
			}
			document.getElementById("PhotoFg").disabled = true;
			document.getElementById("BgWidth").value = SmallPhotoWidth;
			document.getElementById("AvatarBorder_1").style.pixelLeft = 0;
			document.getElementById("UserNameBorder_1").style.pixelLeft = Math.floor(SmallPhotoWidth / 4);
			
			var MyBg = GetBackground(MyAvatar);
			if(MyBg != '') {
				document.getElementById("photo_bg").src = GetItemPicURL(LocalPic, PicPath, MyBg, '1');
				document.getElementById("photo_bg").style.display = 'inline';
			} else {
				document.getElementById("photo_bg").src = 'about:blank';
				document.getElementById("photo_bg").style.display = 'none';
			}
		}
	} else {
		document.getElementById("ThePhotoBorder").style.pixelWidth = parseInt(NormalPhotoWidth) + 2;
		document.getElementById("ThePhoto").style.pixelWidth = NormalPhotoWidth;
		document.getElementById("photo_bg").style.pixelWidth = NormalPhotoWidth;
		document.getElementById("BgWidth").value = NormalPhotoWidth;
		document.getElementById("PhotoBodyBack").disabled = false;
		document.getElementById("PhotoBodyFore").disabled = false;
		document.getElementById("PhotoFg").disabled = false;
		document.getElementById("ThePhoto").children[5].style.pixelLeft = Math.floor((NormalPhotoWidth - SmallPhotoWidth) / 2);
		document.getElementById("ThePhoto").children[6].style.pixelLeft = document.getElementById("AvatarBorder_1").style.pixelLeft + Math.floor(SmallPhotoWidth / 4);
		document.getElementById("photo_bg").src = 'about:blank';
		document.getElementById("photo_bg").style.display = 'none';
	}
}

function selBodyBack(LocalPic, PicPath, selValue) {
	if(selValue != '') {
		document.getElementById("photo_bodyback").src = GetItemPicURL(LocalPic, PicPath, selValue, '2');
		document.getElementById("photo_bodyback").style.display = 'inline';
	} else {
		document.getElementById("photo_bodyback").src = 'about:blank';
		document.getElementById("photo_bodyback").style.display = 'none';
	}
}

function selBodyFore(LocalPic, PicPath, selValue) {
	if(selValue != '') {
		document.getElementById("photo_bodyfore").src = GetItemPicURL(LocalPic, PicPath, selValue, '24');
		document.getElementById("photo_bodyfore").style.display = 'inline';
	} else {
		document.getElementById("photo_bodyfore").src = 'about:blank';
		document.getElementById("photo_bodyfore").style.display = 'none';
	}
}

function selFg(LocalPic, PicPath, selValue) {
	if(selValue != '') {
		document.getElementById("photo_fg").src = GetItemPicURL(LocalPic, PicPath, selValue, '25');
		document.getElementById("photo_fg").style.display = 'inline';
	} else {
		document.getElementById("photo_fg").src = 'about:blank';
		document.getElementById("photo_fg").style.display = 'none';
	}
}

function KeyTitle(Title) {
	document.getElementById("PhotoNameBorder").innerText = Title;
}

function CheckRequest() {
	if(document.getElementById("PhotoName").value == '') {
		alert("照片名称不能为空！")
		return false;
	}
	if(!document.getElementById("PhotoMyself").checked && document.getElementById("PhotoMsg").value == '') {
		alert("请求内容不能为空！")
		return false;
	}
	if(!document.getElementById("PhotoMyself").checked && document.getElementById("PhotoUser").value == '') {
		alert("必须指定参与者！")
		return false;
	}
	return true;
}

function GetBackground(UserAvatar) {
	var AvatarSplit;
	
	if(UserAvatar == '') return '';
	AvatarSplit = UserAvatar.split('|');
	if(AvatarSplit.length != 25) return '';
	if(AvatarSplit[1] != '')
		return AvatarSplit[1].split('.') + '.2';
	else
		return '';
}

function SetUploadBg(FileName, MyMoney) {
	document.getElementById("bgfname").value = FileName;
	if(document.getElementById("PhotoBg").selectedIndex != 2) {
		document.getElementById("PhotoBg").selectedIndex = 2;
		document.getElementById("PhotoBg").fireEvent('onchange');
	}
	document.getElementById("MyMoneySpan").innerHTML = '<b>' + MyMoney + '</b>';
}

function ToggleButton(UserID,UserSex,No) {
	if(No == 1) {
		document.getElementById("AvatarButton1").disabled = true;
		document.getElementById("AvatarButton2").disabled = false;
		RecFlag = 1;
	} else {
		document.getElementById("AvatarButton1").disabled = false;
		document.getElementById("AvatarButton2").disabled = true;
		RecFlag = 0;
	}
	setCookie("RecFlag_" + UserID, RecFlag);
	if(UserID == '0')
		document.getElementById("AvatarShow").InitDressList(getCookie("MyAvatarRec_" + UserSex + "_" + UserID));
	else
		document.getElementById("AvatarShow").InitDressList(getCookie("MyAvatarRec_" + UserID));
}

function SaveRec(UserID,UserSex,LayerNo,itemNo) {
	if (itemNo < 15) return;

	if(UserID == '0')
		var recShow = getCookie("MyAvatarRec_" + UserSex + "_" + UserID);
	else
		var recShow = getCookie("MyAvatarRec_" + UserID);

	if(recShow.length == 0)
		var recShow = itemNo+'.'+LayerNo;
	else {
		var recArr = recShow.split('|');
		var OldLayer = "";
		for(var i=0;i<recArr.length;i++) {
			if((new Number(getItemNo(recArr[i])) - new Number(itemNo)) == 0) {
				if(OldLayer != "") OldLayer = OldLayer + "_";
				OldLayer = OldLayer + getLayerNo(recArr[i]);
				for(var j=i;j+1<recArr.length;j++) {
					recArr[j]=recArr[j+1];
				}
				recArr.length=recArr.length-1;
			}
		}
		if(OldLayer == "")
			var tmpStr = itemNo + '.' + LayerNo;
		else {
			if(("_" + OldLayer + "_").indexOf("_" + LayerNo + "_") < 0) OldLayer = OldLayer + "_" + LayerNo;
			var tmpStr = itemNo + "." + OldLayer;
		}
		recArr = new Array(tmpStr).concat(recArr);
		recShow = recArr.join('|');
	}
	if(UserID == '0')
		setCookie("MyAvatarRec_" + UserSex + "_" + UserID,recShow);
	else
		setCookie("MyAvatarRec_" + UserID,recShow);
}

function getItemNo(itemsn) {
	var tmpArr = itemsn.split('.');
	
	return tmpArr[0];
}

function getLayerNo(itemsn) {
	var tmpArr = itemsn.split('.');
	
	return tmpArr[1];
}

function SaveAvatar(MySex, CurSex) {
	if(MySex != CurSex) {
		if(confirm('对不起，性别不符，无法保存！是否切换回同性别？'))
			document.location="Plus_Avatar_Center.asp?mysex=" + MySex + "&shopid=" + CurShopID;
		return false;
	} else
		return true;
}

function SelectToolbarItem(event) {
	var srcElement = (event.srcElement ? event.srcElement : event.target);
	if(srcElement) {
		srcElement.filters(0).enabled = false;
		srcElement.parentElement.className='ToolbarDown';
	}
}

function UnSelectToolbarItem(event) {
	var srcElement = (event.srcElement ? event.srcElement : event.target);
	if(srcElement) {
		srcElement.filters(0).enabled = true;
		srcElement.parentElement.className='ToolbarUp';
	}
}

function ChangeFontColor() {
	var arr = showModalDialog("images/post/selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0; help:0");
	if(arr != null) {
		if(document.getElementById("FontColor").value.toLowerCase() != arr.toLowerCase()) {
			document.getElementById("FontColor").value = arr.toLowerCase();
			SetFontColor();
		}
		return true;
	}
}

function selFontName(selValue) {
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	
	if(CurObj != "") {
		CurObjType = CurObj.split("_")[0];
		CurObjID = CurObj.split("_")[1];
		if(CurObjType == "PhotoName") {
			document.getElementById("PhotoNameFont").value = selValue;
			document.getElementById("PhotoNameBorder").style.fontFamily = selValue;
		} else if(CurObjType == "PhotoDate") {
			document.getElementById("PhotoDateFont").value = selValue;
			document.getElementById("PhotoDateBorder").style.fontFamily = selValue;
		} else if(CurObjType == "UserName") {
			document.getElementById("UserNameFont_" + CurObjID).value = selValue;
			document.getElementById("UserNameBorder_" + CurObjID).style.fontFamily = selValue;
		}
		return true;
	}
}

function selFontStyle(selValue) {
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	
	if(CurObj != "") {
		CurObjType = CurObj.split("_")[0];
		CurObjID = CurObj.split("_")[1];
		if(CurObjType == "PhotoName") {
			if(selValue == 1 || selValue == 3) {
				document.getElementById("PhotoNameBold").value = 1;
				document.getElementById("PhotoNameBorder").style.fontWeight = "bolder";
			} else {
				document.getElementById("PhotoNameBold").value = 0;
				document.getElementById("PhotoNameBorder").style.fontWeight = "normal";
			}
			if(selValue == 2 || selValue == 3) {
				document.getElementById("PhotoNameItalic").value = 1;
				document.getElementById("PhotoNameBorder").style.fontStyle = "italic";
			} else {
				document.getElementById("PhotoNameItalic").value = 0;
				document.getElementById("PhotoNameBorder").style.fontStyle = "normal";
			}
		} else if(CurObjType == "PhotoDate") {
			if(selValue == 1 || selValue == 3) {
				document.getElementById("PhotoDateBold").value = 1;
				document.getElementById("PhotoDateBorder").style.fontWeight = "bolder";
			} else {
				document.getElementById("PhotoDateBold").value = 0;
				document.getElementById("PhotoDateBorder").style.fontWeight = "normal";
			}
			if(selValue == 2 || selValue == 3) {
				document.getElementById("PhotoDateItalic").value = 1;
				document.getElementById("PhotoDateBorder").style.fontStyle = "italic";
			} else {
				document.getElementById("PhotoDateItalic").value = 0;
				document.getElementById("PhotoDateBorder").style.fontStyle = "normal";
			}
		} else if(CurObjType == "UserName") {
			if(selValue == 1 || selValue == 3) {
				document.getElementById("UserNameBold_" + CurObjID).value = 1;
				document.getElementById("UserNameBorder_" + CurObjID).style.fontWeight = "bolder";
			} else {
				document.getElementById("UserNameBold_" + CurObjID).value = 0;
				document.getElementById("UserNameBorder_" + CurObjID).style.fontWeight = "normal";
			}
			if(selValue == 2 || selValue == 3) {
				document.getElementById("UserNameItalic_" + CurObjID).value = 1;
				document.getElementById("UserNameBorder_" + CurObjID).style.fontStyle = "italic";
			} else {
				document.getElementById("UserNameItalic_" + CurObjID).value = 0;
				document.getElementById("UserNameBorder_" + CurObjID).style.fontStyle = "normal";
			}
		}
		return true;
	}
}

function selFontSize(selValue) {
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID, OldFontSize, NewFontSize;
	
	if(CurObj != "") {
		CurObjType = CurObj.split("_")[0];
		CurObjID = CurObj.split("_")[1];
		NewFontSize = parseInt(selValue);
		if(CurObjType == "PhotoName") {
			OldFontSize = parseInt(document.getElementById("PhotoNameBorder").style.fontSize.replace(/px/gi,""));
			document.getElementById("PhotoNameSize").value = NewFontSize;
			document.getElementById("PhotoNameBorder").style.fontSize = NewFontSize + "px";
			document.getElementById("PhotoNameBorder").style.lineHeight = NewFontSize + "px";
			document.getElementById("PhotoNameBorder").style.height = (NewFontSize + 6) + "px";
			document.getElementById("PhotoNameBorder").style.width = (Math.floor((document.getElementById("PhotoNameBorder").style.pixelWidth - 6) / OldFontSize * NewFontSize) + 6) + "px";
		} else if(CurObjType == "PhotoDate") {
			OldFontSize = parseInt(document.getElementById("PhotoDateBorder").style.fontSize.replace(/px/gi,""));
			document.getElementById("PhotoDateSize").value = selValue;
			document.getElementById("PhotoDateBorder").style.fontSize = NewFontSize + "px";
			document.getElementById("PhotoDateBorder").style.lineHeight = NewFontSize + "px";
			document.getElementById("PhotoDateBorder").style.height = (NewFontSize + 6) + "px";
			document.getElementById("PhotoDateBorder").style.width = (Math.floor((document.getElementById("PhotoDateBorder").style.pixelWidth - 6) / OldFontSize * NewFontSize) + 6) + "px";
		} else if(CurObjType == "UserName") {
			OldFontSize = parseInt(document.getElementById("UserNameBorder_" + CurObjID).style.fontSize.replace(/px/gi,""));
			document.getElementById("UserNameSize_" + CurObjID).value = NewFontSize;
			document.getElementById("UserNameBorder_" + CurObjID).style.fontSize = NewFontSize + "px";
			document.getElementById("UserNameBorder_" + CurObjID).style.lineHeight = NewFontSize + "px";
			document.getElementById("UserNameBorder_" + CurObjID).style.height = (NewFontSize + 6) + "px";
			document.getElementById("UserNameBorder_" + CurObjID).style.width = (Math.floor((document.getElementById("UserNameBorder_" + CurObjID).style.pixelWidth - 6) / OldFontSize * NewFontSize) + 6) + "px";
		}
	}
	return true;
}

function chkFontHidden(selValue) {
	if(selValue) {
		document.getElementById("FontColor").value = "";
		document.getElementById("FontColor").disabled = true;
		document.getElementById("FontColorButton").disabled = true;
	} else {
		document.getElementById("FontColor").value = "#ffffff";
		document.getElementById("FontColor").disabled = false;
		document.getElementById("FontColorButton").disabled = false;
	}
	SetFontHidden();
	return true;
}

function selAccouterment(LocalPic, PicPath, selValue, PhotoUserCount) {
	var CurID = document.getElementById("CurrentObject").selectedIndex;
	
	if(CurID < PhotoUserCount * 2 + 3 || CurID > PhotoUserCount * 2 + 8) return false;
	CurID = CurID - PhotoUserCount * 2 - 2;
	if(selValue != "") {
		document.getElementById("AccoutermentBorder_" + CurID).children[0].src = GetItemPicURL(LocalPic, PicPath, selValue, '23');
		document.getElementById("AccoutermentBorder_" + CurID).style.display = "inline";
		document.getElementById("AccoutermentItemID_" + CurID).value = selValue;
		EnableOperationToolbar("Accouterment",true, document.getElementById("AccoutermentDirection_" + CurID).value, CurID);
		EnableAccoutermentToolbar(document.getElementById("AccoutermentItemID_" + CurID).value);
		EnableSelectObject(document.getElementById("AccoutermentBorder_" + CurID));
	} else {
		document.getElementById("AccoutermentBorder_" + CurID).children[0].src = "about:blank";
		document.getElementById("AccoutermentBorder_" + CurID).style.display = "none";
		document.getElementById("AccoutermentItemID_" + CurID).value = "";
		DisableOperationToolbar();
		DisableSelectObject();
	}
	return true;
}

function SetFontColor() {
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	
	if(CurObj != "") {
		CurObjType = CurObj.split("_")[0];
		CurObjID = CurObj.split("_")[1];
		if(CurObjType == "PhotoName") {
			document.getElementById("PhotoNameColor").value = document.getElementById("FontColor").value;
			document.getElementById("PhotoNameBorder").style.color = document.getElementById("FontColor").value;
		} else if(CurObjType == "PhotoDate") {
			document.getElementById("PhotoDateColor").value = document.getElementById("FontColor").value;
			document.getElementById("PhotoDateBorder").style.color = document.getElementById("FontColor").value;
		} else if(CurObjType == "UserName") {
			document.getElementById("UserNameColor_" + CurObjID).value = document.getElementById("FontColor").value;
			document.getElementById("UserNameBorder_" + CurObjID).style.color = document.getElementById("FontColor").value;
		}
	}
}

function SetFontHidden() {
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	
	if(CurObj != "") {
		CurObjType = CurObj.split("_")[0];
		CurObjID = CurObj.split("_")[1];
		if(CurObjType == "PhotoName") {
			if(document.getElementById("FontHidden").checked) {
				document.getElementById("PhotoNameColor").value = "";
				document.getElementById("PhotoNameBorder").style.display = "none";
				DisableOperationToolbar();
				DisableTextToolbar();
				DisableSelectObject(document.getElementById("PhotoNameBorder"));
			} else {
				document.getElementById("PhotoNameColor").value = document.getElementById("FontColor").value;
				document.getElementById("PhotoNameBorder").style.color = document.getElementById("FontColor").value;
				document.getElementById("PhotoNameBorder").style.display = "inline";
				EnableOperationToolbar(CurObjType, true, document.getElementById("PhotoNameDirection").value, CurObjID);
				EnableTextToolbar(true, document.getElementById("PhotoNameFont").value, parseInt(document.getElementById("PhotoNameBold").value) * 2 + parseInt(document.getElementById("PhotoNameItalic").value), document.getElementById("PhotoNameSize").value, document.getElementById("PhotoNameColor").value);
				EnableSelectObject(document.getElementById("PhotoNameBorder"));
			}
		} else if(CurObjType == "PhotoDate") {
			if(document.getElementById("FontHidden").checked) {
				document.getElementById("PhotoDateColor").value = "";
				document.getElementById("PhotoDateBorder").style.display = "none";
				DisableOperationToolbar();
				DisableTextToolbar();
				DisableSelectObject(document.getElementById("PhotoDateBorder"));
			} else {
				document.getElementById("PhotoDateColor").value = document.getElementById("FontColor").value;
				document.getElementById("PhotoDateBorder").style.color = document.getElementById("FontColor").value;
				document.getElementById("PhotoDateBorder").style.display = "inline";
				EnableOperationToolbar(CurObjType, true, document.getElementById("PhotoDateDirection").value, CurObjID);
				EnableTextToolbar(true, document.getElementById("PhotoDateFont").value, parseInt(document.getElementById("PhotoDateBold").value) * 2 + parseInt(document.getElementById("PhotoDateItalic").value), document.getElementById("PhotoDateSize").value, document.getElementById("PhotoDateColor").value);
				EnableSelectObject(document.getElementById("PhotoDateBorder"));
			}
		} else if(CurObjType == "UserName") {
			if(document.getElementById("FontHidden").checked) {
				document.getElementById("UserNameColor_" + CurObjID).value = "";
				document.getElementById("UserNameBorder_" + CurObjID).style.display = "none";
				DisableOperationToolbar();
				DisableTextToolbar();
				DisableSelectObject(document.getElementById("UserNameBorder_" + CurObjID));
			} else {
				document.getElementById("UserNameColor_" + CurObjID).value = document.getElementById("FontColor").value;
				document.getElementById("UserNameBorder_" + CurObjID).style.color = document.getElementById("FontColor").value;
				document.getElementById("UserNameBorder_" + CurObjID).style.display = "inline";
				EnableOperationToolbar(CurObjType, true, document.getElementById("UserNameDirection_" + CurObjID).value, CurObjID);
				EnableTextToolbar(true, document.getElementById("UserNameFont_" + CurObjID).value, parseInt(document.getElementById("UserNameBold_" + CurObjID).value) * 2 + parseInt(document.getElementById("UserNameItalic_" + CurObjID).value), document.getElementById("UserNameSize_" + CurObjID).value, document.getElementById("UserNameColor_" + CurObjID).value);
				EnableSelectObject(document.getElementById("UserNameBorder_" + CurObjID));
			}
		}
	}
}

function InitSelectionValue(SelectObj, CurValue) {
	SelectObj.selectedIndex = -1;
	for(var i = 0; i < SelectObj.options.length; i ++) {
		if(SelectObj.options[i].value == CurValue) {
			SelectObj.selectedIndex = i;
			break;
		}
	}
}

function selObject(selValue) {
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	var CurRotate, CurFlip;
	var i, OldMode = 0;
	
	if(document.getElementById("B01").className == "ToolbarDown")
		OldMode = 1;
	else if(document.getElementById("B02").className == "ToolbarDown")
		OldMode = 2;
	else if(document.getElementById("B03").className == "ToolbarDown")
		OldMode = 3;
	DisableOperationToolbar();
	DisableTextToolbar();
	DisableAccoutermentToolbar();
	DisableSelectObject();
	if(CurObj != "") {
		CurObjType = CurObj.split("_")[0];
		CurObjID = CurObj.split("_")[1];
		if(CurObjType == "Avatar") {
			EnableOperationToolbar(CurObjType, true, document.getElementById("AvatarDirection_" + CurObjID).value, CurObjID);
			EnableSelectObject(document.getElementById("AvatarBorder_" + CurObjID));
			if(OldMode == 2)
				document.getElementById("B02").fireEvent("onclick");
			else if(OldMode == 3)
				document.getElementById("B03").fireEvent("onclick");
		} else if(CurObjType == "PhotoName") {
			EnableOperationToolbar(CurObjType, document.getElementById("PhotoNameBorder").style.display != "none", document.getElementById("PhotoNameDirection").value, CurObjID);
			EnableTextToolbar(document.getElementById("PhotoNameBorder").style.display != "none", document.getElementById("PhotoNameFont").value, parseInt(document.getElementById("PhotoNameBold").value) * 2 + parseInt(document.getElementById("PhotoNameItalic").value), document.getElementById("PhotoNameSize").value, document.getElementById("PhotoNameColor").value);
			EnableSelectObject(document.getElementById("PhotoNameBorder"));
		} else if(CurObjType == "PhotoDate") {
			EnableOperationToolbar(CurObjType, document.getElementById("PhotoDateBorder").style.display != "none", document.getElementById("PhotoDateDirection").value, CurObjID);
			EnableTextToolbar(document.getElementById("PhotoDateBorder").style.display != "none", document.getElementById("PhotoDateFont").value, parseInt(document.getElementById("PhotoDateBold").value) * 2 + parseInt(document.getElementById("PhotoDateItalic").value), document.getElementById("PhotoDateSize").value, document.getElementById("PhotoDateColor").value);
			EnableSelectObject(document.getElementById("PhotoDateBorder"));
		} else if(CurObjType == "UserName") {
			EnableOperationToolbar(CurObjType, document.getElementById("UserNameBorder_" + CurObjID).style.display != "none", document.getElementById("UserNameDirection_" + CurObjID).value, CurObjID);
			EnableTextToolbar(document.getElementById("UserNameBorder_" + CurObjID).style.display != "none", document.getElementById("UserNameFont_" + CurObjID).value, parseInt(document.getElementById("UserNameBold_" + CurObjID).value) * 2 + parseInt(document.getElementById("UserNameItalic_" + CurObjID).value), document.getElementById("UserNameSize_" + CurObjID).value, document.getElementById("UserNameColor_" + CurObjID).value);
			EnableSelectObject(document.getElementById("UserNameBorder_" + CurObjID));
		} else if(CurObjType == "Accouterment") {
			EnableOperationToolbar(CurObjType, document.getElementById("AccoutermentItemID_" + CurObjID).value != "", document.getElementById("AccoutermentDirection_" + CurObjID).value, CurObjID);
			EnableAccoutermentToolbar(document.getElementById("AccoutermentItemID_" + CurObjID).value);
			EnableSelectObject(document.getElementById("AccoutermentBorder_" + CurObjID));
			if(OldMode == 2)
				document.getElementById("B02").fireEvent("onclick");
			else if(OldMode == 3)
				document.getElementById("B03").fireEvent("onclick");
		}
		return true;
	}
}

function SelRotate() {
	var CurButton;
	var CurObj = document.getElementById("CurrentObject").value;
	
	if(CurObj == "") return false;
	if(document.getElementById("B04").className == "ToolbarDown")
		CurButton = document.getElementById("B05");
	else if(document.getElementById("B05").className == "ToolbarDown")
		CurButton = document.getElementById("B06");
	else if(document.getElementById("B06").className == "ToolbarDown")
		CurButton = document.getElementById("B07");
	else if(document.getElementById("B07").className == "ToolbarDown")
		CurButton = document.getElementById("B04");
	CurButton.fireEvent("onclick")
	return true;
}

function SetOperationMode() {
	var CurButton;
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	var objElement;
	
	if(CurObj == "") return false;
	CurObjType = CurObj.split("_")[0];
	CurObjID = CurObj.split("_")[1];
	if(event.srcElement.tagName == "IMG")
		CurButton = event.srcElement.parentElement;
	else
		CurButton = event.srcElement;
	if(CurButton.className == "ToolbarDown") return false;
	isDragging = false;
	isCropping = false;
	isCroppable = false;
	isResizing = false;
	isResizable = false;
	objElement = GetElementByType(CurObjType, CurObjID);
	for(var i = 1; i < 4; i ++) {
		if(i == parseInt(CurButton.id.substr(2, 1))) {
			SetButtonDown("B0" + i);
			if(i == 3) {
				CroppedWidthRate = objElement.children[0].style.pixelWidth / objElement.style.pixelWidth;
				CroppedHeightRate = objElement.children[0].style.pixelHeight / objElement.style.pixelHeight;
				CroppedLeftRate = - objElement.children[0].style.pixelLeft / objElement.children[0].style.pixelWidth;
				CroppedTopRate = - objElement.children[0].style.pixelTop / objElement.children[0].style.pixelHeight;
			}
		} else
			SetButtonUp("B0" + i);
	}
	EnableSelectObject(objElement);
}

function SetRotate() {
	var CurButton;
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	var CurRotation;
	var CurFlip;
	var CurDirection;
	
	if(CurObj == "") return false;
	CurObjType = CurObj.split("_")[0];
	CurObjID = CurObj.split("_")[1];
	if(event.srcElement.tagName == "IMG")
		CurButton = event.srcElement.parentElement;
	else
		CurButton = event.srcElement;
	if(CurButton.className == "ToolbarDown") return false;
	for(var i = 4; i < 8; i ++) {
		if(i == parseInt(CurButton.id.substr(2, 1)))
			SetButtonDown("B0" + i);
		else
			SetButtonUp("B0" + i);
	}
	CurRotation = parseInt(CurButton.id.substr(2, 1)) - 4;
	CurFlip = (document.getElementById("B09").className == "ToolbarDown" ? 1 : 0) * 2 + (document.getElementById("B08").className == "ToolbarDown" ? 1 : 0);
	CurDirection = CurFlip * 4 + CurRotation;
	if(CurObjType == "PhotoName") {
		document.getElementById("PhotoNameDirection").value = CurDirection;
		document.getElementById("PhotoNameBorder").filters(0).rotation = CurRotation;
	} else if(CurObjType == "PhotoDate") {
		document.getElementById("PhotoDateDirection").value = CurDirection;
		document.getElementById("PhotoDateBorder").filters(0).rotation = CurRotation;
	} else if(CurObjType == "UserName") {
		document.getElementById("UserNameDirection_" + CurObjID).value = CurDirection;
		document.getElementById("UserNameBorder_" + CurObjID).filters(0).rotation = CurRotation;
	} else if(CurObjType == "Avatar") {
		document.getElementById("AvatarDirection_" + CurObjID).value = CurDirection;
		document.getElementById("AvatarBorder_" + CurObjID).filters(0).rotation = CurRotation;
	} else if(CurObjType == "Accouterment") {
		document.getElementById("AccoutermentDirection_" + CurObjID).value = CurDirection;
		document.getElementById("AccoutermentBorder_" + CurObjID).filters(0).rotation = CurRotation;
	}
}

function SelFlipH() {
	var CurObj = document.getElementById("CurrentObject").value;
	
	if(CurObj == "") return false;
	document.getElementById("B08").fireEvent("onclick")
	return true;
}

function SelFlipV() {
	var CurObj = document.getElementById("CurrentObject").value;
	
	if(CurObj == "") return false;
	document.getElementById("B09").fireEvent("onclick")
	return true;
}

function SetFlip() {
	var CurButton;
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	var CurRotation;
	var CurFlip;
	var CurDirection;
	
	if(CurObj == "") return false;
	CurObjType = CurObj.split("_")[0];
	CurObjID = CurObj.split("_")[1];
	if(event.srcElement.tagName == "IMG")
		CurButton = event.srcElement.parentElement;
	else
		CurButton = event.srcElement;
	SetButtonReverse(CurButton.id);
	CurRotation = 0;
	for(var i = 4; i < 8; i ++)
		if(document.getElementById("B0" + i).className == "ToolbarDown") {
			CurRotation = i - 4;
			break;
		}
	CurFlip = (document.getElementById("B09").className == "ToolbarDown" ? 1 : 0) * 2 + (document.getElementById("B08").className == "ToolbarDown" ? 1 : 0);
	CurDirection = CurFlip * 4 + CurRotation;
	if(CurObjType == "PhotoName") {
		document.getElementById("PhotoNameDirection").value = CurDirection;
		if(CurFlip == 1 || CurFlip == 3)
			document.getElementById("PhotoNameBorder").filters(1).enabled = true;
		else
			document.getElementById("PhotoNameBorder").filters(1).enabled = false;
		if(CurFlip == 2 || CurFlip == 3)
			document.getElementById("PhotoNameBorder").filters(2).enabled = true;
		else
			document.getElementById("PhotoNameBorder").filters(2).enabled = false;
	} else if(CurObjType == "PhotoDate") {
		document.getElementById("PhotoDateDirection").value = CurDirection;
		if(CurFlip == 1 || CurFlip == 3)
			document.getElementById("PhotoDateBorder").filters(1).enabled = true;
		else
			document.getElementById("PhotoDateBorder").filters(1).enabled = false;
		if(CurFlip == 2 || CurFlip == 3)
			document.getElementById("PhotoDateBorder").filters(2).enabled = true;
		else
			document.getElementById("PhotoDateBorder").filters(2).enabled = false;
	} else if(CurObjType == "UserName") {
		document.getElementById("UserNameDirection_" + CurObjID).value = CurDirection;
		if(CurFlip == 1 || CurFlip == 3)
			document.getElementById("UserNameBorder_" + CurObjID).filters(1).enabled = true;
		else
			document.getElementById("UserNameBorder_" + CurObjID).filters(1).enabled = false;
		if(CurFlip == 2 || CurFlip == 3)
			document.getElementById("UserNameBorder_" + CurObjID).filters(2).enabled = true;
		else
			document.getElementById("UserNameBorder_" + CurObjID).filters(2).enabled = false;
	} else if(CurObjType == "Avatar") {
		document.getElementById("AvatarDirection_" + CurObjID).value = CurDirection;
		if(CurFlip == 1 || CurFlip == 3)
			document.getElementById("AvatarBorder_" + CurObjID).filters(1).enabled = true;
		else
			document.getElementById("AvatarBorder_" + CurObjID).filters(1).enabled = false;
		if(CurFlip == 2 || CurFlip == 3)
			document.getElementById("AvatarBorder_" + CurObjID).filters(2).enabled = true;
		else
			document.getElementById("AvatarBorder_" + CurObjID).filters(2).enabled = false;
	} else if(CurObjType == "Accouterment") {
		document.getElementById("AccoutermentDirection_" + CurObjID).value = CurDirection;
		if(CurFlip == 1 || CurFlip == 3)
			document.getElementById("AccoutermentBorder_" + CurObjID).filters(1).enabled = true;
		else
			document.getElementById("AccoutermentBorder_" + CurObjID).filters(1).enabled = false;
		if(CurFlip == 2 || CurFlip == 3)
			document.getElementById("AccoutermentBorder_" + CurObjID).filters(2).enabled = true;
		else
			document.getElementById("AccoutermentBorder_" + CurObjID).filters(2).enabled = false;
	}
}

function SetAvatarLayer(SeqNo, LayerNo) {
	document.getElementById("AvatarBorder_" + SeqNo).style.zIndex = LayerNo;
	document.getElementById("LayerNo_" + SeqNo).value = LayerNo;
	document.getElementById("AvatarBorder_" + SeqNo).children[0].style.zIndex = LayerNo + 1;
	for(var i = 0; i < document.getElementById("AvatarBorder_" + SeqNo).children[0].children.length; i ++)
		document.getElementById("AvatarBorder_" + SeqNo).children[0].children[i].style.zIndex = LayerNo + 2 + i;
}	

function ForeMost() {
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	var i, j;
	
	if(CurObj == "") return false;
	CurObjType = CurObj.split("_")[0];
	CurObjID = parseInt(CurObj.split("_")[1]);
	if(CurObjType == "Avatar") {
		if(AvatarArray[0] != CurObjID)
			for(i = 1; i < AvatarArray.length; i ++)
				if(AvatarArray[i] == CurObjID) break;
			if(i < AvatarArray.length) {
				var TempSeqNo = AvatarArray[i];
				var TempLayer = document.getElementById("AvatarBorder_" + AvatarArray[0]).style.zIndex;
				for(j = 0; j < i; j ++) {
					SetAvatarLayer(AvatarArray[j], document.getElementById("AvatarBorder_" + AvatarArray[j + 1]).style.zIndex);
				}
				for(j = i; j > 0; j --) {
					AvatarArray[j] = AvatarArray[j - 1];
				}
				AvatarArray[0] = TempSeqNo;
				SetAvatarLayer(AvatarArray[0], TempLayer);
			}
	}
	SetButtonUp();
	InitPositionButton(CurObjID);
}

function ForeMore() {
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	var i;
	
	if(CurObj == "") return false;
	CurObjType = CurObj.split("_")[0];
	CurObjID = parseInt(CurObj.split("_")[1]);
	if(CurObjType == "Avatar") {
		if(AvatarArray[0] != CurObjID)
			for(i = 1; i < AvatarArray.length; i ++)
				if(AvatarArray[i] == CurObjID) break;
			if(i < AvatarArray.length) {
				var TempSeqNo = AvatarArray[i];
				var TempLayer = document.getElementById("AvatarBorder_" + AvatarArray[i - 1]).style.zIndex;
				SetAvatarLayer(AvatarArray[i - 1], document.getElementById("AvatarBorder_" + AvatarArray[i]).style.zIndex);
				SetAvatarLayer(AvatarArray[i], TempLayer);
				AvatarArray[i] = AvatarArray[i - 1];
				AvatarArray[i - 1] = TempSeqNo;
			}
	}
	SetButtonUp();
	InitPositionButton(CurObjID);
}

function BackMore() {
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	var i;
	
	if(CurObj == "") return false;
	CurObjType = CurObj.split("_")[0];
	CurObjID = parseInt(CurObj.split("_")[1]);
	if(CurObjType == "Avatar") {
		if(AvatarArray[AvatarArray.length - 1] != CurObjID)
			for(i = 0; i < AvatarArray.length - 1; i ++)
				if(AvatarArray[i] == CurObjID) break;
			if(i < AvatarArray.length - 1) {
				var TempSeqNo = AvatarArray[i];
				var TempLayer = document.getElementById("AvatarBorder_" + AvatarArray[i + 1]).style.zIndex;
				SetAvatarLayer(AvatarArray[i + 1], document.getElementById("AvatarBorder_" + AvatarArray[i]).style.zIndex);
				SetAvatarLayer(AvatarArray[i], TempLayer);
				AvatarArray[i] = AvatarArray[i + 1];
				AvatarArray[i + 1] = TempSeqNo;
			}
	}
	SetButtonUp();
	InitPositionButton(CurObjID);
}

function BackMost() {
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
	var i, j;
	
	if(CurObj == "") return false;
	CurObjType = CurObj.split("_")[0];
	CurObjID = parseInt(CurObj.split("_")[1]);
	if(CurObjType == "Avatar") {
		if(AvatarArray[AvatarArray.length - 1] != CurObjID)
			for(i = 0; i < AvatarArray.length - 1; i ++)
				if(AvatarArray[i] == CurObjID) break;
			if(i < AvatarArray.length - 1) {
				var TempSeqNo = AvatarArray[i];
				var TempLayer = document.getElementById("AvatarBorder_" + AvatarArray[AvatarArray.length - 1]).style.zIndex;
				for(j = AvatarArray.length - 1; j > i; j --) {
					SetAvatarLayer(AvatarArray[j], document.getElementById("AvatarBorder_" + AvatarArray[j - 1]).style.zIndex);
				}
				for(j = i; j < AvatarArray.length - 1; j ++) {
					AvatarArray[j] = AvatarArray[j + 1];
				}
				AvatarArray[AvatarArray.length - 1] = TempSeqNo;
				SetAvatarLayer(AvatarArray[AvatarArray.length - 1], TempLayer);
			}
	}
	SetButtonUp();
	InitPositionButton(CurObjID);
}

function DisableSelectObject(TheObj) {
	if(!TheObj) {
		for(var i = 0; i < document.getElementById("ThePhoto").children.length; i ++) {
			TheObj = document.getElementById("ThePhoto").children[i];
			if(TheObj.tagName == "DIV") {
				if(TheObj.style.border != "") {
					TheObj.style.border = "";
					if(TheObj.filters(0).rotation == 0) {
						TheObj.style.pixelLeft = TheObj.style.pixelLeft + 2 - (TheObj.filters(1).enabled ? 2 : 0) * 2;
						TheObj.style.pixelTop = TheObj.style.pixelTop + 2 - (TheObj.filters(2).enabled ? 2 : 0) * 2;
					} else if(TheObj.filters(0).rotation == 1) {
						TheObj.style.pixelLeft = TheObj.style.pixelLeft - 2 + (TheObj.filters(1).enabled ? 2 : 0) * 2;
						TheObj.style.pixelTop = TheObj.style.pixelTop + 2 - (TheObj.filters(2).enabled ? 2 : 0) * 2;
					} else if(TheObj.filters(0).rotation == 2) {
						TheObj.style.pixelLeft = TheObj.style.pixelLeft - 2 + (TheObj.filters(1).enabled ? 2 : 0) * 2;
						TheObj.style.pixelTop = TheObj.style.pixelTop - 2 + (TheObj.filters(2).enabled ? 2 : 0) * 2;
					} else if(TheObj.filters(0).rotation == 3) {
						TheObj.style.pixelLeft = TheObj.style.pixelLeft + 2 - (TheObj.filters(1).enabled ? 2 : 0) * 2;
						TheObj.style.pixelTop = TheObj.style.pixelTop - 2 + (TheObj.filters(2).enabled ? 2 : 0) * 2;
					}
				}
			}
		}
	} else {
		if(TheObj.tagName == "DIV") {
			if(TheObj.style.border != "") {
				TheObj.style.border = "";
				if(TheObj.filters(0).rotation == 0) {
					TheObj.style.pixelLeft = TheObj.style.pixelLeft + 2 - (TheObj.filters(1).enabled ? 2 : 0) * 2;
					TheObj.style.pixelTop = TheObj.style.pixelTop + 2 - (TheObj.filters(2).enabled ? 2 : 0) * 2;
				} else if(TheObj.filters(0).rotation == 1) {
					TheObj.style.pixelLeft = TheObj.style.pixelLeft - 2 + (TheObj.filters(1).enabled ? 2 : 0) * 2;
					TheObj.style.pixelTop = TheObj.style.pixelTop + 2 - (TheObj.filters(2).enabled ? 2 : 0) * 2;
				} else if(TheObj.filters(0).rotation == 2) {
					TheObj.style.pixelLeft = TheObj.style.pixelLeft - 2 + (TheObj.filters(1).enabled ? 2 : 0) * 2;
					TheObj.style.pixelTop = TheObj.style.pixelTop - 2 + (TheObj.filters(2).enabled ? 2 : 0) * 2;
				} else if(TheObj.filters(0).rotation == 3) {
					TheObj.style.pixelLeft = TheObj.style.pixelLeft + 2 - (TheObj.filters(1).enabled ? 2 : 0) * 2;
					TheObj.style.pixelTop = TheObj.style.pixelTop - 2 + (TheObj.filters(2).enabled ? 2 : 0) * 2;
				}
			}
		}
	}
	SetKeyPressEvent(TheObj);
}

function EnableSelectObject(TheObj) {
	if(TheObj.tagName == "DIV") {
		if(TheObj.style.display != "none" && TheObj.style.border == "") {
			if(TheObj.filters(0).rotation == 0) {
				TheObj.style.pixelLeft = TheObj.style.pixelLeft - 2 + (TheObj.filters(1).enabled ? 2 : 0) * 2;
				TheObj.style.pixelTop = TheObj.style.pixelTop - 2 + (TheObj.filters(2).enabled ? 2 : 0) * 2;
			} else if(TheObj.filters(0).rotation == 1) {
				TheObj.style.pixelLeft = TheObj.style.pixelLeft + 2 - (TheObj.filters(1).enabled ? 2 : 0) * 2;
				TheObj.style.pixelTop = TheObj.style.pixelTop - 2 + (TheObj.filters(2).enabled ? 2 : 0) * 2;
			} else if(TheObj.filters(0).rotation == 2) {
				TheObj.style.pixelLeft = TheObj.style.pixelLeft + 2 - (TheObj.filters(1).enabled ? 2 : 0) * 2;
				TheObj.style.pixelTop = TheObj.style.pixelTop + 2 - (TheObj.filters(2).enabled ? 2 : 0) * 2;
			} else if(TheObj.filters(0).rotation == 3) {
				TheObj.style.pixelLeft = TheObj.style.pixelLeft - 2 + (TheObj.filters(1).enabled ? 2 : 0) * 2;
				TheObj.style.pixelTop = TheObj.style.pixelTop + 2 - (TheObj.filters(2).enabled ? 2 : 0) * 2;
			}
		}
		if(document.getElementById("B01").className == "ToolbarDown")
			TheObj.style.border = "2px dotted red";
		else if(document.getElementById("B02").className == "ToolbarDown")
			TheObj.style.border = "2px dotted green";
		else if(document.getElementById("B03").className == "ToolbarDown")
			TheObj.style.border = "2px dotted blue";
		SetKeyPressEvent(TheObj);
	}
}

function SetKeyPressEvent(TheObj) {
	if(!TheObj) {
		document.onkeydown = new Function();
	} else if(TheObj.tagName == "DIV") {
		if(TheObj.style.display != "none")
			document.onkeydown = ProcessKeyDown;
		else
			document.onkeydown = new Function();
	}
}

function DisableOperationToolbar() {
	for(var i = 1; i < 14; i ++)
		if(i < 10) {
			SetButtonDisable("B0" + i);
			document.getElementById("B0" + i).onclick = new Function();
		} else {
			SetButtonDisable("B" + i);
			document.getElementById("B" + i).onmousedown = new Function();
			document.getElementById("B" + i).onmouseup = new Function();
		}
}

function DisableTextToolbar() {
	document.getElementById("FontName").selectedIndex = -1;
	document.getElementById("FontName").disabled = true;
	document.getElementById("FontStyle").selectedIndex = -1;
	document.getElementById("FontStyle").disabled = true;
	document.getElementById("FontSize").selectedIndex = -1;
	document.getElementById("FontSize").disabled = true;
	document.getElementById("FontColor").value = "";
	document.getElementById("FontColor").disabled = true;
	document.getElementById("FontColorButton").disabled = true;
	document.getElementById("FontHidden").checked = false;
	document.getElementById("FontHidden").disabled = true;
}

function DisableAccoutermentToolbar() {
	document.getElementById("Accouterment").selectedIndex = -1;
	document.getElementById("Accouterment").disabled = true;
}

function EnableOperationToolbar(ObjType, IsDisplay, Direction, ObjSeqNo) {
	var CurRotate = Direction % 4;
	var CurFlip = Math.floor(Direction / 4);

	if(IsDisplay) {
		SetButtonDown("B01");
		document.getElementById("B01").onclick = SetOperationMode
		if(ObjType == "Avatar" || ObjType == "Accouterment") {
			SetButtonUp("B02");
			document.getElementById("B02").onclick = SetOperationMode
			SetButtonUp("B03");
			document.getElementById("B03").onclick = SetOperationMode
		}
		for(var i = 4; i < 8; i ++) {
			if(i == CurRotate + 4)
				SetButtonDown("B0" + i);
			else
				SetButtonUp("B0" + i);
			document.getElementById("B0" + i).onclick = SetRotate;
		}
		if(CurFlip == 1 || CurFlip == 3)
			SetButtonDown("B08");
		else
			SetButtonUp("B08");
		document.getElementById("B08").onclick = SetFlip;
		if(CurFlip == 2 || CurFlip == 3)
			SetButtonDown("B09");
		else
			SetButtonUp("B09");
		document.getElementById("B09").onclick = SetFlip;
		if(ObjType == "Avatar") InitPositionButton(ObjSeqNo);
	}
}

function EnableTextToolbar(IsDisplay, FontName, FontStyle, FontSize, FontColor) {
	if(IsDisplay) {
		InitSelectionValue(document.getElementById("FontName"), FontName);
		document.getElementById("FontName").disabled = false;
		InitSelectionValue(document.getElementById("FontStyle"), FontStyle);
		document.getElementById("FontStyle").disabled = false;
		InitSelectionValue(document.getElementById("FontSize"), FontSize);
		document.getElementById("FontSize").disabled = false;
	}
	document.getElementById("FontHidden").disabled = false;
	if(FontColor == "") {
		document.getElementById("FontColor").value = "";
		document.getElementById("FontColor").disabled = true;
		document.getElementById("FontColorButton").disabled = true;
		document.getElementById("FontHidden").checked = true;
	} else {
		document.getElementById("FontColor").value = FontColor;
		document.getElementById("FontColor").disabled = false;
		document.getElementById("FontColorButton").disabled = false;
		document.getElementById("FontHidden").checked = false;
	}
}

function EnableAccoutermentToolbar(AccoutermentItemID) {
	InitSelectionValue(document.getElementById("Accouterment"), AccoutermentItemID);
	document.getElementById("Accouterment").disabled = false;
}

function InitPositionButton(ObjSeqNo) {
	if(AvatarArray.length == 1) {
		SetButtonDisable("B10");
		document.getElementById("B10").onclick = new Function();
		SetButtonDisable("B11");
		document.getElementById("B11").onclick = new Function();
		SetButtonDisable("B12");
		document.getElementById("B12").onclick = new Function();
		SetButtonDisable("B13");
		document.getElementById("B13").onclick = new Function();
	} else {
		if(ObjSeqNo == AvatarArray[0]) {
			SetButtonDisable("B10");
			document.getElementById("B10").onmousedown = new Function();
			document.getElementById("B10").onmouseup = new Function();
			SetButtonDisable("B11");
			document.getElementById("B11").onmousedown = new Function();
			document.getElementById("B11").onmouseup = new Function();
		} else {
			SetButtonUp("B10");
			document.getElementById("B10").onmousedown = SetButtonDown;
			document.getElementById("B10").onmouseup = ForeMost;
			SetButtonUp("B11");
			document.getElementById("B11").onmousedown = SetButtonDown;
			document.getElementById("B11").onmouseup = ForeMore;
		}
		if(ObjSeqNo == AvatarArray[AvatarArray.length - 1]) {
			SetButtonDisable("B12");
			document.getElementById("B12").onmousedown = new Function();
			document.getElementById("B12").onmouseup = new Function();
			SetButtonDisable("B13");
			document.getElementById("B13").onmousedown = new Function();
			document.getElementById("B13").onmouseup = new Function();
		} else {
			SetButtonUp("B12");
			document.getElementById("B12").onmousedown = SetButtonDown;
			document.getElementById("B12").onmouseup = BackMore;
			SetButtonUp("B13");
			document.getElementById("B13").onmousedown = SetButtonDown;
			document.getElementById("B13").onmouseup = BackMost;
		}
	}
}	
	
function SetButtonDisable(ButtonID) {
	var CurButton;
	
	if(!ButtonID) {
		if(event.srcElement.tagName == "IMG")
			CurButton = event.srcElement.parentElement;
		else
			CurButton = event.srcElement;
	} else
		CurButton = document.getElementById(ButtonID);
	CurButton.children[0].filters(0).enabled = true;
	CurButton.style.cursor = "default";
	CurButton.className = "ToolbarDisable";
}

function SetButtonReverse(ButtonID) {
	var CurButton;
	
	if(!ButtonID) {
		if(event.srcElement.tagName == "IMG")
			CurButton = event.srcElement.parentElement;
		else
			CurButton = event.srcElement;
	} else
		CurButton = document.getElementById(ButtonID);
	if(CurButton.className == "ToolbarDisable") return false;
	CurButton.children[0].filters(0).enabled = false;
	CurButton.style.cursor = "pointer";
	if(CurButton.className == "ToolbarDown")
		CurButton.className = "ToolbarUp";
	else
		CurButton.className = "ToolbarDown";
}

function SetButtonDown(ButtonID) {
	var CurButton;
	
	if(!ButtonID) {
		if(event.srcElement.tagName == "IMG")
			CurButton = event.srcElement.parentElement;
		else
			CurButton = event.srcElement;
	} else
		CurButton = document.getElementById(ButtonID);
	CurButton.children[0].filters(0).enabled = false;
	CurButton.style.cursor = "pointer";
	CurButton.className = "ToolbarDown";
}

function SetButtonUp(ButtonID) {
	var CurButton;
	
	if(!ButtonID) {
		if(event.srcElement.tagName == "IMG")
			CurButton = event.srcElement.parentElement;
		else
			CurButton = event.srcElement;
	} else
		CurButton = document.getElementById(ButtonID);
	CurButton.children[0].filters(0).enabled = false;
	CurButton.style.cursor = "pointer";
	CurButton.className = "ToolbarUp";
}

function IsPosition(PosX, PosY, TheObj) {
	var ObjLeft, ObjTop, ObjRight, ObjBottom;
	
	if(TheObj.style.display == "none") return false;
	if(TheObj.filters(0).rotation == 0 || TheObj.filters(0).rotation == 2) {
		ObjLeft = TheObj.style.pixelLeft;
		ObjRight = TheObj.style.pixelLeft + TheObj.style.pixelWidth - 1;
		ObjTop = TheObj.style.pixelTop;
		ObjBottom = TheObj.style.pixelTop + TheObj.style.pixelHeight - 1;
	} else {
		ObjLeft = TheObj.style.pixelLeft;
		ObjRight = TheObj.style.pixelLeft + TheObj.style.pixelHeight - 1;
		ObjTop = TheObj.style.pixelTop;
		ObjBottom = TheObj.style.pixelTop + TheObj.style.pixelWidth - 1;
	}
	if(ObjLeft <= PosX && ObjRight >= PosX && ObjTop <= PosY && ObjBottom >= PosY) return true;
	return false;
}

function ProcessKeyDown() {
	var deltaX, deltaY;
	var CurObj = document.getElementById("CurrentObject").value;
	var CurObjType, CurObjID;
		
	if(CurObj == "") {
		event.returnValue = true;
		return true;
	}
	if(event.keyCode != 40 && event.keyCode != 37 && event.keyCode != 39 && event.keyCode != 38) {
		event.returnValue = true;
		return true;
	}
	CurObjType = CurObj.split("_")[0];
	CurObjID = CurObj.split("_")[1];
	if(CurObjType == "PhotoName") {
		objMoved = document.getElementById("PhotoNameBorder");
		objMovedLeft = document.getElementById("PhotoNameLeft");
		objMovedTop = document.getElementById("PhotoNameTop");
	} else if(CurObjType == "PhotoDate") {
		objMoved = document.getElementById("PhotoDateBorder");
		objMovedLeft = document.getElementById("PhotoDateLeft");
		objMovedTop = document.getElementById("PhotoDateTop");
	} else if(CurObjType == "UserName") {
		objMoved = document.getElementById("UserNameBorder_" + CurObjID);
		objMovedLeft = document.getElementById("UserNameLeft_" + CurObjID);
		objMovedTop = document.getElementById("UserNameTop_" + CurObjID);
	} else if(CurObjType == "Avatar") {
		if(document.getElementById("B01").className == "ToolbarDown") {
			objMoved = document.getElementById("AvatarBorder_" + CurObjID);
			objMovedLeft = document.getElementById("AvatarOuterLeft_" + CurObjID);
			objMovedTop = document.getElementById("AvatarOuterTop_" + CurObjID);
		} else if(document.getElementById("B02").className == "ToolbarDown") {
			objCropped = document.getElementById("AvatarBorder_" + CurObjID);
			objCroppedOuterLeft = document.getElementById("AvatarOuterLeft_" + CurObjID);
			objCroppedOuterTop = document.getElementById("AvatarOuterTop_" + CurObjID);
			objCroppedOuterWidth = document.getElementById("AvatarOuterWidth_" + CurObjID);
			objCroppedOuterHeight = document.getElementById("AvatarOuterHeight_" + CurObjID);
			objCroppedInnerLeft = document.getElementById("AvatarInnerLeft_" + CurObjID);
			objCroppedInnerTop = document.getElementById("AvatarInnerTop_" + CurObjID);
		} else if(document.getElementById("B03").className == "ToolbarDown") {
			objResized = document.getElementById("AvatarBorder_" + CurObjID);
			objResizedOuterLeft = document.getElementById("AvatarOuterLeft_" + CurObjID);
			objResizedOuterTop = document.getElementById("AvatarOuterTop_" + CurObjID);
			objResizedOuterWidth = document.getElementById("AvatarOuterWidth_" + CurObjID);
			objResizedOuterHeight = document.getElementById("AvatarOuterHeight_" + CurObjID);
			objResizedInnerLeft = document.getElementById("AvatarInnerLeft_" + CurObjID);
			objResizedInnerTop = document.getElementById("AvatarInnerTop_" + CurObjID);
			objResizedInnerWidth = document.getElementById("AvatarInnerWidth_" + CurObjID);
			objResizedInnerHeight = document.getElementById("AvatarInnerHeight_" + CurObjID);
		}
	} else if(CurObjType == "Accouterment") {
		if(document.getElementById("B01").className == "ToolbarDown") {
			objMoved = document.getElementById("AccoutermentBorder_" + CurObjID);
			objMovedLeft = document.getElementById("AccoutermentOuterLeft_" + CurObjID);
			objMovedTop = document.getElementById("AccoutermentOuterTop_" + CurObjID);
		} else if(document.getElementById("B02").className == "ToolbarDown") {
			objCropped = document.getElementById("AccoutermentBorder_" + CurObjID);
			objCroppedOuterLeft = document.getElementById("AccoutermentOuterLeft_" + CurObjID);
			objCroppedOuterTop = document.getElementById("AccoutermentOuterTop_" + CurObjID);
			objCroppedOuterWidth = document.getElementById("AccoutermentOuterWidth_" + CurObjID);
			objCroppedOuterHeight = document.getElementById("AccoutermentOuterHeight_" + CurObjID);
			objCroppedInnerLeft = document.getElementById("AccoutermentInnerLeft_" + CurObjID);
			objCroppedInnerTop = document.getElementById("AccoutermentInnerTop_" + CurObjID);
		} else if(document.getElementById("B03").className == "ToolbarDown") {
			objResized = document.getElementById("AccoutermentBorder_" + CurObjID);
			objResizedOuterLeft = document.getElementById("AccoutermentOuterLeft_" + CurObjID);
			objResizedOuterTop = document.getElementById("AccoutermentOuterTop_" + CurObjID);
			objResizedOuterWidth = document.getElementById("AccoutermentOuterWidth_" + CurObjID);
			objResizedOuterHeight = document.getElementById("AccoutermentOuterHeight_" + CurObjID);
			objResizedInnerLeft = document.getElementById("AccoutermentInnerLeft_" + CurObjID);
			objResizedInnerTop = document.getElementById("AccoutermentInnerTop_" + CurObjID);
			objResizedInnerWidth = document.getElementById("AccoutermentInnerWidth_" + CurObjID);
			objResizedInnerHeight = document.getElementById("AccoutermentInnerHeight_" + CurObjID);
		}
	} else {
		event.returnValue = true;
		return true;
	}
	if(!event.ctrlKey && !event.shiftKey) {
		event.returnValue = true;
		return true;
	}
	deltaX = 0;
	deltaY = 0;
	if(!event.ctrlKey) {
		if(event.keyCode == 37)          // Shift+Left
			deltaX = -1;
		if(event.keyCode == 38)          // Shift+Up
			deltaY = -1;
		if(event.keyCode == 39)          // Shift+Right
			deltaX = 1;
		if(event.keyCode == 40)          // Shift+Down
			deltaY = 1;
	} else {
		if(event.keyCode == 37) {        // Ctrl+Left
			if(document.getElementById("B01").className == "ToolbarDown")
				deltaX = -20;
			else
				deltaX = -1;
		} else if(event.keyCode == 38) { // Ctrl+Up
			if(document.getElementById("B01").className == "ToolbarDown")
				deltaY = -20;
			else
				deltaY = -1;
		} else if(event.keyCode == 39) { // Ctrl+Right
			if(document.getElementById("B01").className == "ToolbarDown")
				deltaX = 20;
			else
				deltaX = 1;
		} else if(event.keyCode == 40) { // Ctrl+Down
			if(document.getElementById("B01").className == "ToolbarDown")
				deltaY = 20;
			else
				deltaY = 1;
		}
	}
	if(document.getElementById("B01").className == "ToolbarDown" && objMoved) {
		MoveElement(objMoved, objMovedLeft, objMovedTop, deltaX, deltaY, 0, 0, document.getElementById("ThePhoto").style.pixelWidth, document.getElementById("ThePhoto").style.pixelHeight);
		window.status = "(" + objMovedLeft.value + "," + objMovedTop.value + ")";
	} else if(document.getElementById("B02").className == "ToolbarDown" && objCropped) {
		CropElement(objCropped, objCroppedOuterLeft, objCroppedOuterTop, objCroppedOuterWidth, objCroppedOuterHeight, objCroppedInnerLeft, objCroppedInnerTop, 
			GetDirectionByKey(event.ctrlKey, event.shiftKey, deltaX, deltaY), deltaX, deltaY, 0, 0, document.getElementById("ThePhoto").style.pixelWidth, document.getElementById("ThePhoto").style.pixelHeight);
	} else if(document.getElementById("B03").className == "ToolbarDown" && objResized) {
		ResizeElement(objResized, objResizedOuterLeft, objResizedOuterTop, objResizedOuterWidth, objResizedOuterHeight, objResizedInnerLeft, objResizedInnerTop, objResizedInnerWidth, objResizedInnerHeight, 
			GetDirectionByKey(event.ctrlKey, event.shiftKey, deltaX, deltaY), deltaX, deltaY, 0, 0, document.getElementById("ThePhoto").style.pixelWidth, document.getElementById("ThePhoto").style.pixelHeight);
	}
	event.returnValue = false;
}

function ProcessMouseDown(PhotoUserCount) {
	var PosX, PosY, CurObj, i, j, TempLayer, OldMode = 0;
	
	if(event.button != 1 && event.button != 2) {
		event.returnValue = true;
		return true;
	}
	if(!event.srcElement) {
		event.returnValue = true;
		return true;
	}
	if(!event.srcElement.id || event.srcElement.id != "ThePhoto") {
		PosX = event.offsetX;
		PosY = event.offsetY;
		CurObj = event.srcElement;
		while (CurObj.id != "ThePhoto") {
			PosX = PosX + CurObj.style.pixelLeft;
			PosY = PosY + CurObj.style.pixelTop;
			CurObj = CurObj.parentElement;
			if(!CurObj) {
				event.returnValue = true;
				return true;
			}
			if(!CurObj.id) {
				event.returnValue = true;
				return true;
			}
		}
	} else {
		PosX = event.offsetX;
		PosY = event.offsetY;
	}
	if(!isCroppable && !isResizable) {
		if(IsPosition(PosX, PosY, document.getElementById("PhotoNameBorder"))) {
			if(document.getElementById("CurrentObject").selectedIndex != PhotoUserCount + 1) {
				document.getElementById("CurrentObject").selectedIndex = PhotoUserCount + 1;
				DisableOperationToolbar();
				DisableTextToolbar();
				DisableAccoutermentToolbar();
				DisableSelectObject();
				EnableOperationToolbar("PhotoName", true, document.getElementById("PhotoNameDirection").value, 0);
				EnableTextToolbar(true, document.getElementById("PhotoNameFont").value, parseInt(document.getElementById("PhotoNameBold").value) * 2 + parseInt(document.getElementById("PhotoNameItalic").value), document.getElementById("PhotoNameSize").value, document.getElementById("PhotoNameColor").value);
				EnableSelectObject(document.getElementById("PhotoNameBorder"));
			}
			if(!event.ctrlKey && !event.shiftKey) {
				if(event.button == 1 && document.getElementById("B01").className == "ToolbarDown") {
					objMoved = document.getElementById("PhotoNameBorder");
					objMovedLeft = document.getElementById("PhotoNameLeft");
					objMovedTop = document.getElementById("PhotoNameTop");
					isDragging = true;
				} else if(event.button == 2) {
					SelRotate();
					return false;
				} else {
					returnValue = true;
					return true;
				}
			} else if(event.shiftKey) {
				if(event.button == 1)
					SelFlipH();
				else
					SelFlipV();
				return false;
			} else if(event.ctrlKey) {
				if(event.button == 1) {
				}
				else {
				}
				return false;
			}
		} else if(IsPosition(PosX, PosY, document.getElementById("PhotoDateBorder"))) {
			if(document.getElementById("CurrentObject").selectedIndex != PhotoUserCount + 2) {
				document.getElementById("CurrentObject").selectedIndex = PhotoUserCount + 2;
				DisableOperationToolbar();
				DisableTextToolbar();
				DisableAccoutermentToolbar();
				DisableSelectObject();
				EnableOperationToolbar("PhotoDate", true, document.getElementById("PhotoDateDirection").value, 0);
				EnableTextToolbar(true, document.getElementById("PhotoDateFont").value, parseInt(document.getElementById("PhotoDateBold").value) * 2 + parseInt(document.getElementById("PhotoDateItalic").value), document.getElementById("PhotoDateSize").value, document.getElementById("PhotoDateColor").value);
				EnableSelectObject(document.getElementById("PhotoDateBorder"));
			}
			if(!event.ctrlKey && !event.shiftKey) {
				if(event.button == 1 && document.getElementById("B01").className == "ToolbarDown") {
					objMoved = document.getElementById("PhotoDateBorder");
					objMovedLeft = document.getElementById("PhotoDateLeft");
					objMovedTop = document.getElementById("PhotoDateTop");
					isDragging = true;
				} else if(event.button == 2) {
					SelRotate();
					return false;
				} else {
					returnValue = true;
					return true;
				}
			} else if(event.shiftKey) {
				if(event.button == 1)
					SelFlipH();
				else
					SelFlipV();
				return false;
			} else if(event.ctrlKey) {
				if(event.button == 1) {
				}
				else {
				}
				return false;
			}
		} else {
			for(i = 1; i <= PhotoUserCount; i ++)
				if(IsPosition(PosX, PosY, document.getElementById("UserNameBorder_" + i))) {
					if(document.getElementById("CurrentObject").selectedIndex != PhotoUserCount + 2 + i) {
						document.getElementById("CurrentObject").selectedIndex = PhotoUserCount + 2 + i;
						DisableOperationToolbar();
						DisableTextToolbar();
						DisableAccoutermentToolbar();
						DisableSelectObject();
						EnableOperationToolbar("UserName", true, document.getElementById("UserNameDirection_" + i).value, i);
						EnableTextToolbar(true, document.getElementById("UserNameFont_" + i).value, parseInt(document.getElementById("UserNameBold_" + i).value) * 2 + parseInt(document.getElementById("UserNameItalic_" + i).value), document.getElementById("UserNameSize_" + i).value, document.getElementById("UserNameColor_" + i).value);
						EnableSelectObject(document.getElementById("UserNameBorder_" + i));
					}
					if(!event.ctrlKey && !event.shiftKey) {
						if(event.button == 1 && document.getElementById("B01").className == "ToolbarDown") {
							objMoved = document.getElementById("UserNameBorder_" + i);
							objMovedLeft = document.getElementById("UserNameLeft_" + i);
							objMovedTop = document.getElementById("UserNameTop_" + i);
							isDragging = true;
							break;
						} else if(event.button == 2) {
							SelRotate();
							return false;
						} else {
							returnValue = true;
							return true;
						}
					} else if(event.shiftKey) {
						if(event.button == 1)
							SelFlipH();
						else
							SelFlipV();
						return false;
					} else if(event.ctrlKey) {
						if(event.button == 1) {
						}
						else {
						}
						return false;
					}
				}
			if(i > PhotoUserCount) {
				for(i = 6; i >= 4; i --)
					if(IsPosition(PosX, PosY, document.getElementById("AccoutermentBorder_" + i))) {
						if(document.getElementById("CurrentObject").selectedIndex != PhotoUserCount * 2 + 2 + i) {
							document.getElementById("CurrentObject").selectedIndex = PhotoUserCount * 2 + 2 + i;
							if(document.getElementById("B01").className == "ToolbarDown")
								OldMode = 1;
							else if(document.getElementById("B02").className == "ToolbarDown")
								OldMode = 2;
							else if(document.getElementById("B03").className == "ToolbarDown")
								OldMode = 3;
							DisableOperationToolbar();
							DisableTextToolbar();
							DisableAccoutermentToolbar();
							DisableSelectObject();
							EnableOperationToolbar("Accouterment", true, document.getElementById("AccoutermentDirection_" + i).value, i);
							EnableAccoutermentToolbar(document.getElementById("AccoutermentItemID_" + i).value);
							if(OldMode == 2)
								document.getElementById("B02").fireEvent("onclick");
							else if(OldMode == 3)
								document.getElementById("B03").fireEvent("onclick");
							EnableSelectObject(document.getElementById("AccoutermentBorder_" + i));
						}
						if(!event.ctrlKey && !event.shiftKey) {
							if(event.button == 1 && document.getElementById("B01").className == "ToolbarDown") {
								objMoved = document.getElementById("AccoutermentBorder_" + i);
								objMovedLeft = document.getElementById("AccoutermentOuterLeft_" + i);
								objMovedTop = document.getElementById("AccoutermentOuterTop_" + i);
								isDragging = true;
								break;
							} else if(event.button == 2) {
								SelRotate();
								return false;
							} else {
								returnValue = true;
								return true;
							}
						} else if(event.shiftKey) {
							if(event.button == 1)
								SelFlipH();
							else
								SelFlipV();
							return false;
						} else if(event.ctrlKey) {
							if(event.button == 1) {
							}
							else {
							}
							return false;
						}
					}
				if(i < 4) {
					for(i = 1; i <= PhotoUserCount; i ++)
						if(IsPosition(PosX, PosY, document.getElementById("AvatarBorder_" + AvatarArray[i - 1]))) {
							if(document.getElementById("CurrentObject").selectedIndex != AvatarArray[i - 1]) {
								document.getElementById("CurrentObject").selectedIndex = AvatarArray[i - 1];
								if(document.getElementById("B01").className == "ToolbarDown")
									OldMode = 1;
								else if(document.getElementById("B02").className == "ToolbarDown")
									OldMode = 2;
								else if(document.getElementById("B03").className == "ToolbarDown")
									OldMode = 3;
								DisableOperationToolbar();
								DisableTextToolbar();
								DisableAccoutermentToolbar();
								DisableSelectObject();
								EnableOperationToolbar("Avatar", true, document.getElementById("AvatarDirection_" + AvatarArray[i - 1]).value, AvatarArray[i - 1]);
								if(OldMode == 2)
									document.getElementById("B02").fireEvent("onclick");
								else if(OldMode == 3)
									document.getElementById("B03").fireEvent("onclick");
								EnableSelectObject(document.getElementById("AvatarBorder_" + AvatarArray[i - 1]));
							}
							if(!event.ctrlKey && !event.shiftKey) {
								if(event.button == 1 && document.getElementById("B01").className == "ToolbarDown") {
									objMoved = document.getElementById("AvatarBorder_" + AvatarArray[i - 1]);
									objMovedLeft = document.getElementById("AvatarOuterLeft_" + AvatarArray[i - 1]);
									objMovedTop = document.getElementById("AvatarOuterTop_" + AvatarArray[i - 1]);
									isDragging = true;
									break;
								} else if(event.button == 2) {
									SelRotate();
									return false;
								} else {
									returnValue = true;
									return true;
								}
							} else if(event.shiftKey) {
								if(event.button == 1)
									SelFlipH();
								else
									SelFlipV();
								return false;
							} else if(event.ctrlKey) {
								if(event.button == 1)
									BackMore();
								else
									BackMost();
								return false;
							}
						}
					if(i > PhotoUserCount) {
						for(i = 3; i >= 1; i --)
							if(IsPosition(PosX, PosY, document.getElementById("AccoutermentBorder_" + i))) {
								if(document.getElementById("CurrentObject").selectedIndex != PhotoUserCount * 2 + 2 + i) {
									document.getElementById("CurrentObject").selectedIndex = PhotoUserCount * 2 + 2 + i;
									if(document.getElementById("B01").className == "ToolbarDown")
										OldMode = 1;
									else if(document.getElementById("B02").className == "ToolbarDown")
										OldMode = 2;
									else if(document.getElementById("B03").className == "ToolbarDown")
										OldMode = 3;
									DisableOperationToolbar();
									DisableTextToolbar();
									DisableAccoutermentToolbar();
									DisableSelectObject();
									EnableOperationToolbar("Accouterment", true, document.getElementById("AccoutermentDirection_" + i).value, i);
									EnableAccoutermentToolbar(document.getElementById("AccoutermentItemID_" + i).value);
									if(OldMode == 2)
										document.getElementById("B02").fireEvent("onclick");
									else if(OldMode == 3)
										document.getElementById("B03").fireEvent("onclick");
									EnableSelectObject(document.getElementById("AccoutermentBorder_" + i));
								}
								if(!event.ctrlKey && !event.shiftKey) {
									if(event.button == 1 && document.getElementById("B01").className == "ToolbarDown") {
										objMoved = document.getElementById("AccoutermentBorder_" + i);
										objMovedLeft = document.getElementById("AccoutermentOuterLeft_" + i);
										objMovedTop = document.getElementById("AccoutermentOuterTop_" + i);
										isDragging = true;
										break;
									} else if(event.button == 2) {
										SelRotate();
										return false;
									} else {
										returnValue = true;
										return true;
									}
								} else if(event.shiftKey) {
									if(event.button == 1)
										SelFlipH();
									else
										SelFlipV();
									return false;
								} else if(event.ctrlKey) {
									if(event.button == 1) {
									}
									else {
									}
									return false;
								}
							}
						if(i < 1) {
							if(document.getElementById("CurrentObject").selectedIndex != 0) {
								document.getElementById("CurrentObject").selectedIndex = 0;
								DisableOperationToolbar();
								DisableTextToolbar();
								DisableAccoutermentToolbar();
								DisableSelectObject();
							}
							isDragging = false;
						}
					}
				}
			}
		}
		if(isDragging) {
			mouseX = PosX - objMoved.style.pixelLeft;
			mouseY = PosY - objMoved.style.pixelTop;
			SetCursor("pointer");
		}
	} else if(isCroppable) {
		isCropping = true;
		mouseX = PosX - objCropped.style.pixelLeft;
		mouseY = PosY - objCropped.style.pixelTop;
	} else if(isResizable) {
		isResizing = true;
		mouseX = PosX - objResized.style.pixelLeft;
		mouseY = PosY - objResized.style.pixelTop;
	}
	return true;
}

function ProcessMouseMove() {
	var PosX, PosY, CurObj;
	var CurObjType, CurObjID, CurEdge;

	if(event.button != 1 && (isDragging || isCropping || isResizing)) {
		ProcessMouseUp();
		return false;
	}
	if((isDragging && document.getElementById("B01").className == "ToolbarDown") || document.getElementById("B02").className == "ToolbarDown" || document.getElementById("B03").className == "ToolbarDown") {
		if(!event.srcElement) return false;
		if(!event.srcElement.id || event.srcElement.id != "ThePhoto") {
			PosX = event.offsetX;
			PosY = event.offsetY;
			CurObj = event.srcElement;
			while (CurObj.id != "ThePhoto") {
				PosX = PosX + CurObj.style.pixelLeft;
				PosY = PosY + CurObj.style.pixelTop;
				CurObj = CurObj.parentElement;
				if(!CurObj) return false;
				if(!CurObj.id) return false;
			}
		} else {
			PosX = event.offsetX;
			PosY = event.offsetY;
		}
		if(isDragging || isCropping || isResizing) {
			if(isDragging) {
				MoveElement(objMoved, objMovedLeft, objMovedTop, PosX - mouseX - objMoved.style.pixelLeft, PosY - mouseY - objMoved.style.pixelTop, 
					0, 0, document.getElementById("ThePhoto").style.pixelWidth, document.getElementById("ThePhoto").style.pixelHeight);
			} else if(isCropping) {
				CropElement(objCropped, objCroppedOuterLeft, objCroppedOuterTop, objCroppedOuterWidth, objCroppedOuterHeight, objCroppedInnerLeft, objCroppedInnerTop, 
					CropDirection, PosX - mouseX - objCropped.style.pixelLeft, PosY - mouseY - objCropped.style.pixelTop, 0, 0, document.getElementById("ThePhoto").style.pixelWidth, document.getElementById("ThePhoto").style.pixelHeight);
				mouseX = PosX - objCropped.style.pixelLeft;
				mouseY = PosY - objCropped.style.pixelTop;
			} else if(isResizing) {
				ResizeElement(objResized, objResizedOuterLeft, objResizedOuterTop, objResizedOuterWidth, objResizedOuterHeight, objResizedInnerLeft, objResizedInnerTop, objResizedInnerWidth, objResizedInnerHeight, 
					ResizeDirection, PosX - mouseX - objResized.style.pixelLeft, PosY - mouseY - objResized.style.pixelTop, 0, 0, document.getElementById("ThePhoto").style.pixelWidth, document.getElementById("ThePhoto").style.pixelHeight);
				mouseX = PosX - objResized.style.pixelLeft;
				mouseY = PosY - objResized.style.pixelTop;
			}
		} else {
			CurObj = document.getElementById("CurrentObject").value;
			CurObjType = CurObj.split("_")[0];
			CurObjID = CurObj.split("_")[1];
			if(CurObj == "") {
				event.returnValue = true;
				return true;
			}
			if(CurObjType == "Avatar" && document.getElementById("AvatarBorder_" + CurObjID).style.display != "none")
				CurEdge = WhichEdge(PosX, PosY, document.getElementById("AvatarBorder_" + CurObjID));
			else if(CurObjType == "Accouterment" && document.getElementById("AccoutermentBorder_" + CurObjID).style.display != "none")
				CurEdge = WhichEdge(PosX, PosY, document.getElementById("AccoutermentBorder_" + CurObjID));
			else {
				event.returnValue = true;
				return true;
			}
			if(CurEdge > 0) {
				if(document.getElementById("B02").className == "ToolbarDown")
					isCroppable = true;
				else if(document.getElementById("B03").className == "ToolbarDown")
					isResizable = true;
				if(CurEdge == 1)
					SetCursor("N-resize");
				else if(CurEdge == 2)
					SetCursor("NE-resize");
				else if(CurEdge == 3)
					SetCursor("E-resize");
				else if(CurEdge == 4)
					SetCursor("SE-resize");
				else if(CurEdge == 5)
					SetCursor("S-resize");
				else if(CurEdge == 6)
					SetCursor("SW-resize");
				else if(CurEdge == 7)
					SetCursor("W-resize");
				else
					SetCursor("NW-resize");
				if(isCroppable) {
					CropDirection = CurEdge;
					if(CurObjType == "Avatar") {
						objCropped = document.getElementById("AvatarBorder_" + CurObjID);
						objCroppedOuterLeft = document.getElementById("AvatarOuterLeft_" + CurObjID);
						objCroppedOuterTop = document.getElementById("AvatarOuterTop_" + CurObjID);
						objCroppedOuterWidth = document.getElementById("AvatarOuterWidth_" + CurObjID);
						objCroppedOuterHeight = document.getElementById("AvatarOuterHeight_" + CurObjID);
						objCroppedInnerLeft = document.getElementById("AvatarInnerLeft_" + CurObjID);
						objCroppedInnerTop = document.getElementById("AvatarInnerTop_" + CurObjID);
					} else if(CurObjType == "Accouterment") {
						objCropped = document.getElementById("AccoutermentBorder_" + CurObjID);
						objCroppedOuterLeft = document.getElementById("AccoutermentOuterLeft_" + CurObjID);
						objCroppedOuterTop = document.getElementById("AccoutermentOuterTop_" + CurObjID);
						objCroppedOuterWidth = document.getElementById("AccoutermentOuterWidth_" + CurObjID);
						objCroppedOuterHeight = document.getElementById("AccoutermentOuterHeight_" + CurObjID);
						objCroppedInnerLeft = document.getElementById("AccoutermentInnerLeft_" + CurObjID);
						objCroppedInnerTop = document.getElementById("AccoutermentInnerTop_" + CurObjID);
					}
				} else if(isResizable) {
						ResizeDirection = CurEdge;
						if(CurObjType == "Avatar") {
							objResized = document.getElementById("AvatarBorder_" + CurObjID);
							objResizedOuterLeft = document.getElementById("AvatarOuterLeft_" + CurObjID);
							objResizedOuterTop = document.getElementById("AvatarOuterTop_" + CurObjID);
							objResizedOuterWidth = document.getElementById("AvatarOuterWidth_" + CurObjID);
							objResizedOuterHeight = document.getElementById("AvatarOuterHeight_" + CurObjID);
							objResizedInnerLeft = document.getElementById("AvatarInnerLeft_" + CurObjID);
							objResizedInnerTop = document.getElementById("AvatarInnerTop_" + CurObjID);
							objResizedInnerWidth = document.getElementById("AvatarInnerWidth_" + CurObjID);
							objResizedInnerHeight = document.getElementById("AvatarInnerHeight_" + CurObjID);
						} else if(CurObjType == "Accouterment") {
							objResized = document.getElementById("AccoutermentBorder_" + CurObjID);
							objResizedOuterLeft = document.getElementById("AccoutermentOuterLeft_" + CurObjID);
							objResizedOuterTop = document.getElementById("AccoutermentOuterTop_" + CurObjID);
							objResizedOuterWidth = document.getElementById("AccoutermentOuterWidth_" + CurObjID);
							objResizedOuterHeight = document.getElementById("AccoutermentOuterHeight_" + CurObjID);
							objResizedInnerLeft = document.getElementById("AccoutermentInnerLeft_" + CurObjID);
							objResizedInnerTop = document.getElementById("AccoutermentInnerTop_" + CurObjID);
							objResizedInnerWidth = document.getElementById("AccoutermentInnerWidth_" + CurObjID);
							objResizedInnerHeight = document.getElementById("AccoutermentInnerHeight_" + CurObjID);
						}
				}
			} else {
				if(document.getElementById("B02").className == "ToolbarDown")
					isCroppable = false;
				else if(document.getElementById("B03").className == "ToolbarDown")
					isResizable = false;
				SetCursor("default");
			}
		}
	}
}

function ProcessMouseUp() {
	isDragging = false;
	isCropping = false;
	isResizing = false;
	SetCursor("default");
}

function SetCursor(CursorType) {
	for(var i = 0; i < document.getElementById("ThePhoto").children.length; i ++) {
		if(document.getElementById("ThePhoto").children[i].tagName == "IMG")
			document.getElementById("ThePhoto").children[i].style.cursor = CursorType;
		else if(document.getElementById("ThePhoto").children[i].tagName == "DIV") {
			for(var j = 0; j < document.getElementById("ThePhoto").children[i].children.length; j ++) {
				if(document.getElementById("ThePhoto").children[i].children[j].tagName == "IMG")
					document.getElementById("ThePhoto").children[i].children[j].style.cursor = CursorType;
				else if(document.getElementById("ThePhoto").children[i].children[j].tagName == "DIV") {
					for(var k = 0; k < document.getElementById("ThePhoto").children[i].children[j].children.length; k ++)
						if(document.getElementById("ThePhoto").children[i].children[j].children[k].tagName == "IMG")
							document.getElementById("ThePhoto").children[i].children[j].children[k].style.cursor = CursorType;
					document.getElementById("ThePhoto").children[i].children[j].style.cursor = CursorType;
				}
			}
			document.getElementById("ThePhoto").children[i].style.cursor = CursorType;
		}
	}
	document.getElementById("ThePhoto").style.cursor = CursorType;
}

function WhichEdge(PosX, PosY, TheObj) {
	var ObjLeft, ObjTop, ObjRight, ObjBottom;
	
	if(TheObj.style.display == "none") return 0;
	if(TheObj.filters(0).rotation == 0 || TheObj.filters(0).rotation == 2) {
		ObjLeft = TheObj.style.pixelLeft;
		ObjRight = TheObj.style.pixelLeft + TheObj.style.pixelWidth - 1;
		ObjTop = TheObj.style.pixelTop;
		ObjBottom = TheObj.style.pixelTop + TheObj.style.pixelHeight - 1;
	} else {
		ObjLeft = TheObj.style.pixelLeft;
		ObjRight = TheObj.style.pixelLeft + TheObj.style.pixelHeight - 1;
		ObjTop = TheObj.style.pixelTop;
		ObjBottom = TheObj.style.pixelTop + TheObj.style.pixelWidth - 1;
	}
	if(ObjLeft + 5 < PosX && ObjRight - 5 > PosX && ObjTop - 5 <= PosY && ObjTop + 5 >= PosY) return 1;              // N
	if(ObjRight - 5 <= PosX && ObjRight + 5 >= PosX && ObjTop - 5 <= PosY && ObjTop + 5 >= PosY) return 2;           // NE
	if(ObjRight - 5 <= PosX && ObjRight + 5 >= PosX && ObjTop + 5 < PosY && ObjBottom - 5 > PosY) return 3;          // E
	if(ObjRight - 5 <= PosX && ObjRight + 5 >= PosX && ObjBottom - 5 <= PosY && ObjBottom + 5 >= PosY) return 4;     // SE
	if(ObjLeft + 5 < PosX && ObjRight - 5 > PosX && ObjBottom - 5 <= PosY && ObjBottom + 5 >= PosY) return 5;        // S
	if(ObjLeft - 5 <= PosX && ObjLeft + 5 >= PosX && ObjBottom - 5 <= PosY && ObjBottom + 5 >= PosY) return 6;       // SW
	if(ObjLeft - 5 <= PosX && ObjLeft + 5 >= PosX && ObjTop + 5 < PosY && ObjBottom - 5 > PosY) return 7;            // W
	if(ObjLeft - 5 <= PosX && ObjLeft + 5 >= PosX && ObjTop - 5 <= PosY && ObjTop + 5 >= PosY) return 8;             // NW
	return 0;
}

function MoveElement(objElement, objOutLeft, objOutTop, DeltaX, DeltaY, FrameLeft, FrameTop, FrameWidth, FrameHeight) {
	var RotateMode = GetRotateMode(objElement);
	var DestLeft, DestTop, ElementWidth, ElementHeight;
	
	DestLeft = objElement.style.pixelLeft + DeltaX;
	DestTop = objElement.style.pixelTop + DeltaY;
	if(RotateMode == 0 || RotateMode == 2) {
		ElementWidth = objElement.style.pixelWidth;
		ElementHeight = objElement.style.pixelHeight;
	} else {
		ElementWidth = objElement.style.pixelHeight;
		ElementHeight = objElement.style.pixelWidth;
	}
	if(IsInFrame(DestLeft, ElementWidth, FrameLeft, FrameWidth)) {
		objElement.style.pixelLeft = DestLeft;
		objOutLeft.value = objElement.style.pixelLeft;
	}
	if(IsInFrame(DestTop, ElementHeight, FrameTop, FrameHeight)) {
		objElement.style.pixelTop = DestTop;
		objOutTop.value = objElement.style.pixelTop;
	}
}

function CropElement(objElement, objOuterLeft, objOuterTop, objOuterWidth, objOuterHeight, objInnerLeft, objInnerTop, Direction, DeltaX, DeltaY, FrameLeft, FrameTop, FrameWidth, FrameHeight) {
	var RotateMode = GetRotateMode(objElement);
	var FlipMode = GetFlipMode(objElement);
	var OuterLeft, OuterTop, OuterWidth, OuterHeight;
	var InnerLeft, InnerTop;
	
	OuterLeft = objElement.style.pixelLeft;
	OuterTop = objElement.style.pixelTop;
	InnerLeft = objElement.children[0].style.pixelLeft;
	InnerTop = objElement.children[0].style.pixelTop;
	if(Direction == 6 || Direction == 7 || Direction == 8) {
		OuterLeft = OuterLeft + DeltaX;
		if(RotateMode == 0 || RotateMode == 2) {
			OuterWidth = objElement.style.pixelWidth - DeltaX;
		} else {
			OuterHeight = objElement.style.pixelHeight  - DeltaX;
		}
		if((RotateMode == 0 && (FlipMode == 0 || FlipMode == 2)) || (RotateMode == 2 && (FlipMode == 1 || FlipMode == 3)))
			InnerLeft = InnerLeft - DeltaX;
		else if((RotateMode == 3 && (FlipMode == 0 || FlipMode == 2)) || (RotateMode == 1 && (FlipMode == 1 || FlipMode == 3)))
			InnerTop = InnerTop - DeltaX;
	} else if(Direction == 2 || Direction == 3 || Direction == 4) {
		if(RotateMode == 0 || RotateMode == 2) {
			OuterWidth = objElement.style.pixelWidth + DeltaX;
		} else {
			OuterHeight = objElement.style.pixelHeight  + DeltaX;
		}
		if((RotateMode == 1 && (FlipMode == 0 || FlipMode == 2)) || (RotateMode == 3 && (FlipMode == 1 || FlipMode == 3)))
			InnerTop = InnerTop + DeltaX;
		else if((RotateMode == 2 && (FlipMode == 0 || FlipMode == 2)) || (RotateMode == 0 && (FlipMode == 1 || FlipMode == 3)))
			InnerLeft = InnerLeft + DeltaX;
	}
	if(Direction == 8 || Direction == 1 || Direction == 2) {
		OuterTop = OuterTop + DeltaY;
		if(RotateMode == 0 || RotateMode == 2) {
			OuterHeight = objElement.style.pixelHeight  - DeltaY;
		} else {
			OuterWidth = objElement.style.pixelWidth - DeltaY;
		}
		if((RotateMode == 0 && (FlipMode == 0 || FlipMode == 2)) || (RotateMode == 2 && (FlipMode == 1 || FlipMode == 3)))
			InnerTop = InnerTop - DeltaY;
		else if((RotateMode == 1 && (FlipMode == 0 || FlipMode == 2)) || (RotateMode == 3 && (FlipMode == 1 || FlipMode == 3)))
			InnerLeft = InnerLeft - DeltaY;
	} else if(Direction == 4 || Direction == 5 || Direction == 6) {
		if(RotateMode == 0 || RotateMode == 2) {
			OuterHeight = objElement.style.pixelHeight  + DeltaY;
		} else {
			OuterWidth = objElement.style.pixelWidth + DeltaY;
		}
		if((RotateMode == 2 && (FlipMode == 0 || FlipMode == 2)) || (RotateMode == 0 && (FlipMode == 1 || FlipMode == 3)))
			InnerTop = InnerTop + DeltaY;
		else if((RotateMode == 3 && (FlipMode == 0 || FlipMode == 2)) || (RotateMode == 1 && (FlipMode == 1 || FlipMode == 3)))
			InnerLeft = InnerLeft + DeltaY;
	}
	if(RotateMode == 0 || RotateMode == 2) {
		if(IsInFrame(OuterLeft, OuterWidth, FrameLeft, FrameWidth) && IsInOuter(OuterLeft, OuterWidth, InnerLeft, objElement.children[0].style.pixelWidth) && OuterWidth >= gnDeltaSize) {
			objElement.style.pixelLeft = OuterLeft;
			objOuterLeft.value = objElement.style.pixelLeft;
			objElement.style.pixelWidth = OuterWidth;
			objOuterWidth.value = objElement.style.pixelWidth;
			objElement.children[0].style.pixelLeft = InnerLeft;
			objInnerLeft.value = objElement.children[0].style.pixelLeft;
		}
		if(IsInFrame(OuterTop, OuterHeight, FrameTop, FrameHeight) && IsInOuter(OuterTop, OuterHeight, InnerTop, objElement.children[0].style.pixelHeight) && OuterHeight >= gnDeltaSize) {
			objElement.style.pixelTop = OuterTop;
			objOuterTop.value = objElement.style.pixelTop;
			objElement.style.pixelHeight = OuterHeight;
			objOuterHeight.value = objElement.style.pixelHeight;
			objElement.children[0].style.pixelTop = InnerTop;
			objInnerTop.value = objElement.children[0].style.pixelTop;
		}
	} else {
		if(IsInFrame(OuterLeft, OuterHeight, FrameLeft, FrameWidth) && IsInOuter(OuterLeft, OuterHeight, InnerTop, objElement.children[0].style.pixelHeight) && OuterHeight >= gnDeltaSize) {
			objElement.style.pixelLeft = OuterLeft;
			objOuterLeft.value = objElement.style.pixelLeft;
			objElement.style.pixelHeight = OuterHeight;
			objOuterHeight.value = objElement.style.pixelHeight;
			objElement.children[0].style.pixelTop = InnerTop;
			objInnerTop.value = objElement.children[0].style.pixelTop;
		}
		if(IsInFrame(OuterTop, OuterWidth, FrameTop, FrameHeight) && IsInOuter(OuterTop, OuterWidth, InnerLeft, objElement.children[0].style.pixelWidth) && OuterWidth >= gnDeltaSize) {
			objElement.style.pixelTop = OuterTop;
			objOuterTop.value = objElement.style.pixelTop;
			objElement.style.pixelWidth = OuterWidth;
			objOuterWidth.value = objElement.style.pixelWidth;
			objElement.children[0].style.pixelLeft = InnerLeft;
			objInnerLeft.value = objElement.children[0].style.pixelLeft;
		}
	}
}

function ResizeElement(objElement, objOuterLeft, objOuterTop, objOuterWidth, objOuterHeight, objInnerLeft, objInnerTop, objInnerWidth, objInnerHeight, Direction, DeltaX, DeltaY, FrameLeft, FrameTop, FrameWidth, FrameHeight) {
	var RotateMode = GetRotateMode(objElement);
	var FlipMode = GetFlipMode(objElement);
	var OuterLeft, OuterTop, OuterWidth, OuterHeight;
	var InnerLeft, InnerTop, InnerWidth, InnerHeight;

	OuterLeft = objElement.style.pixelLeft;
	OuterTop = objElement.style.pixelTop;
	if(Direction == 6 || Direction == 7 || Direction == 8) {
		OuterLeft = OuterLeft + DeltaX;
		if(RotateMode == 0 || RotateMode == 2) {
			OuterWidth = objElement.style.pixelWidth - DeltaX;
			InnerWidth = Math.round(OuterWidth * CroppedWidthRate);
			InnerLeft = - Math.round(InnerWidth * CroppedLeftRate);
		} else {
			OuterHeight = objElement.style.pixelHeight  - DeltaX;
			InnerHeight = Math.round(OuterHeight * CroppedHeightRate);
			InnerTop = - Math.round(InnerHeight * CroppedTopRate);
		}
	} else if(Direction == 2 || Direction == 3 || Direction == 4) {
		if(RotateMode == 0 || RotateMode == 2) {
			OuterWidth = objElement.style.pixelWidth + DeltaX;
			InnerWidth = Math.round(OuterWidth * CroppedWidthRate);
			InnerLeft = - Math.round(InnerWidth * CroppedLeftRate);
		} else {
			OuterHeight = objElement.style.pixelHeight  + DeltaX;
			InnerHeight = Math.round(OuterHeight * CroppedHeightRate);
			InnerTop = - Math.round(InnerHeight * CroppedTopRate);
		}
	}
	if(Direction == 8 || Direction == 1 || Direction == 2) {
		OuterTop = OuterTop + DeltaY;
		if(RotateMode == 0 || RotateMode == 2) {
			OuterHeight = objElement.style.pixelHeight  - DeltaY;
			InnerHeight = Math.round(OuterHeight * CroppedHeightRate);
			InnerTop = - Math.round(InnerHeight * CroppedTopRate);
		} else {
			OuterWidth = objElement.style.pixelWidth - DeltaY;
			InnerWidth = Math.round(OuterWidth * CroppedWidthRate);
			InnerLeft = - Math.round(InnerWidth * CroppedLeftRate);
		}
	} else if(Direction == 4 || Direction == 5 || Direction == 6) {
		if(RotateMode == 0 || RotateMode == 2) {
			OuterHeight = objElement.style.pixelHeight  + DeltaY;
			InnerHeight = Math.round(OuterHeight * CroppedHeightRate);
			InnerTop = - Math.round(InnerHeight * CroppedTopRate);
		} else {
			OuterWidth = objElement.style.pixelWidth + DeltaY;
			InnerWidth = Math.round(OuterWidth * CroppedWidthRate);
			InnerLeft = - Math.round(InnerWidth * CroppedLeftRate);
		}
	}
	if(RotateMode == 0 || RotateMode == 2) {
		if(IsInFrame(OuterLeft, OuterWidth, FrameLeft, FrameWidth) && IsInOuter(OuterLeft, OuterWidth, InnerLeft, InnerWidth) && OuterWidth >= gnDeltaSize) {
			objElement.style.pixelLeft = OuterLeft;
			objOuterLeft.value = objElement.style.pixelLeft;
			objElement.style.pixelWidth = OuterWidth;
			objOuterWidth.value = objElement.style.pixelWidth;
			objElement.children[0].style.pixelLeft = InnerLeft;
			objInnerLeft.value = objElement.children[0].style.pixelLeft;
			objElement.children[0].style.pixelWidth = InnerWidth;
			objInnerWidth.value = objElement.children[0].style.pixelWidth;
			for(var i = 0; i < objElement.children[0].children.length; i ++)
				objElement.children[0].children[i].style.pixelWidth = InnerWidth;
		}
		if(IsInFrame(OuterTop, OuterHeight, FrameTop, FrameHeight) && IsInOuter(OuterTop, OuterHeight, InnerTop, InnerHeight) && OuterHeight >= gnDeltaSize) {
			objElement.style.pixelTop = OuterTop;
			objOuterTop.value = objElement.style.pixelTop;
			objElement.style.pixelHeight = OuterHeight;
			objOuterHeight.value = objElement.style.pixelHeight;
			objElement.children[0].style.pixelTop = InnerTop;
			objInnerTop.value = objElement.children[0].style.pixelTop;
			objElement.children[0].style.pixelHeight = InnerHeight;
			objInnerHeight.value = objElement.children[0].style.pixelHeight;
			for(var i = 0; i < objElement.children[0].children.length; i ++)
				objElement.children[0].children[i].style.pixelHeight = InnerHeight;
		}
	} else {
		if(IsInFrame(OuterLeft, OuterHeight, FrameLeft, FrameWidth) && IsInOuter(OuterLeft, OuterHeight, InnerTop, InnerHeight) && OuterHeight >= gnDeltaSize) {
			objElement.style.pixelLeft = OuterLeft;
			objOuterLeft.value = objElement.style.pixelLeft;
			objElement.style.pixelHeight = OuterHeight;
			objOuterHeight.value = objElement.style.pixelHeight;
			objElement.children[0].style.pixelTop = InnerTop;
			objInnerTop.value = objElement.children[0].style.pixelTop;
			objElement.children[0].style.pixelHeight = InnerHeight;
			objInnerHeight.value = objElement.children[0].style.pixelHeight;
			for(var i = 0; i < objElement.children[0].children.length; i ++)
				objElement.children[0].children[i].style.pixelHeight = InnerHeight;
		}
		if(IsInFrame(OuterTop, OuterWidth, FrameTop, FrameHeight) && IsInOuter(OuterTop, OuterWidth, InnerLeft, InnerWidth) && OuterWidth >= gnDeltaSize) {
			objElement.style.pixelTop = OuterTop;
			objOuterTop.value = objElement.style.pixelTop;
			objElement.style.pixelWidth = OuterWidth;
			objOuterWidth.value = objElement.style.pixelWidth;
			objElement.children[0].style.pixelLeft = InnerLeft;
			objInnerLeft.value = objElement.children[0].style.pixelLeft;
			objElement.children[0].style.pixelWidth = InnerWidth;
			objInnerWidth.value = objElement.children[0].style.pixelWidth;
			for(var i = 0; i < objElement.children[0].children.length; i ++)
				objElement.children[0].children[i].style.pixelWidth = InnerWidth;
		}
	}
}

function IsInFrame(DestStart, DestSize, FrameStart, FrameSize) {
	if(DestStart + DestSize - 1 >= FrameStart + gnDeltaSize && DestStart <= FrameStart + FrameSize - gnDeltaSize - 1)
		return true;
	return false;
}

function IsInOuter(OuterStart, OuterSize, InnerStart, InnerSize) {
	if(InnerStart <= 0 && InnerStart + InnerSize >= OuterSize)
		return true;
	return false;
}

function GetRotateMode(objElement) {
	return objElement.filters(0).rotation;
}

function GetFlipMode(objElement) {
	return (objElement.filters(2).enabled ? 1 : 0) * 2 + (objElement.filters(1).enabled ? 1 : 0);
}

function GetDirectionByKey(IsZoomIn, IsZoomOut, DeltaX, DeltaY) {
	var Direction;
	
	Direction = 0;
	if(DeltaX == 0 && ((IsZoomIn && DeltaY < 0) || (IsZoomOut && DeltaY > 0)))
		Direction = 1;
	else if(((IsZoomIn && DeltaX > 0) || (IsZoomOut && DeltaX < 0)) && ((IsZoomIn && DeltaY < 0) || (IsZoomOut && DeltaY > 0)))
		Direction = 2;
	else if(((IsZoomIn && DeltaX > 0) || (IsZoomOut && DeltaX < 0)) && DeltaY == 0)
		Direction = 3;
	else if(((IsZoomIn && DeltaX > 0) || (IsZoomOut && DeltaX < 0)) && ((IsZoomIn && DeltaY > 0) || (IsZoomOut && DeltaY < 0)))
		Direction = 4;
	else if(DeltaX == 0 && ((IsZoomIn && DeltaY > 0) || (IsZoomOut && DeltaY < 0)))
		Direction = 5;
	else if(((IsZoomIn && DeltaX < 0) || (IsZoomOut && DeltaX > 0)) && ((IsZoomIn && DeltaY > 0) || (IsZoomOut && DeltaY < 0)))
		Direction = 6;
	else if(((IsZoomIn && DeltaX < 0) || (IsZoomOut && DeltaX > 0)) && DeltaY == 0)
		Direction = 7;
	else if(((IsZoomIn && DeltaX < 0) || (IsZoomOut && DeltaX > 0)) && ((IsZoomIn && DeltaY < 0) || (IsZoomOut && DeltaY > 0)))
		Direction = 8;
	return Direction;
}

function GetElementByType(ObjType, ObjID) {
	if(ObjType == "PhotoName") {
		return document.getElementById("PhotoNameBorder");
	} else if(ObjType == "PhotoDate") {
		return document.getElementById("PhotoDateBorder");
	} else if(ObjType == "UserName") {
		return document.getElementById("UserNameBorder_" + ObjID);
	} else if(ObjType == "Avatar") {
		return document.getElementById("AvatarBorder_" + ObjID);
	} else if(ObjType == "Accouterment") {
		return document.getElementById("AccoutermentBorder_" + ObjID);
	}
	return false;
}

function ShowPageList(CurPage, PageSize, TotalRec, URLStr) {
	var PageCount, TempStr = '', StartPage, EndPage;

	if(TotalRec % PageSize == 0)
		PageCount = TotalRec / PageSize;
	else
		PageCount = Math.floor(TotalRec / PageSize) + 1;
	TempStr = TempStr + '<table class="Tableborder5" cellpadding="0" cellspacing="1" align="center"><form action="' + URLStr + '" method="post" name="PageForm">\n';
	TempStr = TempStr + '<tr align="center" height="20">\n';
	TempStr = TempStr + '<td class="tabletitle1" title="合计数">&nbsp;' + TotalRec + '&nbsp;</td>\n';
	TempStr = TempStr + '<td class="tabletitle1" title="本页数">&nbsp;';
	if(CurPage == PageCount)
		TempStr = TempStr + (TotalRec - (PageSize * (CurPage - 1)));
	else
		TempStr = TempStr + PageSize;
	TempStr = TempStr + '&nbsp;</td>\n';
	TempStr = TempStr + '<td class="tabletitle1">&nbsp;' + CurPage + '/' + PageCount + '页&nbsp;</td>\n';
	if(CurPage == 1)
		TempStr = TempStr + '<td class="tablebody1">&nbsp;<img src="images/pagelist/First.gif" border="0" alt="">&nbsp;</td>\n';
	else
		TempStr = TempStr + '<td class="tablebody1">&nbsp;<a href="' + URLStr + '&page=1"><img src="images/pagelist/First.gif" border="0" alt="首页"/></a>&nbsp;</td>\n';
	if(CurPage > 11)
		TempStr = TempStr + '<td class="tablebody1">&nbsp;<a href="' + URLStr + '&page=' + (CurPage - 10) + '"><img src="images/pagelist/Previous.gif" border="0" alt="前十页"/></a>&nbsp;</td>\n';
	if(CurPage < 6)
		StartPage = 1;
	else
		StartPage = CurPage - 5;
	if(CurPage + 9 < PageCount)
		EndPage = StartPage + 9;
	else
		EndPage = PageCount;
	TempStr = TempStr + ShowOnePage(StartPage, EndPage, URLStr, CurPage);
	if(PageCount > CurPage + 10)
		TempStr = TempStr + '<td class="tablebody1">&nbsp;<a href="' + URLStr + '&page=' + (CurPage + 10) + '"><img src="images/pagelist/Next.gif" border="0" alt="下十页"/></a>&mnsp;</td>\n';
	if(CurPage != PageCount)
		TempStr = TempStr + '<td class="tablebody1">&nbsp;<a href="' + URLStr + '&page=' + PageCount + '"><img src="images/pagelist/Last.gif" border="0" alt="尾页"/></a>&nbsp;</td>\n';
	else
		TempStr = TempStr + '<td class="tablebody1">&nbsp;<img src="images/pagelist/Last.gif" border="0" alt=""/>&nbsp;</td>\n';
	TempStr = TempStr + '<td class="tablebody1"><input type="text" name="page" size="1" value="' + CurPage + '" class="PageInput"/><input type="submit" value="GO" name="submit" class="PageInput"/></td>\n';
	TempStr = TempStr + '</tr></form></table>';
	document.write(TempStr);
}

function ShowOnePage(StartPage, EndPage, URLStr, CurPage) {
	var TempStr = '';
	
	if(CurPage != StartPage)
		TempStr = TempStr + '<td class="tablebody1">&nbsp;<a href="' + URLStr + '&page=' + StartPage + '">' + StartPage + '</a>&nbsp;</td>\n';
	else
		TempStr = TempStr + '<td class="tablebody2">&nbsp;<font class="normalTextSmall"><u><b>' + StartPage + '</b></u></font>&nbsp;</td>\n';
	if(EndPage > StartPage)
		TempStr = TempStr + ShowOnePage(StartPage + 1, EndPage, URLStr, CurPage);
	return TempStr;
}

function TryTool(CurItemID, CurItemLayer, CurItemSex, CurItemPeriod) {
	var CurTD, ParentTBody;
	
	if(CurItemSex != '2' && CurItemSex != UserSex) {
		alert("性别不符，无法使用！");
		return;
	}
	if(!event) return;
	if(!event.srcElement) return;
	CurTD = event.srcElement.parentElement;
	if(CurTD.className == 'TableBody1') return;
	ParentTBody = CurTD.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
	for(var i = 0; i < ParentTBody.children.length; i ++)
		for(var j = 0; j < ParentTBody.children[i].children.length; j ++)
			for(var k = 0; k < ParentTBody.children[i].children[j].children[0].children[1].children.length; k ++)
				if(k == 2) {
					ParentTBody.children[i].children[j].children[0].children[1].children[k].children[0].className = "TableBody2";
					ParentTBody.children[i].children[j].children[0].children[1].children[k].children[1].className = "TableBody2";
				} else
					ParentTBody.children[i].children[j].children[0].children[1].children[k].children[0].className = "TableBody2";
	CurTD.className = 'TableBody1';
	CurTD.parentElement.parentElement.children[1].children[0].className = 'TableBody1';
	CurTD.parentElement.parentElement.children[2].children[0].className = 'TableBody1';
	CurTD.parentElement.parentElement.children[2].children[1].className = 'TableBody1';
	document.getElementById("ItemID").value = CurItemID;
	CurPeriod = parseInt(CurItemPeriod)
	NewAvatar = UserAvaSetting;
	var nPos = CurItemLayer.indexOf('_');
	if(nPos < 0) {
		TakeOnSingle(CurItemLayer, CurItemID, UserSex);
	} else {
		TakeOnMulti(CurItemID, CurItemLayer, UserSex);
	}
	DvbbsShowAvatar(NewAvatar,'1','1','0',AvatarWidth,AvatarHeight,'0','0','0','0','0','0','0','0','',LocalPic,PicPath,'0','0',document.getElementById("UserName").value + '的虚拟形象','',document.getElementById("AvatarTD"));
}

function ConfirmUseTool() {
	if(CurPeriod < 0) {
		alert("过期道具，无法使用，请选择其他道具或者翻新后再使用！");
		return false;
	}
	return true;
}

function GetGenderItemID(ItemLayer, UserSex) {
	var ItemID;
	
	if(UserSex == '1') {
		switch(ItemLayer) {
			case '7':
				ItemID = 14;
				break;
			case '8':
				ItemID = 13;
				break;
			case '9':
				ItemID = 12;
				break;
			case '11':
				ItemID = 11;
				break;
			case '13':
				ItemID = 10;
				break;
			case '14':
				ItemID = 9;
				break;
			case '18':
				ItemID = 8;
				break;
			default:
				return -1;
		}
	} else {
		switch(ItemLayer) {
			case '7':
				ItemID = 7;
				break;
			case '8':
				ItemID = 6;
				break;
			case '9':
				ItemID = 5;
				break;
			case '11':
				ItemID = 4;
				break;
			case '13':
				ItemID = 3;
				break;
			case '14':
				ItemID = 2;
				break;
			case '18':
				ItemID = 1;
				break;
			default:
				return -1;
		}
	}
	return ItemID;
}

function GetPart(ItemLayer) {
	return NewAvatar.split("|")[ItemLayer - 1];
}

function TakeOnMulti(ItemID, layers, UserSex) {
	var layerArray = layers.split('_');
	var layerArrayLen = layerArray.length;	
	
	for(i = 0; i < layerArrayLen; i ++) {
		var genderItemID = GetGenderItemID(layerArray[i], UserSex);
		TakeOnSingle(layerArray[i], genderItemID, UserSex);
	}
	for(i = 0; i < layerArrayLen; i ++) {
		TakeOnSingle(layerArray[i], ItemID, UserSex);
	}
}

function TakeOffMulti(layers, UserSex) {
	var layerArray = layers.split('_');
	var layerArrayLen = layerArray.length;
	
	for(i=0; i < layerArrayLen; i++) {
		TakeOffSingle(layerArray[i], UserSex);
	}
}

function TakeOnSingle(ItemLayer, ItemID, UserSex) {
	var t = GetPart(ItemLayer);
	var nPos = t.indexOf('_');

	if (nPos < 0) {
		TakeLayer(ItemLayer, ItemID);
		return 0;
	} else {
		var layerArray = t.split('.');		
		TakeOffMulti(layerArray[1], UserSex);
		return 0;
	}
}

function TakeOffSingle(ItemLayer, UserSex) {
	SetGenderIMG(ItemLayer, UserSex);
}

function SetGenderIMG(ItemLayer, UserSex) {
	var ItemID = GetGenderItemID(ItemLayer, UserSex);

	TakeLayer(ItemLayer, ItemID);
}

function TakeLayer(ItemLayer, ItemID) {
	var t, AvatarSplit = NewAvatar.split("|");

	t = GetPart(ItemLayer);
	if(ItemID == -1) {
		AvatarSplit[ItemLayer - 1] = "";
	} else {
		AvatarSplit[ItemLayer - 1] = ItemID + '.' + ItemLayer;
	}
	NewAvatar = "";
	for(var i = 0; i < AvatarSplit.length; i ++) {
		if(i > 0) NewAvatar += "|";
		NewAvatar += AvatarSplit[i];
	}
}
