previousBtnClicked = false;
	alive = null;
	heartbeat_rate = 60 * 1000;
Event.observe(window,'load',function(){
	$('AdColumnSponsorLabel').style.visibility = 'hidden';
	$('AdvertiseWithUs').style.visibility = 'hidden';
	$('BannerAdWrapper').hide();
});

Event.observe(window,'load',function(){

	
	    alive = setInterval(heartbeat, heartbeat_rate);
	current_page = current_page == null ? '' : current_page;
	if (current_page == 'community') {
		Event.observe('user_match_profile_ministries_other', 'keyup', function(e){
			checkBox(e, 'user_match_profile_ministries_99')
		})
		Event.observe('user_match_profile_ministries_99', 'click', function(e){
			clearText(e, $('user_match_profile_ministries_99').checked, 'user_match_profile_ministries_other')
		})
	}
	if (current_page == 'prayer') {
		Event.observe('user_match_profile_prayer_styles','keyup',function(e){checkBox(e,'user_match_profile_prayer_styles_99')})
		Event.observe('user_match_profile_prayer_styles_99','click',function(e){clearText(e,$('user_match_profile_prayer_styles_99').checked,'user_match_profile_prayer_styles')})
	}
	
	if (current_page == 'discernment'){
	}
	if (current_page == 'background'){
		Event.observe('user_match_profile_work_experience_other','keyup',function(e){checkBox(e,'user_match_profile_work_experience_99')})
		Event.observe('user_match_profile_work_experience_99','click',function(e){clearText(e,$('user_match_profile_work_experience_99').checked,'user_match_profile_work_experience_other')})
		Event.observe('user_match_profile_education_99','click', function(e){
			$('user_match_profile_education_1').checked = false;
			$('user_match_profile_education_2').checked = false;
		});
		Event.observe('user_match_profile_education_1','click', function(e){
			if ($('user_match_profile_education_1').checked) {
				$('user_match_profile_education_99').checked = false;
			} else {
				$('user_match_profile_education_2').checked = false;
			}
		});
		Event.observe('user_match_profile_education_2','click', function(e){
			if ($('user_match_profile_education_2').checked) {
				$('user_match_profile_education_1').checked = true;
				$('user_match_profile_education_99').checked = false;
			}
		});

		Event.observe('user_match_profile_religious_training_other','keyup',function(e){checkBox(e,'user_match_profile_religious_training_99')})
		Event.observe('user_match_profile_religious_training_99','click',function(e){clearText(e,$('user_match_profile_religious_training_99').checked,'user_match_profile_religious_training_other')})

		Event.observe('user_match_profile_language_other','keyup',function(e){checkBox(e,'user_match_profile_language_99')})
		Event.observe('user_match_profile_language_99','click',function(e){clearText(e,$('user_match_profile_language_99').checked,'user_match_profile_language_other')})
	}	
	if (current_page == 'personal') {
		Event.observe('user_match_profile_residency_other','keyup',function(e){checkBox(e,'user_match_profile_residency_99')})
		Event.observe('user_match_profile_residency_99','click',function(e){clearText(e,$('user_match_profile_residency_99').checked,'user_match_profile_residency_other')})
		Event.observe('user_match_profile_lives_in_other','keyup',function(e){checkBox(e,'user_match_profile_lives_in_99')})
		Event.observe('user_match_profile_lives_in_99','click',function(e){clearText(e,$('user_match_profile_lives_in_99').checked,'user_match_profile_lives_in_other')})
		
		Event.observe('user_match_profile_reason','change',function(e){
			var reason_val = $('user_match_profile_reason').value			
			if(reason_val == 2){								
				$('asterisk_area').update('<div class="QInst" style="margin-top:4px">'+ message['AgeWillNotAffected']+'</div>');
			}
			else{
				$('asterisk_area').update("<img src='/images/themes/camino/asterisk_red_transp_16x15px.gif'/>")
			}
		});
		//user_match_profile_reason
		$$('.lives_in').each(function(item){
			Event.observe(item,'click',function(e){$('user_match_profile_lives_in_99').checked = false;$('user_match_profile_lives_in_other').value = ''})
		});

		// Removing for now Sept 31, 2009
		// START
		//Event.observe('user_match_profile_country_base_other', 'keyup', function(e){
		//	checkBox(e, 'user_match_profile_country_base_99')
		//})
		//Event.observe('user_match_profile_country_base_99', 'click', function(e){
		//	clearText(e, $('user_match_profile_country_base_99').checked, 'user_match_profile_country_base_other')
		//})
		// END

	}
});	
	function heartbeat(){
	    var url = "/directory/community_heartbeat"
	    var params = "authenticity_token=" + authenticity_token;
	    new Ajax.Request(url, {
	        method: 'post',
	        postBody: params
	    })
	}	

function validate_page(current_page){
	if (previousBtnClicked) return true
	current_page = (current_page == null) ? '' : current_page;
	errorString = '';
	if (current_page == 'community') {
		errorString += checkChecker('user_match_profile_group_size_', 4, message['SelectCommunitySize']);
		errorString += checkChecker('user_match_profile_garb_', 4, message['SelectGarb']);
		errorString += checkChecker('user_match_profile_organization_type_', 5, message['SelectOrganizationType']);
		errorString += checkChecker('user_match_profile_ministries_', 11, message['SelectMinistry'],true);
		if ($('user_match_profile_ministries_99').checked) {
			if (!checkCheckText('user_match_profile_ministries_99','user_match_profile_ministries_other')) {
				errorString += message['EnterOtherMinistryOptions'];
			}
		}

	}	
	if (current_page == 'prayer') {
		errorString += checkChecker('user_match_profile_prayer_styles_', 7, message['SelectPrayerStyle'],true);
		if ($('user_match_profile_prayer_styles_99').checked) {
			if (!checkCheckText('user_match_profile_prayer_styles_99','user_match_profile_prayer_styles')) {
				errorString += message['EnterOtherPrayerStyles'];
			}
		}
		errorString += checkChecker('user_match_profile_prayer_frequency_', 6, message['CommunityPrayerFrequency']);
	}
	if (current_page == 'discernment'){
		errorString += checkChecker('user_match_profile_vocations_', 7, message['SelectVocations']);

	}	
	if (current_page == 'background') {
		errorString += checkChecker('user_match_profile_education_', 2, message['SelectEducationLevel'],true);
		if ($('user_match_profile_education_degrees').value.blank()){
			errorString +=  message['DescribeEducationalBackground']
		}
		if ($('user_match_profile_religion').selectedIndex == 0) {
			errorString += message['SelectIfCatholic']
		}
		errorString += checkChecker('user_match_profile_language_', 12, message['SelectLanguagesSpoken'],true);
	}	
	if (current_page == 'personal') {




		if ($('user_match_profile_reason').selectedIndex == 0) {
			errorString += message['SelectParticipateReason']
		}
		if ($('user_match_profile_gender').selectedIndex == 0) {
			errorString += message['SelectGender']
		}
		if ($('user_match_profile_marital').selectedIndex == 0) {
			errorString += message['SelectMarital']
		}
		if ($('user_match_profile_age').selectedIndex == 0) {
			errorString += message['SelectAge']
		}
		
		if ($('user_match_profile_consider').selectedIndex == 0) {
			errorString += message['SelectConsiderTime']
		}
		
		errorString += checkChecker('user_match_profile_residency_', 5, message['SelectResidency'],true);
		if ($('user_match_profile_residency_99').checked) {
			if (!checkCheckText('user_match_profile_residency_99','user_match_profile_residency_other')) {
				errorString += message['EnterOtherResidency'];
			}
		}

		errorString += checkChecker('user_match_profile_lives_in_', 5, message['SelectLivesIn'],true);
		if ($('user_match_profile_lives_in_99').checked) {
			if (!checkCheckText('user_match_profile_lives_in_99','user_match_profile_lives_in_other')) {
				errorString += message['EnterOtherLivesIn'];
			}
		}	
		errorString += checkChecker('user_match_profile_country_ministry_', 31, message['SelectRegion']);

		// Removing for now Sept 31, 2009
		// START
		//errorString += checkChecker('user_match_profile_country_base_', 3, message['SelectBaseCountry'],true);
		//if ($('user_match_profile_country_base_99').checked) {
		//	if (!checkCheckText('user_match_profile_country_base_99','user_match_profile_country_base_other')) {
		//		errorString += message['EnterOtherMinistryCountry'];
		//	}
		//}
		// END			
	}	
	if (current_page == 'register'){
		if($('user_data_first_name').value.blank()) {
			errorString += message['EnterFirstName'];
		}
		if($('user_data_city').value.blank()) {
			errorString += message['EnterCity'];
		}
		if($('countrySelect').value.blank()) {
			errorString += message['SelectACountry'];
		}
		if($('stateSelect').value.blank()) {
			errorString += message['SelectEnterState'];
		}
		try {
			if($('user_data_email').value.blank()) {
				errorString += message['EnterEmailAddress'];
			}
		} catch(e){}

		try {
			if ($('user_data_password').value.blank()) {
				errorString += message['EnterPassword'];
			}

		} catch(e){}

	}
	if (errorString != '') {
		Modalbox.show('<div class=\'warning\' style=\'text-align:center\'><strong>' + message['PleaseCorrect'] + ':</strong><ul style=\'text-align:left;\'>' + errorString + '</ul></div>', {
			title: message['Notice'],
			width: 400
		});
		return false;
	}
	return true;

}

function save_match(status_user){
        if(status_user == 0){
         Modalbox.show('<div class=\'warning\'><p>'+ message['LoginMatchSave'] +'</p>  <div style=\'text-align:right\'> <input type=\'button\' value=\'Exit\' onclick=\'Modalbox.hide()\' /></div></div>',{title: 'NOTICE', width: 400});
		return false;
	}
	return true;
}

function checkBox(event,item){
	$(item).checked = true;
}
function clearText(event,status,item){
	if (!status) {
		$(item).value = '';
	}
}

function checkCheckText(checkbox,textbox) {

	if ($(checkbox).checked && $(textbox).value.blank()) {
		return false;
	}
	return true;
}
function checkChecker(item,max,message,has_99){
	var has_99 = (has_99 == null) ? false : true;
	var is_checked = false;
	for (var x = 1; x <= max; x++ ) {
		try {
			if ($(item + x).checked) {
				is_checked = true;
			}
		} catch (e) {
			//alert(item + x);
		}
	}

	if (has_99 && $(item + '99').checked) {
		is_checked = true;
	}

	if (!is_checked) {
		return message;
	}
	return ""
}

function clearChecks(item,max,disable,has_99){
	var has_99 = (has_99 == null) ? false : true;
	var disable = (disable == null) ? false : true;
	for (var x = 1; x <= max; x++) {
		$(item + x).checked = false;
		if (disable){
			$(item + x).disabled = true;
		}
	}
	if (has_99) {
		$(item + '99').checked = false;

		if (disable) {
			$(item + '99').disabled = true;
		}
	}

}

function enableChecks(item,max,has_99){
	var has_99 = (has_99 == null) ? false : true;
	for (var x = 1; x <= max; x++) {
		$(item + x).disabled = false;
	}
	if (has_99) {
		$(item + '99').disabled = false;
	}	
}
function hideBannerAd(){
	$$(".BannerAdHolder")[0].hide();
}
