var fm_sorttype = 'ASC';
var fm_orderby = 'Price';
var fm_listExpanded = false;

function flightMatrixLoading() {
	sHTML='';
	sHTML+='<table border="1" cellpadding="15" cellspacing="0" class="FlightMatrixTable">';
	sHTML+='<tr>';
	sHTML+='<td><div align="center"><img src="/images/animations/ajax-loader-white.gif" /><br /><br /><span class="resultPleaseWait">Loading... Please wait.</span></div></td>';
	sHTML+='</tr>';
	sHTML+='</table>';
	document.getElementById('divResortInfo_5').innerHTML = sHTML;	
}

function flightMatrixSortIcons() {
	if(document.getElementById('divSort_'+fm_orderby)) {
		document.getElementById('divSort_'+fm_orderby).className='FlightMatrixSort'+fm_sorttype.toUpperCase();
		document.getElementById('divSort_'+fm_orderby).style.display='';
	}
}
function flightMatrixSort(orderby) {
	flightMatrixLoading();
	if(orderby.toLowerCase()==fm_orderby.toLowerCase() && fm_sorttype.toLowerCase()=='asc') {
		fm_sorttype = 'DESC';
		GetResortInfo(currentSearchType, '', currentFMVars, orderby, 'DESC');
	}else{
		fm_sorttype = 'ASC';
		fm_orderby = orderby;
		GetResortInfo(currentSearchType, '', currentFMVars, orderby, 'ASC');
	}
}

function flightMatrixExpandList() {
	document.getElementById('fm_topplus').style.display='';
	document.getElementById('fm_topplustext').style.display='none';
	fm_listExpanded = true;
}

function flightMatrix_RemoveContent(id) {
	if(id) {
		if(confirm('Do you want to remove this flight?')) {
			flightMatrixLoading();
			flightMatrixAjax('remove',id);
		}
	}
}
function flightMatrix_BookContent(id) {
	if(id) {
		div_switch('websiteDiv',false,true);
		scroll(0,0);
		div_switch('pleasewaitDiv',true,true);
		setTimeout('replaceImages()',100);
		flightMatrixAjax('book',id);
	}
}



var flightMatrixAjaxType = '';

function flightMatrixAjax(type, id) {
	flightMatrixAjaxType = type;
	sURL = '/includes/flightmatrix/flightmatrix.asp?type='+type+'&id='+id+'&flightmatrixuser='+currentFMUser;
	if(sURL!='') {
		sURL=sURL.replace("'","");
		if(bDebug) {
			if(confirm('Open '+ sURL)) {
				window.open(sURL);
			}
		}
		setTimeout("loadFMAjaxXMLDoc('"+sURL+"')", 100);
	}else{
		alert('No url defined');
	}
	
}
function loadFMAjaxXMLDoc(url) {
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		reqFM = new XMLHttpRequest();
		reqFM.onreadystatechange = processFMAjax;
		reqFM.open("GET", url, true);
		reqFM.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		reqFM = new ActiveXObject("Microsoft.XMLHTTP");
		if (reqFM) {
			reqFM.onreadystatechange = processFMAjax;
			reqFM.open("GET", url, true);
			reqFM.send();
		}
	}
}
function processFMAjax() {
	if (reqFM.readyState == 4) {
		if (reqFM.status == 200){
			xmldoc = reqFM.responseXML.documentElement;
			if(flightMatrixAjaxType.toLowerCase()=='remove') {
				GetResortInfo(currentSearchType, '', currentFMVars, fm_orderby, fm_sorttype);
			}else{
				fm_book = xmldoc.getElementsByTagName('Book');
				if(fm_book.length>0) {
					sSessionID = fm_book.item(0).attributes.getNamedItem("SessionID").nodeValue;
					sFlightID = fm_book.item(0).attributes.getNamedItem("FlightID").nodeValue;
					sFlightProvider = fm_book.item(0).attributes.getNamedItem("FlightProvider").nodeValue;
					setLevel('PRICING');
					document.frmResults.SessionID.value=sSessionID;
					document.frmResults.fare_id.value=sFlightID;
					document.frmResults.Provider_Flight.value=sFlightProvider;
					frmBYOSubmit();
					
				}
				//alert('cool');
			}
		}
	}
}
