// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function text_field_clear(fieldID) {
	var inputValue = Field.getValue(fieldID);
	if(fieldID == 'layout_search') {
		if(inputValue == 'Enter search term here') {
			Field.clear(fieldID);
		}
	}
	else if(fieldID == 'admin_search') {
		if(inputValue == 'Search for user here' || inputValue == 'Search for nominations here' || inputValue == 'Search for blog here') {
			Field.clear(fieldID);
		}
	}
	else if(fieldID == 'user_email') {
		if(inputValue == 'example@isp.com') {
			Field.clear(fieldID);
		}
	}
	else if(fieldID == 'user_date_of_birth') {
		if(inputValue == 'mm/dd/yyyy') {
			Field.clear(fieldID);
		}
	}
	else {
		Field.clear(fieldID);
	}
}

function text_field_reset(fieldID) {
	if(fieldID == 'layout_search' && $F(fieldID) == '') {
		Form.reset('form_search');
	} else 	if(fieldID == 'admin_search' && $F(fieldID) == '') {
		Form.reset('form_admin_search');
	}
}

function toggle_login_bar() {
	// Element.visible('loginbar'));
	Effect.toggle('loginbar', 'blind', {duration:1}); 
	setTimeout('Form.focusFirstElement(\'form_login\');', 1250);
}

function set_categories_height() {
	main_content_height = Element.getHeight('main_content');
	categories_height = Element.getHeight('categories');
	h = main_content_height + 'px';
	if(main_content_height > categories_height) {
		Element.setStyle('categories', {height: h});
	}
}
function show_forgot_if_necessary() {
	Try.these(
		function() {
			if( Element.visible('notfound') ) {
				Element.show('forgot_password');
			}
		},
		function() {
			if(!Element.visible('notfound') ) {
				Element.show('forgot_password');
			}
		},
		function() {
			// do nothing
			return false;
		}
	);
}
function set_correct_checks(english, adult_content) {
	$('blog_english').checked = english;
	$('blog_safe_content').checked = adult_content;
}
function set_foreign_language_category(num_categories, foreign_category_id) {
	for (var i = 1; i <= num_categories; i++ ) {
		if($('category_' + i)) {
			if( i != foreign_category_id ) {
				$('category_' + i).checked = false;
				$('category_' + i).disabled = true;
			}
			else {
				$('category_' + i).checked = true;
				$('flashes').update('Foreign Language blogs are restricted to the foreign language category.')
			}
		}
	}
}