﻿var Diy2008 = {

	//------------------------------------------------------
	onclick: function (e) {
	
		if (!e) e = window.event;
		
		var dom = (typeof e.target != "undefined")?e.target:e.srcElement;
		
		if(dom.nodeName=="IMG")
		{
			//alert(document.elementFromPoint(e.clientX,e.clientY))
		}
		if(dom.getAttribute("_hot_id"))
		{
			dom.getAttribute("_hot_id");
			//Diy2008.select_p = $(dom.getAttribute("_hot_id")).childNodes[0];
			Diy2008.select_p_on($(dom.getAttribute("_hot_id")).childNodes[0]);
			//alert(Diy2008.select_p.id);
		}
	},
	
	ondown: function (e) {
	
		if (!e) e = window.event;
		
		Diy2008.clientx = e.clientX;
		Diy2008.clienty = e.clientY;
		
		var dom = (typeof e.target != "undefined")?e.target:e.srcElement;
		if(dom.nodeName=="IMG"&&dom.className=="P")
		{
			$("pbox").innerHTML = "";
			$("pbox").style.display = '';
			
			var pdom = dom.cloneNode(true);
			$("pbox").style.left = e.clientX - 40 + "px";
			$("pbox").style.top = e.clientY - 40 + "px";
			$("pbox").style.zIndex = 100;
			
			Diy2008.dx = e.clientX - 40;
			Diy2008.dy = e.clientY - 40;
			
			$("pbox").appendChild(pdom);
			Diy2008.movedom = $("pbox");
			document.onmousemove = Diy2008.onmove;
			//$("ts").innerHTML = Diy2008.dx;
			Diy2008.photo_i = dom.getAttribute("_i");
		}
		if(dom.getAttribute("_on")=="move_left"||dom.getAttribute("_on")=="move_right")
		{
			Diy2008.down = true;
		}
	},
	
	onup: function (e) {
	
		if (!e) e = window.event;
		
		var dom = (typeof e.target != "undefined")?e.target:e.srcElement;
		document.onmousemove = null;
		$("pbox").style.display = 'none';
		
		if(dom.getAttribute("_on")=="move_left"||dom.getAttribute("_on")=="move_right")
		{
			Diy2008.down = false;
		}
		if(Diy2008.photo_i)
		{
			Diy2008.release = true;
		}
	},
	
	onmove: function (e)
	{
		if (!e) e = window.event;
		
		if (Diy2008.movedom)
		{
			Diy2008.movedom.style.left = Diy2008.dx + e.clientX - Diy2008.clientx + "px";
			if(_version)
			{
				if(_version<7.0)
				{
					Diy2008.movedom.style.top = (Diy2008.dy + e.clientY - Diy2008.clienty + document.documentElement.scrollTop) + "px";
				}
				else
				{
					Diy2008.movedom.style.top = Diy2008.dy + e.clientY - Diy2008.clienty + "px";
				}
			}
			else
			{
				Diy2008.movedom.style.top = Diy2008.dy + e.clientY - Diy2008.clienty + "px";
			}
		}
	},
	
	onout: function (e) {
	
		if (!e) e = window.event;
		
		var dom = (typeof e.target != "undefined")?e.target:e.srcElement;
		if(dom.nodeName=="IMG"&&dom.getAttribute("_replace"))
		{
			if(Diy2008.now_month_dom&&Diy2008.now_month_src)
			{
				Diy2008.now_month_dom.src = Diy2008.now_month_src;
				Diy2008.now_month_dom = null;
				Diy2008.now_month_src = null;
			}
		}
		
		if(dom.getAttribute("_on")=="move_left"||dom.getAttribute("_on")=="move_right")
		{
			Diy2008.move = false;
		}
	},
	
	onover: function (e)
	{
		if (!e) e = window.event;

		var dom = (typeof e.target != "undefined")?e.target:e.srcElement;
		if(dom.nodeName=="IMG"&&dom.getAttribute("_replace"))
		{
			Diy2008.now_month_dom = dom;
			Diy2008.now_month_src = dom.src;
			dom.src = dom.getAttribute("_replace");
		}
		
		if(dom.getAttribute("_on")=="move_right")
		{
			Diy2008.move_right_over();
		}
		if(dom.getAttribute("_on")=="move_left")
		{
			Diy2008.move_left_over();
		}
		//Diy2008.release释放
		if(Diy2008.photo_i)//已经选中照片
		{
			if(Diy2008.release)//已经释放照片
			{
				Diy2008.execution = true;
				if(!dom.getAttribute("_hot_id")) 
				{
					Diy2008.release = null;
					Diy2008.photo_i = null;
					return false;
				}
				//alert(Diy2008.photo_i + "\n" + $(dom.getAttribute("_hot_id")).innerHTML);
				//alert(dom.getAttribute("_hot_id"));
				var i = dom.getAttribute("_hot_id").replace(/hot_/gi,"")*1;
				var arrays = Diy2008.edit_month["hotzone"][i];
				var src_array = Diy2008.photo_list_array[Diy2008.photo_i];
				if(src_array["big_photo"])//如果存在大图片
				{
					if(src_array["width"]/src_array["height"]>arrays["width"]/arrays["height"])
					{
						var width = Math.ceil(src_array["width"] * arrays["height"]/src_array["height"]);
						$(dom.getAttribute("_hot_id")).innerHTML = '<img src="' + src_array["big_photo"] + '" alt="" width="' + width + '" height="' + arrays["height"] + '" id="p_' + Diy2008.edit_month_i + '_' + i + '" />';
						Diy2008.edit_month["hotzone"][i]["p_width"] = width;
						Diy2008.edit_month["hotzone"][i]["p_height"] = arrays["height"];
					}
					else
					{
						var height = Math.ceil(src_array["height"] * arrays["width"]/src_array["width"]);
						$(dom.getAttribute("_hot_id")).innerHTML = '<img src="' + src_array["big_photo"] + '" alt="" width="' + arrays["width"] + '" height="' + height + '" id="p_' + Diy2008.edit_month_i + '_' + i + '" />';
						Diy2008.edit_month["hotzone"][i]["p_height"] = height;
						Diy2008.edit_month["hotzone"][i]["p_width"] = arrays["width"];
					}
					
					/*$("p_" + Diy2008.edit_month_i + "_" + i).style.position = "relative";
					if(arrays["p_top"])
					{
						$("p_" + Diy2008.edit_month_i + "_" + i).style.top = arrays["p_top"] + "px";
					}
					if(arrays["p_left"])
					{
						$("p_" + Diy2008.edit_month_i + "_" + i).style.left = arrays["p_left"] + "px";
					}
					*/
					
					//Diy2008.select_p = $("p_" + Diy2008.edit_month_i + "_" + i);
					Diy2008.select_p_on($("p_" + Diy2008.edit_month_i + "_" + i));
					
					Diy2008.template[Diy2008.edit_month_i]["hotzone"][i]["insert_p"] = src_array["big_photo"];
					Diy2008.template[Diy2008.edit_month_i]["hotzone"][i]["insert_p_i"] = Diy2008.photo_i;
					
					//变换按钮效果
					$("month_" + Diy2008.edit_month_i).className = $("month_" + Diy2008.edit_month_i).getAttribute("_reclass");
				}
				else if(src_array["most_photo"])//如果存在超大图片
				{
					if(src_array["width"]/src_array["height"]>arrays["width"]/arrays["height"])
					{
						var width = Math.ceil(src_array["width"] * arrays["height"]/src_array["height"]);
						var height = arrays["height"];
						$(dom.getAttribute("_hot_id")).innerHTML = '<img src="' + src_array["most_photo"] + '" alt="" height="' + height + '" width="' + width + '" id="p_' + Diy2008.edit_month_i + '_' + i + '" />';
						Diy2008.edit_month["hotzone"][i]["p_width"] = width;
						Diy2008.edit_month["hotzone"][i]["p_height"] = arrays["height"];
					}
					else
					{
						var height = Math.ceil(src_array["height"] * arrays["width"]/src_array["width"]);
						var width = arrays["width"];
						$(dom.getAttribute("_hot_id")).innerHTML = '<img src="' + src_array["most_photo"] + '" alt="" width="' + width + '" height="' + height + '" id="p_' + Diy2008.edit_month_i + '_' + i + '" />';
						Diy2008.edit_month["hotzone"][i]["p_height"] = height;
						Diy2008.edit_month["hotzone"][i]["p_width"] = arrays["width"];
					}
					
					/*
					if(arrays["p_top"])
					{
						$("p_" + Diy2008.edit_month_i + "_" + i).style.position = "relative";
						$("p_" + Diy2008.edit_month_i + "_" + i).style.top = arrays["p_top"] + "px";
					}
					if(arrays["p_left"])
					{
						$("p_" + Diy2008.edit_month_i + "_" + i).style.left = arrays["p_left"] + "px";
					}
					*/
					//Diy2008.select_p = $("p_" + Diy2008.edit_month_i + "_" + i);
					Diy2008.select_p_on($("p_" + Diy2008.edit_month_i + "_" + i));
					
					Diy2008.template[Diy2008.edit_month_i]["hotzone"][i]["insert_p"] = src_array["most_photo"];
					Diy2008.template[Diy2008.edit_month_i]["hotzone"][i]["insert_p_i"] = Diy2008.photo_i;
					Diy2008.template[Diy2008.edit_month_i]["hotzone"][i]["p_width"] = width;
					Diy2008.template[Diy2008.edit_month_i]["hotzone"][i]["p_height"] = height;
					$("month_" + Diy2008.edit_month_i).className = $("month_" + Diy2008.edit_month_i).getAttribute("_reclass");
				}
				Diy2008.photo_i = null;
				Diy2008.release = null;
				//width:"1920",
				//height:"2560",
				//most_photo:"/album/upload/25883/ac9cf312b8/2ba0a.jpg",
				//small_photo:"/album/photo_view/25883/ac9cf312b8/117de.jpg",
				//big_photo:"/album/photo_view/25883/ac9cf312b8/8f751.jpg",
				
				Diy2008.adjust_photo('vertical');//垂直居中
				Diy2008.adjust_photo('level');//水平居中
			}
		}
	},
	//------------------------------------------------------
	
	move_left_over: function () {
	
		var _L = $("photo_box").style.left;
		if(!_L) 
			_L = 0;
		else
			_L = _px(_L);
			
		if(Diy2008.down)
		{
			$("photo_box").style.left = (_L-10) + "px";
		}
		else
		{
			$("photo_box").style.left = (_L-2) + "px";
		}
		
		if(Diy2008.move)
		{
			setTimeout("Diy2008.move_left_over()",50);
		}
		else
		{
			Diy2008.move = true;
		}
	},

	move_right_over: function () {
	
		var _L = $("photo_box").style.left;
		if(!_L) 
			_L = 0;
		else
			_L = _px(_L);
		
		if(_L<0)
		if(Diy2008.down)
		{
			$("photo_box").style.left = (_L+10) + "px";
		}
		else
		{
			$("photo_box").style.left = (_L+2) + "px";
		}
		
		if(Diy2008.move)
		{
			setTimeout("Diy2008.move_right_over()",50);
		}
		else
		{
			Diy2008.move = true;
		}
		
	},
	
	move: true, down:false,
	
	//------------------------------------------------------
	//---------------------生成月份表-----------------------
	//------------------------------------------------------
	
	export_month: function (array,array_name,x,y) {
	
		Diy2008.array_name = array_name;
		if(array&&array.length>0)
		{
			var HTML = '<table height="40" border="0" cellpadding="0" cellspacing="0" id="month_box"><tr>';
			var I,J;
			I = x? ((x>0)?x-1:0):0;
			J = y?(((y<array.length)?y:array.length)):array.length;
			Diy2008.month_be = I;//开始月份
			Diy2008.month_en = J;//结束月份
			Diy2008.fixed_be = I;//开始限制
			Diy2008.fixed_en = J;//结束限制
			
			var exit = false;
			for(var i= I; i<J; i++)
			{
				exit = false;
				for(var j=0; j<array[i]["hotzone"].length; j++)
				{
					arrays = array[i]["hotzone"][j];
					var src = null;
					if(arrays["insert_p"])
					{
						exit = true;
					}
				}
				if(exit)
				{
					HTML += '<td align="center"><div id="month_' + i + '" class="div23x20" onclick="Diy2008.export_template(' + array_name + '[' + i + '],' + i + ')" _reclass="div23x20r">' + (i+1) + '</div></td>';
				}
				else
				{
					HTML += '<td align="center"><div id="month_' + i + '" class="div23x20" onclick="Diy2008.export_template(' + array_name + '[' + i + '],' + i + ')" _reclass="div23x20r">' + (i+1) + '</div></td>';
				}
				/*
				if(exit)
				{
					HTML += '<td align="center"><img src="' + array[i]["month_p_r"] + '" border="0" _replace="' + array[i]["month_p_r"] + '" onclick="Diy2008.export_template(' + array_name + '[' + i + '],' + i + ')" _month="true" id = "month_' + i + '" onload="Diy2008.img_onload(this,' + i + ');" /></td>';
				}
				else
				{
					HTML += '<td align="center"><img src="' + array[i]["month_p"] + '" border="0" _replace="' + array[i]["month_p_r"] + '" onclick="Diy2008.export_template(' + array_name + '[' + i + '],' + i + ')" _month="true" id = "month_' + i + '" onload="Diy2008.img_onload(this,' + i + ');" /></td>';
				}*/
			}
			HTML += '</tr></table>';
			
			$("month_list").innerHTML = HTML;
			Diy2008.export_template(Diy2008.template[0],0);
		}
		
	},
	
	img_onload: function (dom,i) {
	
		if(dom)
		{
			if(Diy2008.template[i])
			{
				Diy2008.template[i]["month_dom"] = dom.parentNode;
			}
		}
		if(i==Diy2008.fixed_be&&!Diy2008.default_edit)
		{
			Diy2008.export_template(Diy2008.template[i],i);
			Diy2008.default_edit = true;
		}
		
	},
	//------------------------------------------------------
	
	//------------------------------------------------------
	//----------------------生成模板------------------------
	//------------------------------------------------------
	export_template: function (array,I) {
	
		if(array)
		{
			Diy2008.edit_month_i = I;
			var arrays;
			
			var HTML = '<table width="' + array["tel_w"] + '" height="' + array["tel_h"] + '" border="0" cellpadding="0" cellspacing="0"><tr><td align="left" valign="top">';
			HTML += '<div style="width:' + array["tel_w"] + 'px;height:' + array["tel_h"] + 'px;overflow:hidden;">';
			
			//---模板响应区域
			HTML += '<div style="background-color: #FFFFFF;filter:alpha(opacity=0);-moz-opacity:0;z-index: 20;position: absolute;width:' + array["tel_w"] + 'px;height:' + array["tel_h"] + 'px;overflow:hidden;">';
			
			for(var i=0; i<array["hotzone"].length; i++)
			{
				arrays = array["hotzone"][i];
				HTML += '<div style="background-color: #FFFFFF;filter:alpha(opacity=0);-moz-opacity:0;position: relative;width:' + arrays["width"] + 'px;height: ' + arrays["height"] + 'px;left: ' + arrays["left"] + 'px;top: ' + arrays["top"] + 'px;" _hot_id="hot_' + i + '"></div>';
			}
			
			HTML += '</div>';
			//---
			
			//---模板区域
			
			if (_version >= 5.5 && _version < 7.0) 
			{
				var _tel_p_z = array["tel_p_z"].slice(0,-4) + ".gif";
			}
			else
			{
				var _tel_p_z = array["tel_p_z"];
			}
	
			HTML += '<div style="position: absolute;z-index: 10;"><img src="' + _tel_p_z + '" width="' + array["tel_w"] + '" height="' + array["tel_h"] + '" /></div>';
			//<div style="position: absolute;z-index: 10;border: 1px dashed #CCCCCC;">
			//HTML += '<div style="position: absolute;z-index: 10;"><img src="' + array["tel_p_z"] + '" width="' + array["tel_w"] + '" height="' + array["tel_h"] + '" /></div>';
			for(var i=0; i<array["hotzone"].length; i++)
			{
				arrays = array["hotzone"][i];
				var src = null;
				if(arrays["insert_p"])
				{
					var src = arrays["insert_p"];
				}
				else if(arrays["def_p"])
				{
					var src = arrays["def_p"];
				}
				if(src)
				{
					var style = "style=\"position: relative;";
					if(arrays["p_top"])
					{
						style += "top:" + arrays["p_top"] + "px;";
					}
					if(arrays["p_left"])
					{
						style += "left:" + arrays["p_left"] + "px;";
					}
					
					style += "\"";
					HTML += '<div style="overflow: hidden;height: ' + arrays["height"] + 'px;width: ' + arrays["width"] + 'px;position: relative;left: ' + arrays["left"] + 'px;top: ' + arrays["top"] + 'px;background-image: url(/diy/images/new/diy/no_photo_bj.gif);background-repeat: repeat;" id="hot_' + i + '">';
					
					if (arrays["p_width"])
					{
						var width = 'width="' + arrays["p_width"] + '"';
					}
					else
					{
						var width = 'width="' + arrays["width"] + '"';
					}
					
					if (arrays["p_height"])
					{
						var height = ' height="' + arrays["p_height"] + '"';
					}
					else
					{
						height = '';
					}
					
					HTML += '<img src="' + src + '" alt="" ' + width + height + ' id="p_' + Diy2008.edit_month_i + '_' + i + '"' + style + ' /></div>';
					var _id = "p_" + Diy2008.edit_month_i + "_" + i;
				}
				else
				{
					HTML += '<div style="overflow: hidden;height: ' + arrays["height"] + 'px;width: ' + arrays["width"] + 'px;position: relative;left: ' + arrays["left"] + 'px;top: ' + arrays["top"] + 'px;background-image: url(/diy/images/new/diy/no_photo_bj.gif);background-repeat: repeat;" id="hot_' + i + '"></div>';
				}
			}
			//---
			
			HTML += '</td></tr></table>';
			HTML += '</div>';
			
			$("template_box_z").innerHTML = HTML;
			
			//Diy2008.select_p = $(_id);
			
			Diy2008.select_p_on($(_id));
			//Diy2008.show_edit(array["month_dom"]);
			Diy2008.show_edit($('month_' + I).parentNode);
			Diy2008.edit_month = array;
			Diy2008.save_html(I);
			
			//显示额外的
			if(Diy2008.template[I]["superfluity"]) 
			document.orders.superfluity.value = Diy2008.template[I]["superfluity"];
			else
			document.orders.superfluity.value = "";
		}
		
	},
	
	//显示正在编辑图标
	show_edit: function (dom) {
		if(!Diy2008.div_exit||!Diy2008.div_exit.parentNode)
		{
			var div_exit = document.createElement("div");
			div_exit.style.position = "absolute";
			
			var img_exit = document.createElement("img");
			img_exit.src = "/diy/images/new/diy/exit1.gif";
			img_exit.style.position = "relative";
			if (navigator.appName=="Microsoft Internet Explorer")
			{
				img_exit.style.left = "-7px";
				img_exit.style.top = "-18px";
			}
			else
			{
				img_exit.style.left = "5px";
				img_exit.style.top = "-18px";
			}
			div_exit.appendChild(img_exit);
				
			dom.appendChild(div_exit);
			Diy2008.div_exit = div_exit;
		}
		else
		{
			div_exit = Diy2008.div_exit.parentNode.removeChild(Diy2008.div_exit);
			dom.appendChild(div_exit);
			Diy2008.div_exit = div_exit;
		}
	},
	//------------------------------------------------------
	
	//------------------------------------------------------
	//----------------------增减月份------------------------
	//------------------------------------------------------
	
	alter_month: function (x,y) {
	
		if(x)//0:首 1:尾
		{
			if(y)//0:减 1:加
			{
				if(Diy2008.month_en<Diy2008.template.length)
				{
					var array = Diy2008.template[Diy2008.month_en];
					var td = $("month_box").rows[0].insertCell($("month_box").rows[0].cells.length);
					td.innerHTML = '<img src="' + array["month_p"] + '" border="0" _replace="' + array["month_p_r"] + '" onclick="Diy2008.export_template(' + Diy2008.array_name + '[' + Diy2008.month_en + '],' + Diy2008.month_en + ')" _month="true" id = "month_' + Diy2008.month_en + '" onload="Diy2008.img_onload(this,' + Diy2008.month_en + ');"  />';
					Diy2008.month_en++;
				}
			}
			else
			{
				if(Diy2008.month_en>Diy2008.fixed_en)
				{
					//alert(Diy2008.edit_month["month_dom"].innerHTML + "\n" + $("month_box").rows[0].cells[$("month_box").rows[0].cells.length-1].innerHTML);
					if(Diy2008.edit_month["month_dom"] == $("month_box").rows[0].cells[$("month_box").rows[0].cells.length-1])
					{
						Diy2008.export_template(Diy2008.template[Diy2008.month_en-2],Diy2008.month_en-2);
					}
					$("month_box").rows[0].deleteCell($("month_box").rows[0].cells.length-1);
					Diy2008.month_en--;
				}
			}
		}
		else
		{
			if(y)//0:减 1:加
			{
				if(Diy2008.month_be>0)
				{
					var array = Diy2008.template[--Diy2008.month_be];
					var td = $("month_box").rows[0].insertCell(0);
					td.innerHTML = '<img src="' + array["month_p"] + '" border="0" _replace="' + array["month_p_r"] + '" onclick="Diy2008.export_template(' + Diy2008.array_name + '[' + Diy2008.month_be + '],' + Diy2008.month_be + ')" _month="true" id = "month_' + Diy2008.month_be + '" onload="Diy2008.img_onload(this,' + Diy2008.month_be + ');"  />';
				}
			}
			else
			{
				if(Diy2008.month_be<Diy2008.fixed_be)
				{
					//alert(Diy2008.edit_month);
					if(Diy2008.edit_month["month_dom"] == $("month_box").rows[0].cells[0])
					{
						Diy2008.export_template(Diy2008.template[Diy2008.month_be+1],Diy2008.month_be+1);
					}
					$("month_box").rows[0].deleteCell(0);
					Diy2008.month_be++;
				}
				
			}
		}
		
	},
	//------------------------------------------------------
	
	//------------------------------------------------------
	//----------------------相片列表------------------------
	//------------------------------------------------------
	
	photo_list: function (array) {
		if(array&&array.length>0)
		{
			var HTML = '<table border="0" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF"><tr>';
			for(var i=0; i<array.length; i++)
			{
				if(array[i]["small_photo"])
				{
					HTML += '<td align="center" nowrap="nowrap"><img src="' + array[i]["small_photo"] + '" onmousedown="return false;"  onmousemove="return false;" height="80" class="P" _i="' + i + '" /></td>';
				}
				else if(array[i]["big_photo"])
				{
					HTML += '<td align="center" nowrap="nowrap"><img src="' + array[i]["big_photo"] + '" onmousedown="return false;"  onmousemove="return false;" height="80" class="P" _i="' + i + '" /></td>';
				}
			}
			HTML += '</tr></table>';
			
			$("photo_box").innerHTML = HTML;
		}
		else
		{
			if(!COOKIE.ReadCookie("users_username"))
				$("photo_box").innerHTML = '请<a href="/users/enter.php" target="_blank">登录</a>';
			else
				$("photo_box").innerHTML = '请<a href="/album/" target="_blank">上传照片</a>';
		}
		Diy2008.photo_list_array = array;
	},
	//------------------------------------------------------
	
	//------------------------------------------------------
	//----------------------调整相片------------------------
	//------------------------------------------------------
			
	select_p_on: function (dom) {
	
		if(!dom) return false;
		Diy2008.select_p = dom;
		if((Diy2008.select_p.width/Diy2008.select_p.height)>(6/7))
		{
			$("select_p_box").innerHTML = '<img src="' + Diy2008.select_p.src + '" width="60" hspace="5" vspace="5" />';
		}
		else
		{
			$("select_p_box").innerHTML = '<img src="' + Diy2008.select_p.src + '" height="70" hspace="5" vspace="5" />';
		}
	},
			
	adjust_photo: function (par) {
		
		if(!Diy2008.select_p) return false;
		var A = Diy2008.select_p.id.split("_");
		var I = A[1];
		var i = A[2];
		var p_i = Diy2008.template[I]["hotzone"][i]["insert_p_i"];
		switch(par)
		{
			case "vertical": //垂直居中
				var top = Math.ceil((Diy2008.template[I]["hotzone"][i]["height"] - _px(Diy2008.select_p.height + ""))/2);
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.top = top + "px";
				Diy2008.template[I]["hotzone"][i]["p_top"] = top;
				//alert(Diy2008.template[I]["hotzone"][i]["height"] + " " + Diy2008.select_p.height);
				//alert($("p_" + I + "_" + i).style.top);
				break;
			case "level": //水平居中
				var left = Math.ceil((Diy2008.template[I]["hotzone"][i]["width"] - _px(Diy2008.select_p.width + ""))/2);
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.left = left + "px";
				Diy2008.template[I]["hotzone"][i]["p_left"] = left;
				break;
			case "left": //往左
				var left = _px(Diy2008.select_p.style.left + "");
				if(!left) left = 0;
				left -= 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.left = left + "px";
				Diy2008.template[I]["hotzone"][i]["p_left"] = left;
				break;
			case "right": //往右
				var left = _px(Diy2008.select_p.style.left + "");
				if(!left) left = 0;
				left += 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.left = left + "px";
				Diy2008.template[I]["hotzone"][i]["p_left"] = left;
				break;
			case "top": //往上
				var top = _px(Diy2008.select_p.style.top + "");
				if(!top) top = 0;
				top -= 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.top = top + "px";
				Diy2008.template[I]["hotzone"][i]["p_top"] = top;
				break;
			case "bottom": //往下
				var top = _px(Diy2008.select_p.style.top + "");
				if(!top) top = 0;
				top += 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.top = top + "px";
				Diy2008.template[I]["hotzone"][i]["p_top"] = top;
				break;
			case "bottom_left": //左下
				var top = _px(Diy2008.select_p.style.top + "");
				if(!top) top = 0;
				top += 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.top = top + "px";
				Diy2008.template[I]["hotzone"][i]["p_top"] = top;
				
				var left = _px(Diy2008.select_p.style.left + "");
				if(!left) left = 0;
				left -= 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.left = left + "px";
				Diy2008.template[I]["hotzone"][i]["p_left"] = left;
				break;
			case "bottom_right": //右下
				var left = _px(Diy2008.select_p.style.left + "");
				if(!left) left = 0;
				left += 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.left = left + "px";
				Diy2008.template[I]["hotzone"][i]["p_left"] = left;
				
				var top = _px(Diy2008.select_p.style.top + "");
				if(!top) top = 0;
				top += 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.top = top + "px";
				Diy2008.template[I]["hotzone"][i]["p_top"] = top;
				break;
			case "top_right": //右上
				var left = _px(Diy2008.select_p.style.left + "");
				if(!left) left = 0;
				left += 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.left = left + "px";
				Diy2008.template[I]["hotzone"][i]["p_left"] = left;
				
				var top = _px(Diy2008.select_p.style.top + "");
				if(!top) top = 0;
				top -= 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.top = top + "px";
				Diy2008.template[I]["hotzone"][i]["p_top"] = top;
				break;
			case "top_left": //左上
				var top = _px(Diy2008.select_p.style.top + "");
				if(!top) top = 0;
				top -= 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.top = top + "px";
				Diy2008.template[I]["hotzone"][i]["p_top"] = top;
				
				var left = _px(Diy2008.select_p.style.left + "");
				if(!left) left = 0;
				left -= 10;
				Diy2008.select_p.style.position = "relative";
				Diy2008.select_p.style.left = left + "px";
				Diy2008.template[I]["hotzone"][i]["p_left"] = left;
				break;
			case "zoom_in": //放大
				var width = _px(Diy2008.select_p.width + "");
				var height = _px(Diy2008.select_p.height + "");
				if(width&&height)
				{
					Diy2008.select_p.style.position = "relative";
					var Width = Math.ceil(width*1.1);
					var Height = Math.ceil(height*1.1);
					
					var T = Math.ceil((Height - height)/2);
					var L = Math.ceil((Width - width)/2);
					
					var top = _px(Diy2008.select_p.style.top + "");
					if(!top) top = 0;
					
					var left = _px(Diy2008.select_p.style.left + "");
					if(!left) left = 0;
					
					top -= T;
					Diy2008.select_p.height = Height;
					Diy2008.select_p.style.top = top + "px";
					Diy2008.template[I]["hotzone"][i]["p_top"] = top;
					Diy2008.template[I]["hotzone"][i]["p_height"] = Height;
				
					left -= L;
					Diy2008.select_p.width = Width;
					Diy2008.select_p.style.left = left + "px";
					Diy2008.template[I]["hotzone"][i]["p_left"] = left;
					Diy2008.template[I]["hotzone"][i]["p_width"] = Width;
				}
				break;
			case "zoom_out": //缩小
				var width = _px(Diy2008.select_p.width + "");
				var height = _px(Diy2008.select_p.height + "");
				
				if(width&&height)
				{
					Diy2008.select_p.style.position = "relative";
					var Width = Math.ceil(width*0.9);
					var Height = Math.ceil(height*0.9);
					
					var T = Math.ceil((Height - height)/2);
					var L = Math.ceil((Width - width)/2);
					
					var top = _px(Diy2008.select_p.style.top + "");
					if(!top) top = 0;
					
					var left = _px(Diy2008.select_p.style.left + "");
					if(!left) left = 0;
					
					top -= T;
					Diy2008.select_p.height = Height;
					Diy2008.select_p.style.top = top + "px";
					Diy2008.template[I]["hotzone"][i]["p_top"] = top;
					Diy2008.template[I]["hotzone"][i]["p_height"] = Height;
				
					left -= L;
					Diy2008.select_p.width = Width;
					Diy2008.select_p.style.left = left + "px";
					Diy2008.template[I]["hotzone"][i]["p_left"] = left;
					Diy2008.template[I]["hotzone"][i]["p_width"] = Width;
				}
				break;
			case "moderate": //适中
	
				var arrays = Diy2008.template[I]["hotzone"][i];
				var src_array = Diy2008.photo_list_array[p_i];
				if(src_array["big_photo"])
				{
						
					if(src_array["width"]/src_array["height"]>arrays["width"]/arrays["height"])
					{
						var width = Math.ceil(src_array["width"] * arrays["height"]/src_array["height"]);
						Diy2008.select_p.height = arrays["height"];
						Diy2008.select_p.width = width;
						Diy2008.template[I]["hotzone"][i]["p_width"] = width;
						Diy2008.template[I]["hotzone"][i]["p_height"] = arrays["height"];
					}
					else
					{
						var height = Math.ceil(src_array["height"] * arrays["width"]/src_array["width"]);
						Diy2008.select_p.height = height;
						Diy2008.select_p.width = arrays["width"];
						Diy2008.template[I]["hotzone"][i]["p_height"] = height;
						Diy2008.template[I]["hotzone"][i]["p_width"] = arrays["width"];
					}
				}
				Diy2008.adjust_photo('vertical');
				Diy2008.adjust_photo('level');
				break;
			case "show_all": //显示全部
	
				var arrays = Diy2008.template[I]["hotzone"][i];
				var src_array = Diy2008.photo_list_array[p_i];
				if(src_array["big_photo"])
				{
						
					if(src_array["width"]/src_array["height"]>arrays["width"]/arrays["height"])
					{
						var height = Math.ceil(src_array["height"] * arrays["width"]/src_array["width"]);
						Diy2008.select_p.height = height;
						Diy2008.select_p.width = arrays["width"];
						Diy2008.template[I]["hotzone"][i]["p_height"] = height;
						Diy2008.template[I]["hotzone"][i]["p_width"] = arrays["width"];
					}
					else
					{
						var width = Math.ceil(src_array["width"] * arrays["height"]/src_array["height"]);
						Diy2008.select_p.height = arrays["height"];
						Diy2008.select_p.width = width;
						Diy2008.template[I]["hotzone"][i]["p_width"] = width;
						Diy2008.template[I]["hotzone"][i]["p_height"] = arrays["height"];
					}
				}
				Diy2008.adjust_photo('vertical');
				Diy2008.adjust_photo('level');
				break;
			default:
				;
				break;
		}
		Diy2008.save_html(Diy2008.edit_month_i);//保存设计
	},
	//------------------------------------------------------
	template_js :	[[
						"/diy/js/dhj/1.js"
					],
					[
						"/diy/images/new/diy/dhj/s1.gif"
					]],
	
	export_template_js: function(i)
	{
		if(Diy2008.template_js_i==i) return false;
		Diy2008.default_edit = false;
		IncJsFiles(Diy2008.template_js[0][i] + "?" + _random());
		if(Diy2008.template_js_i||Diy2008.template_js_i==0)
		{
			switch(Diy2008.template_js_i)
			{
				case 0: 
					$("select_te_div_" + Diy2008.template_js_i).className = "s2t";
					$("select_te_img_" + Diy2008.template_js_i).className = "s";
					break;
				case 7:
				case Diy2008.template_js[1].length-1: 
					$("select_te_div_" + Diy2008.template_js_i).className = "s2f";
					$("select_te_img_" + Diy2008.template_js_i).className = "s";
					break;
				default:
					$("select_te_div_" + Diy2008.template_js_i).className = "s2";
					$("select_te_img_" + Diy2008.template_js_i).className = "s";
					break;
			}
		}
		switch(i)
		{
			case 0: 
				$("select_te_div_" + i).className = "s1t";
				$("select_te_img_" + i).className = "";
				break;
			default:
				$("select_te_div_" + i).className = "s1";
				$("select_te_img_" + i).className = "";
				break;
		}
		Diy2008.template_js_i = i;
	},
	
	export_array: function ()//数组状态代码
	{
		var ARRAY = "[";
		var T="",J="";
		for(var i=0; i<Diy2008.template.length; i++)
		{
			J = (i==0)? "" : ",";
			ARRAY += J + "{T:null";
			if(Diy2008.template[i]["tel_w"]) ARRAY += ",tel_w:" + Diy2008.template[i]["tel_w"];
			if(Diy2008.template[i]["tel_h"]) ARRAY += ",tel_h:" + Diy2008.template[i]["tel_h"];
			if(Diy2008.template[i]["hotzone"])
			{
				ARRAY += ",hotzone:[";
				for(j=0; j<Diy2008.template[i]["hotzone"].length; j++)
				{
					T = (j==0)? "" : ",";
					ARRAY += T + "{T:null";
					if(Diy2008.template[i]["hotzone"][j]["width"]) ARRAY += ",width:" + Diy2008.template[i]["hotzone"][j]["width"];
					if(Diy2008.template[i]["hotzone"][j]["height"]) ARRAY += ",height:" + Diy2008.template[i]["hotzone"][j]["height"];
					if(Diy2008.template[i]["hotzone"][j]["left"]) ARRAY += ",left:" + Diy2008.template[i]["hotzone"][j]["left"];
					if(Diy2008.template[i]["hotzone"][j]["top"]) ARRAY += ",top:" + Diy2008.template[i]["hotzone"][j]["top"];
					if(Diy2008.template[i]["hotzone"][j]["def_p"]) ARRAY += ",def_p:\"" + Diy2008.template[i]["hotzone"][j]["def_p"] + "\"";
					if(Diy2008.template[i]["hotzone"][j]["insert_p"]) ARRAY += ",insert_p:\"" + Diy2008.template[i]["hotzone"][j]["insert_p"] + "\"";
					if(Diy2008.template[i]["hotzone"][j]["insert_p_i"]) ARRAY += ",insert_p_i:" + Diy2008.template[i]["hotzone"][j]["insert_p_i"];
					if(Diy2008.template[i]["hotzone"][j]["p_left"]) ARRAY += ",p_left:" + Diy2008.template[i]["hotzone"][j]["p_left"];
					if(Diy2008.template[i]["hotzone"][j]["p_top"]) ARRAY += ",p_top:" + Diy2008.template[i]["hotzone"][j]["p_top"];
					if(Diy2008.template[i]["hotzone"][j]["p_width"]) ARRAY += ",p_width:" + Diy2008.template[i]["hotzone"][j]["p_width"];
					if(Diy2008.template[i]["hotzone"][j]["p_height"]) ARRAY += ",p_height:" + Diy2008.template[i]["hotzone"][j]["p_height"];
					ARRAY += T + "}";
				}
				ARRAY += "]";
			}
			if(Diy2008.template[i]["tel_p_z"]) ARRAY += ",tel_p_z:\"" + Diy2008.template[i]["tel_p_z"] + "\"";
			if(Diy2008.template[i]["tel_w_b"]) ARRAY += ",tel_w_b:" + Diy2008.template[i]["tel_w_b"];
			if(Diy2008.template[i]["tel_h_b"]) ARRAY += ",tel_h_b:" + Diy2008.template[i]["tel_h_b"];
			if(Diy2008.template[i]["tel_p_b"]) ARRAY += ",tel_p_b:\"" + Diy2008.template[i]["tel_p_b"] + "\"";
			if(Diy2008.template[i]["year"]) ARRAY += ",year:" + Diy2008.template[i]["year"];
			if(Diy2008.template[i]["month"]) ARRAY += ",month:" + Diy2008.template[i]["month"];
			if(Diy2008.template[i]["month_p"]) ARRAY += ",month_p:\"" + Diy2008.template[i]["month_p"] + "\"";
			if(Diy2008.template[i]["month_p_r"]) ARRAY += ",month_p_r:\"" + Diy2008.template[i]["month_p_r"] + "\"";
			ARRAY += "}";
		}
		ARRAY += "]";
		return ARRAY;
		/*
		tel_w:310,
		tel_h:213,
		hotzone:[
					{
						width:224,
						height:143,
						left:43,
						top:39
						//def_p:"/diy/images/new/diy/taili/temp/7.jpg",
						//insert_p:,
						//p_left:,
						//p_top:,
						//p_width:,
						//p_height:
					}
				],
		tel_p_z:"/diy/images/new/diy/taili/m2/7.png",
		
		tel_w_b:310,
		tel_h_b:213,
		tel_p_b:"/diy/images/new/diy/taili/m2/b7.png",
		
		year:2008,
		month:7,
		month_p:"/diy/images/new/diy/taili/diy_yuefen_7.gif",
		month_p_r:"/diy/images/new/diy/taili/diy_yuefen_7_2.gif"
		*/
	},
	
	export_html: function ()//数组状态代码
	{
		var HTML = "";
		for(var i=0; i<Diy2008.template.length; i++)
		{
			if(Diy2008.template[i]['html'])
			{
				HTML += '<table border="0" cellspacing="0" cellpadding="2">';
				HTML += '<tr>';
				HTML += '<td>' + Diy2008.template[i]['html'] + '</td>';
				HTML += '</tr>';
				if(Diy2008.template[i]["superfluity"])
				{
					HTML += '<tr>';
					HTML += '<td>' + Diy2008.template[i]['superfluity'] + '</td>';
					HTML += '</tr>';
				}
				HTML += '</table>';
			}
		}
		return HTML;
	},
	
	save_works_on : function() {
	
		var data;
		data = "arrays=" + escape(Diy2008.export_array()) + "&content=" + escape(Diy2008.export_html()) + "&title=" + escape(Diy2008.title) + "&number=" + Diy2008.number + "&aprice=" + document.orders.unit_price.value;
		//alert(data);
		//prompt("请输入书签标题!","/explor/php/folder_del.php?" + data);
		XMLHttp.sendReq("POST", "/diy/php/updata_product.php", data, Diy2008.save_works);
			
	},
	
	save_works : function(obj) {
		if(obj.readyState == 4)
		{
			if (obj.status == 200)
			{
				var xmlDoc = obj.responseText;
				//alert(xmlDoc);
				//prompt("请输入书签标题!",xmlDoc);
				if (xmlDoc.indexOf("ok")!=-1)
				{
					Diy2008.number = xmlDoc.split("|")[1];
					$("preview").href = "preview.php?number=" + Diy2008.number;
					document.orders.url.value = "/diy/preview.php?number=" + Diy2008.number;
					document.orders.wnumber.value = Diy2008.number;
					//alert("作品保存成功!");
					//if (confirm("作品保存成功,你需要提交到购物车吗?"))
					//{
						Orders.add(0);
					//}
				}
				else
				{
					alert("作品保存失败");
				}
			}
		}
	},
	
	save_html: function(i)
	{
		Diy2008.template[i]['html'] = $("template_box_z").innerHTML;
	},
	
	show_explains: function(array)
	{
		if(array)
		{
			$("explains1").innerHTML = array[0];
			if(Diy2008.title) document.orders.name.value = Diy2008.title;
			if(array[1])
			{
				var HTML = '<table border="0" cellspacing="0" cellpadding="0"><tr>';
				for(var i=0; i<array[1].length; i++)
				{
					HTML += '<td><input name="s2" type="radio" value="' + array[1][i]["text"] + '"';
					if(!i) HTML += ' checked="checked"';
					HTML += ' onclick="Diy2008.select_explains(' + i + ');" /></td><td>' + array[1][i]["text"] + '</td>';
				}
				HTML += '</tr></table>';
				$("explains2").innerHTML = HTML;
				Diy2008.select_explains(0);
			}
		}
	},
	
	select_explains: function(i)
	{
		if(Diy2008.explains)
		{
			if(Diy2008.explains[1][i]&&Diy2008.explains[1][i]["price"])
			{
				//$("price").innerHTML = "￥" + Diy2008.explains[1][i]["price"];
				//document.orders.unit_price.value = Diy2008.explains[1][i]["price"];
				if(Diy2008.explains[1][i]["text"]) document.orders._explains.value = Diy2008.explains[1][i]["text"];
			}
		}
	},
	
	superfluity: function()
	{
		Diy2008.template[Diy2008.edit_month_i]["superfluity"] = document.orders.superfluity.value;
	}
}

window.onload=function(){
	//alert(document.elementFromPoint(400,200).parentNode.nodeName);
	document.onclick = Diy2008.onclick;
	document.onmousedown = Diy2008.ondown;
	document.onmouseup = Diy2008.onup;
	
	document.onmouseout = Diy2008.onout;
	document.onmouseover = Diy2008.onover;
	
	//Diy2008.export_month(template,"template");
	//IncJsFiles("/2008diy/huache/template/dys_huangse.js?" + _random());
	
	IncJsFiles("/album/diyphoto.php?" + _random()); 
	/*
	if(REQUEST.QS("album"))
	{
		IncJsFiles("/diy/js/album_list.php?album=" + REQUEST.QS("album") + "&" + _random());//图片列表
	}
	else
	{
		IncJsFiles("/diy/js/album_list.php?" + _random());//图片列表
	}
	*/
	
	if(Diy2008.template_js)
	{
		/*
		<div class="s2t"><img src="images/new/diy/taili/dys_baiban/s.png" alt="" width="73" height="50" hspace="30" vspace="8" class="s" /></div>
		<div class="s1"><img src="images/new/diy/taili/m2/s.png" alt="" width="73" height="50" hspace="30" vspace="8" /></div>
		<div class="s2"><img src="images/new/diy/taili/qb_caitiao/s.png" alt="" width="73" height="50" hspace="30" vspace="8" class="s" /></div>
		<div class="s2f"><img src="images/new/diy/taili/dys_huangse/s.png" alt="" width="73" height="50" hspace="30" vspace="8" class="s" /></div>
		*/
		var HTML = "";
		for(var i=0; (i<Diy2008.template_js[1].length&&i<8); i++)
		{
			switch(i)
			{
				case 0: //显示全部
					HTML += '<div class="s2t" id="select_te_div_' + i + '" onclick="Diy2008.export_template_js(' + i + ')"><img id="select_te_img_' + i + '" src="' + Diy2008.template_js[1][i] + '" alt="" hspace="30" vspace="8" class="s" /></div>';
					break;
				case 7: //显示全部
				case Diy2008.template_js[1].length-1: //显示全部
					HTML += '<div class="s2f" id="select_te_div_' + i + '" onclick="Diy2008.export_template_js(' + i + ')"><img id="select_te_img_' + i + '" src="' + Diy2008.template_js[1][i] + '" alt="" hspace="30" vspace="8" class="s" /></div>';
					break;
				default:
					HTML += '<div class="s2" id="select_te_div_' + i + '" onclick="Diy2008.export_template_js(' + i + ')"><img id="select_te_img_' + i + '" src="' + Diy2008.template_js[1][i] + '" alt="" hspace="30" vspace="8" class="s" /></div>';
					break;
			}
		}
		$("select_template").innerHTML = HTML;
		if(REQUEST.QS("template"))
		{
			if(Diy2008.template_js[REQUEST.QS("template")])
			{
				Diy2008.export_template_js(REQUEST.QS("template"));
			}
			else
			{
				Diy2008.export_template_js(0);
			}
		}
		else
		{
			Diy2008.export_template_js(0);
		}
		
	}
	
	//onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image100','','images/diy_yuefen_1_2.gif',1)"
	
}
//HTMLElement.offsetLeft
//HTMLElement.offsetHeight
//diy_text_ajax.php?fs=1&fset=1&fb=0&_T_Size=15&_T_Color=000000&_Text=%u4F60%u597D