// JavaScript Document


$(document).ready(function(){	
	downloadHndl.init();
	
	$("a.popup").click(function(){
		
		$.ajax({
			dataType:"html",
			url:this.href,
			success:function(data){
				msgBox.show({
					title:"Inmarsat Terms and Conditions",
					message:data,
					type:"popup"
				})
			},
			error:function(x,t){
				alert("An error occurred during the Ajax request!");
			}
		});
																
		return false;
	})
});




/***********************************/
// msgBox object usage example:
/*
	msgBox.show({
		title:"",				lightBox title
		message:"",				message to display
		type:"alert|popup",		defines the messageBox style.
		callback:function(){}	function to call when the user closes the message box
	})
*/
var msgBox={
	lightBoxBg:$("<div id='lightBoxBg'></div>").attr("tabIndex",0).appendTo("body"),	//creating the BG
	lightBoxPanel:$("<div id='lightBoxPanel'></div>").appendTo("body"),					//creating the panel
	title:$("<p>msgBox</p>").appendTo($("<div class='title'></div>").appendTo($("#lightBoxPanel"))),
	messageBody:$("<div class='message'>msgBox</div>").appendTo($("#lightBoxPanel")),
	closeBtn:$("<a title='close' class='close' href='#close'><span>close</span></a>")
			.click(function(){
				msgBox.close();
				return false;
			})
			.appendTo($("#lightBoxPanel")),
	
	callback:null,
	
	show:function(msgObj){
		msgBox.lightBoxPanel.attr("className",msgObj.type);
		msgBox.title.text(msgObj.title);
		msgBox.messageBody.empty().append(msgObj.message);
		msgBox.callback=msgObj.callback;
		
		if ( $.browser.msie && ($.browser.version=="6.0")) {
			msgBox.lightBoxPanel.css("top",100+document.documentElement.scrollTop)
		}
		
		msgBox.lightBoxBg.fadeTo(200,0.6);
		msgBox.lightBoxPanel.show(0);
	},

	close:function(){
		msgBox.lightBoxPanel.hide(0);		
		if (msgBox.callback) msgBox.callback();	
		msgBox.lightBoxBg.fadeOut(100);		
	}
}


/***********************************/
/* 	downloadHndl:
	Requires: 	div#termsParagraph
				div#termsParagraph input#terms
	
	Looks for:	a.needsTerms
	
	This component prevent the user from following a link (whose className=='needsTerms') if the checkbox#terms is not checked
*/
var downloadHndl={
	termParagraph:null,
	chkBox:null,
	accepted:null,
	init:function(){	
	
		downloadHndl.termParagraph=$("#termsParagraph");
		downloadHndl.chkBox=$("#terms");
		downloadHndl.accepted=$("#terms").attr("checked");
	
		downloadHndl.chkBox.click(function(){
			downloadHndl.accepted=this.checked;
			downloadHndl.termParagraph.removeClass("alert");
		});
		
		$("a.needsTerms").click(function(){
			if (downloadHndl.accepted){
				return true;	
			}else{				
				msgBox.show({
					title:"Warning:",
					message:'<p>Please accept the "Terms and Conditions" before downloading any file.</p>',
					type:"alert",
					callback:function(){
						downloadHndl.termParagraph.addClass("alert")
						$("html").animate({scrollTop:downloadHndl.chkBox.position().top-30},800);
					}
				})
				
				return false;
			}
		})			
	}
}

