function setListeners() {

	adjustWidth();
	addEvent(window, 'resize', adjustWidth, false);
	var diaryblock = document.getElementById("diaryblock");
	if (diaryblock) {
	var tds = diaryblock.getElementsByTagName("td");
		for (var i = 0; i < tds.length; i++) {
			if (tds[i].className=="showstate") {
				tds[i].onmouseover = diaryOn;
				tds[i].onmouseout = diaryOff;
			}
		}
	}
	
	if (document.getElementById('diaryspans')) {
		var diarySpans = document.getElementById('diaryspans').getElementsByTagName('div');
		for (var i = 0; i < diarySpans.length; i++) {
			if (diarySpans[i].className=="linkcursor") {
				el = diarySpans[i];
				for (var j = 0; j < el.childNodes.length; j++) {
					
					if (el.childNodes[j].nodeName.toLowerCase()=='div') {
						diarySpans[i].onmouseover = showToolTip;
						diarySpans[i].onmouseout = hideToolTips;
					}
				}
			}
		}
	}

}

function showToolTip() {
	this.className="linkcursori";
	for (i = 0; i < this.childNodes.length; i++) {
		if (this.childNodes[i].nodeName.toLowerCase() == 'div') {
			this.childNodes[i].style.display="block";
		}
	}
}
function hideToolTips() {
	this.className="linkcursor";
	for (i = 0; i < this.childNodes.length; i++) {
		if (this.childNodes[i].nodeName.toLowerCase() == 'div') {
			this.childNodes[i].style.display="none";
		}
	}
}

function addEvent(elm, evType, fn, useCapture) {
  if (elm.addEventListener) { 
    elm.addEventListener(evType, fn, useCapture); 
    return true; 
  } else if (elm.attachEvent) { 
    var r = elm.attachEvent('on' + evType, fn); 
    return r; 
  } else {
    elm['on' + evType] = fn;
  }
}

function diaryOn() {
	this.className="showstateover";
}
function diaryOff() {
	this.className="showstate";
}

function expandcontent(curobj, cid){
	var browser=navigator.appName;
if (browser == "Netscape" || browser == "Opera") {
	document.getElementById(cid).style.display="table-row";
	document.getElementById(curobj).style.display="none";
} else {
	document.getElementById(cid).style.display="block";
	document.getElementById(curobj).style.display="none";
}
}

function confirmSubmit()
{
var agree=confirm("Are you sure you wish to delete this item?");
if (agree)
	return true ;
else
	return false ;
}

function hidebar() {
	document.getElementById("diaryblock").style.display="none";
	document.getElementById("nodiary").style.display="block";
	document.getElementById("content").style.marginRight="10px";
	createCookie("sidebar","false",30);
	adjustWidth();
}
function showbar() {
	document.getElementById("diaryblock").style.display="block";
	document.getElementById("nodiary").style.display="none";
	document.getElementById("content").style.marginRight="200px";
	createCookie("sidebar","true",30);
	adjustWidth();
}



function adjustWidth() {
	if (document.getElementById("column1")) {
		if (xWidth("content")<450){
			//1 column
			document.getElementById("column1").style.width="100%";
			document.getElementById("column2").style.width="100%";
			document.getElementById("column2").style.position="relative";
			document.getElementById("column2").style.left="0px";
			document.getElementById("col1div").style.paddingRight="0";
			document.getElementById("col2div").style.paddingLeft="0";
			//document.getElementById("columnhack").style.paddingRight="0px";
		} else {
			//2 columns
				var browser=navigator.appName;

			document.getElementById("column1").style.width="50%";
			if (browser == "Netscape" || browser == "Opera") {
			document.getElementById("column2").style.width="50%";
			} else {
			document.getElementById("column2").style.width="32%";
			}
			document.getElementById("column2").style.position="absolute";
			document.getElementById("column2").style.left="50%";
			//document.getElementById("column2").style.right="100%";
			document.getElementById("col1div").style.paddingRight="5px";
			document.getElementById("col2div").style.paddingLeft="5px";
			//document.getElementById("columnhack").style.paddingRight="10px";
		}
	}
}

function xWidth(e,w)
{
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(w)) {
    if (w<0) w = 0;
    else w=Math.round(w);
  }
  else w=-1;
  var css=xDef(e.style);
  if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    w = xClientWidth();
  }
  else if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
    if(w>=0) {
      var pl=0,pr=0,bl=0,br=0;
      if (document.compatMode=='CSS1Compat') {
        var gcs = xGetComputedStyle;
        pl=gcs(e,'padding-left',1);
        if (pl !== null) {
          pr=gcs(e,'padding-right',1);
          bl=gcs(e,'border-left-width',1);
          br=gcs(e,'border-right-width',1);
        }
        // Should we try this as a last resort?
        // At this point getComputedStyle and currentStyle do not exist.
        else if(xDef(e.offsetWidth,e.style.width)){
          e.style.width=w+'px';
          pl=e.offsetWidth-w;
        }
      }
      w-=(pl+pr+bl+br);
      if(isNaN(w)||w<0) return;
      else e.style.width=w+'px';
    }
    w=e.offsetWidth;
  }
  else if(css && xDef(e.style.pixelWidth)) {
    if(w>=0) e.style.pixelWidth=w;
    w=e.style.pixelWidth;
  }
  return w;
}

function xGetComputedStyle(oEle, sProp, bInt)
{
  var s, p = 'undefined';
  var dv = document.defaultView;
  if(dv && dv.getComputedStyle){
    s = dv.getComputedStyle(oEle,'');
    if (s) p = s.getPropertyValue(sProp);
  }
  else if(oEle.currentStyle) {
    // convert css property name to object property name for IE
    var a = sProp.split('-');
    sProp = a[0];
    for (var i=1; i<a.length; ++i) {
      c = a[i].charAt(0);
      sProp += a[i].replace(c, c.toUpperCase());
    }   
    p = oEle.currentStyle[sProp];
  }
  else return null;
  return bInt ? (parseInt(p) || 0) : p;
}

function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xStr(s)
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}

function xNum()
{
  for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
  return true;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



window.onload = setListeners;

