function calcAmount()
{
	var myChildCount = 1;	// # children
	var myPayPeriod = 1;	// # months
	var strPayTime = "M";	// M or Y
	var periodArray = [1,3,6,12];
	var periodArrayStr = ["Monthly","Quarterly","Biannually","Yearly"];
	var clist = document.getElementById("myChildCount");
	myChildCount = clist.options[clist.selectedIndex].text;
	clist = document.getElementById("myPeriod");
	myPayPeriod = periodArray[clist.selectedIndex];
	strPayPeriod = periodArrayStr[clist.selectedIndex];
	var theAmount = myChildCount * 30 * myPayPeriod;
	document.getElementById("myAmountVerify").value = "$" + (theAmount) + ".00 " + strPayPeriod;
	var strChildren = myChildCount + " Child" + (myChildCount>1 ? "ren":"");
	document.getElementById("myChildVerify").value = strChildren;

// DESCRIPTIVE items
// "item_name" form value - long description

// clean up the strChildIDs
	validateIDs(document.forms["subscription"].elements["myChildIDs"]);
	var strChildIDs = document.forms["subscription"].elements["myChildIDs"].value;
	strChildIDs = strChildIDs.replace(/(^[\/])|([\/]$)/g,"");
	if( strChildIDs )
		strChildIDs = " (" + strChildIDs + ")";

	document.forms["subscription"].elements["item_name"].value = "Kilimambogo Sponsorship - " + strChildren + " - " + strPayPeriod + strChildIDs;

// "item_number" form value - short description MONTHLY-1-30  Period-ChildCount-DollarAmount
	document.forms["subscription"].elements["item_number"].value = strPayPeriod.toUpperCase() + "-" + myChildCount + "-" + theAmount;

// VALUE items

	if( myPayPeriod==12 )
	{
		strPayTime = "Y";
		myPayPeriod = 1;
	}
	
	document.forms["subscription"].elements["a3"].value = theAmount + ".00";
	document.forms["subscription"].elements["t3"].value = strPayTime;
	document.forms["subscription"].elements["p3"].value = myPayPeriod;

// DEBUG LINE:
//	document.getElementById("myDebugVerify").value = document.forms["subscription"].elements["item_name"].value;

	return true;
}

// only allow numbers and comma, slash or space as dividers
function validateIDs(theID)
{
	var val = theID.value;
	val = val.replace(/[^//, 0-9]/g,"");	// delete non-numerics except for /, spc
	val = val.replace(/[//, ]+/g,"/");	// replace runs of /, spc with /
	theID.value = val;
//	document.getElementById("myDebugVerify").value = theID.value;
}

var nameUpdateTimerID = 0;

function childIDkeyUp(theID)
{
	validateIDs(theID);
	if( nameUpdateTimerID )
	{
		clearTimeout( nameUpdateTimerID );
	}
	nameUpdateTimerID = setTimeout ( "ajaxGetChildNames()", 750 );	// msec
}

function ajaxGetChildNames()
{
	var xmlHttp;
	try {
    	// Firefox, Opera 8.0+, Safari
    	xmlHttp=new XMLHttpRequest();
	} catch (e) {
    // Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function()
	{
		if( xmlHttp.readyState==4 )
		{
			document.getElementById("childIDsDisplay").innerHTML = xmlHttp.responseText;
		}
	}

	calcAmount();
	var str = document.forms["subscription"].elements["myChildIDs"].value;
	str = str.replace(/(^[\/])|([\/]$)/g,"");
	str = str.replace(/\//g,"+");
	xmlHttp.open("GET","childname.php?ids="+str,true);
	xmlHttp.send(null);
}
