		
	String.prototype.ltrim = function () { return this.replace(/^\s+/g, "") }
	String.prototype.rtrim = function () { return this.replace(/\s+$/g, "") }
	String.prototype.trim  = function () { return this.ltrim().rtrim() }

	function OpenChildWindow(fileName, windowName) 
	{
		var childWindow = window.open(fileName, windowName, "height=500,width=530,status=no,toolbar=yes,directories=no,menubar=no,location=yes,scrollbars=yes,resizable=yes");
		childWindow.focus();
	}

	function DiffDate(dFrom, dTo)
	// Return number of whole days from Date object dFrom to Date object dTo, midday to roughly midday.
	{
	  var df = new Date(dFrom.getYear(), dFrom.getMonth(), dFrom.getDate(), 0);
	  var dt = new Date(dTo.getYear(), dTo.getMonth(), dTo.getDate(), 12);
	  
	  return Math.floor(dt.valueOf()/(24*60*60*1000) - df.valueOf()/(24*60*60*1000));
	}
	
	function curr_date() 
	{
		var adate = new Date();
		var month = adate.getMonth() + 1;
		var day = adate.getDate();
		var year = adate.getYear();
		
		if (month < 10) {month = "0" + month;}
		if (day < 10) {day = "0" + day;}
		
		date = month + "/" + day + "/" + year;
		return date;
	}
	
	function SetSelectIndex(objSelect, strValue)
	{	
		var i;
	
		for(var i=0; i < objSelect.options.length; i++)
		{
 			if(objSelect.options[i].value==strValue){objSelect.selectedIndex=i;}
		}
	}

	function GetRadioValue(strRadioName)
	{
		var colRadio = document.getElementsByName(strRadioName);
		
		for (var i = 0; i < colRadio.length; i++)
		{
			if (colRadio[i].checked){return colRadio[i].value;}
		}
		return null;
	}

	function SetRadioValue(strRadioName, strValue)
	{
		//alert(strRadioName + strValue);
		var colRadio = document.getElementsByName(strRadioName);
		
		for (var i = 0; i < colRadio.length; i++)
		{
			if (colRadio[i].value == strValue){colRadio[i].checked = true; return;}
		}
		return null;
	}

	function validate_frs(frs_num)
	{
		if (frs_num.length < 5 || frs_num.length > 8)
		{
			return false;
		}else{
			return true;
		}
	}
	
	function init_form()
	{
		var bFound = false;

		// for each form
		for (f=0; f < document.forms.length; f++)
		{
		// for each element in each form
		for(i=0; i < document.forms[f].length; i++)
		{
		  // if it's not a hidden element
		  if (document.forms[f][i].type != "hidden")
		  {
			// and it's not disabled
			if (document.forms[f][i].disabled != true)
			{
				// set the focus to it
				document.forms[f][i].focus();
				var bFound = true;
			}
		  }
		  // if found in this element, stop looking
		  if (bFound == true)
			break;
		}
		// if found in this form, stop looking
		if (bFound == true)
		  break;
		}
	}
					
	/*
	 PhoneNumber object copyright(c)2001 by Fox Mahoney. 
	 Permission for free use with this copyright notice (thank you).
	*/
	var pn = new PhoneNumber();
	
	function PhoneNumber(num, pat)
	{
		this.pattern = pat || "(###) ###-#### x####";
		this.setPattern = function(s) { this.pattern = s; }
		this.number = num || 0;
		this.setNumber = function(n) { this.number = n; }
		this.formatted = "";
		this.format = function()
		{
			var tstr = "" + this.number;
			var findex = 0;    // format string index
			var nindex = 0;    // number string index
	
			var re = /[ A-Za-z\+\(\)\-]/;
			var parts = tstr.split(re);
				   
			tstr = parts.join(""); 
			this.formatted = "";
				   
			while(nindex < tstr.length)
			{
				if(this.formatted.length == this.pattern.length) break; // we're done
				while(this.pattern.charAt(findex) != "#") 
				{
					this.formatted += this.pattern.charAt(findex++);
				}
				findex++;
				this.formatted += tstr.charAt(nindex++);
			}
			return this.formatted;
		}
	}
	
	function modifyEntry(elem)
	{
		pn.setNumber(elem.value);
		elem.value =  pn.format();
	}
	
	function format_phone(elem,pattern)
	{
		pn.setPattern(pattern);
		modifyEntry(elem);
	}
