﻿/********************************************

 THIS FILE IS ASSOCIATED WITH PupUpDiv.ascx
 Add to page only 1 time if used many time.
 Yahoo Ext Must be also on page!
----------------------------------------------
 [ Yahoo Ext Js Files ] 

<script type="text/javascript" src="adapter/yui/yui-utilities.js"></script>     
<script type="text/javascript" src="adapter/yui/ext-yui-adapter.js"></script>     <!-- ENDLIBS -->
<script type="text/javascript" src="Javascript/ext-all.js"></script>
----------------------------------------------
 Created By: Andrew Timmins - July 2, 2007 
 Bergmann Associates
 Modifed By: Carol Zollweg - June 19, 2008
********************************************/
function DialogBox(contentDivId,launchId,width,height,title, constraint)
{
    this.contentDivId = contentDivId;
    this.id =  "Dialog" +  Math.floor(Math.random()*50000);
    this.launchID = launchId;
    this.width = width;
    this.height = height;
    this.title = title;
    // If caller did not provide a value for constrain to window size then do not
    // constrain and set to false.
    if (constraint == null)
    {
      this.constraint = false;
    }
    else
    {
      this.constraint = constraint;
    }
    
    this.isOpen = false;
    this.htmlText = "";
    this.clicked = false;
    
    this.Load();
}

DialogBox.prototype.CreatDialogDiv = function()
{
     if (!document.getElementById(this.id))
	 {
	  
        var content = document.getElementById(this.contentDivId);
        content.style.display = "none";
        content.style.top = "-1000px";
        content.style.left = "-1000px";
        // style="top:0px; left:0px; display: block; visibility: visible; position: relative;" class="x-layout-active-content x-tabs-item-body">';
        this.htmlText = '<div id="'+this.id+'_Container">';
        this.htmlText +='<div id="'+content.id+'">';
        this.htmlText += content.innerHTML;
        this.htmlText += '</div>';
        this.htmlText += '</div>';
        
        content.innerHTML = ""; 
        content.id = content.id+ "_OLD";

        
	    var newDiv = document.createElement(this.id);
	    newDiv.id = this.id;
	    newDiv.style.position = "absolute";
	    newDiv.style.visibility = "hidden";
	    newDiv.style.top = "0px";
	
	    //check if div exist..
	    document.body.appendChild(newDiv);
        var elem = document.getElementById(this.id)

	    elem.innerHTML = '<div class="x-dlg-bd" style="padding:5px;"><div class="x-dlg-tab">'+this.htmlText+'</div></div>\n';
	
	    this.showBtn = '';
        this.showBtn = Ext.get(this.launchID);

        //lazy initialize the dialog and only create it once
        var copy = this;
//        this.dialog = new Ext.BasicDialog(this.id, {  modal: false,  constraintoviewport:true, title:this.title, width:this.width,height:this.height,shadow:false,proxyDrag: true, autoTabs:false, autoScroll: false, animate:false });
//        this.dialog = new Ext.BasicDialog(this.id, {  modal: false,  constraintoviewport:false, title:this.title, width:this.width,height:this.height,shadow:false,proxyDrag: true, autoTabs:false, autoScroll: false, animate:false });
        this.dialog = new Ext.BasicDialog(this.id, {  modal: false,  constraintoviewport:this.constraint, title:this.title, width:this.width,height:this.height,shadow:false,proxyDrag: true, autoTabs:false, autoScroll: false, animate:false });
        this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);
        this.clicked = true;     
	}
} 


DialogBox.prototype.Loader = function()
{
    this.CreatDialogDiv();
}


DialogBox.prototype.Refresh = function()
{
    var el = document.getElementById(this.contentDivId);
    el.innerHTML = this.contentDivId;
}
     
DialogBox.prototype.Show = function()
{
     this.dialog.show(this.showBtn.dom);
     this.dialog.toFront();
     //this.dialog.refresh();
     this.dialog.resizeTo(this.dialog.width,this.dialog.height); //refreshes css if theme change
}
DialogBox.prototype.Hide = function()
{
    this.dialog.hide(this.showBtn.dom);
}
DialogBox.prototype.Collapse = function()
{
    this.dialog.collapse(this.showBtn.dom);
}
DialogBox.prototype.Load = function()
{
	this.Loader();
}