///*
// * Functionality for closing the generated litebox
// */
//function closeLitebox() {
//	// close the modal box
//	$$('.modal-close').each(function(elm) {
//		elm.observe('click', function(event) {
//			event.stop();
//			$('rp_litebox_bg').fade({duration:0.2});
//		});
//	});
//}
//
///*
// * Functionality to display comments for specific blog
// */
//function showComments(id) {
//	new Ajax.Updater('rp_modal_functions', '/blogs/comments/', {method: 'post', postBody: 'id='+id, onComplete: function() {
//		closeLitebox();
//	}});
//}
//
///*
// * Functionality 
// */
//function prefillUser(elm) {
//	new Ajax.Request('/users/player_info/', {method: 'post', postBody: 'id='+elm.value, onComplete: function(transport) {
//		var data = transport.responseText.evalJSON();
//		console.log(data.first_name);
//		$('UserFirstName').value = data.first_name;
//		$('UserLastName').value = data.last_name;
//	}});
//}
//
///* Front-end 
//function setExternalLink() {
//	$$('a[rel="external"]').each(function(elm) {
//		elm.setAttribute('target', '_blank');
//	});
//}
//
//document.observe('dom:loaded', setExternalLink);
//*/
//
function bannerImg() {
	if($('banner')) {
		var imgNumber = Math.floor(Math.random()*4);
		$('banner').className = 'banner-'+imgNumber;
	}
}
document.observe('dom:loaded', bannerImg);
//
///*
// * Functions for building setting and removing form hints
// */
//function setFormHints() {
//	// loop through all form input elements where class="form-hint"
//	$$('input.form-hint').each(function(elm) {
//		// watch for any focus events on the form input
//		elm.observe('focus', function() {
//			removeFormHint(elm);
//		});
//		// watch for any blur events on the form input
//		elm.observe('blur', function() {
//			displayFormHint(elm);
//		});
//		// watch for any blur events on the form input
//		elm.up('form').observe('submit', function() {
//			if(elm.value == elm.title) {
//				elm.value = '';
//			}
//		});
//		displayFormHint(elm);
//	});
//}
//function removeFormHint(elm) {
//	// if the value of the field is equal to the title, then we need to clear it and set the styling.
//	if(elm.value == elm.title) {
//		elm.value = "";
//		elm.style.color = "#000";
//		elm.style.fontStyle = "normal";
//	}
//}
//function displayFormHint(elm) {
//	// if the value of the filed is empty then set it to the form hint (the title).
//	if(elm.value == "") {
//		elm.value = elm.title;
//		elm.style.color = "#999";
//		elm.style.fontStyle = "italic";
//	} else if (elm.value == elm.title) {
//		elm.style.color = "#999";
//		elm.style.fontStyle = "italic";
//	}
//}
//
//// when the dom has loaded, apply all form hint observers
//document.observe('dom:loaded', setFormHints);

/* Newsletter Export */
function chooseExport() {
	$$('input.export-type').each(function(elm) {
		elm.observe('change', function() {
			new Ajax.Request('/newsletters/cc_export/'+$('NewsletterId').value, {method: 'post', onComplete: function(transport) {
				$('NewsletterCode').value = transport.responseText;
			}});
		});
	});
}

document.observe('dom:loaded', chooseExport);

// fundraiser / bout
function changeTypes() {
	if($$('input.event-type')) {
		$$('input.event-type').each(function(elm) {
			elm.observe('change', function() {
				if(elm.value == 'Bout') {
					$$('div.fund').each(function(e) {
						e.hide();
					});
					$$('div.bout').each(function(e) {
						e.show();
					});
				} else if(elm.value == 'Fundraiser') {
					$$('div.bout').each(function(e) {
						e.hide();
					});
					$$('div.fund').each(function(e) {
						e.show();
					});
				}
				$$('div.error-message').each(function(message) {
					message.hide();
				});
			});
		});
	}
}
document.observe('dom:loaded', changeTypes);

/*
 * Show status dates (if using a date range)
 */
function showStatusDates() {
	$$('div.status-dates').each(function(elm) {
		showDiscontinueDate();
		elm.previous('div.status').childElements().each(function(child) {
			if(child.readAttribute('type') == 'radio') {
				if(child.checked && child.value != 2) {
					elm.hide();
				}
				child.observe('click', function(radio) {
					if(child.value == 2) {
						elm.show();
					} else {
						elm.hide();
					}
				});
			}
		});
	});
}
function showDiscontinueDate() {
	$$('div.use-end-date').each(function(elm) {
		if(elm.down().next().checked == false) {
			elm.next('div.end-date').hide();
			elm.next('div.end-date').previous().hide();
		}
		elm.observe('click', function(e) {
			if(elm.down().next().checked == true) {
				elm.next('div.end-date').show();
				elm.next('div.end-date').previous().show();
			} else {          
				elm.next('div.end-date').hide();
				elm.next('div.end-date').previous().hide();
			}
		})
	});
}
document.observe('dom:loaded', showStatusDates);

// events module
function allowTeams(elm) {
	if(elm.value == 1) {
		$$('.is-team').each(function(elm) {
			elm.disabled = false;
		});
	} else {
		$$('.is-team').each(function(elm) {
			elm.disabled = true;
		});
	}
}

// sponsors module
function showLogo() {
	$$('.sponsor-type').each(function(elm) {
		elm.observe('change', function(e) {
			if(elm.value == 'Platinum') {
				$('sponsor_logo').show();
			} else {
				$('sponsor_logo').hide();
			}
		});
	});
}
document.observe('dom:loaded', showLogo);
