function showPopup(textlength,alignpos){
	alength = textlength.length;
	boxpos = alignpos;
}

addLoadEvent(prepareInputsForHints);

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
  	window.onload = func;
  } else {
  	window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("a");
	for (var i=0; i<inputs.length; i++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
				this.parentNode.getElementsByTagName("span")[0].style.position = "absolute";
				this.parentNode.getElementsByTagName("span")[0].style.left = findPosX(this) + "px";
				this.parentNode.getElementsByTagName("span")[0].style.top = findPosY(this) + "px";
		}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}


function findPosX(obj)
 {
	if (alength<=10){
    	var curleft = (100+alength);
	} else if (alength<=20 && alength>10){
		var curleft = (alength*2+100);
	} else {
		var curleft = alength*6+100
	}
	if (boxpos=="left") {
		curleft = curleft*(-1)*2.95
	} else {
		curleft = curleft*0.97
	}
	if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}


function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
