	//////////////////////////////////////////////////////////////////
	// Ajax Integration 2.0 					//
	//////////////////////////////////////////////////////////////////
        // Written by Kris Wilkinson					//
	// Owned & Copyright by SIRKit Ltd. 				//
        // Duplication, copying & distribution is strictly prohibited	//
	//////////////////////////////////////////////////////////////////

        var xmlHttp, sourceID, destinationID, responseType;

        function createXMLHttpRequest() {

                if (window.ActiveXObject) {
                        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

                }
                else if (window.XMLHttpRequest) {
                        xmlHttp = new XMLHttpRequest();

                }

        }

        function createQueryString() {

                var sourceDiv = document.getElementById(sourceID);
                var queryString = '';

                if ( sourceDiv.hasChildNodes() ) {

                        var divFields = sourceDiv.childNodes;
                        for (var i=0; i<divFields.length;i++) {

                                if (divFields[i].name && divFields[i].value) {
                                        queryString = queryString + encodeURIComponent(divFields[i].name) + "=" + encodeURIComponent(divFields[i].value) + "&";
				}
	
                        }

                }

                return queryString;

        }

	function refreshDiv (destination, query) {

		ajaxRequest('sirkJax.php', null, destination, 'div', false, query);

	}

        function ajaxRequest(phpFile, source, destination, response, async, query) {

                createXMLHttpRequest();
                sourceID = source; 
		destinationID = destination; 
		responseType = response;

                var url 	 = phpFile;
                var queryString  = query;
		if (queryString == null) queryString = createQueryString(); 

		if (async == true) {

                	xmlHttp.open("POST", url);
                	xmlHttp.onreadystatechange = handleStateChange;
                	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
                	xmlHttp.send(queryString);
			parseResults();

		} else {

                	xmlHttp.open("POST", url, false);
                	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
                	xmlHttp.send(queryString);
			parseResults();

		}

        }

	function handleStateChange() {
		
                if(xmlHttp.readyState == 4) {
                        if(xmlHttp.status == 200) {
                                parseResults();
                        }
                                
                }
        }
                         
        function parseResults() {
                 
                var response = xmlHttp.responseText;

                if (responseType == 'div') { updateDiv(destinationID, response); } 
		else if (responseType == 'field') { updateField(destinationID, response); }

        }

	function updateDiv(id, html) {

		document.getElementById(id).innerHTML = html;

	}

	function updateField(id, html) {

		document.getElementById(id).value = html;

	}


