/*
  Workspace Login 
  Vincent Fiduccia
  

  Version: 1.6 () 
  2009-12-04 18:55:08 (p3plpassweb05.prod.phx3.secureserver.net)

  js_file_Popin
*/

function Popin(props)
{Function.importDefaults(this,props,{title:'Popin',body:'',showing:false,on_show:null,placement:{type:'fixed',to:'cm'},actions:[],show_actions:true,close_btn:false,dynamic_pos:true,drop_shadow:5,fade_in:true,fade_out:true,bg_hide:true,bg_fade_in:true,bg_fade_to:null,zindex:null,wrapper_class:'popin_wrapper',title_class:'popin_title',close_class:'popin_close',body_class:'popin_body',actions_class:'popin_actions',action_class:'popin_action',default_class:'popin_action_default'},['showing']);this.id=Popin.next_id++;Popin.inst[this.id]=this;this.div=$L.create('div',{id:'popin_'+this.id},{position:'absolute',display:'none'},'body');this.form=$L.create('form',{id:'popin_form_'+this.id},null,this.div);$E.add('submit',this.checkEnter.bind(this),this.form);Debug.write('showing: '+props.showing+' '+this.showing);if(props.showing)
{this.show();}}
Popin.inst={};Popin.next_id=1;Popin.prototype.show=function()
{this.render();this.place();if(this.showing)
{if(this.on_show)
setTimeout(function(obj){obj.on_show(true)}.bind(this),1);}
else
{this.showing=true;if(this.bg_hide)
{$L.hideBackground(null,this.bg_fade_in,this.bg_fade_to,this.backgroundEscape.bind(this));}
$L.change(this.div,'zIndex',(this.zindex===null?$L.background_zindex++:this.zindex));if(this.dynamic_pos)
{$E.add('resize',this.place.bind(this));$E.add('scroll',this.place.bind(this));}
if(this.fade_in)
{$L.fade(this.div,0,100,null,null,this.on_show);}
else
{$L.change(this.div,'display','block');}
for(var i=0;i<this.actions.length;i++)
{if(this.actions[i].on_enter)
{this.getAction(this.actions[i].name).focus();}}}}
Popin.prototype.render=function()
{var t=new Template();t.assign('this',this);this.form.innerHTML=t.fetch('popin');if(this.close_btn)
$E.add('click',this.checkEscape.bind(this),'popin_close_btn_'+this.id)}
Popin.prototype.place=function()
{if(this.placement.type=='fixed')
this.placeFixed();else if(this.placement.type=='tlbr')
this.placeTlbr();else
Debug.write('"'+this.placement.type+'" is not a valid placement for a Popin');}
Popin.prototype.placeFixed=function()
{var p=this.placement;var popin_body=$('popin_body_'+this.id);if(p.width)
{$L.change(this.div,'width',p.width+'px');}
if(p.height)
{$L.change(popin_body,'height',p.height+'px');this.placeMinMaxHeight();}
$L.fixedPos(this.div,this.placement.to);}
Popin.prototype.placeTlbr=function()
{var p=this.placement;var popin_body=$('popin_body_'+this.id);if(p.top&&p.bottom)
{if(Env.is_ie)
{$L.change(this.div,{top:p.top+'px',bottom:null});$L.style(this.div).setExpression('height','(document.body.clientHeight-'+(p.top+p.bottom)+")+'px'");}
else
{$L.change(this.div,{top:p.top+'px',bottom:p.bottom+'px'});}
$L.change(popin_body,'height',null);this.placeMinMaxHeight(false);}
else
{if(p.top)
$L.change(this.div,{top:p.top+'px',bottom:null});else if(p.bottom)
$L.change(this.div,{top:null,bottom:p.bottom+'px'});else
Debug.write('No top or bottom specified for popin with placement=tlbr');$L.change(popin_body,'height',p.height+'px');this.placeMinMaxHeight();}
if(p.left&&p.right)
{if(Env.is_ie)
{$L.change(this.div,{left:p.left+'px',right:null});$L.style(this.div).setExpression('width','(document.body.clientWidth-'+(p.left+p.right)+")+'px'");}
else
{$L.change(this.div,{left:p.left+'px',right:p.right+'px'});}}
else
{if(p.left)
$L.change(this.div,{left:p.left+'px',right:null});else if(p.right)
$L.change(this.div,{left:null,right:p.right+'px'});else
Debug.write('No left or right specified for popin with placement=tlbr');$L.change(this.div,'width',p.width+'px');}}
Popin.prototype.placeMinMaxHeight=function(set)
{var p=this.placement;var body=$('popin_body_'+this.id);var min,max;if(set===false)
{min=null;max=null;}
else
{min=p.min_height;max=p.max_height;}
Debug.write('min: '+min+', max: '+max+', body: '+body);if(Env.is_ie)
{if(min&&max)
{}}
else
{$L.change(body,{minHeight:min+'px',maxHeight:max+'px'});}}
Popin.prototype.setTitle=function(title)
{this.title=title;if(this.showing)
this.show();}
Popin.prototype.setBody=function(body)
{this.body=body;if(this.showing)
this.show();}
Popin.prototype.setActions=function(actions)
{this.actions=actions;if(this.showing)
this.show();}
Popin.prototype.getAction=function(name)
{return $('popin_'+this.id+'_action_'+name);}
Popin.prototype.hide=function()
{if(!this.showing)
return;this.showing=false;if(this.bg_hide)
$L.showBackground();$L.fade(this.div,(this.fade_out?100:0),0,null,null,this.hidden.bind(this));$E.remove('resize',this.place.bind(this));$E.remove('scroll',this.place.bind(this));}
Popin.prototype.destroy=function()
{this.destroy=1;if(this.showing)
{this.hide();}
else
{this.hidden();}}
Popin.prototype.hidden=function()
{if(this.destroy)
{$L.destroy(this.div);delete(Popin.inst[this.id]);}}
Popin.prototype.checkEnter=function(event)
{for(var i=0;i<this.actions.length;i++)
{if(this.actions[i].on_enter)
{$E.cancel(event);this.doAction(null,this.actions[i].name);return false;}}}
Popin.prototype.checkEscape=function(event)
{for(var i=0;i<this.actions.length;i++)
{if(this.actions[i].on_escape)
{$E.cancel(event);this.doAction(null,this.actions[i].name);return false;}}}
Popin.prototype.backgroundEscape=function()
{for(var i=0;i<this.actions.length;i++)
{if(this.actions[i].on_bg_escape)
{this.doAction(null,this.actions[i].name);return false;}}}
Popin.prototype.doAction=function(event,elem)
{if(typeof(elem)!='string')
elem=elem.name;for(var i=0;i<this.actions.length;i++)
{if(this.actions[i].name==elem)
{var act=this.actions[i].action;if(act)
act(this);else
Debug.write('Action not defined for "'+elem+'"');return;}}}
Popin.prototype.getForm=function()
{return this.form;}
Popin.corner=function(type,title,message,timeout,action)
{if(title==null)
title="Message";if(message==null)
return;if(timeout===undefined||timeout==null)
{timeout=5000;}
if(!action)
{action=function(popin){popin.destroy();};}
var popin=new Popin({title:title,title_class:'popin_'+type+'_title',body_class:'popin_'+type+'_body',body:'<div class="popin_'+type+'_icon"></div><div>'+message+'</div>',placement:{type:'fixed',to:'br',width:300},close_btn:true,actions:[{name:'close',label:'Close',show:false,action:action,on_escape:true,on_bg_escape:true}],show_actions:false,bg_hide:false,drop_shadow:false});popin.show();if(timeout)
setTimeout(popin.destroy.bind(popin),timeout);}
Popin.message=function(title,message,timeout,action)
{Popin.corner('message',title,message,timeout,action);}
Popin.error=function(title,message,timeout,action)
{Popin.corner('error',title,message,timeout,action);return;}

if ( typeof(loaded) == 'undefined' ) var loaded = {};
  loaded['/js.php?file=Popin&r='] = 1;
