
/**
 * Open a modal dialog window.
 * @param url The url for the new window to display.
 * @param height The height of the new dialog window.
 * @param width The width of the new dialog window.
 * @return Handle to the new window.
 */
function openDialog(url, height, width) {
	var parametersStart = url.indexOf("?");
	var parameters = url.substring(parametersStart + 1, url.length);
	var parameterArray = parse(parameters);
	
	return window.showModalDialog(
		url, 
		parameterArray, 
		"unadorned:no; status:yes; center:yes;  dialogWidth:" + width + "; dialogHeight:" + height + "; resizable:yes; scroll:yes; help:no");
}

/**
 * Open a non-modal dialog window.
 * @param url The url for the new window to display.
 * @param height The height of the new dialog window.
 * @param width The width of the new dialog window.
 * @return Handle to the new window.
 */
function openWindow(url, height, width) {
	var parametersStart = url.indexOf("?");
	var parameters = url.substring(parametersStart + 1, url.length);
	var parameterArray = parse(parameters);
	
	return window.open(
		url,
		"_blank", 
		"height=" + height + ",width=" + width + ",location=no,directories=no,menubar=no,status=no,titlebar=no,toolbar=no");  
}

function parse(parameters) { 
    var values = parameters.split("&"); 
    var out = new Object; 
    for (i=0; i<values.length; i++) { 
		var keyv = values[i].split('='); 
        out[keyv[0]]=keyv[1]; 
    } 
    return out; 
} 

function combine(items) { 
    var out = ""; 
    for (i in items) { 
       if (out != '') out += '; '; 
       out += i + "=" + items[i]; 
    } 
    return out; 
} 

// _______________________________________________________________
var NO_MSG = 0;
var ERROR_CODING = 1
var ERROR_SENDING_EMAIL = 2;
var ERROR_RETRIEVING_CONTACT_INFO = 3;
var SUCCESS_SENDING_EMAIL = 51;

function displayStatus(returnValue) {
//	alert ("displayStatus: returning message for: " + returnValue); 
	switch (returnValue) {
		case 0: return "";
		case 1: return "Code Error: Please contact the webmaster and try again.";
		case 2: return "Error: Message not sent. Please try again.";
		case 3: return "Error: Contact information for member could not be retrieved.  Please try again.";
		case 51: return "Message successfully sent";
		default: return "";
	} 
}

function closeDialog(returnValue) {
//	alert ("closeDialog: returning: " + returnValue);
	window.returnValue = returnValue;
	window.close();
}    

function getDialogFeatures(dialogWidth, dialogHeight, resizable) {
	return "dialogWidth: " + dialogWidth + "px;dialogHeight: " + dialogHeight + 
		   "px;status: no;unadorned: yes;scroll: no;help: no;" + 
		   (resizable ? "resizable: yes;" : "");
}

// Usage Example.
// var retValue indow.showModalDialog("SomePage?id=" + id, "", GetDialogFeatures(500, 240, false));    
// if (retValue)
// window.location.reload(true);   


