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


//$(document).ready (function () {
//	$('.service').click(followLinkFromId);
//});

if(location.href.match("edit_page_content") != null || location.href.match("edit_blog") != null) {
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced"
	});
}

//function followLinkFromId () {
//	location.href = "/" + $(this).attr('id')
//}


function validateMessageForm (f) {
	var toValidate = getElementsByClass('required_field', f);
	var valid = true;
	
	for (var i = 0; i < toValidate.length; i++) {		
		if(toValidate[i].className.indexOf("comboBox") != -1){
			if(toValidate[i].selectedIndex == 0 || toValidate[i].selectedIndex == 1) {
				valid = false;
			}
		}
		else {
			if(toValidate[i].value == null || toValidate[i].value == '') {			
				valid = false;	
			}
		}
	}
	
	if(!valid) {
		alert("You have not entered information in all the required fields.\nPlease enter any missing information and try again.");
	}
	
	return valid;
}


// Library functions
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}