/// <reference name="logicbase.Web.json.js" assembly="logicbase.Web" />

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");
 }

//Frage stellen
function askQuestion(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");
 }

//Preis vorschlagen
 function suggestPrice(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';
}

var _formAction;
var _nextButton;
var _prevButton;

function CallSuccessIPayment(res, destCtrl) {

    if (document.getElementById(cbAcceptCtrl).checked == true) {
        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;
    }
    else {
        __doPostBack(btnNextUniqueID, '');
    }
}

function submitIPaymentForm(formAction, nextButton, prevButton) {

    _formAction = formAction;
    _nextButton = nextButton;
    _prevButton = prevButton;

    //Erweiterung Kreditkartendaten merken BEGIN
    var CreditCard = document.getElementById('cc_typ').value;
    var CCNumber = document.getElementById('cc_number').value;
    var CCOwner = document.getElementById('addr_name').value;
    var CCValidToMonth = document.getElementById('cc_expdate_month').value;
    var CCValidToYear = document.getElementById('cc_expdate_year').value;
    var SecurityPin = document.getElementById('cc_checkcode').value;

    logicbase.Shop.LBShopWebService.SetCC(CreditCard, CCNumber, CCOwner, CCValidToMonth, CCValidToYear, SecurityPin, document.getElementById(cbAcceptCtrl).checked, CallSuccessIPayment, CallFailed);
    CreditCard = null;
    CCNumber = null;
    CCOwner = null;
    CCValidToMonth = null;
    CCValidToYear = null;
    SecurityPin = null;
    //Erweiterung Kreditkartendaten merken END
    
    return false;
}
// Umstellung IPayment auf CGI END

// Verfügbarkeitsdarstellung
function ShowAvailability(Ereignis) {

    xPosition = Ereignis.clientX -400;
    yPosition = Ereignis.clientY -480;

    //Scrollposition berücksichtigen
    var docEl = (
             typeof document.compatMode != "undefined" &&
             document.compatMode != "BackCompat"
            ) ? "documentElement" : "body";

    xPosition += document[docEl].scrollLeft;
    yPosition += document[docEl].scrollTop;

    document.getElementById("divAvailability").style.left = xPosition + "px";
    document.getElementById("divAvailability").style.top = yPosition + "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')); } }
            }
        }
    }
};

/*******************************/
/* Ereiterung FactFinder BEGIN */
/*******************************/
function showAccessory(accName, accName2, accName3, showName, hideName) {
    document.getElementById(accName).style.display = 'block';
    document.getElementById(accName2).style.display = 'block';
    document.getElementById(accName3).style.display = 'block';
    document.getElementById(showName).style.display = 'none';
    document.getElementById(hideName).style.display = 'block';
}

function hideAccessory(accName, accName2, accName3, showName, hideName) {
    document.getElementById(accName).style.display = 'none';
    document.getElementById(accName2).style.display = 'none';
    document.getElementById(accName3).style.display = 'none';
    document.getElementById(showName).style.display = 'block';
    document.getElementById(hideName).style.display = 'none';
}
/*******************************/
/* Ereiterung FactFinder END */
/*******************************/

/* ändert die Sichtbarkeit */
function SwitchVisibility(id)
{
    document.getElementById(id).style.display == 'none' ? document.getElementById(id).style.display = 'block' : document.getElementById(id).style.display = 'none';
}

/* ändert die Sichtbarkeit */
function SwitchAccessoryVisibility(DivId, img, shoppingCartPositionId)
{
    var element = document.getElementById(DivId);
    if (element.style.display == 'none')
    {
        element.style.display = 'block';
        element.innerHTML = "<img id='imgAccessoryWait' />";
        document.getElementById('imgAccessoryWait').src = img;
        GetAccessoryItems(shoppingCartPositionId, DivId);
    }
    else
    {
        element.style.display = 'none';
    }
}

function SwitchGuestAccountVisibility(isGuestAccount) {

    if (isGuestAccount == 'true') {
        document.getElementById('divPass1').style.display = 'none';
        document.getElementById('divPass2').style.display = 'none';
        document.getElementById('tbPassword').groupName = '';
        document.getElementById('tbPassword2').groupName = '';
        document.getElementById('tbPassword').InputOptional = 'true';
        document.getElementById('tbPassword2').InputOptional = 'true';
        document.getElementById('tbPassword').className = document.getElementById('tbPassword').cssErrorOff;
        document.getElementById('tbPassword2').className = document.getElementById('tbPassword2').cssErrorOff;
        removeMessage('tbPassword');
        removeMessage('tbPassword2');
    }
    else {
        document.getElementById('divPass1').style.display = 'block';
        document.getElementById('divPass2').style.display = 'block';
        document.getElementById('tbPassword').groupName = 'CreateAccount';
        document.getElementById('tbPassword2').groupName = 'CreateAccount';
        document.getElementById('tbPassword').InputOptional = 'false';
        document.getElementById('tbPassword2').InputOptional = 'false';
    }

}

function ItemsListPaging(url, pages, itemsPerPage, orderBy) { 
//    var FIT = document.getElementById(DDLpages).value;
//    var IPP = document.getElementById(ddlItemsPerPage).value;
//    var ORD = document.getElementById(ddlOrderBy).value;
    location.href = url + '&FIT=' + pages + '&IPP=' + itemsPerPage + '&ORD=' + orderBy;
}


/* Erweiterung Zubehoergruppen */
function blendDIV(controlID) {
    if (document.getElementById(controlID).style.display == 'none') {
        document.getElementById(controlID).style.display = 'inline';
    }
    else {
        document.getElementById(controlID).style.display = 'none';
    }
}

/* Prüfen ob Cookies aktiviert sind: falls nicht entsprechende Warnmeldung in Warenkorb und Mein Konto - Seiten */
function checkCookie() {
    var cookieEnabled = (navigator.cookieEnabled) ? true : false;

    //if navigator,cookieEnabled is not supported
    if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
        document.cookie = "checkCookie";
        cookieEnabled = (document.cookie.indexOf("checkCookie") != -1) ? true : false;
    }

    if (cookieEnabled)
        document.getElementById("divSystemMessage").style.display = 'none';
    else
        document.getElementById("divSystemMessage").style.display = 'block';

}

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 = 'inline-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 = 'inline-block';
            }
            else {
                document.getElementById('divFaq_' + FaqIdList.QuestionIds[i]).style.display = 'none';
            }
        }
    }
}

/// <summary locid="Leitet zu einer Seite weiter" />
function redirect(pathToSite) {
    location.href = pathToSite;
}

/// <summary locid="wird nach dem erfolgreichen erstellen eines Kunden-Accounts aufgerufen" />
function createAccountSuccess(res, ctrl) {

    var ret = res.split("|")[0];
    var redirectUrl = res.split("|")[1];
    if (ret == "1") {
        if (document.getElementById(document.getElementById('inpFileUploadId').value).value != "") {
            __doPostBack(document.getElementById('inpFileUploadId').value, document.getElementById('tbUstId').value + "|" + document.getElementById('tbTax').value + "|" + document.getElementById('tbMessage').value + "|" + redirectUrl);
        }
        else {
            redirect(redirectUrl);
        }
    }
    else {
        document.body.style.cursor = '';
        displayMessages();
    }

}


/// <summary locid="erstellt einen Kunden-Account" />
function createCustomer() {
    document.body.style.cursor = 'wait';
    var customer = new Object();
    customer.email = document.getElementById('tbEMail').value;
    customer.firstname = '';
    customer.name = document.getElementById('tbname').value;
    customer.username = document.getElementById('tbEMail').value;
    customer.password = document.getElementById('tbPassword').value;
    customer.additionalName = '';
    customer.street = document.getElementById('tbStreet').value;
    customer.housenumber = '';
    customer.zipCode = document.getElementById('tbZipCode').value;
    customer.city = document.getElementById('tbCity').value;
    customer.state = '';
    customer.phone = document.getElementById('tbPhone').value;
    customer.mobile = '';
    customer.company = document.getElementById('tbCompany').value;
    customer.customerType = document.getElementById('inpCustomerType').value;
    customer.newsletterAccepted = document.getElementById('cbNewsletter').checked;
    customer.title = '';
    customer.country = document.getElementById('ddlCountries').value;
    customer.file = document.getElementById(document.getElementById('inpFileUploadId').value).value;
    customer.ustId = document.getElementById('tbUstId').value;
    customer.tax = document.getElementById('tbTax').value;
    customer.comment = document.getElementById('tbMessage').value;

    webServiceProxy.CreateCustomer(customer, createAccountSuccess, CallFailed);

}

/// <summary locid="wird nach dem Login-Versuch des Kunden aufgerufen" />
function redirectSuccess(res, ctrl) {

    var ret = res.split("|")[0];
    var redirectUrl = res.split("|")[1];
    if (ret == "1") {
        redirect(redirectUrl);
    }
    else {
        document.body.style.cursor = '';
        displayMessages();
    }

}

/// <summary locid="logt den Kunden ein, bzw. leitet ihn auf die Konto erstellen seite" />
function customerLogin() {
    document.body.style.cursor = 'wait';
    webServiceProxy.CustomerLogin(document.getElementById('rbNew').checked, document.getElementById('tbCCEMail').value, document.getElementById('tbCCPassword').value,1, redirectSuccess, CallFailed);
}

/// <summary locid="speichert eine neue oder vorhandene Adresse" />
function saveAddress() {
    document.body.style.cursor = 'wait';

    var address = new Object();
    address.id = document.getElementById('hfId').value;
    address.name = document.getElementById('tbname').value;
    address.company = document.getElementById('tbCompany').value;
    address.street = document.getElementById('tbStreet').value;
    address.country = document.getElementById('ddlCountries').value;
    address.zipCode = document.getElementById('tbZipCode').value;
    address.city = document.getElementById('tbCity').value;
    address.isShippingAddress = document.getElementById("cbIsShippingAddress").checked;
    address.isBillingAddress = document.getElementById("cbIsBillingAddress").checked;
    address.isPrimaryAddress = document.getElementById("cbIsPrimaryAddress").checked;
    
    webServiceProxy.saveAddress(address, redirectSuccess, CallFailed);

}

function changePassword() {
    document.body.style.cursor = 'wait';
    webServiceProxy.ChangePassword(document.getElementById('tbPasswordOld').value, document.getElementById('tbPassword').value, messageSuccess, CallFailed);
}

function messageSuccess(res, ctrl) {
    document.body.style.cursor = '';
    displayMessages();
}

function holdCreateAccountData(customerType) {

    var customer = new Object();
    customer.email = document.getElementById('tbEMail').value;
    customer.email2 = document.getElementById('tbEMail2').value;
    customer.name = document.getElementById('tbname').value;
    customer.street = document.getElementById('tbStreet').value;
    customer.zipCode = document.getElementById('tbZipCode').value;
    customer.city = document.getElementById('tbCity').value;
    customer.phone = document.getElementById('tbPhone').value;
    customer.company = document.getElementById('tbCompany').value;
    customer.accepted = document.getElementById('cbAccept').checked;
    customer.newsletterAccepted = document.getElementById('cbNewsletter').checked;
    customer.country = document.getElementById('ddlCountries').value;
    customer.customerType = customerType;

    webServiceProxy.holdCreateAccountData(customer, redirectSuccess, CallFailed);
}