$(function() {
    $(".fil_chk").click(filter_submit);
    $(".fil_drop").change(filter_submit);
    filter_submit();
});

function filter_submit() {
    var url = "/global_phone_display/results.php";
    var dataString = "";
    $('input.fil_chk:checked').each(function(index) {
        dataString += $(this).attr('name') + "=" + $(this).val() + "&";
    });
    $('select.fil_drop').each(function(index) {
        dataString += $(this).attr('name') + "=" + $(this).val() + "&";
    });
    $('input.fil_hid').each(function(index) {
        dataString += $(this).attr('name') + "=" + $(this).val() + "&";
    });
    console.log(dataString);
    $.ajax({
        type: "GET",
        url: url,
        data: dataString,
        success: function(data) {
            $("#results").html(data);
        }
    })
}

cam_update = function() {
   var mpixel = document.getElementById('mpixel');
   var cam = document.getElementById('CAM');
   if ( mpixel.value != 'any' ) { 
       cam.checked = true;
   }
   else if ( cam.disabled == false ) document.getElementById('CAM').checked = false;
}
 
mpixel_update = function() {
   var cam = document.getElementById('CAM');
   var mpixel = document.getElementById('mpixel');
   if ( cam.checked ) mpixel.selectedIndex = 1;
   else mpixel.selectedIndex = 0;
}

function toggleCompare(id)
{
  //if(getElementById(id).checked == false) {
     if( checked_phones.contains(id) ) {
        checked_phones.remove(id);
   //  }
  }
  else {
     checked_phones.push(id);
  }

  //alert(checked_phones.implode(','));
}

function openCompare()
{
    if(checked_phones.length > 10) {
        alert("Too Many Plans Selected. Please only select up to 10.");
    }
    else if( checked_phones.length < 1 ) {
        alert('Please select between 1 and 10 phones to compare');
    }
    else {
        var url = "/global_compare/compare_phones.php?zip=&type=single&phone_list=" + checked_phones.implode(',');
        window.open(url,"COMPARE","toolbar=no,menubar=no,scrollbars=1,width=100,height=400");
    }
}
