﻿var Timer_ST1 = null;
var startSelectTemplate = false;
window.addEvent("load", function(){	
	window.ST1 = new SelectTemplate();
	Timer_ST1 = setInterval(function(){
		if(!startSelectTemplate){
			ST1.init();
		}else{
			clearInterval(Timer_ST1);
		}								
	}, 200);
	customizePageLoaded();	
});

var guidingHTML = ['<div class="guide_mod" id="settingStep_01" style="display:none">',
'    <div class="guide_top"></div>',
'    <div class="guide_mid">',
'   <div class="title">',
'           <a href="#" class="guide_close" id="settingStep_01_close"></a> ',
'        <strong>欢迎使用MySpace音乐人空间</strong>',
'      </div>',
'       <div class="guide_cover">',
'	       <div id="ibioCloudContentWrapper" class="ibioCloudContentWrapper"></div>',
'       </div>',
'       <div class="btn_area">',
'            <a href="#" id="settingStep_01_next"><b><i>第一步，选择你的空间模板</i></b></a>',
'       </div>',
'    </div>',
'    <div class="guide_foot"></div>',
'</div>',
'<div class="guide_mod" id="settingStep_02" style="display:none">',
'    <div class="guide_top"></div>',
'    <div class="guide_mid">',
'   <div class="title">',
'           <a href="#" class="guide_close" id="settingStep_02_close"></a> ',
'   </div>',
'      <div class="guide_step step1">',
'          <p>根据自己的曲风选择一个符合个人风格的模板</p>',
'      </div>',
'       <div class="guide_area">',
'	   	<div id="templist" class="temlist">',
'			<div class="temp_select">',
'				<span id="tempAll">全部模板</span>',
'				<select name="tempColor" id="tempColor">',
'					<option value="">选择颜色</option>',
'				</select>',
'				<select name="tempStyle" id="tempStyle">',
'					<option value="">选择风格</option>',
'				</select>',
'			</div>',
'			<div class="tempcenwap clearfix" id="tempItems">',
'			</div>',
'			<div class="temp_view">',
'				<span id="clickView">点击可预览效果</span>',
'			</div>',
'		</div>',
'	   </div>     ',
'       <div class="btn_area">',
'            <a href="#" id="settingStep_02_next"><b><i>保存模板</i></b></a>',
'            <a href="#" class="back" id="settingStep_02_prev">返回上一步</a>',
'       </div>',
'    </div>',
'    <div class="guide_foot"></div>',
'</div>',
'<div class="guide_mod" id="settingStep_03" style="display:none">',
'    <div class="guide_top"></div>',
'    <div class="guide_mid">',
'   <div class="title">',
'           <a href="#" class="guide_close" id="settingStep_03_close"></a> ',
'   </div>',
'      <div class="guide_step step2">',
'         <p>修改头图及背景图，让空间更具你的个人特色</p> ',
'      </div>',
'       <div class="guide_area">',
'			<div class="head_pic_upload"> ',
'				<div class="preview hp_pic">',
'					<img src="http://xfiles.cdnmyspace.cn/dir/music/profile/images/headpic_ex.gif" lang="0" longdesc="jpg" id="ttuploadpre" alt="" />',
'				</div>	',
'				<span class="head_pic_upload_bg"><input id="ttNoneHP" class="checkbox" name="ttSelectType" type="checkbox" />不使用头图</span>		',
'				<div class="addetail">',
'				<h3>修改头图</h3>',
'				<a id="head_upload" href="javascript:void(0)" class="photo" title="上传图片">',
'				<input name="image_file" id="hd_image_file" type="file" class="file_input" hidefocus="true" />',
'				</a>',
'				<div style="display:none"><span id="head_tip"></span></div>',
'				</div>',
'				<div class="addetail">',
'					<h3>对齐方式</h3>',
'					<span style="display:none"><input id="HeaderImageAlignment2" name="hpRpeat" value="2" type="radio" /> 拉伸</span>',
'					<span><input id="HeaderImageAlignment1" name="hpRpeat" value="1" type="radio" checked="checked" /> 平铺</span>',
'					<span><input id="HeaderImageAlignment0" name="hpRpeat" value="0" type="radio" /> 居中</span>					',
'				</div>',
'			</div>',
'			<div class="head_pic_upload bg_pic_upload">',
'			   <div class="preview">',
'			  	 <img id="bguploadpre" lang="1" longdesc="jpg" src="http://xfiles.cdnmyspace.cn/dir/music/profile/images/bgpic.jpg" alt="" />',
'			   </div>',
'			   <span class="head_pic_upload_bg"><input id="bgDefaultHP" class="radio" name="bgSelectType" type="checkbox" />白色背景</span>',
'			   <div class="addetail">',
'				<h3>修改背景图</h3>',
'				<a id="bg_upload" href="javascript:void(0)" class="photo" title="上传图片">',
'				<input name="image_file" id="bg_image_file" type="file" class="file_input" hidefocus="true" />',
'				</a>',
'				<div style="display:none"><span id="bg_tip"></span></div>',
'				</div>',
'				<div class="addetail">',
'					<h3>对齐方式</h3>',
'					<span style="display:none"><input id="bgAlign2" type="radio" name="bgAlign" value="2">拉伸</span>',
'					<span><input id="bgAlign1" type="radio" name="bgAlign" value="1" checked="checked">平辅</span>',
'					<span><input id="bgAlign0" type="radio" name="bgAlign" value="0">居中</span>',
'				</div>',
'				<div class="addetail">',
'					<h3>翻页时是否固定</h3>',
'					<span><input type="radio" name="bgAttachment" id="bgAttachment0" value="0">不固定</span>',
'					<span><input type="radio" name="bgAttachment" id="bgAttachment1" value="1">固定</span>',
'				</div>',
'			</div>',
'	   </div>   ',
'       <div class="btn_area">',
'			<input type="button" value="保存设置" class="button" id="settingStep_03_next" />',
'            <a href="#" class="back" id="settingStep_03_prev">返回上一步</a>',
'       </div>',
'    </div>',
'    <div class="guide_foot"></div>',
'</div>',
'<div class="guide_mod" id="settingStep_04" style="display:none">',
'    <div class="guide_top"></div>',
'    <div class="guide_mid">',
'   <div class="title">',
'           <a href="#" class="guide_close" id="settingStep_04_close"></a> ',
'   </div>',
'      <div class="guide_step step3">',
'         <p>修改模块位置可以将更新频繁的模块，或你的觉得重要的模块调整到空间上方，也可以去掉不使用的模块</p> ',
'      </div>',
'       <div class="guide_area">',
'	   		<div class="dragwrapper" id="dragwrapper">',
'				<div class="dragwrapper_intro">',
'					<span>鼠标拖拽调整模块位置，点击×删除该模块</span>',
'					<span class="re_add">被删除的模块可以在<a href="http://home.myspace.cn/modules/homedisplay/pages/ProfileEdit.aspx?t=profile&s=module">个性化</a>中重新启用</span>',
'				</div>',
'				<div class="columnswap">',
'					  <div class="clearfix" id="columns">',
'							<div class="perpic">头图</div>',
'							<div class="column" id="left_drag">',
'								  <div class="fixed"><div class="body"><span>头像</span></div></div>',
'							</div>',
'							<div class="column" id="right_drag">',
'							</div>',
'					  </div>',
'					  <div id="dragblank" style=""></div>',
'',
'				</div>			',
'			</div>',
'	   </div>  ',
'       <div class="btn_area">',
'             <a href="#" id="settingStepOver"><b><i>完成模板设置</i></b></a>',
'            <a href="#" class="back" id="settingStep_04_prev">返回上一步</a>',
'       </div>',
'    </div>',
'    <div class="guide_foot"></div>',
'</div><div style="width:0;height:0;overflow:hidden"><img src="http://xfiles.cdnmyspace.cn/dir/music/profile/images/btnb.png"><img src="http://xfiles.cdnmyspace.cn/dir/music/profile/images/png.gif"></div>'].join("");

//模板数据填充
var tempObj = {};
tempObj.templistData = [
	{"id":4,"color":"purple","style":"Electronica,Pop,Dance,Classic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin001/cover.jpg","name":"线条_紫色"},
	{"id":5,"color":"blue,black","style":"Alternative,RB,Rock,HipHop","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin002/cover.jpg","name":"迷幻公园"},
	{"id":6,"color":"blue","style":"JazzBlues,Folk,WorldMusic,Pop","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin003/cover.jpg","name":"蓝色布鲁斯"},
	{"id":7,"color":"black","style":"Pop,Alternative,Classic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin004/cover.jpg","name":"空之轨迹"},
	{"id":8,"color":"red,black","style":"Rock,Alternative","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin005/cover.jpg","name":"撕裂的末日"},
	
	{"id":9,"color":"white,metal","style":"Pop,Folk,WorldMusic,Classic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin006/cover.jpg","name":"透明体"},
	{"id":10,"color":"white","style":"Pop,Folk,WorldMusic,Alternative,Classic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin007/cover.jpg","name":"简爱"},
	{"id":11,"color":"brown","style":"HipHop,Rock,Alternative,Dance,Electronica","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin008/cover.jpg","name":"涂鸦时代"},
	{"id":12,"color":"brown,black","style":"Rock,Alternative","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin009/cover.jpg","name":"哥特式寂寞"},
	{"id":13,"color":"pink","style":"Pop,Folk,Alternative","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin010/cover.jpg","name":"仙德瑞拉"},
	
	{"id":14,"color":"red,orange,metal","style":"Rock,Dance,Electronica","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin011/cover.jpg","name":"火舞卿狂"},
	{"id":15,"color":"green","style":"Pop,Folk,WorldMusic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin012/cover.jpg","name":"印染回忆"},
	{"id":16,"color":"black,gray,metal","style":"JazzBlues,R&B,Classic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin013/cover.jpg","name":"机械迷城"},
	{"id":17,"color":"purple,blue","style":"Electronica","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin014/cover.jpg","name":"幻神迷城"},
	{"id":18,"color":"brown","style":"Electronica,WorldMusic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin015/cover.jpg","name":"褐色"},
	
	{"id":19,"color":"blue","style":"Pop,Folk,WorldMusic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin016/cover.jpg","name":"湖蓝"},
	{"id":20,"color":"green","style":"Folk,Classic,WorldMusic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin017/cover.jpg","name":"绿色"},
	{"id":21,"color":"orange","style":"Pop,Folk","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin018/cover.jpg","name":"水晶黄色"},
	{"id":22,"color":"blue","style":"Pop,Folk,WorldMusic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin019/cover.jpg","name":"水晶蓝色"},
	{"id":23,"color":"pink","style":"Pop,Folk,Classic","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin020/cover.jpg","name":"粉色"},
	{"id":24,"color":"white,metal","style":"Pop,Electronica,JazzBlues","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin000/cover.jpg","name":"金属"},
	{"id":25,"color":"white,metal","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin021/cover.jpg","name":"资料页"},
	{"id":26,"color":"blue","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin022/cover.jpg","name":"清新蓝"},
	{"id":27,"color":"white","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin023/cover.jpg","name":"简洁白"},
	{"id":28,"color":"green","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin024/cover.jpg","name":"清新绿"},
	{"id":29,"color":"orange","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin025/cover.jpg","name":"淡雅黄"},
	{"id":30,"color":"pink","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin026/cover.jpg","name":"樱桃粉"},
	{"id":31,"color":"pink","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin027/cover.jpg","name":"清新粉"},
	{"id":32,"color":"purple","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin028/cover.jpg","name":"淡雅紫"},
	{"id":33,"color":"blue","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin029/cover.jpg","name":"淡雅青"},
	{"id":34,"color":"brown","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin030/cover.jpg","name":"淡咖啡"},
	{"id":35,"color":"gray","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin031/cover.jpg","name":"简洁灰"},
	{"id":36,"color":"blue","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin032/cover.jpg","name":"戈壁黄"},
	{"id":37,"color":"blue","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin033/cover.jpg","name":"沉稳蓝"},
	{"id":38,"color":"green","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin034/cover.jpg","name":"沉稳绿"},
	{"id":39,"color":"red","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin035/cover.jpg","name":"玫瑰红"},
	{"id":40,"color":"pink","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin036/cover.jpg","name":"玫瑰粉"},
	{"id":41,"color":"purple","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin037/cover.jpg","name":"神秘紫"},
	{"id":42,"color":"green","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin038/cover.jpg","name":"深湖绿"},
	{"id":43,"color":"blue","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin039/cover.jpg","name":"明亮蓝"},
	{"id":44,"color":"green","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin040/cover.jpg","name":"明亮绿"},
	{"id":45,"color":"orange","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin041/cover.jpg","name":"明亮黄"},
	{"id":46,"color":"red","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin042/cover.jpg","name":"明亮红"},
	{"id":47,"color":"pink","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin043/cover.jpg","name":"明亮粉"},
	{"id":48,"color":"purple","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin044/cover.jpg","name":"明亮紫"},
	{"id":49,"color":"blue","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin045/cover.jpg","name":"淡湖蓝"},
	{"id":50,"color":"brown","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin046/cover.jpg","name":"深咖啡"},
	{"id":51,"color":"gray","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin047/cover.jpg","name":"低调灰"},
	{"id":52,"color":"white","style":"","image":"http://xfiles.cdnmyspace.cn/dir/music/profile/skin048/cover.jpg","name":"明亮白"}
];	

tempObj.color=[
	{"name":"黑色","value":"black"},
	{"name":"褐色","value":"brown"},
	{"name":"灰色","value":"gray"},
	{"name":"金属色","value":"metal"},
	{"name":"蓝色","value":"blue"},
	{"name":"橙色","value":"orange"},
	{"name":"紫色","value":"purple"},
	{"name":"红色","value":"red"},
	{"name":"粉色","value":"pink"},
	{"name":"绿色","value":"green"},
	{"name":"白色","value":"white"}];
tempObj.style=[
	{"name":"电子","value":"Electronica"},
	{"name":"流行","value":"Pop"},
	{"name":"舞曲","value":"Dance"},
	{"name":"古典","value":"Classic"},
	{"name":"R&B","value":"RB"},
	{"name":"摇滚","value":"Rock"},
	{"name":"嘻哈 ","value":"HipHop"},
	{"name":"爵士和布鲁斯","value":"JazzBlues"},
	{"name":"民谣","value":"Folk"},
	{"name":"世界音乐","value":"WorldMusic"},
	{"name":"另类","value":"Alternative"}];

tempObj.selectAdd = function(id,dataJson){
	var Json = dataJson;
	var len = Json.length;
	var JArr= new Array();
	var obj = document.getElementById(id);
	for (var n=0;n<len;n++){
		//JArr[n] = ['<option value="',Json[n].value,'">',Json[n].name,'</option>'].join("");
		obj.options.add(new Option(Json[n].name,Json[n].value)); 
	}
//	var str = JArr.join(""); 
//	alert(str)
//	document.getElementById(id).innerHTML += str;
}

function MsHide(id){var Div = document.getElementById(id);if(Div){Div.style.display="none"}}
function MsShow(id){var Div = document.getElementById(id);if(Div){Div.style.display="block"}}
//蒙版生成div+iframe
function MsPopload(showId){
	var pop_Win = document.getElementById(showId);
	if (!pop_Win) {return false;}
	MsShow(showId);
	pop_Win.style.position = "absolute";
	pop_Win.style.zIndex = "25";
	pop_Win.style.top = (document.documentElement.scrollTop+document.body.scrollTop+document.documentElement.clientHeight/2-pop_Win.offsetHeight/2)+ 'px';
	pop_Win.style.left = (document.documentElement.clientWidth/2-pop_Win.offsetWidth/2) + 'px';
}
function MsUnload(showId) {
	MsHide("popIframe");MsHide("popBox");MsHide(showId);
}

function MsClickPopload(id,div){
	var btn = document.getElementById(id)
	if (btn) {
		btn.onclick = function(){
			MsPopload(div);
			return false;
		}	
	}
}

function MsClickUnPopload(id,div){
	var btn = document.getElementById(id)
	if (btn) {
		btn.onclick = function(){
			MsUnload(div);
			return false;
		}	
	}
}


//模板筛选
function tempSelects(tc,ts){
	var obj = document.getElementById("tempItems");
	if (!obj) {return false}
	var div = obj.getElementsByTagName("div");
	var len = div.length;
	for (var i=0;i<len;i++){		
		if (div[i].className.indexOf("temitem")>=0){
			div[i].style.display="none";
		}
	}
	for (var i=0;i<len;i++){		
		if (div[i].className.indexOf("temitem")>=0){
			var arr = div[i].lang.split("｜")
			if (tc!=="") {
				if (arr[0].indexOf(tc)>=0) {div[i].style.display="block";}
			}
			if (ts!=="") {
				if (arr[1].indexOf(ts)>=0) {div[i].style.display="block";}
			}
			if (tc=="" && ts=="") {div[i].style.display="block";}
		}
	}
}
	
function tagCloudSwf(){
	//ibio cloud
	var so = new SWFObject("http://lads.myspace.cn/widget/ibioCloud/ibioCloud.swf?v=0409", "ibioCloudContentWrapper_SWF", 591 ,455, "9.0.0");
	so.addParam("allowNetworking", "all");
	so.addParam("allowScriptAccess", "always");
	so.addParam("wmode", "transparent");
	so.addVariable("playListData",encodeURIComponent(JSON.encode(JS_Context.tagCloudData)));
	//so.addVariable("dataURL", "stuff/data.xml");
	so.write("ibioCloudContentWrapper");
}

// JavaScript Document
/*===================javascript 序列化 serialize 对象=======================*/
/** 
* 字符串为javascript转码。
*/
String.prototype.trim=function(){
	return this.replace(/^[\s\xa0\u3000]+|[\u3000\xa0\s]+$/g, "");
};
String.prototype.encode4Js=function(){
	var o=[/\\/g,/"/g,/'/g,/\//g,/\r/g,/\n/g];
	var n=["\\u005C","\\u0022","\\u0027","\\u002F","\\u000A","\\u000D"];
	var s=this;
	for(var i=0;i<o.length;i++) 
	{
	   s=s.replace(o[i],n[i]);
	}
	return s;
};
Object.serialize2Str = function (obj){
	if(obj==null) return null;
	if(obj.serialize2Str) return obj.serialize2Str();
	var cst = (obj.constructor+"").split("{")[0].trim();
	switch(cst){
	   case "function String()": return '"'+String.prototype.encode4Js.call(obj)+'"';
	   case "function Number()": return obj+"";
	   case "function Date()": return 'new Date(' + obj.getTime() + ')';
	   case "function Boolean()": return obj+"";
	   case "function Array()" :
		var ar=[];
		for(var i=0;i<obj.length;i++) ar[i]=Object.serialize2Str(obj[i]);
		return '['+ar.join(',')+']';
	   case "function Object()" :
		var ar=[];
		for(var i in obj){
		 ar.push('"'+String.prototype.encode4Js.call(i+'')+'":'+Object.serialize2Str(obj[i]));
		}
		return '{'+ar.join(',')+'}';
	}
	return null;
};

//初始化页面，建DOM
var SelectModule = function(aoConf){
	this.list = aoConf.list;
	this.wap_sel = aoConf.wap_sel;
	this.left_drag = aoConf.left_drag;
	this.right_drag = aoConf.right_drag;
};
SelectModule.prototype = {
	adapterName: {"mod_1":{name:"头像"}, "mod_2":{name:"演出"}, "mod_3":{name:"关于我"}, "mod_4":{name:"相似音乐人"}, "mod_6":{name:" 留言"}, "mod_5":{name:"粉丝"}, "mod_7":{name:"音乐"}, "mod_8":{name:"专辑"}, "mod_9":{name:"微博客"}, "mod_10":{name:"相册"}, "mod_11":{name:"博客"}, "mod_12":{name:"视频"}, "mod_13":{name:"新闻"}, "mod_14":{name:"贴图板1"}, "mod_15":{name:"贴图板2"}, "mod_16":{name:"贴图板3"}, "mod_17":{name:"贴图板4"}, "mod_18":{name:"贴图板5"}, "mod_19":{name:"简介"}, "mod_20":{name:"访客"}, "mod_21":{name:"贴图板6"}, "mod_22":{name:"贴图板7"}, "mod_23":{name:"贴图板8"}, "mod_24":{name:"贴图板9"}, "mod_25":{name:"贴图板10"}, "mod_26":{name:"贴图板11"}, "mod_27":{name:"贴图板12"}},
	HTMLStruct_sel: ['<div id="',"{1}",'" isSel="',"{3}",'" CanMove="',"{5}",'" isdisplay="',"{7}",'" CanDisable="','{9}','" class="smitem ','{11}','"><div class="cont">',"{13}",'</div></div>'],
	HTMLStruct_drag: ['<div class="','{1}',' wap" id="','{3}','" style="',"{5}",'"><div class="body">',"{7}",'<span>','{9}','</span></div></div>'],
	init: function(){
		this.sortList();
		this.buildDom();
		this.addEventToDom();
		this.regDrag();
	},
	sortList: function(){
		this.list.sort(
			function(a,b){
				if(a.PositionX < b.PositionX){
					return -1;
				}
				if(a.PositionX == b.PositionX){
					if(a.PositionY <= b.PositionY){
						return -1;
					}else{
						return 1;
					}
				}
				if(a.PositionX > b.PositionX){
					return 1;
				}
			}
		)
	},
	buildDom: function(){
		var html = [];	
		//新建移动模块
		for(var i=0; i<this.list.length; i++){
			if(this.list[i].ModuleId == 1){//跳过头像
				continue;	
			}
			if(this.list[i].CanMove){
				this.HTMLStruct_drag[1] =  "module";
			}else{
				this.HTMLStruct_drag[1] =  "fix";
			}
			this.HTMLStruct_drag[3] =  "mod_"+this.list[i].ModuleId+"_drag";
			if(this.list[i].CanDisable){
				this.HTMLStruct_drag[7] = '<div class="smhide">&nbsp;</div>';	
			}else{
				this.HTMLStruct_drag[7] = '';	
			}
			if(this.list[i].Display){
				this.HTMLStruct_drag[5] = '';
			}else{
				this.HTMLStruct_drag[5] = 'display:none';
			}

			this.HTMLStruct_drag[9] =  this.adapterName["mod_"+this.list[i].ModuleId].name;
			
			var newDIV = document.createElement("div");
			newDIV.innerHTML = this.HTMLStruct_drag.join("");
			//alert(this.HTMLStruct_drag.join(""));
			var newcreDIV = newDIV.firstChild;
			//左边 右边			
			if(this.list[i].PositionX == 0){
				this.left_drag.appendChild(newcreDIV);
			}else{
				this.right_drag.appendChild(newcreDIV);
			}
		}
	},
	addEventToDom: function(){
		var that = this;
		$$('.smitem').each(function(aeE, indx){
			if(aeE.getAttribute("CanDisable")=="false"){
				return false;
			}
			aeE.addEvent("click", function(){
				var isSel = aeE.getAttribute("isSel");
				if(isSel == "true"){
					that.cancelModule(aeE);
				}else{
					that.selectedModule(aeE);
				}
			});
		});

		$$('.smhide').each(function(aeE, indx){
			aeE.addEvent("click", function(e){
				that.hide(aeE);
			});
		});
	},
	hide: function(aeE){
		var aePP = aeE.parentNode.parentNode;;
		aePP.style.display = "none";
		aePP.setAttribute("parid", aePP.parentNode.id);
		
		var id = aePP.id;
		var selid = "mod_"+id.substring(4, id.lastIndexOf("_"))+"_sel";
		var selEle = $(selid);
		if(selEle){
			selEle.setAttribute("isSel", "false");
			selEle.setAttribute("isdisplay", "false");
			selEle.className = "smitem";
		}
		$('dragblank').setStyle('display','none'); 
	},
	cancelModule: function(aeE){
		aeE.className = "smitem";
		aeE.setAttribute("isSel", "false");
		aeE.setAttribute("isdisplay", "false");
		var id = aeE.id;
		var dragid = "mod_"+id.substring(4, id.lastIndexOf("_"))+"_drag";
		var dragEle = $(dragid);
		if(dragEle.style.display != "none"){
			dragEle.style.display = "none";
		}
		//记住它的父节点
		dragEle.setAttribute("parid", dragEle.parentNode.id);
		
	},
	selectedModule: function(aeE){
		aeE.className = "smitem selected";
		aeE.setAttribute("isSel", "true");
		aeE.setAttribute("isdisplay", "true");
		var id = aeE.id;
		var dragid = "mod_"+id.substring(4, id.lastIndexOf("_"))+"_drag";
		var dragEle = $(dragid);
		if(dragEle.style.display == "none"){
			dragEle.style.display = "block";
		}
		var parid = dragEle.getAttribute("parid");
		if($(parid)){
			$(parid).appendChild(dragEle);
		}
	},
	//引用mootools注册拖动
	ifInRect: function(coord_s, coord_t){  
		var x = coord_s.left+coord_s.width/2;  
		var y = coord_s.top+coord_s.height/2;  
		var ret = false;  
		if(x>coord_t.left && x<coord_t.left+coord_t.width){   
			if(y>coord_t.top && y<coord_t.top+coord_t.height){    
				ret = true;   
			}  
		}  
		return ret; 
	},
	regDrag: function(){
		var that = this;
		
		var mod = $$('.module');
		$$('.module').each(function(drag, idx){					
			var ob_dragmove = new Drag.Move(drag, {droppables: $$('.column'), snap:1}); 
			
			ob_dragmove.element.setStyle('left', '0');    
			ob_dragmove.element.setStyle('top', '0');
			ob_dragmove.element.setStyle('position', 'relative'); 
				
			var isFix = ob_dragmove.element.getAttribute("fix");
			if(isFix == "true"){
				return false;
			}
			ob_dragmove.addEvent('onBeforeStart', function(){
														   
				if(window.event && window.event.srcElement.className == "smhide"){
					that.hide(window.event.srcElement);
					return false;
				}
				
				$$('.module').each(function(aeE){
					$('dragblank').setStyle('display','none');  
					aeE.setStyle('position', 'relative');   
					aeE.setStyle('left',0);   
					aeE.setStyle('top',0);  						
				});
				var left = this.element.getLeft('dragwrapper');   
				var top = this.element.getTop('dragwrapper');
				var vtop = {};
				vtop.T1 = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
				vtop.T2 = $('right_drag').getBoundingClientRect().top;
				vtop.top = vtop.T1 + vtop.T2;
				$('dragblank').setStyle('display','block');   
				$('dragblank').injectBefore(this.element);   
				$('dragblank').setStyle('height',this.element.getStyle('height'));  
				this.element.setStyle('width',this.element.getStyle('width'));   
				this.element.setStyle('position', 'absolute');   
				this.element.setStyle('left',0);
				this.element.setStyle('top',top-vtop.top);
				var modules = $$('#columns').getElements('.module');
				for(var i=0; i<modules.length; i++){
					modules[i].setStyle('zIndex',10);
				}
				this.element.setStyle('zIndex',100);
				
				this.fixleft = this.element.getCoordinates().left;
			});  
			ob_dragmove.addEvent('onDrag', function(){ 
				if(window.event && window.event.srcElement.className == "smhide"){
					return false;
				}										
				var columns = $$('.column');   
				var break_loop = false; 
				this.element.setOpacity(0.6);  
				this.element.setStyle('left',0);
				for (var j =0;j<columns.length && !break_loop ; j++ ){   
					var item = columns[j];
					//只在父节点内移动
					if(that.ifInRect(ob_dragmove.element.getCoordinates(),item.getCoordinates()) && item=== ob_dragmove.element.parentNode){     
						var modules = item.getElements('.wap');
						for (var i =0 ;i< modules.length ;i++ ){      
							if (ob_dragmove.element.getCoordinates().top < modules[i].getCoordinates().top){       
								$('dragblank').injectBefore(modules[i]);
								break_loop = true ;
								break;
							}
						}
						if (!break_loop) $('dragblank').injectInside(item);    
					}   
				};  
			});
			ob_dragmove.addEvent('onComplete', function(){  
				if(window.event && window.event.srcElement.className == "smhide"){
					return false;
				}
				ob_dragmove.element.injectBefore($('dragblank'));    
				ob_dragmove.element.setStyle('position', 'relative');    
				ob_dragmove.element.setStyle('left', '0');    
				ob_dragmove.element.setStyle('top', '0');  
				var width = $('dragblank').offsetWidth;
				ob_dragmove.element.setStyle('width', width);
				$('dragblank').setStyle('display','none');   
				this.element.setOpacity(1);  
			}); 
		}); 
	}
}

//getModuleData
function getModuleData(){
	var data = [];
	
	var left_drag = $("left_drag");
	var right_drag = $("right_drag");
	var smbody = $("smbody");
	
	var left_items = $$("#left_drag .wap");
	var positionY_l = 1;
	for(var i=0; i<left_items.length; i++){
		var modid = parseInt(left_items[i].id.substring(4, left_items[i].id.lastIndexOf("_")));
		var param = "";
		param += modid;
		param += ",";
		param += 0;
		var isDisplay = $("mod_"+modid+"_drag").getStyle("display");

		if(isDisplay == "block"){//只记录显示模块的新位置
			param += ",";
			param += positionY_l++;
		}else{
			param += ",";
			param += positionY_l + 1;
		}
		param += ",";
		
		if (isDisplay == "block") {displaypro = "true"}
		else {displaypro = "false"}
		
		param += displaypro;
		data.push(param);
	}
	var right_items = $$("#right_drag .wap");
	var positionY_r = 1;
	for(var i=0; i<right_items.length; i++){
		var modid = parseInt(right_items[i].id.substring(4, right_items[i].id.lastIndexOf("_")));
		var param = "";
		param += modid;
		param += ",";
		param += 1;
		var isDisplay = $("mod_"+modid+"_drag").getStyle("display");
		if(isDisplay == "block"){   //只记录显示模块的新位置
			param += ",";
			param += positionY_r++;
		}else{
			param += ",";
			param += positionY_r + 1;
		}
		param += ",";
		if (isDisplay == "block") {displaypro = "true"}
		else {displaypro = "false"}
		param += displaypro;
		data.push(param);
	}
	return data;
}

//提交数据
function savemodule(){
	var data = getModuleData();
	//alert(data.join(";"))
	savemoduledata(data.join(";"));
}

//预览后保存
function savepremodule(){
	var data = [];
	
	for(var i=0; i<list.length; i++){
		var param = "";
		param += list[i].ModuleId;
		param += ",";
		param += list[i].PositionX;
		param += ",";
		param += list[i].PositionY;
		param += ",";
		param += list[i].Display;
		data.push(param);
	}
		
	savemoduledata(data.join(";"));
}
function saveafterpreview(){
	savepremodule();
}

//保存数据
function savemoduledata(data){
	var lsURL = "http://ajaxv2.myspace.cn/_common/AjaxService/BandProfileEditService.svc/json/SetModuleSettings";
	var loRequest={
		"url": lsURL,
		"method":"post",
		"data":{"settings": data},
		"callback":callBack
	};
	loadAjax(loRequest);
	function callBack(aoJson){
		aoJson = json2Obj(aoJson);
		if(aoJson.Result == 0){
			location.href = "http://www.myspace.cn/" + MO_MySpaceContext.UserId;
		}else{
			alert(aoJson.Msg);
		}
	}	
}

//切换模板皮肤
function changeSkin(obj,TempId){
	function IsNum(num){
		var reNum=/^\d*$/;
		return(reNum.test(num));
	}
	var cssObj = document.getElementById(obj);
	if (!cssObj) {return false}
	var TempId_src = TempId;
	if (IsNum(TempId) && TempId<25){
		TempId = (TempId-3)%21;
		TempId = "000" + "" + TempId;
		TempId = TempId.substring(TempId.length-3);
		
		cssObj.href = "http://xfiles.cdnmyspace.cn/dir/music/profile/skin" + TempId + "/skin.css"	
	}else{
		cssObj.href = "http://xfiles.cdnmyspace.cn/dir/music/profile/skin0" + (TempId-4) + "/skin.css"	
	}
	
	//设置头图高度
	var imgs = $$("#tem_"+parseInt(TempId_src, 10)+" img");
	if(imgs.length!=0){
		var skin_sidx = imgs[0].src.indexOf("skin")+4;
		var skin_idx = parseInt(imgs[0].src.substring(imgs[0].src.indexOf("skin")+4, imgs[0].src.indexOf("/", skin_sidx-1)), 10);
		templateHeaderHeig = isNaN(skin_idx)? 200: templateHeaderHeightList["skin_"+skin_idx];
		var headerwap = $$("div.box_top_img");
		if(headerwap.length!=0){
			headerwap[0].style.height = templateHeaderHeig+"px";
		}
	}
}

/********选择模板页*******/
var templateHeaderHeightList = {"skin_0":181, "skin_1":177, "skin_2":320, "skin_3":180, "skin_4":470, "skin_5":415, "skin_6":182, "skin_7":182, "skin_8":515, "skin_9":400, "skin_10":318, "skin_11":438, "skin_12":186, "skin_13":363, "skin_14":216, "skin_15":178, "skin_16":177, "skin_17":177, "skin_18":177, "skin_19":177, "skin_20":177, "skin_21":120, "skin_22":180, "skin_23":180, "skin_24":180, "skin_25":180, "skin_26":180, "skin_27":180, "skin_28":180, "skin_29":180, "skin_30":180, "skin_31":180, "skin_32":180, "skin_33":180, "skin_34":180, "skin_35":180, "skin_36":180, "skin_37":180, "skin_38":180, "skin_39":180, "skin_40":180, "skin_41":180, "skin_42":180, "skin_43":180, "skin_44":180, "skin_45":180, "skin_46":180, "skin_47":180, "skin_48":180};
var templateHeaderHeig = 200;
var SelectTemplate = function(aoConf){
	this.cur = null;
	this.list = null;
};

SelectTemplate.prototype = {
	init: function(){
		this.addEvent();
		if(typeof curtempid != "undefined"){
			if($("tem_"+curtempid))
			this.selectTemp($("tem_"+curtempid));
			this.recorddata("tem_"+curtempid);
		}
	},
	addEvent: function(){
		var that = this;
		$$("#templist .temitem").each(function(aeE, indx){
			startSelectTemplate = true;
			aeE.addEvent("click", function(){
				var Arr = this.id.split("_")						   
				changeSkin("skinNum",Arr[1])
				var isSelect = aeE.getAttribute("isSelect");
				if(isSelect && isSelect=="true"){
					that.clearLast(that.cur);
					that.recorddata("tem_0");
					return;
				}
				if(that.cur != null){
					that.clearLast(that.cur);
				}
				that.selectTemp(aeE);
				var tempid = aeE.id;
				that.recorddata(tempid);
			});
			aeE.addEvent("mouseover", function(){
				var isSelect = aeE.getAttribute("isSelect");
				if(isSelect && isSelect=="true"){
					return;
				}
				aeE.className = "temitem focus";
			});
			aeE.addEvent("mouseout", function(){
				var isSelect = aeE.getAttribute("isSelect");
				if(isSelect && isSelect=="true"){
					return;
				}
				aeE.className = "temitem";
			});
		});
	},
	//选择模板
	selectTemp: function(aeE){
		aeE.className = "temitem focus";
		aeE.setAttribute("isSelect", "true");
		aeE.getElement(".yes").style.display = "block";
		
		this.cur = aeE;
	},
	//清除上一个模板
	clearLast: function(aeE){
		aeE.className = "temitem";
		aeE.setAttribute("isSelect", "false");
		aeE.getElement(".yes").style.display = "none";
	},
	recorddata: function(data){
		this.temid = data;
		
		//获得头图高度
		var imgs = $$("#"+this.temid+" img");
		if(imgs.length!=0){
			var skin_sidx = imgs[0].src.indexOf("skin")+4;
			var skin_idx = parseInt(imgs[0].src.substring(imgs[0].src.indexOf("skin")+4, imgs[0].src.indexOf("/", skin_sidx-1)), 10);
			templateHeaderHeig = isNaN(skin_idx)? 200: templateHeaderHeightList["skin_"+skin_idx];
		}
	}
	
};

//个性化页面提交
var Timer_savepersonal = null;
var savepersonalWaiting = false;
var uploadcallbackdata = {};
//头图id	
	uploadcallbackdata["headerImageId"] = "0";

//背景图id	
	uploadcallbackdata["backgroundImageId"] = "0";	
	
//头图type
	uploadcallbackdata["headerImageType"] = "";
//头图url
	uploadcallbackdata["headerImageUrl"] = "";
//背景图type
	uploadcallbackdata["backgroundImageType"] = "";
//背景图url
	uploadcallbackdata["backgroundImageUrl"] = "";

//图片上传	
function uploadPhotoInMblog(fileID,imgID,msgID){ 
  var uploaderObj = new UploadPhoto(); 
  var wrapper = $(fileID);
  var fileInput = wrapper.getElement(".file_input");
  
  uploaderObj.getDom = function(){
    uploaderObj.dom.wrapper = wrapper;
    uploaderObj.dom.tip = $(msgID);
    uploaderObj.dom.fileInputs = wrapper.getElements(".file_input");
  }
  uploaderObj.getAlbumId = function(callback){
    var lsUrl = "http://mblog.myspace.cn/jsi.php";
    var loRequest={
      "url": lsUrl,
      "method":"get",
      "data":{"action":"get_album_id"},
      "callback":function(asData){
        var loData = JSON.decode(asData);
        uploaderObj.albumId = loData.message;
        callback();
		$('hd_image_file').set("disabled","disabled");
		$('bg_image_file').set("disabled","disabled");
		$('settingStep_03_next').set("disabled","disabled");
      }
    }; 

    MS_loadAjax(loRequest,'/_common/static/ajax.html');
  }  
  uploaderObj.destroy = function(){
    uploaderObj.dom.wrapper.innerHTML = uploaderObj.view.wrapper;
	
	
    if(uploaderObj.response.status!="ok"){
		$('hd_image_file').erase("disabled");
	 	$('bg_image_file').erase("disabled");
		$('settingStep_03_next').erase("disabled");
        return false;
    }
    var lsUrl = "http://mblog.myspace.cn/jsi.php";
    var lsVal = fileInput.value;
    var lsName = lsVal.substring(lsVal.lastIndexOf("\\")+1);
    var lsType = fileInput.value.substring(lsVal.lastIndexOf(".")+1);
    var loRequest={
      "url": lsUrl,
      "method":"get",
      //"data":{"action":"get_img_url","dfs":encodeURIComponent(uploaderObj.response.dfs),"id":uploaderObj.response.mid,"type":lsType,"size":"m"},
	  "data":{"action":"get_img_url","dfs":uploaderObj.response.dfs,"id":uploaderObj.response.mid,"type":lsType,"size":"m"},
      "callback":function(asData){
        var loData = JSON.decode(asData);
		$(imgID).src = loData.message.replace("/m_","/o_");
		$(imgID).lang = uploaderObj.response.mid;
		$(imgID).longdesc = lsType;
		
		$('hd_image_file').erase("disabled");
	 	$('bg_image_file').erase("disabled");
		$('settingStep_03_next').erase("disabled");
	 
  		if (fileID=="head_upload"){	
			uploadcallbackdata["headerImageId"] = uploaderObj.response.mid;
			uploadcallbackdata["headerImageIdUse"] = uploaderObj.response.mid;
			uploadcallbackdata["headerImageType"] = lsType;
			uploadcallbackdata["headerImageUrl"] = uploaderObj.response.dfs;
		}
		
		if (fileID=="bg_upload"){		
			uploadcallbackdata["backgroundImageId"] = uploaderObj.response.mid;
			uploadcallbackdata["backgroundImageIdUse"] = uploaderObj.response.mid;
			uploadcallbackdata["backgroundImageType"] = lsType;
			uploadcallbackdata["backgroundImageUrl"] = uploaderObj.response.dfs;
		}
        fileInput = wrapper.getElement(".file_input");
        fileInput.onchange = function(){
          uploaderObj.batchUpload();
        }
       uploadPhotoInMblog.isUploading = false;
	   
	   uploaderObj.getDom();
	  
      }
    };  
    MS_loadAjax(loRequest,'/_common/static/ajax.html');
  }
  
  uploaderObj.getDom();
  fileInput.onchange = function(){
    uploaderObj.batchUpload();
    uploadPhotoInMblog.isUploading = true;
  }
  uploaderObj.init();
}

function savepersonal(aeE){
	var templateId = 0;
	if(typeof ST1 != "undefined" && ST1.temid){
		templateId = ST1.temid.substring(4);
	}

	//var lsURL = "http://ajaxv2.myspace.cn/Modules/BandProfileEdit/Pages/UpdateBandStyleHandler.ashx";
	var lsURL = "http://ajaxv2.myspace.cn/Modules/BandProfileEdit/Pages/UpdateStyle.aspx";
	var data = {"templateId":templateId, "styleCss":"","headerImageId":uploadcallbackdata.headerImageIdUse, "headerImageType":uploadcallbackdata.headerImageType, "headerImageUrl":uploadcallbackdata.headerImageUrl, "HeaderImageTiled":uploadcallbackdata.HeaderImageTiled, "HeaderImageAlignment":uploadcallbackdata.HeaderImageAlignment,"backgroundImageId":uploadcallbackdata.backgroundImageIdUse, "backgroundImageType":uploadcallbackdata.backgroundImageType, "backgroundImageUrl":uploadcallbackdata.backgroundImageUrl, "BackgroundImageTiled":uploadcallbackdata.BackgroundImageTiled, "BackgroundImageFixed":"0","isFixBackgroundRoolPage":uploadcallbackdata.isFixBackgroundRoolPage, "BackgroundImageAlignment":uploadcallbackdata.BackgroundImageAlignment,"HeaderImageHeight":templateHeaderHeig,"newHeaderAlignment":"1","newBackgroundAlignment":"1"};
	
	var lxUrl=[];
	for(var x in data){					
		lxUrl.push(x);
		lxUrl.push("=");
		lxUrl.push(data[x]);
		lxUrl.push("&");
	}
	lxUrl.pop();
	//alert(lxUrl)
 
	//var loRequest={"webservices": lsURL,"contentType":"application/x-www-form-urlencoded","values":lxUrl.join("")};
	var loRequest={
			"url": lsURL,
			"contentType":"application/x-www-form-urlencoded",
			"method":"post",
			"data":data,
			"callback":callBack

	};
	loadAjax(loRequest,"/_common/static/ajax.html");

	function callBack(aoJson){
		//alert(aoJson)
		aoJson = json2Obj(aoJson);
		//alert(aoJson)
		//alert(aoJson.Result)
		if(aoJson.Result !== 1){
			alert(aoJson.Msg);
			return false;
		}
	}
}

//设置数据初始化
var Timer_cpl = null;
function customizePageLoaded(){
	if(list=="undefined" || !list)return false

	if(!$("ttNoneHP")){
		if(Timer_cpl){clearTimeout(Timer_cpl);}
		Timer_cpl = setTimeout(function(){	
			customizePageLoaded();						
		}, 200);
		return;
	}else{
		if($("ttNoneHP")){
			clearTimeout(Timer_cpl);
		}	
	}
	
	if(list.HeaderImageTiled){
		$("ttNoneHP").checked = true;
	}else{
		$("ttNoneHP").checked = false;
	}
	
	switch(list.HeaderImageAlignment){
		case 2:{
			$("HeaderImageAlignment2").checked = true;;
		}break;
		case 1:{
			$("HeaderImageAlignment1").checked = true;;
		}break;
		case 0:{
			$("HeaderImageAlignment0").checked = true;;
		}
	}

	if(list.BackgroundImageTiled){
		$("bgDefaultHP").checked = true;
	}else{
		$("bgDefaultHP").checked = false;
	}
	switch(list.BackgroundImageAlignment){
		case 2:{
			$("bgAlign2").checked = true;
		}break;
		case 1:{
			$("bgAlign1").checked = true;
		}break;
		case 0:{
			$("bgAlign0").checked = true;
		}
	}
	switch(list.BackgroundImageFixed){
		case 1:{
			$("bgAttachment1").checked = true;
		}break;
		case 0:{
			$("bgAttachment0").checked = true;
		}
	}	
}
//===================ajax 请求==================//
function loadServices(aoOBJ){
	var loXML = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	try {
		loXML.open(aoOBJ.method || "POST", aoOBJ.webservices, false);
		if (aoOBJ.contentType){
			loXML.setRequestHeader("Content-Type", aoOBJ.contentType);
		}
		loXML.send(aoOBJ.values);
	} 
	catch (ex) {
		return "";
	}
	if (loXML != null && loXML.readyState == 4) {
		return loXML.responseText;
	}
	return "";
}
function loadAjax(option,path){
    if(navigator.userAgent.indexOf("IE")!=-1){ 
		(function(){ 
			try{ 
				document.documentElement.doScroll("left"); 
				action(); 
			}catch(error) {                                                  
				setTimeout(arguments.callee, 200); 
			}                                        
		})();
    }else{ 
        action(); 
    } 
    function action(){
		var xDomain = document.domain.split(".");
		if (xDomain.length >= 2){
		   document.domain=xDomain[xDomain.length-2] + "." + xDomain[xDomain.length-1];
		}
		if (!option||!option.url){ 
				return; 
		}
		var liIndex=option.url.indexOf("/",7);
		var lsFrameUrl = option.url.substring(0,liIndex) + (path||"/ajax.html");
		if(option.url.toLowerCase().indexOf("ajaxv2")){
			lsFrameUrl = "http://ajaxv2.myspace.cn/_common/static/ajax.html";
		}
		var lsDomin= option.url.substring(7,liIndex).split(".").join("_");
		var lsFrameName = lsDomin + "_frame"; 
		var lsFrameWrapperId = lsDomin+"_frameWrapper"; 
		var leFrameWrapper = document.getElementById(lsFrameWrapperId); 
		if (window.frames[lsFrameName] == null){ 
			leFrameWrapper = document.createElement("span"); 
			leFrameWrapper.id = lsFrameWrapperId; 
			leFrameWrapper.style.display = "none"; 
			document.body.appendChild(leFrameWrapper); 
			leFrameWrapper.innerHTML = '<iframe name='+lsFrameName+'></iframe>'; 
			listen(); 
		}else if(window.frames[lsFrameName].ajax == null){ 
			listen(); 
		}else{ 
			callback(); 
		} 
		function listen(){
			var leIframe =  leFrameWrapper.getElementsByTagName("iframe")[0]; 
			if (navigator.userAgent.indexOf("IE")!=-1) { 
					leIframe.attachEvent("onload", callback); 
			}else{ 
					leIframe.addEventListener("load", callback, false); 
			}
			leIframe.src = lsFrameUrl;                               
		}
		function callback(){
			var lsGUID="_ajax_callback"+Math.floor(Math.random()*16000).toString(16);
			window[lsGUID]=option.callback||function(){};
			option.callback=lsGUID;
			var lxUrl=[];
			
			if(option.data){
					for(var x in option.data){                                      
							lxUrl.push(x);
							lxUrl.push("=");
							lxUrl.push(option.data[x]);
							lxUrl.push("&");
					}
					lxUrl.pop();
			}
			if(option.method && option.method.toLowerCase()=="get"){
					lxUrl.unshift(option.url.indexOf("?")==-1?"?":"&");
					lxUrl.unshift(option.url);
					option.url=lxUrl.join("");
					option.data = "";
			}else{
					option.data = lxUrl.join("");
			}
			window.frames[lsFrameName].ajax(option); 
		}                               
    }                             
}   

//提交关闭以及下一步操作
function noSubmit(){
	var URL = "http://ajaxv2.myspace.cn/_Common/AjaxService/BandProfileService.svc/json/UpdateBandFirstPopUp";
	var taskData={
			"url": URL,
			"contentType":"application/x-www-form-urlencoded",
			"method":"post"
	};
	loadAjax(taskData);
}



//
var list = [{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexInfo.ascx"}],"ModuleId":1,"Display":true,"PositionX":0,"PositionY":0,"Layout":1,"MaxDisplayItems":3,"CanDisable":false,"CanMove":false},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexShow.ascx"}],"ModuleId":2,"Display":true,"PositionX":0,"PositionY":1,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexIntro.ascx"}],"ModuleId":3,"Display":true,"PositionX":0,"PositionY":2,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexFans.ascx"}],"ModuleId":5,"Display":true,"PositionX":0,"PositionY":4,"Layout":1,"MaxDisplayItems":5,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexComment.ascx"}],"ModuleId":6,"Display":true,"PositionX":0,"PositionY":3,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexPlayer.ascx"}],"ModuleId":7,"Display":true,"PositionX":1,"PositionY":0,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexMblog.ascx"}],"ModuleId":9,"Display":true,"PositionX":1,"PositionY":1,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexAlbum.ascx"}],"ModuleId":10,"Display":true,"PositionX":1,"PositionY":2,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexBlog.ascx"}],"ModuleId":11,"Display":true,"PositionX":1,"PositionY":3,"Layout":1,"MaxDisplayItems":6,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexVedio.ascx"}],"ModuleId":12,"Display":true,"PositionX":1,"PositionY":4,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexNews.ascx"}],"ModuleId":13,"Display":true,"PositionX":1,"PositionY":5,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexFlash.ascx"}],"ModuleId":14,"Display":false,"PositionX":0,"PositionY":5,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexFlash1.ascx"}],"ModuleId":15,"Display":false,"PositionX":0,"PositionY":5,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexFlash2.ascx"}],"ModuleId":16,"Display":false,"PositionX":1,"PositionY":5,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexFlash3.ascx"}],"ModuleId":17,"Display":false,"PositionX":1,"PositionY":5,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true},{"Resource":[{"Key":"ModuleControl","Value":"~/Modules/ProfileMusic/Controls/MusicIndexFlash4.ascx"}],"ModuleId":18,"Display":false,"PositionX":1,"PositionY":5,"Layout":1,"MaxDisplayItems":3,"CanDisable":true,"CanMove":true}];



window.addEvent('domready', function() {
//植入html
	guidiingBox = document.createElement("div");
	guidiingBox.innerHTML = guidingHTML;	

		document.getElementsByTagName("body")[0].appendChild(guidiingBox);

//生成模板项
	tempObj.len = tempObj.templistData.length;
		var tempArr = new Array(); 
		for (var n=0;n<tempObj.len;n++){
		     if((typeof JS_Context.Isreserve=="undefined" || !JS_Context.Isreserve) && tempObj.templistData[n].id==25){
				 continue;
			 }
			 if(tempObj.templistData[n].id==25){
				 var tempwap = document.getElementById("tempItems");
				 if(tempwap){
					 tempwap.style.height = "450px";
				}
				if(tempwap.parentNode.parentNode.className=="guide_area"){
					tempwap.parentNode.parentNode.style.height = "510px";
				}
			 }
			 tempArr[n]= [
				'<div id="tem_',tempObj.templistData[n].id,'" class="temitem" lang="',tempObj.templistData[n].color,'｜',tempObj.templistData[n].style,'">',
				'<div class="yes"></div>',
				'<a><img src="',tempObj.templistData[n].image,'" /></a>',
				'<span id="temname_',tempObj.templistData[n].id,'" class="temname">',tempObj.templistData[n].name,'</span>',
				'</div>'].join("");
		}
	tempObj.str = tempArr.join(""); 
	document.getElementById("tempItems").innerHTML = tempObj.str;
	tempObj.selectAdd("tempColor",tempObj.color);
	tempObj.selectAdd("tempStyle",tempObj.style);

//模板选择
	var sAll = document.getElementById("tempAll");
		if (sAll) {
			sAll.onclick = function(){tempSelects("","")};
		}
	var sTc = document.getElementById("tempColor");
		if (sTc) {
			sTc.onchange = function(){tempSelects(this.value,"")}
		}
		
	var sTs = document.getElementById("tempStyle");
		if (sTs) {
			sTs.onchange = function(){tempSelects("",this.value)}
		}

//上传头图
	uploadPhotoInMblog("head_upload","ttuploadpre","head_tip");	

//上传背景图
	uploadPhotoInMblog("bg_upload","bguploadpre","bg_tip");	

//是否使用头图
	if ($('ttNoneHP')){
		$('ttNoneHP').addEvent('click', function(){
			if(this.checked) {
				uploadcallbackdata["headerImageIdUse"] = "-1";
				this.getParent().addClass("head_pic_upload_bg_check");
			}else {
				uploadcallbackdata["headerImageIdUse"] = uploadcallbackdata["headerImageId"];
				this.getParent().removeClass("head_pic_upload_bg_check");
			}
		});	
	}
//头图对齐方式
	uploadcallbackdata["HeaderImageTiled"] = "true";
	uploadcallbackdata["HeaderImageAlignment"] = "";
	$('HeaderImageAlignment1').addEvent('click', function(){
		if(this.checked) {
			uploadcallbackdata["HeaderImageTiled"] = "true";
			uploadcallbackdata["HeaderImageAlignment"] = "";
		}
	});	
	$('HeaderImageAlignment0').addEvent('click', function(){
		if(this.checked) {
			uploadcallbackdata["HeaderImageAlignment"] = "2";
			uploadcallbackdata["HeaderImageTiled"] = "false";
		}
	});	
	
//白色背景
	if ($('bgDefaultHP')) {
		$('bgDefaultHP').addEvent('click', function(){
			if(this.checked) {
				uploadcallbackdata["backgroundImageIdUse"] = "-1";
				this.getParent().addClass("head_pic_upload_bg_check");
			}else {
				uploadcallbackdata["backgroundImageIdUse"] = uploadcallbackdata["backgroundImageId"];
				this.getParent().removeClass("head_pic_upload_bg_check");
			}
		});	
	}
//翻页固定
	uploadcallbackdata["BackgroundImageFixed"] = "0";
	uploadcallbackdata["isFixBackgroundRoolPage"] = "0";
	$$('input[name="bgAttachment"]').addEvent('click', function(){													
		uploadcallbackdata["isFixBackgroundRoolPage"] = this.value;
	});
//背景对齐方式
	uploadcallbackdata["BackgroundImageTiled"] = "true";
	uploadcallbackdata["BackgroundImageAlignment"] = "";
	$('bgAlign0').addEvent('click', function(){
		if(this.checked) {
			uploadcallbackdata["BackgroundImageAlignment"] = "2";
			uploadcallbackdata["BackgroundImageTiled"] = "false";
		}
	});
	$('bgAlign1').addEvent('click', function(){
		if(this.checked) {
			uploadcallbackdata["BackgroundImageAlignment"] = "";
			uploadcallbackdata["BackgroundImageTiled"] = "true";
		}
	});

var SelectModule1 = new SelectModule({"list": list,"wap_sel": $("smbody"),"left_drag":$("left_drag"),"right_drag":$("right_drag")});
SelectModule1.init();


//默认打开第一步
	if(JS_Context.firstPopOut){
		MsPopload("settingStep_01");
		tagCloudSwf();
	}

//关闭第一步
	var s1c = document.getElementById("settingStep_01_close");
	s1c.onclick = function(){
		MsHide("settingStep_01");
		noSubmit();
		return false;
	}

//1下一步，关闭当前，打开下一步
	var s1n = document.getElementById("settingStep_01_next");
	s1n.onclick = function(){
		MsHide("settingStep_01");
		MsPopload("settingStep_02");
		noSubmit();
		return false;
	}

//关闭第二步
	var s2c = document.getElementById("settingStep_02_close");
	s2c.onclick = function(){
		MsHide("settingStep_02");
		noSubmit();
		return false;
	}

//2上一步，关闭当前，打开上一步	
	var s2p = document.getElementById("settingStep_02_prev");
	s2p.onclick = function(){
		MsHide("settingStep_02");
		MsPopload("settingStep_01");
		return false;
	}

//2下一步，关闭当前，打开下一步
	var s2n = document.getElementById("settingStep_02_next");
	s2n.onclick = function(){
		savepersonal(s2n);
		noSubmit();
		MsHide("settingStep_02");
		MsPopload("settingStep_03");
		return false;
	}

//关闭第三步	
	var s3c = document.getElementById("settingStep_03_close");
	s3c.onclick = function(){
		MsHide("settingStep_03");
		noSubmit();
		return false;
	}
	
//3上一步，关闭当前，打开上一步	
	var s3p = document.getElementById("settingStep_03_prev");
	s3p.onclick = function(){
		MsHide("settingStep_03");
		MsPopload("settingStep_02");
		return false;
	}

//3下一步，关闭当前，打开下一步
	var s3n = document.getElementById("settingStep_03_next");
	s3n.onclick = function(){
		savepersonal(s3n);
		noSubmit();
		MsHide("settingStep_03");
		MsPopload("settingStep_04");
		return false;
	}

//关闭第四步	
	var s4c = document.getElementById("settingStep_04_close");
	s4c.onclick = function(){
		MsHide("settingStep_04");
		noSubmit();
		return false;
	}
	
//4上一步，关闭当前，打开上一步	
	var s4p = document.getElementById("settingStep_04_prev");
	s4p.onclick = function(){
		MsHide("settingStep_04");
		MsPopload("settingStep_03");
		return false;
	}

//结束
	var over = document.getElementById("settingStepOver");
	over.onclick = function(){
		savemodule();
		MsHide("settingStep_04");	
		return false;
	}
});		