var mouseX = mouseY =0;
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

/* ------------------------------------------------------------------------------------------------------------------------------- */
/*  THIS IS VERY IMPORTANT FUNCTION FOR THE COMPLETE SITE TO WORK PROPERLY */
/* ------------------------------------------------------------------------------------------------------------------------------ */

function getelm(thisid){
    try{
	var thiselm = null;
               if (document.getElementById) {
                             // browser implements part of W3C DOM HTML ( Gecko, Internet Explorer 5+, Opera 5+                      
					   thiselm = document.getElementById(thisid);
			     	}
					
                else if (document.all){ 
				 // Internet Explorer 4 or Opera with IE user agent
                 thiselm = document.all[thisid];
              }
						
                else if (document.layers){ // Navigator 4
                    thiselm = document.layers[thisid];
                }

	if(thiselm)	{	
				if(thiselm == null) { return; }
				else {return thiselm;}
			}
	}
	catch(ex){
	    return null;
	}
}

/* ---------------------------------------------------------- */
function setFocus(){
    var content = getelm('content');
   try{ 
        if(content){
          //   content.focus();
        } 
   } 
   catch(ex){}
}
//--------------------------------------------------------------
function Page_Load(destelm){
    try{
            var elm = getelm(destelm);
            var contentelm = getelm('wrapper'); 
            if(elm && contentelm){
                process(elm.value, contentelm);
            } 
    }
    catch(ex) {alert(ex)}
}
//-----------------show/ hide main side menu items -------------------------------------
function showmenu(item){
    try{
        var submenu = getelm('_' + item);
          
           hide_inactive_menu(submenu);
             
          if(submenu){
            switch(submenu.className) {
             case 'submenu_show':
                 submenu.className = 'submenu';     
                break    
             case 'submenu':
                 submenu.className = 'submenu_show';     
                break            
               default:
                //alert(submenu.className)
                break   
            }
       }             
    }
    catch(ex){
             alert(ex)
    }
}
// set global variables for sub menu items
 var submenu_items  = '_fav,_eval,_info,_survey'; // add any submenu items here when required

// the following function handles hiding inactive sub menus (those were opened earlier)
function hide_inactive_menu(active_menu){
        //alert(active_menu.id + ' // ' +  submenu_items)
       var aSubMenu = submenu_items.split(",");
       
       if(active_menu){
            for (var i=0; i<aSubMenu.length; i++){
             // loop through each submenu item and comapre it with active menu
                var curSubMenu = getelm(aSubMenu[i]);
             //  alert(i + ' -- ' + curSubMenu + ' // ' + aSubMenu[i])  
                if(curSubMenu){                 
                     if (curSubMenu.id != active_menu.id){
                        // if the current loop item is not equal to active menu then hide it
                        curSubMenu.className = 'submenu';
                     }
                }          
            }
       } 
}
//-------------------------------- set HTML from source to target ----------------------
function setView(source){
       window.location.href = '/gateway/' + source;      
   }
/*------------------------------------------------------------- */
function showcite(obj, citeid){
  try{
  //function to display citation information for each report link
  //get all the cite elements and set the display as none
   
   var allcites = document.getElementsByTagName('cite');  
    for (i=0; i<allcites.length; i++){         
        allcites[i].className='hide';
    }
   // now get the current cite element and only show this one 
    var citeelm=getelm(citeid);
 //  citeelm.onmouseover = getMouseXY;
   
  // only show cite element if any content is set  
   if(citeelm){     
      if(citeelm.innerHTML.length > 0){ 
        if(!isIE){
                    citeelm.style.top = (mouseY + 10) + 'px';
                 //  citeelm.style.right = (mouseX + 100) + 'px'; //getOffsetHeight(citeelm) + 'px';
                    citeelm.className = 'show'; 
                }
           else { citeelm.style.top = '120px'; citeelm.className = 'show'; } 
          } 
        else {citeelm.className ='hide';}
   } 
   // hide the cite element after a delay = 12 sec
  window.setTimeout("hidecite('"+ citeid +"')", 15000);
 }
    catch(ex){}  
}
/*------------------------------------------- */
function hidecite(citeid){
  //function to display citation information for each report link
  //get all the cite elements and set the display as none
    var allcites = document.getElementsByTagName('cite');  
      for (i=0; i<allcites.length; i++){         
            allcites[i].className='hide';
         }
  }
/*------------------------------------------------------------- */
function showhideElm(id, disp){
	var elm = getelm(id);                              
        if (elm.style){
		    if(disp == 'show') {  elm.style.display='block'; }
		    else {elm.style.display='none';}
		}
	return true;
	}
/*------------------------------------------------------------- */
function showhideImg(id, disp){
	var  id = id;
	var disp = disp;
          // move the element with id to x,y . Where x,y are the horizontal  nd vertical position in pixels
        var elm = getelm(id);
                               
     		if (elm.style){
					if(disp == 1) { elm.style.visibility='visible'; 	}
					else {	elm.style.visibility='hidden';		}
					}
		return true;
	}
/* ---------------------------------------------------------- */
function imgOn(imgName, imgLoc) {
		        if (document.images) {
					onImg = new Image();
					onImg.src = '/images/' + imgLoc;
					var imgObj =  'document.' + imgName;
		            eval(imgObj).src =  onImg.src;
				//	alert(onImg.src)
		        }
		}
function imgOff(imgName, imgLoc) {
		        if (document.images) {
					offImg = new Image();
					offImg.src = '/images/' + imgLoc;
					var imgObj =  'document.' + imgName;
 			          eval(imgObj).src = offImg.src;
		        }
		}
//=============================================
function getGoogleSearch(){
	var qtext = document.SearchSite.q.value;	
	// set the query text so that the search results are from planning site only
		document.SearchSite.q.value = qtext + ' '+ "site:planning.iupui.edu";
		document.SearchSite.submit();
	}
	
/* ----------------------------------------------------------- */
function break_out_of_frames() {
	if (parent.frames.length > 0) {parent.location.href = self.document.location;}
}

/* ----------------------------------------------------------- */
function PageLastUpdated() {
	if (document.lastModified){	document.write("Page Last Updated: " + document.lastModified + "  (IMIR Web Team)");}
}

/* ----------------------------------------------------------- */
function getlink() {
	var elmlist = getelm('linklist');
	if(elmlist){	var linkurl = elmlist.value;
		window.location.href=linkurl;	
	}
	else{return;}
//	linkurl = document.frmSiteSearch..options[document.sitequicklinks.linkslist.selectedIndex].value;

}
/* ----------------------------------------------------------- */
function OpenWindow(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=yes,width=675,height=375,left = 100,top = 100');");
}
/* ----------------------------------------------------------- */
function closewindow(){
//alert
oWindow = window.parent.close(); 
}
/* ----------------------------------------------------------- */

function screenObject()	{
	this.bottom = function(){
		if (document.body.scrollHeight) return document.body.scrollHeight};
	
	this.height = function() {
		if (document.body.offsetHeight) return document.body.offsetHeight;}
	
	this.visHeight = function() {
		if (window.innerHeight) return window.innerHeight;
		if (document.body.clientHeight) return document.body.clientHeight;}
	
	this.width = function() {
		if (document.body.offsetWidth) return document.body.offsetWidth;}
	
	this.scrollTop = function() {
		if(document.body.scrollTop) return document.body.scrollTop
		if (window.pageYOffset) return window.pageYOffset;
		else return 0;};
	}
/* -------------------------------------------- */
/* -------------------------------------- */
function getMouseXY(e) {
try{
  if (isIE) { // grab the x-y pos.s if browser is IE
    tempX =  document.body.scrollLeft;
    tempY =  document.body.scrollTop+ document.body.offsetHeight;
  
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}   
    mouseX = tempX;  mouseY = tempY;
  return true
 }

catch(ex) {}
 
}


// ----------------------------------------------------------   
 function getOffsetHeight(elm) {
            var h = Number.NaN;
             if (elm && typeof elm.offsetHeight != 'undefined') {
                        h = elm.offsetHeight;
                    }
            return h;
        }
 //---------------------------------------------- 
// these first two functions are using fixed parameters for the names
// and number of columns, these can be used for a layout where number of colums are known and limited
// www.candsdesign.co.uk/articles/dhtml/layout/same-height-columns/same-height/
function getmax_h() {
    colLength = new Array(1);
	colLength[0] = getelm('left').offsetHeight;
	colLength[1] = getelm('content').offsetHeight;
	colLength.sort(sortNumeric);
	colLength.reverse();
	return colLength[0];
}
//--------------------------------------------------
function setMenuHeight() {
	divLen = getmax_h();
	//alert(divLen)
	getelm('left').style.height = divLen -8 +"px";
	getelm('content').style.height = divLen+"px";	
}
//-------------------------------------------------
function sortNumeric(a,b){
return a - b
}
//------------------------------------------------
function getLongest(wrapper_elm) {
	parentDiv = getelm(wrapper_elm);
	cols = parentDiv.getElementsByTagName("div"); 
	colLength = new Array(cols.length);
	for (x=0; x < cols.length; x++) {
		colLength[x] = getelm(cols[x].id).offsetHeight;
	}
	colLength.sort(sortNumeric);
	colLength.reverse();
	return colLength[0];
}
//--------------------------------------------------
function setColumns(wrapper_elm) {
	divLen = getLongest(wrapper_elm);
	parentDiv = getelm(wrapper_elm);
	cols = parentDiv.getElementsByTagName("div"); 
	for (x=0; x < cols.length; x++) {
	    getelm(cols[x].id).style.height = divLen+"px";
	}
} 
 // ------------------------------------------------------------------      
function displayFix()	{
	//in IE there is a bug will cause some elements to not draw on screen when the user uses the back button
	//the below fixes that problem by forcing the page to redraw
	    document.getElementById("PAII").style.display = "block"
	}	
//END