function winOpen(theURL,winName,features) 
{ 
  winName = window.open(theURL,winName,features); 
  
  if(winName == null || winName.closed)
    window.open(theURL,winName,features);
  else
    winName.location.href = theURL;

  if (!winName.closed) 
    winName.focus(); 
}

function switch2Url(targeturl)
{
  if (targeturl != null)
  {
    var values = targeturl.split(";"); 
    var target = values[0];
    var href = values[1];
    
    switch (target)
    {
      case "_self":
        self.document.location.href = href;
        break;
      case "_top":
        top.document.location.href = href;
        break;
      case "_parent":
        parent.document.location.href = href;
        break;
      case "_blank":
        window.open(href, target, "", "toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600");
        break;
      case "_winopen":
        window.open(href, target, "", "toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600");
        break;
      default:
        if (document.location.frames == null || document.location.frames[target])
          document.location.href = href;
        else
          document.location.frames[target].href = href;       
    }
  }
}

function sendSearch()
{
  var suchstring = escape(document.getElementById("suchanfrage").value);
  document.location.href = "/Suche.aspx?searchvalue=" + suchstring;
}

function stopSubmit(e)
{
  return false;
}

function stopEvent(e)
{
  if (!e)
    e = window.event;

  var keyCode = 0;

  if (e.which) {
    keyCode = e.which;
  } else if (e.keyCode) {
    keyCode = e.keyCode;
  }


  if(keyCode == 13 || keyCode == 96)
  {
    if (document.getElementById("onControls"))
    {   
      document.getElementById("onControls").onsubmit = stopSubmit; 
    }
    sendSearch();
  }
}

function setAction()
{
  document.getElementById("suchanfrage").onkeydown = stopEvent;
}

function printtxt()
  {
    var Url = encodeURI(document.location.href);
    window.open("/module/print/print.aspx?url=" +encodeURIComponent(Url)+"&outputtype=text", "Drucken","width=775,height=800,scrollbars=yes");
  }

function printpdf()
  {
    var Url = encodeURI(document.location.href);
    window.open("/module/print/print.aspx?url=" +encodeURIComponent(Url)+"&outputtype=pdf", "Drucken","width=775,height=800,scrollbars=yes");
  }

function printnormal()
  {
    var Url = encodeURI(document.location.href);
    window.open("/module/print/print.aspx?url=" +encodeURIComponent(Url)+"&outputtype=html", "Drucken","width=775,height=800,scrollbars=yes");
  }

function setCursor()
{
  var login = document.getElementById("UserLogin");
  if (login != null) {
    login.focus();
  }
}

function updateFBSuche()
{
  ajaxCallCBLAjax(document.getElementById("landesverbandfachbetriebe").value);
}


function myCallbackOCRcontent()
{
  if (document.location.href.indexOf('ContentReader.aspx?remotePage=/Software.aspx') > -1)
  {
    var e = document.getElementById('teaser');
    e.style.display = 'none';
  }
}
var isTeaser = false;

function setValueOnElement(id, value) {
  document.getElementById(id).value = value;
}

function myCallbackfooter_plzOrtUpd(value) {
  if ($(value).find('li').length > 0) {
    if(!isTeaser) {
      $('#plzchoose').css({"left": "705px", "top": "289px"});
    }
    $('#plzchoose').show();
  } else {
    setStadtMitte();
  }
}

function checkPLZ(teaser) {
  if (teaser) {
    isTeaser = teaser;
  }

  if (teaser || ($('.fbsinput').filter(function () { return $(this).val(); }).length >= 1
    || $('#hiderSucheingabe_fbSucheingabe_ausbildungsbetrieb')[0].checked
    || ($('.dropdownCBL > input').length > 0 && $('.dropdownCBL > input:checked').length)
    ))
  {

  if ($('#plzbox').length) { // ALT
    if ($('#plzbox')[0].value.length != 5 && $('#umkreisfachbetriebe')[0].value != -1 && $('#ortsname')[0].value != '') {
      ajaxCallfooter_plzOrtUpd($('#ortsname')[0].value);
    } else {
      plzortSubmit();
    }
  } else {
    if (teaser) {
      if ($('#fbSucheingabe_plzbox').length) { // NEU
        if ($('#fbSucheingabe_plzbox')[0].value.length != 5 && $('#fbSucheingabe_umkreis')[0].value != -1 && $('#fbSucheingabe_ortsname')[0].value != '') {
          ajaxCallfooter_plzOrtUpd($('#fbSucheingabe_ortsname')[0].value);
        } else {
          plzortSubmit();
        }
      }
    } else {
      if ($('#hiderSucheingabe_fbSucheingabe_plzbox').length) { // NEU
        if ($('#hiderSucheingabe_fbSucheingabe_plzbox')[0].value.length != 5 && $('#hiderSucheingabe_fbSucheingabe_umkreis')[0].value != -1 && $('#hiderSucheingabe_fbSucheingabe_ortsname')[0].value != '') {
          ajaxCallfooter_plzOrtUpd($('#hiderSucheingabe_fbSucheingabe_ortsname')[0].value);
        } else {
          plzortSubmit();
        }
      }
    }
  }
} else {
  $('#errortext')[0].innerHTML = 'Bitte schr&auml;nken Sie die Suchkriterien weiter ein!';
}
  return false;
}

function setStadtMitte() {
  if ($('#plzbox').length) { // ALT
    if ($('#ortsname')[0].value.indexOf('(Stadtmitte)') == -1) {
      $('#ortsname')[0].value += ' (Stadtmitte)';
      $('#plzbox')[0].value = '';
    }
  } else {
    if ($('#hiderSucheingabe_fbSucheingabe_ortsname')[0].value.indexOf('(Stadtmitte)') == -1) {
      $('#hiderSucheingabe_fbSucheingabe_ortsname')[0].value += ' (Stadtmitte)';
      $('#hiderSucheingabe_fbSucheingabe_plzbox')[0].value = '';
    }
  }
  plzortSubmit();
}

function setPLZ(plz) {
  if ($('#plzbox').length) { // ALT
    if ($('#ortsname')[0].value.indexOf('(Stadtmitte)') != -1) {
      $('#ortsname')[0].value = $('#ortsname')[0].value.replace(' (Stadtmitte)', '');
    }
    $('#plzbox')[0].value = plz;
  } else {
if (isTeaser) {
    if ($('#fbSucheingabe_ortsname')[0].value.indexOf('(Stadtmitte)') != -1) {
      $('#fbSucheingabe_ortsname')[0].value = $('#fbSucheingabe_ortsname')[0].value.replace(' (Stadtmitte)', '');
    }
    $('#fbSucheingabe_plzbox')[0].value = plz;

} else {
    if ($('#hiderSucheingabe_fbSucheingabe_ortsname')[0].value.indexOf('(Stadtmitte)') != -1) {
      $('#hiderSucheingabe_fbSucheingabe_ortsname')[0].value = $('#hiderSucheingabe_fbSucheingabe_ortsname')[0].value.replace(' (Stadtmitte)', '');
    }
    $('#hiderSucheingabe_fbSucheingabe_plzbox')[0].value = plz;
}
  }
  plzortSubmit();
}

function plzortSubmit() {
  $('#plzchoose').hide();

if (isTeaser) {

        var url = 'FachbetriebSuche.aspx?doPostback=true&stringPlz=' + $('#fbSucheingabe_plzbox')[0].value + '&stringUmkreis=' + $('#fbSucheingabe_umkreis')[0].value + '&stringOrt=' + $('#fbSucheingabe_ortsname')[0].value;
        document.location.href = url;
        return false;

} else {
  if(typeof window.mySubmitfachbetriebe == 'function') { 
    mySubmitfachbetriebe();
  } else {
    mySubmitV2('fbSucheingabe');
  }
  document.forms[0].submit();
}

}

  var xmlhttpfooter_plzOrtUpd;
   function loadXMLDocfooter_plzOrtUpd(url, callback, sc, params)
   {
     scriptCallback = 'if (callback){ callback(filterhtml(window["xmlhttp" + ClientID].responseText, "", ""));}';
     if (!callback || callback == '')
     {
       scriptCallback = '';
     }
     loadXMLDocV2(url, callback, sc, params, 'footer_plzOrtUpd', true, false, true, '', 25000, '0', scriptCallback, false, '', '', false, 'footer_plzOrtUpd', false, '__VIEWSTATE');
   }

 function callbackfooter_plzOrtUpd(result) 
{
  callbackAjaxV2(result, 'footer_plzOrtUpd', 'document.getElementById("footer_plzOrtUpd").innerHTML', false, '');
}

function ajaxCallfooter_plzOrtUpd(params)
{
  callback = 'callbackfooter_plzOrtUpd';
  scriptCallback = 'if (callback){ callback(filterhtml(window["xmlhttp" + ClientID].responseText, "", ""));}';
  scriptCallback = scriptCallback.replace(/callback/g, callback);
  if (!callback || callback == '')
  {
    scriptCallback = '';
  }

  ajaxCallAjaxV2(params, 0, '', 'document.getElementById("footer_plzOrtUpd").innerHTML', '\x2fmodule\x2fajax\x2fAjaxPlzOrt.aspx\x3fajax\x3dfooter_plzOrtUpd', 'callbackfooter_plzOrtUpd' , false, 'footer_plzOrtUpd', true, false, true, '' , 25000, '0', scriptCallback, false, '', '', false, 'footer_plzOrtUpd' , false, '__VIEWSTATE')
}

function myCallbackCBLAjax(html)
{
  var id = getParameterByName('stringRegionId');
  if (id != '' && document.getElementById('landesverbandRegionenfachbetriebe_Data_' + id))
  {
    document.getElementById('landesverbandRegionenfachbetriebe_Data_' + id).checked = true;
    checkPLZ(false);
  }
}

function getParameterByName( name ) 
{ 
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
  var regexS = "[\\?&]"+name+"=([^&#]*)"; 
  var regex = new RegExp( regexS ); 
  var results = regex.exec( window.location.href ); 
  if( results == null ) 
    return ""; 
  else 
    return decodeURIComponent(results[1].replace(/\+/g, " ")); 
} 

/*
nun in behaviour.js
function initTabsFBDetails() {
  if ($('#tab_map').length > 0) {
  $('.generate-ui-tab').tabs({
    show: function (event, ui) {
      if (ui.panel.id == 'tab_map') {
        reInitGoogleMaps();
      }
     else if (ui.panel.id == 'tab_samples') {

    $('#mycarousel').jcarousel({
        scroll: 4});
 }
    }
  });
}
}
*/

function reInitGoogleMaps() {
  if (map) {
    google.maps.event.trigger(map, 'resize');
    map.setCenter(mapCenter);
  }
}

function addDragendListener() {
  google.maps.event.addListener(arrMarker[0], 'dragend', function () { updateCoords(arrMarker[0]); });
}

function updateCoords(marker) {
  var latlng = marker.getPosition();
  $('#updeinleitung_profilBearbeiten_lat')[0].value = latlng.lat().toString().replace('.', ',');
  $('#updeinleitung_profilBearbeiten_lng')[0].value = latlng.lng().toString().replace('.', ',');
}

function fbEdit(a) {
  $('#' + a + 'Preview').toggle();
  $('#' + a + 'Edit').toggle();
  if (a = 'standort') { reInitGoogleMaps(); 
 $("#updeinleitung_profilBearbeiten_gmapsEdit").css({'position':'static'});
 $("#updeinleitung_profilBearbeiten_gmapsEdit").css({'position':'relative'});
}

}

function fbSave(a) {
  $('#' + a + 'Preview').toggle();
  $('#' + a + 'Edit').toggle();
  document.forms[0].submit();
  //ajaxCallctl00_ctl00_MainContent_Content_updeinleitung();
  if (a = 'standort') {
 $("#updeinleitung_profilBearbeiten_gmapsEdit").css({'position':'static'});
 $("#updeinleitung_profilBearbeiten_gmapsEdit").css({'position':'relative'});
}
}

function mySubmitfbSucheingabe() {
checkPLZ(true); return false;
}
