function get_remaining_chars(elem) {
	if ($(elem)){
		var a_strval = $(elem).value;
		var a_intval = a_strval.length;
		var rem_char = 115-a_intval;
		return rem_char;
	}
}

/*
*	display modal popup when accomplishment posted on page > 2
*/
function throw_accomplishment_posted_alert(c) {
	//Effect.Appear('accomplishment_posted_success_msg', {duration: 1.0});
	//Effect.Fade('accomplishment_posted_success_msg', {duration: 1.0, delay: 4.0});
	$('accomplishment_posted_msg').innerHTML = c;
	$('accomplishments_char_cntr').setStyle({color: "#F6FCCD"});
	if($('remaining_chars')) {
		$('remaining_chars').hide();
	}
}

function clear_accomplishment_del_msg() {
	if ($("flash_messages")) {$("flash_messages").innerHTML = "";}
}

function update_accomp_char_cnt(elem) {
	var cc = get_remaining_chars(elem);
	$('remaining_chars').update(cc);
	if(cc < 11) {
		$('remaining_chars').setStyle({color: 'red'});
	} else {
		$('remaining_chars').setStyle({color: '#999999'});
	}
}

function accomplishment_loading() {
	//background: transparent url(/assets/images/chrome/accomplishment_posting_icon.gif) no-repeat top left;
	Effect.Fade('accomplishment_entry_submit', {duration: 1.0});
	if($('accomplishment_posting').innerHTML.length < 1) { $('accomplishment_posting').insert("POSTING"); }
	$('accomplishment_posting').setStyle({
  		backgroundImage: 'url(/assets/images/chrome/accomplishment_posting_icon.gif)',
		backgroundPosition: "top left",
		backgroundRepeat: "no-repeat"
	});
	Effect.Appear('accomplishment_posting', {duration: 1.0, delay: 1.0});
}
function accomplishment_posted() {
	Effect.Appear('accomplishment_entry_submit', {duration: 1.0, delay: 1.0});
	Effect.Fade('accomplishment_posting', {duration: 1.0});
}

function accomplishmentSubmitError() {
	alert('There were errors in your submission');
}

function setUpAccomplishments() {
	if($('accomplishment_body_input')) {
		$('accomplishment_body_input').onfocus = function() {this.value = "";$('accomplishments_char_cntr').setStyle({color: "#999999"});$('remaining_chars').show();}
	}
	//$('accomplishment_body_input').onblur = function() {this.value = 'Take a step in a naturally healthy direction? Shout it out!';}
	
	//if($('accomplishment_posted_success_msg')) {
		// $('accomplishment_posting').setStyle({
		// 			display: "block"
		// 		});
		//$('accomplishment_posted_success_msg').hide();
		
	//}
	if($('accomplishment_posting')) $('accomplishment_posting').hide();
	var cc = "108";
	if(get_remaining_chars('accomplishment_body_input')) {
		
		cc = get_remaining_chars('accomplishment_body_input');
	}
	if($('accomplishments_char_cntr')) {
		$('accomplishments_char_cntr').update('<span id="remaining_chars">'+cc+'</span> characters remaining');
		$('accomplishments_char_cntr').setStyle({color: "#F6FCCD"});
	}
}
function setup_ie_hovers(){
	isIE = (navigator.appName == "Microsoft Internet Explorer")?true:false;
	isIE7 = (isIE && document.documentElement && typeof document.documentElement.style.maxHeight!="undefined")?true:false;
	isIE6 = (isIE && !isIE7)?true:false;
	if(isIE6) throwMosaicElemHoverForIe6();
}
function throwMosaicElemHoverForIe6() {
	//alert("foo");
	theMosaicElements = $$('li.mosaic_elem img');
	theMosaicElements.each(function(s) {
		s.observe('mouseover', function(event){
			Event.element(event).parentNode.addClassName('mosaic_elem_hover_state');
		}).observe('mouseout', function(event){
			Event.element(event).parentNode.removeClassName('mosaic_elem_hover_state');
		});
	});
	
	$$('div.popper').each(function(poElement) {
		var cBGImg = poElement.currentStyle.backgroundImage;
		var cImage = cBGImg.substring(cBGImg.indexOf('"') + 1, cBGImg.lastIndexOf('"'));
		poElement.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + cImage + "', sizingMethod='scale')";
		poElement.style.backgroundImage = "none";
	});
	// mosaic_elem_hover_state
}
Event.observe(window, 'load', function() {
	isIE = (navigator.appName == "Microsoft Internet Explorer")?true:false;
	isIE7 = (isIE && document.documentElement && typeof document.documentElement.style.maxHeight!="undefined")?true:false;
	isIE6 = (isIE && !isIE7)?true:false;
	setUpAccomplishments();
	if(isIE6) throwMosaicElemHoverForIe6();
});


//Event.observe(window,'load',setUpAccomplishments)
