/**
 * browser detection script
 *
 * This script is taken from http://www.quirksmode.org/js/detect.html
 * This script will need to be updated regularly in order for it to remain
 * effective. To update the script you need to either add or alter the object
 * literals found in the dataBrowser array literal.
 * 
 * author: ?
 * Date Implemented here April 17, 2010
 *
 **/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function fetchBlogPosts(numPosts,divID)
{
	 	var url = '/include/social/wordpress/GrabPosts.php?posts='+numPosts;
		//prompt("",url);
		new Ajax.Request(url,
		{
		method:'get',
		onSuccess: function(transport){
		 var response = transport.responseText || "no response text";
		 //prompt("",response);
		 //var theContent = $('centerInfo');
                 //var theContent = $(divID);
		 //theContent.update(response);
                 document.getElementById(divID).innerHTML = response;
		 fixUnderflow();
		},
		onException: function(transport, exception) {
		var ename = exception.name;
		var emsg = exception.message;
		//var theContent = $('centerInfo');
                var theContent = $(divID);
		theContent.update("ERROR: "+ename+", "+emsg);
		}
		});
		//prompt("","After the new Ajax.Request call");
}//end fetchBlogPosts.
function fetchNewsPost()
{
	 	var url = 'http://umanitoba.ca/include/social/wordpress/GrabNewsPost.php';	 	
		//prompt("",url);
		new Ajax.Request(url,
		{		
		method:'get',
		onSuccess: function(transport){
		 var response = transport.responseText || "no response text";
		 //prompt("",response);
		 var theContent = $('newsContent');		  
		 theContent.update(response);
		 //fixUnderflow();
		},
		onException: function(transport, exception) {
		var ename = exception.name;
		var emsg = exception.message;
		var theContent = $('newsContent');
		theContent.update("ERROR: "+ename+", "+emsg);
		}
		});
		//prompt("","After the new Ajax.Request call");
}//end fetchBlogPosts.
function ajaxRequest(url,divID)
{
	//prompt("",url + "          " + divID);	
	new Ajax.Request(url,
	{		
		method:'get',
		onSuccess: function(transport){
		 //prompt("","before var response");			  	
		 var response = transport.responseText || "no response text";
		 //prompt("",response);
		 var theContent = $(divID);		  
		 theContent.update(response);
                 fixUnderflow();
		},
		onFailure: function(){ alert('Something went wrong...'); },
		onException: function(transport, exception) {
		/**
		Of course, this handler will now only restrict its activities to TypeError exceptions. All other errors will be ignored.
		The JavaScript 1.5 specification defines six primary error types, as follows:		
		EvalError - raised when the eval() functions is used in an incorrect manner;		
		RangeError - raised when a numeric variable exceeds its allowed range;		
		ReferenceError - raised when an invalid reference is used;		
		SyntaxError - raised when a syntax error occurs while parsing JavaScript code;		
		TypeError - raised when the type of a variable is not as expected;		
		URIError - raised when the encodeURI() or decodeURI() functions are used in an incorrect manner; 
		excerpt from http://www.alise.lv/ALISE/technolog.nsf/0/53d693d7d1a4f198c2257066003d6153?OpenDocument
		**/
		var ename = exception.name;
		var emsg = exception.message;
		var theContent = $(divID);
		theContent.update("ERROR: "+ename+", "+emsg);
                fixUnderflow();
     	//prompt("",exception.message);
   		}
	});
	//prompt("","After the new Ajax.Request call");		
}//end ajaxRequest
/************************************************
 * getSearchPerson
 *
 * Used by the search function on some of the
 * templates. It is called to get the details of
 * a particular person that was found via the
 * search mechanism. It goes out gets the persons
 * details then inserts those details into the
 * associated div block.
 *
 * returns: void
 * params: pid, d, s
 * auth: Dave Cooke
 * date: Nov. 10, 2009
 */
function getSearchPerson(pid,d,s)
{
	var url = "http://umanitoba.ca/ip/dcooke/aaNewTemplateSearch/search2003_update_2009.php?pid="+pid+"&d=1&s=1";
	new Ajax.Request(url,
	{
		method:'get',
		onSuccess: function(transport){
		 var response = transport.responseText || url;
		 var theContent = $('fpDude');
		 theContent.update(response);
         $('fpRow').show();
		},
		onException: function(transport, exception) {
		var ename = exception.name;
		var emsg = exception.message;
		var theContent = $('fpDude');
		theContent.update("ERROR: "+ename+", "+emsg);
		}

	});
	//prompt("","After the new Ajax.Request call");
}//end search
/**

02 * Returns the value of the selected radio button in the radio group, null if

03 * none are selected, and false if the button group doesn't exist

04 *

05 * @param {radio Object} or {radio id} el

06 * OR

07 * @param {form Object} or {form id} el

08 * @param {radio group name} radioGroup

09 */

function $RF(el, radioGroup) {

     if($(el).type && $(el).type.toLowerCase() == 'radio') {

         var radioGroup = $(el).name;

         var el = $(el).form;

     } else if ($(el).tagName.toLowerCase() != 'form') {

         return false;

     }



     var checked = $(el).getInputs('radio', radioGroup).find(

         function(re) {return re.checked;}

     );

     return (checked) ? $F(checked) : null;

}

function searchTester()
{
    var buttonValue = $RF('frmSearch', 'search_type');
    //alert("buttonValue: "+buttonValue);
    if(buttonValue == 'people')
    {
         var kw = $('kw').value;
         alert("pre kw: "+kw);
         //kw = kw.replace("%5C%27","'");
         //alert("post kw: "+kw);
         var urls = "http://umanitoba.ca/include/search/search2003_update_2009.php?txtSearch=test&s=t&newSearch=t";
        // var parms = "{txtSearch:'"+kw+"',s:'t',newSearch:'t'}";
         //alert("parms: "+parms);
         searchPerson(urls);
    }//end if
}//end function
function searchPerson(url)
{
	var urlss = "http://umanitoba.ca/include/search/ajaxSearch.php?txtSearch=test&s=t&newSearch=t";
        //var urlss = "http://umanitoba.ca/include/search/testpage.php";
        alert("url: "+urlss);
        //var pars = Form.serialize('frmSearch',true);
        var divID = 'searchDisplay';
        //parameters: {company: 'example', limit: 12}

	new Ajax.Request(urlss,
	{
		method:'get',                
                onSuccess: function(transport){
		 var response = transport.responseText || "ahhhhhh I AM BROKEN!!";
                
		 var theContent = $(divID);
		 theContent.update(response);
                 //$('fpRow').show();
		},
                onFailure: function(){ alert('Something went wrong...'); },
		onException: function(transport, exception) {
		var ename = exception.name;
		var emsg = exception.message;
		var theContent = $(divID);
		theContent.update("ERROR: "+ename+", "+emsg);
		}

	});
	prompt("","After the new Ajax.Request call");
}//end search
function submitForm(divID)
{
	var url = "http://umanitoba.ca/include/form_handler.php";
	new Ajax.Request(url,
	{
		method:'get',
		onSuccess: function(transport){
		 var response = transport.responseText || url;
		 var theContent = $(divID);
		 theContent.update(response);
                 //$('fpRow').show();
		},
		onException: function(transport, exception) {
		var ename = exception.name;
		var emsg = exception.message;
		var theContent = $(divID);
		theContent.update("ERROR: "+ename+", "+emsg);
		}

	});
	//prompt("","After the new Ajax.Request call");
}//end search
/**
 * getTableHeights
 *
 * This function looks for any tables inside the given element
 * and, if found, tries to determine their heights.
 *
 * param: divID
 * returns: tableSize
 * author: Dave Cooke
 * date: April 17, 2010
 **/
function getTableHeights(divID)
{
    var listOfTables = $(divID).select('<table>');
    var tempSize = 0;
    for(var i = 0; i < listOfTables.length;i++)
    {
      tempSize = tempSize + listOfTables[i].getHeight();
    }//end for loop
    return tempSize;
}//end getTableHeights
function fixUnderflow()
{
   var midStuffHeight = 0;
   var leftNavHeight = 0;
   var rightColHeight = 0;
   var introHeight = 0;
   var highest = 0;
   var topTasksHt = 0;
   //var test = getTaskGroupHeight();
   //alert("determining section heights....");
   if((typeof(objIntro) != "undefined") && objIntro.ref)
   {

       introHeight = objIntro.getHeight();
       //alert("mid height is: "+midStuffHeight);
   }//end if
   if((typeof(objMidStuff) != "undefined") && objMidStuff.ref)
   {
       if((typeof(objTopTasks) != "undefined") && objTopTasks.ref)
       {
        topTasksHt = objTopTasks.getHeight();
       }//end inner if block
       //some tables heights will get picked up by getHeight() and others
       //do not, I have NO IDEA WHY!!! So this function will get the height
       //, its accuracy is debatable, of any tables contained in the specified
       //div.
       var tableHeights = getTableHeights('centerInfo');
       //alert("table height: "+tableHeights);
       midStuffHeight = objMidStuff.getHeight();
       //now add on the height of the center header area
       midStuffHeight = midStuffHeight + introHeight + topTasksHt;
       //ATTEMPTED FIX
       //so if tableHeights > midStuffHeight then I know that the table inside
       //the mid area did not get picked up by getHeight() so I add it in.
       //WARNING
       //this will not solve the case where the table is indeed smaller than
       //the rest of the content in the midStuff (centerInfo) area. In that
       //case, assuming that the table in question doesn't get detected by
       //getHeight(), the proper total page height will still come up short!
       //if(tableHeights > 0 && tableHeights > midStuffHeight)
       //{
         //alert("mid height: "+ midStuffHeight+", table height: "+tableHeights);
          //midStuffHeight = midStuffHeight + tableHeights;
       //}//end if
       
       //alert("browser: "+BrowserDetect.browser+", ver: "+BrowserDetect.version);
       //for some reason Prototype.js, more specifically the getHeight()
       //function, can't determine the height of any tables contained
       //inside an element. So I wrote a simple function to look for tables
       //in a given element and, if found, determine their heights.
       if(BrowserDetect.browser == "Explorer" && BrowserDetect.version == "7")
       {
            //add table height to the total height to account for bug in getHeight()
            //running on webpages displayed in IE7 or IE 8 compatibility mode.
            if(tableHeights > 0)
            {
                //alert('table heights: '+tableHeights);
                //midStuffHeight = tableHeights;
            }//end if
       }//end if
       else
       {
          //don't do anything, getHeight() can properly determine an objects
          //height on modern browsers just not in IE 7 or IE 8 Compatibility
          //mode.
          //midStuffHeight = midStuffHeight + tableHeights;
       }//end else.
       //alert("mid height is: "+midStuffHeight);
   }//end if
   if((typeof(objLeftNav) != "undefined") && objLeftNav.ref != "")
   {
        
       leftNavHeight = objLeftNav.getHeight();
       //alert("left height is: "+leftNavHeight);
   }//end if
   if((typeof(objRightBar) != "undefined") && objRightBar.ref)
   {
        
       rightColHeight = objRightBar.getHeight();
       //alert("right height is: "+rightColHeight);
   }
   if(midStuffHeight == 0 && leftNavHeight == 0 && rightColHeight == 0)
   {
        //do nothing.
        //alert("all columns are zero");
   }
   else
   {
       //alert("line 58");
       //since all three variables contain valid data then we set out to
       //set the correct height of each section of the page.
       if(midStuffHeight > leftNavHeight)
       {
           if(midStuffHeight > rightColHeight)
           {
               //alert("mid is highest(64): "+highest);
               highest = midStuffHeight;
           }//end if
           else
           {
               //alert("right is highest(69): "+highest);
               highest = rightColHeight;
           }//end else
       }//end if
       else
       {
           if(leftNavHeight > rightColHeight)
           {
               //alert("left is highest(77): "+highest);
               highest = leftNavHeight;
           }//end if
           else
           {
               //alert("right is highest(82): "+highest);
               highest = rightColHeight;
           }//end else
       }//else
       //now set all the heights to the correct height (of the three columns)
       objContent.ref.style.height = highest + "px";
       if((typeof(objLeftNav) != "undefined") && objLeftNav.ref != null)
       {
            objLeftNav.ref.style.height = highest + "px";
            //add a thin bar to the left hand side of the middle column to provide
            //a separator between the left nav and the middle column.
            document.getElementById("centerContent").style.borderLeft = "thin solid #d9d9d8";
       }//end if
	   if ((typeof(objRightBar) != "undefined") && objRightBar.ref) {
	   	objRightBar.ref.style.height = highest + "px";
		//if there is no content in the rightBar don't put the border on the
		//right hand side of the center column.
		if(document.getElementById("rightBar").innerHTML == "")
       	{
          document.getElementById("centerContent").style.borderRight = "";
       	}//end if
		else
		{
		  document.getElementById("centerContent").style.borderRight = "thin solid #d9d9d8";
		}//end else.
	   }//end if
	   //no rightBar defined. So don't put a border along the right hand side
	   //of the center column.
	   else
	   {
	   		document.getElementById("centerContent").style.borderRight = "";
	   }
       //in order to prevent these columns from bleeding through the footer
       //we also adjust the center content area (which contains all the
       //above columns)
       objCenter.ref.style.height = highest + "px";
              
       
   }//end else

}//end fixUnderflow

function getTaskGroupHeight()
{
    var tg = $$('.taskGroup');
}
function moveMenu() {
	if (getActiveStyleSheet() != "ssPrint") {
		var adjBy = (is_ie4up) ? 0:2;
		adjBy = (is_fx) ? 1:adjBy;
		document.getElementById("reposMe").style.top = (document.getElementById("nav").offsetTop + adjBy) + "px";
		document.getElementById("reposMe").style.left = "2px";
		/*if ((is_safari) || (is_fx)) {
			document.getElementById("nav").style.height = "23px";
		} else {
			document.getElementById("nav").style.height = "26px";
		}*/
		document.getElementById("reposMe").style.top = xPageY("nav") + 2;
		document.getElementById("reposMe").style.left = "1px";
		/*if ((is_nav6up) && (!is_nav7up)) {
			document.getElementById("reposMe").style.visibility = "hidden";
			document.getElementById("reposMe").style.display = "none";
		} else {*/
			document.getElementById("reposMe").style.visibility = "visible";
			document.getElementById("reposMe").style.display = "";
		//}
	}
}
/*************************************************
 * setPageObjects
 *
 * Simply sets various javascript objects for use
 * in later functions. This function is called on
 * page load.
 *
 * params: none
 * returns: void
 * 
 */
function setPageObjects() {
	objContent = new pageObject("centerContent");
    objCenter = new pageObject("center");
    objAddress = new pageObject("address");
  	objFooter = new pageObject("footer");
	objTopTasks = new pageObject("topTasks");
	objMidStuff = new pageObject("centerInfo");
	objIntro = new pageObject("centerHeader");
	objRightBar = new pageObject("rightBar");
	objLeftNav = new pageObject("leftNav");
}//end setPageObjects
function getObjectHeight(obj)
{
    return $(obj).getHeight();
}
function pageObject(strId) {
	this.ref = (document.getElementById(strId)) ? document.getElementById(strId):null;
	this.getHeight = function() {
		try {
			return this.ref.offsetHeight;
		} catch(e) {
			return 0;
		}
  }
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
function deacFontBtns() {
	fontSmall.deactivate();
	fontMed.deactivate();
	fontLarge.deactivate();
}
function fontInit() {
	fontSmall = new fontButton("Sm", 10);
	fontMed = new fontButton("Md", 12);
	fontLarge = new fontButton("Lg", 15);
	pageFontSize = getCookie("umFontSize");
	switch(pageFontSize) {
		case "sm":
		  fontSmall.activate();
			break;
		case "md":
		  fontMed.activate();
			break;
		case "lg":
		  fontLarge.activate();
			break;
		default:
		  fontSmall.activate();
      break;
	}
  document.getElementById("fontSizer").style.display = "";
}
function fontButton(strSize, intFontSize) {
	var imgFolder = location.protocol + "//umanitoba.ca/images/";
	this.ref = document.getElementById("imgTxt" + strSize);
	//alert(this.ref.classname);
	this.inactive = new Image();
	this.inactive.src = imgFolder + "a_" + strSize.toLowerCase() + ".gif";
	this.active = new Image();
	this.active.src = imgFolder + "a_" + strSize.toLowerCase() + "_selected.gif";
	this.activated = false;
	this.activate = function() {
		deacFontBtns();
		this.ref.src = this.active.src;
		//this.ref.classname = "fontBtnActive";
		this.activated = true;
		document.body.style.fontSize = intFontSize + "px";
		if ((document.getElementById("midText")) && (thisIsHome)) {
		  document.getElementById("midText").style.height = 150 * (intFontSize + (intFontSize - 10) / 2) / 10 + "px";
	  } else if (!thisIsHome) {
			adjHeight();
		}
		var now = new Date();
	  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	  setCookie("umFontSize", strSize.toLowerCase(), now, "/");
		this.ref.style.cursor = "default";
		if ((document.getElementById("studentMsgSyn")) && (document.getElementById("goingOnSyn"))) {
			if (intFontSize > 14) {
				document.getElementById("goingOnSyn").style.display = "none";
				//document.getElementById("studentMsgSyn").style.display = "none";
			} else {
				document.getElementById("goingOnSyn").style.display = "block";
				//document.getElementById("studentMsgSyn").style.display = "block";
			}
		}
		if (thisIsHome) {
			newsHeight();
		} else {
			fixUnderflow();
		}
	}
	this.deactivate = function() {
		this.ref.src = this.inactive.src;
		//this.ref.classname = "fontBtnInactive";
		this.activated = false;
		this.ref.style.cursor = "pointer";
	}
	this.toggle = function() {
		if (this.activated) {
			this.activate();
		} else {
			this.deactivate();
		}
	}
}
function getActiveStyleSheet() {
var i, a;
 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  if(a.getAttribute("rel").indexOf("style") != -1
  && a.getAttribute("id")
  && !a.disabled) return a.getAttribute("id");
  }
  return null;
}
function adjHeight() {
  var objLnav = document.getElementById("leftNav");
	var objMidCont = document.getElementById("midContent");

	if (((objLnav) && (objMidCont))  && (objLnav.offsetHeight > objMidCont.offsetHeight)) {
	  objMidCont.style.height = objLnav.offsetHeight;
	}/**/
}
/**
 * fixHubPadding
 *
 * Adjusts the task boxes on a hub page that are closest to the leftNav column
 * and makes there margins zero so that the boxes are flush with the left hand
 * side of the page.
 *
 * auth: Dave Cooke
 * date: Jan 26th, 2010
 *
 */
function fixHubPadding()
{
    //gets the list of boxes associated with the class taskGroup
    var taskBoxArray = $$('.taskGroup');
	var rowSize = 3;//number of TaskBoxes in each row. 	
	if(!$('rightBar'))
	{
		//alert("setting rowSize to 4");
		//set the topTasks width to the correct size.
		$('topTasks').style.width = "850px";
		rowSize = 4;
	}//end if
	//alert("rowSize:"+rowSize);
	//determines the size of the array.
    var size = taskBoxArray.length;
    var pos = 0; //first elem in the array.    
    while(pos <= size && size != 0)
    {
        //get the task box at position pos
        var tempBlock = taskBoxArray[pos];
        if(tempBlock != null)
        {
            //adjust its margin
            tempBlock.style.marginLeft = "0px";
			//alert("setting margin to zero for block: "+pos);
        }//end if.
        //increment the pos variable by the max length of a row which is
        //statically defined, its a constant.
        pos = pos + rowSize;
    }//end while loop
    //also adjust the centerInfo padding to zero to ensure that the boxes are
    //indeed flush with the left side of the page.
    //$('centerInfo').style.paddingLeft = "0px";
    
}//fixHubPadding
/**
 *
 * showMedia
 *
 * uses window.js and prototype.js libraries from
 * scriptaculous to display a web page.
 *
 * auth: Dave Cooke
 * date: Mar. 14, 2008
 *
 */
function showMedia(html)
{
//var win = new Window({className: "dialog",  width:600, height:400, zIndex: 1000000, resizable: true, title: "Media Room", url: html,showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true})
var win = new Window({className: "alphacube",  width:600, height:400, zIndex: 1000000, resizable: true, title: "", url: html,showEffect:Effect.Appear, showEffectOptions:({ duration: .5 }), hideEffect: Effect.DropOut, draggable:true, wiredDrag: true})
//var win = new Window({className: "alphacube",  width:600, height:400, zIndex: 1000000, resizable: true, title: "News Release", showEffect:Effect.Appear, hideEffect: Effect.DropOut, draggable:true, wiredDrag: true})
//var win = new Window({className: "dialog", title: "Sample", zIndex:1000000, url: html, width:600, height:400, destroyOnClose: true, recenterAuto:false});
//win.getContent().innerHTML= ;
//win.getContent().update(response);
//win.setStatusBar("Media Room");
win.showCenter();
//win.show();

}//end function
function showTables(id)
{
	//walk the dom and hide any div that is not the div with the id of id.
	//hmmm how do I do this?
	var objArray = $$('.hiddenBoxes');
	var size = objArray.length;
	for( var i = 0; i < size; i++)
	{
		//objArray[i].hide();
		//alert("id"+objArray[i].id+" = "+ id);
		if(objArray[i].id != id)
		{
			//alert("id"+objArray[i].id+" = "+ id);
			Effect.BlindUp(objArray[i].id, { duration: 1.0 });
		}//end if
	}//end for loop	
    //$(id).show(); 
	Effect.BlindDown(id, { duration: 2.0 });
}//end showTables
function trim(s)
{

  return s.replace(/^\s+|\s+$/, '');

}
function validateEmail(fld) {
    
    var error="";
    var tfld = trim(fld.value);  // value of field with whitespace trimmed off    
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    if (fld.value == "")
    {

        //fld.style.background = 'Red';
        error = "Error -- you didn't enter an email address.\n";

    }//end if
    else if (!emailFilter.test(tfld))
    {

        //fld.style.background = 'Red';
        error = "Error -- please enter a valid email address.\n";

    }//end else if
    else if (fld.value.match(illegalChars))
    {

        //fld.style.background = 'Red';
        error = "Error -- the email address contains illegal characters.\n";

    }//end else if
    else
    {
        fld.style.background = 'White';
    }//end else
    return error;

}//end validateEmail
/**
 * writePersistentCookie
 *
 * The University homepage was written for modern browsers. It is known that
 * Internet explorer version 6 or earlier does not display the current website
 * well to say the least. So we have written a set of functions that will look
 * at the users browser and throw up a warning message if that browser is not
 * supported. To prevent the functions from constantly throwing up the warning
 * on every UofM page the user visits, we are goint to set a cookie that
 * essentially says that the user has seen the warning message so not to bother
 * displaying it further.
 *
 * This function simply writes a persistant cookie to the users browser. It is
 * set to expire after one month.
 **/
function writePersistentWarningCookie () {

  var expireDate = new Date ();
  expireDate.setMonth(expireDate.getMonth() + 1);
  expireDate = expireDate.toGMTString();
  document.cookie = escape('bwarning') + "=" + escape('warned') + ";\n\
 expires=" + expireDate + "; path=/";
}//end writePersistentCookie
/*==============================================================================

Routine to get the current value of a cookie

    Parameters:
        cookieName        Cookie name

    Return value:
        false             Failed - no such cookie
        value             Value of the retrieved cookie

   e.g. if (!getCookieValue("pans") then  {
           cookieValue = getCoookieValue ("pans2);
        }
Routines written by John Gardner - 2003 - 2005
*/

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}//end getCookieValue
function rotateImageJQ(flag,mainDivID,subDivClass)
{
   //on faculty landing pages
   // #advert .layer4
   // #events .layer4
   // #taskGroup .content   <---- if we can add a unique id to each hub box.
   var $j = jQuery.noConflict();
   // Use jQuery via $j(...)
   $j(document).ready(function(){
       var flagd = flag;
       var imageListJQ = "#"+mainDivID+" > ."+subDivClass;
       var mDiv = "#"+mainDivID;

       if(flagd == 1)
       {
            //$j('#web_button > .imageList').hide();
            var list = $j(imageListJQ).children();
            var listLength = list.length;
            var randomnumber=Math.floor(Math.random()*listLength);
            //alert(randomnumber);
            $j(mDiv).html(list[randomnumber]);
            //$j(mainDivID).append(list[randomnumber]);
            //$j(mainDivID).show();
            //$j('.taskGroup > .content1').html(list[randomnumber]);
       }//end if
       else
       {
           $j(imageListJQ).show();
           $j(imageListJQ).innerfade({
               speed:'slow',
               timeout:4000,
               type:'sequence'
           });
       }//end else
    });
    // Use Prototype with $(...), etc.
    //$('someid').hide();
}


