
	FOCUSED_DIV = "none";
	COLOR_METHOD = "";
	EDITABLE = false;
		
	function ed_swf()
	{	    
		popup6("main/toolbar/swfselector.aspx");
	}
	
	function insert_swf(swf,mname,w,h,bg,q,wm,fid,version,wrapeclass)
	{
		var sText = document.selection.createRange();
		if(bg.length==0)
		    bg="#ffffff";
		if(version.length==0)
		    version="8";
		
		
		var html="<div "+wrapeclass+">";
			html+="<div id='"+fid+"'>";
			html+="You don't have the Flash player 8 installed.<br />";
			html+="Please <a href='http://www.adobe.com/go/getflashplayer'>click here</a> to download the Flash plugin.<br />";
			html+="If you wish to bypass detection <a href='portfolio.html?detectflash=false'>click here</a>.";
			html+="</div>";
			html+="<script type='text/javascript'>";
			html+="var so = new SWFObject('cmsimages/"+swf+"', '"+mname+"', '"+w+"', '"+h+"', '"+version+"', '"+bg+"');";
			html+="so.addParam('quality', '"+q+"');";
			html+="so.addParam('wmode', '"+wm+"');";			
			html+="so.write('"+fid+"');";
			html+="</script>";
		    html+="</div>";		    
		    sText.pasteHTML(html);
    }	
    
    function ed_forms()
    {
        popup6("main/toolbar/insert_forms.html");
    }
    
    function popup6(page)
	{
	
	    my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=550,height=600");
	    //my_popup.close();
	}
	
	function Insert_Form(html)
	{	    
	    var sText = document.selection.createRange();
	    //if(sText.text!="")
	        sText.pasteHTML(html);
	}
	
	
	function ed_date()
	{
		var today = new Date();
        
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	    {   	        
	        var dt=document.createTextNode(today.toLocaleDateString());
	        window.getSelection().insertNode(dt);
	    }
	    else
	    {
	        var sel = document.selection.createRange();
	        var full_date = today.toLocaleString();
	        var time = today.toLocaleTimeString();
	        var regexp = new RegExp (time);
	        var date = full_date.replace(regexp, "")
            sel.pasteHTML(date);
	        sel.select();
	    }
    }
    
    function ed_time()
    {
	    var today = new Date();
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	    { 
	        var dt=document.createTextNode(today.toLocaleTimeString() + " ");
	        window.getSelection().insertNode(dt);
	    }
	    else
	    {        
            var sel = document.selection.createRange();
            sel.pasteHTML(today.toLocaleTimeString() + " ");
            sel.select();
        }
    }
	
	function ed_bold()
	{	
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	        window.getSelection().toggleTextStyle('font-weight', 'bold', '400');	    
	    else	    
		    document.execCommand("Bold");		
	}
	
	function insert_textoptions(fontname,fontsize,superscript,subscript,color,fontsizem)
	{
		    			 
	    if(fontname.length>0)
	    {	        
	        if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox	        
	        { 
	            window.getSelection().styleText('font-family', fontname);	           
	        }
	        else	        
	            ed_applyfont(fontname);
	    }
	        
	    if(fontsize.length>0)
	    {
	        if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox	        
	            window.getSelection().styleText('font-size', fontsizem);
	        else
	            ed_applysize(fontsize);
	    }
	    
	    if(superscript==1)
	        ed_superscript();
	    
	    if(subscript==1)
	        ed_subscript();
	        
	    if(color.length>0)
	    {
	        COLOR_METHOD="fg";
	        apply_color(color);
	    }
	}	
	
	function ed_applysize(val)
	{
		//identify_focus();		
		document.execCommand('FontSize',false,val);
	}
	
	function ed_applyfont(val)
	{
		//identify_focus();		
		document.execCommand('FontName',0,val);
	}
	
	function ed_superscript()
	{
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	    {
	        window.getSelection().styleText('vertical-align', 'super','');
	        window.getSelection().styleText('font-size', '80%','');
	    }
	    else
	    {	    
	        document.execCommand('superscript');
	    }
	}
	
	function ed_subscript()
	{
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	    {
	        window.getSelection().styleText('vertical-align', 'sub','');
	        window.getSelection().styleText('font-size', '80%','');
	    }
	    else
	        document.execCommand('subscript');
	}	
	
	function ed_strikethrough()
	{
	    //document.execCommand('strikethrough');	
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	    {
	        window.getSelection().toggleTextStyle('text-decoration','line-through', 'none');
	    }
	    else
	    {    
	        var oSelection = document.selection.createRange();
		    var text = oSelection.text;		
		    if(oSelection.text !="")
		    {
		        var elem =document.selection.createRange().parentElement();
                if(elem.tagName.toUpperCase()=='DEL')
                {                
                    document.selection.clear();
                    oSelection.pasteHTML(text);
                }
		        else
		            oSelection.pasteHTML("<del>"+text+"</del>");
		    }
		}
	}
	
	function showheading(divname,isvisible)
    {
        
        var div=document.getElementById(divname);
        if(isvisible==1)                
            div.style.display="";
        else 
            div.style.display="none";
    }
		
	function doHead(hvalue,htext)
	{
		if(hvalue != '')		
		{	    
		    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
		    {	        
		        if(htext == "Unformatted")
				    window.getSelection().removeLinesContainer();
			    else
				    window.getSelection().changeLinesContainer(htext);
		    }
			else
			{
			    if(htext != "Unformatted")		    		    
			        document.execCommand('formatblock', false, hvalue); 
			}
			document.getElementById('divheadings').style.display='none';
		}
	}
	
	function ed_italic()
	{
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	        window.getSelection().toggleTextStyle('font-style', 'italic', 'normal');
	    else
	        document.execCommand("Italic");	
	}	
	
	function fnonbeforepaste()
	{
		event.returnValue = false;		
		clip.innerHTML =window.clipboardData.getData("Text");
		window.clipboardData.setData("Text",clip.innerText);
	}
	
	function ed_bullets(a)
	{
	    if(a==1)
	    {
	        if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	            window.getSelection().toggleListLines("OL", "UL");
	        else
	        { 
	            document.execCommand('InsertOrderedList',true,null);
	        }
	    }
	    else
	    {
	        if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	            window.getSelection().toggleListLines("UL", "OL");
	        else
	        {
	            document.execCommand('InsertUnorderedList');
	        }
	    }
	    document.getElementById('divbullets').style.display='none';	    
	}


	function ed_link()
	{	    
	    my_popup= window.open ("main/toolbar/createlink.htm", "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=384,height=240");        
	}
	
	function ed_textoptions()
	{	    
        popup5("main/toolbar/textoptions.aspx");
	}

	function ed_link_site()
	{
	
		popup2("main/toolbar/page_link_selector.aspx");		
	}
	
	function insert_page_link(link)
	{	    
		if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
		{
		    window.getSelection().linkText(link);
		}
		else
		{
		    var oSelection = document.selection.createRange();
            if(isImage(oSelection))
		    {
		        	
		        var imgheight=oSelection(0).height;
		        var imgwidth=oSelection(0).width;
		        
		        if(imgheight!=0)
		            imgheight="height='"+imgheight+"'";
		        else
		            imgheight="";
		        if(imgwidth!=0)
		            imgwidth="width='"+imgwidth+"'";
		         else
		            imgwidth="";
		        
		        document.selection.clear();
		            		        
		        var image = "<img src='"+oSelection(0).src+"' class='"+oSelection(0).className+"' alt='"+oSelection(0).alt+"' title='"+oSelection(0).title+"' "+imgheight+" "+imgwidth+"  />";
		        var inlink = "<a href='"+link+"'>"+image+"</a>"
		        oSelection = document.selection.createRange();
		        oSelection.pasteHTML(inlink);
		        oSelection.select();
		    }
		    else
		    {		    
                var text = oSelection.text;            
                if(oSelection.text !="")
                {                   
                    document.selection.clear();
                    oSelection.pasteHTML("<a href='"+link+"'>"+text+"</a>");
                    oSelection.select();		    
                }
            }            
		    //document.execCommand('CreateLink',false,link);
		}
	}
	
	function insert_document_link(link,target)
	{
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
		{
		    window.getSelection().linkText(link);
		}
		else
		{
		    var oSelection = document.selection.createRange();
            if(isImage(oSelection))
		    {		        
		        var imgheight=oSelection(0).height;
		        var imgwidth=oSelection(0).width;
		        		        
		        if(imgheight!=0)
		            imgheight="height='"+imgheight+"'";
		        else
		            imgheight="";
		        if(imgwidth!=0)
		            imgwidth="width='"+imgwidth+"'";
		         else
		            imgwidth="";
		            
		        document.selection.clear();
		        
		        var image = "<img src='"+oSelection(0).src+"' class='"+oSelection(0).className+"' alt='"+oSelection(0).alt+"' title='"+oSelection(0).title+"' "+imgheight+" "+imgwidth+ "/>";
		        var link = "<a href='"+link+"' target='"+target+"'>"+image+"</a>"
		        oSelection = document.selection.createRange();		        
		        
		        oSelection.pasteHTML(link);
		        oSelection.select();
		    }
		    else
		    {		    
                var text = oSelection.text;                            
                if(oSelection.text !="")
                {                   
                    document.selection.clear();                    
                    oSelection.pasteHTML("<a href='"+link+"' target='"+target+"'>"+text+"</a>");
                    oSelection.select();		    
                }
            }	                 
	    }
	}		
	
	function apply_color(color)
	{
		if(COLOR_METHOD=="bg")
		{
		    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
		        window.getSelection().styleText('background-color', color);
		    else
			    document.execCommand('BackColor', false,color)		
		}
		if(COLOR_METHOD=="fg")
		{
		    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
		        window.getSelection().styleText('color', color);
		    else
			    document.execCommand('ForeColor', false,color)
		}
	}
	
	function ed_applysize(val)
	{
		//identify_focus();		
		document.execCommand('FontSize',false,val);
	}
	
	function insert_link(url,title,target)
	{
	   if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	   {
	        if(window.getSelection().isCollapsed) // must have a selection or don't prompt
				return;
				 	    	
			if(url != "") 
			{
			    window.getSelection().linkText(url);
		    }
			else
				window.getSelection().clearTextLinks();
	   }
	   else
	   {
            var oSelection = document.selection.createRange();
            if(isImage(oSelection))
		    {
		        
		        
		        var imgheight=oSelection(0).height;
		        var imgwidth=oSelection(0).width;
		        
		        
		        
		        if(imgheight!=0)
		            imgheight="height='"+imgheight+"'";
		        else
		            imgheight="";
		        if(imgwidth!=0)
		            imgwidth="width='"+imgwidth+"'";
		         else
		            imgwidth="";
		            
		        document.selection.clear();
		        
		        var image = "<img src='"+oSelection(0).src+"' class='"+oSelection(0).className+"' alt='"+oSelection(0).alt+"' title='"+oSelection(0).title+"' "+imgheight+" "+imgwidth+ "/>";
		        var link = "<a href='"+url+"' title='"+title+"' target='"+target+"'>"+image+"</a>"
		        oSelection = document.selection.createRange();		        
		        
		        oSelection.pasteHTML(link);
		        oSelection.select();
		    }
		    else
		    {		    
                var text = oSelection.text;            
                alert(text);
                if(oSelection.text !="")
                {                   
                    document.selection.clear();                    
                    oSelection.pasteHTML("<a href='"+url+"' title='"+title+"' target='"+target+"'>"+text+"</a>");
                    oSelection.select();		    
                }
            }
	    }
	}
	
	function Insert_Sybmol(a)
	{
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	    {
	        var td=document.createTextNode(a);	        
	        //window.getSelection().insertCharacter(65);
	        window.getSelection().insertHTML('<b>asim<b/>');
	    }
	    else
	    {
		    var oSelection = document.selection.createRange();
		    var text = oSelection.text;		
		    if(a=='&')
		        a='&amp;'
		    else if(a=='<')
		        a="&lt;"
	        oSelection.pasteHTML(a);
		    oSelection.select();
		}
					
	}	
	
	function ed_table()
	{   
	    popup("main/toolbar/inserttable.htm");	    
	}
	
	function Insert_Table(html)
	{
	    var oSelection = document.selection.createRange();			    
	    oSelection.pasteHTML(html);
	    oSelection.select();
			    
	}
	
	function ed_symbol()
	{
	    popup4("main/toolbar/symbol_selector.htm");		    	
	}
	
	function ed_document()
	{
	    popup3("main/toolbar/document_selector.aspx");		
	}
	
	function popup3(page)
	{	
	    my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=600,height=600");
	}
	
	
	function ed_color_bg()
	{	
		
	    COLOR_METHOD="bg";	
	    popupcolor("main/toolbar/color_selector.aspx");		
		
	}	
	
	function ed_color_fg()
	{
	    	
	    COLOR_METHOD="fg";
	    popupcolor("main/toolbar/color_selector.aspx");	
		
	}
	
	function ed_image()
	{	
		popupimage("main/toolbar/image_selector.aspx");	
	}
	
	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,gid,clas,title,alt,largeimage,width,height,border,bdcolor,bdstyle,padding)
	{	   
	    var style="";
	    if(border.length>0)
	        style+="border:"+border+" "+bdstyle+" "+bdcolor+";";
	        		    
	    if(padding.length>0)
	        style+="padding:"+padding+";"
		         
		if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox	    
		{		    
			var img = documentCreateXHTMLElement("img");
			img.src = "cmsimages/"+image; // any way to tell if it is valid?	
			img.setAttribute("alt",alt);
			img.setAttribute("title",title);		
			img.setAttribute("style",style);
			window.getSelection().insertNode(img);
		}		
		else
		{
		    var sText = document.selection.createRange();    		
		    //var html = "<a href=javascript:DisplayImage('cmsimages/"+image+"','"+width+"','"+height+"')><img src='cmsimages/"+image+"' alt='"+alt+"' title='"+title+"' /></a>";
		    
		        		    
		    var html = "<img src='cmsimages/"+image+"' alt='"+alt+"' title='"+title+"' style='"+style+"' "+clas+" />";		    
		    sText.pasteHTML(html);		
		}
	}
	
	function insert_image12(image,gid,cla)
	{	   
		my_popup.close();				 
		document.execCommand('InsertImage', false,'cmsimages/'+image);		
	}
	
	function insert_text()
	{
		var sText = body.document.selection.createRange();
		newLink = document.createElement("A");
		someText = document.createTextNode("hello");
		newLink.href = "Hello";
		newLink.appendChild(someText);
	}
	
	function insert_template(vtemplate)
	{
		var sText = document.selection.createRange();
		//identify_focus();
		sText.pasteHTML(vtemplate);		
		my_popup.close();
	}
	
	
	function ed_underline()
	{
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
	        window.getSelection().toggleTextStyle('text-decoration', 'underline', 'none');
	    else
		    document.execCommand('Underline');
    }
	
	function ed_align_left()
	{
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
		    window.getSelection().styleLines("text-align", "left");
		else
		    document.execCommand('JustifyLeft');
    }
	
	function ed_align_right()
	{
	    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
		    window.getSelection().styleLines("text-align", "right");
		else		
		    document.execCommand('JustifyRight');
	}
	
	function ed_align_center()
	{
		if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
		    window.getSelection().styleLines("text-align", "center");
		else
		    document.execCommand('JustifyCenter');
	}
	
	function ed_custom1()
	{
		popup("main/toolbar/color_selector.htm");
				
	}
	
	function ed_custom2()
	{	
		popup("main/toolbar/template_selector.htm");	
	}
	
	function ed_undo()
	{
	    document.execCommand('undo');
	}
	
	function ed_redo()
	{
	    document.execCommand('redo');
	}

	function popup(page)
	{
	
	    my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=384,height=240");
	}
	
	function popupimage(page)
	{
	
	    my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=400,height=600");
	}
	
	function popupcolor(page)
	{
	
	    my_popup= window.open (page, "my_popup","resizable=0,location=0,status=0,scrollbars=1,width=384,height=150");
	    //my_popup.close();
	    //alert(my_popup.returnValue);
	}
	
	function popup4(page)
	{
	
	    my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=300,height=400");
	    //my_popup.close();
	}
	
	function popup5(page)
	{
	
	    my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=350,height=400");
	    //my_popup.close();
	}
	
	function popup6(page)
	{
	
	    my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=550,height=600");
	    //my_popup.close();
	}

	function popup2(page)
	{	
	    my_popup= window.open (page, "my_popup","resizable=1,location=0,status=0,scrollbars=1,width=300,height=340");
	}
	
	// Helping Functions
	 
	function isImage(oSelection)
	{
		if(document.selection.type == "Control")
			{
			if(oSelection(0).tagName == "IMG")
				return true;
			else
				return false;
			}
		else 
			return false;
	}
	
	function isTable(oSelection)
	{
		if(document.selection.type == "Control")
			{
			if(oSelection(0).tagName == "TABLE")
				return true;
			else
				return false;
			}
		else 
			return false;
	}
	
	
	function isAnchor(oSelection)
	{
		if(document.selection.type == "Control")
		{
			oElement = oSelection(0).parentElement;
		}
	
		else
		{
			oElement =oSelection.parentElement();
		}
		//document.Form1.TraceBox.value = oElement.tagName;

		
		while (oElement.parentElement != null)
		{
			if(oElement.tagName =="A")
			break;
			oElement = oElement.parentElement;
		}
		if(oElement.tagName == "A")
		{
		return true;
		}
		else 
		{
		return false;
		}
	}
	
/**
	EDITABLE PORTION IDENTIFICATION AND FOCUS
 **/
function change_to()
	{
		oElement=body.document.activeElement;
		if(oElement.id == "edit_body" | oElement.id == "right_column" | oElement.id == "left_column")
		FOCUSED_DIV = oElement.id;
	}
	
	function GetFirstDiv()
	{
		var val;
		val = document.getElementById("tbxalldivs").value;
		var dat=val.split(";");
		return dat[0];
	}
	
	function GetAllDives()
	{
		var val;
		val = document.getElementById("tbxalldivs").value;
		var dat=val.split(";");
		return dat;		
	}
	
	function EditAllDives()
	{
		var dat=GetAllDives();
	}	


function identify_focus()
	{
		
		//div = document.getElementById(FOCUSED_DIV);
		if(FOCUSED_DIV == "none")
		{
			FOCUSED_DIV=GetFirstDiv();
			document.all[FOCUSED_DIV].setActive();
			document.all[FOCUSED_DIV].focus();
		}
		else
		{
			document.all[FOCUSED_DIV].setActive();
			document.all[FOCUSED_DIV].focus();				
		}
		
		//{
		//body.focus();
		//}
	}
	
	function setfocustodiv(a)
	{		
		FOCUSED_DIV=a		
	}
	
function detect_editable()
	{
				
	
	}
	
function apply_editable_style()
{
	
}

//////////////////////////// table menu code////////////////////////////

var dialogProperties="dialogWidth:400px; dialogHeight:180px; resizable:no; scroll:no; status:no; help:no; edge:raised;";

    var el;
    var el1;
    var can_hide=false;
    function TestTable() {
        if (document.selection.type == "Control") {
            var objControlRange = document.selection.createRange();
            if (objControlRange(0).tagName.toUpperCase() == "TABLE") {
                TABLE = document.selection.createRange()(0);
                return true;
            }
        }
    return false;
    }
    
    function toggleMenu() {
       //el1=event.srcElement;
       /*if (el1.className=="menuItem") {
          el1.className="highlightItem";
       } else if (el1.className=="highlightItem") {
          el1.className="menuItem";
       }*/
    }
    
      function deleteColumn()
        {
            if (document.selection.type != "Control") {
                            var elem = document.selection.createRange().parentElement()
                            while (elem.tagName.toUpperCase() != "TD" && elem.tagName.toUpperCase() != "TH")
                              {
                                elem = elem.parentElement;
                                if (TD == null) return;
                              }
            }
                TD = elem;
                TR = elem.parentElement;
                TABLE = TR.parentElement.parentElement;
                EndCount = (TR.cells.length-1) - (TD.cellIndex)
                allRows = TABLE.rows
                for (var i=0;i<allRows.length;i++) {
                    endOfRow = allRows[i].cells.length - 1
                    position = endOfRow - EndCount
                    if (position < 0) {
                        position = 0
                    }
                    allCellsInRow = allRows[i].cells
                    if (allCellsInRow[position].colSpan > 1) {
                        allCellsInRow[position].colSpan = allCellsInRow[position].colSpan - 1
                    } else {                    allRows[i].deleteCell(position)
                    }
                }
        }
        
        function deleteRow()
        {
            if (document.selection.type != "Control") {
            var elem = document.selection.createRange().parentElement()
            while (elem.tagName.toUpperCase() != "TD" && elem.tagName.toUpperCase() != "TH")
              {
                elem = elem.parentElement;
                if (elem == null) return;
              }
            }
            TR = elem.parentElement;
            TABLE = TR.parentElement.parentElement;
            TABLE.deleteRow(TR.rowIndex);
        }
        
        function TablePropertiesDialog()
        {
            var TableProperties=new Object();
            if (TestTable()){
                TableProperties.width=TABLE.width;
                TableProperties.height=TABLE.height;
                TableProperties.cellpadding=TABLE.cellPadding;
                TableProperties.cellspacing=TABLE.cellSpacing;
                TableProperties.borderColor=TABLE.borderColor;
                TableProperties.border=TABLE.border;
                TableProperties.bgcolor=TABLE.bgColor;
            today = new Date();
            nocash="?nocash="+today.getTime();
                showModalDialog('main/toolbar/table.htm'+nocash,TableProperties,dialogProperties);
                TABLE.bgColor=TableProperties.bgcolor;
                TABLE.border=TableProperties.border;
                TABLE.borderColor=TableProperties.borderColor;
            TABLE.cellPadding=TableProperties.cellpadding;
            TABLE.cellSpacing=TableProperties.cellspacing;
            TABLE.width=TableProperties.width;
            TABLE.height=TableProperties.height;
            }
        }

    
    function hideMenu(menu) {
    if (can_hide){
       menu.releaseCapture();
       menu.style.display="none";
       el1=event.srcElement;
       if (el1.doFunction != null) {
         eval(el1.doFunction);
       }
    }
        can_hide=true;
    }
    
     function CellDialog()
     {
        if (document.selection.type != "Control") {
                        var elem = document.selection.createRange().parentElement()
                        while (elem.tagName.toUpperCase() != "TD" && elem.tagName.toUpperCase() != "TH")
                              {
                                elem = elem.parentElement                                
                              }
        }            
            var HTML=showModalDialog('main/toolbar/cell.htm',elem,dialogProperties);            
        //mytext.focus();
    }

    
    function TestTableCell() {
        if (document.selection.type != "Control") {
                          var elem = document.selection.createRange().parentElement()
                          while (elem.tagName.toUpperCase() != "TD" && elem.tagName.toUpperCase() != "TH")
                          {
                            elem = elem.parentElement
                            if (elem == null) return false
                          }
                if (elem) return true
        }
    return false;
    }
    
    function TableDialog()
    {    
        //popup("main/toolbar/inserttable.htm");
        today = new Date();
        nocash="?nocash="+today.getTime();
        var HTML=showModalDialog('main/toolbar/table.htm'+nocash,"",dialogProperties);                
        var sel = document.selection;
        if (sel!=null) {
            var rng = sel.createRange();
                    if (rng!=null) {
                rng.pasteHTML(HTML);
            }
        }        
       // if (ShowGuidelines == "yes") {ToggleGuidelines();ToggleGuidelines();}
    }   
    
    
function TableOptions()
{
    if (navigator.userAgent.indexOf("Firefox")!=-1)	//code for firefox
    {
        var rowno = prompt("number of rows");
		var colno = prompt("number of columns");
		var te = documentCreateXHTMLTable(rowno, colno);
		if(!te)
			alert("Can't create table: invalid data");
		else
		{
		    te.setAttribute("border","1px");
			window.getSelection().insertNode(te);
		}
    }
    else
    {   
       can_hide=false;
       //ContextElement=event.srcElement;
       
       tableOptions.style.leftPos+=5; 
       //alert(event.clientX);
       tableOptions.style.display="";
           
       if (TestTable())  {
            TOInsertTable.style.display="none";
            TOTableProperties.style.display="";
       }
       else  {
            TOTableProperties.style.display="none";
            TOInsertTable.style.display="";
       }
       if (TestTableCell()) {
            TOCellProperties.style.display="";
            TOCellPropertiesSeparator.style.display="";
            TOInsertRowAbove.style.display="";
            TOInsertRowBelow.style.display="";
            TOInsertSeparator.style.display="";
            TOInsertColumntoLeft.style.display="";
            TOInsertColumntoRight.style.display="";
            TODeleteSeparator.style.display="";
            TODeleteColumn.style.display="";
            TODeleteRow.style.display="";
       }  
       else {
            TOCellProperties.style.display="none";
            TOCellPropertiesSeparator.style.display="none";
            TOInsertRowAbove.style.display="none";
            TOInsertRowBelow.style.display="none";
            TOInsertSeparator.style.display="none";
            TOInsertColumntoLeft.style.display="none";
            TOInsertColumntoRight.style.display="none";
            TODeleteSeparator.style.display="none";
            TODeleteColumn.style.display="none";
            TODeleteRow.style.display="none";
       }
        tableOptions.setCapture();        
    }
    }
    
    
    function InsertRow(location) {
        if (document.selection.type != "Control") {
                        var elem = document.selection.createRange().parentElement()
                        while (elem.tagName.toUpperCase() != "TD" && elem.tagName.toUpperCase() != "TH")
                          {
                            elem = elem.parentElement;
                            if (elem == null) return;
                          }
        }
            TR = elem.parentElement
            TABLE = TR.parentElement.parentElement
            var numCols = 0
            allCells = TR.cells
            for (var i=0;i<allCells.length;i++) {
                numCols = numCols + allCells[i].getAttribute('colSpan')
            }
            var newTR="";
            if (location=="above") newTR=TABLE.insertRow(TR.rowIndex);
            if (location=="below") newTR=TABLE.insertRow(TR.rowIndex+1);
            for (i = 0; i < numCols; i++) {
                newTD = newTR.insertCell()
                newTD.innerHTML = "&nbsp;"
            }
    }



    function InsertColmn(location) {
        if (document.selection.type != "Control") {
                        var elem = document.selection.createRange().parentElement()
                        while (elem.tagName.toUpperCase() != "TD" && elem.tagName.toUpperCase() != "TH")
                          {
                            elem = elem.parentElement;
                            if (elem == null) return;
                          }
        }
            TD = elem;
            TR = elem.parentElement;
            TABLE = TR.parentElement.parentElement;
            EndCount = (TR.cells.length-1) - (TD.cellIndex);
            allRows = TABLE.rows;
            for (i=0;i<allRows.length;i++) {
                rowCount = allRows[i].cells.length-1;
                position = rowCount - EndCount
                if (position < 0) {
                    position = 0
                }
                if (location=="left")  newCell = allRows[i].insertCell(position)
                if (location=="right") newCell = allRows[i].insertCell(position+1)
                newCell.innerHTML = "&nbsp;"
            }
    }