/* ################################################################# */
/*                              sol.js                              */
/* ################################################################# */

function solIsShittyBrowser ()
{
    // shitty t-online browser won't get nifty ajax ...
    if (navigator.userAgent.match(/TOB/))
        return true;
    // .. neither does aol browser (and TOB sometimes covers as AOL)
    if (navigator.userAgent.match(/America Online/))
        return true;
    // see: http://www.mageblog.de/2009/10/02/user-agent-wechsel-dich-pfusch-beim-t-online-browser/
    return false;
}

function solChangeStatus(iSolIndicator,sSolText,blSolIsParent){
	var eSolStockinfo = "";

	if(eSolStatFlag = document.getElementById('solStatFlag')) {
		switch (iSolIndicator){
			case "4":
				eSolStatFlag.className = "flag orange";
				break;
			case "3":
				eSolStatFlag.className = "nodisp";
				break;
			case "2":
			case "1":
				eSolStatFlag.className = "flag green";
				break;
		}
		if(blSolIsParent) eSolStatFlag.className = "flag";
		
	}	
	if(eSolStatText = document.getElementById('solStatText')) {
		switch (iSolIndicator){
			case "4":
				eSolStatText.className = "";
				eSolStatText.innerHTML = sSolText;
				break;
			case "3":
				eSolStatText.className = "nodisp";
				eSolStatText.innerHTML = "";
				break;
			case "2":
			case "1":
				eSolStatText.className = "";
				eSolStatText.innerHTML = sSolText;
				break;
		}
	}
}


function solChangeVariant(varid){
	var oSAJ = oSolArticleJson[varid];
	var oSolPriceElem=document.getElementById('sSolSelPrice');
	oSolPriceElem.innerHTML=oSAJ.price;
	var blSolIsParent = varid=="0"?1:0;

	if (oSolTPriceElem=document.getElementById('sSolTPrice')){
		oSolTPriceElem.innerHTML = oSAJ.tprice!="0"?oSAJ.tprice:"";
	}

	if (oSolPercentElem=document.getElementById('sSolPercent')){
		oSolPercentElem.innerHTML = oSAJ.percent!="0"?oSAJ.percent:"";
	}

	if(oSAJ.pic1){
		oxid.image('product_img',oSAJ.pic1); 
		if(oSAJ.zoom1){
			oxid.image('zoom_img',oSAJ.zoom1);
		}
	}

	if(oSAJ.icoid){
		solMarkSelectedPic(oSAJ.icoid);
	}
/*
	if( document.getElementById('blSolHasDiffDiscPerc').value ){
		if( oSolTPriceElem.innerHTML == ""  && !blSolIsParent ){
			document.getElementById('sSolSelPrice').className = 'price';
		}else{
			document.getElementById('sSolSelPrice').className = 'price highlight';
		}
	}
*/
	solChangeStatus(oSAJ.indicator,oSAJ.delinfo,blSolIsParent);
}

function solCahngeIcon(iconid){
	if(sSolVarId) sSolVarId=iconid;
}

function solMarkSelectedPic(icoelemid){
    /*
	if(sSolVarId) { 
		if(document.getElementById(sSolVarId)) document.getElementById(sSolVarId).className='icon'; 
		if(document.getElementById('z_'+sSolVarId)) document.getElementById('z_'+sSolVarId).className='icon'; 
	}
    */
    $('.morepics .icon_frame .icon').removeClass('act');
	if(document.getElementById(icoelemid)) document.getElementById(icoelemid).className='icon act'; 
	if(document.getElementById('z_'+icoelemid)) document.getElementById('z_'+icoelemid).className='icon act';
	sSolVarId=icoelemid;
}

var oSol = {
    text: null,
	addDynToBasket: function(obj,title){
        if (this.text == null)
           this.text = document.getElementById("wait").innerHTML;
        waitText = this.text.replace(/'.*'/g, "'"+title+"'");
        document.getElementById("wait").innerHTML = waitText;
        hs.htmlExpand(obj,{
            maincontentId: 'wait'
    	});
        $('.highslide-body',document).html(waitText);
        oxid.popup.resizeInterval();
        // now process the ajax request
        $.get(
            obj.href,
            function (data) {
                var resp = document.createElement('div');
                resp.innerHTML = data.replace(/<head.*head>/,'').replace(/<script.*script>/,'');
                // update popup content
                $('.highslide-body',document).html('<div id="popup" class="popup">' + $('div#popup',resp).html() + '</div>');
                oxid.popup.resizeInterval();
                // update minibasket
                $('.minibasket',document).html($('.minibasket',resp).html());
                // recreate wait div if destroyed by highslider
                if ($('div#wait',document).length <= 0)
                {
                    var elem = document.createElement('div');
                    elem.id = 'wait';
                    elem.innerHTML = $('div#wait',resp).html();
                    document.body.appendChild(elem);
                    $('#wait',document).addClass('popup');
                }
            }
        );
        return false;
    }
}

function showReview()
{
    document.getElementById('write_review').style.display = 'block';
    document.getElementById('write_new_review').style.display = 'none';
    if (arguments.length == 1) {
        var oActForm = document.getElementById("rating");
        if ( oActForm !== null) {
            if (oActForm.artrating) {
                oActForm.artrating.value = arguments[0];
            } else if (oActForm.recommlistrating) {
                oActForm.recommlistrating.value = arguments[0];
            }
            var width = arguments[0] * 20;
            document.getElementById('current_rate').style.width = width + '%';
        }
    }
}

function setSellList( oInObj)
{
    //for module wlist
    var _wlist = document.getElementById("wlist");
    if ( _wlist !== null) {
        _wlist.href = _wlist.href + "&" + oInObj.name + "=" + oInObj.value;
    }
    //for original selectlist
    var _slist = document.getElementById("slist");
    if ( _slist !== null) {
        _slist.href = _slist.href + "&" + oInObj.name + "=" + oInObj.value;
    }
}


function solListToggleInit ()
{
  /* hide all objects */
  $('.toggleHandle').each(function () {
    /* do not hide objects with "forceShow" class */
    if ($(this).hasClass('forceShow') || $(this).hasClass('initShow'))
      return;
    var obj = this.nextSibling;
    while (obj.nodeType != 1)
      obj = obj.nextSibling;
    $(obj).hide();
  });

  /* init click handler */
  $('.toggleHandle').click(function(){
    /* search for new element to show*/
    var obj = this.nextSibling;
    while (obj && obj.nodeType != 1)
      obj = obj.nextSibling;
    /* do nothing if current element is clicked */
    if ($(obj).is(':visible') && !$(this).hasClass('forceShow'))
      return;

    /* hide all objects */
    $('.toggleHandle').each(function () {
      if ($(this).hasClass('forceShow'))
        return;
      var obj = this.nextSibling;
      while (obj.nodeType != 1)
        obj = obj.nextSibling;
      $(obj).slideUp();
    });
    /* show clicked object */
    $(obj).slideDown();
  });
}

function solSlideInit ()
{
    $('.slideHandle').each(function(){
        if ($(this).hasClass('forceShow'))
          return;
        var obj = this.nextSibling;
        while (obj.nodeType != 1)
          obj = obj.nextSibling;
        $(obj).hide();
    });

    $('.slideHandle').click(function(){
        var obj = this.nextSibling;
        while (obj.nodeType != 1)
          obj = obj.nextSibling;
        $(obj).slideToggle();
    });
}

function solShowRating (obj)
{
    var par = $(obj.parentNode);
    par.after('<div class="left ajaxrating"><img src="/out/bergfreunde/src/bg/ajax-loader.gif" /><br /></span><br style="clear:both;" />');
    par.hide();
    $('.ajaxrating',par.parentNode).load(obj.href+' .ratingcontent',function (text) {
        $(this).hide().slideDown(200); // fancy animation ;)
        solShowRatingHandler(this);
        solInitReviewForceSubmit(this);
    });
}

function solShowRatingHandler (obj)
{
    $('form',obj).submit(function(){
        $(this).parents('.ajaxrating').load(this.action+' .ratingcontent',$(this).serializeArray(),function(){
            // check for form tag
            if ($('form.ratingform',this).length == 1)
            {
                // failure in form, just register submit handler
                solShowRatingHandler(this);
                solInitReviewForceSubmit(this);
                return;
            }
            // form submit valid, filter contents in span tag
            $('span',this.parentNode).remove();
            $('div',this.parentNode).removeClass('padding');
            if ($(this).parents('.ratingproduct').hasClass('forcereload'))
            {
                window.location.href = window.location.href;
                return;
            }
            window.setTimeout('solShowRatingClear()',2000);
        });
        return false; // prevent default submit action
    });
    $('form .bar.prevnext .btn',obj).before('<span style="float: left; text-align: left;"><a href="#" onClick="solCancelRating(this); return false;" title="Schlie&szlig;en ohne zu Speichern">[X] Abbrechen</a></span>');
    $('.rating_hints',obj).hide();
    $('.account_hints',obj).show();
    return true;
}

function solCancelRating (obj)
{
    var cont = $(obj).parents('.ajaxrating:first').parentNode;
    $('div.ajaxrating',cont).slideUp(function(){
        $(this).remove();
        $('div.button',cont).show();
    });
}

function solShowRatingClear (obj)
{
    if (obj != undefined)
    {
        $(obj).slideUp(200,function(){
            $(this).remove();
        });
    } else {
        $('.ratingproduct').each(function() {
            if ($('.ajaxrating',this).length == 1 &&
                 $('form',this).length <= 1)
                $(this).slideUp(200,function(){
                    $(this).remove();
                });
        });
    }
    $('.ratingshow5 .ratingproduct:lt(6):hidden').slideDown();
}

function solNeverRate (obj)
{
    var form = $(obj).parent('form');
    $.ajax({
        type: 'POST',
        url: form.attr('action'),
        data: form.serialize(),
        success: function(data) {
            $(obj).addClass('ajaxrating');
            solShowRatingClear($(form).parents('div.ratingproduct'));
        },
        error: function(data) {
            // in case server return 500
        }
    });
    return false; 
}

function solRatingInit ()
{
    $('.ratingshow5 .ratingproduct:gt(4)').hide();
}

function solTabInit ()
{
    // set active tab
    $('.solinitactive').removeClass('solinitactive').addClass('solactive');
    if (!$('.solactive').length)
        $('.soltabhandle:first').addClass('solactive');
    //
    $('.soltabhandle:first').addClass('bffirst');
    $('.soltabhandle:last').addClass('bflast');
    // and overwrite css display setting for js capable browsers
    $('.soltabhandle').addClass('bftabdesign');
    // hide all content divs
    $('.soltabhandle ~ .soltabcontent').hide();
    // create content element container
    $('.soltabhandle:first').parent('.soltabcontainer').append($('<div class="clear" />'));
    $('.soltabhandle:first').parent('.soltabcontainer').append($('<div id="soltabcontentcontainer" />'));
    // register click event handler to switch to another tab
    $('.soltabhandle').click(function(obj){
        // get content from new tab and write into tab container
        $('#soltabcontentcontainer').html($(this).next('.soltabcontent').html());
        // switch active class
        $('.soltabhandle').removeClass('solactive');
        $(this).toggleClass('solactive');
    });
    // fire click event on active tab
    $('.solactive').click();
}

function bfShowPackstation()
{
	document.getElementById('packstation').style.visibility = 'visible';
	var elems = document.getElementsByName('deladr[oxaddress__oxstreet]');
	elems[0].value = 'Packstation';
	var elems = document.getElementsByName('deladr[oxaddress__oxstreetnr]');
	elems[0].style.background = '#fc0';
	var elems = document.getElementsByName('deladr[oxaddress__oxcompany]');
	elems[0].style.background = '#fc0';
}

function bfHidePackstation()
{
	document.getElementById('packstation').style.visibility = 'hidden';
	var elems = document.getElementsByName('deladr[oxaddress__oxstreet]');
	elems[0].value = '';		
	var elems = document.getElementsByName('deladr[oxaddress__oxstreetnr]');
	elems[0].style.background = '#fff';
	var elems = document.getElementsByName('deladr[oxaddress__oxcompany]');
	elems[0].style.background = '#fff';
}

function solAccountNewsletterCheckbox ()
{
    $('form[name=newsletter] input[type=checkbox]').change(function(){
        if (this.id == 'status_solcancel')
        {
            if (this.checked)
            {
                $('form[name=newsletter] input[type=checkbox]').attr('checked',false);
                this.checked = true;
            }
            return;
        }
        if (this.id == 'status_solall')
        {
            if (this.checked)
            {
                $('form[name=newsletter] input[type=checkbox]').attr('checked',true);
                document.getElementById('status_solcancel').checked = false;
                this.checked = true;
            } else {
                $('form[name=newsletter] input[type=checkbox]').attr('checked',false);
                document.getElementById('status_solcancel').checked = true;
                this.checked = false;
            }
            return;
        }
        if (this.checked)
        {
            var cancel = document.getElementById('status_solcancel');
            if (cancel)
                cancel.checked = false;
            if (document.getElementById('status_soloutdoor').checked &&
                document.getElementById('status_soloutdoorlive').checked &&
                document.getElementById('status_solcrocs').checked &&
                document.getElementById('status_solcrocslive').checked)
                document.getElementById('status_solall').checked = true;
        } else {
            document.getElementById('status_solall').checked = false;
        }
    });
}

solAccountNewsletterCheckbox();

function solFlyOut ()
{
    var timerFadeOut = null;
    var timerFadeIn = null;
    $('div.flyout').css('display','none');

    $('.menue > li.flyout').bind('mouseenter',function(){
        // clear timeout
        window.clearTimeout(timerFadeOut);
        window.clearTimeout(timerFadeIn);
        $('.menue > li.flyout').removeClass('pasthover');
        $('.menue > li.flyout').removeClass('hover');
        $(this).addClass('hover');
        $(this).next('li').addClass('pasthover');
        if ($('.menue > li.flyout > div.flyout:visible').length == 0)
        {
            var that = this;
            timerFadeIn = window.setTimeout(function(){
                $('div.flyout').css('display','none');
                $('div.flyout',that).css('display','block');
            },150);
            return;
        }
        $('div.flyout').css('display','none');
        $('div.flyout',this).css('display','block');
    });
    $('.menue').bind('mouseleave',function(){
        var that = this;
        timerFadeOut = window.setTimeout(function(){
        	$('li.flyout',that).removeClass('pasthover');
            $('div.flyout',that).css('display','none');
            $('li.flyout',that).removeClass('hover');
        },150);
        window.clearTimeout(timerFadeIn);
    });
}

solFlyOut();

var solZoomInterval = null;

function solShowArticleZoomPic (obj)
{
    if (!obj.href.match(/tpl=/))
    {
        if (obj.href.match(/\?/))
            obj.href += '&';
        else
            obj.href += '?';
        obj.href += 'tpl=inc/popup_zoom.tpl';
    }
    obj.href = obj.href.replace(/moredetails/,'details');
    oxid.popup.resizeInterval();
    solZoomInterval = window.setInterval(function(){solSetActiveZoomPic(obj);}, 100);
    hs.htmlExpand(obj, { objectType: 'ajax'} );
    return;
}

function solSetActiveZoomPic (obj)
{
    var exp = hs.getExpander();
    if (exp){
        $('#zoom .icon').removeClass('act');
        var context = $(obj).parents('div.product');
        $('div.icon.act',context).each(function(){
            $('#zoom #z_'+this.id).click();
            $('#zoom #z_'+this.id+' a').click();
        });
        window.clearInterval(solZoomInterval);
    }
}

function solSubmitBasket (obj)
{
    // normal checks
    if (!submitbasket(obj))
        return false;
    if (solIsShittyBrowser())
        return true;
    if (obj != undefined)
        var form = $(obj);
    else
        var form = $('#tobasketform');
    // create fake a-tag for highslider
    var a = document.getElementById('solSubmitBasketHack');
    if (!a)
    {
        $(this).append('<a href="javascript:;" id="solSubmitBasketHack"></a>');
        a = document.getElementById('solSubmitBasketHack');
    }
    if (obj != undefined && $('#wait').length)
        $('#wait').html($('#wait').html().replace(/'.*'/,''));
    // show highslider
    hs.htmlExpand(a,{
        maincontentId: 'wait'
    });
    oxid.popup.resizeInterval();
    // now process the ajax request
    $.post(
        form.attr('action'),
        form.serialize(),
        function (data) {
            var resp = $(data);
            // update popup content
            $('.highslide-body',document).empty();
            resp.find('#popup').appendTo('.highslide-body',document);
            oxid.popup.resizeInterval();
            // update minibasket
            $('.minibasket',document).empty();
            resp.find('.minibasket > *').appendTo('.minibasket',document);
        }
    );
    return false;
}

function solGetFixedUrl (url)
{
    if (url.substring(0,4) !== "http")
        return;
    // url seems to be absolute, check for http vs. https
    if (window.location.href.substring(0,5) == "https")
        return url.replace(/http:/,"https:");
    return url.replace(/https:/,"http:");
}

function solToggleNotepad (obj)
{
    if (solIsShittyBrowser())
        return true;
    hs.htmlExpand(obj,{
        maincontentText: '<div class="popup" style="text-align: center;"><img src="/out/bergfreunde/src/bg/ajax-loader.gif" style="margin-top: 50px;" /></div>',
        cacheAjax: false,
        forceAjaxReload: true
    });
    oxid.popup.resizeInterval();
    $.get(
        solGetFixedUrl(obj.href),
        function (data) {
            var resp = $(data);
            // update popup content
            var oldobj = $('#slist');
            var newobj = $('#slist',resp);
            oldobj.html(newobj.html());
            oldobj.attr('href',newobj.attr('href'));
            $('.highslide-body',document).empty();
            resp.find('#popup').appendTo('.highslide-body',document);
            solUpdateActionsList(resp);
            oxid.popup.resizeInterval();
        }
    );
    return false;
}

function solToggleCompare (obj)
{
    if (solIsShittyBrowser())
        return true;
    hs.htmlExpand(obj,{
        maincontentText: '<div class="popup" style="text-align: center;"><img src="/out/bergfreunde/src/bg/ajax-loader.gif" style="margin-top: 50px;" /></div>',
        cacheAjax: false,
        forceAjaxReload: true
    });
    oxid.popup.resizeInterval();
    var func = function (data) {
            var resp = $(data);
            var oldobj = $(obj);
            var ext = '';
            if (oldobj[0].tagName != 'FORM')
                if (oldobj.attr('id').match(/NoticeList/))
                    var ext = oldobj.attr('id').replace(/test_(toCmp|removeCmp)/,'');
            var newobj = $('#test_toCmp'+ext,resp);
            if (!newobj.length)
                newobj = $('#test_removeCmp'+ext,resp);
            if (oldobj[0].tagName != 'FORM')
            {
                oldobj.html(newobj.html());
                oldobj.attr('href',newobj.attr('href'));
            }
            //$('.highslide-body',document).html('<div id="popup" class="popup">' + $('div#popup',resp).html() + '</div>');
            $('.highslide-body',document).empty();
            resp.find('#popup').appendTo('.highslide-body',document);
            // update actionlist
            solUpdateActionsList(resp);
            oxid.popup.resizeInterval();
        };
    if (obj.tagName == 'FORM')
    {
        $.get(
            solGetFixedUrl(obj.action),
            $(obj).serialize(),
            func
        );
        return false;
    } else {
        $.get(
            solGetFixedUrl(obj.href),
            func
        );
    }
    return false;
}

function solUpdateActionsList (resp)
{
    // delete all actionslist elems if any
    $('dl.actionslist').remove();
    $('dl.actionslist',resp).each(function(){
        $('div.box.login').append('<dl class="actionslist">' + $(this).html() + '</dl>');
    });
    return;
}

function solClearBasket (obj)
{
    hs.htmlExpand(obj,{
        maincontentId: 'clearbasket',
        cacheAjax: false,
        forceAjaxReload: true
    });
    oxid.popup.resizeInterval();
    return false;
}

// validation

function solZipValidation (oxcountryid, zip)
{
    if (aZipChecks[oxcountryid] && aZipChecks[oxcountryid].length > 0)
    {
        var check = new RegExp('^'+aZipChecks[oxcountryid]+'$');
        return check.test(zip);
    }
    // at least a mandatory check is done
    if (zip.length > 0)
        return true;
    return false;
}

function solFormValidation ()
{
    var formId = $('form[name="order"]').attr('id');
    if (formId && formId.substring(0,7) == 'payform') // do not start validator on payment page
        return;
    if ($('#lgn_pwd2').length == 0)
    {
        var origMail = $('#lgn_usr').val();
        $('#lgn_usr').change(function(){
            var obj = $(this);
            if (obj.val() == origMail)
                $('#lgn_pwd').rules('remove','required');
            else
                $('#lgn_pwd').rules('add','required');
        });
    }
    $('select[name="invadr[oxuser__oxcountryid]"]').change(function(){
        $('form[name="order"]').validate().element('input[name="invadr[oxuser__oxzip]"]');
        if ($(this).val() == "")
            $('#err_invadr_oxuser__oxzip').attr('alt',sFormDefaultError);
    });
    $('select[name="deladr[oxaddress__oxcountryid]"]').change(function(){
        $('form[name="order"]').validate().element('input[name="deladr[oxaddress__oxzip]"]');
        if ($(this).val() == "")
            $('#err_deladr_oxaddress__oxzip').attr('alt',sFormDefaultError);
    });
    $('form[name="order"] input, form[name="order"] select').focus(function(){
        for (var i = 0; i < document.forms["order"].elements.length; i ++)
        {
            var elem = document.forms["order"].elements[i];
            if (elem == this)
                break;
            var j = 0;
            var rules = $(elem).rules();
            for (var rule in rules);
                j++;
            if (j == 0)
                continue;
            $('form[name="order"]').validate().element(elem);
        }
    });
    if ($('form[name="order"]').length == 0)
        return;
    jQuery.getScript('/out/bergfreunde/src/jquery.validate.min.js',function() {
        jQuery.validator.addMethod('zip',function (value,form) {
            var oxid = $('select[name="invadr[oxuser__oxcountryid]"]')[0].value;
            if (value.length == 0)
            {
                $('#err_invadr_oxuser__oxzip').html(sFormDefaultError);
                return false;
            }
            if (solZipValidation(oxid,value))
                return true;
            // set error
            $('#err_'+form.id).attr('alt',aZipErrors[oxid]);
            return false;
        });
        jQuery.validator.addMethod('zipDel',function (value,form) {
            var shipaddr = $('select[name="solshipaddress"]')[0].value;
            if (shipaddr == 0)
                return true;
            if (shipaddr == 2)
            {
                var oxid = $('#deladr_oxaddress__oxcountryid')[0].value;
            } else {
                var oxid = $('select[name="deladr[oxaddress__oxcountryid]"]')[0].value;
            }
            if (value.length == 0)
            {
                $('#err_invadr_oxuser__oxzip').html(sFormDefaultError);
                return false;
            }
            if (solZipValidation(oxid,value))
                return true;
            // set error
            $('#err_'+form.id).attr('alt',aZipErrors[oxid]);
            return false;
        });
        jQuery.validator.addMethod('noDigits',function (value,form){
            var reg = /[0-9]+/;
            if (reg.test(value))
                return false;
            return true;
        });
        jQuery.validator.addMethod('notPackstation',function(value,form){
            var reg = /packst/i;
            if (reg.test(value))
            {
                $('#err_'+form.id).attr('alt',sFormPackstationError);
                return false;
            }
            return true;
        });
        $('form[name="order"]').validate({
            rules: {
                lgn_pwd2: {
                    equalTo: "#lgn_pwd"
                },
                "invadr[oxuser__oxzip]": {"zip":true,"notPackstation":true},
                "invadr[oxuser__oxcity]": {"noDigits":true,"notPackstation":true},
                "deladr[oxaddress__oxzip]": "zipDel",
                "deladr[oxaddress__oxcity]": "noDigits",
                "invadr[oxuser__oxfname]": "notPackstation",
                "invadr[oxuser__oxlname]": "notPackstation",
                "invadr[oxuser__oxcompany]": "notPackstation",
                "invadr[oxuser__oxstreet]": "notPackstation",
                "invadr[oxuser__oxstreetnr]": "notPackstation",
                "invadr[oxuser__oxaddinfo]": "notPackstation",
                "invadr[oxuser__oxfon]": "notPackstation",
                "invadr[oxuser__oxmobfon]": "notPackstation"
            },
            onkeyup: false,
            showErrors: function (errorMap, errorList) {
                for (var i = 0; errorList[i]; i++)
                {
                    var elem = $(errorList[i].element);
                    $(errorList[i].element).addClass('error');
                    $('label[for="'+errorList[i].element.id+'"]').addClass('error');
                    var errorElem = $('#err_'+errorList[i].element.id);
                    if (!errorElem.attr('alt'))
                        errorElem.attr('alt',errorElem.html())
                    if (elem.val() == "")
                        errorElem.html(sFormDefaultError);
                    else
                        errorElem.html(errorElem.attr('alt'));
                    errorElem.show();
                }
                for (var i = 0, elements = this.validElements(); elements[i]; i++)
                {
                    $(elements[i]).removeClass('error');
                    $('label[for="'+elements[i].id+'"]').removeClass('error');
                    $('#err_'+elements[i].id).hide();
                }
            }
        });
    });
}

function solInitReviewForceSubmit (scope)
{
    $('input[name="solForceShortReview"]').val('false');
    if (!scope)
        scope = document;
    var check = $('.solShortReviewError');
    if (!check.length)
        return;
    check.hide();
    $(':hidden',check).show();
    hs.htmlExpand(false,{
        maincontentText: '<div id="popup" class="popup">'+check.html()+'</div>',
        cacheAjax: false,
        forceAjaxReload: true
    });
    oxid.popup.resizeInterval();
}

function solReviewForceSubmit (obj)
{
    var obj = $('.solShortReviewError');
    var ratingContent = $(obj).parent('.ratingcontent');
    var form = $('form.ratingform',ratingContent);
    $('input[name="solForceShortReview"]',form).val('true');
    hs.close();
    form.submit();
}

var suggest = new FFSuggest();

function solInitFF ()
{
    var searchURL			= '/lib/FACTFinder/suggest.php';
    var formname			= 'search_word_inc';
    var queryParamName		= 'searchparam';
    var channelParamName	= 'channel';
    var channel				= 'de';
    var divLayername		= 'suggestLayer';
    var instanceName		= 'suggest';
    var debugMode			= false;
    var showImages          = true;
    suggest.init(searchURL, formname, queryParamName, divLayername, instanceName, debugMode, channelParamName, channel, showImages);
    document.onmousedown = suggest.hideLayerOutsideCall;
}

function solInitSlider ()
{
    /*
    var objs = $('.price_slider');
    if (objs.length < 1)
        return;
    */
    $('.price_slider').each(function(){
        var obj = $('input[type=slider]',this);
        var min = $('input.min',this);
        var max = $('input.max',this);
        //link.attr('orig',link.attr('href'));
        obj.slider({
            from: parseInt(obj.attr('min')),
            to: parseInt(obj.attr('max')),
            step: 1,
            round: 0,
            dimension: '&nbsp;'+$(this).attr('sign'),
            onstatechange: function (val) {
                var minmax = val.split(';');
                min.val(minmax[0]);
                max.val(minmax[1]);
                obj.parent('form').attr('action',obj.parent('form').attr('orig').replace(/minrepl/,minmax[0]).replace(/maxrepl/,minmax[1]));
                /*
                var href = link.attr('orig');
                link.attr('href',href.replace(/%min/,minmax[0]).replace(/%max/,minmax[1]));
                */
            }
        });
        min.change(function(){
            obj.slider('value',min.val(),max.val());
        });
        max.change(function(){
            obj.slider('value',min.val(),max.val());
        });
        obj.parent('form').submit(function(){
            document.location.href = $(this).attr('action');
            return false;
        });
    });
}

function solInitAsnGroupSwitch ()
{
    var objs = $('.filter div.more');
    objs.parent('div').each(function(){
        var obj = $(this);
        obj.attr('origHeight',obj.height()+24);
    });
    objs.parent('div').height('100px');
    objs.click(function(){
        var obj = $(this).parent('div');
        var that = this;
        if (obj.height() > 100)
        {
            obj.animate({height:'100px'},500,function(){
                $(that).removeClass('less').addClass('more');
            });
        } else {
            obj.animate({height:obj.attr('origHeight')+'px'},500,function(){
                $(that).removeClass('more').addClass('less');
            });
        }
    });
    $('.filter > p').click(function(){
        var obj = $(this).parent('div');
        obj.stop(true,true);
        if (obj.height() > 19)
        {
            obj.attr('height',obj.height());
            obj.animate({height:'19px'},500);
            $('div.more',obj).fadeOut();
            $('div.less',obj).fadeOut();
            $(this).addClass('closed');
            var collapsed = $.cookie('solFFAsnFilterCollapsed');
            if (collapsed && collapsed.length)
            {
                collapsed = collapsed.replace(new RegExp(obj.attr('id')+';'),'');
                collapsed += obj.attr('id')+';';
            } else {
                collapsed = ';'+obj.attr('id')+';';
            }
            $.cookie('solFFAsnFilterCollapsed',collapsed,{path:'/'});
        } else {
            obj.animate({height:obj.attr('height')+'px'},500);
            $('div.more',obj).fadeIn();
            $('div.less',obj).fadeIn();
            $(this).removeClass('closed');
            var collapsed = $.cookie('solFFAsnFilterCollapsed');
            if (collapsed && collapsed.length)
            {
                collapsed = collapsed.replace(new RegExp(obj.attr('id')+';'),'');
            }
            if (collapsed.length > 1)
                $.cookie('solFFAsnFilterCollapsed',collapsed,{path:'/'});
            else
                $.cookie('solFFAsnFilterCollapsed',null,{path:'/'});
        }
    });
    var collapsed = jQuery.cookie('solFFAsnFilterCollapsed');
    if (collapsed && collapsed.length)
    {
        var tmp = collapsed.split(';');
        var j = tmp.length;
        for (var i = 0; i < j; i++)
        {
            if (tmp[i].length == 0)
                continue;
            var obj = $('#'+tmp[i]);
            obj.attr('height',obj.height());
            obj.height('19px');
            $('p',obj).addClass('closed');
            $('div.more',obj).hide();
            $('div.less',obj).hide();
        }
    }
}

function solInitTeaserSlide ()
{
    var obj = $('.category-text');
    if (!obj)
        return;
    var height = obj.height();
    if (height < 150)
        return;
    height += 20;
    obj.attr('origHeight',height);
    obj.height('150px');
    obj.append('<div class="more"></div>');
    $('.more',obj).click(function(){
        var button = $(this);
        var height = obj.height();
        if (height > 150)
        {
            obj.animate({height:'150px'},500);
            button.addClass('more').removeClass('less');
        } else {
            obj.animate({height:obj.attr('origHeight')+'px'},500);
            button.addClass('less').removeClass('more');
        }
    });
}

function solInitFFSubmit ()
{
    $('form.searchNoSuggest').submit(function(){
        var tmp = $('#search',this).val();
        var tmpQuery = encodeURIComponent(tmp.replace(/[ \/]/g,'--'));
        var tmpQueryUri = encodeURIComponent(tmp);
        document.location.href = "/s/"+tmpQuery+'/?searchparam='+tmpQueryUri;
        return false;
    });
}

function solHideThankyouLayer ()
{
    $('#pleaseWait').hide();
    return;
}

function solInitCreditCardChange ()
{
    $('input[name="ACCOUNT.NUMBER"]').blur(function(){
        var iCCType = this.value[0];
        if (iCCType == 4)
        {
            $('select[name="ACCOUNT.BRAND"]').val('VISA');
        } else if (iCCType == 5) {
            $('select[name="ACCOUNT.BRAND"]').val('MASTERCARD');
        }
    });
}

/* highslider form submit */

function solHighSliderFormSubmitInit ()
{
    $('body').delegate('.highslide-body input.lightbox','click',function(e){
        e.preventDefault();
        var form = $(this).parents('form')[0];
        form = $(form);
        // now process the ajax request
        $.post(
            form.attr('action'),
            form.serialize(),
            function (data) {
                var resp = $(data);
                // update popup content
                $('.highslide-body',document).empty();
                resp.appendTo('.highslide-body',document);
                oxid.popup.resizeInterval();
            }
        );
        return false;
    });
}

function bfFreegiftVoucherInit(obj)
{
	$('.info form[name=voucher]').submit(function(e){
		var voucherNr = $('input[name=voucherNr]',this).val();
		if (voucherNr.match(/^VN-/i)) {
			e.preventDefault();
		    if (solIsShittyBrowser())
		        return true;
		    if (obj != undefined)
		        var form = $(obj);
		    else
		        var form = $('.info form[name=voucher]');
		    // create fake a-tag for highslider
		    var a = document.getElementById('solSubmitVoucherHack');
		    if (!a)
		    {
		        $(this).append('<a href="javascript:;" id="solSubmitVoucherHack"></a>');
		        a = document.getElementById('solSubmitVoucherHack');
		    }
		    if (obj != undefined && $('#wait').length)
		        $('#wait').html($('#wait').html().replace(/'.*'/,''));
		    // show highslider
		    hs.htmlExpand(a,{
		        maincontentId: 'voucherWait'
		    });
		    //oxid.popup.resizeInterval();
		    // now process the ajax request
		    $.post(
		        form.attr('action'),
		        form.serialize(),
		        function (data) {
		            var resp = $(data);
		            // update popup content
		            $('.highslide-body',document).empty();
		            if ($('#blFreeGiftPopup',resp).length >= 1) {
		            	$('#blFreeGiftPopup',resp).css('display','block');
                        $('body').append('<div id="solHighSlideContainer" style="visbility: hidden;"><div id="blFreeGiftPopup" style="display: block;">'+$('#blFreeGiftPopup',resp).html()+'</div></div>');
                        var height = $('#blFreeGiftPopup').height();
                        $('#blFreeGiftPopup').remove();
		            	resp.find('#blFreeGiftPopup').appendTo('.highslide-body',document);
                        hs.getExpander().resizeTo(750,height+50);
		        	}else{
		            	resp.find('.err ').append('<br>').appendTo('.highslide-body',document);
					}
		            //oxid.popup.resizeInterval();
		        }
		    );
		    return false;
		}
		return true;
	});

}

/* end highslider form submit */


/**
 * should stay at the bottom of this file
 */
 /*
jQuery('document').ready(function(){
*/
function solInitHandler()
{
    if (!solIsShittyBrowser())
    {
        solListToggleInit();
        solSlideInit();
        solRatingInit();
        solTabInit();
    }
    solHideThankyouLayer();
    // register function to be run on dom ready
    solFormValidation();
    solInitReviewForceSubmit();
    solInitFF();
    solInitSlider();
    solInitAsnGroupSwitch();
    solInitTeaserSlide();
    solInitFFSubmit();
    solInitCreditCardChange();
    solHighSliderFormSubmitInit();
    bfFreegiftVoucherInit();
    if (typeof(window['pid']) != "undefined" && pid.length)
        $('#solPartner').after(" ["+pid+"]");

}

// everything loaded, no call the inline scripts
solCallInlineScript();
solInitHandler();

