function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function SpellCheck(fldname, type, spcheckerPath){
    var fldvalue;

    if (type == "HTML") {
        fldvalue = fldname+ ".innerHTML";
    } else {
        fldvalue = fldname+ ".value";
    }

    fldvalue = eval(fldvalue);

    html = '';
    html += '<body onload="javascript:checkspell();" style="font:10pt arial">';
    html += '<head>';
    html += '<script>';
    html += 'function checkspell(){';
    html += '  var width         = 590;';
    html += '  var height        = 265;';
    html += '  var leftPo        = (screen.availWidth-width)/2;';
    html += '  var topPo         = (screen.availHeight-height)/2;';
    html += '  var windowoptions = "scrollbars=no,toolbar=no,status=no,location=no,menubar=no,resizable=yes,height="+height+",width="+width+",left="+leftPo+",top="+topPo;';
    html += '  var newwin = window.open("", "newwin", windowoptions);';
    html += '  document.spform.submit();';
    html += '  newwin.focus();'; 
    html += '}</';
    html += 'script>';
    html += '</head>';
    html += '<form name="spform" method="post" action="' + spcheckerPath + 'spchecker.php" target="newwin">';
    html += '<textarea style="display:none" name="sptext">'+ fldvalue + '</textarea>';
    html += '<input type="hidden" id="idnumber" name="idnumber" value="'+ fldname + '">';
    html += '<input type="hidden" id="idtype" name="idtype" value="'+ type + '">';
    html += '</form>';
    html += '</body>';

    eval("spframe").document.open();
    eval("spframe").document.write(html);
    eval("spframe").document.close();
}

function UpdateSpellCheckChanges(id, type, changes){
    var newstring, strleft, strright;
    var pos, len, str;
    var arycorrections, aryc;
    var sptext1;
    var newlen;
    var fldvalue;

    if (changes.length>0) {
        if (type == "HTML") {
            fldvalue = id + ".innerHTML";
        } else {
            fldvalue = id + ".value";
        }

        newstring = eval(fldvalue);
        arycorrections = tokenize(changes, ';');
        newlen = 0;
        for (var i=0; i<arycorrections.length-1; ++i ) {
            aryc = tokenize(arycorrections[i],',');

            pos = eval(parseInt(aryc[0])) + newlen;
            len = parseInt(aryc[1]);
            str = aryc[2];

            strleft  = newstring.substring(0, eval(pos));
            strright = newstring.substring(eval(pos + len));
            newstring = strleft + str + strright;

            newlen += parseInt(str.length) - len;
        }

        if (type == "HTML") {
            eval(id).innerHTML = newstring
        } else {
            eval(id).value = newstring
        }
    }
}
