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 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 calcTotal(thisid) {
	document.getElementById("resultstable").style.display = '';
	var thisValue = thisid;
	if(thisValue != "" && IsNumeric(thisValue)) {
		thisValue = parseFloat(thisid);
		var total1 = thisValue / 54;
		var total2 = thisValue / 5.43;
		var total3 = thisValue / 12.02;
		var total4 = thisValue / 1.50;
		var total5 = thisValue / 7.50;
		var total6 = thisValue / 2.28;
		//alert(thisValue);
		document.getElementById("resultbox").innerHTML = "";
		document.getElementById("contrib1").innerHTML = "$" + addCommas(thisValue.toFixed(2));
		//document.getElementById("contrib2").innerHTML = "$" + addCommas(thisValue.toFixed(2));
		//document.getElementById("contrib3").innerHTML = "$" + addCommas(thisValue.toFixed(2));
		//document.getElementById("contrib4").innerHTML = "$" + addCommas(thisValue.toFixed(2));
		//document.getElementById("contrib5").innerHTML = "$" + addCommas(thisValue.toFixed(2));
		//document.getElementById("contrib6").innerHTML = "$" + addCommas(thisValue.toFixed(2));
		
		document.getElementById("help1").innerHTML = addCommas(Math.round(total1));
		document.getElementById("help2").innerHTML = addCommas(Math.round(total2));
		document.getElementById("help3").innerHTML = addCommas(Math.round(total3));
		document.getElementById("help4").innerHTML = addCommas(Math.round(total4));
		document.getElementById("help5").innerHTML = addCommas(Math.round(total5));
		document.getElementById("help6").innerHTML = addCommas(Math.round(total6));
	}
	else {
		document.getElementById("resultbox").innerHTML = "Contribution must be numeric";
	}
	//alert(thisValue);
}
// function to process calendar clicks
	function calendarClick(caldate, calcell) {
		var currcolor = document.getElementById(calcell).style.backgroundColor;
		var currdates = window.parent.document.frmUpdate.selecteddates.value;
		var alreadyexists = -1;
		var alreadyexists = currdates.indexOf(caldate)
		//alert(caldate);
		if(currcolor == "#e2e2e2" || alreadyexists > 0) {
			//this means we are removing from the calendar
			var replacekey = "|" + caldate;
			currdates = currdates.replace(replacekey, "");
			window.parent.document.frmUpdate.selecteddates.value = currdates;
			document.getElementById(calcell).style.backgroundColor = '#ffffff';
		}
		else {
			//this means we are adding to the calendar
			currdates = currdates + "|" + caldate + "|";
			window.parent.document.frmUpdate.selecteddates.value = currdates;
			document.getElementById(calcell).style.backgroundColor = '#e2e2e2';
		}
		//alert(window.parent.document.frmUpdate.selecteddates.value);
	}
	function highlightcurrentdates() {
		var selecteddates = window.parent.document.frmUpdate.selecteddates.value;
		var eachdate = selecteddates.split("|");
		for(i = 0; i < eachdate.length; i++) {
			if(eachdate[i] != "") {
				var callid = "cell" + eachdate[i].replace("/", "");
				callid = callid.replace("/", "");
				//alert(callid);
				if(document.getElementById(callid)) {
					document.getElementById(callid).style.backgroundColor = '#e2e2e2';
				}
			}
		}
	}
	function setyear(thisid, thisyr) {
	for(i = 1; i <= 9; i++) {
		if(thisid == i) {
			document.getElementById('img_' + i).src = 'images/timeline_' + i + '_on.jpg';	
			document.getElementById('yeardes_' + i).style.display = '';	
		}
		else {
			document.getElementById('img_' + i).src = 'images/timeline_' + i + '.jpg';	
			document.getElementById('yeardes_' + i).style.display = 'none';	
		}
	}
}
function settab(thistab) {
	//alert(document.MM_sr[0].oSrc);
	//alert(x.oSrc);
	var thiselement = "";
	var thisimage = "";
	for(i = 1; i <= 4; i++) {
		var thisitem = "tab_content_" + i;
		var thisicon = "tab_off_" + i;
		if(i == thistab) {
			thiselement = document.getElementById(thisitem);
			thiselement.style.display = "block";
			thisimage = document.getElementById(thisicon);
			thisimage.src = "images/tab_on_" + i + ".gif";
			document.MM_sr[0].oSrc = "images/tab_on_" + i + ".gif";
			
		}
		else {
			thiselement = document.getElementById(thisitem);
			thiselement.style.display = "none";
			thisimage = document.getElementById(thisicon);
			thisimage.src = "images/tab_off_" + i + ".gif";
			//document.MM_sr[0].oSrc = "images/tab_off_" + i + ".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];}
}
function viewpageid(thispage, thisid, thiswidth, thisheight) {
	var thiswindow;
	thiswindow = window.open(thispage + '?id=' + thisid, 'viewpage', 'width=' + thiswidth + ',height=' + thisheight + ',scrollbars,resizable');
	thiswindow.focus();
}
function viewpage(thispage, thiswidth, thisheight) {
	var thiswindow;
	thiswindow = window.open(thispage, 'viewpage2', 'width=' + thiswidth + ',height=' + thisheight + ',scrollbars,resizable');
	thiswindow.focus();
}
function viewimage(thisimg, thiswidth, thisheight) {
	var thiswindow;
	thiswindow = window.open('viewimage.php?id=' + thisimg, 'viewphoto', 'width=' + thiswidth + ',height=' + thisheight + ',scrollbars,resizable');
	//alert('viewimage.php?id=' + thisimg);
	thiswindow.focus();
}
function viewphotogallery(thisimg, thiswidth, thisheight) {
	var thiswindow;
	thiswindow = window.open('viewphotogallery.php?id=' + thisimg, 'viewphotogallery', 'width=' + thiswidth + ',height=' + thisheight + ',scrollbars,resizable');
	//alert('viewimage.php?id=' + thisimg);
	thiswindow.focus();
}
function closethiswindow() {
	window.close();
	window.opener.focus();
}
function inittb(pagestr)
{
	tb_show('Loaded onload', pagestr, null);
}
