/********** MODAL *****************/
function modal(obj){
	$('body').append($('<div></div>').attr('id','bg_modal')).append($('<div></div>').attr('id','container_modal'));
	
	$('#bg_modal').width($('html')[0].scrollWidth).height($('html')[0].scrollHeight);
	
	$('#container_modal').css(
		{
			top: '50%',
			left: '50%',
			'margin-left': '-'+ parseInt($('#container_modal').width()/2)+ 'px',
			'margin-top': '-'+ parseInt($('#container_modal').height()/2)+ 'px'
		}
	);
	
	$('#bg_modal').css('opacity',0);
	$('#container_modal').css('opacity',0);

	$('#bg_modal').fadeTo(300, 0.5, function(){
		$('#container_modal').load(obj, function(){
			$(this).fadeTo(300, 1);
		});
	});
};
 
function close_modal(){
	$('#container_modal').fadeTo(300, 0, function(){
		$(this).remove();
		$("#bg_modal").fadeTo(300, 0, function(){
			$(this).remove();
		});
	});
}; 

/**************/



jQuery.fn.modal=function(options){if(!options){if(this.attr("href")){var options={url:this.attr("href")}}}else{if(!options.url){if(this.attr("href")){options.url=this.attr("href")}}}var settings={url:"#",backgroundColor:"#000",backgroundOpacity:0.5,position:"center",referencePosition:this,top:0,left:0,closeEsc:true,closeClickOut:false,autoOpen:false};options=jQuery.extend(settings,options);function openModal(){$("body").append($("<img />").attr({src:"/nextelwebsite/images/load.gif",width:88,height:78,alt:"",className:"load"})).append($("<div></div>").addClass("bg_modal")).append($("<div></div>").addClass("view_modal"));var altura=$("html")[0].scrollHeight<$(window).height()?$(window).height():$("html")[0].scrollHeight;$('.bg_modal').css('width', '100%');$('.bg_modal').css('height', altura);if(options.backgroundOpacity!=0){$(".bg_modal").css("background-color",options.backgroundColor);$(".view_modal").css("opacity",0);$(".bg_modal").css("opacity",0)}$("select").css("visibility","hidden");if(options.position=="relative"){var offset=options.referencePosition.offset();leftModal=offset.left;topModal=offset.top}$(".bg_modal").fadeTo("fast",options.backgroundOpacity,function(){$(".view_modal").load(options.url,{nocacheattr:(new Date()).getTime()},function(){$(".load").remove();GB_getPageScrollTop=function(){var yScrolltop;if(self.pageYOffset){yScrolltop=self.pageYOffset}else{if(document.documentElement&&document.documentElement.scrollTop||document.documentElement.scrollLeft){yScrolltop=document.documentElement.scrollTop}else{if(document.body){yScrolltop=document.body.scrollTop}}}return yScrolltop};if(options.position!="center"){var alturaModal=parseInt(options.top)+parseInt(topModal)+parseInt($(".view_modal").height());if(altura<alturaModal){options.top=0;topModal=altura-parseInt($(".view_modal").height())}$(".view_modal").css({marginTop:topModal,marginLeft:leftModal,left:options.left,top:options.top})}else{var url = location.href;if (url.toLowerCase().indexOf("sms.aspx") == -1){$(".view_modal").css({marginTop:parseInt(GB_getPageScrollTop()-($(".view_modal").height()/2)),marginLeft:-parseInt($(".view_modal").width()/2)})}}if(options.backgroundOpacity!=0){$(".view_modal").fadeTo("fast",1)}$("a[rel~='modalclose']").click(function(){closeModal();return false})})});if(options.closeClickOut==true){$(".bg_modal").click(function(){closeModal()})}if(options.closeEsc==true){$(window).keydown(function(event){if(event.keyCode==27){closeModal()}})}return false}if(options.autoOpen==false){this.click(openModal)}else{openModal()}function closeModal(){$(".view_modal").fadeTo("fast",0,function(){$(this).remove()});$(".bg_modal").fadeTo("fast",0,function(){$(this).remove();$("select").css("visibility","visible")});$(window).unbind();$(".bg_modal").unbind();__doPostBack=newDoPostBack}function newDoPostBack(eventTarget,eventArgument){var theForm=document.forms[0];if(!theForm){theForm=document.aspnetForm}if(!theForm.onsubmit||(theForm.onsubmit()!=false)){document.getElementById("__EVENTTARGET").value=eventTarget;document.getElementById("__EVENTARGUMENT").value=eventArgument;theForm.submit()}}this.css("visibility","visible")};$(document).ready(function(){$('a[rel="modal"]').each(function(){$(this).modal()})});
