/*	
###############################################
# Previsto- Anpassung
# @version	04.07.2005
	#
	# @filename:   skripte.js
	# @version:    08.08.2005
	# @author:	   D. Deertz
	# @descr:	   Haupt-Javascript-Datei
	#
	#########################################################
*/
var blinkclass = " orangebg";

function showHilfe(hid) {
	var ha = document.getElementById("helparea");
	if(ha !=null) {
		var hf = document.getElementById("helpframe");
		ha.style.display = "block";
		hf.src="hilfe.php?hid="+hid;
	}
	else {
		DD_openWindow("hilfe.php?hid="+hid,100,100,300,400);
	}
}

/**@js Formularkomponente blinken lassen */
function blinkIt (id, count) {
	var obj = document.getElementById(id);
	if(obj==null) return;
	if(count ==0) {
		obj.focus(); 
		return;
	}
	if(count%2) {
		obj.className = obj.className + blinkclass;
		
	}
	else {
		if(obj.className.indexOf(blinkclass)>=0) {
			obj.className = obj.className.replace(blinkclass,"");
		}
	}
	count--;
	setTimeout("blinkIt ('"+id+"',"+count+")",150);
}

/**@js Alle Zeilen eines Auswahlfeldes auswählen */
function selectAll(selec) {
	if(selec !=null) {
		for(i=0; i < selec.length ;i++) {
			selec.options[i].selected=true;
		}
	}
}

function showHideLayer(id,b) {
		
	 	var obj = document.getElementById(id);
		
		if(obj!=null) {
			if(obj.style.display!="") {
				obj.style.display = b?'block':'none';
			}
			else {
				obj.style.visibility = b?'visible':'hidden';
				obj.style.position= b?'relative':'absolute';
			}
		}
}

/**@js Deselektieren von Radiobuttons bei nochmaligem Klick 
	Sinnvoll nur bei Radiogroups, bei denen auch KEINE Auswahl getroffen 
	werden kann
	@param rad 	Das Radiobutton-Objekt
*/
function unselectRadio(rad) {
	// deselektieren
	if(rad.checked==true) {
		rad.checked =false;
	}
	else{ 
		alert();
		rad.checked =true;
	}
}

/**@js Popupfenster */
var MyWindow = null;
function DD_openWindow(url,left,top,breite,hoehe) {
	if(MyWindow != null && !MyWindow.closed)
		MyWindow.close();
	MyWindow = open (url, "Win", "left="+left+",top="+top+",toolbar=0,menubar=1,location=0,status=1,scrollbars=1,resizable=1,width="+breite+",height="+hoehe); 
} 
/**@js	Feiner Unterschied! DIese Funktion nutzt ein Objekt der aktuellen Seite , damit jede Seite 
	ihr eigenes Fensterobjekt besitzen kann
*/
function openOwnWindow(url,left,top,breite,hoehe) {
	if(win != null && !win.closed)
		win.close();
	win = open (url, "", "left="+left+",top="+top+",toolbar=0,menubar=1,location=0,status=1,scrollbars=1,resizable=1,width="+breite+",height="+hoehe); 
}


/** Drucken einer Seite mit Ausblenden der Toolbar*/
function printMe() 
{
	var tb = document.getElementById('toolbar');
	if(tb !=null) {
		tb.style.visibility = 'hidden';
	}
	
	self.print();
	
	if(tb !=null) {
		tb.style.visibility = 'visible';
	}
}

/** Deaktivierung von Formularfeldern */
function disable(check,id)
{
	if(check==null) return;
	var field = document.getElementById(id);
	field.disabled= check.checked;
	field.style.backgroundColor = check.checked?'#CCCCCC':'#FFFFFF';
}

/** Hier fehlt noch eine Pattern-abhängige Variante */
function checkDate(fieldname, sep, pattern)
{
	var src = document.getElementById(fieldname);
	if(src == null) return true; // kann nicht prüfen, da Feld nicht vorhanden
	var datum = src.value;
	if (!datum || datum=="") return true;  // kann nicht prüfen, da kein Value
	
	var result = true; 
	datum=datum.split(sep);
	if (datum.length!=3)  result=false;
	else {
		 //(Schritt 3) Entfernung der fuehrenden Nullen und Anpassung des Monats
		
		 datum[0]=parseInt(datum[0],10);
		 datum[1]=parseInt(datum[1],10)-1;
		
		 //  Jahr vierstellig machen
		 if (datum[2].length==2) datum[2]="19"+datum[2];
		
		 // Erzeugung eines neuen Dateobjektes
		 var kontrolldatum=new Date(datum[2],datum[1],datum[0]);
		
		 // Vergleich, ob das eingegebene Datum gleich dem JS-Datum ist
		 if (kontrolldatum.getDate()==datum[0] && kontrolldatum.getMonth()==datum[1] 
		 	 && kontrolldatum.getFullYear()==datum[2]
		 ) {
		 	
			result = true;
		 }
		 else {
		 	result = false;
		 }
	 }
	if(!result) {
		src.focus();
		src.select();
	} 
	return result;
}

/** Einfärben von Formularfeldern */
function makeColored(ar, colorclass, title)
{
	for(i=0; i< ar.length; i++)
	{
		var obj = document.getElementById(ar[i]);
		if(obj == null) return;
		obj.className=
			obj.className + " " + colorclass;
		if(arguments.length>2) {
			obj.title = title;	
		}
	}
}

//# Utilities //////////////////////////////////////

function getScreenWidth() {
	if(document.body.offsetWidth) {
		return document.body.offsetWidth;
	}
	return window.innerWidth;
}

function getStyle(el, style) {
   if(!document.getElementById) return;
   
    var value = el.style[toCamelCase(style)];
   
    if(!value)
        if(document.defaultView)
            value = document.defaultView.
                 getComputedStyle(el, "").getPropertyValue(style);
       
        else if(el.currentStyle)
            value = el.currentStyle[toCamelCase(style)];
     
     return value;
}

 /** toCamelCase(input)
 * Converts string input to a camel cased version of itself.
 * For example:
 * toCamelCase("z-index"); // returns zIndex
 * toCamelCase("border-bottom-style"); // returns borderBottomStyle.
 */
function toCamelCase( sInput ) {
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)    
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ? 
    	oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}

//# Funktionen zum Prüfen von Formularen /////////////////////

/** Email- Format prüfen;
	@param id die ID des Textelementes
 */
function checkEmail(id) {
	var src = document.getElementById(id);
	if(src == null) return true;
	var inhalt = src.value;
	if(!inhalt || inhalt == "") return true;// Prüfe NICHT auf leeres Feld!
	
	if(!inhalt.match(/^[_a-zA-Z0-9äöüÄÖÜ-]+(\.[_a-zA-Z0-9äöüÄÖÜ-]+)*@([a-zA-Z0-9äöüÄÖÜ-]+\.)+([a-zA-Z]{2,})$/))
    {
		src.focus();
		src.select();
		return false;
    }
	return true;
}

/** Prüfe Feld auf Leere - weicht ab von anderen ähnlichen Funktionen!
	@param id die ID des Textelementes
 */
function checkEmpty(id) {

	var src = document.getElementById(id);
	
	if(src == null) return true; //prüfe keine nichtexistenten Felder
	var inhalt = src.value;
	inhalt = inhalt.replace(/\s/,"");
	if (inhalt.length == 0)
	{	
		src.focus();
		return false;
	}
	return true;
}

/** Prüft String auf das Vorhandensein alphanumerischer Zeichen
*/
function hasAlphaNum( string) {
	 if( string.match(/\w/) ) return true;
	 return false;
}

function inArray(val,ar)
{
	if(ar==null) return -1;
	
	for(i=0; i< ar.length; i++) {
		if(val==ar[i])
			return i;
	}
	return -1;
}

/** Liest den aktuellen Style aus */
function getStyle(el, style) {
   if(!document.getElementById) return;
   
    var value = el.style[toCamelCase(style)];
   
    if(!value)
        if(document.defaultView)
            value = document.defaultView.
                 getComputedStyle(el, "").getPropertyValue(style);
       
        else if(el.currentStyle)
            value = el.currentStyle[toCamelCase(style)];
     
     return value;
}

 /** toCamelCase(input)
 * Converts string input to a camel cased version of itself.
 * For example:
 * toCamelCase("z-index"); // returns zIndex
 * toCamelCase("border-bottom-style"); // returns borderBottomStyle.
 */
function toCamelCase( sInput ) {
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)    
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ? 
    	oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}