$(document).ready(function() {	

	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//get agent code
		var agentCode = $(this).parent().find("input#agent_code").val();
		var propertyNo = $(this).parent().find("input#property_no").val();
		if(agentCode)
			getAgentDetails(agentCode, propertyNo);
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight,'display':'block','opacity':'0.3'});
		
		//$('#mask').show();
		//transition effect		
		//$('#mask').fadeIn(100);	
		
		$('#mask').fadeTo("fast",0.3);	
		
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		
		if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)){
			//IE explorer
			$(id).css('top',  (winH-$(id).height())/2 + document.documentElement.scrollTop);
		} else  if (navigator.userAgent.indexOf('Firefox') >= 0){
			//firefox
			$(id).css('top',  (winH-$(id).height())/2 + window.pageYOffset);
		}
		
		$(id).css('left', (winW-$(id).width())/2);
	
		//transition effect
		$(id).fadeIn(100); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});

