
$(window).scroll(function(){
	if($(document).scrollTop() > 0) {
		$("#vtd-header").addClass("vtd-fixed-header");
	} else {
                $("#vtd-header").removeClass("vtd-fixed-header");
	}
});

$(document).ready(function() {

	$("#vtd_get_quote").click(function() {
		$privacypolicy = $("input[name='vtd_privacy_policy']");
                $($privacypolicy).parent().parent().find(".error").remove();

		if(!$("input[name='vtd_privacy_policy']").is(':checked')) {
			$($privacypolicy).parent().parent().append('<span class="error">You must accept the privacy policy.</span>');
			return;
		}

		$("#vtd_form_status").html('<i class="fas fa-spinner fa-spin"></i>');
		$("#vtd_quote_form").find(".error").remove();
		$currentinsured = 0;

		$currentinsuredval = $("input[name='vtd_current_insured']:checked").val();
		if($currentinsuredval !== undefined) {
			if($currentinsuredval == "on") {
				$currentinsured = 1;
			}
		}
		$email_marketing = false;
		$sms_marketing = false;
		$tel_marketing = false;
		$post_marketing = false;


                if($("input[name='vtd_privacy_email']:checked").length) {
			$email_marketing = true;
		}

               if($("input[name='vtd_privacy_sms']:checked").length) {
                        $sms_marketing = true;
                }

               if($("input[name='vtd_privacy_post']:checked").length) {
                        $post_marketing = true;
                }

               if($("input[name='vtd_privacy_tel']:checked").length) {
                        $tel_marketing = true;
                }




		$data = {vtd_refpage: $("#vtd_refpage").val(), vtd_first_name: $("#vtd_first_name").val(), vtd_last_name: $("#vtd_last_name").val(), vtd_phone_number: $("#vtd_phone_number").val(), vtd_email: $("#vtd_email").val(), vtd_dob: $("#vtd_dob").val(), vtd_postcode: $("#vtd_postcode").val(), vtd_current_insured: $currentinsured, vtd_emailmarketing: $email_marketing, vtd_smsmarketing: $sms_marketing, vtd_telmarketing: $tel_marketing, vtd_postmarketing: $post_marketing};

		$.post( "assets/process.php", $data, function( data ) {
				console.log(data);
				data = JSON.parse(data);
				$("#vtd_form_status").html("");
				if(data.code == "200") {
$("#vtd_form_status").html('<script language="JavaScript">window.open("thankyou.php","Window Name", width="430px", height="360px")</script>');						$("#vtd_quote_form").find("input").val("");
						$("input[name='vtd_current_insured']:checked").prop('checked', false);
						dataLayer.push({'event': 'conversion'});

				} else if(data.code == "300") {
					$.each(data.errors, function(key, value) {
						eval('$obj = $("#' + key + '");');
						$obj.parent().append('<span class="error">' + value + '</span>');
					});
				} else {
                                                $("#vtd_form_status").html(data.message);

				}

		});
	});
	$( ".vtd_phonelink" ).hover(
  		function() {
    			$( this ).addClass("link-hover");
  		}, function() {
    			$( this ).removeClass("link-hover");
  		}
	);

   $( ".vtd_qqlink" ).hover(
                function() {
                        $( this ).addClass("link-hover");
                }, function() {
                        $( this ).removeClass("link-hover");
                }
        );

 $( ".vtd_footer_qqlink" ).hover(
                function() {
                        $( this ).addClass("link-hover");
                }, function() {
                        $( this ).removeClass("link-hover");
                }
        );

});
