﻿// JavaScript Document

//标签切换
function getNames2(obj,name,tij) {	
var p = document.getElementById(obj);
var plist = p.getElementsByTagName(tij);
var rlist = new Array();
for(i=0;i<plist.length;i++) {
	if(plist[i].getAttribute("name") == name){
		rlist[rlist.length] = plist[i];
	}
}
return rlist;
}

function fod2(obj,tag,name,css1,css2){
//var p = obj.parentNode.getElementsByTagName("td");
var p = getNames2(tag,"t","div");
var p1 = getNames2(name,"f","div"); // document.getElementById(name).getElementsByTagName("div");
for(i=0;i<p1.length;i++){
	if(obj==p[i]){
		p[i].className = css1;
		p1[i].className = "dis";
	}else{
		p[i].className = css2;
		p1[i].className = "undis";
	}
}
}

//顶、踩新闻
function goTips(id,gosubmit) {
	var xmlHttp01;
	if (window.ActiveXObject){
	   xmlHttp01=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
	   xmlHttp01=new XMLHttpRequest();
	}

	var url="/news/tips.jsp?gosubmit="+gosubmit+"&newsID="+id+"&"+Math.random();
	xmlHttp01.open("GET",url,true);
	xmlHttp01.onreadystatechange= function () {
		if(xmlHttp01.readyState==4){
		  if(xmlHttp01.status==200){
			var msg= xmlHttp01.responseText;
			if (gosubmit=='din'){
				document.getElementById("tips"+id).innerHTML=msg;
				document.getElementById("dig"+id).innerHTML="<font color='#999999'>顶</font>";
			}else if(gosubmit=='cai'){
				document.getElementById("steps"+id).innerHTML=msg;
				document.getElementById("cai"+id).innerHTML="<font color='#999999'>踩</font>";
			}else if(gosubmit=='sup'){
				document.getElementById("tips"+id).innerHTML=msg;
			}
		  }
		}
	}
	xmlHttp01.send(null);
}

//更新新闻点击量
function updateNewsHits(id) {
	var xmlHttp;
	if (window.ActiveXObject){
	   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
	   xmlHttp=new XMLHttpRequest();
	}
	
	var url="/news/hits.jsp?newsID="+id+"&"+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=getMes;
	xmlHttp.send(null);
	
	function getMes() {
		if(xmlHttp.readyState==4){
		  if(xmlHttp.status==200){
			var mes= xmlHttp.responseText;
			document.getElementById("hits").innerHTML=mes;
		  }
		}
	}
}

//更新网络红人点击量
function updateRedHits(id) {
	var xmlHttp;
	if (window.ActiveXObject){
	   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
	   xmlHttp=new XMLHttpRequest();
	}
	
	var url="/red/hits.jsp?redID="+id+"&"+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=getMes;
	xmlHttp.send(null);
	
	function getMes() {
		if(xmlHttp.readyState==4){
		  if(xmlHttp.status==200){
			var mes= xmlHttp.responseText;
			document.getElementById("hits").innerHTML=mes;
		  }
		}
	}
}

//更新下载点击量
function updateDownHits(id) {
	var xmlHttp;
	if (window.ActiveXObject){
	   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
	   xmlHttp=new XMLHttpRequest();
	}
	
	var url="/down/hits.jsp?downID="+id+"&"+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=getMes;
	xmlHttp.send(null);
	
	function getMes() {
		if(xmlHttp.readyState==4){
		  if(xmlHttp.status==200){
			var mes= xmlHttp.responseText;
			document.getElementById("hits").innerHTML=mes;
		  }
		}
	}
}

//更新下载量
function updateDownCount(id) {
	var xmlHttp;
	if (window.ActiveXObject){
	   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
	   xmlHttp=new XMLHttpRequest();
	}
	
	var url="/down/count.jsp?downID="+id+"&"+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=getMes;
	xmlHttp.send(null);
	
	function getMes() {
		if(xmlHttp.readyState==4){
		  if(xmlHttp.status==200){
			var mes= xmlHttp.responseText;
			document.getElementById("downCount").innerHTML=mes;
		  }
		}
	}
}

//顶、踩红人
function goRedTips(id,gosubmit) {
	var xmlHttp01;
	if (window.ActiveXObject){
	   xmlHttp01=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
	   xmlHttp01=new XMLHttpRequest();
	}

	var url="/red/tips.jsp?gosubmit="+gosubmit+"&redID="+id+"&"+Math.random();
	xmlHttp01.open("GET",url,true);
	xmlHttp01.onreadystatechange= function () {
		if(xmlHttp01.readyState==4){
		  if(xmlHttp01.status==200){
			var msg= xmlHttp01.responseText;
			if (gosubmit=='din'){
				document.getElementById("tips"+id).innerHTML=msg;
				alert("支持成功！感谢您的参与");
			}else if(gosubmit=='cai'){
				document.getElementById("steps"+id).innerHTML=msg;
				alert("投票成功！感谢您的参与");
			}
		  }
		}
	}
	xmlHttp01.send(null);
}

//顶、踩会员
function goUserTips(id,gosubmit) {
	var xmlHttp01;
	if (window.ActiveXObject){
	   xmlHttp01=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
	   xmlHttp01=new XMLHttpRequest();
	}

	var url="/blog/tips.jsp?gosubmit="+gosubmit+"&userID="+id+"&"+Math.random();
	xmlHttp01.open("GET",url,true);
	xmlHttp01.onreadystatechange= function () {
		if(xmlHttp01.readyState==4){
		  if(xmlHttp01.status==200){
			var msg= xmlHttp01.responseText;
			if (gosubmit=='din'){
				document.getElementById("tips"+id).innerHTML=msg;
				alert("投票成功！感谢您的参与");
			}else if(gosubmit=='cai'){
				document.getElementById("steps"+id).innerHTML=msg;
				alert("投票成功！感谢您的参与");
			}
		  }
		}
	}
	xmlHttp01.send(null);
}

//判断是否登录
function isLogin() {
	var xmlHttp;
	if (window.ActiveXObject){
	   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
	   xmlHttp=new XMLHttpRequest();
	}
	
	var url="/inc/isLogin.jsp?web=51tuishou&"+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=getMes;
	xmlHttp.send(null);
	
	function getMes() {
		if(xmlHttp.readyState==4){
		  if(xmlHttp.status==200){
			var mes= xmlHttp.responseText;
			document.getElementById("login_txt").innerHTML=mes;
		  }
		}
	}
}

//图片按比例缩放
function DrawImage(ImgD,iwidth,iheight){
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
    if(image.width/image.height>= iwidth/iheight){
        if(image.width>iwidth){  
        ImgD.width=iwidth;
        ImgD.height=(image.height*iwidth)/image.width;
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    else{
        if(image.height>iheight){  
        ImgD.height=iheight;
        ImgD.width=(image.width*iheight)/image.height;        
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    }
}

//关闭窗口IE6、IE7、IE8、FF通用代码
function closeWin() {
	window.opener=null;
	window.open('','_self');
	window.close();
}

//复制文本
function copy_text(text){
	window.clipboardData.setData('text',text);
	alert("链接已经复制，您可以直接粘贴发送给你的朋友们一起分享啦!");
}

//加入收藏
function addFav(title,url){
	if (document.all)
		window.external.AddFavorite(url, title+"-中国网络推手联盟");
	else if (window.sidebar)
		window.sidebar.addPanel(title+"-中国网络推手联盟", url, "")
}
