ajaxErrorFunction=function(req){alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
editMode=false;function editfaq(){AjaxRequest.get({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'edit','chapterid':current_chapter},'onSuccess':function(req){document.getElementById('chaptercontent').innerHTML=req.responseText;editMode=true;},'onError':function(req){ajaxErrorFunction(req)}});}
function viewfaq(){AjaxRequest.get({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'view','chapterid':current_chapter},'onSuccess':function(req){document.getElementById('chaptercontent').innerHTML=req.responseText;editMode=false;},'onError':function(req){ajaxErrorFunction(req)}});}
function previewPage(){AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'message':document.getElementById('message').value,'action':'preview','chapterid':current_chapter},'onSuccess':function(req){document.getElementById('preview_container').innerHTML=req.responseText;location.hash="preview_anchor";},'onError':function(req){ajaxErrorFunction(req)}});}
function cancelEdit(){AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'cancel','chapterid':current_chapter},'onSuccess':function(req){document.getElementById('chaptercontent').innerHTML=req.responseText},'onError':function(req){ajaxErrorFunction(req)}});}
function savepage(action,change_desc){AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'message':document.getElementById('message').value,'action':action,'chapterid':current_chapter,'change_desc':document.getElementById(change_desc).value},'onSuccess':function(req){document.getElementById('chaptercontent').innerHTML=req.responseText;if(document.getElementById('imagepicker')){document.getElementById('imagepicker').options[imagepicker_index].selected=true;getImages();}},'onError':function(req){ajaxErrorFunction(req)}});}
function save(action){}
function createNewSection(){oEl=document.getElementById('sectionName');AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'chapter_title':oEl.value,'action':'newChapter'},'onSuccess':function(req){document.getElementById('chapter_container').innerHTML=req.responseText;makeSortables('chapter_listing','div','chapter_');current_chapter=document.getElementById('chapter_listing').lastChild.id.replace(/handle_/,"");chapTitle=document.getElementById('chapter_'+current_chapter).innerHTML;updateChapterTitleOnPage(current_chapter,'innerHTML');},'onError':function(req){ajaxErrorFunction(req)}});}
function makeSortables(elementId,childTag,childTagId){oEl=document.getElementById(elementId);if(oEl){for(count=0;count<oEl.childNodes.length;count++){if(oEl.childNodes[count].nodeName.toLowerCase()==childTag&&oEl.childNodes[count].id.indexOf(childTagId)==0){}}
Sortable.create(elementId,{tag:childTag,onUpdate:updateChapters});}}
editingChapters=false;function editchapters(){action='';if(editingChapters){document.getElementById('editChaptersLink').innerHTML="Edit Chapters";action='viewChapters';}else{document.getElementById('editChaptersLink').innerHTML="View Chapters";action='editChapters';}
editingChapters=!editingChapters;AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':action,'chapterid':current_chapter},'onSuccess':function(req){document.getElementById('chapter_container').innerHTML=req.responseText;makeSortables('chapter_listing','div','chapter_');},'onError':function(req){ajaxErrorFunction(req)}});}
function updateChapters(){AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'current_chapter':current_chapter,'action':'updateChapterOrder','changed_chapter':changed_chapter,'order':Sortable.serialize('chapter_listing',{tag:'div',name:'chapter_listing'})},'onSuccess':function(req){document.getElementById('chapter_container').innerHTML=req.responseText;makeSortables('chapter_listing','div','chapter_');chapters=document.getElementById('chapter_listing').getElementsByTagName('a');for(var i=0;i<chapters.length;i++){document.getElementById('imagepicker').options[parseInt(i+2)].text=chapters[i].innerHTML
document.getElementById('videopicker').options[parseInt(i+2)].text=chapters[i].innerHTML}},'onError':function(req){ajaxErrorFunction(req)}});}
function deleteChapter(evt,chapterId){if(!evt)evt=window.event;if(evt.screenX==mouse_x_pos){current_chapter=chapterId;if(confirm('Please Confirm you want to permanently delete this chapter')){AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'deleteChapter','chapterid':chapterId,'current_chapter':current_chapter},'onSuccess':function(req){document.getElementById('chapter_container').innerHTML=req.responseText;makeSortables('chapter_listing','div','chapter_')},'onError':function(req){ajaxErrorFunction(req)}});}}}
function approve_chapter(chapterId){if(confirm('This chapter is currently only visible to authors of this vfag.\n Is this chapter ready to be shown to the neoseeker community?')){AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'approveChapter','chapterid':chapterId},'onSuccess':function(req){document.getElementById('handle_'+chapterId).getElementsByTagName('img')[0].style.display='none';if(document.getElementById('chapter_msg')){document.getElementById('chapter_msg').style.display='none'}},'onError':function(req){ajaxErrorFunction(req)}});}}
function updateChapterTitle(chapterId,chapTitle){if(document.getElementById('chapter_'+chapterId).value.length>0){AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'updateChapterTitle','title':document.getElementById('chapter_'+chapterId).value,'chapterid':chapterId,'current_chapter':current_chapter},'onSuccess':function(req){document.getElementById('chapter_container').innerHTML=req.responseText;makeSortables('chapter_listing','div','chapter_');chapters=document.getElementById('chapter_listing').getElementsByTagName('a');for(var i=0;i<chapters.length;i++){document.getElementById('imagepicker').options[parseInt(i+2)].text=chapters[i].innerHTML
document.getElementById('videopicker').options[parseInt(i+2)].text=chapters[i].innerHTML}},'onError':function(req){ajaxErrorFunction(req)}});}else{alert('Chapter name cannot be blank');}}
function updateChapterTitleOnPage(chapterId,oElProperty){chapTitle=document.getElementById('chapter_'+chapterId)[oElProperty].replace(/</g,"&lt;");chapTitle=chapTitle.replace(/>/g,"&gt;");document.title=pageTitle+': '+chapTitle
document.getElementById('pagetitle').innerHTML=document.title;}
originalHTML='';editingChapter='';editingChapterText='';function editChapterName(evt,chapterId){if(!evt)evt=window.event;if(evt.screenX==mouse_x_pos){editingChapter=chapterId;editingChapterText=document.getElementById('chapter_'+editingChapter).innerHTML;setTimeout("editChapterNameFromTimeout(editingChapter);",100)}}
function editChapterNameFromTimeout(chapterId){chapterElement=document.getElementById('handle_'+chapterId);originalHTML=chapterElement.innerHTML;chapterElement.innerHTML="<img class='hand_cursor' alt='Save' title='Save' src='http://i.neoseeker.com/v/page_tick.gif' onclick='updateChapterTitle(\""+chapterId+"\")'>"+"<img class='hand_cursor' alt='Cancel' title='Cancel' src='http://i.neoseeker.com/v/delete.gif' onclick='cancelChapterName(\""+chapterId+"\")'>"+"<input type='text' id='chapter_"+chapterId+"' value='"+editingChapterText+"' onkeypress='checkforsubmit_edit(event,\""+chapterId+"\")'>";}
function cancelChapterName(chapterId){document.getElementById('handle_'+chapterId).innerHTML=originalHTML;}
function checkforsubmit_edit(e,chapterId){if(checkForEnterKey(e))updateChapterTitle(chapterId)}
function checkForEnterKey(e){if(!e)e=window.event;if(window.event)
{keynum=e.keyCode}
else if(e.which)
{keynum=e.which}
keychar=String.fromCharCode(keynum)
numcheck=/[\r]/return numcheck.test(keychar)}
rupAction='';rupIndex=0;rupHTMLid='';function uploadCompleted(){switch(rupAction){case'reloadimage':case'reloadvideo':oldurl=document.getElementById("resource_image_"+rupHTMLid).src
document.getElementById("resource_image_"+rupHTMLid).src='';document.getElementById("resource_image_"+rupHTMLid).src=oldurl+"?refresh";break;default:chapter_selection=document.getElementById('imagepicker')[document.getElementById('imagepicker').selectedIndex].value;if(document.rup_video&&document.rup_video.getUploadStatus()==1){AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'get_resource_table','chapterid':current_chapter,'resourcetype':'video'},'onSuccess':function(req){document.getElementById('video_container').innerHTML=req.responseText;},'onError':function(req){ajaxErrorFunction(req)}});}else{AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'get_resource_table','chapterid':chapter_selection,'resourcetype':'image'},'onSuccess':function(req){document.getElementById('image_container').innerHTML=req.responseText;},'onError':function(req){ajaxErrorFunction(req)}});}}}
imagepicker_index=-1;function getResources(selectElName,resourceType){index=document.getElementById(selectElName).selectedIndex;imagepicker_index=index;AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'get_resource_table','chapterid':document.getElementById(selectElName).options[index].value,'resourcetype':resourceType},'onSuccess':function(req){document.getElementById(resourceType+'_container').innerHTML=req.responseText;},'onError':function(req){ajaxErrorFunction(req)}});}
function getImages_edit(){index=document.getElementById('imagepicker').selectedIndex;imagepicker_index=index;AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'view_images','current_chapter':current_chapter,'chapterid':document.getElementById('imagepicker').options[index].value},'onSuccess':function(req){document.getElementById('chaptercontent').innerHTML=req.responseText;},'onError':function(req){ajaxErrorFunction(req)}});}
function getVideos_edit(){index=document.getElementById('videopicker').selectedIndex;videopicker_index=index;AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'view_videos','current_chapter':current_chapter,'chapterid':document.getElementById('videopicker').options[index].value},'onSuccess':function(req){document.getElementById('chaptercontent').innerHTML=req.responseText;},'onError':function(req){ajaxErrorFunction(req)}});}
mouse_x_pos=0;function getChapterPos(evt){if(!evt)evt=window.event;mouse_x_pos=evt.screenX;}
function checkChapterPos(evt,chapter_id){if(!evt)evt=window.event;if(evt.screenX==mouse_x_pos){current_chapter=chapter_id;if(editMode){editfaq();}else{viewfaq();}
updateChapterTitleOnPage(current_chapter,'innerHTML');editingChapters=!editingChapters;editchapters();}}
imageupload_timer='';function getImageUploader(radHTMLid,raduploadIndex){document.getElementById(radHTMLid).style.display='block';imageid=radHTMLid.substr(radHTMLid.indexOf("_")+1);rupAction='reloadimage';rupIndex=raduploadIndex;rupHTMLid=imageid;}
function updateimage(elementId,indexId){if(document.rup[indexId]){rup=document.rup[indexId];}else{rup=document.rup;}
if(rup.getUploadStatus()==1){oldurl=document.getElementById("resource_image_"+elementId).src
document.getElementById("resource_image_"+elementId).src='monjey.gif';document.getElementById("resource_image_"+elementId).src=oldurl+"?refresh";clearInterval(imageupload_timer)}}
imageupload_timer='';function getVideoUploader(radHTMLid,raduploadIndex){document.getElementById(radHTMLid).style.display='block';videoid=radHTMLid.substr(radHTMLid.indexOf("_")+1);rupAction='reloadvideo';rupIndex=raduploadIndex;rupHTMLid=videoid;}
function update_videos(){index=document.getElementById('videopicker').selectedIndex;AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'update_video_info','titles':serialize('input','video_title'),'descriptions':serialize('input','video_description'),'chapterid':document.getElementById('videopicker').options[index].value},'onSuccess':function(req){document.getElementById('video_container').innerHTML=req.responseText;},'onError':function(req){ajaxErrorFunction(req)}});}
function deleteImage(imageid){deleteConfirm=false;if(document.getElementById('image_list_'+imageid)){deleteConfirm=confirm('Image is linked in '+document.getElementById('image_list_'+imageid).getElementsByTagName("li").length+' chapter(s).\nDeleting the image will result in a broken link.\nConfirm you want to permanently delete this image')}else{deleteConfirm=confirm('Confirm you want to permanently delete this image')}
if(deleteConfirm){AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'delete_resource','resourceid':imageid},'onSuccess':function(req){document.getElementById('resource_'+imageid).innerHTML=''},'onError':function(req){ajaxErrorFunction(req)}});}}
function deleteVideo(videoid){deleteConfirm=false;if(document.getElementById('video_list_'+videoid)){deleteConfirm=confirm('Video is linked in '+document.getElementById('video_list_'+videoid).getElementsByTagName("li").length+' chapter(s).\nDeleting the video will result in a broken link.\nConfirm you want to permanently delete this video')}else{deleteConfirm=confirm('Confirm you want to permanently delete this video')}
if(deleteConfirm){AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'delete_resource','resourceid':videoid},'onSuccess':function(req){document.getElementById('resource_'+videoid).innerHTML=''},'onError':function(req){ajaxErrorFunction(req)}});}}
function changeresource_ref(resourceid){selectedIndex=document.getElementById('resourcepicker_'+resourceid).selectedIndex;AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'update_resource_ref','resourceid':resourceid,'chapterid':document.getElementById('resourcepicker_'+resourceid).options[selectedIndex].value},'onSuccess':function(req){},'onError':function(req){ajaxErrorFunction(req)}});}
function serialize(elementTag,prefix){elements=document.getElementsByTagName(elementTag);serialized_ar='';if(elements.length>0){for(i=0;i<elements.length;i++){if(elements[i].name.indexOf(prefix)!=-1){serialized_ar+=elements[i].name+"[]="+elements[i].value+"&"}}}
return serialized_ar;}
function update_video_info(videoid){index=document.getElementById('videopicker').selectedIndex;AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'update_video_info','titles':serialize('input','video_title'),'descriptions':serialize('input','video_description'),'chapterid':document.getElementById('videopicker').options[index].value},'onSuccess':function(req){},'onError':function(req){ajaxErrorFunction(req)}});}
rad_div='';function getRadUploader(resourcetype){rad_div='radupload_'+resourcetype
AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'get_rad_html','resource':resourcetype,'chapterid':current_chapter},'onSuccess':function(req){document.getElementById(rad_div).innerHTML=req.responseText},'onError':function(req){ajaxErrorFunction(req)}});return false;}
function upload_video(vfaqid,resourceid){document.getElementById('but_vidupload_'+resourceid).disabled=true;document.getElementById('but_vidupload_'+resourceid).readonly=true;document.getElementById('upload_success_'+resourceid).innerHTML="Upload in progress";AjaxRequest.post({'url':neo_url+'Games/vfaq_ajax.php','parameters':{'vfaqid':vfaqid,'action':'upload_video_direct','resourceid':resourceid,'chapterid':current_chapter,'url':document.getElementById('video_upload_'+resourceid).value},'onSuccess':function(req){document.getElementById('upload_success_'+resourceid).innerHTML=req.responseText;document.getElementById('but_vidupload_'+resourceid).disabled=false;document.getElementById('but_vidupload_'+resourceid).readonly=false;document.getElementById('video_upload_'+resourceid).value='';getResources("videopicker","video")},'onError':function(req){ajaxErrorFunction(req)}});}
var clientPC=navigator.userAgent.toLowerCase();var clientVer=parseInt(navigator.appVersion);var is_ie=((clientPC.indexOf("msie")!=-1)&&(clientPC.indexOf("opera")==-1));var is_nav=((clientPC.indexOf('mozilla')!=-1)&&(clientPC.indexOf('spoofer')==-1)&&(clientPC.indexOf('compatible')==-1)&&(clientPC.indexOf('opera')==-1)&&(clientPC.indexOf('webtv')==-1)&&(clientPC.indexOf('hotjava')==-1));var is_moz=0;var is_win=((clientPC.indexOf("win")!=-1)||(clientPC.indexOf("16bit")!=-1));var is_mac=(clientPC.indexOf("mac")!=-1);var selectedtxt='';function getcursor(txt){selectedtxt=(document.all)?document.selection.createRange().text:window.getSelection();if(txt.createTextRange)
txt.caretPos=document.selection.createRange().duplicate();return true;}
function addtxt(opentag,closetag){var cursorpos;if(!closetag){closetag='';}
posttextarea=document.postingform.message;if((clientVer>=4)&&is_ie&&is_win){cursorpos=document.getElementById('message').caretPos;if(posttextarea.createTextRange&&posttextarea.caretPos){str=opentag+selectedtxt+closetag;cursorpos.text=cursorpos.text.charAt(cursorpos.text.length-1)==' '?str+' ':str;}else{posttextarea.value+=str;}
posttextarea.focus();}else if((document.getElementById)||(posttextarea.selectionEnd&&(posttextarea.selectionEnd-posttextarea.selectionStart>0))){mozWrap(posttextarea,opentag,closetag);posttextarea.focus();return;}else{posttextarea.value+=opentag+closetag;posttextarea.focus();}}
function mozWrap(posttextarea,open,close){var scrollTop,scrollLeft;if(posttextarea.type=='textarea'&&typeof posttextarea.scrollTop!='undefined'){scrollTop=posttextarea.scrollTop;scrollLeft=posttextarea.scrollLeft;}
var selLength=posttextarea.textLength;var selStart=posttextarea.selectionStart;var selEnd=posttextarea.selectionEnd;if(selEnd==1||selEnd==2)
selEnd=selLength;var s1=(posttextarea.value).substring(0,selStart);var s2=(posttextarea.value).substring(selStart,selEnd)
var s3=(posttextarea.value).substring(selEnd,selLength);posttextarea.value=s1+open+s2+close+s3;if(typeof scrollTop!='undefined'){posttextarea.scrollTop=scrollTop;posttextarea.scrollLeft=scrollLeft;}
var newWordLength=close.length+s2.length+open.length;posttextarea.setSelectionRange(selStart+newWordLength,selStart+newWordLength);return false;}
function addmarkup(code){addtxt('['+code+']','[/'+code+']');}
function addlink(){addtxt('[link name=','][/link]');}
function addimage(imageURL,linkURL,displayLinkText){if(displayLinkText){addtxt('[faqimg='+linkURL+']'+imageURL,'[/faqimg]');}else{addtxt('[img]'+linkURL,'[/img]');}}
function addvideo(videoPath,size){if(size.length==0){addtxt('[neovid]'+videoPath,'[/neovid]');}else{addtxt('[neovid size='+size+']'+videoPath,'[/neovid]');}}
function changecolor(colorselect,color){if(color){addtxt('[color='+color+']','[/color]');colorselect.selectedIndex=0;}}
function changesize(sizeselect,size){if(size){addtxt('[size='+size+']','[/size]');sizeselect.selectedIndex=0;}}
function storeCaret(textEl){if(textEl.createTextRange)textEl.caretPos=document.selection.createRange().duplicate();}