﻿$(document).ready(function(){
	var lock_comment_submit = false; 
	$('.comment_post_form').submit(function(){
		if(lock_comment_submit) return false;
		lock_comment_submit=true;
		var url = $(this).attr('action');
		var data= $(this).serialize();	
		$.getJSON(url,data,function callback(json){				
			if(json.is_saved){
				$("#content .comment_post .submit_btn").hide();
				$("#content .comment_post .validation_msg").slideDown(400);
			} else {
				if(json.error_pseudo) {
					$("#content .comment_post .err b").html(json.error_pseudo);
					$("#content .comment_post .err .err_alert").show(200);	
					$('.comment_post_form #pseudo').css({'background-color':'#EFE1B3'});					
				}
				if(json.error_comment) {
					$('.comment_post_form #comment').css({'background-color':'#EFE1B3'});					
				}
				lock_comment_submit = false;
			}						
		});
		return false;
	});
	$('.comment_post_form #pseudo').focus(function(){		
		$("#content .comment_post .err .err_alert").hide(110,function(){
			$("#content .comment_post .err b").html('');														 
		});		
		$('.comment_post_form #pseudo').css({'background-color':'#fff'});
	});
	
	$('.comment_post_form #comment').focus(function(){		
		$('.comment_post_form #comment').css({'background-color':'#fff'});
	});
	$(".comment_post .product_connect_form input:submit").button();
	var lock_coonect_submit = false; 
	$('.comment_post .product_connect_form').submit(function(){
		if(lock_coonect_submit) return false;
		lock_coonect_submit=true;
		var url = $(this).attr('action');
		var data= $(this).serialize();
		$.getJSON(url,data,function callback(json){				
			if(json.is_connected){
				var url=$('.comment_post .product_connect_form').attr('call_back');
				$(location).attr('href',url) ;					
			} else {
				$(".comment_post .member_form #member_err_msg").html(json.error);
				$(".comment_post .member_form #member_err_msg").slideDown(200);				
				lock_coonect_submit = false; 
			}									 
		});
		return false;
	});	
	$('.comment_post .member_form input:not(.submit_btn)').focus(function(){
		$(this).css('opacity','1');												  
	});
	$('.comment_post .member_form input:not(.submit_btn)').blur(function(){
		$(this).css('opacity','0.6');												  
	});
	$('body').click(function() {
	 	$(".comment_post .member_form #member_err_msg").slideUp(300);
	 });
	
	 $(".comment_post .member_form #member_err_msg").click(function(e){
		 e.stopPropagation();
	 });
});

