var newState;
var sInitColor = null;
var editor;
var HTMLTextBox;
var ColorBtn;

//Move 
/*window.onscroll = window_onscroll;

function window_onscroll()
{
    if (document.all) 
    {
        //alert(document.body.scrollTop);
        try 
        { 
            dwindow.style.top = document.body.scrollTop;
        }
        catch(e)
        {
        }
    }
}*/

/*function SetEditor()
{
    document.getElementById("").focus("editor");
    //editor.focus();
}*/


//*************Image List *************************
function ShowImagList(ImageDivName)
        {
           if(ImageDivName.style.visibility == "visible")
           {         
             ImageDivName.style.visibility = "hidden";
           }
           else
           {
                ImageDivName.style.left = event.x;
                ImageDivName.style.top = event.y;
                ImageDivName.style.visibility = "visible";
           }
        }
//*************************************************
//****************Popup Menu**********************
    var prvObj = null;
                
        function ShowList(obj)
        {   
            if(prvObj != null && obj.id != prvObj.id)
            {   prvObj.style.visibility = "hidden";
            }
            if(obj.style.visibility == "visible")
            {   obj.style.visibility = "hidden";
            }
            else
            {   
                var Post = event.x - 130; 
                obj.style.left = Post;
                obj.style.visibility = "visible";
            }   
             prvObj = obj; 
        }  
//************************************************

function SetSelectedEditArea(obj, txtBoxObj)
{
	editor = obj;
	HTMLTextBox = txtBoxObj;
}
function EditDoc(cmd)
{
	//window.alert(cmd);
	switch(cmd)
	{
		case "FontSize":
		    //var Fs = document.getElementById("FntSize")
			//var Fs=FntSize.value;
			//editor.document.execCommand(cmd,false,Fs);
			break;
		case "FontName":
			var Fn=ddFont.value;
			editor.document.execCommand(cmd,false,Fn);
			break;
		case "FormatBlock":
			var BF= ddBlocFormats.value;
			editor.document.execCommand(cmd,false,BF);	
			break;
		case "InsertImage":
			editor.document.execCommand(cmd,false); //InsertImagePrompt
			break;	
		default:
			editor.document.execCommand(cmd);
	};
	editor.focus;
	WriteToTextbox();
}

function CreateLink()
{
    editor.document.execCommand('createLink', true);
    editor.focus;
    WriteToTextbox(); 
}

function setFontSize(obj)
{
    editor.document.execCommand("FontSize",false,obj.value);
    editor.focus;
    WriteToTextbox(); 
}

function InsertImage(obj)
{
    editor.document.execCommand("InsertImage",false,obj.value);  
    editor.focus;
    WriteToTextbox(); 
}

function fnToggleEdits(oObj,oBtn) 
{
    currentState = oObj.isContentEditable;
    newState = !currentState;
    oObj.contentEditable = newState;
    
    newState==false ? oBtn.src= 'images/Icon_off.gif': //  .innerHTML='Turn Editing On' :
        oBtn.src='images/Icon_on.gif';
}

function fnInit(){
   editor.unselectable = "off";
   editor.focus();
   editor.document.execCommand("FontSize",false,"2pt"); 
}

/*function WriteToEditor(obj)
{
    editor.innerHTML = obj.value;
}*/

//function WriteToTextbox(obj)
function WriteToTextbox()
{
	//alert(editor.innerHTML);
	HTMLTextBox.value = editor.innerHTML;
}

function getSystemFonts()
{
	var a=dlgHelper.fonts.count;
	for(var i=1; i<a; i++)
	{ 
		var newOpt = new Option(dlgHelper.fonts(i), dlgHelper.fonts(i));
	}
} 

function getBlockFormats()
{
	var a=dlgHelper.blockFormats.count;
	for(var i=1; i<a; i++)
	{ 
		var newOpt = new Option(dlgHelper.blockFormats(i), dlgHelper.blockFormats(i));
	}
}  

function callColorDlg(sColorType)
{
	if (sInitColor == null) 
		var sColor = dlgHelper.ChooseColorDlg();
	else
		var sColor = dlgHelper.ChooseColorDlg(sInitColor);
	sColor = sColor.toString(16);
	
	if (sColor.length < 6) 
	{
  		var sTempString = "000000".substring(0,6-sColor.length);
  		sColor = sTempString.concat(sColor);
	}
	document.execCommand(sColorType, false, sColor);
	sInitColor = sColor;
	editor.focus();
}

var colorStatus = false;
function ShowColorList()
{
	colorStatus = !colorStatus;
	if(colorStatus)
		tdt.style.visibility = "";
	else
		tdt.style.visibility = "hidden"; 
}

function SetStrColor(colorStr)
{
    //alert(ColorBtn)
   
    if(ColorBtn == "btn_forcolor")
        ColorType = "forecolor";
    else
        ColorType = "backcolor";
    //alert(ColorType)  
    //if (color == null) { alert("Invalid color code: " + string); return 0;}
	var obj = document.getElementById('DivColorTable');
	obj.style.visibility = "hidden"; 
	//editor.document.execCommand("ForeColor","false","#" + colorStr);
	editor.document.execCommand(ColorType,"false","#" + colorStr);
	editor.focus;
    WriteToTextbox(); 
    
}  

//function ShowBFColorList()
//{   
//	colorStatus = !colorStatus;
//	if(colorStatus)
//		BFC.style.visibility = "";
//	else
//		BFC.style.visibility = "hidden"; 
//}

//function SetBFColor(colorStr)
//{   
//	editor.document.execCommand("BackColor","false","#" + colorStr);
//}
//***************Color Table*******************************
function View(color) 
{                  // preview color
  document.all.ColorPreview.style.backgroundColor = '#' + color;
  document.all.ColorHex.value = '#' + color;
  //editor.document.execCommand("ForeColor","false","#" + color);
}

function iSet(string) 
{                   // select color
 color = ValidateColor(string);
  if (color == null) { alert("Invalid color code: " + string); }        // invalid color
  else {                                                                // valid color
    View(color);     }                     // show selected color
    //window.returnValue = color;           // set return value
    //window.close();   */                    // close dialog
}

function ValidateColor(string) 
{                // return valid color code
  string = string || '';
  string = string + "";
  string = string.toUpperCase();
  chars = '0123456789ABCDEF';
  out   = '';

  for (i=0; i<string.length; i++) {             // remove invalid color chars
    schar = string.charAt(i);
    if (chars.indexOf(schar) != -1) { out += schar; }
  }
    
  if (out.length != 6) { return null; }            // check length
  return out;
} 

function ShowColorList(Obj)
{
    var o = Sys.UI.DomElement.getLocation(Obj);
    //alert(o.x);
    var tblColor = document.getElementById('DivColorTable');
    tblColor.style.left= Obj.offsetLeft;
 	tblColor.style.top = Obj.offsetTop;
 	tblColor.style.visibility = "visible";
 	ColorBtn = Obj.id;    
}
//**************Color Table End*******************************  
//**********Move Toolbar**********************************
var dragapproved=false;
var minrestore=0;
var initialwidth,initialheight;
var ie5=document.all&&document.getElementById;
var ns6=document.getElementById&&!document.all;
var SelectDiv;

function drag_drop(e)
{
	//alert(WindName);
	if (ie5&&dragapproved&&event.button==1)
	{
		document.getElementById(SelectDiv).style.left=tempx+event.clientX-offsetx+"px";
		document.getElementById(SelectDiv).style.top=tempy+event.clientY-offsety+"px";
	}
	else if (ns6&&dragapproved)
	{
		document.getElementById(SelectDiv).style.left=tempx+e.clientX-offsetx+"px";
		document.getElementById(SelectDiv).style.top=tempy+e.clientY-offsety+"px";
	}
}

function initializedrag(e,WindName)
{
	SelectDiv = WindName;
	offsetx=ie5? event.clientX : e.clientX
	offsety=ie5? event.clientY : e.clientY
	tempx=parseInt(document.getElementById(WindName).style.left)
	tempy=parseInt(document.getElementById(WindName).style.top)

	dragapproved=true
	document.getElementById(WindName).onmousemove=drag_drop
}

function stopdrag(WindName)
{
	dragapproved=false;
	document.getElementById(WindName).onmousemove=null;
}




//*****************************************************

//**************Image TV On Master Page****************
function ShowImgBox(obj)
{
    document.getElementById("tblDisplayImg").style.visibility = "visible";
    document.getElementById("tblDisplayImg").src = obj.src;
}

function HideImgBox()
{
    document.getElementById("tblDisplayImg").style.visibility = "Hidden";
}
//*****************************************************