function hideValue(what, def)
{
	if(trim(what.value) == def)
	{
		what.value = "";
	}
	return;
}

function showValue(what, def)
{
	if(trim(what.value) == '')
	{
		what.value = def;
	}
	return;
}

// Removes leading whitespaces
function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value )
{
	return LTrim(RTrim(value));
	
}

function changeContent(what)
{
	var old_title = document.getElementById('showtitle').innerHTML;
	var old_text = document.getElementById('showtext').innerHTML;
	
	document.getElementById('showtitle').innerHTML = document.getElementById('showlink_'+what).innerHTML;
	document.getElementById('showtext').innerHTML = document.getElementById('hiddentext_'+what).innerHTML;
	
	document.getElementById('showlink_'+what).innerHTML = old_title;
	document.getElementById('hiddentext_'+what).innerHTML = old_text;
}

function setArrow(what, cfg, arrpath)
{
	var imgarrow = '<img src="'+arrpath+'" style="vertical-align:middle;" alt="" />';
	
	if(cfg == 1) document.getElementById(what).innerHTML = imgarrow;
	if(cfg == 2) document.getElementById(what).innerHTML = '&nbsp;';
}

function checkForm(form_name, fields_array, messages_array)
{
	eval("reg = document."+form_name+";");
	
	for(i = 0; i < fields_array.length; i++)
	{
		eval("cfield = reg."+fields_array[i]+";");
		if(trim(cfield.value) == '')
		{
			alert(messages_array[i]);
			cfield.focus();
			return false;
		}
	}
	
	reg.submit();
}

function email_check(what)
{
	var chk = /[^-A-z0-9@._]/g;
	if ( chk.exec ( what.value ) )
	{ 
		alert ( 'Invalid symbol!' );
		what.value = what.value.replace( chk, "" );
		what.focus();
		return false;
	}
	return true;
}

function changeBgck(tid, img, img2)
{
	eval("document.getElementById('showlink_"+tid+"').style.backgroundImage = 'url(\\'"+img+"\\')';");
	eval("document.getElementById('showlink_"+tid+"a').src = '"+img2+"';");
}
