//******************************************
// WICHTIG: die noimage Bilder müssen immer vorhanden sein !!!
//******************************************
var noImageImgSmall;
var noImageImgBig;

function handleErrorIMG(controlId, size) {

    switch (size) {
        //case 'small': controlId.src = noImageImgSmall; break;
        //case 'big': controlId.src = noImageImgBig; break;
        default: controlId.style.display = 'none';
    }
    
}
//******************************************

// Menü für Kategorien und Marken
function toggleKatandBrands(index, prae) {
    var imgkategorien = document.getElementById(prae + '_imgkategorien');
    var imgmarken = document.getElementById(prae + '_imgmarken');

    if (index == 1) {
        imgkategorien.src = imgkategorien.src.replace('kategorien_2.gif', 'kategorien.gif');
        imgmarken.src = imgmarken.src.replace('marken_2.gif', 'marken.gif');
        document.getElementById("content1").style.display = "block";
        document.getElementById("content2").style.display = "none";
        logicbase.Shop.LBShopWebService.SetBrandsActive(false);
    }
    else {
        imgkategorien.src = imgkategorien.src.replace('kategorien.gif', 'kategorien_2.gif');
        imgmarken.src = imgmarken.src.replace('marken.gif', 'marken_2.gif');
        document.getElementById("content1").style.display = "none";
        document.getElementById("content2").style.display = "block";
        logicbase.Shop.LBShopWebService.SetBrandsActive(true);
    }
    document.getElementById(prae + '_hfSelected').value = index;
}

function toggleMenuOnWebservice(index) {
 
    if (index == 1) {
        logicbase.Shop.LBShopWebService.SetBrandsActive(false);
    }
    else {
        logicbase.Shop.LBShopWebService.SetBrandsActive(true);
    }
}

//function content1() {
//    if (document.getElementById)
//        document.getElementById("content1").style.display = "block";
//        document.getElementById("content2").style.display = "none";
//}
//function content2() {
//    if (document.getElementById)
//        document.getElementById("content1").style.display = "none";
//        document.getElementById("content2").style.display = "block";
//}
//-------------------------------------------------------------------------------//

// Reitermenü für Detailseite
function toggleReiterDetail(index) {

    logicbase.Shop.LBShopWebService.SetTabIndex(index);
    
    if (document.getElementById) {
        for (var i = 1; i <= 3; i++) {
            if (i == index) {
                document.getElementById("detailcontent" + i).style.display = "block";
                document.getElementById("detailreiter" + i).className = 'detail_reiter_active';
            }
            else {
                document.getElementById("detailcontent" + i).style.display = "none";
                document.getElementById("detailreiter" + i).className = 'detail_reiter';
            }
        }
        if (index == 3) {
            document.getElementById("divInfoReiter").style.display = "none";
        }
        else {
            document.getElementById("divInfoReiter").style.display = "inline";
        }
    }
}


//function detailcontent1() {
//    if (document.getElementById)
//        document.getElementById("detailcontent1").style.display = "block";
//        document.getElementById("detailcontent2").style.display = "none";
//        document.getElementById("detailcontent3").style.display = "none";
//        document.getElementById("detailcontent4").style.display = "none";
//}

//function detailcontent2() {
//    if (document.getElementById)
//        document.getElementById("detailcontent1").style.display = "none";
//        document.getElementById("detailcontent2").style.display = "block";
//        document.getElementById("detailcontent3").style.display = "none";
//        document.getElementById("detailcontent4").style.display = "none";
//}

//function detailcontent3() {
//    if (document.getElementById)
//        document.getElementById("detailcontent1").style.display = "none";
//        document.getElementById("detailcontent2").style.display = "none";
//        document.getElementById("detailcontent3").style.display = "block";
//        document.getElementById("detailcontent4").style.display = "none";
//}

//function detailcontent4() {
//    if (document.getElementById)
//        document.getElementById("detailcontent1").style.display = "none";
//        document.getElementById("detailcontent2").style.display = "none";
//        document.getElementById("detailcontent3").style.display = "none";
//        document.getElementById("detailcontent4").style.display = "block";
//}

//-------------------------------------------------------------------------------//

function noPostBack(sNewFormAction)
{
    document.forms[0].action = sNewFormAction;
    document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
    document.forms[0].target = '_blank';
    setTimeout('resetPostBack()', 0);
}

// Bug-Fix um nach Absenden des Trusted-Shop-Money-Back Formulars noch Postback-Buttons nutzen zu können
function resetPostBack() {
    document.forms[0].action = "Default.aspx";
    document.forms[0].__VIEWSTATE.name = '__VIEWSTATE';
    document.forms[0].target = '';
}
  
// Artikel weiterempfehlen    
function empfehlen(ausg) {
     dis = window.open(ausg,"my2","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=420,height=500,top=150,left=250");
}

function printWindow() {
Browser = parseInt(navigator.appVersion);
if (Browser >= 4) window.print();
}

// Mouse-Over für Detailansicht
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

// ändert den Wert des VariantenDropDowns
function changeDropDownValue(dropDownId,indexToSelect){
    document.getElementById(dropDownId).selectedIndex = indexToSelect;
}

// Umstellung IPayment auf CGI BEGIN
function showInfo(divName,e)
{
  document.getElementById(divName).style.display='block';
}

function hideInfo(divName)
{
    document.getElementById(divName).style.display='none';
}

function submitIPaymentForm(formAction, nextButton, prevButton)
{
    var sImage = document.getElementById("imgWait").src;
    document.getElementById(nextButton).disabled = true;
    document.getElementById(prevButton).disabled = true;
    document.getElementById("divIPaymentWait").style.display='block';
    document.forms[0].action = formAction;
    document.forms[0].__VIEWSTATE.value = '';
    document.forms[0].__EVENTVALIDATION.value = '';
    document.forms[0].method = 'POST';   
    document.forms[0].submit();  
    document.getElementById("imgWait").src = sImage;
    return false;
}
// Umstellung IPayment auf CGI END

// Verfügbarkeitsdarstellung
function ShowAvailability(e) {
    var posx = 0, posy = 0;
    if (e == null) e = window.event;
    if (e.pageX || e.pageY) {
        posx = e.pageX; posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        if (document.documentElement.scrollTop) {
            posx = e.clientX + document.documentElement.scrollLeft;
            posy = e.clientY + document.documentElement.scrollTop;
        }
        else {
            posx = e.clientX + document.body.scrollLeft;
            posy = e.clientY + document.body.scrollTop;
        }
    }
    document.getElementById("divAvailability").style.top = (posy - 230) + "px";
    document.getElementById("divAvailability").style.left = (posx - 470) + "px";
    document.getElementById("divAvailability").style.display = 'block';
}

function HideAvailability() {
    document.getElementById("divAvailability").style.display = 'none';
}

// firefox update-defaul-button fix
function addClickFunction(id) {

    {
        var b = document.getElementById(id);
        if (b && typeof (b.click) == 'undefined') b.click = function() {

            {
                var result = true; if (b.onclick) result = b.onclick();
                if (typeof (result) == 'undefined' || result) { { eval(b.getAttribute('href')); } }
            }
        }
    }
};


//ImageGallery

var _galleryStep = 1;
var _galleryIndex = 0;
var _scroll = null;
var _way = null;
var _speed = 300; //Millisekunden

function loadGallery() {

    for (var i = 1; i <= 4; i++) {
        if (JSONGalleryObject[_galleryIndex + i - 1] != null) {
            document.images['GalleryImage' + i].style.visibility = 'visible';
            document.images['GalleryImage' + i].src = JSONGalleryObject[_galleryIndex + i - 1].GalleryImage;
            document.images['GalleryImage' + i].title = JSONGalleryObject[_galleryIndex + i - 1].Title;
            document.images['GalleryImage' + i].onclick = new Function("location.href = '" + JSONGalleryObject[_galleryIndex + i - 1].URL + "';");
        }
        else {
            document.images['GalleryImage' + i].style.visibility = 'hidden';
        }
    }
}

function startScroll(way) {
    if (JSONGalleryObject.length > 4) {
        _scroll = true;
        _way = way;
        doScroll();
    }
}

function doScroll() {
    if (_scroll) {
        if (_way > 0) {
            _galleryIndex = _galleryIndex + _galleryStep;
        }
        else {
            _galleryIndex = _galleryIndex - _galleryStep;
        }

        if (_galleryIndex <= 0) {
            _galleryIndex = 0;
            document.images['imgDOWN'].style.visibility = 'hidden';
        }
        else {
            document.images['imgDOWN'].style.visibility = 'visible';
        }

        if (_galleryIndex + 4 > JSONGalleryObject.length - 1) {
            _galleryIndex = JSONGalleryObject.length - 5;
            document.images['imgUP'].style.visibility = 'hidden';
        }
        else {
            document.images['imgUP'].style.visibility = 'visible';
        }

        loadGallery();
        window.setTimeout('doScroll()', _speed);
    }
}

function stopScroll() {
    _scroll = false;
    _way = null;
}

var FaqIdList;  //wird in Faq.ascx.vb mit Inhalt gefüllt

function swapCategory(categoryId) {

    for (var i = 0; i < FaqIdList.CategoryIds.length; i++) {
        if (document.getElementById('divFaqCategory_' + FaqIdList.CategoryIds[i]) != null) {
            if (categoryId == FaqIdList.CategoryIds[i]) {
                document.getElementById('divFaqCategory_' + FaqIdList.CategoryIds[i]).style.display = 'block';
            }
            else {
                document.getElementById('divFaqCategory_' + FaqIdList.CategoryIds[i]).style.display = 'none';
            }
        }
    }
}

function swapQuestion(faqId) {

    for (var i = 0; i < FaqIdList.QuestionIds.length; i++) {
        if (document.getElementById('divFaq_' + FaqIdList.QuestionIds[i]) != null) {
            if (faqId == FaqIdList.QuestionIds[i]) {
                document.getElementById('divFaq_' + FaqIdList.QuestionIds[i]).style.display = 'block';
            }
            else {
                document.getElementById('divFaq_' + FaqIdList.QuestionIds[i]).style.display = 'none';
            }
        }
    }
}

function swapVisibility(divId) {

    if (document.getElementById(divId).style.display == 'block') document.getElementById(divId).style.display = 'none';
    else document.getElementById(divId).style.display = 'block';
}

function ItemsListPaging(url, FirstItem, ddlItemsPerPage, OrderBy) {
    var IPP = document.getElementById(ddlItemsPerPage).value;
    location.href = url + '&FIT=' + FirstItem + '&IPP=' + IPP + '&ORD=' + OrderBy;
}

function toogleProducerDiv(letter) {

    if (document.getElementById('div_' + document.getElementById('lblSelectedLetter').value) != null) {
        document.getElementById('div_' + document.getElementById('lblSelectedLetter').value).style.display = 'none';
    };

    document.getElementById('lblSelectedLetter').value = letter;
    document.getElementById('div_' + letter).style.display = 'inline';
}
