function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
cntfield.value = maxlimit - field.value.length;
}

function myMoveAForm() {
	var oContent = document.getElementById('content');
	var oForm = document.getElementById('aForm');
	if (oContent && oForm) {
		oContent.parentNode.insertBefore(oForm, oContent);
	}
}

function myAddClassifiedClick() {
	if (document.getElementById('aFormContainer')) {
		Effect.toggle('aFormContainer', 'Appear');
	}
	if (document.getElementById('aFormError')) {
		Effect.toggle('aFormError', 'Appear');
	}
	if (document.getElementById('aFormPosted')) {
		Effect.toggle('aFormPosted', 'Appear');
	}
}

function myContactAuthorClick(sTitle) {
	var oEl = document.getElementById('cFormContainer');
	if (!oEl) {
		return;
	}
	if (!oEl.innerHTML) {
		oEl.innerHTML =
			'<div id="cFormError"></div>\
			<form id="cForm">\
			Name:<br/><input type="text" name="cname"/><br/>\
			Email:<br/><input type="text" name="cemail"/><br/>\
			Subject:<br/><div class="like_input"><b>RE: ' + sTitle + '</b></div><br/>\
			Message:<br/><textarea name="cmsg" rows="1" cols="2"></textarea>\
			<input type="hidden" name="cid" value="' + myCid + '"/>\
			<input type="hidden" name="action" value="email"/>\
			<center><input type="button" id="cFormSend" value="Send Message" onclick="myContactAuthorSend(this.form)"/></center>\
			</form>';
	}
	var oEl = document.getElementById('cFormError');
	if (!oEl) {
		return;
	}
	oEl.innerHTML = '';
	Effect.toggle('cFormContainer','Appear');
}

function myContactAuthorSend(oForm) {
	var oEl = document.getElementById('cFormSend');
	if (!oEl) {
		return;
	}
	oEl.disabled = 'disabled';
	oEl.value = 'Please Wait...';
	new Ajax.Request(
		document.location.toString(),
		{
			parameters: $('cForm').serialize(true),
			onSuccess: myContactAuthorSuccess,
			onFailure: myContactAuthorFailure
		}
	);
}

function myContactAuthorSuccess(oResponse) {
	var oElSuccess = document.getElementById('cFormSuccess');
	var oElError = document.getElementById('cFormError');
	var oElSend = document.getElementById('cFormSend');
	if (!oElSuccess || !oElError || !oElSend) {
		return;
	}
	if (oResponse && oResponse.responseText) {
		oResponse = oResponse.responseText.evalJSON();
	}
	if (oResponse && oResponse.success) {
		oElSuccess.innerHTML = '<div class="email_ok">Your message has been sent</div>';
		myContactAuthorClick = null;
		myContactAuthorSend = null;
		myContactAuthorSuccess = null;
		myContactAuthorFailure = null;
		return;
	}
	oElSend.disabled = null;
	oElSend.value = 'Send Message';
	if (oResponse && oResponse.error) {
		oElError.innerHTML = '<div class="email_err">' + oResponse.error.replace(/[^\w\s]/g, '') + '</div>';
		return;
	}
	oElError.innerHTML = '<div class="email_err">Could not send message. Please reload this page and try again.</div>';
}

function myContactAuthorFailure() {
	myContactAuthorSuccess();
}
