﻿$(document).ready(function() {
    if ($.browser.msie) {
        if ($.browser.version < 7) {
            DD_belatedPNG.fix('.png');

            $("#pageHeaderBottom").css("position", "relative");
            $("#pageHeaderBottom").css("z-index", "-100");
            $("ul#nav").superfish({
                animation: { opacity: "show", height: "show" }
            });
        }
    }

    if ($(".lagaeLives").length > 0) {
        $(".lagaeLives a").lightBox();
    }

    loadAnimation();
    
    $(function() {
        $('#ctl00_cphBody_dlFotos a').lightBox();
    });
});

function loadAnimation() {
    if ($('#flashAnimation').length > 0) {
        var flashvars = {};
        flashvars.url = SiteUrl;
        flashvars.sort = 0;
        var params = {};
        params.wmode = 'transparent';
        var attributes = {};
        swfobject.embedSWF('' + SiteUrl + 'frame.swf?t=' + new Date().getTime(), 'flashAnimation', '517', '295', '9.0.0', false, flashvars, params, attributes);
    }

}

function fixSubmenu() {
    $("#nav li").hover(function() {
        $(this).removeClass();
        $(this).addClass("over")
    }, function() {
        $(this).removeClass();
    });
}

//function ieHover() {
//    var ieULs = document.getElementById('nav').getElementsByTagName('ul');
//    
//    
//    for (j=0; j<ieULs.length; j++) {
//        ieULs[j].innerHTML = ('<iframe src="about:blank" scrolling="no" frameborder="0"></iframe>' + ieULs[j].innerHTML);
//	    var ieMat = ieULs[j].firstChild;
//	    ieMat.style.width=ieULs[j].offsetWidth+"px";
//	    ieMat.style.height=ieULs[j].offsetHeight+"px";	
//	    ieULs[j].style.zIndex="99";
//    }
//    
//    /** IE script to change class on mouseover **/
//	var sfEls = document.getElementById("nav").getElementsByTagName("li");
//	
//	for (var i=0; i<sfEls.length; i++) {
//		sfEls[i].onmouseover=function() {
//			this.className+="over";
//		}
//		sfEls[i].onmouseout=function() {
//			this.className=this.className.replace(new RegExp("over\\b"), "");
//		}
//	}
//}

////if (window.attachEvent) window.attachEvent('onload', ieHover);

function validationContact(type, language) {
    var url, ok_color, error_color, i, postForm;

    error_color = "#fae7e0";
    ok_color = "#FFFFFF";
    postForm = true;

    var fields = new Array();
    switch (type) {
        case 'vakman':
            var vm_naam = new Array("#ctl00_cphBody_txtVM_Naam", "textbox");
            var vm_bedrijf = new Array("#ctl00_cphBody_txtVM_Bedrijf", "textbox");
            var vm_postcode = new Array("#ctl00_cphBody_txtVM_Postcode", "textbox");
            var vm_plaats = new Array("#ctl00_cphBody_txtVM_Plaats", "textbox");
            var vm_email = new Array("#ctl00_cphBody_txtVM_Email", "textbox");

            var fields = new Array(vm_naam, vm_bedrijf, vm_postcode, vm_plaats, vm_email);
            break;
        case 'particulier':
            var p_naam = new Array("#ctl00_cphBody_txtP_Naam", "textbox");
            var p_postcode = new Array("#ctl00_cphBody_txtP_Postcode", "textbox");
            var p_plaats = new Array("#ctl00_cphBody_txtP_Plaats", "textbox");
            var p_email = new Array("#ctl00_cphBody_txtP_Email", "textbox");

            var fields = new Array(p_naam, p_postcode, p_plaats, p_email);
            break;
    }

    for (i = 0; i < fields.length; i++) {
        var temp = fields[i];

        switch (temp[1]) {
            case "textbox":
                if ($(temp[0]).val().length < 1) {
                    $(temp[0]).removeClass();
                    $(temp[0]).addClass("TextBoxError");
                    postForm = false;
                }
                else {
                    $(temp[0]).removeClass();
                    $(temp[0]).addClass("TextBox");
                }
                break;

            case "datum":
                if ($(temp[0]).val().length < 8) {
                    $(temp[0]).removeClass();
                    $(temp[0]).addClass("TextBoxError");
                    postForm = false;
                }
                else {
                    if (isDate($(temp[0]))) {
                        $(temp[0]).removeClass();
                        $(temp[0]).addClass("TextBox");
                    }
                    else {
                        $(temp[0]).removeClass();
                        $(temp[0]).addClass("TextBoxError");
                        postForm = false;
                    }
                }
                break;

            case "email":
                if (!validateEmail($(temp[0]).val())) {
                    $(temp[0]).removeClass();
                    $(temp[0]).addClass("TextBoxError");
                    postForm = false;
                }
                else {
                    $(temp[0]).removeClass();
                    $(temp[0]).addClass("TextBox");
                }
                break;

            case "username":
                if ($(temp[0]).val().length < 6) {
                    $(temp[0]).removeClass();
                    $(temp[0]).addClass("TextBoxError");
                    postForm = false;
                }
                else {
                    $(temp[0]).removeClass();
                    $(temp[0]).addClass("TextBox");
                }

                break;
        }
    }

    if (postForm) {
        $("#ctl00_cphBody_lblMessage").removeClass();
        $("#ctl00_cphBody_lblMessage").addClass("Sending");

        switch (language) {
            case 1:
                $("#ctl00_cphBody_lblMessage").html("<img src=\"images/ajax-loader.gif\" alt=\"\" /> bezig met versturen van uw aanvraag...");
                break;
            case 2:
                $("#ctl00_cphBody_lblMessage").html("<img src=\"images/ajax-loader.gif\" alt=\"\" /> en train d'envoyer...");
                break;
        }

    }

    else {  
        $("#ctl00_cphBody_lblMessage").html($("#ctl00_cphBody_errorMessageAlleVelden").val());
        $("#ctl00_cphBody_lblMessage").removeClass();
        $("#ctl00_cphBody_lblMessage").addClass("Error");
    }

    return postForm;
}

function validateEmail(strEmail) {
    var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
    var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid

    if (!reg1.test(strEmail) && reg2.test(strEmail)) { // if syntax is valid
        return true;
    }
    else {
        return false;
    }
}

// * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
// */
//// Declaring valid date character, minimum year and maximum year
var dtCh = "/";
var minYear = 1900;
var maxYear = 2007;

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31;
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30; }
        if (i == 2) { this[i] = 29; }
    }
    return this;
}

function isDate(dtStr) {
    var daysInMonth = DaysArray(12);
    var pos1 = dtStr.indexOf(dtCh);
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
    var strDay = dtStr.substring(0, pos1);
    var strMonth = dtStr.substring(pos1 + 1, pos2);
    var strYear = dtStr.substring(pos2 + 1);
    strYr = strYear;
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1);
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1);
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1);
    }
    month = parseInt(strMonth);
    day = parseInt(strDay);
    year = parseInt(strYr);
    if (pos1 == -1 || pos2 == -1) {
        //alert("The date format should be : dd/mm/yyyy");
        return false;
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        //alert("Please enter a valid month");
        return false;
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        //alert("Please enter a valid day");
        return false;
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        //alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
        return false;
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        //alert("Please enter a valid date");
        return false;
    }
    return true;
}
