﻿var viewsCount = 7;
function ShowPrevPage() {
    ChangeActiveViewIndex(-1);
}
function ShowNextPage() {
    ChangeActiveViewIndex(1);
}
function ShowFirstPage() {
    ResetHiddenFields();
    cpCurveConfigurator.PerformCallback();
}
function ChangeActiveViewIndex(changeIndex) {
    hfDenirollCurve.Set("viewIndex", GetViewIndex() + changeIndex);
    cpCurveConfigurator.PerformCallback();
}
function GetViewIndex() {
    return hfDenirollCurve.Get("viewIndex");
}
function SetButtonState() {
    btnPrev.SetVisible(GetViewIndex() > 0 && !IsPreviewPage());
    btnNext.SetVisible(!IsLastPage());
    btnNext.SetEnabled(!IsPreviewPage() || (IsPreviewPage() && gridShoppingBasket.GetVisibleRowsOnPage() > 0));
    btnSubmit.SetVisible(IsLastPage());
    btnNewConfiguration.SetVisible(IsPreviewPage());
}
function IsLastPage() {
    return GetViewIndex() == (viewsCount - 1);
}
function IsPreviewPage() {
    return GetViewIndex() == (viewsCount - 2);
}
function OnBandStyleChanged(s, e) {
    hfDenirollCurve.Set("modulebandstyle", s.GetValue());
}
function OnBandTypeChanged(s, e) {
    hfDenirollCurve.Set("modulebandtype", s.GetValue());
}
function OnRadiusChanged(s, e) {
    hfDenirollCurve.Set("radius", Number(s.GetValue()));
}
function OnAngleChanged(s, e) {
    hfDenirollCurve.Set("angle", Number(s.GetValue()));
}
function OnTypeChanged(s, e) {
    hfDenirollCurve.Set("type", s.GetSelectedItem().value);
}
function OnTemperatureChanged(s, e) {
    hfDenirollCurve.Set("temperature", Number(s.GetValue()));
}
function OnConditionChanged(s, e) {
    hfDenirollCurve.Set("condition", s.GetValue());
}
function OnAggressiveChanged(s, e) {
    hfDenirollCurve.Set("aggressive", s.GetSelectedItem().value);
}
function OnMediumsChanged(s, e) {
    hfDenirollCurve.Set("mediums", s.GetValue());
}

function OnAmountChanged(s, e) {
    var prefix = '_cell';
    var suffix = '_1_tbAmount';
    var visibleIndex = s.name.substring(s.name.indexOf(prefix) + prefix.length, s.name.indexOf(suffix));
    gridShoppingBasket.PerformCallback(visibleIndex + '|' + s.GetValue());
}

//----- Kontakt Infos-------------------------------------

function OnCompanyChanged(s, e) {
    hfContact.Set("company", s.GetValue());
}
function OnFunctionChanged(s, e) {
    hfContact.Set("function", s.GetValue());
}
function OnLastnameChanged(s, e) {
    hfContact.Set("lastname", s.GetValue());
}
function OnFirstnameChanged(s, e) {
    hfContact.Set("firstname", s.GetValue());
}
function OnStreetChanged(s, e) {
    hfContact.Set("street", s.GetValue());
}
function OnZipChanged(s, e) {
    hfContact.Set("zip", s.GetValue());
}
function OnCityChanged(s, e) {
    hfContact.Set("city", s.GetValue());
}
function OnCountryChanged(s, e) {
    hfContact.Set("country", s.GetValue());
}
function OnEmailChanged(s, e) {
    hfContact.Set("email", s.GetValue());
}
function OnPhoneChanged(s, e) {
    hfContact.Set("phone", s.GetValue());
}
function OnFaxChanged(s, e) {
    hfContact.Set("fax", s.GetValue());
}
function OnMessageChanged(s, e) {
    hfContact.Set("message", s.GetValue());
}

//------------------------------------------------------

function ResetHiddenFields() {
    hfDenirollCurve.Set("viewIndex", 0);
    hfDenirollCurve.Set("oid", generateGuid());
    hfDenirollCurve.Set("modulebandstyle", "");
    hfDenirollCurve.Set("modulebandtype", "");
    hfDenirollCurve.Set("radius", 1);
    hfDenirollCurve.Set("angle", 0);
    hfDenirollCurve.Set("type", "VB");
    hfDenirollCurve.Set("temperature", 0);
    hfDenirollCurve.Set("condition", "");
    hfDenirollCurve.Set("aggressive", "No");
    hfDenirollCurve.Set("mediums", "");
}

function generateGuid() {
    var result, i, j;
    result = '';
    for (j = 0; j < 32; j++) {
        if (j == 8 || j == 12 || j == 16 || j == 20)
            result = result + '-';
        i = Math.floor(Math.random() * 16).toString(16).toUpperCase();
        result = result + i;
    }
    return result
} 
