﻿/*
''' 
IP Zhi Dao
Powered by Google App Engine
http://www.baibudu.com/
'''
*/
String.prototype.trim　= function() {
	var t = this.replace(/(^\s*)|(\s*$)/g, "");
	return t.replace(/(^　*)|(　*$)/g, "");
};
window.onload=function() {
	submit = document.getElementById("sbtn");
	submit.onclick=function() {
		keys = document.getElementById("keyw").value;
		keys = keys.trim();
		if(checkIP(keys)) {
		window.location.href +='ip/'+ keys;
		}
		else alert('--------------------------\nIP 格式或信息错误！\n--------------------------\n\n');
	};
	function checkIP(ip) {
		var pattern=/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
		flag_ip = pattern.test(ip)
		if(flag_ip) {return true;}
		else {return false;}
		
	}
};