var Browser = new Object();
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
function getElement(aID)
{
  return (document.getElementById) ? document.getElementById(aID): document.all[aID];
}
var http_request=false;
function makeRequest(url){
 http_request=false;
 if(window.XMLHttpRequest){//Mozilla,Safari,...
 http_request=new XMLHttpRequest();
 if(http_request.overrideMimeType){
 http_request.overrideMimeType('text/xml');
 }
 }else if(window.ActiveXObject){//IE
 try{
 http_request=new ActiveXObject("Msxml2.XMLHTTP");
 }catch(e){
 try{
 http_request=new ActiveXObject("Microsoft.XMLHTTP");
 }catch(e){}
 }
 }
 if(!http_request){
 alert('Giving up:(Cannot create an XMLHTTP instance)');
 return false;
 }
return http_request;
 }
  var cflag = 0;
 var ajccache=new Object();

var hidid;
function calendar(divid,obj)
{	
	clearTimeout(hidid);
	obj.onmouseout=function(){
		hidid=setTimeout("hideDiv1()",300);
	}
	document.getElementById(divid).style.display="block";
	document.getElementById(divid).onmouseover=function(){
		clearTimeout(hidid);
	}
	document.getElementById(divid).onmouseout=function(aEvent){
		var myEvent = window.event ? window.event : aEvent;
		var srcElement=window.event ? myEvent.srcElement : myEvent.target;
		if(srcElement==document.getElementById("calendarContainer")){
			hidid=setTimeout("hideDiv1()",300);
		}
	}
}
function ranklist(divid,obj)
{	
	clearTimeout(hidid);
	obj.onmouseout=function(){
		hidid=setTimeout("hideDiv11()",300);
	}
	document.getElementById(divid).style.display="block";
	document.getElementById(divid).onmouseover=function(){
		clearTimeout(hidid);
	}
	document.getElementById(divid).onmouseout=function(aEvent){
		var myEvent = window.event ? window.event : aEvent;
		var srcElement=window.event ? myEvent.srcElement : myEvent.target;
		if(srcElement==document.getElementById("rankcontent")){
			hidid=setTimeout("hideDiv11()",300);
		}
	}
}

function floatDiv1(divid,obj)
{	
	clearTimeout(hidid);
	obj.onmouseout=function(){
		hidid=setTimeout("hideDiv2()",300);
	}
	document.getElementById(divid).style.display="block";
	document.getElementById(divid).onmouseover=function(){
		clearTimeout(hidid);
	}
	document.getElementById(divid).onmouseout=function(aEvent){
		var myEvent = window.event ? window.event : aEvent;
		var srcElement=window.event ? myEvent.srcElement : myEvent.target;
		if(srcElement==document.getElementById("morekeyword1")){
			hidid=setTimeout("hideDiv2()",300);
		}
	}
}
function floatDiv2(divid,obj)
{	
	clearTimeout(hidid);
	obj.onmouseout=function(){
		hidid=setTimeout("hideDiv3()",300);
	}
	document.getElementById(divid).style.display="block";
	document.getElementById(divid).onmouseover=function(){
		clearTimeout(hidid);
	}
	document.getElementById(divid).onmouseout=function(aEvent){
		var myEvent = window.event ? window.event : aEvent;
		var srcElement=window.event ? myEvent.srcElement : myEvent.target;
		if(srcElement==document.getElementById("morekeyword2")){
			hidid=setTimeout("hideDiv3()",300);
		}
	}
}
function hideDiv1()
{
	try{document.getElementById("dcalendar").style.display="none"}catch(e){};
}
function hideDiv11()
{
	try{document.getElementById("ranklist").style.display="none"}catch(e){};
}
function hideDiv2()
{
	try{document.getElementById("hotkeyword1").style.display="none"}catch(e){};
}
function hideDiv3()
{
	try{document.getElementById("hotkeyword2").style.display="none"}catch(e){};
}

function hideDiv4()
{
	try{document.getElementById("bldiv").style.display="none"}catch(e){};
}
function hideDiv5()
{
	try{document.getElementById("origin").style.display="none"}catch(e){};
}

function hideDiv6()
{
	try{document.getElementById("bldiv1").style.display="none"}catch(e){};
}

function IsChild(cNode,pNode){
	if(cNode==pNode) return false;
	while(cNode!=null){
		cNode=cNode.parentNode;
		if(cNode==pNode) return true; 
	}
	return false;
}
document.onmousedown=function(aEvent){
	var myEvent = window.event ? window.event : aEvent;
	var srcElement=window.event ? myEvent.srcElement : myEvent.target;
	if(!IsChild(srcElement,document.getElementById("dcalendar"))) hideDiv1();
	if(!IsChild(srcElement,document.getElementById("ranklist"))) hideDiv11();
	if(!IsChild(srcElement,document.getElementById("morekeyword1"))) hideDiv2();
	if(!IsChild(srcElement,document.getElementById("morekeyword2"))) hideDiv3();
	if(!IsChild(srcElement,document.getElementById("bldiv"))) hideDiv4();
	if(!IsChild(srcElement,document.getElementById("origin"))) hideDiv5();
	if(!IsChild(srcElement,document.getElementById("bldiv1"))) hideDiv6();
}
var months = new Array("01", "02", "03","04", "05", "06", "07", "08", "09","10", "11", "12");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);
var days = new Array("日","一", "二", "三","四", "五", "六");
function getDays(month, year) {
if (1 == month)
return ((0 == year % 4) && (0 != (year % 100))) ||
(0 == year % 400) ? 29 : 28;
else
return daysInMonth[month];
}
function getToday() {
this.now = new Date();
this.year = this.now.getFullYear();
this.month = this.now.getMonth();
this.day = this.now.getDate();
this.hours=this.now.getHours();
}
today = new getToday();
function newCalendar() {
today = new getToday();
var parseYear = parseInt(document.getElementById("year")[document.getElementById("year").selectedIndex].text);
var newCal = new Date(parseYear,document.getElementById("month").selectedIndex, 1);
var day = -1;
var startDay = newCal.getDay();
var daily = 0;
if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth()))
day = today.day;
var tableCal = document.getElementById("dayList");
var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear());
for (var intWeek = 0; intWeek < tableCal.rows.length;intWeek++)
for (var intDay = 0;intDay < tableCal.rows[intWeek].cells.length;intDay++)
{
var cell = tableCal.rows[intWeek].cells[intDay];
if ((intDay == startDay) && (0 == daily))
daily = 1;
if(day==daily)
cell.className = "active";
else if(intDay == 0 || intDay == 6)
cell.className = "c1";
else  
cell.className ="c2";
if ((daily > 0) && (daily <= intDaysInMonth))
{ 
setInnerText(cell,daily);
daily++;
}
else
setInnerText(cell,"");
}}
function setInnerText(elm,text){
	if(navigator.appName.indexOf("Explorer") > -1){
    elm.innerText = text;
	} else{
     elm.textContent = text;
	}
}
function getInnerText(elm){
	if(navigator.appName.indexOf("Explorer") > -1){
     return elm.innerText;
	} else{
     return elm.textContent;
	}
}
function fSetYearMon(iYear,iMon){
	document.getElementById("month").options[iMon-1].selected=true;
	for(var i=0;i<document.getElementById("year").length;i++){
		if(document.getElementById("year").options[i].value==iYear){
			document.getElementById("year").options[i].selected=true;
		}
	}
	newCalendar();
}
function NextMonth(){
	var iMon=document.getElementById("month").value;
	var iYear=document.getElementById("year").value;
	if(++iMon>12){iMon=1;iYear++;}
	fSetYearMon(iYear,iMon);
}
function PrevMonth(){
	var iMon=document.getElementById("month").value;
	var iYear=document.getElementById("year").value;
	if(--iMon<1){iMon=12;iYear--;}
	fSetYearMon(iYear,iMon);
}
function getDate(evt,pagename) {
	evt=evt?evt:(window.event?window.event:null);
var srcElement = evt.srcElement ? evt.srcElement : evt.target;
var srcInnerText=getInnerText(srcElement);
var noday=new Date(document.getElementById("year").value,document.getElementById("month").value-1,srcInnerText,12,0,0);
var starday=new Date(2005,01,1);
var now_day=new Date(today.year,today.month,today.day,today.hours,0,0);
if ((noday>=starday) && (now_day>=noday)){
if (srcElement.tagName =="TD" )
	if (srcInnerText != "")
	{
		var sToday=srcInnerText;
		if (parseInt(sToday)<10) {
			sToday="0"+sToday;
		}
	var sDate =document.getElementById("year").value + "-" + months[document.getElementById("month").value-1] + "-"+sToday;
	//alert(sDate);
	getContents2(pagename,"shlist",sDate);
	hideDiv1();
	getElement("shfy").style.display="none";
	}
}else{
	alert("暂时没有内容！请选择其他日期！")
}
}

function getContents(pagenum,cid,urlname,hpage){
 var contentele = getElement(cid);

 contentele.innerHTML = '<img src="http://cimg2.163.com/cnews/img07/newswj/loading.gif" width="24" height="24" />';

 var username = getElement("username1").value;
 var url = "http://go.news.163.com/dingyue/"+urlname+".jsp?start=" + pagenum + "&username="+username;
 getElement(hpage).value = pagenum;
 if(ajccache[url]==null) {
 var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{			
					contentele.innerHTML=xhttp.responseText;
					ajccache[url]=contentele.innerHTML;					
				}
					
			}
		xhttp.open("GET",url,true);
		xhttp.send(null);		
 }else
 {
 contentele.innerHTML=ajccache[url];
 }

}

function getContents2(urlname,cid,sdate){ 
var username = getElement("username1").value;
 var contentele = getElement(cid);
 contentele.innerHTML = '<img src="http://cimg2.163.com/cnews/img07/newswj/loading.gif" width="24" height="24" />';
 var url = "http://go.news.163.com/dingyue/"+urlname+".jsp?date=" + sdate + "&username="+username;  
 if(ajccache[url]==null) {
 var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{				
                //  if (Browser.isMozilla) { 
					   contentele.innerHTML=xhttp.responseText;
				  // }else{		
						//contentele.innerHTML=bytes2BSTR(xhttp.responseBody);
					//}
					ajccache[url]=contentele.innerHTML;					
					}
					
			}
		xhttp.open("GET",url,true);
		xhttp.send(null);		
 }else
 {
 contentele.innerHTML=ajccache[url];
 }
}


function getContents33(pagenum,cid,urlname,hpage,commentid){ 
 var contentele = getElement(cid);
 contentele.innerHTML = '<img src="http://cimg2.163.com/cnews/img07/newswj/loading.gif" width="24" height="24" />';
 var url = "http://go.news.163.com/dingyue/"+urlname+".jsp?start=" + pagenum+"&commentid="+commentid;
 getElement(hpage).value = pagenum;
 if(ajccache[url]==null) {
 var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{				      
					   contentele.innerHTML=xhttp.responseText;
					ajccache[url]=contentele.innerHTML;					
					}
					
			}
		xhttp.open("GET",url,true);
		xhttp.send(null);	
			
 }else
 {
 contentele.innerHTML=ajccache[url];
 }
 
}

function toPre(hpage,cid,urlname){
 var pageid = parseInt(getElement(hpage).value)-1;
 var commentid = getElement("commentid").value;
 if(pageid>0){
 	 if(hpage=="commentpage"){
 	 	getContents33(pageid,cid,urlname,hpage,commentid);
 	 	}else{
   getContents(pageid,cid,urlname,hpage);
  }
 }else{
   alert("已经是第一页了");
 }
}

function toNext(hpage,cid,count,urlname){
 var pageid = parseInt(getElement(hpage).value)+1;
 var commentid = getElement("commentid").value;
    if(hpage=="commentpage"){
 	 	getContents33(pageid,cid,urlname,hpage,commentid);
 	 	}else{ 	 	
   getContents(pageid,cid,urlname,hpage);
  } 
}

function getContents1(hpage,pagenum,cid,urlname){ 
 var contentele = getElement(cid);
 contentele.innerHTML = '<img src="http://cimg2.163.com/cnews/img07/newswj/loading.gif" width="24" height="24" />';
 var username = getElement("username1").value;
 var commentid = getElement("commentid").value;
 var url = "";
 if(hpage=="commentpage"){
     url = "http://go.news.163.com/dingyue/"+urlname+".jsp?start=" + pagenum + "&commentid="+commentid;
 }else{
     url = "http://go.news.163.com/dingyue/"+urlname+".jsp?start=" + pagenum + "&username="+username;
 }

 getElement(hpage).value = pagenum;
 for(i=1;i<=8;i++){
   var liid = cid+i;
   if(pagenum==i){
     getElement(liid).className="active";
   }else{
     getElement(liid).className="";
   }
 }

 if(ajccache[url]==null) {
 var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{				
                //  if (Browser.isMozilla) { 
					   contentele.innerHTML=xhttp.responseText;
				  // }else{		
						//contentele.innerHTML=bytes2BSTR(xhttp.responseBody);
					//}
					ajccache[url]=contentele.innerHTML;					
					}
					
			}
		xhttp.open("GET",url,true);
		xhttp.send(null);		

 }else
 {
 contentele.innerHTML=ajccache[url];
 }

}



function toPre1(hpage,cid,urlname){
 var pageid = parseInt(getElement(hpage).value)-1;
 var commentid = getElement("commentid").value;
 if(pageid>0){   	
        getContents1(hpage,pageid,cid,urlname);
  }else{
      alert("已经是第一页了");
  }
}

function toNext1(hpage,cid,urlname){
 var pageid = parseInt(getElement(hpage).value)+1;
    var commentid = getElement("commentid").value;
    getContents1(hpage,pageid,cid,urlname);
}


function toHidden(divid){
  getElement(divid).style.display = "none";
}

function toBl(){
   getElement("bldiv").style.display="block";  
}

function toBl5(){
   getElement("bldiv1").style.display="block";  
}

function showorigin(){
   getElement("origin").style.display="block";  
}

function toBl2(){
   getElement("bldiv").style.top="93%";
   getElement("bldiv").style.display="block";  
}


//show
function toShEdit(did,id){
   var editid = did + id;
   if(did=="bl"){
      getElement("editdiv1").style.top="80%";
   }else if(did=="osh"){
      getElement("editdiv1").style.top="98%";
   }
   getElement("editdiv1").style.display="block";
   getElement("editdiv2").style.display="none";
   getElement("bldiv").style.display="none";
   getElement("titlevalue").value = getElement(editid).innerHTML;   
   getElement("editid").value = id; 
   getElement("kind").value = did; 
}

function UserEdit(){
   getElement("editdiv2").style.display="block";
   getElement("editdiv1").style.display="none";
   getElement("bldiv").style.display="none";
}

function delData(id,kind){
if(confirm('是否删除？')){
  document.location.href = "delete.jsp?id="+id+"&kind="+kind;
}

}

function shData(id){
  document.location.href = "shsave.jsp?id="+id;
}

function shOData(id,title,url){
  title = encodeURIComponent(title);
  document.location.href = "oshsave.jsp?id="+id+"&title="+title+"&url="+url;
}


function toBl1(){
   getElement("editdiv2").style.display="none";
   getElement("editdiv1").style.display="none";
   getElement("bldiv").style.display="block";  
}