var xx="<script type='text/javascript'>";

function handleForms_setSelectValue(theForm,theFieldName,theValue)
{
	for (i=0;i < document.forms[theForm].elements[theFieldName].length;i++)
	{
		if (document.forms[theForm].elements[theFieldName].options[i].value == theValue)
		{
		document.forms[theForm].elements[theFieldName].options[i].selected = true;
		}
	}
}


function handleForms_checkForm(theForm)
{
	for (i=0;i<=document.forms[theForm].length - 1 ;i++)
	{
		FormError = false;
		FormName = document.forms[theForm][i].name;
		var colFormName = FormName.split("_");
		//alert(FormName + ' - ' + colFormName.length)
		if (colFormName.length > 1)
		{//dann ist es ein Checkfeld
		
			theVal = document.getElementsByName(FormName)[0].value;
			theCheckType = colFormName[1].toLowerCase();
			switch (theCheckType)
			{
				case 'text':
					if (theVal == '')
					{
					FormError = true;
					}	
				break;
				case 'date':
					if (theVal != '')
						{
						if (handleForms_isValidDate(theVal) != true)
							{
							FormError = true;
							}
						}	
				break;
				case 'datep':
					
					if (handleForms_isValidDate(theVal) != true)
					{
					FormError = true;
					}
					
						
				break;
				case 'int':
					if (theVal != '')
					{ 
						if (isNaN(theVal) == true)
						{
							FormError = true;
						}
					}
				case 'intp':
					if (isNaN(theVal) == true)
						{
							FormError = true;
						}
					
				case 'checked':
					if (document.getElementsByName(FormName)[0].checked != true)
					{
						FormError = true;
					}
					
				break;
			}
			
					
			
			if (FormError == true)
			{
				//errortext ist ein selbst definiertes HTML Attribut
				
				theErrorText = document.getElementsByName(FormName)[0].errortext;
				if (theErrorText != '' && typeof theErrorText != 'undefined'){alert(theErrorText)}
				
				try
				{				
				document.getElementsByName(FormName)[0].focus();
				document.getElementsByName(FormName)[0].select();
				}
				catch(e){}
				return false;
			}
							
		}
	}
	return true;
}
function handleForms_delFormfield(toDel)
{
	document.getElementById(toDel).value = '';
}
function HandleForms_leaveIt()
{
	
	if(ChangeContent == true && justSaving == false)
	{
	event.returnValue = cls_166; //Achtung, ungespeicherte Änderungen gehen verloren!
	}
}

function handleForms_checkCheckbox (which,whichID)
{
try
{
	if (which[whichID].disabled != true)
	{
	which[whichID].checked ? which[whichID].checked = false : which[whichID].checked = true;
	}
}
catch (e)
{
if (which[whichID].disabled != true)
	{
	which.checked ? which.checked = false : which.checked = true;
	}
}

}

function handleForms_setReadOnly (whichForm)
{
	for (i=0;i < document.forms[whichForm].elements.length;i++)
	{
			if (document.forms[whichForm].elements[i].type == "text" || document.forms[whichForm].elements[i].type == "textarea")
			{
			document.forms[whichForm].elements[i].readonly = true;
			}
			else
			{
			document.forms[whichForm].elements[i].disabled = true;
			}
		
	}
}
// ############################################
// # Autor: Frank Dühnelt (frank.duehnelt@it-direkt)  	  #
// #         								  #
// #------------------------------------------#
// #   checkt ob ein Datum im Format  		  #
// #   tt.mm.yyy eingegeben wurde     		  #
// #------------------------------------------#
// #   Übergabeparameter:   Datum als String  #
// #                                          #
// ############################################
function handleForms_isValidDate(dateStr) {

//01. davorsetzen falls nur 5 Stellen (mm.jj) angegeben wurden
if (dateStr.length == 7)
	{
	dateStr = '01.' + dateStr;
	}


// Checks for the following valid date formats:
// MM/YY
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|.)(\d{1,2})\2(\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert(cls_138); //Das Datum liegt nicht im Format tt.mm.jjjj vor
return false;
}
day = matchArray[1]; // parse date into variables
month = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert(cls_139); //Der Monat muß zwischen 1 und 12 liegen.
return false;
}
if (day < 1 || day > 31) {
alert(cls_140); //Der Tag muß zwischen 1 und 31 liegen.
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert( cls_141 + " " + month+" " + cls_142); //Der Monat xy hat keine 31 Tage!
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert(cls_143 + " " + year + " " + cls_144 + " " + day + " " + cls_145); //februar im Jahr xy hat keine 29 Tage
return false;
  }
}
return true;  // date is valid
}
