<!--

// Preload Tab Images
var most_read =    new Image(); most_read.src =    "/images/most_read_on.gif";
var most_emailed = new Image(); most_emailed.src = "/images/most_emailed_on.gif";
var top_stories =  new Image(); top_stories.src =  "/images/top_stories_off.gif";

var divids=new Array('mostread','mostemailed','topstories');
var tabids=new Array('most_read','most_emailed','top_stories');


function switchid(id,tab){  
        hideallids();
        showdiv(id,tab);
}

function hideallids(){
        //loop through the array and hide each element by id
        for (var i=0;i<divids.length;i++){
                hidediv(divids[i],tabids[i]);
        }                 
}

function hidediv(id,taboff) {
        //safe function to hide an element with a specified id
        if (document.getElementById) { // DOM3 = IE5, NS6
                document.getElementById(id).style.display = 'none';
        }
        else {
                if (document.layers) { // Netscape 4
                        document.id.display = 'none';
                }
                else { // IE 4
                        document.all.id.style.display = 'none';
                }
        }
        // switch tab image to off state
        document.getElementById(taboff).src = "/images/"+taboff+"_off.gif";
}

function showdiv(id,tab) {
        //safe function to show an element with a specified id
                  
        if (document.getElementById) { // DOM3 = IE5, NS6
                document.getElementById(id).style.display = 'block';
        }
        else {
                if (document.layers) { // Netscape 4
                        document.id.display = 'block';
                }
                else { // IE 4
                        document.all.id.style.display = 'block';
                }
        }
        // switch tab image to current selection
        document.getElementById(tab).src = "/images/"+tab+"_on.gif";
}
//-->


function sfgate_un() {
    var start = document.cookie.indexOf('hd=')
    if (start == -1) {
        return '';
    }
    start +=3 ;
    var username = document.cookie.substr(start);
    var end = username.indexOf(';');
    if ( end != -1 ) {
        username = username.substr(0,end);
    }
    if ( username.length == 0 ) {
        return '';
    }
    end = username.indexOf('|');
    if ( end == -1 ) {
        return '';
    }

    return username.substr(0,end);
}

function print_sfgate_un() {
    var encodedURL = escape(window.location);
    var sfgate_user = sfgate_un();
    if (sfgate_user) {
        document.write('Hello, <span class="pipe"><a href="/cgi-bin/contribute/sn/persona?plckPersonaPage=PersonaHome&amp;plckUserId='+sfgate_user+'&amp;User='+sfgate_user+'">' + sfgate_user + '</a>');
        document.write(' | <a href="/cgi-bin/webreg/user/account?user=' +
                       sfgate_user + '">My Account</a>');
        document.write(' | <a href="/cgi-bin/webreg/user/loaccount">Sign Out</a></span>');
    } else {
        document.write('<span class="pipe"><a href="/cgi-bin/webreg/user/xaccount">Sign In</a>');
        document.write(' | <a href="/cgi-bin/webreg/user/reg_cnt">Register</a></span>');
    }
}


// oas.js
function sfgate_IsTsp() {
    var ref = document.referrer;
    var refRE = /^http:\/\/[a-z.]*sfgate\.com(\/|\/index.s?html)?$/;
    if ( ! ref.match(refRE) ) {
        return false;
    }
    var qs = window.location.search.substring(1, window.location.search.length);
    if (qs.length > 1) {
        var qarray = qs.split("&");
        var re = /^tsp=/;
        for(var i=0; i < qarray.length; i++) {
            if (qarray[i].match(re)) {
                return true;
            }
        }
    }
    return false;
}
OAS_target = '_top';
OAS_url = 'http://oascentral.sfgate.com/RealMedia/ads/';
OAS_rn = new String (Math.random()); OAS_rns = OAS_rn.substring (2, 11);
if ( sfgate_IsTsp() ) {
    OAS_page += '/tsp';
}
OAS_sitepage = 'www.sfgate.com/'+OAS_page;

function sfg_ShowListings() {
  var i=6;
  var last_item = 0;
  var lastel = zSr.length - 6;
  if (zSr.length != null) {
    document.write('\n<div class="contextualad">\n<div class="sfg_ysm001">\n');
    document.write('<h3><a href="http://searchmarketing.yahoo.com/srch/contentmatch.php" target="_new">Ads by Yahoo!</a></h3>\n');
    while (i < zSr.length) {
      if (i == lastel) {
        last_item = 1;
      }
      var descr = zSr[i++];
      var unused1 = zSr[i++];
      var clickURL = zSr[i++];
      var title = zSr[i++];
      var sitehost = zSr[i++];
      var unused2 = zSr[i++];
      if (last_item) {
        document.write('<div class="item_last">\n');
      } else {
        document.write('<div class="item">\n');
      }
      document.write('<h4><a target="_new" href="' + clickURL + '">' + title + '</a></h4>\n');
      document.write('<p><a target="_new" href="' + clickURL + '">' + descr + '</a></p>\n');
      document.write('<p class="sitehost"><a target="_new" href="' + clickURL + '">(' + sitehost + ')</a></p>\n');
      document.write('</div>\n\n');
    }
    document.write('</div>\n</div><!-- end contextual ad -->\n');
  } else {
      document.write('<!-- YSM error - no ads returned -->');
  }
}

