﻿// JScript File

function SilverWindow() {

var isIE=navigator.userAgent.indexOf('MSIE')>=0?true:false;
var WindowId;
var varWidth;
var varHeight;
this.getWindowBorder=function()
{
var HTMLWIndow="";
//For IE
if(isIE){
HTMLWIndow="<div class=\"x-ie-shadow\" id=\"@dialogid_shadow\" style=\"display: block; z-index: 9002; filter: progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=5);"
HTMLWIndow+="         width: 0px;  height: 0px\">"
HTMLWIndow+="</div>"
}else{
//For Mozilla
HTMLWIndow="<div style=\"z-index: 9001;   width: 0px; height: 0px;";
HTMLWIndow+="            display: block;\" id=\"@dialogid_shadow\" class=\"x-shadow\">";
HTMLWIndow+="        <div class=\"xst\">";
HTMLWIndow+="            <div class=\"xstl\">";
HTMLWIndow+="            </div>";
HTMLWIndow+="            <div id=\"@dialogid_shadow1\" style=\"width: 0px;\" class=\"xstc\">";
HTMLWIndow+="            </div>"
HTMLWIndow+="            <div class=\"xstr\">"
HTMLWIndow+="            </div>"
HTMLWIndow+="        </div>"
HTMLWIndow+="        <div id=\"@dialogid_shadowheight\" style=\"height: 0px;\" class=\"xsc\">"
HTMLWIndow+="            <div class=\"xsml\">"
HTMLWIndow+="            </div>"
HTMLWIndow+="            <div id=\"@dialogid_shadow2\" style=\"width: 0px;\" class=\"xsmc\">"
HTMLWIndow+="            </div>"
HTMLWIndow+="            <div class=\"xsmr\">"
HTMLWIndow+="            </div>"
HTMLWIndow+="        </div>"
HTMLWIndow+="        <div class=\"xsb\">"
HTMLWIndow+="            <div class=\"xsbl\">"
HTMLWIndow+="            </div>"
HTMLWIndow+="            <div id=\"@dialogid_shadow3\" style=\"width: 498px;\" class=\"xsbc\">"
HTMLWIndow+="            </div>"
HTMLWIndow+="            <div class=\"xsbr\">"
HTMLWIndow+="            </div>"
HTMLWIndow+="        </div>"
HTMLWIndow+="</div>"
}
// Content
HTMLWIndow+="<div id=\"@dialogid_outermost\" class=\"x-dlg x-dlg-closable x-dlg-resizable x-resizable-pinned x-dlg-draggable x-dlg-auto-tabs\"";
    HTMLWIndow+=" style=\"visibility: visible; position: absolute;  width: 500px;";
    HTMLWIndow+=" height: 300px;  z-index: 9002;\">";
HTMLWIndow+="<div id=\"@dialogid_Header\" class=\"x-dlg-hd-left\">";
            HTMLWIndow+="<div class=\"x-dlg-hd-right\" >";
                HTMLWIndow+="<div class=\"x-dlg-hd x-unselectable\" >";
                    HTMLWIndow+="<span id=\"@dialogid_Title\">Hello Dialog</span>";
                HTMLWIndow+="</div>";
            HTMLWIndow+="</div>";
        HTMLWIndow+="</div>";
        HTMLWIndow+="<div class=\"x-dlg-dlg-body\"  id=\"@dialogid_Content\" style=\"  width: 100%; ";
            HTMLWIndow+="\">";
            HTMLWIndow+="<span id=\"@dialogid_Title\">jj</span>";
        HTMLWIndow+="</div>";
        HTMLWIndow+="<div class=\"x-dlg-toolbox\" onclick=\"javascript:CloseWIndow('@dialogid');\" id=\"@dialogid_ToolBox\">";
            HTMLWIndow+="<div class=\"x-dlg-close\"   id=\"@dialogid_Close\">";
            HTMLWIndow+="</div>";
            //HTMLWIndow+="<div class=\"x-dlg-collapse\" id=\"@dialogid_Minimize\">";
            //HTMLWIndow+="</div>";
        HTMLWIndow+="</div>";
HTMLWIndow+="</div>";
return HTMLWIndow;
}

this.CreateWindow= function(WindowTitle)
{
    var htmlcode=this.getWindowBorder();
    var uniqueid=this.getUniqueID('DialogWindow');
    var divid=document.createElement("div");
    divid.id=uniqueid;
    this.WindowId=uniqueid;
    var c=htmlcode.split("@dialogid")
    for(i=0;i<c.length;i++)
    {
        htmlcode=htmlcode.replace("@dialogid",divid.id);
    }
   
    divid.innerHTML=htmlcode;
    document.body.appendChild(divid);
    document.getElementById(this.WindowId+'_Close').onclick=function() {CloseWIndow(this.WindowId) };
    document.getElementById(this.WindowId+'_Title').innerHTML=WindowTitle;
    document.getElementById(this.WindowId).style.position='absolute';
    document.getElementById(this.WindowId).style.display = 'none';
    
  
    this.SetWindowSize(800,500);
//    this.SetWindowPosition(100,100);
}
this.AnimateWindow=function()
{
    var spos=this.__getScrollPos();
    var brSize =this.__getBrowserSize();
    var widthC=brSize[0]/2;
    var heightC=brSize[1]/2;
    
    var Owidth=0;
    var Oheight=0;
    var Oleft=widthC+spos.x;
    var OTop=heightC+spos.y;
    
}
this.DisplayWindow=function()
{

  document.getElementById(this.WindowId).style.position='absolute';
  document.getElementById(this.WindowId).style.display = 'block';
}
this.makeDragabble=function()
{
    var id=this.WindowId;
    var objWindow=document.getElementById(id);
    var objWindowHeader=document.getElementById(id+'_Header');
    makeDraggable(id,id+'_Header');
}
this.SetHTMLContentFromSourceDivID=function(sourceDivID)
{
   var id=this.WindowId;
   document.getElementById(id+'_Content').innerHTML=document.getElementById(sourceDivID).innerHTML;
}
this.SetIframe=function(url)
{
   var id=this.WindowId;
   document.getElementById(id+'_Content').innerHTML="<iframe width=\"100%\" height=\"100%\" frameborder=\"0\" src='"+url+"'></iframe>";
}
this.SetWindowPosition=function(left,top)
{
   var id=this.WindowId;
   
    if(isIE){
    document.getElementById(id).style.left=left+'px'
    document.getElementById(id+'_shadow').style.left=(left-10)+'px';
    document.getElementById(id+'_outermost').style.left=left+'px';
    
    document.getElementById(id).style.top=top+'px'
    document.getElementById(id+'_shadow').style.top=top+'px';
    document.getElementById(id+'_outermost').style.top=top+'px';
    }
    else
    {
        document.getElementById(id).style.left=left+'px'
    document.getElementById(id+'_shadow').style.left=(left-5)+'px';
    document.getElementById(id+'_outermost').style.left=left+'px';
    
    document.getElementById(id).style.top=top+'px'
    document.getElementById(id+'_shadow').style.top=top+'px';
    document.getElementById(id+'_outermost').style.top=(top-5)+'px';
    }
    document.getElementById(id).style.left='0px'
    document.getElementById(id).style.top='0px'
    
}
this.SetWindowSize=function(width,height)
{
var id=this.WindowId;
this.varWidth=width;
this.varHeight=height;
if(isIE){
    document.getElementById(id).style.width=width+'px';
    document.getElementById(id+'_shadow').style.width=width+'px';
    document.getElementById(id+'_outermost').style.width=(width-10)+'px';
    document.getElementById(id+'_Content').style.width=(width-0-22)+'px';
    
    document.getElementById(id).style.height=height+'px';
    document.getElementById(id+'_shadow').style.height=height+'px';
    document.getElementById(id+'_outermost').style.height=height+'px';
    document.getElementById(id+'_Content').style.height=(height-45)+'px';

    
    
    }else
    {
        document.getElementById(id).style.width=width+'px';
        document.getElementById(id+'_shadow').width=width+'px';
        document.getElementById(id+'_shadow1').style.width=(width-12)+'px';
        document.getElementById(id+'_shadow2').style.width=(width-12)+'px';
        document.getElementById(id+'_shadow3').style.width=(width-12)+'px';
        document.getElementById(id+'_outermost').style.width=(width-10)+'px';
        document.getElementById(id+'_Content').style.width=(width-0-22)+'px';
        
        document.getElementById(id).style.height=height+'px';
        document.getElementById(id+'_shadow').style.height=height+'px';
        document.getElementById(id+'_shadowheight').style.height=(height-12)+'px';
        document.getElementById(id+'_outermost').style.height=height+'px';
        document.getElementById(id+'_Content').style.height=(height-45)+'px';
    }
    
}

this.getUniqueID=function(id)
{
    for(i=0;i<1000;i++)
    {
        if(document.getElementById(id)==null)
            break;
		else
			id=id+i;
    }
    return id;
}
this.CenterWindow=function()
	{
	
	    var brSize =this.__getBrowserSize();
	    var widthC=brSize[0]/2;
	    var heightC=brSize[1]/2;
	    
	    var WWidth='';
        WWidth=document.getElementById(this.WindowId).style.width;
        
        WWidth=parseInt(WWidth.substring(0,WWidth.length-2))/2;
       
        var Wheight='';
        Wheight=document.getElementById(this.WindowId).style.height;
        Wheight=parseInt(Wheight.substring(0,Wheight.length-2))/2;
        var spos=this.__getScrollPos();
       

	    var leftC=widthC-WWidth+spos.x;
	    var topC=heightC-Wheight+spos.y;
	    this.SetWindowPosition(leftC,topC);
	    
	    
	}
this.__getScrollPos=function()
{
var nav4=window.event?true:false;
       if (nav4) {
                 x1 =  document.documentElement.scrollLeft + document.body.scrollLeft;
                 y1 = document.documentElement.scrollTop + document.body.scrollTop;
            }
        else {
                 x1 =window.scrollX;
                 y1 = window.scrollY;
            }
        return {x:x1,y:y1}
}
this.__getBrowserSize=function()
	    {
    	    var bodyWidth = document.documentElement.clientWidth;
    	    var bodyHeight = document.documentElement.clientHeight;
        	
		    var bodyWidth, bodyHeight; 
		    if (self.innerHeight){ // all except Explorer 
		       bodyWidth = self.innerWidth; 
		       bodyHeight = self.innerHeight; 
		    }  else if (document.documentElement && document.documentElement.clientHeight) {
		       // Explorer 6 Strict Mode 		 
		       bodyWidth = document.documentElement.clientWidth; 
		       bodyHeight = document.documentElement.clientHeight; 
		    } else if (document.body) {// other Explorers 		 
		       bodyWidth = document.body.clientWidth; 
		       bodyHeight = document.body.clientHeight; 
		    } 
		   
                
            bodyWidth=bodyWidth;
            bodyHeight=bodyHeight
      
		    return [bodyWidth,bodyHeight];		
    		
	    }

}

function CloseWIndow(id)
{
    var objWindow=document.getElementById(id);
    if(objWindow!=null)
        document.body.removeChild(objWindow);
}
