$(function(){
	"use strict";
	var lastPos = 0;
	var index = 1;
	var isTotalLoaded = false; 		//  does all records loaded

	//$(window).swipeUp(scrollRefresh);
	$(window).bind("scroll", scrollRefresh);

	function scrollRefresh(){
		if(isTotalLoaded) { return false;}
		if ($(document).height() <= $(window).scrollTop() + $(window).height()){
			// 这里开始请求刷新
			var refresh = $("#refresh");
			refresh.show();
			if(1 == (++index)) return false;
			var url = "";
			
			if($("#topnext").val()=="get"){
				
				url = "viewDtlist.htm?type=get";
			}else{
				url = "viewDtlist.htm";
			}
			
			var page = index;
			
			if (url.indexOf("?") != -1) {
				url += "&pageNumber=" + page;
			} else {
				url += "?pageNumber=" + page;
			}
			
			
			$.ajax( {
				type : 'POST',
				url : url,
				contentType : "application/html; charset=utf-8",
				dataType : "html",
				cache : false,
				success : function(data) {
					var html = $.trim(data.split("||||")[0]);
					$("#topnext").val($.trim(data.split("||||")[1]));
					
					if("" == html){
						isTotalLoaded = true;
						--index;
						
						
					}
					
					
					
					else{
						console.log(html);
						$("#user-records").append(html);
					}
					refresh.css("display", "none");
					
				},
				error : function(xhr, statusText, err) {
					alert(decodeURI(xhr.statusText));
				}
			});
		}
	}
});
