$(document).ready(function() {
    $('.slideshowBlock').cycle({
        fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });
                
    $("a[rel=group]").fancybox({
        'transitionIn'  : 'none',
        'transitionOut' : 'none',
        'titlePosition' : 'over',
        'titleFormat'   : function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });
    
    $("a[rel=flame]").fancybox({
        'transitionIn'  : 'none',
        'transitionOut' : 'none',
        'titlePosition' : 'over',
        'titleFormat'   : function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });
    
    $("a[rel=aamn]").fancybox({
        'transitionIn'  : 'none',
        'transitionOut' : 'none',
        'titlePosition' : 'over',
        'titleFormat'   : function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });
    
    $("a[rel=events]").fancybox({
        'transitionIn'  : 'none',
        'transitionOut' : 'none',
        'titlePosition' : 'over',
        'titleFormat'   : function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });
});

function getSelectionKO(text1, text2, text3, text4, text5, text6) {
    document.getElementById("cell1").innerHTML = "<input type='radio' name='auswahl2' id='auswahl2' class='radio' value=1 onclick='getSelKONeu(\"" + text3 + "\", \"" + text4 + "\")' />" + text1;
    document.getElementById("cell3").innerHTML = "<input type='radio' name='auswahl2' id='auswahl2' class='radio' value=2 onclick='getSelKOUmbau(\"" + text5 + "\", \"" + text6 + "\")' />" + text2;
    document.getElementById("cell5").innerHTML = "";
    document.getElementById("cell2").innerHTML = "";
    document.getElementById("cell4").innerHTML = "";
    document.getElementById("cell6").innerHTML = "";
}
function getSelectionFliesen(text1, text2, text3, text4, text5) {
    document.getElementById("cell1").innerHTML = "<input type='radio' name='auswahl2' id='auswahl2' class='radio' value=3 onclick='getSelFliesenAllg(\"" + text3 + "\", \"" + text4 + "\", \"" + text5 + "\")' />" + text1;
    document.getElementById("cell3").innerHTML = "<input type='radio' name='auswahl2' id='auswahl2' class='radio' value=4 onclick='getSelFliesenAllg(\"" + text3 + "\", \"" + text4 + "\", \"" + text5 + "\")' />" + text2;
    document.getElementById("cell5").innerHTML = "";
    document.getElementById("cell2").innerHTML = "";
    document.getElementById("cell4").innerHTML = "";
    document.getElementById("cell6").innerHTML = "";
}
function getSelectionService(text1, text2, text3, text4, text5) {
    document.getElementById("cell1").innerHTML = "<input type='radio' name='auswahl2' id='auswahl2' class='radio' value='5' onclick='getSelServiceAllg(\"" + text4 + "\", \"" + text5 + "\")' />" + text1;
    document.getElementById("cell3").innerHTML = "<input type='radio' name='auswahl2' id='auswahl2' class='radio' value='6' onclick='getSelServiceAllg(\"" + text4 + "\", \"" + text5 + "\")' />" + text2;
    document.getElementById("cell5").innerHTML = "<input type='radio' name='auswahl2' id='auswahl2' class='radio' value='7' onclick='getSelServiceAllg(\"" + text4 + "\", \"" + text5 + "\")' />" + text3;
    document.getElementById("cell2").innerHTML = "";
    document.getElementById("cell4").innerHTML = "";
    document.getElementById("cell6").innerHTML = "";
}

function getSelKONeu(text1, text2) {
    document.getElementById("cell2").innerHTML = "<input type='radio' name='auswahl3' id='auswahl3' class='radio' value=1 />" + text1;
    document.getElementById("cell4").innerHTML = "<input type='radio' name='auswahl3' id='auswahl3' class='radio' value=2 />" + text2;
    document.getElementById("cell5").innerHTML = "";
}
function getSelKOUmbau(text1, text2) {
    document.getElementById("cell2").innerHTML = "<input type='radio' name='auswahl3' id='auswahl3' class='radio' value=3 />" + text1;
    document.getElementById("cell4").innerHTML = "<input type='radio' name='auswahl3' id='auswahl3' class='radio' value=4 />" + text2;
    document.getElementById("cell6").innerHTML = "";
}

function getSelFliesenAllg(text1, text2, text3) {
    document.getElementById("cell2").innerHTML = "<input type='checkbox' name='auswahl3' id='auswahl3' class='radio' value=1 />" + text1;
    document.getElementById("cell4").innerHTML = "<input type='checkbox' name='auswahl4' id='auswahl4' class='radio' value=1 />" + text2;
    document.getElementById("cell6").innerHTML = "<input type='text' name='auswahl5' id='auswahl5' style='width: 100px; height: 14px; margin: 0 10px;' value='' />" + text3;
}

function getSelServiceAllg(text1, text2) {
    var value = 0;
    for (var i = 0; i < document.form1.auswahl2.length; ++i) {
        if (document.form1.auswahl2[i].checked) {
            value = document.form1.auswahl2[i].value;
        }
    }

    if (value == "6") {
        document.getElementById("cell2").innerHTML = "<input type='text' name='auswahl3' id='auswahl3' style='width: 50px; height: 14px; margin: 0 10px;' value='' />" + text1;
        document.getElementById("cell4").innerHTML = "<input type='checkbox' name='auswahl4' id='auswahl4' class='radio' value=1 />" + text2;
        document.getElementById("cell6").innerHTML = "";
    } else {
        document.getElementById("cell2").innerHTML = "";
        document.getElementById("cell4").innerHTML = "";
        document.getElementById("cell6").innerHTML = "";
    }
}

function checkValues(errorselected, errorname, erroremail, errortel, erroranfrage) {
    if (document.getElementById("name").value == "") {
        alert(errorname);
        return false;
    }
    
    if (document.getElementById("email").value == "" || !preg_match('/^(\w([-._\w]*\w)*@(\w[-_\w]*\w\.)+\w{2,9})$/', document.getElementById("email").value)) {
        alert(erroremail);
        return false;
    }
    
    if (document.getElementById("tel").value == "") {
        alert(errortel);
        return false;
    }
    
    var aus1 = 0;
    for (var i = 0; i < document.form1.auswahl.length; ++i) {
        if (document.form1.auswahl[i].checked) {
            aus1 = document.form1.auswahl[i].value;
        }
    }
        
    if (aus1 == 1) {
        var aus2 = 0;
        for (var i = 0; i < document.form1.auswahl2.length; ++i) {
            if (document.form1.auswahl2[i].checked) {
                aus2 = document.form1.auswahl2[i].value;
            }
        }
        
        if (aus2 == 0) {
            alert(errorselected);
            return false;
        } else {
            var aus3 = 0;
            for (var i = 0; i < document.form1.auswahl3.length; ++i) {
                if (document.form1.auswahl3[i].checked) {
                    aus3 = document.form1.auswahl3[i].value;
                }
            }
            
            if (aus3 == 0) {
                alert(errorselected);
                return false;
            }
        }
    } else if (aus1 == 2) {
        var aus2 = 0;
        for (var i = 0; i < document.form1.auswahl2.length; ++i) {
            if (document.form1.auswahl2[i].checked) {
                aus2 = document.form1.auswahl2[i].value;
            }
        }
        
        if (aus2 == 0) {
            alert(errorselected);
            return false;
        } else {
            var aus3 = document.getElementById("auswahl3").checked;
            var aus4 = document.getElementById("auswahl4").checked;
            var aus5 = document.getElementById("auswahl5").value;
            
            if (!aus3 && !aus4 && aus5 == "") {
                alert(errorselected);
                return false;
            }
        }
    } else if (aus1 == 3) {
        var aus2 = 0;
        for (var i = 0; i < document.form1.auswahl2.length; ++i) {
            if (document.form1.auswahl2[i].checked) {
                aus2 = document.form1.auswahl2[i].value;
            }
        }
        
        if (aus2 == 0) {
            alert(errorselected);
            return false;
        } else {
            var aus3 = document.getElementById("auswahl3").value;
            var aus4 = document.getElementById("auswahl4").checked;
            
            if (aus3 == "" && !aus4) {
                alert(errorselected);
                return false;
            }
        }
    } else {
        alert(errorselected);
        return false;
    }
    
    if (document.getElementById("message").value == "") {
        alert(erroranfrage);
        return false;
    }
    
    document.forms.form1.submit();
    return true;
}

