function ajaxSubmit(formId){
	$('input, option, checkbox, select, button, radio').removeClass("formError");
	$.ajax({
		url: $('#'+formId).attr('action'),
		type: 'POST',
		data: $('#'+formId).serializeArray(),
		success: ajaxReturn
	});
	return false;
} 
function ajaxReturn(jSonMsg){
	try{
		var response = eval('('+jSonMsg+')');
	} catch(e){}
			
	try{ 
		if(true == response.redirect){
			window.location.replace(response.url);
			return true;
		}
	} catch(e){}
			
	try{
		$.each(response.content, function(key,value){
			if("_external"==key){
				$.each(value,displayError);
			}else{
				displayError(key, value);
			}
		});
	}catch(e){}
}

function displayError(fieldId,message){
	alert(fieldId+' - '+message.toString());
	$('#'+fieldId).addClass("formError");
}
/* check radius suppors and force if can't find*/
jQuery(function() {
	jQuery.support.borderRadius = false;
	jQuery.each(['BorderRadius','MozBorderRadius','WebkitBorderRadius','OBorderRadius','KhtmlBorderRadius'], function() {
		if(document.body.style[this] !== undefined) jQuery.support.borderRadius = true;
		return (!jQuery.support.borderRadius);
	});
});
$(document).ready(function() {
	if(!$.support.borderRadius) curvyCorners.init();
});

function sendEmail(formId){
	document.getElementById('fade').style.display='block';
	document.getElementById('pop').style.display='block';
	$.ajax({
		url: URL_ROOT+'contato/send',
		type: 'POST',
		data: $('#'+formId).serializeArray(),
		success: function(data){
			document.getElementById('fade').style.display='none';
			document.getElementById('pop').style.display='none';
			alert(data);
		}
	});
}
