function getXmlhttp(){
        var request = false;
        if(window.XMLHttpRequest) {
                request = new XMLHttpRequest();
                if(request.overrideMimeType) {
                        request.overrideMimeType('text/xml');
                }
        }else if(window.ActiveXObject) {
                var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
                for(var i=0; i<versions.length && !request; i++) {
                         try {
                                 request = new ActiveXObject(versions[i]);
                                 if(request) {
                                         return request;
                                  }
                         }catch(e) {
                                 disPlayError(e.message);
                         }
                }
        }
        return request;
}


function disPlayError(mess)
{
        alert(mess);
}

function getajax(url,contentid,showtype,anya){
        var xhttp=getXmlhttp();
	xhttp.open("GET",url,anya);
        xhttp.send(null);
        xhttp.onreadystatechange=function(){
               if(xhttp.readyState==4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
               {
			if(showtype == 1){
       	        		datafun(xhttp.responseText,contentid);
			}else{
				data2fun(xhttp.responseText,contentid);
			}
               }
        }
}

function postajax(url,datastr,showtype,anya){
	var xhttp=getXmlhttp();
	xhttp.open("POST",url,anya);
	xhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
	xhttp.setRequestHeader("context-type", "text/html;charset=UTF-8");
	xhttp.send(datastr);
	xhttp.onreadystatechange=function(){
		if(xhttp.readyState==4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
		{
			if(showtype == 1){
				postfun(xhttp.responseText);
			}else{
				post2fun( xhttp.responseText);
			}
		}
	}
}


function getServer(gp,weburl,datastr,tfalse) {
	var rn = parseInt(Math.random()*1000);
	var reqesturl = weburl+"&rn="+rn;
	return sendOnBackGround(gp,reqesturl,datastr,"rtnvalue",tfalse);
}

function sendOnBackGround(getpost,reqesturl,data,rtnname,asyna) {
	xmlHttp = getXmlhttp();
	xmlHttp.open(getpost,reqesturl,asyna);
	if(getpost == "POST"){
		xmlHttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("context-type", "text/html;charset=UTF-8");
	}
	xmlHttp.send(data);
	var results = null;
	if (rtnname != null && rtnname!="") {
		results = xmlHttp.getResponseHeader("" + rtnname);
	}
	return results;
}

function postfun(str){
	var bkey = parseInt(str);
	if(bkey == 0){
		alert("未登录或数据传输错误");
		return false;
	}else if(bkey == 1){
		alert("信息提交成功");
		return false;
	}else if(bkey == 2){
		alert("信息提交失败");
		return false;
	}
}

function data2fun(str,contentid){
        var bkey = parseInt(str);
        if(bkey == 0){
                alert("未登录或数据传输错误");
                return false;
        }else if(bkey == 1){
               // alert("设置合格成功");
                document.getElementById("showbutton_"+contentid).style.display = "none";
		document.getElementById("hege_"+contentid).style.display = "inline";
                return false;
        }else if(bkey == 2){
               // alert("设置不合格成功");
                document.getElementById("showbutton_"+contentid).style.display = "none";
		document.getElementById("buhege_"+contentid).style.display = "inline";
                return false;
        }else if(bkey == 3){
                alert("操作失败");
                return false;
        }
}


function post2fun(str){
	TB_remove();
	var bkey = parseInt(str);
	if(bkey == 0){
		alert("未登录或数据传输错误");
		return false;
	}else if(bkey == 1){
		alert("报名成功，请及时交稿哦");
		//location.href="http://www.zhubajie.com/ework";
		return false;
	}else if(bkey == 2){
		alert("报名失败啦，请您再试一次");
		return false;
	}else if(bkey == 3){
		alert("您已经报过名了");
		return false;
	}else if(bkey == 4){
		alert("报名成功，如果你没有安装比赛插件请下载安装\n 如有任何问题可以查看发帖指南。");
		return false;
	}else if(bkey > 4){
		alert("报名成功，请及时交稿哦,转向我的工作管理,由工作室管理我完成这个任务");
		location.href="http://www.zhubajie.com/ework/?com=todos&id="+bkey;
		return false;
	}
}

function datafun(str,contentid){
	var bkey = parseInt(str);
	if(bkey>0&&bkey<8){
		var ocontentid = getElement(contentid);
		ocontentid.innerHTML = parseInt(ocontentid.innerHTML)+1;
		alert("投票成功,此任务你还可投"+bkey+"票");	
		return false;
	}
	if(bkey == 8){
		alert("你还未登录呢，请登录再投票哦");
		return false;
	}
	if(bkey ==0){
		alert("投票已经截止了，谢谢关注^_^");
		return false;
	}
	if(bkey ==9){
		alert("数据不完整,请重新投票哦");
		return false;
	}
	if(bkey == 10 || bkey==13){
		alert("你已经投过票了哦");
		return false;
	}
	if(bkey == 11){
		alert('你不能投自己的稿件哦');
		return false;
	}
	if(bkey == 12){
		alert('此任务中，你已经投了 5 票，到上限了');
		return false;
	}
	if(bkey == 14){
		alert('此稿件是为发布者可见，不能投票');
		return false;
	}
	if(bkey == 15){
		if(confirm('您没有通过实名认证，不能投票,现在要实名认证吗？')){
			location.href="http://www.zhubajie.com/ework/?mod=profile&com=certification";
		}
		return false;
	}
}

function getElement(aID){
	return (document.getElementById) ? document.getElementById(aID): document.all[aID];

}

function outnew(url,title,width,height){
	var w = 1024;
	var h = 768;

	if (document.all || document.layers){
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var leftPos = (w/2-width/2);
	var topPos = (h/2.3-height/2.3);

	window.open(url,title,"width="+width+",height="+height+",top="+topPos+",left="+leftPos+",scrollbars=no,resizable=no,status=no")
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll);
	return arrayPageScroll;
}


function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}



function showmybox()
{	
	var objOverlay = getElement('overlay');
	//var objmybox = getElement('mybox');
	var arrayPageSize = getPageSize();
	//var arrayPageScroll = getPageScroll();
	//set height of Overlay to take up whole page and show
	objOverlay.style.width = (arrayPageSize[0] + 'px');
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'inline';

	//objmybox.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 400) / 2) + 'px');
	//objmybox.style.left = ((arrayPageSize[0]-640)/2 + 'px');
	//objmybox.style.width = "640px";
	//objmybox.style.display = 'inline';
	//objmybox.innerHTML = tabstr;

}

function hidelay(box)
{
	// get objects
	var objOverlay = getElement('overlay');
	var objbox = getElement("mybox");

	// hide mybox and overlay
	objOverlay.style.display = 'none';
	objbox.style.display = 'none';

	// make select boxes visible
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

function initmybox()
{
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function (){return false;}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '99';
	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);

	//var objmybox = document.createElement("div");
	//objmybox.setAttribute('id','mybox');
	//objmybox.style.display = 'none';
	//objmybox.style.position = 'absolute';
	//objmybox.style.zIndex = '100';	
	//objBody.insertBefore(objmybox, objOverlay.nextSibling);
}

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}

}
//addLoadEvent(initmybox);
// run initmybox onLoad
