// ===========================================================
// @author		murphy.yang
// @package		easynis js framework [index.htm]
// @function	the parent file
// @copyright	www.easynis.com 
// @license 	www.voson.com
// ===========================================================

var channel,item,task,typeid,id;
//获取参数
channel	=GetQueryString("channel");
item	=GetQueryString("item");
task	=GetQueryString("task");
typeid	=GetQueryString("typeid");
id		=GetQueryString("id");
//调取新闻
document.all["new_content"].innerHTML=ListNews("show_news",10,"#000000",1);
//调取通知
document.all["not_content"].innerHTML=ListNotice("show_notice",2,"#000000");
if (channel!=null){
	document.all["mod_index"].innerHTML="";
	switch(channel){
	case "show_content":
		if (item!="" && item!=null){
			ShowContent(channel,item);
		}else{
			document.all["mod_title"].innerHTML="<font class='font-title'>Voson Associates</font>";
			document.all["mod_content"].innerHTML="Sorry,Failed to find the content,Please check the web url. <br\>Any question,please contact the website administrator, whose email is <a href='mailto:POSTMASTER@VOSON.COM'>Postmaster@Voson.Com</a>";
		}
		break;
	case "list_news":
		document.all["mod_title"].innerHTML="<font class='font-title'>News Center</font>";
		document.all["mod_content"].innerHTML=ListNews("show_news",1000,"#ffffff",0);
		break;
	case "list_notice":
		document.all["mod_title"].innerHTML="<font class='font-title'>Notice Center</font>";
		document.all["mod_content"].innerHTML=ListNotice("show_notice",1000,"#ffffff");
		break;
	case "show_news":
		if (id){
			ShowNews(channel,id);
		}else{
			document.all["mod_title"].innerHTML="<font class='font-title'>Voson Associates</font>";
			document.all["mod_content"].innerHTML="Sorry,Failed to find the content,Please check the web url. <br\>Any question,please contact the website administrator, whose email is <a href='mailto:POSTMASTER@VOSON.COM'>Postmaster@Voson.Com</a>";
		}
		break;
	case "show_notice":
		if (id){
			ShowNews(channel,id);
		}else{
			document.all["mod_title"].innerHTML="<font class='font-title'>Voson Associates</font>";
			document.all["mod_content"].innerHTML="Sorry,Failed to find the content,Please check the web url. <br\>Any question,please contact the website administrator, whose email is <a href='mailto:POSTMASTER@VOSON.COM'>Postmaster@Voson.Com</a>";
		}
		break;
	default:
		document.all["mod_title"].innerHTML="<font class='font-title'>Voson Associates</font>";
		document.all["mod_content"].innerHTML="Sorry,Failed to find the content,Please check the web url. <br\>Any question,please contact the website administrator, whose email is <a href='mailto:POSTMASTER@VOSON.COM'>Postmaster@Voson.Com</a>";
		break;
	}
}else{
	document.all["mod_title"].innerHTML="<font class='font-title'>Voson Associates</font>";
}
//=======================================================================
// @author 		murphy.yang
// @function	显示新闻内容
// @out			string
//=======================================================================
function ShowNews(channel,id){   
	var xmlDoc=GetXML("xml/"+channel+".xml");
	var temp=false;
	var tempstr="";
	for (var i=0;i<xmlDoc.length;i++ )	{
		if (xmlDoc!=null &&id==xmlDoc.item(i).childNodes[0].text){
			tempstr=xmlDoc.item(i).childNodes[3].text
			//回车换行
			tempstr=tempstr.replace(/\n/g,"<br/>");
			document.all["mod_title"].innerHTML="<font class='font-title'>"+xmlDoc.item(i).childNodes[2].text+"</font>";
			document.all["mod_content"].innerHTML=tempstr;
			temp=true;
		}
	}
	if (temp==false){
		document.all["mod_title"].innerHTML="<font class='font-title'>Voson Associates</font>";
		document.all["mod_content"].innerHTML="Sorry,Failed to find the content,Please check the web url. <br\>Any question,please contact the website administrator, whose email is <a href='mailto:POSTMASTER@VOSON.COM'>Postmaster@Voson.Com</a>";
	}
} 
//=======================================================================
// @author 		murphy.yang
// @function	显示单页内容
// @out			string
//=======================================================================
function ListNotice(xmlname,num,color){   
	var xmlDoc=GetXML("xml/"+xmlname+".xml");
	var tempstr="";
	if (xmlDoc!=null){
		for (var i=xmlDoc.length-1;i>=0 && (xmlDoc.length-i-1)<num;i-- )	{
			tempstr=tempstr+"<b>"+xmlDoc.item(i).childNodes[1].text+"</b>&nbsp;&nbsp;";
			tempstr=tempstr+"<a href='index.htm?channel=show_notice&id="+xmlDoc.item(i).childNodes[0].text+"'><font color='"+color+"'>"+xmlDoc.item(i).childNodes[2].text+"</font></a><br/><br/><br/>";
		}
		tempstr="<font color='"+color+"'>"+tempstr+"</font>";
	}else{
		tempstr="No Records!"
	}
	return tempstr;
}
//=======================================================================
// @author 		murphy.yang
// @function	显示新闻内容
// @out			string
//=======================================================================
function ListNews(xmlname,num,color,flag){   
	var xmlDoc=GetXML("xml/"+xmlname+".xml");
	var tempstr="";
	if (xmlDoc!=null){
		for (var i=xmlDoc.length-1;i>=0 && (xmlDoc.length-i-1)<num;i-- )	{
			tempstr=tempstr+"<b>"+xmlDoc.item(i).childNodes[1].text+"</b>&nbsp;&nbsp;";
			if (flag==1){
				tempstr=tempstr+"<br/>"
			}
			tempstr=tempstr+"<a href='index.htm?channel=show_news&id="+xmlDoc.item(i).childNodes[0].text+"'><font color='"+color+"'>"+xmlDoc.item(i).childNodes[2].text+"</font></a><br/><br/><br/>";
		}
		tempstr="<font color='"+color+"'>"+tempstr+"</font>";
	}else{
		tempstr="No Records!"
	}
	return tempstr;
}
//=======================================================================
// @author 		murphy.yang
// @function	显示单页内容
// @out			string
//=======================================================================
function ShowContent(channel,item){   
	var xmlDoc=GetXML("xml/"+channel+".xml");
	var temp=false;
	var tempstr="";
	for (var i=0;i<xmlDoc.length;i++ )	{
		if (xmlDoc!=null &&item==xmlDoc.item(i).childNodes[0].text){
			tempstr=xmlDoc.item(i).childNodes[2].text
			//回车换行
			tempstr=tempstr.replace(/\n/g,"<br/>");
			tempstr=tempstr.replace(/##/g,"<");
			tempstr=tempstr.replace(/%%/g,">");
			tempstr=tempstr.replace(/#%/g,"&");
			document.all["mod_title"].innerHTML="<font class='font-title'>"+xmlDoc.item(i).childNodes[1].text+"</font>";
			document.all["mod_content"].innerHTML=tempstr;
			temp=true;
		}
	}
	if (temp==false){
		document.all["mod_title"].innerHTML="<font class='font-title'>Voson Associates</font>";
		document.all["mod_content"].innerHTML="Sorry,Failed to find the content,Please check the web url. <br\>Any question,please contact the website administrator, whose email is <a href='mailto:POSTMASTER@VOSON.COM'>Postmaster@Voson.Com</a>";
	}
} 
//=======================================================================
// @author 		murphy.yang
// @function	获取html后参数
// @out			xml文档内容
//=======================================================================
function GetQueryString(name){   
	var reg	= new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
	var r	= window.location.search.substr(1).match(reg);
	if  (r!=null){
		return unescape(r[2]);
	}else{
		return null;
	}
} 
//=======================================================================
// @author 		murphy.yang
// @function	获取xml
// @out			xml文档内容
//=======================================================================
function GetXML(filename){   
	var xmlDoc= new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async="false";  
	if (xmlDoc.load(filename)){
		var nodes= xmlDoc.documentElement.childNodes;
		return nodes;
	}else{
		return null;
	}
} 