﻿// JScript 文件
 
 
window.onerror=fnErrorTrap; 
function fnErrorTrap(sMsg,sUrl,sLine){ 
//    var s=" <b>An error was thrown and caught. </b> <p>"; 
//    s+="Error: " + sMsg + " <br>"; 
//    s+="Line: " + sLine + " <br>"; 
//    s+="URL: " + sUrl + " <br>"; 
//    alert(s);
    return true; 
} 

 
 var divContent='<div class="mainblock" id="{0}" style="{2}">\
     <div class="noInherit">\
      <div class="mbPadding">\
        <div class="mbLine"></div>\
        <div class="mbContent" id="{1}">\
        \
        </div>\
        <div class="clear"></div>\
      </div>\
     </div>\
     </div>\r\n    '; 
     
//模板里加用这个
var tem_divContent='<div class="mainblock" id="{0}" style="{2}">\
     <div class="noInherit">\
      <div class="mbPadding">\
        <div class="mbLine"></div>\
        <div class="mbContent" id="{1}">\
        \
        </div>\
        <div class="clear"></div>\
      </div>\
     </div>\
     </div>\r\n'; 
     
     
     

var topID='';//定义当前选中的ID



function isTopID()
{
    {if(topID!='')return true; else return false;}
}

function getNumber()
{
    var t='<p class="num" id="spNumber{2}"  onclick="MainsetFocus({0},this);">{1}</p>';
    var to='';
    var o=getElementsByClassName("mbContent");

    for(var i=0;i<o.length;i++)
    {
            to+=t.replace('{1}',i+1).replace('{0}',i).replace('{2}',i);
    }

    if(parent!=null)
    parent.document.getElementById('toTd').innerHTML=to;
    
}
 

function FloatAll()
{
    HiAll();
    var o=getElementsByClassName("mainblock");

    for(var i=0;i<o.length;i++)
    {

            //全左浮动
            //o[i].style.width=parseInt(((o[i].offsetWidth)/pageWidth)*100)+'%';
            //o[i].style.width=o[i].offsetWidth;
            //o[i].style.styleFloat='left';
            
            //添加事件
            //o[i].onmouseover=function(){alert(o[i].className);};
            //o[i].onmouseout=function(){}
            if(o[i].id.indexOf('MAIN_')==-1)
            {

            
//                (function(){ 
//                    var temp = o[i]; 
//                    temp.onmousedown = function(){obj_lsdown(temp.id);} 
//                    } 
//                )();
//                
//                (function(){ 
//                    var temp = o[i]; 
//                    temp.onmouseup = function(){obj_up(temp.id);} 
//                    } 
//                )();

//                (function(){ 
//                try{
//                    var temp = o[i]; 
//                    temp.onmousemove = function(){obj_move(temp.id);} 
//                    }catch(e){}
//                    } 
//                )();
                
//                (function(){ 
//                    var temp = o[i]; 
//                    temp.onmouseover = function(){
//                    showResizeGif(temp.id);
//                    temp.style.cursor="hand";
//                    } 
//                    } 
//                )();
                
                
//                (function(){ 
//                    var temp = o[i]; 
//                    temp.onmouseout = function(){closeResizeGif();} 
//                    } 
//                )();
                (function(){ 
                    var temp = o[i]; 
                    var p = i; 
                    temp.onclick = function(){setFocus(p,parent.document.getElementById('spNumber'+p));} 
                    } 
                )();
            }
            else
            {
//                (function(){ 
//                    var temp = o[i]; 
//                    temp.onmousedown = function(){} 
//                    } 
//                )();
//                
//                (function(){ 
//                    var temp = o[i]; 
//                    temp.onmouseup = function(){} 
//                    } 
//                )();

//                (function(){ 
//                    var temp = o[i]; 
//                    temp.onmousemove = function(){} 
//                    } 
//                )();
//                
//                (function(){ 
//                    var temp = o[i]; 
//                    temp.onmouseover = function(){
//                        temp.style.cursor="default";
//                    } 
//                    } 
//                )();
//                
//                
//                (function(){ 
//                    var temp = o[i]; 
//                    temp.onmouseout = function(){} 
//                    } 
//                )();
                (function(){ 
                    var temp = o[i]; 
                    var p = i; 
                    temp.onclick = function(){} 
                    } 
                )();
            }
    }
}


function getEditRegin()
{
    var o=getElementsByClassName("EditRegin");
    if(o!=null)
    {
        if(o.length!=0)
        {
            for(var i=0;i<o.length;i++)
             {     

                        (function(){ 
                            var temp = o[i]; 
                            temp.onmouseover = function(){
                                showEditGif(temp.id);
                                } 
                            } 
                        )();
                        
//                        (function(){ 
//                            var temp = o[i]; 
//                            temp.onmouseout = function(){HiEditGif(temp.id);} 
//                            } 
//                        )();
                        

                         
             }
         }
 
     }
}



function getReginData()
{

    var o=getElementsByClassName("EditRegin");
    if(o!=null)
    {
        var sPath = document.location.pathname+document.location.search; //==by Leotiger
        var idStr='';
        if(sPath.indexOf("_id=")>-1){
            var re=sPath.match(/_id=\d+/);
            if(re!=null&&re!='')
            {
                idStr='&'+re;
            }
        }
        
        //代入当前地址里的pageid
        var pageid=QueryStringFromStr(sPath,"pageid");
        if(pageid!=null&&pageid!='')
        {
            idStr+='&pageid='+pageid;
        }
        
        //代入当前地址里的-temid 以示区pageid区别
        var temid=QueryStringFromStr(sPath,"temid");
        if(temid!=null&&temid!='')
        {
            idStr+='&pageid=-'+temid;
        }

        var _len=0;
        if(o.length!=0)
        {
            for(var i=0;i<o.length;i++)
             {     
                try
                {
                     getContent('../ProAjax/getReloadData.aspx?divName='+o[i].id+idStr,o[i].id,o.length);
                }catch(e){}
             }
             

   
         }
 
     }
     
     

     
}

//function getReginDataByDivName(DivName)
//{
//    var sPath = document.location.pathname+document.location.search; //==by Leotiger
//    var idStr='';
//    if(sPath.indexOf("_id=")>-1){
//        var re=sPath.match(/_id=\d+/);
//        if(re!=null&&re!='')
//        {
//            idStr='&'+re;
//        }
//    }


//    if(DivName!=0)
//    {
//        try
//        {
//             getContent('../ProAjax/getReloadData.aspx?divName='+DivName+idStr,DivName);
//        }catch(e){}
//     }
//}

function getLastChar(str)
{
    if(str!='')
    {
        var l=str.length;
        return str.substring(l-1)
    }
}

var _editdiv=null;

function showEditGif(id)
{
 
 try
 {
    //显示两个div
    //1用于拖动
    //2用于点击编辑
    
    var sPath = document.location.pathname; //==by Leotiger
    
    if(getLastChar(id)=='T'&&sPath.indexOf('TypeSetTep.aspx')==-1) //最后一个字符是T的是模板,则在非模板页不显示编辑
    {
        
    }
    else
    {
        var t=document.getElementById('DV_'+id);
        if(t!=null)
        {
            if(document.getElementById(id).style.position.toLowerCase()=='absolute')
            {
                t.style.display='';
                t.style.marginLeft='0px';
                t.style.marginRight='5px';
                FloatDiv(id);
                document.getElementById('Mov_'+id).style.display='';
            }else
            {
                var o=document.getElementById(id);
                var left=getLeft(id)+o.offsetWidth-40;
                var top=getTop(id);
             
                t.style.display='';
                t.style.left=left;
                t.style.top=top;
            }
        }
      
    }
    
    //if(_editdiv!=null)clearTimeout(_editdiv);
    
 }catch(e){}

}


function HiEditGif(id)
{
     var e='HiEditGifAct(\''+id+'\')'
     _editdiv=setTimeout(e,2000);
    
}

function HiEditGifAct(id)
{
    var _t=document.getElementById('DV_'+id);
    _t.style.display='none';
}


 
function setDiv(id,state)
{
    try
    {
	    var w=document.getElementById(id).offsetWidth;
    	
	    var BorderWidth=document.getElementById(id).style.borderWidth;
     
        var offsetLeft=getLeft(id);
        var offsetTop=getTop(id);
     
        
        var t='<span style="border:1px solid #CC99FF; background-color:#ccc;width:'+w+'px;z-index:101;text-align:center;position: absolute; top: '+offsetTop+'px; height: 5px; left: '+offsetLeft+'px;filter:alpha(opacity=50);opacity: 0.5;">'+w+'px</span>';
     
        if(state==0)
        {
            document.getElementById("Wstate").style.display='none';
        }
        else
        {
            document.getElementById("Wstate").style.display='';
            document.getElementById("Wstate").innerHTML=t;
        }
    }catch(e){}
}

function setFocus(id,thisobj)
{	    

    if(topID!='')
    {
        //判断是不是自已
        var _topID=getElementsByClassName("mbContent")[id].id.replace('blockC_','block_');
        if(_topID==topID)//是自己 //隐藏所有
        {
            //document.getElementById("Wstate").style.display='none';
            //HiAll();
            //topID='';
            setDiv(topID,1);
        }else
        {
            HiAll();
            if(thisobj!=null){thisobj.style.cssText=thisobj.style.cssText+';background:blue';}

            //getElementsByClassName("mbContent")[id].previousSibling.style.display = "";
            
             //getElementsByClassName("mbContent")[id].style.backgroundColor="#EFEFEF";

             var thisID=getElementsByClassName("mbContent")[id].id;
             topID=thisID.replace('blockC_','block_');

             //document.getElementById(thisID).style.borderWidth='0px';
             //document.getElementById(thisID).style.borderColor='#999';

             setDiv(topID,1);
             
             //document.getElementById('CurReginW').value=document.getElementById(topID).offsetWidth;
             //document.getElementById('CurReginH').value=document.getElementById(topID).offsetHeight-22;//这里以后要改 20px magin 和2px边框
             //document.getElementById('FloatDirection').value=document.getElementById(topID).styleFloat;
             //document.getElementById("ALL").value=document.body.innerHTML;
           }  
    }else
    {
        HiAll();
        if(thisobj!=null){thisobj.style.cssText=thisobj.style.cssText+';background:blue';}

        //getElementsByClassName("mbContent")[id].previousSibling.style.display = "";
        
         //getElementsByClassName("mbContent")[id].style.backgroundColor="#EFEFEF";

         var thisID=getElementsByClassName("mbContent")[id].id;
         topID=thisID.replace('blockC_','block_');
         
         
         
         
         //document.getElementById(thisID).style.borderWidth='0px';
         //document.getElementById(thisID).style.borderColor='#999';
         

         
         setDiv(topID,1);
         
         //document.getElementById('CurReginW').value=document.getElementById(topID).offsetWidth;
         //document.getElementById('CurReginH').value=document.getElementById(topID).offsetHeight-22;//这里以后要改 20px magin 和2px边框
         //document.getElementById('FloatDirection').value=document.getElementById(topID).styleFloat;
         //document.getElementById("ALL").value=document.body.innerHTML;
    }
}

//关闭所有高亮
function HiAll()
	{
	    var o=getElementsByClassName("mbContent");
 
	    for(var i=0;i<o.length;i++)
	    {
	        if(o[i]&&parent.document.getElementById('spNumber'+i))
	        {
	            o[i].style.borderWidth='0px';
	            o[i].style.borderColor='#eee';
	            parent.document.getElementById('spNumber'+i).style.backgroundColor="#EFEFEF";
	            
                //o[i].previousSibling.style.display = "";

                //o[i].style.backgroundColor="";
             }   
	    }
	}


 
    function ButAddDiv_onclick(typename) {
        
        var type=typename;
 
        var selWidth=document.getElementById(topID).offsetWidth;
        if(type=='上面'||type=='下面')
        {
            //改掉topID为,如上面则到_为1的id,如下面则到 最大的一个id
            
 
            //0 代表下面加时宽100%
            AddDivAction(0,typename);
        }else
        {
            if(type=='内部')
            {
                 ShowC1('../22.aspx?selWidth='+selWidth,600,420);
            }
            else
            {
                ShowC1('../222.aspx?type='+type,300,200);
            }
        }
        
        //AddDivAction(200);
    }
 
    
    function getRandDivID(divid)
    {
        var rdid=rand(1000);
        try
        {
            return divid.match(/\w+_(?=(\d+))/)[0]+rdid;
        }catch(e)
        {
            return "ID"+rdid;
        }    
    }
    
    function AddDivAction(Iwidth,typename)
    {
           var tdivContent='';
           var sPath = document.location.pathname; //==by Leotiger
           if(sPath.indexOf('TypeSetTep.aspx')==-1)//非模板方式
           {
                tdivContent=divContent;
           }else
           {
                tdivContent=tem_divContent;
           }
 
           var type=typename;
           
           var newDivID='';
//           if(type!='内部')
//           {
//              var topNumber='';
//              topNumber=topID.match(/\d+$/);
//              newDivID=topID.match(/\w+_(?=(\d+))/)[0]+(parseInt(topNumber)+1);
// 
//           }else
//           {
//           
//              var innserHTML=document.getElementById(topID).innerHTML;
//              var retop=topID+'_\\d+';

//              if (innserHTML.match(retop)) {
//	                //已有过插入,就查出最大的
//	                var va=innserHTML.match(eval('/'+retop+'/g'));
//	                var maxva=0;
//	                for(var i=0;i<va.length;i++)
//	                {
//	                    var remax='\\d+$';
//	                    var tva=va[i].match(remax);
// 	                    
//	                    if(maxva<tva)maxva=tva;
//	                }
//	                //得到最终新的ID_number
// 
//	                maxva++;
//	                //最终div id
//	                newDivID=topID+'_'+maxva;
//	                
//                }
//                else {
//	                // Match attempt failed
//	                newDivID=topID+'_1';
//                }
//           }

           var seed = new Date().getTime();
           newDivID=topID+'_'+seed;
           
           newDivID=newDivID.replace('MAIN_','');
           if(document.getElementById(newDivID))
           {
                newDivID=getRandDivID(newDivID);
           }
           //换参数
           tdivContent=tdivContent.replace(/\{0\}/g,newDivID);
           tdivContent=tdivContent.replace(/\{1\}/g,newDivID.replace('block_','blockC_'));
           //tdivContent=tdivContent.replace(/\{2\}/g,'width:'+Iwidth+'px;');
           //换参数over
           tdivContent=tdivContent.replace(/<!--\{3\}-->/ig,'');
           
           var topWidth=document.getElementById(topID).offsetWidth;
           //左右加入的边框值
           var borderWidth=0;
           switch(type)
           {
                case '上面':
                {
                    tdivContent=tdivContent.replace(/\{2\}/g,'width:100%;');
                    document.getElementById(topID).outerHTML=tdivContent+''+document.getElementById(topID).outerHTML;

                    break;
                }
                case '下面':
                {
                    tdivContent=tdivContent.replace(/\{2\}/g,'width:100%;');
                    document.getElementById(topID).outerHTML=document.getElementById(topID).outerHTML+tdivContent+'';break;
                    
                }
                case '左面':
                { 
                    
                    tdivContent=tdivContent.replace(/\{2\}/g,'width:'+Iwidth+'px;');
                    //老的div减去相应的宽度
                    //旧宽度
                    var oW=document.getElementById(topID).style.width.replace('px','');
                    //新宽度
                    var nW=(document.getElementById(topID).offsetWidth-borderWidth-Iwidth);
                    
                    var thisrate=parseFloat(nW/oW);
 
                    document.getElementById(topID).style.width=nW;
                    document.getElementById(topID).outerHTML =tdivContent+''+document.getElementById(topID).outerHTML;
                    
                    if(topID.indexOf("MAIN_")>-1)
                    {
                        DiffWidthByParObj(topID,thisrate);
                    }
                    //new dialog().close();
                    break;
                
                }
                case '右面':
                {
//                    tdivContent=tdivContent.replace(/\{2\}/g,'width:'+Iwidth+'px;');
//                    //老的div减去相应的宽度
//                    document.getElementById(topID).style.width=(document.getElementById(topID).offsetWidth-borderWidth-Iwidth);
//                    document.getElementById(topID).outerHTML=document.getElementById(topID).outerHTML+tdivContent+'';break;
                    tdivContent=tdivContent.replace(/\{2\}/g,'width:'+Iwidth+'px;');
                    //老的div减去相应的宽度
                    //旧宽度
                    var oW=document.getElementById(topID).style.width.replace('px','');
                    //新宽度
                    var nW=(document.getElementById(topID).offsetWidth-borderWidth-Iwidth);
                    
                    var thisrate=parseFloat(nW/oW);
 
                    document.getElementById(topID).style.width=nW;
                    document.getElementById(topID).outerHTML=document.getElementById(topID).outerHTML+tdivContent+'';
                    
                    if(topID.indexOf("MAIN_")>-1)
                    {
                        DiffWidthByParObj(topID,thisrate);
                    }
                    break;

                }
                 case '内部':
                {
//                    var innerID=topID.replace('block','blockC');
//                    
//                    
//                    
//                    tdivContent=tdivContent.replace(/\{2\}/g,'width:'+Iwidth+'px;'); 
//                    document.getElementById(innerID).innerHTML=document.getElementById(innerID).innerHTML+tdivContent;
//                    if(topID.indexOf('MAIN_')==-1)
//                    {
//                        document.getElementById(topID).id='MAIN_'+document.getElementById(topID).id;
//                        topID='MAIN_'+topID; //父级不再有事件
//                        
//                        document.getElementById(innerID).id='MAIN_'+document.getElementById(innerID).id;
//                        
//                    }
//                    
                    break;

                }
           
           }
           FloatAll();
           

            //设定当前选的为新加入的
           //topID=newDivID;
           mbLine();
           getNumber();
           SaveHTML();
        
    }
    

//在内部插入框架
function InsertInner(strVa,BorderWidth)
{
    var re='';
    
    var str=strVa.split(',');
    var topWidth=document.getElementById(topID.replace('block_','blockC_')).offsetWidth;
    //左右加入的边框值
    var borderWidth=2;
    
    //要减掉左右的padding值
    var InnerID=topID.replace('block_','blockC_');
    var pleft=(document.getElementById(InnerID).style.paddingLeft==null?'0px':document.getElementById(InnerID).style.paddingLeft);
        pleft=pleft.replace('px','');
        
    var pright=(document.getElementById(InnerID).style.paddingRight==null?'0px':document.getElementById(InnerID).style.paddingRight);
        pright=pright.replace('px','');   
    
    topWidth=topWidth-pleft-pright;
    
    

    var innerID=topID.replace('block','blockC');
    var newDivID=topID.replace('MAIN_','');
    for(var i=0;i<str.length;i++)
    {
         newDivID=getRandDivID(newDivID);
 
        if(str[i]<10){str[i]='0'+str[i];}
        var w='100%';
        if(str[i]=='100')
        {
             w=topWidth;
        }else
        {
             w=parseInt(parseFloat('0.'+str[i])*topWidth)-borderWidth;
        }
        
        //alert('0.'+str[i]);
        //换参数
       var t=''
       var sPath = document.location.pathname; //==by Leotiger
       if(sPath.indexOf('TypeSetTep.aspx')==-1)//非模板方式
       {
            t=divContent;
       }else
       {
            t=tem_divContent;
       }
 
        if(str.length>1)
            t=t.replace(/\{2\}/g,'width:'+w+'px;float:left;'); 
        else
            t=t.replace(/\{2\}/g,'width:'+w+'px;'); 
        
        t=t.replace(/\{0\}/g,newDivID);
        t=t.replace(/\{1\}/g,newDivID.replace('block_','blockC_'));
        re+=t;
    }
    
    if(str.length>1)
    {
        re+="<div class='clear'></div>";
    }
    
    document.getElementById(innerID).innerHTML=document.getElementById(innerID).innerHTML+re;
    
    if(topID.indexOf('MAIN_')==-1) //本是最终级
    {
        document.getElementById(topID).id='MAIN_'+document.getElementById(topID).id; 
        topID='MAIN_'+topID; //父级不再有事件
        document.getElementById(innerID).id='MAIN_'+document.getElementById(innerID).id;
        
    }
    SaveHTML();
    
    FloatAll();
    //设定当前选的为新加入的
    topID=newDivID;
    mbLine();
    try
    {
    getNumber();
    }catch(e){}
    
    closeContro1();
    
}    
//在内部插入容器用作拖动排版
function InsertContainer(strVa,BorderWidth)
{
    var re='<table id="{1}" width="{3}" cellpadding="{2}" border="1" class="EditContainer"  height="50" rel='+strVa+'><tr>';
    
    var str=strVa.split(',');
    var topWidth=document.getElementById(topID.replace('block_','blockC_')).offsetWidth;
    //左右加入的边框值
    var borderWidth=2;
    
    //要减掉左右的padding值
    var InnerID=topID.replace('block_','blockC_');
    var pleft=(document.getElementById(InnerID).style.paddingLeft==null?'0px':document.getElementById(InnerID).style.paddingLeft);
        pleft=pleft.replace('px','');
        
    var pright=(document.getElementById(InnerID).style.paddingRight==null?'0px':document.getElementById(InnerID).style.paddingRight);
        pright=pright.replace('px','');   
    
    topWidth=topWidth-pleft-pright;
    
    

    var innerID=topID.replace('block','blockC');
    var newDivID=topID.replace('MAIN_','');
    for(var i=0;i<str.length;i++)
    {
        newDivID=getRandDivID(newDivID);
 
        if(str[i]<10){str[i]='0'+str[i];}
        var w=str[i]+'%';
        
        //alert('0.'+str[i]);
        //换参数
       var t=''
       var sPath = document.location.pathname; //==by Leotiger
       if(sPath.indexOf('TypeSetTep.aspx')==-1)//非模板方式
       {
            t='<td {0} class="EditContainerUnit" valign="top"></td>';
       }else
       {
            t='<td {0} class="EditContainerUnit" valign="top"></td>';
       }
 
        if(str.length>1)
        {
            t=t.replace(/\{0\}/g,'width="'+w+'"');
        }
        else
        {
            t=t.replace(/\{0\}/g,'width:'+w+'px;'); 
        }
        
        re+=t;
    }
    
    re+='</tr></table>';
    re=re.replace(/\{1\}/g,newDivID);
    re=re.replace(/\{2\}/g,borderWidth); 
    re=re.replace(/\{3\}/g,topWidth); 

    document.getElementById(innerID).innerHTML=document.getElementById(innerID).innerHTML+re;    

    SaveHTML();
    reloadball();
}


//得到所有的可移动排版对象(等getReginData结束)
function getbaseball() //初始化时用
{

    var o=$('.EditContainer').find('.MovClass');
    if(o)
    {
        for(var i=0;i<o.length;i++)
        {
 
            o[i].style.display='';
            o[i].className='basebat';
        }
 
    }
}

//更新当前文档内的拖放排版内容(等getReginData结束或中间)
function reloadball() //"#left,#center,#right,#left2,#center2,#right2" 或 .ClassName 传进来
{
    if($(".EditContainerUnit").length>0)
    {
      $.baseball({
	    accepter:".EditContainerUnit",
	    target:".baseball",	
	    handle:".basebat"
	    })
	    
	 }   
    
}

function InitEditContainer()
{
    var ec=$('.EditContainer');
    if(ec)
    {
        for(var i=0;i<ec.length;i++)
        {
            //$(ec[i]).css("border","1px");
            ec[i].border='1px';
//            var tableid=ec[i].id;
//            
//            var tableobj=document.getElementById(tableid);
//            tableobj.onmouseover=function()
//            {
//                var rel="";
//                if(tableobj.rel!=undefined&&tableobj.rel!=""&&tableobj.rel!=null)
//                {
//                    rel=tableobj.rel;
//                }
// 
//                ShowEditContainerEdit(rel);
//            }
            
            
        }
    }
}

//关于容器表格
function ShowEditContainerEdit(rel)
{
    alert(rel);

}

try
{
    jQuery.fn.outerHTML = function(s) {
    return (s)
    ? this.before(s).remove()
    : jQuery("<p>").append(this.eq(0).clone()).html();
    }
}catch(e){}

//把某DivName内容放入容器
function InsertDivToContainer(DivName)
{
    var o=null;
    if(topID!=undefined&&topID!='')
    {
        o=$('#'+topID).find('.EditContainerUnit');
    }
    
    if(o==null||o.length==0)
    {
        o=$('#container').find('.EditContainerUnit');
    }
    
    if(o!=null&&o.length>0)
    {
    
        //把Div的abs属性等去掉
        if(document.getElementById(DivName).className=='EditRegin')
        {
            document.getElementById(DivName).className='baseball EditRegin';
        }

        
        //document.getElementById(DivName).in='1'; //给一个特别标识,现在用baseball
        var thisobj=document.getElementById(DivName);
        
        var _c=$(thisobj).outerHTML();
        //var _c=document.getElementById(DivName).outerHTML;
    
         
        document.getElementById(DivName).outerHTML='';
        //o[0].innerHTML=o[0].innerHTML+_c;
        
        
        $(o[0]).html($(o[0]).html()+_c);
        
        
        document.getElementById(DivName).style.styleFloat='left';
        document.getElementById(DivName).style.position='';
        document.getElementById(DivName).style.width='100%';
        document.getElementById(DivName).style.margin='0px';
        document.getElementById(DivName).style.border='0px';
        document.getElementById('DV_'+DivName).style.display='none';
        document.getElementById('menu_contaner').style.display='none';
 
        document.getElementById('Mov_'+DivName).style.display='';
        document.getElementById('Mov_'+DivName).style.styleFloat='left';
        document.getElementById('Mov_'+DivName).className='basebat';
        
//        document.getElementById(DivName).onmouseover=function()
//        {
//            showEditGif(DivName);
//        }
 
        //计算外框高度
        if(topID!=''&&topID!=undefined)
        {
            var EditContainerObj=$('#'+topID).find('.EditContainer');
            var _maxheight=0;
            if(EditContainerObj.length>0)
            {
                for(var i=0;i<EditContainerObj.length;i++)
                {
                   _maxheight=EditContainerObj[i].offsetHeight;
                }
            }
            if(_maxheight>0)
            
            setHeightByID(topID,_maxheight);
            //$('#'+topID).css('height',_maxheight);
        }
 
        
        
        SaveHTML();
        reloadball();
    }else
    {
        alert('当前没有容器,请在面板上先添加布局控件!');
    
    }
    
 
    
}

//把某DivName移出容器
function RemoveOutContainer(DivName)
{

    document.getElementById(DivName).className='EditRegin';
    
    document.getElementById(DivName).style.styleFloat='';
    document.getElementById(DivName).style.position='';
    document.getElementById(DivName).style.width='100%';
    document.getElementById(DivName).style.margin='0px';
    document.getElementById(DivName).style.border='0px';
    document.getElementById('DV_'+DivName).style.display='none';
    document.getElementById('menu_contaner').style.display='none';

    document.getElementById('Mov_'+DivName).style.display='none';

    document.getElementById('Mov_'+DivName).className='';

    var thisobj=document.getElementByid(DivName);
 
 
    var _Content=$(thisobj).outerHTML();
    
    //var _Content=document.getElementById(DivName).outerHTML;
    document.getElementById(DivName).outerHTML=''; //清空
    //$('#'+DivName).outerHTML(' ');
    

    
    AddHTMLContent(_Content);//重新加入
    
    
//    document.getElementById(DivName).onmouseover=function()
//    {
//        showEditGif(DivName);
//    }
    
    reloadball();
}


//加入选项卡

function AddtoTab(str)
{
    
    var InnerID=topID.replace('block_','blockC_');
    
    str=str.replace('<\/script>','</sc'+'ript>');
    document.getElementById(InnerID).innerHTML=document.getElementById(InnerID).innerHTML+str;
    
    //document.getElementById(topID).id='MAIN_'+document.getElementById(topID).id; 
    //topID='MAIN_'+topID; //父级不再有事件
    
    FloatAll();


    //设定当前选的为新加入的
    //topID=newDivID;
    mbLine();
    getNumber();
    SaveHTML();
}
   

//删除当前的div
function Button1_onclick() {
    if(confirm('确认删除当前区域吗?'))
    {
        document.getElementById(topID).outerHTML='';
        mbLine();
        getNumber();
        //document.getElementById("ALL").value=document.body.innerHTML;
        FloatAll();
        SaveHTML();
    }
}

//整体换宽度
function ReSizeAll()
{
    var oriW=0;
    
    if(document.getElementById('container').width==null)
    {
        oriW=document.getElementById('container').offsetWidth;
    }else oriW=document.getElementById('container').width;
    
    document.getElementById('container').width=newW;
    
    var newW=document.getElementById('thisPageWidth').value;

    var rate=parseFloat(newW/oriW);
 
    var o=document.getElementsByTagName("div");
	    for(var i=0;i<o.length;i++)
	    {
	        if(o[i].className=='mainblock')
	        {
	            o[i].style.width=o[i].style.width.replace('px','')*rate+'px';
 
	        }
	    }
	 
    mbLine();
    SaveHTML();  
}

//由父宽变化得到所有子宽也相应变化
function DiffWidthByParObj(parID,thisrate)
{
    var ParObj=document.getElementById(parID);
    var ParinnserHTML=ParObj.innerHTML;
    
 
    var reSu=ParinnserHTML.match(/WIDTH: ?\d+(?=px)/ig);
    if (reSu!=null) {
        for (var i = 0; i < reSu.length; i++)   
        {   
            var tp=reSu[i];
            tp=tp.replace('WIDTH','').replace(':','').replace(' ','');
            
            var newWidth=parseInt(parseInt(tp)*thisrate);
            
            tp="WIDTH: "+newWidth;
            
            ParinnserHTML=ParinnserHTML.replace(reSu[i],tp);
        }  
      ParObj.innerHTML=ParinnserHTML;
    
    } 
    
}



//产生随机数
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() {
　　　　rnd.seed = (rnd.seed*9301+49297) % 233280;
　　　　return rnd.seed/(233280.0);
};
function rand(number) {
　　　　return Math.ceil(rnd()*number);
};


//统一向布局里加入html内容
 
function AddHTMLContent(inHtml)
{
    inHtml=inHtml.replace('<\/script>','</sc'+'ript>');
    var innertopID=topID.replace('block_','blockC_');
    
    
    //document.getElementById(innertopID).innerHTML=document.getElementById(innertopID).innerHTML+inHtml;
    
    var thisobj=document.getElementById(innertopID);
    
    $(thisobj).html($(thisobj).html()+inHtml);
    
    //内部的已有对像
    var InObj=$(thisobj).find('.EditRegin');
    if(InObj)
    {
        var absposition=''; //是否绝对定位
        var _maxtop=0; //如果有浮动,算到最大的高度 marginTop+offsetHeight
        
        if(InObj[0].style.marginTop!=null&&InObj[0].style.marginTop!='')
            _maxtop=parseInt(InObj[0].style.marginTop)+InObj[0].offsetHeight;
        else
            _maxtop=InObj[0].offsetHeight;
            
        
             for(var i=0;i<InObj.length-2;i=i+2)
             {
                if(InObj[i+2].style.marginTop!=null&&InObj[i+2].style.marginTop!='')
                {
                    if(_maxtop<parseInt(InObj[i+2].style.marginTop)+InObj[i+2].offsetHeight)
                    {
                        _maxtop=parseInt(InObj[i+2].style.marginTop)+InObj[i+2].offsetHeight;
                    }
                }
                
                if(InObj[i].style.position!=undefined&&InObj[i].style.position=='absolute')
                {
                    absposition='absolute';
                }
                        
             }
        
    
            if(absposition!='')
            {
                //找到DivName
                var reg=/<div id=.+?>/i;
                var result=inHtml.match(reg);
                if(result!=null)
                {
                    var resultStr=String(result);
                    var DivName=resultStr.replace('<DIV id=','').replace(' class=EditRegin>','');
                    if(DivName!='')
                    PreFloatDiv(DivName);
                    
                    if(_maxtop!=0)
                    {
                    
                        var _selfHeight=document.getElementById(DivName).offsetHeight;
                        
                        var thisDivName=document.getElementById(DivName);
                        
                        $(thisDivName).css('marginTop',parseInt(_maxtop)+4);
                    
                        //$('#'+innertopID).css("height", parseInt(_maxtop)+_selfHeight+4);
                        setHeightByID(innertopID,parseInt(_maxtop)+_selfHeight+4);
                    }
                }


            }
    

        }
        

    SaveHTML();
    reloadball();
}
 


//统一向布局里加入html内容
function EditHTMLContent(inHtml,DivName)
{
    inHtml=inHtml.replace('</script>','</sc'+'ript>');
    //inHtml=inHtml.replace("\'","\'\'");
    //document.getElementById(DivName).innerHTML=inHtml;
    
    var thisobj=document.getElementById(DivName);
    
    $(thisobj).html(inHtml);
    SetMaxHeightByDivName(DivName);
    
    //如果是在容器里的
    if(document.getElementById(DivName).className.toLowerCase().indexOf('baseball')>-1)//已是内容
    {
        //执行本Div是容器里的样式
                document.getElementById(DivName).style.styleFloat='left';
        document.getElementById(DivName).style.position='';
        document.getElementById(DivName).style.width='100%';
        document.getElementById(DivName).style.margin='0px';
        document.getElementById(DivName).style.border='0px';
        document.getElementById('DV_'+DivName).style.display='none';
        document.getElementById('menu_contaner').style.display='none';
 
        document.getElementById('Mov_'+DivName).style.display='';
        document.getElementById('Mov_'+DivName).style.styleFloat='left';
        document.getElementById('Mov_'+DivName).className='basebat';
 
        //计算外框高度
        if(topID!=''&&topID!=undefined)
        {
            var EditContainerObj=$('#'+topID).find('.EditContainer');
            var _maxheight=0;
            if(EditContainerObj.length>0)
            {
                for(var i=0;i<EditContainerObj.length;i++)
                {
                   _maxheight=EditContainerObj[i].offsetHeight;
                }
            }
            if(_maxheight>0)
            
            setHeightByID(topID,_maxheight);
            //$('#'+topID).css('height',_maxheight);
        }
    }
    
    
    SaveHTML();
    reloadball();
    
}

//邮一个DivName设置其外层高度
function SetMaxHeightByDivName(DivName)
{
    
    //找出父级
    var thisobj=document.getElementById(DivName);
    
    var ParObj=$(thisobj).parent()[0];
    //计算父级里所有的EditRegin
    if(ParObj)
    {
        var InObj=$(ParObj).find('.EditRegin');
        var absposition=''; //是否绝对定位
        var _maxtop=0; //如果有浮动,算到最大的高度 marginTop+offsetHeight
        
        if(InObj.length>0)
        {
        
            if(InObj[0].style.marginTop!=null&&InObj[0].style.marginTop!='')
                _maxtop=parseInt(InObj[0].style.marginTop)+InObj[0].offsetHeight;
            else
                _maxtop=InObj[0].offsetHeight;
            
            for(var i=0;i<InObj.length-2;i=i+2)
             {
                if(InObj[i+2].style.marginTop!=null&&InObj[i+2].style.marginTop!='')
                {
                    if(_maxtop<parseInt(InObj[i+2].style.marginTop)+InObj[i+2].offsetHeight)
                    {
                        _maxtop=parseInt(InObj[i+2].style.marginTop)+InObj[i+2].offsetHeight;
                    }
                }
                
                if(InObj[i].style.position!=undefined&&InObj[i].style.position=='absolute')
                {
                    absposition='absolute';
                }
                        
             }
             
             if(absposition!='')
                {
     
                    if(_maxtop!=0)
                    {
                        //算padding-bottom
                        if(ParObj.style.paddingBottom==null||ParObj.style.paddingBottom==undefined||ParObj.style.paddingBottom==""){}
                        else
                        _maxtop+=parseInt(ParObj.style.paddingBottom);
                    
                        //$(ParObj).css("height",_maxtop);
                        setHeightByObj(ParObj,_maxtop);
                    }
     

                }
             
         }
    
    }
}


function setAllMaxHeight()
{
    var obj=$('#container').find('.mbContent,.tem_mbContent');
    for(var i=0;i<obj.length;i++)
    {

            setMaxHeightByblockCID(obj[i]);

    }
    
}

//检测当前区域的浮动层的最大值是否比offsetHeight大,如果更大则给值,否则会自动撑开，但当外面有style.height值时不撑开，也移不动
function CheckthisBlockHeight()
{
    if(topID!=undefined&&topID!='')
    {
        var innertopID=topID.replace('block_','blockC_');
        var thisblockHeight=document.getElementById(topID).offsetHeight;
        
        var InObj=$('#'+topID).find('.EditRegin');
        var absposition=''; //是否绝对定位
        var _maxtop=0; //如果有浮动,算到最大的高度 marginTop+offsetHeight
        
        if(InObj.length>0)
        {
        
        
            if(InObj[0].style.position!=undefined&&InObj[0].style.position=='absolute')
            {
                if(InObj[0].style.marginTop!=null&&InObj[0].style.marginTop!='')
                    _maxtop=parseInt(InObj[0].style.marginTop)+InObj[0].offsetHeight;
                else
                    _maxtop=InObj[0].offsetHeight;
            }
        
            for(var i=0;i<InObj.length-1;i=i+1)
             {
                  if(InObj[i].style.position!=undefined&&InObj[i].style.position=='absolute'&&InObj[i].rel!='1')
                  {
                        var _mtop=0;
                        if(InObj[i].style.marginTop!=""&&InObj[i].style.marginTop!=null)_mtop=parseInt(InObj[i].style.marginTop);
                        
         
                        if(_maxtop<_mtop+InObj[i+1].offsetHeight)
                        {
                            _maxtop=_mtop+InObj[i+1].offsetHeight;
                        }
                     
                         absposition='absolute';
 
                   }         
             }
             
             //检有没有EditContainer //注意 EditContainer里面的不能算在上面
             var EditContainerObj=$('.EditContainer');
             if(EditContainerObj!=null&&EditContainerObj.length>0)
             {
                for(var i=0;i<EditContainerObj.length;i++)
                {
                    _maxtop+=EditContainerObj[i].offsetHeight;
                }
             
             }
             
             
             if(absposition!='')
            {
 
                //if(_maxtop!=0&&_maxtop>thisblockHeight)
                //{
                    //$(ParObj).css("height",_maxtop);
                    
                    
                    //算padding-bottom
                    var ParObj=document.getElementById(innertopID);
                    if(ParObj!=null)
                    {
                        if(ParObj.style.paddingBottom==null||ParObj.style.paddingBottom==undefined||ParObj.style.paddingBottom==""){}
                        else
                        _maxtop+=parseInt(ParObj.style.paddingBottom);
                    }
                    
                    setHeightByID(innertopID,_maxtop);
                //}
 

            }else
            {
                setHeightByID(innertopID,100);
            }
        }
        
    }
    
    
}

function setMaxHeightByblockCID(ParObj)
{
    //找出父级
    //var ParObj=$('#'+blockCID);
    //计算父级里所有的EditRegin
    if(ParObj)
    {
        var InObj=$(ParObj).find('.EditRegin');
        var absposition=''; //是否绝对定位
        var _maxtop=0; //如果有浮动,算到最大的高度 marginTop+offsetHeight
        
        if(InObj.length>0)
        {
 
        
            if(InObj[0].style.marginTop!=null&&InObj[0].style.marginTop!='')
                _maxtop=parseInt(InObj[0].style.marginTop)+InObj[0].offsetHeight;
            else
                _maxtop=InObj[0].offsetHeight;
            
            for(var i=0;i<InObj.length;i++)
             {
                
                //设置的内部高度先撑开
                var DivName=InObj[i].id;

                if(DivName)AutoiHeight(DivName);
                
                try
                {
                        if(InObj[i+1].style.marginTop!=null&&InObj[i+1].style.marginTop!='')
                        {
                            if(_maxtop<parseInt(InObj[i+1].style.marginTop)+InObj[i+1].offsetHeight)
                            {
                                _maxtop=parseInt(InObj[i+1].style.marginTop)+InObj[i+1].offsetHeight;
                            }
                        }

                        
                        if(InObj[i].style.position!=undefined&&InObj[i].style.position=='absolute')
                        {
                            absposition='absolute';
                        }
                  }catch(e){}
                        
             }
             
             if(absposition!='')
                {
     
                    if(_maxtop!=0)
                    {
                       if(ParObj.style.paddingBottom==null||ParObj.style.paddingBottom==undefined||ParObj.style.paddingBottom==""){}
                        else
                        _maxtop+=parseInt(ParObj.style.paddingBottom);
                        
                        setHeightByObj(ParObj,_maxtop);
                    }
     

                }
             
         }
    
    }
}


function DelDiv(DivName,pageid)
{
 
    document.getElementById('DV_'+DivName).outerHTML='';
    document.getElementById(DivName).outerHTML='';
 
    setAllMaxHeight();
    
    //实际删除Div
    ExecuteNonQuery('../MContent/DivDel.aspx?DivName='+DivName+'&pageid='+pageid);
    //
    SaveHTML();
    
}

function AddEditRegion(iid,RegionName)
{

    var oHTML=document.getElementById(topID).outerHTML;
    oHTML=oHTML.replace('mainblock','mainblock style="borderWidth:0px;padding:0px"');
    oHTML=oHTML.replace('mbPadding','mbPadding style="borderWidth:0px;padding:0px"');
    oHTML=oHTML.replace('mbContent','mbContent style="borderWidth:0px;padding:0px"');
    
    document.getElementById(topID).outerHTML=oHTML;
    setTimeout('InHTML(\''+iid+'\',\''+RegionName+'\');',100);

}

                //廷时执行下面
                function InHTML(iid,RegionName)
                {
                    var innertopID=topID.replace('block_','blockC_');
                    var t='<span style=\'display:none;\'>a</span><!--RegionContent_S'+iid+'--><div style=\"width:100%; height:100%;background:aqua; vertical-align:middle;text-align:center;\">'+RegionName+'</div><!--RegionContent_O'+iid+'-->';
                    //alert(t);
                    document.getElementById(innertopID).innerHTML=t;
                    SaveHTML();
                }

function setBgColor(va)
{
    if(topID!='')
    {
        document.getElementById(topID).style.backgroundColor=va;
        //var innertopID=topID.replace('block_','blockC_');
        document.getElementById(topID).style.backgroundColor=va;
        SaveHTML();
        
    }
}


function setBorderBgColor(BorderWidthVa,BorderColor,BorderType,type)
{
    if(topID!='')
    {
        if(BorderColor.indexOf('#')==-1&&BorderColor!='')BorderColor='#'+BorderColor;
        
         var vastr='\''+ BorderWidthVa+'px'+' '+BorderType+ ' '+BorderColor+'\'';
         
         var exeStr='document.getElementById(\''+topID+'\').style.'+type+'='+vastr+';';
         //alert(exeStr);
         eval(exeStr);
//         
//        
//         document.getElementById(topID).style.borderTop=''+ BorderWidthVa+'px' BorderType;
//         document.getElementById(topID).style.borderColor=BorderColor;
//         document.getElementById(topID).style.borderStyle=BorderType;
         SaveHTML();
         
        
    }
}

//列表默认样式及鼠标样式
function OnDefaultStyle(o,defalutcss)
{
	if(defalutcss.indexOf('height')==-1)
	defalutcss+="height:100%;";
	o.style.cssText=defalutcss;
}
//移上去
function OnOverStyle(o,overcss)
{
	if(overcss.indexOf('height')==-1)
	overcss+="height:100%;";
	o.style.cssText=overcss;
}


//显示大图
function ShowThisForMainPic(tagid,o)
{
    document.getElementById(tagid).src=o.rel;
    document.getElementById(tagid.replace('MainPic','MainPicLink')).href=o.rel;
}


 
//DivContainter中显示菜单
var _menuTimeOut=null;


function ShowContainerMenu(FileName,DivName,pageid)
{
 
    var _t='<div style="width:120px;  border:#CCC 1px solid; margin:2px; text-align:left; line-height:20px;">\
        <div style="background-color:#efefef; padding-left:10px;" ><a href="javascript:ShowC1(\''+FileName+'?DivName='+DivName+'&pageid='+pageid+'\',650,420);">属性和边框</a></div>\
        <div style="background-color:#efefef;padding-left:10px;"><a onclick="return confirm(\'确认删除吗?\');" href="javascript:DelDiv(\''+DivName+'\',\''+pageid+'\');">删除...</a></div>';
      
      if(document.getElementById(DivName).className.toLowerCase().indexOf('baseball')>-1)//已是内容
      {
        _t+= '<div style="background-color:#efefef;padding-left:10px;"><a  href="javascript:RemoveOutContainer(\''+DivName+'\');">移出容器</a></div>';
      }else
      {
        _t+= '<div style="background-color:#efefef;padding-left:10px;"><a  href="javascript:InsertDivToContainer(\''+DivName+'\');">放入容器</a></div>';
      }
      
        
        if(document.getElementById(DivName).style.position.toLowerCase()=='absolute')
        {
           _t+= '<div style="background-color:#efefef;padding-left:10px;"><a onclick="return confirm(\'确认删除浮动吗?\');" href="javascript:RemoveFloatDiv(\''+DivName+'\');">删除浮动</a></div>';
           
           if(document.getElementById(DivName).rel)
           {
                if(document.getElementById(DivName).rel==0)
                {
                    _t+= '<div style="background-color:#efefef;padding-left:10px;"><a  href="javascript:SetOverFlow(\''+DivName+'\',\'1\');">设全局浮动</a></div>';
                }else
                {
                    _t+= '<div style="background-color:#efefef;padding-left:10px;"><a  href="javascript:SetOverFlow(\''+DivName+'\',\'0\');">设局部浮动</a></div>';
                }
           }else _t+= '<div style="background-color:#efefef;padding-left:10px;"><a  href="javascript:SetOverFlow(\''+DivName+'\',\'1\');">设全局浮动</a></div>';
           
           //上置下置
            _t+= '<div style="background-color:#efefef;padding-left:10px;"><a  href="javascript:SetDivNameZindex(\''+DivName+'\',\'0\');">上置一层</a></div>';
            _t+= '<div style="background-color:#efefef;padding-left:10px;"><a  href="javascript:SetDivNameZindex(\''+DivName+'\',\'1\');">下置一层</a></div>';
           
           
        }
        else
        {
            if(document.getElementById(DivName).className.toLowerCase().indexOf('baseball')==-1)//容器内的不能浮动
            {
                _t+= '<div style="background-color:#efefef;padding-left:10px;"><a onclick="return confirm(\'确认设为浮动吗?\');" href="javascript:PreFloatDiv(\''+DivName+'\');">设为浮动</a></div>';
            }
        }
        
        _t+= '<div style="background-color:#efefef;padding-left:10px;"><a  href="javascript:ShowSetDivNameHeight(\''+DivName+'\');">设置高度及滚动</a></div>';
        
        _t+= '</div>';
 
        var p_top=0;
        var p_left=0;
                
 
        if(document.getElementById(DivName).style.position.toLowerCase()=='absolute')
        {
            p_top=parseInt(document.getElementById(DivName).offsetTop);
            p_left=parseInt(document.getElementById(DivName).offsetLeft);
        }else
        {
            p_top=parseInt(document.getElementById('DV_'+DivName).offsetTop);
            p_left=parseInt(document.getElementById('DV_'+DivName).offsetLeft);
        }
        //alert(p_top);
        
 
        document.getElementById('menu_contaner').style.top=p_top;
        document.getElementById('menu_contaner').style.left=p_left;
        document.getElementById('menu_contaner').innerHTML=_t;
        document.getElementById('menu_contaner').style.display='';
        document.getElementById('menu_contaner').style.position='absolute';
        
        if(document.getElementById('menu_contaner'))
        {
            document.getElementById('menu_contaner').onmouseover=function()
            {
                if(_menuTimeOut!=null)
                {
                    clearTimeout(_menuTimeOut);
                }
            }
            
            document.getElementById('menu_contaner').onmouseout=function()
            {
                
                HimenuClass(DivName);
            }
        
        }
        
        return;
        
        
        
}
//document.onmousedown=ClosemenuClass;


function ShowSetDivNameHeight(DivName)
{
    var url='/MContent/SetDivNameHeight.aspx?DivName='+DivName;
    var title='';
    if(document.getElementById(DivName).title!=''&&document.getElementById(DivName).title!=undefined) //能显示出来，不太好
    {
        title=document.getElementById(DivName).title;
    }
    
    var direction='';
    if(document.getElementById(DivName).direction!=''&&document.getElementById(DivName).direction!=undefined)
    {
        direction=document.getElementById(DivName).direction;
    }
    var scrollamount='';
    if(document.getElementById(DivName).scrollamount!=''&&document.getElementById(DivName).scrollamount!=undefined)
    {
        scrollamount=document.getElementById(DivName).scrollamount;
    }
    
    url+='&title='+title+'&direction='+direction+'&scrollamount='+scrollamount;
    
    lhgdialog.opendlg( '自定义高度',url , 400, 250,true);
}


function SetDivNameHeight(DivName,heightva,_direction,_scrollamount)
{
    var thisobj=document.getElementById(DivName);

    //alert($('#'+DivName).find('.textBg_02,.pointer').length);
    if($(thisobj).find('.textBg_02,.pointer').length>0)
    {
         $(thisobj).find('.textBg_02,.pointer').css("height",heightva);
         $(thisobj).find('.textBg_02,.pointer').css("overflow","hidden");
         document.getElementById(DivName).title=String(heightva); //内部高度给个属性 兼容问题？
         if(_direction!='')
         document.getElementById(DivName).direction=_direction;
         document.getElementById(DivName).scrollamount=_scrollamount;
         AutoiHeight(DivName);
    }
    
    SaveHTML();
}

//由Divname自动计算内部高度
function AutoiHeight(DivName)
{
    if(document.getElementById(DivName).title!=undefined&&document.getElementById(DivName).title!=''&&document.getElementById(DivName).title!=null)
    {
        var thisobj=document.getElementById(DivName);
        $(thisobj).find('.textBg_02').css("height",parseInt(document.getElementById(DivName).title));
        $(thisobj).find('.textBg_02').css("overflow","hidden");
    }
    
            
    if(document.getElementById(DivName).direction!=undefined&&document.getElementById(DivName).direction!='')
    {
    
        var _direction=document.getElementById(DivName).direction;
        var _scrollamount=2;
        if(document.getElementById(DivName).scrollamount!=''&&document.getElementById(DivName).scrollamount!=undefined)
        {
            _scrollamount=document.getElementById(DivName).scrollamount;
        }
    
        $('#'+DivName).find('.textBg_02').attr('direction',_direction);
        $('#'+DivName).find('.textBg_02').attr('scrollamount',_scrollamount);
        //$('#'+DivName).find('.textBg_02').marquee('');

        $('#'+DivName).find('.textBg_02').marquee('pointer').mouseover(function () {  $(this).trigger('stop');}).mouseout(function () {  $(this).trigger('start');}).mousemove(function (event) {  if ($(this).data('drag') == true) {    this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);  }}).mousedown(function (event) {  $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);}).mouseup(function () {  $(this).data('drag', false);});


    }
    
}

function SetDivNameZindex(DivName,type)
{
       //上置下置
       if(document.getElementById(DivName).style.zIndex!=null||document.getElementById(DivName).style.zIndex!=undefined||document.getElementById(DivName).style.zIndex!='')
       {
            if(type==0)
                document.getElementById(DivName).style.zIndex=document.getElementById(DivName).style.zIndex+1;
            else if(type==1)document.getElementById(DivName).style.zIndex=(document.getElementById(DivName).style.zIndex==0?0:document.getElementById(DivName).style.zIndex-1);
            else document.getElementById(DivName).style.zIndex=0;
       }else
       {
            document.getElementById(DivName).style.zIndex=0;
       }
       SaveHTML();
       HimenuClass(DivName);
}
 

function HimenuClass(DivName)
{
    try
    {
        if(document.getElementById('menu_contaner'))
        {
            _menuTimeOut=setTimeout('document.getElementById(\'menu_contaner\').style.display=\'none\'',100);
        }
    }catch(e){}
}


//第一次浮动
function PreFloatDiv(id)
{
     var t=document.getElementById('DV_'+id);
        if(t!=null)
        {       
                //FloatAll();
                document.getElementById(id).style.width=getWidth(id);
                document.getElementById(id).style.position='absolute';
//                t.style.display='';
//                t.style.left='';
//                t.style.top='';
                
                t.style.cssText='width:240px;height:20px;position:absolute;z-index:1000;';
                
                FloatDiv(id);
                document.getElementById('Mov_'+id).style.display='';
  
         }    
}



//设为浮动
function FloatDiv(DivName)
{
    
 
    //document.getElementById(DivName).style.position='absolute';
    document.getElementById('Mov_'+DivName).style.cursor='move';
    document.getElementById('Mov_'+DivName).style.display='';
 
    var o=document.getElementById(DivName);
    
    $(o).hover(function() { 
            ShowRedLine(o,1);
        }, function() { 
           ShowRedLine(o,0);
        }); 
 
    
    document.getElementById(DivName).onmousemove=function()
    {
        obj_moveMa(DivName);
    }
    
    document.getElementById(DivName).onmouseup=function()
    {
        obj_upMa(DivName);
    }
    
    document.getElementById(DivName).onmousedown=function()
    {
        obj_lsdownMa(DivName);
    }
    
    
    document.getElementById('Mov_'+DivName).onmousedown=function()
    {
        obj_downMa(DivName);
    }
    
    CheckthisBlockHeight();
}


var _redline=null;
 
function ShowRedLine(o,type)
{
 
    if(type==0)
    {
        $(o).css("border","0px");
    }
    
    else
    {
        $(o).css("border","1px dashed #ff0000");
        //clearTimeout(_redline);
    }

}

//在保存之前隐藏所有的红线 /暂不能用,有问题
function HiRedLine()
{
    var obj=$('#container').find('.EditRegin');
    if(obj)
    {
        for(var i=0;i<obj.length;i++)
        {
            $(obj[i]).css("border","0px");
        }
    }
}

function RemoveFloatDiv(DivName)
{
    document.getElementById(DivName).style.position='';
    
    document.getElementById(DivName).style.marginLeft=0;
    document.getElementById(DivName).style.marginTop=0;
    document.getElementById(DivName).style.width="auto";
    
    document.getElementById(DivName).style.cursor='default';
    document.getElementById('Mov_'+DivName).style.display='none';
    
    document.getElementById(DivName).onmousemove=function()
    {
        //javascript:void(0);
    }
    
    document.getElementById(DivName).onmouseup=function()
    {
        //javascript:void(0);
    }
    
    document.getElementById(DivName).onmousedown=function()
    {
        //javascript:void(0);
    }
    var thisobj=document.getElementById(DivName);
    $(thisobj).css("border","0px"); 
    CheckthisBlockHeight();
}

function SetOverFlow(DivName,type)
{
    document.getElementById(DivName).rel=type;
    document.getElementById('menu_contaner').style.display='none';
    
    if(type=='0')
    {
        document.getElementById(DivName).style.marginTop='0px';
        document.getElementById(DivName).style.marginLeft='0px';
    }
    
}

//给对象付高度的统一方法 //ie6,7,8,firefox
function setHeightByID(id,height) //height不带px
{
	var objCss=document.getElementById(id).style.cssText;
	var hasHeightReg=/;( +)?height ?: ?\d+/i;
	
	//如果有height则说明是调区域硬调的,不需要动态改高度了
	if(objCss!=undefined&&objCss!='')
	{
	    
	    if(objCss.match(hasHeightReg)!=null&&objCss.match(hasHeightReg)!='')
        {
            
        }else
        {
	
	        var regHeight=/MIN-HEIGHT: ?\d+px;?|_?height: ?\d+px;?/ig;
	        if(objCss!=undefined&&objCss!='')
	        {
		        objCss=objCss.replace(regHeight,'');
	        }

	        objCss=objCss+';min-height:'+height+'px;_height:'+height+'px;';
	        document.getElementById(id).style.cssText=objCss;
	     }   
	
	 }
	
	
	
}

function setHeightByObj(obj,height) //height不带px
{
    if(obj)
    {
	    var objCss=obj.style.cssText;
	    var hasHeightReg=/;( +)?height ?: ?\d+/i;
	    //如果有height则说明是调区域硬调的,不需要动态改高度了
	    if(objCss!=undefined&&objCss!='')
	    {
	        if(objCss.match(hasHeightReg)!=null&&objCss.match(hasHeightReg)!='')
	        {
	            
	        }else
	        {
        	    var regHeight=/MIN-HEIGHT: ?\d+px;?|_?height: ?\d+px;?/ig;
                objCss=objCss.replace(regHeight,'');
                objCss=objCss+';min-height:'+height+'px;_height:'+height+'px;';
                obj.style.cssText=objCss;
	        }
	    
	    }
	    

	}
}
