﻿function activeMenu(id, active)
{
	var td = document.getElementById(id);
	if (td != null)
	{
		if (active)
			td.className = td.className.replace('_off', '_on');
		else
			td.className = td.className.replace('_on', '_off');
	}
}

var to;
function waitForIt(funct, time)
{
	clearTimeout(to);
	to = setTimeout(funct + ';', time);
}

function showHide(id, show)
{
	var el = document.getElementById(id);
    if (show)
		el.style.visibility = 'visible';
    else
		el.style.visibility = 'hidden';
}

function showHideDisplay(id, show)
{
	var el = document.getElementById(id);
    if (el != null)
	{
		if (show)
			el.style.display = '';
		else
			el.style.display = 'none';
	}
}

function setFocus(el)
{
	if (el != null)
	{
	    if (typeof(el.focus) != 'undefined')
		    el.focus();
		if (typeof(el.select) != 'undefined')
			el.select();
	}
}

function enableValidation(el, validate)
{
	if (el != null)
		el.enabled = validate;
}

function formatCurrency(amount)
{
	var i = parseFloat(String(amount).replace(',', '.'));
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s.replace('.', ',');
}

function formatDateTime(dateToFormat, time)
{
	if (dateToFormat == '')
		return '';
	
	time = time != null ? time : false;
	
	var date = new Date(dateToFormat);
	var day = date.getDate();
	var month = date.getMonth();
	var year = date.getFullYear();
	
	if (isNaN(day) || isNaN(month) || isNaN(year))
		return '';
		
	var returnDate = PadDigits(day, 2) + '-' + PadDigits(++month, 2) + '-' + year;
	
	if (time)
	{
		var sec = date.getSeconds();
		var min = date.getMinutes();
		var hour = date.getHours();
		
		if (!isNaN(sec) && !isNaN(min) && !isNaN(hour))
			returnDate += ' ' + PadDigits(hour, 2) + ':' + PadDigits(min, 2) + ':' + PadDigits(sec, 2);
	}
	
	return returnDate;
}

function PadDigits(n, totalDigits, digit) 
{
	digit = digit != null ? digit : '0';
	
	n = n.toString();
	var pd = '';
	if (totalDigits > n.length)
	{
		for (i = 0; i < (totalDigits-n.length); i++)
		{
			pd += digit;
		}
	}
	return pd + n.toString();
}

function copyValue(orig, copy, overwrite)
{
	overwrite = overwrite == null ? false : overwrite;
	if (copy.value == '' || overwrite)
		copy.value = orig.value;
}

function checkBoxes(arr, check)
{
	for (var i = 0; i < arr.length; i++)
		document.getElementById(arr[i]).checked = check;
}

function checkAllBox(arr, box)
{
	for (var i = 0; i < arr.length; i++)
	{
		if (!document.getElementById(arr[i]).checked)
		{
			box.checked = false;
			return;
		}
	}
	
	box.checked = true;
}

function showHideFullScreenDiv(id, show)
{
	var el = document.getElementById(id);
    if (el != null)
	{
		if (show)
		{
			// TO SHOW FULLSCREEN IN IE...
			document.body.appendChild(el);
			
			var top = ((document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop);
			el.style.top = top + 'px';
			el.style.display = '';
		}
		else
			el.style.display = 'none';
	}
}

var toFloat;
function floatDiv(id)
{
	var el = document.getElementById(id);
    if (el != null)
	{
		var top = ((document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop);
		el.style.top = top + 'px';
	}
	
	toFloat = setTimeout('floatDiv("' + id + '");', 100);
}