$(document).ready(function(){
 
  Shadowbox.init();
 
  $('#title').change(function() {
  var checked_status = $(this).val();
  if (checked_status == 'Other') {
   $("#q1").fadeIn('slow').css('display','block');
   $('#titleother').css('border','1px solid #DD2200');
    }
  });

  $(".radioselect").click(function() {
  var checked_status = $(this).val();
  if (checked_status == 'Full') {
   $("#note").fadeOut('slow');
   $("#payonline").css('display','none');
   $("#paytype").fadeIn("slow").css('display','block');
   } else {
   $("#paytype").fadeOut('slow').css('display','none');
   $("#note").fadeIn('slow').css('display','block').css('background','#FFF4BD').css('padding','10px');
   $("#payonline").css('display','block');
   $("#proceeddps").css('display','none');
   }
  });

  $(".radioselect2").click(function() {
  var checked_status = $(this).val();
  if (checked_status == 'CreditCard') {
   $("#proceeddps").css('display','block');
   $("#payonline").css('display','none');
  } else {
   $("#payonline").css('display','block');
   $("#proceeddps").css('display','none');
  }
  });

  $(".regtype").click(function() {
  var checked_status = $(this).val();
  if (checked_status == 'Student') {
   $("#note").fadeIn('slow').css('display','block').css('background','#FFF4BD').css('padding','10px');
   $("#payonline").css('display','none');
   $("#proceeddps").css('display','block');
    } else {
   $("#note").fadeOut('slow');
   $("#payonline").css('display','none');
   $("#proceeddps").css('display','block');
   }
  });

    $("#payonline").attr("disabled", "disabled");
    $("#proceeddps").attr("disabled", "disabled");

    $("#terms").click(function() {
    var checked_status = this.checked;
    if (checked_status == true) {
    $("#payonline").removeAttr("disabled");
    $("#proceeddps").removeAttr("disabled");
    } else {
    $("#payonline").attr("disabled", "disabled");
    $("#proceeddps").attr("disabled", "disabled");
    }
  });

// Event Registration

  $(".cocktailattendence").click(function() {
  var checked_status = $(this).val();
  if (checked_status == 'Attending Cocktail with Extras') {
   $("#cocktailevent").fadeIn('slow').css('display','block');
   $("#r1").fadeIn('slow');
    } else {
   $("#cocktailevent").fadeOut('slow').css('display','none');
   $("#r1").fadeOut('slow');
   $("#qty_item_2").val(0);
   }
  });

  $(".dinnerattendence").click(function() {
  var checked_status = $(this).val();
  if (checked_status == 'Attending Dinner with Extras') {
   $("#dinnerevent").fadeIn('slow').css('display','block');
   $("#r2").fadeIn('slow');
    } else {
   $("#dinnerevent").fadeOut('slow').css('display','none');
   $("#r2").fadeOut('slow');
   $("#qty_item_3").val(0);
   }
  });
  
/* --------------------------------------------- */
/* Getting Total Cost */ 
/* --------------------------------------------- */
  $(".regtype").click(function() {
  var checked_status = $(this).val();
  if (checked_status == 'Financial Member') {
   var rtype = 350;
   $('#institutionfrom').fadeOut('slow').css('display','none');
   $('#note').fadeOut('slow');
  } else if (checked_status == 'Student') {
   var rtype = 100;
   $('#institutionfrom').fadeIn('slow');
   $("#note").fadeIn('slow').css('display','block').css('background','#FFF4BD').css('padding','10px');
  } else {
   var rtype = 450;
   $('#institutionfrom').fadeOut('slow').css('display','none');
   $('#note').fadeOut('slow');
  } 
  $('#price_item_1').val('$'+rtype+'.00');
  });

 // bind the recalc function to the quantity fields
 $("input[name^=qty_item_]").bind("keyup", recalc);
 $(".regtype").bind("click", recalc);
 $(".cocktailattendence").bind("click", recalc);
 $(".dinnerattendence").bind("click", recalc);
 // run the calculation function now
 recalc();


function recalc(){
$("[id^=total_item]").calc(
	// the equation to use for the calculation
	"qty * price",
	// define the variables used in the equation, these can be a jQuery object
	{
		qty: $("input[name^=qty_item_]"),
		price: $("[id^=price_item_]")
	},
	// define the formatting callback, the results of the calculation are passed to this function
	function (s){
		// return the number as a dollar amount
		return "$" + s.toFixed(2);
	},
	// define the finish callback, this runs after the calculation has been complete
	function ($this){
		// sum the total of the $("[id^=total_item]") selector
		var sum = $this.sum();
		
		$("#totalcost").val(
			// round the results to 2 digits
			sum.toFixed(2)
		);
	}
);
}

// Change the Amount to Send to DPS
 $('#proceed').click(function(){
  var amount = $('#totalcost').val();
  MM_openBrWindow('http://www.pacifichealth.org.nz/checkoutprocess?process=Y&amt='+amount+'','Process','height=600,width=800,status=yes,toolbar=no,menubar=no,location=no');
  return false; 
});
/* --------------------------------------------- */


});

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var currentTime = new Date();
var day = currentTime.getDate();
var month = currentTime.getMonth() + 1;
var year = currentTime.getFullYear();
var displayDate = day + "/" + month + "/" + year;

var a_p = "";
var hour = currentTime.getHours();
if (hour < 12) {
   a_p = "am";
} else {
   a_p = "pm";
}

if (hour == 0) {
   hour = 12;
}

if (hour > 12) {
   hour = hour - 12;
}

var min = currentTime.getMinutes();
min = min + "";
if (min.length == 1) {
   min = "0" + min;
}

var displayTime =  hour + ":" + min + ""+ a_p;

function getDate() {
 document.subscriptionform.mydate.value=displayDate;
 document.subscriptionform.mytime.value=displayTime;
}
