
function escQuotes(text) {
  var rx = new RegExp("\"", "g"); 
  return text.replace(rx,"&#34;");
}
// lib for spell checker

function escEntities(text) {
  var rx = new RegExp("&", "g"); 
  return text.replace(rx,"&amp;");
}


var spellBoot="";

function popUpCheckSpellingrapidSpellWebLauncher(interfaceObjectName){  

  spellBoot = "<html><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";  
  spellBoot += "<body onLoad='document.forms[0].submit();'><font face='arial, helvetica' size=2>Spell checking document...</font><fo"+"rm action='RapidSpellCheckerPopUp.aspx' method='post'>";  
  spellBoot += "<input type='hidden' name='textToCheck' value=\""+escQuotes(escEntities(eval(interfaceObjectName+'.getText()')))+"\"><input type='hidden' name='InterfaceObject' value='"+interfaceObjectName+"'><input type='hidden' name='mode' value='popup'><input type='hidden' name='UserDictionaryFile' value=''><input type='hidden' name='DictFile' value=''><input type='hidden' name='SuggestionsMethod' value='HASHING_SUGGESTIONS'><input type='hidden' name='LanguageParser' value='ENGLISH'><input type='hidden' name='SeparateHyphenWords' value='True'><input type='hidden' name='V2Parser' value='False'><input type='hidden' name='SSLFriendlyPage' value='blank.html'>"; 
  spellBoot += "<input type='hidden' name='ShowFinishedMessage' value='False'><input type='hidden' name='ShowNoErrorsMessage' value='False'><input type='hidden' name='CreatePopUpWindow' value='False'><input type='hidden' name='FinishClosesWindow' value='True'><input type='hidden' name='WarnDuplicates' value='True'><input type='hidden' name='IgnoreWordsWithDigits' value='True'><input type='hidden' name='IgnoreURLsAndEmailAddresses' value='True'>"; 
  spellBoot += "<input type='hidden' name='SuggestSplitWords' value='True'><input type='hidden' name='CheckCompoundWords' value='False'><input type='hidden' name='CorrectionNotifyListener' value=''><input type='hidden' name='Modal' value='False'><input type='hidden' name='InformFinishListenerOfState' value='True'><input type='hidden' name='PostBackOnFinish' value='False'><input type='hidden' name='RswlClientID' value='rapidSpellWebLauncher'><input type='hidden' name='AllowMixedCase' value='False'>"; 
  spellBoot += "<input type='hidden' name='IncludeUserDictionaryInSuggestions' value='False'><input type='hidden' name='LookIntoHyphenatedText' value='True'><input type='hidden' name='FinishedListener' value='notifyDone'><input type='hidden' name='GuiLanguage' value='ENGLISH'><input type='hidden' name='callBack' value=''><input type='hidden' name='IgnoreXML' value='False'><input type='hidden' name='IgnoreCapitalizedWords' value='False'><input type='hidden' name='ConsiderationRange' value='-1'></form></body>"; 
  spellBoot += "</html>"; 

var sc = window.open('', 'rspellwin', 'resizable=yes,scrollbars=auto,dependent=yes,toolbar=no,left=100,top=100,status=no,location=no,menubar=no,width=370,height=400'); 
 sc.focus(); sc.document.open();  
 sc.document.write(spellBoot); 
 sc.document.close();
}

function RSStandardInterface(tbElementName) {
  this.tbName = tbElementName;
  this.getText = getText;
  this.setText = setText;

  function getText(){	
    return eval('document.'+this.tbName+'.value');
  }

  function setText(text){	
    eval('document.'+this.tbName+'.value = text') ;
  }

}

// ---- The name of the popup window
var spellCheckWin;

// ---- The names of the RapidSpellWebLauncher controls on the form
//var rapidSpellControls = [];
var rapidSpellControls = new Array();

// ---- Tracks the next RapidSpellWebLauncher control to be run
var currentlyChecking = 0;

//runs the spell checker for current control in rapidSpellControls
function runSpellCheck(buttonClick){

  //see if the button has already opened to spell check
  if (buttonClick && spellCheckWin!=null && !spellCheckWin.closed) {
    spellCheckWin.focus();				
  } else {

    //incase the window was closed during a previous check
    if (currentlyChecking>0 && spellCheckWin.closed) currentlyChecking=0;

    if (currentlyChecking==0) 
      spellCheckWin = window.open('', 'rspellwin', 'resizable=yes,scrollbars=auto,dependent=yes,toolbar=no,left=100,top=100,status=no,location=no,menubar=no,width=370,height=400')

				
    //eval("popUpCheckSpelling"+rapidSpellControls[currentlyChecking]+"('rsTCInt"+rapidSpellControls[currentlyChecking]+"')");

//alert (currentlyChecking);

    eval("popUpCheckSpellingrapidSpellWebLauncher('" + rapidSpellControls[currentlyChecking] + "')");

  }
}

//listens for checker to finish and starts up next checker if not finished.
function notifyDone(){
  currentlyChecking++;
  if (currentlyChecking < rapidSpellControls.length){
    runSpellCheck(false);
  } else {

    //--finished
    spellCheckWin.close();
    currentlyChecking=0;
  }
}

