/** 
 * AJAX Communications Lib
 * Originally for Kassi-blog
 * by Lauri Kainulainen <lauriATsokkeloDOTnet>
 */


function _getXMLHttp() {
	var xmlHttp
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest()
    } catch (e) {
        // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")
        } catch (e) {
            try {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
            } catch (e) {
                alert("Your browser does not support AJAX!")
                return false
            }
        }
    }
    return xmlHttp
}


function ajaxCall( address, callback )	{
	var xmlHttp = _getXMLHttp()
  	xmlHttp.open('GET', address, true)
  	xmlHttp.send(null)
  		
  	xmlHttp.onreadystatechange = function() {
  			if( xmlHttp.readyState == 4 ) {
  				callback( xmlHttp.responseText )
  			}
  		}
}



function ajaxPostCall( address, params, callback )  {
    var xmlHttp = _getXMLHttp()
    xmlHttp.open('POST', address, true)
    
    //Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.send(params)
	
    xmlHttp.onreadystatechange = function() {
            if( xmlHttp.readyState == 4 ) {
                callback( xmlHttp.responseText )
            }
        }
}
