﻿function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function popitup(url,wattributes,xwidth,yheight){				    

		if (document.map.address.value == "" && document.map.city.value == "")
		{
			alert('Please enter the orignating address or city.');
		}

		else
		{
			url = url + "from%3A" + document.map.address.value + " " + document.map.city.value +  " " + document.map.state.value +  " " + document.map.zip.value + " to%3A%204900%20e%2038th%20st%20indianapolis%2C%20IN&hl=en";

			newwindow=window.open(url,'newWnd',wattributes); 
			//newwindow.resizeTo(xwidth,yheight); 
			if (window.focus) {newwindow.focus()}
		}
		
		return false;
		
}

function checkgiving()
{

	var tithe="";
	var offering="";
	var building="";
	var pastor="";
	var missions="";
	var outreach="";
	var benevolent="";
	var other1="";
	var other2="";
	var other3="";
	var xtithe="";
	var xoffering="";
	var xbuilding="";
	var xpastor="";
	var xmissions="";
	var xoutreach="";
	var xtotal=0;


	if(document.giving.tithe.value!="")
	{
		tithe = "Tithe/$" + document.giving.tithe.value + ", ";
		  
		if (!IsNumeric(document.giving.tithe.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the amount column') 
			document.giving.tithe.focus(); 
      		return false; 
		}
 
		xtotal = parseFloat(document.giving.tithe.value);
	}
	else
	{
		tithe = "Tithe/$0, ";
	}	

	if(document.giving.offering.value!="")
	{
		offering = "Offering/$" + document.giving.offering.value + ", ";

		if (!IsNumeric(document.giving.offering.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the amount column') 
			document.giving.offering.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseFloat(document.giving.offering.value);
	}
	else
	{
		offering = "Offering/$0, ";
	}

	if(document.giving.building.value!="")
	{
		building = "Building/$" + document.giving.building.value + ", ";

		if (!IsNumeric(document.giving.building.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.building.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseFloat(document.giving.building.value);
	}
	else
	{
		building = "Building/$0, ";
	}	

	if(document.giving.pastor.value!="")
	{
		pastor = "Pastor/$" + document.giving.pastor.value + ", ";

		if (!IsNumeric(document.giving.pastor.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.pastor.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseFloat(document.giving.pastor.value);
	}
	else
	{
		pastor = "Pastor/$0, ";
	}	

	if(document.giving.missions.value!="")
	{
		missions = "Missions/$" + document.giving.missions.value + ", ";

		if (!IsNumeric(document.giving.missions.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.missions.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseFloat(document.giving.missions.value);
	}
	else
	{
		missions = "Missions/$0, ";
	}
		
	if(document.giving.outreach.value!="")
	{
		outreach = "Outreach/$" + document.giving.outreach.value + ", ";

		if (!IsNumeric(document.giving.outreach.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.outreach.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseFloat(document.giving.outreach.value);
	}
	else
	{
		outreach = "outreach/$0, ";
	}


	if(document.giving.benevolent.value!="")
	{
		benevolent = "Benevolent/$" + document.giving.benevolent.value + ", ";

		if (!IsNumeric(document.giving.benevolent.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.benevolent.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseFloat(document.giving.benevolent.value);
	}
	else
	{
		benevolent = "Benevolent Fund/$0, ";
	}

	if(document.giving.other1.value!="")
	{
		other1 = document.giving.othername1.value + "/$" + document.giving.other1.value + ", ";

		if (!IsNumeric(document.giving.other1.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.other1.focus(); 
      		return false; 
		}

		if(document.giving.othername1.value=="")
		{
			alert('Please descibe the Other1 donation') 
			document.giving.othername1.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseFloat(document.giving.other1.value);
	}
	else
	{
		other1 = "Other1/$0, ";
	}

	if(document.giving.other2.value!="")
	{
		other2 = document.giving.othername2.value + "/$" + document.giving.other2.value + ", ";

		if (!IsNumeric(document.giving.other2.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.other2.focus(); 
      		return false; 
		}

		if(document.giving.othername2.value=="")
		{
			alert('Please descibe the Other2 donation') 
			document.giving.othername2.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseFloat(document.giving.other2.value);
	}
	else
	{
		other2 = "Other2/$0, ";
	}

	if(document.giving.other3.value!="")
	{
		other3 = document.giving.othername3.value + "/$" + document.giving.other3.value + ", ";

		if (!IsNumeric(document.giving.other3.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the amount column') 
			document.giving.other3.focus(); 
      		return false; 
		}

		if(document.giving.othername3.value=="")
		{
			alert('Please descibe the Other3 donation') 
			document.giving.othername3.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseFloat(document.giving.other3.value);

	}
	else
	{
		other3 = "Other3/$0";
	}


	document.giving.item_name.value = tithe + offering + building + pastor + missions + outreach + benevolent + other1 + other2 + other3;

	if (xtotal < 0)
	{
		alert(xtotal);
		return false;
	}

	document.giving.amount.value = xtotal;

	return true;
}