
function setTopic(topic,index)
{if(topic=='new')
{$('#current_topic_container').html('');$('#current_title').val('');$('#current_answer').val('');$('#new_topic').removeClass('invisible');$('#remove_topic').addClass('invisible');}
else
{$('#current_topic_container').html($("#"+topic).html());if($('#new_topic').size()>0)
{$('#current_title').val('');$('#current_answer').val('');$('#new_topic').addClass('invisible');$('#remove_topic').removeClass('invisible');}
else
{$('#current_title').html('');$('#current_answer').html('');}
$('#topic')[0].selectedIndex=index;}}
function addTopic(title)
{var xmlFile=$('#xmlFile').val();$('#new_topic_msg').html('Topic: '+title+" added!");var id=setIdFromTitle(title);var newOptionElement=document.createElement('option');newOptionElement.innerHTML=title;newOptionElement.value=id;$(newOptionElement).appendTo($("#topic"));var containerDiv=$('#admin_common_questions');var newTopicDiv=document.createElement('div');newTopicDiv.id=id;newTopicDiv.className='invisible';newTopicDiv.innerHTML="<input type='hidden' id=\""+id+"_question_count\" name=\""+id+"_question_count\" value='0' />";$(newTopicDiv).appendTo($(containerDiv));var res=ajaxAddTopic(id,title,xmlFile);setTimeout("$('#new_topic').addClass('invisible');",2000);setTimeout("clearNewTopicForm()",2000);setTimeout("updateTopics()",2000);setTimeout("addQuestion($('#current_question_form'))",2200);}
function removeTopic(selectElement)
{var xmlFile=$('#xmlFile').val();var res=ajaxRemoveTopic(selectElement.value,xmlFile);var index=selectElement.selectedIndex;var oldTopicId=selectElement.options[index].value;$("#"+oldTopicId).remove();var newIndex=index-1;selectElement.remove(index);var topicId=selectElement.options[newIndex].value;setTopic(topicId,newIndex);}
function updateTopics()
{var lastIndex=$("#topic option").length-1;$("#topic")[0].selectedIndex=lastIndex;setTopic($('#topic').val(),lastIndex);}
function clearNewTopicForm()
{$('#new_topic_msg').html('');$('#new_topic_title').val('');}
function setIdFromTitle(title)
{var id=title;var tmpId=id.toLowerCase();var newId="";var splitstring=tmpId.split(" ");for(i=0;i<splitstring.length;i++)
{newId+=splitstring[i]+"_";}
newId=newId.substring(0,newId.length-1);return newId;}
function setQuestion(topicId,questionId)
{var titleId=topicId+"_"+questionId+"_title";var answerId=topicId+"_"+questionId+"_answer";if($('#new_topic').size()>0)
{$("#current_title").attr('disabled',"disabled");$("#current_answer").attr('disabled',"disabled");$("#current_title").val($("#"+titleId).html());$("#current_answer").val($("#"+answerId).html());$("#current_topic").val($('#topic').val());$("#current_question").val(questionId);}
else
{$("#current_title").html($("#"+titleId).html());$("#current_answer").html($("#"+answerId).html());}
$("#current_topic_container div").each(function()
{var $this=$(this);if($this.attr("id"))
{if($this.attr('id').indexOf(topicId)>=0)
{$this.removeClass("current_question");}}});$("#"+topicId+"_"+questionId).addClass("current_question");}
function addQuestion()
{var xmlFile=$('#xmlFile').val();var topicId=$('#topic').val();var topicDiv=$(topicId);var currentTopicDiv=$('#current_topic_container');var questionCountId='#current_topic_container'+' #'+topicId+'_question_count';var currentQuestionNumber=$(questionCountId).val();var newQuestionId=parseInt(currentQuestionNumber)+1;var id=topicId+"_"+newQuestionId;$("#current_title").val('&nbsp;');$("#current_answer").val('&nbsp;');var newQuestionDiv1=document.createElement('div');newQuestionDiv1.id=id;newQuestionDiv1.innerHTML="<input type='button' onClick='removeQuestion(\""+topicId+"\",\""+newQuestionId+"\");return false;' value='-' />"+"&nbsp;&nbsp;&nbsp;"+newQuestionId+":<a href='#' onClick='setQuestion(\""+topicId+"\",\""+newQuestionId+"\");return false;'> <span id='"+id+"_title'>&nbsp;</span> </a>";var newQuestionAnswerDiv=document.createElement('div');newQuestionAnswerDiv.innerHTML="&nbsp;";newQuestionAnswerDiv.id=id+"_answer";newQuestionAnswerDiv.className='invisible';$(newQuestionDiv1).appendTo($(currentTopicDiv));$(newQuestionAnswerDiv).appendTo($(newQuestionDiv1));$(questionCountId).val(newQuestionId);topicDiv.html(currentTopicDiv.html());setQuestion(topicId,newQuestionId);$("#current_title").attr('disabled',false);$("#current_answer").attr('disabled',false);ajaxAddQuestion(topicId,newQuestionId,xmlFile);}
function saveQuestion()
{var xmlFile=$('#xmlFile').val();var topicId=$('#topic').val();var topicDiv=$("#"+topicId);var titleContent=$("#current_title").val();var answerContent=$("#current_answer").val();var questionId=$("#current_question").val();var titleId=topicId+"_"+questionId+"_title";var answerId=topicId+"_"+questionId+"_answer";$("#"+titleId).html(titleContent);$("#"+answerId).html(answerContent);topicDiv.html($('#current_topic_container').html());$("#current_title").attr('disabled',"disabled");$("#current_answer").attr('disabled',"disabled");saveAddQuestion(topicId,questionId,titleContent,answerContent,xmlFile);}
function removeQuestion(topicId,questionId)
{var xmlFile=$('#xmlFile').val();var questionElemId=topicId+"_"+questionId;$("#"+questionElemId).remove();$("#"+questionElemId).remove();removeAddQuestion(topicId,questionId,xmlFile);}
function ajaxAddTopic(topicId,title,xmlFile)
{strUrl="/pages/faqEditor.php";var retHtml="";var action="addTopic";$.ajax({url:strUrl,cache:false,type:'post',datatype:'html',timeout:1000,async:false,data:{"xmlAction":action,"topicId":topicId,"title":title,"xmlFile":xmlFile},error:function(){},success:function(html){retHtml=html;}});return retHtml;}
function ajaxRemoveTopic(topicId,xmlFile)
{strUrl="/pages/faqEditor.php";var retHtml="";var action="removeTopic";$.ajax({url:strUrl,cache:false,type:'post',datatype:'html',timeout:1000,async:false,data:{"xmlAction":action,"topicId":topicId,"xmlFile":xmlFile},error:function(){},success:function(html){retHtml=html;}});return retHtml;}
function ajaxAddQuestion(topicId,questionId,xmlFile)
{strUrl="/pages/faqEditor.php";var retHtml="";var action="addQuestion";$.ajax({url:strUrl,cache:false,type:'post',datatype:'html',timeout:1000,async:false,data:{"xmlAction":action,"topicId":topicId,"questionId":questionId,"xmlFile":xmlFile},error:function(){},success:function(html){retHtml=html;}});return retHtml;}
function removeAddQuestion(topicId,questionId,xmlFile)
{strUrl="/pages/faqEditor.php";var retHtml="";var action="removeQuestion";$.ajax({url:strUrl,cache:false,type:'post',datatype:'html',timeout:1000,async:false,data:{"xmlAction":action,"topicId":topicId,"questionId":questionId,"xmlFile":xmlFile},error:function(){},success:function(html){retHtml=html;}});return retHtml;}
function saveAddQuestion(topicId,questionId,title,answer,xmlFile)
{strUrl="/pages/faqEditor.php";var retHtml="";var action="saveQuestion";$.ajax({url:strUrl,cache:false,type:'post',datatype:'html',timeout:1000,async:false,data:{"xmlAction":action,"topicId":topicId,"questionId":questionId,"title":title,"answer":answer,"xmlFile":xmlFile},error:function(){},success:function(html){retHtml=html;}});return retHtml;}