// layer level index
var zindex_no = 30;
var isGECKO=((navigator.userAgent.indexOf('Gecko') != -1) || (navigator.userAgent.indexOf("Netscape")!= -1));
var isIE=(navigator.userAgent.indexOf('MSIE') != -1);
var window_layer_handle;

    //declare a structure layer_window(url_src,window_title,window_width,window_height,modal,parent_window)
    function layer_window(url_src,window_title,window_width,window_height,_modal,parent_window,opener)
    {
        this.src = url_src;
        this.title = window_title;
        this.width = window_width;
        this.height = window_height;
        this.modal = _modal;
        this.parent_obj = parent_window;
        this.close = funct_close;    
        this.maskIframe = null;    
        this.layer_Iframe = null;    
        this.layer_node = null;    
        this.opener = null; 
        //this method to be called on close        
        this.callOnclose = null;    
        this.focus = funct_focus;    
        
    }//end layer_window
    
    //declare a function open_layer(url_src,window_title,_width,_height,_modal,parent_window,scrollbar)
	
	//open_layer('/swiz/editor/InsertLink.htm?win=modal&ed_type='+l_str_editor,'links',540,250,true,window.top,false,l_str_editor);
    function open_layer(url_src,window_title,_width,_height,_modal,parent_window,_opener,scrollbar,editor_type,zi_no,output)
    {
		zindex_no = zi_no;
		if (_modal)
        {
            //maskfrm_obj assign call the method parent_window.document.createElement("IFRAME")
            maskfrm_obj = parent_window.document.createElement("IFRAME");
            maskfrm_obj.id = "par"+zindex_no;
            //alert("maskfrm_obj.id  "+maskfrm_obj.id);
            maskfrm_obj.style.width = parent_window.document.body.scrollWidth;
            maskfrm_obj.style.height = parent_window.document.body.scrollHeight;
            maskfrm_obj.style.top = 0;
            maskfrm_obj.style.left = 0;
            zindex_no = zindex_no+1;
            maskfrm_obj.style.position  = "absolute";
            maskfrm_obj.style.zIndex  = zindex_no;
            maskfrm_obj.style.backgroundColor  = "#000000";
            //alert(maskfrm_obj.style.Opacity);
           // if(maskfrm_obj.style.Opacity)
            maskfrm_obj.style.opacity   = "0.5";
           // else
            maskfrm_obj.style.MozOpacity   = "0.5";
            //alert(maskfrm_obj.frameBorder);
            obj=parent_window.document.body.firstChild;
			
            parent_window.document.body.insertBefore(maskfrm_obj,obj);
                        
           
            obj_wind = maskfrm_obj.contentWindow;
            if(isGECKO)
            {   

                //call the method to disable contextmenu 
                
                obj_wind.addEventListener("contextmenu",disableRightClick,false);
               
                //obj_wind.document.body.innerHTML="test";
            }    
            else
            {
                //obj_wind.document.oncontextmenu assign the method disableRightClick to disable contextmenu 
                maskfrm_obj.style.cssText="filter:alpha(opacity=50);background:black;"+maskfrm_obj.style.cssText;
                
                obj_wind.document.oncontextmenu = disableRightClick; 
                obj_wind.document.open(); 
                obj_wind.document.write("<html><body bgcolor='#000000'><table width=100% height=100% ><tr><td></td></tr></body></html>"); 
                obj_wind.document.close(); 
            }    
            //end if
            
        }//end if
        
        //create layer div
        layer_obj = parent_window.document.createElement("DIV");
        layer_obj.id = "par"+zindex_no;
		//alert("layer_obj.id  "+layer_obj.id);
        //get screen width
        screen_width = parent_window.document.body.clientWidth;
        //get screen height
        screen_height = parent_window.document.body.clientHeight;
        //alert("parent_window screen_width "+screen_width);
        //alert("child_window _width "+_width);
		
		//alert("parent_window screen_height "+screen_height);
       // alert("child_window _height "+_height);
        
		screen_left = parseInt((screen_width-_width)/2);
		if(editor_type == "2")
		{
        //screen_top = parseInt((screen_height-_height)/2)+600;
        screen_top = parseInt((screen_height-_height)/2);
		}
		else
		{
		screen_top = parseInt((screen_height-_height)/2);
		}
		//alert("screen_left "+screen_left);
		
/*		
        var screen_width = screen.width;
		//alert("screen_width "+screen_width);
		if(screen_width == 800)
		{
			screen_top = screen_top;
		}
		else if(screen_width == 1024)
		{
			screen_top = screen_top+175;
		}
		else if(screen_width == 1152)
		{
			screen_top = screen_top;
		}
		else if(screen_width == 1280)
		{
			screen_top = screen_top;
		}
*/
		var cur_top=0;
            
            if(isIE)
            {
              if(parent_window.document.documentElement)
                cur_top=parent_window.document.documentElement.scrollTop;

                if(cur_top==0)
                    cur_top=parent_window.document.body.scrollTop;
            }  
            else
                cur_top=parent_window.scrollY; 
                screen_top += cur_top;

		layer_obj.style.top = screen_top;
        layer_obj.style.left = screen_left;
        layer_obj.style.border = "1px solid #CCCCCC";
        obj=parent_window.document.body.firstChild;
                  //increase layer index
        zindex_no = zindex_no+2;
        layer_obj.style.position   = "absolute";
        //assign layer  level index
        layer_obj.style.zIndex = zindex_no;
        parent_window.document.body.insertBefore(layer_obj,obj);
       // parent_window.document.body.appendChild(layer_obj);
        
        //layer_obj.innerHTML assign the html string for title bar
        
        var str='<table width="'+_width+'" border="0" cellspacing="0"  cellpadding="0"><tr>';
        str+='<td colspan="4" bgcolor="#CCCCCC"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='<tr><td style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #000000; text-decoration: none">'+window_title+'</td>';
        str+='<td align="right"><a href="javascript:;" id="cls_but" >';
        str+='<img src="/swiz/editor/images/del_icon.gif" border="0" ></a>&nbsp;</td>';
        str+='</tr></table></td></tr>';  
        
        if(scrollbar)
        {
            //layer_obj.innerHTML assign the html string for iframe with src with scrollbar
			if(output != '')
			{
				str+='<tr><td>'+output+'</td></tr></table>';
			}
			else
			{
            str+='<tr><td><IFRAME name = "frame_layer" style="background-color:#ffffff" id="frame_layer" src="'+url_src+'" frameborder="0" scrolling=yes width='+_width+' height='+_height+' ></IFRAME></td></tr></table>'; 
			}
        }    
        else
		{
            //layer_obj.innerHTML assign the html string for iframe with src
			if(output != '')
			{
				str+='<tr><td>'+output+'</td></tr></table>';
			}
			else
			{
            str+='<tr><td><IFRAME name = "frame_layer" style="background-color:#ffffff" id="frame_layer" src="'+url_src+'" frameborder="0" scrolling=no width='+_width+' height='+_height+'  ></IFRAME></td></tr></table>';
			}
		}
        //end if     

			layer_obj.innerHTML=str;
	
        
        var obj_button=parent_window.document.getElementById("cls_but"); 
        obj_button.onclick=window.funct_close;
        
        //win_layer assign new object of layer_window(url_src,window_title,_width,_height,_modal,parent_window,scrollbar)
        win_layer = new layer_window(url_src,window_title,_width,_height,_modal,parent_window,scrollbar);
        win_layer.layer_node = layer_obj;
        win_layer.maskIframe = maskfrm_obj;
        win_layer.opener = _opener;
		win_layer.layer_Iframe=parent_window.document.getElementById("frame_layer"); 
        window_layer_handle=win_layer;
		//alert("popupja window_layer_handle "+window_layer_handle);
        return (win_layer);
        
    }//end open_layer
    
    //declare a function disableRightClick(evt)
    function disableRightClick(evt)
    {
  
        if(evt)
        {
            if (evt.which == 3)
            {
                evt.returnValue = false;
                evt.cancel = true;
                //call method evt.preventDefault(  ) to stop propagation
                evt.preventDefault();
                return false;
                
            }//end if
        }
        else       
        { 
            window_layer_handle.maskIframe.contentWindow.event.returnValue = false;
            //to stop propagation
            window_layer_handle.maskIframe.contentWindow.event.cancelBubble = true;
    		return false;
        }    
        //end if            

    }//end disableRight

    //declare a function funct_close() to close layer window
    function funct_close()
    {    
		if(window_layer_handle)
        {
            if(window_layer_handle && window_layer_handle.modal)
            {
                window_layer_handle.parent_obj.document.body.removeChild(window_layer_handle.maskIframe);
                zindex_no = zindex_no-1;
                window_layer_handle.maskIframe=null;
            }//end if

            window_layer_handle.parent_obj.document.body.removeChild(window_layer_handle.layer_node);
            window_layer_handle.layer_node=null;
            zindex_no = zindex_no-1;
            
            //alert(window_layer_handle.callOnclose);
            
            if(window_layer_handle.callOnclose)
                window_layer_handle.callOnclose();
              
            window_layer_handle=null;   
        }
    }//end funct_close
    
    
     //declare a function funct_focus() to close layer window
    function funct_focus()
    {    
            if(window_layer_handle && window_layer_handle.maskIframe )
            {
               window_layer_handle.maskIframe.focus();
            }//end if

    }//end funct_close
	
	