//
// openSpellChecker()
//
// this function is provided to be able to invoke
// the the Speller Pages spell-checking process
//
function openSpellChecker(form, fields, baseUrl) {

    var fieldList = fields.split(',');
	var speller = new spellChecker();
	var spellerInputs = new Array();
	for (var i = 0 ; i < fieldList.length; i++) {
        //var docFields = document.getElementsByName(fieldList[i]);
        var field = eval('document.'+form+'.'+fieldList[i]);
        if (field)
        {
            if (window.FCKeditorAPI && FCKeditorAPI.__Instances[fieldList[i]]) {
                document.getElementById(fieldList[i]).value = FCKeditorAPI.__Instances[fieldList[i]].GetHTML();
            }
            spellerInputs[spellerInputs.length] = field;
        }
    }

    if (spellerInputs.length > 0)
    {
        speller.textInputs = spellerInputs;
        //var speller = new spellChecker(document.apc_form_main.title, document.apc_form_main.body, document.apc_form_main.aBstract);
        speller.OnFinished = speller_OnFinished;

        // assign script locations
        speller.popUpUrl = baseUrl + '/speller/spellchecker.html';
        speller.spellCheckScript = getcontextpath + '/spellcheck?baseurl=' + escape(baseUrl);

        speller.openChecker();
    }
    else
    {
        alert('No valid fields have beeon specified for spell checking');
    }
}


function speller_OnFinished( numberOCorrections, textInputs ) {
    if ( numberOCorrections > 0 )
    {
        for (var i = 0 ; i < textInputs.length; i++)
        {
            if (window.FCKeditorAPI && FCKeditorAPI.__Instances[textInputs[i].name]) {
                FCKeditorAPI.__Instances[textInputs[i].name].SetHTML( document.getElementById(textInputs[i].name).value ) ;
            }
        }
    }
}
