var rowcount=20;var unparsed_content;var parsed_symbol;function addslashes(str){str=str.replace(/"/g,"&quot;");return str.replace(/'/g,"&#39;");}
function show_cat_details(cheatform,catid,entityid,allow_edit){if(catid.match(/\d+/)!=null){cheatform.type_title.value=categories[catid]['title'];cheatform.type_title.disabled=(allow_edit&&catid!=1&&catid!=2)?false:true;cheatform.type_desc.value=categories[catid]['description'];cheatform.type_desc.disabled=(allow_edit&&catid!=1&&catid!=2)?false:true;if(allow_edit&&categories[catid]['column1']){cheatform.column1.value=categories[catid]['column1'];cheatform.column1.disabled=(catid!=1&&catid!=2)?false:true;}else if(allow_edit&&(catid==1||catid==2)){cheatform.column1.disabled=true;}else{cheatform.column1.disabled=false;}
if(allow_edit&&categories[catid]['column2']){cheatform.column2.value=categories[catid]['column2'];cheatform.column2.disabled=(catid!=1&&catid!=2)?false:true;}else if(allow_edit&&(catid==1||catid==2)){cheatform.column2.disabled=true;}else{cheatform.column2.disabled=false;}
AjaxRequest.post({'url':NEO_URL+'Games/cheats_ajax.php','parameters':{'act':'check_if_exist','entityid':entityid,'catid':catid},'onSuccess':function(req){document.getElementById('existed_cheats').innerHTML=req.responseText},'onError':function(req){ajaxErrorFunction(req)}});}else if(catid.match(/\w+/)){cheatform.type_title.value=catid;cheatform.type_title.disabled=false;cheatform.type_desc.value='';cheatform.type_desc.disabled=false;cheatform.type_desc.focus();}else{cheatform.type_title.value='';cheatform.type_title.disabled=false;cheatform.type_desc.value='';cheatform.type_desc.disabled=false;cheatform.catid.options[0].selected=true;document.getElementById('existed_cheats').innerHTML='';cheatform.type_title.focus();}}
function show_type_selectbox(cheatform,selected,entityid,filename,platform){AjaxRequest.post({'url':NEO_URL+'Games/cheats_ajax.php','parameters':{'act':'load_category_types','cat':selected,'entityid':entityid,'filename':filename,'platform':platform},'onSuccess':function(req){document.getElementById('ctype_select').innerHTML=req.responseText;}});}
function show_type_editform(cheatform,selected,entityid,filename,platform){category=selected.toUpperCase();if(selected=='unlockable'||selected=='password'||selected=='achievement'||selected=='trophy'){if(typeof(cheatform.rawcontent)!='undefined'){cheatform.type_title.name='old_type_title';cheatform.type_desc.name='old_type_desc';cheatform.column1.name='old_column1';cheatform.column2.name='old_column2';cheatform.rawcontent.name='old_rawcontent';}
html='<h5 class="red">Convert submission to '+category+':</h5><div id="ctype_select"></div>';if(selected=='unlockable'||selected=='password'){html+='<strong>OR</strong> <a href="#" onclick="show_cat_details(document.'+cheatform.name+', \'\'); return false;">add a new '+category+' type</a><br /><br />\
<p><strong>'+category+' Title:</strong> <span class="red">*</span> <input type="text" name="type_title" size="40" value="" /><br />\
<strong>'+category+' Description:</strong> <span class="red">*</span> <small>Please provide any required information to unlock features</small><br />\
<textarea name="type_desc" cols="70" rows="3"></textarea><br />\
<strong>Column 1 Title:</strong> <input type="text" name="column1" value="" size="40" /><br />\
<strong>Column 2 Title:</strong> <input type="text" name="column2" value="" size="40" /></p>';}
html+='<div id="existed_cheats"></div>\
<div id="games_spotlight_platforms">\
 <ul id="tabnav">\
 <li class="right"><a href="#" onclick="sort_table(document.cheatform, \''+selected+'\');return false;">Sort table</a></li>\
 <li><a href="#" id="tab_2col" onclick="toggle_form(document.'+cheatform.name+', \'a\', \''+selected+'\'); return false;">Two column method</a></li>\
 <li><a href="#" id="tab_text" class="current" onclick="return false;">All in one form <small>(Click outside for parsing)</small></a></li>\
 </ul>\
</div>\
<div class="cheat_editform" id="cheat_editform">\
 <textarea rows="30" cols="98" name="rawcontent" id="cheat_rawcontent" onkeyup="parse_content(this.form);" onmouseup="parse_content(this.form);parse_content(this.form);"></textarea>\
</div>';document.getElementById('cheat_extraform').innerHTML=html;if(typeof(cheatform.cheattitle)!='undefined'&&typeof(cheatform.description)!='undefined'){cheatform.cheattitle.readOnly=true;cheatform.description.readOnly=true;}else{cheatform.old_type_title.readOnly=true;cheatform.old_type_desc.readOnly=true;cheatform.old_column1.readOnly=true;cheatform.old_column2.readOnly=true;cheatform.old_rawcontent.readOnly=true;document.getElementById('ctype_select').scrollIntoView(true);}
show_type_selectbox(cheatform,selected,entityid,filename,platform);}else{if(typeof(cheatform.cheattitle)!='undefined'&&typeof(cheatform.description)!='undefined'){document.getElementById('cheat_extraform').innerHTML='';cheatform.cheattitle.readOnly=false;cheatform.description.readOnly=false;}else{document.getElementById('cheat_extraform').innerHTML='<h5 class="red">Convert submission to '+category+':</h5>\
<p><strong>Cheat title:</strong> <input type="text" name="cheattitle" value="" size="45" /></p>\
<p><strong>Cheat description:</strong><br /><textarea name="description" cols="98" rows="10"></textarea></p>';cheatform.type_title.readOnly=true;cheatform.type_desc.readOnly=true;cheatform.column1.readOnly=true;cheatform.column2.readOnly=true;cheatform.rawcontent.readOnly=true;document.getElementById('cheat_extraform').scrollIntoView(true);}}}
function insertRow(){var tbl=document.getElementById('content_tbl');var lastRow=tbl.rows.length;var iteration=lastRow-2;var row=tbl.insertRow(lastRow-2);var cellLeft=row.insertCell(0);var el=document.createElement('input');el.type='text';el.name='title['+iteration+']';el.size=30;cellLeft.appendChild(el);var cellRight=row.insertCell(1);var er=document.createElement('input');er.type='text';er.name='desc['+iteration+']';er.size=95;cellRight.appendChild(er);rowcount++;}
function toggle_form(cheatform,onform,ctype,extra_in_id){if(!extra_in_id){extra_in_id='';}
if(onform=='a'){content=cheatform.rawcontent.value.split('\n');if(content.length>rowcount){rowcount=content.length;}
formhtml='<table width="80%" cellpadding="1" id="content_tbl">';if(ctype=='unlockable'||ctype=='trophy'||ctype=='achievement'){formhtml+='<tr><td width="30%"><strong>'+ctype.substr(0,1).toUpperCase()+ctype.substr(1)+'<\/strong><\/td><td width="70%"><strong>How to Unlock<\/strong><\/td><\/tr>';}else{formhtml+='<tr><td width="30%"><strong>Password<\/strong><\/td><td width="70%"><strong>What it does<\/strong><\/td><\/tr>';}
for(i=0;i<rowcount;i++){if(typeof(content[i])!='undefined'&&content[i]!=''){line=content[i].split('|+|');title_str=' value="'+addslashes(line[0])+'"';desc_str=' value="'+addslashes(line[1])+'"';}else{title_str='';desc_str='';}
formhtml+='<tr><td><input type="text" name="title['+i+']" size="30"'+title_str+' /></td><td><input type="text" name="desc['+i+']" size="95"'+desc_str+' /></td></tr>';}
formhtml+='<tr><td colspan="2" align="right"><a href="#" onclick="insertRow();return false;">Add more rows...<\/a><\/td><\/tr><\/table>';document.getElementById('tab_2col'+extra_in_id).className='current';document.getElementById('tab_2col'+extra_in_id).onclick=function(){return false;};document.getElementById('tab_text'+extra_in_id).className='';document.getElementById('tab_text'+extra_in_id).onclick=function(){toggle_form(cheatform,'b',ctype,extra_in_id);return false};show_form='2col';}else{content='';for(i=0;i<rowcount;i++){if(cheatform['title['+i+']'].value!=''&&cheatform['desc['+i+']'].value!='')
content+=cheatform['title['+i+']'].value+'|+|'+cheatform['desc['+i+']'].value+'\r\n';}
formhtml='<textarea rows="30" cols="98" name="rawcontent" id="cheat_rawcontent" onkeyup="parse_content(this.form);" onmouseup="parse_content(this.form);parse_content(this.form);">'+content+'<\/textarea>';document.getElementById('tab_2col'+extra_in_id).className='';document.getElementById('tab_2col'+extra_in_id).onclick=function(){toggle_form(cheatform,'a',ctype,extra_in_id);return false;};document.getElementById('tab_text'+extra_in_id).className='current';document.getElementById('tab_text'+extra_in_id).onclick=function(){return false};show_form='text';}
document.getElementById('cheat_editform'+extra_in_id).innerHTML=formhtml;}
function parse_content(cheatform){var lineArray=new Array();parsed_content=cheatform.rawcontent.value;content_by_line=parsed_content.split('\n');for(var i=0;i<content_by_line.length;i++){if(content_by_line[i].indexOf('|+|')!=-1){lineArray.push(content_by_line[i]);}else if(content_by_line[i].length>0){lineArray.push(content_by_line[i].replace(/(.+?)(\t|\s?\-\s|:\s?(\[\/.+?\]\s*)?)(.+)$/,'$1|+|$4'));}}
parsed_content=lineArray.join('\r\n');parsed_content=parsed_content.replace(/^\s+/gm,'');cheatform.rawcontent.value=parsed_content;}
function sort_table(cheatform,ctype,extra_in_id){if(show_form=='2col'){toggle_form(cheatform,'b',ctype,extra_in_id);}
parsed_content=cheatform.rawcontent.value.replace(/(^[\n\xD]|[\n\xD]$)/g,'');content=parsed_content.split('\n');sort_content=content.sort();cheatform.rawcontent.value=sort_content.join("\n");}
function preview_submission(cheatform){cheatform.action=NEO_URL+'Games/cheats_ajax.php';cheatform.act.value='preview';var status=AjaxRequest.submit(document.forms[cheatform.name],{'onSuccess':function(req){document.getElementById('preview').innerHTML=req.responseText;cheatform.action='';cheatform.act.value='';}});}
function check_spelling(cheatform){cheatform.action=NEO_URL+'Games/cheats_ajax.php';cheatform.act.value='check_spelling';var status=AjaxRequest.submit(document.forms[cheatform.name],{'onSuccess':function(req){document.getElementById('preview').innerHTML=req.responseText;cheatform.action='';cheatform.act.value='';}});}
function searchproduct(){keywords=document.getElementById('skw').value;if(keywords.length==0){alert('Please enter a keyword.');}else{AjaxRequest.post({'url':NEO_URL+'Games/cheats_ajax.php','parameters':{'keywords':keywords,'act':'searchproduct'},'onSuccess':function(req){document.getElementById('search_results').innerHTML=req.responseText},'onError':function(req){ajaxErrorFunction(req)}});}}
function redirect(){if(document.getElementById('search_results').innerHTML!=''){for(var i=0;i<document.searchform.selected_entities.length;i++){if(document.searchform.selected_entities[i].checked){window.location=NEO_URL+'Game/submit_cheat.html?entityid='+document.searchform.selected_entities[i].value;return;}}
alert('Please select a game.');}else{alert('Please enter a keyword and search.');}}
function validate_form(cheatform){if(cheatform.catid.selectedIndex==0||cheatform.type_title.value==''){alert("Please select a type from the select box or enter a new type of your own.");cheatform.type_title.focus();return false;}
return true;}
$(document).ready(function(){$.ajaxSetup({type:"POST",timeout:15000,success:function(html){if(html=="false"){window.location.reload();}},error:function(){}});$("body").addClass("js");reset_search=function(){$("span.search_message").hide();$(".cheat_box h3, .cheat_entry, #quickjump").show();}
if(typeof(non_ajax_search)!='undefined'&&!non_ajax_search){$("#cheat_options input[name=keywords]").keyup(function(event){if(event.keyCode==27){$(this).val("").focus();reset_search();}
var self=$(this);var search_term=$.trim($(this).val());if(search_term.length>2&&search_term.length<32){var query_string="in_ajax_mode=1&keywords="+search_term
ajax=$.ajax({beforeSend:function(){},data:query_string,success:function(html){if(html!='false'){if(html==''){$("span.search_message strong").html(search_term).parent().show();$(".cheat_box h3, .cheat_entry, #quickjump").hide();}else{$("span.search_message").hide();var cheat_entry_id_array=html.split(',');$(".cheat_box h3, .cheat_entry, #quickjump").hide();$.each(cheat_entry_id_array,function(){$("#ch4"+this).show();});}}}});}else{reset_search();}});$(".clear_search").click(function(){$("#cheat_options input[name=keywords]").val("").focus();reset_search();return false;});}});