// popup
function openWindow(url, name, props) {
  props=props.replace(/(resizable|scrollbars)\=no/g,'$1=yes');
  new_win = window.open(url, name, props);
  new_win.focus();
}

// popup alias
function MM_openBrWindow(url, name, props) {
  openWindow(url, name, props);
}

function openVideoWindow(url, name) { openWindow(url, name, 'width=750,height=550,resizable=yes,scrollbars=auto,toolbar=no,location=no,menubar=no,status=no'); }

function closeWindow() { p_win=window.opener; if (p_win) p_win.focus(); window.close(); }

// image rollovers
var images_on = [];
var images_off = [];

function loadImages() {
  images_length = image_names.length;

  for (i = 0; i < images_length; i++) {
    imgname = siteurl + '/gnav_' + image_names[i];
    images_on[i] = new Image();
    images_on[i].src = imgname + '_h.gif';
    images_off[i] = new Image();
    images_off[i].src = imgname + '.gif';
  }
}

function globalNavChangeOn(index,name) {
  imgOn = images_on[index];
  if (imgOn)
    document[name].src = imgOn.src;
}

function globalNavChangeOff(index,name) {
  imgOff = images_off[index];
  if (imgOff)
    document[name].src = imgOff.src;
}

// generic image rollover
function changeImageOn(url,name) {
  image_on = new Image();
  image_on.src = url;
  document[name].src = image_on.src;  
}

function changeImageOff(url,name) {
  image_off = new Image();
  image_off.src = url;
  document[name].src = image_off.src;
}

function windowLoaded() {
  loadImages();
}

function clearSearch(field) {
  if (field.value == "Search...") {
    field.value = "";
  }
}

function runSearchQuery(form) {
  form = document.globalSearchForm;
  selection = form.gs_options.value;
  if (selection == "archives") {
    form.action ="http://www.newslibrary.com/nlsearch.asp";
    form.search_text.value = form.text.value;
    form.submit();
  } 
  if (selection == "web") {
    form.q.value = form.text.value;
    form.gBtn.value = "Search";
    form.action = "http://google-search.boston.com"
    form.submit();
  }
  else {
    form.submit();
  }
}

// cookie functions
function setCookie(name,value,expires,path,domain,secure){document.cookie=name+'='+escape(value)+((expires)?';expires='+expires.toGMTString():'')+';path='+((path)?path:'/')+';domain='+((domain)?domain:'boston.com')+((secure)?';secure':'');}
function getCookie(name){var dc=document.cookie,prefix=name+'=',begin=dc.indexOf('; '+prefix);if(begin==-1){begin=dc.indexOf(prefix);if(begin!=0)return null;}else begin+=2;var end=dc.indexOf(';',begin);if(end==-1)end=dc.length;return unescape(dc.substring(begin+prefix.length,end));}
function expireCookie(name,path,domain){document.cookie=name+'=;expires=Thu, 01-Jan-70 00:00:01 GMT;path='+((path)?path:'/')+';domain='+((domain)?domain:'boston.com');}

// registration
function showLogin(twidth){
  if(!twidth)twidth=191;
  var cookie1=getCookie('pathAuth'),cookie2=getCookie('pathAuthSess');
  document.writeln('<table width="'+twidth+'" cellpadding="0" cellspacing="0" border="0" style="border-top: 1px solid #ffcc33; border-bottom: 1px solid #ffcc33;"><tr><td align="center" style="background: #f7efce url(\'http://cache.boston.com/bonzai-fba/File-Based_Image_Resource/spacer_f7efce.gif\') repeat;"><div style="font-family: arial,helvetica,sans-serif; font-size: 8pt; padding: 3px 0px;">');
  if(cookie1!=null||cookie2!=null){document.writeln('<span style="font-weight: bold; padding-right: 8px;"><a href="?__goto=mcenter" style="text-decoration: none; color: #000066;">Member Center</a></span> | <span style="padding-left: 8pt;"><a href="?__goto=logout" style="color: #000066;">Log Out</a></span>');}
  else{document.writeln('<span style="font-weight: bold; padding-right: 8px;"><a href="?__goto=loginonlypage" style="text-decoration: none; color: #000066;">Sign In</a></span> | <span style="padding-left: 8pt;"><a href="?__goto=loginpage" style="color: #000066;">Register Now</a></span>');}
  document.writeln('</div></td></tr></table>');
}
