$(document).ready(function() {


	$('#lmtcMenuItem').hover(
				function() {
			        document.body.style.cursor = "hand";
					$('#lmtcMenuItem').attr('src', "/images/home_left_lmtc_over.gif");
				},
				function() {
			        document.body.style.cursor = "auto";
					$('#lmtcMenuItem').attr('src', "/images/home_left_lmtc_off.gif");
				});

	$('#lmtcMenuItem').click(function() {
		cookVal = getLMTCCookie('LMTC');
		if (cookVal != null && cookVal != "") {
			document.location.href = "http://tools.tauck.com/Last-Minute-Travel-Club/default.aspx";
		} else {
        	$('#lmtcFloatForm').slideToggle("slow");
		}

	});


    $('#btnSubmitLMTC').click(function() {
        submit_floatyLMTC();
    });

});

function submit_floatyLMTC() {
    var firstName, lastName, emailAddress;

    firstName = $("#txtLMTCFirstName").val();
    lastName = $("#txtLMTCLastName").val();
    emailAddress = $("#txtLMTCEmail").val();

    if (firstName == "") {
        window.alert("Please enter your first name.");
    }

    else if (lastName == "") {
        window.alert("Please enter your last name.");
    }

    else if (checkemail(emailAddress) == false) {
        window.alert("Please enter a valid email address.");
    }
    else {
        $('#lmtcFloatForm').hide();
        $('#lmtcFloatWorking').fadeIn("slow");
        try {
            fielddata = "<NewsletterSignup><emailAddress>" + emailAddress + "</emailAddress>"
            fielddata = fielddata + "<firstName>" + firstName + "</firstName>"
            fielddata = fielddata + "<lastName>" + lastName + "</lastName>"
            fielddata = fielddata + "<sourceCode>" + getCookie("IDENTIFIER") + "</sourceCode>"
            fielddata = fielddata + "<sourceTypeId>13</sourceTypeId>"
            fielddata = fielddata + "<titleCode>Y</titleCode>"
            fielddata = fielddata + "</NewsletterSignup>"
            $.ajax({
                url: "/ServicesV3/Public/REST/Marketing.svc/LMTCSignup/Invoke",
                processData: true,
                data: fielddata,
                error: ctaform_fail_1,
                success: ctaform_success_1,
                type: "POST",
                contentType: "application/xml"
            });

        } catch (err) {
            ctaform_fail();
        }
    }
    return false;
}

function ctaform_fail_1(r) {
    $('#lmtcFloatWorking').hide();
    $('#lmtcFloatFinishError').fadeIn("slow");
}

function ctaform_success_1() {
    $('#lmtcFloatWorking').hide();
    //$('#lmtcFloatFinishSuccess').fadeIn("slow");
	setLMTCCookie("LMTC", "1", 60);
	document.location.href = "http://tools.tauck.com/Last-Minute-Travel-Club/default.aspx";
	
}

function setLMTCCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getLMTCCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
