var mid;
var side = 1;
var style = 1;
var code = '';


function validateMid(){
	var url ='./ajaxData/saveBbsData.jsp';
	mid = $('#mid').val();
	if( mid == ''){
		$('#midTips').show();
		$('#flashContent').hide()
		$('#blogContent').val('');
		$('#blog_step').hide();
		return ;
	}
	$.ajaxSetup({cache:false});
	$.getJSON(url,{'mid':mid,'type':1},function(json){
		if( json.result == 'success'){
			$('#midTips').hide();
			$('#blog_step').show();
			selectCode();
			$('#mid').replaceWith('<span id="mid" >'+mid+'</span>');
			$('#btn1').replaceWith('<a id="btn1" href="#" onclick="alterMid();return false;" >修改</a');
		}else{
			$('#blog_step').hide();
			$('#midTips').show();
			$('#flashContent').hide()
			$('#blogContent').val('');
		}
	});
}

function alterMid(){
	$('#blog_step').hide();
	$('#flashContent').hide()
	$('#blogContent').val('');
	$('#mid').replaceWith('<input id="mid" value="'+mid+'" >');
	$('#btn1').replaceWith('<input value="确定" id="btn1" onclick="validateMid();"  type="button" />');
}

function selectCode(){
	if( mid == ''){
		$('#midTips').show();
		$('#flashContent').hide()
		$('#blogContent').val('');
		return ;
	}
	if( side-0 == 4){
		code='http://digushow.digu.com/style/images/sign.swf?mid='+ mid +'&style='+ style;
	}else{
		code='<embed type="application/x-shockwave-flash" src="http://digushow.digu.com/style/images/sign.swf?mid='+ mid +'&style='+ style +'" quality="autohigh" wmode="transparent" width="180" height="400"  pluginspage="http://www.adobe.com/go/getflashplayer" ></embed>';
	}
	$('#blogContent').val(code);
	getFlash();
}

function styleSelect(value){
	style = value;
	selectCode();
}

function getFlash(){
	var code2 = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0" width="180" height="308"><param name="movie" value="http://digushow.digu.com/style/images/sign.swf" /><param name="flashvars" value="mid='+  mid +'&style='+ style +'" /><param name="quality" value="autohigh" /><param name="wmode" value="transparent" /><embed type="application/x-shockwave-flash" src="http://digushow.digu.com/style/images/sign.swf" flashvars="mid='+ mid +'&style='+ style +'" quality="autohigh" wmode="transparent" width="180" height="308"><param name="allowScriptAccess" value="always" /></embed></object>';
	$('#flashContent').html(code2);
	$('#flashContent').show()
}

function copy(){
	var text = $('#blogContent').val();
	if (window.clipboardData) {
		window.clipboardData.clearData();
        window.clipboardData.setData("Text", text);
        alert('复制成功！');
    } else {
       	var $f = $("#flashcopier");
		$f.size() ? {} : $f=$('<div id="flashcopier" style="width:0;height:0;"></div>').appendTo('body');
		$f.html('<embed src="http://images.digu.com/web_res_v1/flash/flashcopier.swf" FlashVars="clipboard=' + encodeURIComponent(text) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>');
		alert('复制成功！');
    }
}