//取得网站根目录
function getrootpath(){ 
	var fullpath = window.document.location.href; 
	var pathname = window.document.location.pathname;
	var pos = fullpath.indexOf(pathname); 
	var prepath = fullpath.substring(0, pos); 
	var postpath = pathname.substring(0, pathname.substr(1).indexOf('/') + 1); 
	return(prepath + postpath);
}

//搜索伪静态
function chksearch(){
	var type = $("#type").val();
	var query = $.trim($("#query").val());
	if (type == null) {type = "tags"}
	if (query == "") {
		alert("\u8bf7\u8f93\u5165\u641c\u7d22\u5173\u952e\u5b57\uff01");
		$("#query").focus();
		return false;
	} else {
		window.location.href = getrootpath() + "/search/" + type + "/" + encodeURI(query) + ".html";
	}
	return false;
}

//搜索
$(document).ready(
	function(){
		$("#options").find("a").each(
			function(){
				$(this).click(
					function(){
						$("#cursel").text(this.innerHTML);
						$("#options").toggle();
						$("#type").attr("value", $(this).attr("name"));
						$("#query").css({"background": "#FFFFFF"});
					}
				)
				
			}
		)
		
		$("#cursel").mouseover(
			function(){
				$("#options").toggle().find("a").each(
					function(){
						$(this).parent().attr("className", $(this).text() == $("#cursel").text() ? "current" : "");
					}
				)
			}
		)
	}
)

//刷新验证码
function refreshimg(obj) {
	var randnum = Math.random();
	$("#" + obj).html('<img src="' + getrootpath() + '/source/include/captcha.php?s=' + randnum + '" align="absmiddle" alt="看不清楚?换一张" onclick="this.src+='+ randnum +'" style="cursor: pointer;">');
}

//验证url
function checkurl(url){
	if (url == '') {
		$("#msg").html('请输入网站域名！');
		return false;
	}
	
	$(document).ready(function(){$("#msg").html('<img src="' + getrootpath() + '/public/images/loading.gif" align="absmiddle"> 正在验证，请稍候...'); $.ajax({type: "GET", url: getrootpath() + '/?mod=ajaxget&type=check', data: 'url=' + url, cache: false, success: function(data){$("#msg").html(data)}});});
return true;
};

//获取META
function getmeta(url) {
	if (url == '') {
		$("#msg").html('请输入网站域名！');
		return false;
	}
	$(document).ready(function(){$("#msg").html('<img src="' + getrootpath() + '/public/images/loading.gif" align="absmiddle"> 正在抓取，请稍候...'); $.ajax({type: "GET", url: getrootpath() + '/?mod=ajaxget&type=crawl', data: 'url=' + url, datatype: "script", cache: false, success: function(data){$("#msg").html(data)}});});
}

//点出统计
function clickout(wid) {
	$(document).ready(function(){$.ajax({type: "GET", url: "./common/outstat.php", data: "web_id=" + wid, cache: false, success: function(data){}});});
};

//错误报告
function report(obj, wid) {
	$(document).ready(function(){if (confirm("确认报告此错误吗？")){ $("#" + obj).html("正在提交，请稍候..."); $.ajax({type: "GET", url: "./common/report.php", data: "web_id=" + wid, cache: false, success: function(data){$("#" + obj).html(data);}})};});
};
