function numbersOnly (field, event) {
	  var key, keychar;
	  if (window.event) key = window.event.keyCode;
	  else{
		 if (event) key = event.which;
		 else return true;
	  }
	  keychar = String.fromCharCode (key);
	  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) return true;
	  else {
		 if (("0123456789").indexOf(keychar) > -1) return true;
		 else return false;
	  }
}
$(document).ready(function(){
    $(".menuitem").hover(function(){var id = $(this).attr("id");$("#menu"+id).css({'visibility':'visible'});},function(){var id = $(this).attr("id");$("#menu"+id).css({'visibility':'hidden'});});
});
function LoadingIn(text){$("#loading").html(text);var h = getPageSize();$("#overlay").height(h[1]).fadeIn();/*$("#overlay").css({'top':h[1]}).fadeIn();*/}
function LoadingOut(){$("#overlay").fadeOut();}
function addPosition(id){
    var count = $("#item"+id).val();
	if (count=="" || count==undefined) count = 1;
	var httpParams = "id="+id+"&count="+count;
	$.ajax({url:"/ajax/add.php",data:httpParams,type:"post",success:function(data){LoadingIn('Добавление...');$("#boxorder").html(data);$("#item"+id).val("");LoadingOut();},error:function(data){alert("Не удалось получить данные:"+data);}});
}
function closeOrderTr(id){
   var httpParams = "id="+id;
   $.ajax({url:"/ajax/del.php",data:httpParams,type:"post",success:function(data){LoadingIn('Удаление...');$("#ordertr_"+id+"_1").fadeOut("slow");$("#ordertr_"+id+"_2").fadeOut("slow");if (data==0){$("#aorder").fadeOut("slow");$("#tr_summa").fadeOut("slow");}else{$("#tr_summa div").html("Общая сумма: "+data+" руб.");LoadingOut();}},error:function(data){alert("Не удалось получить данные:"+data);}});  
}
function changeCard(count,id){
   var httpParams = "id="+id+"&count="+count;
   if (count=="" || count==0){closeOrderTr(id);return 0;}
   else{
	 $.ajax({url:"/ajax/change.php",dataType: "json",data:httpParams,type:"post",success:function(data){LoadingIn('Изменение...');var ar = eval(data);
	   $("#tr_summa div").html("Общая сумма: "+ar[0]+" руб.");$("#summa"+id).html(ar[1]);LoadingOut();},error:function(data){alert("Не удалось получить данные:"+data);}});  
   }	  
}
function  getPageSize(){
    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
        xScroll = document.documentElement.scrollWidth;
        yScroll = document.documentElement.scrollHeight;
    } else { // Explorer Mac...would also work in Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) { // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    return [pageWidth,pageHeight,windowWidth,windowHeight];
} 
