$(document).ready(function() {
	$("#news_signup").submit(function() {
		$("#content").html("<center><p><b>Un momento por favor...</b><br><img src='images/loader.gif' /></p></center>");
		//runAjax($(this).attr("action"), $(this).serialize());
		$.ajax({
		   type: "POST",
		   url: $(this).attr("action"),
		   data: $(this).serialize(),
		   dataType: "text",
		   success: function(html) {
				handleNewsResponse(html);
		   },
		   error: function(html) {
				handleNewsResponse(html);
		   }
		 });		
		return false;				 
		
	});
});
function handleNewsResponse(response) {
	var header = "<h1>Ofertas Electr&oacute;nicas</h1>";
	if(response.substring(0, 8) == "response") {
		response = eval(response);
		if(response[0].error_code == NaN) {
			$("#content").html(header +"Lo(s) siguiente(s) error(es) han occurido:<br>"+ response);
			return false;		
		} else if(response[0].error_code == 0) {
			var sMsg = header +"<p><b>Lo(s) siguiente(s) error(es) han occurido:</b></p>";
			for(var i = 0; i < response.length; i++) {
				sMsg += response[i].msg;
			}
			sMsg += "</div>";
			$("#content").html(sMsg);
			return false;		
		}	
	} else {
		$("#content").html(header + response);
	}
}