<!--//
var isIE = (document.all)? true:false;
var mouseX = 0;
var mouseY = 0;
var popupDivName = "";
var popupMaxWidth = 250;
var popupMaxHeight = 50;
var popupDiv = document.getElementById(popupDivName);
document.onmousemove = mouseMove;

function mouseMove(e) {
	if (isIE) {
		mouseX = event.x;
		mouseY = event.y;
	} else {
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	if (popupDiv && popupDiv.style && popupDiv.style.visibility == 'visible') {
		moveDiv(popupDiv);
	}
}

function showPopup() {
	inHTML = "<table cellpadding=0 cellspacing=1 height="+popupMaxHeight+" width="+popupMaxWidth+"><tr><td valign="+popupDiv.vAlign+" align="+popupDiv.hAlign+">";
	inHTML += "<table cellpadding=0 cellspacing=0 bgcolor=#000000 style='border-collapse:separate;border:1px solid black;'><tr><td style='padding-top:2px;padding-bottom:2px;padding-left:2px;padding-right:2px;background-color:#FFFFE7;'>";
	inHTML += popupDiv.srcTxt;
	inHTML += "</td></tr></table>";
	inHTML += "</td></tr></table>";
	popupDiv.innerHTML = inHTML;
	popupDiv.style.visibility = 'visible';
}

function hidePopup() {
	popupDiv.style.visibility = 'hidden';
}

function moveDiv(popupDiv) {
	if (popupDiv) {
		var windowWidth = 0;
		var windowHeight = 0;
		var scrollXOffset = 0;
		var scrollYOffset = 0;
		var XOffset = 0;
		var YOffset = 0;
		if (isIE) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
			scrollXOffset = 0;
			scrollYOffset = 0;
			XOffset = document.body.scrollLeft;
			YOffset = document.body.scrollTop;
			if (document.documentElement && document.documentElement.scrollTop)
			{
				XOffset = document.documentElement.scrollLeft;
				YOffset = document.documentElement.scrollTop;
			}
			else if (document.body)
			{
				XOffset = document.body.scrollLeft;
				YOffset = document.body.scrollTop;
			}
		} else {
			windowWidth = window.innerWidth;
			windowHeight = window.innerHeight;
			scrollXOffset = window.pageXOffset;
			scrollYOffset = window.pageYOffset;
			XOffset = 0;
			YOffset = 0;
		}
		if (mouseX+30-scrollXOffset+popupMaxWidth < windowWidth) {
			popupDiv.style.left = (mouseX+12+XOffset)+"px";
			popupDiv.style.right = "";
			popupDiv.style.width = popupMaxWidth+"px";
			if (popupDiv.hAlign != "left" || popupDiv.style.visibility != "visible") {
				popupDiv.hAlign = "left";
				showPopup(popupDiv.id);
			}
		} else {
			popupDiv.style.left = (mouseX-6-popupMaxWidth+XOffset)+"px";
			popupDiv.style.right = (0+windowWidth-mouseX)+"px";
			popupDiv.style.width = popupMaxWidth+"px";
			if (popupDiv.hAlign != "right" || popupDiv.style.visibility != "visible") {
				popupDiv.hAlign = "right";
				showPopup(popupDiv.id);
			}
		}

/* unremark this section to make the code work properly ;) - Mark
		if (mouseY+30-scrollYOffset+popupMaxHeight < windowHeight) {
			popupDiv.style.top = (mouseY+2+YOffset)+"px";
			popupDiv.style.bottom = "";
			popupDiv.style.height = popupMaxHeight+"px";
			if (popupDiv.vAlign != "top" || popupDiv.style.visibility != "visible") {
				popupDiv.vAlign = "top";
				showPopup(popupDiv.id);
			}
		} else {
*/
			if (popupDiv.vAlign == "top") {
				popupDiv.style.top = (mouseY+20+YOffset)+"px";
			} else {
				popupDiv.style.top = (mouseY-2-popupMaxHeight+YOffset)+"px";
			}
			popupDiv.style.bottom = (0+windowHeight-mouseY)+"px";
			popupDiv.style.height = (popupMaxHeight)+"px";
			showPopup(popupDiv.id);
//		}
	}
}

function stopTimer(timerID) {
	hidePopup();
	return clearTimeout(timerID);
}

function startTimer(theObj,popupDivName,txt,vAlign) {
	if (!vAlign) {
		vAlign = "bottom";
	}
	popupDiv = document.getElementById(popupDivName);
	txt = txt.replace(/\+/g," ");
	txt = unescape(txt);
	txt = txt.replace(/\n/g,"<br>");
	popupDiv.srcTxt = txt;
	popupDiv.vAlign = vAlign;
	moveDiv(popupDiv);
	theObj.timerID = setTimeout("moveDiv(popupDiv)", 1);
}

function getCompStyle(obj, styleProp, rInt) {
	var cs, prop = 'undefined';
	if(document.defaultView && document.defaultView.getComputedStyle) {
		cs = document.defaultView.getComputedStyle(obj, '');
		if (cs) { prop = cs.getPropertyValue(styleProp); }
	} else if(obj.currentStyle) {
		var propName = styleProp.split('-');
		styleProp = propName[0];
		for (var i=1; i<propName.length; ++i) {
			var ch = propName[i].charAt(0);
			styleProp += propName[i].replace(ch, ch.toUpperCase());
		}
		prop = obj.currentStyle[styleProp];
	} else { return null; }
	if (rInt) { return parseInt(prop); }
	return prop;
}

function hideFreetextSizer(pricingLineCount) {
	console.log("hideFreetextSizer::pricingLineCount=" + pricingLineCount);
	var freetextSizerDiv = document.getElementById('freetextSizerDiv_' + pricingLineCount)
	freetextSizerDiv.style.visibility = 'hidden';
}

function showFreetextSizer(pricingLineCount) {
	console.log("showFreetextSizer::pricingLineCount=" + pricingLineCount);
	var freetextSizerDiv = document.getElementById('freetextSizerDiv_' + pricingLineCount);
	var field = document.getElementById('OTHER_' + pricingLineCount);
	var inHTML = "<table cellpadding=0 cellspacing=1 height="+popupMaxHeight+" width="+popupMaxWidth+"><tr><td valign="+freetextSizerDiv.vAlign+" align="+freetextSizerDiv.hAlign+">";
	inHTML += "<table cellpadding=0 cellspacing=0 bgcolor=#000000 style='border-collapse:separate;border:1px solid black;'><tr><td style='padding-top:2px;padding-bottom:2px;padding-left:2px;padding-right:2px;background-color:#FFFFE7;'>";
	console.log("field.value=" + field.value);
	console.log("field.value.length=" + field.value.length);
	var fieldlength = field.value.length;
	if ( fieldlength == undefined ) {fieldlength= 0;};
	if ( fieldlength == 200 )
	{
		inHTML += "Maximum 200 characters allowed";
	}
	else
	{
		inHTML += (200 - fieldlength) + " characters remaining";
	}
	console.log("inHTML=" + inHTML);
	inHTML += "</td></tr></table>";
	inHTML += "</td></tr></table>";
	freetextSizerDiv.innerHTML = inHTML;
	freetextSizerDiv.style.visibility = 'visible';
}


//-->
