$().ready( function() {

  if (document.referrer!=undefined && document.referrer!="") {
    googleQuery = processReferrer();
  } else {
    googleQuery = "";
  }

  $.ajax({
      type: "GET",
      url: "/nf/AjaxResponse/quickPostingBottom",
      data: "categoryId=" + categoryId + "&locationId="+ locationId + "&referrer=" + googleQuery + "&rnd=" + Math.random(),
      success: function(resp){
        $("#" + quickPostingBottomTarget).html(resp);        
      }      
    });
  });


function getProvinces(countryId, provinceId, target) {    
  $.ajax({
    type: "GET",
    url: "/nf/AjaxResponse/getProvinces",
    data: "locationId=" + countryId + "&provinceId=" + provinceId /*+ "&bottom=true"*/,
    success: function(resp) {        
      $(target).html(resp);
    }
  });
}

function addFileInput(id, txtFileInput, txtRemove, max) {
  if ($("div#files p").size() < max) {
    nId = id + 1;
    $("div#files").append("<p id='img_p_" + nId + "'><label for='image_" + nId + "' class='optional'>" + txtFileInput + "</label> <input type='file' name='image_" + nId + "' id='image_" + nId + "' onChange=\"addFileInput(" + nId + ", '" + txtFileInput + "', '" + txtRemove + "', "+ max +");\" /> <input type='button' value='" + txtRemove + "' onClick=\"$('p#img_p_" + nId + "').remove();\" name='remove_" + nId + "' /></p>");
  }    
}


function autoSuggestCallback(obj) {

  var ids      = obj.id.split("|");
  var country  = ids[0] || 1;
  var province = ids[1] || 0;

  var countryCombo = $("select#qfbCountry");

  $("select#qfbCountry option:selected").removeAttr('selected');
  $("select#qfbCountry option[value='" + country + "']").attr('selected', 'selected');

  getProvinces(country, province, $("#qfbProvinces"));

  $("select#qfbProvince option:selected").removeAttr('selected');
  $("select#qfbProvince option[value='" + province + "']").attr('selected', 'selected');
}


