function onChange(pair, new_hash){
	if($(pair.key).match('select'))
		return $(pair.key).title + ' changed to ' + $(pair.key).options[$(pair.key).selectedIndex].text + '\r\n';
	else if($(pair.key).match('input')){
		if('checkbox' == $(pair.key).readAttribute('type'))
			return $(pair.key).title + ' deactivated \r\n';
		else if('text' == $(pair.key).readAttribute('type'))
			return $(pair.key).title + ' changed to ' + nullIfEmpty(new_hash.get(pair.key)) + '\r\n';
	}		
	else 
		return $(pair.key).title + ' changed to ' + nullIfEmpty(new_hash.get(pair.key)) + '\r\n';
}
function getChanges(hash,fname, onchange, checkback) 
{
	if(null == checkback)checkback = true;
	var changes = "";
	var new_hash = $H($(fname).serialize(true));
	var clone_hash = hash.clone();
	clone_hash.each(function(pair) {
		if(pair.value != new_hash.get(pair.key))
			if(null != onchange){
				changes += onchange(pair, new_hash);
			}
		clone_hash.unset(pair.key);
		new_hash.unset(pair.key);
		});
	if(checkback){
		new_hash.each(function(pair) {changes += $(pair.key).title + ' activated \r\n';});
	}
	return changes;
}

function logAndGo(loc, setlogtextfunc, onrestruefunc)
{
		if(null != setlogtextfunc){setlogtextfunc();}
		showPopWin(loc,function(res) {if(res && (null != setlogtextfunc)){onrestruefunc();}});
}

function setInfo(txt, focus, dvInfo)
{
	if(null == dvInfo) dvInfo = 'div_info'; 
	if(null == focus) focus = false;
	$(dvInfo).setStyle({ color: 'black' }).update(txt).blindDown({duration: 0.5 });//show();
	if(focus)$(dvInfo).focus();
}
function setErrorInfo(txt, focus, dvInfo)
{
	if(null == dvInfo) dvInfo = 'div_info';
	if(null == focus) focus = true;
	$(dvInfo).setStyle({ color: 'red' }).update(txt).blindDown({duration: 0.5 });//show();
	if(focus)$(dvInfo).focus();
}

function clearInfo(dvInfo)
{
	if(null == dvInfo) dvInfo = 'div_info'; 
	$(dvInfo).update('').hide();
}

function confirm_NavigateAway(getactionfunc){
	if(null != getactionfunc) 
	{		
		//&& ('' != getactionfunc())
		/*	return confirm("Your unsaved changes will be lost. Are you sure?");*/
		var res = getactionfunc();
		if('' != res)
		{
			if('false' != res){
				return confirm("Your unsaved changes will be lost. Are you sure?");
			}else{
				return false;
			}
		}
	}
	return true;
}
function confirm_NavigateAwayTo(Url, getactionfunc){
	if (confirm_NavigateAway(getactionfunc)) window.location = Url;
}

function addParam(url, pname, pvalue)
{
	var result = url;
	if ((null != url) && !url.include(pname + '=') && (null != pvalue))
	{
		if (url.include('?')){
			result += '&';
		}else{
			result += '?';}
		result += pname + '=' + pvalue;
	}
	
	return result;
}

function isFloat(s)
{
	s = s.strip();
	if(s.blank()) return true; 
	return (/^-?\d*[0-9]?(\.\d*[0-9]|,\d*[0-9])?$/).test(s);
}

function isInteger(s)
{
	s = s.strip();
	if(s.blank()) return true;
	return (/^[-+]?[0-9]\d*\.?[0]*$/).test(s); 
}
		

function popWin(url, params)
{
	if(null == params)params = '';
	window.open(url, 'window', params);
}
