function create_input(name){
	// creates an input element if it does not exist.
	// returns the input element.
	var elem = null;
	inputList = document.forms[0].getElementsByTagName('input');
	for(i=0; i<inputList.length; i++){
		if(name == inputList[i].name){
			elem = inputList[i];
			break;
		}	
	}
	if(null == elem){
		try {
			// this hokey method is for IE... for shame. Mozilla and other browsers will throw an exception.
			var new_input = document.createElement('<input name="'+name+'">');
		} catch(e){
				// Catch the exception and do it the right way.
				var new_input = document.createElement('input');
				new_input.setAttribute('name', name)
		}
		new_input.setAttribute('type','hidden');
		document.forms[0].appendChild(new_input);
		elem = document.forms[0].lastChild;
	} 
	return elem;		
}


function pop_photo(src){
	window.open(src,'popup','statusbar.visible=false, toolbar.visible=false, personalbar.visible=false, resizable=no, titlebar=no, status=no, width=620, height=420');
}
function nav_content_cat(cat_id) {
	if (document.forms[0].content_cat_id) {
		document.forms[0].content_cat_id.value = cat_id;
		FuseAction('cms.cms_article_browse');
	}
}
function click_article(id) {
	if (undefined == document.forms[0].content_id){
		new_inp = create_input('content_id');
	}
	document.forms[0].content_id.value = id;
	FuseAction('cms.cms_article_display_by_id');
}
function click_news(id) {
	if (undefined == document.forms[0].content_id){
		new_inp = create_input('content_id');
	}
	document.forms[0].content_id.value=id;
   FuseAction('cms.news_display_full');
}
// --- search function
function run_search(e){
	if (13 == e.keyCode) {
		FuseAction('search.fts');
		return true;
	}
}
// --- attach keypress event to the search input
function attach_enter(){
	dojo.connect(dojo.byId('q_redundant'),'onkeypress','run_search');
	if (undefined != dojo.byId('q')) {
		dojo.connect(dojo.byId('q'),'onkeypress','run_search');		
	}
}
dojo.addOnLoad(attach_enter);

function change_archive(param) {
	document.forms[0].archive_year.value = param;
	document.forms[0].submit();
}
function pager(param) {
	var new_val = null;
	switch(param){
		case 'back':
			document.forms[0].current_page.value = parseInt(document.forms[0].current_page.value) - 1;
		break;
		case 'next':
			document.forms[0].current_page.value = parseInt(document.forms[0].current_page.value) + 1;
		break;
		default:
			document.forms[0].current_page.value = param;
	}
	document.forms[0].submit();
}
function church_finder() {
	document.forms[0].content_cat_id.value = "";
	var loc = document.forms[0].church_finder.value;
	FuseAction('cms.church_finder_'+loc);
}
function verifyRequired() {
	if (document.forms[0].fields_email.value == "") {
		document.forms[0].fields_email.focus();
		alert("The Email field is required.");
	}
	else {
		document.location = "http://app.icontact.com/icp/signup.php?listid=85925&specialid:85925=QVKS&clientid=283302&formid=6521&reallistid=1&doubleopt=0&redirect=http://www.icontact.com/www/signup/thanks.html&errorredirect=http://www.icontact.com/www/signup/error.html&fields_email=" + document.forms[0].fields_email.value;	
	}
}
