// Used for pages with strict doctypes (i.e. no target="_blank")
// Automagically adds them back in to links with rel="external"

function externalLinks() {
 var popupdetails = 'toolbar=no,menubar=no,height=400,width=600,location=no,scrollbars=yes,resizable=no,status=no,left=30,top=30';
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") { anchor.target = "_blank";  }
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup") {
    var subscribeURL = anchor.getAttribute('href');
    anchor.onkeypress = function(){window.open(this.href, 'SubscribeWindow',popupdetails); return false; }
    anchor.onclick = function(){window.open(this.href, 'SubscribeWindow',popupdetails); return false; }
    }
  }
}
page_onload(externalLinks);

/* JAVASCRIPT ONLINE CLOCK 
function checkTime(i) {
  if (i<10)  { i="0" + i; }
  return i;
}
function GetTime(t) {
  if (document.getElementById) {
    clock = document.getElementById(t);
    if(clock) {
    window.setTimeout( "GetTime('"+t+"')", 1000 );
    d = new Date();
    var weekdays=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var months=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    day = weekdays[d.getDay()];
    date = d.getDate();
    month = months[d.getMonth()];
    year = d.getFullYear();
    hours = checkTime(d.getHours());
    mins = checkTime(d.getMinutes());
    secs = checkTime(d.getSeconds());
    clock.innerHTML = day + " " + date + " " + month + " " + year + " | " + hours + ":" + mins + ":" + secs;
    }
  }
}*/
//page_onload(function() { GetTime("time") });


var ie = document.all; // IE Test
// Gets around the problem of having multiple onload handlers ----------------------------------
// http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
// http://www.quirksmode.org/js/events_advanced.html

function addEvent(obj, evType, fn) {

    // W3C type of event registration model
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    // MS event registration model
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    // Bad browsers that cant do either
    } else {
        return false;
    }
}


// DISPLAY OR HIDE CERTAIN ELEMENTS BY ID
function showItem(id,force) {
  if (document.getElementById) {
    obj = document.getElementById(id);
    if(obj) {
      if(force) { if(!obj.className.match(force)) { obj.className = obj.className + " " + force; } }
      else { 
        if(obj.className.match("hidden")) { obj.className = obj.className.replace(/hidden/, "shown"); }
        else if (obj.className.match("shown")) {  obj.className = obj.className.replace(/shown/,"hidden");  }
        else {obj.className = obj.className + " shown"; }
      }
    }
  }
}
function warmItem(id,force) {
//  alert('Warm Item: ' + id);
  if (document.getElementById) {
    obj = document.getElementById(id);
    if(obj) {
      if(force) { obj.className = obj.className + " " + force;}
      else { 
        if(obj.className.match("cool")) { obj.className = obj.className.replace(/cool/, "warm"); }
        else if (obj.className.match("warm")) {  obj.className = obj.className.replace(/warm/,"cool");  }
        else {obj.className = obj.className + " warm"; }
      }
    }
  }
}

function showItems(portion,className) {
  if(document.getElementById) {
    var divs = document.getElementsByTagName("div");
    for(var i=0;i<divs.length; i++) { 
      var div = divs[i];
      var thisid = new String(div.getAttribute("id"));
      if(thisid.match(portion)) { showItem(thisid,className); }
    }
    var h4s = document.getElementsByTagName("h4");
    for(var i=0;i<h4s.length; i++) { 
      var h4 = h4s[i];
      var thish4 = new String(h4.getAttribute("id"));
      if(thish4.match(portion)) { showItem(thish4,className); }
    }
    setTabs(className);
  }
}



// EMAIL OBLITARATOR //
var blit={
  dc:function(i){var o="",c1,c2,c3,e1,e2,e3,e4,j=0,k="gNAkZGdEiV3jM7QXORxrfJKvzps";i=i.replace(/[^A-Za-z0-9+\/=]/g,"");k+="1ucwTyU092H4l658I+tDmPYBonbLqSaWehCF/=";while(j<i.length){e1=k.indexOf(i.charAt(j++));e2=k.indexOf(i.charAt(j++));e3=k.indexOf(i.charAt(j++));e4=k.indexOf(i.charAt(j++));c1=(e1<<2)|(e2>>4);c2=((e2&15)<<4)|(e3>>2);c3=((e3&3)<<6)|e4;o=o+String.fromCharCode(c1);if(e3!=64){o=o+String.fromCharCode(c2);}if(e4!=64){o=o+String.fromCharCode(c3);}}return o;
  }
};


function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
// if cookie exists
    if (offset != -1) {
    offset += search.length
// set index of beginning of value
    end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
    if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
    }
  }
  return returnvalue;
}

function setTabs(v){
  document.cookie="tabs="+v;
}

function checkCookie(n) {
  if(get_cookie(n)) { 
    showItems('segment',get_cookie(n));
  }
}

//page_onload(function() { checkCookie("tabs") });



function showNav(id,parent) {
  if (!document.getElementById) return;
  hideLvl (parent);
  obj = document.getElementById(id);
  if(obj) { obj.className = "shown"; }
}

function hideLvl(parent) {
  switch(parent) {
    case 'Company':
      document.getElementById('Investment').className = "hidden";
      document.getElementById('Agency').className = "hidden";
      document.getElementById('Asset').className = "hidden";
      document.getElementById('Professional').className = "hidden";
    break;
    case 'Properties':
      document.getElementById('Let').className = "hidden";
      document.getElementById('Review').className = "hidden";
      document.getElementById('Let').className = "hidden";
    break;
    default:
      document.getElementById('Company').className = "hidden";
      document.getElementById('Properties').className = "hidden";
      document.getElementById('Retailers').className = "hidden";
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function MM_popupMsg(msg) { //v1.0
  alert(msg);
}


