function contextualwin(title, msg) {
	Tip(msg, STICKY, true, DELAY, 2000, FADEIN, 500, FADEOUT, 100, BGIMG, 'resources/images/backtranswhite.png', TITLE, title, TITLEBGCOLOR, '#BCB190', BORDERCOLOR, '#BCB190', SHADOW, true, CLOSEBTN, true);
}

function tooltip(title, url) {
	var msg = '<div id=\'tooltip\' style=\'width: 250px; padding: 0 10px 0 10px; z-index: 10 \'><img src=\'resources/images/tiny-roller.gif\'> cargando...<br><br><br>';
	contextualwin(title, msg)
// 	Tip(msg, STICKY, true, DELAY, 2000, FADEIN, 500, FADEOUT, 100, BGIMG, 'resources/images/backtranswhite.png', TITLE, title, TITLEBGCOLOR, '#BCB190', BORDERCOLOR, '#BCB190', SHADOW, true, CLOSEBTN, true);
	loadpage(url, 'tooltip');
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}

function showwaitmsg(id, id2) {
	var waiting_msg = '<img src=\'resources/images/tiny-roller.gif\'> cargando...<br><br><br>';
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', id);
	newdiv.style.position = "absolute";
	newdiv.style.background = "white";
	newdiv.style.width = document.getElementById(id2).offsetWidth + 'px';
	newdiv.style.height = document.getElementById(id2).offsetHeight + 'px';
	newdiv.style.background = "url('resources/images/backtranswhite.png')";
	newdiv.style.padding = "5px 5px 5px 5px";
	newdiv.style.top = getAbsoluteTop(id2) + 'px';
	newdiv.style.left = getAbsoluteLeft(id2) + 'px';
	newdiv.innerHTML = waiting_msg;
	document.body.appendChild(newdiv);
}

function loadpagecontent(url, div, removediv) {
	var req = new XMLHttpRequest();
	req.open("GET", url, false);
	req.send(null);
	var page = req.responseText;
	document.getElementById(div).innerHTML = page;
	if (removediv)
		document.body.removeChild(document.getElementById(div + '_wait'))
}

function loadpage(url, div, removediv) {
	if (removediv) {
		showwaitmsg(div + '_wait', div);
		setTimeout(function(){loadpagecontent(url, div, 1);}, 500);
	} else
		loadpagecontent(url, div, 0)
}

function asf_close(name) {
	document.body.removeChild(document.getElementById(name));
}

function asf_window_close(name) {
	asf_close('asf_window_' + name);
	asf_close('asf_window_background');
	document.body.style.overflow = "auto";
}

function asf_menucontextual(name, content, width, x, y) {
	// create menu
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', name);
	newdiv.setAttribute('class', "vert-menu");
// 	newdiv.setAttribute('onmouseout', "asf_close('" + name + "')");
	newdiv.style.width = width;
	newdiv.style.position = "absolute";
	newdiv.style.top = y + "px";
	newdiv.style.left = x + "px";
	newdiv.style.zIndex = 30;
	newdiv.innerHTML = document.getElementById(content).innerHTML;
	document.body.appendChild(newdiv);
}

// create background
function asf_background() {
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'asf_window_background');
	newdiv.style.position = "absolute";
	newdiv.style.top = "0px";
	newdiv.style.left = "0px";
	newdiv.style.width = "100%";
	newdiv.style.height = "100%";
	newdiv.style.zIndex = 80;
	newdiv.style.background = "url('resources/images/backtrans.png')";
	document.body.appendChild(newdiv);
}

function asf_window(title, name, width, height, url, iframe) {

	// create background
	asf_background();

	// create window
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'asf_window_' + name);
	newdiv.style.position = "absolute";
	newdiv.style.top = "0";
	newdiv.style.left = "0";
	newdiv.style.bottom = "0";
	newdiv.style.right = "0";
	newdiv.style.border = "solid 2px #E0D3AB";
	newdiv.style.margin = "auto";
	newdiv.style.width = width + "px";
	newdiv.style.height = height + "px";
	newdiv.style.background = "white";
	newdiv.style.zIndex = 90;
	var h = height - 20;
	newdiv.innerHTML = "<table width='100%' height='100%'><tr height='15'><td bgcolor='#E0D3AB'  width='99%'><strong>" + title + "</strong></td><td width='1%'><a href=\"javascript:asf_window_close('" + name + "')\"><img src='resources/images/browselist/delete_inline.gif'></a></td></tr><tr height='99%'><td colspan='2' valign='top'><div id='asf_window_content_" + name + "' style='overflow:auto;width:100%;height:" + h + "px'></div></td></tr></table>";
	document.body.appendChild(newdiv);
	document.body.style.overflow = "hidden";

	// load window content
	if (iframe)
		document.getElementById('asf_window_content_' + name).innerHTML = '<iframe border=\"0\" width=\"100%\" height=\"100%\" src=\"' + url + '\" style=\"padding: 10px 10px 10px 10px\""></iframe>';
	else
		setTimeout(function(){loadpage(url, 'asf_window_content_' + name, 1);}, 500);

}

function asf_msg_window_close() {
	asf_close('msgbox');
	asf_close('asf_window_background');
	document.body.style.overflow = "auto";
}

function asf_msg_window(msg) {
	// show background
	asf_background();

	// create window
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'msgbox');
	newdiv.style.position = "absolute";
	newdiv.style.top = "0";
	newdiv.style.left = "0";
	newdiv.style.bottom = "0";
	newdiv.style.right = "0";
	newdiv.style.margin = "auto";
	newdiv.style.zIndex = 100;
	newdiv.style.verticalAlign = "middle";
	newdiv.innerHTML = "<table width='100%' height='100%'><tr><td><img src='resources/images/messagebox_warning.png'></td><td align='center'><p style='font-size: 16px;'><strong>" + msg + "</strong></p></td></tr><tr><td colspan='2'><p><a href='JavaScript:asf_msg_window_close()' class='link_button'><img src='resources/images/browselist/delete_inline.gif'> cerrar</a></p></td></tr></table>";
	document.body.appendChild(newdiv);
	document.body.style.overflow = "hidden";
}

function asf_wait_window_close() {
	asf_close('waitwin');
	asf_close('asf_window_background');
	document.body.style.overflow = "auto";
}

function asf_wait_window(msg) {
	// show background
	asf_background();
	// create window
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'waitwin');
	newdiv.setAttribute('onclick', 'asf_wait_window_close()');
	newdiv.style.position = "absolute";
	newdiv.style.top = "0";
	newdiv.style.left = "0";
	newdiv.style.bottom = "0";
	newdiv.style.right = "0";
	newdiv.style.margin = "auto";
	newdiv.style.zIndex = 110;
	newdiv.style.verticalAlign = "middle";
	newdiv.innerHTML = "<table width='100%'><tr><td><img src='resources/images/big-roller.gif'></td><td>espere ...</td></tr></table>";
	document.body.appendChild(newdiv);
	document.body.style.overflow = "hidden";
}

function asf_ajax_action(url) {
	// show waiting window
	setTimeout(function(){asf_wait_window();}, 500);
	// create result container
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'ajaxaction_result');
	newdiv.style.position = "absolute";
	newdiv.style.top = "0";
	newdiv.style.left = "0";
	newdiv.style.top = "0";
	newdiv.style.visibility = "hidden";
	document.body.appendChild(newdiv);
	// ejecute action
	loadpagecontent(url, 'ajaxaction_result', 0)
	// close waiting window
	setTimeout(function(){asf_wait_window_close();}, 600);
	// show result
	setTimeout(function(){asf_msg_window(document.getElementById('ajaxaction_result').innerHTML);}, 700);
	setTimeout(function(){asf_close('ajaxaction_result');}, 800);
}