//------------------------------------------------------[TG]
// Public: JS
//------------------------------------------------------[TG]


function addBookmark(title,url) {
	if (window.sidebar) { 
	window.sidebar.addPanel(unescape(title), url,""); 
	} else if( document.all ) {
	window.external.AddFavorite( url, unescape(title));
	} else if( window.opera && window.print ) {
	return true;
	}
}


function ShowNotes(NoteID) {
	if($('#Note' + NoteID).css('display') ==  'none')
		$('#Note' + NoteID).css('display','block');
	else if ($('#Note' + NoteID).css('display') ==  'block')
		$('#Note' + NoteID).css('display','none');	
}

// PopCal-----------------------------------------------[BD]
var PopCal = function(){
	this.HoverClass = 'Hover';

	this.Create = function( Config ){
		var Error = '';

		if( !Config.ButtonImg )
			Error = 'ButtonImg not set.';
		else if( !Config.RelativeParent )
			Error = 'RelativeParent not set.';
		else if( !Config.InputID )
			Error = 'InputID not set.';
		else if( !Config.Callback )
			Error = 'Callback not set.';
		
		if( Error )
			alert( 'Error: '+ Error );
		else{
			var ExistingCalendar = document.getElementById( 'PopCal_'+ Config.InputID );

			if( ExistingCalendar )
				ExistingCalendar.parentNode.removeChild( ExistingCalendar );
			else{
				var CurrentValue = document.getElementById( Config.InputID ).value;
				var QueryString = new Array( 'InputID='+ Config.InputID, 'Value='+ CurrentValue, 'Callback='+ Config.Callback, 'FocusOnValue=TRUE' );

				if( Config.DateFormat )
					QueryString.push( 'DateFormat='+ Config.DateFormat );
				if( Config.DateStart )
					QueryString.push( 'DateStart='+ Config.DateStart );
				if( Config.DateEnd )
					QueryString.push( 'DateEnd='+ Config.DateEnd );

				var Calendar = document.createElement( 'iframe' );
					Calendar.frameBorder	= 0;
					Calendar.style.width	= ( Config.Width ? Config.Width : '200' ) + 'px';
					Calendar.style.height	= ( Config.Height ? Config.Width : '200' ) + 'px';
					Calendar.style.position	= 'absolute';
					Calendar.style.top		= ( Config.Top ? Config.Top : animation.getBounds( Config.ButtonImg ).top - animation.getBounds( Config.RelativeParent ).top ) +'px';
					Calendar.style.left		= ( Config.Left ? Config.Left : animation.getBounds( Config.ButtonImg ).left - animation.getBounds( Config.RelativeParent ).left ) +'px';
					Calendar.src			= '/xpop_calendar/?'+ QueryString.join( '&' );
					Calendar.id				= 'PopCal_'+ Config.InputID;

				Config.ButtonImg.parentNode.appendChild( Calendar );
			}
		}
	}

	this.InsertDate = function( InputID, MyDate ){
		document.getElementById( InputID ).value = MyDate;
		this.Remove( InputID );

		//document.getElementById( 'HasDate_Yes' ).checked = 'selected';
	}

	this.HighlightDate = function( MyTD ){
		MyTD.className = MyTD.className +' '+ Cal.HoverClass;
	}

	this.UnHighlightDate = function( MyTD ){
		var DayClasses = MyTD.className.split( ' ' );

		var Tmp = new Array();
		for( var i = 0; i < DayClasses.length; i++ ){
			if( DayClasses[i] != Cal.HoverClass )
				Tmp.push( DayClasses[i] );
		}
		
		MyTD.className = Tmp.join( ' ' );
	}

	this.Remove = function( InputID ){
		var MyCalendar = document.getElementById( 'PopCal_'+ InputID );
		MyCalendar.parentNode.removeChild( MyCalendar );
	}
}

var Cal = new PopCal();
//------------------------------------------------------[BD]


// Main Menu -------------------------------------------[SK]
$(document).ready(function(){
	if($('.Header .Navigation .TopNav li table').length){
		$('.Header .Navigation .TopNav li').hover(
			function(){
				$(this).find('table').show();
			},
			function(){
				$(this).find('table').hide();
			}
		)
	}
});
//------------------------------------------------------[SK]

// Inmate Charges Email --------------------------------[MJ]
function SendInmateCharges(e) {
	var myVars = {
		'ChargesUsername'	: $('#Charges_Username').val(),
		'ChargesPassword'	: $('#Charges_Password').val(),
		'ChargesBookingNo'	: $('#Charges_BookingNo').val(),
		'ChargesImageCode'	: $('#Charges_ImageCode').val()
	};
	$.post('/inmatecharges.process/', myVars, 
		function(myReturn) {
			if(myReturn['Status'] == 'Success') {
				// Hide Form
				$('#ChargesForm').css('display','none');
				
				// Show Email Sent
				$('#ChargesSuccess').css('display','block');
			} else {
				// Error
				$('#ChargesError').css('display','block');
				$('#ChargesError').html(myReturn['ErrorMsg']);
				$('.ChargesRequest img').attr('src','/code.image/?Rand='+Math.random(0,900));
				return(false);
			}
		}, 'json');
	return false;
}
//------------------------------------------------------[MJ]