// lib functions
function getElem(eid)
{
	if(document.getElementById(eid))
	{
		return document.getElementById(eid);
	}
	else
	{
		return null;
	}
}

function showElem(elem)
{
	if(elem)
	{
		elem.style.visibility = 'visible';
	}
}

function hideElem(elem)
{
	if(elem)
	{
		elem.style.visibility = 'hidden';
	}
}

function OpenWindow(url, w, h) 
{
	window.open(url, '', 'toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=0,height='+h+',width='+w+',left=50,top=50');
}

function flip(item)
{
	if (item.style.display == 'none')
	{
		item.style.display = 'inline';
	}
	else
	{
		item.style.display = 'none';
	}
}

function scrolled()
{
	parent.leftFrame.document.body.scrollTop=document.body.scrollTop;
	parent.rightFrame.document.body.scrollTop=document.body.scrollTop;
}

 
function isOpera()
{
	if(navigator.userAgent.toLowerCase().indexOf('opera')  > -1) {
		return true;
	} else {
		return false;
	}
}

function isIE()
{
	if(navigator.userAgent.toLowerCase().indexOf('msie')  > -1) {
		return true;
	} else {
		return false;
	}
} 

function oldIE()
{
	var ua = navigator.userAgent.toLowerCase();
	var i = ua.indexOf('msie');
	if(i<0) {
		return false;
	}
	var uatrimmed = ua.substr(i);
	var j = uatrimmed.indexOf(';');
	var vers = uatrimmed.substring(5,j);
	vers = parseFloat(vers);
	if(vers < 7)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function getDocumentHeight() 
{
	var h1 = document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight;
	var h2 = getViewportHeight();
	return Math.max(h1, h2);
}
 
function getViewportHeight() {
  return ((document.compatMode || isIE()) && !isOpera()) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}


function isNotEmpty(str)
{
	var PatternEmpty = /^[\s]*$/i;
	if(PatternEmpty.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function isValidEmail(str)
{
	var PatternEmail = /^([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\.\-]+)\.([a-zA-Z]{2,4})$/;
	if(!PatternEmail.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function formatPositive(str)
{
	var pattern = /[^0-9\.]+/gi;
	var nstr = str.toString();
	nstr = nstr.replace(/,/g, ".");
	nstr = nstr.replace(pattern, "");
	if(!nstr || nstr.length == 0) {
		nstr = '0';
	}
	var aft, bef, i;
	i = nstr.indexOf('.');
	if(i > -1)
	{
		bef = nstr.substr(0, i+1);
		aft = nstr.substr(i);
		aft = aft.replace(/\./g, "");
		if(aft == '') {
			bef = bef.substr(0, i);
		}
		if(bef == '' || bef == '.') {
			bef = '0' + bef;
		}
		nstr = bef + aft;
	}
	return nstr;	
}

function formatPositiveInteger(str)
{
	var pattern = /[^0-9\.]+/gi;
	var nstr = str.toString();
	nstr = nstr.replace(/,/g, ".");
	nstr = nstr.replace(pattern, "");
	if(!nstr || nstr.length == 0) {
		nstr = '0';
	}
	var i;
	i = nstr.indexOf('.');
	if(i > -1)
	{
		nstr = nstr.substr(0, i);
	}
	return parseInt(nstr, 10);
}

function setCookie(c_name, value, expiredays)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires="+exdate.toGMTString());
} 

function getCookie(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{ 
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) 
			{
				c_end = document.cookie.length;
			}
			
			return unescape(document.cookie.substring(c_start, c_end));
		} 
	}
	
	return "";
}
