function button_over(eButton)
	{
	eButton.style.backgroundColor = "#B5BDD6";
	eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
	}
function button_out(eButton)
	{
	eButton.style.backgroundColor = "threedface";
	eButton.style.borderColor = "threedface";
	}
function button_down(eButton)
	{
	eButton.style.backgroundColor = "#8494B5";
	eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
	}
function button_up(eButton)
	{
	eButton.style.backgroundColor = "#B5BDD6";
	eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
	eButton = null; 
	}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var isHTMLMode=false
var RetryCount;
var DefaultEditorID='1';
var loader;
var editorTitle;

function InsertItem(pLoader)
	{	
		var nodeID=pLoader.id.substring(6,pLoader.id.length);	
		if(nodeID==0)
			GetElement('NodeID').value='null';
		else
			GetElement('NodeID').value=nodeID;		
		if(typeof(idContent)!='undefined')
			GetElement('Body').value=idContent.document.body.innerHTML;		
	}

function LoadEditor(obj,title)
	{	
		var PresetEditorID=GetCookie('EditorID');
		var RetryCount=0;
		loader=obj;
		editorTitle=title;
		loader.innerHTML='LOADING ...';

		if ((PresetEditorID==null)||(PresetEditorID==""))
			PresetEditorID=DefaultEditorID	
		GetElement('editors').src='/EditorSimple/Default.aspx?dontparse=true&EditorID=' + PresetEditorID;
		if (title==null)
			title="";
		setTimeout('FillDiv("'+escape(title)+'")',2000)			
	}
	
function ResetEditor(obj)
	{
		GetElement('editors').src='';
		obj.innerHTML='';
	}
	
function SwitchEditor(obj)
	{
		var PresetEditorID=GetCookie('EditorID');
		
		ResetEditor(obj);		
		if(PresetEditorID==null)
			PresetEditorID=DefaultEditorID;
		if(PresetEditorID=='1')
		{
			SetCookie('EditorID','0');
		}
		else
		{
			SetCookie('EditorID','1');
		}			
		LoadEditor(obj);
	}	
	
function GetElement(o)
	{
	if (document.all)  
		return document.all[o];
	else        
		return document.getElementById(o);
	}
	
function GetCookie(name) 
	{
	var a, b, cook; 
	cook = ' ' + document.cookie + ';'
	a = cook.indexOf(' ' +name+"="); 
	if (a != -1)  {
		a += name.length+2; 
		b = cook.indexOf(";", a);
		if (b == -1) b = cook.length;
		return unescape(cook.substring(a, b));       
	} 
	return null; 
	} 

function SetCookie(sName, sValue)
	{
	date = new Date();
	document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2010 23:59:59 GMT;";
	}

function DelCookie(sName)
	{
	document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
	}

function FillDiv(title)
	{	
		var temp=(window.frames['editors'].document.body).innerHTML;
		
		if(temp==''&&RetryCount<5)
		{
			setTimeout('FillDiv("'+title+'")',1000);
			++RetryCount;
		}
		else
		{	
			try
			{
				loader.innerHTML=temp;
			}
			catch (ex)
			{
				loader.innerHTML="";
				var div=document.createElement("DIV");
				div.innerHTML=temp;
				loader.appendChild(div);
			}
			if(typeof(idContent)=="object")
				idContent.document.designMode="On";

			if (title!="")
			{
				var title_el=FindChildEl(loader,"Title");
				if (title_el!=null)
					title_el.value=unescape(title);
			}
			
			GetElement('AuthorName').focus();
		}
	}

function FindChildEl(par,id)
{
	if (par.childNodes==null)
		return null;
	
	for (var a=0;a<par.childNodes.length;a++)
		if ((par.childNodes[a].id!=null)&&(par.childNodes[a].id==id))
			return par.childNodes[a];
		else
		{
			var find=FindChildEl(par.childNodes[a],id);
			if (find!=null)
				return find;
		}
		
	return null;
}

function checkParent(src, dest) 
	{
		while (src!=null && src.tagName != "BODY")
		{		
			if (src.tagName == dest)
			{
				return src;
			}
			else
			{
				src = src.parentNode;
			}
		}
		return null;
	}

function cmdExec(cmd,opt) 
	{
  	idContent.document.execCommand(cmd,"",opt);idContent.focus();
	}
	
function createLink()
	{	
	cmdExec("CreateLink");
	}
	
function insertImage()
	{
	var sImgSrc=prompt("Insert Image : ", "http://www.netdirect.cz/aspnet/sample.jpg");
	if(sImgSrc!=null) cmdExec("InsertImage",sImgSrc);
	}
	
function Save() 
	{
	GetElement('Body').innerHTML=idContent.document.body.innerHTML;
  	var sImgTag = idContent.document.body.all.tags("IMG");
  	var oImg;
  	for (var i = sImgTag.length - 1; i >= 0; i--) 
		{
    	oImg = sImgTag[i];
    	alert("Add your code to Upload local image file here. Image Inserted : " + oImg.src );
  		}
  	alert("Add your code to Save Document here");
  	alert("Your Document : " + GetElement('Body').innerHTML);
	}
function foreColor()
	{
	var arr = showModalDialog("/EditorSimple/selcolor.htm","","font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:34em" );
	if (arr != null) cmdExec("ForeColor",arr);	
	}
