function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
if (strURL == "grand.php") {
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
	            updatepage(self.xmlHttpReq.responseText);
        }
    }
} else  {
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
	            updatelink(self.xmlHttpReq.responseText);
        }
    }
}
    self.xmlHttpReq.send(null);
}

function updatelink(str) {
	var title="隨機推薦連結";
	var urlpath="http://hotpot.hk/story.php?id=";
	var link = new Array;
	var html="";

	link = str.split("\t");
	document.getElementById("randlink").innerHTML="";
	html+="<br /><small>"+title+"<br />"
	html+="<ol>";
	for (i = 0; i < link.length ; i+=2) {
		if (link[i].length > 0) {
			html+="<li><a href='"+urlpath+link[i+1]+"' />"+link[i]+"</a><br/></li>";
		}
	}
	html+="</ol></small>"
	document.getElementById("randlink").innerHTML=html;
}

function updatepage(str){
	var imgpath="http://hotpot.hk/download/images/";
	var urlpath="http://hotpot.hk/story.php?id=";
	var link = new Array;
	link = str.split("|");
	document.getElementById("result").innerHTML="";
	for (i = 0; i < link.length ; i+=2) {
		if (link[i].length > 0) {
		document.getElementById("result").innerHTML+="<a href='"+urlpath+link[i+1]+"' />"+"<img border='1' src='"+imgpath+link[i]+"' /></a>";
		document.getElementById("result").innerHTML+="&nbsp;&nbsp;&nbsp;";
		}
	}

	xmlhttpPost("grandlink.php");
}
