
function formatStr (v) {
    if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    if (v == 'ul') {
      //document.selection.createRange().text = '<' + v + '>\n' + str + '\n</' + v + '>';
      rExp = /\r\n/gi;
      str = '<ul><li class="li">' + str + '</li></ul>';
      str = str.replace(rExp, '</li>\n<li class="li">');
      //rExp = /<ul class="li"><li><\/li>/gi;
      //str = str.replace(rExp, '<ul>');
      rExp = /<li class="li"><\/li>/gi;
      str = str.replace(rExp, '');
      document.selection.createRange().text = str;
    }
    else if (v == 'dl') {
      //document.selection.createRange().text = '<' + v + '>\n' + str + '\n</' + v + '>';
      rExp = /\r\n/gi;
      str = '<dl><dd class="dd">' + str + '</dd></dl>';
      str = str.replace(rExp, '</dd>\n<li class="dd">');
      //rExp = /<dl class="dd"><dd><\/dd>/gi;
      //str = str.replace(rExp, '<dl>');
      rExp = /<dl class="dd"><\/dd>/gi;
      str = str.replace(rExp, '');
      document.selection.createRange().text = str;
    }
    /*
    else if (v == 'li') {
      document.selection.createRange().text = '  <' + v + '>' + str + '</' + v + '>';
    }
    */
    else if (v == 'highlight') {
      //document.selection.createRange().text = '<font class="content_highlight">' + str + '</font>';
      str = '<font class="highlight">' + str + '</font>';
      rExp = /\r\n/gi;
      str = str.replace(rExp, '</font>\r\n<font class="content_highlight">');
      document.selection.createRange().text = str
    }
    else if (v == 'h') {
      //document.selection.createRange().text = '<p class="title_sub">' + str + '</p>\n';
      str = '<p class="title_sub">' + str + '</p>\n';
      rExp = /\r\n/gi;
      str = str.replace(rExp, '</p>\r\n<p class="title_sub">');
      document.selection.createRange().text = str
    }
/*
    else if (v == 'consultants') {
      //document.selection.createRange().text = '<p class="title_small">' + str + '</p>\n';
      //alert('Hello!');
      insertAtCaret(document.pages.PageContent, "<!--Consultants-->");
      //alert('Hello! Hello!');
    }
*/
    else {
      //document.selection.createRange().text = '<' + v + '>' + str + '</' + v + '>';
      str = '<' + v + '>' + str + '</' + v + '>';
      rExp = /\r\n/gi;
      str = str.replace(rExp, '</' + v + '>\r\n<' + v + '>');
      document.selection.createRange().text = str
    }
}

function storeCaret (textEl) {
  if (textEl.createTextRange)
    textEl.caretPos = document.selection.createRange().duplicate();
}
function insertAtCaret (textEl, text) {
  if (textEl.createTextRange && textEl.caretPos) {
    var caretPos = textEl.caretPos;
    caretPos.text =
    caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
    text + ' ' : text;
  }
  /*
  else {
    textEl.value  = text;
    alert('Hi!');
  }
  */
}


function validate() {
  if (document.forms[0].Email.value == '') {
    alert("You must enter an Email address!")
    document.forms[0].Email.focus();
    //return false;
  }
  else if (document.forms[0].Password.value == '') {
    alert("You must enter a Password!")
    document.forms[0].Password.focus();
    //return false;
  }
  else if (document.forms[0].Firstname.value == '') {
    alert("You must enter the Firstname!")
    document.forms[0].Firstname.focus();
    //return false;
  }
  else if (document.forms[0].Lastname.value == '') {
    alert("You must enter the Lastname!")
    document.forms[0].Lastname.focus();
    //return false;
  }
  else {
    document.forms[0].submit();
  }
}



function helpWindow() {
  helpText = '';
  helpText = helpText + '<html><head><link rel=stylesheet type=text/css href=/Style.css></head><body>';
  helpText = helpText + '    <p class=title_small>Content Edit Help</p>';
  helpText = helpText + '    <table width="100%" cellpadding="0" cellspacing="0" border="0">';
  helpText = helpText + '    <tr>';
  helpText = helpText + '      <td valign="top" class="bar_text">';
  helpText = helpText + '        &#160;';
  helpText = helpText + '      </td>';
  helpText = helpText + '    </tr>';
  helpText = helpText + '    </table>';

  helpText = helpText + '    <ul>';

  helpText = helpText + '      <li class=content_small_noindent>';
  helpText = helpText + '        <b>List:</b>';
  helpText = helpText + '        To create a bulleted items list, make sure to have each item in the list end with a single carriage return (Enter key).';
  helpText = helpText + '        Select the items, then click the <i>List</i> button.';
  helpText = helpText + '        The proper formatting HTML code will be inserted into the text.';
/*
  helpText = helpText + '        Creating a bulleted items list is simple, two step process.';
  helpText = helpText + '        First, create your list of items, separating each by single carriage return (Enter key).';
  helpText = helpText + '        Make sure to do any other formatting (for example, bold, or links) to the list items before continuing.';
  helpText = helpText + '        Then, after you have finished creating your list of items,';
  helpText = helpText + '        select the entire list (all the list items and any HTML code already generated for them),';
  helpText = helpText + '        then click the List button.';
  helpText = helpText + '        The text will be properly reformatted with the proper HTML code.';
  helpText = helpText + '        For multiple lists on the same page, repeat the above two steps for each individual list.';
*/
  helpText = helpText + '      </li>';
  helpText = helpText + '      <li class=content_small_noindent>';
  helpText = helpText + '        <b>Left Margin:</b>';
  helpText = helpText + '        To create an indented left margine, separate your paragraphs with a single carriage return (Enter key).';
  helpText = helpText + '        Select the paragraphs, then click the <i>Left Margin</i> button.';
  helpText = helpText + '        The proper formatting HTML code will be inserted into the text.';
  helpText = helpText + '      </li>';

  helpText = helpText + '      <li class=content_small_noindent>';
  helpText = helpText + '        <b>Bold, Italics, Underline, Highlight, Center:</b>';
  helpText = helpText + '        Simply select the text that you want to format,';
  helpText = helpText + '        then click the respective button for the type of formatting you would like to apply.';
  helpText = helpText + '        The proper formatting HTML code will be inserted into the text.';
  helpText = helpText + '      </li>';

  helpText = helpText + '      <li class=content_small_noindent>';
  helpText = helpText + '        <b>Headline:</b>';
  helpText = helpText + '        Note that the page title will appear automatically.';
  helpText = helpText + '        Simply select the text that you want to format as a headline,';
  helpText = helpText + '        then click the <i>Headline</i> button.';
  helpText = helpText + '        The proper formatting HTML code will be inserted into the text.';
  helpText = helpText + '      </li>';

  helpText = helpText + '      <li class=content_small_noindent>';
  helpText = helpText + '        <b>External Link:</b>';
  helpText = helpText + '        To create a link, first select the text that you want to make into the link';
  helpText = helpText + '        (this is the text that the site visitor will click on to visit the page you want them to go to).';
  helpText = helpText + '        Then click on the <i>URL Link</i> button.';
  helpText = helpText + '        A dialog box will then appear prompting you for the URL, a.k.a. website/web page address.';
  helpText = helpText + '        Type the URL you want to link to into the text box in the prompt';
  helpText = helpText + '        (make sure to include the <i>http://</i> portion of the URL), then click <i>OK</i>.';
  helpText = helpText + '        A second dialog box will then appear, asking if the link is to a different website (i.e. NOT garritytoolcompany.com):';
  helpText = helpText + '        if so, click <i>OK</i>; otherwise, click <i>Cancel</i>.';
  helpText = helpText + '        The proper link HTML code will then be inserted into the text.';
  helpText = helpText + '      </li>';

  helpText = helpText + '      <li class=content_small_noindent>';
  helpText = helpText + '        <b>Mail Link:</b>';
  helpText = helpText + '        To create an email link, first select the text that you want to make into the link';
  helpText = helpText + '        (this is the text that the site visitor will click on to launch the email).';
  helpText = helpText + '        Then click on the <i>Mail Link</i> button.';
  helpText = helpText + '        A dialog box will then appear prompting you for the mailto email address, i.e. the email address you want the message sent to when they click the link.';
  helpText = helpText + '        Type the email address you want into the text box in the prompt, then click <i>OK</i>.';
  helpText = helpText + '        (make sure to include the <i>mailto:</i>, with the email address after with no spaces), then click <i>OK</i>.';
  helpText = helpText + '        The proper link HTML code will then be inserted into the text.';
  helpText = helpText + '      </li>';

  helpText = helpText + '      <li class=content_small_noindent>';
  helpText = helpText + '        <b>Special Content:</b>';
  helpText = helpText + '        To insert special content, just place your curser in the Page Content box where you would like the special content to appear.';
  helpText = helpText + '        Then click on the content button of the content you want to insert (for example, "Instructors").';
  helpText = helpText + '        The special content code will be inserted into the text, indicating where the content will appear among your text.';
  helpText = helpText + '        Note that your special content will NOT appear in the Text Preview area.';
  helpText = helpText + '      </li>';

  helpText = helpText + '      <li class=content_small_noindent>';
  helpText = helpText + '        <b>Images:</b>';
  helpText = helpText + '        To embed an image into your page, just place your curser in the Page Content box where you would like the image to appear.';
  helpText = helpText + '        Then use the "Select An Image" dropdown to select your image (a thumbnail of the image will be shown to the left),';
  helpText = helpText + '        and decide whether to give the image a border or to justify it.';
  helpText = helpText + '        You can also resize it (with or without constrained proportions) but this is not recommended;  it is instead recommended that you resize the image to an appropriate size prior to uploading.';
  helpText = helpText + '        Once your parameters are correct, click the Insert Image button and the proper image HTML code will then be inserted into the text.';
  helpText = helpText + '      </li>';

  helpText = helpText + '      <li class=content_small_noindent>';
  helpText = helpText + '        <b>Internal Links:</b>';
  helpText = helpText + '        Internal Links are links to items anywhere on your website (as opposed to external links to things on other websites).';
  helpText = helpText + '        There are three types of Internal Links: an HTML page, created with the Pages tool;  an uploaded PDF file;  or an uploaded image (.jpg, .gif, etc.) file.';
  helpText = helpText + '        To create an internal link, first select the text that you want to make into the link';
  helpText = helpText + '        (this is the text that the site visitor will click on to launch the email).';
  helpText = helpText + '        Then select the item to be linked <i>to</i> from the appropriate dropdown in the Internal Links section';
  helpText = helpText + '        (for images, a thumbnail preview will be shown to the right).  Then click the Internal Link button';
  helpText = helpText + '        The proper link HTML code will then be inserted into the text.';
  helpText = helpText + '      </li>';


  helpText = helpText + '    </ul>';
  helpText = helpText + '    <p class=content_small_center><a href=javascript:window.close(); class=content_link>Close Window</a></p>';
  helpText = helpText + '</body></html>';

  myWindow = window.open("", "tinyHelpWindow", 'toolbar=no,width=320,height=360,top=50,left=250,scrollbars=yes,resizable=yes');
  myWindow.document.write(helpText);
  myWindow.document.bgColor="#FFFFF0";
  myWindow.document.close();
  myWindow.focus();
}

// Allows instant preview of HTML
function ShowPreview() {
  // replace div innerHTML content
  //previewarea.innerHTML = '<table border=1 width=100 height=100% cellpadding=0 cellspacing=0><tr><td valign=top align=left>' + pages.PageContent.value + '</td></tr></table>';
  previewarea.innerHTML = pages.PageContent.value;

  // replace div innerHTML content
  thisText = pages.PageContent.value;
    
  myString = new String(thisText)
  rExp = />\r\n</gi
  myString = myString.replace(rExp, '><')
  rExp = /\n/gi;
  //newString = new String ("http://www.devguru.com")
  //results = myString.replace(rExp, '</p><p class=content>')
  myString = myString.replace(rExp, '</p><p class=content>')

  rExp  = /<!--/gi;
  myString = myString.replace(rExp, '[!--')
  rExp  = /-->/gi;
  myString = myString.replace(rExp, ' List--]')
  
  results = myString

  //alert(results)

  //previewarea.innerHTML = pages.PageContent.value;
  previewarea.innerHTML = '<p class=content>' + results + '</p>';
}
