﻿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 loveoffering="";
	var capitalcampaign="";
	var media="";
	var homeless="";
	var other="";
	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 = parseInt(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 + parseInt(document.giving.offering.value);
	}
	else
	{
		offering = "Offering/$0, ";
	}

	if(document.giving.loveoffering.value!="")
	{
		loveoffering = "Loveoffering/$" + document.giving.loveoffering.value + ", ";

		if (!IsNumeric(document.giving.loveoffering.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.loveoffering.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseInt(document.giving.loveoffering.value);
	}
	else
	{
		loveoffering = "Loveoffering/$0, ";
	}	

	if(document.giving.capitalcampaign.value!="")
	{
		capitalcampaign = "Capitalcampaign/$" + document.giving.capitalcampaign.value + ", ";

		if (!IsNumeric(document.giving.capitalcampaign.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.capitalcampaign.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseInt(document.giving.capitalcampaign.value);
	}
	else
	{
		capitalcampaign = "Capitalcampaign/$0, ";
	}	

	if(document.giving.media.value!="")
	{
		media = "Media/$" + document.giving.media.value + ", ";

		if (!IsNumeric(document.giving.media.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.media.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseInt(document.giving.media.value);
	}
	else
	{
		media = "Media/$0, ";
	}
		
	if(document.giving.homeless.value!="")
	{
		homeless = "Homeless/$" + document.giving.homeless.value + ", ";

		if (!IsNumeric(document.giving.homeless.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the account column') 
			document.giving.homeless.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseInt(document.giving.homeless.value);
	}
	else
	{
		homeless = "homeless/$0, ";
	}

	if(document.giving.other.value!="")
	{
		other = document.giving.othername.value + "/$" + document.giving.other.value + ", ";

		if (!IsNumeric(document.giving.other.value)) 
   		{ 
			alert('Please enter only numbers or decimal points in the amount column') 
			document.giving.other.focus(); 
      		return false; 
		}

		if(document.giving.othername.value=="")
		{
			alert('Please descibe the Other donation') 
			document.giving.othername.focus(); 
      		return false; 
		}

		xtotal = xtotal + parseInt(document.giving.other.value);
	}
	else
	{
		other = "Other/$0";
	}


	document.giving.item_name.value = tithe + offering + loveoffering + capitalcampaign + media + homeless + other;

	if (xtotal < 0)
	{
		alert(xtotal);
		return false;
	}

	document.giving.amount.value = xtotal;

	return true;
}
