
function ClockTick()
{
	var ClockDisplayValue = "";
	ClockSeconds = ClockSeconds + 1;

	if (ClockSeconds == 60)
	{
		ClockSeconds = 0;
		ClockMinutes = ClockMinutes + 1;
	}

	ClockDisplayValue = (ClockSeconds < 10) ? ":0" + eval(ClockSeconds) : ":" +eval(ClockSeconds);

	if (ClockMinutes == 60)
	{
		ClockMinutes = 0;
		ClockHours = ClockHours + 1;
	}

	ClockDisplayValue = ((ClockMinutes < 10) ? ":0" + eval(ClockMinutes) : ":" + eval(ClockMinutes)) + ClockDisplayValue;
	if (ClockHours == 24) ClockHours = 0; else if (ClockHours < 10) ClockHours = "0" + eval(ClockHours);
	ClockDisplayValue = ((ClockHours < 10) ? "0" + eval(ClockHours) : eval(ClockHours)) + ClockDisplayValue;
	setTimeout(ClockTick, 1000);

	var ClockIdEl = document.getElementById('ClockId');
	if (ClockIdEl != null) ClockIdEl.innerText = ClockDisplayValue;
}

function ClockStartTime()
{
	setTimeout(ClockTick, 1000);
}

function iCheck(myForm, myElement)
{
	fE = document.getElementById(myForm);
	if (fE == null) return false;

	for (var i = 0; i <= fE.length; i++)
 	{
		if (fE.elements[i].name != myElement) continue;
		fE.elements[i].checked = !fE.elements[i].checked;
    }

	return false;
}

function rCheck(myForm, myElement)
{
	fE = document.getElementById(myForm);
	if (fE == null) return false;

	for (var i = 0; i <= fE.length; i++)
 	{
		if (fE.elements[i].name != myElement) continue;

		if (fE.elements[i].checked) while (fE.elements[i].name == myElement)
		{
			fE.elements[i].checked = !fE.elements[i].checked;
			
			if (fE.elements[++i].checked)
			{
				fE.elements[i].checked = !fE.elements[i].checked;
				return false;
			}
		}
    }
    
    return false;
}

function chUserIcon(sEName, dEName)
{
	sE = document.getElementById(sEName);
	if (sE == null) return false;

	dE = document.getElementById(dEName);
	if (dE == null) return false;

	sE.value = sE.value.toUpperCase();
	dE.src = './../ico/' + sE.value + '.png';
}

function chMailUser(sEName, username)
{
	sE = document.getElementById(sEName);
	if (sE == null) return false;

	sE.value = username;

	chUserIcon('suser','userico');
}

var rtpVisible = 0;

function flipRtp()
{
	if (rtpVisible)
	{
		hideRtp();
	
	} else {
	
		showRtp();
	}
	
	return false;
}

function hideRtp()
{
	var eHide = document.getElementById('rtp');
	if (eHide == null) return false;

	eHide.style.visibility='hidden';
	eHide.style.display='none';
	
	rtpVisible = 0;
}

function showRtp()
{
	var eShow = document.getElementById('rtp');
	if (eShow == null) return false;

	eShow.style.visibility='';
	eShow.style.display='';

	rtpVisible = 1;
	
	updateRtpContent();
}

function updateRtpContent()
{
	if (!rtpVisible) return false;

    var codeBox = document.getElementById('content_specialchars');
    if (codeBox == null) return false;

	var eContent = document.getElementById('rtp_content');
	if (eContent == null) return false;

	var tContent = document.getElementById('content');
	if (tContent == null) return false;
	
	var tmpContent = tContent.value;

	if (codeBox.checked)
	{
		tmpContent = tmpContent.replace(/</g, "&lt;");
		tmpContent = tmpContent.replace(/>/g, "&gt;");
	}

	tmpContent = tmpContent.replace(/\n/g, "<br/>");
        
	eContent.innerHTML = tmpContent;
	
	setTimeout(updateRtpContent, 500);
}

function AddTextInTextArea(textik)
{
	fE = document.getElementById('content');

	if (fE.length > 0) textik = '\n' + textik;
	fE.value += textik;
}

function addReply(user,webroot,ident,entry,rdate)
{
	fE = document.getElementById('content');
	cnt = '<b>' + user + '</b> <a href="' + webroot + '/node/discussion.php?ident=' + ident + '&amp;focus=' + entry + '">' + rdate + '</a>:'; 
	if (fE.value.length > 0) cnt = '\n' + cnt;
	fE.value += cnt;
	//fE.focus();
}

function chLocation2MailByUsername(username)
{
    if (username != "none")
    {
	top.location.href = './mail.php?username=' + username;
    }
}

function chStatus()
{ 
	var b = document.getElementById('submit_changestatus');
	b.click();
} 