// addLoadEvent function
function addLoadEvent(fn) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = fn;
    } else {
        window.onload = function() {
            oldonload();
            fn();
        }
    }
}
addLoadEvent(init);

// Init function
function init() {
    // Code to run after window.onLoad
    placeFooter(); // Place footer
    
    resetStyleRadioCheckbox(); // Reset background and with from radio and checkbox elements
    
    formAddSubmit('headerTab_form_send', 'headerTab_form'); // Search
    formAddSubmit('home_pollVote', 'home_poll_form'); // Poll
    formAddSubmit('contact_contactform_formSend', 'contact_contactform_form'); // Contactform
    formAddSubmit('vipArea_login_formSend', 'vipArea_login_form'); // VIP Area log in
    formAddSubmit('vipArea_register_formSend', 'vipArea_register_form'); // VIP Area register
    formAddSubmit('vipArea_newsletter_formSend', 'vipArea_newsletter_form'); // VIP Area newsletter
    formAddSubmit('vipArea_cardNumber_formSend', 'vipArea_cardNumber_form'); // VIP Area newsletter
    
    makePrintLink('vipArea_vipOffer_print'); // Adds print functionality to link
    
    uploadPhotoSwitch(); // Upload photo switch
    routePlanner(); // Route Planner
    
    if (typeof initLightbox == 'function') {
        initLightbox(); // litebox
    }
}

// placeFooter function
function placeFooter() {
    var oSiteContainer = document.getElementById('siteContainer');
    var oFooter = document.getElementById('footer');
    
    var iBottomSiteContainer = oSiteContainer.offsetHeight + oSiteContainer.offsetTop;
    
    oFooter.style.top = (iBottomSiteContainer - 138) + "px";
}

// formAddSubmit function
function formAddSubmit(oLinkID, oFormID) {
    var oLink = document.getElementById(oLinkID);
    
    if (!oLink) { return false; }
    
    oLink.onclick = function() {
        var oForm = document.getElementById(oFormID);
        
        oForm.submit();
        
        return false;
    }
}

// resetStyleRadioCheckbox function
function resetStyleRadioCheckbox() {
    var aInputs = document.getElementsByTagName('input');

    var i = aInputs.length;
    while(i--) {
        if(aInputs[i].getAttribute('type') == 'radio' || aInputs[i].getAttribute('type') == 'checkbox') {
            aInputs[i].style.background = 'transparent none';
            aInputs[i].style.width = "20px";
        }
    }
}

// routePlanner function
function routePlanner() {
    var oLink = document.getElementById('contact_routePlanner_formSend');
    
    if (!oLink) { return false; }
    
    oLink.onclick = function() {
        var sFrom = document.getElementById('contact_routePlanner_form').zipcode.value;

        window.open('http://maps.google.nl/maps?saddr=' + sFrom + '&daddr=Winkelhof+26,+leiderdorp','RoutePlanner','resizable,scrollbars');
        
        return false;
    }
}

// uploadPhoto function
function uploadPhotoSwitch() {
    var oLink = document.getElementById('vipArea_welcome_formSwitch');
    
    if (!oLink) { return false; }
    
    oLink.onclick = function() {
        var oTextContainer = document.getElementById('vipArea_welcome_textContainer');
        var oFormContainer = document.getElementById('vipArea_welcome_formContainer');
        var oPhoto = document.getElementById('vipArea_welcome_userPhoto');

        if (oTextContainer.style.display == 'block' || oTextContainer.style.display == '') {
            oTextContainer.style.display = 'none';
            oFormContainer.style.display = 'block';
            oPhoto.style.display = 'none';
        } else {
            oTextContainer.style.display = 'block';
            oFormContainer.style.display = 'none';
            oPhoto.style.display = 'block';
        }
        
        return false;
    }
}

// makePrintLink function
function makePrintLink(oLinkID) {
    var oLink = document.getElementById(oLinkID);
    
    if (!oLink) { return false; }
    
    oLink.onclick = function () {
        print();
        
        return false;
    }
}

// openSoundplayer function
function openSoundplayer()
{
	window.open('soundplayer.htm', 'Soundplayer', 'width=239,height=39,srollbars=no,toolbar=no,location=no');
	
	return false;
}
