////////////////////////////////////////////////////////////////////
var offsetxpoint=20 //Customize x offset of tooltip
var offsetypoint=-50 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
//var enabletip=true
var calendar=false

var mx;
var my;

if(ie||ns6) var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody() {
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth) {
	if (ns6||ie) {
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e) {
	var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
	var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;
	//Find out how close the mouse is to the corner of the window
	var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
	var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
	var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -100
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<245)
		//move the horizontal position of the menu to the left by it's width
		mx=ie? ietruebody().scrollLeft+event.clientX-245 : window.pageXOffset+e.clientX-245
	else
		if (curX<leftedge) mx=5
		else
			//position the horizontal position of the menu where the mouse is positioned
			mx=curX+offsetxpoint
	//same concept with the vertical position
	if (bottomedge<225)
		my=ie? ietruebody().scrollTop+event.clientY-225-offsetypoint : window.pageYOffset+e.clientY-225-offsetypoint
	else my=curY+offsetypoint
	if(calendar) calendar.moveTo(mx,my);
}

document.onclick=positiontip

////////////////////////////////////////////////////////////////////
function open_calendar(forma, field) {
	var x=245;
	var y=225;
	URL="calendar/calendar.php?forma="+forma+"&field="+field+"&start_date="+document.forms[forma].elements[field].value;
	calendar=window.open(URL,"Calendar","width="+x+",height="+y+",top="+my+",left="+mx+",status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no");
	calendar.focus();
}
function parseData(dt, format, delim) {
	p1=dt.indexOf(delim);
	d1=dt.substring(0,p1);
	t=dt.substring(p1+1,dt.length);
	p2=t.indexOf(delim);
	d2=t.substring(0,p2);
	d3=t.substring(p2+1,t.length);
	if(format==1) {	// mm-dd-yyyy
		day=d2;
		month=d1;
		year=d3;
	} else if(format==2) {	// yyyy-mm-dd
		day=d3;
		month=d2;
		year=d1;
	} else if(format==3) {	// yyyy-dd-mm
		day=d2;
		month=d3;
		year=d1;
	} else {	// dd-mm-yyyy, default
		day=d1;
		month=d2;
		year=d3;
	}
	if(day.length==0 || month.length==0 || year.length==0) s="";
	else {
		if(day.length==1) day="0"+day;
		if(month.length==1) month="0"+month;
		if(year.length==2) year="20"+year;
		s=parseInt(""+year+month+day,10);
	}
	return s;
}
function createData(dt, format, delim) {
	p1=dt.indexOf(delim);
	d1=dt.substring(0,p1);
	t=dt.substring(p1+1,dt.length);
	p2=t.indexOf(delim);
	d2=t.substring(0,p2);
	d3=t.substring(p2+1,t.length);
	if(format==1) {	// mm-dd-yyyy
		day=d2;
		month=d1;
		year=d3;
	} else if(format==2) {	// yyyy-mm-dd
		day=d3;
		month=d2;
		year=d1;
	} else if(format==3) {	// yyyy-dd-mm
		day=d2;
		month=d3;
		year=d1;
	} else {	// dd-mm-yyyy, default
		day=d1;
		month=d2;
		year=d3;
	}
	if(day.length==0 || month.length==0 || year.length==0) s="";
	else {
		if(month.length==1) month="0"+month;
		if(year.length==2) year="20"+year;
		if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12) day=31;
		else if(month==2) day=28;
		else day=30;

		if(format==1) {	// mm-dd-yyyy
			s=month+delim+day+delim+year;
		} else if(format==2) {	// yyyy-mm-dd
			s=year+delim+month+delim+day;
		} else if(format==3) {	// yyyy-dd-mm
			s=year+delim+day+delim+month;
		} else {	// dd-mm-yyyy, default
			s=day+delim+month+delim+year;
		}
	}
	return s;
}