addWindowEvent("onload", function() {
      preloadFooterImages();
      preloadChangeEditionImages();
    });

function backToArchives(url) {
  if(document.referrer && /^http:\/\/(www.)?urbandaddy.com/.test(document.referrer)) {
    history.go(-1);
  } else
    document.location.href = url;
}

function preloadFooterImages() {
  var names = new Array("home", "archives", "aboutus", "myaccount", "aboutus", "contact", "jobs", "adv", "tips", "subscribe");
  for(var i=0;i<names.length;i++) {
    preloadImage("/images/footer/" + names[i] + "_on.gif");
  }
}

function preloadChangeEditionImages() {
  MM_preloadImages("/images/buttons/change_edition_nyc_on.gif");
  MM_preloadImages("/images/buttons/change_edition_nyc_off.gif");
  MM_preloadImages("/images/buttons/change_edition_la_on.gif");
  MM_preloadImages("/images/buttons/change_edition_la_off.gif");
  MM_preloadImages("/images/buttons/change_edition_lv_on.gif");
  MM_preloadImages("/images/buttons/change_edition_lv_off.gif");
  MM_preloadImages("/images/buttons/change_edition_sfo_on.gif");
  MM_preloadImages("/images/buttons/change_edition_sfo_off.gif");
  MM_preloadImages("/images/buttons/change_edition_chi_on.gif");
  MM_preloadImages("/images/buttons/change_edition_chi_off.gif");
}


function tagArticleReferrer(aElem) {
  aElem.href += "/";
  return true;
}

function activateEditionOption(img) {
  var edition = (img.src.indexOf("nyc")>=0)?"nyc":"la";
  img.src = "/images/buttons/change_edition_" + edition + "_on.gif";
}

function deactivateEditionOption(img) {
  var edition = (img.src.indexOf("nyc")>=0)?"nyc":"la";
  img.src = "/images/buttons/change_edition_" + edition + "_off.gif";
}

function rolloverEditionOption(aElem) {
  var img = aElem.firstChild;
  var edition = (img.src.indexOf("nyc")>=0)?"nyc":"la";
  activateEditionOption(img);

  var otherImg = $("change_edition_" + ((edition=="nyc")?"la":"nyc"));
  deactivateEditionOption(otherImg);
}

function rolloutEditionOption(aElem) {
  var img = aElem.firstChild;
  var edition = (img.src.indexOf("nyc")>=0)?"nyc":"la";
  deactivateEditionOption(img);

  var currentImg = $("change_edition_" + currentEditionName);
  activateEditionOption(currentImg);
}

function changeEdition(editionName) {
  currentEditionName = editionName;
  var button_la, button_nyc, button_lv, button_sf, button_chi, button_ntl;
  if(button_la = $("change_edition_la")) {
    button_la.src = "/images/buttons/change_edition_la_" + ((editionName=="la")?"on":"off") + ".gif";
  }
  if(button_nyc = $("change_edition_nyc")) {
    button_nyc.src = "/images/buttons/change_edition_nyc_" + ((editionName=="nyc")?"on":"off") + ".gif";
  }
  if(button_lv = $("change_edition_lv")) {
    button_lv.src = "/images/buttons/change_edition_lv_" + ((editionName=="lv")?"on":"off") + ".gif";
  }
  if(button_sf = $("change_edition_sf")) {
    button_lv.src = "/images/buttons/change_edition_sfo_" + ((editionName=="sfo")?"on":"off") + ".gif";
  }
  if(button_chi = $("change_edition_chi")) {
    button_chi.src = "/images/buttons/change_edition_chi_" + ((editionName=="chi")?"on":"off") + ".gif";
  }
  if(button_ntl = $("change_edition_ntl")) {
    button_ntl.src = "/images/buttons/change_edition_ntl_" + ((editionName=="ntl")?"on":"off") + ".gif";
  }

  var url = "/home/" + editionName;

  if(document.location.href.indexOf("/archives")>=0) {
    url = "/archives/" + editionName;
    var params = document.location.href.substring(document.location.href.indexOf("/archives/")+10);
    params = params.split("/");
    if(params.length>=2 && !parseInt(params[1]) && params[1]!="search") {
      url += "/" + params[1];
    }
  }

  document.location.href = url;
}


var showingEditionSelector = false;



function _reallyHideEditionSelector() {
  if(showingEditionSelector) return;

  var editionSelector = $("change-edition-selector");
  editionSelector.style.display = "none";

}


function hoverFooter(aElem) {
  if(aElem && aElem.firstChild) {
    if(!aElem.firstChild.src || aElem.firstChild.src.indexOf("_on")>=0) return;

    var newSrc = aElem.firstChild.src.substring(0, aElem.firstChild.src.indexOf(".gif")) + "_on.gif";
    aElem.firstChild.src = newSrc;
  }
}

function unhoverFooter(aElem) {
  if(aElem && aElem.firstChild) {
    if(!aElem.firstChild.src || aElem.firstChild.src.indexOf("_on")<0) return;

    var newSrc = aElem.firstChild.src.substring(0, aElem.firstChild.src.indexOf("_on.gif")) + ".gif";
    aElem.firstChild.src = newSrc;
  }
}


// Quirksmode.org simple cookie utils:

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  } else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/; domain=.urbandaddy.com";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
  createCookie(name,"",-1);
}


var _preloadedImages = new Array();

function preloadImage(src) {
  var img = new Image();
  img.src = src;
  _preloadedImages[_preloadedImages.length] = img;
}

function swapImage(imgId, src) {
  document.getElementById(imgId).src = src;
}

function isValidEmail(email) {
  return (typeof email == "string") && email.match(/^[^@ ]+@[^@ ]+\.[^@ ]+$/);
}


// MACROMEDIA FUNCTIONS

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); if (obj) obj.value = newText;
}

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

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}



function addWindowEvent(event_name, function_to_add) {
  var current_event = window[event_name];

  //dbg("adding "+function_to_add+" to "+current_event);

  if (typeof(current_event) != 'function') {
    window[event_name] = function_to_add;

  } else {
    window[event_name] = function() {
      current_event();
      function_to_add();
    };
  }
} // END: addWindowEvent()

function $(id) {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

function popChromeless(url, width, height) {
  window.open(url, "popChromeless", "width=" + width + ",height=" + height + ",status=no,toolbar=no,menubar=no,location=no,resizable=yes");
}

function addSelectOption(sel, val, label) {
  var opt = new Option(label, val);
  sel.options[sel.options.length] = opt;
  return opt;
}


function removeAllSelectOptions(sel) {
  for(var i=sel.options.length-1;i>=0;i--) {
    removeSelectOption(sel, i);
  }
}

function removeSelectOption(sel, i) {
  sel.options[i] = null;
}

function setSelectedOption(sel, val) {
  for(var i=0;i<sel.options.length; i++) {
    if(sel.options[i].value==val) {
      sel.selectedIndex = i;
      break;
    }
  }
}

function swapSelectOptions(sel, index1, index2) {
  var text1 = sel.options[index1].text;
  var val1 = sel.options[index1].value;
  sel.options[index1].text = sel.options[index2].text;
  sel.options[index1].value = sel.options[index2].value;
  sel.options[index2].text = text1;
  sel.options[index2].value = val1;
  if(sel.selectedIndex==index1) {
    sel.selectedIndex = index2;
  } else if(sel.selectedIndex==index2) {
    sel.selectedIndex = index1;
  }
}

function array_remove(a, index) {
  var newA = new Array();
  for(var i=0;i<a.length;i++) {
    if(i!=index)
      newA.push(a[i]);
  }
  return newA;
}

function checkCookiesEnabled(callbackName) {
  var iframe = document.createElement("IFRAME");
  iframe.style.display = "none";
  document.body.appendChild(iframe);
  iframe.src = "/cookie_detect_frame.php?callbackName=" + callbackName;
}

function changeEditionNew(edition)
{
    if(edition == "nyc")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_on.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_off.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_off.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_off.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_off.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_off.gif"
    }

    if(edition == "la")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_off.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_on.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_off.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_off.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_off.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_off.gif"
    }

    if(edition == "ntl")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_off.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_off.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_on.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_off.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_off.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_off.gif"
    }

    if(edition == "lv")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_off.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_off.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_off.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_off.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_off.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_on.gif"
    }

    if(edition == "sfo")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_off.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_off.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_off.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_on.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_off.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_off.gif"
    }

    if(edition == "chi")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_off.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_off.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_off.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_off.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_on.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_off.gif"
    }
}

function hideEditionSelector(edition) {

  showingEditionSelector = false;
    if(edition == "nyc")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_on.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_off.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_off.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_off.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_off.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_off.gif"
    }

    if(edition == "la")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_off.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_on.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_off.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_off.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_off.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_off.gif"
    }

    if(edition == "ntl")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_off.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_off.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_on.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_off.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_off.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_off.gif"
    }

    if(edition == "lv")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_off.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_off.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_off.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_off.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_off.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_on.gif"
    }

    if(edition == "sfo")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_off.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_off.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_off.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_on.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_off.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_off.gif"
    }

    if(edition == "chi")
    {
     document.getElementById('change_edition_nyc').src="/images/buttons/change_edition_nyc_off.gif"
     document.getElementById('change_edition_la').src="/images/buttons/change_edition_la_off.gif"
     document.getElementById('change_edition_ntl').src="/images/buttons/change_edition_ntl_off.gif"
     document.getElementById('change_edition_sfo').src="/images/buttons/change_edition_sfo_off.gif"
     document.getElementById('change_edition_chi').src="/images/buttons/change_edition_chi_on.gif"
     document.getElementById('change_edition_lv').src="/images/buttons/change_edition_lv_off.gif"
    }

  setTimeout("_reallyHideEditionSelector();", 200);
}

function showEditionSelector() {
  var editionSelector = $("change-edition-selector");
  editionSelector.style.display = "block";

  showingEditionSelector = true;

}
function hoverFooter(aElem) {
  if(aElem && aElem.firstChild) {
    if(!aElem.firstChild.src || aElem.firstChild.src.indexOf("_on")>=0) return;

    var newSrc = aElem.firstChild.src.substring(0, aElem.firstChild.src.indexOf(".gif")) + "_on.gif";
    aElem.firstChild.src = newSrc;
  }
}

function unhoverFooter(aElem) {
  if(aElem && aElem.firstChild) {
    if(!aElem.firstChild.src || aElem.firstChild.src.indexOf("_on")<0) return;

    var newSrc = aElem.firstChild.src.substring(0, aElem.firstChild.src.indexOf("_on.gif")) + ".gif";
    aElem.firstChild.src = newSrc;
  }
}