
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that handle preload. */
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function WM_netscapeCssFix() {
  /*
    Source: Webmonkey Code Library
    (http://www.hotwired.com/webmonkey/javascript/code_library/)


    Author: Taylor
    Author Email: taylor@wired.com
    Author URL: http://www.taylor.org/
    */


  // This part was inspired by Matthew_Baird@wayfarer.com
  // It gets around another unfortunate bug whereby Netscape 
  // fires a resize event when the scrollbars pop up. This 
  // checks to make sure that the window's available size 
  // has actually changed.
  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
    document.location = document.location;
  }
}


function WM_netscapeCssFixCheckIn() {
  // This function checks to make sure the version of Netscape 
  // in use contains the bug; if so, it records the window's 
  // width and height and sets all resize events to be handled 
  // by the WM_netscapeCssFix() function.
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
      document.WM = new Object;
    }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
      document.WM.WM_netscapeCssFix = new Object;
      document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
      document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
    }
    window.onresize = WM_netscapeCssFix;
  }
}


/* Netscape 4.x Highlighting Text Rollover Support
   by Richard Prangnell (Praggers), March 2001
     website: www.praggers.co.uk
       email: praggers@praggers.co.uk
*/	   
function nnWrite(what,text) {
  what.document.open();
  what.document.write(text);
  what.document.close();
}


function nnOver(what, href, linktext, align, style) {
    if (document.layers) {
	  if (align=="inflow")
	    var text = '<A HREF="' + href + '" class="nnhover">' + linktext + '<\/A>';
	  else
        var text = '<div align="' + align + '" class="' + style + '"><A HREF="' + href + '" class="nnhover">' + linktext + '<\/A></div>';
      nnWrite(what, text);
    }
}


function nnOut(what, href, linktext, align, style) {
    if (document.layers) {
	  if (align=="inflow")
	    var text = '<A HREF="' + href + '" class="A">' + linktext + '<\/A>';
	  else	
        var text = '<div align="' + align + '" class="' + style + '"><A HREF="' + href + '" class="A">' + linktext + '<\/A></div>';
      nnWrite(what, text);
    }
}

function change_in(obj,img) {
	//obj.style.color = "#993333";
	obj.className  = "label_req";
	//MM_swapImage(img,'',root_dir + 'graphics/VASTmenuButtonBlack.gif',1);
}

function change_out(obj,img) {
	//obj.style.color = "#000000";
	obj.className = "label";
	//MM_swapImgRestore();
}

function trim(xstring) {
//Trims leading and trailing spaces from string - same as VBscript trim
	tmpstr = "";
	if(xstring.substring(0,1) == " ") {
		//alert("first space");
		tmpstr = trim(xstring.substring(1,xstring.length));
	}
	else if(xstring.substring(xstring.length-1,xstring.length) == " ") {
		//alert("last space");
		tmpstr = trim(xstring.substring(0,xstring.length-1));
	}
	else
		tmpstr = xstring;
	return(tmpstr);
}

//Function removes vChar from vString
function removeChar(vString, vChar)
{
  var nString = "";
  var i;
  
  for(i=0;i<vString.length;i++)
  {
    if(vString.charAt(i) != vChar)
    {
      nString += vString.charAt(i);
    }
  }
  return(nString);
}

//Function replaces vChar with vReplace in vString
function replaceChar(vString, vChar, vReplace)
{
  var nString = "";
  var i;
  
  for(i=0;i<vString.length;i++)
  {
    if(vString.charAt(i) == vChar)
    {
      nString += vReplace;
    } else {
      nString += vString.charAt(i);
	 }
  }
  return(nString);
}




//Formats string of numbers to (999) 999-9999 if 10 chars
function formatPhone(vString)
{
	var phoneNum = "";
	var i;
	  
	for(i=0;i<vString.length;i++)
	{
		if(isNumOnly(vString.charAt(i)) && (vString.charAt(i) != " "))
		{
			phoneNum += vString.charAt(i);
		}
	}
	  
	if(phoneNum.length == 10)
	{
		phoneNum = "("+phoneNum.substring(0,3)+") "+phoneNum.substring(3,6)+"-"+phoneNum.substring(6,10);		 
	} else {
		phoneNum = vString;
	}
	return(phoneNum);
}

function isNull(vString)
{	
	return((trim(vString)).length == 0);
}

//Checks select list to see if value has been selected
function isSelected(vField)
{ 
	return(!vField.selectedIndex == 0);
}

//Get the value associated with a SELECT box.
function getSelectValue(vField) {	
	return(vField.options[vField.selectedIndex].value);
}

//Get the displayed text associated with a SELECT box.
function getSelectText(vField) {	
	return(vField.options[vField.selectedIndex].text);
}

//Checks if vString is a valid email address
function isEmailAddress(vString)
{
	return((vString.indexOf("@")>0) && (vString.indexOf(".")>0));
}

var NUMBERS = "0123456789";
var LOWER = "abcdefghijklmnopqrstuvwxyz";
var UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var ALL_CHAR = LOWER + UPPER;

function checkChars(vString, vChars)
{
	var valid = true;
	var i, j;

	//Loop through each char of the string
	for (var i=0;i<vString.length;i++)
	{
		//Get the current character
		var ch = vString.charAt(i);
		
		//loop through the allowed chars
		for (j=0;j<vChars.length;j++)
			if (ch==vChars.charAt(j))
				break;					
				
		if (j==vChars.length)
		{
			valid = false;
			break;
		}
	}		
	return(valid);
}	

//Formats the date 'Mon-dd-yyyy'
function formatDate(vDate)
{  
	var m, d, y;
	
	m = vDate.getMonth()+1;
	d = vDate.getDate();
	y = vDate.getFullYear();
		
	return(m+"/"+d+"/"+y);
}   

//Formats Date String
function formatDateString(vString)
{
	return(formatDate(new Date(vString)));
}

//Checks if string is in date format
function isDate(vDateString)
{	
	return(Date.parse(vDateString))		
}

//Checks if two date strings are in cronological order
function isDateRage(vDateString1, vDateString2)
{
	if ((new Date(vDateString1)) < (new Date(vDateString2)))
  		return true;
	else
		return false;
}




var daysInMonth = new Array(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;


function getDaysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
	if(year == '')
		return(28)
	else
	    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function getDaysInMonth(vMonth, vYear) {
	if (vMonth == 2) 
		return getDaysInFebruary(vYear);
	else
		return daysInMonth[vMonth];
}

function setDaysInMonth(vField, vMonth, vYear) {
	vDaysInMonth = getDaysInMonth(vMonth, vYear);
	vDaysInField = vField.length - 1;
	vDaysDiff = vDaysInMonth - vDaysInField;
	vCurrentValue = vField.options[vField.selectedIndex].value;
	
	//Add or remove days
	if (vDaysDiff > 0) {
		//Add days to field
		for(i = vDaysInMonth - vDaysDiff; i < vDaysInMonth+1; i++) {
			opt=new Option;
            opt.value=i;
            opt.text=i;
            vField.options[i]=opt;
		}
	} else {
		//Remove days from field	
		vField.length = vDaysInMonth + 1;
	}
	
	//Set the selected value back if still an option
	for(i=0;i<vField.length;i++) {
		if(vCurrentValue == vField.options[i].value)
			vField.options[i].selected = true;
	}
}

//Checks if value is number. Nulls will test as Zero.
function isNumber(vNumber)
{
	return(!isNaN(Number(vNumber)) && !isNull(vNumber));
}

//Returns true if value passed is a positive number
function isPositiveNumber(vNumber)
{
	return(isNumber(vNumber) && vNumber >= 0);
}

//Returns true if checkbox/group is checked
function isRadioChecked(vRadio)
{
	var returnValue;
	
	if(!vRadio.length){
		returnValue = vRadio.checked;
	}else{
		for(i=0;i<vRadio.length;i++)
			returnValue |= vRadio[i].checked;
	}
	return(Boolean(returnValue));
}

//Call function validate for every elemet on form passed
function validateForm(vForm){	
    var i, isValid;
    for(i=0;i<vForm.elements.length;i++){
        isValid = validate(vForm.elements[i]);
        if(!isValid)
            break;
    }
    return(isValid);
}

//Open Help Files
function openHelp(helpFile)
{
	window.open(helpFile,'help_window','scrollbars=yes,resizable=yes,width=390,height=300,top='+(screen.height-375)+',left='+(screen.width-425)).focus();
}

function FormatNumber(Number,Decimals,Separator)
{
 // **********************************************************
 // Placed in the public domain by Affordable Production Tools
 // March 21, 1998
 // Web site: http://www.aptools.com/
 //
 // November 24, 1998 -- Error which allowed a null value
 // to remain null fixed. Now forces value to 0.
 //
 // October 28, 2001 -- Modified to provide leading 0 for fractional number
 // less than 1.
 //
 // This function accepts a number to format and number
 // specifying the number of decimal places to format to. May
 // optionally use a separator other than '.' if specified.
 //
 // If no decimals are specified, the function defaults to
 // two decimal places. If no number is passed, the function
 // defaults to 0. Decimal separator defaults to '.' .
 //
 // If the number passed is too large to format as a decimal
 // number (e.g.: 1.23e+25), or if the conversion process
 // results in such a number, the original number is returned
 // unchanged.
 // **********************************************************
 Number += ""          // Force argument to string.
 Decimals += ""        // Force argument to string.
 Separator += ""       // Force argument to string.
 if((Separator == "") || (Separator.length > 1))
  Separator = "."
 if(Number.length == 0)
  Number = "0"
 var OriginalNumber = Number  // Save for number too large.
 var Sign = 1
 var Pad = ""
 var Count = 0
 // If no number passed, force number to 0.
 if(parseFloat(Number)){
  Number = parseFloat(Number)} else {
  Number = 0}
 // If no decimals passed, default decimals to 2.
 if((parseInt(Decimals,10)) || (parseInt(Decimals,10) == 0)){
  Decimals = parseInt(Decimals,10)} else {
  Decimals = 2}
 if(Number < 0)
 {
  Sign = -1         // Remember sign of Number.
  Number *= Sign    // Force absolute value of Number.
 }
 if(Decimals < 0)
  Decimals *= -1    // Force absolute value of Decimals.
 // Next, convert number to rounded integer and force to string value.
 // (Number contains 1 extra digit used to force rounding)
 Number = "" + Math.floor(Number * Math.pow(10,Decimals + 1) + 5)
 if((Number.substring(1,2) == '.')||((Number + '')=='NaN'))
  return(OriginalNumber) // Number too large to format as specified.
 // If length of Number is less than number of decimals requested +1,
 // pad with zeros to requested length.
 if(Number.length < Decimals +1) // Construct pad string.
 {
  for(Count = Number.length; Count <= Decimals; Count++)
   Pad += "0"
 }
 Number = Pad + Number // Pad number as needed.
 if(Decimals == 0){
  // Drop extra digit -- Decimal portion is formatted.
  Number = Number.substring(0, Number.length -1)} else {
  // Or, format number with decimal point and drop extra decimal digit.
 Number = Number.substring(0,Number.length - Decimals -1) +
          Separator +
          Number.substring(Number.length - Decimals -1,
          Number.length -1)}
 if((Number == "") || (parseFloat(Number) < 1))
  Number="0"+Number // Force leading 0 for |Number| less than 1.
 if(Sign == -1)
  Number = "-" + Number  // Set sign of number.
 return(Number)
}

function PadLeft(String,Length,PadChar)
{
 // **********************************************************
 // Placed in the public domain by Affordable Production Tools
 // April 1, 1998
 // Web site: http://www.aptools.com/
 //
 // December 2, 1998 -- Modified to allow specification of
 // pad character.
 //
 // This function accepts a number or string, and a number
 // specifying the desired length. If the length is greater
 // than the length of the value passed, the value is padded
 // with spaces (default) or the specified pad character
 // to the length specified.
 //
 // The function is useful in right justifying numbers or
 // strings in HTML form fields.
 // **********************************************************
 String += ""       // Force argument to string.
 Length += ""       // Force argument to string.
 PadChar += ""      // Force argument to string.
 if((PadChar == "") || (!(PadChar.length == 1)))
  PadChar = " "
 var Count = 0
 var PadLength = 0
 Length = parseInt(0 + Length,10)
 if(Length <= String.length) // No padding necessary.
  return(String)
 PadLength = Length - String.length
 for(Count = 0; Count < PadLength; Count++)
  String = PadChar + String
 return(String)
}

function FormatNumberField(Object,Decimals,Pad,Separator,PadChar)
{
 // **********************************************************
 // Placed in the public domain by Affordable Production Tools
 // March 23, 1998
 // Web site: http://www.aptools.com/
 //
 // November 24, 1998 -- Error which allowed a null field
 // to remain null fixed. Now forces value to 0.
 //
 // December 2, 1998 -- Modified to allow specification of
 // pad character.
 //
 // This function formats a number in an HTML form field,
 // setting the decimal precision and right justifying the
 // number in the field. An optional decimal separator other
 // than '.' may be specified and an optional pad character
 // may be specified (default is space).
 //
 // Note that this function uses two other library functions,
 // FormatNumber() and PadLeft().
 //
 // Usage: Call the function with an onblur or onchange event
 // attached to the field:
 //
 // onblur="FormatNumberField(this,Decimals,Pad,[Separator],[PadChar])"
 // where Decimals is the number of decimals desired and Pad
 // is the size of the field.
 // **********************************************************
 if(Object.value == "")
  Object.value = "0"
 if(Object == null)
  return(null)
 Separator += ""      // Force argument to string.
 if((Separator == "") || (Separator.length > 1))
  Separator = "."
 PadChar += ""
 if((PadChar == "") || (!(PadChar.length == 1)))
  PadChar = " "
 Object.value = FormatNumber(Object.value,Decimals,Separator)
 Object.value = PadLeft(Object.value,Pad,PadChar)
 return(Object.value)
}


 function CheckKey(ctl , e, tmpFunction)
 //Waits for enter key before executing function
 {
  //var KeyCode = (window.Event) ? e.which : e.keyCode;
  //if (KeyCode == 13) {
//	eval(tmpFunction);
//		}
return false;
 }
 
function getDayofWeek()
{
  var d, day, x;
  var x = new Array("Sunday", "Monday", "Tuesday");
  var x = x.concat("Wednesday","Thursday", "Friday");
  var x = x.concat("Saturday");
  d = new Date();
  day = d.getDay();
  return(x[day]);
}

function getTodaysDate()
{
  var d, s = "";
  d = new Date();
  s += (d.getMonth() + 1) + "/";
  s += d.getDate() + "/";
  s += d.getFullYear();
  return(s);
}

function get_percent(tmpvar) {
	tmpstr = parseFloat(tmpvar);
	if (isNaN(tmpstr)) {
		return(0);
	}
	else {
		return(FormatNumber(tmpstr/100,5,"."));
	}	
}

function format_percent(tmpvar) {
	tmpstr = parseFloat(tmpvar);
	if (isNaN(tmpstr)) {
		return("0%");
	}
	else if (tmpstr < .1) {
		//already in a percent format
		tmpstr = Math.round(tmpstr * 100000)/1000;
		return(tmpstr + "%");
	}
	else {
		return(tmpstr + "%");
	}
}

function format_currency(field) {
	//returns value with $ and 2 dec. places
    var temp;
    temp = field.value;
    temp = temp.replace(",","");
	temp = "$" + FormatNumber(temp.replace("$",""),2,".")
    field.value = temp;

}

function format_currency2(field){
	//returns value with 2 decimal places without $
    var temp;
    temp = field.value;
    temp = temp.replace(",","");
	temp = FormatNumber2(temp.replace("$",""))
    field.value = temp;

}