/*
	author:	Chip Kreis
	date:	3.2.07
*/

//=====================================================================================================================

    function createXmlHttpRequest()
    {
	    var p_xmlHttp;
	    if ( window.ActiveXObject ) 
	    {
		    p_xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
	    }	
	    else if ( window.XMLHttpRequest ) 
	    {
		    p_xmlHttp = new XMLHttpRequest();
	    }
	    return p_xmlHttp;
    }


//=====================================================================================================================

    function doXmlHttpPost( inRESTPage, inVals, inDiv, inDiv2, inSuccessMsg )
    {
	    var prvXmlHttpObject = new createXmlHttpRequest();
    	
	    prvXmlHttpObject.open( "POST", inRESTPage, true );
    	
	    prvXmlHttpObject.onreadystatechange = function()
	    {
		    handleXmlHttpPostStateChange( prvXmlHttpObject, inDiv, inDiv2, inSuccessMsg );
	    }
    	
	    prvXmlHttpObject.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded;" );
	    prvXmlHttpObject.send( inVals );
    }


//=====================================================================================================================

    function handleXmlHttpPostStateChange( inXmlHttpObject, inDiv, inDiv2, inSuccessMsg )
    {
	    if ( inXmlHttpObject.readyState == 4 ) 
	    {
		    if ( inXmlHttpObject.status == 200 ) 
		    {
			    if ( inXmlHttpObject.responseText != "" )
			    {
				    document.getElementById(inDiv).innerHTML = inXmlHttpObject.responseText;
			    }
			    if ( (inDiv2 != "") && (inSuccessMsg != "") )
			    {
					if (inSuccessMsg == inXmlHttpObject.responseText)
					{
						document.getElementById(inDiv2).style.display = "none";	
					}
				}	
		    }
	    }
    }


//== SAMPLE TO INITIATE AJAX CALL =====================================================================================

		/*function getComments( RESTPage, contentId, theDiv, baseURL )
		{
			var thisVals = "";
			var outContentId = "contentId=" + contentId;
			var completeURL = baseURL + RESTPage;
			
			thisVals = outContentId;
			
			doXmlHttpPost( completeURL, thisVals, theDiv );
		}*/