//	Restaurant Livebookings Network DBI
//	Version: 1.0.1
//	Updated: 13.05.2007
//	-------------------------------------
//				VALIDATE CALL
//	-------------------------------------
var errStr = "";
var errMsg = "";
function isValidCall(args){
	var numArgs = args.length;
	var r = args[0];
	var l = args[1];
	isValid = true;
	if(numArgs < 2){
		errStr += "[Not enough parameters supplied]";
		isValid = false;
	}
	if(r == null || l == null || r == "" || l == "" || r.length < 30 || l.length < 30){
		errStr += "[One or more UID parameter missing or invalid]";
		isValid = false;
	}
	return isValid;	
}
//	-------------------------------------
//			EMBED INGRID
//	-------------------------------------
var clientUrl = location.href;
var ingridURL = "https://secure.livebookings.com/lbci/IngridV1.3.3.swf";
function embedLB(restlocationUID,linkUID,panelColour,borderSize,borderColour,countryCode,languageOptions,subLocationUID,requestDate,requestSession,requestCovers,customSess,conciergeUID,bookingRef){
	if(isValidCall(arguments) || arguments[13] != null){
	lbUserGet() == "undefined" ? userName = "": userName = lbUserGet();
	document.write("<OBJECT	CLASSID='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' WIDTH='275' HEIGHT='321' CODEBASE='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,41,0'>" +
		"<PARAM NAME='MOVIE' VALUE='" + ingridURL +
			"?restlocationUID=" + restlocationUID + 
			"&linkUID=" + linkUID + 
			"&bookingid=0" +
			"&panelColour=" + panelColour + 
			"&border=" + borderSize + 
			"&bdrColour=" + borderColour +
			"&countryCode=" + countryCode +
			"&showLangOpts=" + languageOptions +
			"&restUID=" + subLocationUID +
			"&requestDate=" + requestDate +
			"&requestSession=" + requestSession +
			"&requestCovers=" + requestCovers +
			"&concID=" + conciergeUID +
			"&bookingRef=" + bookingRef +
			"&clientUrl=" + clientUrl +
			"&userName=" + userName + "'>" +
		"<PARAM NAME='PLAY' VALUE='true'>" +
		"<PARAM NAME='LOOP' VALUE='false'>" +
		"<PARAM NAME='QUALITY' VALUE='high'>" +
		"<PARAM NAME='MENU' VALUE='false'>" +
		"<PARAM NAME='BGCOLOR' VALUE='#FFFFFF'>" +
		"<EMBED SRC='" + ingridURL +
			"?restlocationUID=" + restlocationUID + 
			"&linkUID=" + linkUID + 
			"&bookingid=0" +
			"&panelColour=" + panelColour + 
			"&border=" + borderSize + 
			"&bdrColour=" + borderColour +
			"&countryCode=" + countryCode +
			"&showLangOpts=" + languageOptions +
			"&restUID=" + subLocationUID +
			"&requestDate=" + requestDate +
			"&requestSession=" + requestSession +
			"&requestCovers=" + requestCovers +
			"&concID=" + conciergeUID +
			"&bookingRef=" + bookingRef +
			"&clientUrl=" + clientUrl +
			"&userName=" + userName + "' " +
			"WIDTH='275' " +
			"HEIGHT='321' " +
			"PLAY='true' " +
			"LOOP='false' " +
			"QUALITY='high' " +
			"BGCOLOR='#FFFFFF' " +
			"MENU='false' " +
			"TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/flashplayer/'>" +
			"</EMBED>" +
			"</OBJECT>");
		}else{
			errMsg="<div style='color:red;width:300px;'><p>Unfortunately there is an error in the code that is trying to display the restaurant booking interface.</p><p>" + errStr + "</p><p>We apologise for the inconvenience and would ask that you please inform the website administrator of this problem, so that it can be rectified as soon as possible.<br>Thank you.</p></div>";
			document.write(errMsg);
			return
		}
}
//	-------------------------------------
// 			DBI POP UP
//	-------------------------------------
function popLB(restlocationUID,linkUID,panelColour,borderSize,borderColour,countryCode,languageOptions,subLocationUID,requestDate,requestSession,requestCovers,customSess,conciergeUID){
	if(isValidCall(arguments)){
	height = 380; 
	width = 320;
  xPos = (640 - width)/2;
	yPos = (480 - height)/2;
    if (screen) {
		xPos = (screen.availWidth - width)/2;
        yPos = (screen.availHeight - height)/2;        
    }
		tgtUrl = 	"https://secure.livebookings.com/lbci/index.cfm?" +
							"restlocationUID=" + restlocationUID + 
							"&linkUID=" + linkUID + 
							"&panelColour=" + panelColour + 
							"&border=" + borderSize + 
							"&bdrColour=" + borderColour +
							"&country=" + countryCode +
							"&showLangOpts=" + languageOptions +
							"&restUID=" + subLocationUID +
							"&requestDate=" + requestDate +
							"&requestSession=" + requestSession +
							"&requestCovers=" + requestCovers +
							"&concID=" + conciergeUID;				
			args = 	"width=" + width + 
							",height=" + height + 
							",screenX=" + xPos + 
							",screenY=" + yPos +
							",left=" + xPos +
							",top=" + yPos +
							",status=1";
			
    lbWindow = window.open(tgtUrl,'bkgWin',args);
		lbWindow.focus();
	}else{
		errMsg="Unfortunately there is an error in the code that is trying to display the restaurant booking interface.\n\n" + errStr + "\n\nWe apologise for the inconvenience and would ask that you please inform the website administrator of this problem, so that it can be rectified as soon as possible.\nThank you.";
		alert(errMsg);
	}				
}
//	-------------------------------------
//				COOKIES
//	-------------------------------------
var lbUser = "";
function lbUserSet(lbUser){
	var sellBy = new Date();
	var life = sellBy.getTime()+(60*86400000);
	sellBy.setTime(life);
	document.cookie = "livebookingsUser="+escape(lbUser)+";expires="+sellBy.toGMTString()+";";
}
function lbUserGet(){	
	if(document.cookie){
		cookieData = unescape(document.cookie).split(";");
		for(k = 0; k < cookieData.length; k++){		
				myCookie = cookieData[k].split("=");
				if(myCookie[0].indexOf("livebookingsUser") != -1){
					lbUser = myCookie[1];
					return lbUser;
				}
		}		
	}	
}
//	-------------------------------------
//				CARD POLICY
//	-------------------------------------
function ccPolicy(countryCode){	
	height = 300; 
	width = 400;
    xPos = (640 - width)/2;
	yPos = (480 - height)/2;
    if (screen) {
		xPos = (screen.availWidth - width)/2;
        yPos = (screen.availHeight - height)/2;        
    }
	tgtUrl = "http://reservations.livebookings.com/" + countryCode + "/messages/ccPolicy.htm";
	args = 	"width=" + width + 
			",height=" + height + 
			",screenX=" + xPos + 
			",screenY=" + yPos +
			",left=" + xPos +
			",top=" + yPos +
			"status=1,scrollbars=0";			
    ccWindow = window.open(tgtUrl,'ccWindow',args);
	ccWindow.focus();
	}
//	-------------------------------------
//			SECURITY CODE HELP
//	-------------------------------------
function ccSecurity(){
	height = 300; 
	width = 450;
    xPos = (640 - width)/2;
	yPos = (480 - height)/2;
    if (screen) {
		xPos = (screen.availWidth - width)/2;
        yPos = (screen.availHeight - height)/2;        
    }
	tgtUrl = "http://reservations.livebookings.com/uk/dsp_CCcode.cfm";
	args = 	"width=" + width + 
			",height=" + height + 
			",screenX=" + xPos + 
			",screenY=" + yPos +
			",left=" + xPos +
			",top=" + yPos +
			"status=1,scrollbars=1";
			
    ccWindow = window.open(tgtUrl,'ccWindow',args);
	ccWindow.focus();
}
//	-------------------------------------
// 				DEPRECATED
//	-------------------------------------
function dspLivebookings(restID,linkID,panel,border,bdrColour,subID,requestDate,requestSession,requestCovers,concID,country,showLangOpts,customSess){
	//	Transfer params and call embedLB
	embedLB(restID,linkID,panel,border,bdrColour,country,showLangOpts,subID,requestDate,requestSession,requestCovers,customSess,concID);
}
function popLivebookings(restID,linkID,panel,border,bdrColour,subID,requestDate,requestSession,requestCovers,concID,country,showLangOpts,customSess){
	//	Transfer params & call popLB
	popLB(restID,linkID,panel,border,bdrColour,country,showLangOpts,subID,requestDate,requestSession,requestCovers,customSess,concID);			
}