/***
 @description: blog个性化所用到的js函数库
 @auth leuko
 @date 2007-10-29
***/

//**ajax得到月历
function get_blog_calendar(cal){
	$.get("date_func.php?"+Math.random(),{'act':'ajax_cal','username':ownName,'date':cal},function(d){
		$e('diary_cal_data').innerHTML = d;
	});
}

function chk_ifim_style(style){
	$.get("/blog/do_ajax.php?"+Math.random(),{'style':style,'act':'chg_style','username':ownName},function(){window.location.reload();});

	try{hide_confirm()}catch(e){};
	return;
}
function chg_style(style){
	if(style.substr(0,2)=='im'){
		show_confirm("chk_ifim_style('"+style+"')",'你转换的是框架版的博客，你之前的模块定制仍存在！',0,1);
		return;
	}
	chk_ifim_style(style);
}


//**
function chg_set_which(t,o){
	if(t==1){
		$('#h_self_pic').show();
		$('#h_self_pset').show();
		$('#b_self_pic').hide();
		$('#b_self_pset').hide();
		$('#module_self_pic').hide();
		$('#mouse_self_pic').hide();$('#blog_mouse_setting').val('');$('#keep_mouse_setting').val('');
		$('#title_self_pic').hide();$('#blogtitsetting').val('0');
		$('#self_set_tit1').css({'background':'#DDDDDD','border':'1px solid #D4D4D4','fontWeight':'bold'});
		$('#self_set_tit2').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit3').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit4').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
	}else if(t==2){
		$('#b_self_pic').show();
		$('#b_self_pset').show();
		$('#h_self_pic').hide();
		$('#h_self_pset').hide();
		$('#module_self_pic').hide();
		$('#mouse_self_pic').hide();$('#blog_mouse_setting').val('');$('#keep_mouse_setting').val('');
		$('#title_self_pic').hide();$('#blogtitsetting').val('0');
		$('#self_set_tit2').css({'background':'#DDDDDD','border':'1px solid #D4D4D4','fontWeight':'bold'});
		$('#self_set_tit1').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit3').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit4').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
	}
	else if(t==4){//title
		init_title_setting(1);
		$('#blogtitsetting').val('1');
		$('#b_self_pic').hide();
		$('#b_self_pset').hide();
		$('#h_self_pic').hide();
		$('#h_self_pset').hide();
		$('#module_self_pic').hide();	
		$('#mouse_self_pic').hide();$('#blog_mouse_setting').val('');$('#keep_mouse_setting').val('');
		$('#title_self_pic').show();

		$('#tit_color_grid').show();
		$('#self_set_tit4').css({'background':'#DDDDDD','border':'1px solid #D4D4D4','fontWeight':'bold'});
		$('#self_set_tit1').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit2').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit3').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
	}
	else if(t==5){//mouse
		$('#mouse_self_pic').show();
		if($('#mouse_self_pic').html()==''){init_mouse_setting();}
		$('#blog_mouse_setting').val('1');
		$('#keep_mouse_setting').val('');
		$('#b_self_pic').hide();
		$('#b_self_pset').hide();
		$('#h_self_pic').hide();
		$('#h_self_pset').hide();
		$('#module_self_pic').hide();
		$('#title_self_pic').hide();$('#blogtitsetting').val('0');
		$('#self_set_tit2').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit1').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit3').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit4').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit5').css({'background':'#DDDDDD','border':'1px solid #D4D4D4','fontWeight':'bold'});
	}
	else{
		if($('#colors_tab').html()=='') initColorsTab();
		if($('#mod_bg_set').html()=='') init_mod_set_bg();
		$('#b_self_pic').hide();
		$('#b_self_pset').hide();
		$('#h_self_pic').hide();
		$('#h_self_pset').hide();
		$('#mouse_self_pic').hide();$('#blog_mouse_setting').val('');$('#keep_mouse_setting').val('');
		$('#title_self_pic').hide();$('#blogtitsetting').val('0');
		$('#module_self_pic').show();
		$('#self_set_tit3').css({'background':'#DDDDDD','border':'1px solid #D4D4D4','fontWeight':'bold'});
		$('#self_set_tit1').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit2').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
		$('#self_set_tit4').css({'background':'#EEEEEE','border':'1px solid #EBEBEB'});
	}
}
//**blog的头背景和body背景
function init_header_body_set(){
	//**临时存放
	_tmp_header_body_set = {"h":{"background":"","background-repeat":"","background-positionX":"","background-positionY":"","height":""},"b":{"background":"","background-repeat":"","background-positionX":"","background-positionY":""},'hu':{'background':'','use':0},'bu':{'background':'','use':0}};
	if(typeof header_body_set=='object'){
		_tmp_header_body_set.hu.background = header_body_set.hu.background;
		_tmp_header_body_set.bu.background = header_body_set.bu.background;
		_tmp_header_body_set.hu.use = header_body_set.hu.use;
		_tmp_header_body_set.bu.use = header_body_set.bu.use;

		//**header
		var tmp_h = header_body_set.h;
		if(get_slt_index('h_repeat',tmp_h['background-repeat']) !=-1)
			$e('h_repeat').options.selectedIndex = get_slt_index('h_repeat',tmp_h['background-repeat']);
		if(get_slt_index('h_x',tmp_h['background-positionX']) != -1)
			$e('h_x').options.selectedIndex = get_slt_index('h_x',tmp_h['background-positionX']);
		if(get_slt_index('h_y',tmp_h['background-positionY']) != -1)
			$e('h_y').options.selectedIndex = get_slt_index('h_y',tmp_h['background-positionY']);
		if(!!$e('h_height'))
			$e('h_height').value = tmp_h['height'];
		if(header_body_set.hu.use==1 && header_body_set.hu.background != '')
			$('#header').css('background','url(http://blog.mzsky.cc/blog/skin/customize/upload_bg/'+header_body_set.hu.background+')');
		for(var p in tmp_h){
			if(!!tmp_h[p]==false) continue;
			_tmp_header_body_set.h[p] = tmp_h[p];
			if(p=='background'){
				if(header_body_set.hu.use==1) continue;
				var oImg1 = new Image();
				oImg1.src = tmp_h[p];
				$('#header').css(p,'url('+tmp_h[p]+')');
				continue;
			}
			if(p=='height'){//zhangming 20090624
				$('#header').css(p,tmp_h[p]+'px');
			}
			try{$('#header').css(p,tmp_h[p]);}catch(e){};
		}
		
		//**body
		var tmp_b = header_body_set.b;
		if(get_slt_index('b_repeat',tmp_b['background-repeat']) !=-1)
			$e('b_repeat').options.selectedIndex = get_slt_index('b_repeat',tmp_b['background-repeat']);
		if(get_slt_index('b_x',tmp_b['background-positionX']) != -1)
			$e('b_x').options.selectedIndex = get_slt_index('b_x',tmp_b['background-positionX']);
		if(get_slt_index('b_y',tmp_b['background-positionY']) != -1)
			$e('b_y').options.selectedIndex = get_slt_index('b_y',tmp_b['background-positionY']);
		if(header_body_set.bu.use==1 && header_body_set.bu.background!='')
			$('#body').css('background','url(http://blog.mzsky.cc/blog/skin/customize/upload_bg/'+header_body_set.bu.background+')');
		//wrapper zhangming 20090624
	//	$('#wrapper').css('background','url(http://blog.mzsky.cc/blog/skin/customize/upload_bg/'+header_body_set.bu.background+')');
		for(var p in tmp_b){
			if(!!tmp_b[p]==false) continue;
			_tmp_header_body_set.b[p] = tmp_h[p];
			if(p=='background'){
				if(header_body_set.bu.use==1) continue;
				var oImg1 = new Image();
				oImg1.src = tmp_b[p];
				$('#body').css(p,'url('+tmp_b[p]+')');
				//$('#wrapper').css(p,'url('+tmp_b[p]+')');
				continue;
			}
			$('#body').css(p,tmp_b[p]);
			//$('#wrapper').css(p,tmp_b[p]);
		}

	}else{
		header_body_set = {"h":{"background":"","background-repeat":"","background-positionX":"","background-positionY":"","height":"","background":""},"b":{"background":"","background-repeat":"","background-positionX":"","background-positionY":""},'hu':{'background':'','use':0},'bu':{'background':'','use':0}};
	}
}



//**上传头图片
function upload_h_p(o){
	if(chk_hb_upload_ext($('#upload_header_file').val())==false){
		return;
	}
	o.disabled = true;
	o.value = '上传中...';
	ajaxFileUpload('upload_header_file',o);
}
function upload_b_p(o){
	if(chk_hb_upload_ext($('#upload_body_file').val())==false){
		return;
	}
	o.disabled = true;
	o.value = '上传中...';
	ajaxFileUpload('upload_body_file',o);
}
function chk_hb_upload_ext(s){
	var arr = s.split('.');
	var ext = arr[arr.length-1].toLowerCase();
	if(ext!='gif' && ext!='jpg' && ext!='jpeg' && ext!='png'){
		show_confirm('hide_confirm()','不允许的文件格式！',0,0);
		return false;
	}
	return true;
}
//**设置header的background
function chg_header_bg(t,i){
	//typeof i=='undefined'时，用默认的，，
	if(t==1){	//*header背景图
		_tmp_header_body_set.hu.use = 0;
		$('#upload_header_bg').hide();
		if(typeof i=='undefined'){
			_tmp_header_body_set.h.background = '';
			document.getElementById('header').style.background = '';
			return;
		}else if(i==0){   //**自己上传
			$('#upload_header_bg').show();
			_tmp_header_body_set.hu.use=1;
			if(header_body_set.hu.background == '' || $('#header').css('background').indexOf('upload_bg') > -1)
				return;
			var src = '/blog/skin/customize/upload_bg/'+header_body_set.hu.background;
			
		}else{
			var src = '/blog/skin/customize/header_bg/'+i+'.jpg';
			_tmp_header_body_set.h.background = src;
		}
		var oImg = new Image();
		oImg.src = src;
		document.getElementById('header').style.background = 'url('+src+')';
	}else{	//*body背景图
		_tmp_header_body_set.bu.use = 0;
		$('#upload_body_bg').hide();
		if(typeof i=='undefined'){
			var arrHref = $('#_style').attr('href').split('/');
			var src = '/blog/skin/'+arrHref[1]+'/images/body_bg.jpg';
			_tmp_header_body_set.b.background = '';
			var oImg = new Image();
			oImg.src = src;
			document.getElementById('body').style.background = skin_bg_color[arrHref[1]]+' url('+src+') repeat-x';
			return;
		}else if(i==0){   //**自己上传
			$('#upload_body_bg').show();
			_tmp_header_body_set.bu.use=1;
			//if(header_body_set.bu.background == '' || $('#wrapper').css('background').indexOf('upload_bg') > -1)
			if(header_body_set.bu.background == '' || $('#body').css('background').indexOf('upload_bg') > -1)
				return;
			var src = '/blog/skin/customize/upload_bg/'+header_body_set.bu.background;
		}else{
			var src = '/blog/skin/customize/body_bg/'+i+'.jpg';
			_tmp_header_body_set.b.background = src;
		}
		var oImg = new Image();
		oImg.src = src;
		document.getElementById('body').style.background = 'url('+src+')';
	}
}
function chg_header_set(t,o,w){
	if(w=='h'){
		if(t=='h_repeat'){
			document.getElementById('header').style.backgroundRepeat = o.value;
			_tmp_header_body_set.h['background-repeat'] = o.value;
		}
		if(t=='h_x'){
			document.getElementById('header').style.backgroundPositionX = o.value;
			_tmp_header_body_set.h['background-positionX'] = o.value;
		}
		if(t=='h_y'){
			document.getElementById('header').style.backgroundPositionY = o.value;
			_tmp_header_body_set.h['background-positionY'] = o.value;
		}
		if(t=='h_height'){
			var h = parseInt(o.value);
			if(h<100 || h>300){
				show_confirm("hide_confirm()",'高度值只能在100~300之间',0,0);
				o.focus();
				return ;
			}
			document.getElementById('header').style.height = h+'px';
			_tmp_header_body_set.h.height = o.value;
		}
	}else{
		if(t=='b_repeat'){
			document.getElementById('body').style.backgroundRepeat = o.value;
			_tmp_header_body_set.b['background-repeat'] = o.value;
		}
		if(t=='b_x'){
			document.getElementById('body').style.backgroundPositionX = o.value;
			_tmp_header_body_set.b['background-positionX'] = o.value;
		}
		if(t=='b_y'){
			document.getElementById('body').style.backgroundPositionY = o.value;
			_tmp_header_body_set.b['background-positionY'] = o.value;
		}
	}
}
function save_self_set(){
	$('#set_s').hide();
	if(typeof _tmp_header_body_set =='object'){
		if($('#blogtitsetting').val()>0)
		{
			var sTitSet='';
			if($('#tit_font_color').val()!=0) 
				sTitSet +='color:'+$('#tit_font_color').val()+'!important;';
			if($('#tit_font_size').val()!=0) 
				sTitSet +='font-size:'+$('#tit_font_size').val()+'!important;';
			if($('#tit_font_family').val()!=0) 
				sTitSet +='font-family:'+$('#tit_font_family').val()+'!important;';
			if($('#tit_font_bolder').val()!=0) 
				sTitSet +='font-weight:'+$('#tit_font_bolder').val()+'!important;';

			if(sTitSet!=''){
				$.get("/blog/do_ajax.php?"+Math.random(),{'type':$('#blogtitsetting').val(),'setting':sTitSet,'act':'set_Blog_Title_css','username':ownName},function(){
				show_confirm("hide_confirm()",'设置成功',0,0);
				});
			}
			else
				return;
		}
		else if($('#blog_mouse_setting').val()!='' && $('#keep_mouse_setting').val()!=''){
				$.get('/blog/do_ajax.php?'+Math.random(),{'username':ownName,'act':'chg_mouse_ico','mouse':$('#keep_mouse_setting').val()},function(){show_confirm("hide_confirm()",'鼠标图片设置成功',0,0);});
		}
		else{
			var sModSet = '';
			if(_mod_set.bg.length>0 || _mod_set.font.length>0 || _mod_set.border.length>0)
				sModSet = JSON.stringify(_mod_set);
			var s_set = JSON.stringify(_tmp_header_body_set)
			$.get("/blog/do_ajax.php?"+Math.random(),{'set':s_set,'mod_set':sModSet,'act':'set_header_body','username':ownName},function(){
				eval('header_body_set = ' + s_set);
			});
		}
			return;
	}else{
		show_confirm("hide_confirm()",'出现不明错误，请联系技术人员',0,0);
	}
	$('#set_s').hide();
}
function cancel_self_set(){
	$('#blog_title').removeAttr('style');
	$('#blog_url').removeAttr('style');
	$('#des').removeAttr('style');

	$('#header').removeAttr('style');
	$('#body').removeAttr('style');
	//$('#wrapper').removeAttr('style');
	$('#set_s').hide();
	init_header_body_set();
}

function clear_all_set(i){
	if(i==0){
		_tmp_header_body_set = {"h":{"background":"","background-repeat":"","background-positionX":"","background-positionY":"","height":""},"b":{"background":"","background-repeat":"","background-positionX":"","background-positionY":""},'hu':{'background':'','use':0},'bu':{'background':'','use':0}};
		header_body_set =  {"h":{"background":"","background-repeat":"","background-positionX":"","background-positionY":"","height":""},"b":{"background":"","background-repeat":"","background-positionX":"","background-positionY":""},'hu':{'background':'','use':0},'bu':{'background':'','use':0}};
		_mod_set = {'bg':[],'font':[],'border':[]};
		$('#header').removeAttr('style');
		$('#body').removeAttr('style');
		//$('#wrapper').removeAttr('style');
		$('.modTable .mheader').removeAttr('style');
		$('.modTable tbody').removeAttr('style');
		$('.fc0').removeAttr('style');
		$('.fc1').removeAttr('style');
		$('.fc2').removeAttr('style');
		$('.fc3').removeAttr('style');
		$('.mod').removeAttr('style');
		var act = 'clear_all_set';
	}else if(i==1){
		_mod_set = {'bg':[],'font':[],'border':[]};
		$('.modTable .mheader').removeAttr('style');
		$('.modTable tbody').removeAttr('style');
		$('.fc0').removeAttr('style');
		$('.fc1').removeAttr('style');
		$('.fc2').removeAttr('style');
		$('.fc3').removeAttr('style');
		$('.mod').removeAttr('style');
		var act = 'clear_mod_set';
	}
	else if(i==41){
		$('.titfc1').removeAttr('style');
		$('.titfc1').removeAttr('class');
		var act = 'clear_blogtit_set';
	}
	else if(i==42){
		$('.titfc2').removeAttr('style');$('.titfc2').removeAttr('class');
		var act = 'clear_blogurl_set';
	}
	else if(i==43){
		$('.titfc3').removeAttr('style');$('.titfc3').removeAttr('class');
		var act = 'clear_blogdes_set';
	}
	else if(i==5){
		document.body.style.cursor='default';
		var act = 'clear_mouse_set';
	}
	else{
		_tmp_header_body_set = {"h":{"background":"","background-repeat":"","background-positionX":"","background-positionY":"","height":""},"b":{"background":"","background-repeat":"","background-positionX":"","background-positionY":""},'hu':{'background':'','use':0},'bu':{'background':'','use':0}};
		header_body_set =  {"h":{"background":"","background-repeat":"","background-positionX":"","background-positionY":"","height":""},"b":{"background":"","background-repeat":"","background-positionX":"","background-positionY":""},'hu':{'background':'','use':0},'bu':{'background':'','use':0}};
		$('#header').removeAttr('style');
		$('#body').removeAttr('style');
	//	$('#wrapper').removeAttr('style');
		var act = 'clear_hb_set';
	}
	$.get("/blog/do_ajax.php?"+Math.random(),{'act':act,'username':ownName},function(){});
	hide_confirm();
}
//**编辑blog的信息
function edit_blog_info(o,type){
	var e = $(o).prev();
	/*if($(e).html().toLowerCase().indexOf('<input')!=-1)
		return;*/
	if(e.attr('title')=='')
		return;
	e.attr('title','');
	var content = $(e).html();
	content = content.replace(/\"/g,"&quot;");
	var randID = Math.random();
	$(e).html('<input type="text" id="'+randID+'" value="'+content+'" onblur="save_blog_info(this,\''+type+'\')" />');
	setTimeout("$e("+randID+").focus();",5);
}
function save_blog_info(o,type){
	var e = $(o).parent();
	e.attr('title','点击编辑');
	var content = $(o).val();
	$.get("blog_data.php?"+Math.random(),{'act':'save_blog_info','username':ownName,'type':type,'c':content},function(){});
	content = content.replace(/</g,"&lt;");
	content = content.replace(/>/g,"&gt;");
	e.html(content);
}

//**保存我的设置
//**当增加了模块或删除了模块后，要重新序列化_blog_data
function serialize_my_style(){
	var blog_info = getElementsByClassName("blog_info",'div');
	var json = '[';
	for(var i=0,max=blog_info.length;i<max;i++){
		if(json == '[')
			json = json + "{'w':'" + blog_info[i].style.width + "','d':[";
		else
			json = json + ",{'w':'" + blog_info[i].style.width + "','d':[";
		var isFirst = 0;
		$(blog_info[i]).children().each(function(){
			if(this.id.substr(0,2)=='pk'){
				if(isFirst == 0){
					json = json + this.id.substr(2);
					isFirst = 1;
				}
				else
					json = json + ',' + this.id.substr(2);
			}
		});
		json = json + ']}';
	}
	json = json + ']';
	_blog_data[cur_nav_No] = eval('('+json+')');
	//alert(JSON.stringify(_blog_data[cur_nav_No]));
}

function style_json2string(){
	//**example : JSON.stringify;
alert(JSON.stringify(
	[[{'w':'24%','d':[1,2,3]},{'w':'46%','d':[4,5,6]},{'w':'24%','d':[7,8,9]}],[{'w':'28%','d':[3,2,1]},{'w':'68%','d':[4,5,6]}]]
	));
}


//***增加模块
function addModule(n,e){
	$('#add_m').hide();
	var have_module = chk_module_menu();	//*已有的模块
	for(var i=0,l=have_module.length;i<l;i++){	//**所添加的模块是否已存在
		if(n==have_module[i]){
			show_confirm("hide_confirm()","该模块已经存在页面中！不能重复添加！",0);
			return;
		}
	}
	var cur_data = _blog_data[cur_nav_No];
	var cur_module_len = 0;
	for(var i=0,l=cur_data.length;i<l;i++){
		cur_module_len += cur_data[i].d.length;
	}
	if(cur_module_len > 8){
		show_confirm("hide_confirm()","此页面的模块太多，过多的模块会影响你的浏览性能<br />不如再添加个页面，把新模块放在那里吧<br />",0,0);
		return;
	}
	if(!$e('pk'+n)){
		$('#loading').show();
		var sid = '';
		$("#blog_0").children().each(function(){
			if(this.id.substr(0,2) == 'pk'){
				sid = sid + ',' + this.id.substr(2);
			}
		});
		$.get("blog_data.php?"+Math.random(),{'id':sid+','+n,'username':ownName},function(d){
			if(d){
				$("#blog_0").html(d);
			}
			init_mod_set()
			execDragDrog();
			execModAdminHideShow();
			serialize_my_style();
			var sPage_content = JSON.stringify(_blog_data);
			$.get("blog/do_ajax.php?"+Math.random(),{'page_content':sPage_content,'act':'chg_page_content','username':ownName},function(){
				setTimeout(init_add_module_menu,500);
				$('#loading').hide();
			});

			if(n==43)
				start_bg_music();
			if(n==45)
				refresh_module(45);
		});
		
	}
	

}
//**删除模块
function delModule(e){
	if(!!$('#'+e)){
		$('#loading').show();
		$('#'+e).remove();
		var id = e.substr(2);
		/*$('#a'+id+' img[@tag]').remove();
		$("#a"+id).css({'filter':'alpha(opacity=100)','opacity':'1','color':'#000','background':'#fff','cursor':'pointer'});
		$("#a"+id).click(function(){addModule(id,"a"+id)});*/
		serialize_my_style();
		var sPage_content = JSON.stringify(_blog_data);
		$.get("blog/do_ajax.php?"+Math.random(),{'page_content':sPage_content,'act':'chg_page_content','username':ownName},function(){
			setTimeout(init_add_module_menu,500);
			$('#loading').hide();
			//if(id!=45)refresh_module(45)
		});
		
	}
}

//zhangming 20090224
//删除博客大赛模块
function del2008(){

	if(!!$('#46')){
		$('#loading').show();
		$('#46').remove();
		serialize_my_style();
		var sPage_content = JSON.stringify(_blog_data);
		$.get("blog/blog_guest_do.php?"+Math.random(),{'page_content':sPage_content,'act':'chg_page_content','username':ownName},function(){
		});		
	}
}

//***修改版式
function show_format(evnt){
	var evt = evnt?evnt:window.event;
	var domBody = document.documentElement?document.documentElement:document.body;
	if($e('format_data').style.display=='')
		$e('format_data').style.display='none';
	else
		$e('format_data').style.display='';
	$e('format_data').style.left = evt.clientX+15 + 'px';
	$e('format_data').style.top = evt.clientY+15 + 'px';
}

function get_cur_style(){
	if($e('blog_0').style.width == '28%') return 1 ;
	if($e('blog_0').style.width == '68%') return 2 ;
	if($e('blog_0').style.width == '24%') return 3 ;
	if($e('blog_0').style.width == '97%') return 4 ;
	if($e('blog_0').style.width == '31%') return 5 ;
	if($e('blog_0').style.width == '48%') return 6 ;
}
function chgFormat(n){
	$("div[@class=blog_info]") || alert('你还没添加模块！');
	var blog_info = getElementsByClassName("blog_info",'div');
	//var curStyle = blog_info.length;
	var curStyle = get_cur_style();
	
	if(n==curStyle) return;

	$('#loading').show();

	$('#col_style a').removeAttr('style');
	$('#col_style a').eq(n-1).css('border','1px solid #78d03c');

	if(curStyle==1 || curStyle==2){
		if(n==2 || n==1){
			if(curStyle==1){
				var w1 = "68%";
				var w2 = "28%";
			}else{
				var w1 = "28%";
				var w2 = "68%";
			}
			blog_info[0].style.width = w1;
			blog_info[1].style.width = w2;
		}
		if(n==3 || n==5){
			$('<div class="blog_info" id="blog_2"></div>').appendTo($('#blog_data'));
			if(n==3){
				blog_info[0].style.width = "24%";
				blog_info[1].style.width = "46%";
				$e("blog_2").style.width = "24%";
			}else{
				blog_info[0].style.width = "31%";
				blog_info[1].style.width = "31%";
				$e("blog_2").style.width = "31%";
			}
		}
		if(n==4){
			appendChilds(blog_info[0],$(blog_info[1]).children());
			$(blog_info[1]).remove();
			blog_info[0].style.width = '97%';
		}
		if(n==6){
			blog_info[0].style.width = "48%";
			blog_info[1].style.width = "48%";
		}
	}

	if(curStyle==3 || curStyle==5){
		if(n==1 || n==2){
			appendChilds(blog_info[1],$(blog_info[2]).children());
			$(blog_info[2]).remove();
			if(n==2){
				var w1 = "68%";
				var w2 = "28%";
			}else{
				var w1 = "28%";
				var w2 = "68%";
			}
			blog_info[0].style.width = w1;
			blog_info[1].style.width = w2;
		}
		if(n==4){
			appendChilds(blog_info[0],$(blog_info[1]).children());
			appendChilds(blog_info[0],$(blog_info[2]).children());
			$(blog_info[2]).remove();
			$(blog_info[1]).remove();
			blog_info[0].style.width = '97%';
		}
		if(n==5 || n==3){
			if(n==3){
				blog_info[0].style.width = "24%";
				blog_info[1].style.width = "46%";
				$e("blog_2").style.width = "24%";
			}else{
				blog_info[0].style.width = "31%";
				blog_info[1].style.width = "31%";
				blog_info[2].style.width = "31%";
			}
		}
		if(n==6){
			appendChilds(blog_info[1],$(blog_info[2]).children());
			$(blog_info[2]).remove();
			blog_info[0].style.width = "48%";
			blog_info[1].style.width = "48%";
		}
	}
	if(curStyle==4){
		if(n==1 || n==2){
			$('<div class="blog_info" id="blog_1"></div>').appendTo($('#blog_data'));
			if(n==2){
				var w1 = "68%";
				var w2 = "28%";
			}else{
				var w1 = "28%";
				var w2 = "68%";
			}
			blog_info[0].style.width = w1;
			$e("blog_1").style.width = w2;
		}
		if(n==3 || n==5){
			$('<div class="blog_info" id="blog_1"></div>').appendTo($('#blog_data'));
			$('<div class="blog_info" id="blog_2"></div>').appendTo($('#blog_data'));
			if(n==3){
				w1 = "24%";
				w2 = "46%";
				w3 = "24%";
			}else{
				w1 = '31%';
				w2 = '31%';
				w3 = '31%';
			}
			blog_info[0].style.width = w1;
			$e("blog_1").style.width = w2;
			$e("blog_2").style.width = w3;
		}
		if(n==6){
			$('<div class="blog_info" id="blog_1"></div>').appendTo($('#blog_data'));
			blog_info[0].style.width = "48%";
			$e('blog_1').style.width = "48%";
		}
	}
	if(curStyle==6){
		if(n==1 || n==2){
			if(n==2){
				var w1 = "68%";
				var w2 = "28%";
			}else{
				var w1 = "28%";
				var w2 = "68%";
			}
			blog_info[0].style.width =w1;
			blog_info[1].style.width = w2;
		}
		if(n==3 || n==5){
			if(n==3){
				w1 = "24%";
				w2 = "46%";
				w3 = "24%";
			}else{
				w1 = '31%';
				w2 = '31%';
				w3 = '31%';
			}
			$('<div class="blog_info" id="blog_2"></div>').appendTo($('#blog_data'));
			blog_info[0].style.width = w1;
			$e("blog_1").style.width = w2;
			$e("blog_2").style.width = w3;
		}
		if(n==4){
			appendChilds(blog_info[0],$(blog_info[1]).children());
			$(blog_info[1]).remove();
			blog_info[0].style.width = "97%";
		}
	}
	execDragDrog();
	serialize_my_style();
	var sPage_content = JSON.stringify(_blog_data);
	$('#set_frame').hide();
	$.get("blog/do_ajax.php?"+Math.random(),{'page_content':sPage_content,'act':'chg_page_content','username':ownName},function(){$('#loading').hide();refresh_module(45);});
}

function appendChilds(p,a){
	for(var i=0,l=a.length;i<l;i++){
		if(a[i].id.substr(0,2) != 'pk'){
			continue;
		}
		p.appendChild(a[i]);
	}
}

function init_blog_data(_blog_data_){	//**获得blog的首页JSON数据
	if(!_blog_data_[0]){
		$("#blog_data").html('<div class="blog_info" id="blog_0"></div><div class="blog_info" id="blog_1"></div>');
		return;
	}
	write_blog(_blog_data_);
}

function write_blog(json){	//**版式的格式化
	for(var i=0;i<json.length;i++){
		$('<div class="blog_info" id="blog_'+i+'"></div>').appendTo($('#blog_data'));
		$e("blog_"+i).style.width = json[i]['w'];
	}
	write_blog_data(json);
}
function execModAdminHideShow(){
	var oMod = $('div.mod');
	oMod.children().find('.modRfs,.modCls,.modShow').hide();
	oMod.hover(function(){$(this).children().find('.modRfs,.modCls,.modShow').show();},function(){$(this).children().find('.modRfs,.modCls,.modShow').hide();});
}
function write_blog_data(__blog_data__){	//**各模块的数据载入
	//alert(__blog_data__);
	while(_write_blog_j>=__blog_data__[_write_blog_i]['d'].length){
		_write_blog_i++;
		_write_blog_j=0;
		if(_write_blog_i>=__blog_data__.length){
			//setTimeout('refresh_module(21)',5000);
			ifIniting = 0;
			$('#loading').hide();
			if(ifAdmin>0)
				execDragDrog();
			execModAdminHideShow();
			return;
		}
	}
	$.get("blog_data.php?"+Math.random(),{'id':__blog_data__[_write_blog_i]['d'][_write_blog_j],'username':ownName},function(d){
		$e("blog_" + _write_blog_i).innerHTML += d ;
		try{init_mod_set();}catch(e){}
		if(__blog_data__[_write_blog_i]['d'][_write_blog_j]==43)	//**背景音乐模块
			start_bg_music();
		if(__blog_data__[_write_blog_i]['d'][_write_blog_j]==35){	//**全部留言，表情的添加
			oFace1 = new ReplyMenu({elementID:'guestbook_comment','retn':1,allowFace:8});
			$('#guestbook_comment_face').html(oFace1.draw());
		}
		if(__blog_data__[_write_blog_i]['d'][_write_blog_j]==6){	//**最新留言，表情的添加
			oFace2 = new ReplyMenu({elementID:'index_comment','retn':1,allowFace:5});
			$('#index_comment_face').html(oFace2.draw());
		}
		_write_blog_j++;
		write_blog_data(__blog_data__);
	});
}
function $e(e){
	return document.getElementById(e);	
}
function getElementsByClassName(clsName,htmltag){   
	var arr = new Array();   
	var elems = document.getElementsByTagName(htmltag);  
	for ( var cls, i = 0; ( elem = elems[i] ); i++ ){  
		if ( elem.className == clsName ){ //只能取到className完全相等的情况，为考虑有多个class的情况  
			arr[arr.length] = elem;  
		}
	}
	return arr;  
}

//**start导航
function chk_cur_nav(hash){	//**获得当前处在第几个导航，若有传递参数就用参数，若没传递参数就检查地址栏中的hash
	if(hash){
		location.hash = hash;
	}
	var sHash = location.hash.substr(1);
	for(var i=0,l=_main_nav.length;i<l;i++){
		if(_main_nav[i].hash==sHash)
			return i;
	}
	return 0;
}

//**改变导航中的图标
function chg_nav_ico(s){
	$('#set_ico a').removeAttr('style');
	$('#set_ico a[@title='+s+']').css('border','1px solid #f00');
	$('#loading').show();
	_main_nav[cur_nav_No].ico = s
	$('#set_frame').hide();
	$.get("blog/do_ajax.php?"+Math.random(),{'nav_data':JSON.stringify(_main_nav),'act':'chg_nav_name','username':ownName},function(){
		$.get("blog_data.php?"+Math.random(),{'act':'get_nav','cur_nav':cur_nav_No,'cur_hash':_main_nav[cur_nav_No].hash,'username':ownName},function(d){$('#m_main').html(d);$('#loading').hide();});
	});
}

function init_main_nav(){
	$.get("blog_data.php?"+Math.random(),{'act':'get_nav','cur_nav':cur_nav_No,'cur_hash':_main_nav[cur_nav_No].hash,'username':ownName},function(d){$('#m_main').html(d);});
	return;

	var s = '';
	for(var i=0,l=_main_nav_.length;i<l;i++){
		if(i==cur_nav_No){
			
			if(_main_nav_[i].hash=='nav_index'){
				s +='<li class="on" id="mainnav'+i+'"><div class="nav_l"><a href="javascript:void(0);">'+_main_nav_[i].name+'</a></div><div class="nav_r" style="display:block" id="down1"><div class="nav_d"><a href="javascript:void(0);" onclick="show($(\'#set_frame\'),this)"><img src="skin/default/images/down.gif" /></a></div></div></li>';

			}
			else if(_main_nav_[i].hash=='nav_blog' || _main_nav_[i].hash=='nav_photo' || _main_nav_[i].hash=='nav_music' || _main_nav_[i].hash=='nav_msg' || _main_nav_[i].hash=='nav_bbs' || _main_nav_[i].hash=='nav_friend'){
				s +='<li class="on" id="mainnav'+i+'"><div class="nav_l"><a href="javascript:void(0);">'+_main_nav_[i].name+'</a></div><div class="nav_r" style="display:block" id="down1"><div class="nav_c" style="position:relative; bottom:2px; display:block"><a href="javascript:void(0);" onclick="show_confirm(\'delete_nav('+i+')\',\'该页面的内容将被删除\');"><img src="skin/default/images/close.gif" /></a></div><div class="nav_d" onclick="show($(\'#set_frame\'),this)"><a href="javascript:void(0);"><img src="skin/default/images/down.gif" /></a></div></div></li>';

			}else{
				s +='<li class="on" id="mainnav'+i+'"><div class="nav_l"><a href="javascript:void(0);" onclick="edit_nav(this);">'+_main_nav_[i].name+'</a></div><div class="nav_r" style="display:block" id="down1"><div class="nav_c" style="position:relative; bottom:2px; display:block"><a href="javascript:void(0);" onclick="show_confirm(\'delete_nav('+i+')\',\'该页面的内容将被删除\');"><img src="skin/default/images/close.gif" /></a></div><div class="nav_d"><a href="javascript:void(0);" onclick="show($(\'#set_frame\'),this)"><img src="skin/default/images/down.gif" /></a></div></div></li>';

			}
		}else{
			s +='<li id="mainnav'+i+'"><div class="nav_l"><a href="javascript:void(0);" onclick="chg_nav_content(\''+_main_nav_[i].hash+'\')">'+_main_nav_[i].name+'</a></div></li>';

		}
	}
	$('#m_main').append(s);
}

function sleep(t,s){
	if(t) _sleep_t = t;
	if(_sleep_t<1){
		$('#m_main').html(s);
		return;
	}
	_sleep_t = _sleep_t-1;
	setTimeout("sleep(_sleep_t)",1000);
}

function add_nav(s){	//**增加导航
	
	if(_main_nav.length > 7){
		$('#add_s').hide();
		show_confirm("hide_confirm();","不能再增加了，调整下你的菜单内容是否合理！",0);
		return;
	}
	cur_nav_No = _main_nav.length;
	var num = false;
	if(s=='define'){	//**添加自定义的导航
		num = 6;
		var rand = [1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
		s = 'nav_';
		for(var i=0;i<8;i++){
			var rand_index = Math.round(Math.random()*35);
			s += rand[rand_index];
		}
		_main_nav[cur_nav_No] = {};
		_main_nav[cur_nav_No].hash = s;
		_main_nav[cur_nav_No].name = '新页面';
		_main_nav[cur_nav_No].ico = '';
	}else{	//**添加固有的
		for(var i=0,l=nav_data.length;i<l;i++){
			if(s==nav_data[i].hash){
				num = i;
				break;
			}
		}
		_main_nav[cur_nav_No] = nav_data[i];
	}

	var want_add_module = default_module[num];	//**改变blog数据的json

	var have_module = chk_module_menu();	//*已有的模块
	var tips = '';
	for(var i=0,l=have_module.length;i<l;i++){	//**所添加的模块是否已存在
		for(var j=0,jl=want_add_module.length;j<jl;j++){
			var tmp = want_add_module[j].d;
			for(var k=0,kl=tmp.length;k<kl;k++){
				if(have_module[i]==tmp[k]){
					tips += '['+module_name[i]+']，';
					tmp.splice(k,1);
				}
			}
			want_add_module[j].d = tmp;
		}
	}
	
	_blog_data[cur_nav_No] = want_add_module;
	$('#add_s').hide();
	$('#loading').show();
	if(tips != ''){
		tips = '你所增加的新页面中，模块：'+tips+'<br />在您其他页面中已经添加，它将不在新页面中显示。';
		show_confirm("save_add_nav()",tips,0,0);
		return;
	}
	save_add_nav();
}
function save_add_nav(){
	hide_confirm();
	var sNav_data = JSON.stringify(_main_nav);
	var sPage_content = JSON.stringify(_blog_data);
	$.get("blog/do_ajax.php?"+Math.random(),{'nav_data':sNav_data,'page_content':sPage_content,'act':'chg_nav_content','username':ownName},function(){chg_nav_content(_main_nav[cur_nav_No].hash);chk_nav_menu();});
	setTimeout(init_add_module_menu,500);
}

function delete_nav(id){
	$('#loading').show();
	_main_nav.splice(id,1);	//**在json中删除此页面的导航数据
	_blog_data.splice(id,1);	//**在json中删除此页面的内容数据
	cur_nav_No = cur_nav_No-1;	//**当前页面数减1
	
	//alert(JSON.stringify(_main_nav));
	$('#mainnav'+id).remove();
	var sNav_data = JSON.stringify(_main_nav);
	var sPage_content = JSON.stringify(_blog_data);
	$.get("blog/do_ajax.php?"+Math.random(),{'nav_data':sNav_data,'page_content':sPage_content,'act':'chg_nav_content','username':ownName},function(){chk_nav_menu();chg_nav_content(_main_nav[cur_nav_No].hash);});
	hide_confirm();
	setTimeout(init_add_module_menu,500);
}
function edit_nav(o){
	var cur_nav_tit = $(o).html();
	//var cur_nav_html = $(o).parent().html();
	var tmpRandom = Math.random();
	$(o).parent().html("<input type='text' id='"+tmpRandom+"' style='width:60px;' onblur='save_nav(this,\""+cur_nav_tit+"\")' value='"+cur_nav_tit+"' />");
	$e(tmpRandom).style.color = "#000";
	setTimeout("$e("+tmpRandom+").focus();",5);
}
function save_nav(oInput,old_tit,tmpRandom){	//**改变导航title后保存
	if(oInput.value==''){
		show_confirm("hide_confirm();","不能为空",0,0);
		return;
	}
	if(oInput.value==old_tit){
		$(oInput).parent().html('<a href="javascript:void(0);" onclick="edit_nav(this);return false;">'+old_tit+'</a>');
		return;
	}
	if(/(<|>|\'|\")/.test(oInput.value)){
		show_confirm("hide_confirm();","含有非法字符",0,0);
		return;
	}
	if(oInput.value.length>4){
		show_confirm("hide_confirm();","最多只能4个字！",0,0);
		return;
	}
	_main_nav[cur_nav_No].name = oInput.value;
	$(oInput).parent().html('<a href="javascript:void(0);" onclick="edit_nav(this);return false;">'+oInput.value+'</a>');
	var nav_data = JSON.stringify(_main_nav);
	
	$.get("blog/do_ajax.php?"+Math.random(),{'nav_data':nav_data,'cur_nav_no':cur_nav_No,'name':oInput.value,'act':'chg_nav_name','username':ownName},function(){});
}

function nav_json2string(json){	//**导航菜单中，把json转换为字符串型
	var retStr = "[";
	var str = [];
	for(var i=0,l=json.length;i<l;i++){
		str[i] = '{';
		for(var p in json[i]){
			if(str[i] == "{")
				str[i] += "'"+ p + "':'" + json[i][p] + "'"; 
			else
				str[i] += ",'"+ p + "':'" + json[i][p] + "'"; 
		}
		str[i] += '}';
	}
	for(var i=0,l=str.length;i<l;i++){
		if(i==0)
			retStr += str[i];
		else
			retStr += ','+str[i];
	}
	retStr += "]";
	return retStr;
}
//**end 导航

//**得到当前_blog_data中所有模块的id
function chk_module_menu(){
	var aModule = [];
	for(var i=0,il=_blog_data.length;i<il;i++){
		for(var j=0,lj=_blog_data[i].length;j<lj;j++){
			var arrD = _blog_data[i][j].d;
		
			for(var l=0,ll=arrD.length;l<ll;l++){
				aModule.push(arrD[l]);
				//alert(aModule[l]);
			}
		}
	}
	return aModule;
}

//**初始化增加模块菜单

function init_add_module_menu(){
	var menu = chk_module_menu();
	$('#add_m ul li a').each(function(){
		var thisId = $(this).attr('id');

		try{$('#'+thisId+' img[@tag]').remove();}catch(e){};
		$(this).unbind("click");
		if(mzsky.in_array(thisId.substr(1),menu)){
			var oImg = new Image();
			oImg.setAttribute('src','images/ico_tick_small.gif');
			oImg.setAttribute('tag','ico_tick');
			try{this.appendChild(oImg);}catch(e){}
			$(this).css({'filter':'alpha(opacity=80)','opacity':'0.8','color':'#888','background':'#eee','cursor':'default'});
		}else{
			$(this).click(function(){addModule(thisId.substr(1),thisId);return false;});
			$(this).css({'filter':'alpha(opacity=100)','opacity':'1','color':'#000','background':'#fff','cursor':'pointer'});
		}
	});

	return ;

}

function chk_nav_menu(){	//**检测增加导航页面菜单，若存在就不可再选
	$('#add_s ul li a').each(function(j){
		$(this).unbind("click");
		if($(this).attr('tag')=='define') return;
		var arr = [];
		for(var i=0,l=_main_nav.length;i<l;i++){
			arr[i] = _main_nav[i].hash;
		}
		
		if(mzsky.in_array($(this).attr('tag'),arr)){
			$(this).unbind("click");
			//$(this).removeAttr("class");

			$(this).css({'filter':'alpha(opacity=80)','opacity':'0.8','color':'#888','background':'#eee','cursor':'default'});
		}else{
			//$(this).attr({'class':'a_off'});
			$(this).css({'filter':'alpha(opacity=100)','opacity':'1','color':'#000','background':'#fff','cursor':'pointer'});
			$(this).click(function(){add_nav($(this).attr('tag'));return false;});
		}
	});
}

function chg_nav_content(hash){
	if(ifIniting == 1) return;	//**当页面载入时，不能改变页面的导航
	ifIniting = 1;
	$('#loading').show();
	$('#set_frame').hide();
	stop_bg_music();	//**音乐模块，停止音乐播放
	$('#blog_data').children().remove();
	_write_blog_i = 0;
	_write_blog_j = 0;
	cur_nav_No = chk_cur_nav(hash);	//**获得当前导航或内容的下标
	//alert(cur_nav_No);	
	//	del2008();
	//alert(_blog_data);
	init_blog_data(_blog_data[cur_nav_No]);	//**获得当前页面的内容
	init_main_nav();	//**初始话导航
}

//**刷新具体的模块
function refresh_module(id){
	$('#pc'+id).html("数据加载中...");

	$.get("/defaultdata.php?"+Math.random(),{'id':id,'username':ownName,'act':'refresh_module'},function(d){
		if(d){
			$("#pc"+id).html(d);
		}else{
			$("#pc"+id).html('加载完毕，数据为空！');
		}
		try{childWindow.close();}catch(e){}
	});
}


	


//**从url中提取username
function getUserName(){
	var reg = /.+\/([a-z0-9_]+)\/*$/i;
	var arr = reg.exec(location.href);
	return arr[1];
}

//**删除日记
function index_del_mod_diary(id,t){
	var pre = '';
	if(t==1){	//**blog中删日记
		pre = '../';
	}
	$.get(pre+"blog/do_ajax.php?"+Math.random(),{'act':'delete_diary','username':ownName,'id':id},function(d){
		if(d=='true'){
			try{$('#index_mod_diary_li'+id).remove();}catch(e){}
			alert('删除成功！');
		}else
			alert('删除失败！');
	});
	hide_confirm();
}
//**删除博客文章
function del_blog_entry(id){
	hide_confirm();
	$.get("blog/do_ajax.php?"+Math.random(),{'act':'delete_entry','username':ownName,'id':id},function(d){
			 refresh_module(31)
	});
    
}


//**某一标签博客
function ch_blog_tag(){
	$('#aaa').hide();
    $('#cancelset').hide();
    $('#set_blog').show();
   if($('#tag_subject').val()=='' || $('#blogstag').val()==''){
		return;
	}
	$('#tag_blog').html($('#tag_subject').val().replace(/</,'&lt;').replace(/>/,'&gt;'));
	$.get("blog/do_ajax.php?"+Math.random(),{'act':'chg_blog_tag','title':$('#tag_subject').val(),'username':ownName,'tag':$('#blogstag').val(),'type':'tag_logs'},function(){
		   refresh_module(22)
	});
}

//**博客标签
function ch_tag_sort(){
	$('#bbb').hide();
    $('#cancelsortset').hide();
    $('#set_blogsort').show();
    if($('#tagsort').val()==''){
		return;
	}
	$.get("blog/do_ajax.php?"+Math.random(),{'act':'ch_tag_sort','sort':$('#tagsort').val(),'username':ownName,'type':'tag_sort'},function(){
		   refresh_module(27)
		
	});
}

//**时钟设置
function ch_clock(v){
	$('#clo_detail').hide();
    $('#cancelclockset').hide();
    $('#set_clock').show();
	if(v==''){
		return;}
	$.get("blog/do_ajax.php?"+Math.random(),{'act':'ch_clock_style','style':v,'username':ownName,'type':'clock_style'},function(d){
		$('#pc29').html(d);
	});
}
//显示备选时钟
function show_clock(o){
    show($('#clo_detail'),o,2);
	$('#clo_detail').html("loading...");
    $.get('blog/do_ajax.php?'+Math.random(),{'username':ownName,'act':'show_clo'},function(d){$('#clo_detail').html(d);});
}

//判断URL是否正确
function chk_url(url,divid){
	var urlreg = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/i;
	if (!urlreg.test(url)){
		alert("无效的链接地址！");
		divid.focus();
		return false;
	}
}
//新增 友情链接
function add_connect(){
   
   if ($('#co_name').val()=='' || $('#co_des').val()=='' || $('#co_url').val()=='')
   { return;}
   var urlreg = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/i;
   if (!urlreg.test($('#co_url').val())){
		alert("无效的链接地址！");
		$('#co_url').focus();
		return;
	}
	
   $.get("blog/do_ajax.php?"+Math.random(),{'act':'add_connect','username':ownName,'type':'connect','name':$('#co_name').val(),'des':$('#co_des').val(),'url':$('#co_url').val()},function(){
 $('#co_name').val('');
	$('#co_des').val('');
	$('#co_url').val('http://');
 $('#cancelsortset').hide();  
    $('#set_add_co').show();
    $('#ddd').hide();
    refresh_module(30)
   
	});
}

//删除 链接
function delete_co(id){
	$.get("blog/do_ajax.php?"+Math.random(),{'id':id,'username':ownName,'act':'del_co'},function(d){
		if(d=='false')
			return;
		$('#co'+id).hide();
		hide_confirm();
	});
}


//显示 修改 框
function show_co(id,o){
    $('#edit_co_id').val(id);
    show($('#ch_co_set'),o,2);

	$('#ch_co_name').val($('#con_name'+id).html());
	$('#ch_co_des').val($('#con_des'+id).html());
	$('#ch_co_url').val($('#con_url'+id).val());
 }

 //clear co
 function clear_co(){
     $('#ch_co_name').val('');
	 $('#ch_co_des').val('');
	 $('#ch_co_url').val('');
 }

//提交 修改 链接
function ch_co(){
   if ($('#ch_co_name').val()=='' || $('#ch_co_des').val()=='' || $('#ch_co_url').val()=='')
       return;  
   var urlreg = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/i;
   if (!urlreg.test($('#ch_co_url').val())){
		alert("无效的链接地址！");
		$('#ch_co_url').focus();
		return;
	}
  $.get("blog/do_ajax.php?"+Math.random(),{'act':'edit_connect','username':ownName,'type':'connect','name':$('#ch_co_name').val(),'des':$('#ch_co_des').val(),'url':$('#ch_co_url').val(),'id':$('#edit_co_id').val()},function(d){
		$('#co'+$('#edit_co_id').val()).html(d);
	});
	$('#ch_co_set').hide();
	clear_co();
}

//**博客分类
function ch_blog_setting_sort(){
	$('#eee').hide();
    $('#cancelblogsortset').hide();
    $('#set_blog_sort').show();
    if($('#setting_sort').val()==''){
		return;
	}
	$.get("blog/do_ajax.php?"+Math.random(),{'act':'ch_blog_setting_sort','sort':$('#setting_sort').val(),'username':ownName,'type':'blog_sort'},function(){
		   refresh_module(32)
		
	});
}

//**显示博客标签 文章列表
function show_blog_tag_list(tagid,o){
	show($('#show_blog_tag_list'),o,2);
    $('#show_blog_tag_list').html('loading...');
	 $.get("blog/blog_guest_do.php?"+Math.random(),{'act':'show_blog_tag_list','tagid':tagid,'username':ownName},function(d){
		$('#show_blog_tag_list').html(d);
	});
    

}

//**自写文本
function set_write_text(){
	$('#write_set_area').html('<div>标题：<input type="text" class="login_input" value="'+$('#pk44 .modTitle').html().replace(/\"/g,'&quot;')+'" id="write_tit_setting" /></div><div><div style="float:left;line-height:20px;height:20px;">背景：</div><div class="color_slt" style="background-color: white; filter:alpha(opacity=0);border:1px solid #000;" title="透明">&nbsp;</div><div class="color_slt" style="background-color:#fff" title="#fff">&nbsp;</div><div class="color_slt" style="background-color:lightyellow" title="lightyellow">&nbsp;</div><div class="color_slt" style="background-color:#eeffe0" title="#eeffe0">&nbsp;</div><div class="color_slt" style="background-color:#ffe0e1" title="#ffe0e1">&nbsp;</div><div class="color_slt" style="background-color:#e0e0ff" title="#e0e0ff">&nbsp;</div><div class="color_slt" style="background-color:#fee8bd" title="#fee8bd">&nbsp;</div></div><input type="button" class="button" value="保存" onclick="set_write_text_save();" /><input type="hidden" id="write_text_color" />');
	$('#write_set_area .color_slt').click(function(){
		if(this.title=='透明'){
			$('#write_mood').css({'background':'transparent'});
			$('#write_text_color').val('opacity');
		}else{
			$('#write_mood').css('background',this.title);
			$('#write_text_color').val('background-color:'+this.title);
		}
	});
}
function set_write_text_save(){
	if($('#write_tit_setting').val()=='') return false;
	if($('#write_tit_setting').val().length>10){
		alert('数字过多！');return false;
	}
	$('#pk44 .modTitle').html($('#write_tit_setting').val());
		$.get("blog/do_ajax.php?"+Math.random(),{'act':'write_text','tit':$('#write_tit_setting').val(),'username':ownName,'set':$('#write_text_color').val()});
	$('#write_set_area').html('<a href="javascript:void(0);" onclick="set_write_text();return false;">设置</a>');
}
function write_text_over(){
	$('#write_mood').css('border','1px solid #f00');
}
function write_text_out(){
	if($('#write_mood').attr('tag') != 1){
		$('#write_mood').css('border','0');
	}
}
function write_text_focus(){
	$('#write_mood').attr('tag',1);
	$('#write_mood').css('border-color','#f00');
}
function write_text_blur(){
	$.post("blog/do_ajax.php?username="+ownName,{'act':'write_mood','story':$('#write_mood').html()});
	$('#write_mood').html();
	$('#write_mood').removeAttr('tag');
	$('#write_mood').css('border','0');
}


//休闲小游戏
function ch_blog_flash(){
	$('#flashbox').hide();
    $('#cancel_flash_set').hide();
    $('#set_flash').show();
    if($('#flashset').val()==''){
		return;
	}
	$.get("blog/do_ajax.php?"+Math.random(),{'act':'ch_blog_flash','id':$('#flashset').val(),'username':ownName},function(){
		   refresh_module(45)
		
	});
}

function playflash(){
	var gameurl=$('#gameurl').val();
	var gamename=$('#gamename').val();var gameskin=$('#gameskin').val();
	$('#pc45').html('<div style="text-align: center;"><a href="javascript:void(0)"  onclick="endflash()">不玩了，休息一下～</a></div><div style="height: '+gameskin+'px;"><object width="100%" height="100%" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="http://game.mzsky.cc/upload/'+gameurl+'" name="movie"/><param value="high" name="quality"/><embed width="100%" height="100%" swliveconnect="true" pluginspage="http://game.mzsky.cc/upload/'+gameurl+'" type="application/x-shockwave-flash" quality="high" src="http://game.mzsky.cc/upload/'+gameurl+'"/></object></div><input type="hidden" id="gamename" value="'+gamename+'"/><input type="hidden" id="gameurl" value="'+gameurl+'"/><input type="hidden" id="gameskin" value="'+gameskin+'"/>');
}

function endflash(){
	var gameurl=$('#gameurl').val();
	var gamename=$('#gamename').val();var gameskin=$('#gameskin').val();
	$('#pc45').html('<div style="text-align: center;"><div><a href="javascript:void(0);" onclick="playflash()">点击这里开始玩“'+gamename+'”</a><a target="_blank" href="http://game.mzsky.cc/upload/'+gameurl+'"><img align="absbottom" alt="在弹出窗口玩" src="skin/default/images/ico_game.gif"/></a></div><div class="more"><a target="_blank" href="http://game.mzsky.cc">去小游戏频道</a></div></div><input type="hidden" id="gamename" value="'+gamename+'"/><input type="hidden" id="gameurl" value="'+gameurl+'"/><input type="hidden" id="gameskin" value="'+gameskin+'"/>');
}
//end flash games

function my2008_entry_join(id,oSelf){
	//show_confirm('hide_confirm();','“我的2008”博客大赛即将开通！',0,0);
	//return false;
	$.get("blog/do_ajax.php?"+Math.random(),{'act':'my2008_entry_join','id':id,'username':ownName},function(d){
		if(d=='ok'){
			show_confirm('hide_confirm();','感谢你参加我的2008博文大赛！',0,0);
			$(oSelf).remove();
		}else if(d=='no')
			show_confirm('hide_confirm();','参赛失败！',0,0);
		else if(d=='no_join')
			show_confirm('hide_confirm();','你还未报名我的2008博客大赛，<br />请先去<a href="http://my2008.mzsky.cc/join.php" target="_blank">报名</a>吧！',0,0);
		else
			show_confirm('hide_confirm();','参赛失败！你是否已登陆！',0,0);
	});
}

function my2008_entry_unjoin(id,oSelf){
	//show_confirm('hide_confirm();','“我的2008”博客大赛即将开通！',0,0);
	//return false;
	$.get("blog/do_ajax.php?"+Math.random(),{'act':'my2008_entry_unjoin','id':id,'username':ownName},function(d){
		if(d=='ok'){
			show_confirm('hide_confirm();','对自己没信心么？加油吧！<br />有信心不一定能赢，但没信心就一定会输！',0,0);
			$(oSelf).remove();
		}else if(d=='no')
			show_confirm('hide_confirm();','参赛失败！',0,0);
		else if(d=='no_join')
			show_confirm('hide_confirm();','你还未报名我的2008博客大赛，<br />请先去<a href="http://my2008.mzsky.cc/join.php" target="_blank">报名</a>吧！',0,0);
		else
			show_confirm('hide_confirm();','参赛失败！你是否已登陆！',0,0);
	});
}

function my2008_vote_bloger(id){
	//show_confirm('hide_confirm();','“我的2008”博客大赛即将开通！',0,0);
	//return false;
	$.get("blog/do_ajax.php?"+Math.random(),{'act':'vote_bloger','id':id,'username':ownName},function(d){
		if(d=='ok'){
			refresh_module(46);
			show_confirm('hide_confirm();','谢谢你的投票！<br />已扣除你10银币！',0,0);
		}else if(d=='no')
			show_confirm('hide_confirm();','投票失败！',0,0);
		else if(d=='no_join')
			show_confirm('hide_confirm();','投票失败，博主还没报名博客大赛',0,0);
		else if(d=='no_enough_silver')
			show_confirm('hide_confirm();','投票失败，你的银币不够支付此次投票，去论坛发帖快速赚银币吧',0,0);
		else if(d=='owner_self')
            show_confirm('hide_confirm();','博主不能给自己投票！去论坛拉票或者让朋友来给你投票吧',0,0);
		else if(d=='too_quick')
            show_confirm('hide_confirm();','半小时内只能投一票，请稍后再投！',0,0);
		else if(d=='no_out_vote')
            show_confirm('hide_confirm();','每天只能给一个人投10票，明天再来继续支持博主吧！',0,0);
		else
			show_confirm('hide_confirm();','投票失败！你是否已登陆！',0,0);
	});
}

//星座每日运程
function ch_blog_star(){
	$('#starbox').hide();
    $('#cancel_star_set').hide();
    $('#set_star').show();
    if($('#starset').val()==''){
		return;
	}
	$.get("blog/do_ajax.php?"+Math.random(),{'act':'ch_blog_star','id':$('#blogstar').val(),'username':ownName},function(){
		   refresh_module(47)
		
	});
}


//新增自写文本
function turn_textarea(str){//将textarea中的字符串以正确方式显示（包括回车，换行，空格）
	while(str.indexOf("\n")!=-1){
		str = str.substring(0,str.indexOf("\n"))+"<BR>"+str.substring(str.indexOf("\n")+1);
	}
	while(str.indexOf(" ")!=-1){
		str = str.substring(0,str.indexOf(" "))+"&nbsp;"+str.substring(str.indexOf(" ")+1);
	}
	return str;
}

function show_textarea(id){
	var str=$('#note_show'+id).html();

	var reg=new RegExp("<BR>","g");
	str= str.replace(reg,"\n");

	var reg2= new RegExp("&nbsp;","g");
	str= str.replace(reg2," ");

	var reg3=new RegExp("<br>","g");
	str= str.replace(reg3,"\n");

	$('#note_text'+id).val(str);
}




function note_chg_color(id,type){//背景色预览
	var color='';
	switch(type){
		case 2:color='rgb(255, 255, 255)';break;
		case 3:color='lightyellow';break;
		case 4:color='rgb(238, 255, 224)';break;
		case 5:color='rgb(255, 224, 225)';break;
		case 6:color='rgb(224, 224, 255)';break;
		case 7:color='rgb(254, 232, 189)';break;
		case 1:
		default:
			color='transparent';break;
	}
	$('#note_text_color_'+id).val(color);
	$('#textnotecontainer'+id).css({'background-color':color});
}

function note_on_focus(id){
	$('#pc'+id).css({'border':'1px solid red','padding':'4px','background-color':'transparent','cursor':'text'});
}

function note_out_focus(id){
	$('#pc'+id).css({'border':'medium none','padding':'5px','background-color':'transparent','cursor':'default'});
}

function note_on_click(id){
	show_textarea(id);
		$('#note_show'+id).hide();
		$('#note_divtext'+id).show();
		$('#note_text'+id).focus();
}

function note_text_blur(id){//保存文本内容
	var newstr1=$('#note_text'+id).val(); 
	var oldstr=$('#note_show'+id).html(); 

	var newstr=turn_textarea(newstr1);
//	if(oldstr==temp_new){

	if(oldstr==newstr){
			$('#note_show'+id).show();
			$('#note_divtext'+id).hide();
			note_out_focus(id);
			return;
	}
	else{
			$.post("blog/do_ajax.php?"+Math.random()+'&username='+ownName,{'act':'ch_notetext','id':id,'content':newstr},function(){
						$('#note_show'+id).html(newstr);
						$('#note_divtext'+id).hide();
						$('#note_show'+id).show();						
						 note_out_focus(id);
			});
	}
}

function note_chg_tit_setting(id){//保存标题和颜色
	var newstr=$('#note_text_title_'+id).val();
	var oldstr=$('#note_show_title_'+id).html();
	var color =$('#note_text_color_'+id).val();


	if(newstr==oldstr && color=='0'){//color=0 表示不更改颜色
		$('#setting'+id).hide();
		$('#cancel_setting'+id).hide();
		$('#set_setting'+id).show();
		return;
	}
	else{
			$.post("blog/do_ajax.php?"+Math.random()+'&username='+ownName,{'act':'ch_notetext','id':id,'title':newstr,'color':color},function(){	
						$('#note_show_title_'+id).html(newstr);
						$('#note_text_color_'+id).val('0');
						$('#setting'+id).hide();
						$('#cancel_setting'+id).hide();
						$('#set_setting'+id).show();
			});
	}
}

