function dialog(obj){var did='#dialog';var cd='display';var cb='block';var cn='none';var imgdir='/tpl/images/';if(!$(did).attr('id'))$('body').append('<div id="dialog"  title="" style="display:none"></div>');this.dialog=$(did);this.btns=0;this.c=new Array();this.maxH=400;this.maxW=800;this.of='auto';this.move=function(crd){$(did).css({"top":crd.top,"left":crd.left});}
this.text=function(txt){$(did+'-txtcont').html(txt);this.normalize();}
this.normalize=function(){if($(did).width()>this.maxW){$(did+'-txtcont').css('width',this.maxW);$(did+'-txtcont').css('overflow',this.of)}
if($(did).height()>this.maxH){$(did+'-txtcont').css('height',this.maxH);$(did+'-txtcont').css('overflow',this.of)}}
this.show=function(){$(did).css(cd,cb);}
this.remove=function(){$(did).css(cd,cn);$(did).html('');$(did).removeClass();}
this.hide=function(){$(did).css(cd,cn);}
this.title=function(t){$(did+'-title').html(t);}
this.getTxtCont=function(){return $(did+'-txtcont')}
this.getDialogCont=function(){return $(did)}
this.button=function(ibtns){var btnid='dialog-button'+(this.btns++);if(ibtns.length)
for(var i in ibtns){$(did+'-butt').append('&nbsp;<input type="button" id="'+btnid+'_'+i+'" value="'+ibtns[i].name+'" class="dialog-butt2">&nbsp;');$('#'+btnid+'_'+i).click(ibtns[i].func);}
else{$(did+'-butt').append('&nbsp;<input type="button" id="'+btnid+'" value="'+ibtns.name+'" class="dialog-butt2">&nbsp;');$('#'+btnid).click(ibtns.func);}}

var th=this.remove;$(did+':not(.dialog-maincont)').addClass('dialog-maincont');$(did).attr("align",'center');$(did).html('<table class="dialog-w" border=0 cellpadding=0 cellspacing="0"><tr style="background-image:url('+imgdir+'bk-grey-01.gif);background-repeat:repeat-x;"><td id="dialog-title" align="center" class="dialog-t-td">'+$(did).attr('title')+'</td><td class="dialog-t-td" style="text-align:center;width:20px;vertical-align:top"><img id="dialog-iclose" src="'+imgdir+'dclose4.gif"></td></tr></table>');$(did+'-iclose').click(th);$(did).append('<div id="dialog-txtcont" class="dialog-txt"></div>');$(did).append('<div id="dialog-butt" align=center class="dialog-w dialog-butt"></div>');if(!obj){this.c=getCenterPos($(did).width(),$(did).height());
if(this.c.left<0)this.c.left=0;if(this.c.top<0)this.c.top=0;}
else this.c=$(obj).offset();this.move(this.c);}
function getCenterPos(w,h){var myWidth=0,myHeight=0,f=new Array();if(typeof(window.innerWidth)=='number'){myWidth=window.innerWidth;myHeight=window.innerHeight;}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){myWidth=document.documentElement.clientWidth;myHeight=document.documentElement.clientHeight;}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){myWidth=document.body.clientWidth;myHeight=document.body.clientHeight;}
var scrOfX=0,scrOfY=0;if(typeof(window.pageYOffset)=='number'){scrOfY=window.pageYOffset;scrOfX=window.pageXOffset;}else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){scrOfY=document.body.scrollTop;scrOfX=document.body.scrollLeft;}else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){scrOfY=document.documentElement.scrollTop;scrOfX=document.documentElement.scrollLeft;}
f.top=Math.round((myHeight-h)/2)+scrOfY;f.left=Math.round((myWidth-w)/2)+scrOfX;return f;}
