var http = createRequestObject();
function createRequestObject(){
    var request_;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        request_ = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        request_ = new XMLHttpRequest();
    }
    return request_;
}
function getComments(mod,id,page){
	var randomValue = Math.random(); 
    http.open('get', '/comments.php?mod='+mod+'&id='+id+'&page='+page+"&rand="+randomValue);
    http.onreadystatechange = handleComments;
    http.send(null);
}

function postInfo(){//alert('Hello');
var commentValue = "title="+document.getElementById('title').value;
    commentValue +="&name="+document.getElementById('name').value;
	commentValue +="&cid="+document.getElementById('cid').value;
	commentValue +="&mod="+document.getElementById('mod').value;
	commentValue +="&country="+document.getElementById('country').value;
	commentValue +="&comment="+document.getElementById('comment').value;
	commentValue +="&captcha="+document.getElementById('captcha').value;
http.open('post', '/addComment.php',true);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.setRequestHeader('Content-type','text/html; charset=windows-1256');
http.onreadystatechange = handleInfo;
http.send(commentValue);
}

function handleInfo(){
    if(http.readyState == 1){
        document.getElementById('commentDiv').innerHTML = '<img src="/images/loadingicon.gif">';
    }
    if(http.readyState == 4){
        var response = http.responseText;
        document.getElementById('commentDiv').innerHTML = response;
    }
}

function handleComments(){
    if(http.readyState == 1){
        document.getElementById('showComments').innerHTML = '<img src="/images/loadingicon.gif">';
    }
    if(http.readyState == 4){
        var response = http.responseText;
        document.getElementById('showComments').innerHTML = response;
    }
}
