function search(selectType,searchWord)
{
	if (searchWord.value == "")
	{
		alert("请输入搜索关键词");
		searchWord.focus();
	}
	else
	{
		var url = "http://" + window.location.host + window.location.pathname + "?template=search&type="+selectType.value + "&searchWord="+ searchWord.value;
		url = encodeURI(url);		
		window.location.href = url;
		//window.open(url,"blank");
	}
}
function cursorChange(obj)
{
	obj.style.cursor = "hand";
}
function vote(survey)
{
	var checked = false; //记录每一条是否选中
	var checkedAll = false; //检查全部问题是否都回答完
	var questionIds = survey.innerHTML;	//获取到问题的ID，格式为：1，2，3
	question = survey.innerHTML.split(','); //获取各问题的ID
	//检测是否选中，如果未选中则提示，如果选中，则循环提交
	for (var i = 0; i < question.length; i++)
	{
		var options = document.getElementsByName(question[i]);//得到问题组		
		//读取问题组中选中项的值，并加入questionIds
		for (var j = 0; j < options.length; j++)
		{
			if (options[j].checked)
			{
				//alert(options[j].value);				
				checked = true;
			}			
		}
		if (checked)//加入无选中项，发出提示
		{
			checkedAll = true;
			checked = false;			
		}else
		{
			checkedAll = false;
			alert("请您选择投票选项！投票有遗漏！");			
			break;
		}
	}	
	if (checkedAll)	
	{
		var voteSuccess = false;
		//根据各问题ID读取其中选中项的ID
		for (var i = 0; i < question.length; i++)
		{
			var questionIdsEvery = question[i];
			//alert(question[i]);
			var options = document.getElementsByName(question[i]);//得到问题组
			//alert(options.length);
			//读取问题组中选中项的值，并加入questionIds
			for (var j = 0; j < options.length; j++)
			{
				if (options[j].checked)
				{
					//alert(options[j].value);
					questionIdsEvery += "," + options[j].value;				
				}
				//alert(options[j].checked);
			}		
			createXMLHttpRequest();		
			var url = "http://" + window.location.host + window.location.pathname + "servlet/ChangeChooseTimeServlet.do?questionIds=" + questionIdsEvery;		
			//alert(url);
			xmlHttp.open("POST",url,false);
			xmlHttp.send();		
			if (xmlHttp.status == 200 && xmlHttp.responseText=="addSuccess")
			{
		    	voteSuccess = true;		    	        	
		    }
		    else
		    {
		    	voteSuccess = false;
		    	  
		    }
			//alert(url);		
		}
		if (voteSuccess)
		{
			if (window.confirm("感谢您的投票，是否查看调查结果？"))
		    {
		    	showVoteResult(survey);
		    }
		}
		else
		{
			if(window.confirm("感谢您的投票，可能由于网络原因您此次投票没有成功，是否查看投票结果？"))
		    {
		    	showVoteResult(survey);
		    } 		
		}
	}	
}
function showVoteResult(survey)
{
	var urlResult = "http://" + window.location.host + window.location.pathname + "?template=wenjuandiaocha&questionIds=" + survey.innerHTML;
	window.open(urlResult,"_blank");
}
var xmlHttp;
//创建XMLHttpRequest对象
function createXMLHttpRequest()
{
    if (window.ActiveXObject)
    {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");        
    }
    else if (window.XMLHttpRequest)
    {
        xmlHttp = new XMLHttpRequest();        
    }
}

function showChildCatalog(obj,owner)
{
	//var objA = getInfo(obj);
	var ownerA = getInfo(owner);
	childCatalog.style.position = 'absolute';
	childCatalog.style.posLeft=ownerA.left;	
	childCatalog.style.posTop=ownerA.top + 20;	
	childCatalog.innerHTML = obj.innerHTML;	
}
function getInfo(obj)
{
	 var to=new Object();                                      //建立临时对象
     to.left=to.right=to.top=to.bottom=0;                      //为临时对象增加左右上下边界的位置属性，并初始值均为0
     var twidth=obj.offsetWidth;                                 //建立临时宽度变量，值等于参数对象的宽度
     var theight=obj.offsetHeight;                               //建立临时高度变量，值等于参数对象的高度
     while(obj!=document.body && obj!=document.html)
     {                                  //如果参数对象不是<body>---设置临时对象的左边界为相对于<body>体的左边界
        to.left+=obj.offsetLeft;                                   //临时对象的左边界等于参数对象的左边界+临时对象的上次左边界
        to.top+=obj.offsetTop;                                     //临时对象的左边界等于参数对象的左边界+临时对象的上次顶边界
        obj=obj.offsetParent;                                        //将对象设置为包含此对象的父对象
     }
     to.right=to.left+twidth;                                 //设置临时对象的右边界属性
     to.bottom=to.top+theight;                               //设置临时对象的底边界属性
     return to; 
}
//for onlinequestion search
function searchQuestion(searchType,keyWord)
{	
	if (keyWord.value != "请输入" && keyWord.value != ""&& searchType.value == "searchCondition")
	{
		alert("请选择查询条件！");
		searchType.foucs();
		return false;
	}
	else
	{
		var url = "http://" + window.location.host + window.location.pathname + "?template=onlinepaging&type=OnlineQuestion&sortName=服务通道-在线问答&searchType="+searchType.value + "&keyWord="+ keyWord.value;
		url = encodeURI(url);
		window.open(url,"_self");
	}
		
}
function changeInputState(obj){
	obj.focus();
	if(obj.value == "请输入")
		obj.value = "";
}

function onchangeCondition(obj){
	if(obj.value == "searchCondition" )
		document.getElementById("keyWord").value = "请输入";
}
function onloadCondition(){
	var hiddensearchType = document.getElementById("hiddensearchType").value;
	document.getElementById("searchType").value = hiddensearchType;
}


function searchIndex(selectType,searchWord)
{
	if (searchWord.value == "")
	{
		alert("请输入搜索关键词");
		searchWord.focus();
	}
	else
	{
		var url = "http://" + window.location.host + window.location.pathname + "?template=search&type="+selectType + "&searchWord="+ searchWord.value;
		url = encodeURI(url);
		window.location.href = url;
		//window.open(url,"blank");
	}
}

