var Request = { 
	QueryString: function (key) {
	var svalue = window.location.search.match(new RegExp("[\?\&]" + key + "=([^\&]*)(\&?)", "i"));
	return svalue ? svalue[1] : svalue;
	}
}


//回车事件
function EnterFunction(ElementInput, ElementBtn) {
	$(document).on("keydown",ElementInput,function(e){
		var curKey = e.which;
        if (curKey == 13) {
            $(ElementBtn).click();
        }	
	})
    /*$(ElementInput).keydown(function (e) {
        var curKey = e.which;
        if (curKey == 13) {
            $(ElementBtn).click();
        }
    });*/
}
$(function () {
    EnterFunction("#formd_search_id", "#btnSearch");
	EnterFunction("#formd_search_id1", "#btnSearch1");
    EnterFunction("#search-field", "#btnSearch");
    EnterFunction("#keywords", ".go_page");

})

/*-----------------------------搜索结果绑定-------------------------------------------------------------------------*/
$(function () {
    $(document).on("click","#btnSearch",function(){
		var searchtype=$(".year_select1").find("dt").data("val");
        search(searchtype);
    });
    function search(type) {
        if ($.trim($("#formd_search_id").val()) == '' || $.trim($("#formd_search_id").val()) == "search...") {
            $('#formd_search_id').focus();
            alert("请输入关键词！");
            return false;
        }
        else {
            window.location = "/other/search.html?key=" + encodeURIComponent($.trim($("#formd_search_id").val()))+"&type="+type;
        }
    }
})

$(function () {
    $(document).on("click","#btnSearch1",function(){
		var searchtype=$(".year_select1").find("dt").data("val");
        search1(searchtype);
    });
    function search1(type) {
        if ($.trim($("#formd_search_id1").val()) == '' || $.trim($("#formd_search_id1").val()) == "search...") {
            $('#formd_search_id1').focus();
            alert("请输入关键词！");
            return false;
        }
        else {
            window.location = "/other/search.html?key=" + encodeURIComponent($.trim($("#formd_search_id1").val()))+"&type="+type;
        }
    }
})



//危险字符过滤
$(function () {
    $(document).on('keyup', 'input[type=text],textarea,input[type=password]', function () {
        var val = $(this).val().toLocaleLowerCase();
        var otherKey = " and | exec | count | chr | mid | master | or | truncate | char | declare | join |<|>|/*|*/|;|\\u|insert|select|delete|update|create|drop|script|javascript|alert";
        var goon = true;
        for (var i = 0; i < otherKey.split('|').length ; i++) {
            if (goon) {
                if (val.indexOf(otherKey.split('|')[i]) != -1) {
                    alert("不能包含危险字符!");
                    $(this).val('');
                    goon = false;
                    return;
                }
            }
        }
    });
})

function checkSQL(tempKey) {
    var val = tempKey;
    var otherKey = " and | exec | count | chr | mid | master | or | truncate | char | declare | join |<|>|*|/*|*/|;|\\u|insert|select|delete|update|create|drop|script|javascript|alert";
    var goon = true;
    for (var i = 0; i < otherKey.split('|').length ; i++) {
        if (goon) {
            if (val.indexOf(otherKey.split('|')[i]) != -1) {                
                goon = false;
            }
        }
    }
    return goon;
}


var classid = '';
var key = '';

var ToPage = function (pageIndex,type) {
	if (!checkSQL(key)) {
		alert("请不要包含危险字符！");
		window.location.href="../index.html";
		return false;
	}
	var html_start=$("#html_start").val();
	var html_end=$("#html_end").val();
	var pageclass=$("#pageClass").val();
	var pagesize=$("#pagesize").val();
	var updatetime=$("#updatetime").val();
	var listhtml=$("#listhtml").val();
	var pagehtml=$("#pagehtml").val();
    $.ajax({
        type: "post",
        url: "../index.php?a=qwsearch",
        data: {
            pageindex: pageIndex,
            pagesize: pagesize,
            key: key,
			html_start: html_start,
			html_end: html_end,
			pageclass: pageclass,
			updatetime: updatetime,
			listhtml: listhtml,
			pagehtml: pagehtml,
			type: type
        },
        success: function (msg) {
            var obj = eval('(' + msg + ')');
            $('#AjaxList').html(obj.ListHtml.toString());
            $('#AjaxPageList').html(obj.PageHtml.toString());
            $('#searchNum').html(obj.RecordCount);
            $('#formd_search_id').val(key);
            $('#searchText').html('"'+key+'"');
			$('#formd_search_id1').val(key);
        }
    })
}


/*-----------------------------利用cookie保存浏览记录-------------------------------*/
function SetMyCollect(id,url,photo){
	$.ajax({
        type: "post",
        url: "../index.php?a=history",
        data: {
            id: id,
            url: url,
            photo: photo
        },
        success: function (msg) {
            
        }
    })	
}
/*-----------------------------获取浏览记录-------------------------------*/
function getMyCollect() {
    $.ajax({
        type: "post",
        url: "../index.php?a=gethistory",
        data:"",
        success: function (msg) {
            var obj = eval('(' + msg + ')');
            $('#GetMyCollect').html(obj.ListHtml);
            
        }
    })	
}

/*----------------------当前位置定位-------------------*/
$(function () {
    var MenuName = $.trim($("div.site> a:eq(1)").text());
    $('div.warper>ul>li>a').map(function () {
        if ($.trim($(this).text()) == MenuName) {
            $(this).parent().addClass('on').siblings().removeClass('on');
        }
    });

    MenuName = $.trim($("div.site> span").text());

    $('div.warper>ul>li>a').map(function () {
        if ($.trim($(this).text()) == MenuName) {
            $(this).parent().addClass('on').siblings().removeClass('on');
        }
    });
    

})


/*----------------------点击下载及时更新下载次数-------------------*/
$(document).on('click', '.Mylike', function () {
    var strid = $(this).attr("data-id");//ID
    var strurl =$(this).attr("data-url");
    var stremid = $(this).parents('.AForm').find('.Mylikelist');
    var objMylike = $(this);
    data = "id=" + strid;
	$.ajax({
        type: "post",
        url: "../index.php?a=downloadnum",
        data:data,
        success: function (msg) {
            var obj = eval('(' + msg + ')');
			if(obj.status==1){
            stremid.text(Number(stremid.text()) + Number(1));
            window.location = "" + strurl;
			}
        }
    })
});

/*----------------------获取下载次数-------------------*/
$(function () {
    var ids = '';
    $('.Mylikelist').map(function () {
        ids += $(this).attr('data-id') + ',';
    });
    if (ids.length == 0) {
        return;
    }
    data="ids="+ids;
	$.ajax({
        type: "post",
        url: "../index.php?a=getdownloadnum",
        data:data,
        success: function (msg) {
            var obj = eval('(' + msg + ')');
			var hits=(obj.info);
			for (var i = 0; i < hits.split(',').length; i++) {
	            $('.Mylikelist').eq(i).text(hits.split(',')[i]);
	        }
        }
    })
});

function getAajaxInclude(dataUrl,element) {
	
	$.ajax({
		"type": "get",
		"url": "" + dataUrl+"",
		"datatype": "html",
		"success": function (msg) {
			$(element).html(msg);
			if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
                var wow = new WOW({
                    boxClass: 'wow',   //需要执行动画的元素的 class
                    animateClass: 'animated',   //animation.css 动画的 class
                    offset: 100,  //距离可视区域多少开始执行动画
                    mobile: false,  //是否在移动设备上执行动画
                    live: true   //异步加载的内容是否有效
                });
                wow.init();
            };
		},
		"error": function (e) {
			
		}
	})
}


function getyuqing(pageindex){
	data="pageindex="+pageindex;
	$.ajax({
        type: "post",
        url: "../index.php?a=getyuqingdata",
        data:data,
        success: function (msg) {
            var obj = eval('(' + msg + ')');
			$('#yuqing_list').html(obj.ListHtml);
            $('#yuqing_page').html(obj.PageHtml);
        }
    })	
}










	
