﻿$(document).ready(function(){
						   
	_initAction();
	
	_initSummary();
	
	_ininAction();
	
	_initCalendar();
	
	getActionDearm(nowdate);
	
	_initupnext();
	
	initproceeding();
	
	initprint();

	logionDefault='今日事今日毕，拖延和半途而废是美梦成真的天敌。';
})


function initprint(){
	
  $(".action-top a:last").click(function(){
										   
	     var datestr = $(this).attr("date");
		 
		 if(datestr!='')
		 {
			 window.open("/"+domain+"/today/print/date/"+datestr); 
		 }
		 
   })

}


function initproceeding(){
	
	  $(".proceeding a:first").toggle(
		function(){
			
		     $(this).html("收起详情");
			 
			  $(".proceedcontent").css("height","auto");	 
		}, 
		function(){ 
			
			$(this).html("查看详情");
			
			 $(".proceedcontent").css("height","90px");

		});
	  
        if(edit)
		{
			$(".proceeding a:first").click();
	    }
	  
}



function _ininAction(){
	
        $(".actionadd img").click(function(){
										   
		  $(this).parent().find("li").show();
		   
		})
}

function _initupnext(){
	
     $(".yesterday a").click(function(){
		
	       <!-- start -->
			$.ajax({
				  url: '/'+domain+'/today/yesterday',
				  type: 'post',
				  dataType: 'json',
				  data: 'date='+nowdate,
				  success: function(o){
				  if (o != null)
				  {
					  changeinfo(o);

				  }
                  }
            });
		   <!-- end -->
	 })
	 
	 $(".tomorrow a").click(function(){
		   <!-- start -->
			$.ajax({
				  url: '/'+domain+'/today/tomorrow',
				  type: 'post',
				  dataType: 'json',
				  data: 'date='+nowdate,
				  success: function(o){
				  if (o != null)
				  {
					  changeinfo(o);

				  }
                  }
            });
		   <!-- end -->					 

	 })
}

//进度条
function Loading(){
	
	
	  var  html = "加载中.....";
	  
	  var  loadimg = '<li class="load"><img src="/images/today/load.gif" /></li>';
	  
	  $("#left .time").html(html); 
	  
	  $(".todaytop .date").html(html);     
	  
	  $(".actionadd a:first").html(html);
	  
	  $(".todaybody ul:first").html(loadimg);
	  
	  $(".todaybody ul:last").html(loadimg);
	  
}

//日历

function _initCalendar(){
	
	$("#calendar").calendar({
		initDate:new Date(),
        range:[new Date(1949,0,1),new Date(2015,0,1)],
        clickEvent:function(a){

				var year  = a.getFullYear();
				
				var month = a.getMonth()+1;
				
				var day   = a.getDate();
				
				month     = month<10?"0"+month:month;
				
				day       = day<10?"0"+day:day;
				
				var date  =year+"-"+month+"-"+day;

				if(date!=nowdate)                      //判断是否是当前的日期，是否要重新加载
				{
				    getActionDearm(date);
				}
		  }
    });
}

//获取今日行动和今日梦想

function getActionDearm(date){
	
	   
	        Loading();
	
        	   <!-- start -->
			$.ajax({
				  url: '/'+domain+'/today/getaction',
				  type: 'post',
				  dataType: 'json',
				  data: 'date='+date,
				  success: function(o){
				  if (o != null)
				  {
					  changeinfo(o);
				  }
                  }
            });
		      <!-- end -->
}

//显示数据
function changeinfo(o){

	  var dreamitem    = o.dream;
	  
	  var actionitem   = o.action;
	  
	  var summaryitem  = o.summary;
	  
	  var dreamlength  = dreamitem.length;
	  
	  var actionlength = actionitem.length;
	  
	  var  lock        = o.lock               // 是否锁定 0:未锁定

	  var html="";
	  
	  var important;
	  
	  var operateHtml;
	  
	  $("#left .time").html(o.dates); 
	  
	  $(".todaytop .date").html(o.dates);      // 显示当前日期
	  
	  $(".actionadd a:first").html(o.dates);

	  nowdate = o.date;
	  
	  $(".todaybody ul").empty();
	  
	  $(".todaybody ul").hide();

	  if(dreamlength>0)
	  {
		
		 for(i=0;i<dreamlength;i++)
		 {
			 if(dreamitem[i].i=="1")
			 {
				 important = 'class="important"';
			 }
			 else
			 {
			     important = "";	 
			 }
			 

			 if(nowdate==dreamitem[i].finishdate)
			 {
			  html+='<li mid="'+dreamitem[i].id+'" '+important+'><a href="/'+domain+'/dream/dream/mid/'+dreamitem[i].id+'" target="_blank">';
			  
			  html+=dreamitem[i].title+'</a><span><img src="/images/today/complete.gif" /></span></li>';
			 }
			 else
			 {
				 
			 html+='<li mid="'+dreamitem[i].id+'" '+important+'><a href="/'+domain+'/dream/dream/mid/'+dreamitem[i].id+'" target="_blank" >'+dreamitem[i].title+"</a>";
			   
			   if(loginStatus=="host")
			   {
				  html+='<span><img type="action" src="/images/module/'+models+'/action.gif" /></span>';
			   }
				   
			      html+='</li>';
			   
			 }
		 }
                 $(".todaybody ul:first").html(html);  
	  }
	  
//  行动	  
	  
	  if(actionlength>0)
	  {
		     html = "";

		 for(i=0;i<actionlength;i++)
		 {
			  if(actionitem[i].i=="1")
			 {
				 important = 'class="important"';
			 }
			 else
			 {
			     important = "";	 
			 }
			 
			 if(actionitem[i].f==1)
			 {
			   html+='<li aid="'+actionitem[i].id+'" '+important+'>'+actionitem[i].title+'<font><img src="/images/today/complete.gif" /></font></li>';
			 }
			 else
			 {
			   html+='<li aid="'+actionitem[i].id+'" '+important+'>'+actionitem[i].title;
			   
			   if(loginStatus=="host")
				 {
				      html+='<span><img type="action" src="/images/module/'+models+'/action.gif" /></span>';
				 }
				   
			          html+='</li>';
			 }
		 }
		 
		             $(".todaybody ul:last").html(html);
					 
					 
					 $(".todaybody ul:first").slideDown("normal",function(){
																		  
								$(".todaybody ul:last").slideDown();									  
					 })
	  }
	  
	  if(summaryitem.id>0)
	  {
		    $(".logion").html(summaryitem.summary);  
	  }
	  else
	  {
		    $(".logion").html(logionDefault);  
	  }  
	        _initOperate();  
		  
	  if(lock==0)                       
	  {
           Hide(0);                        // 未锁定时
		   
		  if(summaryitem.edit=="0")
	      {
             $("#logiontitle span").hide();
	      }
		  else
		  {
			 $("#logiontitle span").show();
		  }  
      }
	  else
	  {
		   Hide(1);                       //  锁定时
	  }
	      _initLock();
		  
		  initprintdate();
}

function initprintdate(){
	
	$(".action-top a:last").attr("date",nowdate);
	
}


// 行动操作 

function _initOperate(){
	
       $(".todaybody span img[@type=action]").click(function(){															 
			
			  var mid    =  $(this).parent().parent().attr("mid");
			  
			  var aid    =  $(this).parent().parent().attr("aid");
			  
			  var imgurl =  $(this).attr("src");
			  
		          $(".todaybody span img").show();
				  
				  $(this).hide();
				  
				  //清除现在的对话框
				  $("li[@class=operate]").remove();
				  
				  if(mid>0)
				  {
					 OperateDearm(mid);
				  }
				  if(aid>0)
				  {
					 OperateAction(aid);
				  }
	   })	
}

//梦想操作

function OperateDearm(mid){
	
		 var html;
		 
		 var important      = $("li[@mid="+mid+"]").attr("class");
			 
		 var importantname;
		 
		 id = mid;

	        if(important=="important")
			 {
				 importantname = "设为普通";
				 
				 tempVar       =  0;
			 }
			 else
			 {
				 importantname = "设为重要";
				 				 
				 tempVar       = 1;
			 } 
			 
		 html='<li class="operate"><h4>请选择您要进行的操作：</h4><h5><input type="button"  value="梦想成真" /><input type="button"  value="编辑梦想" />';
		 
	     html+='<input type="button"  value="删除梦想" /><input type="button" value="'+importantname+'" /><input type="button"  value="取消操作" /></h5></li>';  
		 
		 $("li[@mid="+mid+"]").after(html);
		 
		 //取消操作
		 $(".operate input:last").click(function(){ $("li[@class=operate]").remove(); $(".todaybody span img").show();})
		 
		 //设置重点
		 $("input[@value="+importantname+"]").click(function(){
			
			  <!-- start -->
				$.post(
			   "/"+domain+"/today/important",
				{id:id,importantid:tempVar,type:"dream",date:nowdate},
				 function(msg)
					{
					  if(msg==1)
					  {
					        $("li[@mid="+id+"]").addClass("important");	
					  }
					  else if(msg==0)
					  {
						    $("li[@mid="+id+"]").removeClass("important");	
					  }
					        $(".operate input:last").click();  
			  });
		      <!-- end -->
				 
		 })
		
		// 梦想成真
		$(".operate input:first").click(function(){ 
			
			 $(".operate").remove();
			 
			 html='<li class="operate"><h4>温馨提示 ：</h4><h4>1、梦想完成后除梦想名称之外都可以编辑。</h4>';
			 
			 html+='<h4>2、可发表梦想成真感言，说说你梦想成真的心情、经验教训、庆祝活动、要感谢的人和感谢的话（最多250个中文）</h4>'
 
			 html+='<h6><input type="button"  value="梦想成真" /><input type="button"  value="再想一想" /></h6></li>';  
		 
		     $("li[@mid="+id+"]").after(html);
			 
			   $(".operate  input:first").click(function(){						
			        <!-- start -->
								$.post(
							   "/"+domain+"/today/dreamfinish",
								{mid:id,date:nowdate},
								 function(msg)
									{
									  if(msg==1)
									  {
											$("li[@mid="+id+"] span").remove();
											
											$("li[@mid="+id+"]").append('<font><img src="/images/today/complete.gif" /></font>'); 
											
											$(".operate input:last").click();
									  }
								 });
				 <!-- end -->
		       })
			   
			   $(".operate  input:last").click(function(){
														
					$("li[@class=operate]").remove(); $(".todaybody span img").show();

		       })
			 	
		})
		
		//编辑梦想
		
		$("input[@value=编辑梦想]").click(function(){
		
		    $(".operate").remove();
			
			var title = $("li[@mid="+id+"]").text();
		   
		   	 html='<li class="operate"><h4>温馨提示 ： 此操作将会修改这个梦想的名称</h4>';
		 
	         html+='<h4><input type="text" id="updatetitle" value="'+title+'" /></h4>';
			 
			 html+='<h6><input type="button"  value="保存梦想" /><input type="button"  value="取消操作" /></h6></li>';  
		 
		     $("li[@mid="+id+"]").after(html);
			 
			 $(".operate  input:last").click(function(){
														
					$("li[@class=operate]").remove(); $(".todaybody span img").show();
					
			  })
			 
			  $(".operate  input[@value=保存梦想]").click(function(){
					
					var newtitle =  $("#updatetitle").val();
					
					if(newtitle=="")
					{
					   alert("请输入新的梦想名称");	
					}
					else
					{
						$.post(
					   "/"+domain+"/today/updatedream",
						{mid:id,title:newtitle},
						 function(msg)
						 {
							  if(msg==1)
							  {
								    $("li[@mid="+id+"]").html(newtitle+'<span><img type="action" src="/images/module/'+models+'/action.gif"/></span>');
									
									$(".operate").remove();
									
								    _initOperate();
							  }	
							 if(msg=="login")
							 {
							        alert("请你先登录");	 
							 }  	  
						});
						
					}
			  })
												 
	     })
		
		
		
		//梦想删除
	   $("input[@value=删除梦想]").click(function(){ 
			
			 $(".operate").remove();
			 
			 html='<li class="operate"><h4>温馨提示 ：</h4><h4>1、只从当天删除：只从当天的今日行动栏目删除。</h4>';
		 
	         html+='<h4>2、完全删除：将该梦想从梦想栏目和今日行动栏目完全删除（被锁定日期的今日行动内容不会被删除）。</h4>';
			 
			 html+='<h6><input type="button"  value="只从当天删除" /><input type="button"  value="完全删除" /><input type="button"  value="取消操作" /></h6></li>'; 

			 $("li[@mid="+mid+"]").after(html);
			 
			 $(".operate input:first").click(function(){
					<!-- start  今日删除-->
						$.post(
					   "/"+domain+"/today/todaydelete",
						{id:mid,type:"dreamdel",date:nowdate},
						 function(msg)
							{
							  if(msg==1)
							  {
									$("li[@mid="+mid+"]").remove();
									
									$(".operate").remove();
							  }		
							  
						});
				   <!-- end  今日删除-->
			 })
			 $(".operate  input[@value=完全删除]").click(function(){
													  
			     <!-- start   完全删除-->
						$.post(
					   "/"+domain+"/today/dreamdelete",
						{id:mid},
						 function(msg)
							{
							  if(msg==1)
							  {
									$("li[@mid="+mid+"]").remove();
									
									$(".operate").remove();
							  }		  
						});
				  <!-- end  完全删除-->
			 })
			 
			 $(".operate input:last").click(function(){
													 
			           $("li[@class=operate]").remove(); $(".todaybody span img").show();
			 })
		})
	 
}

//行动操作

function  OperateAction(aid){
	
	  var html;
		 
		 var important      = $("li[@aid="+aid+"]").attr("class");
			 
		 var importantname;
		 
		 id = aid;

	        if(important=="important")
			 {
				 importantname = "设为普通";
				 
				 tempVar       =  0;
			 }
			 else
			 {
				 importantname = "设为重要";
				 				 
				 tempVar       = 1;
			 } 
			 
		 html='<li class="operate"><h4>请选择您要进行的操作：</h4><h5><input type="button"  value="完成行动" /><input type="button"  value="编辑行动" />';
		 
	     html+='<input type="button"  value="删除行动" /><input type="button" value="'+importantname+'" /><input type="button"  value="取消操作" /></h5></li>';  
		 
		 $("li[@aid="+aid+"]").after(html);
		 
		 //取消操作
		$(".operate input:last").click(function(){ $("li[@class=operate]").remove(); $(".todaybody span img").show();})
		 
		 //设置重要
		 $("input[@value="+importantname+"]").click(function(){
				
			  <!-- start -->
				$.post(
			   "/"+domain+"/today/important",
				{id:id,importantid:tempVar,type:"action",date:nowdate},
				 function(msg)
					{
					  if(msg==1)
					  {
					        $("li[@aid="+id+"]").addClass("important");	
					  }
					  else if(msg==0)
					  {
						    $("li[@aid="+id+"]").removeClass("important");	
					  }
					        $(".operate input:last").click();
					  
			  });
		      <!-- end -->  
		 })
		 
		 // 行动完成
		 
		 
		 $(".operate input:first").click(function(){ 
												  

            $(".operate").remove();
		   
		   	 html='<li class="operate"><h4>温馨提示 ：</h4><h4>1、当天完成：当天已经完成了此行动计划，以后按照设置的提醒时间继续提醒。</h4>';
		 
	         html+='<h4>2、永久完成：已经彻底完成了此行动计划，以后不再提醒。</h4>';
			 
			 html+='<h6><input type="button"  value="当天完成" /><input type="button"  value="永久完成" /><input type="button"  value="取消操作" /></h6></li>'; 

			 $("li[@aid="+aid+"]").after(html);
					
				
			 //今天完成
		      $(".operate input:first").click(function(){
													  
					<!-- start  -->
						$.post(
					   "/"+domain+"/today/todayaction",
						{id:aid,type:"todayfinish",date:nowdate},
						 function(msg)
							{
							  if(msg==1)
							  {
								    $("li[@aid="+aid+"] span").remove();
												
									$("li[@aid="+aid+"]").append('<font><img src="/images/today/complete.gif" /></font>'); 
									
									$(".operate").remove();
							  }		 
						});
				   <!-- end -->
			
			  })
			  
			   //永久完全
		      $(".operate  input[@value=永久完成]").click(function(){
													  
					<!-- start  -->
						$.post(
					   "/"+domain+"/today/todayaction",
						{id:aid,type:"todayfinish",date:nowdate,finish:"1"},
						 function(msg)
							{
							  if(msg==1)
							  {
								    $("li[@aid="+aid+"] span").remove();
												
									$("li[@aid="+aid+"]").append('<font><img src="/images/today/complete.gif" /></font>'); 
									
									$(".operate").remove();
							  }		
							  
						});
				   <!-- end -->
			  })
			  
			   $(".operate input:last").click(function(){
													   
				   	$("li[@class=operate]").remove(); $(".todaybody span img").show();								   
				
				})
		})

		
		//编辑梦想
		
		$("input[@value=编辑行动]").click(function(){
		
		    $(".operate").remove();
			
			var title = $("li[@aid="+id+"]").text();
		   
		   	 html='<li class="operate"><h4>温馨提示 ： 此操作将会修改这条行动计划</h4>';
		 
	         html+='<h4><input type="text" id="updatetitle" value="'+title+'" /></h4>';
			 
			 html+='<h6><input type="button"  value="保存行动" /><input type="button"  value="取消操作" /></h6></li>';  
		 
		     $("li[@aid="+id+"]").after(html);
			 
			 $(".operate  input:last").click(function(){
														
					$("li[@class=operate]").remove(); $(".todaybody span img").show();
					
			  })
			 
			  $(".operate  input[@value=保存行动]").click(function(){
					
					var newtitle =  $("#updatetitle").val();
					
					var len      =  calculate_byte(newtitle);
					
					if(newtitle=="")
					{
					   alert("请输入新的梦想名称");  
					}
					else if(len>80)
	                {
	                   alert("行动计划最多40个中文或80个字符！");
	                }
					else
					{
						$.post(
					   "/"+domain+"/today/updateaction",
						{mid:id,title:newtitle},
						 function(msg)
						 {
							  if(msg==1)
							  {
								    $("li[@aid="+id+"]").html(newtitle+'<span><img type="action" src="/images/module/'+models+'/action.gif"/></span>');
									
									$(".operate").remove();
									
								    _initOperate();
							  }	
							  if(msg=="login")
							  {
							        alert("请你先登录");	 
							  }  	  
						});
						
					}
			  })
												 
	     })
		
		 //行动删除
	    $("input[@value=删除行动]").click(function(){ 
			
			 $(".operate").remove();
			 
			 html='<li class="operate"><h4>温馨提示 ：</h4><h4>1、只从当天删除：只从当天的今日行动栏目删除。</h4>';
		 
	         html+='<h4>2、完全删除：将该行动计划从梦想栏目和今日行动栏目完全删除（被锁定日期的今日行动内容不会被删除）。</h4>';
			 
			 html+='<h6><input type="button"  value="只从当天删除" /><input type="button"  value="完全删除" /><input type="button"  value="取消操作" /></h6></li>'; 

			 $("li[@aid="+aid+"]").after(html);
			 
			 $(".operate input:first").click(function(){
													  
						<!-- start   今日删除-->
						$.post(
					   "/"+domain+"/today/todaydelete",
						{id:aid,type:"actiondel",date:nowdate},
						 function(msg)
							{
							  if(msg==1)
							  {
									$("li[@aid="+aid+"]").remove();
									
									$(".operate").remove();
							  }		
							  
						});
				   <!-- end  今日删除-->
			
			 })
			 
			 // 完全删除
			$("input[@value=完全删除]").click(function(){
													  
			     <!-- start   完全删除-->
						$.post(
					   "/"+domain+"/today/actiondelete",
						{id:aid},
						 function(msg)
							{
							  if(msg==1)
							  {
									$("li[@aid="+aid+"]").remove();
									
									$(".operate").remove();
							  }		
							  
						});
				  <!-- end  完全删除-->
			 })
			
			$(".operate input:last").click(function(){
													
			  $("li[@class=operate]").remove(); $(".todaybody span img").show();
			
			})
			
		})
}
/************                                 以下是添加行动                                       *************/



function calculate_byte(sTargetStr) {
        var sTmpStr, sTmpChar;
        var nOriginLen = 0;
        var nStrLength = 0;
         
        sTmpStr = new String(sTargetStr);
        nOriginLen = sTmpStr.length;

        for ( var i=0 ; i < nOriginLen ; i++ ) {
                sTmpChar = sTmpStr.charAt(i);

                if (escape(sTmpChar).length > 4) {
                        nStrLength += 2;
                } else if (sTmpChar!='\r') {
                        nStrLength ++;
                }
        }
        return nStrLength;    
}





//设置行动计划时间
function _initAction(){
	
	//点击时间设置时出现的对话框
	
     $(".actionadd a:first").click(function(){
		
			var html;
			var html ='<div class="showtime"><h3>设置提醒时间<font><a>确定</a> &nbsp; <a>关闭</a></font></h3><h3>';
			    html +='<select id="sort"><option value="day">每天</option><option value="week">每周</option><option value="month">每月</option>';
                html +='<option value="year">每年</option><option value="special">指定时间</option><option value="area">时间范围</option></select>';
				html +='<span></span></h3><div class="special"></div></div>';
	
			$(this).parent().parent().parent().append(html); 
			
		   //关闭时间设置选项
			$(".showtime a:last").click(function(){
	
			    $(this).parent().parent().parent().remove();
												  
			})
			
		   //时间类型选择
		   $(".showtime select").change(function(){
				showtime(this);			
		   })
		   
		   //保存时间设置选项
		   $(".showtime a:first").click(function(){
			     var type = $("#sort").val();
			     savetime(type);								  
		   })
       })	
	 
	     //保存行动计划
		 $(".action-bottom img:first").click(function(){
			
			var title =  $(".actionadd input").val();
			
			var cyc   =  $(".actionadd input").attr("cyc");
			
			var len   =  calculate_byte(title);
			
			
			var html;
			
			cyc       = cyc==undefined?"":cyc;

			if(title=="")
			{
			    alert("请输入你的行动计划");	
			}
			else if(len>80)
	        {
	           alert("行动计划最多40个中文或80个字符！");
	        }
			else
			{
			  <!-- start -->
				$.post(
			   "/"+domain+"/today/addaction",
				{title:title,cyc:cyc,date:nowdate},
				 function(msg)
					{
					  if(msg=="1")
					  {
					     $(".action-bottom img:last").click();
						 
						 getActionDearm(nowdate);
					  }
			   });
		      <!-- end -->
			}
		 })
		 
	    //保存行动计划
		 $(".action-bottom img:last").click(function(){
			
			     $(".actionadd input").val("");
						 
				 $(".actionadd input").removeAttr("cyc"); 
				 
				 $(".actionadd a:first").html("每天");
			
		 })
}



function showtime(obj){
	           
		var type = obj.value;
		$(".special").html(""); 
		if(type=="day")
		{
			 $(obj).parent().find("span").html("");
			 
			 $(".special").html(""); 
		}
		else if(type=="week")
		{
			week(obj);
		}
		else if(type=="month")
		{
			month(obj);
		}
		else if(type=="year")
		{
		    year(obj);	
		}
		else if(type=="special")
		{
		    special(obj);	
		}
		else if(type=="area")
		{
		  	area(obj);
		}
	       
}

function week(obj){
	
      var  week = '<select id="week">';
	  
	       week+= '<option value="1">周一</option><option value="2">周二</option><option value="3">周三</option>';
		   
		   week+= '<option value="4">周四</option><option value="5">周五</option><option value="6">周六</option><option value="7">周日</option></select>';
		   
	  $(obj).parent().find("span").html(week);
}

function month(obj){
	
      var  month = '<select id="day">';
	  
	   var array = Array();
		 
	       array = nowdate.split("-");
		   
		   var d = array[2];
		   
	       for(i=1;i<32;i++)
			{
	           if(i==d)
				{
				    month+= '<option value="'+i+'" selected="selected"> '+i+' </option>';
				}
				else
				{
					month+= '<option value="'+i+'"> '+i+' </option>';
				}
			}
			
		   month+= '</select> 日';
		   
	      $(obj).parent().find("span").html(month); 
}


function year(obj){
	
	     var year  = "";
		 
		 var array = Array();
		 
		 array = nowdate.split("-");
		 
		 var y = array[0];
		 
		 var m = array[1];
		 
		 var d = array[2];
		 
		 
		 year = '<select id="month">';
	  
	       for(i=1;i<=12;i++)
		   {
			   if(i==m)
			   {
				     year+= '<option value="'+i+'" selected="selected"> '+i+' </option>';
			   }
			   else
			   {
	                 year+= '<option value="'+i+'"> '+i+' </option>';
			   }
		   }
		       year+= '</select> 月';
     
               year+= '<select id="day">';
	  
	       for(i=1;i<32;i++)
			{
				if(i==d)
				{
				    year+= '<option value="'+i+'" selected="selected"> '+i+' </option>';
				}
				else
				{
					year+= '<option value="'+i+'"> '+i+' </option>';
				}
			}
		   year+= '</select> 日';
		   
		   $(obj).parent().find("span").html(year); 
}


function special(obj){
	
	     var special = "";
		 
		 var year    = 2008;
		 
		 var array = Array();
		 
		 array = nowdate.split("-");
		 
		 var y = array[0];
		 
		 var m = array[1];
		 
		 var d = array[2];

		 special = '<select id="year">';
		 
	      for(i=0;i<=12;i++)
			{
				if(year==y)
				{
					special+= '<option value="'+year+'" selected="selected"> '+year+' </option>';
			    }
				else
				{
			        special+= '<option value="'+year+'"> '+year+' </option>';
				}
			        year++;
			}
		   special+= '</select> 年';

	       special+= '<select id="month">';
	  
	       for(i=1;i<=12;i++)
		   {
			   if(i==m)
			   {
				   special+= '<option value="'+i+'" selected="selected"> '+i+' </option>';
			   }
			   else
			   {
	               special+= '<option value="'+i+'"> '+i+' </option>';
			   }
			}
		  special+= '</select> 月';
     
          special+= '<select id="day">';
	  
	       for(i=1;i<32;i++)
			{
				if(i==d)
				{
				    special+= '<option value="'+i+'" selected="selected"> '+i+' </option>';
				}
				else
				{
					special+= '<option value="'+i+'"> '+i+' </option>';
				}
		   }
		   
		  special+= '</select> 日';
		  
		  $(obj).parent().find("span").html(""); 
		  
		  $(".special").html(special); 
}


function area(obj){
	
	     var special = "";
		 
		 var year    = 2008;
		 
		 var array = Array();
		 
		 array = nowdate.split("-");
		 
		 var y = array[0];
		 
		 var m = array[1];
		 
		 var d = array[2];

		 special = '<select id="year">';
		 
	      for(i=0;i<=12;i++)
			{
			   special+= '<option value="'+year+'"> '+year+' </option>';
			   
			    if(year==y)
				{
					special+= '<option value="'+year+'" selected="selected"> '+year+' </option>';
			    }
				else
				{
			        special+= '<option value="'+year+'"> '+year+' </option>';
				}

			        year++;
			}
		  special+= '</select> 年';

	      special+= '<select id="month">';
	  
	       for(i=1;i<=12;i++)
			{
	           if(i==m)
			   {
				   special+= '<option value="'+i+'" selected="selected"> '+i+' </option>';
			   }
			   else
			   {
	               special+= '<option value="'+i+'"> '+i+' </option>';
			   }
			}
		  special+= '</select> 月';
     
          special+= '<select id="day">';
	  
	       for(i=1;i<32;i++)
			{
				if(i==d)
				{
				    special+='<option value="'+i+'" selected="selected"> '+i+' </option>';
				}
				else
				{
					special+='<option value="'+i+'"> '+i+' </option>';
				}
			}
		  special+= '</select> 日 至 ';
		  
		  year    = 2008;
		  
		  special+= '<select id="eyear">';
		  
	      for(i=0;i<=12;i++)
			{
			    if(year==y)
				{
					special+= '<option value="'+year+'" selected="selected"> '+year+' </option>';
			    }
				else
				{
			        special+= '<option value="'+year+'"> '+year+' </option>';
				}
			        year++;
			}
		  special+= '</select> 年';

	      special+= '<select id="emonth">';
	  
	       for(i=1;i<=12;i++)
			{
	           if(i==m)
			   {
				   special+= '<option value="'+i+'" selected="selected"> '+i+' </option>';
			   }
			   else
			   {
	               special+= '<option value="'+i+'"> '+i+' </option>';
			   }
			}
		       special+= '</select> 月';
      
               special+= '<select id="eday">';
	  
	        for(i=1;i<32;i++)
		    {
	            if(i==d)
				{
				    special+='<option value="'+i+'" selected="selected"> '+i+' </option>';
				}
				else
				{
					special+='<option value="'+i+'"> '+i+' </option>';
				}
			}
			
		  special+= '</select> 日';

		  $(obj).parent().find("span").html(""); 
		  
		  $(".special").html(special); 
}

/*        保 存 时 间       */


function savetime(type){
	
	    var html="";
		var value="";
	
	    if(type=="day")
		{
		      html="每天";
			  
			  value = "day";
		}
		else if(type=="week")
		{
			var week = $("#week").val();
	        var time;
			  if(week==1)       time="周一";
			  else if(week==2)  time="周二";
			  else if(week==3)  time="周三";
			  else if(week==4)  time="周四";
			  else if(week==5)  time="周五";
			  else if(week==6)  time="周六";
			  else if(week==7)  time="周日";
			  
			  html ="每周"+time;
			  
			  value = "week|"+week;
		}
		else if(type=="month")
		{
	     
		      html ="每月"+$("#day").val()+"号";
			  
			  value = "month|"+$("#day").val();
		 
		}
		else if(type=="year")
		{
	     
		      html  = "每年"+$("#month").val()+"月"+$("#day").val()+"日";
			  
			  value = "year|"+$("#month").val()+"-"+$("#day").val();
		 
		}
		else if(type=="special")
		{
		      html  = $("#year").val()+"年"+$("#month").val()+"月"+$("#day").val()+"日";
			  
			  value = "special|"+$("#year").val()+"-"+$("#month").val()+"-"+$("#day").val();
		}
		else if(type=="area")
		{
		     html  = $("#year").val()+"年"+$("#month").val()+"月"+$("#day").val()+"日 至 "+$("#eyear").val()+"年"+$("#emonth").val()+"月"+$("#eday").val()+"日";
		     
			 value = "area|"+$("#year").val()+"-"+$("#month").val()+"-"+$("#day").val()+"|"+$("#eyear").val()+"-"+$("#emonth").val()+"-"+$("#eday").val();
		}
		
		 $(".actionadd a:first").html(html);
		 
		 $(".actionadd input").attr("cyc",value);
		 
		 $(".showtime a:last").click();
}



//行动小节

function _initSummary(){
	
	$("#logiontitle a").click(function(){
		
		var logion = $(".logion").html();
		
		var temphtml   = logion.replace(/<br\/?>/ig,"\n"); 

	   $(".logion").attr("logion",logion);
	   
	   if(logion==logionDefault)
	   {
		     logion="";
	   }
		
	   $("#logiontitle span").addClass("edit");
	   
	   $("#logiontitle span").html('<a href="javascript:summarySave();">保存</a> <a href="javascript:summaryCanle();">取消</a>');
	   
	   $(".logion").html('<textarea name="logion" id="logion">'+temphtml+'</textarea>');
	})
}
function summaryCanle(){
		   
		$("#logiontitle span").removeClass("edit");
		
		$("#logiontitle span").html('<a href="javascript:;">编辑</a>');
		
		var logion = $(".logion").attr("logion");
		
		$(".logion").html(logion);
		
		_initSummary();
}

function summarySave(){
	
          var summary =   $("#logion").val();
		  
		  var len     =   calculate_byte(summary);
		  
		  if(summary=="")
		  {
		      alert("请输入行动小结内容");
		  }
		  else if(len>600)
	      {
	          alert("行动小结最多300个中文或600个字符！");
	      }
		  else
		  {
			  <!-- start -->
						$.post(
					   "/"+domain+"/today/summary",
						{summary:summary,date:nowdate},
						 function(msg)
							{
							  if(msg=="1")
							  {
								 summaryCanle();
								 
								 getActionDearm(nowdate);
							 }
					    });
			  <!--  end  -->
	       }
}


//锁定 

function _initLock(){

    $(".action-top img:first").unbind("click");

    var img = $(".action-top img:first").attr("src");

	if(img=="/images/module/"+models+"/unlocked.jpg")
	 {	 
	
			$(".action-top img:first").click(function(){
			
			   if (confirm("锁定期间此天“今日行动”内容将不可做任何操作，也不会因其他任何操作的影响而改变。您确定要锁定吗？"))
				{
					<!-- start -->
							$.post(
						   "/"+domain+"/today/Lock",
							{date:nowdate},
							 function(msg)
								{
								  if(msg==1)
								  {
									  Hide(1)
									  
									  _initLock();
								  } 
						  });
					   <!-- end -->		
					   
				}
			})
	  }
	  else
	  {
			   $(".action-top img:first").click(function(){
				
					 if (confirm("解除锁定后系统将立刻读取锁定期间的更新数据并刷新此天“今日行动”页面，您在锁定期间的某些操作可能导致目前内容改变且不可恢复。您确定要解除锁定吗？"))
					 {
						  <!-- start -->
								$.post(
							   "/"+domain+"/today/Unlock",
								{date:nowdate},
								 function(msg)
									{
									  if(msg==1)
									  {
										  getActionDearm(nowdate);
										  
										   _initLock();
									  } 
							  });
						   <!-- end -->		   
					 }
				})
	  }
}



//销定时隐藏和显示

function Hide(hide){
	
	if(hide==1)
	{
		$(".todaybody span").hide();
		
		$(".actionadd li").not(".action-top").hide();
		
		$("#logiontitle span").hide();
		
		$(".action-top img:first").attr("src","/images/module/"+models+"/locked.jpg");
		
		 $(".action-top img:first").attr("title",'解除当天的“今日行动”锁定');
		
		$(".action-top span").html("解除当天锁定");
	}
	else
	{
	   $(".todaybody span").show();
	   
	   $(".actionadd li").show();

	   $(".action-top img:first").attr("src","/images/module/"+models+"/unlocked.jpg");
	   
       $(".action-top img:first").attr("title",'锁定当天的“今日行动”内容');
	   
	}
}
