function _byID(id)
{
  return document.getElementById(id);
}

function alert1()
{
  alert('test');
}

function configPopup(id, newTitle, newWidth, newHeight)
{
  var popup = _byID(id);
  with (popup.style) {
    width = newWidth + 'px';
    height = newHeight + 'px';
  }
  _byID(id + '_title').innerHTML = newTitle;
  centerLayer(id);
}

function centerLayer(id)
{
  iLeft = parseInt(_byID(id).style.left);
  iTop = parseInt(_byID(id).style.top);

  lWidth = parseInt(_byID(id).style.width);
  lHeight = parseInt(_byID(id).style.height);

  if (String(navigator.userAgent).toLowerCase().search(/gecko/) != -1) {
    cWidth = window.innerWidth;
    cHeight = window.innerHeight;

    xOffset = window.pageXOffset;
    yOffset = window.pageYOffset;

  } else {
    cWidth = document.body.clientWidth;
    cHeight = document.body.clientHeight;

    xOffset = document.body.scrollLeft;
    yOffset = document.body.scrollTop;

  }
  _byID('screenFade').style.height = ((window.Enumerable && window.Enumerable.max)
      ? [document.body.scrollHeight, document.documentElement.scrollHeight,
          document.body.offsetHeight, document.documentElement.clientHeight]
          .max()
      : document.documentElement.scrollHeight) + 'px';
  _byID('screenFade').style.width = ((window.Enumerable && window.Enumerable.max)
      ? [document.body.scrollWidth, document.documentElement.scrollWidth,
          document.body.offsetWidth, document.documentElement.clientHeight]
          .max()
      : document.documentElement.scrollWidth) + 'px';

  var lLeft = Math.round((cWidth - lWidth) / 2) + xOffset;
  var lTop = Math.round((cHeight - lHeight) / 2) + yOffset;

  if (lLeft < 0)
    lLeft = 0;
  if (lTop < 0)
    lTop = 0;

  hDiff = lLeft - iLeft;
  vDiff = lTop - iTop;

  if (Math.abs(hDiff) > Math.abs(vDiff)) {
    hStep = Math.round(hDiff / vDiff) * (Math.abs(hDiff) / hDiff);
    vStep = 1 * (Math.abs(vDiff) / vDiff);
  } else {
    vStep = Math.round(vDiff / hDiff) * (Math.abs(vDiff) / vDiff);
    hStep = 1 * (Math.abs(hDiff) / hDiff);
  }

  cTop = iTop;
  cLeft = iLeft;

  slideLayerTo(id, lLeft, lTop);
}

function slideLayerTo(id, cLeft, cTop)
{
  new Effect.Move(id, {
    x :cLeft,
    y :cTop,
    mode :'absolute'
  });
}

function fadePopup()
{
  new Effect.Fade('popupContent', {
    duration :'0.3'
  });
  new Effect.Fade('screenFade', {
    duration :'0.1'
  });

}

function resizeMyPage()
{
  if (String(navigator.userAgent).toLowerCase().search(/gecko/) != -1) {
    cHeight = window.innerHeight;
  } else {
    cHeight = document.documentElement.clientHeight;
  }
  _byID('mybiz_page').style.height = (cHeight - 108) + 'px';

  if (_byID('screenFade')) {
    _byID('screenFade').style.height = ((window.Enumerable && window.Enumerable.max)
        ? [document.body.scrollHeight, document.documentElement.scrollHeight,
            document.body.offsetHeight, document.documentElement.clientHeight]
            .max()
        : document.documentElement.scrollHeight) + 'px';
    _byID('screenFade').style.width = ((window.Enumerable && window.Enumerable.max)
        ? [document.body.scrollWidth, document.documentElement.scrollWidth,
            document.body.offsetWidth, document.documentElement.clientHeight]
            .max()
        : document.documentElement.scrollWidth) + 'px';
  }

}

var currentrating = 0;

function getposOffset(overlay, offsettype)
{
  var totaloffset = (offsettype == "left")
      ? overlay.offsetLeft
      : overlay.offsetTop;
  var parentEl = overlay.offsetParent;
  while (parentEl != null) {
    totaloffset = (offsettype == "left")
        ? totaloffset + parentEl.offsetLeft
        : totaloffset + parentEl.offsetTop;
    parentEl = parentEl.offsetParent;
  }
  return totaloffset;
}

function overlay(curobj, subobjstr, opt_position)
{
  if (document.getElementById) {
    var subobj = document.getElementById(subobjstr);
    // subobj.style.display=(subobj.style.display!="block")? "block" : "none"
    subobj.style.display = "block";
    // var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined"
    // && opt_position.indexOf("right")!=-1)?
    // -(subobj.offsetWidth-curobj.offsetWidth) : 0)
    var xpos = getposOffset(document.getElementById("content"), "left") + 2;
    var ypos = getposOffset(curobj, "top")
        + 2
        + ((typeof opt_position != "undefined" && opt_position
            .indexOf("bottom") != -1) ? curobj.offsetHeight : 0);
    subobj.style.left = xpos + "px";
    subobj.style.top = ypos + "px";
    return false;
  } else {
    return true;
  }
}

function overlay4mybizz_tips(curobj, subobjstr)
{
  if (document.getElementById) {
    var subobj = document.getElementById(subobjstr);
    subobj.style.display = "block";
    var xpos = getposOffset(curobj, "left") + 75;
    var ypos = getposOffset(curobj, "top") + curobj.offsetHeight;
    subobj.style.left = xpos + "px";
    subobj.style.top = ypos + "px";
    return false;
  } else {
    return true;
  }
}

function overlay4videos(subobjstr)
{
  if (document.getElementById) {
    var subobj = document.getElementById(subobjstr);
    subobj.style.display = "block";
    var xpos = getposOffset(document.getElementById("top_videos_div"), "left")
        + 2 + (subobjstr == "dropdown4community_videos" ? 166 : 0)
        + (subobjstr == "dropdown4video_categories" ? 83 : 0);
    var ypos = getposOffset(document.getElementById("top_videos_div"), "top")
        + document.getElementById("top_videos_div").offsetHeight - 8;
    subobj.style.left = xpos + "px";
    subobj.style.top = ypos + "px";
    return false;
  } else {
    return true;
  }
}

function overlay4events(curobj, icount, opt_position)
{
  var agt = navigator.userAgent.toLowerCase();
  var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
  if (document.getElementById) {
    for ( var i = 1; i <= 7; i++) {
      var div2close = document.getElementById("icons4events" + i);
      if (div2close) {
        overlayclose("icons4events" + i);
      }
    }
    var subobj = document.getElementById("icons4events" + icount);
    subobj.style.display = "block";
    var xpos = getposOffset(curobj, "left") - 82;
    var ypos = getposOffset(curobj, "top")
        + ((typeof opt_position != "undefined" && opt_position
            .indexOf("bottom") != -1) ? curobj.offsetHeight : 0)
        - (is_ie ? 2 : 0);
    subobj.style.left = xpos + "px";
    subobj.style.top = ypos + "px";
    return false;
  } else {
    return true;
  }
}

function overlay4blogs(subobjstr)
{
  if (document.getElementById) {
    var subobj = document.getElementById(subobjstr);
    subobj.style.display = "block";
    var xpos = getposOffset(document.getElementById("question_mark"), "left") - 222;
    var ypos = getposOffset(document.getElementById("question_mark"), "top")
        + document.getElementById("question_mark").offsetHeight - 43;
    subobj.style.left = xpos + "px";
    subobj.style.top = ypos + "px";
    return false;
  } else {
    return true;
  }
}

function overlayclose(subobj)
{
  document.getElementById(subobj).style.display = "none";
}

var cl_close_timer;
function counties_listings_close()
{
  cl_close_timer = setTimeout("overlayclose('listings_counties')", 5000);
}

function reset_cl_timer()
{
  clearTimeout(cl_close_timer);
}

function change_picture4video_page(picture)
{
  if (picture == 1) {
    document.video_listing_top_videos.src = '/images/video_listing_top_videos.gif';
    document.video_listing_categories.src = '/images/video_listing_categories.gif';
    document.video_listing_community.src = '/images/video_listing_community.gif';
  } else if (picture == 2) {
    document.video_listing_top_videos.src = '/images/video_listing_top_videos_white.gif';
    document.video_listing_categories.src = '/images/video_listing_categories_grey.gif';
    document.video_listing_community.src = '/images/video_listing_community.gif';
  } else if (picture == 3) {
    document.video_listing_top_videos.src = '/images/video_listing_top_videos_white.gif';
    document.video_listing_categories.src = '/images/video_listing_categories.gif';
    document.video_listing_community.src = '/images/video_listing_community_grey.gif';
  }
}

function place_w_rolodex_list(ev)
{
  var wrlist = document.createElement('div');
  wrlist.setAttribute('id', 'w_rolodex_entrylist');
  document.body.appendChild(wrlist);

  with (_byID('w_rolodex_entrylist').style) {
    position = 'absolute';
    visibility = 'visible';
    backgroundColor = '#fff';
    width = '200px';
    height = '330px';
    overflow = 'auto';
    left = (ev.clientX - 20) + 'px';
    top = (ev.clientY - 20) + 'px';
    zIndex = '100000';
    padding = '10px';
    border = '1px solid #ccc';
  }

  if (window.document.all) {
    _byID('w_rolodex_entrylist').attachEvent('onclick', remove_w_rolodex_list);
  } else {
    _byID('w_rolodex_entrylist').addEventListener('click',
        remove_w_rolodex_list, false);
  }

}

function remove_w_rolodex_list()
{
  document.body.removeChild(_byID('w_rolodex_entrylist'));
}

function addOption(id, value, text)
{
  var option = document.createElement('option');
  option.value = value;
  option.text = text;
  _byID(id).appendChild(option);
}

function addOptionV2(id, value, text)
{
  var myEle = document.createElement('option');
  myEle.setAttribute('value', value);
  var txt = document.createTextNode(text);
  myEle.appendChild(txt);
  document.getElementById(id).appendChild(myEle);
}

function deleteOption(id, value)
{
  for ( var i = 0; i < _byID(id).options.length; i++) {
    if (_byID(id).options[i].value == value)
      _byID(id).options[i] = null;
  }
}

var flash_stack = '.';
function restore_flashes()
{
  var flashes = flash_stack.substr(1, flash_stack.length - 2).split('.');
  for ( var i = 0; i < flashes.length; i++) {
    _byID(flashes[i]).style.display = 'block';
  }

  flash_stack = '.';
}

function pausescroller(content, divId, divClass, delay)
{
  this.content = content; // message array content
  this.tickerid = divId; // ID of ticker div to display information
  this.delay = delay; // Delay between msg change, in miliseconds.
  this.mouseoverBol = 0; // Boolean to indicate whether mouse is currently over
                          // scroller (and pause it if it is)
  this.hiddendivpointer = 1; // index of message array for hidden div
  document
      .write('<div id="'
          + divId
          + '" class="'
          + divClass
          + '" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'
          + divId
          + '1">'
          + content[0]
          + '</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'
          + divId + '2">' + content[1] + '</div></div>');
  var scrollerinstance = this;
  if (window.addEventListener) // run onload in DOM2 browsers
  {
    window.addEventListener("load", function()
    {
      scrollerinstance.initialize();
    }, false);
  } else if (window.attachEvent) // run onload in IE5.5+
  {
    window.attachEvent("onload", function()
    {
      scrollerinstance.initialize();
    });
  } else if (document.getElementById) // if legacy DOM browsers, just start
                                      // scroller after 0.5 sec
  {
    setTimeout( function()
    {
      scrollerinstance.initialize();
    }, 500);
  }
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize = function()
{
  this.tickerdiv = document.getElementById(this.tickerid);
  this.visiblediv = document.getElementById(this.tickerid + "1");
  this.hiddendiv = document.getElementById(this.tickerid + "2");
  this.visibledivtop = parseInt(pausescroller.getCSSpadding(this.tickerdiv));
  // set width of inner DIVs to outer DIV's width minus padding (padding assumed
  // to be top padding x 2)
  this.visiblediv.style.width = this.hiddendiv.style.width = this.tickerdiv.offsetWidth
      - (this.visibledivtop * 2) + "px";
  this.getinline(this.visiblediv, this.hiddendiv);
  this.hiddendiv.style.visibility = "visible";
  var scrollerinstance = this;
  document.getElementById(this.tickerid).onmouseover = function()
  {
    scrollerinstance.mouseoverBol = 1;
  };
  document.getElementById(this.tickerid).onmouseout = function()
  {
    scrollerinstance.mouseoverBol = 0;
  };
  if (window.attachEvent) // Clean up loose references in IE
  {
    window
        .attachEvent(
            "onunload",
            function()
            {
              scrollerinstance.tickerdiv.onmouseover = scrollerinstance.tickerdiv.onmouseout = null;
            });
  }
  setTimeout( function()
  {
    scrollerinstance.animateup();
  }, this.delay);
};

// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup = function()
{
  var scrollerinstance = this;
  if (parseInt(this.hiddendiv.style.top) > (this.visibledivtop + 5)) {
    this.visiblediv.style.top = parseInt(this.visiblediv.style.top) - 5 + "px";
    this.hiddendiv.style.top = parseInt(this.hiddendiv.style.top) - 5 + "px";
    setTimeout( function()
    {
      scrollerinstance.animateup();
    }, 50);
  } else {
    this.getinline(this.hiddendiv, this.visiblediv);
    this.swapdivs();
    setTimeout( function()
    {
      scrollerinstance.setmessage();
    }, this.delay);
  }
};

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs = function()
{
  var tempcontainer = this.visiblediv;
  this.visiblediv = this.hiddendiv;
  this.hiddendiv = tempcontainer;
};

pausescroller.prototype.getinline = function(div1, div2)
{
  div1.style.top = this.visibledivtop + "px";
  div2.style.top = Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)
      + "px";
};

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's
// visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage = function()
{
  var scrollerinstance = this;
  if (this.mouseoverBol == 1) // if mouse is currently over scoller, do nothing
                              // (pause it)
  {
    setTimeout( function()
    {
      scrollerinstance.setmessage();
    }, 100);
  } else {
    var i = this.hiddendivpointer;
    var ceiling = this.content.length;
    this.hiddendivpointer = (i + 1 > ceiling - 1) ? 0 : i + 1;
    this.hiddendiv.innerHTML = this.content[this.hiddendivpointer];
    this.animateup();
  }
};

pausescroller.getCSSpadding = function(tickerobj)
{ // get CSS padding value, if any
  if (tickerobj.currentStyle) {
    return tickerobj.currentStyle["paddingTop"];
  } else if (window.getComputedStyle) // if DOM2
  {
    return window.getComputedStyle(tickerobj, "").getPropertyValue(
        "padding-top");
  } else {
    return 0;
  }
};

function change_featured_news(news_count)
{
  for ( var i = 0; i < 4; i++) {
    var news2highlight = document.getElementById("news_box_little" + i);
    if (news2highlight) {
      news2highlight.className = (i == news_count)
          ? 'featured_4news_withbg'
          : 'featured_4news_nobg';
    }
    var news2show = document.getElementById("news_box_big" + i);
    if (news2show) {
      news2show.style.display = (i == news_count) ? 'block' : 'none';
    }
  }
}

function updateBDescriptionSize()
{
  csize = _byID('user_business_description').value.length;
  _byID('bdescription_size').innerHTML = csize;
  if (csize > 320) {
    _byID('bdescription_size').style.color = '#f00';
  } else {
    _byID('bdescription_size').style.color = '#929292';
  }
}

function friendly_url(str)
{
  var r1 = /\&/g;
  var r2 = /([^\w]+)/g;
  var r3 = /([-]+)/g;
  var r4 = /^(-*)/;
  var r5 = /(-*)$/;

  str = str.replace(r1, '-and-');
  str = str.replace(r2, '-');
  str = str.replace(r3, '-');
  str = str.replace(r4, '');
  str = str.replace(r5, '');

  return str.toLowerCase();
}

function getPropertyValue(elm, property)
{
  if (document.all) { //IE
    return elm.currentStyle[property];
  } else { //Moz.
    return document.defaultView.getComputedStyle(elm, null).getPropertyValue(
        property, null);
  }
}

