var smallIconSize=40;
var IS_INDEX=true;

function reloadIndex()
{
	request(null,"indexb.asp","dataReady(%channel%)","alert('error');",null);
}

function dataReady(index_ch)
{
	var xmlDoc=xmlObj[index_ch].responseXML;
	//alert(xmlObj[index_ch].responsetext);
	getServerTime(index_ch);
	if (hasError(index_ch)) {
		release(index_ch);
		return;
	}
	release(index_ch);

	var rhtml='';
	var tbl_fileupdate=document.getElementById("div_fileupdate");
	var tmpnodes=xmlDoc.getElementsByTagName("Latest_Updated_Folders");
	tmpnodes=tmpnodes[0].getElementsByTagName("folder");
	if (tmpnodes.length>0){
		rhtml+='<table cellpadding="3" cellspacing="0" width="100%" class="contentfont">';
		rhtml+='<tr valign="top"><td width="100%">最近更新的库<hr></td></tr>';
		for (var i=0; i<tmpnodes.length; i++) {
			var tmpnode=tmpnodes[i];
			var dispname=tmpnode.getElementsByTagName("displayName")[0].firstChild.nodeValue;
			var lastmodify=tmpnode.getElementsByTagName("lastModify")[0].firstChild.nodeValue;
			var iconfile=tmpnode.getElementsByTagName("iconfile")[0];
			if (iconfile.hasChildNodes()){
				iconfile=iconfile.firstChild.nodeValue;
				var imgtag="<img src='image/icon/"+iconfile+"' width='"+smallIconSize+"' height='"+smallIconSize+"'>";
			}else{
				var iconwidth=tmpnode.getElementsByTagName("iconwidth")[0].firstChild.nodeValue;
				var iconheight=tmpnode.getElementsByTagName("iconheight")[0].firstChild.nodeValue;
				if (iconwidth>iconheight) {
					iconheight=smallIconSize*iconheight/iconwidth;
					iconwidth=smallIconSize;
				}else{
					iconwidth=smallIconSize*iconwidth/iconheight;
					iconheight=smallIconSize;
				}
				//todo: more!!
				var imgtag="<img width='"+iconwidth+"' height='"+iconheight+"' src='geticon/id="+tmpnode.getAttribute("id")+"/type=folder/'>";
			}
			rhtml+='<tr><td>';
			rhtml+='<a class="a_noUnderLine" href="filelist.htm?id='+tmpnode.getAttribute("id")+'" onclick="location.href=this.href">';
			rhtml+='<table cellpadding="0" cellspacing="1" width="100%" class="linkdot">';
//			rhtml+='<table cellpadding="0" cellspacing="1" width="100%" class="linkdot" onclick="location.href='+"'filelist.htm?id="+tmpnode.getAttribute("id")+"'"+'">';
			rhtml+='<tr valign="middle" title="浏览这个库">';
			rhtml+='	<td width="12%">'+imgtag+'</td>';
			rhtml+='	<td>'+dispname+'</td>';
			rhtml+='	<td width="30%">'+timeStr(lastmodify)+'</td>';
			rhtml+='</tr>';
			rhtml+='</table></a>';
			rhtml+='</td></tr>';
		}
		rhtml+='</table>';
	}

	tmpnodes=xmlDoc.getElementsByTagName("Latest_Uploaded_Files");
	tmpnodes=tmpnodes[0].getElementsByTagName("file");
	if (tmpnodes.length>0){
		rhtml+='<table cellpadding="3" cellspacing="0" width="100%" class="contentfont">';
		rhtml+='<tr valign="top"><td width="100%">最近上传的文件<hr /></td></tr>';
		for (var i=0; i<tmpnodes.length; i++) {
			var tmpnode=tmpnodes[i];
			var dispname=tmpnode.getElementsByTagName("displayName")[0].firstChild.nodeValue;
			var parentid=tmpnode.getElementsByTagName("parentid")[0].firstChild.nodeValue;
			var lastmodify=tmpnode.getElementsByTagName("uploadtime")[0].firstChild.nodeValue;
			var iconfile=tmpnode.getElementsByTagName("iconfile")[0];
			if (iconfile.hasChildNodes()){
				iconfile=iconfile.firstChild.nodeValue;
				var imgtag="<img src='image/icon/"+iconfile+"' width='"+smallIconSize+"' height='"+smallIconSize+"' />";
			}else{
				var iconWidth=tmpnode.getElementsByTagName("iconwidth")[0].firstChild.nodeValue;
				var iconHeight=tmpnode.getElementsByTagName("iconheight")[0].firstChild.nodeValue;
				if (iconWidth>iconHeight) {
					iconHeight=parseInt(smallIconSize*iconHeight/iconWidth);
					iconWidth=smallIconSize;
				}else{
					iconWidth=parseInt(smallIconSize*iconWidth/iconHeight);
					iconHeight=smallIconSize;
				}
				var imgtag="<img src='geticon/id="+tmpnode.getAttribute("id")+"/type=file/' width='"+iconWidth+"' height='"+iconHeight+"'>";
			}
			rhtml+='<tr><td>';
			rhtml+='<a class="a_noUnderLine" href="filelist.htm?id='+parentid+'" onclick="location.href=this.href">';
			//rhtml+='<table cellpadding="0" cellspacing="1" width="100%" class="linkdot" onclick="location.href='+"'filelist.htm?id="+parentid+"'"+'">'
			rhtml+='<table cellpadding="0" cellspacing="1" width="100%" class="linkdot">'
			rhtml+='<tr valign="middle" title="浏览这个文件所在的库">'
			rhtml+='	<td width="12%">'+imgtag+'</td>'
			rhtml+='	<td>'+dispname+'</td>'
			rhtml+='	<td width="30%">'+timeStr(lastmodify)+'</td>'
			rhtml+='</tr>'
			rhtml+='</table></a>'
			rhtml+='</td></tr>'
		}
		rhtml+='</table>';
	}
	//alert (rhtml);
	tbl_fileupdate.innerHTML=rhtml;
	
	var div_notice=document.getElementById("div_notice");
	rhtml='';
	tmpnodes=xmlDoc.getElementsByTagName("notice");
	tmpnodes=tmpnodes[0].getElementsByTagName("msg");
	if (tmpnodes.length>0){
		rhtml+='<table width="100%" class="contentfont">';
		for (i=0;i<tmpnodes.length;i++){
			var tmpnode=tmpnodes[i];
			rhtml+='<tr>';
			rhtml+='<td style="width:12px"><img src="image/envelope/file.gif" /></td>';
			rhtml+='<td style="width:220px">';
			rhtml+='<a href="express/topic.htm?id='+tmpnode.getAttribute("id")+'"><div class="strictW" style="cursor:pointer">'+getVar(tmpnode,"title")+'</div></a>';
			rhtml+='</td>';
			rhtml+='<td>'+timeStr(getVar(tmpnode,"time"))+'</td>';
			rhtml+='</tr>';
		}
		rhtml+='<tr><td colspan="3" align="right"><a href="express/?id=2">更多...</a></td></tr></table>';
	}else{
		rhtml='(没有记录)';
	}
	div_notice.innerHTML=rhtml;

	var div_msg=document.getElementById("div_msg");
	rhtml='';
	tmpnodes=xmlDoc.getElementsByTagName("newMessage");
	tmpnodes=tmpnodes[0].getElementsByTagName("msg");
	if (tmpnodes.length>0){
		rhtml+='<table width="100%" class="contentfont">';
		for (i=0;i<tmpnodes.length;i++){
			var tmpnode=tmpnodes[i];
			rhtml+='<tr>';
			rhtml+='<td style="width:12px"><img src="image/envelope/d8.gif" /></td>';
			rhtml+='<td style="width:220px">';
			rhtml+='<a href="express/topic.htm?id='+tmpnode.getAttribute("pid")+'"><div class="strictW" style="cursor:pointer">'+getVar(tmpnode,"content")+'</div></a>';
			rhtml+='</td>';
			rhtml+='<td>'+timeStr(getVar(tmpnode,"time"))+'</td>';
			rhtml+='</tr>';
		}
		rhtml+='<tr><td colspan="3" align="right"><a href="express/">更多...</a></td></tr></table>';
	}else{
		rhtml='(没有记录)';
	}
	div_msg.innerHTML=rhtml;
}
