
String.prototype.isArgument=function()
{
	return /^([a-zA-Z]){1,}=([0-9]){1,}$/.test(this);
}


/*
call this function just work like window.open(url,name,feature);
however, for IE5.0+, it will open a showModelessDialog window;
and For (Mozilla or Netscape), the child window will stay on top focus untill user close it.
*/


function dialog(Pageurl,Pagename,feature,isModal)
{
     if(Pageurl==null)
     {
        return false;
     }
     Pageurl = Pageurl
     if(Pagename==null)
     {
        Pagename=""
     }
     if(feature==null)
     {
        feature=""
     }
    if(window.showModelessDialog)
    {
  	    var WindowFeature = new Object();
	    WindowFeature["width"] = 400;
	    WindowFeature["height"]  =400;
	    WindowFeature["left"]  = "";
	    WindowFeature["top"]  =  "";
	    WindowFeature["resizable"]  = "";

	    if(feature !=null && feature!="")
	    {
            feature = ( feature.toLowerCase()).split(",");
	
            for(var i=0;i< feature.length;i++)
		    {
                if( feature[i].isArgument())
			    {
                    var featureName = feature[i].split("=")[0];
			        var featureValue = feature[i].split("=")[1];
			  
			        if(WindowFeature[featureName]!=null)
			        {
			            WindowFeature[featureName] = featureValue; 
			        }
			    }
		    }
	    }
 
        if(WindowFeature["resizable"]==1 || WindowFeature["resizable"]=="1" || WindowFeature["resizable"].toString().toLowerCase()=="yes")
        {
            WindowFeature["resizable"] = "resizable:1;minimize:1;maximize:1;"
        }
        if(WindowFeature["left"]!="")
        {
            WindowFeature["left"] ="dialogLeft:" +  WindowFeature["left"] +"px;";
        }
        if(WindowFeature["top"]!="")
        {
            WindowFeature["top"] ="dialogTop:" +  WindowFeature["Top"] +"px;"; 
        }
        if(window.ModelessDialog ==null)
        {
            window.ModelessDialog = new Object() ; 
        }
        if(Pagename!="")
        {
            if(window.ModelessDialog[Pagename]!=null && !window.ModelessDialog[Pagename].closed )
            {
                window.ModelessDialog[Pagename].focus();
	            return window.ModelessDialog[Pagename];
            }
        }
	    var F = WindowFeature["left"] +WindowFeature["top"] +  "dialogWidth:"+WindowFeature["width"] +" px;dialogHeight:"+WindowFeature["height"]+"px;center:1;help:0;" + WindowFeature["resizable"] +"status:0;unadorned:0;edge: raised; ;border:thick;"
	    if(isModal)
	    {
		    window.showModalDialog(Pageurl,self,F);
		    return false;
	    }
	    else
	    {
		    window.ModelessDialog[Pagename] = window.showModelessDialog(Pageurl,self,F);
		    return window.ModelessDialog[Pagename];
	    }	
    }
    else
    {
        if(document.getBoxObjectFor)
        {
	        if(isModal)
	        {		 
		        var Modal = window.open(Pageurl,Pagename,"modal=1," + feature);
		        var ModalFocus = function()
		        {
			        if(!Modal.closed)
			        {
			            Modal.focus();
			        }
			        else
			        {
			            Modal =null;
			            window.removeEventListener(ModalFocus,"focus");
			            ModalFocus = null; 
			        }					
		        }
		        window.addEventListener( "focus",ModalFocus, false ); 
		        return false;
	        }
	        else
	        {
		        return window.open(Pageurl,Pagename,"modal=1," + feature);
	        }	 
        }
        else
        { 
            return window.open(Pageurl,Pagename,feature);
        }
    }
    return null;
} 

 /*Function to open the window as a modal dialog */  
function modal(Pageurl,feature)
{
	dialog(Pageurl,"",feature,true);
}

