﻿/****	---------- Menu navigation animation script --------------
*****	Note: this script is different from the script located at 
*****	/z-omniupdate/menu/cssverticalmenu.js
*****	This script does not contain the offset and uses the visibility
*****	instead of the display css keyword due to ghosts appearing in IE 7.0
*****	when display is used.
*****/	
var menuids=new Array("verticalmenu") //Enter id(s) of UL menus, separated by commas
var targetMenu = null;

function createcssmenu(){
	for (var i=0; i<menuids.length; i++){
		var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
	    for (var t=0; t<ultags.length; t++){
		    var spanref=document.createElement("span");
		    spanref.className="arrowdiv";
		    spanref.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;";
                    var aTag = ultags[t].parentNode.getElementsByTagName("a")[0];
                    if (aTag.offsetHeight > 32) {spanref.style.margin = "-13px 0 0 0";}
                    aTag.appendChild(spanref);
		    	
		    /* create onmouseover, onmouseout functions */
		    ultags[t].parentNode.onmouseover=function() {
                        this.getElementsByTagName("ul")[0].style.visibility = "visible";
                        //targetMenu = this.getElementsByTagName("ul")[0];
                        //setTimeout("show()", 200);
                    }
		    ultags[t].parentNode.onmouseout=function() {
                        this.getElementsByTagName("ul")[0].style.visibility = "hidden";
                        //targetMenu = this.getElementsByTagName("ul")[0];
                        //setTimeout("hide()", 200);		    
                    }
	    }
	}
}

function show() {
    targetMenu.style.visibility='visible';
}

function hide() {
    targetMenu.style.visibility='hidden';
}

if (window.addEventListener)
window.addEventListener("load", createcssmenu, false)
else if (window.attachEvent)
window.attachEvent("onload", createcssmenu)
// ----------END menu navigation animation script ---------------

// ---------- General AJAX API ------------
/**
 * This function initializes the xmlHttp global variable.  Applies a singleton
 * design pattern approach to this object.
 */
function initxmlHttp() {
	var xmlHttp = null;
	try {
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		try {
			xmlHttp = new ActiveXObject("Mxsml2.XMLHTTP");
		}
		catch(e) {
			try{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				alert("Browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

/**
 *	Performs an ajax call passing the input parameter as a POST request.
 */
 /* not functional at this moment
function ajaxpost(url, parameters, cbFunction) {
	// initialize a new xmlHttp object
	initxmlHttp();
	
	// define Ajax callback function
	xmlHttp.onreadystatechange = cbFunction;
		
	// open POST connection
	xmlHttp.open("POST", url, true);
	
	// define POST headers
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	// send Ajax call
	xmlHttp.send(parameters);
}
*/
/**
 *	Performs an ajax call passing the input parameter as a GET request.
 */
function ajaxget(url, parameters, cbObject) {
	// initialize a new xmlHttp object
	var xmlHttp = initxmlHttp();
	cbObject.xhrObject = xmlHttp;
	
	// define Ajax callback function
	xmlHttp.onreadystatechange = function() {
		cbObject.cbFunction(cbObject);
	}
		
	// open GET connection
	xmlHttp.open("GET", url + "?" + parameters, true);
	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	
	// send Ajax call
	xmlHttp.send(parameters);
}


//  ----------------  END General AJAX functions -------------------


/**
 	requestOpportunities
	Performs an AJAX call to the server to retrieve opportunity data from the database.
	
	Param id - id of the division to write the ouput of the script to
	Param sub - subcategory to display
*/
function requestOpportunities(sub, id) {
	var cbObject = new Object();
	cbObject.div_id = id;
	cbObject.cbFunction = displayxhrtoDiv
	var subcategory = "subcategory=" + sub;
	ajaxget("http://medschool.umaryland.edu/osr/scripts/getOpportunities.asp", subcategory, cbObject);
}

/**
	requestAnnouncements
	Performs an AJAX call to the server to retrieve announcements from the database
	
	Param page - page that the announcements are requested for.
	Param id - id of the division to write the output to
*/
function requestAnnouncements(page, id) {
	var cbObject2 = new Object();
	cbObject2.div_id = id;
	cbObject2.cbFunction = displayxhrtoDiv;
	ajaxget("http://medschool.umaryland.edu/osr/scripts/getAnnouncements.asp", "page="+page, cbObject2);
}

function requestMontlyOpportunity(month, id) {
	var cbObject = new Object();
	cbObject.div_id = id;
	cbObject.cbFunction = displayxhrtoDiv;
	ajaxget("http://medschool.umaryland.edu/osr/scripts/getMonthlyOpportunities.asp", "month="+month, cbObject);
	return false;
}

/** 
	Helper function to display the response text of an AJAX request to a div determined
	by the cbObj.div_id.
	
	param cbObj - call back object created in the original function to hold this function,
					the XHR object and the div id to write the data to.
*/
function displayxhrtoDiv(cbObj) {
	var div = document.getElementById(cbObj.div_id);
	var xhrObj = cbObj.xhrObject;
	if (xhrObj.readyState == 4 && xhrObj.responseText.length > 0) {
		div.innerHTML = xhrObj.responseText;
	}
}


/**
	Helper function to expand/contract a menu.
*/
function expand(id) {
	var ele = document.getElementById(id.toString() + '_content');
	var link = document.getElementById(id.toString() + '_link');
	if (ele.style.display == 'none') {
		ele.style.display = 'block';
		link.src = "/osr/images/collapse.jpg";
	} else {
		ele.style.display = 'none';
		link.src = "/osr/images/expand.jpg";
	}
	
	return false;
}	





















