// JavaScript Document
UTF8 = {
    encode: function(s){
        for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
            s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
        );
        return s.join("");
    },
    decode: function(s){
        for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
            ((a = s[i][c](0)) & 0x80) &&
            (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
            o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
        );
        return s.join("");
    }
};
var jQ = jQuery.noConflict();
jQ('#nombre').live("keypress", function(e) {
	/* ENTER PRESSED*/
	if (e.keyCode == 13) {
		validate();
	}
});
jQ('#edad').live("keypress", function(e) {
	/* ENTER PRESSED*/
	if (e.keyCode == 13) {
		validate();
	}
});

jQ('#ocupacion').live("keypress", function(e) {
	/* ENTER PRESSED*/
	if (e.keyCode == 13) {
		validate();
	}
});
jQ('#email').live("keypress", function(e) {
	/* ENTER PRESSED*/
	if (e.keyCode == 13) {
		validate();
	}
});
jQ('#telefono').live("keypress", function(e) {
	/* ENTER PRESSED*/
	if (e.keyCode == 13) {
		validate();
	}
});

jQ('#celular').live("keypress", function(e) {
	/* ENTER PRESSED*/
	if (e.keyCode == 13) {
		validate();
	}
});

jQ('#pais').live("keypress", function(e) {
	/* ENTER PRESSED*/
	if (e.keyCode == 13) {
		validate();
	}
});

jQ('#ciudad').live("keypress", function(e) {
	/* ENTER PRESSED*/
	if (e.keyCode == 13) {
		validate();
	}
});

function validate () {
	if (jQ('#nombre').val()=='') {
		jAlert ('Debe digitar el nombre.','Error');
		return false;
	}
	if (jQ('#edad').val()=='') {
		jAlert ('Debe digitar la edad.','Error');
		return false;
	}
	if (jQ('#ocupacion').val()=='') {
		jAlert ('Debe digitar el tel&eacute;fono.','Error');
		return false;
	}
	if (jQ('#email').val()!='') {
		if(jQ('#email').val().indexOf('@', 0) == -1 || jQ('#email').val().indexOf('.', 0) == -1) {  
			jAlert ('La direcci&oacute;n email es incorrecta', 'Error');  
			return false;  
		} 
	}else{
		jAlert ('Debe digitar el email.','Error');
		return false;
	}
	if (jQ('#telefono').val()=='') {
		jAlert ('Debe digitar el tel&eacute;fono.','Error');
		return false;
	}	
	if (jQ('#celular').val()=='') {
		jAlert ('Debe digitar el n&uacute;mero de celular.','Error');
		return false;
	}
	if (jQ('#pais').val()=='') {
		jAlert ('Debe digitar el pa&iacute;s.','Error');
		return false;
	}
	if (jQ('#ciudad').val()=='') {
		jAlert ('Debe digitar la ciudad.','Error');
		return false;
	}
}

function validate2 () {

	if (jQ('#nombre').val()=='') {
		jAlert ('Debe digitar el nombre.','Error');
		return false;
	}
	if (jQ('#email').val()!='') {
		if(jQ('#email').val().indexOf('@', 0) == -1 || jQ('#email').val().indexOf('.', 0) == -1) {  
			jAlert ('La direcci&oacute;n email es incorrecta', 'Error');  
			return false;  
		} 
	}else{
		jAlert ('Debe digitar el email.','Error');
		return false;
	}
	if (jQ('#telefono').val()=='') {
		jAlert ('Debe digitar el tel&eacute;fono.','Error');
		return false;
	}	
	if (jQ('#city').val()=='') {
		jAlert ('Debe digitar la ciudad.','Error');
		return false;
	}
	
	var datos = "nombre=" + jQ('#nombre').val() + "&email=" + jQ('#email').val() + "&telefono=" + jQ('#telefono').val() + "&city=" + jQ('#city').val() + "&comentarios=" + jQ('#comentarios').val(); 
	
	jQ('#formulario').html('<p style="text-align:center; font-family: arial; "><img src="images/ajax-loader.gif" /><br>Enviando Datos</p>');
	
	jQ.ajax
	(
		{
			type: "POST",
			url: "enviar_valoracion.php",
			data: datos, 
			success: function(data)
			{
				jQ('#formulario').html(data);
				return false;
			},
			error: function(data)
			{
				jAlert('Se ha producido un error interno. ()\n' + data,'Error');
			}
		}
	);
}
