var popup_is_loaded = 0;

$(document).ready(function(){
  $("a.popup__popup_container_open").each(function(){
    $(this).click(function(){
      var btn_id = $(this).attr('id');
      var p_id = 'popup__'+btn_id;
      loadPopup(p_id);  
    });
  });
    //CLOSING POPUP  
    //Click the x event!  
  $("a.popup__popup_container_close").each(function(){
    $(this).click(function(){
      var p_id = $(this).parent("div.popup__popup_container").attr('id');
      disablePopup(p_id);
    });
  });
  //Press Escape event!  
  $(document).keypress(function(e){  
    if(e.keyCode==27 && popup_is_loaded){  
      disablePopup();  
    }  
  });
  $(".tt").mouseover(function(e){
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = $(document).height();
    if(e.pageX+$(".tt span").width()>windowWidth){
      $(".tt span").css("left",(-10-$(".tt span").width())+"px");
    }else{
      $(".tt span").css("left","20px");
    }
    if (e.pageY+$(".tt span").height()>windowHeight){
      $(".tt span").css("top",(10-$(".tt span").height())+"px");
    }else{
      $(".tt span").css("top","10px");
    }
  })
});  
function empty( x ){
  if(x === "" || x === 0  || x === "0" || x === null || x === false || x === undefined)
    return true;
  return false;
}

function get_object_position(obj){
  var oPosition = {x:0, y:0};
  if(obj == null)
	return oPosition;
  if(obj.offsetParent){
    while (obj.offsetParent){
	//  alert('parent offset: '+obj.offsetLeft + ', '+obj.offsetTop);
	  oPosition.x += obj.offsetLeft;
	  oPosition.y += obj.offsetTop;
	  obj = obj.offsetParent;
	}
  }else if (obj.x){
	oPosition.x += obj.x;
	oPosition.y += obj.y;
  }
 // alert("x: " + oPosition.x + ", y:" + oPosition.y)
  return oPosition;
}

function new_win(link){
  window.open(link,'_blank',"height=400, width=400, left=200, top=200, status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
  return false;
}

function allow_define_login(location){
  $("#"+location+"_login_predefined").hide();
  $("#"+location+"_login_define").show();
}