
function Viewport(){}
Viewport.getElementBoundingRect=function(element)
{var rect={x:0,y:0,width:element.offsetWidth,height:element.offsetHeight};while(element)
{rect.x+=element.offsetLeft;rect.y+=element.offsetTop;element=element.offsetParent;}
return rect;};Viewport.getRect=function()
{var dimensions={x:0,y:0,height:0,width:0};if(window.innerHeight)
{dimensions.height=window.innerHeight;dimensions.width=window.innerWidth;dimensions.x=window.pageXOffset;dimensions.y=window.pageYOffset;}
else if(document.documentElement&&document.documentElement.clientHeight)
{dimensions.height=document.documentElement.clientHeight;dimensions.width=document.documentElement.clientWidth;dimensions.x=document.documentElement.scrollLeft;dimensions.y=document.documentElement.scrollTop;}
else if(document.body)
{dimensions.height=document.body.clientHeight;dimensions.width=document.body.clientWidth;dimensions.x=document.body.scrollLeft;dimensions.y=document.body.scrollTop;}
return dimensions;};Viewport.getSourceFromEvent=function(arguments)
{var source=null;var event=null;if(arguments.length==1)
{event=arguments[0];source=arguments[0].currentTarget;}
else
{event=window.event;source=window.event.srcElement;}
return source;};function Modal(index,parms,func_ok_onclick,func_cancel_onclick)
{if((Modal.caller!=Modal.CreateInstance)&&(Modal.caller!=Confirm)&&(Modal.caller!=undefined))
{throw'This is a private function: '+Modal.caller;}
this.__classname='Modal';this._type=Modal.POPUP;this._index=index;this._css=null;this._css_title=null;this._css_message=null;this._css_pp=null;this._css_ok_button=null;this._css_cancel_button=null;this._ok_caption='Ok';this._ok_presser=null;this._cancel_caption='Cancel';this._panel_bgcolor='#dfdfdf';this._dialog_width='300px';this._dialog_border='2px solid black';this._dialog_bgcolor='#fff';this._img_url_icon=null;this._img_url_close=null;this._is_visible=false;this._arr_extra_controls=new Array();this._panel=null;this._dialog=null;this._btn_ok=null;this._div_content=null;this._p_buttons=null;this._lbl_message=null;this._lbl_caption=null;this._func_ok_onclick=func_ok_onclick;this._func_cancel_onclick=func_cancel_onclick;this._custom_data=null;if(!parms||typeof(parms)!="object")
return;var legit_params=new Array('css','css_title','css_message','css_pp','css_ok_button','css_cancel_button','ok_caption','cancel_caption','panel_bgcolor','dialog_width','dialog_border','dialog_bgcolor','img_url_icon','img_url_close');for(var i=0;i<legit_params.length;i++)
{if(parms[legit_params[i]])
{this['_'+legit_params[i]]=parms[legit_params[i]];}}}
Modal.CreateInstance=function(type,parms,func_ok_onclick,func_cancel_onclick)
{if(type!=Modal.POPUP&&type!=Modal.CONFIRM&&type!=Modal.INPUT)
throw'Only Modal.POPUP, Modal.CONFIRM, and Modal.INPUT are allowed for Modal, but you asked for type '+type;var s_parms=null;if(typeof(parms)=="undefined"||!parms)
s_parms="undefined";else
s_parms=parms.ConvertToString();s_parms+='-'+type+func_ok_onclick+func_cancel_onclick;s_parms=str_md5(s_parms);var index=null;if(!Modal._obj_params.hasOwnProperty(s_parms))
{index=Modal._obj_params.count;Modal._obj_params[s_parms]=index;Modal._obj_params.count++;switch(type)
{case Modal.POPUP:Modal._arr_instances[index]=new Modal(index,parms,func_ok_onclick);break;case Modal.CONFIRM:Modal._arr_instances[index]=new Confirm(index,parms,func_ok_onclick,func_cancel_onclick);break;case Modal.INPUT:Modal._arr_instances[index]=new Input(index,parms,func_ok_onclick,func_cancel_onclick);break;default:throw"Error trying to create an undefined Modal dialog box of "+type;}}
else
{index=Modal._obj_params[s_parms];}
return Modal._arr_instances[index];};Modal.GetInstance=function(index)
{return Modal._arr_instances[index];};Modal.prototype.IsVisible=function()
{return this._is_visible;}
Modal.IsAnyShowing=function()
{return Modal._are_any_instances_showing;};Modal.IsVisible=function()
{return this._is_visible;}
Modal.prototype.AddExtraControl=function(ctrl)
{if(this._arr_extra_controls[ctrl.id])
return;this._arr_extra_controls[ctrl.id]=ctrl;this._dialog.insertBefore(ctrl,this._p_buttons);}
Modal.prototype.Show=function(caption,message)
{if(Modal._are_any_instances_showing)
{Modal._modals_in_waiting.push(new Array(this,caption,message));return false;}
Modal._are_any_instances_showing=true;if(!this._dialog)
this._Setup();this._lbl_caption.innerHTML=caption;this._lbl_message.innerHTML=message;this._lbl_message.style.overflow='auto'
var rectBounding=Viewport.getElementBoundingRect(this._dialog);var rectViewport=Viewport.getRect();if(rectBounding.height>rectViewport.height)
{this._lbl_message.style.height=(rectViewport.height-200)+'px';rectBounding=Viewport.getElementBoundingRect(this._dialog);}
var left=(rectViewport.width-rectBounding.width)/2+rectViewport.x;var top=(rectViewport.height-rectBounding.height)/2+rectViewport.y;this._dialog.style.left=left+'px';this._dialog.style.top=top+'px';var rectBody=Viewport.getElementBoundingRect(document.body);if(document.body.offsetHeight>rectViewport.height)
this._panel.style.height=(document.body.offsetHeight+0)+'px';else
this._panel.style.height=rectViewport.height+'px';this._panel.style.top='0px';this._panel.style.visibility='visible';if(Modal._static_selects_and_iframes)
{alert("how did static selects become not null?");alert(Modal._static_selects_and_iframes);throw"Somehow Modal._static_selects_and_iframes is not null";}
Modal._static_selects_and_iframes=new Array();var arr_controls=new Array('select','iframe');for(var i=0;i<arr_controls.length;i++)
{var controls=document.getElementsByTagName(arr_controls[i]);for(var j=0;j<controls.length;j++)
{if(controls[j].style.visibility!='hidden'&&controls[j].style.display!='none')
{controls[j].style.visibility='hidden';Modal._static_selects_and_iframes.push(controls[j]);}}}
this._is_visible=true;this._dialog.style.visibility='visible';this._ok_presser.focus();return true;};Modal.prototype.Hide=function()
{if(Modal._static_selects_and_iframes)
{for(var i=0;i<Modal._static_selects_and_iframes.length;i++)
{Modal._static_selects_and_iframes[i].style.visibility='';}}
Modal._static_selects_and_iframes=null;this._is_visible=false;this._panel.style.visibility='hidden';this._dialog.style.visibility='hidden'
Modal._are_any_instances_showing=false;var waiting_modal=Modal._modals_in_waiting.pop();if(waiting_modal)
waiting_modal[0].Show(waiting_modal[1],waiting_modal[2]);};Modal.prototype.SetCustomData=function(obj)
{this._custom_data=obj;};Modal.prototype.GetCustomData=function()
{return this._custom_data;};Modal.prototype.toString=function()
{return"Modal object";};Modal.prototype._Setup=function()
{var firstForm=document.forms[0];this._panel=document.createElement('div');this._panel.onclick=this._panel.onkeypress=function(){if(arguments.length==1)arguments[0].cancelBubble=true;else window.event.cancelBubble=true;};this._panel.id='Modal_panel_'+this._index;this._panel.style.position='absolute';this._panel.style.width='100%';this._panel.style.height='100%';this._panel.style.top='0px';this._panel.style.left='0px';this._panel.style.backgroundColor=this._panel_bgcolor;this._panel.style.visibility='hidden';this._panel.style.opacity=(.5);this._panel.style.MozOpacity=(.5);this._panel.style.KhtmlOpacity=(.5);this._panel.style.filter="alpha(opacity="+50+")";document.body.appendChild(this._panel);this._dialog=document.createElement('div');this._dialog.onclick=this._dialog.onkeypress=function(){if(arguments.length==1)arguments[0].cancelBubble=true;else window.event.cancelBubble=true;};this._dialog.style.position='absolute';this._dialog.style.top='0px';this._dialog.style.left='0px';this._dialog.style.visibility='hidden';if(this._css)
this._dialog.className=this._css;else
{this._dialog.style.width=this._dialog_width;this._dialog.style.border=this._dialog_border;this._dialog.style.backgroundColor=this._dialog_bgcolor;}
document.body.appendChild(this._dialog);this._div_content=document.createElement('div');if(this._css_title)
this._div_content.className=this._css_title;else
{this._div_content.style.border='1px solid black';this._div_content.style.color='#ffe';this._div_content.style.background='#859F9F';}
this._dialog.appendChild(this._div_content);if(this._img_url_icon)
{var img=document.createElement('img');img.setAttribute('src',this._img_url_icon);img.style.verticalAlign='middle';this._div_content.appendChild(img);}
var textNode=document.createTextNode('  ');this._div_content.appendChild(textNode);this._lbl_caption=document.createElement('span');this._div_content.appendChild(this._lbl_caption);this._lbl_message=document.createElement('div');if(this._css_message)
{this._lbl_message.className=this._css_message;}
else
{this._lbl_message.style.padding='15px';}
this._dialog.appendChild(this._lbl_message);this._p_buttons=document.createElement('p');if(this._css_pp)
{this._p_buttons.className=this._css_pp}
else
{this._p_buttons.style.textAlign='center';this._p_buttons.style.paddingBottom='10px';}
this._dialog.appendChild(this._p_buttons);this._btn_ok=document.createElement('input');this._btn_ok.id='Modal_btn_ok_'+this._index;this._btn_ok.name='Modal_btn_ok_'+this._index;this._btn_ok.type='button';this._btn_ok.value=this._ok_caption;this._btn_ok.className=this._css_ok_button;this._btn_ok.setAttribute('index',this._index);if(this._css_ok_button)
this._btn_ok.className=this._css_ok_button;this._btn_ok.onclick=function()
{var source=null;var event=null;if(arguments.length==1)
{event=arguments[0];source=arguments[0].currentTarget;}
else
{event=window.event;source=window.event.srcElement;}
var dialog=Modal.GetInstance(source.getAttribute('index'));dialog.Hide();if(dialog._func_ok_onclick)
dialog._func_ok_onclick(event);}
this._p_buttons.appendChild(this._btn_ok);this._ok_presser=document.createElement('input');this._ok_presser.type='text';this._ok_presser.style.position='absolute';this._ok_presser.style.left='-900px';this._ok_presser.setAttribute('btn_ok_id',this._btn_ok.id);this._ok_presser.onkeypress=function(e){var key=e?e.which:window.event.keyCode;if(key==13)document.getElementById(this.getAttribute('btn_ok_id')).click();};this._dialog.appendChild(this._ok_presser);};Modal.POPUP=1;Modal.CONFIRM=2;Modal.INPUT=3;Modal._obj_params=new Object();Modal._obj_params.count=0;Modal._arr_instances=new Array();Modal._are_any_instances_showing=false;Modal._static_selects_and_iframes=null;Modal._modals_in_waiting=new Array();function Confirm(index,parms,func_ok_onclick,func_cancel_onclick)
{if(Confirm.caller!=Modal.CreateInstance&&(Confirm.caller!=Input))
{throw'Confirm Constructor is a private function';}
this._confirm_var='Confirm ctor';Confirm.parentCtor.call(this,index,parms,func_ok_onclick,func_cancel_onclick);this._type=Modal.CONFIRM;this.__classname='Confirm';this._btn_cancel=null;}
Object.extend(Confirm,Modal);Confirm.prototype.toString=function()
{return"Confirm object";};Confirm.prototype._Setup=function()
{Confirm.parent._Setup.call(this);var nbsp=document.createTextNode(' ');this._p_buttons.appendChild(nbsp);this._btn_cancel=document.createElement('input');this._btn_cancel.id='Confirm_btn_cancel_'+this._index;this._btn_cancel.name='Confirm_btn_cancel_'+this._index;this._btn_cancel.type='button';this._btn_cancel.value=this._cancel_caption;this._btn_cancel.className=this._css_cancel_button;this._btn_cancel.setAttribute('index',this._index);if(this._css_cancel_button)
this._btn_cancel.className=this._css_cancel_button;this._btn_cancel.onclick=function()
{var source=null;var event=null;if(arguments.length==1)
{event=arguments[0];source=arguments[0].currentTarget;}
else
{event=window.event;source=window.event.srcElement;}
var dialog=Modal.GetInstance(source.getAttribute('index'));dialog.Hide();if(dialog._func_cancel_onclick)
dialog._func_cancel_onclick(event);};this._p_buttons.appendChild(this._btn_cancel);};function Input(index,parms,func_ok_onclick,func_cancel_onclick)
{if(Input.caller!=Modal.CreateInstance)
{throw'Input Constructor is a private function and cannot be called by '+Input.caller;}
if(!parms)
parms=new Array();this._text_box=null;this._css_textbox=null;if(parms['css_textbox'])
this._css_textbox=parms['css_textbox'];Input.parentCtor.call(this,index,parms,func_ok_onclick,func_cancel_onclick);this._type=Modal.INPUT;this.__classname='Input';}
Object.extend(Input,Confirm);Input.prototype.GetText=function()
{if(this._text_box)
return this._text_box.value;else
return null;}
Input.prototype.Show=function(caption,message)
{if(this._text_box)
this._text_box.value='';Input.parent.Show.call(this,caption,message);this._text_box.focus();};Input.prototype.toString=function()
{return"Input object";};Input.prototype._Setup=function()
{Input.parent._Setup.call(this);var div=document.createElement('div');div.style.padding='2px 10px 2px 10px';this._text_box=document.createElement('input');this._text_box.style.zIndex="100";this._text_box.id='input_'+this._index;this._text_box.style.width='100%';if(this._css_textbox)
this._text_box.className=this._css_textbox;div.appendChild(this._text_box);this.AddExtraControl(div);var old_onclick=this._btn_ok.onclick;};