function changeOperator() {
    var operator = document.getElementById('operator').value;
    document.getElementById('oper').value = operator.substring(7);
    
    if (document.getElementById('operator').value == 'prepaidorange') {
        document.getElementById('amountInput').style.display='none';
        document.getElementById('amountSelect').style.display='block';
        document.getElementById('gaduAmountSelect').style.display='none';
    }else if (document.getElementById('operator').value == 'prepaidgadu') {
        document.getElementById('amountInput').style.display='none';
        document.getElementById('amountSelect').style.display='none';
        document.getElementById('gaduAmountSelect').style.display='block';
    }
    else {
        document.getElementById('amountInput').style.display='block';
        document.getElementById('amountSelect').style.display='none';
        document.getElementById('gaduAmountSelect').style.display='none';
    }
    
    changeOffer(operator);
}

function changeOfferText(id) {
    var offer = document.getElementById('offer');
    var offer_text = document.getElementById(id);
    
    if (offer_text != null) {
        offer.innerHTML = offer_text.innerHTML;
        offer.style.borderTopStyle = 'solid';
    } else {
        offer.innerHTML = '';
        offer.style.borderTopStyle = 'none';
    }
}

function changeOffer(operator) {
    var offer = document.getElementById('offer');
    
    if (operator == 'prepaidorange') {
        changeOfferText('orange');
    } else if (operator == 'prepaidsimplus') {
        changeOfferText('simplus');
    } else if (operator == 'prepaidmixplus') {
        changeOfferText('mixplus');
    } else if (operator == 'prepaidsamiswoi') {
        changeOfferText('samiswoi');
    } else if (operator == 'prepaidplus366') {
        changeOfferText('36_6');
    } else if (operator == 'prepaidplay') {
        changeOfferText('play');
    } else if (operator == 'prepaidtaktak') {
        changeOfferText('taktak');
    } else if (operator == 'prepaidheyah') {
        changeOfferText('heyah');        
    } else if (operator == 'dialog') {
        changeOfferText('dialog');
    } else {
            offer.innerHTML = '';
            offer.style.borderTopStyle = 'none';        
    }
}

function fillAmount() {
    if (document.getElementById('operator').value == 'prepaidorange') {
        document.getElementById('amount').value = document.getElementById('amountSelect').value;
    } else if (document.getElementById('operator').value == 'prepaidgadu') {
        document.getElementById('amount').value = document.getElementById('gaduAmountSelect').value;
    } else {
        document.getElementById('amount').value = document.getElementById('amountInput').value;
    }
}

function updateProlongation(amount) {
    var operator = document.getElementById('operator').value;
    var outcomingAmount = '0 dni';
    var incomingAmount = '0 dni';
    
    if (operator == 'prepaidorange') {
        if (amount == 5) {
            outcomingAmount = '2 dni';
            incomingAmount = '7 dni';
        } else if (amount == 10) {
            outcomingAmount = '5 dni';
            incomingAmount = '10 dni';
        }else if (amount == 25) {
            outcomingAmount = '30 dni';
            incomingAmount = '180 dni';
        } else if (amount == 40) {
        	outcomingAmount = '40 dni';
            incomingAmount = '360 dni';        
        } else if (amount == 50) {
            outcomingAmount = '90 dni';
            incomingAmount = '360 dni';
        } else if (amount == 100) {
            outcomingAmount = '150 dni';
            incomingAmount = '360 dni';
        } else if (amount == 200) {
            outcomingAmount = '300 dni';
            incomingAmount = '360 dni';
        }
        
    } else if (operator == 'prepaidsimplus') {
        if (amount >= 5 && amount <= 9) {
            outcomingAmount = '2 dni';
            incomingAmount = '32 dni';
        } else if (amount >= 10 && amount <= 29) {
            outcomingAmount = '7 dni';
            incomingAmount = '37 dni';
        } else if (amount >= 30 && amount <= 49) {
            outcomingAmount = '30 dni';
            incomingAmount = '60 dni';
        } else if (amount >= 50 && amount <= 99) {
            outcomingAmount = '90 dni';
            incomingAmount = '120 dni';
        } else if (amount >= 100 && amount <= 150) {
            outcomingAmount = '180 dni';
            incomingAmount = '210 dni';
        }
    } else if (operator == 'dialog') {
        if (amount >= 5 && amount <= 10) {
            outcomingAmount = '7 dni';
            incomingAmount = '37 dni';
        } else if (amount >= 11 && amount <= 25) {
            outcomingAmount = '30 dni';
            incomingAmount = '60 dni';
        } else if (amount >= 26 && amount <= 50) {
            outcomingAmount = '90 dni';
            incomingAmount = '120 dni';
        } else if (amount >= 51 && amount <= 100) {
            outcomingAmount = '180 dni';
            incomingAmount = '210 dni';
        } else if (amount >= 101 && amount <= 180) {
            outcomingAmount = '210 dni';
            incomingAmount = '240 dni';
        } else if (amount >= 181 && amount <= 300) {
            outcomingAmount = '360 dni';
            incomingAmount = '390 dni';
        }
    } else if (operator == 'prepaidmixplus') {
        if (amount >= 5 && amount <= 9) {
            outcomingAmount = '2 dni';
            incomingAmount = '32 dni';
        } else if (amount >= 10 && amount <= 29) {
            outcomingAmount = '7 dni';
            incomingAmount = 'dodatkowe 30 dni';
        } else if (amount >= 30 && amount <= 49) {
            outcomingAmount = '30 dni';
            incomingAmount = 'dodatkowe 30 dni';
        } else if (amount >= 50 && amount <= 99) {
            outcomingAmount = '90 dni';
            incomingAmount = 'dodatkowe 30 dni';
        } else if (amount >= 100 && amount <= 150) {
            outcomingAmount = '180 dni';
            incomingAmount = 'dodatkowe 30 dni';
        }
    } else if (operator == 'prepaidsamiswoi') {
        if (amount >= 10 && amount <= 19) {
            outcomingAmount = '7 dni';
            incomingAmount = '14 dni';
        } else if (amount >= 20 && amount <= 39) {
            outcomingAmount = '30 dni';
            incomingAmount = '60 dni';
        } else if (amount >= 40 && amount <= 79) {
            outcomingAmount = '90 dni';
            incomingAmount = '120 dni';
        } else if (amount >= 80 && amount <= 159) {
            outcomingAmount = '210 dni';
            incomingAmount = '240 dni';
        } else if (amount == 160) {
            outcomingAmount = '240 dni';
            incomingAmount = '270 dni';
        }
    } else if (operator == 'prepaidplus366') {
        if (amount >= 5 && amount <= 9) {
            outcomingAmount = '2 dni';
            incomingAmount = '32 dni';
        } else if (amount >= 10 && amount <= 29) {
            outcomingAmount = '7 dni';
            incomingAmount = '37 dni';
        } else if (amount >= 30 && amount <= 49) {
            outcomingAmount = '30 dni';
            incomingAmount = '60 dni';
        } else if (amount >= 50 && amount <= 99) {
            outcomingAmount = '90 dni';
            incomingAmount = '120 dni';
        } else if (amount >= 100 && amount <= 150) {
            outcomingAmount = '180 dni';
            incomingAmount = '210 dni';
        }
    } else if (operator == 'prepaidplay') {
        if (amount >= 10 && amount <= 24) {
            outcomingAmount = '10 dni';
            incomingAmount = '100 dni';
        } else if (amount >= 25 && amount <= 49) {
            outcomingAmount = '30 dni';
            incomingAmount = '120 dni';
        } else if (amount >= 50 && amount <= 99) {
            outcomingAmount = '90 dni';
            incomingAmount = '180 dni';
        } else if (amount >= 100 && amount <= 300) {
            outcomingAmount = '180 dni';
            incomingAmount = '270 dni';
        }
    } else if (operator == 'prepaidtaktak') {
        if (amount >= 25 && amount <= 49) {
            outcomingAmount = '30 dni';
            incomingAmount = '60 dni';
        } else if (amount >= 50 && amount <= 99) {
            outcomingAmount = '90 dni';
            incomingAmount = '120 dni';
        } else if (amount >= 100 && amount <= 149) {
            outcomingAmount = '120 dni';
            incomingAmount = '150 dni';
        } else if (amount >= 150 && amount <= 500) {
            outcomingAmount = '180 dni';
            incomingAmount = '210 dni';
        }
    } else if (operator == 'prepaidheyah') {
        if (amount >= 20 && amount <= 49) {
            outcomingAmount = '30 dni';
            incomingAmount = '30 dni';
        } else if (amount >= 50 && amount <= 500) {
            outcomingAmount = '90 dni';
            incomingAmount = '90 dni';
        }
    } else if (operator == 'prepaidgadu') {
        if (amount == 10 || amount == 20) {
            outcomingAmount = '90 dni';
            incomingAmount = '120 dni';
        } else if (amount == 50 || amount == 100) {
            outcomingAmount = '180 dni';
            incomingAmount = '210 dni';
        }
    } else if (operator == 'prepaidpolsat') {
        if (amount >= 5 && amount <= 25) {
            outcomingAmount = '14 dni';
            incomingAmount = '90 dni do dnia ostatniej odebranej rozmowy/wiadomości SMS/MMS lub dnia upłynięcia ważność środków na koncie';
        } else if (amount >= 26 && amount <= 50) {
            outcomingAmount = '30 dni';
            incomingAmount = '90 dni do dnia ostatniej odebranej rozmowy/wiadomości SMS/MMS lub dnia upłynięcia ważność środków na koncie';
        } else if (amount >= 51 && amount <= 100) {
            outcomingAmount = '90 dni';
            incomingAmount = '90 dni do dnia ostatniej odebranej rozmowy/wiadomości SMS/MMS lub dnia upłynięcia ważność środków na koncie';
        } else if (amount >= 101) {
            outcomingAmount = '180 dni';
            incomingAmount = '90 dni do dnia ostatniej odebranej rozmowy/wiadomości SMS/MMS lub dnia upłynięcia ważność środków na koncie';
        }
    }
    
    document.getElementById('outcoming').innerHTML = outcomingAmount;
    document.getElementById('incoming').innerHTML = incomingAmount;
}

