profile.myspace = {};
profile.myspace.album_edit = function(aid){
    ST.UI.ModeWindow({'ID':'ALBUMZ-EDIT','TitleText':'修改相册信息','submitcall':function(){
        name=$('#album_name_'+aid).val(),
        desc=$('#desc_'+aid).val();        
        $.AjPost('blog_photo_modAlbumDesc',{'albumid':aid,'albumDesc':desc,'albumName':name},function(rdata){
            $('#span_desc_' + aid).text(desc);            
			$('#input_albumName_' + aid).val(name);
            $('#album_txt_name_' + aid).text(name);
        })
    }}).setContent('<div class="textl"><p style="margin-bottom:6px;"><span class="fl textr" style=" width:50px;padding-right:4px;">名称</span><input type="text" class="border1" value="'+$('#input_albumName_'+aid).val()+'" id="album_name_'+aid+'"></p><span class="fl textr" style=" width:50px;padding-right:4px;">描述</span><textarea rows="3" class="border1" style="width:152px;" id="desc_'+aid+'">'+$('#span_desc_'+aid).html()+'</textarea></div>')
	
};

profile.myspace.album_del=function(id){
	//ST.UI.showMessage('确认操作', 'sure:确定删除此专辑吗?:profile.myspace.dodelAlbum:' + id);
    ST.UI.ModeWindow({'ID':'ID_ALB','TitleText':'确认?','submitcall':function(){profile.myspace.dodelAlbum(id)}}).setContent('确定删除此专辑吗');
}

//删除专辑
profile.myspace.dodelAlbum=function(id) {
	$.ajax( {
		type : 'POST',
		url : '/',
		data : '_do=profile-blog_photo_delAlbum&albumid=' + id,
		success : function(msg) {
			$("#album_"+id).remove();
		}
	});
}


profile.myspace.checkname = function(){
	if($.trim($("#name").val())==''){
		$("#name_tip_err").show();
		$("#name_tip_succ").hide();
	}else{
		$("#name_tip_err").hide();
		$("#name_tip_succ").show();
	}	
}

profile.myspace.saveUserinfo = function(){
		
		var provinceid =  $("#province").val();
    	var cityid = $("#city").val();
    	var countryid = $("#country").val();
        usercity = '('+provinceid+')'+','+'('+cityid+')'+','+'('+countryid+')';
        // 姓名
        var name=$.trim($("#name").val());
        var sex=$(":input[name='sex']:checked").val();
        var domain = $("#domain").val();
        var b_year = $("#b_year").val();
    	var b_month = $("#b_month").val();
    	var b_day = $("#b_day").val();
    	var qq = $("#qq").val();
    	var msn = $("#msn").val();
    	var mobile = $("#mobile").val();
    	if ( parseInt(provinceid,10) == 0  )
    	{
    		ST.UI.showMessage('生日错误','请选择正确的省');
    		return false ;
    	}
    	if ( parseInt(cityid,10) == 0  )
    	{
    		ST.UI.showMessage('生日错误','请选择正确的市区');
    		return false ;
    	}
    	
    	if ( parseInt(b_year,10) == 0  )
    	{
    		ST.UI.showMessage('生日错误','请选择正确的年');
    		return false ;
    	}
    	if ( parseInt(b_month,10) == 0  )
    	{
    		ST.UI.showMessage('生日错误','请选择正确的月');
    		return false ;
    	}
    	if ( parseInt(b_day,10) == 0  )
    	{
    		ST.UI.showMessage('生日错误','请选择正确的日');
    		return false ;
    	}
    	
        var birthday = b_year+'-'+b_month+'-'+b_day ;
       
        var intro=$("#intro").val();
        if(name==""){
            $("#name_tip_err").show();
			$("#name_tip_succ").hide();
			ST.UI.showMessage("错误","请输入姓名");
            $("#name").focus() ;
            return false;
        }
        var len = name.reallength();

    	if( len<4||len>12 ){
            ST.UI.showMessage('错误提示:','姓名长度为4~12个字符');
            $("#name").focus() ;
            return false;
    	}
    	       
        domain = $.trim(domain);
        $.post('?_do=profile-saveUserinfo',{'name':name,'domain':domain,'gender':sex,'birthday':birthday,'intro':intro,'city_id':usercity,'qq':qq,'msn':msn,'mobile':mobile},
        	function(data){
	        	eval('var r='+data+';');
	            if(r['err']){
	                //ST.UI.showMessage('操作失败',''+r['msg'],400,150);
                    ST.UI.showMessage('提示',r['msg'])
	                return false;
	            }else{
	                ST.UI.showMessage('操作成功',r['msg']);
	         	}  
        });
}

profile.myspace.setpass = function(){
    var oldpass=$('#oldpass').val(),
        newpass1=$("#newpass1").val(),
        newpass2=$("#newpass2").val()
	if(oldpass==''){
		 ST.UI.showMessage('错误:','旧密码不能为空');
         $("#oldpass").focus() ;
         return false;
	}
	if(newpass1==''){
		 ST.UI.showMessage('错误:','新密码不能为空');
         $("#newpass1").focus() ;
         return false;
	}
	if(newpass2==''){
		 ST.UI.showMessage('错误:','确认密码不能为空');
         $("#newpass2").focus() ;
         return false;
	}
	if(newpass1!=newpass2){
		 ST.UI.showMessage('错误:','新密码与确认密码不相同,请重新输入');
         $("#newpass2").focus() ;
         return false;
	}
	$.AjPost('blog_my_actionSavePass',{'oldpass':oldpass,'newpass1':newpass1,'newpass2':newpass2},function(rdata){
	        eval('var rdata='+rdata+';');
            ST.UI.showMessage('提示:',rdata['msg'],2000);
	})
};

profile.myspace.saveTheme = function()
{
  var  theme =$(":input[name='theme']:checked").val(); 
  $.ajax({
      type:'POST',
      url:'?_do=my-actionUserModel&ajax=1',
      data:'themes='+theme,
      success:function (data)
      {
            eval('var r='+data+';');
            if(r['err'])
            {
                ST.UI.showMessage('操作失败',''+r['msg']);
            }else
            {
                ST.UI.showMessage('操作成功',''+r['msg']);
                window.location.href= r['domain']!= undefined ? r['domain'] : '/?_do=my-index-uid-'+r['uid']+'.shtml';
            }
      }
  });
}


profile.myspace.saveAvatar = function(){
	$("#do").val("profile-blog_my_saveAvatar");
	
	if ( checkCoords() ) {
	
		//$('#uploadForm').submit();
		var data = {};
		data.imgPath = $('#imgPath').val();
		data.nx = $('#nx').val();
		data.ny = $('#ny').val();
		data.nw = $('#nw').val();
		data.nh = $('#nh').val();
		$.ajax({
			url:'index.php?_do=profile-blog_my_saveAvatar',
			dataType:'json',
			type:'post',
			data:data,
			success:function(res){
				if(res.succ==1){
					ST.UI.showMessage('提示','操作成功');
                    $('.jcrop-holder').hide();
                    $('#submitDiv').hide();
                    $('img[node-type="avatar"]').attr('src',res.face_name)
				}else{
					ST.UI.showMessage('操作失败',''+res.desc);
				}
			}
		});		
	}
}

profile.myspace.saveCover = function(){
	$("#do").val("profile-blog_my_saveCover");
	//$('#uploadForm').submit();
	var data = {};
	data.imgPath = $('#imgPath').val();
	data.nx = $('#nx').val();
	data.ny = $('#ny').val();
	data.nw = $('#nw').val();
	data.nh = $('#nh').val();
	$.ajax({
		url:'index.php?_do=profile-blog_my_saveCover',
		dataType:'json',
		type:'post',
		data:data,
		success:function(res){
			if(res.succ==1){
				ST.UI.showMessage('提示','操作成功');
			}else{
				ST.UI.showMessage('操作失败',''+res.desc);
			}
		}
	});		
}



//删除照片
profile.myspace.delPhoto = function(id) {
//	ST.UI.showMessage('确认操作', 'sure:确定删除此照片吗?:profile.myspace.doDelPhoto:' + id);
	ST.UI.ModeWindow({'ID':'ID_ALB','TitleText':'确认','submitcall':function(){profile.myspace.doDelPhoto(id);}}).setContent('确定删除此照片吗?')
}
// 删除照片 操作
profile.myspace.doDelPhoto = function(id){
	$.post('?_do=profile-blog_photo_delPhoto' , {photoid:id}, function(msg) {
		eval('var r=' + msg + ';');
		if (r['succ'] == 1) {
			$("#js_remove_photo_" + id).remove();
		} else {
			ST.UI.showMessage('提示：', '删除失败,请重试！');
		}
	});
}


//编辑相片
profile.myspace.editPhoto = function(id) {
    
	$("#js_isEdit_" + id).toggle();
	$("#js_edit_photo_button_" + id).hide();
	$("#js_albumNameOutDesc_" + id).hide();
	$("#js_albumNameOutput_" + id).hide();
	$("#js_hidden_photo_operate_" + id).hide();
}

// 关闭编辑
profile.myspace.cancelEditPhoto = function(id) {
	$("#js_isEdit_" + id).hide();
	$("#js_edit_photo_button_" + id).show();
	$("#js_albumNameOutDesc_" + id).show();
	$("#js_albumNameOutput_" + id).show();
	$("#js_hidden_photo_operate_" + id).show();

}

// 保存相片编辑
profile.myspace.modEidt = function(id) {
	var title = $("#js_albumNameInput_" + id).val();
	
	if ($.trim(title) == '') {
		alert('请输入相片标题！');
		$("#js_albumNameInput_" + id).focus();
		return false;
	}else if (title.length > 11) {
		alert('您输入的标题的长度不能大于11个字符！');
		$("#js_albumNameInput_" + id).focus();
		return false;
	} 
	
	
	$.post('?_do=profile-blog_photo_modPhotoDesc', {'photoid' : id,'photoTitle' : title }, function(msg) {
	   
		eval('var r=' + msg + ';');
		if (r['succ'] == 1) {
			$("#js_isEdit_" + id).hide();
			$("#js_edit_photo_button_" + id).show();
			$("#js_albumNameOutDesc_" + id).show();
			$("#js_albumNameOutput_" + id).show();
			$("#photo-name-" + id).html(title);
			$("#js_albumNameOutDesc_" + id).html(desc);
			ClassPhoto.cancelEditPhoto(id);
		} else {
			ClassPhoto.cancelEditPhoto(id);
			// ST.UI.showMessage('提示：','图片编辑失败！');
		}
	});
}

// 推荐相片
profile.myspace.photoIndex = function(id) {
	var isIndex = $("#js_isIndex_photo_" + id).attr("checked");
	var setIndex = isIndex ? 1 : 0;
	var desc = isIndex ? "相册首页显示" : "取消相册首页显示";
	$.ajax( {
		type : 'POST',
		url : '/',
		data : '_do=profile-blog_photo_digPhoto&photoid=' + id+'&d='+setIndex+ "&rand=" + Math.random(),
		success : function(msg) {
			eval("var r = " + msg + ";");
			try {
				if (r['succ'] == 1) {
					$("#isIndex" + id).attr("checked", isIndex);
					if (isIndex) {
						$("#js_isIndex_photo_" + id).next('span').html(
								'已在首页展示');
					} else {
						$("#js_isIndex_photo_" + id).next('span').html(
								'首页展示');
					}
				} else {
					ST.UI.showMessage("错误", "<div class='tc textc'>" + desc
							+ '失败,重试!</div>');
				}
			} catch (ex) {
				alert(ex);
				return false;
			}
		}
	});
}


//设置相册封面  o 对象   aid 专辑的ID
profile.myspace.setCover = function(o,aid) {
	$.post('?_do=profile-blog_photo_setAlbumFace',{photoid:$(o).val(),albumid:aid},function(){
		
	});
	
}

//学校的园长信箱相关js
/**
*公示，取消公示信件
*/
profile.myspace.showSchoolMsg = function(id,val){
	 if(val==0){
	 	tip = '取消公示的信件将使信件不再显示到校园网站的“园长信箱”页面内，确定吗？';
	 }else{
	 	tip = '公示信件将显示到校园网站的“园长信箱”页面内，并且该信件将无法回复，确定吗？';
	 }
	 ST.UI.ModeWindow({'ID':'ID_ALB',width:500,'TitleText':'确认','submitcall':function(){
		$.ajax( {
			type : 'POST',
			url : '/interface/message.php',
			data : '_do=school_msg&act=showSchoolMsg&msgid=' + id+"&val="+val+'&random='+Math.random() ,
			dataType : 'json',
			success : function(res) {
				 if(res.succ==1){
				 	var a = '<a href="javascript:void(0);"  class="ac009" onclick="profile.myspace.showSchoolMsg('+id+',0);return false;">取消公示</a>';
				 	var desc = '<div algin="center">信件已经公示到<a href="'+res.data.school_link+'">'+res.data.name+'</a>,点击查看<a href="'+res.data.school_link+'/index.php?_do=msg-index-en-msg.shtml">该校已公示的信件</a></div>';
				 	if(val==0){//取消公示
				 		
		                a = '<a href="javascript:void(0);"  class="ac009" onclick="profile.myspace.showSchoolMsg('+id+',1);return false;">公示</a>&nbsp;';
		                //a += '<a href="javascript:;" class="ac009" title="回复" onclick="replySchoolMsg('+id+',1);return false;">回复</a>';
		                desc = '<div algin="center">取消公示成功</div>';
		            }else{
		            	$("#replySchoolMsg_"+id).hide();
		            }
		            $("#a_showSchoolMsg_"+id).html(a);
		            //$("#jsTip").html(desc);
		           // var len = realLength(delHtmlTag(desc));
		         }else{
		         	 desc = res.desc == undefined ? '对不起，系统忙' : res.desc;
		             //alert(desc);
		         }
		         leftMenu.goToUrl(document.getElementById('current_url'));
		         ST.UI.ModeWindow({'ID':'ID_ALB',width:500,'TitleText':'确认','submitcall':function(){}}).setContent(desc);
		         
			}
		});
	 }}).setContent(tip);
}
//删除学校园长信箱 对话
profile.myspace.deleteSchoolMsg = function(id,val){
	tip = '确认要删除吗？';
	ST.UI.ModeWindow({'ID':'ID_ALB','TitleText':'确认','submitcall':function(){
		$.ajax( {
			type : 'POST',
			url : '/interface/message.php',
			data : '_do=school_msg&act=deleteSchoolMsg&msgid=' + id+"&val="+val+'&random='+Math.random() ,
			dataType : 'json',
			success : function(res) {
				 if(res.succ==1){
				  // $("#message_"+id).remove();
				 	leftMenu.goToUrl(document.getElementById('current_url'));
		         }else{
		         	 desc = res.desc == undefined ? '对不起，系统出错啦' : res.desc;
		             alert(desc);
		         }
			}
		});
	}
	}).setContent(tip);
}

//删除学校园长信箱 回复
profile.myspace.deleteSchoolMsgReply = function(id,val){
	tip = '确认要删除吗？';
	ST.UI.ModeWindow({'ID':'ID_ALB','TitleText':'确认','submitcall':function(){
		$.ajax( {
			type : 'POST',
			url : '/interface/message.php',
			data : '_do=school_msg&act=deleteSchoolMsgReply&msgid=' + id+"&val="+val+'&random='+Math.random() ,
			dataType : 'json',
			success : function(res) {
				 if(res.succ==1){
				 	//$("#message_reply_"+id).remove();
				 	leftMenu.goToUrl(document.getElementById('current_url'));
				 	//ST.UI.showMessage('提示','删除成功',2000);
		         }else{
		         	 desc = res.desc == undefined ? '对不起，系统出错啦' : res.desc;
		             alert(desc);
		         }
			}
		});
	}
	}).setContent(tip);
	
}

//回复园长信箱的内容
profile.myspace.replySchoolMsg = function(id,val){
	if(val==1){
		$("#replySchoolMsg_"+id).show();
	}else{
		$("#replySchoolMsg_"+id).hide();
	}
}

//保存回复内容
profile.myspace.saveReplyContent = function(id){
	var val = $("#reply_content").val();
	if(val==''){
		ST.UI.showMessage('提示','对不起，请输入回复内容');
		$("#reply_content").focus();
		return false;
	}else{
		$.ajax( {
			type : 'POST',
			url : '/interface/message.php',
			data : '_do=school_msg&act=replySchoolMsg&msgid=' + id+"&val="+encodeURIComponent(val)+'&random='+Math.random() ,
			dataType : 'json',
			success : function(res) {
				 if(res.succ==1){
				 	profile.myspace.replySchoolMsg(id);
				 	leftMenu.goToUrl(document.getElementById('current_url'));
		         }else{
		         	 desc = res.desc == undefined ? '对不起，系统忙' : res.desc;
		             alert(desc);
		         }
			}
		});
	}

}
