<!--

	// last updated 2006-10-02

	// 2006-02-17 - added function to detect enter key
	// 2006-02-22 - added ability to find x and y positions of an element
	// 2006-02-27 - added open_window function
	// 2006-10-02 - added dropdown menu functions

	function setCookie(name, value, expires, path, domain, secure) {
		 document.cookie = name + "=" + escape(value) +
			  ((expires) ? "; expires=" + expires.toGMTString() : "") +
			  ((path) ? "; path=" + path : "") +
			  ((domain) ? "; domain=" + domain : "") +
			  ((secure) ? "; secure" : "");
	}
	
	function getCookie(name) {
		 var dc = document.cookie;
		 var prefix = name + "=";
		 var begin = dc.indexOf("; " + prefix);
		 if (begin == -1) {
			  begin = dc.indexOf(prefix);
			  if (begin != 0) return null;
		 } else {
			  begin += 2;
		 }
		 var end = document.cookie.indexOf(";", begin);
		 if (end == -1) {
			  end = dc.length;
		 }
		 return unescape(dc.substring(begin + prefix.length, end));
	}

	function deleteCookie(name, path, domain)	{
		 if (getCookie(name)) {
			  document.cookie = name + "=" + 
					((path) ? "; path=" + path : "") +
					((domain) ? "; domain=" + domain : "") +
					"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		 }
	}
	
	function trim(sString) {
		while (sString.substring(0, 1) == ' ') {
			sString = sString.substring(1, sString.length);	
		}
		while (sString.substring(sString.length-1, sString.length) == ' ') {
			sString = sString.substring(0,sString.length-1);
		}
		return sString;
	}
	
	function addEvent(elm, evType, fn, useCapture) {
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	}
	
	/*
	// example usage of addEvent
	function addListeners(e) {
		addEvent(document.getElementById('zip'), 'keyup', refresh_local_colleges, false);
	}
	
	addEvent(window, 'load', addListeners, false);
	*/

	function format_number(p,d) {
	  var r;
	  if(p<0){p=-p;r=format_number2(p,d);r="-"+r;}
	  else   {r=format_number2(p,d);}
	  return r;
	}
	
	function format_number2(pnumber,decimals) {
	  var strNumber = new String(pnumber);
	  var arrParts = strNumber.split('.');
	  var intWholePart = parseInt(arrParts[0],10);
	  var strResult = '';
	  if (isNaN(intWholePart))
		 intWholePart = '0';
	  if(arrParts.length > 1)
	  {
		 var decDecimalPart = new String(arrParts[1]);
		 var i = 0;
		 var intZeroCount = 0;
		  while ( i < String(arrParts[1]).length )
		  {
			 if( parseInt(String(arrParts[1]).charAt(i),10) == 0 )
			 {
				intZeroCount += 1;
				i += 1;
			 }
			 else
				break;
		 }
		 decDecimalPart = parseInt(decDecimalPart,10)/Math.pow(10,parseInt(decDecimalPart.length-decimals-1)); 
		 Math.round(decDecimalPart); 
		 decDecimalPart = parseInt(decDecimalPart)/10; 
		 decDecimalPart = Math.round(decDecimalPart); 
	
		 //If the number was rounded up from 9 to 10, and it was for 1 'decimal' 
		 //then we need to add 1 to the 'intWholePart' and set the decDecimalPart to 0. 
	
		 if(decDecimalPart==Math.pow(10, parseInt(decimals)))
		 { 
			intWholePart+=1; 
			decDecimalPart="0"; 
		 } 
		 var stringOfZeros = new String('');
		 i=0;
		 if( decDecimalPart > 0 )
		 {
			while( i < intZeroCount)
			{
			  stringOfZeros += '0';
			  i += 1;
			}
		 }
		 decDecimalPart = String(intWholePart) + "." + stringOfZeros + String(decDecimalPart); 
		 var dot = decDecimalPart.indexOf('.');
		 if(dot == -1)
		 {
			decDecimalPart += '.'; 
			dot = decDecimalPart.indexOf('.'); 
		 } 
		 var l=parseInt(dot)+parseInt(decimals); 
		 while(decDecimalPart.length <= l) 
		 {
			decDecimalPart += '0'; 
		 }
		 strResult = decDecimalPart;
	  }
	  else
	  {
		 var dot; 
		 var decDecimalPart = new String(intWholePart); 
	
		 decDecimalPart += '.'; 
		 dot = decDecimalPart.indexOf('.'); 
		 var l=parseInt(dot)+parseInt(decimals); 
		 while(decDecimalPart.length <= l) 
		 {
			decDecimalPart += '0'; 
		 }
		 strResult = decDecimalPart;
	  }
	  return strResult;
	}
	
	// e.g. usage: <input name="title" id="title" type="text" size="60" onKeyUp="SubmitOnEnter(event, 'frm_quick_add');">
	function EnterKeyPressed(e) { //e is event object passed from function invocation
		var characterCode; //literal character code will be stored in this variable
		
		if (e && e.which) { //if which property of event object is supported (NN4)
			e = e;
			characterCode = e.which; //character code is contained in NN4's which property
		} else {
			e = event;
			characterCode = e.keyCode; //character code is contained in IE's keyCode property
		}
		
		if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
			return true;
		}

		return false;
	
	}
	
	function findPosX(obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}
	
	function findPosY(obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}

	function open_window(pageurl, winname, w_width, w_height) {
	
		top_pos  = (screen.availHeight - w_height) / 2;
		left_pos = (screen.availWidth  - w_width)  / 2;

		w = window.open(pageurl, winname, 'width=' + w_width + ',height=' + w_height + ',toolbars=0,resizable=1,scrollbars=1,top=' + top_pos + ',left=' + left_pos);
		w.focus();
	}

	function show(element_id, display_type) {
		if (arguments.length < 2) {
			display_type = "block";	
		}
		document.getElementById(element_id).style.display = display_type;
	}

	function hide(element_id) {
		document.getElementById(element_id).style.display = "none";
	}
	
	function change_content(element_id, html) {
		document.getElementById(element_id).innerHTML = html;	
	}

	function popup(filename, width, height) {
		var center_left = (screen.width/2) - width/2;
		var center_top = (screen.height/2) - height/2;
		var filename_array = filename.split(".");
		z = window.open(filename, filename_array[0], 'width=' + width + ',height=' + height + ',left=' + center_left + ',top=' + center_top + ',scrollbars=yes,resizable=yes');
		z.focus();
	}
	
	//Finds value[s] of checked inputs (could be radio buttons or checkboxes.
	function findChecked(input_name) {
		
		//Determine if object is an array.		
		if (input_name[1]) { 
			var array_size = input_name.length;
			var checked_values = Array();
			
			//Loop through each array element checking to see if 
			//value is checked and if it is, add it to checked_values array.
			var j = 0;//For populating the checked_values array.
			for (var i = 0; i < array_size; i++) {
				if (input_name[i].checked) {
					checked_values[j++] = input_name[i].value;
				}
			}//end for
			
			//if (settingCookie) {
				//alert(checked_values.toString());
				//return checked_values.toString();
			//} else {
				//Return array of checked values.
				return checked_values;
			//}
			
		} else {//Object is a single checkbox, so see if it is checked.
			if (input_name.checked) return 1;
			else return 0;
		}
	}//end function findChecked

//-->