﻿
$(function()
 {
    $("#msg").val("");
});


function inlineFieldLabel(label, inputid) {
    var fieldLabel = label;     // string to put in your text input
    var textInput = $(inputid)  // your text input field


    /* add the field label css class to the form field and set the value */
    textInput.addClass("intra-field-label").val(fieldLabel);

    /* remove the placeholder string when field gets focus */
    textInput.focus(function() {
        if (this.value == fieldLabel) {
            $(this).removeClass("intra-field-label").val("");
        };
    });

    /* add the field label string when field looses focus */
    textInput.blur(function() {
        if (this.value == "") {
            $(this).addClass("intra-field-label").val(fieldLabel);
        };
    });

    /* if the field is set to the fieldLabel on submit, clear the field */
/*    $(inputid)form.submit(function() {
        if (textInput.val() == fieldLabel) {
            textInput.removeClass("intra-field-label").val("");
        };
    });*/
}

$(function() {
    $('input[type=submit]', '#contactForm').click(function() {

        $(".error").hide();
        var hasError = false;
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

        var mail = $('#txtMail').val();
        var msg = $('#txtBody').val();

        if (msg == '') {
            $("label input#txtMail").after('<span class="error">Du måste skriva ett meddelande</span>');
            hasError = true;
        }

        if (mail == '') {
            $("label input#txtMail").after('<span class="error">Du måste ange en epost</span>');
            hasError = true;
        }
        else if (!emailReg.test(mail)) {
        $("label input#txtMail").after('<span class="error">Du måste ange en giltig epost</span>');
            hasError = true;
        }

        if (hasError == true) {
            return false;
        }
        /*
        $.ajax({
        contentType: "text/html; charset=utf-8",
        data: "mail=" + mail + "&" + "msg=" + msg,
        url: "/Contact.aspx",
        dataType: "html",
        success: function(data) {
        $("#MailDetails").html(data);
        }
        });
        }
        */
        return true;

    });
});

$(document).ready(function() {
    inlineFieldLabel("Fyll i din e-postadress om du vill få svar", "#mail");
});

