function exposepopup(id, hash){
LeftPosition = (screen.width) ? (screen.width-710)/2 : 0;
TopPosition = (screen.height) ? (screen.height-680)/2 : 0;
settings =
'height=680,width=710,top=10,left='+LeftPosition+',scrollbars=yes,resizable=no';
open("/wtsh/de/datenbanken/standort_sh/popup/expose.php?id="+id+"&amp;hash="+hash,"exposepopup",settings);
}

function uploadpopup(filename){
var w = 400;
var h = 300;
LeftPosition = (screen.width) ? (screen.width - w)/2 : 0;
TopPosition = (screen.height) ? (screen.height - h)/2 : 0;
settings = 'width='+w+',height='+h+',top=100,left='+LeftPosition+',scrollbars=no,resizable=no';
open(filename,'uploadpopup',settings);
}


var picked=1;
function bildwechselOn(id, pfad)
{
    if (picked != 0) {
        document.getElementById("exposethumb"+ picked).className="gfpopupthumboff";
    }
    document.getElementById("exposethumb"+ id).className = "gfpopupthumbon";
    document.images['tauschbild'].src = pfad; 
    // ms
    document.images['tauschbild'].alt   = bildbeschreibungen[id-1];
    document.images['tauschbild'].title = bildbeschreibungen[id-1];
    document.getElementById("bildbeschreibung").innerHTML = bildbeschreibungen[id-1];
    //
    picked = id;
}

function bildwechselOff(id) {
if ( id != picked) {
document.getElementById("exposethumb"+ id).className="gfpopupthumboff";
}
}

/* funktionen für's formular */

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

function scrollAnchor(anchorName) {
  //location.hash = anchorName;
  es = document.getElementsByName(anchorName);
  found = false;
  i = 0;
  
  while (i < es.length) {
    if (es[i].nodeName.toLowerCase() == 'a') {
      destinationLink = es[i];
      found = true;
      break;
    }
    i++;
  }
  if (!found) return true;

  // Find the destination's position
  var destx = destinationLink.offsetLeft;
  var desty = destinationLink.offsetTop;
  var thisNode = destinationLink;
  while (thisNode.offsetParent &&
        (thisNode.offsetParent != document.body)) {
    thisNode = thisNode.offsetParent;
    destx += thisNode.offsetLeft;
    desty += thisNode.offsetTop;
  }
  window.scrollTo(0,desty);
}

function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return document.getElementById(movieName);
  } else {
//    alert('non-microsoft');
    m = document.getElementById(movieName);
    return m.getElementsByTagName('embed')[0];
  }
}

function Flashon() {
  $("#gfblocksucheposition").hide();
  
  $("#standort-sh-karte").width(562).height(500);
  if (! $.browser.msie) $("#standort-sh-karte > embed:first").width(562).height(500);
  $("#flashkarte").width(562).height(500);

  setTimeout("scrollAnchor('bottom')", 100);
}

function Flashoff() {
  $("#gfblocksucheposition").show();
  
  $("#standort-sh-karte").width(261).height(270);
  if (! $.browser.msie) $("#standort-sh-karte > embed:first").width(261).height(270);
  $("#flashkarte").width(261).height(270);

  status=0;
}

var cdi=0; // can do it

var r_kern  = Array('s_kiel', 'k_rendsburgeckernfoerde', 's_neumuenster');
var r_metro = Array('k_dithmarschen', 'k_steinburg', 'k_pinneberg', 'k_segeberg', 'k_stormarn', 'k_herzogtumlauenburg', 's_norderstedt');

function updateFlash (dump, obj) {
if(!obj) {
obj = this;
}
    aktiv = Array();
    inaktiv = Array();
    
  	for (var j=0; j<obj.options.length; j++) {
  	  if(obj.options[j].selected == true) {
  	    if (obj.options[j].value.indexOf("r_") == 0) {
  	      values = eval(obj.options[j].value);
  	      for (key in values) aktiv.push(values[key]);
  	    } else {
  	      aktiv.push(obj.options[j].value);
  	    }
  	  } else {
  	    inaktiv.push(obj.options[j].value);
  	  }
  	}
  
  	str_aktiv = ";"+aktiv.join(";")+";";

//jsonDisables
//{"ids": ["ort", "plz"], "wqclass": "wqDisabled"}
//if(str_aktiv.indexOf(";s_") !== -1) {
//if(aktiv.length > 0) {
if(aktiv.length == 1 && aktiv[0].indexOf("s_") !== -1) {

  for (i = 0; i<jsonDisables.ids.length; i++) {
    obj = $("#"+jsonDisables.ids[i]);

obj.parent("div").hover( function() {
$("#tooltip").html("Bei Auswahl eines Kreises oder einer Stadt ist in diesem Bereich keine Eingabe nötig");
  $("#tooltip").show();
  $(document).mousemove( function(e) {
    $("#tooltip").css({
      left: e.pageX + 20 + "px",
      top: e.pageY + 10 + "px"
    });
  } );
}, function() {
  $(document).unbind("mousemove");
  $("#tooltip").hide();
}).css( { background: "url(/wtsh/standort_sh/media/bilder/_layout/stripes.gif)" } );

    obj.attr("disabled", "disabled");
    obj.addClass(jsonDisables.wqclass);
  }
} else if (aktiv.length > 0) {

  for (i = 0; i<jsonDisables.ids.length; i++) {
if(jsonDisables.always[i]) {
    obj = $("#"+jsonDisables.ids[i]);

obj.parent("div").hover( function() {
$("#tooltip").html("Bei Auswahl eines Kreises oder einer Stadt ist in diesem Bereich keine Eingabe nötig");
  $("#tooltip").show();
  $(document).mousemove( function(e) {
    $("#tooltip").css({
      left: e.pageX + 20 + "px",
      top: e.pageY + 10 + "px"
    });
  } );
}, function() {
  $(document).unbind("mousemove");
  $("#tooltip").hide();
}).css( { background: "url(/wtsh/standort_sh/media/bilder/_layout/stripes.gif)" } );

    obj.attr("disabled", "disabled");
    obj.addClass(jsonDisables.wqclass);
} else {
    obj = $("#"+jsonDisables.ids[i]);

obj.parent("div").unbind("hover").css( { background: "none" } );

    obj = $("#"+jsonDisables.ids[i]);
    obj.removeAttr("disabled");
    obj.removeClass(jsonDisables.wqclass);
}
  }

  
} else {

  for (i = 0; i<jsonDisables.ids.length; i++) {
    obj = $("#"+jsonDisables.ids[i]);

obj.parent("div").unbind("hover").css( { background: "none" } );

    obj = $("#"+jsonDisables.ids[i]);
    obj.removeAttr("disabled");
    obj.removeClass(jsonDisables.wqclass);
  }
}

  	str_inaktiv = ";";
  	for(key in inaktiv) {
  	  if(str_aktiv.indexOf(";"+inaktiv[key]+";") == -1) {
  	    str_inaktiv += inaktiv[key]+";";
  	  }
  	}
  
  	str_aktiv = str_aktiv.substring(1,(str_aktiv.length-1));
  	str_inaktiv = str_inaktiv.substring(1,(str_inaktiv.length-1));
  	thisMovie('standort-sh-karte').SetVariable("_flash0/java_mc:aktiv", str_aktiv);
  	thisMovie('standort-sh-karte').SetVariable("_flash0/java_mc:inaktiv", str_inaktiv);
  	thisMovie('standort-sh-karte').TGotoFrame("_flash0/java_mc", 5);
  	thisMovie('standort-sh-karte').TPlay("_flash0/java_mc");
  }

var jsonDisables;
function init() {
  $("#kreis_stadt").change( updateFlash );
}


function regionKlick2(str_aktiv) {
  str_aktiv = ";"+str_aktiv+";";
  
  $("#kreis_stadt > option").each( function(i) {
    if (str_aktiv.indexOf(";"+this.value+";") != -1) this.selected = true;
    else this.selected = false;
  });

  $("#kreis_stadt").change();
}


function addGreyOut(idElement, aGreyOut, sClass, iLen, sErsatz, disableFlash) {
    $("#"+idElement).keyup( function () {
      if ( $(this).val().length >= iLen ) {

if(disableFlash) {
  	thisMovie('standort-sh-karte').SetVariable("_flash0/_root:inaktivText", sErsatz);
  	thisMovie('standort-sh-karte').TGotoLabel("_flash0/bg_mc", "inaktiv");
  	thisMovie('standort-sh-karte').TPlay("_flash0/bg_mc");
}

for(var d=0; d<aGreyOut.length; d++) {
  var obj = $('#'+aGreyOut[d]);

//Hier Tooltip hinzfügen!!
obj.parent("div").hover( function() {
$("#tooltip").html(sErsatz);
  $("#tooltip").show();
  $(document).mousemove( function(e) {
    $("#tooltip").css({
      left: e.pageX + 20 + "px",
      top: e.pageY + 10 + "px"
    });
  } );
}, function() {
  $(document).unbind("mousemove");
  $("#tooltip").hide();
}).css( { background: "url(/wtsh/standort_sh/media/bilder/_layout/stripes.gif)" } );

        obj.attr("disabled", "disabled");
        obj.addClass(sClass);

}
      } else {

if(disableFlash) {
  	thisMovie('standort-sh-karte').TGotoLabel("_flash0/bg_mc", "aktiv");
  	thisMovie('standort-sh-karte').TPlay("_flash0/bg_mc");
}

for(var d=0; d<aGreyOut.length; d++) {
  var obj = $('#'+aGreyOut[d]);

obj.parent("div").unbind("hover").css( { background: "none" } );
        obj.removeAttr("disabled");
        obj.removeClass(sClass);
        obj.change();

}
      }
    });
}



/* autosuggest für ort */

function suggestInit ( idElement, idSuggestionBox, jsonFormElements ) {
  var oSuggestionBox = $("#"+idSuggestionBox);
  $("#"+idElement).blur( function() { $("#"+idSuggestionBox).hide(); } );
  $("#"+idElement).keyup( function(oEvent) {
    if (!oEvent) oEvent = window.event;
    var iKeyCode = oEvent.keyCode;
/*    if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode <= 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {  }
    else {*/
      if(this.value.length > 1) {
        
        // [{id:"kreis_stadt", type:"select"}, {id:"autobahn", type:"text"}]
        sParams = '';
        for (i = 0; i<jsonFormElements.length; i++) {
            if (jsonFormElements[i].type == 'select') {
                tmp = '';
                $("#"+jsonFormElements[i].id+" > option").each( function(i) { if(this.selected) tmp += this.value+";"; } );
                sParams += '"'+jsonFormElements[i].id+'"' + ":\""+ tmp.substr(0,tmp.length-1) + "\", ";
            } else {
                sParams += '"'+jsonFormElements[i].id+'"' + ":\"" + $("#"+jsonFormElements[i].id).val() + "\", ";
            }
        }
        sParams = "{"+sParams.substr(0,sParams.length-2)+"}";

        $.getJSON("/wtsh/standort_sh/_comp/wquadrat/standortsh_ajax_ortssuche.php", eval('('+sParams+')'), function(json){
            var sSuggestions = '';
            for ( var i = 0; i<json.length; i++) {
                if(json[i].anzahl>=0) anzahl = ' ('+json[i].anzahl+')';
                else anzahl = '';
                sSuggestions += '<div onmouseover="this.className=\'sOver\'" onmouseout="this.className=\'sOut\'" onmousedown="$(\'#'+idElement+'\').val(\''+json[i].ort+'\');">'+json[i].ort+anzahl+'</div>';
            }
            $("#"+idSuggestionBox).html(sSuggestions).show();
        });
      } else {
        $("#"+idSuggestionBox).html('').hide();
      }
/*    }*/
  });
}

function addNumFilter (sElement, iLen) {
  oElement = $("#"+sElement);
  oElement.keyup(function (oEvent) {
    if (!oEvent) {
      oEvent = window.event;
    }
    var iKeyCode = oEvent.keyCode;
    
    if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode <= 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {
      //ignore
    } else {
      this.value = this.value.replace(/[^\d]/g, '');
    }
  });
}


$(document).ready(function() {
    $("body").append('<div id="tooltip" class="tooltip">Dieses Element ist momentan deaktiviert.</div>');
jsonDisables = {"ids": ["ort", "plz"], "always": [0,1], "wqclass": "wqDisabled"};
    init();
//$("#kreis_stadt").load(updateFlash);
//window.setTimeout("updateFlash(null, $('#kreis_stadt').get(0))", 1000);
//updateFlash('nada', $("#kreis_stadt").get(0));
    suggestInit('ort', 'sBoxOrte', [{id:"kreis_stadt", type:"select"}, {id:"objektart", type:"select"}, {id:"ort", type:"text"}, {id:"autobahn", type:"text"}, {id:"bahn", type:"text"}, {id:"hafen", type:"text"}, {id:"flughafen", type:"text"}]);
    addNumFilter('plz', 5);
    addNumFilter('autobahn', 3);
    addNumFilter('bahn', 3);
    addNumFilter('hafen', 3);
    addNumFilter('flughafen', 3);
    addGreyOut('plz', ['ort', 'kreis_stadt'], 'wqDisabled', 1, 'Bei Angabe einer PLZ ist in diesem Bereich keine Eingabe nötig', true);
    addGreyOut('ort', ['plz'], 'wqDisabled', 1, 'Bei Angabe eines Ortes ist in diesem Bereich keine Eingabe nötig', false);
//    addGreyOut('ort', 'kreis_stadt', 'wqDisabled', 2, 'Bei Auswahl einer Stadt ist in diesem Bereich keine Eingabe nötig');
});
