function togglePaymentMethod() {
	value = $('#payment_method').val();
	$('.payment_method_group').hide();
	$('#' + value + '_info').show();
}

function toggleReferralLabel() {

	selindex = document.getElementById('referred_by').selectedIndex;
	switch (selindex) {
		case 1: case 2: case 3: case 4:
			$('#referral_extra_label').html('Referred by');
			$('#referral_extra_container').show();
		break;
		case 5: case 6:
			$('#referral_extra_label').html('Which event?');
			$('#referral_extra_container').show();
		break;
		case 7: case 8:
			$('#referral_extra_label').html('Which publication?');
			$('#referral_extra_container').show();
		break;
		case 9:
			$('#referral_extra_label').html('Which Website?');
			$('#referral_extra_container').show();
		break;
		case 11:
			$('#referral_extra_label').html('Explain Other...');
			$('#referral_extra_container').show();
		break;
		default:
			$('#referral_extra_container').hide();
		break;
	}

}

function togglePaymentFrequency() {

	/* this is unused... */
	
	selindex = document.getElementById('membership_type').selectedIndex;
	mySelect = document.getElementById('payment_frequency');
	mySelect.options.length = 0;
		
	switch (selindex) {
		case 0:
    		mySelect.options[0] = new Option ("1 Annual Payment of $1500","Yearly");
    		mySelect.options[1] = new Option ("4 Quarterly Payments of $375","Quarterly");
    		mySelect.options[2] = new Option ("12 Monthly Payments of $125","Monthly");
		break;
		case 1:
    		mySelect.options[0] = new Option ("1 Annual Payment of $750","Yearly");
    		mySelect.options[1] = new Option ("4 Quarterly Payments of $187.50","Quarterly");
    		mySelect.options[2] = new Option ("12 Monthly Payments of $62.50","Monthly");
		break;
		case 2:
    		mySelect.options[0] = new Option ("1 Annual Payment of $350","Yearly");
    		mySelect.options[1] = new Option ("4 Quarterly Payments of $87.50","Quarterly");
    		mySelect.options[2] = new Option ("12 Monthly Payments of $29.17","Monthly");
		break;
		case 3:
    		mySelect.options[0] = new Option ("1 Annual Payment of $125","Yearly");
    		mySelect.options[1] = new Option ("4 Quarterly Payments of $31.25","Quarterly");
    		mySelect.options[2] = new Option ("12 Monthly Payments of $10.24","Monthly");
		break;
		case 4:
			mySelect.options[0] = new Option ("1 Annual Payment of $75","Yearly");
		break;
		case 5:
			mySelect.options[0] = new Option ("1 Annual Payment of $25","Yearly");
		break;
	}
	
	// replaceSelects();
	
}

function togglePaymentOptions() {
	
	selindex = document.getElementById('membership_type').selectedIndex;
	// mySelect = document.getElementById('payment_frequency');
	// mySelect.options.length = 0;
		
	switch (selindex) {
		case 4:
		case 5:
			$('#frequency_quarterly').attr('disabled', true);
			$('#frequency_monthly').attr('disabled', true);
			$('#frequency_quarterly_tr label').addClass('gray');
			$('#frequency_monthly_tr label').addClass('gray');
			$('#frequency_yearly').attr('checked',true);
		break;
		default:
    		$('#frequency_table tr').show();
    		$('#frequency_table tr td input').removeAttr('disabled');
    		$('#frequency_table tr td label').removeClass('gray');
		break;
	}
	
}

function toggleCCPaymentDetails() {
	if ($('input:radio[name=payment_method]:checked').val() == 'PayPal') {
		$('#cc_payment_details').slideDown();
		$('#paypal_instructions').show();
		$('#check_instructions').hide();
	} else {
		$('#cc_payment_details').slideUp();
		$('#paypal_instructions').hide();
		$('#check_instructions').show();
	}
}

function toggleNeighborhoods() {
	value = $('#directory_county').val();
	if (value=='Philadelphia') {
		// $('#neighborhoods_container').show();
	} else {
		// $('#neighborhoods_container').hide();
		// $('#hidden_neighborhood').val('');	// make sure the old neighborhood doesn't get stored.
	}
}

function syncCategories() {

	value = $("#select_neighborhood option:selected").text();
	if (value.indexOf('-- ')===0) {
		$('#hidden_neighborhood').val(value.substr(3));
	} else {
		$('#hidden_neighborhood').val(value);
	}
		
	value = $("#select_category option:selected").text();
	if (value.indexOf('-- ')===0) {
		$('#hidden_category').val(value.substr(3));
	} else {
		$('#hidden_category').val(value);
	}
	
	neighborhood = $("#select_neighborhood option:selected").val();
	category = $("#select_category option:selected").val();
	
	var array = new Array(neighborhood, category);
	$('#new_category_multiselect').val(array);
	
}

function clearSearch(element, value) {
	if (value=='Site Search') element.value='';
}

function toggleSubject() {
	value = $("#subject option:selected").text();
	if (value == 'Other') {
		$('#other_subject').show();
	} else {
		$('#other_subject').hide();
	}
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


function validateContactForm() {
	if (isValidEmail($('#contact_email').val())) {
		return true;
	} else {
		alert("Please enter a valid e-mail address.");
		return false;
	}
}

function validateReferralForm() {
	if ($('#your_name').val()=='') {
		alert("Please enter your name.");
		return false;
	}
	if (!isValidEmail($('#your_email').val())) {
		alert("Please enter a valid e-mail for Your E-mail.");
		return false;
	}
	if ($('#contact_first_name').val()=='') {
		alert("Please enter your contact's first name.");
		return false;
	}
	if (!isValidEmail($('#contact_email').val())) {
		alert("Please enter a valid e-mail for Contact E-mail.");
		return false;
	}
	return true;
}

var business_name_ok = true;

function check_business_name() {
	submitted_name = $('#company_name').val();
	business_name_ok = true;

	$.post('/scripts/salesforce/check_business_name.php', { name: submitted_name }, function(data) {
	  if (data=='0') {
	  	alert("The Business Name you chose already exists in our database. Please log in to your existing account rather than creating a new account.\n\nIf you don't know your existing account info, please contact us at info@sbnphiladelphia.org.");
	  	business_name_ok = false;
	  }
	});
	
}

function check_business_name_onsubmit() {
	if (business_name_ok == true) {
		return true;
	} else {
		alert("The Business Name you chose already exists in our database. Please log in to your existing account rather than creating a new account.\n\nIf you don't know your existing account info, please contact us at info@sbnphiladelphia.org.");
		return false;
	}
}
