$(document).ready(function () {

	// if user clicked on button, the overlay layer or the dialogbox, close the dialog	
	//$('a.btn-ok, #dialog-overlay, #dialog-box').click(function () {
	$('a.buttons, #dialog-overlay').click(function () {		
		$('#dialog-overlay, #dialog-box').fadeOut();	
		$("body").css("overflow","auto");	
		return false;
	});
	
	// if user resize the window, call the same function again
	// to make sure the overlay fills the screen and dialogbox aligned to center	
	$(window).resize(function () {
		
		//only do it if the dialog box is not hidden
		if (!$('#dialog-box').is(':hidden')) popup();		
	});	
	
	/*$("title").text("test");
	$(document).scroll(function(){
		$("title").text(getScrollXY());
	});*/
	 /*$(document).mousemove(function(e){
      $('title').text(e.pageX +', '+ e.pageY);
   }); */
	
});

//Popup dialog
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  //return [ scrOfX, scrOfY ];
  return scrOfY;
}

function popup(message) {
		
	// get the screen height and width  
	//var maskHeight = $(document).height(); 
	//$("body").css("overflow","hidden");
	//$("body").scrollTop();
	$('#dialog-message').html(message);
	
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();
	
	// calculate the values for center alignment
	var dialogTop =  ($(window).height()/3) - ($('#dialog-box').height());  
	var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2); 
	var widths=$('#dialog-box').width();
	//alert($('#dialog-box').height());
	dialogTop=50;
	
	// assign values to the overlay and dialog box
	$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
	$('#dialog-box').css({width:"50px"});
	$('#dialog-box').css({top:dialogTop, left:(maskWidth/2)-($('#dialog-box').width()/2)}).show();
	
	$('#dialog-message').hide();
	
	$('#dialog-box').animate({
	    width:widths,
		left:dialogLeft,
		height:$('#dialog-message').height()-120
	  }, 500, "linear", function(){ 
	  $('#dialog-message').fadeIn();
	   });
	
	
	// display the message
	
	
	//$('#dialog-message').fadeIn();
	
}

function popup1(){
	$.get(
	  'www.dbd.go.th/edirectory/paper/?id=0905551002251&st=1',
	  function(data){
	  alert(data);
	  }
	);
}






function popups(){
		
	/*$.get(
		urls,
		function(data) {
 		$('#dialog-message').html(data);
		}
	);*/
	$.get(
	  'http://www.dbd.go.th/edirectory/paper/index.php?id=0905551002251&st=1',
	  function(data){
	 	$('#dialog-message').html(data);
	  }
	);
	// get the screen height and width  
	//var maskHeight = $(document).height(); 
	//$("body").css("overflow","hidden");
	//$("body").scrollTop();
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	// calculate the values for center alignment
	var dialogTop =  (maskHeight/3) - ($('#dialog-box').height());  
	var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2); 
	
	// assign values to the overlay and dialog box
	$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
	$('#dialog-box').css({top:dialogTop, left:dialogLeft}).fadeIn();
	
	// display the message
	//'www.dbd.go.th/edirectory/paper/?id=0905551002251&st=1',
	
}
