	/** ----------------------------- initPage --------------------------- **
		given a javascript field element object, this routine will select it and give it focus
	**/

	function initPage(fieldobj)	{
		fieldobj.focus();
		fieldobj.select();	
	}


	/** ----------------------------- swapImage --------------------------- **
		a simple image swap routine for easy animation
			expects "path" to be the URL path to the images
			expects "oldimage" to be a javascript img object
			expects "newimagename" to be the name of the new image in "path"
	**/

	function swapImage(path, oldimage, newimagename)	{
		oldimage.src = path + newimagename;
	}






	/** ----------------------------- re_select --------------------------- **
		This routine simply reselects a field
	**/
	
	function re_select(f)	{
		f.focus();
		if (f.type == 'text' || f.type == 'password' || f.type == 'textarea') f.select();
		return false;
	}


	/** ----------------------------- check_select --------------------------- **
		This routine checks the provided object, presumably a select object, to make
		sure that the selected index value != 0
	**/

	function check_select(fs, fieldname)	{
		if (fs.options[fs.selectedIndex].value == 0) { 
			alert("You forgot to make a selection from the required field: " + fieldname);
			return false;
		}
		return true;
	}
		
	
	/** ----------------------------- check_field --------------------------- **
		This routine simply checks that a field has some kind of input, and complains
		with an alert if it doesn't
	**/

	function check_field(s, fieldname)	{
		if (s == null || s == "" || s == "undefined"){ 
			alert("You forgot to enter the required field: " + fieldname);
			return false;
		}
		return true;
	}


	/** ----------------------------- fetchOneMultiSelect --------------------------- **
		fetches the selected values of a select object as a comma delimited list
	**/

	function fetchOneMultiSelect(fs)	{
		var str = "";
		first=true;
		for (x=0; x < fs.options.length; x++)	{
			if (fs.options[x].selected)	{
				if (!first) str += ",";
				str += fs.options[x].value;
				first=false;
			}
		}
		return str;
	}
//	export fetchOneMultiSelect;


	/** ----------------------------- findSelectValue --------------------------- **
		given a select id & a value that is supposedly one of the value in the options[] array
		this routine will return the indice of the option of found, and -1 if not
	**/

	function findSelectValue(objid, val)	{
		var obj = self.document.getElementById(objid);
		if (obj != null)	{
			for (x=0; x < obj.options.length; x++)	{
				if (obj.options[x].value == val) return x;
			}
		}
		return -1;
	}

	/** ----------------------------- setSelectByValue --------------------------- **
		given a select id & a value that is supposedly one of the value in the options[] array
		this routine will find the indice and set it if it's there.
		Returns the indice or -1 if not found
	**/

	function setSelectByValue(objid, val)	{
		var i = findSelectValue(objid, val);		
		if (i != -1)	{
			var obj = self.document.getElementById(objid);
			obj.selectedIndex = i;
		}
		return i;
	}




	/** ----------------------------- makeCookie --------------------------- **
		sets any arbitrary cookie
		**Note if the cookie exists, the value will be replaced
		MUST always have a name & a value
		all the rest of the params are optional & can be null
		
			name	=	the name of the cookie
			value	=	the value of the cookie (will be converted to htmlspecial characters)
			ttl		=	the time to live in hours (if null, set to end of session)
			path	=	the path where cookie is valid (set to current directory if null)
			doman	=	the domain where cookie is valid (send 'wacad.edu' if you want this cookie 
							to be valid across the whole domain, null will make it specific like 'db.wacad.edu')
			sslOnly	=	boolean.  true means will only be accessed from a secure (https) site.

	**/

	function makeCookie(name, value, ttl, path, domain, sslOnly)  {
	
		var str = name + "=" + escape(value);
		
		if (ttl != 0)	{
			var expiry=new Date();
			expiry.setHours(expiry.getHours() + ttl);
			str += ";expires=" + expiry.toString();
		}
		str += (path != null) ? ";path=" + path : "";
		str += (domain != null) ? ";domain=" + domain : "";
		str += (sslOnly) ? ";secure" : "";

		document.cookie=str;
	}


	/** ----------------------------- setCookie --------------------------- **
		sets any arbitrary cookie
		**Note if the cookie exists, the value will be replaced
		MUST always have a name & a value
		See MakeCookie for definitions of path & name
		
		**NOTE if you've made the cookie using path & name, you'll have to supply them

	**/

	function setCookie(name, value, path, domain)  {
		var str = name + "=" + escape(value);
		str += (path != null) ? ";path=" + path : "";
		str += (domain != null) ? ";domain=" + domain : "";
		document.cookie=str;
	}
	
	

	/** ----------------------------- getCookie --------------------------- **
		fetches the selected values of a select object as a comma delimited list
	**/

	function getCookie(name)	{
		var str = "";

		if (document.cookie.length > 0)	{

			start=document.cookie.indexOf(name + "=");
			if (start != -1)	{ 
				start = start + name.length + 1; 
				end = document.cookie.indexOf(";", start);
				if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(start,end));
			} 
		}



		return str;
	}


	/** ----------------------------- getCookieArray --------------------------- **
		returns the array designated by "name" as a javascript array object
		

	**/

	function getCookieArray(name)  {
		var str = getCookie(name);
		var a = new Array();
		var x=0;
		var end=0;
		var start=0;
		
		if (str.length > 0)	{
			while (x >= 0)	{
				var ss = "";
				end = str.indexOf(',', start);
				
				if (end != -1) ss = str.substring(start, end);
				else ss = str.substring(start, str.length);		//-- will be valid text if there is no trailing comma
				
				if (ss.length > 0)	a[x] = ss;
				
				if (end != -1)	{
					start = end + 1;
					x = (start >= str.length) ? -1 : (x+1);
				} else x = -1;		//-- break our looop

			}
		}
		return a;
	}	
	
	

	/** ----------------------------- pushCookie --------------------------- **
		adds a comma-delimited index to the end of a cookie
		**Note if the cookie exists, the value will be replaced
		MUST always have a name & a value
		See MakeCookie for definitions of path & name
		
		**NOTE if you've made the cookie using path & name, you'll have to supply them

	**/

	function pushCookie(name, value, path, domain)  {
		var str = getCookie(name);
		if (str.length > 0) str += ",";
		str += value;
		setCookie("goback", str, path, domain);
	}
	
	/** ----------------------------- popCookie --------------------------- **
		subtracts a comma-delimited index from the end of a cookie
		**Note if the cookie exists, the value will be replaced
		MUST always have a name & a value
		See MakeCookie for definitions of path & name
		
		**NOTE if you've made the cookie using path & name, you'll have to supply them

	**/

	function popCookie(name, path, domain)  {
	
		var str = getCookie(name);
		var strr = "";
		
		if (str.length > 0)	{
			off = str.lastIndexOf(",");
			if (off != -1)	{
				strr = str.substring(off+1,str.length);
				setCookie(name, str.substring(0,off), path, domain);
			} else {
				strr = str;
				setCookie(name, "", path, domain);
			}
			
		}
		return strr;
	}



	/** ----------------------------- showHidden --------------------------- **
		show any hidden css object
	*/
	function showHidden(whichID)	{
		var obj = self.document.getElementById(whichID);
		obj.style.visibility = "visible";
	}


	/** ----------------------------- hideHidden --------------------------- **
		hide any css object
	*/
	function hideHidden(whichID)	{
		var obj = self.document.getElementById(whichID);
		obj.style.visibility = "hidden";
	}


	/** ----------------------------- encodeTags --------------------------- **
		Given a string that is suspected to include html tags, this routine converts that string
		to and encoded string, compatible with our php routine "decodeTags" in utils.php
		Right now we're only doing the < & > symbols, but might want to get more sophisticated.
	**/

	function encodeTags(str){
		s = "";
		for (x=0; x < str.length; x++)	{
			if (str[x] == '<')
				s += "%0c";
			else if (str[x] == '>')
				s += "%0e";
			else s+= str[x];
		}
		return s;
	}



 	/** ----------------------------- msieversion --------------------------- **
		returns the version of msie or 0 if we're not an msie browser
		from the microsoft site, supposedly compatible with all future versions, 
		
	**/

  function msieversion()
   {
      var ua = window.navigator.userAgent
      var msie = ua.indexOf ( "MSIE " )

      if ( msie > 0 )      // If Internet Explorer, return version number
         return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
      else                 // If another browser, return 0
         return 0

   }



	/** ----------------------------- wait --------------------------- **
		waits for a specified number of milliseconds (1000 millis == 1 sec)
	**/

	function wait(millis)	{
		var date = new Date();
		var curDate = null;
		
		do { curDate = new Date(); }
		while(curDate-date < millis);
	}





	

	
