// JavaScript Document

	// FrmChck Object
	
	var frm = function(frmE, type, lmin, lmax)
	{
		this.minimum	= lmin;
		this.maximum	= lmax;
//		this.formE		= document.getElementById(frmE);
		this.formE		= frmE;
		this.errDesc	= document.getElementById('errorDesc');
		this.value		= this.formE.value;
		this.subBtn		= document.getElementById('submit');
	

		switch(type)
		{
			case 'i':
				this.chk = checkInt;
				break;
			
			case 's':
				this.chk = checkString;
				break;
				
			case 'd':
				this.chk = checkDate;
				break;
			
			case 't':
				this.chk = checkTime;
				break;

			case 'r':
				this.chk = checkRst;
				break;
		}
		
		if(!this.chk())
		{
			alert('Ungültige Eingabe!');
			window.setTimeout( function() { this.formE.focus();}, 1);
			this.formE.select();
		}
	}
	
	
	function checkInt()
	{
		this.error = "ganze Zahl zwischen " + this.minimum + " und " + this.maximum + "eingeben";
		return !isNaN(this.value) && (this.value >= this.minimum) && (this.value <= this.maximum);
	}
	
	function checkString()
	{
		this.error = this.minimum + " - " + this.maximum + " Zeichen sind einzugeben";
		return (this.value.length>=this.minimum) && (this.value.length<=this.maximum);	
	}

	function checkTime()
	{
		if(this.value=="")
			return true;
		this.value +='';
		
		this.value = this.value.replace('\.', ':');
		formE.value = this.value;
		
		var split = this.value.split(":");
		var stunde = parseInt(split[0]);
		var minute = parseInt(split[1]);
		
		if(stunde >= 0 && stunde <24 && minute >=0 && minute <=59)
			return true;
		else
			return false;
	}
	
	function checkDate()
	{
		if(this.value=="")
			return true;
		this.value +='';

    	this.value = this.value.replace(/[^0-9^\.]/g, '');

	    var split = this.value.split(".");
		
    	var day = parseInt(split[0], 10);
	    var month = parseInt(split[1] || 0, 10);
    	var year = parseInt(split[2] || 0, 10);

	    if(isNaN(year))
			year = getFullYear();;

	    var check = new Date(year, month - 1, day);

		var day2 = check.getDate();
	    var year2 = check.getFullYear();
    	var month2 = check.getMonth() + 1;

	    if ( year2 == year && month == month2 && day == day2 )
		{
			formE.value = day+"."+month+"."+year;
			return true;
		}
		else
		{
			this.error = "Datum ist ungültig!";
			return false;
		}
	}
	
	
	function checkRst()
	{
		return true;	
	}
	
	var filenum = 1;
	
	function addUp(els)
	{
		var container,
		lastipt = els['file' + filenum];
		if(lastipt.value == "")
		{
			alert('Bitte vorher ein Bild auswählen!');
			return;
		}

		if(filenum > 9)
			return;
			
		newipt = lastipt.cloneNode(true);
		
		newipt.value="";
		newipt.name = 'file' + ++filenum;
		newipt.id = newipt.name;
		
		if (container = document.getElementById('uploads'))
		{
			container.appendChild(document.createElement('br') );
			container.appendChild(newipt);
//			els[newipt.name] = newipt; //IE, yech...
		}

	}
	
	function refreshPictures()
	{
		var e = document.getElementById('pictures');
		
		e.innerHTML = "";
	}
	
	function togglePicBtn(oldFormat)
	{
		var	f = document.forms[0];
		var nF = f.elements['newsFormat'];
		var pO = f.elements['picsIDold'];
		
		var nfv = parseInt(nF.options[nF.selectedIndex].value);
		var	e = document.getElementById('picBtn');
		
		switch(nfv)
		{
			case 1:
				e.value = "Titelthema - Bildliste aktualisieren, Bild auswählen";
				e.disabled = false;
				break;
			
			case 2:
				e.value = "Wichtige Meldung - Bildliste aktualisieren, Bild auswählen";			
				e.disabled = false;				
				break;
				
			case 4:
				e.value = "Standardnachricht -  Bildliste aktualisieren, Bild auswählen";			
				e.disabled = false;
				break;
			
			case 8:
				e.value = "Kurzmeldung -  keine Bildverknüpfung möglich";
				e.disabled = true;
				break;
			
		}
		if(nfv != parseInt(oldFormat))
			pO.name = "picsIDdontFit"
		else
			pO.name ="picsIDold";
		
	}
	
	function chkFrmNews()
	{
		var nh1 =	document.getElementById('newsH1');
		var nh2	=	document.getElementById('newsH2');
		var ntxt =	document.getElementById('newsText');
		var frm = document.forms[0];
		
		var error = "";
		
		if(nh2.value=="")
			error = error + "Kurzüberschrift fehlt!\n";
		if(nh1.value=="")
			error = error + "Hauptüberschrift fehlt!\n";
		if(ntxt.value=="")
			error = error + "Nachrichtentext fehlt!";
		if(error != "")
			alert(error);
		else
			frm.submit();
	}
