var xmlhttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
 // JScript gives us Conditional compilation, we can cope with old IE versions.
 // and security blocked creation of the objects.
 try {
 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
 try {
 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 } catch (E) {
 xmlhttp = false;
 }
 }
 @end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
        xmlhttp = new XMLHttpRequest();
    } catch (e) {
        xmlhttp = false;
    }
}
if (!xmlhttp && window.createRequest) {
    try {
        xmlhttp = window.createRequest();
    } catch (e) {
        xmlhttp = false;
    }
}


$(function() {


    $(".popup").click(function() {

        url = $(this).attr("href");

        window.open(url, 'popup', 'width=430,height=360,scrollbars=no,toolbar=no,location=no');
        return false

    });


    $(".submit_nieuwsbrief").click(function() {
        val = $(".adres_nieuwsbrief").val();
        if (!validate_email(val)) {
            alert('Het ingevoerde e-mail adres is niet correct');
            return false;
        }

        $.post("nieuwsbrief_api/ajax.php", {a:'submit_nieuwsbrief',e:val});
        alert('Bedankt voor uw aanmelding');
        $(".adres_nieuwsbrief").val('');

    });

    $(".adres_nieuwsbrief").focus(function() {
        if ($(this).val() == 'uw e-mail adres...') {
            $(this).val('');
        }
    });


});

function validate_email(email) {
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(email)) {
        return true;
    } else {
        return false;
    }
}


function verzend_belme() {
    if (document.getElementById('belme_naam').value == '') {
        alert('Vul een naam in');
        return;
    }
    if (document.getElementById('belme_nummer').value == '') {
        alert('Vul een telefoonnummer in');
        return;
    }

    //var postdata = new Array('belme_naam','belme_nummer','belme_wanneer','belme_van','belme_tot','url','paginanaam');
    //postit(postdata,'belme_form_verzenden');
    $.post("post.php",
        {
            post_id:'belme_form_verzenden',
            belme_naam:$('#belme_naam').val(),
            belme_nummer:$('#belme_nummer').val(),
            belme_van:$('#belme_van').val(),
            belme_tot:$('#belme_tot').val(),
            url:$('#url').val(),
            paginanaam:$('#paginanaam').val()
        },
        function(data) {
            document.getElementById('belme_form').style.display = 'none';
            document.getElementById('belme_verzonden').style.display = '';
            setTimeout("restore_belme()", 4000);
        });


}

function restore_belme() {
    document.getElementById('belme_form').reset();
    document.getElementById('belme_form').style.display = '';
    document.getElementById('belme_verzonden').style.display = 'none';
}


function verzend_contact() {
    if (document.getElementById('contact_naam').value == '') {
        alert('Vul een naam in');
        return;
    }
    if (document.getElementById('contact_email').value == '') {
        alert('Vul een e-mail adres in');
        return;
    }
    if (document.getElementById('contact_bericht').value == '') {
        alert('Vul een bericht in');
        return;
    }

//	var postdata = new Array('','','','','','','contact_plaats','contact_bericht');
//	postit(postdata,'contact_form_verzenden');
    $.post("post.php",
        {
            post_id:'contact_form_verzenden',
            contact_naam:$('#contact_naam').val(),
            contact_email:$('#contact_email').val(),
            contact_adres:$('#contact_adres').val(),
            contact_bedrijf:$('#contact_bedrijf').val(),
            contact_telefoon:$('#contact_telefoon').val(),
            contact_postcode:$('#contact_postcode').val(),
            contact_plaats:$('#contact_plaats').val(),
            contact_bericht:$('#contact_bericht').val()
        }, function(data) {
            document.getElementById('contact_form').style.display = 'none';
            document.getElementById('contact_verzonden').style.display = '';
            setTimeout("restore_contact()", 4000);
        });


}

function restore_contact() {
    document.getElementById('contact_form').reset();
    document.getElementById('contact_form').style.display = '';
    document.getElementById('contact_verzonden').style.display = 'none';
}


function postit(postarray, post_id) {
    var poststr = "";
    var parameters = ""
    var url = 'post.php';

    for (i = 0; i < postarray.length; i++) {
        parameters += postarray[i] + "=" + encodeURI(document.getElementById(postarray[i]).value) + "&";
    }
    parameters += 'post_id=' + post_id;
    //alert(parameters); return;

    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
            }
        }
    }
    if (!http_request) {
        alert('Cannot create XMLHTTP instance');
        return false;
    }

    http_request.onreadystatechange = alertContents;
    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.send(parameters);

    function alertContents() {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                if (http_request.responseText.length > 2) {
                    alert(http_request.responseText);
                }
            }
            else {
                alert('There was a problem with the request.');
            }
            return true;
        }
    }
}


onload = function() {
    a_tags = document.getElementsByTagName('a')
    for (i = 0; i < a_tags.length; i++) {
        a_tags[i].onfocus = blur_links
    }

    if (document.getElementById('directchatvenster')) {
        document.getElementById('directchatvenster').style.display = '';
    }
}

function blur_links() {
    this.blur()
}


var win = null;
function NewWindow(mypage, w, h, myname) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    var settings = 'height=' + h + ',';
    settings += 'width=' + w + ',';
    settings += 'top=' + wint + ',';
    settings += 'left=' + winl + ',';
    settings += 'scrollbars=yes,';
    settings += 'resizable=yes';
    win = window.open(mypage, myname, settings);
    if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus();
    }
}
function MM_openBrWindow(theURL, winName, features) {
    window.open(theURL, winName, features);
}

function switch_img(file, id, type) {
    if (type == 1) {
        var extensie = file;
        document.getElementById('productafb').style.backgroundImage = 'url(/afb/producten/' + id + '.' + extensie + ')';
        afb_groot = baseimg;
        imgwidth = basewidth;
        imgheight = baseheight;
    }

    if (type == 2) {
        document.getElementById('productafb').style.backgroundImage = 'url(/afb/producten/' + id + '/170/' + file + ')';
        afb_groot = 'afb/producten/' + id + '/groot/' + file;
        imgwidth = w[file];
        imgheight = h[file];
    }
}


function switch_img_materiaal(file, id, type) {
    var extensie = file;

    if (type == 1) {
        document.getElementById('productafb').style.backgroundImage = 'url(/afb/materialen/' + id + '.' + extensie + ')';
        afb_groot = 'afb/materialen/' + id + '_groot.' + extensie;
        imgwidth = w['afb/materialen/' + id + '_groot.' + extensie];
        imgheight = h['/afb/materialen/' + id + '_groot.' + extensie];
    }

    if (type == 2) {
        document.getElementById('productafb').style.backgroundImage = 'url(/afb/producten/' + id + '.' + extensie + ')';
        afb_groot = 'afb/producten/' + id + '_groot.' + extensie;
        imgwidth = w['afb/producten/' + id + '_groot.' + extensie];
        imgheight = h['/afb/producten/' + id + '_groot.' + extensie];
    }
}

