﻿/**
 * @author Nhiep Phong
 */
 
 var show_input_warning = true;
 var TYPING_WARNING = "Hãy cùng Nescafe giữ gìn sự trong sáng của tiếng Việt bằng cách gõ tiếng Việt có dấu, bạn nhé!";
 var validate;
$(document).ready(function(){
	validate = true;
	$('#GoAdvance').click(function() {
		validate = false;
    });
	
	// From binh luan o phia duoi trong trang chi tiet
    $('#chitietAddForm').submit(function(){
				if(show_input_warning || $.trim($('#PostContent').val()) == ""){
					message = "<div>Nội dung reply Của bạn chưa có!</div>";
					$('#dialog p').html(message)
					$('#dialog').dialog('open');
					return false;
				}
				return true;
			}
	);
	
	
	// From binh luan o trong video_module
	/*$('#video_moduleAddForm').submit(function(){
				if($.trim($('#PostContent').val()) == "Vui lòng bình luận bằng tiếng việt có dấu." || $.trim($('#PostContent').val()) == ""){
					message = "<div>Nội dung reply Của bạn chưa có!</div>";
					$('#dialog p').html(message)
					$('#dialog').dialog('open');
					return false;
				}
				return true;
			}
	);*/
	
	// From tao chu de moi
	$('#PostContent').click(function(){
		$('#PostContent').removeClass('color1');
        $('#PostContent').addClass('color2');
		if(show_input_warning){
            $('#PostContent').val('');
		}
		show_input_warning = false;
	});
	$('#PostContent').blur(function(){
		if($.trim($('#PostContent').val())==''){
            $('#PostContent').val(TYPING_WARNING);
            $('#PostContent').removeClass('color2');
            $('#PostContent').addClass('color1');
			show_input_warning = true;
		}
	});
	$('#vietbaiAddForm').submit(function(){
				if(validate && ($.trim($('#PostTitle').val()) == "Tiêu đề" || $.trim($('#PostTitle').val()) == "")){
					message = "<div>Tiêu đề Của bạn chưa có!</div>";
					$('#dialog p').html(message)
					$('#dialog').dialog('open');
					return false;
				}
				if(validate && (show_input_warning || $.trim($('#PostContent').val()) == "")){
					message = "<div>Nội dung Của bạn chưa có!</div>";
					$('#dialog p').html(message)
					$('#dialog').dialog('open');
					return false;
				}
				return true;
			}
	);
	
	// From tim kiem
	$('#SearchForm').submit(function(){
				if($.trim($('#keyword').val()) == "Từ khóa ..." || $.trim($('#keyword').val()) == ""){
					message = "<div>Bạn chưa nhập từ khóa !</div>";
					$('#dialog p').html(message)
					$('#dialog').dialog('open');
					return false;
				}
				return true;
			}
	);
	
	// From gui ban be
	$('#UserAddForm').submit(function(){
				if($.trim($('#name').val()) == "Name" || $.trim($('#name').val()) == ""){
					message = "<div>Bạn chưa nhập tên !</div>";
					$('#dialog p').html(message)
					$('#dialog').dialog('open');
					return false;
				}
				if($.trim($('#email').val()) == "Địa chỉ email người nhận" || $.trim($('#email').val()) == ""){
					message = "<div>Bạn chưa nhập địa chỉ email người nhận !</div>";
					$('#dialog p').html(message)
					$('#dialog').dialog('open');
					return false;
				}
				if($.trim($('#data').val()) == "Thông điệp" || $.trim($('#data').val()) == ""){
					message = "<div>Bạn chưa nhập Thông điệp !</div>";
					$('#dialog p').html(message)
					$('#dialog').dialog('open');
					return false;
				}
				
				return true;
			}
	);

});
