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

function clearTextField(initial_message, element) {
	if (element.value == initial_message) {
		element.value = '';
	}
}

function removeEmailErrorMessage() {
	if ($('email_store_failed') != null) {
		Element.remove('email_store_failed')
	}
}

function enableErrorOnField(id) {
	removeEmailErrorMessage();
  	$(id).addClassName("fieldWithErrors");
}

function removeEmailFieldWithErrors(element) {
    if (element.className == "fieldWithErrors") {
		element.removeClassName('emailFieldWithErrors');
    }
}
    

function commentsLoading() {
	$('submit_comment').disabled = true;
}

function contactLoading() {
	$('submit_contact').disabled = true;
}

function enableContactSubmit() {
	$('submit_contact').disabled = false;
}

function showSpinner() {
	$('spinner').show();
}

function hideSpinner() {
	$('spinner').hide();
}

String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};

// Contact

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	};
}

function addContactEmail() {
	if (document.getElementById('contact_address') != null) {
		var link = document.createElement('a');
		link.href = "znvygb:pbagngb\100vzcebirvg\056pbz\056oe".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
		link.innerHTML = "pbagngb\100vzcebirvg\056pbz\056oe".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
	
		var contactAddress = document.getElementById('contact_address');
		contactAddress.innerHTML = 'Email: ';
		contactAddress.appendChild(link);
	};
}


// Newsletter methods
function disbleFormEmailSubmit() {
	$(formEmailSubmit()).disabled = true;
}

function formEmailSubmit() {
	return 'newsletter_email_submit'
}

function personEmailValue() {
	$('person_email').value = $('person_email').value.trim();
	return $('person_email').value;
}

function validInput() {
	if (personEmailValue() != '' && personEmailValue() != 'seu e-mail') { 
		return true;
	} else {
		return false;
	}
}

function clearFieldAndMessages(initial_message, element) {
	clearTextField(initial_message, element)
	removeEmailErrorMessage();
	$(formEmailSubmit()).disabled = false;
	if (element.className == "fieldWithErrors") {
		element.removeClassName("fieldWithErrors");
	}
}

addLoadEvent(addContactEmail);