//
//	PANEL OBJECT
//

// Panel Object Types
var TYPE_TEXT 					= 1;
var TYPE_LABEL_TEXT 			= 2;
var TYPE_TEXT_EDIT 				= 3;
var TYPE_TEXT_EDIT_READ_ONLY 	= 4;
var TYPE_POPUP 					= 5;
var TYPE_IMG_BUTTON 			= 6;
var TYPE_STD_BUTTON 			= 7;
var TYPE_PHOTO_WITH_FRAME 		= 8;
var TYPE_RADIO_CLUSTER 			= 9;
var TYPE_FILE_IMPORT 			= 10;
var TYPE_TITLE 					= 11;
var TYPE_DIGITS 				= 12;
var TYPE_LINK_TEXT 				= 13;
var TYPE_BOX 					= 14;
var TYPE_TEXT_EDIT_BOX 			= 15;
var TYPE_SHADOW_TEXT 			= 16;
var TYPE_CHECK_BOX 				= 17;
var TYPE_HIDDEN_VALUE 			= 18;
var TYPE_IMAGE 					= 19;
var TYPE_IMG					= 20;
var TYPE_TITLE_BAR				= 21;
var TYPE_BEGIN_FRAME			= 22;
var TYPE_END_FRAME				= 23;

var TYPE_DIV = 50;

var LABEL_VOFFSET = 15;

var mElem;
var mTopMostPanelZIndex = 100;
var mTitleBarHeight = 20;

//---------------------------------------------------------
function PanelObject(objID, objType, top, left, height, width, text, parent, val, name)
	{
	this.objID = objID;
	this.objType = objType;
	this.top = top;
	this.left = left;
	this.height = height;
	this.width = width;
	this.fontSize = 9;
	this.text = text;
	this.options = new Array();
	this.optionCnt = 0;
	this.changeFunc = "DoNothing";
	this.parent = parent;
	this.value = val;
	this.active = true;
	this.name = name;
	this.leftBorder = "double darkblue";
	this.topBorder = "double darkblue";
	this.rightBorder = "double darkblue";
	this.bottomBorder = "double darkblue";
	this.bkgndColor = "black";
	this.bkgndImage = "";
	this.textColor = "dragblack";
	this.shadowColor = "green";
	this.color = "black";
	this.bkColor = "white"
	this.fontWeight = "bold";
	this.fontAlign = "left";
	this.leftOffset = 0;
	this.widthOffset = 0;
	this.cursor = "default";
	this.digitEditCnt = 0;
	this.mouseOver = "DoNothing";
	this.mouseOut = "DoNothing";
	this.butMouseOver = DoNothing;
	this.butMouseOut = DoNothing;
	this.butFontSize = 12;
	this.dragParent = false;
	this.dragSelf = false;
	this.zIndex = 100;
	this.hidden_color = "#cccccc";
	this.mouseOverFuncName = "";
	this.savedHeight;
	this.butColor = "";
	this.imgPath = "";
	this.dragTargetID = "";
	this.postDragFunc = null;
	}
	
//-----------------------------------------------------
function DoNothing()
	{
	}
//-----------------------------------------------------
PanelObject.prototype.SetButtonFontSize = function(butFontSize)
	{
	this.butFontSize = butFontSize;
	}
//-----------------------------------------------------
PanelObject.prototype.SetCursor = function(cursor)
	{
	this.cursor = cursor;
	}
//-----------------------------------------------------
PanelObject.prototype.SetZIndex = function(zIndex)
	{
	this.zIndex = zIndex;
	}
//-----------------------------------------------------
PanelObject.prototype.SetTextAndShadowColor = function(txtColor, shadowColor)
	{
	this.textColor = txtColor;
	this.shadowColor = shadowColor;
	}

//-----------------------------------------------------
PanelObject.prototype.SetPostDragFunc = function(postDragFunc)
	{
	this.postDragFunc = postDragFunc;
	}

//-----------------------------------------------------
PanelObject.prototype.SetImage = function(imgPath)
	{
	this.imgPath = imgPath;
	}
//-----------------------------------------------------
PanelObject.prototype.SetSrc = function(src)
	{
	GetElemByID(this.objID).src = src+'?'+escape(new Date());
	}
	
//-----------------------------------------------------
PanelObject.prototype.SetBorders = function(border)
	{
	this.leftBorder = border;
	this.topBorder = border;
	this.rightBorder = border;
	this.bottomBorder = border;
	}
//-----------------------------------------------------
PanelObject.prototype.SetMouseDown = function(downFunc)
	{
	this.mouseDown = downFunc;
	}
//-----------------------------------------------------
PanelObject.prototype.SetMouseOver = function(overFunc)
	{
	this.mouseOver = overFunc;
	}
	
//-----------------------------------------------------
PanelObject.prototype.SetMouseOut = function(outFunc)
	{
	this.mouseOut = outFunc;
	}
//-----------------------------------------------------
PanelObject.prototype.SetLinkURL = function(url)
	{
	this.linkURL = url;
	}	
//-----------------------------------------------------
PanelObject.prototype.SetButMouseOver = function(overFunc)
	{
	this.butMouseOver = overFunc;
	}
//-----------------------------------------------------
PanelObject.prototype.SetButMouseOut = function(outFunc)
	{
	this.butMouseOut = outFunc;
	}

//-----------------------------------------------------
PanelObject.prototype.SetBackColor = function(bkColor)
	{
	this.bkColor = bkColor;
	}
//-----------------------------------------------------
PanelObject.prototype.SetBkgndImage = function(bkgndImage)
	{
	this.bkgndImage = bkgndImage;
	}
//-----------------------------------------------------
PanelObject.prototype.SetColor = function(color)
	{
	this.color = color;
	}
//-----------------------------------------------------
PanelObject.prototype.SetTextColor = function(color)
	{
	this.textColor = color;
	}

//-----------------------------------------------------
PanelObject.prototype.SetHorizOffsets = function(leftOffset, widthOffset)
	{
	this.leftOffset = leftOffset;
	this.widthOffset = widthOffset;
	}
//-----------------------------------------------------
PanelObject.prototype.SetFontAlign = function(fontAlign)
	{
	this.fontAlign = fontAlign;
	}

//-----------------------------------------------------
PanelObject.prototype.SetFontWeight = function(fontWt)
	{
	this.fontWeight = fontWt;
	}
//-----------------------------------------------------
PanelObject.prototype.SetOnKeyDownFunc = function(onKeyDownFunc)
	{
	this.onKeyDownFunc = onKeyDownFunc;
	}

//-----------------------------------------------------
PanelObject.prototype.GetElem = function()
	{
	return document.getElementById(this.objID);
	}
//-----------------------------------------------------
PanelObject.prototype.SetMouseOverFuncName = function(funcName)
	{
	this.mouseOverFuncName = funcName;
	}

//-----------------------------------------------------
PanelObject.prototype.MakeActive = function()
	{
	this.active = true;
	switch(this.objType)
		{
		case TYPE_TEXT:
		case TYPE_LABEL_TEXT:
		case TYPE_TEXT_EDIT:
		case TYPE_TEXT_EDIT_READ_ONLY:
		case TYPE_TITLE:
		case TYPE_POPUP:
		case TYPE_DIGITS:
		case TYPE_LINK_TEXT:
		case TYPE_BOX:
		case TYPE_TEXT_EDIT_BOX:
		case TYPE_IMAGE:
		case TYPE_IMG:
		case TYPE_SHADOW_TEXT:
		case TYPE_CHECK_BOX:
		case TYPE_HIDDEN_VALUE:
		case TYPE_TITLE_BAR:
		case TYPE_BEGIN_FRAME:
		case TYPE_END_FRAME:
			break;
		
		case TYPE_IMG_BUTTON:
			this.GetElem().src = this.normalImg;
		break;
		}
	}
//-----------------------------------------------------
PanelObject.prototype.MakeInActive = function()
	{
	this.active = false;
	switch(this.objType)
		{
		case TYPE_TEXT:
		case TYPE_LABEL_TEXT:
		case TYPE_TEXT_EDIT:
		case TYPE_TEXT_EDIT_READ_ONLY:
		case TYPE_TITLE:
		case TYPE_POPUP:
		case TYPE_DIGITS:
		case TYPE_LINK_TEXT:
		case TYPE_BOX:
		case TYPE_TEXT_EDIT_BOX:
		case TYPE_SHADOW_TEXT:
		case TYPE_CHECK_BOX:
		case TYPE_HIDDEN_VALUE:
		case TYPE_IMAGE:
		case TYPE_IMG:
		case TYPE_TITLE_BAR:
		case TYPE_BEGIN_FRAME:
		case TYPE_END_FRAME:
			break;
		
		case TYPE_IMG_BUTTON:
			this.GetElem().src = this.inactiveImg;
			break;
		}
	}
//-----------------------------------------------------
PanelObject.prototype.SetText = function(text)
	{
	this.text = text;
	}
//-----------------------------------------------------
PanelObject.prototype.SetTextSize = function(size)
	{
	this.fontSize = size;
	}
//-----------------------------------------------------
PanelObject.prototype.SetTitleText = function(text)
	{
	this.GetElem().value = text;
	this.value = text;
	}

//-----------------------------------------------------
PanelObject.prototype.AddOption = function(option)
	{
	this.options[this.optionCnt++] = option;
	}
//-----------------------------------------------------
PanelObject.prototype.AddOptions = function()
	{
	for (var argCnt = 0; argCnt < arguments.length; argCnt++)
		{
		this.options[this.optionCnt++] = arguments[argCnt];	
		}
	}
//-----------------------------------------------------
PanelObject.prototype.KillOptions = function()
	{
	delete this.options;
	this.options = new Array();
	this.optionCnt = 0;
	}

//-----------------------------------------------------
PanelObject.prototype.MakeFront = function()
	{
	++mTopMostPanelZIndex;
	GetElemByID(this.GetElem().id+"_frame").style.zIndex = mTopMostPanelZIndex;
	}
//-----------------------------------------------------
PanelObject.prototype.LoadFromDB = function(table, colName, doneFunc, doneArg)
	{
	str="TableName="+table+"^ColName="+colName;

	// Make AJAX call -------------------
	var ajax = new AJAX("lib_pages/get_col_data.php", str);
	ajax.doneFunc = doneFunc;
	ajax.doneArg = doneArg;
	ajax.onload = RefreshPopup;
	ajax.object = this;
	ajax.get();
	}
//-----------------------------------------------------
function RefreshPopup(ajax, success)
	{
	if (success)
		{
		var data = ajax.GetRtnStr();
		var rowData = data.split(",");
		for (var row = 0; row < rowData.length; row++)
			{	
			ajax.object.AddOption(rowData[row]);
			}
		ajax.doneFunc(ajax.doneArg);
		}
	delete ajax;
	}

//-----------------------------------------------------
PanelObject.prototype.SetButtonImages = function(normalImg, overImg, downImg, inactiveImg)
	{
	this.normalImg = normalImg;
	this.overImg = overImg;
	this.downImg = downImg;
	this.inactiveImg = inactiveImg;
	}
//-----------------------------------------------------
PanelObject.prototype.SetButClickFunc = function(butClickFunc, arg)
	{
	this.butClickFunc = butClickFunc;
	this.changeArg = arg;
	}
//-----------------------------------------------------
PanelObject.prototype.SetButColor = function(butColor)
	{
	this.butColor = butColor;
	}

//-----------------------------------------------------
PanelObject.prototype.SetChangeFunc = function(changeFunc, changeArg)
	{
	this.changeFunc = changeFunc;
	this.changeArg = changeArg;
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML = function()
	{	
	switch(this.objType)
		{
		case TYPE_TEXT: 
			return this.GetHTML_TEXT(this.fontSize, 0, "");
			
		case TYPE_LABEL_TEXT:
			return this.GetHTML_LABEL_TEXT();
			
		case TYPE_TEXT_EDIT:
			return this.GetHTML_EDIT_TEXT();
		
		case TYPE_TEXT_EDIT_READ_ONLY:
			return this.GetHTML_EDIT_TEXT_READ_ONLY();
		
		case TYPE_TITLE:
			return this.GetHTML_TYPE_TITLE();
			
		case TYPE_POPUP:
			return this.GetHTML_POPUP();
		
		case TYPE_IMG_BUTTON:
			return this.GetHTML_IMG_BUTTON();
		
		case TYPE_STD_BUTTON:
			return this.GetHTML_STD_BUTTON();
			
		case TYPE_PHOTO_WITH_FRAME:
			return this.GetHTML_PHOTO_WITH_FRAME();
			
		case TYPE_RADIO_CLUSTER:
			return this.GetHTML_RADIO_CLUSTER();
			
		case TYPE_FILE_IMPORT:
			return this.GetHTML_FILE_IMPORT();
		
		case TYPE_DIV:
			return this.GetHTML_DIV();
		
		case TYPE_DIGITS:
			return this.GetHTML_DIGITS();
		
		case TYPE_LINK_TEXT:
			return this.GetHTML_LINK_TEXT();
			
		case TYPE_BOX:
			return this.GetHTML_BOX();
			
		case TYPE_TEXT_EDIT_BOX:
			return this.GetHTML_TextEditBox();
			
		case TYPE_SHADOW_TEXT:
			return this.GetHTML_ShadowText();
		
		case TYPE_CHECK_BOX:
			return this.GetHTML_Check_Box();
		
		case TYPE_HIDDEN_VALUE:
			return this.GetHTML_Hidden_Value();
		
		case TYPE_IMAGE:
			return this.GetHTML_Image();
		
		case TYPE_IMG:
			return this.GetHTML_Img();
			
		case TYPE_TITLE_BAR:
			return this.GetHTML_Titlebar();
		
		case TYPE_BEGIN_FRAME:
			return this.GetHTML_BeginFrame();
			
		case TYPE_END_FRAME:
			return this.GetHTML_EndFrame();
			
		}
	}
//-----------------------------------------------------
PanelObject.prototype.GetHTML_TEXT = function(fontSize, hOffset, idPrefix)
	{
	left = parseInt(this.left) + hOffset;
	return "<div id='"+idPrefix+this.objID+"'; style='z-index:200; position: absolute; " +
		   "cursor:"+this.cursor+"; " +
		   "top:"+parseInt(this.top)+"; left:"+parseInt(left)+";" +
		   "width:"+parseInt(this.width)+"; height:"+parseInt(this.height)+";"+
		   "font-weight:"+this.fontWeight+"; "+
		   "color:"+this.textColor+"; " +
		   "text-align: "+this.fontAlign+"; '>" +
		   "<span style='font-size: "+fontSize+"pt'>"+this.text+"</span></div>";
	}
//-----------------------------------------------------
PanelObject.prototype.GetHTML_EDIT_TEXT = function()
	{
	var top = parseInt(this.top) + LABEL_VOFFSET;
	var left = parseInt(this.left) + this.leftOffset;
	var width = parseInt(this.width) + this.widthOffset;
	var s = this.GetHTML_TEXT(10, 3,"lbl_") +
		   "<input id='"+this.objID+"'; onKeyUp='"+this.changeFunc+"(this)'; "+
//		   "onKeyDown='"+this.onKeyDownFunc+"(this)'; " +
		   "value = '"+this.value+"'"+
		   "style='z-index:200; font-size: "+this.fontSize+"; "+
		   "cursor:text;"+					
		   "font-weight:"+this.fontWeight+"; "+
		   "text-align: "+this.fontAlign+"; "+
		   "; position: absolute; " +
		   "color: "+this.color+"; " +
		   "background-color: "+this.bkColor+"; " +
		   "top:"+top+"; left:"+left+"; " +
		   "width:"+width+"; height:"+this.height+";'>";
	return s;
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_EDIT_TEXT_READ_ONLY = function()
	{
	var top = this.top + LABEL_VOFFSET;

	var s = this.GetHTML_TEXT(this.fontSize-1, 3,"lbl_") +
		   "<input id='"+this.objID+"' onKeyUp='"+this.changeFunc+"(this)'; "+
		   "value = '"+this.value+"'; "+
		   "style='z-index:200; font-size:"+this.fontSize+"; position: absolute; " +
		   "or:"+this.cursor+"; " +
		   "color: "+this.color+"; " +
		   "font-weight:"+this.fontWeight+"; "+
		   "text-align: "+this.fontAlign+"; "+
		   "background-color: "+this.bkColor+"; " +
		   "top:"+top+"px; left:"+this.left+"px; " +
		   "width:"+this.width+"px; height:"+this.height+"px;' READONLY>";
	return s;
	}
//-----------------------------------------------------
PanelObject.prototype.GetHTML_TYPE_TITLE = function()
	{
	var s = "<input id='"+this.objID+"' value='"+this.text+"'; "+
		   "style='z-index:200; font-size: "+this.fontSize+"; position: absolute; " +
		   "text-align: center; vertical-align: middle; "+
		   "top:"+this.top+"px; left:"+this.left+"px; " +
		   "width:"+this.width+"px; height:"+this.height+"px; "+
		   "background-color: transparent; "+
		   "color: "+this.color+"; "+
		   "font-weight:"+this.fontWeight+"; "+
		   "border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; "+
		   "READONLY'>";
	return s;
	}
	
//-----------------------------------------------------
PanelObject.prototype.GetHTML_LABEL_TEXT = function()
	{
	var s = this.GetHTML_TEXT(this.fontSize-1, 3,"lbl_") + "; ";
	var oldTop = this.top;

	this.top = this.top + LABEL_VOFFSET;
	var save = this.text;
	this.text = this.value;
	s += this.GetHTML_TEXT(this.fontSize-1, 3, "");
	this.text = save;
	this.top = oldTop;
	return s;
	}
	
//-----------------------------------------------------
PanelObject.prototype.GetDigitDiv = function(digitNum)
	{
	return GetElemByID(this.objID+digitNum);
	}

//-----------------------------------------------------
PanelObject.prototype.GetDigit = function(digitNum)
	{
	return this.GetDigitDiv(digitNum).innerHTML;
	}
//-----------------------------------------------------
PanelObject.prototype.SetDigit = function(digitNum, value)
	{
	this.GetDigitDiv(digitNum).innerHTML = value;
	}
//-----------------------------------------------------
PanelObject.prototype.GetDigitsValue = function()
	{
	return this.GetDigit(1)+this.GetDigit(2)+this.GetDigit(3)+this.GetDigit(4);
	}
//-----------------------------------------------------
PanelObject.prototype.SetDigitsValue = function(s)
	{
	if (s.length == 4)
		{
		if (parseInt(s) >= 0) s = " "+s;
		}
	if (s.length != 5) s = " 0.00";
	this.SetDigit(1, s.charAt(0));
	this.SetDigit(2, s.charAt(1)+".");
	this.SetDigit(3, s.charAt(3));
	this.SetDigit(4, s.charAt(4));
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_DIGITS = function()
	{
	var s = this.GetHTML_EDIT_TEXT_READ_ONLY();
	var boxLeft = this.left+3;
	var top =this.top + 16;
	var height = this.height - 6;
	var color = "#000000";	// "transparent";	//#000000";
	var border = "single darkblue";
	var digit;
	var digits;
	
	// ------- Create the 4 Divs representing 4 changeable characters 
	digits = this.value;

	for (var cnt = 1; cnt <= 4; ++cnt)
		{
		switch(cnt)
			{
			case 1:
				boxWidth = 12;  
				digit = digits.substr(0,1);
				break;
			case 2:
				boxWidth = 21;  
				digit = digits.substr(1,1)+".";	
				break;
			case 3:
				boxWidth = 21;  
				digit = digits.substr(3,1);	
				break;
			case 4:
				boxLeft -= 4;
				boxWidth = 18;  
				digit = digits.substr(4,1);
				break;
			}		
		s += "<div id = "+this.objID+cnt+" "+
	   "onMouseOver='"+this.mouseOver+"(this)' "+
	   "onMouseOut='"+this.mouseOut+"(this)' " +
		"style='z-index: 380; position: absolute;"+
		"top: "+top+"px; "+ 
		"left: "+boxLeft+"px; "+
		"width: "+boxWidth+"px; "+
		"height: "+height+"px;"+ 
		"border-left:"+border+";"+
		"border-top:"+border+";"+
		"border-bottom:"+border+";"+
		"border-right:"+border+";"+
		"background-color: "+color+"; "+
		"color: #00ff00; "+
		"font-weight:"+this.fontWeight+"; "+
		"text-align: "+this.fontAlign+"; "+
		"font-size: "+this.fontSize+"; "+
		"cursor: hand; "+
		"'>"+digit+"</div>";
		
		boxLeft += boxWidth;
		}
	return s;
	}
	
//-----------------------------------------------------
PanelObject.prototype.SetValue = function(val)
	{
	this.value = val;
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_POPUP = function()
	{
	var opts = "";
	var sel;
	
	if (this.optionCnt > 0)
		{
		for (var optCnt = 0; optCnt < this.optionCnt; optCnt++)
			{
				var opt = this.options[optCnt];
				if (this.value)
					{
					if (opt == this.value) sel = " selected='selected' ";
					else sel = "";
					}
				else	
					{
					if (optCnt == 0) sel = " selected='selected' ";
					else sel = "";
					}
				
				opts=opts+"<option "+sel+"value='"+opt+"'>"+opt+"</option>";
			}

		var top = parseInt(this.top) + parseInt(LABEL_VOFFSET);

		var s = this.GetHTML_TEXT(this.fontSize-1, 3, "lbl_") + 
			"<select id='"+this.objID+"'; onchange='"+this.changeFunc+"(this)'; "+
				"style='z-index: 100; position: absolute; font-size: "+this.fontSize+"pt; "+
						"top: "+top+"px; "+ 
						"left: "+this.left+"px; "+
						"width: "+this.width+"px; "+
						"height: "+this.height+"px;>"+
			"<option value = ''></option>"+opts+
			"</select>";
		return s;
		}
	return "";
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_RADIO_CLUSTER = function()
	{
	var opts = "";
	var chk;
	if (this.optionCnt > 0)
		{
		for (var optCnt = 0; optCnt < this.optionCnt; optCnt++)
			{
			var opt = this.options[optCnt];
			if (this.value == opt) chk = " CHECKED ";
			else chk = "";
				
			var val = this.options[optCnt];
			opts = opts + "<INPUT TYPE = 'radio' NAME='"+this.name+"' VALUE='"+val+"' "+
			chk+" onClick='"+this.changeFunc+"(this)'>"+val+"\ \ \ \ ";
			}

		var s = "<FORM id = '"+this.objID+"' name = '"+this.name+"_radios;' "+ 
				"style='z-index:100; position:absolute; top:"+this.top+"px; left:"+this.left+"px; "+
				"font-size: 12;'>"+
				opts + "</FORM>";
		return s;
		}
	return "";
 }
 
 //-----------------------------------------------------
PanelObject.prototype.GetHTML_FILE_IMPORT = function()
	{
	var s = "<div id='lbl_"+this.objID+"'; style='z-index:200; position: absolute; " +
		   "top:"+this.top+"px; left:"+left+"px; " +
		   "width:"+this.width+"px; height:"+this.height+"px;'>" +
		   "<?php " +
			"$uploadDirectory = 'uploads'; " +
			"require_once('lib_players/ajax_uploader.php');" +
			"$ajaxFileUploader = new AjaxFileuploader($uploadDirectory);" +
			"echo $ajaxFileUploader->showFileUploader('id1');" +
		"?></div>";
	return s;
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_IMG_BUTTON = function()
	{
	s= "<img id='"+this.objID+"'; "+
		   "src='"+this.normalImg+"'; "+
		   "onMouseOver='But_OnMouseOver(this)'; "+
		   "onMouseOut='But_OnMouseOut(this)'; "+
		   "onMouseDown='But_OnMouseDown(this)'; "+
		   "onMouseUp='But_OnMouseUp(this)'; "+
		   "style='z-index:200; font-size: "+this.fontSize+"; position: absolute; " +
		    "cursor: hand; "+
		   "top:"+this.top+"px; left:"+this.left+"px;'>" +	
		   	   
		   "<div id='invis_"+this.objID+"'; "+
		   "onMouseOver='InvisBut_OnMouseOver(this.id)'; "+
		   "onMouseOut='InvisBut_OnMouseOut(this.id)'; "+
		   "style='z-index: 199; position: absolute;"+
		   "cursor: hand; "+
		   "top:"+this.top+"px; left:"+this.left+"px; width:19; height: 19; background-color: "+this.hidden_color+"'>"+
		   "</div>";
	return s;
	}
//--------------------------------------------------------------------
function InvisBut_OnMouseOver(id)
	{
	GetElemByID(id.substr(6)).obj.Show();
	}

//-----------------------------------------------------
function InvisBut_OnMouseOut(id)
	{
	GetElemByID(id.substr(6)).obj.Hide();
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_PHOTO_WITH_FRAME = function()
	{
	var s = "<div id='"+this.objID+"_frame'; style='z-index: 80; position: absolute;"+
						"top: "+this.top+"px; "+ 
						"left: "+this.left+"px; "+
						"width: "+this.width+"px; "+
						"height: "+this.height+"px;"+
						"border-left:"+this.leftBorder+";"+
						"border-top:"+this.topBorder+";"+
						"border-bottom:"+this.bottomBorder+";"+
						"border-right:"+this.rightBorder+";"+
						"background-color:"+this.bkgndColor+
						"'>"+
				"<img style='z-index: 200; position: absolute; left:0; top: 0'; "+
				"id = '"+this.objID+"'; src = '../photos/aa_initializing.jpg'; " +
				"alt=''; onload='CenterPict(this)'; /></div>";
	return s;
  	}
//-----------------------------------------------------
PanelObject.prototype.GetHTML_Image = function()
	{
	var dragStr = this.GetMouseDownDragStr();
	var mouseOverStr = this.GetMouseOverStr();
	var cursStr = "";
	if (dragStr !="") cursStr = " cursor: hand; ";
	
	var s = "<div id='"+this.objID+"_frame'; "+dragStr+mouseOverStr+" style='z-index: 80; position: absolute;"+
						"top: "+this.top+"px; "+ 
						"left: "+this.left+"px; "+
						"width: "+this.width+"px; "+
						"height: "+this.height+"px;"+
						cursStr+
						"'>"+
				"<img style='z-index: 200; position: absolute; left:0; top: 0'; "+
				"id = '"+this.objID+"'; src = '../photos/aa_initializing.jpg'; " +
				"alt=''; onload='CenterPict(this)'; /></div>";
	return s;
	}
//-----------------------------------------------------
PanelObject.prototype.GetHTML_Img = function()
	{
	var dragStr = this.GetMouseDownDragStr();

	var mouseOverStr = this.GetMouseOverStr();
	var cursStr = "";
	if (dragStr !="") cursStr = " cursor: hand; ";
	
	var s = "<img id='"+this.objID+"'; src='"+this.imgPath+"';"+
						dragStr+mouseOverStr+
						" style='z-index: 80; position: absolute;"+
						"top: "+this.top+"px; "+ 
						"left: "+this.left+"px; "+
						cursStr+
						"'/>";
		return s;
	}

//-----------------------------------------------------
PanelObject.prototype.SetDragTargetID = function(id)
	{
	this.dragTargetID = id;
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_Titlebar = function()
	{
	this.left = 0;
	this.top = 0;
	this.width = this.parent.width-2;
	this.height = mTitleBarHeight;
	this.SetBorders("");
	this.bottomBorder = "1 inset #999999";
	this.SetZIndex(5000);

	var s = GetTextHTML(this.text,1,0,this.height, this.width,12, "bold", "#111155", "center", "middle");
	var butBoxSize = this.height-1;
 	var closeBut = new PanelObject(this.objID+"_closebut", TYPE_STD_BUTTON, 
								0, this.left+this.width-butBoxSize, butBoxSize, butBoxSize, "x", this, "", "");
	closeBut.changeFunc = "TB_CloseBoxHit"
	closeBut.parent = this.parent;
	var butHTML = closeBut.GetHTML_STD_BUTTON();
	delete closeBut;

	this.SetDragTargetID(this.parent.div.id);
	s= this.BeginDIV() + s + butHTML + this.EndDIV();
//zzzzzzzzzzzzzzzz
	return s;
	}
//-----------------------------------------------------
PanelObject.prototype.GetHTML_STD_BUTTON = function()
	{
	var panelID = "";

	if (this.parent)
		{
		if (this.parent.div)	
			{
			panelID = this.parent.div.id;
			}
		}
	var butColor;
	if (this.butColor == "") butColor = "";
	else butColor = "background-color: "+this.butColor+"; ";
	var s = "<input id = '"+this.objID+"'; type='button'; value='"+this.text+"' "+
						"onclick='"+this.changeFunc+"(this, event,\""+panelID+"\")'; "+
						"onmousedown='MouseDownInButton(this, event)'; "+
						"style = 'z-index:200; position: absolute;"+
						butColor +
						"top: "+this.top+"px; "+ 
						"left: "+this.left+"px; "+
						"cursor: hand; ";
	if (this.width > 0) s = s + "width: "+this.width+"px; ";
	if (this.height > 0) s = s + "height: "+this.height+"px; ";
	s = s + " font-size:"+this.butFontSize;
	s = s + "'>";
	return s;
	}

//-----------------------------------------------------
PanelObject.prototype.GetMouseDownDragStr = function()
	{
	if (this.dragTargetID != "")
		{
		return " onMouseDown=Drag_Begin(event,'"+this.dragTargetID+"'); ";  	
		}
	return "";
	}
//-----------------------------------------------------
PanelObject.prototype.GetMouseOverStr = function()
	{
	if (this.mouseOverFuncName != "")
		{
		return " onMouseOver="+this.mouseOverFuncName+"(this); ";	
		}
	return "";
	}

//-----------------------------------------------------
PanelObject.prototype.BeginDIV = function()
	{
	var dragStr = this.GetMouseDownDragStr();
	var cursStr = "";
	
	if (dragStr !="") cursStr = "cursor: move; ";
	
	return "<div id='"+this.objID+"'; "+dragStr+
						"style='z-index:"+this.zIndex+"; position: absolute; "+
						"top: "+this.top+"px; "+ 
						"left: "+this.left+"px; "+
						"width: "+this.width+"px; "+
						"height: "+this.height+"px;"+
						"border-left:"+this.leftBorder+";"+
						"border-top:"+this.topBorder+";"+
						"border-bottom:"+this.bottomBorder+";"+
						"border-right:"+this.rightBorder+";"+
						"background-color:"+this.bkgndColor+";"+
						"background-image: url("+this.bkgndImage+");"+
						cursStr+"'>";
	}
//-----------------------------------------------------
PanelObject.prototype.EndDIV = function()
	{
	return "</div>";
	}
//-----------------------------------------------------
PanelObject.prototype.GetHTML_DIV = function()
	{
	return this.BeginDIV() + this.EndDIV();
	}		

//-------------------------------
function But_OnMouseOver(elem)
	{
	elem.src = elem.obj.overImg;
	elem.obj.butMouseOver(elem.id);
	}
//-------------------------------
function But_OnMouseOut(elem)
	{
	elem.src = elem.obj.normalImg;
	elem.obj.butMouseOut(elem.id);
	}
//-------------------------------
function But_OnMouseDown(elem)
	{
	elem.src = elem.obj.downImg;
	}
//-------------------------------
function But_OnMouseUp(elem)
	{
	elem.src = elem.obj.normalImg;
	if (elem.obj.butClickFunc)
		{
		elem.obj.butClickFunc(elem.obj);
		}
	}
//-------------------------------------------------------------------
PanelObject.prototype.GetSelectIndex = function(popupElem)
	{
	var total = popupElem.options.length;
	for (idx = 0; idx < total; idx++)
		{
		if (popupElem.options[idx].selected == true) return idx;
		}
	return -1;
	}

//-------------------------------------------------------------------
PanelObject.prototype.SetOptionByIndex = function(popupElem, index)
	{
	popupElem.options[index].selected = true;
	}
//-------------------------------------------------------------------
PanelObject.prototype.SetOptionFirst = function(popupElem)
	{
	this.SetOptionByIndex(popupElem, 0);
	return popupElem.options[0].value;
	}
//-------------------------------------------------------------------
PanelObject.prototype.SetOptionPrev = function(popupElem)
	{
	var currIdx = this.GetSelectIndex(popupElem);
	if (currIdx > 0)
		{
		popupElem.options[currIdx-1].selected = true;
		return popupElem.options[currIdx-1].value;
		}
	return "";
	}
//-------------------------------------------------------------------
PanelObject.prototype.SetOptionNext = function(popupElem)
	{
	var currIdx = this.GetSelectIndex(popupElem);
	if (currIdx < (popupElem.options.length-1))
		{
		popupElem.options[currIdx+1].selected = true;
		return popupElem.options[currIdx+1].value;
		}
	return "";
	}
//-------------------------------------------------------------------
PanelObject.prototype.SetOptionLast = function(popupElem)
	{
	this.SetOptionByIndex(popupElem, popupElem.options.length-1);
	return popupElem.options[popupElem.options.length-1].value;
	}

//-------------------------------------------------------------------
function CenterPict(elem)
	{
	var frame = elem.parentNode;

	var frameW = parseInt(frame.style.width)
	var frameH = parseInt(frame.style.height)
	var img = new Image();

	img.src = elem.src;
	var imgW = img.width;
	var imgH = img.height;
	elem.style.left = ((frameW - imgW)/2)-4;
	elem.style.top = ((frameH - imgH)/2)-4;

	elem.style.width = imgW;
	elem.style.height = imgH;
	}

//-------------------------------------------------------------------
PanelObject.prototype.SetDblLeftButImages = function(func, destObj)
	{
	this.SetButtonImages(	"images_ui/buttons/but_left_dbl_normal.jpg",
						 	"images_ui/buttons/but_left_dbl_mouse_over.jpg",
							"images_ui/buttons/but_left_dbl_mouse_down.jpg",
							"images_ui/buttons/but_left_dbl_inactive.jpg");
	this.SetButClickFunc(func, destObj);
	}
//-------------------------------------------------------------------
PanelObject.prototype.SetLeftButImages = function(func, destObj)
	{
	this.SetButtonImages(	"images_ui/buttons/but_left_normal.jpg",
						 	"images_ui/buttons/but_left_mouse_over.jpg",
							"images_ui/buttons/but_left_mouse_down.jpg",
							"images_ui/buttons/but_left_inactive.jpg");
	this.SetButClickFunc(func, destObj);
	}
//-------------------------------------------------------------------
PanelObject.prototype.SetRtButImages = function(func, destObj)
	{
	this.SetButtonImages(	"images_ui/buttons/but_rt_normal.jpg",
						 	"images_ui/buttons/but_rt_mouse_over.jpg",
							"images_ui/buttons/but_rt_mouse_down.jpg",
							"images_ui/buttons/but_rt_inactive.jpg");
	this.SetButClickFunc(func, destObj);
	}
//-------------------------------------------------------------------
PanelObject.prototype.SetDblRtButImages = function(func, destObj)
	{
	this.SetButtonImages(	"images_ui/buttons/but_rt_dbl_normal.jpg",
						 	"images_ui/buttons/but_rt_dbl_mouse_over.jpg",
							"images_ui/buttons/but_rt_dbl_mouse_down.jpg",
							"images_ui/buttons/but_rt_dbl_inactive.jpg");
	this.SetButClickFunc(func, destObj);
	}
//-----------------------------------------------------
PanelObject.prototype.Show = function()
	{
	this.GetElem().style.display = "inline";
	}
//-----------------------------------------------------
PanelObject.prototype.Hide = function()
	{
	this.GetElem().style.display = "none";
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_LINK_TEXT = function()
	{
	return "<div id='"+this.objID+"'; style='z-index:200; position: absolute; " +
		   "cursor:"+this.cursor+"; " +
		   "top:"+this.top+"px; left:"+this.left+"px; " +
		   "width:"+this.width+"px; height:"+this.height+"px;"+
		   "font-weight:"+this.fontWeight+"; "+
		   "color:"+this.textColor+"; " +
		   "text-align: "+this.fontAlign+"; '>" +
		   "<span style='font-size: "+this.fontSize+"pt'>"+
			"<a href ="+this.linkURL+">"+this.text+"</a>"
			+"</span></div>";
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_BOX = function()
	{
	s= "<div style='z-index:51; position: absolute; " +
		   "cursor:"+this.cursor+"; " +
		   "top:"+this.top+"px; left:"+this.left+"px; " +
		   "width:"+this.width+"px; height:"+this.height+"px;"+
		   "background-color: "+this.color+";' ></div>";
	return s;
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_TextEditBox = function()
	{
	return "<textarea id='"+this.objID+"'; " +
	"onMouseDown='TextEdit_OnMouseDown(this)'; "+
		"style='z-index: 1000; position: absolute; " +
    	"top:"+parseInt(this.top)+"; " +
		"left:"+parseInt(this.left)+"; " +
		"height:"+parseInt(this.height)+"; " +
		"width:"+parseInt(this.width)+"; " +
		"cursor:text; " +
		"'></textarea>";
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------
function TextEdit_OnMouseDown(elem)
	{
	elem.focus();
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_ShadowText = function()
	{
	var savedColor = this.textColor;
	this.textColor = this.shadowColor;
	var s = this.GetHTML_TEXT(this.fontSize, 0, "");
	this.textColor = savedColor;
	this.left += 1;
	this.top += 1;
	return s + this.GetHTML_TEXT(this.fontSize, 0, "");
	}
//-----------------------------------------------------
PanelObject.prototype.GetHTML_Check_Box = function()
	{
	if (this.value == true) $chkTxt = " checked='CHECKED' ";
	else $chkTxt = "";
	if (this.changeFunc != "") s = " onchange='"+this.changeFunc+"(this)'; "; 
	s = "<input id ='"+this.objID+"'; type='checkbox'; "+s+$chkTxt+"style='z-index: 100; position: absolute; left:"+this.left+
		"; top:"+this.top+"' />";
	// this.name should be text next to checkbox
	return s;
	}
//-----------------------------------------------------
PanelObject.prototype.GetHTML_BeginFrame = function()
	{
	s= "<div style='z-index:51; position: absolute; " +
		   "top:"+this.top+"px; left:"+this.left+"px; " +
		   "width:"+this.width+"px; height:"+this.height+"px;"+
//		   "border-top: thin dashed;"+
//		   "border-left: thin dashed;"+
//		   "border-bottom: thin dashed;"+
//		   "border-right: thin dashed;"+
		   "' >";
	return s;
	}
//-----------------------------------------------------
PanelObject.prototype.GetHTML_EndFrame = function()
	{
	return "</div>";
	}

//-----------------------------------------------------
PanelObject.prototype.GetHTML_Hidden_Value = function()
	{
	return "<input id="+this.objID+" type=hidden  value='' />";
	}
	
//------------------------------------------------------------------------------------
function GetTextHTML(text,top,left,height,width,fontSize, fontWt, color, hAlign, vAlign)
	{
	return 	"<div style='z-index:5000; position:absolute; "+
			"top:"+top+"; left:"+left+";"+
			"height:"+height+"; width:"+width+";"+
		   	"font-size:"+fontSize+"; "+
			"text-align:"+hAlign+"; vertical-align:"+vAlign+";"+
			"font-weight:"+fontWt+"; color:"+color+"; '>"+text+"</div>";
	}


//------------------------------------------------------------------------------------
function TB_CloseBoxHit(elem, event, panel_id)
	{
	var panel = GetElemByID(panel_id);
	if (parseInt(panel.style.height) == (mTitleBarHeight+1))
		{
			panel.style.height = panel.savedHeight;	
		}
	else
		{
		panel.savedHeight = panel.style.height;
		panel.style.height = mTitleBarHeight+1;
		}
	}
//------------------------------------------------------------------------------------
function MouseDownInButton(elem, event)
	{
	event.cancelBubble = true;
	}

/*
//------------------------------------------------------------------------------------
function SetZIndexOfAllPanels(zIndex)
	{
	var divs = document.getElementsByTagName('div');
	for (var idx = 0; idx < divs.length; idx++) 
		{	
		var div = divs[i];
		if (div.className == "panel")
			{
			div.zIndex = zIndex;
			}
		}
	}
*/

