//触发服务器事件
function AjaxServer()
{

}

//创建XMLhttp对象
AjaxServer.CreateHttpObj=function(){
	var objhttp;
	try
	{
		//IE浏览器
		try
		{
			objhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			objhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	catch(e)
	{
		//不是IE浏览器
		try
		{
			objhttp = new XMLHttpRequest();
		}
		catch(e)
		{
			objhttp = null;
		}
	}
	return objhttp
}


//获取新闻点击量
AjaxServer.getHits = function(id,pathstr)
{
	var xmlhttp = AjaxServer.CreateHttpObj();
	if(xmlhttp)
	{
		xmlhttp.open("GET", pathstr +"www/js/server.asp?flag=hits&ID="+ id, false); 
		xmlhttp.send(); 
		if(xmlhttp.status==200)
		{
			document.getElementById("show").innerHTML = xmlhttp.responseText
		}
	}
}

AjaxServer.ShowMenu = function(sort)
{
	var xmlhttp = AjaxServer.CreateHttpObj();
	if(xmlhttp)
	{
		xmlhttp.open("GET","/www/js/server.asp?flag=showmenu&sort="+sort+"&num="+Math.random(),false);
		xmlhttp.send();
		if(xmlhttp.status==200)
		{
			document.getElementById("submenu").innerHTML = xmlhttp.responseText;
		}
	}
}


AjaxServer.GetNews = function(flag,n,usertag)
{
	var xmlhttp = AjaxServer.CreateHttpObj();
	if(xmlhttp)
	{
		xmlhttp.open("GET","/www/js/server.asp?flag="+ flag +"&n="+n+"&num="+Math.random(),false);
		xmlhttp.send();
		if(xmlhttp.status==200)
		{
			document.getElementById(usertag).innerHTML = xmlhttp.responseText;
		}
	}
}

AjaxServer.GetPreAndNextNews = function(id)
{

	var xmlhttp = AjaxServer.CreateHttpObj();
	if(xmlhttp)
	{
		xmlhttp.open("GET","/www/js/server.asp?flag=getprenext&id="+id+"&num="+Math.random(),false);
		xmlhttp.send();
		if(xmlhttp.status==200)
		{
			document.getElementById("PreAndNext").innerHTML = xmlhttp.responseText;
		}
	}
}

//图片等比例缩放函数
function ResizePic(ImgTag,FitWidth,FitHeight)
{
	var image = new Image();
	image.src = ImgTag.src;
	if(image.width>0 && image.height>0)
	{
		if(image.width/image.height >= FitWidth/FitHeight)
		{
			if(image.width > FitWidth)
			{
				ImgTag.width = FitWidth;
				ImgTag.height = (image.height*FitWidth)/image.width;
			}
			else
			{ 
				ImgTag.width = image.width;
				ImgTag.height = image.height;
			}
		}
		else
		{
			if(image.height > FitHeight)
			{
				ImgTag.height = FitHeight;
				ImgTag.width = (image.width*FitHeight)/image.height;
			}
			else
			{
				ImgTag.width = image.width; 
				ImgTag.height = image.height;
			}
		}
	}
}
