<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<meta name="generator" content="Adobe GoLive 6" />
		<title>Menu Extension</title>
	</head>

	<body>
		<hr />
		<p>ADOBE SYSTEMS INCORPORATED</p>
		<p>Copyright 2000 - 2002 Adobe Systems Incorporated<br />
			All Rights Reserved</p>
		<p>NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the Adobe license agreement accompanying it. If you have received this file from a source other than Adobe, then your use, modification, or distribution of it requires the prior written permission of Adobe.</p>
		<hr />
		<p><b>Extension Name:</b> LayoutGrid</p>
		<p><b>Folder name:</b> LayoutGrid</p>
		<hr />
		<p><b>Description:</b></p>
		<p>Layout Grid - Converts the layout grid to a table.</p>
		<hr />
		<p><b>Module Definition:</b></p>
		<jsxmodule info="$$$/info=This extension adds a menu item to the Special menu that converts a GoLive layout grid into a table." name="layoutGridXTND" version="1.0" /> 
		<p><b>Scripts:</b></p>
		<script><![CDATA[

//--------------------------------------------------------------------
// CALLBACK FUNCTIONS
//--------------------------------------------------------------------

// test the preferences by using a persistent counter

function initializeModule()
{
	if (prefs.count == undefined)
		prefs.count = 0;
	
	convertDialog.getterLink = null;
}

function checkForGrid()
{
		if(document != null)
			{
			if(document.selection != null && document.selection.element != undefined)
				{
				var element = document.selection.element;
		
				if(element.tagName == "table" && element.cool != undefined)
					{
					if(element.parent.textArea != undefined)
						{
						var searchElement = element.parent;
						
						while(searchElement.textArea == element.textArea)
							{
							if(searchElement.tagName.toLowerCase() == "table" && searchElement.cool != undefined)
								return false;
							searchElement = searchElement.parent;
							}
						return true;
						
						}
						
					}
				}
			}
		return false;
}

function menuSetup(menuItem)
{
	switch (menuItem.name)
	{
		case "layouttotable":
			menuItem.enabled = checkForGrid();
			break;
	}
}

function menuSignal(menuItem)
{
	switch (menuItem.name)
	{
		case "layouttotable":
			convertDialog.stripCheck.state = true;
			convertDialog.spacerReplace.state = false;
			convertDialog.spacerReplace.enabled = false;
			convertDialog.urlgetter.enabled = false;
			
			if (convertDialog.runModal())
				convertToTable();
			
		convertDialog.urlgetter.setLink();
		if(convertDialog.getterLink != null)
				{
				document.removeLink(convertDialog.getterLink);
				convertDialog.getterLink = null;
				}	
			break;
	}
}

function controlSignal (control) 
{
	switch (control.name)
		{
		case "stripCheck":
			if(control.state)
				{
				convertDialog.spacerReplace.state = false;
				convertDialog.spacerReplace.enabled = false;
				convertDialog.urlgetter.enabled = false;
				convertDialog.urlgetter.setLink("");
				}
			else
				{
				convertDialog.spacerReplace.state = false;
				convertDialog.spacerReplace.enabled = true;
				convertDialog.urlgetter.enabled = false;
				convertDialog.urlgetter.setLink("");
				}
			break;
		case "spacerReplace":
			if(control.state)
				{
				if(convertDialog.getterLink == null)
					convertDialog.getterLink = document.createLink("");
					
				convertDialog.urlgetter.enabled = true;
				convertDialog.urlgetter.setLink(convertDialog.getterLink);
				}
			else
				{
				convertDialog.urlgetter.enabled = false;
				convertDialog.urlgetter.setLink("");
				}
			break;
		}
}

function checkProperty(element,prop)
	{
	var str = prop.toLowerCase();
	
	if(str == "border"
		|| str == "cellspacing"
		|| str == "cellpadding"
		|| str == "background"
		|| str == "bgcolor"
		||  str == "align"
		||  str == "valign"
		||  str == "width" 
		||  str == "height"
		||  str == "rowspan" 
		||  str == "colspan")
		return true;
	return false;
	}
	
function createStartTag(element)
	{
		var str = "";
		
		str = "<" + element.tagName;

		for(var prop in element)
			{
			if(checkProperty(element,prop))
				{ 
				if(element[prop] != undefined)
					{ 
					str += " " + prop + "=" +"\"";
					str += element[prop] +"\"";
					}
				}
			}
		str += ">";	
		return str;
	}
	
function createStartLayoutTag(element)
	{
		var str = "";
		
		str = "<" + element.tagName;

		for(var prop in element)
			{
			if(checkProperty(element,prop))
				{ 
				if(element[prop] != undefined)
					{
					if(convertDialog.stripCheck.state)
						{
						if(prop == "width")
							{
							str += " " + prop + "=" +"\"";
							str += (element[prop]-1) +"\"";
							continue;
							}
						else if (prop == "height")
							{
							str += " " + prop + "=" +"\"";
							str += (element[prop]-1) +"\"";
							continue;
							}
						}

					str += " " + prop + "=" +"\"";
					str += element[prop] +"\"";
					}
				}
			}
		str += ">";	
		return str;
	}
	
function createEndTag(element)
	{
		var str = "";
		
		str = "</" + element.tagName + ">\n";
		return str;
	}
	
function addRow(element)
	{
	var str = "";

	if(convertDialog.stripCheck.state)
		{
		for(var prop in element)
			{
			str = prop.toLowerCase();
			if(str == "cntrlrow")
				return "";
			}
		}
		
	str = "";
	
	str += createStartTag(element);	
	
	var cellCount = element.subElements.length;
	
	if(convertDialog.stripCheck.state)
		cellCount--;
	
	for(var i=0;i<cellCount;i++)
		{
		var subElement = element.subElements[i];
		str += createStartTag(subElement);
		
		var innerString = subElement.getInnerHTML();
		
		if(convertDialog.spacerReplace.state)
			{
			if(subElement.subElements.length==1)
				{
				var spacerElement = subElement.subElements[0];
				if(spacerElement.tagName.toLowerCase() =="spacer")
					{
					innerString = "<img src=\"" + convertDialog.getterLink.url + "\" width=\"" + spacerElement.width +  "\" height=\"" + spacerElement.height + "\">";
					}
				}
			}
				
		str += innerString;
		str += createEndTag(subElement);
		}

	str += createEndTag(element);	
	
	return str;
	}
	
function convertToTable()
	{
	var tableElement = null;
	
	if(document != null)
		{
		if(document.selection != null && document.selection.element != undefined)
			{
			var element = document.selection.element;
			
			if(element.tagName == "table" && element.cool != undefined)
				tableElement = element;
			}
		}
	
	
	if(tableElement != null)
		{
		var content = "";
		
		content += createStartLayoutTag(tableElement);
		
		for(var i=0;i<tableElement.subElements.length;i++)
			{
			var subElement = tableElement.subElements[i];
			var tagName = subElement.tagName.toLowerCase();
			if(tagName == "tr")
				content += addRow(subElement);
			else
				{
				if(tagName == "csnopos")
					{
					for(var j=0;j<subElement.subElements.length;j++)
						{
						var csPosElement = subElement.subElements[j];
						content += csPosElement.getInnerHTML();
						}
					}
				}
			}
			
		content += createEndTag(tableElement);
		tableElement.parent.textArea.insertHTML(content);
		}
	}

		]]></script>
		<p>The menu bar</p>
		<jsxmenubar>
			<jsxmenu name="special">
				<jsxmenu name="CONV">
					<jsxitem dynamic="dynamic" name="layouttotable" location="before" lname="CON5" title="$$$/item=Layout Grid to Table..." />
				</jsxmenu>
			</jsxmenu>
		</jsxmenubar>
		<p>The dialog</p>
		<jsxdialog height="160" name="convertDialog" title="$$$/dlg=Convert" width="260">
			<jsxcontrol height="19" name="stripCheck" posx="15" posy="15" type="checkbox" value="$$$/check1=Strip Control Row and Column" width="210"></jsxcontrol>
			<jsxcontrol height="19" name="spacerReplace" posx="15" posy="59" type="checkbox" value="$$$/check2=Replace Spacers by Image" width="220"></jsxcontrol>
			<jsxcontrol height="21" name="urlgetter" posx="15" posy="85" type="URLGetter" width="211"></jsxcontrol>
			<jsxcontrol height="19" name="dialogcancel" posx="90" posy="125" type="button" value="$$$/cancel=Cancel" width="65"></jsxcontrol>
			<jsxcontrol height="19" name="dialogok" posx="160" posy="125" type="button" value="$$$/ok=OK" width="65"></jsxcontrol>
		</jsxdialog>
	</body>

</html>