
var testEl;

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function cmdButton(cmd, promptText)
{
	if (!testEl)
	{
		var oDoc = iframe.contentWindow || oIframe.contentDocument;
		if (oDoc.document)
		{
			oDoc = oDoc.document;
		}
		testEl = oDoc.getElementById('testElement');
	}
	var bool = false;
	var smilie = false;
	var value = "";
	switch (cmd)
	{
        case 'createLinkURL':
            cmd = 'createLink';
            break;
        case 'createLinkeMail':
            cmd = 'createLink';
            value = 'mailto:' + value;
            break;
        case 'smilie':
            smilie = true;
	}
	if (smilie == false)
	{
        if (promptText != "") { value = prompt(promptText); }
        var returnValue = iframe.contentWindow.inBetween(cmd,bool,value);
    } else {
        insertText2(promptText);
    }
}

function cmdButton2(cmd, promptText)
{
	var bool = false;
	var smilie = false;
	var strURL = "";
    var strCaption = "";
    var value = "";

	switch (cmd)
	{
        case 'createLinkURL':
            strCaption = prompt("Enter the on screen display text for the Hyperlink", "");
            if (strCaption == "") { return; }
            strURL = prompt("Enter the URL address to create Hyperlink to", "http://");
            if (strURL == "") { return; }
            value += "[URL=" + strURL + "]" + strCaption + "[/URL]";
            if (strURL == null || strCaption == null)
            {
                alert("You did not answer both of the required questions.");
            } else {
                insertText2(value);
            }
            break;
        case 'createLinkeMail':
            strCaption = prompt("Enter the on screen display text for the email address", "");
            if (strCaption == "") { return; }
            strURL = prompt("Enter the email address to link to");
            if (strURL == "") { return; }
            value += "[EMAIL=" + strURL + "]" + strCaption + "[/EMAIL]";
            if (strURL == null || strCaption == null)
            {
                alert("You did not answer both of the required questions.");
            } else {
                insertText2(value);
            }
            break;
        case 'bold':
            strCaption = prompt("Enter text you want formatted in Bold\n[B]xxx[/B]", "");
            if (strCaption == "") { return; }
            value += "[B]" + strCaption + "[/B]";
            insertText2(value);
            break;
        case 'italic':
            strCaption = prompt("Enter text you want formatted in Italic\n[I]xxx[/I]", "");
            if (strCaption == "") { return; }
            value += "[I]" + strCaption + "[/I]";
            insertText2(value);
            break;
        case 'smilie':
            smilie = true;
            insertText2(" " + promptText + " ");
            break;
        case 'quote':
            smilie = true;
            var varAuthor = $("#bubble" + promptText + " cite strong a").text();
            var varContent = $("#bubble" + promptText + " blockquote :not(p.h1)").html();
            varContent
            varContent = trim(varContent);
            varContent = varContent.replace("<b>", "[b]"); 
            varContent = varContent.replace("</b>", "[/b]"); 
            varContent = varContent.replace("<p>", ""); 
            varContent = varContent.replace("</p>", ""); 
            varContent = varContent.replace(/\<br\>/gi, "\r\n"); 
            varContent = varContent.replace(/\<br\/\>/gi, "\r\n"); 
            varContent = varContent.replace(/\<span class\="quoted"\>/gi, "");
            varContent = varContent.replace(/\<\/span\>/gi, ""); 
            insertText2("[quote=" + varAuthor + "]" + varContent + "[/quote] \n");

            var p = $('#frmContent').position();
            $('html, body').animate({scrollTop: (p.top - 550) }, 'slow', 'swing');             

	}
    document.getElementById('txtContent').focus();
    return false;
}

function Source()
{
    var oDoc = iframe.contentWindow || oIframe.contentDocument;
    return oDoc.document.body.innerHTML;
}
function formPost()
{
    var src = Source();
    var srcTest = src;

    srcTest = srcTest.replace("<br>", ""); 
    srcTest = srcTest.replace("&nbsp;", ""); 
    srcTest = srcTest.replace(/^\s+|\s+$/g, '') ;

    var author = "";
    try
    {
        author = document.getElementById('txtauthor').value;
        if (author == "")
        {
            bool = false;
            alert("Please enter your name");
            document.getElementById('txtauthor').focus();
            return false;
        }
    } catch (e)
    {
    }
    var bool = true;
    if (srcTest == "")
    {   
        bool = false;
        alert("Please enter your post");
        return false;
    }
    
    if (bool == true)
    {
        document.getElementById('hidpost').value = src; 
        document.frmpost.submit();
    }
}
function formPost2()
{
    var src = document.getElementById('txtContent').value;
    //var author = "";
    var bool = true;
    var srcTest = src.replace(/^\s+|\s+$/g, '') ;
    //try
    //{
    //    //author = document.getElementById('txtauthor').value;
    //    author = $('#txtauthor').val();
    //    if (author == "")
    //    {
    //        bool = false;
    //        alert("Please enter your name");
    //        document.getElementById('txtauthor').focus();
    //        return;
    //    }
    //} catch (e) {
    //}
    if (srcTest == "")
    {   
        bool = false;
        alert("Please enter your post");
        document.getElementById('txtContent').focus();
        return false;
    }
    
    if (bool === true)
    {

        return true;
        //test = test.replace(/\[b\]/gi, '<b>') ;

        //document.frmContent.submit();
        //$("#frmContent").submit();

    }
}
function insertText(content)
{
    var oDoc = iframe.contentWindow || oIframe.contentDocument;
    var txt = oDoc.document.body.innerHTML;
    oDoc.document.body.innerHTML += content;

} 
function insertText2(content)
{
    var txt = document.getElementById('txtContent').value;
    document.getElementById('txtContent').value += content;

} 
function reportConcern(id)
{
    var varAuthor = $("#bubble" + id + " cite strong a").text();
    var varDate = $("#bubble" + id + " cite span").text();
    var varTopic = $('p.h1').text();
    var varContent = $("#bubble" + id + " blockquote").text();
    varContent = varContent.replace('\n', '%0d%0a');
    window.location.href = 'mailto:louisa@beautyguild.com?subject=Report%20Form%20Post%20Concern&body=' + 'Topic: ' + varTopic + '%0d%0aAuthor: ' + varAuthor + '%0d%0aDate Time: ' + varDate + '%0d%0a%0d%0a' + varContent + '%0d%0a%0d%0a';
}

