
// Global array for activity extras (e.g., text and images)
var activityExtraArray = new Array();
var activityLinkArray = new Array();

// Constructor for single ActivityExtra
function ActivityExtra (imageURL, borderColor, borderWidth, text, link, linkTarget, left, top, width, height, fontFace, fontStyle, fontSize, fontColor) {

	this.type = "extra";
	this.imageURL = imageURL;
	this.borderColor = borderColor;
	this.borderWidth = borderWidth;
	this.text = text;
	this.link = link;
	this.linkTarget = linkTarget;
	this.left = left;
	this.top = top;
	this.width = width;
	this.height = height;
	this.zindex = 100;
	this.fontFace = fontFace;
	this.fontStyle = fontStyle;
	this.fontSize = fontSize;
	this.fontColor = fontColor;
}

// Constructor for single ActivityExtra
function NonPrintingActivityExtra (imageURL, borderColor, borderWidth, text, link, linkTarget, left, top, width, height, fontFace, fontStyle, fontSize, fontColor) {

	this.type = "nonprinting extra";
	this.imageURL = imageURL;
	this.borderColor = borderColor;
	this.borderWidth = borderWidth;
	this.text = text;
	this.link = link;
	this.linkTarget = linkTarget;
	this.left = left;
	this.top = top;
	this.width = width;
	this.height = height;
	this.zindex = 100;
	this.fontFace = fontFace;
	this.fontStyle = fontStyle;
	this.fontSize = fontSize;
	this.fontColor = fontColor;
}

function StaticBox(left, top, width, height, backgroundColor, borderColor, borderWidth){

	this.type = "static box";
	this.left = left;
	this.top = top;
	this.width = width;
	this.height = height;
	this.zindex = 0;
	this.backgroundColor = backgroundColor;
	this.borderColor = borderColor;
	this.borderWidth = borderWidth;
}

// Constructor for single LinkExtra object
function LinkObject (url, linkText, linkTarget) {

	this.url = url;
	this.linkText = linkText;
	this.linkTarget = linkTarget;
}

// Constructor for single LinkExtra object
function LinkExtra (textStart, textEnd, linkArray, left, top, width, height, fontFace, fontStyle, fontSize, fontColor) {

	this.type = "link";
	this.textStart = textStart;
	this.textEnd = textEnd;
	this.linkArray = linkArray;
	this.left = left;
	this.top = top;
	this.width = width;
	this.height = height;
	this.zindex = 100;
	this.fontFace = fontFace;
	this.fontStyle = fontStyle;
	this.fontSize = fontSize;
	this.fontColor = fontColor;
}



// go to the selected url in the submitted form
function goUrl(form) {

	var urlList = form.urlList;
	var linkTargetList = form.linkTarget;
	var urlIndex = urlList.selectedIndex;
	var linkTarget = linkTargetList[urlIndex-1].value; // Decrement by 1 because first option on url menu is a label
 
	
	// go to top frame
	//alert("goUrl");
	if (linkTarget == "_top") {
		parent.location = urlList.options[urlIndex].value;
	}
	else if (linkTarget == "_self") {
		location = urlList.options[urlIndex].value;
	}

}

// format one Static Box
function formatStaticBox (itemData, shiftLeft, shiftTop)
{
	var itemHTML = "";
	
	// Fix a bug on NN
	if (NN && itemData.backgroundColor == "") {
		itemData.backgroundColor = "white";
	}
	
	if (itemData.backgroundColor == "") {
		itemHTML = "<DIV id = \"staticBoxDiv\" class = \"staticBoxDiv\" style=\"position:absolute; left:" + (itemData.left + shiftLeft) + "; top:" + (itemData.top + shiftTop) + "; width:" + itemData.width + "; height:" + itemData.height + "; border-style:solid; border-width:" + itemData.borderWidth + "; border-color:" + itemData.borderColor + "; z-index:" + itemData.zindex + "\">";
		itemHTML += "<TABLE border=0 cellspacing=0 cellpadding=0 width=" + itemData.width + " height=" + itemData.height + "><TR><TD>&nbsp;</TD></TR></TABLE>";
	}
	else {
		itemHTML = "<DIV id = \"staticBoxDiv\" class = \"staticBoxDiv\" style=\"position:absolute; left:" + (itemData.left + shiftLeft) + "; top:" + (itemData.top + shiftTop) + "; width:" + itemData.width + "; height:" + itemData.height + "; border-style:solid; border-width:" + itemData.borderWidth + "; border-color:" + itemData.borderColor + "; background-color:" + itemData.backgroundColor + "; z-index:" + itemData.zindex + "\">";
		itemHTML += "<TABLE border=0 cellspacing=0 cellpadding=0 width=" + itemData.width + " height=" + itemData.height + "><TR><TD bgColor = \"" + itemData.backgroundColor + "\">&nbsp;</TD></TR></TABLE>";
	}

	itemHTML += "</DIV>";

	return itemHTML;
}



// format one ActivityExtra
// this function formats text/image extras
function formatActivityExtra (itemIndex, itemData, shiftLeft, shiftTop)
{

	var itemHTML;

	var left = activityExtraArray[itemIndex].left + shiftLeft;
	var top = activityExtraArray[itemIndex].top + shiftTop;
	var width = activityExtraArray[itemIndex].width;
	var height = activityExtraArray[itemIndex].height;
	


	
	var footerHTML = "</DIV>";
		
	var theStyle="normal",theWeight="normal";	

	if (itemData.fontStyle != null) {
		if(itemData.fontStyle.indexOf("Bold")!=-1)
		{
			theWeight="Bold";
		}
		if(itemData.fontStyle.indexOf("Italic")!=-1)
		{
			theStyle="Italic";
		}
	}

	var theFontColorStyle = "";
	if (itemData.fontColor)
		theFontColorStyle = "; color:" + itemData.fontColor;

	if ((activityExtraArray[itemIndex].type == "extra") || (activityExtraArray[itemIndex].type == "nonprinting extra")) {
		var imageURL = activityExtraArray[itemIndex].imageURL;
		var text = activityExtraArray[itemIndex].text;
		var linkHTML = "";
		var endLinkHTML = "";

//		if (text != "")
//		{
//			if (MAC)
//			{
//				top += 3;
//			}
//		}


//		var adjTop;
//		adjTop = prompt("enter the adjustment", "0");
//		top += parseInt(adjTop);


//		alert(itemData.fontFace + " " + itemData.fontSize);


		
		if (text != "" && MAC)
		{
			var adjTop = 1;

			switch (itemData.fontFace)
			{
				case 'Arial':
					switch (itemData.fontSize)
					{
						case '14':
						case '32':
							adjTop = 0;
							break;

						case '24':
							adjTop = -1;
							break;
					}
					break;

				case 'Courier':
					switch (itemData.fontSize)
					{
						case '8':
							adjTop = 3;
							break;

						case '12':
						case '14':
						case '16':
							adjTop = 0;
							break;
					}
					break;

				case 'Times':
					switch (itemData.fontSize)
					{
						case '12':
							adjTop = 2;
							break;

						case '16':
						case '20':
						case '24':
							adjTop = 3;
							break;

						case '32':
							adjTop = 4;
							break;
					}
					break;
			}

//			alert(adjTop);
			top += adjTop;
		}





		var headerHTML = "<DIV id=\"activityExtra" + itemIndex + "\" STYLE=\"position:absolute; left:" + left + "; top:" + top + "; visibility:show; ";


		if (width != 0) headerHTML += "; width:" + width; 
		if (height != 0) headerHTML += "; height:" + height; 
		if (text != "") {
			headerHTML += "; z-index:" + (itemData.zindex + 1); // make sure text extra above image extra
		}
		else {
			headerHTML += "; z-index:" + itemData.zindex;
		}
		headerHTML += "\">";
		
		if (itemData.link != "") {
			linkHTML = "<A HREF = \"" + itemData.link + "\" target = \"" + itemData.linkTarget + "\">";
			endLinkHTML = "</A>";
		}

		// format for text extra
		if (text != "")
		{
			itemHTML = headerHTML + linkHTML + "<FONT STYLE=\"font-family:'"+itemData.fontFace + "'; font-size:"+itemData.fontSize+"px; font-style:"+theStyle+"; font-weight:"+theWeight+ theFontColorStyle + "\">" + text + "</FONT>" + endLinkHTML + footerHTML;
		}	
		// format for image extra
		// TODO borders on images not working in Netscape
		else if (imageURL != "") {
			if (IE) {
				itemHTML = headerHTML + linkHTML + "<img src=\"" + imageURL + "\" style=\"border:solid " + activityExtraArray[itemIndex].borderColor + " " + activityExtraArray[itemIndex].borderWidth + "px\" width=" + itemData.width + " height=" + itemData.height + ">" + endLinkHTML + footerHTML;
			}
			else {
				itemHTML = headerHTML + linkHTML + "<img border=0 src=\"" + imageURL + "\" width=" + itemData.width + " height=" + itemData.height + ">" + endLinkHTML + footerHTML;
			}
		}
	}
	
	//alert (itemHTML);
	return itemHTML;
}



// format one LinkExtra
// this function formats link extras
function formatLinkExtra (itemIndex, itemData)
{

	var itemHTML;

	var left = activityLinkArray[itemIndex].left;
	var top = activityLinkArray[itemIndex].top;
	var width = activityLinkArray[itemIndex].width;
	var height = activityLinkArray[itemIndex].height;
	
	var headerHTML = "<DIV id=\"activityExtra" + itemIndex + "\" STYLE=\"position:absolute; left:" + left + "; top:" + top + "; visibility:show; z-index:" + itemData.zindex;
	if (width != 0) headerHTML += "; width:" + width; 
	if (height != 0) headerHTML += "; height:" + height; 
	headerHTML += "\">";
	
	var footerHTML = "</DIV>";
		
	var theStyle="normal",theWeight="normal";	

	if (itemData.fontStyle != null) {
		if(itemData.fontStyle.indexOf("Bold")!=-1)
		{
			theWeight="Bold";
		}
		if(itemData.fontStyle.indexOf("Italic")!=-1)
		{
			theStyle="Italic";
		}
	}

	var theFontColorStyle = "";
	if (itemData.fontColor)
		theFontColorStyle = "; color:" + itemData.fontColor;

	if (activityLinkArray[itemIndex].type == "link") {
		var textStart = activityLinkArray[itemIndex].textStart;
		var textEnd = activityLinkArray[itemIndex].textEnd;
		var linkArray = activityLinkArray[itemIndex].linkArray;
		
		if (linkArray.length == 1) {
			itemHTML = headerHTML + "<FONT STYLE=\"font-family:'"+itemData.fontFace + "'; font-size:"+itemData.fontSize+"px; font-style:"+theStyle+"; font-weight:"+theWeight+ theFontColorStyle + "\">" + textStart + " <A HREF=\"" + linkArray[0].url + "\" target=\"" + linkArray[0].linkTarget + "\">" + linkArray[0].linkText + "</A> " + textEnd + "</FONT>" + footerHTML;
		}
		else {
		//alert("menu");
			var linkMenu = "<FORM>" + textStart;
			linkMenu += " <SELECT NAME=\"urlList\" onChange='goUrl(this.form)'>";
			linkMenu += "<OPTION SELECTED VALUE=\"\">Choose Location\n";

			for (var i = 0; i < linkArray.length; i ++) {
				linkMenu += "<OPTION VALUE=\"" + linkArray[i].url + "\">" + linkArray[i].linkText + "\n";
				
			}
			linkMenu += "</SELECT> " + textEnd;
			
			// put link targets into an array of hidden inputs
			for (var i = 0; i < linkArray.length; i ++) {
				linkMenu += "<INPUT TYPE=HIDDEN NAME=\"linkTarget\" VALUE=\"" + linkArray[i].linkTarget + "\">" + "\n";
				
			}
			
			linkMenu += "</FORM>";
			itemHTML = headerHTML + linkMenu + footerHTML;

		}
	}
	
	//alert (itemHTML);
	return itemHTML;
}


