﻿//javascript functions for launching other pages

function addVersion(target){
	var str = new String();
	str = target;
	var vers = new String('version=3.0');
	if(str.indexOf('?')==-1){
		target=target+'?'+vers;
	}
	else if((str.indexOf('?')+1)==str.length){
		target=target+vers;
	}
	else{
		target=target+"&"+vers;
	}
	return target;
}
function getScrWidth(){
	if(document.layers){return screen.availWidth;}
	else if(document.all){return screen.width;}
	else{return 0;}
}
function getScrHeight(){
	if(document.layers){return screen.availHeight;}
	else if(document.all){return screen.height;}
	else{return 0;}
}
var windows = new Array();
function new_window(src, winName, pageWidth, pageHeight, scrollbars, unbound){
	var posStr = new String();
	src = addVersion(src);
	if(document.layers){posStr=", top=" + ((screen.availHeight/2)-(pageHeight/2)).toString() + ", left=" + ((screen.availWidth/2)-(pageWidth/2)).toString();}
	else if(document.all){posStr=", top=" + ((screen.height/2)-(pageHeight/2)).toString() + ", left=" + ((screen.width/2)-(pageWidth/2)).toString();}
	var props = new String();
	var behavior;
	if(scrollbars){
		behavior = ", scrollbars=1";
	}
	else{
		behavior = ", resizable=yes";
	}
	props = "status=1" + behavior + ", width=" + pageWidth + ", height=" + pageHeight + posStr;
	if(unbound){
		var dummy = window.open(src, winName,props);
		if(pageWidth==0){
			maximise(dummy);
		}
		dummy.focus();
	}
	else{
		windows[windows.length]=window.open(src, winName,props);
		if(pageWidth==0){
			maximise(windows[(windows.length)-1]);
		}
		windows[(windows.length)-1].focus();
	}
}
function load_page(src, winName, pageWidth, pageHeight){
	new_window(src, winName, pageWidth, pageHeight, false);
}
function load_scrollpage(src, winName, pageWidth, pageHeight){
	new_window(src, winName, pageWidth, pageHeight, true);
}
function load_srollpage(src, winName, pageWidth, pageHeight){
	new_window(src, winName, pageWidth, pageHeight, true);
}
/*
Any page that references these functions should also include 
the closeWindows() function on the body onUnload event.
This will close all child windows opened on the page.
*/
function closeWindows(){
	if(windows.length > 0){
		for(var i = 0;i < windows.length;i++){
			windows[i].close();
		}
	}
}
//check browser/platform versions
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_nav = ((agt.indexOf('mozilla')!=-1)
    && (agt.indexOf('spoofer')==-1)
    && (agt.indexOf('compatible') == -1)
    && (agt.indexOf('opera')==-1)
    && (agt.indexOf('webtv')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
    (agt.indexOf("; nav") != -1)) );
var is_nav5 = (is_nav && (is_major == 5));
var is_nav5up = (is_nav && (is_major >= 5));

var is_ie = (agt.indexOf("msie") != -1);
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) &&
    (agt.indexOf("msie 5.0")==-1) );
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5 = (is_ie && (is_major == 4) &&
    (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);

// os detection
var is_pc=(navigator.platform.substring(0,3)=='Win');
var is_mac=(navigator.platform.substring(0,3) == 'Mac');

function load_report(target,scroll){
	new_window(target, "bkngs", 800, 800, true);
}
function mapit(pCode){
	load_srollpage("http://www.multimap.com/map/browse.cgi?pc=" + pCode,"mapWin",700,500,1);
}
function findPos(obj,leftOrTop){
	var cur = 0;
	if(obj.offsetParent){
		while(1){
			leftOrTop == "left"?cur +=obj.offsetLeft:cur += obj.offsetTop;
		 	if(!obj.offsetParent){
				break;
			}
		  	obj = obj.offsetParent;
		}
	}else if(obj.x){
		leftOrTop == "left"?cur +=obj.x:cur += obj.y;
	}
	return cur;
}
var calShown = new Array();
function setCalPosition(tgtObj,calObj){
	var tgt = document.getElementById(tgtObj);
	var cal = document.getElementById(calObj);
	//var yOffset = 0;
	cal.style.display = "block";
	calShown[calShown.length] = calObj;
	//cal.style.left = (findPos(tgt,"left")-12)+"px";
	//cal.style.top = (findPos(tgt,"top")+20)+"px";
	//cal.style.zIndex = "99";
}
function hideCal(){
	for(i=0;i < calShown.length;i++){
		var tgt = document.getElementById(calShown[i]);
		tgt.style.display = "none";
	}
}
var cal;
function calBtnClick(dateControl){
	/*
	if(cal==undefined){
		var container = document.getElementById("pop_div"+dateControl);
		cal = document.createElement("iframe");
		cal.setAttribute("name", "pop_cal"+dateControl);
		cal.setAttribute("id", "pop_cal"+dateControl);
		cal.setAttribute("width", 146);
		cal.setAttribute("height", 106);
		cal.setAttribute("marginwidth", 0);
		cal.setAttribute("marginheight", 0);
		cal.setAttribute("align", "middle");
		cal.setAttribute("scrolling", "no");
		cal.setAttribute("frameborder", 0);
		container.appendChild(cal);
		//"<iframe name='pop_cal"+dateControl+"' id='pop_cal"+dateControl+"' width='146' height='106' marginwidth='0' marginheight='0' align='middle' scrolling='no' frameborder='0'>Calendar...</iframe>"
	}*/
	setCalPosition(dateControl+'Text','pop_div'+dateControl);
	var pop_cal = document.getElementById('pop_cal'+dateControl);
	var pop_cal_link = document.getElementById('lnkCal'+dateControl);
	pop_cal.src=pop_cal_link.getAttribute('href')+'&requestDate='+document.getElementById(dateControl).value;
}
function sizeWindow(scr_w,scr_h){
	if (scr_w != window.width || scr_h != window.height) {
	     window.resizeTo(scr_w, scr_h);
	}
}
var thisTimeout;
function scrollToPoint(scrollPoint,scrollElementID,scrollwidth,scrollSpeed,scrollIncr,margin,itemwidth){
	//auto scroll accross the time-line to the beginning of an element
	//scrollPoint - the left hand point of the element you want to see
	//scrollElementID - the ID of the element that scrolls
	//scrollwidth - the width of the element that scrolls
	//scrollSpeed - time between movements of the scroll in milliseconds
	//scrollIncr - amount to scroll each movement
	//margin - amount to scroll into the window
	//itemwidth - amount of the item we want to be visible
	clearTimeout(thisTimeout);
	var divT = document.getElementById(scrollElementID);
	if((scrollPoint + margin) + itemwidth > (divT.scrollLeft + scrollwidth)){//right hand end of what we want visible is off to the right
		divT.scrollLeft = divT.scrollLeft + scrollIncr;
		thisTimeout = setTimeout("scrollToPoint("+scrollPoint+",'"+scrollElementID+"',"+scrollwidth+","+scrollSpeed+","+scrollIncr+","+margin+","+itemwidth+")", scrollSpeed);
	}
	else if(divT.scrollLeft > 0 && divT.scrollLeft > (scrollPoint - margin)){//left hand end of item is off to the left
		divT.scrollLeft = divT.scrollLeft - scrollIncr;
		thisTimeout = setTimeout("scrollToPoint("+scrollPoint+",'"+scrollElementID+"',"+scrollwidth+","+scrollSpeed+","+scrollIncr+","+margin+","+itemwidth+")", scrollSpeed);
	}
}
function pop_addBkng(restdataid,bookDate,bookSession,bookCovers,dinerUID,bookTime){
	var params = new String("");
	if(restdataid){
		params+="&restdataID="+restdataid;
	}
	if(bookDate){
		params+="&bookdate="+bookDate;
	}
	if(bookSession){
		params+="&booksession="+bookSession;
	}
	if(bookCovers){
		params+="&bookCovers="+bookCovers;
	}
	if(dinerUID){
		params+="&dinerUID="+dinerUID;
	}
	if(bookTime){
		params+="&bookTime="+bookTime;
	}
	if(params.length > 0){
		params = "?"+params.substring(1,params.length);
	}
	load_scrollpage('/restconsole/cfm/reservation/index.cfm'+params.toString(),'bkngWin',682,700);
}
function pop_viewBkng(bookingid){
	load_scrollpage('/restconsole/cfm/reservation/index.cfm?bookingid='+bookingid,'bkngWin'+bookingid,682,700);
}
function custPopUp(uid, tab){
	var params="thisaction=onecust&userUID="+uid;
	if(tab){
		params+="&tab="+tab;
	}
	load_page('/restconsole/cfm/customers/index.cfm?'+params,'custWin'+uid.replace(/[\W_]/g,''),735,642);
}
function configPopUp(templateid, restdatauid, configdate, configsess, userToken){
	var urlStr = new String("/restconsole/cfm/availability/index.cfm?thisaction=TManager");
	if(templateid){
		urlStr += '&templateid='+templateid;
	}
	else{
		urlStr += '&restdatauid='+restdatauid+'&bookingDate='+configdate+'&session='+configsess;
	}
	if(userToken){
		urlStr += '&userToken='+userToken;
	}
	loadConfigPage(urlStr);
}
function tableNumPopUp(restdataid,configsess,templateid,userToken){
	var urlStr = new String("/restconsole/cfm/availability/index.cfm?thisaction=TableNumbers");
	if(restdataid){
		urlStr += '&restdataid='+restdataid;
	}
	if(configsess){
		urlStr += '&sessionid='+configsess;
	}
	if(templateid){
		urlStr += '&templateid='+templateid;
	}
	if(userToken){
		urlStr += '&userToken='+userToken;
	}
	loadConfigPage(urlStr);
}
function loadConfigPage(urlStr){
	load_page(urlStr,'configWin',800,600);
}
function maximise(winVar){
	winVar.moveTo(0,0);
	var vendorStr = new String(navigator.vendor);
	if(document.all || vendorStr.indexOf('Apple') > -1){//Fix for Safari
		winVar.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if(document.layers || document.getElementById){ 
	   if(winVar.outerHeight < screen.availHeight || winVar.outerWidth < screen.availWidth){
			winVar.outerHeight = winVar.screen.availHeight; 
			winVar.outerWidth = winVar.screen.availWidth;
		} 
	} 
}
function windowWidth(){
	if(typeof(window.innerWidth)=='number'){
    	//Non-IE
    	return window.innerWidth;
  	}
	else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight)){
    	//IE 6+ in 'standards compliant mode'
   		return document.documentElement.clientWidth;
  	} 
	else if(document.body && ( document.body.clientWidth || document.body.clientHeight)){
    	//IE 4 compatible
  		return document.body.clientWidth;
  	}
	return 0;
}
function windowHeight(){
	if(typeof(window.innerWidth)=='number'){
    	//Non-IE
    	return window.innerHeight;
  	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
    	//IE 6+ in 'standards compliant mode'
   		return document.documentElement.clientHeight;
  	}
	else if(document.body && ( document.body.clientWidth || document.body.clientHeight)){
    	//IE 4 compatible
  		return document.body.clientHeight;
  	}
	return 0;
}
function logout(){
	pageContent.location.href = "/Restconsole/cfm/general/index.cfm?fuseaction=logout";
}
//this is the LB corporate site function allowing us to copy and paste partner logo html form the sites.
//used in the web content section.
function launchWindow(url, w, h){
	window.open(url, "popup", "scrollbars=1,toolbar=1,status=1,statusbar=1,resizable=1,width=" + w + ",height=" + h);
}
function grayOut(on,withtimer,withrefresh){
	var grayOutWithTimer = document.getElementById("grayOutWithTimer");
	var grayOut = document.getElementById("grayOut");
	if(withtimer){
		var thisGrayOut = grayOutWithTimer;
	}else{
		var thisGrayOut = grayOut;
	}
	if(on){
		thisGrayOut.style.display = "block";
		thisGrayOut.style.width = windowWidth()+"px";
		thisGrayOut.style.height = windowHeight()+"px";
	}
	else{
		grayOut.style.display = "none";
		grayOutWithTimer.style.display = "none";
	}
	if(withrefresh){
		showRefresh(on);
	}
}
function showRefresh(on){
	var refresh = document.getElementById("refresh");
	if(on){
		refresh.style.display = "block";
		refresh.style.top = ((windowHeight()-50)/2)+"px";
		refresh.style.left = ((windowWidth()-300)/2)+"px";
	}
	else{
		refresh.style.display = "none";
	}
}
