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

	function initPage(fieldobj)	{
		if (fieldobj.type == 'text' || fieldobj.type == 'password' || fieldobj.type == 'textarea')	{
			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)	{
		if (f.type == 'text' || f.type == 'password' || f.type == 'textarea')	{
			f.focus();
			f.select();
		 }
		return false;
	}

	/** ----------------------------- doSelectAll --------------------------- **
		This routine takes a select object id as a param, and either selects or deselects all based on the boolean second param
	**/
	
	function doSelectAll(selobjid, doSelect) 	{
		var obj =  self.document.getElementById(selobjid);
		if (obj == null) return;
		
		for (j=0;j<obj.options.length;j++)	{
			if (j!=0) obj.options[j].selected = doSelect;
		}	//--for
		
		
	}

	/** ----------------------------- clearOneElement --------------------------- **
		clears a form element based on that element's type
	**/
	
	function clearOneElement(objid) 	{
		var obj =  self.document.getElementById(objid);
		if (obj != null) {
			if (obj.type == 'checkbox')
				obj.checked = false;
			else if (obj.type == 'select-one' || obj.type == 'select-multiple')	{
				obj.selectedIndex = 0;
				obj.value = "";
			} else {
				obj.value = "";
			}
		}
	
	}	//-- clearOneElement


	/** ----------------------------- 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_select_text --------------------------- **
		This routine is exactly like "check_select" above, except it accepts a value that the 
		currently selected indice should NOT have in it's value field
	**/

	function check_select_text(fs, val, fieldname)	{
		if (fs.options[fs.selectedIndex].text == val) { 
			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;
	}


	/** ----------------------------- check_field_polite --------------------------- **
		Exactly same as check_field above, but accepts a complain arg to indicate whether
		to post an alert, or just return false.
	**/

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

	/** ----------------------------- check_select_polite --------------------------- **
		Exactly same as check_select above, but accepts a complain arg to indicate whether
		to post an alert, or just return false.
	**/

	function check_select_polite(fs, fieldname, complain)	{
		if (fs.options[fs.selectedIndex].value == 0) { 
			if (complain) alert("You forgot to make a selection from the required field: " + fieldname);
			return false;
		}
		return true;
	}
	

	/** ----------------------------- check_field_ssn --------------------------- **
		Checks an ssn field to make sure it's filled in with the proper format
		xxx-xx-xxxx
	**/

	function check_field_ssn(s, fieldname, complain)	{
	
		var flag = false;
		var msg = "";
		
		if (s == null || s == "" || s == "undefined"){ 
			msg = "You forgot to enter the required field: " + fieldname;
		} else {
			msg = "You don't seem to have a valid SSN in field: " + fieldname;
			var exp = new RegExp("[^0123456789]");
			
			var a = s.split('-');
			if (a.length == 3 && a[0].length == 3 && a[1].length == 2 && a[2].length == 4) {
				if (exp.test(a[0] == false) && exp.test(a[1] == false) && exp.test(a[2] == false))
					flag = true;
			}

		}
		if (!flag && complain) alert(msg);
		return flag;
	}
	
	

	/** ----------------------------- 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;
	}

	/** ----------------------------- fetchOnePosMultiSelect --------------------------- **
		exactly like fetchOneMultiSelect above, but will only return positive numbers in the string
	**/

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

	/** ----------------------------- plugTodaysDate --------------------------- **
		plugs today's date in the value of the supplied form object, using the supplied format
		
			1:	mm/dd/yyyy
			2:	mm-dd-yyyy
			3:	yyyy-mm-dd
	**/
	function plugTodaysDate(objid, format)	{
		var obj =  self.document.getElementById(objid);
		if (obj != null) {
			var d = new Date();
			var yy = d.getFullYear();
			var mm = d.getMonth() + 1;
			var dd = d.getDate();
			
			switch (format)	{
				case 1: var s = mm + "/" + dd + "/" + yy; break;
				case 2: var s = mm + "-" + dd + "-" + yy; break;
				case 3: var s = yy + "-" + mm + "-" + dd; break;
				default: var s = mm + "/" + dd + "/" + yy; break;
			}
			obj.value = s;
		}
	}
	

	/** ----------------------------- 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

   }


	/** ----------------------------- isValidEmailFormat --------------------------- **
		all this does is see if there is an "@" character with valid chars on each side.
	*/
	function isValidEmailFormat(str)	{
		var a = str.split("@");
		var failed = false;
		
		if (a.length != 2)	{
			failed = true;
		} else if (a[0].length == 0 || a[1].length == 0) {
			failed = true;
		}	
		return !failed;		//-- 'failed' will be true if we are NOT valid
	}
	


	

	

