﻿// JavaScript Document

//Valid time scope
var date_start,date_end,g_object
var today = new Date();
var separator="-";
var inover=false;
var _om=$G("cele_date_month"),_oy=$G("cele_date_year");

//mode :The type of time transformation 0- year 1- month 2- direct choice month
function change_date(temp,mode){	
	_om=$G("cele_date_month");
	_oy=$G("cele_date_year");
	var t_month,t_year
    if (mode){
        if(mode==1) t_month=parseInt(_om.innerHTML,10)+parseInt(temp,10);			
		else t_month=parseInt(temp);
        if (t_month<1) {
            _om.innerHTML=12;
            change_date(parseInt(_oy.innerHTML,10)-1,0);
        }else{			
            if (t_month>12){
                _om.innerHTML=1;
                change_date(parseInt(_oy.innerHTML,10)+1,0);
            }else{
				_om.innerHTML=t_month;
                set_cele_date(parseInt(_oy.innerHTML,10),parseInt(_om.innerHTML));           
            }
        }
    }else{
        t_year=parseInt(temp,10);
        
        if (t_year<1990) {
            _oy.value=1990;
            set_cele_date(parseInt(_oy.innerHTML,10),1);                
        }else{
            if (parseInt(t_year,10)>2040){
                _oy.value=2040;
                set_cele_date(parseInt(_oy.innerHTML,10),12);                
            }else{
				_oy.innerHTML=t_year;
                set_cele_date(parseInt(_oy.innerHTML,10),parseInt(_om.innerHTML,10));                
            }
        }
    }
	$G("date_year_list").style.display="none";
	$G("date_year_list").style.visibility="hidden";
	$G("date_month_list").style.display="none";
	$G("date_month_list").style.visibility="hidden";
}

//init calendar
function init(d_start,d_end){	 
     var temp_str;
     var i=0
     var j=0
     date_start=new Date(2000,7,1)
     date_end=new Date(2004,8,1)
     document.writeln("<div name=\"cele_date\" id=\"cele_date\"  style=\"display:none\" style=\"LEFT: 69px; POSITION: absolute;z-index:999;\" onBlur=\"hilayer()\" onMouseout=\"lostlayerfocus()\">&nbsp; </div>");
	 if($G("cele_date")!=null){
     	$G("cele_date").innerHTML="";		
	 }
     temp_str="<table style=\"background:#ffffff url(/images_i/datebg.gif) no-repeat left top; width:146px; height:23px;\"><tr colspan=5><td style=\"padding: 0px;\"colspan=7 onmouseover=\"overcolor(this)\">";
     temp_str+="<input  type=\"image\" src=\"/images_i/dateleftbtn.gif\" onclick=\"change_date(-1,1)\" onmouseover=\"getlayerfocus()\" style=\"font-size: 10px;color: #FFFFFF; background-color: #5d7790; cursor: pointer\"></td>";//左面的箭头

     temp_str+=""//Year
     temp_str+="&nbsp;<td style=\"padding: 0px;\" valign=\"top\"><select name=\"cele_date_year\" id=\"cele_date_year\" language=\"javascript\" onchange=\"change_date(this.value,0)\" onmouseover=\"getlayerfocus()\" onblur=\"getlayerfocus()\" style=\"background-color: #D0F1FD;overflow-y:scroll;overflow-x:hidden; outline:hidden; font-family:tahoma; font-size:10px;\">"


     for (i=1990;i<=2040;i++){
     	temp_str+="<OPTION value=\""+i.toString()+"\">"+i.toString()+"</OPTION>";
     }
     temp_str+="</select></td>";
     temp_str+=""//Month
     temp_str+="<td style=\"padding: 0px;\" valign=\"top\"><select  name=\"cele_date_month\" id=\"cele_date_month\" language=\"javascript\" onchange=\"change_date(this.value,2)\" onmouseover=\"getlayerfocus()\" onblur=\"getlayerfocus()\" style=\"background-color: rgb(208, 241, 253); overflow-y: scroll; overflow-x: hidden; font-family: tahoma; font-size: 10px;\">"
     for (i=1;i<=12;i++){
     	temp_str+="<OPTION value=\""+i.toString()+"\">"+i.toString()+"</OPTION>";
     }
     temp_str+="</select></div></td>&nbsp;";
     temp_str+=""//Right arrowhead
     temp_str+="<td><input input  type=\"image\" src=\"/images_i/daterightbtn.gif\" onclick=\"change_date(1,1)\" onmouseover=\"getlayerfocus()\"  style=\"font-size: 10px;color: #FFFFFF; background-color: #5d7790; cursor: hand\">";
     temp_str+="</td></tr></table>";
	 //Form boundary
	 temp_str+="<table cellspacing=\"2\" cellpadding=\"3\" style=\"margin-left:1px; margin-top:-1px;width:144px; border:1px solid #000000; background-color:#FFFFFF;\"><tr style=\"font-size: 9px; color:#005825; \"><td width=\"14%\" align=\"center\" style=\"padding: 0px; font-size:9px;\" onmouseover=\"overcolor(this)\">"
     temp_str+="<font color=red>Su</font></td><td style=\"padding: 0px; font-size:9px;\">";
     temp_str+="Mo</td><td style=\"padding: 0px; font-size:9px;\" width=\"14%\" align=\"center\">"; 
     temp_str+="Tu</td><td style=\"padding: 0px; font-size:9px;\" width=\"14%\" align=\"center\">";
     temp_str+="We</td><td style=\"padding: 0px; font-size:9px;\" width=\"14%\" align=\"center\">"
     temp_str+="Th</td><td style=\"padding: 0px; font-size:9px;\" width=\"14%\" align=\"center\">";
     temp_str+="Fr</td><td style=\"padding: 0px; font-size:9px;\" width=\"14%\" align=\"center\">"; 
     temp_str+="Sa</td></tr>";
     for (i=1 ;i<=6 ;i++){
     	temp_str+="<tr>";
        for(j=1;j<=7;j++){
            temp_str+="<td style=\"padding: 0px;\" name=\"c"+i+"_"+j+"\"id=\"c"+i+"_"+j+"\" style=\"CURSOR: hand;font-size: 9px;\" style=\"COLOR:#0076A3;  font-family:Arial, Helvetica, sans-serif;\" language=\"javascript\" onmouseover=\"overcolor(this)\" onmouseout=\"outcolor(this)\" onclick=\"td_click(this)\">&nbsp;</td>"
        }
     	temp_str+="</tr>"        
     }
     temp_str+="</td></tr></table>";
     if($G("cele_date")!=null){
     	$G("cele_date").innerHTML=temp_str;
	 }	 
}

function getNow(){
    var Stamp=new Date();
    var year = Stamp.getFullYear();
    var month = Stamp.getMonth()+1;
    var day = Stamp.getDate();
    if(month<10){
		month="0"+month;
    }
    if(day<10){
		day="0"+day;
    }
    return year+separator+month+separator+day;
}

function set_cele_date(year,month){
	_om=$G("cele_date_month");
	_oy=$G("cele_date_year");
	var i,j,p,k,ii,kk;
	kk=0;
	var nd=new Date(year,month-1,1);
   //event.cancelBubble=true;
/*	for (ii=1900;ii<=2040;ii++){
		if(parseInt(_oy.options[kk].text)==year){
			_oy.selectedIndex=kk;
		}
		kk++;
	}*/
	_oy.innerHTML=year;  
	_om.innerHTML=month;  
	k=nd.getDay()-1;
	var temp;
	for (i=1;i<=6;i++)
	  for(j=1;j<=7;j++){
		  eval("$G('c"+i+"_"+j+"').innerHTML=\"\"");
		  eval("$G('c"+i+"_"+j+"').bgColor=\"#EFEFEF\"");
		  eval("$G('c"+i+"_"+j+"').style.cursor=\"pointer\"");		 
		  eval("$G('c"+i+"_"+j+"').align=\"center\"");
	  }
	while(month-1==nd.getMonth()){ 
		j=(nd.getDay() +1);
	  	p=parseInt((nd.getDate()+k) / 7)+1;
	  	if(j==1||j==7) eval("$G('c"+p+"_"+j+"').style.color=\"#A70000\""); 
		else eval("$G('c"+p+"_"+j+"').style.color=\"#000\"");
		eval("$G('c"+p+"_"+j+"').innerHTML="+"\""+nd.getDate()+"\"");
		if ((nd.getDate()==today.getDate())&&(parseInt(_om.innerHTML,10)==(today.getMonth()+1))&&(parseInt(_oy.innerHTML,10)==today.getFullYear())){
			eval("$G('c"+p+"_"+j+"').align=\"center\"");
			eval("$G('c"+p+"_"+j+"').bgColor=\"#36B1DF\"");
		}
		if (nd>date_end || nd<date_start){
			eval("$G('c"+p+"_"+j+"').bgColor=\"#FF9999\"");
			eval("$G('c"+p+"_"+j+"').style.cursor=\"pointer\"");
		}
		nd=new Date(nd.valueOf() + 86400000);
	}
}

//s_object：Object of click;Valid time block of d_start- d_end;The demand deposits to be worth of control the piece;
var nCurClick=-1;
var curJsFunc=null;
var curJsParam=null;
var _od=$G("cele_date");
function show_cele_date(eP,d_start,d_end,t_object,nIndex,jsFunc,jsParam){
	if(nIndex!=null) nCurClick=nIndex;
	if(jsFunc!=null) curJsFunc=jsFunc;
	if(jsParam!=null) curJsParam=jsParam;
	var getAPos=new genGetPos(eP);
	_od=$G("cele_date");
	_od.style.position="absolute";
	_od.style.display="";
	_od.style.zIndex=99;
	_od.style.left=getAPos.Left+"px";
	_om=$G("cele_date_month");
	_oy=$G("cele_date_year");
	if(_om!=null){
		_om.onclick=function(){
			var _o=$G("date_month_list");			
			genSwitchElementDisplay(_o.id);
			genChangeElementDisplay("date_year_list",false);
			$G("date_year_list").style.visibility="hidden";
			_o.style.visibility="visible";
			if(_o.style.display!="none"){
				_o.style.position="absolute";
				_o.style.zIndex=101;
				_o.style.left=85+"px";
				_o.style.top=20+"px";
				$G("date_month_select").selectedIndex=parseInt(_om.innerHTML,10)-1;
			}
		}
	}
	if(_oy!=null){
		_oy.onclick=function(){
			var _o=$G("date_year_list");
			genSwitchElementDisplay(_o.id);		
			genChangeElementDisplay("date_month_list",false);
			$G("date_month_list").style.visibility="hidden";
			_o.style.visibility="visible";
			if(_o.style.display!="none"){
				_o.style.position="absolute";
				_o.style.zIndex=101;
				_o.style.left=25+"px";
				_o.style.top=20+"px";
				var ii=0;kk=0
				for (ii=1990;ii<=2040;ii++){
					if(parseInt($G("date_year_select").options[kk].text)==parseInt(_oy.innerHTML,10)){
						$G("date_year_select").selectedIndex=kk;
					}
					kk++;
				}
			}
		}
	}
	_od.style.top=getAPos.Top+getAPos.Height+"px";
	var s,cur_d;
	
	if (d_start!=""){
		if (d_start=="today"){
			date_start=new Date(today.getFullYear(),today.getMonth(),today.getDate());
		}else{
			s=d_start.split(separator);
			date_start=new Date(s[0],s[1]-1,s[2]);
		}
	}else{
		date_start=new Date(1990,1,1);
	}
	
	if (d_end!=""){
		s=d_end.split(separator);
		date_end=new Date(s[0],s[1]-1,s[2]);
	}else{
		date_end=new Date(2040,1,1);
	}
	
	g_object=t_object;
	
	cur_d=new Date();
	set_cele_date(cur_d.getFullYear(),cur_d.getMonth()+1);
	genAddEvent(document.body,"mousedown",dtPopClose);
}

function dtPopClose(evt,n){
	var emPop=_od;
	if(!genIsOnPopArea(evt,n,emPop)) return;	
    if (emPop!=null) {
		emPop.style.display="none";
		$G("date_year_list").style.display="none";
		$G("date_year_list").style.visibility="hidden";
		$G("date_month_list").style.display="none";
		$G("date_month_list").style.visibility="hidden";
	}
	genRemoveEvent(document.body,"mousedown",dtPopClose);
}
//////////////////////////////////////
function checkDt(){
	/*var dtStart=$G("at_Start_text");
	var dtEnd=$G("at_End_text");
	var dtSign=$G("at_Sign_text");
	if(nCurClick==0&&dtSign.value!=""&&dtEnd.value!=""&&dtStart.value.valueOf()>dtEnd.value.valueOf()&&dtStart.value.valueOf()>dtSign.value.valueOf()){
		alert(cmLang.AlertPluginVoteWarn1);
		dtSign.value="";
		dtEnd.value="";
		return;
	}
	if(nCurClick==0&&dtEnd.value!=""&&dtStart.value.valueOf()>dtEnd.value.valueOf()){
		alert(cmLang.AlertPluginVoteWarn2);
		dtEnd.value="";
		return;
	}
	if(nCurClick==0&&dtSign.value!=""&&dtStart.value.valueOf()>dtSign.value.valueOf()){
		alert(cmLang.AlertPluginVoteWarn3);
		dtSign.value="";
		return;
	}	
	if(nCurClick==1&&dtEnd.value!=""&&dtStart.value.valueOf()>dtEnd.value.valueOf()){
		alert(cmLang.AlertPluginVoteWarn4);
		dtEnd.value="";
		return;
	}
	if(nCurClick==1&&dtSign.value!=""&&dtEnd.value!=""&&dtEnd.value.valueOf()<dtSign.value.valueOf()){
		alert(cmLang.AlertPluginVoteWarn5);
		dtEnd.value="";
		return;
	}
//	if(nCurClick==2&&dtSign.value!=""&&dtStart.value.valueOf()>dtSign.value.valueOf()){
//		alert("报名截止日期不能小于开始日期");
//		dtSign.value="";
//		return;
//	}
	if(nCurClick==2&&dtSign.value!=""&&dtEnd.value!=""&&dtEnd.value.valueOf()<dtSign.value.valueOf()){
		alert(cmLang.AlertPluginVoteWarn5);
		dtSign.value="";
		return;
	}*/
}

function td_click(t_object){
	var t_d;
	if (parseInt(t_object.innerHTML,10)>=1 && parseInt(t_object.innerHTML,10)<=31 ){ 
		t_d=new Date(parseInt(_oy.innerHTML,10),parseInt(_om.innerHTML,10),t_object.innerHTML);
		if (t_d<=date_end && t_d>=date_start){
			var year = _oy.innerHTML;
			var month = _om.innerHTML;
			var day = t_object.innerHTML;
			if (parseInt(month,10)<10) month = "0" + month;
			if (parseInt(day,10)<10) day = "0" + day;
			if(g_object.nodeName.toUpperCase()=="INPUT") g_object.value=year+separator+month+separator+day;
			else g_object.innerHTML=year+separator+month+separator+day;
			_od.style.display="none";
		}
	}
	if(nCurClick>=0&&curJsFunc!=null) {
		if(curJsParam!=null) curJsFunc(curJsParam,year+separator+month+separator+day);
		else curJsFunc();
	}
	genChangeElementDisplay("date_month_list",false);
	genChangeElementDisplay("date_year_list",false);
}

function h_cele_date(){
	_od.style.display="none";
}

function overcolor(obj){
  obj.style.color = "#FF9C00";
  inover=true;
  _od.focus();
}

function outcolor(obj,color){
  obj.style.color = color;  
  inover=false;
}

function hilayer(){	
	if (!inover) _od.style.display="none";
}
function getlayerfocus(){
	inover=true;
	_od.focus();
}
function lostlayerfocus(){
	inover=false;
}