$(document).ready(function(){
$("#nav li:eq(1), #nav > #pr").hover(
  function(){
    $('.item').each(function(){
      $('.more', this).hide();
    });
    $("#pr").show();
    $("#nav li:last").addClass("lihover");
  },
  function(){
    $("#pr").hide();
    $("#nav li:last").removeClass("lihover");
  });

  document.onkeydown = doOnKeyDown;
  getSAHeight();

  $("#sa").ajaxStart(function(){
    hideRe();
    $(this).append('<div id="loading"></div>');
    $(this).show();
  });
  $("#sa").ajaxStop(function(){
    $(this).html('');
  });

});



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 doEdit() {
  $('.pp-res').each(function(){ $(this).hide(); });
  $('.pp-r').each(function(){ $(this).show(); });
}
function doCancel() {
  $('.pp-res').each(function(){ $(this).show(); });
  $('.pp-r').each(function(){ $(this).hide(); });
}

function getPopup(mfile, mode, frm) {
    var options = {
    url:      '/request/'+mfile+'.php',
    type:     'POST',
    data:     {mode:mode},
    success:  function(answer) { 
                $('#advance').html(answer).animate({"opacity": "show"}, "slow");
                if (mode == "save" || mode == "view"){
                  $(document).ready(function(){ $('.pp-r').each(function(){ $(this).hide(); }); });
                }
                if (mode == "showitem"){
                  $(document).ready(function(){ $('.pp-res').each(function(){ $(this).hide(); }); });
                }
                if (mode == "remove") $('.rfq').hide();
                putLayer('advance', 100);
              } 
    }
    if(mode=='showlist'){
      $.ajax(options);
    } else {
      $("#"+frm).ajaxSubmit(options);
    }
}

function getMain(mfile, mode, frm) {
    var options = {
    url:      '/_content/'+mfile+'.php',
    type:     'POST',
    data:     {mode:mode},
    success:  function(answer) { 
                $('#advance').html(answer).animate({"opacity": "show"}, "slow");
                putLayer('advance', 100);
              } 
    }
    $("#"+frm).ajaxSubmit(options);
}


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";
}
