//globals
var sitePalette = getSitePalette();
var boxTypeArray = new Array();
var boxArray = new Array();
var generalContentArray = new Array();
var workingBoxId = 0;
var boxIndex = -1;
var currentFontEdit = ''
var currentStyleItem = '';
var xmlPost;


//style index
var styleUseTab = 0;
var styleBottomDropShadow = 1;
var styleRightDropShadow = 2;
var styleTopLeftRounded = 3;
var styleTopRightRounded = 4;
var styleBottomLeftRounded = 5;
var styleBottomRightRounded = 6;
var styleBottomSperator = 7;
var styleLeftSeperator = 8;


//objects
function boxType(id, name, helpHTML, minHeight, minWidth, infoBox, listBox, pollBox, whatsHotBox, rotatingBox)
{
	this.id = id;
	this.name = name;
	this.helpHTML = helpHTML;
	this.minHeight = minHeight;
	this.minWidth = minWidth;
	this.isInfoBox = infoBox;
	this.isListBox = listBox;
	this.isPollBox = pollBox;
	this.isWhatsHotBox = whatsHotBox
	this.isRotatingBox = rotatingBox;
}

function layoutBox(id, type, options, content, contentStyles, header, headerStyles, footer, footerStyles, linkStyles, pageBGColor, bgColor, bgStyle, bgImage, bgTile, borderSize, borderStyle, borderColor, underlineColor, bulletColor)
{
	this.id = id;
	this.type = type;
	this.options = options;
	this.content = content;
	this.contentStyles = contentStyles;
	this.header = header;
	this.headerStyles = headerStyles;
	this.footer = footer;
	this.footerStyles = footerStyles;
	this.linkStyles = linkStyles;
	this.pageBGColor = pageBGColor;
	this.bgColor = bgColor;
	this.bgStyle = bgStyle;
	this.bgImage = bgImage;
	this.bgTile = bgTile;
	this.borderSize = borderSize;
	this.borderStyle = borderStyle;
	this.borderColor = borderColor;
	this.underlineColor = underlineColor;
	this.bulletColor = bulletColor;
	return this;
}

function queryOption(name, value)
{
	this.name = name;
	this.value = value;
}

function generalContent(id, group, title, content, linkText, linkURL, image)
{
	this.id = id;
	this.group = group;
	this.title = title;
	this.content = content;
	this.linkText = linkText;
	this.linkURL = linkURL;
	this.image = image;
}


//array helpers
function findStyleSheetIndex(href)
{
	//array helper to find index by stylesheet location
	for (var i=0; i<document.styleSheets.length; i++)
	{
		if ((document.styleSheets[i].href.toLowerCase().indexOf('/re2006_' + href.toLowerCase() + '.') != -1) || (document.styleSheets[i].href.toLowerCase().indexOf('/re2006_' + href.toLowerCase() + '_') != -1))
			return i;
	}	
	return -1;
}

function findBoxTypeIndex(id)
{
	//array helper to find index by Id
	for(var i=0; i<boxTypeArray.length; i++)
	{
		if (boxTypeArray[i].id == id)
			return i;
	}
	return -1;
}

function findBoxIndex(id)
{
	//array helper to find index by Id
	for(var i=0; i<boxArray.length; i++)
	{
		if (boxArray[i].id == id)
			return i;
	}
	return -1;
}

function findContentIndex(id)
{
	//array helper to find index by id
	for(var i=0; i<generalContentArray.length; i++)
	{
		if (generalContentArray[i].id == id)
			return i;
	}
	return -1;
}


//initialize
function initSitePalette()
{
	var fontPalettePicker = document.getElementById('FontEditor_SitePalette');
	var bgPalettePicker = document.getElementById('BGEditor_SitePalette');
	var borderPalettePicker = document.getElementById('BorderEditor_SitePalette');
	var underlinePalettePicker = document.getElementById('UnderlineEditor_SitePalette');
	var bulletPalettePicker = document.getElementById('BulletEditor_SitePalette');

	//fontPalettePicker.innerHTML += '<SPAN onclick="setColor(\'\');" style="cursor:pointer;height:12px;width:12px;overflow:hidden;border:1px solid #000000;margin-left:1px;margin-right:4px;background-image:url(images/content_colortrans.gif);background-repeat:repeat;"></SPAN>';
	bgPalettePicker.innerHTML += '<SPAN onclick="setColor(\'\');" style="cursor:pointer;height:12px;width:12px;overflow:hidden;border:1px solid #000000;margin-left:1px;margin-right:12px;background-image:url(images/content_colortrans.gif);background-repeat:repeat;" title="Transparent"></SPAN>';
	borderPalettePicker.innerHTML += '<SPAN onclick="setColor(\'\');" style="cursor:pointer;height:12px;width:12px;overflow:hidden;border:1px solid #000000;margin-left:1px;margin-right:12px;background-image:url(images/content_colortrans.gif);background-repeat:repeat;" title="Transparent"></SPAN>';
	underlinePalettePicker.innerHTML += '<SPAN onclick="setColor(\'\');" style="cursor:pointer;height:12px;width:12px;overflow:hidden;border:1px solid #000000;margin-left:1px;margin-right:12px;background-image:url(images/content_colortrans.gif);background-repeat:repeat;" title="Transparent"></SPAN>';
	bulletPalettePicker.innerHTML += '<SPAN onclick="setColor(\'\');" style="cursor:pointer;height:12px;width:12px;overflow:hidden;border:1px solid #000000;margin-left:1px;margin-right:12px;background-image:url(images/content_colortrans.gif);background-repeat:repeat;" title="Transparent"></SPAN>';

	for (var i=0; i<sitePalette.length; i++)
	{
		if (sitePalette[i] != '#ffff00')
		{
			fontPalettePicker.innerHTML += '<SPAN onclick="setColor(\'' + sitePalette[i] + '\');" style="cursor:pointer;height:12px;width:12px;overflow:hidden;border:1px solid #000000;margin-left:3px;margin-right:1px;background-color:' + sitePalette[i] + '"></SPAN>';
			bgPalettePicker.innerHTML += '<SPAN onclick="setColor(\'' + sitePalette[i] + '\');" style="cursor:pointer;height:12px;width:12px;overflow:hidden;border:1px solid #000000;margin-left:1px;margin-right:1px;background-color:' + sitePalette[i] + '"></SPAN>';
			borderPalettePicker.innerHTML += '<SPAN onclick="setColor(\'' + sitePalette[i] + '\');" style="cursor:pointer;height:12px;width:12px;overflow:hidden;border:1px solid #000000;margin-left:1px;margin-right:1px;background-color:' + sitePalette[i] + '"></SPAN>';
			underlinePalettePicker.innerHTML += '<SPAN onclick="setColor(\'' + sitePalette[i] + '\');" style="cursor:pointer;height:12px;width:12px;overflow:hidden;border:1px solid #000000;margin-left:1px;margin-right:1px;background-color:' + sitePalette[i] + '"></SPAN>';
			bulletPalettePicker.innerHTML += '<SPAN onclick="setColor(\'' + sitePalette[i] + '\');" style="cursor:pointer;height:12px;width:12px;overflow:hidden;border:1px solid #000000;margin-left:1px;margin-right:1px;background-color:' + sitePalette[i] + '"></SPAN>';
		}
	}
}

function initBoxData()
{
	//find the box placeholders and create instances
	document.getElementById('savingMessage').className = 'LayoutContentHidden';
	document.getElementById('savedMessage').className = 'LayoutContentHidden';
	var boxes = document.getElementsByName('LayoutBox');
	if (boxes != null)
	{
		for(var i=0; i<boxes.length; i++)
		{
			//create a layoutBox instance an put it in the array
			boxes[i].firstChild.className = 'LayoutBox';
			var defaultBGColor = '';
			if (boxes[i].firstChild.style.left.replace('px','') > 130)
				defaultBGColor = document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[4].style.backgroundColor
			else
				defaultBGColor = document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[0].style.backgroundColor
			boxArray[boxArray.length] = new layoutBox(boxes[i].tag, null, new Array(), '', new Array('color: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[0].style.color,'font-family: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[0].style.fontFamily,'font-weight: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[0].style.fontWeight,'font-style: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[0].style.fontStyle,'text-decoration: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[0].style.textDecoration,'text-align: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[0].style.textAlign,'font-size: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[0].style.fontSize), '', new Array('color: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[1].style.color,'font-family: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[1].style.fontFamily,'font-weight: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[1].style.fontWeight,'font-style: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[1].style.fontStyle,'text-decoration: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[1].style.textDecoration,'text-align: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[1].style.textAlign,'font-size: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[1].style.fontSize), '', new Array('color: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[2].style.color,'font-family: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[2].style.fontFamily,'font-weight: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[2].style.fontWeight,'font-style: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[2].style.fontStyle,'text-decoration: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[2].style.textDecoration,'text-align: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[2].style.textAlign,'font-size: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[2].style.fontSize), new Array('color: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[3].style.color,'font-family: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[3].style.fontFamily,'font-weight: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[3].style.fontWeight,'font-style: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[3].style.fontStyle,'text-decoration: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[3].style.textDecoration,'text-align: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[3].style.textAlign,'font-size: ' + document.styleSheets[findStyleSheetIndex('WelcomePageEditor')].rules[3].style.fontSize), defaultBGColor, defaultBGColor, new Array(), '', false, '1', 'none', '', '', '');
		}
	}
}

function initBoxText()
{
	//find the box placeholders and set the type text
	document.getElementById('savingMessage').className = 'LayoutContentHidden';
	document.getElementById('savedMessage').className = 'LayoutContentHidden';
	var boxes = document.getElementsByName('LayoutBox');
	if (boxes != null)
	{
		for(var i=0; i<boxArray.length; i++)
		{
			if (boxArray[i].type != null)
			{
				for(var j=0; j<boxes.length; j++)
				{
					if (boxes[j].tag == boxArray[i].id)
					{
						boxes[j].firstChild.innerText = boxArray[i].type.name;
						break;
					}
				}
			}
		}
	}
}

function initGeneralContent()
{
	//populate choices in general content area
	var useLabel = document.getElementById('Layout_ContentGenericUseList');
	var copyLabel = document.getElementById('Layout_ContentGenericCopyList');
	var useHTML = '';
	var copyHTML = '';
		
	for (var i=0; i<generalContentArray.length; i++)
	{
		if (boxArray[boxIndex].type.isRotatingBox)
		{
			if (boxArray[boxIndex].options[0].value == 0)
			{
				//rotating with no pre-selected group, hide by default
				document.getElementById('Layout_ContentGeneric').className = 'LayoutContentHidden';
			}
			else
			{
				document.getElementById('Layout_ContentGeneric').className = 'LayoutContent';
				
				if (generalContentArray[i].group == boxArray[boxIndex].options[0].value)
				{
					//this content belongs to the selected group, display it
					//useLabel.innerHTML += '<SPAN style="cursor:pointer;" onClick="existingContent(' + i + ');">' + generalContentArray[i].title + '</SPAN><BR/>';
					//copyLabel.innerHTML += '<SPAN style="cursor:pointer;" onClick="newContent(' + i + ');">' + generalContentArray[i].title + '</SPAN><BR/>';
					if (useHTML == '')
					{
						useHTML += '<select name="ContentListBox" id="ContentListBox" multiple class="textinput" style="height:100px;" onchange="existingContent(this.value);">';
						copyHTML += '<select name="ContentListBox" id="ContentListBox" multiple class="textinput" style="height:100px;" onchange="newContent(this.value);">';
					}
					useHTML += '<option value="' + i + '">' + generalContentArray[i].title + '</option>';
					copyHTML += '<option value="' + i + '">' + generalContentArray[i].title + '</option>';
				}
				
				//allow for a group to be changed only if it is new content
				if ((document.getElementById('Layout_ContentGenericContent').tag < 0) && (generalContentArray[i].id == document.getElementById('Layout_ContentGenericContent').tag))
					generalContentArray[i].group = boxArray[boxIndex].options[0].value
			}
		}
		else
		{
			//show the full list
			document.getElementById('Layout_ContentGeneric').className = 'LayoutContent';
			//useLabel.innerHTML += '<SPAN style="cursor:pointer;" onClick="existingContent(' + i + ');">' + generalContentArray[i].title + '</SPAN><BR/>';
			//copyLabel.innerHTML += '<SPAN style="cursor:pointer;" onClick="newContent(' + i + ');">' + generalContentArray[i].title + '</SPAN><BR/>';
			if (useHTML == '')
			{
				useHTML += '<select name="ContentListBox" id="ContentListBox" multiple class="textinput" style="height:100px;" onchange="existingContent(this.value);">';
				copyHTML += '<select name="ContentListBox" id="ContentListBox" multiple class="textinput" style="height:100px;" onchange="newContent(this.value);">';
			}
			useHTML += '<option value="' + i + '">' + generalContentArray[i].title + '</option>';
			copyHTML += '<option value="' + i + '">' + generalContentArray[i].title + '</option>';
		}		
	}
	if (useHTML != '')
	{
		useHTML += '</select>';
		copyHTML += '</select>';
	}
	else
	{
		//no content, either in this group or all together
		if (boxArray[boxIndex].type.isRotatingBox)
		{
			useHTML = 'There is currently no existing content in this group';
			copyHTML = 'There is currently no existing content in this group';
		}
		else
		{
			useHTML = 'There is currently no existing content';
			copyHTML = 'There is currently no existing content';
		}
	}
	
	useLabel.innerHTML = useHTML;
	copyLabel.innerHTML = copyHTML;
	
	//box being edited already belongs to a group, make sure it is hidden when changing groups
	if ((boxArray[boxIndex].type.isRotatingBox) && (document.getElementById('Layout_ContentGenericContent').tag > 0))
			document.getElementById('Layout_ContentGenericContent').className = 'LayoutContentHidden';
}


//begin edit
function beginBoxEdit(box)
{
	//box was chosen, init
	document.getElementById('FontEditor_UnderlineButton').style.visibility = 'hidden';
	document.getElementById('SaveContent').className = 'LayoutContent';
	
	document.getElementById('Layout_FontEditor').style.display = 'none';
	document.getElementById('Layout_FontEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BGEditor').style.display = 'none';
	document.getElementById('Layout_BGEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BorderEditor').style.display = 'none';
	document.getElementById('Layout_BorderEditor').style.visibility = 'hidden';
	document.getElementById('Layout_UnderlineEditor').style.display = 'none';
	document.getElementById('Layout_UnderlineEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BulletEditor').style.display = 'none';
	document.getElementById('Layout_BulletEditor').style.visibility = 'hidden';
	document.getElementById('Layout_ContentInfoHelp').style.display = '';
	document.getElementById('Layout_ContentInfoHelp').style.visibility = 'visible';
	
	document.getElementById('Layout_ContentGenericContent').className = 'LayoutContentHidden';
	document.getElementById('Layout_ContentGenericUseList').className = 'LayoutContentHidden';
	document.getElementById('Layout_ContentGenericCopyList').className = 'LayoutContentHidden';	
	var boxes = document.getElementsByName('LayoutBox');
	if (boxes != null)
	{
		for(var i=0; i<boxes.length; i++)
		{
			//reset all the box classes except for the box that was just clicked
			if (boxes[i].tag != box.tag)
				boxes[i].firstChild.className = 'LayoutBox';
		}
	}
	//change the working box style
	box.firstChild.className = 'LayoutBoxSelected';

	if (box.tag != workingBoxId)
	{
		//find the index in the array of the working box
		workingBoxId = box.tag;
		boxIndex = findBoxIndex(workingBoxId);

		if (boxArray[boxIndex].type == null)
		{
			//box has no type, hide any display fields from the previous edit (except content type)
			document.getElementById('Layout_QueryOptions').className = 'LayoutContentHidden';
			document.getElementById('Layout_QueryFields').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentGeneric').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentInfo').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentList').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentPoll').className = 'LayoutContentHidden';	
			document.getElementById('Layout_ContentWHot').className = 'LayoutContentHidden';
			drawType();
			drawBoxInfo();
			drawOptions(null);
			drawContent(null);
			drawBGStyles(null);
		}
		else
		{
			//box already has a type, populate the display fields with working information
			drawType();
			drawBoxInfo();
			downloadQueryXml();	//since we already have a type, options and fields can be downloaded
		}
	}
}

function beginFontEdit(editName, friendlyName)
{
	//show the font editor
	document.getElementById('Layout_BGEditor').style.display = 'none';
	document.getElementById('Layout_BGEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BorderEditor').style.display = 'none';
	document.getElementById('Layout_BorderEditor').style.visibility = 'hidden';
	document.getElementById('Layout_ContentInfoHelp').style.display = 'none';
	document.getElementById('Layout_ContentInfoHelp').style.visibility = 'hidden';	
	document.getElementById('Layout_UnderlineEditor').style.display = 'none';
	document.getElementById('Layout_UnderlineEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BulletEditor').style.display = 'none';
	document.getElementById('Layout_BulletEditor').style.visibility = 'hidden';
	document.getElementById('Layout_FontEditor').style.display = '';
	document.getElementById('Layout_FontEditor').style.visibility = 'visible';

	document.getElementById('FontEditor_Sample').style.fontWeight = 'normal';
	document.getElementById('FontEditor_Sample').style.fontStyle = 'normal';
	document.getElementById('FontEditor_Sample').style.textDecoration = 'none';
	document.getElementById('FontEditor_Sample').style.textAlign = 'left';
	document.getElementById('FontEditor_BoldButton').className = 'LayoutFontEditorButton';
	document.getElementById('FontEditor_ItalicButton').className = 'LayoutFontEditorButton';
	document.getElementById('FontEditor_UnderlineButton').className = 'LayoutFontEditorButton';
	document.getElementById('FontEditor_ALeftButton').className = 'LayoutFontEditorButton';
	document.getElementById('FontEditor_ACenterButton').className = 'LayoutFontEditorButton';
	document.getElementById('FontEditor_ARightButton').className = 'LayoutFontEditorButton';
	document.getElementById('FontEditor_AJustifyButton').className = 'LayoutFontEditorButton';
	
	
	//show the location being edited
	currentFontEdit = editName;
	document.getElementById('FontEditor_CurrentSection').innerText = 'Now editing font properties for "' + friendlyName + '"';
	document.getElementById('FontEditor_UnderlineButton').style.visibility = (document.getElementById(currentFontEdit).tag == 'link') ? 'hidden' : 'visible';

	for (var i=0; i<document.frmFontEditor.FontEditor_Font.options.length; i++)
	{
		if (document.frmFontEditor.FontEditor_Font.options[i].value == eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[1].replace('font-family: ', ''))
			document.frmFontEditor.FontEditor_Font.selectedIndex = i
	}

	//set the working values from the previously set values
	setColor(eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[0].replace('color: ', ''));
	setFont(eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[1].replace('font-family: ', ''));
	if (eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[2].replace('font-weight: ', '') == 'bold')
		setBold();
	if (eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[3].replace('font-style: ', '') == 'italic')
		setItalic();
	if (eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[4].replace('text-decoration: ', '') == 'underline')
		setUnderLine();
	setAlign(eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[5].replace('text-align: ', ''));
	setSize(eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[6].replace('font-size: ', ''));
}

function beginBGEdit()
{
	currentFontEdit = '';
	document.getElementById('Layout_FontEditor').style.display = 'none';
	document.getElementById('Layout_FontEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BorderEditor').style.display = 'none';
	document.getElementById('Layout_BorderEditor').style.visibility = 'hidden';
	document.getElementById('Layout_ContentInfoHelp').style.display = 'none';
	document.getElementById('Layout_ContentInfoHelp').style.visibility = 'hidden';	
	document.getElementById('Layout_UnderlineEditor').style.display = 'none';
	document.getElementById('Layout_UnderlineEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BulletEditor').style.display = 'none';
	document.getElementById('Layout_BulletEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BGEditor').style.display = '';
	document.getElementById('Layout_BGEditor').style.visibility = 'visible';

	//document.frmBGEditor.BGEditor_Style.options.selectedIndex = 0;
	document.frmBGEditor.BGEditor_Image.options.selectedIndex = 0;
	
	if (boxArray[boxIndex].bgImage != '')
	{
		for (var i=0; i<document.frmBGEditor.BGEditor_Image.options.length; i++)
		{
			if (document.frmBGEditor.BGEditor_Image.options[i].value == boxArray[boxIndex].bgImage)
				document.frmBGEditor.BGEditor_Image.options.selectedIndex = i;
		}
	}

	document.frmBGEditor.BGEditor_TileImage.checked = boxArray[boxIndex].bgTile;
	setColor(boxArray[boxIndex].bgColor);
}

function beginBorderEdit()
{
	currentFontEdit = '';
	document.getElementById('Layout_FontEditor').style.display = 'none';
	document.getElementById('Layout_FontEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BGEditor').style.display = 'none';
	document.getElementById('Layout_BGEditor').style.visibility = 'hidden';
	document.getElementById('Layout_ContentInfoHelp').style.display = 'none';
	document.getElementById('Layout_ContentInfoHelp').style.visibility = 'hidden';	
	document.getElementById('Layout_UnderlineEditor').style.display = 'none';
	document.getElementById('Layout_UnderlineEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BulletEditor').style.display = 'none';
	document.getElementById('Layout_BulletEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BorderEditor').style.display = '';
	document.getElementById('Layout_BorderEditor').style.visibility = 'visible';

	for (var i=0; i<document.frmBorderEditor.BorderEditor_Style.options.length; i++)
	{
		if (document.frmBorderEditor.BorderEditor_Style.options[i].value == boxArray[boxIndex].borderStyle)
			document.frmBorderEditor.BorderEditor_Style.options.selectedIndex = i;
	}

	for (var i=0; i<document.frmBorderEditor.BorderEditor_Size.options.length; i++)
	{
		if (document.frmBorderEditor.BorderEditor_Size.options[i].value == boxArray[boxIndex].borderSize)
			document.frmBorderEditor.BorderEditor_Size.options.selectedIndex = i;
	}

	if (boxArray[boxIndex].borderStyle == 'custom')
	{
		document.frmBorderEditor.BorderEditor_Size.disabled = true;
		document.getElementById('BorderEditor_Styles').style.visibility = 'visible';
		drawBGStyles();
	}
	else
	{
		document.frmBorderEditor.BorderEditor_Size.disabled = false;
		document.getElementById('BorderEditor_Styles').style.visibility = 'hidden';
		boxArray[boxIndex].bgStyle = new Array();
	}
	setColor(boxArray[boxIndex].borderColor);
}


function beginUnderlineEdit()
{
	currentFontEdit = '';
	document.getElementById('Layout_FontEditor').style.display = 'none';
	document.getElementById('Layout_FontEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BGEditor').style.display = 'none';
	document.getElementById('Layout_BGEditor').style.visibility = 'hidden';
	document.getElementById('Layout_ContentInfoHelp').style.display = 'none';
	document.getElementById('Layout_ContentInfoHelp').style.visibility = 'hidden';	
	document.getElementById('Layout_BorderEditor').style.display = 'none';
	document.getElementById('Layout_BorderEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BulletEditor').style.display = 'none';
	document.getElementById('Layout_BulletEditor').style.visibility = 'hidden';
	document.getElementById('Layout_UnderlineEditor').style.display = '';
	document.getElementById('Layout_UnderlineEditor').style.visibility = 'visible';

	setColor(boxArray[boxIndex].underlineColor);
}

function beginBulletEdit()
{
	currentFontEdit = '';
	document.getElementById('Layout_FontEditor').style.display = 'none';
	document.getElementById('Layout_FontEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BGEditor').style.display = 'none';
	document.getElementById('Layout_BGEditor').style.visibility = 'hidden';
	document.getElementById('Layout_ContentInfoHelp').style.display = 'none';
	document.getElementById('Layout_ContentInfoHelp').style.visibility = 'hidden';	
	document.getElementById('Layout_BorderEditor').style.display = 'none';
	document.getElementById('Layout_BorderEditor').style.visibility = 'hidden';
	document.getElementById('Layout_UnderlineEditor').style.display = 'none';
	document.getElementById('Layout_UnderlineEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BulletEditor').style.display = '';
	document.getElementById('Layout_BulletEditor').style.visibility = 'visible';

	setColor(boxArray[boxIndex].bulletColor);
}

//draw values
function drawType()
{
	//populate the type drop down
	document.getElementById('Layout_ContentType').className = 'LayoutContent';			
	document.frmLayoutBoxes.boxType.selectedIndex = 0;

	for(var i=document.frmLayoutBoxes.boxType.options.length; i>0; i--)
	{
		document.frmLayoutBoxes.boxType.options[i] = null;
	}

	var trueHeight = document.getElementsByName('LayoutBox')[boxIndex].firstChild.trueHeight;
	var trueWidth = document.getElementsByName('LayoutBox')[boxIndex].firstChild.trueWidth;

	for(var j=0; j<boxTypeArray.length; j++)
	{
		if ((trueWidth >= boxTypeArray[j].minWidth) && (trueHeight >= boxTypeArray[j].minHeight))
			document.frmLayoutBoxes.boxType.options[document.frmLayoutBoxes.boxType.options.length] = new Option(boxTypeArray[j].name, boxTypeArray[j].id);

		if ((boxArray[boxIndex].type != null) && (boxArray[boxIndex].type.id == boxTypeArray[j].id))
			document.frmLayoutBoxes.boxType.selectedIndex = document.frmLayoutBoxes.boxType.options.length-1;
	}
}

function drawBoxInfo()
{
	//show help information for box based on type
	document.getElementById('FontEditor_UnderlineButton').style.visibility = 'hidden';
	document.getElementById('SaveContent').className = 'LayoutContent';
	
	document.getElementById('Layout_FontEditor').style.display = 'none';
	document.getElementById('Layout_FontEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BGEditor').style.display = 'none';
	document.getElementById('Layout_BGEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BorderEditor').style.display = 'none';
	document.getElementById('Layout_BorderEditor').style.visibility = 'hidden';
	document.getElementById('Layout_UnderlineEditor').style.display = 'none';
	document.getElementById('Layout_UnderlineEditor').style.visibility = 'hidden';
	document.getElementById('Layout_BulletEditor').style.display = 'none';
	document.getElementById('Layout_BulletEditor').style.visibility = 'hidden';
	document.getElementById('Layout_ContentInfoHelp').style.display = '';
	document.getElementById('Layout_ContentInfoHelp').style.visibility = 'visible';	

	//make sure there is a type for this box.
	if (boxArray[boxIndex].type != null)
	{
		//show the help information
		document.getElementById('Layout_ContentInfoHolder').innerHTML = boxArray[boxIndex].type.helpHTML;	
	}
}

function drawOptions(xmlDoc)
{
	//create and populate options from downloaded XML
	var optionLayer = document.getElementById('Layout_QueryOptions');
	if (xmlDoc != null)
	{
		optionLayer.innerHTML = '';
		optionLayer.className = 'LayoutContent';	
		var queryOptions = xmlDoc.selectNodes('//options');
		if (queryOptions.length > 0)
		{
			optionLayer.innerHTML = '<BR/>';
			for (var i=0;i<queryOptions.length; i++)
			{
				//options are available for this option- display and populate
				var optionGroup = queryOptions[i].selectNodes('option');
				if ((optionGroup.length == 1) && (!boxArray[boxIndex].type.isInfoBox) && (!boxArray[boxIndex].type.isListBox) && (!boxArray[boxIndex].type.isPollBox) && (!boxArray[boxIndex].type.isWhatsHotBox))
				{
					if ((queryOptions[i].parentNode.selectSingleNode('friendlyName') != null) && (boxArray[boxIndex].options[0] == null))
						boxArray[boxIndex].options[0] = new queryOption(queryOptions[i].parentNode.selectSingleNode('friendlyName').text, '0');
				}
				else if(optionGroup.length > 1)
				{
					var optionDiv = document.createElement('DIV');
					optionDiv.innerText = queryOptions[i].parentNode.selectSingleNode('friendlyName').text + ': ';
					var optionSel = document.createElement('SELECT');
					optionSel.name = queryOptions[i].parentNode.selectSingleNode('friendlyName').text;
					optionSel.className = 'TextInput';

					//need and event handler for the change to update the layoutBox instance
					if (optionSel.attachEvent)
						optionSel.attachEvent('onchange', setOptions);
					else if (optionSel.addEventListener)
						optionSel.addEventListener('change', setOptions, false);

					//check if a setting has already been chosen
					var currentSetting = null;
					for(var k=0; k<boxArray[boxIndex].options.length; k++)
					{
						if (boxArray[boxIndex].options[k].name == optionSel.name)
						{
							currentSetting = boxArray[boxIndex].options[k];
							break;
						}
					}

					if ((currentSetting == null) && (boxArray[boxIndex].type.isRotatingBox))
						boxArray[boxIndex].options[0] = new queryOption(queryOptions[i].parentNode.selectSingleNode('friendlyName').text, '0');					

					var blankOpt = document.createElement('OPTION');
					blankOpt.text = '';
					blankOpt.value = '';
					optionSel.options[j] = blankOpt;
					
					//populate individual options
					for(var j=0; j<optionGroup.length; j++)
					{
						var optionOpt = document.createElement('OPTION');
						optionOpt.text = optionGroup[j].selectSingleNode('friendlyName').text;
						optionOpt.value = optionGroup[j].selectSingleNode('value').text;
						optionSel.options[j+1] = optionOpt;

						//default to previously selected setting
						if ((currentSetting != null) && (currentSetting.value == optionOpt.value))
							optionSel.selectedIndex = j+1;
					}
					optionDiv.appendChild(optionSel);
					optionLayer.appendChild(optionDiv);
				}
			}
		}
		optionLayer.appendChild(document.createElement('BR'));
	}
}

function drawContent(xmlDoc)
{
	//populate content string
	document.getElementById('Layout_ContentGenericContent').tag	= '';
	if (boxArray[boxIndex].type != null)
	{
		var contentLayer;
		//each overall box type has differnt content to pull/display
		if (boxArray[boxIndex].type.isInfoBox)
		{
			//populate header and content fields if available
			document.frmLayoutBoxes.Layout_ContentInfoTitle.value = boxArray[boxIndex].header;
			document.frmLayoutBoxes.Layout_ContentInfoBody.value = boxArray[boxIndex].content;
			document.getElementById('Layout_ContentGeneric').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentInfo').className = 'LayoutContent';
			document.getElementById('Layout_ContentList').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentPoll').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentWHot').className = 'LayoutContentHidden';			
			contentLayer = document.getElementById('Layout_ContentInfo');
			
			//show list of available fields to place in content
			var fieldsLayer = document.getElementById('Layout_ContentInfoFields');
			fieldsLayer.innerHTML = '';

			var selectFields = xmlDoc.selectNodes('//select/fields/field');
			if (selectFields.length > 0)
			{
				for (var i=0;i<selectFields.length; i++)
				{
					//option has friendly name, show it
					if (selectFields[i].selectSingleNode('friendlyName').text != '')
						fieldsLayer.innerHTML += '<DIV style="cursor:default;padding-left:5px;" title="' + selectFields[i].selectSingleNode('description').text.replace('"', '\'\'') + '\n Use: <' + selectFields[i].selectSingleNode('friendlyName').text.toLowerCase() + '/>">' + selectFields[i].selectSingleNode('friendlyName').text + '</DIV>';
				}
			}
			fieldsLayer.innerHTML += '<BR/>';
		}
		else if (boxArray[boxIndex].type.isListBox)
		{
			//populate header and footer fields if available
			document.frmLayoutBoxes.Layout_ContentListTitle.value = boxArray[boxIndex].header;
			document.frmLayoutBoxes.Layout_ContentListMessage.value = boxArray[boxIndex].footer;
			document.frmLayoutBoxes.Layout_ContentListLinks.value = 'Links...';
			document.getElementById('Layout_ContentGeneric').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentInfo').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentList').className = 'LayoutContent';
			document.getElementById('Layout_ContentPoll').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentWHot').className = 'LayoutContentHidden';			
			contentLayer = document.getElementById('Layout_ContentList');
			
			var fields = boxArray[boxIndex].content.split('@|@');
			var names;
			var values;

			if (fields.length == 2)
			{
				names = fields[0].split('#|#');
				values = fields[1].split('#|#');
			}
						
			var selectFields = xmlDoc.selectNodes('//select/fields/field');
			if (selectFields.length > 0)
			{
				var fieldList = document.getElementById('Layout_ContentListFields');
				for (var j=fieldList.rows.length; j>0; j--)
				{
					//don't display selection criteria fields
					fieldList.deleteRow(j-1);
				}

				for (var i=0;i<selectFields.length; i++)
				{
					//option has friendly name, show it
					if (selectFields[i].selectSingleNode('friendlyName').text != '')
					{
						var tblRow = fieldList.insertRow(fieldList.rows.length);
						var tblChkCell = tblRow.insertCell(0);
						var chkBox = document.createElement('INPUT');
						chkBox.type = 'checkbox';
						chkBox.id = 'ListField';
						chkBox.name = 'ListField';
						chkBox.tag = selectFields[i].selectSingleNode('friendlyName').text.toLowerCase();
						
						//need and event handler for the change to update the layoutBox instance
						if (chkBox.attachEvent)
							chkBox.attachEvent('onclick', setContent);
						else if (chkBox.addEventListener)
							chkBox.addEventListener('click', setContent, false);
						tblChkCell.appendChild(chkBox);							
						
						var tblNameCell = tblRow.insertCell(1);
						var fieldName = document.createElement('SPAN');
						fieldName.innerText = selectFields[i].selectSingleNode('friendlyName').text + ' as ';
						tblNameCell.appendChild(fieldName);
						
						var tblDispNameCell = tblRow.insertCell(2);
						var dispName = document.createElement('INPUT');
						dispName.type = 'text';
						dispName.width = 75;
						dispName.id = 'ListFieldName';
						dispName.name = 'ListFieldName';
						dispName.className = 'TextInput';

						//need and event handler for the change to update the layoutBox instance
						if (dispName.attachEvent)
							dispName.attachEvent('onchange', setContent);
						else if (dispName.addEventListener)
							dispName.addEventListener('change', setContent, false);						
						tblDispNameCell.appendChild(dispName);
						
						if ((values != null) && (names != null))
						{
							for (var j=0; j<values.length; j++)
							{
								if (values[j] == chkBox.tag)
								{
									chkBox.checked = true;
									dispName.value = names[j];
									break;
								}
							}
							if (chkBox.checked == false)
								dispName.value = selectFields[i].selectSingleNode('friendlyName').text;
						}
						else
						{
							chkBox.checked = true;
							dispName.value = selectFields[i].selectSingleNode('friendlyName').text;
						}						
					}
				}
			}			
		}
		else if (boxArray[boxIndex].type.isPollBox)
		{
			//populate header field if available
			document.frmLayoutBoxes.Layout_ContentPollTitle.value = boxArray[boxIndex].header;
			document.frmLayoutBoxes.Layout_ContentPollBody.value = 'Content...';
			document.getElementById('Layout_ContentGeneric').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentInfo').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentList').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentPoll').className = 'LayoutContent';
			document.getElementById('Layout_ContentWHot').className = 'LayoutContentHidden';			
			contentLayer = document.getElementById('Layout_ContentPoll');
		}	
		else if (boxArray[boxIndex].type.isWhatsHotBox)
		{
			//populate header and content fields with generic sample text
			document.frmLayoutBoxes.Layout_ContentWHotTitle.value = 'Title...';
			document.frmLayoutBoxes.Layout_ContentWHotBody.value = 'Body...';
			document.frmLayoutBoxes.Layout_ContentWHotLinks.value = 'Link...';
			document.getElementById('Layout_ContentGeneric').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentInfo').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentList').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentPoll').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentWHot').className = 'LayoutContent';			
			contentLayer = document.getElementById('Layout_ContentWHot');
		}				
		else
		{
			//if not rotating find working content id (no default item for rotating)
			var contentIndex = -1;
			if ((!boxArray[boxIndex].type.isRotatingBox) && (boxArray[boxIndex].options[0] != null))
				contentIndex = findContentIndex(boxArray[boxIndex].options[0].value)

			if (contentIndex != -1)
			{
				//working content was found, populate general content fields if available
				document.getElementById('Layout_ContentGenericContent').tag = generalContentArray[contentIndex].id;
				document.frmLayoutBoxes.Layout_ContentGenericTitle.value = generalContentArray[contentIndex].title;
				document.frmLayoutBoxes.Layout_ContentGenericBody.value = generalContentArray[contentIndex].content;
				document.frmLayoutBoxes.Layout_ContentGenericLinkText.value = generalContentArray[contentIndex].linkText;
				document.frmLayoutBoxes.Layout_ContentGenericLinkURL.value = generalContentArray[contentIndex].linkURL;
				document.frmLayoutBoxes.Layout_ContentGenericImage.value = generalContentArray[contentIndex].image;
				document.getElementById('Layout_ContentGenericContent').className = 'LayoutContent';
			}
			else
			{
				//no working content or no default content, clear general content fields
				document.frmLayoutBoxes.Layout_ContentGenericTitle.value = '';
				document.frmLayoutBoxes.Layout_ContentGenericBody.value = '';
				document.frmLayoutBoxes.Layout_ContentGenericLinkText.value = '';
				document.frmLayoutBoxes.Layout_ContentGenericLinkURL.value = '';
				document.frmLayoutBoxes.Layout_ContentGenericImage.value = '';
			}
			document.getElementById('Layout_ContentGeneric').className = 'LayoutContent';
			document.getElementById('Layout_ContentInfo').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentList').className = 'LayoutContentHidden';
			document.getElementById('Layout_ContentPoll').className = 'LayoutContentHidden';	
			document.getElementById('Layout_ContentWHot').className = 'LayoutContentHidden';			
			contentLayer = document.getElementById('Layout_ContentGeneric');
			initGeneralContent();
		}
		contentLayer.parentElement.style.height = contentLayer.clientHeight + 'px';
	}
}

function drawBGStyles()
{
	//populate content string
	if (boxArray[boxIndex].type != null)
	{
		document.frmBorderEditor.BorderEditor_Tab.checked = (boxArray[boxIndex].bgStyle[styleUseTab] == null) ? false : eval(boxArray[boxIndex].bgStyle[styleUseTab]);
		document.frmBorderEditor.BorderEditor_BottomDropShadow.checked = (boxArray[boxIndex].bgStyle[styleBottomDropShadow] == null) ? false : eval(boxArray[boxIndex].bgStyle[styleBottomDropShadow]);
		document.frmBorderEditor.BorderEditor_RightDropShadow.checked = (boxArray[boxIndex].bgStyle[styleRightDropShadow] == null) ? false : eval(boxArray[boxIndex].bgStyle[styleRightDropShadow]);
		document.frmBorderEditor.BorderEditor_TopLeftCorner.checked = (boxArray[boxIndex].bgStyle[styleTopLeftRounded] == null) ? false : eval(boxArray[boxIndex].bgStyle[styleTopLeftRounded]);
		document.frmBorderEditor.BorderEditor_TopRightCorner.checked = (boxArray[boxIndex].bgStyle[styleTopRightRounded] == null) ? false : eval(boxArray[boxIndex].bgStyle[styleTopRightRounded]);
		document.frmBorderEditor.BorderEditor_BottomLeftCorner.checked = (boxArray[boxIndex].bgStyle[styleBottomLeftRounded] == null) ? false : eval(boxArray[boxIndex].bgStyle[styleBottomLeftRounded]);
		document.frmBorderEditor.BorderEditor_BottomRightCorner.checked = (boxArray[boxIndex].bgStyle[styleBottomRightRounded] == null) ? false : eval(boxArray[boxIndex].bgStyle[styleBottomRightRounded]);
		document.frmBorderEditor.BorderEditor_BottomSeperator.checked = (boxArray[boxIndex].bgStyle[styleBottomSperator] == null) ? false : eval(boxArray[boxIndex].bgStyle[styleBottomSperator]);
		document.frmBorderEditor.BorderEditor_LeftSeperator.checked = (boxArray[boxIndex].bgStyle[styleLeftSeperator] == null) ? false : eval(boxArray[boxIndex].bgStyle[styleLeftSeperator]);
	}
}


//set values
function setType()
{
	boxArray[boxIndex].type = null;
	boxArray[boxIndex].content = '';
	boxArray[boxIndex].header = '';
	boxArray[boxIndex].footer = '';

	document.getElementsByName('LayoutBox')[boxIndex].firstChild.innerText = '';
	//type has been chosen
	if (((boxArray[boxIndex].type == null) || (boxArray[boxIndex].type.id != document.frmLayoutBoxes.boxType.options[document.frmLayoutBoxes.boxType.selectedIndex].value)) && (document.frmLayoutBoxes.boxType.options[document.frmLayoutBoxes.boxType.selectedIndex].value != ''))
	{
		//type has changed, clear any working options and set type
		boxArray[boxIndex].options = new Array();
		boxArray[boxIndex].type = boxTypeArray[findBoxTypeIndex(document.frmLayoutBoxes.boxType.options[document.frmLayoutBoxes.boxType.selectedIndex].value)];
		if (boxArray[boxIndex].type != null)
			document.getElementsByName('LayoutBox')[boxIndex].firstChild.innerText = boxArray[boxIndex].type.name;
		
		document.getElementById('FontEditor_UnderlineButton').style.visibility = 'hidden';		
		
		document.getElementById('Layout_BGEditor').style.display = 'none';
		document.getElementById('Layout_BGEditor').style.visibility = 'hidden';
		document.getElementById('Layout_BorderEditor').style.display = 'none';
		document.getElementById('Layout_BorderEditor').style.visibility = 'hidden';
		document.getElementById('Layout_FontEditor').style.display = 'none';
		document.getElementById('Layout_FontEditor').style.visibility = 'hidden';
		document.getElementById('Layout_UnderlineEditor').style.display = 'none';
		document.getElementById('Layout_UnderlineEditor').style.visibility = 'hidden';
		document.getElementById('Layout_BulletEditor').style.display = 'none';
		document.getElementById('Layout_BulletEditor').style.visibility = 'hidden';
		document.getElementById('Layout_ContentInfoHelp').style.display = '';
		document.getElementById('Layout_ContentInfoHelp').style.visibility = 'visible';	
		
		//show the help information
		document.getElementById('Layout_ContentInfoHolder').innerHTML = boxArray[boxIndex].type.helpHTML;
	}
	//download options and field info
	downloadQueryXml();
}

function setOptions()
{
	//option has been set
	var optionLayer = document.getElementById('Layout_QueryOptions');
	var selects = optionLayer.getElementsByTagName('SELECT');

	for (var i=0; i<selects.length; i++)
	{
		//see if a choice for this option already exists
		var currentSetting = null;
		for(var j=0; j<boxArray[boxIndex].options.length; j++)
		{
			if (boxArray[boxIndex].options[j].name == selects[i].name)
			{
				currentSetting = boxArray[boxIndex].options[j];
				break;
			}
		}
		
		//create new or update existing option selection
		if (currentSetting == null)
			boxArray[boxIndex].options[boxArray[boxIndex].options.length] = new queryOption(selects[i].name, selects[i].options[selects[i].selectedIndex].value);
		else
			currentSetting.value = selects[i].options[selects[i].selectedIndex].value;
	}
	
	if ((!boxArray[boxIndex].type.isInfoBox) && (!boxArray[boxIndex].type.isListBox) && (!boxArray[boxIndex].type.isPollBox) && (!boxArray[boxIndex].type.isWhatsHotBox) && (boxArray[boxIndex].options[0].value != ''))
		initGeneralContent();
}

function setContent()
{
	//set content string
	if (boxArray[boxIndex].type != null)
	{
		if (boxArray[boxIndex].type.isInfoBox)
		{
			boxArray[boxIndex].header = document.frmLayoutBoxes.Layout_ContentInfoTitle.value;
			boxArray[boxIndex].content = document.frmLayoutBoxes.Layout_ContentInfoBody.value;
			boxArray[boxIndex].footer = '';
		}
		else if (boxArray[boxIndex].type.isListBox)
		{
			var selCount = 0;
			var head = '';
			var cont = '';
			var chkBoxes = document.getElementsByName('ListField');
			var txtBoxes = document.getElementsByName('ListFieldName');

			for (var i=0; i<chkBoxes.length; i++)
			{
				if (chkBoxes[i].checked)
				{
					head += (head == '') ? txtBoxes[i].value : '#|#' + txtBoxes[i].value;
					cont += (cont == '') ? chkBoxes[i].tag : '#|#' + chkBoxes[i].tag;
					selCount++;
				}
			}
			boxArray[boxIndex].header = document.frmLayoutBoxes.Layout_ContentListTitle.value;
			boxArray[boxIndex].content = head + '@|@' + cont;
			boxArray[boxIndex].footer = document.frmLayoutBoxes.Layout_ContentListMessage.value;
		}
		else if (boxArray[boxIndex].type.isPollBox)
		{
			boxArray[boxIndex].header = document.frmLayoutBoxes.Layout_ContentPollTitle.value;
			boxArray[boxIndex].content = '';
			boxArray[boxIndex].footer = '';
		}
		else if (boxArray[boxIndex].type.isWhatsHotBox)
		{
			boxArray[boxIndex].header = '';
			boxArray[boxIndex].content = '';
			boxArray[boxIndex].footer = '';
		}
		else
		{
			var contentId = document.getElementById('Layout_ContentGenericContent').tag
			var contentIndex = -1;
			if (contentId != '')
			{
				for (var i=0; i<generalContentArray.length; i++)
				{
					if (generalContentArray[i].id == contentId)
					{
						contentIndex = i;
						break;
					}
				}
			}
			if (contentIndex != -1)
			{
				generalContentArray[contentIndex].title = document.frmLayoutBoxes.Layout_ContentGenericTitle.value;
				generalContentArray[contentIndex].content = document.frmLayoutBoxes.Layout_ContentGenericBody.value;
				generalContentArray[contentIndex].linkText = document.frmLayoutBoxes.Layout_ContentGenericLinkText.value;
				generalContentArray[contentIndex].linkURL = document.frmLayoutBoxes.Layout_ContentGenericLinkURL.value;
				generalContentArray[contentIndex].image = document.frmLayoutBoxes.Layout_ContentGenericImage.value;
			}

			boxArray[boxIndex].header = '';
			boxArray[boxIndex].content = '';
			boxArray[boxIndex].footer = '';
		}
	}
}

function setFont()
{
	//font has been selected
	if (currentFontEdit != '')
	{
		//display sample
		var sample = document.getElementById('FontEditor_Sample');
		sample.innerText = document.getElementById(currentFontEdit).value.length > 10 ? document.getElementById(currentFontEdit).value.substring(0, 10) + '...' : document.getElementById(currentFontEdit).value;

		//set for object based on sample tag (header content footer)
		sample.style.fontFamily = document.frmFontEditor.FontEditor_Font.options[document.frmFontEditor.FontEditor_Font.selectedIndex].value;
		eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[1] = 'font-family: ' + sample.style.fontFamily;
	}
}

function setBold()
{
	//bold has been toggled
	if (currentFontEdit != '')
	{
		//display sample
		var sample = document.getElementById('FontEditor_Sample');
		sample.innerText = document.getElementById(currentFontEdit).value.length > 10 ? document.getElementById(currentFontEdit).value.substring(0, 10) + '...' : document.getElementById(currentFontEdit).value;
		
		//set for object based on sample tag (header content footer)
		if (sample.style.fontWeight == 'bold')
		{
			sample.style.fontWeight = 'normal';
			document.getElementById('FontEditor_BoldButton').className = 'LayoutFontEditorButton';
		}
		else
		{
			sample.style.fontWeight = 'bold';
			document.getElementById('FontEditor_BoldButton').className = 'LayoutFontEditorButtonDepressed';
		}
			
		eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[2] = 'font-weight: ' + sample.style.fontWeight;
	}
}

function setItalic()
{
	//italic has been toggled
	if (currentFontEdit != '')
	{
		//display sample
		var sample = document.getElementById('FontEditor_Sample');
		sample.innerText = document.getElementById(currentFontEdit).value.length > 10 ? document.getElementById(currentFontEdit).value.substring(0, 10) + '...' : document.getElementById(currentFontEdit).value;
		
		//set for object based on sample tag (header content footer)
		if (sample.style.fontStyle == 'italic')
		{
			sample.style.fontStyle = 'normal';
			document.getElementById('FontEditor_ItalicButton').className = 'LayoutFontEditorButton';
		}
		else
		{
			sample.style.fontStyle = 'italic';
			document.getElementById('FontEditor_ItalicButton').className = 'LayoutFontEditorButtonDepressed';
		}		
		eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[3] = 'font-style: ' + sample.style.fontStyle;
	}
}

function setUnderline()
{
	//underline has been toggled
	if (currentFontEdit != '')
	{
		//display sample
		var sample = document.getElementById('FontEditor_Sample');
		sample.innerText = document.getElementById(currentFontEdit).value.length > 10 ? document.getElementById(currentFontEdit).value.substring(0, 10) + '...' : document.getElementById(currentFontEdit).value;

		//set for object based on sample tag (header content footer)		
		if (sample.style.textDecoration == 'underline')
		{
			sample.style.textDecoration = 'none';
			document.getElementById('FontEditor_UnderlineButton').className = 'LayoutFontEditorButton';
		}
		else
		{
			sample.style.textDecoration = 'underline';
			document.getElementById('FontEditor_UnderlineButton').className = 'LayoutFontEditorButtonDepressed';
		}
		eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[4] = 'text-decoration: ' + sample.style.textDecoration;
	}
}

function setAlign(align)
{
	//alignment has been altered
	if (currentFontEdit != '')
	{
		//display sample
		var sample = document.getElementById('FontEditor_Sample');
		sample.innerText = document.getElementById(currentFontEdit).value.length > 10 ? document.getElementById(currentFontEdit).value.substring(0, 10) + '...' : document.getElementById(currentFontEdit).value;
		
		//set for object based on sample tag (header content footer)
		sample.style.textAlign = align;
		eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[5] = 'text-align: ' + sample.style.textAlign;		
		if (align == 'center')
		{
			document.getElementById('FontEditor_ALeftButton').className = 'LayoutFontEditorButton';
			document.getElementById('FontEditor_ACenterButton').className = 'LayoutFontEditorButtonDepressed';
			document.getElementById('FontEditor_ARightButton').className = 'LayoutFontEditorButton';
			document.getElementById('FontEditor_AJustifyButton').className = 'LayoutFontEditorButton';
		}
		else if (align == 'right')
		{
			document.getElementById('FontEditor_ALeftButton').className = 'LayoutFontEditorButton';
			document.getElementById('FontEditor_ACenterButton').className = 'LayoutFontEditorButton';
			document.getElementById('FontEditor_ARightButton').className = 'LayoutFontEditorButtonDepressed';
			document.getElementById('FontEditor_AJustifyButton').className = 'LayoutFontEditorButton';
		}
		else if (align == 'justify')
		{
			document.getElementById('FontEditor_ALeftButton').className = 'LayoutFontEditorButton';
			document.getElementById('FontEditor_ACenterButton').className = 'LayoutFontEditorButton';
			document.getElementById('FontEditor_ARightButton').className = 'LayoutFontEditorButton';
			document.getElementById('FontEditor_AJustifyButton').className = 'LayoutFontEditorButtonDepressed';
		}
		else
		{
			document.getElementById('FontEditor_ALeftButton').className = 'LayoutFontEditorButtonDepressed';
			document.getElementById('FontEditor_ACenterButton').className = 'LayoutFontEditorButton';
			document.getElementById('FontEditor_ARightButton').className = 'LayoutFontEditorButton';
			document.getElementById('FontEditor_AJustifyButton').className = 'LayoutFontEditorButton';
		}
		
	}
}

function setSize(size)
{
	//size has been altered
	if (currentFontEdit != '')
	{
		//display sample
		var sample = document.getElementById('FontEditor_Sample');
		sample.innerText = document.getElementById(currentFontEdit).value.length > 10 ? document.getElementById(currentFontEdit).value.substring(0, 10) + '...' : document.getElementById(currentFontEdit).value;

		//set for object based on sample tag (header content footer)		
		if (size == '+')
			sample.style.fontSize = (sample.style.fontSize == '') ? '12px' : (eval(sample.style.fontSize.replace('px', '')) + 1) + 'px';
		else if (size == '-')
			sample.style.fontSize = (sample.style.fontSize == '') ? '10px' : (eval(sample.style.fontSize.replace('px', '')) - 1) + 'px';
		else
			sample.style.fontSize = size;

		eval('boxArray[boxIndex].' + document.getElementById(currentFontEdit).tag + 'Styles')[6] = 'font-size: ' + sample.style.fontSize;
	}
}

function setBorderStyle()
{
	//set border style
	if (boxArray[boxIndex] != null)
	{
		boxArray[boxIndex].borderStyle = document.frmBorderEditor.BorderEditor_Style.options[document.frmBorderEditor.BorderEditor_Style.options.selectedIndex].value;
		
		if (boxArray[boxIndex].borderStyle == 'custom')
		{
			document.frmBorderEditor.BorderEditor_Size.disabled = true;
			document.getElementById('BorderEditor_Styles').style.visibility = 'visible';
		}
		else
		{
			document.frmBorderEditor.BorderEditor_Size.disabled = false;
			document.getElementById('BorderEditor_Styles').style.visibility = 'hidden';
			boxArray[boxIndex].bgStyle = new Array();
		}
	}	
}

function setBorderSize()
{
	//set border size
	if (boxArray[boxIndex] != null)
		boxArray[boxIndex].borderSize = document.frmBorderEditor.BorderEditor_Size.options[document.frmBorderEditor.BorderEditor_Size.options.selectedIndex].value;
}

function setBGImage()
{
	if (boxArray[boxIndex] != null)
	{
		boxArray[boxIndex].bgStyle = new Array();
		boxArray[boxIndex].bgImage = document.frmBGEditor.BGEditor_Image.options[document.frmBGEditor.BGEditor_Image.options.selectedIndex].value;
		//document.frmBGEditor.BGEditor_Style.options.selectedIndex = 0;
	}
}

function setBGImageTile()
{
	if (boxArray[boxIndex] != null)
		boxArray[boxIndex].bgTile = document.frmBGEditor.BGEditor_TileImage.checked;
}

function setBGStyle()
{
	if (boxArray[boxIndex] != null)
	{
		boxArray[boxIndex].bgStyle[styleUseTab] = document.frmBorderEditor.BorderEditor_Tab.checked;
		boxArray[boxIndex].bgStyle[styleBottomDropShadow] = document.frmBorderEditor.BorderEditor_BottomDropShadow.checked;
		boxArray[boxIndex].bgStyle[styleRightDropShadow] = document.frmBorderEditor.BorderEditor_RightDropShadow.checked;
		boxArray[boxIndex].bgStyle[styleTopLeftRounded] = document.frmBorderEditor.BorderEditor_TopLeftCorner.checked;
		boxArray[boxIndex].bgStyle[styleTopRightRounded] = document.frmBorderEditor.BorderEditor_TopRightCorner.checked;
		boxArray[boxIndex].bgStyle[styleBottomLeftRounded] = document.frmBorderEditor.BorderEditor_BottomLeftCorner.checked;
		boxArray[boxIndex].bgStyle[styleBottomRightRounded] = document.frmBorderEditor.BorderEditor_BottomRightCorner.checked;
		boxArray[boxIndex].bgStyle[styleBottomSperator] = document.frmBorderEditor.BorderEditor_BottomSeperator.checked;
		boxArray[boxIndex].bgStyle[styleLeftSeperator] = document.frmBorderEditor.BorderEditor_LeftSeperator.checked;

		boxArray[boxIndex].bgImage = '';
		document.frmBGEditor.BGEditor_Image.options.selectedIndex = 0;
	}
}

function checkColorHex(input)
{
	if (input.value != '')
	{
		input.value = input.value.toUpperCase();
		var regexp = /[^0-9 ^A-F]/g;
		input.value = input.value.replace(regexp, '');
		if (input.value.length == 6)
		{
			input.value = '#' + input.value;
			setColor(input.value);
		}
		else if (input.value.length > 6)
		{
			input.value = '#' + input.value.substring(0, 6);
			setColor(input.value);
		}
	}
}


//general content selection
function useExistingContent()
{
	//shows choices for existing
	document.getElementById('Layout_ContentGenericUseList').className = 'LayoutContent';
	document.getElementById('Layout_ContentGenericCopyList').className = 'LayoutContentHidden';
	adjustHeights(false);
}

function copyExistingContent()
{
	//shows choices for copy
	document.getElementById('Layout_ContentGenericUseList').className = 'LayoutContentHidden';
	document.getElementById('Layout_ContentGenericCopyList').className = 'LayoutContent';
	adjustHeights(false);
}

function useNewContent()
{
	//no choices to show
	document.getElementById('Layout_ContentGenericUseList').className = 'LayoutContentHidden';
	document.getElementById('Layout_ContentGenericCopyList').className = 'LayoutContentHidden';

	//go directly to new content
	adjustHeights(false);
	newContent(null);
}

function existingContent(contentIndex)
{
	//show edit fields for an existing box
	//non-rotating box will need the option set to the working general content id
	if (!boxArray[boxIndex].type.isRotatingBox)
		boxArray[boxIndex].options[0] = new queryOption('General Content', generalContentArray[contentIndex].id);
		
	document.frmLayoutBoxes.Layout_ContentGenericTitle.value = generalContentArray[contentIndex].title;
	document.frmLayoutBoxes.Layout_ContentGenericBody.value = generalContentArray[contentIndex].content;
	document.frmLayoutBoxes.Layout_ContentGenericLinkText.value = generalContentArray[contentIndex].linkText;
	document.frmLayoutBoxes.Layout_ContentGenericLinkURL.value = generalContentArray[contentIndex].linkURL;
	document.frmLayoutBoxes.Layout_ContentGenericImage.value = generalContentArray[contentIndex].image;
	document.getElementById('Layout_ContentGenericContent').tag = generalContentArray[contentIndex].id;
	document.getElementById('Layout_ContentGenericContent').className = 'LayoutContent';
}

function newContent(contentIndex)
{
	//show edit fields for a new box
	//find an open content id
	var newId = -1;
	while (findContentIndex(newId) >= 0)
	{
		newId--;
	}
	//non-rotating box will need the option set to the new general content id
	if (!boxArray[boxIndex].type.isRotatingBox)
		boxArray[boxIndex].options[0] = new queryOption('General Content', newId);

	document.frmLayoutBoxes.Layout_ContentGenericTitle.value = (contentIndex == null) ? '' : generalContentArray[contentIndex].title;
	document.frmLayoutBoxes.Layout_ContentGenericBody.value = (contentIndex == null) ? '' : generalContentArray[contentIndex].content;
	document.frmLayoutBoxes.Layout_ContentGenericLinkText.value = (contentIndex == null) ? '' : generalContentArray[contentIndex].linkText;
	document.frmLayoutBoxes.Layout_ContentGenericLinkURL.value = (contentIndex == null) ? '' : generalContentArray[contentIndex].linkURL;
	document.frmLayoutBoxes.Layout_ContentGenericImage.value = (contentIndex == null) ? '' : generalContentArray[contentIndex].image;
	document.getElementById('Layout_ContentGenericContent').tag = newId;
	document.getElementById('Layout_ContentGenericContent').className = 'LayoutContent';

	//rotating need a groupid set	
	if (boxArray[boxIndex].type.isRotatingBox)
	{
		//copy existing content into new content if available
		if (contentIndex == null)
			generalContentArray[generalContentArray.length] = new generalContent(newId, boxArray[boxIndex].options[0].value, '', '', '', '', '');
		else
			generalContentArray[generalContentArray.length] = new generalContent(newId, boxArray[boxIndex].options[0].value, generalContentArray[contentIndex].title, generalContentArray[contentIndex].content, generalContentArray[contentIndex].linkText, generalContentArray[contentIndex].linkURL, generalContentArray[contentIndex].image);
	}
	else
	{
		//copy existing content into new content if available
		if (contentIndex == null)
			generalContentArray[generalContentArray.length] = new generalContent(newId, null, '', '', '', '', '');
		else
			generalContentArray[generalContentArray.length] = new generalContent(newId, null, generalContentArray[contentIndex].title, generalContentArray[contentIndex].content, generalContentArray[contentIndex].linkText, generalContentArray[contentIndex].linkURL, generalContentArray[contentIndex].image);
	}
}


//XML
function buildPageXml()
{
	//build info nodes for each box
	var xmlDoc = createXmlDocument();
	var root = xmlDoc.createElement('welcomePage')
	root.setAttribute('pageId', document.frmLayoutBoxes.pageId.value);
	root.setAttribute('layoutId', document.frmLayoutBoxes.layoutId.value);
	root.setAttribute('langId', document.frmLayoutBoxes.langId.value);

	for (var i=0; i<boxArray.length; i++)
	{
		if (boxArray[i].type != null)
		{
			//construct the boxData
			var boxData = xmlDoc.createElement('boxData')
			
			var boxId = xmlDoc.createElement('boxId');
			boxId.text = boxArray[i].id;
			boxData.appendChild(boxId);

			var boxTypeId = xmlDoc.createElement('boxTypeId');
			boxTypeId.text = boxArray[i].type.id;
			boxData.appendChild(boxTypeId);

			var content = xmlDoc.createElement('content');
			content.text = boxArray[i].content;
			boxData.appendChild(content);

			var contentStyles = xmlDoc.createElement('contentStyles');
			contentStyles.text = boxArray[i].contentStyles.join(';');
			boxData.appendChild(contentStyles);
			
			var header = xmlDoc.createElement('header');
			header.text = boxArray[i].header;
			boxData.appendChild(header);

			var headerStyles = xmlDoc.createElement('headerStyles');
			headerStyles.text = boxArray[i].headerStyles.join(';');
			boxData.appendChild(headerStyles);
			
			var footer = xmlDoc.createElement('footer');
			footer.text = boxArray[i].footer;
			boxData.appendChild(footer);

			var footerStyles = xmlDoc.createElement('footerStyles');
			footerStyles.text = boxArray[i].footerStyles.join(';');
			boxData.appendChild(footerStyles);

			var linkStyles = xmlDoc.createElement('linkStyles');
			linkStyles.text = boxArray[i].linkStyles.join(';');
			boxData.appendChild(linkStyles);

			var pageBGColor = xmlDoc.createElement('pageBGColor');
			pageBGColor.text = boxArray[i].pageBGColor;
			boxData.appendChild(pageBGColor);
			
			var bgColor = xmlDoc.createElement('bgColor');
			bgColor.text = boxArray[i].bgColor;
			boxData.appendChild(bgColor);

			var bgStyle = xmlDoc.createElement('bgStyle');
			bgStyle.text = boxArray[i].bgStyle.join(';');
			boxData.appendChild(bgStyle);
			
			var bgImage = xmlDoc.createElement('bgImage');
			bgImage.text = boxArray[i].bgImage;
			boxData.appendChild(bgImage);

			var bgTile = xmlDoc.createElement('bgTile');
			bgTile.text = boxArray[i].bgTile.toString();
			boxData.appendChild(bgTile);
									
			var borderSize = xmlDoc.createElement('borderSize');
			borderSize.text = boxArray[i].borderSize;
			boxData.appendChild(borderSize);
			
			var borderStyle = xmlDoc.createElement('borderStyle');
			borderStyle.text = boxArray[i].borderStyle;
			boxData.appendChild(borderStyle);
			
			var borderColor = xmlDoc.createElement('borderColor');
			borderColor.text = boxArray[i].borderColor;
			boxData.appendChild(borderColor);									

			var underlineColor = xmlDoc.createElement('underlineColor');
			underlineColor.text = boxArray[i].underlineColor;
			boxData.appendChild(underlineColor);									

			var bulletColor = xmlDoc.createElement('bulletColor');
			bulletColor.text = boxArray[i].bulletColor;
			boxData.appendChild(bulletColor);									
						
			var queryOptions = xmlDoc.createElement('queryOptions');
			for (var j=0; j<boxArray[i].options.length; j++)
			{
				//inject option nodes
				var option = xmlDoc.createElement('option');

				var optName = xmlDoc.createElement('name');
				optName.text = boxArray[i].options[j].name;
				option.appendChild(optName);
				
				var optValue = xmlDoc.createElement('value');
				optValue.text = boxArray[i].options[j].value;
				option.appendChild(optValue);

				queryOptions.appendChild(option);
			}
			boxData.appendChild(queryOptions);
			
			root.appendChild(boxData);
		}
	}
	
	//add general content change nodes
	for (var j=0; j<generalContentArray.length; j++)
	{
		var generalContentData = xmlDoc.createElement('genericContent')

		var contentId = xmlDoc.createElement('id');
		contentId.text = generalContentArray[j].id;
		generalContentData.appendChild(contentId);	

		var contentGroup = xmlDoc.createElement('group');
		if (generalContentArray[j].group != null)
			contentGroup.text = generalContentArray[j].group;
		generalContentData.appendChild(contentGroup);	
		
		var contentTitle = xmlDoc.createElement('title');
		contentTitle.text = generalContentArray[j].title;
		generalContentData.appendChild(contentTitle);	
		
		var contentBody = xmlDoc.createElement('content');
		contentBody.text = generalContentArray[j].content;
		generalContentData.appendChild(contentBody);	

		var contentLinkText = xmlDoc.createElement('linkText');
		contentLinkText.text = generalContentArray[j].linkText;
		generalContentData.appendChild(contentLinkText);	

		var contentLinkURL = xmlDoc.createElement('linkURL');
		contentLinkURL.text = generalContentArray[j].linkURL;
		generalContentData.appendChild(contentLinkURL);	

		if (generalContentArray[j].image.indexOf('<') != -1)
		{
			var tempDoc = createXmlDocument();
			tempDoc.loadXML(generalContentArray[j].image);
			if (tempDoc.xml == '')
				tempDoc.loadXML(generalContentArray[j].image.replace('>', '/>'));
			if (tempDoc.xml != '')
			{
				if (tempDoc.firstChild.getAttribute('src') != '')
					generalContentArray[j].image = tempDoc.firstChild.getAttribute('src');
			}
		}
		
		var contentImage = xmlDoc.createElement('image');
		contentImage.text = generalContentArray[j].image;
		generalContentData.appendChild(contentImage);	
		
		root.appendChild(generalContentData);
	}
	
	xmlDoc.appendChild(root)
	//alert(xmlDoc.xml);
	return xmlDoc;
}

function downloadQueryXml()
{
	//AJAX call to download query XML
	if (document.frmLayoutBoxes.boxType.options[document.frmLayoutBoxes.boxType.selectedIndex].value != '')
	{
		var loaded = loadXmlDocument('system_welcomepagegetoptions.asp?id=' + document.frmLayoutBoxes.boxType.options[document.frmLayoutBoxes.boxType.selectedIndex].value, downloadCallback)
//		if (!(loaded))
//			alert('Download failed.');
	}
}

function downloadCallback(xmlDoc)
{
	//download was successful, now draw the downloaded information
	drawOptions(xmlDoc);
	drawContent(xmlDoc);
	drawBGStyles(xmlDoc);
	setContent();
}

function savePage()
{
	//if the general/rotating content stuff is open, initialize it
	if(document.getElementById('Layout_ContentGeneric').className != 'LayoutContentHidden')
	{
		initGeneralContent();
	}

	//AJAX call to save page XML
	document.getElementById('savedMessage').className = 'LayoutContentHidden';
	document.getElementById('savingMessage').className = 'LayoutContent';
	var saved = sendXmlDocument('system_welcomepagesave.asp', buildPageXml(), saveCallback);
	//if (!(saved))
	//		alert('Save failed.');
}

function saveCallback()
{
	//save was successful
	if (xmlPost.readyState == 4)
	{
		if (xmlPost.status==200)
		{
			document.getElementById('savedMessage').className = 'LayoutContent';
			document.getElementById('savingMessage').className = 'LayoutContentHidden';
			
			//if there was general content inserted replace the temp (negative) ids with the actual identities
			var inserts = xmlPost.responseText.split('#');
			for (var i=0;i<inserts.length;i++)
			{
				//delimited as temp|ident#temp|ident
				var ids = inserts[i].split('|');
				for(var j=0; j<generalContentArray.length; j++)
				{
					if (generalContentArray[j].id == ids[0])
					{
						generalContentArray[j].id = ids[1];
						break;
					}
				}
				
				//all options that refer to the temp ids will need to be updated with the identities
				for(var k=0; k<boxArray.length; k++)
				{
					if ((boxArray[k].type != null) && (!boxArray[k].type.isInfoBox) && (!boxArray[k].type.isListBox) && (!boxArray[k].type.isPollBox) && (!boxArray[k].type.isWhatsHotBox) && (boxArray[k].options.length == 1) && (boxArray[k].options[0].value == ids[0]))
						boxArray[k].options[0].value = ids[1];
				}
			}
		}
		//else
		//{
			//alert('saved failure');
		//	alert(xmlPost.responseText);
		//}
	}
}

function previewPage()
{
	//post preview form to preview page
	document.getElementById('savedMessage').className = 'LayoutContentHidden';
	document.getElementById('savingMessage').className = 'LayoutContentHidden';	
	pageXml = buildPageXml();
	document.frmPreview.pageData.value = pageXml.xml;
}

