<!--
	/*
		$Id: searchObj.js,v 1.47 2009/09/24 10:29:40 bernd Exp $
		$AUTOFTP:1 $
		$PURPOSE: Javascript für searchObj.php3 $
		
	*/		

	// ---	
	var GruppeAbw = 30 ;
	var LageAbw = 30;
	var RegionAbw = 30;
	var TypAbw = 100;
	var OrtsLageAbw = 30;
	var WohnLageAbw = 30;
	var OrtAbw = 30;
	var AustAbw= 30;
	var LandAbw= 100;
	var QualityAbw = 100;
	
	var NRaucher = 0;
    var strWDay = new Array ( "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So" ) ;
	var maxAdults = false;

    function GetCheckBox (strObj)  {
        if(strObj) {
            if(strObj.checked)
                strObj.value = 1 ; 
            else
                strObj.value = 0 ; 
        }
    }

	function SetTiere (val) {
		document.form0.TIERE0.value = val ;
	}
	function SetRaucher (val) {
		document.form0.RAUCHER0.value = val ;
	}
	function SetAllergiker (val) {
		
		if(document.form0.ALLERGIKER0)
			document.form0.ALLERGIKER0.value = val ;
	}


   	function ObjekteIn ()   { 
       FillBox (document.form0.OBJNR);
    }
    
    function GetBoxValue (selBox)  {
		if(selBox) {
			if( (selBox.options[selBox.selectedIndex].value) && 
				(selBox.options[selBox.selectedIndex].value != "egal"))
			{
				return selBox.options[selBox.selectedIndex].value ;
			}
		}
		return 0;
	}	
    
	function GetKriterien () {
        var	str4, val  ;
        var persKinder = 0 ;

        if(document.form0.PERSKINDER && document.form0.PERSKINDER.value) {
        	persKinder = document.form0.PERSKINDER.value-0;
		}        
        if(document.form0.PERSONEN && document.form0.PERSONEN.value) {
        	if(isNaN(document.form0.PERSONEN.value))
        		document.form0.PERSONEN.value = 1 ;
			document.form0.PERSONEN.value = document.form0.PERSONEN.value-0;
			persKinder = persKinder - 0;
			if(document.form0.PERSONEN.value > 0) {
				persKinder += document.form0.PERSONEN.value-0;
	        	str4 = "fob_maxpersonen:>=:" +  persKinder;
	        }	
		}
		else if(document.form0.ERWACHSENE && document.form0.ERWACHSENE.value) {
        	if(isNaN(document.form0.ERWACHSENE.value))
        		document.form0.ERWACHSENE.value = 1 ;
			document.form0.ERWACHSENE.value = document.form0.ERWACHSENE.value-0;
			if(document.form0.ERWACHSENE.value > 0) {
				if(maxAdults)
		    		str4 = "fob_maxadults:>=:" + document.form0.ERWACHSENE.value;
				else
		    		str4 = "fob_personen:>=:" + document.form0.ERWACHSENE.value;
	        }	
		}	        
        if(document.form0.KINDER && document.form0.KINDER.value) {
            str4 += ",fob_kinder:>=:("+document.form0.KINDER.value+" - (fob_maxpersonen-"+document.form0.PERSONEN.value+"))" ;
        }
        else if(document.form0.MAXKINDER && document.form0.MAXKINDER.value) {
            str4 += ",fob_kinder:>=:"+document.form0.MAXKINDER.value;
        }

		Check4Time ();		// erstmal die Zeiten korrigieren, wenn notwendig
		Check4Mieter();		// Mieter übernehmen

       	str4 = GetUserKrit(str4);

		if(val = GetBoxValue(document.form0.GRUPPE)) {
   			str4 += ",fob_f_stm_gruppe:=:"+val;
   			if(GruppeAbw >= 100) {
   			} else
   				str4 += ": -= "+GruppeAbw+":"+notGruppe;
       	}
		if(val = GetBoxValue(document.form0.LAGE)) {
   			str4 += ",fob_f_stm_lage:=:"+val;
   			if(LageAbw >= 100) {
   			} else
       			str4 += ": -= "+LageAbw+":"+notLage;
        }
		if(val = GetBoxValue(document.form0.REGION)) {
   			str4 += ",fob_f_stm_region:=:"+val;
			if(RegionAbw >= 100) {
   			} else
   				str4 += ": -= "+RegionAbw+":"+notRegion;
        }
		if(val = GetBoxValue(document.form0.ORT)) {
   			str4 += ",fob_f_stm_ort:=:" + val;
			if(OrtAbw >= 100) {
   			} else
   				str4 += ": -= "+OrtAbw+":"+notOrt;
        }
		if(val = GetBoxValue(document.form0.ORTSLAGE)) {
   			str4 += ",fob_f_stm_ortslage:=:" + val;
			if(OrtsLageAbw >= 100) {
   			} else
   				str4 += ": -= "+OrtsLageAbw+":" + notOrtslage;
        }
		if(val = GetBoxValue(document.form0.WOHNLAGE)) {
   			str4 += ",fob_f_stm_wohnlage:=:" + val;
			if(WohnLageAbw >= 100) {
   			} else
   				str4 += ": -= "+WohnLageAbw+":"+notWohnlage;
        }
		if(val = GetBoxValue(document.form0.TYP)) {
   			str4 += ",fob_f_stm_typ:=:" + val;
   			if(TypAbw >= 100) {
   			} else
   				str4 += ": -= "+TypAbw+":"+notTyp;
        }
		if(val = GetBoxValue(document.form0.AUSSTATTUNG)) {
   			str4 += ",fob_f_stm_ausstattung:=:" + val;
			if(AustAbw >= 100) {
   			} else
  				str4 += ": -= "+AustAbw+":"+notAusstattung;
        }
		if(val = GetBoxValue(document.form0.LAND)) {
   			str4 += ",fob_land:like:" + val;
			if(LandAbw >= 100) {
   			} else
  				str4 += ": -= "+LandAbw+":"+notLand;
        }
		if(val = GetBoxValue(document.form0.STERNE)) {
   			str4 += ",fob_quality:=:" + val;
			if(QualityAbw >= 100) {
   			} else
   				str4 += ": -= "+QualityAbw+":nicht die Kategorie";
        }
        
        // Ausschlusskriterien, müssen erfüllt sein
		if(document.form0.ZIMMER && document.form0.ZIMMER.value) {
			// alert(typeof (document.form0.ZIMMER.value-0));
			document.form0.ZIMMER.value = document.form0.ZIMMER.value-0;
			if(document.form0.ZIMMER.value > 0)
	        	str4 += ",fob_zimmer:>=:" + document.form0.ZIMMER.value;
		}		        
		if(document.form0.RAUCHER0) {
	        if(document.form0.RAUCHER0.value == 'J') {
	            str4 += ",fob_raucher:eq:J" ;
	        }
	        else if(document.form0.RAUCHER0.value == 'N') {
	            str4 += ",fob_raucher:eq:N" ;
	        }
	    }
	    if(document.form0.TIERE0) {    
	        if(document.form0.TIERE0.value == 'J') {
	            str4 += ",fob_tiere:eq:J" ;
	        }
	        else if(document.form0.TIERE0.value == 'N') {
	            str4 += ",fob_tiere:eq:N" ;
	        }
	    }    
	    if(document.form0.ALLERGIKER0) {    
	        if(document.form0.ALLERGIKER0.value == 'J') {
	            str4 += ",fob_allergiker:eq:J" ;
	        }
	        else if(document.form0.ALLERGIKER0.value == 'N') {
	            str4 += ",fob_allergiker:eq:N" ;
	        }
	    }    
	    
	    if(document.form0.NEU) {    
	        if(document.form0.NEU.value == 'J') {
	            str4 += ",fob_flags:&:0x4000" ;
	    	}	
	    }
	   	if(val = GetBoxValue(document.form0.OBJNR)) {
			str4 += ",fob_objnr:like:" + val + "%"; 
	  	}	
	//  	alert(str4);
       	document.form0.SEARCH4.value = str4 ;
	}

    
    var MieterID = 0 ;
    
    function Check4Mieter () {
    	if(MieterID != document.form0.MIETERID.value) {
    		MieterID = document.form0.MIETERID.value ;
    		status = "Mieter ausgewählt ID : " + MieterID;
    	}
        setTimeout ("Check4Mieter()", 500);
    }

    function FocusMieter (key) {
    	var win = window.parent.frames["MieterSuche"] ;
    	
    	if(win) {
    		win.focus();
    		if(win.document.SelMieter.NAME) {
    			win.document.SelMieter.NAME.focus ();
    			if(is.ie5 || is.ie4 || is.nav) {
	    			win.document.SelMieter.NAME.value += String.fromCharCode(key).toLowerCase(); 
	    		}
    		}
    	}
    }

//    var strZeit0 = document.form0.ANREISE.value;
    if(document.form0) {
	    var strZeit0 = "" ;
	    var strZeit1 = document.form0.ABREISE.value;
	    var strNaechte = document.form0.NAECHTE.value;
	    var curDate = new Date ();
	 }
	
	// --

	function GetKey (e) {
		var key = GetKeyCode (e);

//		status = "Key " + key ;		
		if((key >= 65) && (key <= 128)) {	// a - ...
			if((key >= 96) && (key <= 105)) {
			} else {
				var obj = GetEventObj (e);
				if(obj) {
					if(obj.name == "WANTOBJ")
						return ;	
				}	
				FocusMieter (key);
			}	
		}
	}

	function GetKeyObj (e) {
		var key = GetKeyCode (e);
		CancleBubble ();
		alert (key);
	}

	function SetNaechte (strForm) {
		var ZEIT0 = GetFormObject (strForm, 'ANREISE') ;
		var ZEIT1 = GetFormObject (strForm, 'ABREISE') ;
 		var NAECHTE = GetFormObject (strForm, 'NAECHTE') ;

  		if(ZEIT0 && ZEIT1 && NAECHTE) {
			if(! VerifyDatum (ZEIT0))
				return false ;
			if(! VerifyDatum (ZEIT1))
				return false ;
			NAECHTE.value = countDays (ZEIT0, ZEIT1);	
  		}
	}

	function SetTage (strForm) {
		var ZEIT0 	= GetFormObject (strForm, 'ANREISE') ;
		var ZEIT1 	= GetFormObject (strForm, 'ABREISE') ;
 		var TAGE 	= GetFormObject (strForm, 'TAGE') ;

  		if(ZEIT0 && ZEIT1 && TAGE) {
			if(! VerifyDatum (ZEIT0))
				return false ;
			if(! VerifyDatum (ZEIT1))
				return false ;
			TAGE.value = countDays (ZEIT0, ZEIT1);	
  		}
	}


	// setzt das Abreisedatum auf Anreise + TAGE
	function SetAbreise (strForm) {
		var ZEIT0 = GetFormObject (strForm, 'ANREISE') ;
		var ZEIT1 = GetFormObject (strForm, 'ABREISE') ;
 		var TAGE = GetFormObject (strForm, 'TAGE') ;
 		var NAECHTE = GetFormObject (strForm, 'NAECHTE') ;

		if(ZEIT0 && ZEIT1 && TAGE && NAECHTE) {
			if(! TAGE.value) {
				TAGE.value = NAECHTE.value ;
			}
  			if(! VerifyDatum (ZEIT0)) {
				return false ;
			}
			if(isNaN (TAGE.value)) {		// falls die Tage schon gesetzt sind,
				return false ;				// berechnen wir das zweite Datum, andernfalls
			}								// passiert nichts
			var str = ZEIT0.value ;
			var	date= _Str2Date (str);
			var date1= new Date (date.getTime() + ((TAGE.value) * 60*60*1000*24) + 60*60*1000*4);
	
			str = _Date2Str (date1);
			ZEIT1.value = str ;
  			_GetWochenTag ("abwot", str, document.forms[strForm].ABREISE);
        }
  	}

	// bei Änderung der Anreise, Abreise neu setzen
	function ChangeAnreise (strForm) {
		var ANREISE = GetFormObject (strForm, 'ANREISE') ;
		var ABREISE = GetFormObject (strForm, 'ABREISE') ;
 		var NAECHTE = GetFormObject (strForm, 'NAECHTE') ;
 		var TAGE= GetFormObject (strForm, 'TAGE') ;


   		if(ANREISE && ABREISE && NAECHTE && TAGE) {
 			if(! VerifyDatum (ANREISE)) {
            	//status = "Fehler" ;
            	//alert ("der Anreisetag kann nicht in der Vergangenheit liegen...\n" + ZEIT0.value + " - " +  strCurDate);    
				return false ;
			}
  			_GetWochenTag ("anwot", document.forms[strForm].ANREISE.value, document.forms[strForm].ANREISE);
  			
			if(isNaN (NAECHTE.value)) {
				if(ANREISE.value != "")
					SetNaechte (strForm);
				return false ;
			}
			SetAbreise (strForm);
  		}
	}

    function GetWochenTag (obj) {
   		var date0 = _Str2Date (obj.value);
   		var day = date0.getDay();
   		if(typeof strWDay != 'undefined')
   			obj.title = strWDay[day] + " " + obj.value;
    }

    function Check4Time () {
    	_Check4Time(0);
	}
	// überprüft die An und Abreise Werte
    function _Check4Time (setNaechte) {
    	
    	// hat sich das Anreisedatum verändert ?
        if (strZeit0 != document.form0.ANREISE.value) {
            strZeit0 = document.form0.ANREISE.value ;
            
            if(VerifyDate (document.form0.ANREISE, 1)) {
                var date = _Str2Date (document.form0.ANREISE.value);
                /*
                if(date < curDate) {	// liegt in der Vergangenheit ? geht nicht
                    document.form0.ANREISE.value = _Date2Str (curDate);                    
                }
                */
                ChangeAnreise ('form0');
           		_GetWochenTag ('anwot', document.form0.ANREISE.value, document.form0.ANREISE);	
            }
        }
    	// haben sich die Nächte verändert ?
        if (strNaechte != document.form0.NAECHTE.value) {
            strNaechte = document.form0.NAECHTE.value;
            // wenn die Naechte jetzt größer als der Zeitraum sind,
            // dann Abreisedatum und TAGE ändern
            if(strNaechte-0 >  document.form0.TAGE.value-0) {
//            	alert (strNaechte + " > " + document.form0.TAGE.value);
            	document.form0.TAGE.value = document.form0.NAECHTE.value ;
            	SetAbreise('form0');
            }
        }
    	// Abreisedatum geändert ?
        if (strZeit1 != document.form0.ABREISE.value) {
            strZeit1 = document.form0.ABREISE.value ;
            
            if(VerifyDate (document.form0.ABREISE, 1)) {
            	date0 = _Str2Date (document.form0.ANREISE.value);
            	date1 = _Str2Date (document.form0.ABREISE.value);
            	if(date1 > date0) {		// sollte schon sein
                	SetTage('form0');

	            	if(setNaechte || (strNaechte-0 >  document.form0.TAGE.value-0)) {
	            	//	alert ("! " + strNaechte + " > " + document.form0.TAGE.value);
	            		strNaechte = document.form0.TAGE.value ;
		            	document.form0.NAECHTE.value = strNaechte;
					}
				}					
           		_GetWochenTag ("abwot", document.form0.ABREISE.value, document.form0.ABREISE);	
            }
        }
    }
    
    var g_nDateEdit = 0 ;

	// periodische Kontrolle, ob Eingaben gemacht wurden
	function Check4TimeT () {
		if(g_nDateEdit) {
			if(--g_nDateEdit == 0) {
				_Check4Time (1);
			}
		}
    	setTimeout ("Check4TimeT()", 100);
	}    
    
    function EditDate () {
//    	status = "Edit Date..." ;
    	g_nDateEdit = 7 ;
    }

	function AddOption (name, val, text, selected) {
		var box = document.form0.elements[name];
		
		if(box && box.options) {
			box.options.length++ ;
			box.options[box.options.length-1] = new Option (text, val);
			if(selected) {
				box.selectedIndex = box.options.length-1 ;
			}	
		}		
	}
	function ClearBox(name) {
		var i ;
		var box = document.form0.elements[name];
		
		if(box && box.options) {
			do {
				for(i = 0 ; i < box.options.length ; i++) {
					box.options[i] = null ;
				}
			}	
			while (box.options.length);	
		}	
	}
	var searchScript = "../search/fastsearch.php3";
	function ChangeOption(selBox) {
		if(document.form0.CHANGE) {
			document.form0.action = "../katalog/recalc.php" ;
			document.form0.target = "recalc" ;
			document.form0.CHANGE.value = selBox.name ;
			
			document.form0.submit();
			
			document.form0.action = searchScript ;
			document.form0.target = "Kriterien" ;
		}	
	}


    function _GetWochenTag (name, strDate, Field) {
		var obj = GetObjectByName (name);
   		var date0 = _Str2Date (strDate);
   		var day = date0.getDay();
    

		if(obj) {
			innerHTML (obj, strWDay [day]);
		}    	
    	if(Field)
    		Field.title = strWDay[day] + " " + Field.value;
    }

	
	function ExtendedSearch () {
		if(document.images['xSearch']) { 
			if(document.images['xSearch'].src.indexOf("mkriterien") > 0) {
				document.images['xSearch'].src = SiteImgPath + "wkriterien.gif" ;
				ajax_Extended("Step3", 0);
			} else {
				document.images['xSearch'].src = SiteImgPath + "mkriterien.gif" ;
				ajax_Extended("Step3", 1);
			}	
		}
	}
	function Check4ObjCount () {
		try {
			var vars = new Array (7);
			
			if(req) {
				vars[0] = "ObjCount" ;
				vars[1] = document.form0.LAND.options[document.form0.LAND.options.selectedIndex].value ;
				vars[2] = document.form0.REGION?document.form0.REGION.options[document.form0.REGION.options.selectedIndex].value:0 ;
				vars[3] = document.form0.GRUPPE?document.form0.GRUPPE.options[document.form0.GRUPPE.options.selectedIndex].value:0 ;
				vars[4] = document.form0.LAGE?document.form0.LAGE.options[document.form0.LAGE.options.selectedIndex].value:0 ;
				vars[5] = document.form0.WOHNLAGE?document.form0.WOHNLAGE.options[document.form0.WOHNLAGE.options.selectedIndex].value:0 ;
				vars[6] = document.form0.ORTSLAGE?document.form0.ORTSLAGE.options[document.form0.ORTSLAGE.options.selectedIndex].value:0 ;
			
				if(document.form0.PERSONEN)
					vars[7] = document.form0.PERSONEN.value; 
				if(document.form0.ZIMMER)
					vars[8] = document.form0.ZIMMER.value ;
				
//				req.debug = true ;
//				alert(vars);
				req.call ("../search/ajaxSearch.php", "ObjCount", vars, "GET");
			}	
		} 
		catch(e) {
			alert("Fehler aufgetreten");
		}
	}

//-->
