/**
 function openSDialog(url)
 function closeSDialog()
 function Enable()
 */

function Dialog(sId, url, iXStartPosi, iYStartYposi, iWidth, iHeight,sFormName)
{
    this.sDilogWidowID = {popup:null, visible:false};

    this.openSDialog = function(sId, url, iXStartPosi, iYStartYposi, iWidth, iHeight,sFormName)
    {
        //alert(sId +","+url+","+ iXStartPosi+","+ iYStartYposi+","+ iWidth+","+ iHeight);
        this.sFormName = sFormName;
        this.sDilogWidowID.popup = document.getElementById(sId + 'SWindow');
        var sDilogTitleBarID = document.getElementById(sId + "titlebar") ;
        this.sDilogcontentFrameID = document.getElementById(sId + "contentFrame");

        if (!this.sDilogWidowID.visible)
        {
           // this.disable();
            if (url)
            {
                this.sDilogcontentFrameID.src = url;
                //document.getElementById(sId + "STitlebar").firstChild.nodeValue = url;
            }
            if (navigator.appName == "Microsoft Internet Explorer")
            {
                if (iWidth > 10)
                {
                    var width = '' + iWidth + 'px';
                    var Widthn = parseInt(width) - 6;
                    //alert("dialog  "+this.sDilogcontentFrameID)
                    this.sDilogcontentFrameID.style.width = '' + Widthn + '';
                    this.sDilogWidowID.popup.style.width = '' + width + '';
                    sDilogTitleBarID.style.width = '' + Widthn + '';
                }
                else
                {
                    this.sDilogcontentFrameID.style.width = '594px';
                    this.sDilogWidowID.popup.style.width = '600px';
                    sDilogTitleBarID.style.width = '594px';
                }
                if (iHeight > 40)
                {
                    var iheight = '' + iHeight + 'px';
                    //var IHeightn = '' + (parseInt(iheight) - 36) + 'px';
                    var IHeightn = '' + (parseInt(iheight) - 26) + 'px';
                    this.sDilogcontentFrameID.style.height = '' + (IHeightn)+ '';
                    this.sDilogWidowID.popup.style.height = '' + iheight + '';
                }
                else
                {
                    this.sDilogcontentFrameID.style.height = '266px';
                    this.sDilogWidowID.popup.style.height = '302px';
                }
            }
            else
            {
                if (iWidth > 10)
                {
                    var width = '' + iWidth + 'px';
                    var Widthn = parseInt(width) - 4;
                    this.sDilogcontentFrameID.style.width = '' + width + '';
                    this.sDilogWidowID.popup.style.width = '' + width + '';
                    sDilogTitleBarID.style.width = '' + Widthn + '';
                }
                else
                {
                    this.sDilogcontentFrameID.style.width = '600px';
                    this.sDilogWidowID.popup.style.width = '600px';
                    sDilogTitleBarID.style.width = '596px';
                }

                if (iHeight > 40)
                {
                    var iheight = '' + iHeight + 'px';
                    var IHeightn = '' + (parseInt(iheight) - 30) + 'px';
                    this.sDilogcontentFrameID.style.height = '' + IHeightn + '';
                    this.sDilogWidowID.popup.style.height = '' + iheight + '';
                }
                else
                {
                    this.sDilogcontentFrameID.style.height = '272px';
                    this.sDilogWidowID.popup.style.height = '302px';
                }
            }
            /*this.sDilogWidowID.popup.style.visibility = "hidden";
            this.sDilogWidowID.popup.style.display = "block"*/
            var xPosition = 2;
            var YPosition = 2;

            if (iXStartPosi > 1)
                xPosition = iXStartPosi;
            else
                xPosition = 2;
            if (iYStartYposi > 1)
                YPosition = iYStartYposi;
            else
                YPosition = 2;
            //alert("calling shift  "+xPosition+","+ YPosition);
            /*this.sDilogcontentFrameID.style.overflowX = "hidden";
            this.sDilogcontentFrameID.style.overflowY = "hidden";*/
            shiftTo(this.sDilogWidowID.popup, xPosition, YPosition);
            //starting position of window

            /*this.sDilogWidowID.popup.style.visibility = "visible"
            this.sDilogWidowID.visible = true;*/
        }
       // this.showDialog();
    }
    this.setURL = function(sURL)
    {
        this.sDilogcontentFrameID.src = sURL;
    }
    this.showDialog = function()
    {
        initSpopUpAPI();
        initDrag();
        //this.disable();
        this.sDilogcontentFrameID.style.scrollTop = "0px";
        //alert(this.sDilogcontentFrameID.style.overflowY);
        this.sDilogWidowID.popup.style.visibility = "visible";
        this.sDilogWidowID.popup.style.display = "block";
        this.sDilogWidowID.visible = true;
        //alert("after displaying");
    }
    /**
     Close Operation of Model Window
     */
    this.closeSDialog = function()
    {
        //this.Enable();
        //alert("this.sDilogWidowID  "+this.sDilogWidowID.popup.id);
        this.sDilogWidowID.popup.style.display = "none";
        //alert("visible false");
        this.sDilogWidowID.visible = false;
        removeEvents(); // function in dialogdrag.js to remove event handling
    }
    /**
     Disable Present form controls when Model Dilog Open
     */
    this.disable = function()
    {
        //alert("form "+this.sFormName);
        var objForm = null;
        if(this.sFormName)
        {
            /*var objCurrentFrame = getCurrentFrame();
            if(objCurrentFrame)
                objForm = objCurrentFrame.contentWindow.document.forms[this.sFormName];
            else*/
                objForm = document.forms[this.sFormName];
        }
        else if(document.forms.length > 0)
            objForm = document.forms[0];

        if(objForm)
            for (var j = 0; j < objForm.elements.length; j++)
                objForm.elements[j].disabled = true;
    }

    /**
     Enable Present form control when Model Dilog close
     */
    this.Enable = function()
    {
        var objForm = null;
        if (this.sFormName)
        {
            var objCurrentFrame = getCurrentFrame();
            if(objCurrentFrame)
                objForm = objCurrentFrame.contentWindow.document.forms[this.sFormName];
            else
                objForm = document.forms[this.sFormName];
        }
        else if(document.forms.length > 0)
            objForm = document.forms[0];

        if(objForm)
            for (var j = 0; j < objForm.elements.length; j++)
                objForm.elements[j].disabled = false;
    }
    this.openSDialog(sId, url, iXStartPosi, iYStartYposi, iWidth, iHeight);
}

/**
 This is used for the Window Maxmise the  and Minimise the Window
 */
/**var  isMax =1
 function MaxMin()
 {
 var sTitlebar =document.getElementById("titlebar");
 var sContentFrame =document.getElementById("contentFrame");
 if(isMax==1)
 {
 sTitlebar.style.width='800px';
 sContentFrame.style.width='800px';
 sContentFrame.style.height='500px';
 isMax=0;
 }
 else
 {
 sTitlebar.style.width='600px';
 sTitlebar.style. border='2px solid #666666';
 sContentFrame.style.width='613px';
 sContentFrame.style.height='286px';
 isMax=1;
 }
 } */