/*
 * This javascript file is for functions that require external libraries
 * (Shadowbox, etc)
 * 
 */
 
 // verifies a function exists before flash calls it
function checkFunction(functionName) {
	if(window[functionName]) {
		return true;
	} else {
		return false;
	}
}


function clickBossButton() {
	
	var url = "interface/bossButton.php";
	
	window.open(url,'bossScreen','fullscreen=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');
	
}

function openBuffaloCircle() {
	
	var url = "http://apps.fishbowl.com/a/bww/join.asp";
	
	if (navigator.appVersion.indexOf("MSIE 7.")==-1) {
		// Other browsers open a shadowbox
		openShadowbox(url, "&nbsp;", 643, 720);
	} else {
		// IE7 opens a pop-up due to error in server-side
		// Fishbowl code dealing with Session variables
		window.open('http://apps.fishbowl.com/a/bww/join.asp','circle','width=643,height=720,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');
	}
	
}

function openWingTuesdays() {
	
	var url = "modals/WingTuesdays.html";
	
	openShadowbox(url, "&nbsp;", 674, 441);
	
}

function openWingView() {
	
	var url = "modals/AboutUs/360Viewer.html";
	
	openShadowbox(url, "&nbsp;", 585, 480);
	
}

function openLocations(zip, survey) {
	var url = "http://locations.buffalowildwings.com/";
	var vars = new Array();
	var query_strings = new Array();
	if(zip) { 
		vars["postalcode"] = zip; 
	} else if (getCookie("BWW_zip") != 'unset'){
		vars["postalcode"] = getCookie("BWW_zip");
	}
	if (survey) { 
		vars["survey"] = survey; 
	}
	for (var_name in vars) {
		query_strings.push(var_name + "=" + vars[var_name]);
	}
	if (query_strings.length > 0) {
		url = url + "?" + query_strings.join("&");
	}
	// open in shadowbox
	openShadowbox(url, "&nbsp;", 840, 491);

}

function openDirections(storeID, survey) {
	var url = "http://locations.buffalowildwings.com/";
	var vars = new Array();
	var query_strings = new Array();
	if(storeID) { 
		vars["storeID"] = storeID; 
	} else if (getCookie("BWW_zip") != 'unset'){
		vars["postalcode"] = getCookie("BWW_zip");
	}
	if(survey) { 
		vars["survey"] = survey; 
	}
	for (var_name in vars) {
		query_strings.push(var_name + "=" + vars[var_name]);
	}
	if (query_strings.length > 0) {
		url = url + "?" + query_strings.join("&");
	}
	// open in shadowbox
	openShadowbox(url, "&nbsp;", 840, 491);

}


function getCookie( cookieName )
{
  var strResults = 'unset';
  var offset = 0;
  var end = 0;
  var strSearch = new String(cookieName) + "="; 
  if (document.cookie.length > 0) 
  { 
	offset = document.cookie.indexOf( strSearch);

	if (offset != -1) 
	{ 
	  offset += strSearch.length;
	  end = document.cookie.indexOf(";", offset);
	  if (end == -1)
	  {
		end = document.cookie.length;
	  }
	  strResults = unescape(document.cookie.substring(offset, end));             

	}
  }

 return strResults;
}

function openShadowbox(url, title, width, height) {
	Shadowbox.open({
        content: url,
        type: "iframe",
		player: "iframe",
		title: title,
        width: width,
		height: height
    });
}

function openSWF(url, title, width, height) {
	Shadowbox.open({
        content: url,
        player: "swf",
		title: title,
        width: width,
		height: height
    });
}

function showImages(){
	document.getElementById('islandBg').style.visibility = 'visible';
	document.getElementById('menuBg').style.visibility = 'visible';
	document.getElementById('locatorBg').style.visibility = 'visible';
}


function openSurvey(surveyID){
	var surveyURL = 'http://www.surveymonkey.com/s.aspx?sm=' + surveyID;
	openShadowbox(surveyURL, "&nbsp;", 900, 480);
}