var http = fpv_createRequestObject();



function fpv_createRequestObject() {

    var req;

    if (window.XMLHttpRequest){

        // Firefox, Safari, Opera...

        req = new XMLHttpRequest();

    }

    else if (window.ActiveXObject) {

        // Internet Explorer 5+

        req = new ActiveXObject("Microsoft.XMLHTTP");

    }

    else {

        alert('Problem creating the XMLHttpRequest object');

    }

    return req;

} 



function fpv_LoadComments(page,theobject) {

    commentsCurrentPage = page ? page : 1;

    var myDate = new Date();

    myurl = 'fancomments/loadcomments.php?page='+commentsCurrentPage+'&refresh='+String(myDate.getTime())+'&theid='+theobject;
	//alert(myurl);
    http.open('get', myurl);

    http.onreadystatechange = fpv_LoadComments_callback;

    http.send(null);

}



function fpv_LoadComments_callback() {

    if (http.readyState == 4 && http.status == 200) {

        var response = http.responseText;

		//do not display not found if no file exists

		if (response.indexOf("<h1>Not Found</h1>") != -1) {

			response = '';

		} 

        if (response) {

            document.getElementById('sg1_comments').innerHTML = response;

        }

        else {

            document.getElementById('sg1_comments').innerHTML = "No Comments";

        }

        // get number of pages out of HTML comment <!--cNM(5)-->

		var regexpCP = /<!--cNM\((\d+)\)-->/;

		var aryMatches = regexpCP.exec(response);

		if (!aryMatches) {

			// not found...

		}

		else {

			if (!isNaN(aryMatches[1])) {

				commentsNumPages = parseInt(aryMatches[1]);

			}

		}

		

		fpv_BuildCommentPaging(commentsNumPages, commentsCurrentPage);

    }

}



