var surveyNumQuestions=0;var maxQuestions=50;var maxQuestionId=0;function surveyAddQuestions(num){for(i=0;i<num;i++){surveyAddQuestion("");}}
function surveyAddQuestion(text,id){var questions=document.getElementById("surveyQuestions");var h4=document.createElement("h4");var input=document.createElement("input");var a=document.createElement("a");if(surveyNumQuestions>=maxQuestions)return;var i=(id!=null?id:maxQuestionId+1);h4.innerHTML='Question';h4.setAttribute("id","questionLabel_"+i);input.setAttribute("type","text");input.setAttribute("width","300");input.setAttribute("class","surveyQuestion");input.setAttribute("id","questionText_"+i);input.setAttribute("name","questionText["+i+"]");input.value=text;a.innerHTML="remove";a.setAttribute("id","questionRemove_"+i);a.href="javascript:surveyRemoveQuestion("+i+");";questions.appendChild(h4);questions.appendChild(input);questions.appendChild(document.createTextNode(" "));questions.appendChild(a);maxQuestionId=i;if(++surveyNumQuestions>=maxQuestions)document.getElementById("surveyAddQuestion").style.display="none";}
function surveyRemoveQuestion(id){var questions=document.getElementById("surveyQuestions");if(--surveyNumQuestions==maxQuestions-1)document.getElementById("surveyAddQuestion").style.display="block";questions.removeChild(document.getElementById("questionLabel_"+id));questions.removeChild(document.getElementById("questionText_"+id));questions.removeChild(document.getElementById("questionRemove_"+id));}
function gotoCategory(cat){if(!cat){location.href='/surveys/view';}
else{location.href='/surveys/view?cat_id='+cat;}}
var openmenu;var clickcount=0;var username;var currentZIndex=10;function menuShowSurveys(ob,uid,usn){var m=ob.getElementsByTagName('ul')[0];m.blur();if(openmenu==m)return;if(openmenu){openmenu.style.left='-999px';openmenu=null;}
if(username){username.className='';}
username=ob.getElementsByTagName('a')[0];ob.style.zIndex=++currentZIndex;currentShow=ob;username.className='highlight';openmenu=m;document.onclick=menuHideSurveys;clickcount=0;m.innerHTML='<li><a href="/home/'+usn+'">View Profile</a></li> <li><a href="/messages/send.php?invited_user_id='+uid+'">Add to Friends</a></li> <li><a href="/messages/send.php?to_user_id='+uid+'">Send a Message</a></li><li><a href="/surveys/archive?type=user_surveys&user='+uid+'">View Surveys</a></li></li>';m.style.left='auto';}
function menuHideSurveys(e){var target=(typeof e=='undefined'?event.srcElement.parentNode.parentNode:e.target.parentNode.parentNode);if(!openmenu||!target)return;if(clickcount++>0){if(target!=openmenu){openmenu.style.left='-999px';openmenu=null;document.onclick=null;username.className='';}}}
var max_stars=5;var holder;var preSet;var rated=1;function rating(vote){if(!rated){setStars(vote);}}
function setStars(vote){a=0;for(i=1;i<=max_stars;i++){if(i<=vote){document.getElementById("star"+i).className="on";holder=a+1;a++;}else{document.getElementById("star"+i).className="";}}}
function rating_off(num){if(!rated){if(!preSet){for(i=1;i<=max_stars;i++){document.getElementById("star"+i).className="";}}else{rating(preSet);}}}
function rateSurvey(id,vote){if(!rated){preSet=vote;rated=1;sendRate(id,vote);rating(vote);}}
function configRating(current_rating,taken,voted){if(document.getElementById("surveyRate")==undefined){return false;}
else if(!taken||(taken&&voted)){rated=1}
else{rated=0;}
num=Math.round(current_rating);setStars(num);preSet=num;}
function sendRate(id,vote){ajax_getPage('/quizzes/actions/survey_rate_action.php?id='+id+'&rating='+vote,function(data){});return;}
