	var bValidForm=true
	var QuestionsHTML=""
	function fPollVote(qid, onlyVote, qRedir, bHideReturn){
		var frm=document.forms["PL_vote" + qid]
		if(!frm) frm=document.forms["PL_vote"]
		var AnsId=frm.selectedRadio.value||null
		if(onlyVote && !AnsId){
			alert("עליך לבחור תשובה")
			bValidForm=false
			return
		}
		if(!onlyVote) AnsId=null
		//window.open("/ajaxFiles/PollVote.asp?Qid=" + qid + "&Ansid=" + AnsId)
		//return
		doAjaxRequest("/ajaxFiles/PollVote.asp", {Qid:qid,Ansid:AnsId,Rand:Math.random()},{
						method:"GET",
						onSuccess:(qRedir?fQuestionaryRedir:fDisplayPoll),
						onSuccessParams:qid,
						onFailure:fPollFailure
					});
		try{document.getElementById("oReturn" + qid).style.display=(onlyVote?"none":"")}catch(e){}
		if(bHideReturn==3) try{document.getElementById("oReturn" + qid).style.display="none"}catch(e){}
		if(onlyVote){
			try{
				var n=document.getElementById("oPollHits" + qid).innerText
				n*=1
				document.getElementById("oPollHits" + qid).innerText=(n+1)
			}catch(e){}
		}
	}

	function fPollFailure(){
		alert("error")
	}

	function fDisplayPoll(oReq, qid){
		var xml = oReq.responseXML, oDoc = xml.documentElement, oNodes= oDoc.getElementsByTagName("answer") , Item
		var str="", oAnsArr=[]
		for (i = 0; i < oNodes.length; i++) { 
		   Item = oNodes.item(i); 
		   //str+="Name: " + Item.getAttribute("title") + ", Votes: " + Item.getAttribute("votes") + "\n"
		   oAnsArr[i]=[Item.getAttribute("title"),Item.getAttribute("votes")]
		}
		fBuildGraph(oAnsArr, qid)
	}

	function fBuildGraph(g,qid){
		var total=0, output, calpercentage, calwidth, gwidth=160, str=""
		for (var i=0;i<g.length;i++)
			total+=parseInt(g[i][1])
		output='<table border="0" cellspacing="0" cellpadding="0">'
		for (var i=0;i<g.length;i++){
			calpercentage=Math.round(g[i][1]*100/total)
			calwidth=Math.round(gwidth*(calpercentage/100))
			if(!calpercentage)calpercentage=0
			if(!calwidth)calwidth=1
			
			var sColor="ACD949"
			if(i%4==1) sColor="FFB72A"
			if(i%4==2) sColor="FF9088"
			if(i%4==3) sColor="CAC4C4"
			
			str +=(calwidth + " --> " + calpercentage + "\n")
			output+='<tr><td></td><td style=\"color:#000066; font-size:11px; font-weight:800; padding-bottom:5px;\">'+g[i][0]
			output+='<br /><img src="/images/PollResults_'+sColor+'.gif" style=\"border-right:'+(calwidth)+'px solid #'+sColor+'\" />'
			output+='&nbsp; <span style="color:#'+sColor+'; font:15px Georgia; font-weight:800;">'+calpercentage+'%</span>'
			output+='</td></tr>'
		}
		output+='</table>'
		QuestionsHTML=document.getElementById("oPollDiv"+qid).innerHTML
		document.getElementById("oPollDiv"+qid).innerHTML=output
		try{document.getElementById("oResultData"+qid).style.display=""}catch(e){}
		try{document.getElementById("oPollBtn" + qid).style.display="none";}catch(e){}
	}

	function fCheckAnswers(frm){
		var strIds=frm.strIds.value.split(",")
		for (var i=0; i<strIds.length-1; i++){
			if(!isChecked(frm["quest" + strIds[i]])){
				alert("עליך לענות על כל השאלות")
				return false
			}
		}
		if(!fisValidEmail(frm.sEmail.value)){
			alert("כתובת דואר אלקטרוני לא חוקית")
			return false
		}
		return true
	}

	function fQuestionaryRedir(oReq, id){
		if(bValidForm)location.href="/questionaryAsk.asp?id=" + id
	}

	function fReturnToPoll(qid){
		document.getElementById("oPollDiv"+qid).innerHTML=QuestionsHTML
		document.getElementById("oReturn" + qid).style.display="none"
		try{document.getElementById("oResultData"+qid).style.display="none"}catch(e){}
		try{document.getElementById("oPollBtn" + qid).style.display="";}catch(e){}
	}

function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else 
      window.onload = fnc;
  }
}

