var wtedit_constant={
        viewMode:1
}


var wtedit_fn={
    doBold:function()
    {
        document.getElementById('iView').contentWindow.document.execCommand('bold', false, null);
    },
    doItalic:function()
    {
        document.getElementById('iView').contentWindow.document.execCommand('italic', false, null);
    },
    doUnderline:function()
    {
        document.getElementById('iView').contentWindow.document.execCommand('underline', false, null);
    },
    doLeft:function()
    {
        document.getElementById('iView').contentWindow.document.execCommand('justifyleft', false, null);
    },
    doCenter:function()
    {
        document.getElementById('iView').contentWindow.document.execCommand('justifycenter', false, null);
    },
    doRight:function()
    {
        document.getElementById('iView').contentWindow.document.execCommand('justifyright', false, null);
    },
    doOrdList:function()
    {
        document.getElementById('iView').contentWindow.document.execCommand('insertorderedlist', false, null);
    },
    doBulList:function()
    {
        document.getElementById('iView').contentWindow.document.execCommand('insertunorderedlist', false, null);
    },
    doForeCol:function()
    {
        var fCol = prompt('Enter foreground color', '');
            
        if(fCol != null)
        {
            document.getElementById('iView').contentWindow.document.execCommand('forecolor', false, fCol);
        }
    },
    doBackCol:function()
    {
        var bCol = prompt('Enter background color', '');
            
        if(bCol != null)
        {
            document.getElementById('iView').contentWindow.document.execCommand('backcolor', false, bCol);
        }
    },
    doLink:function()
    {
        var szURL = prompt("Enter the URL", "");

        document.getElementById('iView').contentWindow.document.execCommand('createlink',false,szURL);
    },
    doImage:function (imgSrc)
    {
        if(imgSrc != '')
        {
            document.getElementById('iView').contentWindow.document.execCommand('insertimage', false, imgSrc);
        }
    },
    doRule:function()
    {
        document.getElementById('iView').contentWindow.document.execCommand('inserthorizontalrule', false, null);
    },
    doFont:function(fName)
    {
        if(fName != '')
        {
            document.getElementById('iView').contentWindow.document.execCommand('fontname', false, fName);
        }
    },
    doSize:function(fSize)
    {
        if(fSize != '')
        {
            document.getElementById('iView').contentWindow.document.execCommand('fontsize', false, fSize);
        }
    },
    doHead:function(hType)
    {
        if(hType != '')
        { 
            document.getElementById('iView').contentWindow.document.execCommand('formatblock', false, hType);   
            doFont(selFont.options[selFont.selectedIndex].value);
        }
    },
    doToggleView:function()
    { 
        if(wtedit_constant.viewMode === 1)
        {
            if($.browser.msie)
            {
                //internet explorer
                var iHTML = document.getElementById('iView').contentWindow.document.body.innerHTML;
      
                document.getElementById('iView').contentWindow.document.body.innerText = iHTML;
            }
            else if ($.browser.mozilla)
            {
                //mozilla
                var html = document.createTextNode(document.getElementById('iView').contentWindow.document.body.innerHTML);
                document.getElementById('iView').contentWindow.document.body.innerHTML = "";
                document.getElementById('iView').contentWindow.document.body.appendChild(html);

            } 
            else
            {
                alert('Only Internet Explorer and FireFox currently supported.');
            }
          
            // Hide all controls except toggle button
            $('.topRow').hide();  
            $('#selFont').hide();  
            $('#selSize').hide();  
            $('#selHeading').hide();
            $('#selImage').hide();
              
            document.getElementById("iView").contentWindow.focus();
                  
            wtedit_constant.viewMode = 2; // Code
        }
        else
        {
            if($.browser.msie)
            {
                //internet explorer
                var iText = document.getElementById('iView').contentWindow.document.body.innerText;
     
                document.getElementById('iView').contentWindow.document.innerHTML = iText;
            }
            else if ($.browser.mozilla)
            {
                //mozilla
                var html = document.getElementById('iView').contentWindow.document.createRange();
                html.selectNodeContents(document.getElementById('iView').contentWindow.document.body);
                document.getElementById('iView').contentWindow.document.body.innerHTML = html.toString();

            } 
            else
            {
                alert('Only Internet Explorer and FireFox currently supported.');
            }
          
            // Show all controls
            $('.topRow').show(); 
            $('#selFont').show(); 
            $('#selSize').show();  
            $('#selHeading').show();
            $('#selImage').show();
              
            document.getElementById("iView").contentWindow.focus();
                  
            wtedit_constant.viewMode = 1; // WYSIWYG
        }
     
    },
    saveContent:function()
    {
        var contentArea;
        if(wtedit_constant.viewMode === 1)
        { 
            //html
            if($.browser.msie)
            {
                //internet explorer
                contentArea = document.getElementById('iView').contentWindow.document.body.innerHTML;
            }
            else if ($.browser.mozilla)
            {
                //mozilla
                contentArea = document.getElementById('iView').contentWindow.document.body.innerHTML;
            } 
            else
            {
                alert('Only Internet Explorer and FireFox currently supported.');
            }
        }
        else
        {
            //text
            if($.browser.msie)
            {
                //internet explorer
                contentArea = document.getElementById('iView').contentWindow.document.body.innerText;
            }
            else if ($.browser.mozilla)
            {
                //mozilla    
                var html = document.getElementById('iView').contentWindow.document.createRange();
                html.selectNodeContents(document.getElementById('iView').contentWindow.document.body);
                contentArea = html.toString();
            } 
            else
            {
                alert('Only Internet Explorer and FireFox currently supported.');
            }
        }
        //put in asp.net control
        $('#txtEditorContent').val(contentArea);
    }
};

  


  

