/* Forwarding functions

	To provide "service unavailable" page(s), replace this file with one that
	reimplements the public forwarding functions, e.g.

		function ibBeginBooking() {
			return 'unavailable.html' ;
		}

	Ensure that the technique used for replacing the file will cause users' browsers to
	fetch the new one (e.g. make sure the file-modified timestamp is newer)
*/

function ibBeginBooking(sInnID,sPath,bOfferLogin) {
	if (sInnID == null) sInnID = '' ;
	if (sPath == null) sPath = '' ;
	if (bOfferLogin == null) bOfferLogin = true ; 
	var bLogin = !bOfferLogin ? false : !ibIsLoggedIn() ;
	if (!bLogin) {
		return ibBackSiteURL() + '?MGWLPN=' + ibMGWLPN() + '&MGWAPP=' + ibMGWAPP()+ '&Page=ibstart&Command=book&INNID=' + sInnID ;
	} else {
		return sPath + 'ibstart.html#' + sInnID ;
	}
}


function ibBeginCancel(sReturnPage,sBookingRef,sSurname,sArrivalDD,sArrivalMM,sArrivalYYYY) {
	var sParams = '?MGWLPN=' + ibMGWLPN() + '&MGWAPP=' + ibMGWAPP()+ '&Page=' ;
	if (sReturnPage == null) sReturnPage = '' ;
	if (sBookingRef == null) sBookingRef = '' ;
	if (sBookingRef == '') {
		sParams += 'ibstart&Command=cancel,' + sReturnPage ;
	} else {
		sParams += 'cancel1&Command=ok,' + sReturnPage ;
		sParams += '&CBREN=' + sBookingRef ;
		sParams += '&CBSUR=' + sSurname ;
		sParams += '&CANdd=' + sArrivalDD ;
		sParams += '&CANmm=' + sArrivalMM ;
		sParams += '&CANyyyy=' + sArrivalYYYY ;
	}
	return ibBackSiteURL() + sParams ;
}

function ibBeginAmend(sPath) {
	if (sPath == null) sPath = '' ;
	if (ibIsLoggedIn()) {
		return ibBackSiteURL() + '?MGWLPN=' + ibMGWLPN() + '&MGWAPP=' + ibMGWAPP()+ '&Page=ibstart&Command=regamend' ;
	} else {
		return sPath + 'ibstart2.html' ;
	}
}

function ibBeginMyAccount(sPath) {
	if (sPath == null) sPath = '' ;
	if (ibIsLoggedIn()) {
		return ibBackSiteURL() + '?MGWLPN=' + ibMGWLPN() + '&MGWAPP=' + ibMGWAPP()+ '&Page=ibstart&Command=loggedin' ;
	} else {
		return sPath + 'ibstart2.html' ;
	}
}


function ibBeginHistory(sPath) {
	if (sPath == null) sPath = '' ;
	if (ibIsLoggedIn()) {
		return ibBackSiteURL() + '?MGWLPN=' + ibMGWLPN() + '&MGWAPP=' + ibMGWAPP()+ '&Page=loggedin&Command=history' ;
	} else {
		return sPath + 'ibstart2.html' ;
	}
}
function ibBeginPastHistory(sPath) {
	if (sPath == null) sPath = '' ;
	if (ibIsLoggedIn()) {
		return ibBackSiteURL() + '?MGWLPN=' + ibMGWLPN() + '&MGWAPP=' + ibMGWAPP()+ '&Page=loggedin&Command=past' ;
	} else {
		return sPath + 'ibstart2.html' ;
	}
}
function ibBeginRegister(sReturnPage) {
	if (sReturnPage == null) sReturnPage = '' ;
	return ibBackSiteURL() + '?MGWLPN=' + ibMGWLPN() + '&MGWAPP=' + ibMGWAPP()+ '&Page=ibstart&Command=register&ZBackTo=' + sReturnPage ;
}

function ibBeginBookAmend(sReturnPage,sBookingRef,sSurname,sArrivalDD,sArrivalMM,sArrivalYYYY) {
	var sParams = '?MGWLPN=' + ibMGWLPN() + '&MGWAPP=' + ibMGWAPP()+ '&Page=' ;
	if (sReturnPage == null) sReturnPage = '' ;
	if (sBookingRef == null) sBookingRef = '' ;
	if (sBookingRef == '') {
		sParams += 'ibstart&Command=amend,' + sReturnPage ;
	} else {
		sParams += 'amend1&Command=ok,' + sReturnPage ;
		sParams += '&ABREN=' + sBookingRef ;
		sParams += '&ABSUR=' + sSurname ;
		sParams += '&ABdd=' + sArrivalDD ;
		sParams += '&ABmm=' + sArrivalMM ;
		sParams += '&AByyyy=' + sArrivalYYYY ;
	}
	return ibBackSiteURL() + sParams ;
}


// END OF PUBLIC FORWARDING FUNCTIONS
// ----------------------------------
// Helper functions
// ----------------

function ibBackSiteURL() {
  // Specify the backsite URL here
	 return 'https://www.innkeeperslodge.com/web.wls' ;
	// return 'http://129.35.86.42/web.wls' ;
}
function ibMGWLPN() {
  // Specify the WebLink connection name here
	return 'TIIBS' ;
}
function ibMGWAPP() {
  // Specify the WebLink application name here
	return 'TIIBS' ;
}

function ibIsLoggedIn() {
	var sCookies = document.cookie + ';' ;
	if (sCookies.indexOf('ibUSERid=') == -1) return false ; // not set
	if (sCookies.indexOf('ibUSERid=;') != -1) return false ; // the empty Netscape cookie
	return true ;
}

