//*****************************************************************************
//INDEX of public functions
//	- openWindow
//	- openChromelessWindow
//	- convertCharacters
//*****************************************************************************

var NFW = null

function openWindow(windowUrl, windowTitle, windowWidth, windowHeight, windowX, windowY, forcescrolling) {
	//Description:	Opens a new browser window without the toolbars on the desired location in the given measurements.
	//Parameters:	windowUrl		The URL to open in the new window
	//				windowTitle		The title of the new window
	//				windowWidth		The width of the new window
	//				windowHeight	The height of the new window
	//				windowX			The x-coordinate of the new window
	//				windowY			The y-coordinate of the new window

	var autoclose = true  // Set autoclose to true if the popup should close upon leaving the launching page; else, false
	var scrolling = ""

	windowX = Math.ceil( (window.screen.width - windowWidth) / 2 );
	windowY = Math.ceil( ((window.screen.height - windowHeight) / 2) - 100 );
	if (windowY < 0 ) {
		windowY = 0;
	}

	if (forcescrolling)
		scrolling = ", scrollbars=1";
    
	if (document.all)
		attribs = "toolbar=none" + scrolling + ", resizable=yes, status=1, width=" + windowWidth + ", height=" + windowHeight + ", left=" + windowX + ", top=" + windowY
	else
		attribs = "toolbar=none, scrollbars=1"
		
	NFW=window.open(windowUrl, windowTitle, attribs)
	//NFW.blur()
	//NFW.resizeTo(windowWidth, windowHeight)
	//NFW.moveTo(windowX, windowY)
	//NFW.title = windowTitle
	//NFW.focus()

	/*
	if (autoclose){
		window.onunload = function(){if(NFW){NFW.close()}}
	}
	*/
}

function removeRequestVariable(url, str){
    //returns requestString or URL without the given variable in the request string.
    //Example http://localhost/test.asp?example=1&test=2 --> example --> http://localhost/test.asp?test=2
        
    var urlArr = url.split("?");
    var newUrl = urlArr[0]
    if (urlArr.length > 1){
        var varArr = urlArr[1].split("&");
        var newVarArr = new Array();
        for (var i = 0; i < varArr.length; i++){
            variable = varArr[i].split("=")[0];
            if (variable != str){
                newVarArr.push(varArr[i]);
            }
        }
        if (newVarArr.length > 0)
           newUrl = urlArr[0] + "?" + newVarArr.join("&")
    }
    return newUrl
}

function addRequestVariable(url, str){
	if (url.indexOf("?") > 0){
		return url += "&" + str
	}
	else{
		return url += "?" + str
	}
}

function cleanUpRequest(url){
    url = removeRequestVariable(url ,"sort")
    url = removeRequestVariable(url ,"action")
    url = removeRequestVariable(url ,"parentrefresh")
    url = addRequestVariable(url ,"parentrefresh=true")
    return url
}

function parentRefresh(){
    if (window.opener && !window.opener.closed){
        if (window.opener.refreshable){
	        window.opener.location = cleanUpRequest(window.opener.location + "")
        }
    }
}
