var Edit_Object = null;
function Bold(edit,obj)
{
    edit.focus(); 
    edit.document.execCommand("Bold");
}

function Italic(edit, obj)
{
    edit.focus();
    edit.document.execCommand("Italic");
}

function Underline(edit, obj)
{
    edit.focus();
    edit.document.execCommand("Underline");
}

function StrikeThrough(edit, obj)
{
    edit.focus();
    edit.document.execCommand("StrikeThrough");
}

function FontName(edit,name)
{
    edit.focus();
    edit.document.execCommand("FontName",false,name); 
}

function FontSize(edit,size)
{
    edit.focus();
    edit.document.execCommand("FontSize",false,size); 
}

function ForeColor(edit,color)
{
    edit.focus();
    edit.document.execCommand("ForeColor",false,color); 
}

function JustifyLeft(edit, obj)
{
    edit.focus();
    edit.document.execCommand("JustifyLeft");
}

function JustifyCenter(edit, obj)
{
    edit.focus();
    edit.document.execCommand("JustifyCenter");
}

function JustifyRight(edit, obj) 
{
    edit.focus();
    edit.document.execCommand("JustifyRight");
}

function CreateLink(edit, obj)
{
    edit.focus();
    showdivPopup(obj, div_CreateLink.innerHTML.replace("{0}", "<input id='linkUrl' name='linkUrl' type='text'>"));
}

function CreateLink2(edit, url) {
    edit.focus();
    if (url == '')
        return;
    edit.document.execCommand("CreateLink", false, url);
}

function InsertImage(edit, obj) 
{
    edit.focus();
    showdivPopup(obj, div_InsertImage.innerHTML.replace("{0}", "<input id='picUrl' name='picUrl' type='text'>"));
}

function InsertImage2(edit, url) {
    edit.focus();
    if (url == '')
        return;
    edit.document.execCommand("InsertImage", false, url);
 }

function InsertHTML(edit,html) {
    edit.focus();

    var found = false;

    if (edit.document.selection && edit.document.selection.createRange)
    {
        rng = edit.document.selection.createRange();
        if (rng != null) {
            rng.pasteHTML(html);
            found = true;
        }
    }

    if(!found)
    edit.document.execCommand("InsertHTML", false,html);
}

function Outdent(edit, obj)
{
    edit.focus();
    edit.document.execCommand("Outdent");
}


function Indent(edit, obj)
{
    edit.focus();
    edit.document.execCommand("Indent");
}

function InsertOrderedList(edit, obj)
{
    edit.focus();
    edit.document.execCommand("InsertOrderedList");
}

function InsertUnorderedList(edit, obj)
{
    edit.focus();
    edit.document.execCommand("InsertUnorderedList");
}

function SuperScript(edit, obj)
{
    edit.focus();
    edit.document.execCommand("SuperScript");
}

function SubScript(edit, obj)
{
    edit.focus();
    edit.document.execCommand("SubScript");
}

function Paste(edit, obj)
{
    edit.focus();
    edit.document.execCommand("Paste");
}

function Cut(edit, obj)
{
    edit.focus();
    edit.document.execCommand("Cut");
}

function Copy(edit, obj)
{
    edit.focus();
    edit.document.execCommand("Copy");
}

function Undo(edit, obj)
{
    edit.focus();
    edit.document.execCommand("Undo");
}

function Redo(edit, obj)
{
    edit.focus();
    edit.document.execCommand("Redo");
}

function RemoveFormat(edit, obj)
{
    edit.focus();
    edit.document.execCommand("RemoveFormat");
}

//function insertHTML(edit,html)
//{
//    edit.focus();
//    if(edit !=null)
//    {
//        edit.document.pasteHTML(html); 
//    }
//}

//function insertText(edit,text)
//{
//    edit.focus();
//    if(edit !=null)
//    {
//        edit.document.text = text; 
//    }
//}

function design(obj)
{
    obj.style.border = "1px solid red";
    obj.style.background = " #ffffff ";
    obj.style.padding = "0px";
    obj.style.filter = "alpha(opacity=80)"; 
}
   
function OnMouseMove(theDiv) {
    theDiv.onmouseleave = OnMouseLeave;
    theDiv.onmousedown = OnMouseDown; 
	theDiv.style.border = "1px solid #316AC5";
	theDiv.style.padding = "0px";
}
	
function OnMouseLeave() {
  	this.style.border = "0px solid #E9E9E9";
	this.style.padding = "1px"; 
}
	
function OnMouseDown() {
    this.style.border = "1px solid red";
    this.style.padding = "0px";
}

function showdivPopup(sender, html) {
    divPopup.innerHTML = html;
//    oPopup.document.body.style.fontSize = '9pt';
//    oPopup.document.body.style.lineHeight = '120%';
//    oPopup.document.body.style.backgroundColor = '#ffffff';
//    alert(divPopup.innerHTML);
    var obj = sender;
    var x = getLeft(obj) + obj.offsetWidth - 5;
    var y = getTop(obj) + obj.offsetHeight - 3;

    divPopup.style.left = x + 'px';
    divPopup.style.top = y + 'px';
    divPopup.style.visibility = "visible";
    //divPopup.focus();
}


function getTop(e) {
    var t = e.offsetTop
    while (e = e.offsetParent) t += e.offsetTop;
    return t;
}

function getLeft(e) {
    var l = e.offsetLeft
    while (e = e.offsetParent) l += e.offsetLeft;
    return l;
}

function closedivPopup() {
    divPopup.style.visibility = "hidden";
}