// Various JavaScript for SOHO-HOME-BUSINESS.COM

// [1] disable selection -{bug}- in opera comment box cannot type any text
// [2] drop in box content
// [3] highlight select/copy textarea - selection shade not clear because of [1]-disable selection
// [4] currentyear() for footer copyright
// [5] socilizeit
// [6] Selected links to new window
/* ================================================================ */
// [1]
//
// © Dynamic Drive DHTML code library (full source code @ www.dynamicdrive.com)
// This notice MUST stay intact for legal use
function disableSelection(target){
if (typeof target.onselectstart!="undefined") target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") target.style.MozUserSelect="none"
else target.onmousedown=function(){return false}
target.style.cursor = "default"
}

// [2]
// Drop-in content box- By Dynamic Drive
// For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
// This credit MUST stay intact for use

//Specify rate of display (1/freq)
var freq=5

var random_num=Math.floor(Math.random()*freq)
if (random_num==0)
window.onload=initbox
var ie=document.all
var dom=document.getElementById
var ns4=document.layers
var calunits=document.layers? "" : "px"

var bouncelimit=32 //(must be divisible by 8)
var direction="up"

function initbox(){
if (!dom&&!ie&&!ns4)
return
crossobj=(dom)?document.getElementById("dropin").style : ie? document.all.dropin : document.dropin
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
crossobj.top=scroll_top-250+calunits
crossobj.visibility=(dom||ie)? "visible" : "show"
dropstart=setInterval("dropin()",50)
}

function dropin(){
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
if (parseInt(crossobj.top)<100+scroll_top)
crossobj.top=parseInt(crossobj.top)+40+calunits
else{
clearInterval(dropstart)
bouncestart=setInterval("bouncein()",50)
}
}

function bouncein(){
crossobj.top=parseInt(crossobj.top)-bouncelimit+calunits
if (bouncelimit<0)
bouncelimit+=8
bouncelimit=bouncelimit*-1
if (bouncelimit==0){
clearInterval(bouncestart)
}
}

function dismissbox(){
if (window.bouncestart) clearInterval(bouncestart)
crossobj.visibility="hidden"
}

// use this function to call the drop down //
function redo(){
bouncelimit=32
direction="up"
initbox()
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement

: document.body
}

// window.onload=initbox // removed this to stop drop for everypage
// Drop in box end

// [3]
/*
Select and Copy form element script- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.com
*/

//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
//0=no, 1=yes
var copytoclip=1

function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
if (document.all&&copytoclip==1){
therange=tempval.createTextRange()
therange.execCommand("Copy")
window.status="Contents highlighted and copied to clipboard!"
setTimeout("window.status=''",1800)
}
}
//
// [4]
// current year for footer
function currentyear(){
a = new Date();
b = a.getYear();
  if(b >= 2000)
  {
    b -= 2000;
  }
  if(b >= 100)
  {
    b -= 100;
  }
c = "20" + (b<10?"0"+b:b);
document.write(c);
}

// SBI code extract
// [5]
// Socialize It
var socializeit = function(options) {
  if (!options || !options.domain) {
    throw new Error('Error: must pass socializeit a domain (e.g. socializeit({domain:"www.example.com"})).')
  }

  var d = document,
      l = d.location,
      e = encodeURIComponent,
      u = e(l.href),
      t = e(d.title),
      domain = options.domain,
      urlroot = 'http://www.'+domain+'/includes/objects/';

  var sites = [
    {name: 'Google',
     img: urlroot+'google.gif',
     url: 'http://www.google.com/ig/adde?moduleurl=www.google.com/ig/modules/bookmarks.xml&amp;hl=en/u='+ u +'&amp;t=' + t},
    {name: 'Buzz',
     img: urlroot+'yahoobuzz1.gif',
     url: 'http://buzz.yahoo.com/submit?submitUrl='+ u +'&amp;t=' + t},
    {name: 'Facebook',
     img: urlroot+'Facebook.jpg',
     url: 'http://www.facebook.com/share.php?u='+ u +'&amp;t=' + t},
    {name: 'Myspace',
     img: urlroot+'myspace.gif',
     url: 'http://www.myspace.com/Modules/PostTo/Pages/?u='+ u +'&amp;t=' + t},
    {name: 'StumbleUpon',
     img: urlroot+'StumbleUpon.jpg',
     url: 'http://www.stumbleupon.com/submit?url=' + u + '&amp;title=' + t},
    {name: 'Technorati',
     img: urlroot+'Technorati.jpg',
     url: 'http://technorati.com/faves/?add=' + u},
    {name: 'del.icio.us',
     img: urlroot+'del.jpg',
     url: 'http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=' + u + '&amp;title=' + t},
    {name: 'Twitter',
     img: urlroot+'twitter.gif',
     url: 'http://twitter.com/home?status=Reading%20about%20this:%20'+t+'%20-%20' + u}
  ];

  arguments.callee.getURL = function(which) {
    for (var i=0, ilen=sites.length; i<ilen; i++) {
      var site = sites[i];
      if (site.name == which) {
        return site.url;
      }
    }
  };

  var html = '<table  align="center" style="border: 1px solid #ccc;padding:2px;width:480px;"><tbody><tr><td rowspan="2" style="white-space:nowrap;"><strong>Share this page:&nbsp;</strong>';
  if (options.whatIsThisUrl) {
    html += '<br><span style="font-size:11px;"><a href="#" onclick="window.open\(\''+options.whatIsThisUrl+'\', \'sharer\',\'toolbar=0,status=0,width=700,height=500,resizable=yes,scrollbars=yes\'\); return false;">What\'s This?</a></span>';
  }
  html += '</td>';
  // visually want two rows of links
  var midpoint = Math.floor((sites.length-1)/2);
  var iCols= ((2 + midpoint) <ilen)? 2 + midpoint: ilen;

  for (var i=0, ilen=sites.length; i<ilen; i++) {
    var site = sites[i].name;
    var imgURL = sites[i].img;
    var url = sites[i].url;
    html += '<td><a href="#share_on_'+site+'" onclick="window.open(socializeit.getURL(\''+site+'\'), \'sharer\', \'toolbar=0,status=0,width=700,height=500,resizable=yes,scrollbars=yes\');return false;"><img src="'+imgURL+'" alt="'+site+'" style="border:0"></a></td>';
    if ((i == midpoint) && (i+1)<ilen) {
      html += '</tr><tr>';
    }
  }
  html += '</tr>';

  // pay it forward
  if (options.payItText) {
     var id = 'socializeit' + (new Date()).getTime() + Math.floor(Math.random() * 1e7)
     html += '<tr><td colspan="'+(midpoint+2)+'" style="background:#ccc;padding:1em;"><p style="text-align:center;margin-top:0;margin-bottom:0;"><a href="#pay_it_forward" onclick="document.getElementById(\''+id+'\').style.display=\'block\';return false;">' +
             options.payItText + '</a></p><div style="display:none;" id="'+id+'"><p>Would you prefer to share this page with others by linking to it?</p>'+
             '<ol><li>Click on the HTML link code below.</li><li>Copy and paste it, adding a note of your own, into your blog, a Web page, forums, a blog comment, your Facebook account, or anywhere that someone would find this page valuable.</li></ol><form action="#"><div style="text-align:center"><textarea cols="50" rows="2" onclick="this.select();">&lt;a href="'+l+'"&gt;'+d.title+'&lt;/a&gt;</textarea></div></form></div></td></tr>';
  }
  html += '</tbody></table>';

  document.writeln(html);
};


// [6]
/***********************************************
* Open select links in new window script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/*****************USAGE NOTES:*****************
Add: <form name="targetmain"><input type="checkbox" name="targetnew" checked onClick="applywindow(targetlinks)">Open designated links in new window</form>

anywhere on your page to automatically switch the script to manual mode, whereby only checking a checkbox will cause designated links to open in a new window. Customize the form as desired, but preserve key information such as the name attributes and onClick command. Remove form to switch back to auto mode.
***********************************************/
function new-window(){
var linktarget="_blank" //Specify link target added to links when set to open in new window

var formcache=document.targetmain

function applywindow(){
if (typeof targetlinks=="undefined") return
if (!formcache || (formcache && formcache.targetnew.checked)){
for (i=0; i<=(targetlinks.length-1); i++)
targetlinks[i].target=linktarget
}
else
for (i=0; i<=(targetlinks.length-1); i++)
targetlinks[i].target=""
}


function collectElementbyClass(){
if (!document.all && !document.getElementById) return
var linksarray=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className=="nwindow")
linksarray[inc++]=alltags[i]
if (alltags[i].className=="nwindowcontainer"){
var alldivlinks=document.all? alltags[i].all.tags("A") : alltags[i].getElementsByTagName("A")
for (t=0; t<alldivlinks.length; t++)
linksarray[inc++]=alldivlinks[t]
}
}
return linksarray
}
if (formcache && formcache.targetnew.checked) //overcome IE bug, manually check checkbox that has "checked" attribute
setTimeout("document.targetmain.targetnew.checked=true",100)
var targetlinks=collectElementbyClass()
applywindow()

} // close function

// USAGE NOTES
/*
As noted, the script lets you designate links to open in a new window using two ways:
1) Give the link a special class:
<a href="http://www.dynamicdrive.com" class="nwindow">Dynamic Drive</a>

2) Wrap groups of links in a container with a special class:

<div class="nwindowcontainer">
link 1
link 2
etc
</div>

Furthermore, you have the option of letting the visitor decide whether these links should open in a new window, by adding a checkbox to your page:

<form name="targetmain"><input type="checkbox" name="targetnew" checked
onClick="applywindow(targetlinks)">Open designated links in new window</form>

The mere presence of this checkbox will cause the script to switch to "manual" mode.
*/