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_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_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 MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function popup(url){
  var xOffset = (screen.availWidth - 420)/2;
  yOffset = (screen.availHeight - 450)/2;
  var popup=window.open(url,"popup","WIDTH=420,HEIGHT=450,SCROLLBARS,screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset);
}

function textareasize(fieldlength,displayname,fieldname){
	if (document.form1.elements[fieldname].value.length > fieldlength) {
		alert(displayname + " too long:\n" + document.form1.elements[fieldname].value.length + " characters\nmaximum: " + fieldlength + " characters");
		document.form1.elements[fieldname].focus()
		}
	}

// insertcode is used for bold, italic, underline and quote and just
// wraps the tags around a selection or prompts the user for some
// text to apply the tag to
function insertcode(tag, desc, form, field)
{
    // our textfield
    var textarea = b = document.forms[form].elements[field];

    // our open tag
    var open = "<" + tag + ">";

    // our close tag
    var close = "</" + tag + ">";

    if(!textarea.setSelectionRange)
    {
        var selected = document.selection.createRange().text;
        if(selected.length <= 0)
        {
            // no text was selected so prompt the user for some text
            textarea.value += open + prompt("Please enter the text you'd like to " + desc, "") + close;
        }
        else
        {
            // put the code around the selected text
            document.selection.createRange().text = open + selected + close;
        }

    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, b.selectionStart);

        // the selected text with tags before and after
        var codetext = open + textarea.value.substring(b.selectionStart, b.selectionEnd) + close;

        // the text after the selection
        var posttext = textarea.value.substring(b.selectionEnd, textarea.value.length)

        // check if there was a selection
        if(codetext == open + close)
        {
            //prompt the user
            codetext = open + prompt("Please enter the text you'd like to " + desc, "") + close;
        }

        // update the text field
        textarea.value = pretext + codetext + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}

// inserts an image by prompting the user for the url
function insertimage(form, field)
{
    // our textfield
    var textarea = document.forms[form].elements[field];

    // our image
    var image = "<img src='" + prompt("Please enter the url", "http://") + "' alt='' />";

    if(!textarea.setSelectionRange)
    {
        // get selected text
        var selected = document.selection.createRange().text;

        if(selected.length <= 0)
        {
            // no text was selected so add the image to the end
            textarea.value += image;
        }
        else
        {
            // replace the selection with the image
            document.selection.createRange().text = image;
        }
    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, b.selectionStart);

        // the text after the selection
        var posttext = textarea.value.substring(b.selectionEnd, textarea.value.length)

        // update the text field
        textarea.value = pretext + image + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}

// inserts a link by prompting the user for a url
function insertlink(form, field)
{
    // our textfield
    var b = textarea = document.forms[form].elements[field];

    // our link
    var url = prompt("Please enter the url", "http://");
    var link = "<a href=" + url + ">" + url + "</a>";

    if(!textarea.setSelectionRange)
    {
        // get selected text
        var selected = document.selection.createRange().text;

        if(selected.length <= 0)
        {
            // no text was selected so add the link to the end
            textarea.value += link;
        }
        else
        {
            // replace the selection with the link
            document.selection.createRange().text = link;
        }
    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, b.selectionStart);

        // the selected text with tags before and after
        var linktext = textarea.value.substring(b.selectionStart, b.selectionEnd);

        // the text after the selection
        var posttext = textarea.value.substring(b.selectionEnd, textarea.value.length)

        // update the text field
        textarea.value = pretext + "<a href=" + url + ">" + linktext + "</a>" + posttext;
    }

    // set the focus on the text field
    // textarea.focus();
}

function fix_quotes(field) {
  field.value = field.value.replace(/\u2013/g,'-');
  field.value = field.value.replace(/\u2014/g,'-');
  field.value = field.value.replace(/\u2018/g,"'");
  field.value = field.value.replace(/\u2019/g,"'");
  field.value = field.value.replace(/\u201C/g,'"');
  field.value = field.value.replace(/\u201D/g,'"');
  field.value = field.value.replace(/\u2026/g,'...');
  field.value = field.value.replace(/\u2022/g,'&bull;');
  }

function fix_unicode(form) {
  for (i=0;i<form.elements.length;i++) {
    field = form.elements[i];
    if (field.type == "text" || field.type == "textarea") {
      fix_quotes(field);
      }
    }
  }
