var tbl_schema = (("https:" == document.location.protocol) ? "https://" : "http://")
var tbl_site_base_url="www.thebestlinks.com/";
var tbl_images_base_url= (("https:" == document.location.protocol) ? tbl_schema+tbl_site_base_url+'images/' : "http://wd.thebestlinks.com/images/");
var tbl_btn_base_url=tbl_schema+"b.thebestlinks.com/";
var d = new Date();
var currentHour = d.getHours(); //note 0-23

var tbl_formShown = false;
if (typeof(tbl_btn_updated)!=='undefined') { 
    var tbl_btn_updated = false;
}
function tbl_update_btn() {
    if (!tbl_btn_updated) {
        var elems = document.getElementsByTagName('span')
        if (elems) {
            for (var i = 0; i < elems.length; i++) {
                if (elems[i].id == 'tbl' || (elems[i].firstChild!=null && elems[i].firstChild.nodeName.toLowerCase()=="a" && elems[i].firstChild.href=='http://'+tbl_site_base_url)) {
                    var tbl = elems[i]
                    if (typeof(label)!=='undefined') {
                        tbl.innerHTML = '<span style="position: relative; border: 0"><img border="0" src="'+tbl_btn_base_url+'button.cgi?btn='+btn+'&r='+escape(document.referrer)+((typeof(screen)=='undefined')?'':'&s='+screen.width+'-'+screen.height+'-'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+'&u='+escape(document.URL)+((typeof(navigator)=='undefined')?'':'&b='+navigator.appName+'&bv='+navigator.appVersion)+ (typeof(rid) !== 'undefined'?'&rid='+rid:'') + '&rn='+Math.random()+'" style="cursor: hand; cursor: pointer; vertical-align:middle;" onclick="tbl_display_form(null)">' 
//if ((currentHour == 2) | (currentHour == 3) | (currentHour == 4) | (currentHour == 5) | (currentHour == 6) | (currentHour == 7) | (currentHour == 23) | (currentHour == 22) | (currentHour == 1))
// {

// }
						+
                        (typeof(label)!=='undefined'?'&nbsp;<span onclick="tbl_display_form(null)" style="cursor: hand; cursor: pointer; text-decoration: underline">'+label+'</span>':'')+
                        '</span>';
                    } else {
                        tbl.innerHTML = '<span style="position: relative; border: 0"><img border="0" src="'+tbl_btn_base_url+'button.cgi?btn='+btn+'&r='+escape(document.referrer)+((typeof(screen)=='undefined')?'':'&s='+screen.width+'-'+screen.height+'-'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+'&u='+escape(document.URL)+((typeof(navigator)=='undefined')?'':'&b='+navigator.appName+'&bv='+navigator.appVersion)+ (typeof(rid) !== 'undefined'?'&rid='+rid:'') + '&rn='+Math.random()+'" style="cursor: hand; cursor: pointer;" onclick="tbl_display_form(null)">'
//if ((currentHour == 2) | (currentHour == 3) | (currentHour == 4) | (currentHour == 5) | (currentHour == 6) | (currentHour == 7) | (currentHour == 23) | (currentHour == 22) | (currentHour == 1))
// {

// }
						+
                        '</span>';
                    }
                }
            }
        }
        tbl_btn_updated = true;
    }
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function get_window_size2() {   
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth,myHeight];
}
function is_quirks(){return document.compatMode=='BackCompat'}


function tbl_embed_form() {
    if (document.getElementById('tbl_div')!=null)
        return null;
    if (is_quirks()) {
        winSize=get_window_size2();        
    }
    
    var d = document.createElement('div');
    d.innerHTML = (
    (is_quirks()?'<div id="tbl_div" style="position: absolute; overflow: hidden; left: 0; top: 0; width:'+winSize[0]+'px; height: '+winSize[1]+'px; display: none; z-index: 100001; padding: 0px; border: 0;">\
    <div style="border: 0;left: 0; top: 0; width:100%; height: 100%; z-index: 100001; padding: 0px; background-color: black; opacity: 0.7;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);-moz-opacity: 0.7;-khtml-opacity: 0.7" onclick="tbl_hide_form()">\
    </div>':
        '\
    <div id="tbl_div" style="position: fixed; left: 0; top: 0; width:100%; height: 100%; display: none; z-index: 100001; padding: 0px; border: 0;">\
    <div style="border: 0;position: fixed; left: 0; top: 0; width:100%; height: 100%; z-index: 100001; padding: 0px; background-color: black; opacity: 0.7;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);-moz-opacity: 0.7;-khtml-opacity: 0.7;" onclick="tbl_hide_form()">\
    </div>')

     +
    '<div style="opacity: 1; -moz-opacity: 1; -khtml-opacity: 1; position: absolute; border: 0; width: 372px; left: 50%; top: 50%; margin-left: -186px; margin-top: -200px; z-index: 100002">\
    <form id="tbl_form" name="tbl_form" action="http://'+ tbl_site_base_url+'loc/subscribe" method="post" style="margin:0px;padding:0px;" target="_blank">\
    <input id="tbl_url" maxlength="255" name="url" size="40" type="hidden" />\
    <table dir="ltr" border="0" cellspacing="0" cellpadding="0" style="width:372px; border: 0;opacity: 1; ">\
  <tr>\
    <td style="border: 0;padding: 0px;margin:0px;width:33px;height:33px;background:url('+tbl_images_base_url+'widget_sprh.png);background-position: -471px 0px;"></td>\
    <td align="left" style="border: 0;padding: 0px;margin:0px;height:33px;background:url('+tbl_images_base_url+'widget_sprv.png) repeat-x; background-position: 0px -33px; font-style: normal;font-size:11px;color:#CCC;vertical-align:bottom;line-height: normal"><div style="padding-bottom: 3px"><div style="float: left; padding-bottom: 3px"><a href="http://www.thebestlinks.com/"  target="_blank" style="font-family:verdana,arial,sans-serif;font-size:11px;font-style: normal;color: #CCC; text-decoration: none; font-weight: normal">thebestlinks.com</a></div><div style="float: right; padding-bottom: 3px"><a href="javascript:void(0)"  onclick="tbl_hide_form()" style="font-family:verdana,arial,sans-serif;font-size:11px;font-style: normal;color: #CCC; text-decoration: none; font-weight: normal">close</a></div></div></td>\
    <td style="border: 0;padding: 0px;margin:0px;width:23px;height:33px;background:url('+tbl_images_base_url+'widget_sprh.png);background-position: -504px 0px;"></td>\
    <td style="border: 0;padding: 0px;margin:0px;width:32px;height:33px;background:url('+tbl_images_base_url+'widget_sprh.png);background-position: -527px 0px;"></td>\
  </tr>\
  <tr>\
    <td style="border: 0;padding: 0px;margin:0px;width:33px;background:url('+tbl_images_base_url+'widget_sprh.png) repeat-y;background-position: -383px 0px;"></td>\
    <td style="border: 0;padding: 0px;margin:0px;background:#e6e6e6;text-align: center">\
    <div style="border: 0;margin:16px 0;font-family:Arial Black;font-size:24px;font-weight:normal;font-style: normal;color:#333;line-height:30px;text-align: left;">get notified when page is updated</div>\
    <input id="tbl_email" maxlength="255" name="email" size="15" style="border: 0;width:100%;background:url('+tbl_images_base_url+'widget_sprh.png) left top no-repeat #FFF; background-position: 0px 0px; border:0; font-size:16px; color:#999; margin: 0px; padding: 6px 0 6px 5px; line-height: normal" type="text" value="your email"/>\
    <div style="border: 0;padding-top:20px;text-align:center;"><input  id="tbl_submit" name="commit" type="submit" value="get updates" style="border: 0;background:#fd5a5b;font-size:20px;color:#FFF;font-family:Arial Black;text-decoration:none;z-index:100;padding:0 10px;height: 32px;; width: auto"></div>\
    </td>\
    <td style="border: 0;padding: 0px;margin:0px;width:23px;background:url('+tbl_images_base_url+'widget_sprh.png) repeat-y;background-position: -416px 0px;"></td>\
    <td style="vertical-align: top; border: 0;padding: 0px;margin:0px;width:32px;background:url('+tbl_images_base_url+'widget_sprh.png) repeat-y;background-position: -439px 0px;">\
        <img src="'+tbl_images_base_url+'widget_stats.png" width="32" height="144" alt="view statistics" style="border: none" usemap="#tbl_stats_map"/>\
    </td>\
  </tr>\
  <tr>\
    <td style="border: 0;padding: 0px;margin:0px;width:33px;height:33px;background:url('+tbl_images_base_url+'widget_sprh.png);background-position: -295px 0px;"></td>\
    <td style="border: 0;padding: 0px;margin:0px;height:33px;background:url('+tbl_images_base_url+'widget_sprv.png) repeat-x;background-position: 0px 0px;"></td>\
    <td style="border: 0;padding: 0px;margin:0px;width:23px;height:33px;background:url('+tbl_images_base_url+'widget_sprh.png);background-position: -328px 0px;"></td>\
    <td style="border: 0;padding: 0px;margin:0px;width:32px;height:33px;background:url('+tbl_images_base_url+'widget_sprh.png);background-position: -351px 0px;"></td>\
  </tr>\
</table>\
<map name="tbl_stats_map"><area shape="rect" coords="0,0,23,134" href="http://'+tbl_site_base_url+'directory/search_by_referrer" alt="view statistics" title="view link statistics"/></map>\
</form>\
</div>\
</div>');
    return d;
}

function getEvent(event) {
    if (event!=null) {
        return event;
    } else {
        return window.event;
    }
}

function getEventTarget(event) {
    ev = getEvent(event);
    if (ev.target!=null) {
        return ev.target;
    } else {
        return ev.srcElement;
    }

}

function tbl_form_submit(event) {    
    if (!tbl_validate_email(document.getElementById('tbl_email').value)) {
        alert("Please enter a valid email address");
        return false;
    } else {
        tbl_hide_form();
        return true;
    }
}

function tbl_validate_email(email) {
    var r=/^([\w\-\+!#%\*\=\?\^\{\}\|~]+(?:\.[\w\-\+!#%\*\=\?\^\{\}\|~]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    return r.test(email);
}
function detectBrowser()
{
    return navigator.appName;
}
function tbl_reset_email_field(event) {
    if (getEvent(event).type=='focus') {
        if (detectBrowser()=="Microsoft Internet Explorer")
            if (getEventTarget(event).value=='your email') getEventTarget(event).select();
        else
            if (getEventTarget(event).value=='your email') getEventTarget(event).value='';
    } else if (getEvent(event).type=='blur') {
        if (getEventTarget(event).value=='') getEventTarget(event).value='your email';
    } else if (getEvent(event).type=='submit') {
        if (getEventTarget(event).value=='your email') getEventTarget(event).value='';
    }
    return true;
}

function tbl_hide_form() {
    document.getElementById('tbl_div').style.display='none';
    document.getElementById('tbl_email').onfocus=null;
    document.getElementById('tbl_email').onblur=null;
    document.getElementById('tbl_form').onsubmit=null;
    tbl_formShown=false;
}
function tbl_display_form(useUrl) {
    if (!tbl_formShown) {
        tbl_formShown = true;
        if (is_quirks()) {
            scrolls=getScrollXY();
            document.getElementById('tbl_div').style.left = scrolls[0];
            document.getElementById('tbl_div').style.top = scrolls[1];
        }
        if (useUrl==null)
            document.getElementById('tbl_form').url.value=document.URL;
        else
            document.getElementById('tbl_form').url.value=useUrl;
        document.getElementById('tbl_div').style.display='block';
        document.getElementById('tbl_email').focus();
        document.getElementById('tbl_email').select();
        
        document.getElementById('tbl_form').onsubmit=tbl_form_submit;
        document.getElementById('tbl_email').onfocus=tbl_reset_email_field;
        document.getElementById('tbl_email').onblur=tbl_reset_email_field;
    }
}
function tbl_preloadimages(){
    var tbl_images=new Array()
    for (i=0;i<tbl_preloadimages.arguments.length;i++){
        tbl_images[i]=new Image()
        tbl_images[i].src=tbl_preloadimages.arguments[i]
    }
}

if (typeof(tbl_onReady)=='undefined') {
    tbl_onReady = (function(ie){
     var d = document;
     return ie ? function(c){
       var n = d.firstChild,
        f = function(){
         try{
          c(n.doScroll('left'))
         }catch(e){
          setTimeout(f, 10)
         }
        }; f()
      } :
      /webkit|safari|khtml/i.test(navigator.userAgent) ? function(c){
       var f = function(){
         /loaded|complete/.test(d.readyState) ? c() : setTimeout(f, 10)
        }; f()
      } :
      function(c){
       d.addEventListener("DOMContentLoaded", c, false);
      }
    })(/*@cc_on 1@*/);
    tbl_onReady(function(){
      var tbl_form_div = tbl_embed_form();
      if (tbl_form_div!=null) {
        document.body.appendChild(tbl_form_div);
        window.setTimeout("tbl_preloadimages(tbl_images_base_url+'widget_sprh.png',tbl_images_base_url+'widget_sprv.png',tbl_images_base_url+'widget_stats.png');",1);
      }
      tbl_update_btn();
    });
}

