﻿// global vars for dev
//var _yothost = 'http://localhost:57123';
var _yothost='http://www.yotify.com';
//var _yothost='http://dev.bnalerts.com:800';
//var _yothost = '';
// _yotstate is an object for tracking state of requests and other client-side action
if (typeof _yotstate==="undefined"){
  var _yotstate={
    visible:false,
    rollover:false
  }
}
// _yotutils is an object with some utility methods
if(typeof _yotutils==="undefined"){
  var _yotutils={
    host:_yothost,
    afpage: '/af/afv3.aspx',
    ropage: '/utils/rollover.htm',
    get:function(id){
      // helper util for getting element by id
      return document.getElementById(id);
    },
    removeHTMLTags: function(text) {
        /* 
        This line is optional, it replaces escaped brackets with real ones, 
        i.e. < is replaced with < and > is replaced with >
        */
        text = text.replace(/&(lt|gt);/g, function(strMatch, p1) {
            return (p1 == "lt") ? "<" : ">";
        });
        var strTagStrippedText = text.replace(/<\/?[^>]+(>|$)/g, "");
        return strTagStrippedText;
    }
  }
}
// _yotwin is an object that contains params and methods for the popup
if(typeof _yotwin==="undefined"){
  var _yotwin={
    divid:"yotaf_div",
    iframeid:"yotaf_iframe",
    anchorid:"yotaf_anchor",
    roiframeid: "yotaf_ro_iframe",
    toid: null,
    show:function(elt){
      // show the element
        elt.style.display="block";
      _yotstate.visible=true;
    },
    close:function(){
      // close the window
      var div=_yotutils.get(_yotwin.divid);
      if(div){
        div.style.display="none";
      }
      _yotstate.visible=false;
    },
    clearto:function(){
      // clear the timeout if it exists
      if(_yotwin.toid!==null){
        clearTimeout(_yotwin.toid);
      }
    },
    getpos:function(elt){
      // get the position of the elt element
      var x=0,y=0;
      while (elt != null){
        x+=elt.offsetLeft;
        y+=elt.offsetTop;
        elt=elt.offsetParent;
      }
      return [x,y];
    },
    getwsize:function(){
      // get the vertical & horizontal size of the window
      var w=window,
          d=document,
          de=d.documentElement,
          db=d.body;
      if(typeof (w.innerWidth)=="number"){
        return [w.innerWidth,w.innerHeight];
      }else{
        if(de&&(de.clientWidth||de.clientHeight)){
          return [de.clientWidth,de.clientHeight];
        }else{
          if(db&&(db.clientWidth||db.clientHeight)){
            return [db.clientWidth,db.clientHeight];
          }else{
            return [0,0];
          }
        }
      }
    },
    getspos:function(){
      // get the vertical & horizontal scroll position
      var w=window,
          d=document,
          de=d.documentElement,
          db=d.body;
      if(typeof (w.pageYOffset)=="number"){
        return [w.pageXOffset,w.pageYOffset];
      }else{
        if(db&&(db.scrollLeft||db.scrollTop)){
          return [db.scrollLeft,db.scrollTop];
        }else{
          if(de&&(de.scrollLeft||de.scrollTop)){
            return [de.scrollLeft,de.scrollTop];
          }else{
            return [0,0];
          }
        }
      }
    }    
  }
}
// the following are functions used in the mouse element events on the page
function askfriend_open(anchor,tab){
  _yotwin.clearto(); //clear the timeout in case the close command had been issued
  if (!_yotstate.visible){
    _yotwin.close();
    var _vhtoff=16; // offset
    var _elt=_yotutils.get(anchor);
    var _img=_elt.getElementsByTagName("img");
    if(_img&&_img[0]){
      _elt=_img[0];
      _vhtoff=0;
    }
    // position and show the dialog
    if (tab==''){
      tab=_yotwin.divid;
    }
    _div=_yotutils.get(tab);
    var _eltpos=_yotwin.getpos(_elt),
        _left=_eltpos[0]+addthis_offset_left,
        _top=_eltpos[1]+_vhtoff+1+addthis_offset_top,
        _winsize=_yotwin.getwsize(),
        _scrollpos=_yotwin.getspos();
    _yotwin.show(_div);
    if(_left-_scrollpos[0]+_div.clientWidth+20>_winsize[0]){
      _left=_left-_div.clientWidth+50;
    }
    if(_top-_scrollpos[1]+_div.clientHeight+_elt.clientHeight+20>_winsize[1]){
      _top=_top-_div.clientHeight-20;
    }
    _div.style.left=_left+"px";
    _div.style.top = (_top + _elt.clientHeight) + "px";
    //set src on rollover iframe
    if (!_yotstate.rollover) {
        var ro = _yotutils.get(_yotwin.roiframeid);
        var rosrc = _yothost + _yotutils.ropage + "?u=" + encodeURI(location.href) + "&pi=" + encodeURI(askfriend_partner);
        ro.setAttribute("src", rosrc);
        _yotstate.rollover = true;
    }
  }
}
function askfriend_close(){
  // set a 1 second delay before closing the window
  _yotwin.toid=setTimeout("_yotwin.close()",1000);
}
// the following runs on load of script
(function() {
    try {
        // these are widget configurable params
        if (typeof addthis_offset_top !== "number") {
            addthis_offset_top = 0;
        }
        if (typeof addthis_offset_left !== "number") {
            addthis_offset_left = 0;
        }
        if (typeof askfriend_partner === "undefined") {
            askfriend_partner = '';
        }
        // add the iframe to the page
        var d = document;
        var src = _yothost + _yotutils.afpage + "?u=" + encodeURI(location.href) + "&pi=" + encodeURI(askfriend_partner) + "&t=" + encodeURI(_yotutils.removeHTMLTags(document.title));
        //create the widget iframe
        var str = "<div id=\"" + _yotwin.divid + "\" onmouseover=\"_yotwin.clearto()\" onmouseout=\"askfriend_close()\" style=\"position:absolute; display:none; z-index:1000;\" >";
        str += "<iframe id=\"" + _yotwin.iframeid + "\" frameborder=\"0\" style=\"height: 150px; width: 353px;\" scrolling=\"no\" src=\"" + src + "\"></iframe>\n";
        str += "</div>\n";
        _yot_div = d.createElement("div");
        _yot_div.innerHTML = str;
        d.body.insertBefore(_yot_div, d.body.firstChild);
        _yot_div.style.zIndex = 1000000;
        //create the rollover iframe
        str = "<div style=\"display:none; z-index:-1000;\">";
        str += "<iframe id=\"" + _yotwin.roiframeid + "\" frameborder=\"0\" style=\"height: 1px; width: 1px;\" scrolling=\"no\"></iframe>\n";
        str += "</div>\n";
        _yot_div = d.createElement("div");
        _yot_div.innerHTML = str;
        d.body.insertBefore(_yot_div, d.body.firstChild);
        _yot_div.style.zIndex = -1000000;    
    }
    catch (e) {
    }
})();