
var handleSuccess_enviarFormContacto = function(o){
	if(o.responseText !== undefined){
				
		var messages = [];
		var mensajeError = '';
        // Use the JSON Utility to parse the data returned from the server
        try {
            messages = YAHOO.lang.JSON.parse(o.responseText);
            for(var campo in messages) { 
             		for (var razon in messages[campo])	{
             			if (messages[campo][razon] !== undefined && messages[campo][razon] != '')	
             				mensajeError += "<p>&raquo; " + messages[campo][razon] + "</p>\n";
             				
             			 
             				clase = new String(document.getElementById(campo).className);
             				
             				//alert(clase + "Error");
             				
             				//if (clase.indexOf('Error') <= 0)
								//document.getElementById(campo).className = clase + "Error";
             		} 
             }
             if (mensajeError != '')	{
             	document.getElementById("mensaje-error-contacto").innerHTML = mensajeError;
             	document.getElementById("mensaje-error-contacto").className = "mensaje-error";
             }
             else	{
             	document.getElementById('form-contacto-zona-publica').submit();
             }
            
        }
        catch (x) {
            alert("JSON Parse failed! " + x);
            return;
        }
	}
};

var handleFailure_enviarFormContacto = function(o){
	if(o.responseText !== undefined){
		alert("<li>Transaction id: " + o.tId + "</li>");
		alert("<li>HTTP status: " + o.status + "</li>");
		alert("<li>Status code message: " + o.statusText + "</li>");
		
		//div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
		//div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
		//div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
	}
};

var callback_enviarFormContacto =
{
  success:handleSuccess_enviarFormContacto,
  failure:handleFailure_enviarFormContacto
};

function enviarFormContacto()	{
	//Reset todos los estilos:
	
	//document.getElementById("correo-electronico").className		= "form_campoBuscadorHome";
    //document.getElementById("codigo-personal").className 		= "form_campoBuscadorHome";
    //document.getElementById("mensaje-error").className 			= "oculto";
   
	// argument formId can be the id or name attribute value of the
	// HTML form, or an HTML form object.
	var formObject = document.getElementById('form-contacto-zona-publica');
	YAHOO.util.Connect.setForm(formObject);
	// This example facilitates a POST transaction.
	// An HTTP GET can be used as well.
	var request = YAHOO.util.Connect.asyncRequest('POST', '/validar/formulario', callback_enviarFormContacto);
}




