/*Declare Rules
-----------------------------------------------------*/
if(!is_report) {
	
	var Rules = {
	
		/*Login Bar
		-----------------------------------------------------*/	
		'a#btn_login_bar:click': function(element, event) {
			Event.stop(event);
			Effect.toggle('loginbar', 'slide', {duration: .5});
		},
		'#loginbar input.text_small:focus': function(element, event) {
			element.value = '';
		},
	
		/*Amber Alerts Form
		-----------------------------------------------------*/
		'#amber_alerts_form:loaded' : function(element) {
			element.target = '_blank';
		},
	
		/*New Window Links
		-----------------------------------------------------*/
		'a.new_window:loaded' : function(element) {
			element.target = '_blank';
		},
	
		/*Search Tabs
		-----------------------------------------------------*/
		'a#s_people_search:click' : function(element, event) {
			Event.stop(event);
			getTabData('people_search');
		},
		'a#s_background_information:click' : function(element, event) {
			Event.stop(event);
			getTabData('background_information');
		},
		'a#s_reverse_lookup:click' : function(element, event) {
			Event.stop(event);
			getTabData('reverse_lookup');
		},
		'a#s_criminal_records:click' : function(element, event) {
			Event.stop(event);
			getTabData('criminal_records');
		},
	
		/*Search Forms
		-----------------------------------------------------*/
		'form#people_search_form:submit' : function(element, event) {
			if(!validate_people_search_form(element)) {
				Event.stop(event);
			}
		},
		'form#people_search_standalone_form:submit' : function(element, event) {
			if(!validate_people_search_form(element)) {
				Event.stop(event);
			}
		},
		'form#background_search_form:submit' : function(element, event) {
			if(!validate_background_search_form(element)) {
				Event.stop(event);
			}
		},
		'form#background_search_standalone_form:submit' : function(element, event) {
			if(!validate_background_search_form(element)) {
				Event.stop(event);
			}
		},
		'form#criminal_search_form:submit' : function(element, event) {
			if(!validate_criminal_search_form(element)) {
				Event.stop(event);
			}
		},
		'form#criminal_search_standalone_form:submit' : function(element, event) {
			if(!validate_criminal_search_form(element)) {
				Event.stop(event);
			}
		},
		'form#phone_search_form:submit' : function(element, event) {
			if(!validate_phone_search_form(element)) {
				Event.stop(event);
			}
		},
		'form#phone_search_standalone_form:submit' : function(element, event) {
			if(!validate_phone_search_form(element)) {
				Event.stop(event);
			}
		},
		'form#address_search_form:submit' : function(element, event) {
			if(!validate_address_search_form(element)) {
				Event.stop(event);
			}
		},
		'form#address_search_standalone_form:submit' : function(element, event) {
			if(!validate_address_search_form(element)) {
				Event.stop(event);
			}
		},
		'form#advanced_search_form:submit' : function(element, event) {
			type = $('search_type').value;
			if(!validate_advanced_search_form(element, type)) {
				Event.stop(event);
			}
		},
		'#form_container input.first_name:keypress' : function(element, event) {
			inputs = document.getElementsByClassName('first_name');
			inputs.each(
				function(input)
				{
					input.value = element.value;
				}
			);
		},
		'#form_container input.first_name:change' : function(element, event) {
			inputs = document.getElementsByClassName('first_name');
			inputs.each(
				function(input)
				{
					input.value = element.value;
				}
			);
		},
		'#form_container input.middle_initial:keypress' : function(element, event) {
			inputs = document.getElementsByClassName('middle_initial');
			inputs.each(
				function(input)
				{
					input.value = element.value;
				}
			);
		},
		'#form_container input.middle_initial:change' : function(element, event) {
			inputs = document.getElementsByClassName('middle_initial');
			inputs.each(
				function(input)
				{
					input.value = element.value;
				}
			);
		},
		'#form_container input.last_name:keypress' : function(element, event) {
			inputs = document.getElementsByClassName('last_name');
			inputs.each(
				function(input)
				{
					input.value = element.value;
				}
			);
		},
		'#form_container input.last_name:change' : function(element, event) {
			inputs = document.getElementsByClassName('last_name');
			inputs.each(
				function(input)
				{
					input.value = element.value;
				}
			);
		},
		'#form_container input.city:keypress' : function(element, event) {
			inputs = document.getElementsByClassName('city');
			inputs.each(
				function(input)
				{
					input.value = element.value;
				}
			);
		},
		'#form_container input.city:change' : function(element, event) {
			inputs = document.getElementsByClassName('city');
			inputs.each(
				function(input)
				{
					input.value = element.value;
				}
			);
		},
		'#form_container select.state:change' : function(element, event) {
			inputs = document.getElementsByClassName('state');
			inputs.each(
				function(input)
				{
					input.selectedIndex = element.selectedIndex;
				}
			);
		},
	
		/*Validate Subscriber Application Form
		-----------------------------------------------------*/
		'form#registration_application:submit' : function(element, event) {
			if(!validate_registration_form()) {
				Event.stop(event);
			}
		},
	
		/*Clear All Form Fields
		-----------------------------------------------------*/
		'a#clear_fields:click' : function(element, event) {
			Event.stop(event);
			// Get the ID of the second form on the page (exclude the login form at the top)
			form = document.getElementsByTagName("form")[1].id;
			Form.reset(form);
			Form.focusFirstElement(form);
		},
	
		/*Populate billing address with street address
		-----------------------------------------------------*/
		'#address_check:click' : function() {
			$('billing_address').value = $('org_street_address').value;
			$('billing_city').value = $('org_city').value;
			$('billing_state').selectedIndex = $('org_state').selectedIndex;
			$('billing_zip').value = $('org_zip').value;
		},
	
		/*CC Info Table
		-----------------------------------------------------*/
		'#cc_info_table:loaded' : function(element) {
			element.style.display = 'none';
		},
		'#cc_info_table_toggle:click' : function(element) {
			Effect.toggle('cc_info_table', 'slide', {duration: .5});
		},
	
		/*CC Security Code PopUp
		-----------------------------------------------------*/
		'a#csc_popup:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'csc_popup_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=600,height=470");
		},
	
		/*Service Agreement PopUp
		-----------------------------------------------------*/
		'a.service_popup:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'service_popup_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,top=50,left=50,width=600,height=600");
		},
		
		/*Printable Report PopUp
		-----------------------------------------------------*/
		'a.report_popup:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'report_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=800,height=470");
		},
	
		/*Sample Report PopUp
		-----------------------------------------------------*/
		'a.sample_report:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'report_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=800,height=470");
		},
	
		/*Mobile Comparison PopUp
		-----------------------------------------------------*/
		'a.mobile_comparison:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'mobile_comparison_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=850,height=550");
		},
	
		/*Product Comparison PopUp
		-----------------------------------------------------*/
		'a.product_comparison:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'product_comparison_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=850,height=660");
		},
	
		/*Court Details PopUp
		-----------------------------------------------------*/
		'a.court_details:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'court_details_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=850,height=660");
		},
	
		/*Geo Relatives PopUp
		-----------------------------------------------------*/
		'a.geo_relatives:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'geo_relatives_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=850,height=660");
		},
	
		/*Businesses PopUp
		-----------------------------------------------------*/
		'a.businesses_popup:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'court_details_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=850,height=660");
		},
	
		/*Forgot Password Form
		-----------------------------------------------------*/
		'a#forgot_pass_link:click': function(element, event) {
			Event.stop(event);
			Effect.toggle('forgot_pass_form', 'slide', {duration: .5});
		},
	
		/*Messages
		-----------------------------------------------------*/
		'div.error_message:loaded' : function(element, event) {
			new Effect.Pulsate(element, {duration: 2.0});
		},
		'div.success_message:loaded' : function(element, event) {
			new Effect.Pulsate(element, {duration: 2.0});
		},
	
		/*Window Overlays
		-----------------------------------------------------*/
		'li#f_email_this_page a:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('email_this_page', 'appear', {duration: .5});
			toggleSelects('hidden');
		},
		'#email_this_page a.close:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('email_this_page', 'appear', {duration: .5});
			toggleSelects('visible');
		},
		'#whats_this:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('login_whats_this', 'appear', {duration: .5});
			toggleSelects('hidden');
		},
		'#login_whats_this a.close:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('login_whats_this', 'appear', {duration: .5});
			toggleSelects('visible');
		},
		'a#password_popup:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('password_whats_this', 'appear', {duration: .5});
			toggleSelects('hidden');
		},
		'#password_whats_this a.close:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('password_whats_this', 'appear', {duration: .5});
			toggleSelects('visible');
		}
		
	};
	
} else {
	
	var Rules = {
		/*Login Bar
		-----------------------------------------------------*/	
		'a#btn_login_bar:click': function(element, event) {
			Event.stop(event);
			Effect.toggle('loginbar', 'slide', {duration: .5});
		},
		'#loginbar input.text_small:focus': function(element, event) {
			element.value = '';
		},
		/*New Window Links
		-----------------------------------------------------*/
		'a.new_window:loaded' : function(element) {
			element.target = '_blank';
		},
		/*Printable Report PopUp
		-----------------------------------------------------*/
		'a.report_popup:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'report_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=800,height=470");
		},
		/*Court Details PopUp
		-----------------------------------------------------*/
		'a.court_details:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'court_details_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=850,height=660");
		},
		/*Geo Relatives PopUp
		-----------------------------------------------------*/
		'a.geo_relatives:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'geo_relatives_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=850,height=660");
		},
		'form.geo_link:submit' : function(element, event) {
			href = element.action;
			windowName = 'geo_relatives_window';
			element.target = windowName;
			popup = window.open(href, windowName, "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=850,height=660");
		},
		
		/*Businesses PopUp
		-----------------------------------------------------*/
		'a.businesses_popup:click' : function(element, event) {
			Event.stop(event);
			href = element.href;
			popup = window.open(href, 'court_details_window', "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=50,left=50,width=850,height=660");
		},
		/*Window Overlays
		-----------------------------------------------------*/
		'li#f_email_this_page a:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('email_this_page', 'appear', {duration: .5});
			toggleSelects('hidden');
		},
		'#email_this_page a.close:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('email_this_page', 'appear', {duration: .5});
			toggleSelects('visible');
		},
		'#whats_this:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('login_whats_this', 'appear', {duration: .5});
			toggleSelects('hidden');
		},
		'#login_whats_this a.close:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('login_whats_this', 'appear', {duration: .5});
			toggleSelects('visible');
		},
		'a#password_popup:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('password_whats_this', 'appear', {duration: .5});
			toggleSelects('hidden');
		},
		'#password_whats_this a.close:click' : function(element, event) {
			Event.stop(event);
			Effect.toggle('password_whats_this', 'appear', {duration: .5});
			toggleSelects('visible');
		}
	};
	
}


/* Initialize Rules
-----------------------------------------------------*/
function startEvents() {
	EventSelectors.start(Rules);
}

/*Hide the login bar when the DOM is loaded, 
but before the page is loaded, so we don't see it*/
Event.onDOMReady(function() {
	Element.hide('loginbar');
});

Event.observe(window, "load", startEvents, false);
//Event.observe(window, "load", initTabs, false);
Event.observe(window, "load", getExternalLinks, false);
