/**
 * (c) Copyright Ashantiplc Limited
 * All Rights Reserved
 * Duplication prohibited. Redistriubtion, Transmission, displayed by any means prohibited.
 * You may not alter or remove any trademark, copyright or other notices.
 * Author: Vyacheslav Shindin | no email
 */
function createHelpBox(id, text, parentId, xCoord, yCoord, type) {
	var obj = document.createElement("div");
	obj.setAttribute("id", "helpbox"+id);
	obj.style.position = 'relative';
	obj.style.left = xCoord + 'px';
	obj.style.top = yCoord + 'px';
	obj.style.zIndex = 7000;
	obj.onclick = function () {
		obj.style.display = 'none';
		var theDate = new Date();
		var expiryDate = new Date( "1 Jan 2550" );
		setCookie(id, 1, expiryDate, '/');
	}
	var table = '<table style="position: absolute; z-index:7000;" cellspacing="0" cellpadding="0"  width="150px" >';
	if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
		// IE
		var closeButtonStyle = ' style="position: relative; right:-3px"';
	} else {
		// Other
		var closeButtonStyle = '';
	}
	if (type == "normal") {
		table += '<tr><td style="position: static; border-bottom: 0px;" class="helpbox" width="150px"><img src="images/helpbox-close.gif" align="right"'+closeButtonStyle+' width="7" height="7" />'+text+'</td></tr> <tr><td><img src="images/helpbox-down.gif"></td></tr>';
	} else {
		table += '<tr><td><img src="images/helpbox-down-rotated.gif"></td></tr><tr><td style="position: static; border-top: 0px;" class="helpbox" width="150px"><img src="images/helpbox-close.gif" align="right"'+closeButtonStyle+' width="7" height="7" />'+text+'</td></tr>';
	}
	table+='</table>';
	obj.innerHTML = table;
	parentObj = document.getElementById(parentId);
	if (parentObj) {
		parentObj.appendChild(obj);
	}
}

function hideHelpboxes() {
	var i = 0;
	obj = document.getElementById('helpbox'+i);
	while (obj != null) {
		obj.style.visibility = 'hidden';
		obj = document.getElementById('helpbox'+(++i));
	}
}

var tooltipId = 0;
/**
 * 
 * The function for creating tooltip
 * @param  id int               - The id, to be store in cookies.
 * @param  elementId int - The element id for tooltip
 * @param  text string 	   - The text in tooltip
 * @param  xR int             - The relative x-coordinate for tooltip
 * @param  yR int             - The relative y-coordinate for tooltip
*/
function createTooltip(id, elementId, text, xR, yR){ 
	if (!document.getElementById(elementId)) return;
	var element = $("#" + elementId);
	var objStr = '<div style="cursor: pointer; display: none; position: absolute; width: 150px; " class="helpbox">' + text + '</div>';
	
	var obj = $(objStr);
	obj.attr('id', "tooltip" + tooltipId++);
	// I can't find how to get offsetLeft and offsetTop properties with jQuery
	var x = (xR ? xR : 20) + document.getElementById(elementId).offsetLeft; // 20 is default;
	var y = (yR ? yR : 20) + document.getElementById(elementId).offsetTop; // 20 is default;
	obj.css('left', x);
	obj.css('top', y);
	obj.css('opacity', 0);
	obj.appendTo(element.parent());
	obj.showed = false;
	
	element.bind('mouseover',function (event) {
		if (!obj.showed)
			obj.animate({'opacity':1}, 300);
		obj.showed = true;
	});	
	
	obj.bind('click',function (event) {
		obj.animate({'opacity':0}, 200);
		var theDate = new Date();
		var expiryDate = new Date( "1 Jan 2550" );
		setCookie(id, 1, expiryDate, '/');
	});	
}
//createTooltip("postResumeButton", "This is a resume button :)", 100, -20);