var nidcache="";

function bookmark(url,title) {
  pvaddress="/bookmark/?url="+location.href;
  if(pageTracker!='undefined') {pageTracker._trackPageview(pvaddress);}
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function re(nid,channel) {
  if(nid!="") {
      if(channel!="") {
	  trackvaddress="/newsclick?channel="+channel+"&nid="+nid+"&refurl="+location.href;
	  if(pageTracker!='undefined') {
	      pageTracker._trackPageview(trackvaddress);
	      pageTracker._trackEvent("Newsclick","External",channel+"");
	  }
      }
  }
}

function sharet() {
    trackvaddress="/sharethis?refurl="+location.href;
    if(pageTracker!='undefined') {pageTracker._trackPageview(trackvaddress);}
}


function ol(nid) {
    if(nid!="") {
	if(nid!=nidcache) {
	  window.location.href="/load.php?nid="+nid;
	  nidcache=nid;
	}
    }
}

function ot(nid) {
    if(nid!="") {
        if(nid!=nidcache) {
	  nidcache=nid;
	  return true;
        } else {
	  return false;
        }
    }
}

function showslotmenu(slotid) {
    if(slotid>0) {
	idstrslot='islot'+slotid;
	if(document.getElementById(idstrslot) != null) {
	    document.getElementById(idstrslot).innerHTML=slotchangehtml.replace(/SLOTID/g,slotid);
        }
    }
}

function changeslot(slotid,content) {
    if(slotid>0) {
	if(content!="") {
	     seturl="/index.php?mode=NDK&setslot="+slotid+"&content="+content;
	     location.href=seturl;
	}
    }
}

function getcookie(check_name) {
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false;

    for ( i = 0; i < a_all_cookies.length; i++ )
	{
	    a_temp_cookie = a_all_cookies[i].split( '=' );
	    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	    if ( cookie_name == check_name )
		{
		    b_cookie_found = true;
		    if ( a_temp_cookie.length > 1 )
			{
			    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
		    return cookie_value;
		    break;
		}
	    a_temp_cookie = null;
	    cookie_name = '';
	}
    if ( !b_cookie_found )
	{
	    return null;
	}
}

function ticker_start() {
    if(document.getElementById("TICKER") != null) {
      var tSup = false;
      tickercontent = document.getElementById("TICKER").innerHTML;

      // Firefox
      if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
         	document.getElementById("TICKER").innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'><SPAN class=tickerbody ID='TICKER_BODY' width=100%>&nbsp;</SPAN></TD></TR></TABLE>";
	  tSup = true;
      }
      // IE
      if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
	  document.getElementById("TICKER").innerHTML = "<DIV nowrap='nowrap' style='width:100%;'><SPAN class=tickerbody ID='TICKER_BODY' width=100%></SPAN></DIV>";
	  tSup = true;
      }

      if(!tSup) {
	  document.getElementById("TICKER").outerHTML = "";
      } else {
	  document.getElementById("TICKER").scrollLeft = 0;
	  document.getElementById("TICKER_BODY").innerHTML = tickercontent;
	  document.getElementById("TICKER").style.display="block";
	  ticktheticker();
      }
    }
}

function ticktheticker() {
    document.getElementById("TICKER").scrollLeft += 1;
    if(document.getElementById("TICKER").scrollLeft >= document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth) {
	document.getElementById("TICKER").scrollLeft = 0;
    }
    window.setTimeout("ticktheticker()", 40);
}

function reltime(timval) {
    var parsed = Date.parse(timval);
    var relto = (arguments.length>1)?arguments[1]:new Date();
    var dlt = parseInt((relto.getTime()-parsed)/1000);
    if(dlt<60) {return 'less than a minute ago';}
    else if(dlt<120) {return 'about a minute ago';}
    else if(dlt<(45*60)) {return (parseInt(dlt/60)).toString()+' minutes ago';}
    else if(dlt<(90*60)) {return 'about an hour ago';}
    else if(dlt<(24*60*60)) {return 'about '+(parseInt(dlt/3600)).toString()+' hours ago';}
    else if(dlt<(48*60*60)) {return '1 day ago';}
    else {return (parseInt(dlt/86400)).toString()+' days ago';
    }
}
