/* Contact Form */
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sendemail() {
    var msg = document.forms["two"].elements["message"].value;
    var name = document.forms["two"].elements["name"].value;
    var email = document.forms["two"].elements["mail"].value;
    var subject = document.forms["two"].elements["subject"].value;
    var phone = document.forms["two"].elements["phone"].value;

    if(!checkEmail(email) || name.length < 3) {
        alert("Bitte überprüfen Sie Ihre Angaben.");
        return;
    } else {
        document.forms["two"].elements["button1"].disabled=true; 
        document.forms["two"].elements["button1"].value='Sending...';
        http.open('get', './contact.php?msg='+msg+'&name='+name+'&subject='+subject+'&email='+email+'&phone='+phone+'&action=send');
        http.onreadystatechange = handleResponse;
        http.send(null);
    }
}

function callback(data) {
    //console.log(data);
}

function sendApplication() {
    // create iframe to submit form to due to XHTMLRequest deficit
    var iframe = $('<iframe name="request_send" id="request_send"></iframe>');
    iframe.css("display", "none").appendTo("#contactarea");

    $("#two").attr("target", "request_send");
    $("#two").submit();

    iframe.unbind().load(function() {
        var myFrame = document.getElementById(iframe.attr('name'));
        var response = $(myFrame.contentWindow.document.body).text();
        //console.log(response);
        $("#contactarea").empty();
        $("#contactarea").append("<h2>" + response + "</h2>");
    });

}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
         
        }
    }
}

function checkEmail(address) {
    return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(address));
}
/* Contact Form */

/* Email Validation */
function checkEmail(address) {
    return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(address));
}
/* Email Validation */
