﻿// JScript 文件
//搜索
$(function() {
		var name = $("#name"),
			content = $("#content"),
			allFields = $([]).add(name).add(content),
			tips = $("#validateTips");

		function updateTips(t) {
			tips.text(t).effect("highlight",{},1500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("" + n + " 的长度必须在 "+min+" 和 "+max+"之间.");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}
		
		$("#dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			height: 400,
			modal: true,
			buttons: {
				'发表': function() {
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(content,"发表内容",5,500);
					
					if (bValid) {
					    tfdenglu(name.val(),content.val());
					}
				},
				'返回': function() {
					$(this).dialog('close');
				},
				'查看点评': function() {
					window.open('/baodingfangchanxiaoqu-'+name.val()+'.qm');
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		gettfshop(1);
	});
function tfdenglu(name,content)
{
$.getJSON("msg.aspx?w"+Math.random()+"="+Math.random(),
            {op:"addmsg",name:name,content:escape(content)}, 
          function(json)
          {
           if(json==1)
           {
              alert("发表成功。");
              $('#dialog').dialog('close');
           }
           else
           {    
              alert("禁止连续发言。");
           }
        })
}