/* General and GUI utility functions */

function formatOutput (num) {
	num += '';
	if (num.indexOf('.') > -1 && num.indexOf('.') == num.length - 2) {
		num += '0';
	}
	return num;
}

function formatOutputWithTrim (num) {
	var floored_num = Math.round(num);
	var dec = num - floored_num;
	dec = Math.round(dec*100)/100;
	if (dec == 0) {
		dec = '.00';
	}
	num = floored_num + dec;
	nStr = num + '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function change_img (s_id, src) {
	document.getElementById(s_id).src = _IG_GetImageUrl('http://' + src_url +'.labpixies.com/campaigns/expenses/images/' + src);
}

function show(s_id, display) {
	if( typeof(display) == 'undefined') {
		display = 'block'
	}
	document.getElementById(s_id).style.display = display;
}

function hide(s_id) {
	if (!document.getElementById(s_id)) {
		return false;
	}
	document.getElementById(s_id).style.display = 'none';
}

function show_vis(s_id) {
	document.getElementById(s_id).style.visibility = 'visible';
}

function hide_vis(s_id) {
	document.getElementById(s_id).style.visibility = 'hidden';
}

function slideOpen (sId, finalHeight) {
	var slidingElement = document.getElementById(sId);
	slidingElement.style.height = '1px';
	var actualHeight = 2;
	show (sId);
	var slideInt = setInterval(function () {
		while (actualHeight < finalHeight ) {
			slidingElement.style.height = actualHeight + 'px';
			actualHeight++;
		}
		clearInterval(slideInt);
	}, 500);
}

function slideClose (sId) {
	var slidingElement = document.getElementById(sId);
	var actualHeight = slidingElement.offsetHeight;
	var slideCloseInt = setInterval(function () {
		while (actualHeight >= 1 ) {
			slidingElement.style.height = actualHeight + 'px';
			actualHeight--;
		}
		hide (sId);
		clearInterval(slideCloseInt);
	}, 500);
}

function detectIe6 () {
	if(!document.getElementById('ie6Detector')) {
		return false;
	}
	if (navigator.appVersion.indexOf('MSIE 6.0') > -1) {
		document.getElementById('ie6Detector').innerHTML = '<p><strong>האינטרנט שלך לא מעודכן!</strong>. זו אינה הגרסה האחרונה של  Microsoft Internet Explorer</p>\n<p>אתה יכול לשפר בהרבה את חוויית הגלישה עם דפדפן בגרסה עדכנית. זה אפילו בחינם!</p>\n<p><a href="http://www.mozilla-europe.org/en/products/firefox/" target="_blank">התקן <strong>Firefox</strong></a> | <a href="http://www.microsoft.com/windows/products/winfamily/ie/default.mspx" target="_blank">שדרג ל-Internet Explorer 7</a> | <a href="http://www.uweb.ucsb.edu/~mguidry/firefox/" target="_blank"><strong>מה כדאי לי?</strong></a></p>\n<p class="button" onclick ="slideClose(\'ie6Detector\');">אחליט אחר כך. סגור את החלון.</p>';
		slideOpen('ie6Detector', 65);
	}
}