// Funktionen fuehren eine Buchungsanfrage fuer ein TT-Angebot durch
// und laden dieses per Ajax nach
// waehrend der Anfrage wird ein "Warte-Div" angezeigt
var offerId;
var requestInUse = false;
var ibeTdInnerHtml = new Array();
var ibeTrClassName = '';
var what;
function xmlRequestSend(url, tableId, type) {
	// branch for native XMLHttpRequest object
	what = type;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		if (tableId == "tblOfferListExact") req.onreadystatechange = xmlRequestProcessReqChange;
		else if (tableId == "tblOfferListAlternate")  req.onreadystatechange = xmlRequestProcessReqChange2;
		req.open("GET", url, true);
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			if (tableId == "tblOfferListExact") req.onreadystatechange = xmlRequestProcessReqChange;
			else if (tableId == "tblOfferListAlternate")  req.onreadystatechange = xmlRequestProcessReqChange2;
			req.open("GET", url, true);
			req.send();
		}
	}
}
function xmlRequestProcessReqChange() {
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			var index = getElement(offerId).rowIndex;
			document.getElementById( 'tblOfferListExact' ).deleteRow( index );
			var row = document.getElementById( 'tblOfferListExact' ).insertRow( index );
			var td = document.createElement( 'td' );
			td.setAttribute('class', 'availCheck' );
			if (what == 'package') td.setAttribute('colSpan', '6' );
			else td.setAttribute('colSpan', '5' );
			td.setAttribute('style', "padding:0;");
			td.innerHTML = req.responseText;
			row.appendChild( td );
			requestInUse = false;
		}
		requestInUse = false;
	}
}
function xmlRequestProcessReqChange2() {
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			var index = getElement(offerId).rowIndex;
			document.getElementById( 'tblOfferListAlternate' ).deleteRow( index );
			var row = document.getElementById( 'tblOfferListAlternate' ).insertRow( index );
			var td = document.createElement( 'td' );
			if (what == 'package') td.setAttribute('colSpan', '6' );
			else td.setAttribute('colSpan', '5' );
			td.setAttribute('style', "padding:0;");
			td.innerHTML = req.responseText;
			row.appendChild( td );
			requestInUse = false;
		}
		requestInUse = false;
	}
}
function  abortBookingQuestionReq(tableId) {
	var index = getElement(offerId).rowIndex;
	document.getElementById( tableId ).deleteRow( index );
	var row = document.getElementById( tableId ).insertRow( index );
	for (i=0;i<ibeTdInnerHtml.length;i++) {
		var td = document.createElement( 'td' );
		td.innerHTML = ibeTdInnerHtml[i];
		if ( i==0 || i==3 ) {
			td.style.textAlign = 'left';
		}
		else if ( i == 1 || i == 2) {
			td.style.textAlign = 'center';
		}
		else if  ( i==4 ) {
			td.style.textAlign = 'right';
		}
		row.appendChild( td );
	}
	row.id = offerId;
	row.className = ibeTrClassName;
	requestInUse = false;
}
function bookingQuestionReq ( host, id, va, iff, hotel, stars, ver, lref, tableId, picture, s1, buchcode, veranstaltername, s3, s5 ) {
	if ( requestInUse == true ) return;
	requestInUse = true;
	offerId = id;
	var html = '<div>'; 
	html += '		<center><b>Bitte warten! Es werden freie Pl&auml;tze direkt beim Veranstalter gepr&uuml;ft.</b></center>';
	html += '	</div>';
	html += '	<div style="text-align:center; width:100%; padding: 5px 0px;">';
	html += '		<img src="'+host+'img/loadingAnimation.gif" alt="" align="absmiddle" />';
	html += '	</div>';
	html += '	<div align="right"><a onclick="abortBookingQuestionReq(\''+tableId+'\')" style="margin-left:200px; cursor:pointer; text-decoration:underline">Abbrechen</a></div>';
	var index = getElement(offerId).rowIndex;
	
	ibeRow = document.getElementById( tableId ).rows[index];
	for ( i=0; i<ibeRow.cells.length;i++) {
		ibeTdInnerHtml[i] = ibeRow.cells[i].innerHTML;
	}
	ibeTrClassName = ibeRow.className;
		
	document.getElementById( tableId ).deleteRow( index );
	var row = document.getElementById( tableId ).insertRow( index );
	var td = document.createElement( 'td' );
	row.id = offerId;
	td.setAttribute('colSpan', '6' );
	td.setAttribute('style', "background-color:#ECEDF4;");
	td.innerHTML = html;
	row.appendChild( td );

	xmlRequestSend ( host+'hotel/getTTOffer/offerId/'+offerId+'/va/'+va+'/iff/'+iff+'/hotel/'+escape(hotel)+'/stars/'+stars+'/ver/'+ver+'/lref/'+lref+'/pic/'+picture+'/s1/'+s1+'/bc/'+buchcode+'/veranstaltername/'+escape(veranstaltername)+'/s3/'+s3+'/s5/'+s5, tableId, 'hotel' );
}
function bookingQuestionReqTheme ( host, id, va, iff, hotel, stars, adult , child1 , child2 , child3 , ver, tableId, picture, buchcode, veranstaltername, s3, s5 ) {
	if ( requestInUse == true ) return;
	requestInUse = true;
	offerId = id;
	var html = '<td colspan="5" style="background-color:#ECEDF4; padding-left:10px; padding-top:5px;"><div>'; 
	html += '		<center><b>Bitte warten! Es werden freie Pl\xE4tze direkt beim Veranstalter gepr\xFCft.</b></center>';
	html += '	</div>';
	html += '	<div style="text-align:center; width:100%; padding: 5px 0px;">';
	html += '		<img src="'+host+'img/loadingAnimation.gif" alt="" align="absmiddle" />';
	html += '	</div></td>';
	html += '	<div align="right"><a onclick="abortBookingQuestionReq(\''+tableId+'\')" style="margin-left:200px; cursor:pointer; text-decoration:underline">Abbrechen</a></div>';
	var index = getElement(offerId).rowIndex;
	
	ibeRow = document.getElementById( tableId ).rows[index];
	for ( i=0; i<ibeRow.cells.length;i++) {
		ibeTdInnerHtml[i] = ibeRow.cells[i].innerHTML;
	}
	ibeTrClassName = ibeRow.className;
	
	document.getElementById( tableId ).deleteRow( index );
	var row = document.getElementById( tableId ).insertRow( index );
	var td = document.createElement( 'td' );
	row.id = offerId;
	td.setAttribute('colSpan', '6' );
	td.setAttribute('style', "background-color:#ECEDF4;");
	td.innerHTML = html;
	row.appendChild( td );
	xmlRequestSend ( host+'specialhotel/getTTOffer/offerId/'+offerId+'/va/'+va+'/iff/'+iff+'/hotel/'+escape(hotel)+'/stars/'+stars+'/adult/'+adult+'/child1/'+child1+'/child2/'+child2+'/child3/'+child3+'/ver/'+ver+'/pic/'+picture+'/bc/'+buchcode+'/veranstaltername/'+escape(veranstaltername)+'/s3/'+s3+'/s5/'+s5, tableId, 'hotel' );
}
function bookingQuestionReqPackage ( host, id, va, iff, hotel, stars, adult , child1 , child2 , child3 , ver, tableId, picture, abflug, abflughafen, zusatz, transfer, buchcode, veranstaltername ) {
	if ( requestInUse == true ) return;
	requestInUse = true;
	offerId = id;
	var html = '<td colspan="5" style="background-color:#ECEDF4; padding-left:10px; padding-top:5px;"><div>'; 
	html += '		<center><b>Bitte warten! Es werden freie Pl\xE4tze direkt beim Veranstalter gepr\xFCft.</b></center>';
	html += '	</div>';
	html += '	<div style="text-align:center; width:100%; padding: 5px 0px;">';
	html += '		<img src="'+host+'img/loadingAnimation.gif" alt="" align="absmiddle" />';
	html += '	</div></td>';
	html += '	<div align="right"><a onclick="abortBookingQuestionReq(\''+tableId+'\')" style="margin-left:200px; cursor:pointer; text-decoration:underline">Abbrechen</a></div>';
	var index = getElement(offerId).rowIndex;
	
	ibeRow = document.getElementById( tableId ).rows[index];
	for ( i=0; i<ibeRow.cells.length;i++) {
		ibeTdInnerHtml[i] = ibeRow.cells[i].innerHTML;
	}
	ibeTrClassName = ibeRow.className;
	
	document.getElementById( tableId ).deleteRow( index );
	var row = document.getElementById( tableId ).insertRow( index );
	var td = document.createElement( 'td' );
	row.id = offerId;
	td.setAttribute('colSpan', '6' );
	td.setAttribute('style', "background-color:#ECEDF4;");
	td.innerHTML = html;
	row.appendChild( td );
	xmlRequestSend ( host+'package/getOffer/offerId/'+offerId+'/va/'+va+'/iff/'+iff+'/hotel/'+escape(hotel)+'/stars/'+stars+'/adult/'+adult+'/child1/'+child1+'/child2/'+child2+'/child3/'+child3+'/ver/'+ver+'/pic/'+picture+'/abflug/'+escape(abflug)+'/abflughafen/'+escape(abflughafen)+'/zusatz/'+zusatz+'/transfer/'+transfer+'/bc/'+buchcode+'/veranstaltername/'+escape(veranstaltername), tableId, 'package' );
}
function getElement(obj)
{
	if(document.getElementById)
		return document.getElementById(obj);
	else if(document.all)
		return document.all[obj];
	else if(document.layers)
		return document.obj;
}

