﻿var voteObject = {
    XMLHttpObject:null,
    inProcessing:false,
	voteId:0,
	voteName:"",
	classKey:"",
	div:null,
    getXMLHttpObject:function(){
        if(window.XMLHttpRequest) return new XMLHttpRequest();
		try{
			return new ActiveXObject('MSXML2.XMLHTTP');
		}
		catch(e){
			try{
				return new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch(e){
				return null;
			}
		}
    },
	init:function(key){
		voteObject.classKey = key;
		document.writeln("<style type=\"text/css\">");
		document.writeln(".popwin{display:block; background: #6CCAEE; border:1px solid #0099FF; font-size:12px; position:absolute; z-index:555;}");
		document.writeln(".popwintitle{width:100px; text-align:left; color:#FFFFFF; font-weight:bold; padding-left:10px;   padding-top:2px;height:20px; line-height:20px; float:left;}");
		document.writeln(".popwinclose{ display:block; float:left; text-align:right; width:120px; padding-top:1px;}");
		document.writeln(".popwinclose img{ border:0px;}");
		document.writeln(".popcontent{ padding:10px; color:#006699; background:#FFFFFF; float:left; display:block; width:215px; line-height:150%;}");
		document.writeln(".popcontent a{ color:#006699; text-decoration:none; font-weight:bold;}");
		document.writeln(".popcontent a:hover{ color:#ff3300; text-decoration:underline;}");
		document.writeln(".popmore{display:block; clear:both; text-align:right;}");
		document.writeln("</style>");
	},
    loadVote:function(){
        if(voteObject.classKey==""){
			return;
		}
        if(voteObject.XMLHttpObject==null){
            voteObject.XMLHttpObject = voteObject.getXMLHttpObject();
        }
        if(voteObject.XMLHttpObject==null){
            return;
        }
        if(voteObject.inProcessing){
            return;
        }
		voteObject.inProcessing = true;
		voteObject.XMLHttpObject.open("POST","/Tools/GetVotePlan.aspx",true);
		voteObject.XMLHttpObject.onreadystatechange = voteObject.hLoadVote;
		voteObject.XMLHttpObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		voteObject.XMLHttpObject.send("key="+voteObject.classKey);
    },
    hLoadVote:function(){
	    with(voteObject.XMLHttpObject){
		    if(readyState==4){
			    if(status == 200 ){
			        var rtnObj = eval('('+responseText+')');
					if(rtnObj.FLAG){
						voteObject.voteId = rtnObj.voteid;
						voteObject.voteName = rtnObj.votename;
						voteObject.popWin();
					}
			    }
			    voteObject.inProcessing = false;
		    }
	    }
    },
	popWin:function(){
		if(voteObject.div==null){
			voteObject.div = document.createElement("DIV");
			document.body.appendChild(voteObject.div);
			voteObject.div.style.display="none";
			voteObject.div.style.position = "absolute";
			voteObject.div.style.width = "240px";
			voteObject.div.style.overflow = "hidden";
		}
		var html = "<div class=\"popwin\">";
		html += "<div class=\"popwintitle\">在线调查</div>";
		html += "<div class=\"popwinclose\"><a href=\"javascript:voteObject.closeWin();\"><img src=\"/images/popclose.gif\" width=\"23\" height=\"17\" /></a></div>";
		html += "<div class=\"popcontent\">";
		html += "<a href=\"/Vote.aspx?id="+voteObject.voteId+"\">"+voteObject.voteName+"</a><br />";
		html += "<span class=\"popmore\"><a href=\"/Vote.aspx?id="+voteObject.voteId+"\">参与调查 ></a></span> ";
		html += "</div>";
		html += "</div>";
		voteObject.div.innerHTML = html;
		
		if(window.ActiveXObject){
			window.attachEvent("onresize",voteObject.winChange);
			window.attachEvent("onscroll",voteObject.winChange);
		}else{
			window.addEventListener("resize", voteObject.winChange,false);
			window.addEventListener("scroll", voteObject.winChange,false);
		}
		
		voteObject.slideShowWin(1);
	},
	slideShowWin:function(h){
		voteObject.div.style.display="";
		height = h;
		if(h>100){
			return;
		}else{
			var docHeight = window.document.documentElement.clientHeight;
			var docWidth = window.document.documentElement.clientWidth;
			var st = window.document.documentElement.scrollTop;
			var divWidth = voteObject.div.clientWidth;
			voteObject.div.style.height = h+"px";
			voteObject.div.style.left = (docWidth-divWidth - 20) + "px";
			voteObject.div.style.top = (docHeight+st-h)+"px";
			h+=2;
			setTimeout("voteObject.slideShowWin("+h+")",10);
		}
	},
	closeWin:function(){
		var height = voteObject.div.clientHeight;
		voteObject.slideHideWin(height);
	},
	slideHideWin:function(h){
		height = h-2;
		if(height>0){
			var top = parseInt(voteObject.div.style.top);
			top += 2;
			voteObject.div.style.height = height+"px";
			voteObject.div.style.top =  top + "px";
			setTimeout("voteObject.slideHideWin("+height+")",10);
		}else{
			voteObject.div.style.display = "none";
		}
	},
	winChange:function(){
		if(voteObject.div.style.display != "none"){
			var docHeight = window.document.documentElement.clientHeight;
			var docWidth = window.document.documentElement.clientWidth;
			var st = window.document.documentElement.scrollTop;
			var divWidth = voteObject.div.clientWidth;
			var divHeight = voteObject.div.clientHeight;
			voteObject.div.style.left = (docWidth-divWidth - 20) + "px";
			voteObject.div.style.top = (docHeight+st-divHeight)+"px";
		}
	}
};

if(window.ActiveXObject){
	window.attachEvent("onload",voteObject.loadVote);
}else{
	window.addEventListener("load", voteObject.loadVote,false);
}