
function getMembershipCost(membership_type_id)
{
	// show starter payment
	date = document.getElementById('todays_date').value;
	
	$.get("p/getMembershipCost.php?date="+date+"&ma_membership_type_id=" + membership_type_id,function(txt)
	{
		$("#starter_payment").attr('value', txt);
	});
	
	// show total, including joining fee
	$.get("p/getMembershipCost.php?date="+date+"&ma_membership_type_id=" + membership_type_id + "&JOINING_FEE",function(txt)
	{
		$("#total").attr('value', txt);
	});
	
	//show total with no discount
	$.get("p/getTotalCost.php?date="+date+"&ma_membership_type_id=" + membership_type_id,function(txt)
	{
		$("#pre_discount").attr('value', txt);
	});
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function showSubMenu(){
	var cook = readCookie('style') || 'default';
	if(cook=='default'){
		$('#subm1, #subm2, #subm3, #subm4').css('z-index', '1');
		if($.browser.msie && $.browser.version < 7){
			$('ul',$(this)).css({'z-index':'2',marginLeft:'-750px'}).fadeIn(100);
		}else{
			$('ul',$(this)).css('z-index', '2').fadeIn(100);
		}
	}
}

function hideSubMenu(){
	var cook = readCookie('style') || 'default';
	if(cook=='default'){
		$('ul',$(this)).fadeOut(100);
	}
}


$(function()
{
	var cook = readCookie('style') || 'default';
	
	if(cook=='default'){
	
		var config = {    
		    sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		    interval: 1,
			over: showSubMenu,
			timeout: 500, // number = milliseconds delay before onMouseOut    
		    out: hideSubMenu // function = onMouseOut callback (REQUIRED)    
		};
		
		$('li#m1,li#m2,li#m3,li#m4').hoverIntent( config );

		$('.imageWrapper').cycle();
		
		// animated headerNav thing
		$('#headerNav ul li a').each(function()
		{
			var id = $(this).attr('id');
			var arrTitle = id.split('_');
			var idStrip = arrTitle[1];
			var imgBg = '';
			var t = $(this).text();
			var pos = arrTitle[2];
	
			$(this).css({'position':'relative', 'width':'35px', 'height':'60px', 'background':'url(images/navigation/' + idStrip + '.png) no-repeat left top'});
			$(this).html('<img src="images/navigation/orange_arrow.png" alt="' + idStrip + '" style="position:absolute;bottom:4px;left:13px;" />');
			
			$(this).mouseover(function()
			{
				$(this).css({'background-image':'url(images/navigation/' + idStrip + '_white.png)', 'background-color':'#f60'});
				$(this).animate({height:'110px'}, 400);
				$(this).html('<img src="images/navigation/white_arrow.png" alt="' + idStrip + '" style="position:absolute;bottom:4px;left:13px;" />');
				$('#navText').css({'opacity':'1','right':pos+'px'}).text(t);
			}).mouseout(function()
			{
				$(this).html('<img src="images/navigation/orange_arrow.png" alt="' + idStrip + '" style="position:absolute;bottom:4px;left:13px;" />');		
				$(this).animate({height:'60px'}, 400);
				$(this).css({'background-image':'url(images/navigation/' + idStrip + '.png)', 'background-color':'white'});
				$('#navText').text('').css({'opacity':0});
			});
			
			
		});
		
		$('#offers_home .offerPanel:last').css('margin-right','0px');
		
	}
	
	
	
		
	
		
	$('a').click(function(){
		if($(this).html()=='delete'){
			return confirm('Are you sure you want to delete this?');
		}
	});
		
	$('.flash_box_link').fancyZoom();
	
	// assign a onchange handler to the membership type select
	$('select#membership_type_id').change(function()
	{
		//alert( $(this)[0].selectedIndex );
		
		//getMembershipCost($('#ma_membership_type_id')[0].selectedIndex);
		getMembershipCost(document.getElementById('membership_type_id').options[document.getElementById('membership_type_id').selectedIndex].value);
	});
	
	// assign a onchange handler to the membership type select
	$('select#todays_date').change(function()
	{
		//alert( $(this)[0].selectedIndex );
		
		//getMembershipCost($('#ma_membership_type_id')[0].selectedIndex);
		getMembershipCost(document.getElementById('membership_type_id').options[document.getElementById('membership_type_id').selectedIndex].value);
	});
	
	
	$('#bank_sortcode').focus(function(){
		if($(this).val() == '(format: 00-00-00)'){
			$(this).val('');
		}
	});
	$('#bank_accountnumber').focus(function(){
		if($(this).val() == '(8 digits with no spaces)'){
			$(this).val('');
		}
	});
	
	
	$('#offerTable').tableDnD({
		onDrop: function(table, row) {
	    	$('#'+row.id+' th').css('opacity','1');
	        var rows = table.tBodies[0].rows;
	        //var debugStr = "Row dropped was "+row.id+". New order: ";
	        var debugStr = '';
	        for (var i=0; i<rows.length; i++) {
	            debugStr += rows[i].id.replace('offerTableRow','')+",";
	        }
	        //alert(debugStr);
	        $.get('p/update.offer.display.php?x='+debugStr);
	        
	        $('#offerTable tr:even').attr('class','style1');
	        $('#offerTable tr:odd').attr('class','style2');
	        $('#offerTable tr:first').attr('class','');
	    },
	    onDragStart: function(table, row){
	    	$('#'+row.id+' th').css('opacity','0.5');
	    }
	});
	
	$('#packageTable').tableDnD({
		onDrop: function(table, row) {
	    	$('#'+row.id+' th').css('opacity','1');
	        var rows = table.tBodies[0].rows;
	        //var debugStr = "Row dropped was "+row.id+". New order: ";
	        var debugStr = '';
	        for (var i=0; i<rows.length; i++) {
	            debugStr += rows[i].id.replace('packageTableRow','')+",";
	        }
	        //alert(debugStr);
	        $.get('p/update.package.display.php?x='+debugStr);
	        
	        $('#packageTable tr:even').attr('class','style1');
	        $('#packageTable tr:odd').attr('class','style2');
	        $('#packageTable tr:first').attr('class','');
	    },
	    onDragStart: function(table, row){
	    	$('#'+row.id+' th').css('opacity','0.5');
	    }
	});
	
	/*
	$('.pricesForm').submit(function(){
		$(this).attr('target','_blank');
	});*/
	
	$('#voucher_button').click(function(){
		$('#mccaulays').attr('action', 'membership.php#todays_date');
	});

});

