
/**
 * this function will bring up a calendar window to select a given date
 * @param obj an object that is used to place the pop up window
 * @param target the variable that is to be set, e.g. myform.myelement.value
 */
function drawCalendar(obj, target) {
	myWindow = window.open("/includes/calendar.jsp?formTarget=" + target, "tinyWindow", 
		"width=300,height=300, left=" + (findPosX(obj) - 100 + window.screenLeft) + ", top=" + (findPosY(obj) - 100 + window.screenTop + 
		"screenX=" + (findPosX(obj) - 100 + window.screenLeft) + ", screenY=" + (findPosY(obj) - 100 + window.screenTop))); 

	return myWindow;
}

/**
 * this function will bring up a selection window to choose a resource
 * @param obj an object that is used to place the pop up window
 * @param target the variable that is to be set, e.g. myform.myelement.value
 * @param resourceID the resource that the tree will display from
 * @param mode how the resource will be returned, options are LINK or ID

<form name=test>
<input type=text name="myfield" readonly size=20 maxlength=100>
			<a href="javascript:win = drawResourceSelection(this, 'test.myfield.value', <%=hdrResourceID%>, 'LINK'); win.focus();"><img border=0 src='/images/lists/ModuleID_30.gif'></a></td>
</form>

 */
function drawResourceSelection(obj, target, resourceID, mode) {
	myWindow = window.open("/includes/resourceSelection.jsp?resourceID=" + resourceID + "&formTarget=" + target + "&resourceSelectMode=" + mode, "tinyWindow", 
		"toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=450, left=" + (findPosX(obj) - 100 + window.screenLeft) + ", top=" + (findPosY(obj) - 100 + window.screenTop + 
		"screenX=" + (findPosX(obj) - 100 + window.screenLeft) + ", screenY=" + (findPosY(obj) - 100 + window.screenTop))); 

	return myWindow;
}

function fileBrowserCallBack(field_name, url, type, win) {
    var fileBrowserWindow = new Array();
    fileBrowserWindow['title'] = 'File Browser';
    fileBrowserWindow['file'] = "/includes/resourceSelection.jsp" + "?type=" + type + "&resourceSelectMode=" + type;
    fileBrowserWindow['width'] = '420';
    fileBrowserWindow['height'] = '400';
    fileBrowserWindow['close_previous'] = 'no';
    tinyMCE.openWindow(fileBrowserWindow, {
	window : win,
	input : field_name,
	resizable : 'yes',
	inline : 'yes'
    });
    return false;

}

/**
 * this function will bring up a selection window to choose a database field
 * @param obj an object that is used to place the pop up window
 * @param target the variable that is to be set, e.g. myform.myelement.value
 * @param resourceID the resource that the tree will display from

<form name=test>
<input type=text name="myfield" readonly size=20 maxlength=100>
			<a href="javascript:win = drawResourceSelection(this, 'test.myfield.value', <%=hdrResourceID%>); win.focus();"><img border=0 src='/images/lists/ModuleID_30.gif'></a></td>
</form>

 */
function drawDBFieldSelection(obj, target, resourceID) {
	myWindow = window.open("/includes/tableFieldSelection.jsp?resourceID=" + resourceID + "&formTarget=" + target, "tinyWindow", 
		"toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=450, left=" + (findPosX(obj) - 100 + window.screenLeft) + ", top=" + (findPosY(obj) - 100 + window.screenTop + 
		"screenX=" + (findPosX(obj) - 100 + window.screenLeft) + ", screenY=" + (findPosY(obj) - 100 + window.screenTop))); 

	return myWindow;
}

/**
 * launches a window to display the image that is passed in
 * @param url the url to the image that is to be displayed
 * @param width the width of the window
 * @param height the height of the window
 */
function displayImage(obj, url, width, height) {
	myWindow = window.open("/modules/utility/imageDisplay.jsp?image=" + url, "", 
		"toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + ", left=" + (findPosX(obj) - 100 + window.screenLeft) + ", top=" + (findPosY(obj) - 100 + window.screenTop + 
		"screenX=" + (findPosX(obj) - 100 + window.screenLeft) + ", screenY=" + (findPosY(obj) - 100 + window.screenTop))); 
}

function swapImage(imageName, image) {
    document.images[imageName].src = image.src;
}


function popUp(URL, params) {
    day = new Date();
    id = day.getTime();
    window.open(URL + "?" + params, "", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=550,left=0,top=0");
}

function newWindowPopup(myLink) {
	window.open(myLink,'Images','width=780,height=600,resizable=yes,scrollbars=yes');
}

function checkAll(selector, checkbox) {
    //alert(form + ", " + checkbox);
    if (!checkbox) {
	return;
    }

    for (i = 0; i < checkbox.length; i++) {
	checkbox[i].checked = selector.checked;
    }
}

/**
 * AJAX Calls
 */
function makeRequest(url, method) {
    var http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	http_request = new XMLHttpRequest();
	if (http_request.overrideMimeType) {
	    http_request.overrideMimeType('text/xml');
	    // See note below about this line
	}
    } else if (window.ActiveXObject) { // IE
	try {
	    http_request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	    try {
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (e) {}
	}
    }

    if (!http_request) {
	alert('Giving up :( Cannot create an XMLHTTP instance');
	return false;
    }

    if (method == null) {
	method = function() { alertContents(http_request); };
    }

    http_request.onreadystatechange = method;
    http_request.open('GET', url, true);
    http_request.send(null);

}

function alertContents(http_request) {

    if (http_request.readyState == 4) {
	if (http_request.status == 200) {
	    alert(http_request.responseText);
	} else {
	    alert('There was a problem with the request.');
	}
    }

}
