String.prototype.replaceAll = function(
strTarget, // The substring you want to replace
strSubString // The string you want to replace in.
){
var strText = this;
var intIndexOfMatch = strText.indexOf( strTarget );
 
// Keep looping while an instance of the target string
// still exists in the string.
while (intIndexOfMatch != -1){
// Relace out the current instance.
strText = strText.replace( strTarget, strSubString )
 
// Get the index of any next matching substring.
intIndexOfMatch = strText.indexOf( strTarget );
}
 
// Return the updated string with ALL the target strings
// replaced out with the new substring.
return( strText );
}

function validateJoinMailList(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.fields_fname.value,"req") || theform.fields_fname.value=="first name")
  {
	totalstrerrors += "Please Enter Your First Name\n";
  }

  if (validate(theform.fields_lname.value,"req") || theform.fields_lname.value=="last name")
  {
	totalstrerrors += "Please Enter Your Last Name\n";
  }
  
  if (validate(theform.fields_email.value,"email"))
  {
	totalstrerrors += "Please Enter a Valid E-mail Address\n";
  }
  
  if (totalstrerrors == "")
  {
    theform.maillist_submit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.maillist_submit.disabled = false;
    return false;
  }
}

function validateLogin(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.Email.value,"email"))
  {
	totalstrerrors += "Please Enter Your E-mail Address\n";
	addClass('Email', 'highlight');
  }

  if (validate(theform.Password.value,"req"))
  {
	totalstrerrors += "Please Enter Your Password\n";
	addClass('Password', 'highlight');
  }
  
  if (totalstrerrors == "")
  {
    theform.Submit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.Submit.disabled = false;
    return false;
  }
}

function validateVolunteerRegister(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.VolunteerFirstName.value,"req"))
  {
	totalstrerrors += "Please Enter Your First Name\n";
	addClass('VolunteerFirstName', 'highlight');
  }

  if (validate(theform.VolunteerLastName.value,"req"))
  {
	totalstrerrors += "Please Enter Your Last Name\n";
	addClass('VolunteerLastName', 'highlight');
  }
  
  if (validate(theform.VolunteerEmail.value,"email"))
  {
	totalstrerrors += "Please Enter a Valid Email Address\n";
	addClass('VolunteerEmail', 'highlight');
  }

  if (validate(theform.VolunteerPassword.value,"req"))
  {
	totalstrerrors += "Please Enter a Password\n";
	addClass('VolunteerPassword', 'highlight');
  }

  if (validate(theform.VolunteerPassword2.value,"req"))
  {
	totalstrerrors += "Please Re-Enter Your Password\n";
	addClass('VolunteerPassword2', 'highlight');
  }

  if (validate(theform.VolunteerPhone.value,"req"))
  {
	totalstrerrors += "Please Enter Your Phone Number\n";
	addClass('VolunteerPhone', 'highlight');
  }

  if (validate(theform.VolunteerAddress.value,"req"))
  {
	totalstrerrors += "Please Enter Your Address\n";
	addClass('VolunteerAddress', 'highlight');
  }

  if (validate(theform.VolunteerCity.value,"req"))
  {
	totalstrerrors += "Please Enter Your City\n";
	addClass('VolunteerCity', 'highlight');
  }

  if (validate(theform.VolunteerState.value,"req"))
  {
	totalstrerrors += "Please Enter Your State\n";
  }

  if (validate(theform.VolunteerCounty.value,"req"))
  {
	totalstrerrors += "Please Enter Your County\n";
	addClass('VolunteerCounty', 'highlight');
  }

  if (validate(theform.VolunteerZipcode.value,"zip"))
  {
	totalstrerrors += "Please Enter Your Zip Code\n";
	addClass('VolunteerZipcode', 'highlight');
  }

  if (validate(theform.VolunteerAge.value,"req"))
  {
	totalstrerrors += "Please Enter Your Age\n";
	addClass('VolunteerAge', 'highlight');
  }
  
  if (theform.AgreetoTerms.checked!=true)
  {
	totalstrerrors += "Please Read and Agree to our Terms and Conditions\n";
  }

  if (totalstrerrors == "")
  {
    theform.Submit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.Submit.disabled = false;
    return false;
  }
}

function validateVolunteerUpdateProfile(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.VolunteerFirstName.value,"req"))
  {
	totalstrerrors += "Please Enter Your First Name\n";
	addClass('VolunteerFirstName', 'highlight');
  }

  if (validate(theform.VolunteerLastName.value,"req"))
  {
	totalstrerrors += "Please Enter Your Last Name\n";
	addClass('VolunteerLastName', 'highlight');
  }
  
  if (validate(theform.VolunteerEmail.value,"email"))
  {
	totalstrerrors += "Please Enter a Valid E-mail Address\n";
	addClass('VolunteerEmail', 'highlight');
  }

  if ( (theform.VolunteerPassword.value!="" && theform.VolunteerPassword2.value!=theform.VolunteerPassword.value) || (theform.VolunteerPassword.value=="" && theform.VolunteerPassword2.value!="") )
  {
	totalstrerrors += "Password 1 and Password 2 Must Match\n";
	addClass('VolunteerPassword', 'highlight');
	addClass('VolunteerPassword2', 'highlight');
  }

  if (validate(theform.VolunteerPhone.value,"req"))
  {
	totalstrerrors += "Please Enter Your Phone Number\n";
	addClass('VolunteerPhone', 'highlight');
  }

  if (validate(theform.VolunteerAddress.value,"req"))
  {
	totalstrerrors += "Please Enter Your Address\n";
	addClass('VolunteerAddress', 'highlight');
  }

  if (validate(theform.VolunteerCity.value,"req"))
  {
	totalstrerrors += "Please Enter Your City\n";
	addClass('VolunteerCity', 'highlight');
  }

  if (validate(theform.VolunteerState.value,"req"))
  {
	totalstrerrors += "Please Enter Your State\n";
  }

  if (validate(theform.VolunteerCounty.value,"req"))
  {
	totalstrerrors += "Please Enter Your County\n";
	addClass('VolunteerCounty', 'highlight');
  }

  if (validate(theform.VolunteerZipcode.value,"zip"))
  {
	totalstrerrors += "Please Enter Your Zip Code\n";
	addClass('VolunteerZipcode', 'highlight');
  }

  if (validate(theform.VolunteerAge.value,"req"))
  {
	totalstrerrors += "Please Enter Your Age\n";
	addClass('VolunteerAge', 'highlight');
  }

  if (totalstrerrors == "")
  {
    theform.editProfileSubmit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.editProfileSubmit.disabled = false;
    return false;
  }
}

function validateOrganizationApply(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.OrganizationTitle.value,"req"))
  {
	totalstrerrors += "Please Enter Your Organization Name\n";
	addClass('OrganizationTitle', 'highlight');
  }

  if (validate(theform.OrganizationEmail.value,"email"))
  {
	totalstrerrors += "Please Enter a Valid E-mail Address\n";
	addClass('OrganizationEmail', 'highlight');
  }

  if (validate(theform.OrganizationPhone.value,"req"))
  {
	totalstrerrors += "Please Enter a Phone Number\n";
	addClass('OrganizationPhone', 'highlight');
  }

  if (validate(theform.OrganizationAddress.value,"req"))
  {
	totalstrerrors += "Please Enter Your Organization Address\n";
	addClass('OrganizationAddress', 'highlight');
  }

  if (validate(theform.OrganizationCity.value,"req"))
  {
	totalstrerrors += "Please Enter Your Organization City\n";
	addClass('OrganizationCity', 'highlight');
  }

  if (validate(theform.OrganizationCounty.value,"req"))
  {
	totalstrerrors += "Please Enter Your Organization County\n";
	addClass('OrganizationCounty', 'highlight');
  }

  if (validate(theform.OrganizationZipcode.value,"zip"))
  {
	totalstrerrors += "Please Enter Your Organization Zip Code\n";
	addClass('OrganizationZipcode', 'highlight');
  }
  
  if (theform.AgreetoTerms.checked!=true)
  {
	totalstrerrors += "Please Read and Agree to our Terms and Conditions\n";
  }
  
  if (totalstrerrors == "")
  {
    theform.Submit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.Submit.disabled = false;
    return false;
  }
}

function validateOrganizationUpdateProfile(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.OrganizationTitle.value,"req"))
  {
	totalstrerrors += "Please Enter Your Organization Name\n";
	addClass('OrganizationTitle', 'highlight');
  }

  if (validate(theform.OrganizationEmail.value,"email"))
  {
	totalstrerrors += "Please Enter a Valid E-mail Address\n";
	addClass('OrganizationEmail', 'highlight');
  }

  if ( (theform.OrganizationPassword.value!="" && theform.OrganizationPassword2.value!=theform.OrganizationPassword.value) || (theform.OrganizationPassword.value=="" && theform.OrganizationPassword2.value!="") )
  {
	totalstrerrors += "Password 1 and Password 2 Must Match\n";
	addClass('OrganizationPassword', 'highlight');
	addClass('OrganizationPassword', 'highlight');
  }

  if (validate(theform.OrganizationPhone.value,"req"))
  {
	totalstrerrors += "Please Enter a Phone Number\n";
	addClass('OrganizationPhone', 'highlight');
  }

  if (validate(theform.OrganizationAddress.value,"req"))
  {
	totalstrerrors += "Please Enter Your Organization Address\n";
	addClass('OrganizationAddress', 'highlight');
  }

  if (validate(theform.OrganizationCity.value,"req"))
  {
	totalstrerrors += "Please Enter Your Organization City\n";
	addClass('OrganizationCity', 'highlight');
  }

  if (validate(theform.OrganizationCounty.value,"req"))
  {
	totalstrerrors += "Please Enter Your Organization County\n";
	addClass('OrganizationCounty', 'highlight');
  }

  if (validate(theform.OrganizationZipcode.value,"zip"))
  {
	totalstrerrors += "Please Enter Your Organization Zip Code\n";
	addClass('OrganizationZipcode', 'highlight');
  }
  
  if (totalstrerrors == "")
  {
    theform.editProfileSubmit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.editProfileSubmit.disabled = false;
    return false;
  }
}

function valiateSubmitOpportunity(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.OpportunityTitle.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity Name\n";
	addClass('OpportunityTitle', 'highlight');
  }

  if (validate(theform.OpportunityStartDate.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity Start Date\n";
	addClass('OpportunityStartDate', 'highlight');
  }

  if (validate(theform.OpportunityEndDate.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity End Date\n";
	addClass('OpportunityEndDate', 'highlight');
  }

  if (validate(theform.OpportunityStartTime.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity Start Time\n";
	addClass('OpportunityStartTime', 'highlight');
  }
  
  if (validate(theform.OpportunityAddress.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity Address\n";
	addClass('OpportunityAddress', 'highlight');
  }

  if (validate(theform.OpportunityCity.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity City\n";
	addClass('OpportunityCity', 'highlight');
  }

  if (validate(theform.OpportunityZipcode.value,"zip"))
  {
	totalstrerrors += "Please Enter Your Opportunity Zip Code\n";
	addClass('OpportunityZipcode', 'highlight');
  }

  if (validate(theform.OpportunityPhone.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity Phone Number\n";
	addClass('OpportunityPhone', 'highlight');
  }
  
  if ((validate(theform.OpportunityHours.value,"req")) || (!(theform.OpportunityHours.value > 0)))
  {
	totalstrerrors += "Please Enter the # of Hours This Opportunity Lasts\n";
	addClass('OpportunityHours', 'highlight');
  }
  
  if (totalstrerrors == "")
  {
    theform.Submit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.Submit.disabled = false;
    return false;
  }
}

function validateUpdateOpportunity(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.OpportunityTitle.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity Name\n";
	addClass('OpportunityTitle', 'highlight');
  }

  if (validate(theform.OpportunityStartDate.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity Start Date\n";
	addClass('OpportunityStartDate', 'highlight');
  }

  if (validate(theform.OpportunityEndDate.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity End Date\n";
	addClass('OpportunityEndDate', 'highlight');
  }

  if (validate(theform.OpportunityStartTime.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity Start Time\n";
	addClass('OpportunityStartTime', 'highlight');
  }
  
  if (validate(theform.OpportunityAddress.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity Address\n";
	addClass('OpportunityAddress', 'highlight');
  }

  if (validate(theform.OpportunityCity.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity City\n";
	addClass('OpportunityCity', 'highlight');
  }

  if (validate(theform.OpportunityZipcode.value,"zip"))
  {
	totalstrerrors += "Please Enter Your Opportunity Zip Code\n";
	addClass('OpportunityZipcode', 'highlight');
  }

  if (validate(theform.OpportunityPhone.value,"req"))
  {
	totalstrerrors += "Please Enter Your Opportunity Phone Number\n";
	addClass('OpportunityPhone', 'highlight');
  }
  
  if ((validate(theform.OpportunityHours.value,"req")) || (!(theform.OpportunityHours.value > 0)))
  {
	totalstrerrors += "Please Enter the # of Hours this Opportunity Lasts\n";
	addClass('OpportunityHours', 'highlight');
  }
  
  if (totalstrerrors == "")
  {
    theform.Submit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.Submit.disabled = false;
    return false;
  }
}

function validateRequestMicrogrant(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.MicroGrantTitle.value,"req"))
  {
	totalstrerrors += "Please Enter a Grant Title\n";
	addClass('MicroGrantTitle', 'highlight');
  }
  
  if (validate(theform.MicroGrantGrantee.value,"req"))
  {
	totalstrerrors += "Please Enter a Grantee Name\n";
	addClass('MicroGrantGrantee', 'highlight');
  }

  if (validate(theform.MicroGrantGranteeEmail.value,"email"))
  {
	totalstrerrors += "Please Enter a Valid Grantee E-mail Address\n";
	addClass('MicroGrantGranteeEmail', 'highlight');
  }

  if (validate(theform.MicroGrantGranteePhone.value,"req"))
  {
	totalstrerrors += "Please Enter a Grantee Phone Number\n";
	addClass('MicroGrantGranteePhone', 'highlight');
  }

  if (validate(theform.MicroGrantGranteeAddress.value,"req"))
  {
	totalstrerrors += "Please Enter a Grantee Address\n";
	addClass('MicroGrantGranteeAddress', 'highlight');
  }

  if (validate(theform.MicroGrantGranteeCity.value,"req"))
  {
	totalstrerrors += "Please Enter a Grantee City\n";
	addClass('MicroGrantGranteeCity', 'highlight');
  }

  if (validate(theform.MicroGrantGranteeZipcode.value,"zip"))
  {
	totalstrerrors += "Please Enter a Grantee Zip Code\n";
	addClass('MicroGrantGranteeZipcode', 'highlight');
  }

  if (validate(theform.MicroGrantTotal.value,"req"))
  {
	totalstrerrors += "Please Enter a Total Amount\n";
	addClass('MicroGrantTotal', 'highlight');
  }
 
  if (theform.MicroGrantTotal.value.replaceAll( "$", "").replaceAll( ",", "") > 2000)
  {
	totalstrerrors += "Please Enter an Amount below $2000\n";
	addClass('MicroGrantTotal', 'highlight');
  }
  
  if (theform.AgreetoTerms.checked!=true)
  {
	totalstrerrors += "Please Read and Agree to our Terms and Conditions\n";
  }
  
  if (totalstrerrors == "")
  {
    theform.Submit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.Submit.disabled = false;
    return false;
  }
}

function validateMakePayment(theform)
{
	var totalstrerrors = "";
	
	if (validate(theform.Email.value,"req"))
	{
		totalstrerrors += "Please enter the first name on Your credit card\n";
	addClass('Email', 'highlight');
	}
	
	if (validate(theform.CardFirstName.value,"req"))
	{
		totalstrerrors += "Please enter the first name on Your credit card\n";
	addClass('CardFirstName', 'highlight');
	}
	
	if (validate(theform.CardLastName.value,"req"))
	{
		totalstrerrors += "Please enter the last name on Your credit card\n";
	addClass('CardLastName', 'highlight');
	}
	
	if (validate(theform.CardNumber.value,"req"))
	{
		totalstrerrors += "Please enter Your credit card number\n";
	addClass('CardNumber', 'highlight');
	}
	
	if (validate(theform.CardCVV.value,"req"))
	{
		totalstrerrors += "Please enter Your CVV (Card Verification Value)\n";
	addClass('CardCVV', 'highlight');
	}
	
	if (validate(theform.BillingAddress.value,"req"))
	{
		totalstrerrors += "Please enter Your billing address\n";
	addClass('BillingAddress', 'highlight');
	}
	
	if (validate(theform.BillingCity.value,"req"))
	{
		totalstrerrors += "Please enter Your billing city\n";
	addClass('BillingCity', 'highlight');
	}
	
	if (theform.BillingState.value == "")
	{
		totalstrerrors += "Please select Your billing state\n";
	addClass('BillingState', 'highlight');
	}
	
	if (validate(theform.BillingZipcode.value,"zip"))
	{
		totalstrerrors += "Please enter Your billing zip code\n";
	addClass('BillingZipcode', 'highlight');
	}
	
	if (theform.AcceptCharges.checked!=true)
	{
		totalstrerrors += "You must check the box accepting the credit card charge to continue\n";
	}
	
	if (totalstrerrors == "")
  {
    theform.complete_donation.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.complete_donation.disabled = false;
    return false;
  }
}

function validateCreateListing(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.ClassifiedListingTitle.value,"req"))
  {
	totalstrerrors += "Please Enter a Listing Title\n";
	addClass('ClassifiedListingTitle', 'highlight');
  }
  
  if (theform.ClassifiedCategoryID.selectedIndex == 0 || theform.ClassifiedCategoryID.options[theform.ClassifiedCategoryID.selectedIndex].text == "Have" || theform.ClassifiedCategoryID.options[theform.ClassifiedCategoryID.selectedIndex].text == "Need")
  {
	totalstrerrors += "Please Select a Category\n";
  }
  
  if (totalstrerrors == "")
  {
    theform.createListingSubmit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.createListingSubmit.disabled = false;
    return false;
  }
}

function validateUpdateListing(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.ClassifiedListingTitle.value,"req"))
  {
	totalstrerrors += "Please Enter a Listing Title\n";
	addClass('ClassifiedListingTitle', 'highlight');
  }
  
  if (theform.ClassifiedCategoryID.selectedIndex == 0 || theform.ClassifiedCategoryID.options[theform.ClassifiedCategoryID.selectedIndex].text == "Have" || theform.ClassifiedCategoryID.options[theform.ClassifiedCategoryID.selectedIndex].text == "Need") {
	totalstrerrors += "Please Select a Category\n";
  }
  
  if (totalstrerrors == "")
  {
    theform.editListingSubmit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.editListingSubmit.disabled = false;
    return false;
  }
}

function validateContactUs(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.Name.value,"req"))
  {
	totalstrerrors += "Please Enter Your Name\n";
  }
  
  if (validate(theform.Email.value,"email"))
  {
	totalstrerrors += "Please Enter a Valid E-mail Address\n";
  }
  
  if (validate(theform.Message.value,"req"))
  {
	totalstrerrors += "Please Enter a Message\n";
  }
  
  if (totalstrerrors == "")
  {
    theform.Submit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.Submit.disabled = false;
    return false;
  }
}

function validateOrgFollowup(theform)
{
  var totalstrerrors = "";
  
  if (validate(theform.MicroGrantOrganizationFollowupStory.value,"req"))
  {
	totalstrerrors += "Please Enter a Followup Story for Approval\n";
  }
  
  if (totalstrerrors == "")
  {
    theform.Submit.disabled = true;
    return true;
  }
  else
  {
    alert(totalstrerrors);
    theform.Submit.disabled = false;
    return false;
  }
}
