var x0=0,y0=0,x1=0,y1=0;
var startmove=false;
var moveable=false;
var index=10000;//z-index;
var bottom;

var startleft,starttop;
var endleft,endtop;

var productid;
var navigateid;
var xmlHttp=null;

function getOffsetPositionObj(obj){
  var oleft=parseInt(obj.offsetLeft);/////获取位置
  var otop=parseInt(obj.offsetTop);/////获取位置
  while(obj=obj.offsetParent){////进一步获取绝对位置
     otop+=obj.offsetTop;
     oleft+=obj.offsetLeft;
  } 
  return [oleft,otop];
}
// 初始化装载对象
function startDrag(e,obj)
{
	
	
	var par = obj.parentNode.parentNode;
		par.style.border='1px dashed #ff0000';
	if(par){
	  if(par.tagName=="DIV"){
		
		try{
			
			startleft =par.offsetLeft+"px";
			starttop = par.offsetTop+"px";
		}catch(e){
		
		}
		}
	} 
	var isIE=document.all? true:false ;
	if(isIE)obj.setCapture();
	
	x0 = e.clientX;	
	y0 = e.clientY;
		
	  var movediv=document.createElement("DIV");
	   movediv = par.cloneNode(true);
	   movediv.style.position = "absolute"; 
	   movediv.style.border='1px dashed #ff0000';
	   movediv.style.zIndex=10000;
	   movediv.style.backgroundColor="#FF0000"; 
	   movediv.style.filter = "alpha(opacity=40)"; 

	   movediv.style.width=par.childNodes[0].childNodes[0].clientWidth;
	   movediv.style.heigth=par.childNodes[0].childNodes[0].clientHeight;

	   window.document.getElementById("specific_div").appendChild(movediv);	
	  movediv.childNodes[0].childNodes[0].id="tempDiv";
	   startmove = true;


}

function drag(e,obj)
{
	 obj=window.document.getElementById("tempDiv");

	if(startmove&&obj)
	{	
		
		x1=e.clientX;
		y1=e.clientY;
		var par = obj.parentNode.parentNode;
		if((parseInt(startleft) + x1 - x0)<0){
			par.style.left =0;
		}else{
	
			par.style.left = (parseInt(startleft) + x1 - x0)+"px";
		}
		if((parseInt(starttop) + y1 - y0) <0)
		{
			par.style.top = 0;
		}
		else{
			
			par.style.top = (parseInt(starttop) + y1 - y0)+"px";
			
		}
		moveable=true;
	}
}



function stopDrag(obj)
{
	

	if(startmove&&moveable)
	{
			
		    var par = obj.parentNode.parentNode;	
			var isIE=document.all? true:false ;
			if(isIE)obj.releaseCapture();
		
			startmove = false;
			moveable = false;
			var tem=window.document.getElementById("tempDiv");	
			var	temp=tem.parentNode.parentNode;

						par.style.left=temp.offsetLeft+"px";;
						par.style.top=temp.offsetTop+"px";;
						
	
	}


		var tem=window.document.getElementById("tempDiv");	
		if(tem){
			var temp=tem.parentNode.parentNode;
			temp.parentNode.removeChild(temp);
			var par = obj.parentNode.parentNode;	
			par.style.border=''
			
		}
		

	
}


function addDiv(divid,divcssurl,divhtml){
	if(divhtml!="fail"){
		
		var ishas="N";
		var linknum=window.top.document.getElementsByTagName("link");	
			 for(var i=1;i<linknum.length;i++)
			 {	
				if(linknum[i].href==divcssurl){
					ishas="Y";
				}
			 }
		
		if(ishas=="N"){
					var linkstyle = document.createElement("link");
					 linkstyle.type = "text/css";
					 linkstyle.setAttribute("rel","stylesheet");
					 linkstyle.setAttribute("href",divcssurl);
					 
					 var obj_head=document.getElementsByTagName("head")[0];
						obj_head.appendChild(linkstyle);
										
					 var head_list=obj_head.childNodes;
								 
					 for(i=0;i<head_list.length;i++){			 		
							if(head_list[i].tagName=="LINK"&&head_list[i].href.indexOf("style")>0){				
									obj_head.appendChild(head_list[i]);
									break;
							}
							
					 } 
					// alert(obj_head.innerHTML);
		}
			 
		var specific_div=window.document.getElementById("specific_div");
			specific_div.innerHTML=divhtml+specific_div.innerHTML;
			setmove();	//重新加载一次移动方法；

			window.setTimeout("load_onediv_content('"+divid+"')",1000);//load_div 数据;
	}
	
}



function editDiv(e,obj,div_obj_id,navigateId){	
   
			var xy=getOffsetPositionObj(obj)
			var seturl="";
			var textarea_vlue="";
			var selid=window.document.getElementById("input_param"+div_obj_id).value;//当前正编辑小框架的某一个内容；
			var otextarea=window.document.getElementById("textarea_param"+div_obj_id+"_"+selid);
			if(otextarea)
			{
				 textarea_vlue=otextarea.value;
				if(textarea_vlue!=""&&textarea_vlue.indexOf("param")>-1)
					{
						var ss=textarea_vlue.split(";");
						seturl=getmtag(ss[3])[1];//获取地址；load_content.js
						var param=ss[0];	
						if(seturl!=null&&seturl!=""){
							if(seturl.indexOf("?")>0){
							seturl=seturl+"&"+param
							}
							else{
							seturl=seturl+"?"+param
							}
							
						}
						
						var index_b=param.indexOf("productId=");
						var index_e=param.indexOf(",",index_b);
						if(index_e=="-1")index_e=param.length;
				
						var productId=param.substring(index_b+10,index_e);
	
					}
			}
			// g_c_hand

			 var content="";	
			 		content+='<div class="index_module_set">';
					content+='<div class="index_module_set_shadow">';
					content+='<ul id="index_module_set_qzMenu_1" class="index_module_set_ul">';
			if(seturl!=""){
			 		content+='<li><a class="index_module_set_a" href="javascript:void(0);" onClick="window.parent.editDivWindow(\'eidtDiv1000\',\'显示设置\',\''+seturl+'\',600,450,'+xy[0]+','+xy[1]+',\'N\',\'Y\',\''+div_obj_id+'\','+productId+',\''+navigateId+'\')" >显示设置</a></li>';					
					content+='<li><div class="index_module_set_separator"></div></li>';
					
			 }
			 else{
				 	content+='<li><a class="index_module_set_a" href="javascript:void(0);"  >暂无设置</a></li>';
					content+='<li><div class="index_module_set_separator"></div></li>';
			 }
					content+='<li><a class="index_module_set_a" href="javascript:void(0);" onClick="window.parent.hiddrenDiv(\''+div_obj_id+'\','+productId+',\''+navigateId+'\')">隐藏</a></li>';
					
					content+='</ul>';
					content+='</div>';
					content+='</div>';	 
			 var oPopup = window.createPopup();
			 var oPopupBody = oPopup.document.body;
				 oPopupBody.document.body.innerHTML=content;
				 oPopup.document.createStyleSheet().addImport("/design/css/beauty_custom.css"); 
				 oPopup.show(xy[0]-20,xy[1],100,60,document.body);
				
	
 }
function editDivWindow(id,title,url,width,height,left,top,isrefresh,iscoverage,divid,productId,navigateId)
{
/*
  id:窗口Id
  url：窗口对应的地址
  isrefresh：窗口关闭时是否刷新
  iscoverage:
*/
   var iframename=id+"Iframe";
    var content="<iframe   id='"+iframename+"' name='"+iframename+"' src='"+url+"' frameborder=\"0\" scrolling=\"auto\" width="+width+" height="+height+" style=\"width:590px;height:370px;padding-left:10px;\" ></iframe>";
	//	+ "<div class='pop_custom' id=" + id + " style='z-index:10000;width:" + width + ";height:250px"  + ";left:" + left + ";top:" + top + ";cursor:default; overflow:visible;;"
	//	+ "position:absolute;cursor:default;' >"
		var str = ""	
			str='<div class="pop_page_top" style="cursor:move;width:600px" onmousedown="winstartDrag(event,this)" onmouseup="winstopDrag(this)" onmousemove="windrag(event,this)">'+
					'<div class="pop_page_title" style="width:600px;">'+title+'</div>'+
					'<div class="pop_page_close">'+
						'<button class="pop_page_close_default" onmousemove="this.className=\'pop_page_close_hover\'" onmouseout="this.className=\'pop_page_close_default\'" onclick=\'CloseWin("'+id+'","'+isrefresh+'")\' onmousedown=\'Event.stop(event);\'></button>'+
					'</div>'+
				'</div>'+
				'<div class="g_h_20"></div>';
			/*str= "<div class='main'>"
				+ "<div class='index_module_showSetting' >"
				+ content
				+ "</div>"
			+ "<div >";*/
			str+=content;
		str+='<div  style="width:600px;text-align:center;background-color:#FFFFFF""><img src="/design/images/pop_qd.gif" style="cursor:pointer" onclick="editDivSave(\''+divid+'\',\''+productId+'\',\''+navigateId+'\')" />&nbsp;&nbsp;';
		str+='<img src="/design/images/pop_qx.gif"style="cursor:pointer" onclick="CloseWin(\''+id+'\',\''+isrefresh+'\')" /></div>';
		str+='<div class="pop_page_buttom_line"style="height:20px;"></div>';
		//+ "</div>";
		
			var Div1=window.document.createElement("DIV");
			Div1.id=id;
			Div1.className="pop_page_outter";
			Div1.style.zIndex="10000";
		 	Div1.style.top=top+"px";
   			//Div1.style.left=left+"px";
   			Div1.style.left=(left-500)+"px";
			Div1.style.width=width;
   			Div1.style.height=height;
			Div1.style.cursor="default";
			Div1.style.overflow="visible";
			Div1.style.position="absolute"
			
			Div1.innerHTML=str;
			window.document.body.appendChild(Div1);
			
			//window.document.body.insertAdjacentHTML("beforeEnd",str);
				 
			 if(iscoverage=="Y"){
				 openWincovDiv();///////////////////高亮覆盖背景
			 }
 
}

function editDivSave(id,productId,navigateId){
		
		var param ="param="+eval("window.eidtDiv1000Iframe.getParameter()");
		var jsFunction =eval("window.eidtDiv1000Iframe.getJavaFunction()");
		var selid=window.document.getElementById("input_param"+id).value;//当前正编辑小框架的某一个内容；
		
		var textarea_vlue=window.document.getElementById("textarea_param"+id+"_"+selid).value;
		if(textarea_vlue!=""&&textarea_vlue.indexOf("param")>-1)
		{
			var ss=textarea_vlue.split(";");
			var new_t=param+";"+ss[1]+";"+jsFunction+";"+ss[3];
			var divcontentId="div_content"+id+"_"+selid;  //例如：div_content255734_1
			
			
			var url="/design/div.do?method=simpleEditDiv&oper=show&productId="+productId+"&navigateId="+navigateId+"&divid="+id+"&divcontentId="+divcontentId+"&divcontent="+new_t;
			var text=getContent(url);
			
			if(text!="fail"){
				
				window.document.getElementById("textarea_param"+id+"_"+selid).value=new_t;
				load_onediv_content(id);
			}
			else{
				alert("数据出错是!");	
			}
			
		}
	
}


function hiddrenDiv(id,productId,navigateId){
	try{
		
		var url="/design/div.do?method=simpleEditDiv&isshow=N&productId="+productId+"&navigateId="+navigateId+"&divid="+id+"&oper=isshow";
		
		var text=getContent(url);
		if(text=="success"){
			var divobj=window.document.getElementById(id);
			var pobj=divobj.parentNode;
				pobj.removeChild(divobj);

			
			var inputobj=window.index_div_custom_iframe.document.getElementById("check_"+id);
				if(inputobj)inputobj.checked=false;
			
			
		}
		else{
			alert("数据出错！");
			
		}
		
	}catch(e){
		//alert(e);
	}
	
}

function setmove(){
	
		var specific_div_child=window.top.document.getElementById("specific_div").childNodes;
					
			for(i=0;i<specific_div_child.length;i++){
			
				var obj1=specific_div_child[i].childNodes;
				var obj2=obj1[0].childNodes;
						
				obj2[0].title="按住鼠标，可随意拖动模块";
				obj2[0].style.cursor="move;";
				obj2[0].setAttribute("onmousedown",function(){startDrag(event,this)}); 
				obj2[0].setAttribute("onmouseup",function(){stopDrag(this)}); 
				obj2[0].setAttribute("onmousemove",function(){drag(event,this)}); 
			}	
}
