var targetUrl = LANG_ROOT_PATH + 'AJAX/FlexibleFlights.aspx';
var xmlReq1 = GetXmlRequestObject();
var xmlReq2 = GetXmlRequestObject();

// gets a reference to the xml request object
function GetXmlRequestObject(){
	var obj = null;
	if(window.XMLHttpRequest){
		obj = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		try{ obj = new ActiveXObject('Msxml2.XMLHTTP'); }
		catch(e){
			try{ obj = new ActiveXObject('Microsoft.XMLHTTP'); }
			catch(oc){ obj = null; }
		}
	}
	return obj;
}

function FlexibleRequestObject(resultType)
{
	var useReq1 = (resultType==1 || resultType==4);
	this.xmlReq = (useReq1 ? xmlReq1 : xmlReq2);
	this.stateChanged = (useReq1 ? RequestObj1Changed : RequestObj2Changed);

	// make a request to the server
	function FetchResults(type, group, dep, dest, d, m, y, adt, chd, inf, way, region){
		if(this.xmlReq && this.xmlReq.readyState != 0)
			this.xmlReq.abort();

		if(this.xmlReq)
		{
			var pg = targetUrl;
			pg += '?type=' + type;
			pg += '&group=' + group;
			pg += '&dep=' + dep;
			pg += '&dest=' + dest;
			pg += '&d=' + d;
			pg += '&m=' + m;
			pg += '&y=' + y;
			pg += '&adults=' + adt;
			pg += '&children=' + chd;
			pg += '&infants=' + inf;
			pg += '&way=' + way;
			pg += '&currency=' + region;
			
			this.xmlReq.open('GET', pg, true);
			this.xmlReq.onreadystatechange = this.stateChanged;
			this.xmlReq.send(null);
		}
	}
	this.FetchResults = FetchResults;
}

function RequestObj1Changed()
{
	RequestStateChanged(xmlReq1)
}

function RequestObj2Changed()
{
	RequestStateChanged(xmlReq2)
}

function RequestStateChanged(req)
{
	try
	{
		if(req.readyState == 4)
		{
			if(req.responseText)
				eval(req.responseText);

			if(UpdateFlexible)
				UpdateFlexible();
		}
	}
	catch(ex){}
}

