// JavaScript Document
var _G = jQuery.noConflict();
var editor; //自定义模块内容编辑时的编辑器
var spaceDiy = {
	// 加载空间装扮
	// 预先输出内容，页面加载完成后进行布局操作
	// 将模块内容布局到栏目
	reBuild : function()
	{ 
		
		if(moduleConfig.length > 1){	
		_G.each(moduleConfig,function(i,items)
		{
			if(diy==true)_G("#"+Modules[i]).empty();
			_G.each(items.split(","),function(m,mn)
			{	
				if(mn) {
					if(m==0)_G("#"+Modules[i]).empty();
					_G("#"+mn).appendTo(_G("#"+Modules[i]));
				}
			});	
		});	
		}else{
		_G.each( Modules, function(s, sn){	   		
	   		_G.each(ModuleItems[s], function(m, mn){    		
	    		if(_G("#"+mn) )
	    			{    		 	
	    		 	if(m==0)_G("#"+Modules[s]).empty();
	    		 	_G("#"+mn).appendTo(_G("#"+sn));
	    		 	}    			    			
	   			})
	  	}); 
	  }
	  _G("#contentlist").hide();// 隐藏缓存模块
	  if(uid){  
		  // 加载布局
		  container=container?container:'1:2:1';
		  spaceDiy.changeLayout(container,'loading');		 
	  } 
	   
	},
	//设计菜单切换
	showControl :function(e,nav){
		ctrArr= new Array('contentstart','contentframe','contentstyle','contentmodules','contentcustom');
		navArr= new Array('navstart','navlayout','navstyle','navblock','navdiy');
		_G.each(ctrArr,function(cid,cname){
		_G('#'+cname).hide();
		_G('#'+navArr[cid]).removeClass("current");
			if(e==cname){_G('#'+cname).show();_G('#'+navArr[cid]).addClass("current");}
		})
		if(e=='contentcustom'){		
			spaceDiy.setCurrentDiy("space");
		}
	},
	// changeLayout 版式布局切换函数
	// e 布局模式
	// type=loading 页面下载模式
	// 是css名.class
	// CssTextId 默认css数组编号
	changeLayout :function(e,type){
		// 布局模式
		var CssMode= new Array('1:2:1','1:1:2','2:1:1','2:2','1:3','3:1','1:4','4:1','2:2:1','1:2:2','1:1:3','1:3:1','3:1:1','3:2','2:3');
		//布局对应的css
		var CssText= new Array(['w240','w490','w240'],['w240','w240','w490'],['w490','w240','w240'],['w485','w485','wnone'],['w240','w730','wnone'],['w730','w240','wnone'],['w190','w780','wnone'],['w780','w190','wnone'],['w390','w390','w190'],['w190','w390','w390'],['w190','w190','w580'],['w190','w580','w190'],['w580','w190','w190'],['w580','w390','wnone'],['w390','w580','wnone']); 
		// 栏目id 左中右
		var Modules=new Array('frame1_left','frame1_center','frame1_right');
		var CssTextId=0;
		var ModuleItems="";
		_G.each( CssMode, function(m, mn){
			_G("#layout"+mn).removeClass("activity");
			if(e==mn)CssTextId=m;
			}); // css 赋值 
		 _G("#layout"+e).addClass("activity");
		 _G.each( Modules, function(s, sn){  
		  if(CssText[CssTextId][s]=='wnone' && type !="loading") {// 出现布局由3->2的变化,最右边栏目的内容搬到最左边															
		   ModuleItems=_G('#'+sn).sortable('toArray');// 获取最新的模块元素   
		   _G.each( ModuleItems, function(m, mn){    
		   _G("#frame1_left").append(_G("#"+mn));// 注意在两栏三栏间切换的时候,返回已丢失的模块,且要逐个添加									 
		   });
		   _G("#"+sn).empty();// 摧毁原有的元素，以免重复出现冲突
		  }  
		  _G("#"+sn).removeClass();// 清空css，以免css重复冲突
		  _G("#"+sn).addClass("z column " + CssText[CssTextId][s]);// 恢复css
		 });  
	},
	// makeStyle 主题切换
	// styleId 主题id
	// ie6下必须延迟执行
	makeStyle : function(t){
		 if (t == '') t='black';
		 //spaceDiy.reCallColor('clear');
		 _G("#stylevalue").val(t);
		 _G("#link"+styleConfig).removeClass();
		 _G("#link"+t).addClass("themeselect");
		 styleConfig=t;
		 window.setTimeout(function(){
		 _G("#stylecss").attr("href","static/space/" + t + "/style.css");	 
		 },5);	 
		 
	},
	// 模块配置
	// 隐藏的模块缓存到 #contentlist,需要时恢复
	configModule : function (mid){  
	 if(_G("#chk"+mid).attr("checked")) 
	 { 
		lItems=_G('#frame1_left').sortable('toArray');	
		if(typeof lItems[0] == 'undefined') {
			_G("#"+mid).appendTo(_G('#frame1_left'));
		}
		else 
		{
			_G("#"+mid).insertBefore(_G("#"+lItems[0]));
		}
	 }
	 else 
	 {
		  _G("#"+mid).appendTo(_G("#contentlist"));
	 }
	},
	// 添加新模块
	// 插入新的模块，模块名字:c_时间
	addModule :function(cp,formname,e){
		var ModuleId=_G("#mModuleId").val();
		var ModuleTitle=_G("#ModuleTitle").val();	
		var ModuleType=_G("#ModuleType").val();
		var ModuleContent=_G("#Content"+ModuleType).val();
		if(ModuleType=='1') //编辑器模式
		{
		ModuleContent=editor.getData();
		_G("#Content"+ModuleType).val(ModuleContent)
		}
		if(ModuleTitle==""){
			alert('标题是必须的～');
			_G("#ModuleTitle").focus();
			return false;
			}
		if(ModuleContent=="") {
			return confirm('没有内容，模块建立之后类型不能修改，你确定吗？');
		}	
		var itemHeaderCss="blocktitle title";
		var itemContentCss="content";
		var itemData="";
		if(ModuleType =='2'){
			if(checkImage(ModuleContent)=="")
			{
				alert('图片地址不存在或格式错误～');
				_G("#Content"+ModuleType).focus();		
				return false;
			}
			makeContent='<img src="'+ModuleContent +'" />'		
			itemData="<div id='"+ModuleId+"' class='block cursor move'><div class='blocktitle title'><span>"+ModuleTitle+"</span><span class=\"blockedit\"><a href=\"cp.php?ac=spaceconfig&op=editModule&moduleId="+ModuleId+"\" id=\"editItem_"+ModuleId+"\" onclick=\"ajaxmenu(event, this.id, 1)\">编辑</a></span></div><div class="+itemContentCss+">"+makeContent+"</div></div>";
		}
		else if(ModuleType > 2 )
		{
			if(checkvd(ModuleContent)=="")
			{
				alert('文件地址不存在或格式错误～');
				_G("#Content"+ModuleType).focus();		
				return false;		
			}		
			makeContent='<embed src="'+ModuleContent+'" quality="high" width="480" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>';
			itemData="<div id='"+ModuleId+"' class='block cursor move'><div class='blocktitle title'><span>"+ModuleTitle+"</span><span class=\"blockedit\"><a href=\"cp.php?ac=spaceconfig&op=editModule&moduleId="+ModuleId+"\" id=\"editItem_"+ModuleId+"\" onclick=\"ajaxmenu(event, this.id, 1)\">编辑</a></span></div><div class="+itemContentCss+">"+makeContent+"</div></div>";
		}else
		{	
			itemData="<div id='"+ModuleId+"' class='block cursor move'><div class='blocktitle title'><span>"+ModuleTitle+"</span><span class=\"blockedit\"><a href=\"cp.php?ac=spaceconfig&op=editModule&moduleId="+ModuleId+"\" id=\"editItem_"+ModuleId+"\" onclick=\"ajaxmenu(event, this.id, 1)\">编辑</a></span></div><div class="+itemContentCss+">"+ModuleContent+"</div></div>";
		}
		
		if(cp=='add'){
			_G("#contentlist").append(itemData);
			lItems=_G('#frame1_left').sortable('toArray');
			_G("#"+ModuleId).insertBefore(_G("#"+lItems[0]));// 在第一个模块前插	
		}else if(cp=='edit')
		{
			_G("#"+ModuleId).replaceWith(itemData);
		}
			
		_G("#"+ModuleId).css("cursor","move");
		var url="cp.php?ac=spaceconfig&op=saveModule&uid="+uid;
		var Data=_G("#"+formname).serialize();
		_G.post(url, Data, function(theResponse){			
			if(theResponse=="add"){
				mcontent="<li id=\"li"+ModuleId+"\"><input type=\"checkbox\" id=\"chk"+ModuleId+"\" checked=\"checked\" onclick=\"spaceDiy.configModule('"+ModuleId+"');this.blur();\" />"+ModuleTitle+"</li>";
				_G("#addnl").before(mcontent);	
				alert('模块添加成功');		
							
			}
			else if(theResponse=="update")
			{
				alert('已经更新');
				
			}else
			{
				alert('操作失败，请重试,请确认您输入的内容尽量不要包含\r\n\t script,iframe，onload 之类的特殊字符');		
				
			}
			_G("#append_parent").empty();
			_G("#mzoom").empty();		
			hideMenu();
		});
		
	},
	editModule : function(e,action)
	{
		if(action=='del' && confirm("模块删除不可恢复，请确认删除模块操作")) 
		{
			var data="ac=spaceconfig&op=delModule&moduleId="+e+"&uid="+uid;
			_G.get('cp.php', data, function(theResponse){
				if(theResponse=='done'){
					_G("#"+e).remove();
					_G("#li"+e).remove();
					hideMenu();	
				}else
				{
					alert('删除失败，请稍后重试');
				}		
			});			
		}
	},
	previewModule : function (formname){
		var ModuleType=_G("#ModuleType").val();	
		var itemHeaderCss="blocktitle title";
		var itemContentCss="content";
		var itemData="";
		var ModuleTitle=_G("#ModuleTitle").val();
		if(ModuleType =='2'){
			ModuleContent=_G("#Content"+ModuleType).val();	
			if(checkImage(ModuleContent)=="")
			{
				alert('图片地址不存在或格式错误～');
				_G("#Content"+ModuleType).focus();		
				return false;
			}
			makeContent='<img src="'+ModuleContent +'" />'		
			itemData="<div class='block cursor move'><div class='blocktitle title'><span>"+ModuleTitle+"</span></div><div class="+itemContentCss+">"+makeContent+"</div></div>";
		}
		else if(ModuleType > 2 )
		{
			ModuleContent=_G("#Content"+ModuleType).val();
			if(checkvd(ModuleContent)=="")
			{
				alert('文件地址不存在或格式错误～');
				_G("#Content"+ModuleType).focus();		
				return false;		
			}		
			makeContent='<embed src="'+ModuleContent+'" quality="high" width="480" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>';
			itemData="<div class='block cursor move'><div class='blocktitle title'><span>"+ModuleTitle+"</span></div><div class="+itemContentCss+">"+makeContent+"</div></div>";
		}else
		{
			
		   	ModuleContent=_G("#Content"+ModuleType).val();	   	 			
			itemData="<div  class='block cursor move'><div class='blocktitle title'><span>"+ModuleTitle+"</span></div><div class="+itemContentCss+">"+ModuleContent+"</div></div>";
		}	
			
	   	itemData =itemData + "<br><p><input type=\"button\" onclick=\"_G('#mzoom').show();_G('#previwzoom').empty()\" value=\"返回\" \/>  <input type=\"button\" onclick=\"_G('#btnsubmit').click()\" value=\"确定\" \/><\/p>"
		_G("#previwzoom").html(itemData);
		_G('#mzoom').hide('slow');	
	},
	addcontenttomd : function(eid,parentid){
		var pContent=_G("#"+parentid).val();
		var cContent=_G("#"+eid).val();
		if(typeof cContent == 'undefined' || cContent=="") {alert('图片路径不正确');_G("#"+eid).focus();return false;}
		var img="<img src='"+cContent+"' />";
		_G("#"+parentid).val(pContent+img);
		_G("#"+eid).val('');	
	},
	showMc : function(mcs,e){
		ids = mcs.split(",");
		for (var i=0;i<ids.length; i++)
		{	
	
			 _G("#"+ids[i]).hide("slow");
		}	
		 _G("#mc"+e).show("slow");
	
	},
	mSpaceTitle : function(formname){
		var mId=_G("#mId").val();
		if(mId=="") return false;		
		var url="cp.php?ac=spaceconfig&op=saveMf&uid="+uid;
		var Data=_G("#"+formname).serialize();
		_G.post(url, Data, function(theResponse){
			if(theResponse=='update')
			{		
		    alert('操作成功，你可能要刷新才能看到效果');
		    itemData="<span id='spacetitle'>"+_G("#mTitle").val()+"<a href='cp.php?ac=spaceconfig&op=editSpTitle&moduleId=spacetitle' id='sptitlelink' alt='点击编辑' onclick='ajaxmenu(event, this.id, 1)'>编辑<\/a><\/span>"
		    _G("#spacetitle").replaceWith(itemData);
			}
			else{alert('操作失败，请稍候重试')}
			hideMenu();
			_G("#__editmattr__"+mId).remove();//删除缓存表单
		});	
	
	},
	mFdone : function(formname){
		var mId=_G("#mId").val();
		var mNum=_G("#mNum").val();	
		if(mNum==""){alert('数量错误'); _G("#mNum").focus();return false;}			
		var url="cp.php?ac=spaceconfig&op=saveMf&uid="+uid;
		var Data=_G("#"+formname).serialize();
		_G.post(url, Data, function(theResponse){
			if(theResponse=='add' || theResponse=='update')
			{		
			_G("#"+mId+"_title").empty();
			_G("#"+mId+"_title").html(_G("#mTitle").val());
			alert('操作成功，你可能要刷新才能看到效果');
			}
			else{alert('操作失败，请稍候重试')}
			hideMenu();
			_G("#__editmattr__"+mId).remove();//删除缓存表单
		});		
		var mcontent= new Array();
		if(mId=='blog'){
			mcontent=_G("#"+mId).children(".content").children("ul").get();	
			_G("#"+mId).children(".content").empty();
		}else if (mId=='wall'){
			mcontent=_G("#"+mId).children(".content").children("ul").children("dl").get();	
			_G("#"+mId).children(".content").children("ul").empty();
	
		}
		else if(mId=='profile'){
			return true;
		}
		else{
			mcontent=_G("#"+mId).children(".content").children("ul").children("li").get();	
			_G("#"+mId).children(".content").children("ul").empty();
		}
		
		for(var i=0;i<mNum;i++){
		 if(mId=='blog'){
		 	_G("#"+mId).children(".content").append(mcontent[i]);
		 }
		 else if(mId=='profile'){
		 	return ture;
		 }
		 else{
		 	_G("#"+mId).children(".content").children("ul").append(mcontent[i]);
		 }
		}	
	},
	extendModule : function(e){
		 if(_G("#chk"+e).attr("checked")) // 恢复模块
		 { 
			lItems=_G('#frame1_left').sortable('toArray');
			_G("#"+e).insertBefore(_G("#"+lItems[0]));// 在第一个模块前插
			_G("#"+e).show();
		 }
		 else // 删除模块
		 {
			 _G("#"+e).appendTo(_G("#contentlist"));
			 _G("#"+e).hide(); 
		 }
	},
	//自定义装扮
	makeDiyItem : function(eid){	
		hid=eid;
		bgArr = new Array();
		bgArr[eid]=new Array();
		if(eid=="blocktitle"){
			key=".title";
			_G(".title").css({ height: "27px", "line-height": "27px" });
		}
		else if(eid=="block")key=".block";
		else key="#"+eid;
		this.eid=key;
		
	},
	//准备颜色
	reCallColor : function(resetcolor){	
		if(_G("#nocss").val()=="1") return false;		
		//隐藏表单对象
	 	var valkeys=new Array('#bodybgcolor','#blockbgcolor','#nvcolor','#titlecolor','#txtcolor','#linkcolor','#graycolor','#hdh2color');
	 	//页面css对象,用于获取颜色
	 	var keys=new Array(['body'],['.block'],['#nv li a'],['.block .title'],['body'],['.block .title a'],['.gray'],['#hd h2']);
	 	//用于填充表单
	 	var keysforvalue=new Array(['body'],['.block,.rcolor'],['#nv li .a,#nv li .a:visited,#nv li a,#nv li a:visited'],['.block .title,.block .title a,.block .title a:visited'],['body'],['.block .title a,.block .title a:visited'],['.gray,.gray a,.gray a:visited'],['#hd h2,#hd h2 a']);
	 	//css属性
	 	var keyattr=new Array(['background-color'],['background-color'],['color','color'],['color','color','color','color','color'],['color'],['color','color'],['color'],['color','color']);	
		var csscontent=_G("#diy_style").html();		
		_G.each(valkeys, function(s, sn){
	   		cssVal='';
	   		colorVal='';
	   		_G.each(keys[s], function(m, mn){
	   		 	if(csscontent.indexOf(mn)>0){
	   		 		colorVal=toHex(_G(mn).css(keyattr[s][m]));
	   		 	if(toHex(_G(mn).css(keyattr[s][m]))!="")
	   		 		cssVal=cssVal+mn+"\{"+keyattr[s][m]+":"+toHex(_G(mn).css(keyattr[s][m]))+"\}";
	   		 	} 		 	   		 	
	  		})
	  		if(resetcolor=='reset') 
	  		{	
	  			if(colorVal!='') _G(sn).val(colorVal);
	  		}
	  		if(resetcolor=='clear') 
	  		{
	  			_G(sn).val('');
	  		}
	  		
	  	});
	  	 
	},
	//设置空间透明
	//在先设置了背景的情况下再执行透明有bug
	setBgFresh : function (){
		if(_G("#setfresh").attr("checked")==true){
			_G('.block,.rcolor,.controlbg,.cleft').css({"background-color":"transparent"});			
			_G('.controlbg').css({"border":"none"});
			
			if(_G("#headcontentbg").val() == '') hdbg='#hd,#headcontent,' 
			else hdbg = '#hd,';
			
			if(_G("#nvbg").val() == '') nvbg='#nv,'
			else nvbg = '';
			
			if(_G("#blockbg").val() == '') blockbg='.block,' 
			else blockbg = '';
			
			if(_G("#blocktitlebg").val() == '') titlebg='.block .title'
			else titlebg = '';
			
			FreshItems='.cheader4,'+hdbg + nvbg + blockbg + titlebg;
			//一律透明				
			_G(FreshItems).css({"background-image":"none"});			
			
			_G('#headcontent,#nv').css({"width":"960px","background-repeat":'repeat'});								 
			_G('.hc').css({"padding-left":"5px"});
						
			_G("#BgFresh").val(".block,.rcolor,.controlbg,.cleft{background-color:transparent;}.controlbg{border:none} .hc{padding-left:5px} #headcontent,#nv{width:960px} " + FreshItems + "ak{background-image:url('')}" );
						
			_G("#spacetransparent").val('1');			
				
		}
		else{
			//透明还原
			_G("#spacetransparent").val('0');
			_G("#BgFresh").val('');		
			_G('#hd').css({"background-image":"url(static/space/" + styleConfig + "/images/spacebg.gif)"});	
			_G('.hc').css({"padding-left":"10px"});
			_G('#headcontent,#nv').css({"width":"951px"});
			_G("#notece").show();	
	  		_G("#notece").html("透明效果已经取消，但是有些效果将在保存并刷新后才能看到。");  	 
	  		_G("#notece").hide(3000);
		}
	},
	//背景全局变量
	setCurrentDiy : function(eid){	
		diyItem= new this.makeDiyItem(eid);		
		eidArr= new Array('space','headcontent','blocktitle','block','nv');
		_G.each( eidArr, function(m, mn){
			_G("#diy_tag_"+mn).removeClass("activity");
			if(eid==mn)_G("#diy_tag_"+eid).addClass('activity');
		});
	},
	//设计背景	
	setBgImage : function(bgurl){
		_G(key).css({"background-image":"url("+bgurl+")"});
		var morecss='';
		if(hid=='blocktitle')
		{
			morecss="height:27px;line-height:27px;"
		}
		if(hid=='nv')
		{
			morecss="height:23px;"
		}
		bgArr[hid]['0']= key+"\{background-image: url("+bgurl+");"+morecss+"\}";	
		_G("#"+hid+"bg").val(bgArr[hid]);
		_G("#nocss").val()=="0";
		//bug 会丢失之前设置 //默认设置 url("imgurl") repeat scroll left -261px transparent		
		this.setBgRepeat('repeat');
		this.setBgAttachment('fixed');
		this.setBgPosition('top left','bgimgposition0');
	},
	//返回背景以及背景属性
	checkbg : function(){
		if(bgArr[hid]['0'] == '' || typeof(bgArr[hid]['0'])=='undefined') 
		{
			var morecss='';
			if(hid=='blocktitle')
			{
				morecss="height:27px;line-height:27px;"
			}
			if(hid=='nv')
			{
				morecss="height:23px;"
			}			
			bgurl= _G(key).css("background-image");
			bgArr[hid]['0']= key+"\{background-image: "+bgurl+";"+morecss+"\}";									
		}
		if(bgArr[hid]['1'] == '' || typeof(bgArr[hid]['1'])=='undefined') 
		{
			repeat= _G(key).css("background-repeat");
			bgArr[hid]['1']= key+"\{background-repeat: "+repeat+";\}";
		}
		if(bgArr[hid]['2'] == '' || typeof(bgArr[hid]['2'])=='undefined') 
		{
			Position = _G(key).css("background-position");
			bgArr[hid]['2']= key+"\{background-position: "+Position+";\}";	
		}
		if(bgArr[hid]['3'] == '' || typeof(bgArr[hid]['3'])=='undefined') 
		{
			attachment= _G(key).css("background-attachment");
			bgArr[hid]['3']= key+"\{background-attachment: "+attachment+";\}";
		}		
		_G("#"+hid+"bg").val(bgArr[hid]);			
	}, 
	//位置偏移
	setBgAttachment : function(attachment){
		_G(key).css({"background-attachment":attachment});
		bgArr[hid]['3']= key+"\{background-attachment: "+attachment+";\}";	
		//_G("#"+hid+"bg").val(bgArr[hid]);
		this.checkbg();					
	},	
	//设计背景漂移
	setBgRepeat : function(repeat){	
		_G(key).css({"background-repeat":repeat});	
		bgArr[hid]['1']= key+"\{background-repeat: "+repeat+";\}";	
		//_G("#"+hid+"bg").val(bgArr[hid]);
		this.checkbg();	
	},
	//设计背景闪动
	setBgPosition : function(Position,tdid){	
		_G(key).css({"background-position":Position});	
		for(var i=0;i<9;i++){
			_G("#bgimgposition"+i).css({"background-color":"#EEEEEE"});		
		}	
		_G("#"+tdid).css({"background-color":"red"});
		bgArr[hid]['2']= key+"\{background-position: "+Position+";\}";	
		//_G("#"+hid+"bg").val(bgArr[hid]);
		this.checkbg();
		
	},
	hideBg : function(){	
		_G(key).css({"background-image":"url()"});
		bgArr[hid]['0']= key+"\{background-image: url();\}";
		_G("#"+hid+"bg").val(bgArr[hid]);
	},
	//自定义颜色
	setColor : function(cid,ck){
	 	//有颜色设置的元素
	 	var valkeys=new Array('#bodybgcolor','#blockbgcolor','#nvcolor','#titlecolor','#txtcolor','#linkcolor','#graycolor','#hdh2color');
	 	//valkeys包含的元属性
	 	//多个元素支持逗号隔开
	 	var keys=new Array(['body'],['.block,.rcolor'],['#nv li .a,#nv li .a:visited,#nv li a,#nv li a:visited'],['.block .title,.block .title a,.block .title a:visited'],['body'],['.block .title a,.block .title a:visited'],['.gray,.gray a,.gray a:visited'],['#hd h2,#hd h2 a']);
	 	//对于keys属性的值
	 	var keyattr=new Array(['background-color'],['background-color'],['color'],['color'],['color'],['color'],['color'],['color']);
		
		cssDataArr=new Array();
		cssDataArr[cid]=new Array();
		cssval=_G(cid).val();
		valCss="";	
		_G.each(keys[ck],function(ckey,cname){		
			if(keyattr[ck][ckey]=='background-color'){
				_G(cname).css({"background-color":cssval});
			}
			else
			{
				_G(cname).css({"color":cssval});
			}	
			valCss= valCss + cname+"\{"+keyattr[ck][ckey]+":"+cssval+";\}";
		});	
		_G(cid+"val").val(valCss);		
		
	},
	recoverStyle : function(){
		flag=confirm(this.cancelConfirm ? this.cancelConfirm : '版式布局、风格、模块、全部自定义背景都会恢复到初始状态，\r\t\n自定义模块、背景等默认不显示，需要你重新设计,\r\t\n确认恢复？');
	    if (flag) {
	    	var Data="ac=spaceconfig&op=clearbase&uid="+uid;    		
	    	_G.get('cp.php', Data, function(theResponse){
	    		if(theResponse=='done')
	    		{    	    	    	    	
	    	    	location.href = location.href;
	    		}else
	    		{
	    			alert('恢复失败，请稍后重试');
	    		}
	    			
	    	});    		
	    }		
	},
	getdiy : function(albumid,divId){
		if(albumid == 'none') {
			G_('#'+divId).innerHTML = '没有选择相册';
		} else {
			ajaxget('do.php?ac=ajax&op=diybg&id='+albumid+'&ajaxdiv='+divId, divId);
		}	
		
	},
	toggleEle : function(showid,hideid){
		_G("#"+showid).removeClass("hide");
		_G("#"+showid).addClass("z");
		_G("#"+hideid).removeClass("z");
		_G("#"+hideid).addClass("hide");
		
	},
	uploadSubmit: function()
	{
		//this.toggleEle('uploadmsg_button','upload')	
		return true;
	},
	// 保存配置
	saveConfig : function (){
		var ConfigEmpty=false;
		var moduleConfig="";
		var moduleConfig_l=_G('#frame1_left').sortable('toArray'); 
		var moduleConfig_m=_G('#frame1_center').sortable('toArray');
		var moduleConfig_r=_G('#frame1_right').sortable('toArray');
		if(moduleConfig_l=='[object Object]' || moduleConfig_m=='[object Object]' || moduleConfig_r=='[object Object]')
		{
			alert('模块配置数据读取失败，请稍候再试')
			return false;
		}
		//需要检查对象是否存在
		 _G.each(moduleConfig_l,function(i,value){	 	
		 	if(typeof _G("#"+value) == 'undefined') alert('出现数据错误\r\t\n暂时无法保存配置');
		 })
		if(moduleConfig_l=="" && moduleConfig_m=="" && moduleConfig_r=="")ConfigEmpty=true;
		if(ConfigEmpty==false) moduleConfig="'"+moduleConfig_l+"','"+moduleConfig_m+"','"+moduleConfig_r+"'";
		else moduleConfig="";
	 	_G("#MDSconfig").val(moduleConfig); 
		var url="cp.php?ac=spaceconfig&op=base&uid="+uid;
		var Data=_G("#config_space").serialize();
	
		_G.post(url, Data, function(theResponse){			
			if(theResponse=='done')
			{
			    var flag = false;
			    flag = confirm('个性化设置保存成功，可能要刷新才能看到效果\r\t\n返回查看效果？');    
			    if (flag) {
			        //location.href = location.href.replace(/[\?|\&]diy\=yes/g,'');
			        location.href = location.href.replace(/[\-|\?|\&]diy[\=|\-]yes/g,'');
			    }		
			}
			//else{alert(theResponse)}
			else{alert('操作失败，请稍候重试')}		
		}); 
	},
	//note 取消diy
	cancel:function () {
	    var flag = false;    
	    flag = confirm('退出将不会保存您刚才的设置。是否确认退出？');    
	    if (flag) {       
	        location.href = location.href.replace(/[\-|\?|\&]diy[\=|\-]yes/g,'');
	    }
	},
	//加载自定义模块时用的编辑器
	getEditor:function(e,checke){
		//新建之前先检查是否已经存在编辑器对象，如果存在必须先摧毁，然后重建
		_G('#me').html('编辑器加载中....');
		var o=CKEDITOR.instances[e];
	    if (o) o.destroy();		
		editor=CKEDITOR.replace(e,
        {
            toolbar :
            [
   				['Bold','Italic','Underline','Strike','TextColor','BGColor','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
				['NumberedList','BulletedList','Outdent','Indent'],			
				['Image','Flash','SpecialChar','Source'],						
				['Font','FontSize','Format','Styles','-','Link', 'Unlink','Undo','Redo']
            ],
            width : '540',
            height : '250'
        });
        _G('#me').html('');
	},
	test:function(e)
	{
		alert(e?e:'正常');
		return false;
	}
}
