//to validate the email address (called below)
function echeck(str)
	{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1)
		{
		return false
		}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		return false
		}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		return false
		}
	 if (str.indexOf(at,(lat+1))!=-1)
		{
		return false
		}
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		{
		return false
		}
	 if (str.indexOf(dot,(lat+2))==-1)
		{
		return false
		}
	 if (str.indexOf(" ")!=-1)
		{
		return false
		}
	 return true
	}



//to check for blank fields and submit the form
$(function()
	{
	$('.error').hide();
	$(".button").click(function()
		{
	  	// validate and process form here
	  	$('.error').hide();
	  	
		var name = $("input#name").val();
		if (name == "")
			{
			$("label#name_error").show();
			$("input#name").focus();
			return false;
			}
		
		var organization = $("input#organization").val();
		if (organization == "")
			{
			$("label#organization_error").show();
			$("input#organization").focus();
			return false;
			}
		
		var city = $("input#city").val();
		if (city == "")
			{
			$("label#city_error").show();
			$("input#city").focus();
			return false;
			}
		
		var province = $("input#province").val();
		if (province == "")
			{
			$("label#province_error").show();
			$("input#province").focus();
			return false;
			}
		
		var email = $("input#email").val();
		if (email == "")
			{
			$("label#email_error").show();
			$("input#email").focus();
			return false;
			}
		if (echeck(email)==false)
			{
			$("label#email_error2").show();
			$("input#email").focus();
			return false;
			}
			
		var you_attend = $('[name=you_attend]').val();
		var someone_attend = $('[name=someone_attend]').val();
		
		if (you_attend == "Did")
			{
			$("label#you_attend_error").show();
			return false;
			}
		
		if (someone_attend == "Did")
			{
			$("label#someone_attend_error").show();
			return false;
			}

		
		document.forms['contact'].elements['submit_btn'].disabled = true; //added this line w/ false to the onload in case people hit back then refresh
		document.forms['contact'].elements['submit_btn'].value = "Processing...";
		
		var dataString = 'name='+ name + '&organization=' + organization + '&city=' + city + '&province=' + province + '&email=' + email + '&you_attend=' + you_attend + '&someone_attend=' + someone_attend;
		//alert (dataString);return false;
		$.ajax(
			{
			type: "POST",
			url: "processForm.php", /* use relative link here, otherwise problems appear when on http://www vs just http (if written as http://www.southfraser.com/cra_workshops/processForm.php */
			data: dataString,
			success: function()
				{
				$('#contactForm').html("<div id='message'></div>");
				$('#message').html("<p><em>Note: if you have problems viewing these files, right click and choose 'Save Target As' or 'Save Link As'.</em></p>")
				.append("<p><strong>Good Governance of Charities</strong></p><ul><li><a target='_blank' href='the_documents_2010/Good_governance_principles_and_practices.ppt'>Good governance principles and practices (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/Additional_notes_for_good_governance_session.doc'>Additional notes for good governance session (.doc)</a></li><li><a target='_blank' href='the_documents_2010/Duties_of_directors.ppt'>Duties of directors (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/Directors_checklist.doc'>Directors' checklist (.doc)</a></li></ul>")
				.append("<p><strong>Financial Records and Reporting</strong></p><ul><li><a target='_blank' href='the_documents_2010/Keeping_proper_books_and_records.ppt'>Keeping proper books and records (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/Managing_donation_receipts_and_split_receipting.ppt'>Managing donation receipts and split receipting (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/T3010B_overview.ppt'>T3010B overview (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/GST_HST_for_charities.ppt'>GST / HST for charities (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/GST_HST_for_non_profit_organizations.ppt'>GST / HST for non profit organizations (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/Audits_and_sanctions.ppt'>Audits and sanctions (.ppt)</a></li></ul>")
				.append("<p><strong>Allowable Fundraising Activities and Enterprise</strong></p><ul><li><a target='_blank' href='the_documents_2010/Fundraising_by_charities.ppt'>Fundraising by charities (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/Community_economic_development_activities.ppt'>Community economic development activities (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/Charities_and_related_business.ppt'>Charities and related business (.ppt)</a></li></ul>")
				.append("<p><strong>Factsheets – English</strong></p><ul><li><a target='_blank' href='the_documents_2010/Related_business_and_social_enterprise_for_charities.pdf'>Related business and social enterprise for charities (.pdf)</a></li><li><a target='_blank' href='the_documents_2010/Contracting_to_non-qualified_donees.pdf'>Contracting to non-qualified donees (.pdf)</a></li><li><a target='_blank' href='the_documents_2010/Directors_checklist.pdf'>Directors checklist (.pdf)</a></li><li><a target='_blank' href='the_documents_2010/Duties_of_directors.pdf'>Duties of directors (.pdf)</a></li><li><a target='_blank' href='the_documents_2010/T3010B.pdf'>T3010B (.pdf)</a></li></ul>")
				.append("<p><strong>Factsheets – French</strong></p><ul><li><a target='_blank' href='the_documents_2010/Structure_d_entreprise_sociale.doc'>Structure d'entreprise sociale (.doc)</a></li><li><a target='_blank' href='the_documents_2010/28_conseils_pour_vous_aider_a_devenir_un_meilleur_administrateur_dorganisme_de_bienfaisance.doc'>28 conseils pour vous aider a devenir un meilleur administrateur d'organisme de bienfaisance (.doc)</a></li><li><a target='_blank' href='the_documents_2010/Conclure_des_ententes_avec_des_donataires_non_reconnus.doc'>Conclure des ententes avec des donataires non reconnus (.doc)</a></li><li><a target='_blank' href='the_documents_2010/Devoirs_des_administrateurs.doc'>Devoirs des administrateurs (.doc)</a></li><li><a target='_blank' href='the_documents_2010/T3010B_Declaration_de_renseignements_des_organismes_de_bienfaisance_enregistres.doc'>T3010B Declaration de renseignements des organismes de bienfaisance enregistres (.doc)</a></li></ul>")
				.append("<p><strong>Presentations – French</strong></p><ul><li><a target='_blank' href='the_documents_2010/Activites_de_financement_permises_pour_les_organismes_de_bienfaisance.ppt'>Activites de financement permises pour les organismes de bienfaisance (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/Apercu_du_T3010B_declaration_de_renseignments_des_organismes_de_bienfaisance_enregistres.ppt'>Apercu du T3010B declaration de renseignments des organismes de bienfaisance enregistres (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/Gerer_les_recus_de_dons_conseils_pour_les_organismes_de_bienfaisance.ppt'>Gerer les recus de dons conseils pour les organismes de bienfaisance (.ppt)</a></li><li><a target='_blank' href='the_documents_2010/Organismes_de_bienfaisance_et_activites_commerciales_complementaires.ppt'>Organismes de bienfaisance et activites commerciales complementaires (.ppt)</a></li></ul>")
				.hide()
				.fadeIn(1500, function()
					{
					$('#message').append("");
					}); //end fade in
				} //end success
			}); //end .ajax
			return false; //so page doesn't reload


		}); //end button.click function

	}); //end function





