/**公共js**/
//ip验证
function checkIP(){
	var ip = $("#ipaddress").val();
	ip = ip.replace(/(^\s*)|(\s*$)/g,"");
 	var strRegex = "^((https|http|ftp|rtsp|mms)?://)" 
 	+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@
    + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
    + "|" // 允许IP和DOMAIN（域名）
    + "([0-9a-z_!~*'()-]+\.)*" // 域名- www. 
    + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 
    + "((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)|(io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(ir)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp)))" // first level domain- .com or .museum 
    + "(:[0-9]{1,4})?" // 端口- :80 
    + "((/?)|" // a slash isn't required if there is no file name 
    + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; 
    var re=new RegExp(strRegex); 
    if (re.test(ip)){
    	$("#ip_error").html('');
       	return true; 
    }else{
    	$("#ip_error").html('IP/域名有误，请检查是否有多余空格！');
    	$("#ipaddress").focus();
        return false; 
    }
}
//手机号码验证
function checkMobile(){
	var sMobile = $("#mobileaddress").val();
	var strRegex = /^1[3|4|5|8][0-9]\d{4,8}$/;
	var mobileaddress_num = document.getElementById("mobileaddress").value.length;
	if(!(strRegex.test(sMobile))){
		if(mobileaddress_num<7){
			$("#error_mobile").html('手机号码还差'+(7-(document.getElementById("mobileaddress").value.length))+'位');
		}else if(mobileaddress_num<11){
			$("#error_mobile").html('');
		}else{
			$("#error_mobile").html('手机号码输入有误，请检查是否以13、14、15、18开头的手机号码！');
		}
		$("#mobileaddress").focus();
		return false;
	}
	$("#error_mobile").html('');
	return true;
}
//邮政编码验证
function checkZip(){
	var sZip = $("#postaladdress").val();
	var postaladdress_num = document.getElementById("postaladdress").value.length;
	if(!(/^(\d{6})+$/.test(sZip))){
		if(postaladdress_num<6){
			$('#error_postal').html('邮政编码还差'+(6-(document.getElementById("postaladdress").value.length))+'位');
		}else{
			$('#error_postal').html('邮政编码有误，请重新输入！');
		}
		$("#postaladdress").focus();
		return false;
	}
	$('#error_postal').html('');
	return true;
}
//地名验证
function checkArea2Zip(){
	var sArea = $("#areaAlddress").val();
	var sArea_num = document.getElementById("areaAlddress").value.length;
	if(sArea_num<2){
		$('#error_postal').html('地名不能少于两个汉字！');
		$("#areaAlddress").focus();
		return false;
	}
	$('#error_postal').html('');
	return true;
}
//电话区号验证
function checkTelephone(){
	var telephonenum =  $("#telephonenum").val();
	var strRegex = /^(\d{3,4})+$/;
	if(!(strRegex.test(telephonenum))){
		$('#error_telephone').html('区号要有3-4个数字');
		$("#telephonenum").focus();
		return false;
	}
	$('#error_telephone').html('');
	return true;
}
//地名查区号验证
function checkTa(){
	var Ta = $("#Ta").val();
	var Ta_num = document.getElementById("Ta").value.length;
	if(Ta_num<2){
		$('#error_telephone').html('地名不能少于两个汉字！');
		$("#Ta").focus();
		return false;
	}
	$('#error_telephone').html('');
	return true;
}
//IP数据显示
function ip_post(){
	if(checkIP()){
		var ipaddress = $("#ipaddress").val();
		$("#main_result_mobile").css({display:"none"});
		$("#main_result_postal").css({display:"none"});
		$("#main_result_telephoneal").css({display:"none"});
		$.ajax({
			type: "post",
			cache:false,
			url: 'index.php',
			data: "do=ip&ipaddress="+ipaddress,
			timeout:10000,
			success: function(data){
				$("#main_result_ip").css({display:"block"});
				$("#ipaddress_value").html(data);
			},
			error: function(){
				$("#ip_error").html('服务器繁忙，请稍后再试！');
			}
		});
	}
}
//手机归属地数据显示
function mobile_post(){
	if (checkMobile()){
		var mobileaddress = $("#mobileaddress").val();
		$("#main_result_ip").css({display:"none"});
		$("#main_result_postal").css({display:"none"});
		$("#main_result_telephoneal").css({display:"none"});
		$.ajax({
			type: "post",
			cache:false,
			url: 'index.php',
			data: "do=mobile&mobileaddress="+mobileaddress,
			timeout:10000,
			success: function(data){
				$("#main_result_mobile").css({display:"block"});
				$("#mobile_value").html(data);
			},
			error: function(){
				$("#error").html('服务器繁忙，请稍后再试！');
			}
		});
	}
}
//邮政编码数据显示
function postal_post(){
	if(checkZip()){
		var postalddress = $("#postaladdress").val();
		$("#main_result_ip").css({display:"none"});
		$("#main_result_mobile").css({display:"none"});
		$("#main_result_telephoneal").css({display:"none"});
		$.ajax({
			type: "post",
			cache:false,
			url: 'index.php',
			data: "do=postal&postalddress="+postalddress,
			timeout:10000,
			success: function(data){
				$("#main_result_postal").css({display:"block"});
				$("#postal_value").html(data);
			},
			error: function(){
				$("#error_postal").html('服务器繁忙，请稍后再试！');
			}
		});
	}
}
//地名数据显示
function area_post(){
	if(checkArea2Zip()){
		var areaAlddress = $("#areaAlddress").val();
		$("#main_result_ip").css({display:"none"});
		$("#main_result_mobile").css({display:"none"});
		$("#main_result_telephoneal").css({display:"none"});
		$.ajax({
			type: "post",
			cache:false,
			url: 'index.php',
			data: "do=area&areaAlddress="+areaAlddress,
			timeout:10000,
			success: function(data){
				$("#main_result_postal").css({display:"block"});
				$("#postal_value").html(data);
			},
			error: function(){
				$("#error_postal").html('服务器繁忙，请稍后再试！');
			}
		});
	}
}
//区号数据显示
function telephoneal_post(){
	if(checkTelephone()){
		var telephonenum = $("#telephonenum").val();
		$("#main_result_ip").css({display:"none"});
		$("#main_result_mobile").css({display:"none"});
		$("#main_result_postal").css({display:"none"});
		$.ajax({
			type: "post",
			cache:false,
			url: 'index.php',
			data: "do=telephones&telephonenum="+telephonenum,
			timeout:10000,
			success: function(data){
				$("#main_result_telephoneal").css({display:"block"});
				$("#telephoneal_value").html(data);
			},
			error: function(){
				$("#error_telephone").html('服务器繁忙，请稍后再试！');
			}
		});
	}
}
//地名查区号数据显示
function telta_post(){
	if(checkTa()){
		var Ta = $("#Ta").val();
		$("#main_result_ip").css({display:"none"});
		$("#main_result_mobile").css({display:"none"});
		$("#main_result_postal").css({display:"none"});
		$.ajax({
			type: "post",
			cache:false,
			url: 'index.php',
			data: "do=teladdress&Ta="+Ta,
			timeout:10000,
			success: function(data){
				$("#main_result_telephoneal").css({display:"block"});
				$("#telephoneal_value").html(data);
			},
			error: function(){
				$("#error_telephone").html('服务器繁忙，请稍后再试！');
			}
		});
	}
}
//发送反馈意见
function put_comment(){
	var comment = $("#comment").val();
	if(comment==''){
		alert('内容不能为空！');
	}else{
		$.ajax({
			type: "post",
			cache:false,
			url: 'index.php',
			data: "do=put_comment&comment="+comment,
			timeout:10000,
			success: function(data){
				alert('非常感谢您所提出来的意见！我们会在第一时间内给予解决。');
			},
			error: function(){
				$("#error_telephone").html('服务器繁忙，请稍后再试！');
			}
		});
	}
}