// ===================================================================
// FontPicker.js
// Auth.: Monica Socol 
// Date: Nov 04, 2002
// ===================================================================


/* 
DESCRIPTION: This widget is used to select a character, from a table.
It is created using the ColorPicker as a sample.

USAGE:
// Create a new FontPicker object using DHTML popup
var fp = new FontPicker();

// Create a new ColorPicker object using Window Popup
var fp = new FontPicker('window');

// Add a link in your page to trigger the popup. For example:
<A HREF="#" onClick="fp.show('pick');return false;" NAME="pick" ID="pick">Pick</A>

// If using DHTML popup, write out the required DIV tag near the bottom
// of your page.
<SCRIPT LANGUAGE="JavaScript">fp.writeDiv()</SCRIPT>

// Write the 'pickFont' function that will be called when the user clicks
// a symbol and do something with the value
function pickFont(symbol) {
	field.value = symbol;
	}

NOTES:
1) Requires the functions in AnchorPosition.js and PopupWindow.js

2) Your anchor tag MUST contain both NAME and ID attributes which are the 
   same. For example:
   <A NAME="test" ID="test"> </A>

3) There must be at least a space between <A> </A> for IE5.5 to see the 
   anchor tag correctly. Do not do <A></A> with no space.

4) When a FontPicker object is created, a handler for 'onmouseup' is
   attached to any event handler you may have already defined. Do NOT define
   an event handler for 'onmouseup' after you define a FontPicker object or
   the font picker will not hide itself correctly.
*/ 

function FontPicker_writeDiv() {
	document.writeln("<DIV ID=\"fontPickerDiv\" STYLE=\"position:absolute;visibility:hidden;\"> </DIV>");
	}

function FontPicker_show(anchorname) {
	this.showPopup(anchorname);
	}

function FontPicker_pickFont(symbol,obj) {
	//var win = window.parent.TextFrame;
	var win = customizeLayerWin;

	obj.hidePopup();
	if (win.pickFont) {
		win.pickFont(symbol);
		}
	else {
		alert("You must define a function named 'pickFont' to receive the value clicked!");
		}
	}
	
// This function runs when you move your mouse over a symbol block, if you have a newer browser
function FontPicker_highlightFont(c) {
	var thedoc = (arguments.length>1)?arguments[1]:window.document;
	var d;
	d = thedoc.getElementById("fontPickerSelectedFontValue");
	d.innerHTML = "<span style='font-size:24.0pt;font-family:"+CustomLayerPointStyle+"'>"+String.fromCharCode(c)+"</span>";
}


function FontPicker() {
	var windowMode = false;
	// Create a new PopupWindow object
	if (arguments.length==0) {
		var divname = "fontPickerDiv";
		}
	else if (arguments[0] == "window") {
		var divname = '';
		windowMode = true;
		}
	else {
		var divname = arguments[0];
		}
	
	var symbols;

	switch(CustomLayerPointStyle) {
		case "ESRI AMFM Sewer":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,119,120,
				121,122,123,124,125);
			break;
		case "ESRI AMFM Water":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,119,120,
				121,122,123,124,125,
				161,162,163,164,165,166,167,168,169,170,
				171,172,173,174,175,176,177,178,179,180,
				181,182,184,185,186,187,188,189,190,
				191,192,193,194,195,196,197,198,199,200,
				201,202,203,204,205,206,207,208,209,210,
				211,212,213,214,215,216,217,218,219,220,
				221,222,223,224,225,226,227,228,229,230,
				231,232,233,234,235,236,237,218);
			break;
		case "ESRI Cartography":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,119,120,
				121,122,123,124,125,
				161,162,163,164,165,166,167,168,169,170,
				171,172,173,174,175,176,177,178,179,180,
				181,182,183,184,185,186,187,188,189,190,
				191,192,193,194,195,196,197,198,199,200,
				201,202,203,204,205,206,207,208,209,210,
				211,212,213,214,215,216,217,218,219,220,
				221,222,223,224,225,226,227,228,229,230,
				231,232,233,234,235,236,237,238,239,240,
				241,242,243,244,245,246,247,248,249,250,
				251,252,253,254,255);
			break;
		case "ESRI default marker":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,
				161,162,163,164,165,166,167,168,169,170,
				171,172,173,174,175,176,177,178,179,180,
				181,182,183,184,185,186,187,188,189,190,
				191,192,193,194,195,196,197,198,199,200,
				201,202,203,204,205,206,207,208,209,210,
				211,212,213,214,215,216,217,218,219);
			break;
		case "ESRI Environmental & Icons":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,119,120,
				121,122,123,124,125,
				192,193,194,195,196,197,198,199,200,
				201,202,203,204,205,206,207,208,209,210,
				211,212,213,214,215,216,217,218,219,220,
				221,222,223,224,225,226,227,228,229,230,
				231,232,233,234,235,236,237,238,239,240,
				241,242,243,244,245,246,247,248,249,250,
				251,252,253,254,255);
			break;
		case "ESRI Transportation & Civic":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,119,120,
				121,122,123,124,125,
				192,193,194,195,196,197,198,199,200,
				201,202,203,204,205,206,207,208,209,210,
				211,212,213,214,215,216,217,218,219,220,
				221,222,223,224,225,226,227,228,229,230,
				231,232,233,234,235,236,237,238,239,240,
				241,242,243,244,245,246,247,248,249,250,
				251,252,253,254,255);
			break;
	}

	var total = symbols.length;
	var width = 10;

	var ht = Math.round(total/width);
	var dd = ht.toString();
	dd = dd.substring(0,1);
	var ff = parseInt(dd)*10;
	if (ht-ff < 5)
	{	ht = ht + 3;}
	else {  ht = ht + 2; }

	ht = ht * 20;

	if (divname != "") {
		var fp = new PopupWindow(divname);
		}
	else {
		var fp = new PopupWindow();
		fp.setSize(260,ht);
		}

	// Object variables
	fp.currentValue = "#FFFFFF";
	
	// Method Mappings
	fp.writeDiv = FontPicker_writeDiv;
	fp.highlightFont = FontPicker_highlightFont;
	fp.show = FontPicker_show;

	var fp_contents = "";
	var windowRef = (windowMode)?"window.opener.":"";

	if (windowMode) {
		fp_contents += "<HTML><HEAD><TITLE>Select Symbol</TITLE></HEAD>";
		fp_contents += "<BODY MARGINWIDTH=0 MARGINHEIGHT=0 LEFMARGIN=0 TOPMARGIN=0><CENTER>";
		fp_contents += "<span style='font-size:12.0pt;font-family:"+CustomLayerPointStyle+"'>";
		}
	fp_contents += "<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=0>";
	var use_highlight = (document.getElementById || document.all)?true:false;
	for (var i=0; i<total; i++) {
		if ((i % width) == 0) { fp_contents += "<TR>"; }
		if (use_highlight) { var mo = 'onMouseOver="'+windowRef+'FontPicker_highlightFont(\''+symbols[i]+'\',window.document)"'; }
		else { mo = ""; }
		fp_contents += '<TD align = "center" width=24 height=19><A HREF="#" onClick="'+windowRef+'FontPicker_pickFont(\''+symbols[i]+'\','+windowRef+'window.popupWindowObjects['+fp.index+']);return false;" '+mo+' STYLE="text-decoration:none;"><B>'+String.fromCharCode(symbols[i])+'</B></A></TD>';

		if ( ((i+1)>=total) || (((i+1) % width) == 0)) { 
			fp_contents += "</TR>";
			}
	}
	// If the browser supports dynamically changing TD cells, add the fancy stuff
	if (document.getElementById) {
		fp_contents += "<TR><TD COLSPAN='"+width+"' ALIGN='CENTER' BGCOLOR='#FFCC99' height=35 ID='fontPickerSelectedFontValue'><FONT size='6'>"+String.fromCharCode(33)+"</font></TD></TR>";
		}

	fp_contents += "</TABLE>";
	fp_contents += "</span>\n";

	if (windowMode) {

		fp_contents += "</CENTER></BODY></HTML>";
		}
	// end populate code

	// Write the contents to the popup object
	fp.populate(fp_contents+"\n");
	// Move the table down a bit so you can see it
	fp.offsetY = 25;
	fp.autoHide();
	return fp;
}

/*
function PopulateSymbolsArray(){
	var symbols;

	switch(CustomLayerPointStyle) {
		case "ESRI AMFM Sewer":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,119,120,
				121,122,123,124,125);
			break;
		case "ESRI AMFM Water":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,119,120,
				121,122,123,124,125,
				161,162,163,164,165,166,167,168,169,170,
				171,172,173,174,175,176,177,178,179,180,
				181,182,183,184,185,186,187,188,189,190,
				191,192,193,194,195,196,197,198,199,200,
				201,202,203,204,205,206,207,208,209,210,
				211,212,213,214,215,216,217,218,219,220,
				221,222,223,224,225,226,227,228,229,230,
				231,232,233,234,235,236,237,218);
			break;
		case "ESRI Cartography":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,119,120,
				121,122,123,124,125,
				161,162,163,164,165,166,167,168,169,170,
				171,172,173,174,175,176,177,178,179,180,
				181,182,183,184,185,186,187,188,189,190,
				191,192,193,194,195,196,197,198,199,200,
				201,202,203,204,205,206,207,208,209,210,
				211,212,213,214,215,216,217,218,219,220,
				221,222,223,224,225,226,227,228,229,230,
				231,232,233,234,235,236,237,238,239,240,
				241,242,243,244,245,246,247,248,249,250,
				251,252,253,254,255);
			break;
		case "ESRI default marker":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,
				161,162,163,164,165,166,167,168,169,170,
				171,172,173,174,175,176,177,178,179,180,
				181,182,183,184,185,186,187,188,189,190,
				191,192,193,194,195,196,197,198,199,200,
				201,202,203,204,205,206,207,208,209,210,
				211,212,213,214,215,216,217,218,219);
			break;
		case "ESRI Environmental & Icons":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,119,120,
				121,122,123,124,125,
				192,193,194,195,196,197,198,199,200,
				201,202,203,204,205,206,207,208,209,210,
				211,212,213,214,215,216,217,218,219,220,
				221,222,223,224,225,226,227,228,229,230,
				231,232,233,234,235,236,237,238,239,240,
				241,242,243,244,245,246,247,248,249,250,
				251,252,253,254,255);
			break;
		case "ESRI Transportation & Civic":
			// Code to populate font picker window
			symbols = new Array(33,34,35,36,37,38,39,40,
				41,42,43,44,45,46,47,48,49,50,
				51,52,53,54,55,56,57,58,59,60,
				61,62,63,64,65,66,67,68,69,70,
				71,72,73,74,75,76,77,78,79,80,
				81,82,83,84,85,86,87,88,89,90,
				91,92,93,94,95,96,97,98,99,100,
				101,102,103,104,105,106,107,108,109,110,
				111,112,113,114,115,116,117,118,119,120,
				121,122,123,124,125,
				192,193,194,195,196,197,198,199,200,
				201,202,203,204,205,206,207,208,209,210,
				211,212,213,214,215,216,217,218,219,220,
				221,222,223,224,225,226,227,228,229,230,
				231,232,233,234,235,236,237,238,239,240,
				241,242,243,244,245,246,247,248,249,250,
				251,252,253,254,255);
			break;
		default:
			alert(Font not found!);
	}
	return symbols();
}*/
