
var Awsp = {

  init:function() {

    $("#my_crye_email").focus(function(e) {
      if($(this).val() == 'Enter Email') {
        $(this).val('');
      }
    }).blur(function(e) {
      if($(this).val() == '') {
        $(this).val('Enter Email');
      }
    });

    $("#my_crye_password").focus(function(e) {
      if($(this).val() == 'Password') {
        $(this).val('');
      }
    }).blur(function(e) {
      if($(this).val() == '') {
        $(this).val('Password');
      }
    });

    $("#region").change(Awsp.updateRegion);
    $("#choose_mls").change(function(e) { $("#browse_form").submit(); });
    $("#choose_sort").change(function(e) { $("#browse_form").submit(); });

  },

  updateRegion:function(e) {

    $("#regionChange").val('1');
    var post_string = $("#searchForm").serialize() + "&requested_content=cities_for_region";
    $.post("index.php", post_string, Awsp.handleUpdateRegion, "text");
    Awsp.block(".block_on_region_change");

  },

  handleUpdateRegion:function(data) {

    $("#regionChange").val('0');
    eval(data);

    var def = $('<option value="0">- All Cities -</option>');
    var city = $("#city");
    city.empty().append(def);

    for(var i in cities) {
      city.append($('<option value="' + i + '">' + cities[i] + '</option>'));
    }

    var def = $('<option value="0">- All Counties -</option>');
    var counties_select = $("#counties");
    counties_select.empty().append(def);

    for(var i = 0; i < counties.length; i++) {
      counties_select.append($('<option value="' + counties[i] + '">' + counties[i] + '</option>'));
    }

    setTimeout(function() { $(".block_on_region_change").unblock(); }, 1000);
    $("#city").val('0');
    $("#counties").val('0');

    if(showSchools == true) {
      $("#schoolList").show();
    } else {
      $("#schoolList").hide();
    }

  },

  block:function(o) {
    $(o).block({
      message: '<h3>Retrieving Data...</h3>',
      css: {
        border: 'none',
        padding: '3px',
        backgroundColor: '#000',
        '-webkit-border-radius': '5px',
        '-moz-border-radius': '5px',
        opacity: .5,
        width: '150px',
        color: '#fff'
      },
      fadeOut: 1000
    });
  }

  

}

