﻿/// <reference path="jquery-1.3.2.min.js" />

$(document).ready(function () {
    if (isIE6()) {
        $.ifixpng(pngFixPixel);
        $('#modelHead').ifixpng();
        //        $('.pngfix, img, #modelHead, #resultContainer').ifixpng();

        /*
        $(".modelNavContainer div").each(function(i) {
        var margin = parseInt( $(this).css("margin-left") ) +15 ;
        $(this).css("margin-left", margin + "px");
        });
        */

    }

    reinitialiseScrollPane = function () {
        if ($('.scrollPane').height() > 405)
            $('.scrollPane').height('405px').jScrollPane({ showArrows: true, scrollbarWidth: 9 });
    }
    reinitialiseScrollPane();


    $('#popupCloser').click(function () {
        if ($.Growl) {
            $.Growl.close();
        };
        $('#popup').fadeOut('fast');
    });

    var conflContainer = $('#conflictMessage');
    if (null != conflContainer && conflContainer.length > 0) {
        $('#conflictMessageCancel').click(function () {
            $('#conflictMessage').fadeOut('fast');
            return false;
        }
            );
    }
    $("#printBtn").click(function () {

        $('#printDialog').fadeIn('fast');

        var myLink = this.href;

        $("#buildPDF").click(function () {
            var additionalData = $('#printDialog input').serialize();
            var myNewLink = myLink + "?" + additionalData;
            logClick('/ResultCallToAction/html_CC CTA - Save as PDF');
            $('#printDialog').fadeOut('fast');
            window.open(myNewLink, 'Print_Mazda_Konfiguration');
        });

        return false;
    });

    $('#printCloser').click(function () {
        $('#printDialog').fadeOut('fast');
    });

    $(".navbar").each(function (i) {
        var id = this.id;
        var newId = id.replace("nav", "nav_hi");
        var obj = $("#" + newId);

        $(this).parent().hover(
			function () { obj.css("display", "block"); },
			function () { obj.css("display", "none"); }
		);
    });

    /*
    if ($.browser.msie && $.browser.version == 6) {
    $('.modelNav a, .seriesNav a').each(function(i) {
    var img = $(this).children('.modelImg')[0];
    $(img).css("width", img.width + "px");
    $(img).css("height", img.height + "px");
    $(img).css("AlphaFilter", "..."+$(img).src+"...");
    $(img).src = pngFixPixel;
    });
    }
    */
    $('.modelNav a, .seriesNav a').each(function (i) {
        $(this).hover(
            function () {
                //var imgModel = $(this).children('.modelName')[0];
                //imgModel.src = imgModel.src + "&active=1";
                //hilite($(this).children('.modelImg')[0], true);
                $($(this).find('.modelName')[0]).css("display", "none");
                $($(this).find('.modelName')[1]).css("display", "block");
                $($(this).find('.modelImg')[0]).css("display", "none");
                $($(this).find('.modelImg')[1]).css("display", "block");
                $(this).children('span').toggleClass('.modelHover');
            },
            function () {
                //var imgModel = $(this).children('.modelName')[0];
                //imgModel.src = imgModel.src.replace("&active=1", "");
                //hilite($(this).children('.modelImg')[0], false);
                $($(this).find('.modelName')[1]).css("display", "none");
                $($(this).find('.modelName')[0]).css("display", "block");
                $($(this).find('.modelImg')[1]).css("display", "none");
                $($(this).find('.modelImg')[0]).css("display", "block");
                $(this).children('span').toggleClass('.modelHover');
            }
        )
    });

    $('#turnLeft').hover(
    function () {
        hilite(this, true)
    },
    function () {
        hilite(this, false)
    }
    );
    $('#turnRight').hover(
    function () {
        hilite(this, true)
    },
    function () {
        hilite(this, false)
    }
    );
    $('#turnLeft, #turnRight').click(
        function () {
            if ($('#configuredCar').hasClass("opened")) {
                openCloseCarData();
            }
        }
    );
    $('#turnLeft').mousehold(1000,
    function () {
        turnCar(-1);
    }
    );
    $('#turnRight').mousehold(1000,
    function () {
        turnCar(1);
    }
    );
    function turnCar(deg) {
        var img = $('#currentCarView')[0];
        var imgW = $('#currentCarWheel')[0];

        var maxPos = carImages.length;
        currentPos = (maxPos + currentPos + deg) % maxPos;
        img.src = carImages[currentPos];
        if (!!imgW) {
            imgW.src = wheelImages[currentPos];
        }

        //        var oldsrc = "";
        //        oldsrc = img.src;
        //        var spos = oldsrc.lastIndexOf("_", oldsrc.length);
        //        var epos = oldsrc.indexOf(".", spos);
        //        var thisview = oldsrc.substring(spos + 1, epos);
        //        var newview = ((thisview) * 1 + 360 + deg) % 360;
        //        img.src = oldsrc.replace('' + thisview + '.png', '' + newview + '.png');
        $('#currentCarAngle')[0].value = currentPos;
        $.cookie('currentCarAngle', currentPos, { path: '/' });

        $('#currentCarView').ifixpng();
        $('#currentCarWheel').ifixpng();
    }

    var myCarView = $('#currentCarView');
    if (myCarView && myCarView.length > 0) {
        var newview = $.cookie('currentCarAngle');
        if (newview && newview != '') {
            turnCar(0);
        }
    }

    $('.pagerleft').click(
        function () {
            switchUpholstery(-1);
        }
    );

    $('.pagerright').click(
        function () {
            switchUpholstery(1);
        }
    );

    function switchUpholstery(dir) {
        var uphImage = $('#currentInteriorView')[0];
        var thisImg = 0;
        var maxUph = upholsteryImages.length;
        for (var i = 0; i < maxUph; i++) {

            if (uphImage.src.indexOf(upholsteryImages[i]) > -1) {
                thisImg = i;
            }
        }

        thisImg = (thisImg + maxUph + dir) % maxUph;
        uphImage.src = upholsteryImages[thisImg];
    }

    $('#leftOpenCloseBox').hover(
    function () {
        hilite(this.firstChild, true)
    },
    function () {
        hilite(this.firstChild, false)
    }
    );
    $('#leftOpenCloseBox').click(
        function () {
            openCloseCarData();
        }
    );
    function openCloseCarData(noAnimation) {

        $('#configuredCar').toggleClass("opened");
        $('#configuredCar').toggleClass("closed");
        //CloseArrow
        var img = $('#leftOpenCloseBox img')[0];
        if ($('#configuredCar').hasClass("opened")) {
            img.src = img.src.replace("up", "down");
            $.cookie('showCarData', 'true', { path: '/' });
        }
        else if ($('#configuredCar').hasClass("closed")) {
            img.src = img.src.replace("down", "up");
            $.cookie('showCarData', 'false', { path: '/' });
        }
        $("#configuredCar .allData").each(function (i) {
            if (noAnimation)
                $(this).css('display', 'none');
            else
                $(this).slideToggle('fast');

        });
    }
    if ($.cookie('showCarData') == 'false') {
        openCloseCarData(true);
    }

    function setPanelsVisibility(pan, disp) {
        //colorSelectionContainer
        var panel;
        panel = $(pan);
        if (panel.length == 1) {
            panel.css('display', disp);
        }
    }
    function setSelectionVisibility(disp) {
        setPanelsVisibility('#selectionContainer', disp);
        setPanelsVisibility('#selectionContainerShadow', disp);
        setPanelsVisibility('#colorSelectionContainer', disp);
        setPanelsVisibility('#wheelSelectionContainer', disp);
    }
    //interior / exterior
    $('#toggleViewContainer').click(
    function () {
        $('#CarView').toggleClass("exterior");
        $('#CarView').toggleClass("interior");
        if ($('#CarView').hasClass('interior')) {
            //            this.src = this.src.replace('interior', 'exterior');
            $('#toggleViewHi').css('display', 'block');
            $('#toggleView').css('display', 'none');
            setSelectionVisibility('none');
        }
        else {
            //            this.src = this.src.replace('exterior', 'interior');
            //this.src = "/Content/Images/interior_lo.png";
            $('#toggleViewHi').css('display', 'none');
            $('#toggleView').css('display', 'block');
            setSelectionVisibility('block');
        }
        //$('#toggleView').ifixpng();
    }
    );
    $('#toggleViewContainer, #leftOpenCloseBox').hover(
        function () {
            $(this).addClass('mousehover');
        },
        function () {
            $(this).removeClass('mousehover');
        }
    );

    //consumption info (CarDataTemplate)
    var motInfo = $('#motorInformation').cluetip(
            { width: 160, topOffset: -110, leftOffset: 10,
                positionBy: 'fixed', cluetipClass: 'infoLayer', dropShadow: false, splitTitle: ' || '
            });

    //motor-details
    var motorDetails = $('#selectionContainer.accordion a');
    motorDetails.click(function () {
        if ($(this).next().css('display') == 'block') {
            $(this).attr('class', 'closed').next().hide('normal');
        }
        else {
            var that = this;
            motorDetails.each(function () {
                if (that != this) $(this).attr('class', 'closed').next().hide('normal');
            });
            $(this).removeClass('closed');
            $(this).next().show('normal', reinitialiseScrollPane);
        }
        return false;
    });

    //variant- & motor-details
    var variantDetails = $('#selectionContainer .detail .toggleDetail');
    if (variantDetails.length > 0) {
        variantDetails.each(function (i) {
            $(this).click(function () {
                if ($(this).css('display') != 'block') {
                    var that = this;
                    variantDetails.each(function (i) {
                        if (that != this) {
                            //$(this).next().css('display', 'none');
                            $(this).next().hide('normal');
                        }
                    });
                }
                $(this).next().toggle('normal', reinitialiseScrollPane);
                return false;
            });
        }
        );
        $('#selectionContainer dl').each(function (i) {
            $(this).find('.detailInfo a').click(function () {

                $('#popupTitle').html('Alle Informationen zu Ihrer Ausstattungsvariante');
                $('#popupContent').empty().append($(this).closest('dl').next().html());
                $('#popupContent a').click(function () {
                    $(this).toggleClass('closed');
                    $(this).next().slideToggle();
                    return false;
                });
                $('#popup').fadeIn();
                $('#popupContent').jScrollPane({ showArrows: true, scrollbarWidth: 9 });
                return false;
            });

            $(this).hover(
                function () { $(this).addClass("over") },
                function () { $(this).removeClass("over") }
            );
            //            $(this).click(function() {
            //                $(this).find('input').trigger('click');
            //            });
        });
    }

    //variants
    var variantSelCon = $('#selectionContainer input[name=variant]');
    if (variantSelCon.length > 0) {
        $('#frmNCC').submit(function (e) {
            if ($('#frmNCC').data('isValid') == '1') {
                return true;
            }
            return false;
        }
            );
        $('#infoMessageCancel').click(function () {
            $('#infoMessage').fadeOut('fast');
            return false;
        }
            );
        $('#infoMessageOK').click(function () {
            //$('#infoMessage').fadeOut('fast');
            $('#frmNCC').data('isValid', '1');
            var rb = $('#infoMessageOK').data('variantRB')[0];
            //alert(rb.checked);
            rb.checked = true;
            $('#frmNCC').submit(null);
            return false;

        }
            );
        variantSelCon.each(
        function (i) {
            var that = $(this);
            that.click(function () {
                var idval = this.id.replace("variantID", "");
                var infoMessage = $('#variantChangeMessage' + idval);
                if (infoMessage && infoMessage.length > 0) {
                    $('#frmNCC').data('isValid', '0');
                    $('#infoMessageOK').data('variantRB', that);
                    var msg = infoMessage.clone();
                    msg.attr('id', '');
                    msg.css('display', 'block');
                    $('#infoMessage div:first').replaceWith(msg);
                    $('#infoMessage').fadeIn('normal');
                }
                else {
                    $('#frmNCC').data('isValid', '1');
                    $('#frmNCC').submit(null);
                    //return true;
                }
                return false;
            });
        });
    }
    //colors
    var colTilesSelCon = $('#colorSelectionContainer');
    //    alert(typeof (colTilesSelCon));
    if (colTilesSelCon != null) {
        //        $( "#colorSelectionContainer input" ).each(
        //            alert("gefunden")
        //        )

        var colTiles = $('#colorSelectionContainer img');
        var infos = $('#infoLayer');
        if (colTiles != null && colTiles.length > 0) {
            colTiles.each(function (i) {
                var leftOffsetVal = -245;
                var topOffsetVal = -30;
                if ($.browser.msie) {
                    leftOffsetVal = -260;
                    topOffsetVal = -30;
                }

                //$(this).css('margin-top', '-' + ((12 - i) * 15) + 'px');
                //if (i % 2) $(this).css('margin-left', '50px');
                //$(this).css('margin-top', '-' + Math.round(60 * Math.cos((i / 11.0) * Math.PI / 2)) + 'px');

                $(this).cluetip({ width: 160, topOffset: topOffsetVal, leftOffset: leftOffsetVal, positionBy: 'auto', cluetipClass: 'infoLayer', dropShadow: false, splitTitle: ' || ' });

                if (!$(this).hasClass('.chosen')) {
                    $(this).hover(
                    function () {
                        if (!$(this).hasClass('active')) {
                            hilite(this, true);
                            //                            $(this).css('margin-top', (($(this).css('margin-top').replace('px', '') * 1) - 15) + 'px');
                        }
                        /*var props = this.alt.split(' || '); // props[0] --> Name || props[1] --> Aufpreis
                        infos[0].innerHTML = '<b>' + props[0] + '</b><br />Aufpreis ' + props[1] + '€';
                        infos.css('display', 'block');*/
                    },
                    function () {
                        //infos.css('display', 'none');
                        if ($(this).hasClass('active')) {
                            return;
                        }
                        hilite(this, false);
                        //                        $(this).css('margin-top', (($(this).css('margin-top').replace('px', '') * 1) + 15) + 'px');
                    }
                );
                }
            });
        }
    }
    //upholstery thumbnails
    var uphTilesSelcon = $('#upholsteryContainer');
    if (null != uphTilesSelcon && uphTilesSelcon.length > 0) {
        $('#frmNCC').submit(function (e) {
            if ($('#frmNCC').data('isValid') == '1') {
                return true;
            }
            return false;
        }
            );
        $('#infoMessageCancel').click(function () {
            $('#infoMessage').fadeOut('fast');
            return false;
        }
            );
        $('#infoMessageOK').click(function () {
            //$('#infoMessage').fadeOut('fast');
            $('#frmNCC').data('isValid', '1');
            $('#upholstery')[0].value = $('#infoMessageOK').data('upholsteryId');
            $('#frmNCC').submit(null);
            return false;

        }
            );


        $('#upholsteryContainer .uphImage').each(
        function (i) {
            var leftOffsetVal = -190;
            var topOffsetVal = -15;
            if ($.browser.msie) {
                leftOffsetVal = -300;
                topOffsetVal = -15;
            }

            var that = $(this);
            that.cluetip({ width: 160, topOffset: topOffsetVal, leftOffset: leftOffsetVal, positionBy: 'fixed', cluetipClass: 'infoLayer', dropShadow: false, splitTitle: ' || ' });

            if (!that.hasClass('.chosen')) {
                selImageClick(that, 'upholstery');

                that.hover(
                function () {
                    if ($(this).hasClass('active')) {
                        return;
                    }
                    hilite(this, true);
                    //                    $('upholsteryContainer .uphImage').ifixpng();
                },
                function () {
                    if ($(this).hasClass('active')) {
                        return;
                    }
                    hilite(this, false);
                }

            );
            }
        }
    );
    }

    //upholstery pager
    $('#CarViewInterior .pager').each(
        function (i) {
            $(this).hover(
                function () {
                    if ($(this).hasClass('active')) {
                        return;
                    }
                    hilite(this, true);
                },
                function () {
                    if ($(this).hasClass('active')) {
                        return;
                    }
                    hilite(this, false);
                }
            );
            $(this).click(function () {
                if ($(this).hasClass('active')) {
                    return;
                }
                $('#CarViewInterior .pager').each(
                    function (i) {
                        if ($(this).hasClass('active')) {
                            $(this).removeClass('active');
                            hilite(this, false);
                        }
                    }
                )

                $(this).toggleClass('active');
                var img = $('#currentInteriorView')[0];

                var newIdx = this.id.substring(this.id.length - 1) + ".png";
                var oldIdxPos = img.src.indexOf(".png");
                var oldIdx = img.src.substring(oldIdxPos - 1);
                img.src = img.src.replace(oldIdx, newIdx);
            });
        }
    );

    //Wheels
    var wheelsSelCon = $('#wheelSelectionContainer');
    if (wheelsSelCon != null) {
        var wheels = $('.wheel');
        if (wheels != null && wheels.length > 0) {
            $('#frmNCC').submit(function (e) {
                if ($('#frmNCC').data('isValid') == '1') {
                    return true;
                }
                return false;
            }
            );
            $('#infoMessageCancel').click(function () {
                $('#infoMessage').fadeOut('fast');
                return false;
            }
            );
            $('#infoMessageOK').click(function () {
                //$('#infoMessage').fadeOut('fast');
                $('#frmNCC').data('isValid', '1');
                $('#wheel')[0].value = $('#infoMessageOK').data('wheelId');
                $('#frmNCC').submit(null);
                return false;

            }
            );
            wheels.each(function (i) {
                addWheelFuncs($(this).children(".wheelImage"), $(this).children(".glow"), !$(this).hasClass('.chosen'));
            });
        }
    }

    //my conf
    if ($('#addrForm').length) {
        $('#popupTitle').html('Ihr Mazda ist konfiguriert!');
        $('#popupContent').empty().append($('#addrForm'));
        $('#nextStep').click(function () {
            $('#dealerForm').hide();
            $('#formResultMsg').hide();
            $('#popup').fadeIn();
            //logClick('/ResultCallToAction/html_CC CTA - Test Drive');
        });

        $('#findDealer').click(function () {
            var thisSearch = 'dealerZip=' + escape($('#zipcode').attr('value')) + '&dealerCity=' + escape($('#city').attr('value'));
            if (thisSearch == 'dealerZip=&dealerCity=' || isNaN($('#zipcode').attr('value'))) {
                $('#dealerInfo').html('<span class="error">Bitte mindestens die Postleitzahl oder den Ort angeben!</span>');
                return;
            }

            $("#dealerInfo").ajaxError(function (event, request, settings) {
                $(this).html("Verbindungsfehler");
            });

            $.getJSON(webservicePath + '/DealerJsonSearch.ashx?' + thisSearch,
                function (dealers, status) {
                    $("#dealerForm ul").empty();
                    if (dealers.Status == "OK") {
                        $.each(dealers.Dealer, function (i, dealer) {
                            var liAdd = $("<li><strong>" + dealer.Name + "</strong><br />" + dealer.Street + ', ' + dealer.Postcode + ' ' + dealer.City + ' (Entfernung ca: ' + dealer.Distance.replace('.', ',') + 'km)' + "</li>");
                            liAdd.click(function () {
                                var dealerAddr = dealer.Name + ', ' + dealer.Street + ', ' + dealer.Postcode + '&nbsp;' + dealer.City;
                                $('#dealerInfo').html(dealerAddr);
                                $('#dealerForm').fadeOut();
                                $('#dealerId').attr('value', dealer.DealerNumber);
                            });
                            liAdd.hover(
                                function () { $(this).addClass('over'); },
                                function () { $(this).removeClass('over'); }
                            );
                            liAdd.appendTo("#dealerForm ul");
                            if (i == 5) return false;
                        });
                        $('#dealerForm').fadeIn();
                    }
                    else {
                        $('#dealerInfo').html('<span class="error">Fehler bei der Suche</span>');
                    }
                });

        });

        $('#privacyInfo').hover(
            function () {
                $('#privacyInfoText').fadeIn('fast');
            },
            function () {
                $('#privacyInfoText').fadeOut('fast');
            }
        );

        //extended opt in
        var rbOptInsSel = 'input:radio[id^="allowcontact"]';

        var isOptInChosen = function () {
            var enableOptins = $(rbOptInsSel);
            var isChosen = false;
            enableOptins.each(function (idx, optIn) {
                if (optIn.checked) {
                    isChosen = true;
                    return false;
                }
            });

            return isChosen;
        };
        var optInAllowed = function () {
            var enableOptins = $(rbOptInsSel);
            var isAllowed = false;
            enableOptins.each(function (idx, optIn) {
                if (optIn.checked && optIn.value == 'true') {
                    isAllowed = true;
                }
            });

            return isAllowed;
        };

        var checkOptinDependency = function () {
            var isDisabled = !optInAllowed();
            $('.cbOptins input').attr('disabled', isDisabled);
        };

        checkOptinDependency();
        $(rbOptInsSel).live('click', function () {
            //var ftkFakeCtrl = $('#ctl00_RightColumn_formPh_mainFormWizard_ctl28_FakeItem');
            //ftkFakeCtrl.val($(this).attr('value'));
            $(this).blur();
            checkOptinDependency();
            //validateExtOptin();
            //jQuery.data(ftkFakeCtrl[0], 'valueSet', true);
        });
        $('.cbOptins input').live('click', function () {
            //validateExtOptin();
        });
        //extended opt in end

        var showFormError = function (msg) {
            $.Growl.show({
                'message': msg
            });
        };
        $('#sendForm').click(function () {
            $.Growl.close();
            var ok = true;

            //salutation
            if ($('#addrForm input[name="salutation"]').serialize() == "") {
                ok = false;
                showFormError('Bitte geben Sie Ihre Anrede an.');
            }
            //email
            if ($('#addrForm input[name="email"]').attr('value').indexOf('@') <= 0) {
                ok = false;
                showFormError('Bitte geben Sie eine gültige E-Mail-Adresse an.');
            }
            //zipcode
            if (isNaN($('#zipcode').attr('value'))) {
                ok = false;
                showFormError('Bitte geben Sie eine gültige Postleitzahl an.');
            }

            $('#addrForm input[type="text"]').each(function () {
                if ($.trim(this.value) == "") {
                    ok = false;
                    return false;
                }
            });

            if (isOptInChosen()) {
                var testOptIn = optInAllowed();
                if (testOptIn) {
                    var noAllowChecked = true;
                    $('.cbOptins input').each(function (idx, cbAllow) {
                        if (cbAllow.checked) {
                            noAllowChecked = false;
                            return false;
                        }
                    });
                    if (noAllowChecked) {
                        ok = false;
                        showFormError('Bitte geben Sie an, wie sie zukünftig von Mazda informiert werden dürfen.');
                    }
                }
            }
            else {
                showFormError('Bitte geben Sie an, wie sie zukünftig von Mazda informiert werden wollen.');
            }

            if (ok) {
                var sendUrl = webservicePath + '/CustomerRequestJS.svc/Send?';
                var data = $('#addrForm input').serialize();
                $('#formResultMsg').html("<h3>Einen Moment Geduld bitte</h3><p>Daten werden übertragen...</p>");
                $('#formResultMsg').fadeIn();
                $.getJSON(sendUrl + data, function (result, status) {
                    if (result.d.statusField == "OK") {
                        $('#formResultMsg').html("<h3>Ihre Anfrage wurde soeben weitergeleitet.</h3><p>Wir werden uns in Kürze mit Ihnen in Verbindung setzen.</p>");
                        logClick('/ResultCallToAction/html_CC CTA - DealerCallback/Call-to-action Click');
                    }
                    else {
                        $('#formResultMsg').html("<h3>Fehler</h3><p>Ihre Anfrage konnte nicht gespeichert werden</p>");
                        $('<p>' + status + '</p>').append($('#formResultMsg'));
                        $('<p>' + result + '</p>').append($('#formResultMsg'));
                    }
                });
            }
            else {
                $('#formErrorMsg').hide().html('<span class="error">Bitte füllen Sie das Formular vollständig und korrekt aus.</span>').fadeIn();
            }

        });
    }


    //headline box
    window.setTimeout(
        function () {
            $('#modelHead').fadeOut('slow');
        },
        2500
        );
});

function addWheelFuncs(wheelImg, glowImg, addClick) {
    var leftOffsetVal = -230;
    var topOffsetVal = -80;
    if ($.browser.msie) {
        leftOffsetVal = -230;
        topOffsetVal = -80;
    }

    $(wheelImg).cluetip({ width: 160, topOffset: topOffsetVal, leftOffset: leftOffsetVal, positionBy: 'fixed', cluetipClass: 'infoLayer', dropShadow: false, splitTitle: ' || ' });

    if (addClick) {
        $(wheelImg).mouseenter(
                    function () {
                        var obj = $(glowImg);
                        obj.css('display', 'block');
                    }
                );

        $(wheelImg).mouseleave(
                    function () {
                        var obj = $(glowImg);
                        obj.css('display', 'none');
                    }
                );

        selImageClick(wheelImg, 'wheel');
        //        $(wheelImg).click(function() {
        //            var idval = this.id.replace("wheel_", "");
        //            var infoMessage = $('#wheelChangeMessage' + idval);
        //            if (infoMessage && infoMessage.length > 0) {
        //                $('#frmNCC').data('isValid', '0');
        //                $('#infoMessageOK').data('wheelId', idval);
        //                var msg = infoMessage.clone();
        //                msg.attr('id', '');
        //                msg.css('display', 'block');
        //                $('#infoMessage div:first').replaceWith(msg);
        //                $('#infoMessage').fadeIn('normal');
        //            }
        //            else {
        //                $('#frmNCC').data('isValid', '1');
        //                $('#wheel')[0].value = idval;
        //                $('#frmNCC').submit(null);
        //                return false;
        //            }
        //        });
    }
}

function selImageClick(obj, selName) {
    $(obj).click(function () {
        var idval = this.id.replace(selName + "_", "");
        var infoMessage = $('#' + selName + 'ChangeMessage' + idval);
        if (infoMessage && infoMessage.length > 0) {
            $('#frmNCC').data('isValid', '0');
            $('#infoMessageOK').data(selName + 'Id', idval);
            var msg = infoMessage.clone();
            msg.attr('id', '');
            msg.css('display', 'block');
            $('#infoMessage div:first').replaceWith(msg);
            $('#infoMessage').fadeIn('normal');
        }
        else {
            $('#frmNCC').data('isValid', '1');
            $('#' + selName)[0].value = idval;
            $('#frmNCC').submit(null);
            return false;
        }
    });
}


function hilite(obj, isActive) {
    if (isActive) {
        if (isIE6() && obj.style.filter) {
            obj.style.filter = obj.style.filter.replace("_lo.", "_hi.");
            obj.style.cursor = "pointer";
        }
        else obj.src = obj.src.replace("_lo.", "_hi.");
    }
    else {
        if (isIE6() && obj.style.filter) {
            obj.style.filter = obj.style.filter.replace("_hi.", "_lo.");
        }
        else obj.src = obj.src.replace("_hi.", "_lo.");
    }
}

function isIE6() {
    //jquerys $.browser.version is not reliable as it reads userAgent
    return (window.ActiveXObject && !window.XMLHttpRequest); //thanks to mootools:)
}

function isIE7() {
    if (window.XMLHttpRequest && document.epando) {
        return true;
    }
}
