// JavaScript Document
var FIELD_FOCUS="focus";
var FIELD_BLUR="blur";

if(!document.getElementById){
	if(!document.all){
		document.getElementById=function(id){
			return(document.layers[id]);
		}
	}else{
		document.getElementById=function(id){
			return(document.all[id]);
		}
	}
}

function gravy_duplicate(str,num) {
	ret = "";
	for (var c = 1; c<=num; c++) {
		ret += str;
	}
	return (ret);
}

function gravy_insertStr(strToInsert, strDestination, afterCharInd) {
	return (strDestination.substring(0, afterCharInd)+strToInsert+strDestination.substring(afterCharInd));
}

function gravy_round(n, dp, f) {
	dp = (dp == null) ? 2 : dp;
	var num = Math.round(n*Math.pow(10, dp))/Math.pow(10, dp);
	var arNum = num.toString().split(".");
	if (arNum.length == 1) {
		arNum.push(gravy_duplicate("0", dp));
	} else if (arNum[1].length != dp) {
		arNum[1] += gravy_duplicate("0", dp-arNum[1].length);
	}
	if (f) {
		for (var roundC = arNum[0].length; roundC>=1; roundC -= 3) {
			arNum[0] = (roundC<arNum[0].length) ? gravy_insertStr(",", arNum[0], roundC) : arNum[0];
		}
	}
	if (dp<1) {
		return (arNum[0]);
	} else {
		return (arNum[0]+"."+arNum[1]);
	}
}

function helper_default_value(field,text,axn){
	if(axn==FIELD_FOCUS){
		if(field.value==text){
			field.value="";
		}
	}else{
		if(field.value==""){
			field.value=text;
		}
	}
}

function urldecode(value){
	var result=unescape(value);
	result=result.replace(/\+/gi," ");
	return(result);
}

function getMouseXY(e){
	e=e||window.event;
	var cursor=false;
	if(e.pageX||e.pageY){
		cursor={"x":0,"y":0};
		cursor.x=e.pageX;
		cursor.y=e.pageY;
	}else if(e.clientX||e.clientY){
		cursor={"x":0,"y":0};
		var de=document.documentElement;
		var b=document.body;
		cursor.x=e.clientX+(de.scrollLeft || b.scrollLeft)-(de.clientLeft||0);
		cursor.y=e.clientY+(de.scrollTop || b.scrollTop)-(de.clientTop || 0);
	}
	return(cursor);
}

function showToolTip(evnt,elm,text,relativeToMouse,offsetX,offsetY){
	relativeToMouse=(relativeToMouse==null)?true:relativeToMouse;
	offsetX=(offsetX==null)?10:offsetX;
	offsetY=(offsetY==null)?20:offsetY;
	var tt=document.getElementById(elm);
	if(tt){
		tt.style.display="block";
		tt.innerHTML=text;
		if(relativeToMouse){
			cursor=getMouseXY(evnt);
			if(cursor){
				tt.style.position="absolute";
				tt.style.zIndex="1765";
				tt.style.left=(cursor.x+offsetX)+"px";
				tt.style.top=(cursor.y+offsetY)+"px";
			}
		}
	}
}

function hideToolTip(elm){
	var tt=document.getElementById(elm);
	if(tt){
		tt.style.display="none";
	}
}
