window.onload=init;
function init() {
 submitMe();
 //startlist();
}
function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num)) {
    num = "0";
  }
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10) {
    cents = "0" + cents;
  }
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
    num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
  }
  return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function is_number(num) {
  return (!isNaN(parseFloat(num)) && isFinite(num));
}
function validateEmail(email){  
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
   return emailPattern.test(email);
}  

function chooseAdStyle(id) {
 img=document.getElementById("adstyle"+id);
 for(var i=1; i<=4; i++) { //4 is the number of ad styles
  document.getElementById("adstyle"+i).style.border="5px solid white";
 }
 img.style.border="5px solid #99CC00";
 document.getElementById('adStyle').value=id;
}

function submitMe() {
var submitMe=document.getElementById("submitMe");
var submitMePara=document.getElementById("submitMePara");
 if(submitMe!=null&&submitMePara!=null) {
  submitMe.submit();
  submitMePara.innerHTML="Please wait while we process your donation...";
 }
}
function confirmDelete(page) {
 var c=confirm("Are you sure you want to delete "+page+"?");
 if (c) {
  return true;
 }
 else {
  return false;
 }
 return false;
}
function nextPhoneField(id) {
	var num=id.substr(-1);
	if(document.getElementById(id).value.length==3) {
		num++;
		document.getElementById("phone"+num).focus();
	}
}
function gotomonth(month,year) {
 window.location="calendar.php?month="+month+"&&year="+year;
}
function changedays() {
 var day=document.getElementById("day");
 var month=document.getElementById("month").value;
 var year=document.getElementById("year").value;
 
 if(month==9||month==4||month==6||month==11) {
  day.remove(31);
 }
 else if(month==2) {
  day.remove(30);
  day.remove(29);
  if(year%4==0) {
   var x=document.createElement("option");
   x.text="29";
   x.value="29";
   try {
    day.add(x, null); //complies with standards, not with IE
   }
   catch(ex) {
    day.add(x); //works with IE
   }
  }
 }
 else { //has 31 days
   var x=document.createElement("option");
   x.text="31";
   x.value="31";
   try {
    day.add(x, null); //complies with standards, not with IE
   }
   catch(ex) {
    day.add(x); //works with IE
   }
 }
}
startList = function() {
 if (document.all&&document.getElementById) {
  navRoot = document.getElementById("menu");
  for (i=0; i<navRoot.childNodes.length; i++) {
   node = navRoot.childNodes[i];
   if (node.nodeName=="LI") {
    node.onmouseover=function() {
     this.className+=" over";
    }
    node.onmouseout=function() {
     this.className=this.className.replace(" over", "");
    }
   }
  }
 }
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;
 
      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}
