$(document).ready
(
 function()
 {
	 /*求出类型，价格区间切换*/
	 $('#info_type_sel').change
	 (
		function()
		{
			var val = $(this).val();
			if (val == 0)
			{
				$('#so_price_sel_span').html(price_bound);
			}
			else
			{
				if (val % 2 == 0)
				{
					$('#so_price_sel_span').html(price_bound2);
				}
				else
				{
					$('#so_price_sel_span').html(price_bound1);
				}
			}
		}
	 );
	 /*搜索框区域，商圈联动*/
	 $('#region_sel1').change
	 (
		function()
		{
			var val = $(this).val();
			if (val > 0)
			{
				$.getScript('api/region_bind.asp?sel=region_sel2&id='+ val +'&is_ajax=1&ts='+ Math.random());
			}
			else
			{
				removeOptions('region_sel2', 1);
			}
		}
	 );
	 /*信息发布联动*/
	 $('#region_sel11').change
	 (
		function()
		{
			var val = $(this).val();
			if (val > 0)
			{
				$.getScript('api/region_bind.asp?sel=region_sel22&id='+ val +'&is_ajax=1&ts='+ Math.random());
			}
			else
			{
				removeOptions('region_sel22', 1);
			}
		}
	 );
	 /*信息详情页留言表表*/
	 $('#msg_form').submit
	 (
		function()
		{
			var opt = 
			{
				dataType : 'json',
				beforeSubmit : function()
				{
					if ($('input[name=m_title]', this).val() == ''){window.alert('请输入标题内容！');return false;}
					if ($('input[name=m_name]', this).val() == ''){window.alert('请输入您的姓名！');return false;}
					if ($('input[name=m_tel]', this).val() == ''){window.alert('请输入您的联系电话！');return false;}
					if ($('input[name=m_mail]', this).val() == ''){window.alert('请输入您的邮箱！');return false;}
					var reg = /^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|com|gov|mil|org|edu|int)$/;
					if (!reg.test($('input[name=m_mail]', this).val())){window.alert('请输入正确的EMAIL！');return false;}
					if ($('textarea[name=m_content]', this).val() == ''){window.alert('请输入留言内容！');return false;}
					if ($('textarea[name=m_content]', this).val().length > 255){window.alert('留言内容请控制在 255 个字符！');return false;}
					$('#msg_form').block('正在处理您的留言....');
				},
				success : function(sJSON)
				{
					$('#msg_form').unblock();
					if (sJSON.error == 0)
					{
						window.alert('您的留言已成功提交，如果合适，我们的工作人员会联系您！');
						$('#msg_form').resetForm();
					}
					else
					{
						window.alert(sJSON.message);
					}
				}
			};
			$(this).ajaxSubmit(opt);
			return false;
		}
	 );
	 /*ul列表奇偶行变色*/
	 $('ul.tbody').each
	 (
		 function(i)
		 {
			 $(this).css({background: (i % 2 == 0) ? '#ffffff' : '#f5f5f5'});
		 }
	 );
	 /*网站登陆*/
	 $('#login_form').submit
	 (
		 function()
		 {
			 var opt = 
			 {
				 dataType : 'json', 
				 beforeSubmit : function()
				 {
					 if ($('input[name=uid]', this).val() == ''){window.alert('请输入登陆用户名！');return false;}
					 if ($('input[name=pwd]', this).val() == ''){window.alert('请输入登陆密码！');return false;}
					 $('#login_form').block('正在登陆系统...');
				 },
				 success : function(sJSON)
				 {
					 $('#login_form').unblock();
					 if (sJSON.error == 0)
					 {
						 var html = '<div>欢迎您， '+ $('input[name=uid]', this).val() +'</div>';
						 html += '<div><a href="members.asp" class="public">进入会员中心</a></div>';
						 html += '<div><a href="members.asp?mod=logout" class="public">退出</a></div>';
						 $('#login_div').html(html);
						 $('login_form').resetForm();
					 }
					 else
					 {
						 window.alert(sJSON.message);
					 }
				 }
			 };
			 $(this).ajaxSubmit(opt);
			 return false;
		 }
	 );
	 /*申请链接*/
	 $('#fl_form').submit
	 (
		 function()
		 {
			 var opt = 
			 {
				 dataType : 'json',
				 beforeSubmit : function()
				 {
					 if ($('input[name=site_name]', this).val() == ''){window.alert('请输入您的网站名称！');return false;}
					 if ($('input[name=site_url]', this).val() == ''){window.alert('请输入您的网址！');return false;}
					 $('fl_form_div').block('请稍候，正在执行请求....');
				 },
				 success : function(sJSON)
				 {
					 if (sJSON.error == 0)
					 {
						 window.alert('谢谢，您的请求已成功发送！');
						 $('#fl_form_div').hide('normal');
						 $('#fl_form').resetForm();
					 }
					 else
					 {
						 window.alert(sJSON.message);
					 }
					 $('fl_form_div').unblock();
				 }
			 };
			 $(this).ajaxSubmit(opt);
			 return false;
		 }
	 );
 }
);

/*
移出商圈下拉列表
sSelect : 下拉列表框ID
nOptions : 保留下拉列表项数 0
*/
function removeOptions(sSelect, nOptions)
{
	var sel = document.getElementById(sSelect);
	if (nOptions == null) nOptions = 0;
	if (nOptions == 0)
	{
		sel.options.length = 0;
	}
	else
	{
		var i = document.getElementById(sSelect).options.length - 1;
		for (i; i >= nOptions; i--)
		{
			sel.removeChild(sel.options[i]);
		}
	}
}

/*链接*/
function goto(url, target)
{
	if (target == null)
	{
		window.location.href = url;
	}
	else
	{
		window.open(url);
	}
}

/*显示信息详情页联系方式*/
function show_info()
{
  if ($('#link_info_div').css('display') == 'none')
	{
	  $('#link_info_div').parent().block('正在获取联系方式....');
		setTimeout("$('#link_info_div').show('normal');$('#link_info_div').parent().unblock();", 1500);
	}
}
