
	FOCUSED_DIV = "right_section";
	FOCUSED_DIV = "left_section";
	FOCUSED_DIV = "main";

	
	COLOR_METHOD = "";
	EDITABLE = false;
	
	window.onload = detect_editable;
	

	function ed_popupselector_popup()
	{
		popup("main/toolbar/popupselector.aspx");
	}
	
	
	

	function insert_template(vtemplate)
	{
			
		identify_focus();
		var sText = main.document.selection.createRange();
		
		sText.pasteHTML(vtemplate);
		
		my_popup.close();
	}
	
	
	
	function ed_Change_Font()
	{
		identify_focus();	
		document.execCommand("FontName",0,"tahoma"); 
	}

	function doHead(hType)
	{
		if(hType != '')
		{
			var selFont 
			document.execCommand('formatblock', false, hType); 
		}
	}


	function ed_bold()
	{
		identify_focus();	
		document.execCommand("bold");
	}
	

	
	function ed_italic()
	{
		identify_focus();		
		document.execCommand('Italic');
	
	}	
	
	function ed_applysize(val)
	{
		identify_focus();		
		document.execCommand('FontSize',false,val);
	}	
	
	function ed_bullet()
	{
		identify_focus();		
		document.execCommand('InsertUnorderedList');
	}	
	




	function ed_link()
	{
		var oSelection = main.document.selection.createRange();
		if(isAnchor(oSelection))
			document.execCommand('CreateLink');
		else 
		{
			insert_link();
		
		}
			
	}

	function ed_link_site()
	{
	
		popup2("main/toolbar/page_link_selector.aspx");

		
	}
	
	function insert_page_link(link)
	{
		document.execCommand('CreateLink',false,link);
	}
	
	
	function apply_color(color)
	{
		var oSelection = main.document.selection.createRange();
		
		if(COLOR_METHOD=="bg")
		{
			
			oSelection(0).bgColor = color;
			
		}
		if(COLOR_METHOD=="fg")
		{
			document.execCommand('ForeColor', false,color)

		}
	}

	
	function insert_link()
	{
		
		var oSelection = main.document.selection.createRange();
		
		if(document.selection.type == "Text")
		{	
			oText = oSelection.text;
			if(oSelection.text !="")						
			{
				document.execCommand('CreateLink');
				
			}
		}
		
					
			
		else
		{
			
			document.execCommand('CreateLink');
		} 
		
	}
	
	function inslink ()
    {
	    var slink = showModalDialog("sellink.htm","","dialogHeight: 280px; dialogWidth: 310px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: yes; resizable: Yes; status: yes;" );
        if (slink != null){;     
		    var testo=document.selection.createRange().text;  
		    var testohtml=document.selection.createRange();
		    testohtml.pasteHTML ("<a href='"+slink+">"+testo+"</a>");
	    }
    }
	
	function ed_color_bg()
	{
		
		var oSelection = main.document.selection.createRange();
		
		
		COLOR_METHOD="bg";
		if(isTable(oSelection))
		{
			popup("main/toolbar/color_selector.htm");
			
		}
		
	}
	
	
	
	function ed_color_fg()
	{
	
	COLOR_METHOD="fg";
	popup("main/toolbar/color_selector.htm");
	
	}
	
	function ed_image()
	{
		
		identify_focus();		
		popup("main/toolbar/image_selector.aspx?getid=1");
		
	
	}
	
		function ed_image1()
	{
		
		identify_focus();	
		popup("main/toolbar/image_selector.aspx?getid=2");
		
	
	}
	
	
	
	function ed_edit_image()
	{
	

		var oSelection = document.selection.createRange();
		if(isImage(oSelection))
		{		
				document.execCommand('InsertImage', true,'opt');
		}
		else 
		{
			alert("Not an Image");
		}
		
	}
	
	
	function insert_image(image,Check,wrapimage)
	{
	
	
			identify_focus();		
			var sText = main.document.selection.createRange();
			
			var thepic = "thepic"+Math.round( 1+Math.random()*1000);
					
			var path = 'cmsimages/'+image;
					
			textA = "<IMG id="+thepic+ wrapimage +"name="+thepic+" SRC='" +path+ "'>";
			
			sText.pasteHTML(textA);
				
			high = document.getElementById(thepic).height;
			wide = document.getElementById(thepic).width;
			
			
			var h;
			var w;
			
			if (wide > 200)
			{
			
				a = high;
				b = wide;
				c = 200;

    			
				d = (a*c)/b;
				
				document.getElementById(thepic).height = d;
				document.getElementById(thepic).width = c;

			}
			my_popup.close();	
			
			
		
	}
	
	


		
	function insert_text()
	{
		var sText = main.document.selection.createRange();
		newLink = document.createElement("A");
		someText = document.createTextNode("hello");
		newLink.href = "Hello";
		newLink.appendChild(someText);
				

	}
	
	
	function ed_underline()
	{
		document.execCommand('Underline');
	}
	
	function ed_align_left()
	{
		identify_focus();		
		document.execCommand('JustifyLeft');

	}
	
	function ed_align_right()
	{
		identify_focus();		
		document.execCommand('JustifyRight');
	}
	
	function ed_align_center()
	{
		identify_focus();		
		document.execCommand('JustifyCenter');
	}
	
	function ed_custom1()
	{
		popup("main/toolbar/color_selector.htm");
				
	}
	
	function ed_custom2()
	{
	
		popup_temp("main/toolbar/template_selector.htm");
	
	}
	
	
	
	
	
	function popup(page)
	{
	
	
	my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=300,height=300");
	

	}
	
	
	
	
	
	
	function popup2(page)
	{	
	my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=300,height=340");
	}
	
	function popup_temp(page)
	{	
	my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=230,height=60");
	}
	
	
	 
	function isImage(oSelection)
	{
		if(document.selection.type == "Control")
			{
			if(oSelection(0).tagName == "IMG")
				return true;
			else
				return false;
			}
		else 
			return false;
	}
	
	
	
	function isAnchor(oSelection)
	{
		if(document.selection.type == "Control")
		{
			oElement = oSelection(0).parentElement;
		}
	
		else
		{
			oElement =oSelection.parentElement();
		}
		

		
		while (oElement.parentElement != null)
		{
			if(oElement.tagName =="A")
			break;
			oElement = oElement.parentElement;
		}
		if(oElement.tagName == "A")
		{
		return true;
		}
		else 
		{
		return false;
		}
	}
	

function change_to()
	{
		oElement=main.document.activeElement;
		if(oElement.id == "main" | oElement.id == "left_section" | oElement.id == "right_section")
		FOCUSED_DIV = oElement.id;
	}

function identify_focus()
	{
		
	
		document.all[FOCUSED_DIV].setActive();
		document.all[FOCUSED_DIV].focus();
		
	
		
		
	}
	
	
	//function fnonbeforepaste()
	//{
		//event.returnValue = false;
		
		//clip.innerHTML =window.clipboardData.getData("Text");
		//window.clipboardData.setData("Text",clip.innerText);
	//}
	
function detect_editable()
	{
		if(document.getElementById("main") != null) 
			if(main.isContentEditable)
			{
				
				document.onselectionchange = change_to;
				apply_editable_style();	
				//document.body.onbeforepaste = fnonbeforepaste;
			}
		
		
		
		if(document.getElementById("left_section") != null)
			if(left_section.isContentEditable)
			{
				
				document.onselectionchange = change_to;
				apply_editable_style();			
				
			}
			
		if(document.getElementById("right_section") != null)
			if(right_section.isContentEditable)
			{
				
				document.onselectionchange = change_to;
				apply_editable_style();			
				
			}
		
	
	}
	
function apply_editable_style()
{
	if(document.getElementById("main") != null)
	document.getElementById("main").className = "body_portion_editable";

	if(document.getElementById("left_section") != null)
	document.getElementById("left_section").className = "left_column_portion_editable";
	
	if(document.getElementById("right_section") != null)
	document.getElementById("right_section").className = "right_column_portion_editable";
	

}



function ed_media()
{
	popup("main/toolbar/media_selector.aspx");
}

function insert_media_link(media)
	{
		document.execCommand('CreateLink',false,"cmsmedia/"+media);
	}


function insert_media(video)
{
		
		identify_focus();
		var sText = main.document.selection.createRange();
		
		textA = "<img dynsrc='cmsmedia/";
		textB ="' width=160 height=94 border=0>";
		
		textA="<a class='standard' href='cmsmedia/";
		textB="'><img border='0' src='main/toolbar/images/play.gif' width='61' height='59'></a>"
		
		sText.pasteHTML(textA + video + textB);
		

		
		
		
	}

	
function Formatting()
{
	identify_focus();
	var sText = main.document.selection.createRange();
	if(window.getSelection) 
	{
		return window.getSelection();
	}
	else if(document.selection.createRange().text)
	{
		var ssText = document.selection.createRange().text;
		sText.pasteHTML(Del(ssText));
	}
}

	
	function Del(Word) 
	{
		a = Word.indexOf("<");
		b = Word.indexOf(">");
		len = Word.length;
		c = Word.substring(0, a);
		if(b == -1)
		b = a;
		d = Word.substring((b + 1), len);
		Word = c + d;
		tagCheck = Word.indexOf("<");
		if(tagCheck != -1)
		Word = Del(Word);
		return Word;
	}
	
	


