function getQuestions()
{
	var allanids = "";
	var questions = document.getElementsByName("question");
	if(questions)
	{
		for(var q=0;q<questions.length;q++)
		{
			var anids = checkQanswers(questions[q].value);
			if(anids!=null)
			{
				allanids = allanids+anids;
			}
			else
			{
				alert("\u6709\u95ee\u9898\u6ca1\u6709\u9009\u62e9\u7b54\u6848!");
				return null;
			}
		}
	}
	return allanids;
}


function formReset()
{
	document.qform.reset();
}

function pageRefresh()
{
	window.location.reload();
}

function invpinit()
{
	var project_status = parseInt(document.subform.pstatus.value);
	if(project_status!=0)
	{
		document.getElementById("votebtn").disabled = true;
	}
	
	var expdate = document.getElementById("expdate").value;
	
	if("0"!=expdate && expdate.length>=10)
	{
		expdate = expdate.replace(/-0/g,"-");
		var sml = expdate.lastIndexOf("-");				//secondminuslocation
		//alert(expdate+"\n"+sml);
		var _expdate = new Date(parseInt(expdate.substring(0,4)),parseInt(expdate.substring(5,sml))-1,parseInt(expdate.substring((sml+1),10)));
		var _today = new Date();
		if(_expdate<_today)
		{
			alert("This project has been closed!");
			document.getElementById("votebtn").disabled = true;
			document.getElementById("expdate").value=1;
		}
	}
}

function checkQanswers(qid)
{
	var anids = "";
	var answers = document.getElementsByName("answerofq"+qid);
	if(answers)
	{
		for(var a=0;a<answers.length;a++)
		{
			if(answers[a].checked)
			{
				//anids = anids+answers[a].value+",";
				anids = anids+ filterAnid(answers[a].value)+",";
			}
		}
	}
	if(anids.length<2)
		return null;
	else
		return anids;
}


function filterAnid(_value)
{
	if(_value.indexOf("@")>0)
	{
		return _value.substring(0,_value.indexOf("@"));
	}
	return _value;
}

function submitMyAnswers()
{
	var answer_ids = getQuestions();
	if(answer_ids!=null && answer_ids.length>2)
	{
		//alert(answer_ids);
		document.subform.answerids.value = answer_ids;
		document.subform.submit();
	}
}

function viewResult()
{
	window.open('../vote/lookvote_more.jsp?pid='+document.subform.pid.value);
}

