
function genPleaseWaitPage(url, windowName)
{
	return "<html><head><meta HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=" + GMGetPath() + url + "\"></head><body bgColor=#FFFFFF onLoad='window.focus()'><i>Loading...</i></body></html>";
}

function GMGetPath() {
	var query = location.toString();
    var path = query.split("/");
    var path = path[0] + "//" +  path[2];
    return path;
}

function GMOpenWindow(url, windowName)
{
	if (!windowName)
	{
		windowName = "remote";
	}
	
	// detects the resolution of the screen, then sets the pop up window's height accordingly.
	var myHeight = 0;	
	if (screen.width >800)
	{
        // User has more than 800 pixels screen width.
        myHeight = 600;        
    }
    else
    { 
        // User has smaGM screen width.
        myHeight = 480;
    }

	var win = window.open("about:blank", windowName, "toolbar=yes,status=yes,scroGMbars=yes,resizable=yes,width=690,height=" + myHeight + ",left=yes,top=yes");
	if (navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.charAt(0) >3) 
	    win = win.open("javascript:opener.genPleaseWaitPage(\"" + url + "\",'" + windowName + "')", windowName);
	else
	    win = window.open("javascript:opener.genPleaseWaitPage('" + url + "','" + windowName + "')", windowName);

	if (top.name == "remote")
	{
		opener.top.remoteWindow = win;
	}
	else
	{
		top.remoteWindow = win;
	}
}

function GMAddToFavorites(functionid) {
    GMOpenWindow("/GM/ModifyFavoritesServlet?operation=Add&functionid=" + functionid, "remote");   
}

// new open window function for content provider to define the window's size 
var win = new Object();
            
function GMOpenPopUpWindow(url, width, height) {
    var windowName = "remote";
                            
	if (!width)
	    width = "819";
    else {
        if (screen.width <=800 && width > 790 )  
            width = 790;
    }
                                    
    if (!height) {
                                        	    
	    // detects the resolution of the screen, then sets the pop up window's height accordingly.
	    if (screen.height > 600)
            height = 600;        
        else
            height = 480;
	}
	else {
	    if (screen.height <= 600 && height > 480) 
	        height = 480;
	}
	
	if (window.name == "contentMain")
	    window.location = url;
	 
	else{

	    var win = window.open("about:blank", windowName, "toolbar=yes,status=yes,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height + ",left=yes,top=yes");
    	
	    // resize the window.
	    // it is set for IE. Nescape wiGM auto resize the window if width or height is not same as previous one.
	    win.resizeTo(width, height);
    	
	    if (navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.charAt(0) >3) 
	        win = win.open("javascript:opener.genPleaseWaitPage('" + url + "')", windowName, "toolbar=yes,status=yes,scroGMbars=yes,resizable=yes,width=" + width + ",height=" + height + ",left=yes,top=yes");
	    else
	        win = window.open("javascript:opener.genPleaseWaitPage('" + url + "')", windowName, "toolbar=yes,status=yes,scroGMbars=yes,resizable=yes,width=" + width + ",height=" + height + ",left=yes,top=yes");
	}    
}