// Tooltip
var DH = 0;var an = 0;var al = 0;var ai = 0;if (document.getElementById) {ai = 1; DH = 1;}else {if (document.all) {al = 1; DH = 1;} else { browserVersion = parseInt(navigator.appVersion); if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {an = 1; DH = 1;}}} function fd(oi, wS) {if (ai) return wS ? document.getElementById(oi).style:document.getElementById(oi); if (al) return wS ? document.all[oi].style: document.all[oi]; if (an) return document.layers[oi];}
function pw() {return window.innerWidth != null? window.innerWidth: document.body.clientWidth != null? document.body.clientWidth:null;}
function mouseX(evt) {if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return null;}
function mouseY(evt) {if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return null;}
function popUp(evt,oi) {if (DH) {var wp = pw(); ds = fd(oi,1); dm = fd(oi,0); st = ds.visibility; if (dm.offsetWidth) ew = dm.offsetWidth; else if (dm.clip.width) ew = dm.clip.width; if (st == "visible" || st == "show") { ds.visibility = "hidden"; } else {tv = mouseY(evt) + 20; lv = mouseX(evt) - (ew/4); if (lv < 2) lv = 2; else if (lv + ew > wp) lv -= ew/2; if (!an) {lv += 'px';tv += 'px';} ds.left = lv; ds.top = tv; ds.visibility = "visible";}}}
// Einde

// Toon een verborgen div
function showDiv(id) {
	document.getElementById(id).style.display = "block";
	}

// Verberg een div
function hideDiv(id) {
	document.getElementById(id).style.display = "none";
	}

// Foto's op detailpagina
function detailfoto (fotoFlip) {
	for (i = 1; i <= 10; i++) {
		if (document.getElementById('fotoklein_' + i)) {
			if (i == fotoFlip) {
				document.getElementById('fotoklein_' + i).className = 'select';
				document.getElementById('fotogroot_' + i).className = 'show-big';
			}

			else {
				document.getElementById('fotoklein_' + i).className = '';
				document.getElementById('fotogroot_' + i).className = 'hide-big';
			}
		}
	}
}

function togglePopUpDiv(id) {
    if(id == 1){
        showDiv('popup_id_' + 1);
        var inputs = $('popup_id_1').getElementsByTagName('input');
        var subcheck = false;
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].checked) {
                subcheck = true;
                break;
            }
        }
        if (!subcheck) {
            $('popup_id_1').getElementsByTagName('input')[0].checked = true;
        }
        document.getElementById('choose-product-1').style.borderColor = '#000132';
        hideDiv('popup_id_' + 2);
        document.getElementById('choose-product-2').style.borderColor = '#D7D6DA';
    }else{
        showDiv('popup_id_' + 2);
        var inputs = $('popup_id_2').getElementsByTagName('input');
        var subcheck = false;
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].checked) {
                subcheck = true;
                break;
            }
        }
        if (!subcheck) {
            $('popup_id_2').getElementsByTagName('input')[0].checked = true;
        }
        document.getElementById('choose-product-2').style.borderColor = '#000132';
        hideDiv('popup_id_' + 1);
        document.getElementById('choose-product-1').style.borderColor = '#D7D6DA';
    }
}

function togglePopUpAccessoryDiv(id) {
    if(id == 1){
        showDiv('popup_accessories_id_' + 1);
        hideDiv('popup_accessories_id_' + 2);
    }else{
        showDiv('popup_accessories_id_' + 2);
        hideDiv('popup_accessories_id_' + 1);
    }
}

function swapLogo(popup_logo) {
    document.getElementById('logo_big').firstChild.src         = 'cms/upload/popup_logos/small/' + popup_logo;
    document.getElementById('logo_small').firstChild.src       = 'cms/upload/popup_logos/counter/' + popup_logo;
    document.getElementById('popup_logo').value                = popup_logo;
}

function uploadFile() {
    document.getElementById('fileatt-frm').appendChild(document.getElementById('fileatt'));
    document.getElementById('fileatt-frm').submit();
    document.getElementById('fileatt').value = '';
    document.getElementById('file-container').appendChild(document.getElementById('fileatt'));
}

function getReturnValue() {
    if(window.frames['fileatt-iframe'].document.getElementById('returnvalue') != null) {
        var popup_logo = window.frames['fileatt-iframe'].document.getElementById('returnvalue').innerHTML;
        swapLogo(popup_logo);

        var new_option = document.createElement('option');
        new_option.setAttribute('value', popup_logo);
        new_option.innerHTML = popup_logo;
        document.getElementById('select-logo').appendChild(new_option);
        document.getElementById('select-logo').selectedIndex = document.getElementById('select-logo').options.length - 1;
    }
}

function toggleSteps(show, a_hide) {
    var a_hide = a_hide.split(',');
    for(i = 0; i < a_hide.length; i++) {
        hideDiv(a_hide[i]);
    }
    showDiv(show);
    return false;
}

function updatePrice(obj, price) {
    var current_price = document.getElementById('hdn_total_price').value;
    if(obj.checked) {
        new_price = String(parseFloat(current_price) + parseFloat(price));
    } else {
        new_price = String(parseFloat(current_price) - parseFloat(price));
    }
    document.getElementById('hdn_total_price').value = new_price;
    document.getElementById('total_price').innerHTML = formatCurrency(new_price);
}

function formatCurrency(num) {
    // formats a string to ex. 1.233,99

    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num)) {
        num = "0";
    }
    sign  = (num == (num = Math.abs(num)));
    num   = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num   = Math.floor(num / 100).toString();
    if(cents < 10) {
        cents = '0' + cents;
    }
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
        num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3));
    }

    return (((sign)?'':'-') + num + ',' + cents);
}

function setBannerBaseBackgroundColor(str_color) {
    document.getElementById('left').style.backgroundColor    = str_color;
    document.getElementById('right').style.backgroundColor   = str_color;
    document.getElementById('counter').style.backgroundColor = str_color;
    document.getElementById('color1').value                  = str_color;
}

function setBannerMiddleBackgroundColor(str_color) {
    document.getElementById('middle').style.backgroundColor = str_color;
    document.getElementById('color2').value                 = str_color;
}

function setFontColor(str_font_color) {
    document.getElementById('slogan_display').style.color = str_font_color;
    document.getElementById('usp1_display').style.color   = str_font_color;
    document.getElementById('usp2_display').style.color   = str_font_color;
    document.getElementById('usp3_display').style.color   = str_font_color;
}

function setFontFamily(str_font, obj) {
    document.getElementById(obj).style.fontFamily = str_font;
}

function toggleFontStyle(bln_checked, obj) {
    document.getElementById(obj).style.fontStyle = (bln_checked == 1 ? 'italic' : 'normal');
}

function toggleFontWeight(bln_checked, obj) {
    document.getElementById(obj).style.fontWeight = (bln_checked == 1 ? 'bold' : 'normal');
}

function setDefaults(str_color1, str_color2, str_font_color, a_font_family, a_style_checked, a_weight_checked) {
    document.getElementById('left-step3').style.backgroundColor    = str_color1;
    document.getElementById('right-step3').style.backgroundColor   = str_color1;
    document.getElementById('counter-step3').style.backgroundColor = str_color1;
    document.getElementById('middle-step3').style.backgroundColor  = str_color2;

    document.getElementById('slogan_display_step3').style.color    = str_font_color;
    document.getElementById('usp1_display_step3').style.color      = str_font_color;
    document.getElementById('usp2_display_step3').style.color      = str_font_color;
    document.getElementById('usp3_display_step3').style.color      = str_font_color;

    a_font_family = a_font_family.split(',');
    setFontFamily(a_font_family[0], 'slogan_display_step3');
    setFontFamily(a_font_family[1], 'usp1_display_step3');
    setFontFamily(a_font_family[2], 'usp2_display_step3');
    setFontFamily(a_font_family[3], 'usp3_display_step3');

    a_style_checked = a_style_checked.split(',');
    toggleFontStyle(a_style_checked[0], 'slogan_display_step3');
    toggleFontStyle(a_style_checked[1], 'usp1_display_step3');
    toggleFontStyle(a_style_checked[2], 'usp2_display_step3');
    toggleFontStyle(a_style_checked[3], 'usp3_display_step3');

    a_weight_checked = a_weight_checked.split(',');
    toggleFontWeight(a_weight_checked[0], 'slogan_display_step3');
    toggleFontWeight(a_weight_checked[1], 'usp1_display_step3');
    toggleFontWeight(a_weight_checked[2], 'usp2_display_step3');
    toggleFontWeight(a_weight_checked[3], 'usp3_display_step3');
}
