var xmlHttp;

function $ (id){
	return document.getElementById(id);
}

function getXMLHttpRequest(){
	var xmlHttp;
	if (window.XMLHttpRequest) { //兼容Mozilla、Safari等浏览器对象
		xmlHttp = new XMLHttpRequest();
	}

	else if (window.ActiveXObject) { //兼容IE浏览器
	   try {
		   xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); //创建Msxml2.XMLHTTP控件对象
	   } catch (e) {
		   try {//创建Microsoft.XMLHTTP控件对象，该控件作用为获取指定URL的内容
			   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		   } catch (e) {}
	   }
	}
	return xmlHttp;

}

function getDateStr(dt,flag){
	var str = dt.getFullYear()+"/"+(dt.getMonth()+1)+"/"+dt.getDate()+(flag?"%20":" ")+dt.getHours()+":"+(dt.getMinutes()<10?"0"+dt.getMinutes():dt.getMinutes())+":"+(dt.getSeconds()<10?"0"+dt.getSeconds():dt.getSeconds());
	return str;
}

function sendRequest(url){	
	if(url.indexOf('timestamp')<0){
		url += url.indexOf('?')>0?'&':'?';
		url+="timestamp="+getDateStr(new Date());
	}
	if(!xmlHttp)
		xmlHttp = getXMLHttpRequest();
	xmlHttp.open('GET',url,true);
	xmlHttp.onreadystatechange = handleRequest;	
	xmlHttp.send(null);
}

function handleRequest(){        
	if(xmlHttp.readyState == 4){
		if (xmlHttp.status == 200 ){
			var response = xmlHttp.responseText;
			$('DIG_showRecord_recordTableDiv').style.display = "";
			$('DIG_showRecord_loading').style.display = "none";
			listRecord(response);
		}
	}
}

function listRecord(response){	
	var splitPos = response.indexOf(';');
	var params = response.substring(0,splitPos).split(',');
	var maxHeight = Number(params[2]);
	var minHeight = Number(params[1]);
	var totalRecord = Number(params[0]);
	
	response = response.substring(splitPos+1,response.length);		   
	var inHtml = "<table width='100%' id='DIG_showRecord_table' class='DIG_showRecord'><tbody>";
	
	inHtml += response;
	inHtml += "</tbody></table>";
	$('DIG_showRecord_recordTableDiv').innerHTML = inHtml;
	
	var div = $('DIG_showRecord_recordTableDiv');
	var table = $('DIG_showRecord_table').getElementsByTagName('tbody')[0];
	
	while(div.offsetHeight<minHeight || div.offsetHeight>maxHeight){
		if(minHeight!= -1 && div.offsetHeight<=minHeight){
			div.style.height = minHeight+"px";
			break;
		}
		if(div.offsetHeight>maxHeight){
			table.removeChild($('DIG_showRecord_row'+(--totalRecord)));
		}
	}
}

function DIG_FUNC_showRecord_init(path){
	if(!path)
		path = "";
	if(path.indexOf('/')<0){
		path += "/";
	}
		
	document.write("<link rel='stylesheet' type='text/css' href='"+path+"config/showRecord.css' />");
	document.write("<div id='DIG_showRecord_loading' class='DIG_showRecord_loading' style='display:none'>loading...</div><div id='DIG_showRecord_recordTableDiv' style='width:100%;word-wrap:break-all;overflow:hidden;'></div>");
	var url = path+"showRecord.asp";
	$('DIG_showRecord_recordTableDiv').style.display = "none";
	$('DIG_showRecord_loading').style.display = "";
	sendRequest(url);
}
