
function news_count(){
	send_root    = document.getElementById('news_root').value;
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url;
	url = send_root + '/M_news/news_count/'+new Date().getTime();  //最新消息模組1;
	
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {	
					if (document.getElementById('news_totoal_count').value     !=  xmlhttp.responseText){
						document.getElementById('news_totoal_count').value      = xmlhttp.responseText;
						loading_news_gif();
						send_news();
					}
				}
			}
		};
	xmlhttp.send();
	return false;
}

function send_news(){
	
	send_root    = document.getElementById('news_root').value;
	send_url     = document.getElementById('url').value;
	send_target  = document.getElementById('target').value;
	send_load_news_counts     = document.getElementById('load_news_counts').value;
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url;
	send_url = ReplaceAll(send_url,"/","!");
	send_news_select_model    = document.getElementById('news_select_model').value;
	send_news_select_model = parseInt(send_news_select_model);
	
	switch (parseInt(send_news_select_model)){
		case 1:
			url = send_root + '/M_news/news1/'+send_url+"/"+send_target+"/"+send_load_news_counts+"/"+new Date().getTime();  //最新消息模組1
			break;
		case 2:	
			url = send_root + '/M_news/news2/'+send_url+"/"+send_target+"/"+send_load_news_counts+"/"+new Date().getTime(); //最新消息模組2
			break;
		case 3:	
			url = send_root + '/M_news/news3/'+send_url+"/"+send_target+"/"+send_load_news_counts+"/"+new Date().getTime(); //最新消息模組3
			break;
	}	
					
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {
					document.getElementById('show_news').innerHTML = xmlhttp.responseText;	
					
				}
			}
		};
	xmlhttp.send();
	return false;
}



function news_clock(){
	setTimeout("news_clock()",5000);
	news_count();
}


function load_news(news_select_model,root,url,target,counts){
	html_object = "<input id=\"news_root\" type=\"hidden\" value="+root+"/>";
	html_object = html_object + "<input id=\"url\" type=\"hidden\" value="+url+" />";
	html_object = html_object + "<input id=\"target\" type=\"hidden\" value="+target+" />";
	html_object = html_object + "<input id=\"load_news_counts\" type=\"hidden\" value="+counts+" />";
	html_object = html_object + "<input id=\"news_select_model\" type=\"hidden\" value="+news_select_model+" />";
	html_object = html_object + "<input id=\"news_totoal_count\" type=\"hidden\" value=0 />";
	document.getElementById('allNewsScript').innerHTML = html_object;
	document.getElementById('news_totoal_count').value = 0;
	loading_news_gif();
	news_clock();
}


function ReplaceAll(strSource, strFind, strRepl) {   //取代的function 
    var str5 = new String(strSource);
    while (str5.indexOf(strFind) != -1) {
          str5=str5.replace(strFind, strRepl);
    }
   return str5;
}

function loading_news_gif(){
	send_root = document.getElementById('news_root').value;
	send_root = ReplaceAll(send_root,"/index.php","");
	document.getElementById('show_news').innerHTML    = "<div style=\"width:100%\" align=\"center\"><img src=\""+send_root+"/system/media/model_img/M_news/loading.gif\" width=\"50\" height=\"50\"/></div>";	
}