/*----------------------------------------------------------------------
** VAV Professional - Version 3.0
** copyright (c) 2007 NBV-SYSTEMS - EDV und Internet Services
** programmer Engel Thomas / Date: 20.09.2007
-----------------------------------------------------------------------*/


	/*----------------------------------------------------------------------
	** Window Open
	-----------------------------------------------------------------------*/	
	function myPopup(link,id,width,height,scrollbars,resizable) {
		newwindow = window.open( link, id, 'height = '+height+', width = '+width+', dependent = 1, location = 0, scrollbars = '+scrollbars+', status= 0, toolbar = 0, menubar = 0, resizable = '+ resizable +'');
		if (window.focus) {newwindow.focus()}
		return false;
	}
	/*---------------------------------------------------------------------*/
	
		
	/*----------------------------------------------------------------------
	** Change Status for Field
	-----------------------------------------------------------------------*/			
	function upFieldSt() {
    	document.forms[0].FieldUpSt.value = 1;
		/*document.forms[0].className='input_check';		  
		  window.setTimeout("colorWhite()", 100);*/
	}
	/*---------------------------------------------------------------------*/
		
	/*----------------------------------------------------------------------
	** Bilder Vorschau laden
	-----------------------------------------------------------------------*/			
	function load_preview() {	
			
	    var current = document.getElementsByTagName('img');
	    var curLen = current.length;
	
	    for (var j = 0; j < curLen; j++) {
	
	        if (current[j].id == "preview") {
						
	            ImgSrc = current[j].getAttribute("pf");
	            ImgSize = current[j].getAttribute("ps");	            
	            
	            var title = current[j].getAttribute('title');
	            current[j].setAttribute('title', '');
	
	        	var tip = '<div class="tool"><img src="src/plugins/phpThumb/phpThumb.php?src=' + ImgSrc + '&w='+ImgSize+'&h='+ImgSize+'&q=100"></div>';	      		            	
	        	
	            new Tooltip(current[j], tip, {'html': true, 'classname': 'TooltipObject'});
	
	        }
	    }		
	    
	}
	/*---------------------------------------------------------------------*/
	
	
	/*----------------------------------------------------------------------
	** HTML Code umwandeln
	-----------------------------------------------------------------------*/			
	function htmlspecialchars(str,typ) {
 		if(typeof str=="undefined") str="";
 		if(typeof typ!="number") typ=2;
 		typ=Math.max(0,Math.min(3,parseInt(typ)));
 		var html=new Array();
 		html[38]="&amp;"; html[60]="&lt;"; html[62]="&gt;";
 		if(typ==1 || typ==3) html[39]="&#039;";
 		if(typ==2 || typ==3) html[34]="&quot;";
 		for(var i in html) eval("str=str.replace(/"+String.fromCharCode(i)+"/g,\""+html[i]+"\");");
		return str;
	}
	/*---------------------------------------------------------------------*/
	

	/*----------------------------------------------------------------------
	** Scroll
	-----------------------------------------------------------------------*/					
	function doScroll(data) {
		document.getElementById('jmp_'+data).scrollIntoView(true);			
	}
	/*---------------------------------------------------------------------*/

	
	/*----------------------------------------------------------------------
	** HTML Code umwandeln - Alert Funktion
	-----------------------------------------------------------------------*/				
	function html_entity_decode(str) {
	  var ta=document.createElement("textarea");
	  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
	  return ta.value;
	}
	/*---------------------------------------------------------------------*/
	
	
	/*----------------------------------------------------------------------
	** Email Prüfung
	-----------------------------------------------------------------------*/			
	function echeck(str) {
	
			var at="@"
			var dot="."
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
			   return false
			}
	
			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			   return false
			}
	
			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			    return false
			}
	
			 if (str.indexOf(at,(lat+1))!=-1){
			    return false
			 }
	
			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			    return false
			 }
	
			 if (str.indexOf(dot,(lat+2))==-1){
			    return false
			 }
			
			 if (str.indexOf(" ")!=-1){
			    return false
			 }
	
	 		 return true					
	}
	/*---------------------------------------------------------------------*/	

	
	/*----------------------------------------------------------------------
	** ENTER Sperren
	-----------------------------------------------------------------------*/			
	function disableNavigationKeys() {    	
		
		//alert(event.srcElement.type);
		//alert(event.srcElement.isTextEdit);
		//disable Backspace, Alt+Arrowkeys, Ctrl-N 
		if ((event.keyCode == 8 && (event.srcElement.form == null || event.srcElement.isTextEdit== false)) 
			|| event.keyCode == 37 && event.altKey	
			|| event.keyCode == 39 && event.altKey	
			|| event.keyCode == 78 && event.ctrlKey
			|| event.keyCode == 13 && (event.srcElement.form == null || event.srcElement.isTextEdit== false || event.srcElement.type != 'textarea')
			)
	
		{        
			event.cancelBubble = true;
			event.returnValue = false;
		}
		
		if(event.keyCode==27) {
			// spezial for ESC
		}
		// disable Ctrl-P
	}        
	/*---------------------------------------------------------------------*/
		
	/*----------------------------------------------------------------------
	** Formular Check + Save & Update Check
	-----------------------------------------------------------------------*/
	function doSave(go,modul,page,id,msg_save,msg_update) {
		
			if (checkForm() == true) {
		    	if (go == true) {		    		
					location.href = '/?m='+modul+'&s='+page+'&id='+id+'';		    		
		    	} else {						
					if (id == '') {
						Check = confirm(msg_save);
						if(Check == false){
						} else {
	    					document.forms[0].modul.value = modul;
	    					document.forms[0].page.value = page;
				    		document.forms[0].submit();
						}							
					} else {
						Check = confirm(msg_update);
						if(Check == false){
							location.href = '/?m='+modul+'&s='+page+'&id='+id+'';
						} else {
	    					document.forms[0].modul.value = modul;
	    					document.forms[0].page.value = page;
				    		document.forms[0].submit();
						}						
					}				
				}
	    	}
	    	
	}	
	/*---------------------------------------------------------------------*/


	/*----------------------------------------------------------------------
	** Check for Change on Form
	-----------------------------------------------------------------------*/			
	function doCheckSave(modul,page,id) {
		
	    /* Abfragen ob Form da ist --------------------------------- */					
		if (!document.forms[0]) {
			location.href = '/?m='+modul+'&s='+page+'&id='+id+'';	
		} else {

	        /* Formular Werte auslesen --------------------------------- */			
			msg_save = document.forms[0].FormMsgSave.value;
			msg_update = document.forms[0].FormMsgUpdate.value;		
			form_FieldUpSt = document.forms[0].FieldUpSt.value;
			                
		    /* Variable setzen ----------------------------------------- */
	        var go = true;
	
		    /* Formular Werte auf Änderungen prüfen -------------------- */			
			if (form_FieldUpSt == 0) { } else { go = false; }
			
			
		    /* Speicherabfrage starten --------------------------------- */		
			if (checkForm() == true) {
				
		    	if (go == true) {		 
		    		   		
					location.href = '/?m='+modul+'&s='+page+'&id='+id+'';		    		
					
		    	} else {						
		    		
					if (id == '') {
						
		    			/* Save Form ---------------- */							
						Check = confirm(msg_save);
						if(Check == false){
						} else {
	    					document.forms[0].modul.value = modul;
	    					document.forms[0].page.value = page;
				    		document.forms[0].submit();
						}			
										
					} else {
						
		    			/* Update Form -------------- */												
						Check = confirm(msg_update);
						if(Check == false){
							location.href = '/?m='+modul+'&s='+page+'&id='+id+'';
						} else {
	    					document.forms[0].modul.value = modul;
	    					document.forms[0].page.value = page;
				    		document.forms[0].submit();
						}						
						
					}	// Neuer Datensatz oder bestehender Datensatz
								
				} // Änderungscheck
				
	    	} // Pflichtfelder Check
		}
	}

	/*---------------------------------------------------------------------*/


	/*----------------------------------------------------------------------
	** confirm Check
	-----------------------------------------------------------------------*/	
	function confirmCheck(text, link) {
	
		Check = confirm(text);
		if(Check == false){
		} else {
			location.href = link;
		}
	}
	/*---------------------------------------------------------------------*/
		
		
	/*----------------------------------------------------------------------
	** Feldüberprüfung - Zahl
	-----------------------------------------------------------------------*/
	function validVal(event, keyRE) {
		
		if (event.keyCode != 13) {
			if ( String.fromCharCode(((navigator.appVersion.indexOf('MSIE') != (-1)) ? event.keyCode : event.charCode)).search(keyRE) != (-1)
				|| ( navigator.appVersion.indexOf('MSIE') == (-1)
					&& ( event.keyCode.toString().search(/^(8|9|13|45|46|35|36|37|39)$/) != (-1)
						|| event.ctrlKey || event.metaKey ) ) ) {
				return true;
			} else {
				return false;
			}
		}
	}
	
	/* onKeyPress="return validVal(event, /[0-9]/);" /*
	/* onKeyPress="return validVal(event, /[0-9A-Za-z -]/);" /*	
	 
	/*----------------------------------------------------------------------*/	
			

	/*----------------------------------------------------------------------
	** Dynamische Uhrzeit
	-----------------------------------------------------------------------*/			
	function TimeView() {
	
		if(!document.all && !document.getElementById) {
			return;
		}
		
		var Stunden = Serverzeit.getHours();
		var Minuten = Serverzeit.getMinutes();
		var Sekunden = Serverzeit.getSeconds();
		Serverzeit.setSeconds(Sekunden+1);
		   
		if(Stunden<=9) {
			Stunden = "0" + Stunden;
		}
		if(Minuten<=9) {
			Minuten = "0" + Minuten;
		}
		if(Sekunden<=9) {
			Sekunden = "0" + Sekunden;
		}
		Uhrzeitanzeige = Stunden + ":" + Minuten + ":" + Sekunden;
		if(document.getElementById) {
			document.getElementById("Uhrzeit").innerHTML = Uhrzeitanzeige;
		} else if(document.all) {
			Uhrzeit.innerHTML = Uhrzeitanzeige;
		}
		setTimeout("TimeView()", 1000);
	}
	/*----------------------------------------------------------------------*/	


	/*----------------------------------------------------------------------
	** Feldüberprüfung - Datum Neu
	-----------------------------------------------------------------------*/			
	function fDate(vDateName,vDateValue, vDateType, dateCheck)  {

		var strSeperator = ".";		
		var vDateType = 3; // Global value for type of date format		
		var vYearLength = 4; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.		

				
				
		// Fehlerhaftes Datum //////////////////////////////////////////			
		if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
			alert("Datum nicht korrekt!");
		 	vDateName.value = "";
		 	vDateName.focus();			 	
		 	return true;
		}
				
		if (vDateValue.length >= 8  && dateCheck) {
		
			// mmddyyyy ////////////////////////////////////////////////////
			if (vDateType == 1) {
				var mMonth = vDateName.value.substr(0,2);
				var mDay = vDateName.value.substr(3,2);
				var mYear = vDateName.value.substr(6,4)
			}

			// yyyymmdd ////////////////////////////////////////////////////
			if (vDateType == 2) {
				var mYear = vDateName.value.substr(0,4)
				var mMonth = vDateName.value.substr(5,2);
				var mDay = vDateName.value.substr(8,2);
			}

			// ddmmyyyy ////////////////////////////////////////////////////
			if (vDateType == 3) {
				var mDay = vDateName.value.substr(0,2);
				var mMonth = vDateName.value.substr(3,2);
				var mYear = vDateName.value.substr(6,4)
			}
			
			if (vYearLength == 4) {
				if (mYear.length < 4) {
					alert("Datum nicht korrekt!");              	
	             	vDateName.value = "";
	             	vDateName.focus();
	             	return true;
				}
			}
						
			// Create temp. variable for storing the current vDateType
			var vDateTypeTemp = vDateType;
						
           // Change vDateType to a 1 for standard date format for validation
           // Type will be changed back when validation is completed.
           vDateType = 1;
						
           // Store reformatted date to new variable for validation.
           var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
						
			if (!dateValid(vDateValueCheck)) {
				alert("Datum nicht korrekt!");              	
				vDateType = vDateTypeTemp;
				vDateName.value = "";
	            vDateName.focus();								
				return true;
			}
			
			vDateType = vDateTypeTemp;
			return true;

			//vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;			
			
		} else {

			if (vDateType == 1) {
		    	if (vDateValue.length == 2) {
					vDateName.value = vDateValue+strSeperator;
				}
		        if (vDateValue.length == 5) {
					vDateName.value = vDateValue+strSeperator;
		        }
			}
		    
		    if (vDateType == 2) {
				if (vDateValue.length == 4) {
					vDateName.value = vDateValue+strSeperator;
				}
		        if (vDateValue.length == 7) {
					vDateName.value = vDateValue+strSeperator;
		        }
			} 
			
			if (vDateType == 3) {
				if (vDateValue.length == 2) {
					vDateName.value = vDateValue+strSeperator;
				}
		        if (vDateValue.length == 5) {
					vDateName.value = vDateValue+strSeperator;
				}
			}
			
			return true;
		               									
		}

	}
	/*----------------------------------------------------------------------*/	
	
		
	/*----------------------------------------------------------------------
	** Check Datum
	-----------------------------------------------------------------------*/					
	function dateValid(objName) {
	  var strDate;
	  var strDateArray;
	  var strDay;
	  var strMonth;
	  var strYear;
	  var intday;
	  var intMonth;
	  var intYear;
	  var booFound = false;
	  var datefield = objName;
	  var strSeparatorArray = new Array("-"," ","/",".");
	  var intElementNr;
	  // var err = 0;
	  var strMonthArray = new Array(12);
	  strMonthArray[0] = "Jan";
	  strMonthArray[1] = "Feb";
	  strMonthArray[2] = "Mar";
	  strMonthArray[3] = "Apr";
	  strMonthArray[4] = "May";
	  strMonthArray[5] = "Jun";
	  strMonthArray[6] = "Jul";
	  strMonthArray[7] = "Aug";
	  strMonthArray[8] = "Sep";
	  strMonthArray[9] = "Oct";
	  strMonthArray[10] = "Nov";
	  strMonthArray[11] = "Dec";
	  
	  //strDate = datefield.value;
	  strDate = objName;
	  
	  if (strDate.length < 1) {
	     return true;
	  }
	  for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
	     if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
	     {
	        strDateArray = strDate.split(strSeparatorArray[intElementNr]);
	        if (strDateArray.length != 3) 
	        {
	           err = 1;
	           return false;
	        }
	        else 
	        {
	           strDay = strDateArray[0];
	           strMonth = strDateArray[1];
	           strYear = strDateArray[2];
	        }
	        booFound = true;
	     }
	  }
	  if (booFound == false) {
	     if (strDate.length>5) {
	        strDay = strDate.substr(0, 2);
	        strMonth = strDate.substr(2, 2);
	        strYear = strDate.substr(4);
	     }
	  }
	  //Adjustment for short years entered
	  if (strYear.length == 2) {
	     strYear = '20' + strYear;
	  }
	  strTemp = strDay;
	  strDay = strMonth;
	  strMonth = strTemp;
	  intday = parseInt(strDay, 10);
	  if (isNaN(intday)) {
	     err = 2;
	     return false;
	  }
	  
	  intMonth = parseInt(strMonth, 10);
	  if (isNaN(intMonth)) {
	     for (i = 0;i<12;i++) {
	        if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
	           intMonth = i+1;
	           strMonth = strMonthArray[i];
	           i = 12;
	        }
	     }
	     if (isNaN(intMonth)) {
	        err = 3;
	        return false;
	     }
	  }
	  intYear = parseInt(strYear, 10);
	  if (isNaN(intYear)) {
	     err = 4;
	     return false;
	  }
	  if (intMonth>12 || intMonth<1) {
	     err = 5;
	     return false;
	  }
	  if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
	     err = 6;
	     return false;
	  }
	  if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
	     err = 7;
	     return false;
	  }
	  if (intMonth == 2) {
	     if (intday < 1) {
	        err = 8;
	        return false;
	     }
	     if (LeapYear(intYear) == true) {
	        if (intday > 29) {
	           err = 9;
	           return false;
	        }
	     }
	     else {
	        if (intday > 28) {
	           err = 10;
	           return false;
	        }
	     }
	  }
	     return true;
	
	  }
	
	function LeapYear(intYear) {
	  if (intYear % 100 == 0) {
	     if (intYear % 400 == 0) { return true; }
	  }
	  else {
	     if ((intYear % 4) == 0) { return true; }
	  }
	     return false;
	  }
	/*----------------------------------------------------------------------*/	
	
			
		


	/*----------------------------------------------------------------------
	** TR,TD click
	-----------------------------------------------------------------------*/	

	/**
	 * This array is used to remember mark status of rows in browse mode
	 */
	var marked_row = new Array;
	
	/**
	 * Sets/unsets the pointer and marker in browse mode
	 *
	 * @param   object    the table row
	 * @param   integer  the row number
	 * @param   string    the action calling this script (over, out or click)
	 * @param   string    the default background color
	 * @param   string    the color to use for mouseover
	 * @param   string    the color to use for marking a row
	 *
	 * @return  boolean  whether pointer is set or not
	 */
	function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
	{
	    var theCells = null;
	
	    // 1. Pointer and mark feature are disabled or the browser can't get the
	    //    row -> exits
	    if ((thePointerColor == '' && theMarkColor == '')
	        || typeof(theRow.style) == 'undefined') {
	        return false;
	    }
	
	    // 2. Gets the current row and exits if the browser can't get it
	    if (typeof(document.getElementsByTagName) != 'undefined') {
	        theCells = theRow.getElementsByTagName('td');
	    }
	    else if (typeof(theRow.cells) != 'undefined') {
	        theCells = theRow.cells;
	    }
	    else {
	        return false;
	    }
	
	    // 3. Gets the current color...
	    var rowCellsCnt  = theCells.length;
	    var domDetect    = null;
	    var currentColor = null;
	    var newColor     = null;
	    // 3.1 ... with DOM compatible browsers except Opera that does not return
	    //         valid values with "getAttribute"
	    if (typeof(window.opera) == 'undefined'
	        && typeof(theCells[0].getAttribute) != 'undefined') {
	        currentColor = theCells[0].getAttribute('bgcolor');
	        domDetect    = true;
	    }
	    // 3.2 ... with other browsers
	    else {
	        currentColor = theCells[0].style.backgroundColor;
	        domDetect    = false;
	    } // end 3
	
	    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
	    if (currentColor.indexOf("rgb") >= 0)
	    {
	        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
	                                     currentColor.indexOf(')'));
	        var rgbValues = rgbStr.split(",");
	        currentColor = "#";
	        var hexChars = "0123456789ABCDEF";
	        for (var i = 0; i < 3; i++)
	        {
	            var v = rgbValues[i].valueOf();
	            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
	        }
	    }
	
	    // 4. Defines the new color
	    // 4.1 Current color is the default one
	    if (currentColor == ''
	        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
	        if (theAction == 'over' && thePointerColor != '') {
	            newColor              = thePointerColor;
	        }
	        else if (theAction == 'click' && theMarkColor != '') {
	            newColor              = theMarkColor;
	            marked_row[theRowNum] = true;
	            // Garvin: deactivated onclick marking of the checkbox because it's also executed
	            // when an action (like edit/delete) on a single item is performed. Then the checkbox
	            // would get deactived, even though we need it activated. Maybe there is a way
	            // to detect if the row was clicked, and not an item therein...
	            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
	        }
	    }
	    // 4.1.2 Current color is the pointer one
	    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
	             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
	        if (theAction == 'out') {
	            newColor              = theDefaultColor;
	        }
	        else if (theAction == 'click' && theMarkColor != '') {
	            newColor              = theMarkColor;
	            marked_row[theRowNum] = true;
	            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
	        }
	    }
	    // 4.1.3 Current color is the marker one
	    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
	        if (theAction == 'click') {
	            newColor              = (thePointerColor != '')
	                                  ? thePointerColor
	                                  : theDefaultColor;
	            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
	                                  ? true
	                                  : null;
	            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
	        }
	    } // end 4
	
	    // 5. Sets the new color...
	    if (newColor) {
	        var c = null;
	        // 5.1 ... with DOM compatible browsers except Opera
	        if (domDetect) {
	            for (c = 0; c < rowCellsCnt; c++) {
	                theCells[c].setAttribute('bgcolor', newColor, 0);
	            } // end for
	        }
	        // 5.2 ... with other browsers
	        else {
	            for (c = 0; c < rowCellsCnt; c++) {
	                theCells[c].style.backgroundColor = newColor;
	            }
	        }
	    } // end 5
	
	    return true;
	} // end of the 'setPointer()' function

	/*----------------------------------------------------------------------*/