﻿$(function(){
	// Setup vars
	$asx_proceed = $('button#asx_proceed'), proceed_url = $('#asx_url > a').attr('href');
	
	// Set button to 50% opacity on load
	$asx_proceed.css('opacity','0.5');
	
	// Remove opacity on change if checkbox ticked
	$('input#asx_argree').change(function(){
		if( $('input#asx_argree:checked').length > 0 ){
			$asx_proceed.css('opacity','1');
		} else {
			$asx_proceed.css('opacity','0.5');
		}
	});
	
	$('input#asx_argree').click(function(){
		if( $('input#asx_argree:checked').length > 0 ){
			$asx_proceed.css('opacity','1');
		} else {
			$asx_proceed.css('opacity','0.5');
		}
	});

	// ASX checkbox confirm and document url return
	$asx_proceed.click(function(){
		if( $('input#asx_argree:checked').length > 0 ){
			createCookie("asx_terms_accepted", "true", 30);
			document.location = proceed_url;
		} else {
			createCookie("asx_terms_declined", "true", 30);
			return false;
		}
		return false;
	});
});

var asxCookieCheck = function(){
	var asxC1 = readCookie("asx_terms_declined"), asxC2 = readCookie("asx_terms_accepted");
	if(asxC1) {
		document.location = "/asx-announcement";
	} else {
		return false;
	}
};

var deleteAsxCookie = function(){
	eraseCookie("asx_terms_accepted");
	eraseCookie("asx_terms_declined");
};
