﻿$(document).ready(function() {

    $('#defaultReal').realperson();

    $('input[type=text]').focus(function() {
        if ($(this).val() == $(this).attr('placeholder')) {
            $(this).val('');
        }
    });

    $('input[type=text]').blur(function() {
        if ($(this).val() == '') {
            $(this).val($(this).attr('placeholder'));
        }
    });

    $('#ContactOpmerking').focus(function() {
    if ($(this).val() == l_strContactOpmerking) {
            $(this).val('');
        }
    });
    $('#ContactOpmerking').blur(function() {
        if ($(this).val() == '') {
            $(this).val(l_strContactOpmerking);
        }
    });

    $('.toepassingMenuItem img').each(function() {
        $(this).hover(function() {
            $(this).stop().animate({ opacity: 1.0 }, 750);
        }, function() { $(this).stop().animate({ opacity: 0.3 }, 750); });
    });

    $('.Marker img').each(function() {
        $(this).hover(function() {
            $(this).attr('src', '/images/home/targetOver.png');
        },
        function() {
            $(this).attr('src', '/images/home/target.png');
        });
    });
    
    var indx = 0, loop, numberOfFeatures = 5; 

    function imageRotate() {
        indx++;
        if (indx > numberOfFeatures) { indx = 1; }
        $('.Marker img').animate({ rotate: '+=90deg'},1000,'linear');
        loop = setTimeout(imageRotate, 1000);
    }
     imageRotate();
    
});

function checkLogin() {
    if (document.getElementById('Gebruiker').value == '' || document.getElementById('Gebruiker').value == 'Username') {
        window.alert('Username is required.');
        document.getElementById('Gebruiker').focus();
        return false;
    }
    if (document.getElementById('WachtwoordLogin').value == '' || document.getElementById('WachtwoordLogin').value == 'Password') {
        window.alert('Password is required.');
        document.getElementById('WachtwoordLogin').focus();
        return false;
    }
    if (!document.getElementById('CheckboxLogin').checked) {
        window.alert('You must agree to the EULA terms.');
        document.getElementById('CheckboxLogin').focus();
        return false;
    }
    document.LoginForm.submit();
}

function ControleMailingNL() {

    var l_blAlert = false;

    if ($('#naam').val() == '' || $('#naam').val() == $('#naam').attr('placeholder')) {
        $('#naam').css('color', 'red');
        l_blAlert = true;
    }
    var email = $("#adres").val();
    if (!isValidEmailAddress(email)) {
        $('#adres').css('color', 'red');
        l_blAlert = true;
    }
    if ($('#naamontvanger').val() == '' || $('#naamontvanger').val() == $('#naamontvanger').attr('placeholder')) {
        $('#naamontvanger').css('color', 'red');
        l_blAlert = true;
    }
    var email = $("#adresontvanger").val();
    if (!isValidEmailAddress(email)) {
        $('#adresontvanger').css('color', 'red');
        l_blAlert = true;
    }
    if (l_blAlert)
        $('#alertContact').html(l_strErrormailing);

    return (!l_blAlert);
}

function ControleFormulier() {
    var l_blAlert = false;
    if ($('#ContactNaam').val() == '' || $('#ContactNaam').val() == $('#ContactNaam').attr('placeholder')) {
        $('#ContactNaam').css('color', 'red');
        l_blAlert = true;
    }
    if ($('#ContactOpmerking').val() == $('#ContactOpmerking').attr('placeholder')) {
        $('#ContactOpmerking').css('color', 'red');
        l_blAlert = true;
    }
    var email = $("#ContactEmail").val();
    if (!isValidEmailAddress(email)) {
        $('#ContactEmail').css('color', 'red');
        l_blAlert = true;
    }
    if (l_blAlert)
        $('#alertContact').html(l_strErrormailing);

    return (!l_blAlert);
}

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

function make_links() {
    var liens = document.getElementsByTagName('a');
    for (var i = 0; i < liens.length; ++i) {
        if (liens[i].className == 'ext') {
            liens[i].onclick = function() {
                window.open(this.href);
                return false;
            };
        }
    }
}

$(document).ready(function() {
    make_links();
});



function EULAakkoord() {
    var l_blAlert = false;
    var l_blAlertDriver = false;
    $('#AlertDriver').html('');
    $('#Alert').html('');

    if (!document.getElementById('EULA').checked) {
        $('#Alert').html(l_strEulaAkkoord);
        l_blAlert = true;
    }
    if ($('input.downloadDriver:checked').length == 0) {
        $('#AlertDriver').html(l_strDriverSelecteren);
        l_blAlertDriver = true;
    }

    return (!l_blAlert && !l_blAlertDriver);
}

function ClearIf(p_objElement, p_strText) {
    if (p_objElement.value == p_strText)
        p_objElement.value = '';
}

function closeToepassing() {

    $('#OverlayContainerHome').hide('fast', function() {
        $('#OverlayContainerHome').css('display', 'none');
    });
}

function loginDevelopCenter() {
    $('#overlayGrey').css('display', 'block');
    $('#LoginDevelop').css('left', ((screen.width / 2) - 180) + 'px');
    $('#LoginDevelop').show('fast');
}

function close() {
    $('#overlayContainer').hide('fast', function() {
        $('#overlayGrey').css('display', 'none');
    });
    $('#overlayContainerLarge').hide('fast', function() {
        $('#overlayGrey').css('display', 'none');
    });
    $('#LoginDevelop').hide('fast', function() {
        $('#overlayGrey').css('display', 'none');
    });
}

function openDriver(p_strItem, p_strOS) {
    $.get("/templates/overlay/driver.aspx", { product: p_strItem, os: p_strOS },
       function(data) {

           $('#overlayGrey').css('display', 'block');
           $('#overlayContainer').css('left', ((screen.width / 2) - 180) + 'px');
           $('#overlayContainer').html(data);
           $('#overlayContainer').show('fast');
       });
}

function openDemo(p_strItem) {
    $.get("/templates/overlay/demo.aspx", { product: p_strItem },
       function(data) {
           $('#overlayGrey').css('display', 'block');
           $('#overlayContainer').css('left', ((screen.width / 2) - 180) + 'px');
           $('#overlayContainer').html(data);
           $('#overlayContainer').show('fast');
       });
}

function openFoto(p_strItem) {
    $.get("/templates/overlay/foto.aspx", { product: p_strItem },
       function(data) {

           $('#overlayGrey').css('display', 'block');
           $('#overlayContainer').css('left', ((screen.width / 2) - 180) + 'px');
           $('#overlayContainer').html(data);
           $('#overlayContainer').show('fast');
       });
}

function openToepassing(p_strItem, p_strY, p_strX, p_strPositie) {

    $.get("/templates/overlay/toepassingOverlay.aspx", { toepassing: p_strItem },
   function(data) {
       if (p_strPositie == '1') {
           $('#OverlayContainerHome').css('left', p_strX + 'px');
           $('#OverlayContainerHome').css('top', p_strY-135 + 'px');
       } else if (p_strPositie == '2') {
           $('#OverlayContainerHome').css('left', p_strX + 'px');
           $('#OverlayContainerHome').css('top', p_strY + 'px');
       } else if (p_strPositie == '3') {
           $('#OverlayContainerHome').css('left', p_strX-135 + 'px');
           $('#OverlayContainerHome').css('top', p_strY + 'px');
       } else if (p_strPositie == '4') {
           $('#OverlayContainerHome').css('left', p_strX-135 + 'px');
           $('#OverlayContainerHome').css('top', p_strY-135 + 'px');
       }
       $('#OverlayContainerHome').html(data);
       $('#OverlayContainerHome').show('fast');
       $('#ImgMarker' + p_strY + '' + p_strX).attr('src', '/images/home/targetOver.png');
   });

}

function openOverlay(p_strItem) {
    $.get("/templates/overlay/tekstOverlay.aspx", { feature: p_strItem },
   function(data) {
       $('#overlayGrey').css('display', 'block');
       $('#overlayContainer').css('left', ((screen.width / 2) - 180) + 'px');
       $('#overlayContainer').html(data);
       $('#overlayContainer').show('fast');
   });
}

function openOverlayLarge(p_strItem) {
    $.get("/templates/overlay/tekstOverlayLarge.aspx", { feature: p_strItem },
   function(data) {
       $('#overlayGrey').css('display', 'block');
       $('#overlayContainerLarge').css('left', ((screen.width / 2) - 335) + 'px');
       $('#overlayContainerLarge').html(data);
       $('#overlayContainerLarge').show('fast');
   });
}


function doorsturen() {
}


var l_blBusy = false;
var l_strBestemming = '';
function movebubble(p_strID) {


    l_strBestemming = Math.round((document.getElementById(p_strID).offsetParent.offsetLeft + (document.getElementById(p_strID).clientWidth / 2)) - 30);
    if (!l_blBusy) {
        l_blBusy = true;
        if (document.getElementById('bubble').offsetLeft != l_strBestemming) {
            window.setTimeout("move()", 1);

        }
        l_blBusy = false;
    }
}


$(document).ready(function() {
    var l_objDivs = document.getElementsByTagName('a');
    for (i = 0; i < l_objDivs.length; i++) {
        if (l_objDivs[i].className == 'menuItemActive') {
            document.getElementById('bubble').style.left = (Math.round((l_objDivs[i].offsetParent.offsetLeft + (l_objDivs[i].clientWidth / 2)) - 30) + 'px');
        }
    }
});

function move() {
    if ((document.getElementById('bubble').offsetLeft > l_strBestemming || document.getElementById('bubble').style.left > l_strBestemming)) {
        document.getElementById('bubble').style.left = document.getElementById('bubble').offsetLeft - 1 + 'px';
        window.setTimeout("move()", 4);
    }
    else if ((document.getElementById('bubble').offsetLeft < l_strBestemming || document.getElementById('bubble').style.left < l_strBestemming)) {
        document.getElementById('bubble').style.left = document.getElementById('bubble').offsetLeft + 1 + 'px';
        window.setTimeout("move()", 4);
    }
}

$(function() {
    $('#ResizeContact').click(function() {
        if ($('#Contact').css('height') == '60px') {
            $('#Contact').animate({
                width: '400px',
                height: '100px'
            }, 500);
            $('#Contact .Center').animate({
                width: '384px',
                height: '82px'
            }, 500);
            $('#Contact .Top, #Contact .Bottom').animate({
                width: '384px'
            }, 500);
            $('#Contact .Left, #Contact .Right').animate({
                height: '82px'
            }, 500);
            $('#Contact textarea').animate({
                width: '380px',
                height: '80px'
            }, 500);
        }
        else {
            $('#Contact textarea').animate({
                width: '225px',
                height: '40px'
            }, 500);
            $('#Contact .Left, #Contact .Right').animate({
                height: '46px'
            }, 500);
            $('#Contact .Top, #Contact .Bottom').animate({
                width: '239px'
            }, 500);
            $('#Contact .Center').animate({
                width: '239px',
                height: '46px'
            }, 500);
            $('#Contact').animate({
                width: '255px',
                height: '60px'
            }, 500);
        }
        return false;
    });
});

