﻿$(document).ready(
  function()
  {
      $('#ctl00_ContentPlaceHolder1_ddlCities').change(
        function()
        {
          cityChanged();
        }
      );
      
      $('#chkNear').click(
       function()
        {
          cityChanged();
        }
      );
  
  $('.descFull').click(function() {
        $(this).parent().children('span').hide();
        $(this).hide();
        $(this).parent().children('div').show();
    });
  
  }
);

function pRefresh()
{
      $('.descFull').click(function() {
        $(this).parent().children('span').hide();
        $(this).hide();
        $(this).parent().children('div').show();
    });
}

function getPrograms(element)
{
 $.ajax(
          {
            url: "ajax/GetPrograms.ashx",
            type: "POST",
            data: {
                    bandtype: $("input[name='bandType']:checked").val(),
                    timetype: $("input[name='timeType']:checked").val(),
                    sitetype: $("input[name='siteType']:checked").val(),
                    cityid: $('#ctl00_ContentPlaceHolder1_ddlCities').val(),
                    nearcity: $('#chkNear').is(':checked')
                  },
            cache: false,
            dataType: 'json',
            timeout: 10000,
            beforeSend: function (XMLHttpRequest) {
                $('#' + element).after('<img width="10" height="10" border="0" alt="Betöltés" src="common/images/leftmenu_loader.gif" style="margin-left:10px"/>');
            },
			success: function(jsonObj){
			      $('.programSearchMenu img').remove();
                  switch(jsonObj.Status)
                  {
                    case "Ok": showPrograms(jsonObj);
                               pRefresh();
                               break;
                  }
              },
            error:function(ev, XMLHttpRequest, ajaxOptions, thrownError){
            debugger;
                alert("hiba");
               }
          }
        );
}

function showPrograms(jsonObj)
{
    $('#programList').replaceWith(jsonObj.Data);
    gMainMarkerCluster.clearMarkers();
    initClusterer();
    eval(jsonObj.Script);
    refresh();
}

function showCbCities()
{
    $('#ctl00_ContentPlaceHolder1_ddlCities').removeAttr('disabled');
    $('#chkNear').removeAttr('disabled');
}

function hideCbCities()
{
    $('#ctl00_ContentPlaceHolder1_ddlCities').attr('disabled','disabled');
    $('#chkNear').attr('disabled','disabled');
}

function cityChanged()
{
  if ($('#ctl00_ContentPlaceHolder1_ddlCities').val() != "-1")
  {
    getPrograms('ctl00_ContentPlaceHolder1_ddlCities');
  }
}