var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""

var dt = new Date();
//var my_time=dt.getYear(); // coment this line if you want to use getFullYear
var fullYear=dt.getFullYear(); // comment this line if you want to use getYear

if(location.href.indexOf('/funrunrm.org/') != -1 ){
	var rootdomain="http://"+window.location.hostname+"/funrunrm.org/"
	var cgi = "http://"+window.location.hostname+"/funrunrm.org/cgi-bin/";	
}else{
	var rootdomain="http://"+window.location.hostname+"/"
	var cgi = "http://"+window.location.hostname+"/cgi-bin/";	
}
var bustcacheparameter=""

function GetXmlHttpObject(){
var xmlHttp=null;
try{
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }catch (e){
  // Internet Explorer
  try{
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }catch (e){
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
return xmlHttp;
}

function $(element){
    return document.getElementById(element);
}

function Trim(nStr){return nStr.replace(/(^\s*)|(\s*$)/g, "");}

String.prototype.count=function(s1) { 
	return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
}

function cleanValue(value){
	var cleanValue = value.replace(/&/g,'-,-');
	var cleanValue2 = cleanValue.replace(/#/g,'-,,-');	
	
	return cleanValue2;
}

/*
var cleanValueAmp = "|-|";
var cleanValueEqual = "|--|";
var cleanValuePound = "|---|";

function cleanValue(value){
	var origVal = value;
	value = value.replace(/<p>&nbsp;<\/p>/g,'');
//	value = value.replace(/<\/p>/g,'<br /><br />');	
//	value = value.replace(/<[(p\s)|(P\s)].[^<>]*?>/g,"<div>");		
//	value = value.replace(/<\/[p|P]>/g,'</div><br />');		
    //value = value.replace(/<.[^<>]*?[^(div)|(br \/)|(\/div)|(\/span)|(strong)|(\/strong)|(em)|(\/em)].>/g,'');	
	value = value.replace(/&nbsp;/g,' ');
	value = value.replace(/&/g,cleanValueAmp);
	value = value.replace(/=/g,cleanValueEqual);	
	value = value.replace(/#/g,cleanValuePound);
	var cleanValue = value;
	for(var i=0;i<cleanValue.count('<br />');i++){
		value = value.replace(/(<br \/>)$/,"");
	}	
	//if(value.length > 20){alert('origValue \n'+origVal+'\n\n cleanValue \n'+cleanValue+'\n\n value \n'+value);}
	
	return Trim(value);
}
*/
function loading(){
if(document.getElementById('loadingDiv')){document.getElementById('loadingDiv').parentNode.removeChild(document.getElementById('loadingDiv'));return;}
var controlPanel = document.getElementById('controlPanel');
//controlPanel.innerHTML = '';

div = document.createElement('div');
//div.className = 'onLoad';
div.style.position = 'fixed';
div.id = 'loadingDiv';
//div.style.top = '300px';
div.style.top = '45%';
div.style.left = '50%';
div.style.height = '400px';
div.align = 'center';
img = document.createElement('img');
img.src = 'RootImages/onLoad.gif';
div.appendChild(img);
controlPanel.appendChild(div);
}

function openSettings(Id,ty,lastPage){
//document.getElementById('mainContent').style.display = 'none';
//document.getElementById('controlPanel').innerHTML = Id;
if(!document.getElementById('controlPanel')){
	window.location = rootdomain+'account_settings.php';
}else{
	document.getElementById('controlPanel').style.width = '900px';
	var url = rootdomain+'RootControlpanel/users/edit_users.php?ty='+ty+'&Id='+Id;
	//alert(url);
	if(lastPage && lastPage != ''){	
		ajaxFunction(lastPage,'controlPanel','loadPage');
	}else{
		ajaxFunction(url,'controlPanel','loadPage');
	}
	
	ajaxFunction(rootdomain+'RootControlpanel/login.php','loginContainter','loadPage');
	window.scroll(0,0);
}
}
function registerOnline(){
//document.getElementById('mainContent').style.display = 'none';
//document.getElementById('controlPanel').innerHTML = Id;
//alert('http://<?= $Domain; ?>RootControlpanel/view_user_details?ty=sty&Id='+Id);
document.getElementById('controlPanel').style.width = '900px';
var url = rootdomain+'RootControlpanel/users/edit_users.php?ty=reg';
//alert(url);
ajaxFunction(url,'controlPanel','loadPage');
}
function registerOnlineNP(){
//document.getElementById('mainContent').style.display = 'none';
//document.getElementById('controlPanel').innerHTML = Id;
//alert('http://<?= $Domain; ?>RootControlpanel/view_user_details?ty=sty&Id='+Id);
document.getElementById('controlPanel').style.width = '900px';
var url = rootdomain+'RootControlpanel/users/edit_nonprofit.php?ty=reg';
//alert(url);
ajaxFunction(url,'controlPanel','loadPage');

}


function ajaxFunction(url,containerid,functionName){
	if(!document.getElementById('loadingDiv')){loading();}
	var xmlHttp = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		xmlHttp = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")} catch (e){try{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")}	catch (e){}	}
	}else
		return false
		xmlHttp.onreadystatechange=function(){
			loadPage(xmlHttp, containerid,url)
	}
	if (bustcachevar) //if bust caching of external page
	bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	xmlHttp.open('GET', url+bustcacheparameter, true)
	xmlHttp.send(null)
	//alert('url: '+url+bustcacheparameter);
}

function loadPage(xmlHttp, containerid,url){
	if (xmlHttp.readyState == 4){
		document.getElementById(containerid).innerHTML=xmlHttp.responseText;
		window.scroll(0,0);
		lastPage(url);
		if(url){
			document.getElementById('lastPage').innerHTML = url;	
		}
	}
}

var xmlHttp

function lastPage(lastPage){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootIncludes/phpScript.php?req=account_settings.php&mode=lastPage&lastPage="+cleanValue(lastPage);
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.onreadystatechange=function(){lastPageRsp();}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function lastPageRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		//alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[1]){
			document.getElementById('lastPage').innerHTML = theGoods[1];
		}
	}	
}

function shownonprofits(status,iCnt){ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootIncludes/getNonprofits.php";
	url=url+"?status="+status+"&iCnt="+iCnt;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged(){ 
	if (xmlHttp.readyState==4){ 
		var tbl = document.getElementById('donationsTbl');
		var lastRow = tbl.rows.length;
		var lastRowID = tbl.rows[Number(lastRow)-1].id;
		var iCnt = Number(lastRowID);	
		document.getElementById("select_"+iCnt).innerHTML=xmlHttp.responseText;
//		alert("select_"+iCnt+'\n\n'+xmlHttp.responseText);
	}
}

function loginForm(username, pswd){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootControlpanel/login_php.php";
	url=url+"?mode=login&username=" + username + "&pswd="+pswd;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged3;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged3(){ 
	if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText == 0){
			document.thisLoginForm.password.value = "";
			document.thisLoginForm.password.focus();
			document.getElementById("loginWarning2").style.display="";
			document.getElementById("loginWarning").innerHTML="Invalid Username / Password";
		}else if(xmlHttp.responseText.indexOf("1|") != "-1"){
			var theGoods = xmlHttp.responseText.split("|");
			showLoggedin(theGoods[1],theGoods[2]);
			
			openSettings(theGoods[1],'st');
//			alert('here: '+xmlHttp.responseText);			
		}else{
			alert('here: '+xmlHttp.responseText);
		}
		
	}
}

function requestEmail(email){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootControlpanel/login_php.php";
	url=url+"?SendEmailSubmit=y&Email=" + email;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged5;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged5(){ 
	if (xmlHttp.readyState==4){ 
	//	alert(xmlHttp.responseText);
		if(xmlHttp.responseText == 0){
			document.getElementById('requestWarning').innerHTML="The email entered was not found in our database. Contact us if you need help.";
		}else if(xmlHttp.responseText == 1){
			document.getElementById('requestWarning').innerHTML="Your password has been emailed to you.";
		}else{
	//		alert('here: '+xmlHttp.responseText);
		}
		
	}
}

function logout(){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootControlpanel/login_php.php";
	url=url+"?mode=logout";
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged4;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged4(){ 
	if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText == 1){
		ajaxFunction(rootdomain+'RootControlpanel/login.php','loginContainter','loadPage');
			window.location = rootdomain;
		}
	}
}

function ckEmail(username_org,adminUsers){
if(document.thisForm.username.value==""){
	if(adminUsers == "Admin"){return;}
	document.getElementById('usernameWarning').style.display = '';
	document.getElementById("usernameWarning").innerHTML = "- Required";
	document.getElementById('usernameWarning0').style.display = 'none';
	document.getElementById('usernameWarning1').style.display = 'none';
//	document.thisForm.username.focus(); 
	return false;
}else{
	document.getElementById('usernameWarning').style.display = 'none';
}

if (validate(Trim(document.thisForm.username.value), "email") == false) {
	document.getElementById("usernameWarning").style.display = '';
	document.getElementById("usernameWarning").innerHTML = "- Please enter a valid email address";
	document.getElementById('usernameWarning1').style.display = 'none';		
	document.thisForm.username.focus(); 	
	return false;
}else{
	document.getElementById('usernameWarning').style.display = 'none';
}

if ((document.getElementById('2usernameUpdate') && Trim(document.thisForm.alt_contact_email.value) != "") && Trim(document.thisForm.username.value) == Trim(document.thisForm.alt_contact_email.value)) {
	document.getElementById("usernameWarning").innerHTML = "- The Primary Email address must be different from the Alternate Email";
	document.getElementById("usernameWarning").style.display = '';	
	document.getElementById('usernameWarning1').style.display = 'none';		
	document.getElementById('usernameUpdate').focus(); 		
	return false;
}else{
	document.getElementById('usernameWarning').style.display = 'none';
}

if(document.thisForm.username.value!=""){
	checkUsername(username_org,adminUsers);
}
}

function checkUsername(username_org,adminUsers){
//	alert('org: '+ username_org + " now: " + document.getElementById('usernameUpdate').value);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootIncludes/checkUsername.php";
	url=url+"?username_orig=" + username_org + "&username="+document.getElementById('usernameUpdate').value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function(){stateChanged2(username_org,adminUsers);}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged2(username_org,adminUsers){ 
	if (xmlHttp.readyState==4){ 
		var theGoods = xmlHttp.responseText.split('|');
//		alert(xmlHttp.responseText);
		if(theGoods[0] == 0){
	if(!document.getElementById("primaryName")){
			document.getElementById("usernameWarning1").style.display="none";	
			document.getElementById("usernameWarning0").style.display="";
		if(adminUsers == "Admin"){
			document.getElementById("usernameWarning0").innerHTML = "<div style='margin-top:4px;'><b>"+theGoods[1]+"</b> is already active in our system.</div>";
		}else{
			document.getElementById("usernameWarning0").innerHTML = "<div style='margin-top:4px;'><b>"+theGoods[1]+"</b> is already active in our system.  <br>If this email is correct please login using the form at the top of the page to edit your account.  If not, please enter a different email address.</div>";
		}
	}else{

		if(confirm(theGoods[1]+" has already been register in our system and belongs to "+theGoods[2]+" "+theGoods[3]+".  \n\nIs "+theGoods[2]+" "+theGoods[3]+" the correct contact person for your Non Profit Organization?")){
			document.getElementById("primaryUserId").value = theGoods[7];			
			document.getElementById("primaryName").innerHTML = theGoods[2]+" "+theGoods[3];
			document.getElementById("primaryTelephone").innerHTML = theGoods[4]+" "+theGoods[5]+" "+theGoods[6];
			document.getElementById("primary_contact_f_name").value = theGoods[2];
			document.getElementById("primary_contact_l_name").value = theGoods[3];	
			document.getElementById("primary_phone1").value = theGoods[4];	
			document.getElementById("primary_phone2").value = theGoods[5];	
			document.getElementById("primary_phone3").value = theGoods[6];		
		
			document.getElementById("primary_contact_f_name").style.display = "none";
			document.getElementById("primary_contact_l_name").style.display = "none";
			document.getElementById("primaryTelephoneRow").style.display = "none";
			document.getElementById("usernameWarning1").style.display = "";		
			
		}else{
			document.getElementById("usernameUpdate").value = '';
			if(document.getElementById("primaryName").innerHTML != ""){
				document.getElementById("primaryUserId").value = "";
				document.getElementById("primaryName").innerHTML = "";
				document.getElementById("primaryTelephone").innerHTML = "";	
				document.getElementById("primary_contact_f_name").value = "";
				document.getElementById("primary_contact_l_name").value = "";	
				document.getElementById("primary_phone1").value = "";	
				document.getElementById("primary_phone2").value = "";	
				document.getElementById("primary_phone3").value = "";		
				
				document.getElementById("primary_contact_f_name").style.display = "";
				document.getElementById("primary_contact_l_name").style.display = "";
				document.getElementById("primaryTelephoneRow").style.display = "";
			}		
			document.getElementById("usernameUpdate").focus();
			document.getElementById("usernameWarning1").style.display = "none";	
		}
	} //	if(!document.getElementById("primaryName")){
		}else if(theGoods[0] == 1){
			if(document.getElementById("primaryName") && document.getElementById("primaryName") && document.getElementById("primaryName").innerHTML != ""){
				document.getElementById("primaryUserId").value = "";				
				document.getElementById("primaryName").innerHTML = "";
				document.getElementById("primaryTelephone").innerHTML = "";	
				document.getElementById("primary_contact_f_name").value = "";
				document.getElementById("primary_contact_l_name").value = "";	
				document.getElementById("primary_phone1").value = "";	
				document.getElementById("primary_phone2").value = "";	
				document.getElementById("primary_phone3").value = "";		
				
				document.getElementById("primary_contact_f_name").style.display = "";
				document.getElementById("primary_contact_l_name").style.display = "";
				document.getElementById("primaryTelephoneRow").style.display = "";
			}		
//			document.getElementById("usernameUpdate").focus();
			document.getElementById("usernameWarning1").style.display="";
			document.getElementById("usernameWarning0").style.display="none";	
		}else if(theGoods[0] == 2){
			document.getElementById("usernameWarning1").style.display="none";
			document.getElementById("usernameWarning0").style.display="none";	
		}
		return xmlHttp.responseText;
	}
}

function ckEmail2(username_org){
if(document.thisForm.alt_contact_email.value==""){
	document.getElementById('2usernameWarning').style.display = '';
	document.getElementById("2usernameWarning").innerHTML = "- Required";
	document.getElementById('2usernameWarning0').style.display = 'none';
	document.getElementById('2usernameWarning1').style.display = 'none';
//	document.thisForm.alt_contact_email.focus(); 
	return false;
}else{
	document.getElementById('2usernameWarning').style.display = 'none';
}

if (validate(Trim(document.thisForm.alt_contact_email.value), "email") == false) {
	document.getElementById("2usernameWarning").style.display = '';
	document.getElementById("2usernameWarning").innerHTML = "- Please enter a valid email address";
	document.getElementById('2usernameWarning1').style.display = 'none';			
	document.thisForm.alt_contact_email.focus(); 		
	return false;
}else{
	document.getElementById('2usernameWarning').style.display = 'none';
}

if (Trim(document.thisForm.username.value) == Trim(document.thisForm.alt_contact_email.value)) {
	document.getElementById("2usernameWarning").innerHTML = "- The Alternate Email address must be different from the Primary Email";
	document.getElementById("2usernameWarning").style.display = '';	
	document.getElementById('2usernameWarning1').style.display = 'none';		
	document.thisForm.alt_contact_email.focus(); 		
	return false;
}else{
	document.getElementById('2usernameWarning').style.display = 'none';
}

	checkUsername2(username_org);
}

function checkUsername2(username_org){
//	alert('org: '+ username_org + " now: " + document.getElementById('usernameUpdate').value);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootIncludes/checkUsername.php";
	url=url+"?username_orig=" + username_org + "&username="+document.getElementById('2usernameUpdate').value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged22;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged22(){ 
	if (xmlHttp.readyState==4){ 
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 0){
//			document.getElementById("2usernameWarning1").style.display="none";	
//			document.getElementById("2usernameWarning0").style.display="";
//			document.getElementById("2usernameWarning0").innerHTML = "<div style='margin-top:4px;'><b>"+theGoods[1]+"</b> has already been register in our system and belongs to <b>"+theGoods[2]+"</b>.  <br>If this is the correct contact person for your Non Profit Organization please continue.  If not, please enter a different email address.</div>";
if(confirm(theGoods[1]+" has already been register in our system and belongs to "+theGoods[2]+" "+theGoods[3]+".  \n\nIs "+theGoods[2]+" "+theGoods[3]+" the correct contact person for your Non Profit Organization?")){
	document.getElementById("alternateUserId").value = theGoods[7];	
	document.getElementById("alternateName").innerHTML = theGoods[2]+" "+theGoods[3];
	document.getElementById("alternateTelephone").innerHTML = theGoods[4]+" "+theGoods[5]+" "+theGoods[6];
	document.getElementById("alt_contact_f_name").value = theGoods[2];
	document.getElementById("alt_contact_l_name").value = theGoods[3];	
	document.getElementById("alt_phone1").value = theGoods[4];	
	document.getElementById("alt_phone2").value = theGoods[5];	
	document.getElementById("alt_phone3").value = theGoods[6];		

	document.getElementById("alt_contact_f_name").style.display = "none";
	document.getElementById("alt_contact_l_name").style.display = "none";
	document.getElementById("alternatePhoneRow").style.display = "none";
	document.getElementById("2usernameWarning1").style.display = "";		
	
}else{
	document.getElementById("2usernameUpdate").value = '';
	if(document.getElementById("alternateName").innerHTML != ""){
		document.getElementById("alternateUserId").value = "";			
		document.getElementById("alternateName").innerHTML = "";
		document.getElementById("alternateTelephone").innerHTML = "";	
		document.getElementById("alt_contact_f_name").value = "";
		document.getElementById("alt_contact_l_name").value = "";	
		document.getElementById("alt_phone1").value = "";	
		document.getElementById("alt_phone2").value = "";	
		document.getElementById("alt_phone3").value = "";		
		
		document.getElementById("alt_contact_f_name").style.display = "";
		document.getElementById("alt_contact_l_name").style.display = "";
		document.getElementById("alternatePhoneRow").style.display = "";
	}		
	document.getElementById("2usernameUpdate").focus();
	document.getElementById("2usernameWarning1").style.display = "none";	
}
		}else if(theGoods[0] == 1){
			if(document.getElementById("alternateName").innerHTML != ""){
				document.getElementById("alternateUserId").value = "";
				document.getElementById("alternateName").innerHTML = "";
				document.getElementById("alternateTelephone").innerHTML = "";	
				document.getElementById("alt_contact_f_name").value = "";
				document.getElementById("alt_contact_l_name").value = "";	
				document.getElementById("alt_phone1").value = "";	
				document.getElementById("alt_phone2").value = "";	
				document.getElementById("alt_phone3").value = "";		
				
				document.getElementById("alt_contact_f_name").style.display = "";
				document.getElementById("alt_contact_l_name").style.display = "";
				document.getElementById("alternatePhoneRow").style.display = "";
			}
			document.getElementById("2usernameWarning1").style.display="";
			document.getElementById("2usernameWarning0").style.display="none";	
		}else if(theGoods[0] == 2){
			document.getElementById("2usernameWarning1").style.display="none";
			document.getElementById("2usernameWarning0").style.display="none";	
		}		
		return xmlHttp.responseText;
	}
}




function showformView(){
	document.getElementById('subTitle1').style.display = 'none';
	document.getElementById('subTitle2').style.display = '';
	document.getElementById('addView').style.display = 'none';
	document.getElementById('formView').style.display = '';
}

function delp(Id,ty,delAll,version){
	if(version == 'mult'){
		var form = document.thisForm;
		var numck = 0;
		for (i = 0; i < form.elements.length; i++) {
			var elName = form.elements[i].name;
			if(form.elements[i].type == 'checkbox' && form.elements[i].checked){numck = 1;}
		}
		if(numck == 0){	alert("Select at least one User to update.");	return false;	}
	}
if(ty =='ad'){var type = 'User';}
else if(ty =='rac'){var type = 'Race Participant';}
else if(ty =='don'){var type = 'donation';}

if(confirm("This will remove all information for the selected "+ type +"(s) from the database.  Are you sure you would like to delete?")){
			if(Id=='ckAll'){
				var url=rootdomain+"RootControlpanel/users/view_users.php";
				url=url+"?mode=del&ty="+ty;
				var form = document.thisForm
				for (i = 0; i < form.elements.length; i++) {
				var elName = form.elements[i].name;
				if(form.elements[i].type == 'checkbox' && form.elements[i].checked && form.elements[i].name.indexOf('chkSelect') != -1){
				var elValue = form.elements[i].value;		
				url=url+"&"+elName+"="+elValue;
			}
			}
			ajaxFunction(url,'controlPanel','loadPage')

		}else{
//	   alert(rootdomain+'RootControlpanel/users/view_users.php?mode=del&ty='+ty+'&delAll='+delAll+'&chkSelect[]='+Id);
ajaxFunction(rootdomain+'RootControlpanel/users/view_users.php?mode=del&ty='+ty+'&delAll='+delAll+'&chkSelect[]='+Id,'controlPanel','loadPage')
		}
		}
		else
		{
		return false;
		}
	}

function TabNext(obj,event,len,next_field) {
	phone_field_length=1;
    if (event == "down") {
           phone_field_length=obj.value.length;
   }
   else if (event == "up") {
          if (obj.value.length != phone_field_length) {
                phone_field_length=obj.value.length;
                if (phone_field_length == len) {
                next_field.focus();
                }
          }
    }
}


function testPassword(){
	if(document.thisForm.password.value.length < 6){
		alert('This password is too short.  Your password must be at least six characters long.');
		document.thisForm.password.focus(); 
		return false;
	}
}

function testPassword2(){
if(document.thisForm.password.value != document.thisForm.password2.value){
document.getElementById('pswdWarning').style.display='';
//document.thisForm.password2.focus(); 
window.scroll(0,0);
return false;
}else{
document.getElementById('pswdWarning').style.display='none';	
}
}

function ShipCountryDropDown(val){
	if(val == "United States of America"){
		document.getElementById('ShipUsaStates').style.display = '';
		document.getElementById('ShipCanadaStates').style.display = 'none';
	}else{
		document.getElementById('ShipUsaStates').style.display = 'none';
		document.getElementById('ShipCanadaStates').style.display = '';

	}
}


//var fifteen_k_amt = 20;
var ten_k_amt = 35;
var five_k_amt = 35;
var fun_walk_amt = 10;
var kids_dash_amt = 5;


function paymentAmount(){
var form = document.getElementById('thisForm');
//var amt_15k = 20;
var amt_10k = 0;
var amt_5k = 0;
var amt_fun_walk = 0;
var amt_kids_dash = 0;
var amt_donations = 0;
	/*
	for (i = 0; i < form.elements.length; i++) {
		var str = form.elements[i].name;
		if (form.elements[i].type == "checkbox" && form.elements[i].checked && str.indexOf("fifteen_k_") != "-1"){
			amt_15k += 1;
		}
	}
	*/
	for (i = 0; i < form.elements.length; i++) {
		var str = form.elements[i].name;
		if (form.elements[i].type == "checkbox" && form.elements[i].checked && str.indexOf("ten_k_") != "-1"){
			amt_10k += 1;
		}
	}
	for (i = 0; i < form.elements.length; i++) {
		var str = form.elements[i].name;
		if (form.elements[i].type == "checkbox" && form.elements[i].checked && str.indexOf("five_k_") != "-1"){
			amt_5k += 1;
		}
	}
	for (i = 0; i < form.elements.length; i++) {
		var str = form.elements[i].name;
		if (form.elements[i].type == "checkbox" && form.elements[i].checked && str.indexOf("fun_walk_") != "-1"){
			amt_fun_walk += 1;
		}
	}
	for (i = 0; i < form.elements.length; i++) {
		var str = form.elements[i].name;
		if (form.elements[i].type == "checkbox" && form.elements[i].checked && str.indexOf("kids_dash_") != "-1"){
			amt_kids_dash += 1;
		}
	}
	for (i = 0; i < form.elements.length; i++) {
		var str = form.elements[i].name;
		if ((form.elements[i].type == "text" || form.elements[i].type == "hidden") && form.elements[i].value !='' && str.indexOf("amount_") != "-1"){
			amt_donations = Number(stripNonNumeric(amt_donations)) + Number(stripNonNumeric(form.elements[i].value));
//			alert('amt: '+Number(stripNonNumeric(form.elements[i].value)));
		}
	}

var nowDueNonTaxDeductible = (Number(amt_10k) * ten_k_amt) + (Number(amt_5k) * five_k_amt) + (Number(amt_fun_walk) * fun_walk_amt) + (Number(amt_kids_dash) * kids_dash_amt);
var nowDueTaxDeductible = Number(amt_donations);
var nowDue =  nowDueNonTaxDeductible + nowDueTaxDeductible;

var amtDueNonTaxDeductible = Number(nowDueNonTaxDeductible) - Number(document.getElementById('nonTaxDeductiblePaid').innerHTML);
var amtDueTaxDeductible = Number(nowDueTaxDeductible) - Number(document.getElementById('taxDeductiblePaid').innerHTML);

var amtDue = Number(nowDue) - Number(document.getElementById('amtPaid').innerHTML);

document.getElementById('amtDueNonTaxDeductible').innerHTML = formatCurrency(amtDueNonTaxDeductible);
document.getElementById('amtDueTaxDeductible').innerHTML = formatCurrency(amtDueTaxDeductible);
document.getElementById('amtDue').innerHTML = formatCurrency(amtDue);
document.getElementById('totalDue').value = amtDue;
if(amtDue > 0 && document.getElementById('adminUsers').innerHTML != 'Admin'){
	document.getElementById('creditCardDiv').style.display = '';
}else if(amtDue > 0){
//	document.getElementById('paymentMethodDiv').style.display = '';
}else{
	document.getElementById('paymentMethodDiv').style.display = 'none';
}
}

function addRace(){
	var tbl = document.getElementById('raceParticipants');	

	if(document.getElementById('noRaceparticipants')){var noRaceparticipants = 1;tbl.deleteRow(document.getElementById('noRaceparticipants').rowIndex);}

	if(noRaceparticipants == 1){
//		document.getElementById('raceTitle').style.display ="";
		var lastRow = 1;
		var iCnt = 1;	
	}else{
		var lastRow = tbl.rows.length;
		var lastRowID = tbl.rows[Number(lastRow)-1].id;
		var lastRowIDnum = lastRowID.replace('race','');
		var iCnt = Number(lastRowIDnum) + 1;	
//		alert('lastRowIDnum: '+lastRowIDnum);
	}
	var row = tbl.insertRow(lastRow);
	row.className='tblBody';
	row.id = 'race'+iCnt;

    var cell = row.insertCell(0);
	cell.vAlign = 'top';
	div = document.createElement('div');
	el = document.createTextNode('Name: *');
	div.appendChild(el);
	cell.appendChild(div);
	
	div = document.createElement('div');
	el = document.createElement('input');
	el.type = 'text';
    el.className = 'txtbox';
	el.style.width = '250px';
	el.name = 'p_name_new_' + iCnt;
	div.appendChild(el);
	cell.appendChild(div);

	div = document.createElement('div');
	el = document.createTextNode('Email:');
	div.appendChild(el);
	cell.appendChild(div);
	
	div = document.createElement('div');
	el = document.createElement('input');
	el.type = 'text';
    el.className = 'txtbox';
	el.style.width = '250px';
	el.name = 'p_email_new_' + iCnt;
	
	div.appendChild(el);
	cell.appendChild(div);
    
	div = document.createElement('div');
	el = document.createTextNode('T-shirt size:  (Size is not guaranteed)');
	div.appendChild(el);
	cell.appendChild(div);
	
	div = document.createElement('div');
	el = document.createElement('select');
	el.id = 'p_t_shirt_new_' + iCnt;
    el.className = 'txtbox';
	el.style.width = '254px';
	el.name = 'p_t_shirt_new_' + iCnt;
	
	el1 = document.createElement('option');
	el1.value = '';
	el1_ = document.createTextNode('- Select -');

	el2 = document.createElement('option');
	el2.value = 'Youth M';
	el2_ = document.createTextNode('Youth M');
	
	el3a = document.createElement('option');
	el3a.value = 'XS';
	el3a_ = document.createTextNode('XS');
	
	el3 = document.createElement('option');
	el3.value = 'Small';
	el3_ = document.createTextNode('Small');

	el4 = document.createElement('option');
	el4.value = 'Medium';
	el4_ = document.createTextNode('Medium');

	el5 = document.createElement('option');
	el5.value = 'Large';
	el5_ = document.createTextNode('Large');

	el6 = document.createElement('option');
	el6.value = 'XL';
	el6_ = document.createTextNode('XL');

	el7 = document.createElement('option');
	el7.value = 'XXL';
	el7_ = document.createTextNode('XXL');

	el.appendChild(el1);
	el1.appendChild(el1_);
	el.appendChild(el2);
	el2.appendChild(el2_);
	el.appendChild(el3a);
	el3a.appendChild(el3a_);
	el.appendChild(el3);
	el3.appendChild(el3_);
	el.appendChild(el4);
	el4.appendChild(el4_);
	el.appendChild(el5);
	el5.appendChild(el5_);
	el.appendChild(el6);
	el6.appendChild(el6_);
	el.appendChild(el7);
	el7.appendChild(el7_);

	div.appendChild(el);
	cell.appendChild(div);

	div = document.createElement('div');
	div.style.height = '10px';
	cell.appendChild(div);
	
	var cell = row.insertCell(1);
	cell.vAlign = 'top';
//    var el_ = document.createTextNode(iCnt + ' - ');
    var el = document.createTextNode(fullYear+' Fun Run for Charities');

	var el2 = document.createElement('input');
	el2.type = 'hidden';
	el2.name = 'partId_add[]';
	el2.value = iCnt; 

//  cell.appendChild(el_)		
    cell.appendChild(el)
	cell.appendChild(el2)		


	var cell = row.insertCell(2);
	cell.align = 'center';
	cell.vAlign = 'top';


    tbl2 = document.createElement('table');
	tbl2.cellSpacing = 0;
	tbl2.cellPadding = 0;
	tbl2.border = 0;
	tbl2.width = '100%';

/*
	var row2 = tbl2.insertRow(0);
    var cell2 = row2.insertCell(0);
	cell2.align = 'left';

	el4 = document.createElement('input');
	el4.type = 'checkbox';
	el4.name = 'fifteen_k_new_'+iCnt;
	el4.id = 'fifteen_k_new_'+iCnt;	
	el4.value = 'Yes';	
	el4.onclick=function(){return paymentAmount()};
	el5 = document.createTextNode(' 15K');
	cell2.appendChild(el4);
	cell2.appendChild(el5);
	
    var cell2 = row2.insertCell(1);
	cell2.align = 'right';
	el7 = document.createTextNode('$'+fifteen_k_amt+'.00');
	cell2.appendChild(el7);

	var row2 = tbl2.insertRow(0);
    var cell2 = row2.insertCell(0);
	cell2.align = 'left';

	el4 = document.createElement('input');
	el4.type = 'checkbox';
	el4.name = 'ten_k_new_'+iCnt;
	el4.id = 'ten_k_new_'+iCnt;	
	el4.value = 'Yes';	
	el4.onclick=function(){return paymentAmount()};
	el5 = document.createTextNode(' 10K');
	cell2.appendChild(el4);
	cell2.appendChild(el5);
	
    var cell2 = row2.insertCell(1);
	cell2.align = 'right';
	el7 = document.createTextNode('$'+ten_k_amt+'.00');
	cell2.appendChild(el7);

	var row2 = tbl2.insertRow(1);
    var cell2 = row2.insertCell(0);
	cell2.align = 'left';

	el4 = document.createElement('input');
	el4.type = 'checkbox';
	el4.name = 'five_k_new_'+iCnt;
	el4.id = 'five_k_new_'+iCnt;	
	el4.value = 'Yes';	
	el4.onclick=function(){return paymentAmount()};
	el5 = document.createTextNode(' 5K');
	cell2.appendChild(el4);
	cell2.appendChild(el5);
	
    var cell2 = row2.insertCell(1);
	cell2.align = 'right';
	el7 = document.createTextNode('$'+five_k_amt+'.00');
	cell2.appendChild(el7);
*/
	var row2 = tbl2.insertRow(0);
    var cell2 = row2.insertCell(0);
	cell2.align = 'left';

	el4 = document.createElement('input');
	el4.type = 'checkbox';
	el4.name = 'fun_walk_new_'+iCnt;
	el4.id = 'fun_walk_new_'+iCnt;	
	el4.value = 'Yes';	
	el4.onclick=function(){return paymentAmount()};
	el5 = document.createTextNode(' Fun Walk');
	cell2.appendChild(el4);
	cell2.appendChild(el5);
	
    var cell2 = row2.insertCell(1);
	cell2.align = 'right';
	el7 = document.createTextNode('$'+fun_walk_amt+'.00');
	cell2.appendChild(el7);

	var row2 = tbl2.insertRow(1);
    var cell2 = row2.insertCell(0);
	cell2.align = 'left';

	el4 = document.createElement('input');
	el4.type = 'checkbox';
	el4.name = 'kids_dash_new_'+iCnt;
	el4.id = 'kids_dash_new_'+iCnt;	
	el4.value = 'Yes';	
	el4.onclick=function(){return paymentAmount()};
	el5 = document.createTextNode(' Kids Dash');
	cell2.appendChild(el4);
	cell2.appendChild(el5);
	
    var cell2 = row2.insertCell(1);
	cell2.align = 'right';
	el7 = document.createTextNode('$'+kids_dash_amt+'.00');
	cell2.appendChild(el7);

	cell.appendChild(tbl2);

	
	var cell = row.insertCell(3);
	cell.align = 'center';
	cell.vAlign = 'top';	
    el = document.createElement('select');
	el.name = 'gender_new_'+iCnt;
	el.id = 'gender_new_'+iCnt;
	el.className = 'selectmenu';
	el.style.width = '75px';
	
	el1 = document.createElement('option');
	el1.value = '';
	el1_ = document.createTextNode('- Select -');

	el2 = document.createElement('option');
	el2.value = 'Female';
	el2_ = document.createTextNode('Female');
	
	el3 = document.createElement('option');
	el3.value = 'Male';
	el3_ = document.createTextNode('Male');
	
	el.appendChild(el1);
	el1.appendChild(el1_);
	el.appendChild(el2);
	el2.appendChild(el2_);
	el.appendChild(el3);
	el3.appendChild(el3_);
	cell.appendChild(el);

	el = document.createTextNode(' *')
	cell.appendChild(el);

	var cell = row.insertCell(4);
	cell.align = 'center';
	cell.vAlign = 'top';

	el = document.createElement('select');
	el.name = 'age_division_new_' + iCnt;
	el.id = 'age_division_new_' + iCnt;
	el.className = 'selectmenu';
	el.style.width = '80px';

	el1 = document.createElement('option');
	el1.value = '';
	el1_ = document.createTextNode('- Select -');
	
	el2 = document.createElement('option');
	el2.value = 'Under 13';
	el2_ = document.createTextNode('Under 13');
	
	el3 = document.createElement('option');
	el3.value = '14-19';
	el3_ = document.createTextNode('14-19');
	
	el4 = document.createElement('option');
	el4.value = '20-29';
	el4_ = document.createTextNode('20-29');
	
	el5 = document.createElement('option');
	el5.value = '30-39';
	el5_ = document.createTextNode('30-39');
	
	el6 = document.createElement('option');
	el6.value = '40-49';
	el6_ = document.createTextNode('40-49');
	
	el7 = document.createElement('option');
	el7.value = '50-59';
	el7_ = document.createTextNode('50-59');
	
	el8 = document.createElement('option');
	el8.value = '60 & over';
	el8_ = document.createTextNode('60 & over');
	
	el.appendChild(el1);
	el1.appendChild(el1_);
	el.appendChild(el2);
	el2.appendChild(el2_);
	el.appendChild(el3);
	el3.appendChild(el3_);
	el.appendChild(el4);
	el4.appendChild(el4_);
	el.appendChild(el5);
	el5.appendChild(el5_);
	el.appendChild(el6);
	el6.appendChild(el6_);
	el.appendChild(el7);
	el7.appendChild(el7_);
	el.appendChild(el8);
	el8.appendChild(el8_);
	cell.appendChild(el);

	el = document.createTextNode(' *')
	cell.appendChild(el);
	
	var cell = row.insertCell(5);
	cell.align = 'center';
	cell.vAlign = 'top';	
    el = document.createElement('img');
	el.src = 'RootImages/x.gif';
	el.onclick = function(){return removeRaceParticipant(iCnt)}; // iCnt comes from top
	el.title='Click to delete this race participant.'
	cell.appendChild(el);
	
	document.getElementById('waiver').style.display = '';
}
function removeRaceParticipant(iCnt,thisForm){
var ans = confirm('Are you sure you would like to delete this race participant?');
	if(ans){
			var tbl = document.getElementById('raceParticipants');
//			alert('index: '+document.getElementById('race'+iCnt).rowIndex+' - length: '+tbl.rows.length);
			tbl.deleteRow(document.getElementById('race'+iCnt).rowIndex);
			if(tbl.rows.length == 1){
				document.getElementById('raceTitle').style.display ="none";
				var lastRow = tbl.rows.length;
				var iteration = lastRow;
				var row = tbl.insertRow(lastRow);
				row.className='tblBody';
				row.id = 'noRaceparticipants';

				var cell = row.insertCell(0);
				cell.colSpan = '10';
				var el = document.createTextNode('Add a race participant by clicking \'Add Race Participant\' above.');
				cell.appendChild(el)
				cell.align = 'center';
			}

		var form = document.getElementById('thisForm');
		var	newPart = 0;
		for (i = 0; i < form.elements.length; i++) {
		var str = form.elements[i].name;
			if (form.elements[i].type == "text" && str.indexOf("p_name_new_") != "-1"){
				newPart = newPart + 1;
			}
		}
		if(newPart == 0){document.getElementById('waiver').style.display = 'none';}
		paymentAmount();	
	}else{
		return ans;
	}
}

function addDonation(){
	var tbl = document.getElementById('donationsTbl');

	if(document.getElementById('noDonations')){tbl.deleteRow(document.getElementById('noDonations').rowIndex);}
	var lastRow = tbl.rows.length;
	var lastRowID = tbl.rows[Number(lastRow)-1].id;
	
	if(lastRowID == "donationsTitle"){
		var lastRow = 1;
		var iCnt = 1;	
	}else{
		var iCnt = Number(lastRowID.replace('donation','')) + 1;
//		alert(iCnt+'\n\nlastRow: '+lastRow+'\n\nlastRowID: '+lastRowID); 
	}

	var row = tbl.insertRow(lastRow);
	row.className='tblBody';
	row.id = iCnt;
    var cell = row.insertCell(0);
	cell.style.width='400px';
	el = document.createElement('div');
	el.id = 'select_'+iCnt;
	cell.appendChild(el);
	 
 	var cell = row.insertCell(1);
	cell.style.width='280px';
	var el_ = document.createTextNode(iCnt + ' - ');
    var el = document.createTextNode(fullYear+' Fun Run for Charities');

	var el2 = document.createElement('input');
	el2.type = 'hidden';
	el2.name = 'donId_add[]';
	el2.value = iCnt; 	
    cell.appendChild(el)
	cell.appendChild(el2)	
	
	var cell = row.insertCell(2);
	cell.align = 'center';
    el_ = document.createTextNode('$ ');
    el = document.createElement('input');
	el.type = 'text';
	el.className = 'txtbox';	
	el.style.width = '100px';
	el.name = 'amount_new_'+iCnt;
	el.id = 'amount_new_'+iCnt;	
	el.onblur=function(){return paymentAmount()};
	cell.appendChild(el_);
	cell.appendChild(el);

	el = document.createTextNode(' *');
	cell.appendChild(el);

	var cell = row.insertCell(3);
	cell.align = 'center';
	el = document.createElement('img');
	el.src = 'RootImages/x.gif';
	el.title='Click to delete this donation.'
	el.onclick = function(){return removeDonation(iCnt)}; // iCnt comes from top

	cell.appendChild(el);

	shownonprofits('Active',iCnt);
	document.getElementById('anonymousDiv').style.display = '';
	document.getElementById('charityConfirmDiv').innerHTML = 'no';
}

function removeDonation(iCnt){
var ans = confirm('Are you sure you would like to delete this donation?');
	if(ans){
			var tbl = document.getElementById('donationsTbl');
//			alert('index: '+document.getElementById(iCnt).rowIndex+' - length: '+tbl.getElementsByTagName('tr').length);
			tbl.deleteRow(document.getElementById(iCnt).rowIndex);
			if(tbl.getElementsByTagName('tr').length == 1){
				document.getElementById('donationsTitle').style.display ="none";
				var lastRow = tbl.rows.length;
				var iteration = lastRow;
				var row = tbl.insertRow(lastRow);
				row.className='tblBody';
				row.id = 'noDonations';

				var cell = row.insertCell(0);
				cell.colSpan = '7';
			var el = document.createTextNode('Add a donation by clicking \'Make a Donation\' above.');
			cell.appendChild(el);
			cell.align = 'center';
			document.getElementById('anonymousDiv').style.display = 'none';
			document.getElementById('charityConfirmDiv').innerHTML = '';
			}
			paymentAmount();
	}else{
		return ans;
	}
}

function showPaymentMethod(){
for (var i=0; i < document.thisForm.paymentMethod.length; i++){
	if (document.thisForm.paymentMethod[i].checked){
		var paymentMethod = document.thisForm.paymentMethod[i].value;
	}
}

	if(paymentMethod == 'Credit Card'){
		document.getElementById('creditCardDiv').style.display='';
		document.getElementById('checkDiv').style.display='none';
	}else{
		document.getElementById('creditCardDiv').style.display='none';
		document.getElementById('checkDiv').style.display='';
	}
//	var dt = document.getElementById('creditCardDiv').offsetTop;
//	window.top.scroll(0,dt); 
}


function fnSubmit(Id,ty,username_orig,adminUsers,userAdmin){ //userAdmin = user logged in

if(document.thisForm.f_name.value==""){
	document.getElementById('nameWarning').style.display = '';
//	alert("Please enter the first name of this user."); 
	document.thisForm.f_name.focus(); 
	window.scroll(0,0);
	return false;
}else{
	document.getElementById('nameWarning').style.display = 'none';
}
if(document.thisForm.l_name.value==""){
//	alert("Please enter the last name of this user."); 
	document.getElementById('nameWarning').style.display = '';
	document.thisForm.l_name.focus(); 
	window.scroll(0,0);
	return false;
}else{
	document.getElementById('nameWarning').style.display = 'none';
}


ckEmail(username_orig,userAdmin);

if(userAdmin != 'Admin' && adminUsers != 'Admin'){
	if(document.getElementById("usernameWarning").style.display != 'none' || (document.getElementById("usernameWarning1").style.display != "" && username_orig != document.thisForm.username.value)){
		window.scroll(0,0);
		return false;
	}
}else{
	document.getElementById("usernameWarning").style.display = "none"; //if Admin take away required
	if(document.getElementById("usernameWarning0").style.display != "none" && username_orig != document.thisForm.username.value){
		window.scroll(0,0);
		return false;
	}
}

if(document.thisForm.password){
	if(document.thisForm.password.value != ''){
		testPassword();
		testPassword2();
	}
}
if(document.getElementById('pswdWarning')){
		if(document.getElementById('pswdWarning').style.display!='none'){return false;}
}
	
if(userAdmin != 'Admin'){
	if(document.thisForm.ship_street.value==""){
	//	alert("Please enter the last name of this user."); 
		document.getElementById('addressWarning').style.display = '';
		document.thisForm.ship_street.focus(); 
		window.scroll(0,0);
		return false;
	}else{
		document.getElementById('addressWarning').style.display = 'none';
	}
	if(document.thisForm.ship_city.value==""){
	//	alert("Please enter the last name of this user."); 
		document.getElementById('cityWarning').style.display = '';
		document.thisForm.ship_city.focus(); 
		window.scroll(0,0);
		return false;
	}else{
		document.getElementById('cityWarning').style.display = 'none';
	}
	
	 reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
	if(document.thisForm.ship_zip.value==""){
	//	alert("Please enter the last name of this user."); 
		document.getElementById('zipWarning').style.display = '';
		document.thisForm.ship_zip.focus(); 
		window.scroll(0,0);
		return false;
	}else if (!reZip.test(document.thisForm.ship_zip.value)) {
		  document.getElementById('zipWarning').style.display = '';
		document.thisForm.ship_zip.focus(); 
		window.scroll(0,0);
		return false;
	  }else{
		document.getElementById('zipWarning').style.display = 'none';
	}
	if(document.thisForm.ship_phone1.value=="" || document.thisForm.ship_phone2.value=="" || document.thisForm.ship_phone3.value==""){
	//	alert("Please enter the last name of this user."); 
		document.getElementById('phoneWarning').style.display = '';
		document.thisForm.ship_phone1.focus(); 
		window.scroll(0,0);
		return false;
	}else if(document.thisForm.ship_phone1.value.length != 3){ 
		document.getElementById('phoneWarning').style.display = '';
		document.thisForm.ship_phone1.focus(); 
		window.scroll(0,0);
		return false;
	}else if(document.thisForm.ship_phone2.value.length != 3){ 
		document.getElementById('phoneWarning').style.display = '';
		document.thisForm.ship_phone1.focus(); 
		window.scroll(0,0);
		return false;
	}else if(document.thisForm.ship_phone3.value.length != 4){ 
		document.getElementById('phoneWarning').style.display = '';
		document.thisForm.ship_phone1.focus(); 
		window.scroll(0,0);	
		return false;
	}else{
		document.getElementById('phoneWarning').style.display = 'none';
	}
} //end if adminUsers != 'Admin'

if(!eventYes){var eventYes = 0; } // ck to see if there are any race participants
var form = document.thisForm;
	for (i = 0; i < form.elements.length; i++) {
		var str = form.elements[i].name;
        if (form.elements[i].type == "text" && form.elements[i].value == "" && str.indexOf("p_name_") != "-1"){
            alert("Please provide a name for all participants. ");
            form.elements[i].focus();
            return false;
		}else if(form.elements[i].type == "text" && str.indexOf("p_name_") != "-1"){
			var eventYes = 1;  // tells there is at least one event participant
		}
		
		if(str.indexOf("p_name_new_") != "-1"){
				var num = str.replace('p_name_new_','');
	
				if($('ten_k_new_'+num) && $('ten_k_new_'+num).checked != true && $('five_k_new_'+num) && $('five_k_new_'+num).checked != true && $('fun_walk_new_'+num).checked != true && $('kids_dash_new_'+num).checked != true){	
					alert('Please select at least one race for '+form.elements[i].value+'.');
					return false;		
				}
				if(document.getElementById('gender_new_'+num).value == ''){
					alert("Please indicate the gender of all Race Participants. ");
					return false;		
				}
				if(document.getElementById('age_division_new_'+num).value == ''){
					alert("Please indicate the age division for all Race Participants. ");
					return false;		
				}
				
		}else if(str.indexOf("p_name_") != "-1"){
				var num = str.replace('p_name_','');
				if($('ten_k_new_'+num) && $('ten_k_'+num).checked != true && $('five_k_new_'+num) && $('five_k_'+num).checked != true && $('fun_walk_'+num).checked != true && $('kids_dash_'+num).checked != true){
					alert('Please select at least one race for '+form.elements[i].value+'.');
					return false;
				}
		}else{
	
/*			if (document.getElementById('charityConfirmDiv') && document.getElementById('charityConfirmDiv').innerHTML != 'no' && ty == 'reg'){	
				var ans = confirm('This is a charity run so in addition to your registration fee (not tax deductible), please consider making a donation to one of the partnering organizations.');
				if(ans){
					addDonation();
					return ans;
				}else{
					document.getElementById('charityConfirmDiv').innerHTML = 'no';
				}
			}
*/			
					document.getElementById('charityConfirmDiv').innerHTML = 'no';
		}

		if(!donationYes){var donationYes = 0;} // ck to see if there are any donations

		if(str.indexOf("nonprofitId_new_") != "-1"){
			var num = str.replace('nonprofitId_new_','');
			
			if($('nonprofitId_new_'+num).value == ''){
				alert('Please select a Non-Profit Organization to receive your donation.');
				return false;		
			}
			if($('amount_new_'+num).value == '' || $('amount_new_'+num).value == 0){
				alert('Please insert an amount for your donation.');
				return false;		
			}
			donationYes = 1;  // tells there is at least one donation
		}else if(str.indexOf("nonprofitId_") != "-1"){
			var num = str.replace('nonprofitId_','');
			
			if(!$('amount_'+num)){alert('amount_'+num);}
			if($('amount_'+num).value == '' || $('amount_'+num).value == 0){
				alert('Please insert an amount for your donation.');
				return false;		
			}
				donationYes = 1;  // tells there is at least one donation
		}
    }//for()

	if(document.getElementById('waiver') && document.getElementById('waiver').style.display != 'none' && !document.thisForm.waiver.checked){
		alert('In order to register a race participant you must agree to the \'Waiver of Liability\'');
		return false;		
	}

var paymentMethodVal = 0;
for(i=0;i<document.thisForm.paymentMethod.length;i++){
	if(document.thisForm.paymentMethod[i].checked == true){paymentMethodVal = document.thisForm.paymentMethod[i].value;}
}

if(ty == 'reg' || ty == 'st'){
	if(document.getElementById('paymentMethodDiv').style.display != 'none' && paymentMethodVal == 0){
		alert('Please indicate your prefered Payment Method.');
		return false;		
	}
}

if(ty == 'reg' && donationYes == 0 && eventYes == 0){
	alert('In order to submit this application please either Make a Donation or Add a Race Participant.');
	return false;		

}
//alert('Type: ' + ty + 'Donations: '+ donationYes + ' Events: ' + eventYes);

for(i=0; i<document.thisForm.length; i++){
//	document.write(document.thisForm.elements[i].name + " = " + document.thisForm.elements[i].disabled + "<br />");
document.thisForm.elements[i].disabled = false;
}
if(Id == 'add'){
	var mode = 'add'
}else{
	var mode = 'update'
}

updateUserDB(Id,ty,mode);

}
function notChecked2(obj){
	checked = false;

		if(obj.length){
			for(i=0;i<obj.length;i++){
				if(obj[i].checked){
					checked = true;break;
				}
			}
		}else if(obj.checked){	
			checked = true;
		}

		if(!(checked)){
	
	//		alert("Please select the "+msg);
	
			if(obj.length)
				obj[0].focus();
			else
				try{obj.focus();}catch(err){}
				
	return true;
		}else{
			
			return false;	
		}
}

function updateUserDB(Id,ty,mode){ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootControlpanel/users/edit_users.php";
	url=url+"?mode="+mode;
	if(Id != 'add'){url=url+"&Id="+Id;}
var form = document.thisForm
var add_np = '';
for (i = 0; i < form.elements.length; i++) {
	var elName = form.elements[i].name;
	if(form.elements[i].type == 'checkbox' && form.elements[i].checked && form.elements[i].name.indexOf("add_np[]") != "-1"){
		if(add_np != ''){
			add_np = add_np + '|' + form.elements[i].value;
		}else{
			add_np = form.elements[i].value;
		}
	}else if(form.elements[i].type == 'checkbox' && !form.elements[i].checked && form.elements[i].name.indexOf("add_np[]") != "-1"){
		//var elValue = 'No';	
	}else if(form.elements[i].type == 'checkbox' && form.elements[i].checked){
		var elValue = 'Yes';		
	}else if(form.elements[i].type == 'checkbox' && !form.elements[i].checked){
		var elValue = 'No';		
	}else if ((form.elements[i].type == "hidden" || form.elements[i].type == "text") && form.elements[i].value !='' && form.elements[i].name.indexOf("amount_") != "-1"){
		var elValue = stripNonNumeric(form.elements[i].value);
	}else{
		var elValue = form.elements[i].value;		
	}
	if(elName!='Id'  && elName != "add_np[]"){
		url=url+"&"+elName+"="+elValue;
	}

} //end for(

url=url+"&add_np=" + add_np ;

	if(document.getElementById('creditCard') && document.getElementById('creditCard').checked){ //document.getElementById('paymentMethodDiv').style.display != 'none' &&
		url=url+"&paymentMethod=Credit Card";
	}else if(document.getElementById('check') && document.getElementById('check').checked){//document.getElementById('paymentMethodDiv').style.display != 'none' && 
		url=url+"&paymentMethod=Check";
	}
	url=url+"&sid="+Math.random();
//	if($('remoteIP') && $('remoteIP').innerHTML == '75.110.135.86'){alert(url);}
	xmlHttp.onreadystatechange=function() {stateChangedDB()};
	xmlHttp.open("POST",url,true);  //using POST instead of the usual get b/c URL has potential to be really long with multiple race participants
	xmlHttp.send(null);
}

function stateChangedDB(){ 
	if (xmlHttp.readyState==4){ 
//	if($('remoteIP') && $('remoteIP').innerHTML == '75.110.135.86'){alert(xmlHttp.responseText);return;}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
//		 alert(rootdomain+'RootControlpanel/users/view_user_details.php?Id='+theGoods[0]+'&ty='+theGoods[1]+'&page=');

if(theGoods[1] == 'reg'){
	 if(theGoods[3] == 'Credit Card'){
			var url = 'https://www.reachoutrockymount.org/securePay.php?e='+theGoods[4];
		
			window.scroll(0,0);
		
			var controlPanel = document.getElementById('controlPanel');
			controlPanel.innerHTML = '';
			controlPanel.style.height = '500px';
			
			var div = document.createElement('div');
			div.style.fontSize = '16px';
			div.style.fontWeight = 'bold';
			div.paddingBottom = '10';
			var el = document.createTextNode(fullYear+' Fun Run For Charities | Secure Online Payments')
			div.appendChild(el);
			controlPanel.appendChild(div);
			
			var div = document.createElement('div');
			div.style.height = '10px';
			controlPanel.appendChild(div);
			
			
			var div = document.createElement('div');
			div.style.fontSize = '12';
			el = document.createTextNode('You are now being redirected to our secure online payment page.  If your browser does not go there within a few second you may click the link below.')
			div.appendChild(el);
			controlPanel.appendChild(div);
			
			var div = document.createElement('div');
			div.style.height = '10px';
			controlPanel.appendChild(div);
			
			var div = document.createElement('div');
			div.style.fontSize = '10';
			div.style.textDecoration = 'underline';
			div.style.cursor = 'pointer';
			div.onclick = function(){window.location = url;};
			el = document.createTextNode('Proceed to the Secure Online Payment page.')
			
			div.appendChild(el);
			controlPanel.appendChild(div);
	
			window.location = url;
			
		}else{
			openSettings(theGoods[0],theGoods[1]);
		}
}else{
		if(theGoods[2] == 'Credit Card' && theGoods[4] > 0){
			var url = 'https://www.reachoutrockymount.org/securePay.php?e='+theGoods[3];
			window.scroll(0,0);
		
			var controlPanel = document.getElementById('controlPanel');
			controlPanel.innerHTML = '';
			controlPanel.style.height = '500px';
			
			var div = document.createElement('div');
			div.style.fontSize = '16px';
			div.style.fontWeight = 'bold';
			div.paddingBottom = '10';
			var el = document.createTextNode(fullYear+' Fun Run For Charities | Secure Online Payments')
			div.appendChild(el);
			controlPanel.appendChild(div);
			
			var div = document.createElement('div');
			div.style.height = '10px';
			controlPanel.appendChild(div);
			
			
			var div = document.createElement('div');
			div.style.fontSize = '12';
			el = document.createTextNode('You are now being redirected to our secure online payment page.  If your browser does not go there within a few second you may click the link below.')
			div.appendChild(el);
			controlPanel.appendChild(div);
			
			var div = document.createElement('div');
			div.style.height = '10px';
			controlPanel.appendChild(div);
			
			
			var div = document.createElement('div');
			div.style.fontSize = '10';
			div.style.textDecoration = 'underline';
			div.style.cursor = 'pointer';
			div.onclick = function(){window.location = url;};
			el = document.createTextNode('Proceed to the Secure Online Payment page.')
			
			div.appendChild(el);
			controlPanel.appendChild(div);
			
			window.location = url;
			
			
		}else{
//alert(rootdomain+'RootControlpanel/users/view_user_details.php?Id='+theGoods[0]+'&ty='+theGoods[1]+'&page=');
ajaxFunction(rootdomain+'RootControlpanel/users/view_user_details.php?Id='+theGoods[0]+'&ty='+theGoods[1]+'&page=','controlPanel','loadPage');

//openSettings(theGoods[0],theGoods[1]);
	}

}
}
}

function bankAccount(value){
	if(value == 'No'){
		$('bankNameRow').style.display = 'none';
		$('agentRow').style.display = '';
		if($('npId').innerHTML == ''){		
			$('bank_name').value = '';
		}
	}else if(value == 'Yes'){
		$('bankNameRow').style.display = '';
		$('agentRow').style.display = 'none';	
		if($('npId') && $('npId').innerHTML == ''){
			$('fiscal_agent_name').value = '';		
			$('fiscal_agent_contact').value = '';		
			$('fiscal_agent_phone_no1').value = '';		
			$('fiscal_agent_phone_no2').value = '';		
			$('fiscal_agent_phone_no3').value = '';				
			$('fiscal_agent_tax_id').value = '';				
		}
	}
}

function fnSubmitNonProf(Id,username_orig,ty){
var el = document.thisForm.elements;
for(var i=0;i<el.length;i++){
	if(el[i].name == 'fiscal_agent_phone_no1' || el[i].name == 'fiscal_agent_phone_no2' || el[i].name == 'fiscal_agent_phone_no3'){
			var name = 	'fiscal_agent_phone_no';
		}else{
			var name = el[i].name;
		}
	
	if(name == 'bank_account' && $('bank_accountYes').checked == false && $('bank_accountNo').checked == false){
		$(name+'Warning').style.display = '';
		el[i].focus();
		return;
	}	
	if($(name+'Warning') && el[i].value == ''){
		if(
		(name == 'bank_name' && $('bankNameRow').style.display == 'none') || 
		((name == 'fiscal_agent_name' || name == 'fiscal_agent_contact' || name == 'fiscal_agent_phone_no' || name == 'fiscal_agent_tax_id') && $('agentRow').style.display == 'none')
		){continue;}
		
		if(name == 'fiscal_agent_name' || name == 'fiscal_agent_contact' || name == 'fiscal_agent_phone_no' || name == 'fiscal_agent_tax_id'){		
			$(name+'Warning').innerHTML = '- Required';
		}else{
			$(name+'Warning').style.display = '';		
		}
		el[i].style.border = '1px solid red';		
		el[i].focus();
		return;
	}else if($(name+'Warning') && el[i].value != ''){
		if(name == 'fiscal_agent_name' || name == 'fiscal_agent_contact' || name == 'fiscal_agent_phone_no' || name == 'fiscal_agent_tax_id'){				
			$(name+'Warning').innerHTML = '&nbsp;';
		}else{
			$(name+'Warning').style.display = 'none';		
		}	
		el[i].style.border = '1px solid #CCCCCC';				
	}
}

/*
	return ckEmail('');
	return ckEmail2('');
*/

if(document.getElementById('usernameUpdate') && document.getElementById('usernameUpdate').value == ''){
	document.getElementById('usernameWarning').style.display = '';
	document.getElementById('usernameUpdate').focus();
	return false;
}else if(document.getElementById('usernameWarning')){
	document.getElementById('usernameWarning').style.display = 'none';
}

if((document.getElementById('usernameWarning') && document.getElementById('usernameWarning').style.display != 'none') || 
   (document.getElementById('usernameWarning0') && document.getElementById('usernameWarning0').style.display != 'none')){
	document.getElementById('usernameUpdate').focus();
	return false;
}

for(i=0; i<document.thisForm.length; i++){
//	document.write(document.thisForm.elements[i].name + " = " + document.thisForm.elements[i].disabled + "<br />");
document.thisForm.elements[i].disabled = false;
}

/*if(document.getElementById('mission').value.length > 1000){
	alert('Please limit your Mission response to 1,000 characters.');
	document.getElementById('missionDiv').focus();
	return false;
}
*/
if(document.getElementById('about_org').value.length > 500){
	alert('Please limit your About Organization response to 500 characters.');
	document.getElementById('missionDiv').focus();
	return false;
}	
if(document.getElementById('funds_use').value.length > 500){
	alert('Please limit your Use of Funds response to 500 characters.');
	document.getElementById('missionDiv').focus();
	return false;
}	

if(Id == 'add'){
	var mode = 'add'
}else{
	var mode = 'update'
}

updateNonProfDB(Id,mode,ty);

//<? if(isset($_REQUEST['Id'])){ ?>
	//document.thisForm.action = "edit_nonprofit.php?mode=update&Id=<? echo ($_REQUEST['Id']); ?>";
//<? }else{ ?>
//	document.thisForm.action = "edit_nonprofit.php?mode=add";
//<? } ?>
}

function getHTTPObject() {
	var http = false;
	//Use IE's ActiveX items to load the file.
	if(typeof ActiveXObject != 'undefined') {
		try {http = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {http = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {http = false;}
		}
	//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	} else if (XMLHttpRequest) {
		try {http = new XMLHttpRequest();}
		catch (e) {http = false;}
	}
	return http;
}

var http = getHTTPObject();

function updateNonProfDB(Id,mode,ty){ 

	if (http==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootControlpanel/users/edit_nonprofit.php";
	var params= "mode="+mode;
	if(Id != 'add'){params=params+"&Id="+Id;}
	
	var form = document.thisForm
	var add_users = '';

	for (i = 0; i < form.elements.length; i++) {
		var elName = form.elements[i].name;

	if(form.elements[i].type == 'checkbox' && form.elements[i].checked && form.elements[i].name.indexOf("add_user[]") != "-1"){
		if(add_users != ''){
			add_users = add_users + '|' + form.elements[i].value;
		}else{
			add_users = form.elements[i].value;
		}
	}else if(form.elements[i].type == 'checkbox' && !form.elements[i].checked && form.elements[i].name.indexOf("add_user[]") != "-1"){
		//var elValue = 'No';	
	}else if(form.elements[i].type == 'radio' && form.elements[i].checked){
		var elValue = form.elements[i].value;		
	}else if(form.elements[i].type == 'radio' && !form.elements[i].checked){
		//var elValue = 'No';			
	}else{
		var elValue = cleanValue(form.elements[i].value);		
	}
	if(elName!='Id' && elName != "add_user[]"){
		params=params+"&"+elName+"="+cleanValue(elValue);
	}
	}
	if(form.uploadFile.value != ''){
		var uploadFile = 'uploadFile';
	}else{
		var uploadFile = '';
	}
	/*
	url=url+"&add_users=" + add_users+"&ty="+ty ;
	url=url+"&sid="+Math.random();

	alert(url);
	xmlHttp.onreadystatechange=stateChangedNonProfDB;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	*/
	
	params=params+"&add_users=" + add_users+"&ty="+ty ;	
	params=params+"&sid="+Math.random();
	//alert(params.length);
		
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function(){stateChangedNonProfDB(uploadFile)};
	http.send(params);

}

function stateChangedNonProfDB(uploadFile){ 
	if (http.readyState==4 && http.status==200){ 
	//alert(http.responseText);
	//alert(rootdomain+'RootControlpanel/users/view_user_details.php?Id='+theGoods[0]+'&page=');
	var theGoods = http.responseText.split('|');	
	if(uploadFile != ''){
		document.thisForm.Id.value = theGoods[0];
		startUpload();
		return;
	}


	if(theGoods[1] == 'reg'){
		nonProfDBSuccess();
}else{
	ajaxFunction(rootdomain+'RootControlpanel/users/view_nonprofit_details.php?Id='+theGoods[0]+'&page=','controlPanel','loadPage');
}
	}
}

function nonProfDBSuccess(){
				window.scroll(0,0);
		
			var controlPanel = document.getElementById('controlPanel');
			controlPanel.innerHTML = '';
			controlPanel.style.height = '500px';
			
			var div = document.createElement('div');
			div.style.height = '10px';
			controlPanel.appendChild(div);
			
			var div = document.createElement('div');
			div.style.fontSize = '16px';
			div.style.fontWeight = 'bold';
			div.style.marginTop = '20px';			
			div.paddingBottom = '10';
			var el = document.createTextNode(fullYear+' Fun Run For Charities Online Application')
			div.appendChild(el);
			controlPanel.appendChild(div);
			
			var div = document.createElement('div');
			div.style.height = '10px';
			controlPanel.appendChild(div);
			
			
			var div = document.createElement('div');
			div.style.fontSize = '12';
			el = document.createTextNode('Your application has been received successfully.  Contact Reach Out Rocky Mount (info@reachoutrockymount.org) with any questions or concerns you may have.  If you would like to update your application you may click on your email address next to "View Account Settings" above.')
			div.appendChild(el);
			controlPanel.appendChild(div);
			
			var div = document.createElement('div');
			div.style.height = '10px';
			controlPanel.appendChild(div);
			
			
			var div = document.createElement('div');
			div.style.fontSize = '10';
			div.style.textDecoration = 'underline';
			div.style.cursor = 'pointer';
			div.onclick = function(){window.location = rootdomain;};
			el = document.createTextNode('Return to the Fun Run For Charities homepage.')
			
			div.appendChild(el);
			controlPanel.appendChild(div);
if(document.getElementById('loadingDiv')){
	document.getElementById('loadingDiv').style.display = 'none';
}

document.getElementById('controlPanel').style.width = '900px';
			ajaxFunction(rootdomain+'RootControlpanel/login.php','loginContainter','loadPage');	
		document.getElementById('loadingDiv').innerHTML = '';
}

function startUpload(){
	var f1 = document.thisForm;
	f1.action= cgi+"upload.cgi?upload_id=";
	var UID = Math.round(10000*Math.random())+'0'+Math.round(10000*Math.random());
	f1.action = f1.action.split('?')[0]+'?upload_id='+UID;

	if(f1.popup.checked){
		var uploadProgress = $('uploadProgress');
		var iframeProgress = document.createElement('iframe');
		iframeProgress.style.backgroundColor = '#f1f1f1';
		iframeProgress.src = f1.action.split('upload.cgi')[0]+'upload_status.cgi?upload_id='+UID;
		iframeProgress.frameBorder = '0';
		iframeProgress.scrolling = 'no';
		iframeProgress.width = '100%';	
		iframeProgress.id="iframeProgress";
	
	//	alert('action: '+f1.action+'\n progress:'+iframeProgress.src);
	//	return;
	
		uploadProgress.appendChild(iframeProgress);
	}
	f1.submit();
    return true;
}

function delpNP(mode,Id){

if (Id == '' || Id == 'ckAll'){
	var form = document.thisForm;
	var numck = 0;
	for (i = 0; i < form.elements.length; i++) {
	var elName = form.elements[i].name;
	if(form.elements[i].type == 'checkbox' && form.elements[i].checked){numck = 1;}
	}
	if(numck == 0){
	alert("Select at least one Non-Profit Organization to update.");
	return false;
		}
}


if((mode == 'del' && confirm("This will remove all information for the selected Non-Profit Organization(s) from the database.  Are you sure you would like to delete?")) || 
   (mode != 'del')){
if(Id=='ckAll'){
	var url=rootdomain+"RootControlpanel/users/view_nonprofits.php";
	url=url+"?mode="+mode;

var form = document.thisForm
for (i = 0; i < form.elements.length; i++) {
var elName = form.elements[i].name;
if(form.elements[i].type == 'checkbox' && form.elements[i].checked){
var elValue = form.elements[i].value;		
}
if(elName!='Id'){
url=url+"&"+elName+"="+elValue;
}
}
ajaxFunction(url,'controlPanel','loadPage')

		}else{
ajaxFunction(rootdomain+'RootControlpanel/users/view_nonprofits.php?mode=del&chkSelect[]='+Id,'controlPanel','loadPage')
		}
}
		else
		{
		return false;
		}
	}
function fnValidate(){
	if(document.thisLoginForm.username.value == ""){alert("Please enter your email address."); document.thisLoginForm.username.focus(); return false;}
	if(document.thisLoginForm.password.value == ""){alert("Please enter your password."); document.thisLoginForm.password.focus(); return false;}

	loginForm(document.thisLoginForm.username.value,document.thisLoginForm.password.value);
}
function fnValidateR(){
if(Trim(document.thisLoginForm.email.value) == ""){ 
	alert("Please enter your email address."); 
	document.thisLoginForm.email.focus(); 
	return false;
}
if (validate(Trim(document.thisLoginForm.email.value), "email") == false) {
		alert("Please enter a valid email address.");
		document.thisLoginForm.email.focus();
		return false;
	}
	requestEmail(document.thisLoginForm.email.value);
}
function showLogin(){
	document.getElementById('loginForm').style.display = '';
	document.getElementById('requestEmail').style.display = 'none';
	document.getElementById("loginWarning2").style.display="none";
	document.getElementById("loginWarning").innerHTML="";	
	document.getElementById('loggedIn').style.display = 'none';
	document.thisLoginForm.password.value="";		
	document.thisLoginForm.username.focus();
}
function showRequest(){
	document.getElementById('loginForm').style.display = 'none';
	document.getElementById('requestEmail').style.display = '';
	document.getElementById('loggedIn').style.display = 'none';
	document.thisLoginForm.email.focus();
}
function showLoggedin(username,Id){
	document.getElementById('loginForm').style.display = 'none';
	document.getElementById('requestEmail').style.display = 'none';
	document.getElementById('loggedIn').style.display = '';
	document.getElementById('loggedinUsername').innerHTML = username;
	document.getElementById('loggedinUsername').onclick=function(){return openSettings(Id,'st')};
//	document.thisLoginForm.email.focus();
}

function showUpdatePswd(){
	if(document.getElementById('updatePswd1').style.display == 'none'){
		document.getElementById('updatePswd1').style.display = ''
		document.getElementById('updatePswd2').style.display = ''
	}else{
		document.getElementById('updatePswd1').style.display = 'none'
		document.getElementById('updatePswd2').style.display = 'none'
	}
}
function showUsersNP(){
	if(document.getElementById('addUsersDiv').style.display == 'none'){
		document.getElementById('addUsersDiv').style.display = '';
	}else{
		document.getElementById('addUsersDiv').style.display = 'none';
	}
}
function showManageNP(){
	if(document.thisForm.adminNonprofit.value == "User Only" && document.getElementById('addUsersDiv').style.display == 'none'){
		document.getElementById('addUsersDiv').style.display = '';
		document.getElementById('manageUsersDiv').style.display = '';	
		document.getElementById('manageUsersDiv1').style.display = 'none';			
	}else{
		document.getElementById('addUsersDiv').style.display = 'none';
		document.getElementById('manageUsersDiv').style.display = 'none';		
		document.getElementById('manageUsersDiv1').style.display = '';					
	}
}
function stripNonNumeric( str )
{
  str += '';
  var rgx = /^\d|\.|-$/;
   var out = '';
   for( var i = 0; i < str.length; i++ )
   {
     if( rgx.test( str.charAt(i) ) ){
       if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) ||
              ( str.charAt(i) == '-' && out.length != 0 ) ) ){
         out += str.charAt(i);
       }
     }
   }
  return out;
}
				
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 showCheckForm(Id,chkFname,chkLname,chkDate){
	
if(document.getElementById('chkDiv').style.display == 'none'){
document.getElementById('insertChk').style.paddingBottom = '10px';
document.getElementById('chkDiv').style.display = '';
	var chkDiv = document.getElementById('chkDiv');

	
	var tbl = document.createElement('table');
		tbl.className = 'tblHead';
		tbl.cellSpacing = 1;
		tbl.cellPadding = 4;
		tbl.border = 0;
		tbl.width = '100%';
	
	var tr = tbl.insertRow(0);
		tr.className = 'tbltitle';
	var td = tr.insertCell(0);
		td.className = 'txtBold';
	var el = document.createTextNode('Name (First, Last)');
	td.appendChild(el);

	var td = tr.insertCell(1);
		td.className = 'txtBold';
	var el = document.createTextNode('Check Number');
	td.appendChild(el);

	var td = tr.insertCell(2);
		td.className = 'txtBold';
	var el = document.createTextNode('Amount');
	td.appendChild(el);

	var td = tr.insertCell(3);
		td.className = 'txtBold';	
	var el = document.createTextNode('Date');
	td.appendChild(el);

	var tr = tbl.insertRow(1);
	tr.className = 'tblBody';
	var td = tr.insertCell(0);
	var el = document.createElement('input');
		el.type = 'text';
		el.id = 'chkFname';
		el.className = 'txtbox';
		el.style.width = '100px';
		el.value = chkFname;
		td.appendChild(el);

	var el = document.createTextNode(' ');
		td.appendChild(el);

var el = document.createElement('input');
		el.type = 'text';
		el.id = 'chkLname';
		el.className = 'txtbox';
		el.style.width = '100px';
		el.value = chkLname;
		td.appendChild(el);

	var td = tr.insertCell(1);
	var el = document.createElement('input');
		el.type = 'text';
		el.id = 'chkNumber';
		el.style.width = '200px';
		el.className = 'txtbox';
		td.appendChild(el);
	
	var td = tr.insertCell(2);
	var el = document.createElement('input');
		el.type = 'text';
		el.style.width = '200px';
		el.id = 'chkAmount';
		el.className = 'txtbox';
	td.appendChild(el);

	var el = document.createElement('input');
		el.type = 'hidden';
		el.id = 'amountDue';
		el.value = document.getElementById('amtDue').innerHTML;
	td.appendChild(el);

	var el = document.createElement('input');
		el.type = 'hidden';
		el.id = 'amountDueTaxDeductible';
		el.value = document.getElementById('amtDueTaxDeductible').innerHTML;
	td.appendChild(el);

	var el = document.createElement('input');
		el.type = 'hidden';
		el.id = 'amountDueNonTaxDeductible';
		el.value = document.getElementById('amtDueNonTaxDeductible').innerHTML;
	td.appendChild(el);

	var td = tr.insertCell(3);
	var el = document.createTextNode(chkDate);
	td.appendChild(el);

	var tr = tbl.insertRow(2);
	tr.className = 'tblBody';
	var td = tr.insertCell(0);
		td.colSpan = '4';
		td.align = 'center';
	var el = document.createElement('div');
		el.style.cursor = 'pointer';
		el.style.fontSize = '12px';
		el.className = 'txtBold';
		el.style.border = '#333333';
		el.style.borderStyle = 'solid';
		el.style.borderWidth = '1px';		
		el.style.width = '200px';
		el.style.backgroundColor = '#000000';
		el.style.color = '#FFFFFF';
		el.style.paddingBottom = '3px';		
		el.onclick = function(){return submitChk(Id,chkDate,'new')};
		
	var el2 = document.createTextNode('Submit Check');

		el.appendChild(el2);		
		td.appendChild(el);

	chkDiv.appendChild(tbl);
}else{
	document.getElementById('chkDiv').style.display = 'none';
	document.getElementById('chkDiv').innerHTML = '';	
	}
}

function submitChk(Id,chkDate,type){
if(type == 'new'){
if(document.getElementById('chkFname').value == ''){alert('Be sure to include the name of the person who sent the check.');document.getElementById('chkFname').focus();return false;}

if(document.getElementById('chkLname').value == ''){alert('Be sure to include the name of the person who sent the check.');document.getElementById('chkLname').focus();return false;}

if(document.getElementById('chkNumber').value == ''){alert('Be sure to include the check number.');document.getElementById('chkNumber').focus();return false;}
if(document.getElementById('chkAmount').value == ''){alert('Be sure to include the check amount.');document.getElementById('chkAmount').focus();return false;}

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootControlpanel/users/chkSubmit.php";
	url=url+"?Id=" + Id + "&bill_f_name=" + document.getElementById('chkFname').value + 
						  "&bill_l_name=" + document.getElementById('chkLname').value + 
						  "&chkNumber=" + document.getElementById('chkNumber').value +
						  "&amountPaid=" + stripNonNumeric(document.getElementById('chkAmount').value) +
  						  "&amountDue=" + stripNonNumeric(document.getElementById('amtDue').innerHTML) +
						  "&amountDueTaxDeductible=" + stripNonNumeric(document.getElementById('amtDueTaxDeductible').innerHTML) +
						  "&amountDueNonTaxDeductible=" + stripNonNumeric(document.getElementById('amtDueNonTaxDeductible').innerHTML) +						  
						  "&datePaid=" + chkDate + "&type=" + type;

	url=url+"&sid="+Math.random();
}else if(type == 'refresh'){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	var iCnt = iCnt;
	var url=rootdomain+"RootControlpanel/users/chkSubmit.php";
	url=url+"?Id=" + Id + "&type=" + type;
	url=url+"&sid="+Math.random();
	
}
//alert(url);
	xmlHttp.onreadystatechange=stateChangedChkSubmit;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChangedChkSubmit(){ 
	if (xmlHttp.readyState==4){ 
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split("|");		
		document.getElementById('receiptTbl').innerHTML = theGoods[2];
	document.getElementById('chkDiv').style.display = 'none';
	document.getElementById('chkDiv').innerHTML = '';	
//alert(rootdomain+'RootControlpanel/users/view_user_details.php?Id='+theGoods[1]+'&page=');
ajaxFunction(rootdomain+'RootControlpanel/users/view_user_details.php?ty=ad&Id='+theGoods[1]+'&page=','controlPanel','loadPage');
	}
}

function testLength(id,num,limit){
		if(num > limit){
			document.getElementById(id + 'Div').style.color = '#FF0000';	
		}else{
			document.getElementById(id + 'Div').style.color = '#000000';	
		}
		document.getElementById(id + 'Div').innerHTML = num + ' characters (Max '+limit+')';
}

function checkExt(extValid,fileUpload,warning){
	var extValidArr = extValid.split('|');
	var extArr = fileUpload.value.split('.');
	var ext = extArr[extArr.length-1];

	if(!in_array(ext,extValidArr)){
		fileUpload.style.border = '1px #FF0000 solid';
		$(warning).style.display = '';
		$(warning).innerHTML = "."+ ext + " is not an allowed extension";
		return;
	}else{
		$(warning).style.display = 'none';	
		fileUpload.style.border = '1px #CCCCCC solid';		
	}
}

function in_array (needle, haystack, argStrict) {
    var key = '', strict = !!argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
 
    return false;
}

function showElement(el){
	if($(el).style.display == ''){
		$(el).style.display = 'none';
	}else{
		$(el).style.display = '';	
	}
}
