
var hobNob = document.cookie; 

function getCookie(name) { 
var index = hobNob.indexOf(name + "="); 
if (index == -1) return null; 
index = hobNob.indexOf("=", index) + 1; // first character
var endstr = hobNob.indexOf(";", index); 
if (endstr == -1) endstr = hobNob.length;  // last character 
return unescape(hobNob.substring(index, endstr));
}

function initializeDirectory() {
	checkDate();	
      var info = getCookie("mysbcsettings");
	if (info != null) {
		var splitInfo = info.split("xxx");
		var initialzoom = parseInt(splitInfo[0]);
		var pageadvance = parseInt(splitInfo[1]);
	}
	else {
		var initialzoom = "1";
		var pageadvance = "10";
		setMyPreferences(initialzoom, pageadvance);
	}
}

function getPageAdvance() {
     	var info = getCookie("mysbcsettings");
	if (info != null) {
		var splitInfo = info.split("xxx");
		return parseInt(splitInfo[1]);
	}
	else
		return 10;
}

function getZoomLevel() {
     	var info = getCookie("mysbcsettings");
	if (info != null) {
		var splitInfo = info.split("xxx");
		return parseInt(splitInfo[0]);
	}
	else
	 return 1;

}

function reloadCurrentPage() {
	if (top.select.menu.section != 'cover') {
//		this.location.reload(false);
//	} else {
		var page = top.select.menu.getPage();
		var section = top.select.menu.getSection();
		top.select.menu.openSection(section,page);
	}
}

function setMyRadioButtons() {
var zoom = getZoomLevel();
var advance = getPageAdvance();
setZoomButton(zoom);
setAdvanceButton(advance);
}

function setZoomButton(zooming) {
	for (i=0; i < document.radioform1.RadioButton.length; i++) {
		if (document.radioform1.RadioButton[i].value == zooming) {
			document.radioform1.RadioButton[i].checked  = 'true';
		}
	}
}
function setAdvanceButton(pgAdvance) {
	for (i=0; i < document.radioform2.RadioButton.length; i++) {
		if (document.radioform2.RadioButton[i].value == pgAdvance) {
			document.radioform2.RadioButton[i].checked  = 'true';
		}
	}
}

function setMyPreferences(zoom, advance) {
	var cookie_info = zoom + "xxx" + advance;
	document.cookie = 'mysbcsettings='+cookie_info+'; expires=Fri, 31 Dec 2099 11:59:59 UTC; path=/';
}

function checkDate() {

// -- variables for testing --
//	var year = 2006;
//	var month = 1;
// ---------------------------

	var month = (top.issuedate * 1);
	var year = ((top.year * 1)+1);

	if ((month > 0) && (month < 9))  { month = (month+4); }
	else { month = (month-8); year = year+1;}
	
      	var currentDate = new Date();
      	presentUTC = Date.UTC(currentDate.getFullYear(),currentDate.getMonth(),1);
	expiryUTC = Date.UTC(year, (month-1), 1);
 	
     	var notValid = getCookie(top.trakVal);

	var cookieString = top.trakVal+'=expired; expires=Fri, 31 Dec 209911:59:59 UTC; path=/';
	if(expiryUTC <= presentUTC && notValid == null) {
		alert("A new version of this directory is now available.\nPlease contact your network administrator or \ncall"+top.orderNumber+".");
	document.cookie = cookieString;
	}
}

function openHelp()
{
	var helpWindow=window.open(href='flash/flash.htm', 'Help','width=688,height=500,toolbar=auto,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no')
	if(navigator.appName!="Netscape" && navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.charAt(navigator.appVersion.indexOf("MSIE")+5)== '4')
		top.window.blur();
	else
		helpWindow.focus();
}


var prefWindow="";
function openPreferences()
{
	prefWindow=window.open(href='preferences.htm', 'Prefs','width=150,height=220,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no')
	return prefWindow;
}

//function isClosed() { //alert(prefWindow);
//	if (prefWindow!=null) {
//		//alert("not null now");
//		if (prefWindow && !prefWindow.closed) { alert("closed"); }
//	}
//	else { setTimeout('isClosed()', 1000) }
//}


function decline() {
	top.window.close();
}

function activateBack(){
	parent.frames['logo'].document.getElementById('backoff').style.visibility = "hidden"
	parent.frames['logo'].document.getElementById('backon').style.visibility = "visible"
}
function deactivateBack(){
	parent.frames['logo'].document.getElementById('backoff').style.visibility = "visible"
	parent.frames['logo'].document.getElementById('backon').style.visibility = "hidden"
}
function activateForward(){
	parent.frames['logo'].document.getElementById('forwoff').style.visibility = "hidden"
	parent.frames['logo'].document.getElementById('forwon').style.visibility = "visible"
}
function deactivateForward(){
	parent.frames['logo'].document.getElementById('forwoff').style.visibility = "visible"
	parent.frames['logo'].document.getElementById('forwon').style.visibility = "hidden"
}

function doSwitch() {
	parent.frames['logo'].document.getElementById('otherbrowsers').style.visibility = "hidden";
	parent.frames['logo'].document.getElementById('backoff').style.visibility = "visible";
	parent.frames['logo'].document.getElementById('forwoff').style.visibility = "visible";
}

var wn = null;
var addrName = null;
var addrNumber = null;
function openAddress() {
   wn = window.open('addrBook.htm','AddressBook','toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no,width=400,height=270');
}
function openAddressWithInfo(name,phoneNumber) {

	addrName = name;
	addrNumber = phoneNumber;
	if(wn != null)
		wn.close();
     wn = window.open(top.pathPrefix+'addrBook.htm','AddressBook','toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no,width=400,height=270');
	wn.focus();
}

