var LOGIN = {}

LOGIN.init = function (sp,type){
	var strBox = '<div id="logon_box_bg"></div><div id="logon_box"><div class="logon_title"><b style="font-size:14px;">请登录</b></div><ul class="logon_box_ul"><li>用户名/Email/手机号<br /><input value="" id="username" class="logon_text" maxlength="64" type="text"/></li><li>密码<br /><input class="logon_text" value="" id="password" maxlength="16" type="password"/></li></ul><div id="logon_error"></div><div class="logon_btn"><input value="确定" id="submit" type="button"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value="取消" id="cancle" type="button"/></div></div>';
	if(G('#logon_box_span')){
		G('#logon_box_span').remove();
	}
		
	var oSpan = document.createElement('span');
	oSpan.id = "logon_box_span";
	oSpan.innerHTML = strBox;
	G(document.body).append(oSpan);
	
	var nClientWidth  = G(document.documentElement)? G(document.documentElement).attr("clientWidth"):G(document.body).attr("clientWidth") + G(document.documentElement).attr("clientWidth");
	var nScrollHeight = G(document.documentElement)? G(document.documentElement).attr("scrollHeight"):G(document.body).attr("scrollHeight")+ G(document.documentElement).attr("scrollHeight");
	var nClientHeight = G(document.documentElement)? G(document.documentElement).attr("clientHeight"):G(document.body).attr("clientHeight") + G(document.documentElement).attr("clientHeight");
	var nScrollTop    = G(document.documentElement)? G(document.documentElement).attr("scrollTop"):G(document.body).attr("scrollTop") + G(document.documentElement).attr("scrollTop");
	var nBoxleft      = (nClientWidth - G("#logon_box").width()) / 2;
	var nBoxTop       = ((nScrollTop + 80)>0)? (nScrollTop + 80) : 0;
	var nBoxBGHeight  = (nScrollHeight > nClientHeight) ? nScrollHeight:nClientHeight;
	
	//对话框背景位置
	G('#logon_box_bg').css(
		{
			top: "0px",
			left: "0px",
			width: nClientWidth + "px",
			height: nBoxBGHeight + "px",
			display: "block"
		}
	);
	G("#logon_box").css(
		{
			left: nBoxleft+"px",
			top: nBoxTop + "px",
			display: "block"
		}
	);
	G("#cancle").click(function (){
		G('#logon_box').hide();
		G('#logon_box_bg').hide();
	});
	G("#submit").click(function (){
		G("#cancle").attr("disabled","disabled");
		G("#submit").attr("disabled","disabled");
		var username = G('#username').val();
		var password = G('#password').val();
		
		var url   = "/f5/mwfm/uots?timeStamp=" + new Date().getTime();
		var param = "ctrl=lg&sp=" + sp + "&username=" + username  + "&password=" + password;
		
		G("#last_step").hide();
		FMJS.postXML(url, param, function(xml){
			var iCode = G(xml).find("error_code").text();
			if(iCode == 0){
				G('#logon_box').hide();
				G('#logon_box_bg').hide();
				var help = "/f5/jsp/plugin/help/Help"+sp+".html";
				if(type == "f"){
					var swfUrl = G(xml).find("flash").text();
					var accountId = G(xml).find("account_id").text();
					
					G("#last_step_ul").empty();
					G("#id_right").empty();
					
					G("#last_step_ul").append('<li>1. 选择插件样式<div class="last_step_note"><ul id="color_list" class="color_list"><li><input class="style" value="1" checked="checked" type="radio" name="style"/>样式一</li><li><input  class="style" value="2" type="radio" name="style"/>样式二</li><li><input  class="style" value="3" type="radio" name="style"/>样式三</li></ul></div></li>');
					G("#last_step_ul").append('<li>2. 设置插件属性<div class="last_step_note"><div style="margin-top:10px;">宽度 <input id="width_attr" value="260" maxlength="4" class="width_attr" type="text"/>px<span style="margin-left:10px;color:#a0a0a0">(最小宽度 180px)</span></div><div style="margin-top:10px;">高度 <input id="height_attr" value="500" maxlength="4" class="width_attr" type="text"/>px<span style="margin-left:10px;color:#a0a0a0">(最小高度 350px)</span></div></li>');
					G("#last_step_ul").append('<li><input type="button" value="预览并生成代码" class="button" id="preview"/></li>');
					G("#last_step_ul").append('<li>HTML代码<div class="last_step_note" style="color:#a0a0a0">请复制下面的代码，粘贴到博客的自定义模块中。</div><div class="last_step_note"><textarea id="copy_code" class="copy_code" readonly="readonly" rows="6" cols="55"></textarea></div></li>');
					G("#last_step_ul").append('<li>Flash地址<div class="last_step_note" style="color:#a0a0a0">若你的博客不支持HTML代码，那么请复制下面的链接插入。</div><div class="last_step_note"><textarea id="copy_code_swf" class="copy_code" readonly="readonly" rows="6" cols="55"></textarea></div></li>');
					G("#last_step_ul").append('<li><input type="hidden" value="1" id="style_attr"/></li>');
					if(sp != "other"){
						G("#last_step_ul").append('<li>3. 不知道粘贴到哪里？请<a target="_blank" id="help" href="###">查看帮助</a>。</li>');
					}
					
					var code_html = getFlashCode(swfUrl,260,500,1,accountId);
					var code_swf = getFlashCode(swfUrl,260,500,1,accountId,"swf");
					
					G("#copy_code").val(code_html);
					G("#copy_code_swf").val(code_swf);
					G("#id_right").append('<div id="flash_demo">'+code_html+'</div>');
					
					G(".style").click(function () {
						var sy = G(this).val();
						G("#style_attr").val(sy);
					});
					
					G("#copy_code").click(function () {
						G(this).select();
					});
					
					G("#copy_code_swf").click(function () {
						G(this).select();
					});
					
					G("#preview").click(function(){
						var wd = G("#width_attr").val();
						var hi = G("#height_attr").val();
						var sy = G("#style_attr").val();
						G("#copy_code").val(getFlashCode(swfUrl,wd,hi,sy,accountId));
						G("#copy_code_swf").val(getFlashCode(swfUrl,wd,hi,sy,accountId,"swf"));
						G("#flash_demo").html(getFlashCode(swfUrl,wd,hi,sy,accountId));
						
					});
					
					
				}else if(type == "p"){
					var pic   = G(xml).find("pic").text();
					var src   = G(xml).find("src").text();
				
					G("#last_step_ul").empty();
					G("#id_right").empty();
					G("#last_step_ul").append('<li>1. 选择插件类型<div style="margin-left: 12px;"><span><input checked="checked" type="radio" id="list_type" name="type"/>列表式样</span><span class="next_margin"><input id="sign_type" type="radio" name="type"/>签名式样</span></div></li>');
					G("#last_step_ul").append('<li>2. 选择插件样式<div class="last_step_note"><ul id="color_list" class="color_list"><li><input class="style" value="1" checked="checked" type="radio" name="style"/>样式一</li><li><input  class="style" value="2" type="radio" name="style"/>样式二</li><li><input  class="style" value="3" type="radio" name="style"/>样式三</li><li><input  class="style" value="4" type="radio" name="style"/>样式四</li></ul></div></li>');
					G("#last_step_ul").append('<li>3. 设置插件属性<div class="last_step_note"><div>宽度 <input id="width_attr" value="260" maxlength="4" class="width_attr" type="text"/>px</div><div style="margin-top: 10px;">显示 <select id="msg_num" class="select_num"><option value="1">1</option><option value="2">2</option><option value="3" selected="selected">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select>条分享</div></div></li>');
					G("#last_step_ul").append('<li>4. 复制下面的代码<div class="last_step_note"><textarea id="copy_code" class="copy_code" readonly="readonly" rows="6" cols="55"></textarea></div></li>');
					if(sp != "other"){
						G("#last_step_ul").append('<li>5. 不知道粘贴到哪里？请<a target="_blank" id="help" href="###">查看帮助</a>。</li>');
					}
					G("#id_right").append('<img id="img_demo" src='+src+'/>');
					G("#copy_code").val(pic.replace("/temp/",src));
					G("#copy_code").click(function () {
						G(this).select();
					});
					G("#msg_num").change(function () {
						var num = G(this).val();
						var si = src.indexOf("c_");
						var sd = src.indexOf("/", si);
						src = src.substring(0, si+2) + num + src.substring(sd);
						G("#copy_code").val(pic.replace("/temp/",src));
						G("#img_demo").attr("src",src);
					});
					G("#width_attr").keyup(function () {
						var wd = G(this).val();
						if(!FM.String.isNum(wd) || wd < 100){
							wd = 100;
						}
						var pi = src.indexOf("w_");
						var pd = src.indexOf("/", pi);
						src = src.substring(0, pi+2) + wd + src.substring(pd);
						G("#copy_code").val(pic.replace("/temp/",src));
						G("#img_demo").attr("src",src);
					});
					G("#list_type").click(function () {
						var si = src.indexOf("/sign/");
						if(si > 0){
							src = src.substring(0, si) + "/list/" + src.substring(si+6);
						}
						var si2 = src.indexOf("c_");
						var sd = src.indexOf("/", si2);
						var cc = src.substring(si2+2,sd);
						src = subsrc(src);
						G("#copy_code").val(pic.replace("/temp/",src));
						G("#img_demo").attr("src",src);
						G("#msg_num").val(cc);
						G("#width_attr").val("260");
						G("#width_attr").attr("readonly","");
						G("#msg_num").attr("disabled","");
					});
					G("#sign_type").click(function () {
						var si = src.indexOf("/list/");
						if(si > 0){
							src = src.substring(0, si) + "/sign/" + src.substring(si+6);
						}
						src = subsrc(src);
						G("#copy_code").val(pic.replace("/temp/",src));
						G("#img_demo").attr("src",src);
						G("#msg_num").val("1");
						G("#width_attr").val("260");
						G("#width_attr").attr("readonly","readonly");
						G("#msg_num").attr("disabled","disabled");
					});
					G(".style").click(function () {
						var sy = G(this).val();
						var si = src.indexOf("t_");
						src = src.substring(0, si+2) + sy + src.substring(si+3);
						G("#copy_code").val(pic.replace("/temp/",src));
						G("#img_demo").attr("src",src);
					});
				}else {
					var js    = G(xml).find("js").text();
					
					G("#last_step_ul").empty();
					G("#id_right").empty();
					G("#last_step_ul").append('<li>1. 输入显示的的留言条数(1-10条)<div style="margin-left: 15px;"><input value="3" id="msg_num" maxlength="2" class="msg_num" type="text"/><input value="预览" id="preview" class="preview" type="button"/></div></li>');
					G("#last_step_ul").append('<li>2. 选择插件样式<div class="last_step_note"><ul id="color_list" class="color_list"><li><input class="style" value="1" checked="checked" type="radio" name="style"/>样式一</li><li><input  class="style" value="2" type="radio" name="style"/>样式二</li><li><input  class="style" value="3" type="radio" name="style"/>样式三</li><li><input  class="style" value="4" type="radio" name="style"/>样式四</li></ul></div></li>');
					G("#last_step_ul").append('<li>3. 复制下面的代码<div class="last_step_note"><textarea id="copy_code" class="copy_code" readonly="readonly" rows="6" cols="55"></textarea></div></li>');
					if(sp != "other"){
						G("#last_step_ul").append('<li>4. 不知道粘贴到哪里？请<a target="_blank" id="help" href="###">查看帮助</a>。</li>');
					}
					G("#id_right").append('<div id="js_demo">'+js+'</div>');
					G("#copy_code").val(js);
					G("#copy_code").click(function () {
						G(this).select();
					});
					G("#preview").click(function () {
						var num = G("#msg_num").val();
						if(num < 1){
							num = 1;
						}
						if(num > 10){
							num = 10;
						}
						var si = js.indexOf("c_");
						var sd = js.indexOf("/", si);
						js = js.substring(0, si+2) + num + js.substring(sd);
						G("#copy_code").val(js);
						G("#js_demo").html(js);
					});
					G(".style").click(function () {
						var sy = G(this).val();
						var si = js.indexOf("t_");
						js = js.substring(0, si+2) + sy + js.substring(si+3);
						G("#copy_code").val(js);
						G("#js_demo").html(js);
					});
				}
			G("#help").attr("href",help);
			G("#last_step").show();
			var nScrollHeight = G(document.documentElement)? G(document.documentElement).attr("scrollHeight"):G(document.body).attr("scrollHeight")+ G(document.documentElement).attr("scrollHeight");
			window.scrollTo(0,nScrollHeight);
		}else{
			G("#cancle").attr("disabled","");
			G("#submit").attr("disabled","");
			G("#logon_error").html(errMap.get(iCode));
		}
		});
	});
}