$(document).ready(function(){
  document.onkeydown = doOnKeyDown;
  getSAHeight();
  
  $('#brand').change(function(){
    $('#sModel').attr('disabled', 'disabled');
    var cat = $(this).val();
    $.post('/inc/get_model.php',{
      cat:cat
    },function(response){
      $('#sModel').children().remove();
      $('#sModel').append(response);
      $('#sModel').attr('disabled', '');
      $('#sModel').focus();
    });
  })
});

function getSAHeight() {
  h = (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
  document.getElementById('sa').style.height = h + "px";
}
function doOnKeyDown (e) {
  e = e || window.event;
  if (e.keyCode == 27){
    hideRe();
  }
}
function hideRe() {
  $('#sa').hide();
  $('#advance').hide();
}
function putLayer(mydiv, top) {
  var Width = document.documentElement.scrollTop;

  if (document.body.scrollTop == 0) {
    var Y = document.documentElement.scrollTop;
  } else {
    var Y = document.body.scrollTop;
  }
  heightBrowser = top + Y;
  document.getElementById(mydiv).style.top = heightBrowser + "px";
}

function ReloadCaptcha(){
  $('#mycaptcha_img').attr("src", "/inc/captcha/captcha.php?foo="+Math.random());
}

function getPopup(id, prm1, prm2, prm3) {
  $('#advance').html('<div class="top"></div><div class="mid" id="adcontent"></div><div class="btm"></div>');
  $('#sa').show();
  $('#advance').show();
  $('#adcontent').append('<div class="pre"></div>');
  $.ajax({
    url: '/_content/'+id+'.php',
    type: 'POST',
    data: {
      prm1: prm1, 
      prm2: prm2, 
      prm3: prm3
    },
    success: function(answer) {
      $('#advance').html(answer).animate({
        "opacity": "show"
      }, "slow");
      putLayer('advance', 10);
    }
  });
}

function delFile(dprm1, dprm2, dprm3, dprm4) {
  $.post('/_content/profile/services/delfile.php',{
    dprm1:dprm1,
    dprm2:dprm2,
    dprm3:dprm3,
    dprm4:dprm4
  },function(response){
    $("#"+dprm3+"-uploader").show(200);
    $("#"+dprm3+"-uploader .qq-upload-button").show(200);
    $("#"+dprm3+"-uploader li").remove();
    $("#exists-"+dprm3+"").remove();
    $("#"+dprm3+"").val('');
    if (dprm3 == "sImg") $("#imgbox").html('');
  });
}

function delFile2(dprm1, dprm2, dprm3) {
  $.post('/_content/profile/web_ads/delfile.php',{
    dprm1:dprm1,
    dprm2:dprm2,
    dprm3:dprm3
  },function(response){
    $("#"+dprm3+"-uploader").show(200);
    $("#"+dprm3+"-uploader .qq-upload-button").show(200);
    $("#"+dprm3+"-uploader li").remove();
    $("#exists-"+dprm3+"").remove();
    $("#"+dprm3+"").val('');
    if (dprm3 == "sImg") $("#imgbox").html('');
  });
}

function strpos( haystack, needle, offset){
  var i = haystack.indexOf( needle, offset ); // returns -1
  return i >= 0 ? i : false;
}

