$(document).ready(function() {
	
    $("#show_data").click(function(){
        $('#confirm_data').toggle(1000);
    });
	
    $("#link_ft").click(function(){
        if(validate_ft(true)==true){
            $("#ft_form").submit();
        }else{
            $('#confirm_data').toggle(1000)
        }
		
    });
	
    $("#goform2").click(function(){
        if($("#f2_name").val() != "" && $("#f2_email").val() != ""){
            $("#orderform").submit();
        }
    });
	
    $("#link_continue").click(function(){
        if(validate_ft(false) == true){
            $("#cmxform").submit();
        }
    //window.location = "http://lumatrimdietpills.mybigcommerce.com/products/Risk-Free-Trial.html";
    });
	
    $("#same_yes").click(function(){
		
        $("#sh_telephone").val($("#ft_telephone").val());
        $("#sh_country").val($("#ft_country").val());
        $("#sh_street_address").val($("#ft_street_address").val());
        $("#sh_city").val($("#ft_city").val());
        $("#sh_state_province").val($("#ft_state_province").val());
        $("#sh_zip_postal_code").val($("#ft_zip_postal_code").val());
		
    });
	
    $("#same_no").click(function(){
		
        $("#sh_telephone").val("");
        $("#sh_country").val("");
        $("#sh_street_address").val("");
        $("#sh_city").val("");
        $("#sh_state_province").val("");
        $("#sh_zip_postal_code").val("");
		
    });
	
});

/*


*/
function  validate_ft(complete){

    if ($('#ft_first_name').val() == "") {
        alert("Please enter your First Name");
        return false;
    }
    if ($('#ft_last_name').val() == "") {
        alert("Please enter your Last Name");
        return false;
    }
    if ($('#ft_email').val() == ""){
        alert("Please enter your Email");
        return false;
    }
    if (echeck($('#ft_email').val())==false){
        return false;
    }
    if ($('#ft_telephone').val() == "") {
        alert("Please enter your Telephone Number");
        return false;
    }
    if ($('#ft_country').val() == "") {
        alert("Please enter your Country");
        return false;
    }
    if ($('#ft_street_address').val() == "") {
        alert("Please enter your Street Address");
        return false;
    }
    if ($('#ft_city').val() == "") {
        alert("Please enter City");
        return false;
    }
    if ($('#ft_state_province').val() == "") {
        alert("Please enter State/Province");
        return false;
    }
    if ($('#ft_zip_postal_code').val() == "") {
        alert("Please enter Zip/Postal Code");
        return false;
    }
	
    /****************************************/
	
    if ($('#sh_telephone').val() == "") {
        alert("Please enter your Telephone Number for Shipping");
        return false;
    }
    if ($('#sh_country').val() == "") {
        alert("Please enter your Country for Shipping");
        return false;
    }
    if ($('#sh_street_address').val() == "") {
        alert("Please enter your Street Address for Shipping");
        return false;
    }
    if ($('#sh_city').val() == "") {
        alert("Please enter City for Shipping");
        return false;
    }
    if ($('#sh_state_province').val() == "") {
        alert("Please enter State/Province for Shipping");
        return false;
    }
    if ($('#sh_zip_postal_code').val() == "") {
        alert("Please enter Zip/Postal Code for Shipping");
        return false;
    }
	
	
    if(complete){
        if ($('#ft_credit_car').val() == "") {
            alert("Please enter your Card Number");
            return false;
        }
        if(document.getElementById("agree").checked==false){
            alert("Please read the 'Terms and Conditions' page");
            return false;
        }
    }
	
    
	
    return true;
}

function echeck(str) {

    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
        alert("Invalid E-mail")
        return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert("Invalid E-mail")
        return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("Invalid E-mail")
        return false
    }

    if (str.indexOf(at,(lat+1))!=-1){
        alert("Invalid E-mail")
        return false
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("Invalid E-mail")
        return false
    }

    if (str.indexOf(dot,(lat+2))==-1){
        alert("Invalid E-mail")
        return false
    }
		
    if (str.indexOf(" ")!=-1){
        alert("Invalid E-mail")
        return false
    }

    return true
}
