/*
	CMSZWO Public JS Scripts
*/

function litTD(td, color)
{
	if(color != '')
	{
		td.style.backgroundColor  = color;
	}
}

function go(url)
{
	if(url != '')
	{
		window.location.href = url;
		if(document.all && event != null)
		{
			event.cancelBubble = true;
		}
	}
}

function openWin(url, name, style) 
{
		win = window.open(url, name, style);
		win.focus();
}

function goLocation(ctrl, pre)
{
	go(pre + ctrl.options[ctrl.options.selectedIndex].value + '.htm');
}

function getTextValue(id)
{
	result = "";
	result = document.getElementById(id).value.toString();
	return result;
}

function setTextValue(id, value)
{
	document.getElementById(id).value = value.toString();
}

function getComboValue(id)
{
	ret = -1;
	ret = document.getElementById(id).options[getElementById(id).options.selectedIndex].value;
	return ret;
}

function setComboValue(id, value)
{
	var i=0;
	for(i=0; i<document.getElementById(id).length; i++)
	{
		if(document.getElementById(id).options[i].value == value)
		{
			document.getElementById(id).selectedIndex = i;
			break;
		}
	}
}

function submitForm(formId)
{
	if(formId == null)
	{
		formId = "cmszwoform";
	}

	ctrl = document.getElementById(formId);
	ctrl.submit();
}

function submitOnEnter(sender, formId)
{
	if(event.keyCode == 13)
	{		
		submitForm(formId);
	}	
	if(event.keyCode == 27)
	{
		sender.value = "";
	}
}

function submitOnEnterMOZ(eventObject)
{
	if(eventObject != null)
	{
		if(eventObject.which == 13)
		{		
			submitForm();
		}
	}	
}

function toggleElement(id)
{
	ctrl = document.getElementById(id);
	visible = (ctrl.style.visibility == 'visible');
	if(ctrl != null)
	{
		if(!visible)
		{
			ctrl.style.visibility='visible';
			ctrl.style.display='block';
		}
		else
		{
			ctrl.style.visibility='hidden';
			ctrl.style.display='none';
		}
	}
}

function showElement(id, visible)
{
	ctrl = document.getElementById(id);
	if(ctrl != null)
	{
		if(visible)
		{
			ctrl.style.visibility='visible';
			ctrl.style.display='block';
		}
		else
		{
			ctrl.style.visibility='hidden';
			ctrl.style.display='none';
		}
	}
}
	
function checkLength(checkedControl, countControl, maxLen)
{
	if(checkedControl != null)
	{
		var val = checkedControl.value;
		var len = val.length;
		var avail = maxLen-len;
		countControl.value = avail;
		
		if(avail <= 0)
		{
			alert("Deine Nachricht ist zu lang!");
		}
	}
}	
