var _MAX_TIMEOUT_AJAX_ 	= 10000; //10 Segundos de espera m�xima para resposta em ajax
var _HTTP_PATH_			= "/";
var WPMedicSupply = {
		Comentario: function(form)  {
			
			form = $(form);
			$.ajax({
					url			: _HTTP_PATH_ + "securimage/process_comment.php",
					data		: form.serialize(true),
					type		: 'post',
					timeout		: _MAX_TIMEOUT_AJAX_,
					dataType	: "json",
					cache		: false,
					beforeSend	: function() {
						$("#erroComentario").html("");
					},
					success: function(data) {
						if (typeof data == "object"){
							var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
							var nl	= "<br>";
							var msg = "";
							
							if($("#author").val() == "")
								msg += "* Seu nome" + nl;
							
							
							if($("#email").val() == '') 	
								msg	+= "* É necessário informar seu E-mail" + nl;
							else 	
								if(!er.test($("#email").val())) 
									msg += "* Informe um e-mail válido" + nl;
							
							if($("#comment").val() == '')
								msg += "* Sua mensagem" + nl;
							
							if(data.check == 'FALSE')
								msg += "* O código verificador corretamente" + nl;
							
							
							
							
							if(msg != ""){
								$("#erroComentario").html(msg);
								$("#erro_view").css( "display", "block"  );  
							}else{
								$("#erro_view").css( "display", "none"  );  
								form.submit();
							}
						}
						return false;
					},
					error: function() {
						return false;
					}
				});
			return false;
		},
		ComentarioProduto: function(form)  {
			
			form = $(form);
			$.ajax({
					url			: _HTTP_PATH_ + "securimage/process_comment.php",
					data		: form.serialize(true),
					type		: 'post',
					timeout		: _MAX_TIMEOUT_AJAX_,
					dataType	: "json",
					cache		: false,
					beforeSend	: function() {
						$("#erroComentario").html("");
					},
					success: function(data) {
						if (typeof data == "object"){
							var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
							var nl	= "<br>";
							var msg = "";
							
							if($("#seuNome").val() == "" || $("#seuNome").val() == "Seu nome")
								msg += "* Seu nome" + nl;
							
							if($("#seuEmail").val() == '' || $("#seuEmail").val() == "Seu E-mail") 	
								msg	+= "* &Eacute; necess&aacute;rio informar seu E-mail" + nl;
							else 	
								if(!er.test($("#seuEmail").val())) 
									msg += "* Informe um e-mail v&aacute;lido" + nl;
							
							if($("#seuTelefone").val() == "" || $("#seuTelefone").val() == "Seu Telefone")
								msg += "* Seu telefone" + nl;
							
							if($("#comentario").val() == '')
								msg += "* Sua mensagem" + nl;
							
							if(data.check == 'FALSE')
								msg += "* O c&oacute;digo verificador corretamente" + nl;
							
							
							
							
							if(msg != ""){
								$("#erroComentario").html(msg);
								$("#erro_view").css( "display", "block"  );  
							}else{
								$("#erro_view").css( "display", "none"  );  
								form.submit();
							}
						}
						return false;
					},
					error: function() {
						return false;
					}
				});
			return false;
		}
};

$(document).ready(function(){
	var gambi = 0;	//para correção de codificacao para firula
	//FIRULAS FORM
	$("#seuNome").click(function() {
		if($(this).val() == "Seu nome")
			$(this).val("");
	});
	
	$("#seuEmail").click(function() {
		if($(this).val() == "Seu E-mail")
			$(this).val("");
	});
	
	$("#seuTelefone").click(function() {
		if($(this).val() == "Seu Telefone")
			$(this).val("");
	});
	
	$("#captcha_code").click(function() {
		if(gambi == 0){
			$(this).val("");
			gambi = 1;
		}
	});
	
	
	
});
