/*

   Filename: menufunctions.js

   Functions List:
   todayTxt()
      Displays the current date in the format mm/dd/yyyy.

   toFixed2(value)
      Converts value to a text string rounded to 2 decimal places.

   roundValue(value, n)
      Rounds value to n decimal places, where n is a positive or negative
      integer. Returns a numeric value.

   addCommas(value)
      Adds comma grouping to a numeric value (###,###,###.###). Returns a
      text string

   dollars(value)
      Converts a numeric value to a current format, including commas and the
      leading "$" symbol. Returns a text string.

   luhn(num)
      Returns a Boolean value indicating whether the number in the num text
      string fulfills the Luhn Formula.

*/

MSFPhover = 
  (((navigator.appName == "Netscape") && 
  (parseInt(navigator.appVersion) >= 3 )) || 
  ((navigator.appName == "Microsoft Internet Explorer") && 
  (parseInt(navigator.appVersion) >= 4 ))); 
function MSFPpreload(img) 
{
  var a=new Image(); a.src=img; return a; 
}

/* Function XmasDays() 
   Purpose: Calculate the number of days between Christmas and a given date


Variables
CheckDay: A date object containing the given date
XYear: The 4-digit year value of the given date
XDay: December 25 in the year of the given date
DayCount: The number of days between Christmas and the given date
*/


function XmasDays(CheckDay) {
var XYear=CheckDay.getFullYear();
var XDay=new Date("October, 1, 2011");
XDay.setFullYear(XYear);
var DayCount=(XDay-CheckDay)/(1000*60*60*24);
DayCount=Math.round(DayCount);
return DayCount;
}


function startForm() {
	document.convention.date.value = todayTxt();
	document.convention.memname1.focus();
}

function todayTxt() {
   var Today=new Date();
   return Today.getMonth()+1+"-"+Today.getDate()+"-"+Today.getFullYear();
}

function toFixed2(value) {
   n = Math.round(value*100)/100;
   if (n == Math.round(n)) return n+".00";
   else if (n*10 == Math.round(n*10)) return n+"0";
   else return String(n);
}

function roundValue(value, n) {
   return Math.round(Math.pow(10,n)*value)/Math.pow(10,n);
}

function addCommas(value) {
   valuetxt=value+"";
   decimals="";
   re = /(-?\d+)(\d{3})/;

   decimalpos = valuetxt.search(/\./);
   if (decimalpos != -1) {
      decimals = "."+valuetxt.substring(decimalpos+1,valuetxt.length);
      valuetxt = valuetxt.substring(0,decimalpos);
   }
   while(re.test(valuetxt)) {valuetxt = valuetxt.replace(re,"$1,$2")}

   return valuetxt+=decimals;
}


function dollars(value) {
   n = Math.round(value*100)/100;

   if (n == Math.round(n)) {valuetxt=n+".00"}
   else if (n*10 == Math.round(n*10)) {valuetxt=n+"0"}
   else valuetxt=n+"";

   re = /(-?\d+)(\d{3})/;
   decimalpos = valuetxt.search(/\./);
   if (decimalpos != -1) {
      decimals = "."+valuetxt.substring(decimalpos+1,valuetxt.length);
      valuetxt = valuetxt.substring(0,decimalpos);
   }
   while(re.test(valuetxt)) {valuetxt = valuetxt.replace(re,"$1,$2")}

   return "$"+valuetxt+decimals;
}

function luhn(num) {
   var luhnTotal=0;
   for (i=num.length-1; i>=0; i--) {
      luhnTotal += parseInt(num.charAt(i));
      i--;
      num2 = new String(num.charAt(i)*2);
      for (j=0; j < num2.length; j++) {
         luhnTotal += parseInt(num2.charAt(j));
      }
    }
   return (luhnTotal % 10 == 0);
}




if(MSFPhover) { 
	MSFPnav1n=MSFPpreload("images/nohovhome.gif"); 
	MSFPnav1h=MSFPpreload("images/hovhome.gif"); 
	MSFPnav1hs=MSFPpreload("images/stayhome.gif"); 
	MSFPnav2n=MSFPpreload("images/nohovnews.gif"); 
	MSFPnav2h=MSFPpreload("images/hovnews.gif");	
	MSFPnav2hs=MSFPpreload("images/staynews.gif");	
	MSFPnav3n=MSFPpreload("images/nohovdistrictleaders.gif"); 
	MSFPnav3h=MSFPpreload("images/hovdistrictleaders.gif");
	MSFPnav4n=MSFPpreload("images/nohovclubs.gif"); 
	MSFPnav4h=MSFPpreload("images/hovclubs.gif"); 
	MSFPnav4hs=MSFPpreload("images/stayclubs.gif"); 
	MSFPnav5n=MSFPpreload("images/nohovoileaders.gif"); 
	MSFPnav5h=MSFPpreload("images/hovoileaders.gif");
	MSFPnav5hs=MSFPpreload("images/stayoileaders.gif");
	MSFPnav6n=MSFPpreload("images/nohovprograms.gif"); 
	MSFPnav6h=MSFPpreload("images/hovprograms.gif");
	MSFPnav6hs=MSFPpreload("images/stayprograms.gif");
	MSFPnav7n=MSFPpreload("images/nohovdateandlinks.gif"); 
	MSFPnav7h=MSFPpreload("images/hovdateandlinks.gif"); 
	MSFPnav7hs=MSFPpreload("images/staydateandlinks.gif"); 
	MSFPnav8n=MSFPpreload("images/nohovjustfun.gif"); 
	MSFPnav8h=MSFPpreload("images/hovjustfun.gif"); 
	MSFPnav8hs=MSFPpreload("images/stayjustfun.gif"); 
	MSFPnav9n=MSFPpreload("images/nohovdistrictteam.gif");
	MSFPnav9h=MSFPpreload("images/hovdistrictteam.gif");  
	MSFPnav9hs=MSFPpreload("images/staydistrictteam.gif");  
	MSFPnav10n=MSFPpreload("images/nohovforms.gif"); 
	MSFPnav10h=MSFPpreload("images/hovforms.gif");
	MSFPnav10hs=MSFPpreload("images/stayforms.gif");
	MSFPnav11n=MSFPpreload("images/nohovmembers.gif"); 
	MSFPnav11h=MSFPpreload("images/hovmembers.gif");
	MSFPnav11hs=MSFPpreload("images/staymembers.gif");
}






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

function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

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];}
}

