/*
	Copyright 1995-2007 BalticDEV (http://balticdev.com/)
	GPL: You can freely copy, modify and redistribute this file


	Usage:
	-------------------------------------------------------------
	function updateCallback(xmlHttp, parm) {
		var txt = xmlHttp.responseText;
		var elm = document.getElementById( parm );
		if( !elm )
			return;
		elm.innerHTML = txt;
	}

	...

	AjaxRequestData( updateCallback, "price", true, url, post_vars );
	-------------------------------------------------------------

	Whatever output returns generated page gets set as inner html of element "price"
*/

function NewAjaxObject()
{
	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 null;
			}
		}
	}
	return xmlHttp;
}

function AjaxRequestData( func, parm, async, req_get, req_post )
{
	var xmlHttp = NewAjaxObject();
	if( !xmlHttp )
	    return false;
	    
	xmlHttp.onreadystatechange = function() {
	    if( xmlHttp.readyState == 4 && xmlHttp.status == 200 ) {
		     func( xmlHttp, parm );
	    }
	};
	
	if( !req_post )
	{
		xmlHttp.open("GET", req_get, async);
		xmlHttp.send(null);
	} else {
		xmlHttp.open("POST", req_get, async);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", req_post.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(req_post);
	}
	return true;
}

function getXmlChildren( xml, id ) {
	if( !xml )
		return null;
	xml = xml.getElementsByTagName(id);
	if( !xml || !xml[0] )
		return null;
	return xml;
}

function getXmlData( xml, id ) {
	if( !xml )
		return null;
	var txt = xml.getElementsByTagName(id);
	if( !txt || !txt[0] )
		return null;
	if( !txt[0].firstChild )
		return null;
	return txt[0].firstChild.data;
}

