function fnAjax(url, outputElement, customFunction){
var request = false;
   try {
     request = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }  
     }
   }
 qstr = (url.indexOf("?") >= 0) ? "&" : "?";
 var url = url + qstr + "rnd=" + Math.random();
 request.open("GET", url, true);
   if(typeof(customFunction) == "function") {
		//allows custom function to be passed. Passes request object back to function.
		request.onreadystatechange = function() {
		  if (request.readyState == 4) {
			 if (request.status == 200) {
				customFunction(request);	
			 }
		  }
		}
	} else {
		request.onreadystatechange =    function updatePage() {
		  if (request.readyState == 4) {
			 if (request.status == 200) {
				var response = request.responseText
			 if(outputElement!=null){
				$(outputElement).innerHTML = response;
			 }
			} 
		  }
		}
	}
 request.send(null);
}

function switchSearch(){
var request = false;
   try {
     request = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }  
     }
   }
 var url = "/departmental_content/content/search/switchsearch.asp?rnd=" + Math.random();
 request.open("GET", url, true);
		request.onreadystatechange =    function updatePage() {
		  if (request.readyState == 4) {
			 if (request.status == 200) {
				var sresponse = request.responseText;
				 if(sresponse=='google'){
					//$('search_input').value = 'Search Google';
					$('search_input').style.background=" #FFFFFF right url('/departmental_content/images/search/google_custom_search_watermark.gif') no-repeat";
					$('headerSearchForm').setAttribute('action', '/departmental_content/content/search/index.asp');
			 		}
		  		}
			}
		}
 request.send(null);
}
switchSearch();

function flashOpen(URL,windowName,windowProperties){
	newWindow=window.open(URL,windowName,windowProperties);
}

function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';				 
  } else {
     dark.style.display='none';
  }
}

function toggle() {
	for ( var i=0; i < arguments.length; i++ ) {
		$(arguments[i]).style.display = ($(arguments[i]).style.display != 'none' ? 'none' : '' );
	}
}

function hide() {
	for ( var i=0; i < arguments.length; i++ ) {
		$(arguments[i]).style.display = 'none';
	}
}

function show() {
	for ( var i=0; i < arguments.length; i++ ) {
		$(arguments[i]).style.display = '';
	}
}

function showNext(elm) {
		elm = elm.nextSibling;
		while (elm) {
			if(elm.nodeType == 1) {
		 		if(elm.style.display == "") {
					elm.style.display = "none";
				} else {
					elm.style.display = "";
				}
				break;
			} else {
				elm = elm.nextSibling;
			}
		}
	}




function insertAfter( referenceNode, newNode, newText, newId ){ 
        var newNode=document.createElement(newNode);
		newNode.innerText=newText;
		newNode.setAttribute('id',newId)
		newNode.setAttribute('name',newId)
		referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
}

function Left(str, n)
{
		if (n <= 0)     // Invalid bound, return blank string
				return "";
		else if (n > String(str).length)   // Invalid bound, return
				return str;                // entire string
		else // Valid bound, return appropriate substring
				return String(str).substring(0,n);
}

function Right(str, n)
{
		if (n <= 0)     // Invalid bound, return blank string
		   return "";
		else if (n > String(str).length)   // Invalid bound, return
		   return str;                     // entire string
		else { // Valid bound, return appropriate substring
		   var iLen = String(str).length;
		   return String(str).substring(iLen, iLen - n);
		}
}

function InStr(strSearch, charSearchFor)
{
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}

function Mid(str, start, len)
{
		// Make sure start and len are within proper bounds
		if (start < 0 || len < 0) return "";

		var iEnd, iLen = String(str).length;
		if (start + len > iLen)
				iEnd = iLen;
		else
				iEnd = start + len;

		return String(str).substring(start,iEnd);
}

function Len(str)
{  
		return String(str).length;  
}

function centerScreen(obj) {
	obj = $(obj);
	// get viewable window dimensions
	if (self.innerHeight) // !IE
	{
		xwin = self.innerWidth;
		ywin = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // IE6
	{
		xwin = document.documentElement.clientWidth;
		ywin = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		xwin = document.body.clientWidth;
		ywin = document.body.clientHeight;
	}
	//SCROLL POSITION
	var xscroll, yscroll;
	if (self.pageYOffset) { // !IE
	
		xscroll = self.pageXOffset;
		yscroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) { // IE6
		xscroll = document.documentElement.scrollLeft;
		yscroll = document.documentElement.scrollTop;
	} else if (document.body) {
		xscroll = document.body.scrollLeft;
		yscroll = document.body.scrollTop;
	}
	//GET ELEMENT HEIGHT, WIDTH
	myW = obj.offsetWidth;
	myH = obj.offsetHeight;
	
	//POSITION ELEMENT
	if(isIE && obj.parentNode.style.position == "relative") obj.parentNode.style.position = "";
	obj.style.position = "absolute";
	obj.style.top = ((ywin / 2 - myH / 2) + yscroll - 30) + "px";
	obj.style.left = ((xwin / 2 - myW / 2) + xscroll) + "px";
}
	
function removeElement(id)	
{
	var Node = document.getElementById(id);
	Node.parentNode.removeChild(Node);
}

function modClass(a,o,c1,c2)
{
  switch (a){
    case 'swap':
      o.className=!modClass('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
    break;
    case 'add':
      if(!modClass('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}
