var KEY_CODES={ENTER:13,BACKSPACE:8,DELETE:46,TAB:9,SHIFT:16};var maxWords=51;var ajaxCallsDone=true;var wasKeyPressed=false;function writeAjaxStatus(valueToWrite)
{$("#divStatus").text($("#divStatus").text()+valueToWrite);}
function checkForDuplicates()
{var uniqueWords={};var duplicateWords=false;$("table.wordListTable").find(":text").each(function()
{var currentWord=$(this).val();if(currentWord.length>0)
{if(uniqueWords[currentWord])
{duplicateWords=true;$(this).parents("tr").find("td:first").removeClass().addClass("numberCellDuplicate");$(this).parents("tr").find("td:last").removeClass().addClass("wordCellDuplicate");}
else
{uniqueWords[currentWord]=1;}}});if(duplicateWords)
{return true;}
return false;}
function checkWord(wordInputBoxObject,showWordStatus)
{if(!wasKeyPressed)
{return true;}
var numberCell=$(wordInputBoxObject).parents("tr").find("td:first");var wordCell=$(wordInputBoxObject).parents("tr").find("td:last");var vShowWordStatus=showWordStatus;if($.trim(wordInputBoxObject.value))
{writeAjaxStatus(wordInputBoxObject.value+", ");$.get("index2.php",{option:"com_spellingengine",task:"verifyWord",word:$.trim(wordInputBoxObject.value)},function(data)
{writeAjaxStatus(data+", ");if(data&&vShowWordStatus)
{if(data=="obscene")
{numberCell.removeClass().addClass("numberCellObscene");wordCell.removeClass().addClass("wordCellObscene");}
else
{if(data=="false")
{numberCell.removeClass().addClass("numberCellNotApproved");wordCell.removeClass().addClass("wordCellNotApproved");}
else
{if(data=="symbols")
{numberCell.removeClass().addClass("numberCellSymbol");wordCell.removeClass().addClass("wordCellSymbol");}
else
{numberCell.removeClass().addClass("numberCellNormal");wordCell.removeClass().addClass("wordCellNormal");}}}}});}
else
{numberCell.removeClass().addClass("numberCellNormal");wordCell.removeClass().addClass("wordCellNormal");}}
function renumberWordList(wordListTable)
{var j=0;$(wordListTable).find("tr").each(function(i){if($(this).find("td").size()>1)
{j++;$(this).find("td:first").text(j+".");}});}
function removeWord(linkObject)
{if(!confirm("Are you sure you want to delete this word?"))
{return false;}
var wordListTable=$(linkObject).parents("table:first");var currentRowCount=wordListTable.find("tr").length;if(currentRowCount>1)
{var prevInputBox=$(linkObject).parents("tr").prev().find(":text");if(prevInputBox.length>0)
{prevInputBox.focus();}
else
{var nextInputBox=$(linkObject).parents("tr").next().find(":text");if(nextInputBox.length>0)
{nextInputBox.focus();}}
$(linkObject).parents("tr:first").remove();renumberWordList(wordListTable);resetAndUpdateWordLinks(currentRowCount-1);}
else
{alert("A spelling list must have one word.");}
return false;}
function resetAndUpdateWordLinks(currentRowCount)
{resetAddWordLinks();updateWordListLinks(currentRowCount);}
function addWords(addWordsLinkObject,numWordsToAdd)
{var wordListTable=$("table.wordListTable");var currentRowCount=wordListTable.find("tr").length;if(currentRowCount+numWordsToAdd>maxWords){numWordsToAdd=maxWords-currentRowCount;}
var lastRow=wordListTable.find("tr:last");var hint=$('#wordinput-hint').clone();$('#wordinput-hint').remove();var newRow=lastRow.clone(true);newRow.find("td:first").removeClass().addClass("numberCellNormal");newRow.find("td:last").removeClass().addClass("wordCellNormal");newRow.find(":text").attr("value","");var i=0;for(i=0;i<numWordsToAdd;i++)
{lastRow.after(newRow);newRow=lastRow.next().clone(true);}
renumberWordList(wordListTable);lastRow=wordListTable.find("tr:last");$(lastRow).find('td:last').append(hint);tooltip();for(i=0;i<numWordsToAdd-1;i++)
{lastRow=lastRow.prev("tr");}
lastRow.find(":text").focus();updateWordListLinks(currentRowCount+numWordsToAdd);}
function updateWordListLinks(currentRowCount)
{if(currentRowCount!=undefined){var $addWordLinks=$('div.addWordsLinks');if(currentRowCount==maxWords){$addWordLinks.find('span').hide();var maxReached=$addWordLinks.find('p.max-reached');if(maxReached.length==0){var message='<p class="max-reached">You have reached the limit of '+maxWords+' Maximum words</p>';$addWordLinks.prepend(message);}}
if(maxWords-currentRowCount<5){$addWordLinks.find('span.wl-add-1-comma, span.wl-add-5').hide();$addWordLinks.find('span.wl-add-words').text(' word ');}
if(maxWords-currentRowCount<10){$addWordLinks.find('span.wl-add-1-comma').text(' or ');$addWordLinks.find('span.wl-add-10').hide();$addWordLinks.find('span.wl-or').hide();}}else{return false;}}
function resetAddWordLinks()
{var $addWordLinks=$('div.addWordsLinks');$addWordLinks.find('p.max-reached').remove();$addWordLinks.find('span').show();}
function handleSpecialKeys(wordInputBoxObject,e)
{wasKeyPressed=true;var code=e.keyCode||e.charCode;switch(code)
{case KEY_CODES.ENTER:var nextWordInputBox=$(wordInputBoxObject).parents('tr:first').next().find('input');if(nextWordInputBox.length==1)
{nextWordInputBox.focus();}
else
{addWords(wordInputBoxObject,1);}
return true;case KEY_CODES.DELETE:case KEY_CODES.BACKSPACE:if(document.getElementById('listId'))
{if(parseInt(document.getElementById('listId').value,10))
{if(wordInputBoxObject.value.length===0){removeWord(wordInputBoxObject);return true;}}}
break;}
return false;}
function checkDefaultValue(inputBoxObject)
{if(inputBoxObject.value=="List name here"||inputBoxObject.value=="Category here")
{inputBoxObject.value="";}
return true;}
function validateList()
{var obsceneWords=$("table.wordListTable").find(".wordCellObscene");if(obsceneWords.length>0)
{alert("You can't have bad words on a spelling list");return false;}
return true;}
function getValidWordRegex(){return new RegExp(/^[a-zA-Z\-\s\.']+$/);}
function validateListEntry()
{var entryMethod=$("#entryMethod").attr("value");var re=getValidWordRegex();var valid=true;if(entryMethod=="list"){entered=$("#wordListTable").find(":text");$("#wordListTable").find(":text").each(function(){userWord=$(this).val();userWord=userWord.replace(/’/g,"'");if(userWord.length>0&&!userWord.match(re)){valid=false;}});}else{var enteredWords=$.trim($("#wordscsv").attr("value"));enteredWords=enteredWords.replace(/’/g,"'");var wordArray=enteredWords.split(new RegExp("[\n\r\t,|]{1}","g"));$.each(wordArray,function(i,v){if(v.length>0&&!v.match(re)){valid=false;}});}
return valid;}
function howManyWords()
{var j=0;var entryMethod=$("#entryMethod").attr("value");if(!entryMethod)
{var numberOfWords=$("#numberOfWords").attr("value");return numberOfWords;}
if(entryMethod=="list")
{$("#wordListTable").find(":text").each(function(i){var inputBox=this;if($.trim(inputBox.value).length>0)
{j++;}});}
else
{var enteredWords=$.trim($("#wordscsv").attr("value"));if(enteredWords.length>0)
{var wordArray=enteredWords.split(new RegExp("[\n\r\t,|]{1}","g"));j=wordArray.length;}}
return j;}
function processListActionButtons(e,linkObjectClicked,bypassValidation)
{var $el=$(linkObjectClicked);var duplicateWords=false;var validList=true;if(!bypassValidation)
{if(!ajaxCallsDone){writeAjaxStatus(" not done yet, ");alert("We're still checking your list, please try again.");return false;}
validList=validateList();duplicateWords=checkForDuplicates();}
var numberOfWords=howManyWords();if($el.hasClass('pm-block')&&numberOfWords){return false;}else{e.stopImmediatePropagation();}
if(numberOfWords>maxWords){alert('You can not enter more than '+maxWords+' words. Please remove '+(numberOfWords-maxWords)+' words from your list');return false;}
if(validList&&!duplicateWords)
{var userAction=document.getElementById('userAction');var activity=$el.attr('class');activity=activity.split(' ')[0];if(userAction.value)
{if(activity=="testMeButton")
{userAction.value="testMe";if(numberOfWords<1){window.location="/Games/spelling-testme.html";return false;}}
if(activity=="teachMeButton")
{if(numberOfWords<1){window.location="/teachme.html";return false;}
var $notice=$('#teachme-notice');if(typeof $notice[0]!='undefined'){$('#flashcard-inline-form').hide().insertAfter('#worksheetPrint');$notice.remove();if($el.parent().parent('ul').hasClass('wordListActionButtonsMini')||$el.parent().parent('ul').parent('div').hasClass('wordlistButtonsTop')){$notice.insertAfter('#flashcard-inline-form').show();}else{$notice.insertBefore('.wordListActionButtonsSmall:eq(1)').show();}
bindTeachMeNotice();return false;}
userAction.value="teach";}
if(activity=="playGameButton"){if(numberOfWords<1){window.location="/index.php?option=com_spellcity&task=emptyListToPlay";return false;}
userAction.value="play";}
if(activity=="vocabTestMeButton"){if(numberOfWords<1){window.location="/Games/vocabulary-testme.html";return false;}
userAction.value="vocabTestMe";}
if(activity=="flashCardsButton")
{if($('#listEntryBlock').length==0){$el.trigger('stopSubmit');return false;}
if(numberOfWords<1){window.location='/flash-cards.html';return false;}
userAction.value="flashCards";}
$("#formWordListEntry").submit();}
else
{alert('There was a problem submitting the list.  Please try again.');}}
else
{if(numberOfWords===0||numberOfWords==='0')
{alert('You must enter at least one word!');}
else
{alert("There was an issue with some of the words on your list.  Please note that obscenities are not allowed.  Please review the words and correct."+numberOfWords);}}
return false;}
function validateWords()
{$("table.wordListTable").find(":text").each(function(){checkWord(this);});}
function handleFocus()
{wasKeyPressed=false;}
function manageKeyDownWordInputBox(inputBoxObject,theEvent)
{var keyHandled=handleSpecialKeys(inputBoxObject,theEvent);if(keyHandled)
{return false;}
return true;}
function switchToBatch()
{loop_through_inputs();$("#entryMethod").attr("value","batch");$("#listEntryBlock").hide();var currentRowCount=$("#wordListTable").find("tr").length;$("#batchEntryBlock").show();return false;}
function switchToList(el)
{resetAddWordLinks();loop_through_textarea();var currentRowCount=$("#wordListTable").find("tr").length;if(currentRowCount>maxWords){alert('You can not enter more than '+maxWords+' words. Please remove '+(currentRowCount-maxWords)+' words from your list');return false;}else{$("#entryMethod").attr("value","list");$("#listEntryBlock").show();resetAndUpdateWordLinks(currentRowCount);$("#batchEntryBlock").hide();return false;}}
function onSaveList()
{var listNameValue=$.trim(document.getElementById('wordListName').value);if(listNameValue=='List name here'||$.trim(listNameValue)===''){alert('Please enter a spelling list name.');return false;}
if(!validateListEntry()){alert('Some of the words entered have invalid characters.  Please fix and try again.');return false;}
var numberOfWords=howManyWords();switch(true){case howManyWords()===0:alert('A spelling list must have at least 1 word.');return false;break;case howManyWords()>maxWords:alert('You can not enter more than '+maxWords+' words. Please remove '+(numberOfWords-maxWords)+' words from your list');return false;break;default:$('#formWordListEntry').submit();break;}}
function checkTotalWords(numberOfWords)
{if(numberOfWords>maxWords){return false;}else{return true;}}
function checkSentences()
{incompleteWord=new Array();x=0;$('.sentenceCheck').each(function(index){if($(this).val()==''){indexSelected=index+1;incompleteWord[x]=indexSelected;x++;}});return incompleteWord;}
function checkDefinitions()
{var incompleteWord=new Array();var x=0;$('.definitionCheck').each(function(index){if($(this).val()==''){indexSelected=index+1;incompleteWord[x]=indexSelected;x++;}});return incompleteWord;}
function wordIdToWord(unqArray){var wordList=new Array();var problemWords='';$('.wordCheck').each(function(index){indexSelected=index+1;wordList[indexSelected]=$(this).val();x++;});$.each(unqArray,function(){arrIndex=this;problemWords+=wordList[arrIndex]+', ';});problemWords=problemWords.slice(0,-2);return problemWords;}
function mergeDisplay(noDefinitions,noSentences)
{Array.prototype.unique=function(){var a=this.concat();for(var i=0;i<a.length;++i){for(var j=i+1;j<a.length;++j){if(a[i]===a[j])
a.splice(j,1);}}
return a;};var unqArray=noDefinitions.concat(noSentences).unique();$.each(noSentences,function(){});wordsIncomplete=wordIdToWord(unqArray);return wordsIncomplete;}
function onEditList()
{if($('#wordListName').val()==''){alert('Title cannot be empty');$('#wordListName').focus();return false;}
var currentRowCount=$('#wordSentenceTable tr.mainSec').length;if(checkTotalWords(currentRowCount)){noDefinitions=checkDefinitions();noSentences=checkSentences();wordList=mergeDisplay(noDefinitions,noSentences);if(wordList){var answer=confirm('Some words on your list are not recognized by our database and will not appear in games or activities unless you add a definition and a sentence. Would you like to submit the page ?');if(answer){$('#formWordListEntry').submit();}else{return false;}}else{$('#formWordListEntry').submit();}}else{alert('You can not enter more than '+maxWords+' words. Please remove '+(currentRowCount-maxWords)+' words from your list');}}
function onCancelList()
{document.getElementById('userAction').value='cancel';$('#formWordListEntry').submit();return true;}
function manageKeyDownListName(listNameInputObject,theEvent)
{var code=theEvent.keyCode||theEvent.charCode;if(code==KEY_CODES.ENTER)
{var nextWordInputBox=$("#wordListTable").find('input:first');nextWordInputBox.focus();return false;}
return true;}
function printList2(hrefObject)
{var printTypeCursive=document.getElementById('printTypeCursive');var printTypeSign=document.getElementById('printTypeSign');var printTypeDN=document.getElementById('printTypeDN');var arrowsOff=document.getElementById('arrowsOff');var caseUpper=document.getElementById('caseUpper');var sizeSmall=document.getElementById('sizeSmall');var sizeLarge=document.getElementById('sizeLarge');var printType="print";if(printTypeCursive.checked)
{printType="cursive";}
if(printTypeSign.checked)
{printType="sign";}
if(printTypeDN.checked)
{printType="dn";}
var arrows="on";if(arrowsOff.checked)
{arrows="off";}
var caseType="lower";if(caseUpper.checked)
{caseType="upper";}
var size="medium";if(sizeSmall.checked)
{size="small";}
if(sizeLarge.checked)
{size="large";}
hrefObject.href=hrefObject.href+'&printType='+printType+'&arrows='+arrows+'&caseType='+caseType+'&size='+size;}
function printList3(hrefObject)
{var printType=document.getElementById('printType').value;var arrowsOff=document.getElementById('arrowsOff');var caseUpper=document.getElementById('caseUpper');var sizeSmall=document.getElementById('sizeSmall');var sizeLarge=document.getElementById('sizeLarge');var arrows="on";var align;var size;if(arrowsOff.checked)
{arrows="off";}
var caseType="lower";if(caseUpper.checked)
{caseType="upper";}
var size="medium";if(sizeSmall.checked)
{size="small";}
if(sizeLarge.checked)
{size="large";}
hrefObject.href=hrefObject.href+'&printType='+printType+'&arrows='+arrows+'&caseType='+caseType+'&size='+size;}
function showPrintOptions()
{$('.wordlist-popout-form').hide();if($("#worksheetPrint").is(":hidden"))
{$("#worksheetPrint").slideDown("slow");var printTypePrint=document.getElementById('printTypePrint');printTypePrint.checked=true;var arrowsOff=document.getElementById('arrowsOff');arrowsOff.checked=true;var caseLower=document.getElementById('caseLower');caseLower.checked=true;var sizeMedium=document.getElementById('sizeMedium');sizeMedium.checked=true;}
else
{$("#worksheetPrint").hide();}}
function showPrintOptions2()
{$('.wordlist-popout-form').hide();if($("#worksheetPrint").is(":hidden"))
{$("#worksheetPrint").slideDown("slow");var printTypePrint=document.getElementById('printType');var arrowsOff=document.getElementById('arrowsOff');arrowsOff.checked=true;var caseLower=document.getElementById('caseLower');caseLower.checked=true;var sizeMedium=document.getElementById('sizeMedium');sizeMedium.checked=true;}
else
{$("#worksheetPrint").hide();}}
function bindTeachMeNotice(){$('#teachme-notice .dismiss').click(function()
{$('#teachme-notice').hide();});}
$().ready(function()
{try{var anchor=window.location.hash;$(anchor).show();}catch(err){}
bindTeachMeNotice();});
