/*
 * Plasma Font Picker - Library for Font Picking for fields in Plasma.
 * Copyright (C) 1995-2007 IonicWeb, LLC.  All rights reserved.
 *
 * This library is only available for use as part of the Plasma 2007
 * Web Application Server by IonicWeb, LLC.  Any other use is currently
 * prohibited.  For more information and license options for this
 * work, please send requests to info@ionicweb.com. 
 *
 * The Plasma license is found at http://ionicweb.com/plasma/license
 */
     var divSetFont = false;
     var curIdFont;
     var fonts = Array("Arial", "Comic Sans MS", "Courier New", "Tahoma", "Times New Roman", "Verdana");
     
     function getObjFont(id) {
        return document.getElementById(id);
     }

     function setDivFont() {     
     
     	if (!document.createElement) { return; }
        var elemDiv = document.createElement("div");
        if (typeof(elemDiv.innerHTML) != "string") { return; }
        elemDiv.id = "fontpicker";
        elemDiv.style.position = "absolute";
        elemDiv.style.display = "none";
        
        elemDiv.style.zIndex = 99;
        
        elemDiv.style.border = "#000000 1px solid";
        elemDiv.style.background = "#FFFFFF";
        elemDiv.innerHTML = "<span style=\"font-family:Verdana; font-size:11px;\">Pick a font: " 
        	+ getFontTable() 
        	+ "</span>";

        document.body.appendChild(elemDiv);
        divSetFont = true;
     }

     function pickFont(id) {
        
     	if (!divSetFont) { setDivFont(); }
     	var picker = getObjFont("fontpicker");     	
        if (id == curIdFont && picker.style.display == "block") {
            picker.style.display = "none";
            return;
        }
     	curIdFont = id;
     	var thelink = getObjFont(id+"text");
     	picker.style.top = getAbsoluteOffsetTopFont(thelink) + 20;
     	picker.style.left = getAbsoluteOffsetLeftFont(thelink);     
	picker.style.display = "block";
     }

     function getFontTable() {
      	 var tableCode = "";
         tableCode += "<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\">";
         for (i = 0; i < fonts.length; i++) {
            
              tableCode += "<tr>";
              tableCode += "<td height=\"15\" width=\"100%\"><span id=\"font_" + i + "\" onClick=\"setFont(\'" + fonts[i] + "\');\" onMouseOver=\"mouseOverFont(\'font_" + i + "\');\" onMouseOut=\"mouseOutFont(\'font_" + i + "\');\" style=\"cursor:pointer; font-size:10px; font-family:\'" + fonts[i] + "\';\">" + fonts[i] + "</span></td></tr>";
         }
         tableCode += "</table>";
         
      	 return tableCode;
     }

     function getAbsoluteOffsetTopFont(obj) {
     	var top = obj.offsetTop;
     	var parent = obj.offsetParent;
     	while (parent != document.body) {
            top += parent.offsetTop;
            parent = parent.offsetParent;
     	}
     	return top;
     }
     
     function getAbsoluteOffsetLeftFont(obj) {
     	var left = obj.offsetLeft;
     	var parent = obj.offsetParent;
     	while (parent != document.body) {
            left += parent.offsetLeft;
            parent = parent.offsetParent;
     	}
     	return left;
     }
     function setFont(font) {
        
     	var link = getObjFont(curIdFont);
     	var field = getObjFont(curIdFont + "field");
     	var font_text = getObjFont(curIdFont + "text");
     	var picker = getObjFont("fontpicker");
        field.value = font;
        link.value = font;
        field.style.fontFamily = font;
        font_text.innerHTML = "&nbsp;&nbsp;" + font + "&nbsp;&nbsp;";
     	picker.style.display = "none";
        eval(getObjFont(curIdFont + "field").title);

     }
     function mouseOutFont(this_font)
     {
        var t_font = document.getElementById(this_font);
        t_font.style.textDecoration="";
     }
     function mouseOverFont(this_font)
     {
        var t_font = document.getElementById(this_font);
        t_font.style.textDecoration="underline";
     }
