$(function(){
	
	var cookieStatus = readCookie('capesContact');
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
		
			
		$("a[href*='@']").click(function(){
			
			if(cookieStatus == 1) {} //do nothing 		
			
			else {

				var c_email_address = $(this).attr('href');
				var infobox = '<div id="contact_terms" style="position: absolute"><h1>Contact Policy</h1><p>We welcome contact from prospective clients through our website; however, we are not in a position to undertake any engagement until we clear potential conflicts of interest and agree on mutually acceptable terms. We are not responsible to ensure the confidentiality of any unsolicited information received by us outside the attorney/client relationship. As a result, you should not forward us information about a matter that may involve you or others until you receive a written communication (e.g., engagement letter) from us acknowledging that we represent you.<br/><br/>In selecting the ACCEPT button below, you agree that we may review any information you send to us. You acknowledge that our review of your information, even if you submitted it in a good faith effort to engage us and, further, even if you consider it confidential, does not preclude us from representing another client directly adverse to you, even in a matter where that information could and will be used against you. If you understand and accept the foregoing statement and would like to continue your communication with us, please select the ACCEPT button below. Thank you for your understanding.<br/><br/><div align="center"><a class="contact_buttons" id="button_contact_accept" href="">ACCEPT</a><a class="contact_buttons" id="button_contact_decline" href="">DECLINE</a></div><br/></p></div>';
				
	$('#header').after(infobox);

	$('#contact_terms').css("top", ( $(window).height() - $('#contact_terms').height() ) / 2+$(window).scrollTop() + "px");
    $('#contact_terms').css("left", ( $(window).width() - $('#contact_terms').width() ) / 2+$(window).scrollLeft() + "px");

	
	
	
	$('#button_contact_accept').click(function(){handleAccept(true, c_email_address);return false;});
	$('#button_contact_decline').click(function(){handleAccept(false, c_email_address);return false;});

				return false;
			}
			
		});
	
		function handleAccept(acceptCheck, c_email_address){
			
			
			var cookie_exp_date = new Date();
			
			
			if (acceptCheck) { 
				
				$("a[href*='@']").unbind('click');
				document.cookie = 'capesContact=1; expire='+cookie_exp_date.toUTCString()+'; path=/';
				window.location = c_email_address;

			} 
			
			else {

				document.cookie = 'capesContact=0; expire='+cookie_exp_date.toUTCString()+'; path=/';
				window.location = "http://www.capessokol.com/contact-no-accept/";
			} 
		
		$('#contact_terms').hide();

	}

});
