/**********************************************************************************/
function launchWindow(strURL, strName, intWidth, intHeight, strProperties) 
{
	// just create a window with the given properties and don't return the handle
	// to the window. (for inline javascript: calls in hrefs)
	var w = createWindow(strURL, strName, intWidth, intHeight, strProperties);
	// make sure created window has focus. In case a popup profile was in background
	// or minimized, bring it to front.
	w.focus();
}

function createWindow(strURL, strName, intWidth, intHeight, strProperties)
{
	var mywin;
	var intVersion;
	var dummyDate = new Date(); 
	
	var strPoundURL;
	var intPoundPos;

	intVersion = navigator.appVersion.substring(0,1);
	if (strURL != "") 
	{
		intPoundPos = strURL.indexOf("#");
		if (intPoundPos != -1) {
			strPoundURL = strURL.substring(intPoundPos);
			strURL = strURL.substring(0, intPoundPos);
		}
			
		if (strURL.indexOf("?") != -1) { 
			strURL = strURL + "&rnd="
		} else {
			strURL = strURL + "?rnd="
		}
			
		strURL = strURL + dummyDate.getTime();
		
		if (strPoundURL != null)
		{
			strURL = strURL + strPoundURL;
		}
			
		strURL = Replace(strURL,"@","%40");
	}
	
	if (strProperties == "") {
		strProperties = "scrollbars=yes,resizable=yes,menubar=no,location=no,directories=no,toolbar=no";
	}
	
	strProperties = "status=yes,height=" + intHeight + ",width=" + intWidth + "," + strProperties;

	// replace all non-alphacharacters with X
	if(strName.replace)
		strName = strName.replace(/\W/g,"X");
	
	// lower case the string
	strName = strName.toLowerCase();
	
		//try to open a pop-up window
		mywin = window.open(strURL, strName, strProperties);


		// POP-BLOCKER OVERRIDE SECTION
		// try to load the link in the current window, unless this is a view profile request from IM.
		// If it is a view profile request from IM, try to show the profile in window.opener or else give up
		if(mywin==null)//i.e., pop-up blocker
		{		
			mywin = self; // set to self so we don't return null reference
			
			// We are changing the template here to show nav and header 
			// since we can't open a pop-up window
			strURL = strURL.replace("LayoutTemplateID=2", "LayoutTemplateID=1");
			strURL = strURL.replace("LayoutTemplateID=4", "LayoutTemplateID=8");
			strURL = strURL.replace("LayoutTemplateID=11", "LayoutTemplateID=1"); //Open profile in same window if popup blockers are enabled.
			
			// If the current window is an IM window, we will allow the popup blocker to notify the user that
			// the window couldn't be opened, otherwise, we load the link in the current window.
			if (window.location.href.indexOf("/upInstantCommunicator.aspx") == -1)
			{
				window.document.location = strURL;
			}
			else {
			// if this is an IM window request for a profile, check if window.opener is still open
				var IsWindowOpenerClosed = false;
				try
				{	//Attempt to access a property on the window.opener object
					//Using 'window.opener.closed' is not consistent on all browser implementations.
					var temp = window.opener.location.href;		
				}
				catch(e)
				{
					IsWindowOpenerClosed = true;
				}
				if (!IsWindowOpenerClosed) {

					//do not persist the layout template (bug: 15532) (or else all subsequent requests will have nav and header around them)
					strURL = strURL.replace("PersistLayoutTemplate=1", "")
					window.opener.location = strURL;
				}
				else {
					//do nothing. let the pop-up blocker work TODO: resource in other languages
					//alert("to view member's profile requires pop-up blocker to be disabled.");
				}
			
			}
		}
		
	// return handle to caller
	return mywin;
}

/**********************************************************************************/
function Replace(str, substring, newstring) {
	if (str.length <= 0)
		return "";

	temp = "" + str; 

	while (temp.indexOf(substring)>-1) {
	pos = temp.indexOf(substring);
	temp = "" + (temp.substring(0, pos) + newstring + temp.substring((pos + substring.length), temp.length));
	}
	return temp;
}