function jakaSiec(numer){

    /* jesli jest za krotki numer, to olewamy */
    if(numer.length<3) return '???';

    if(numer.substring(0,3) == '+48'){
        numer=numer.substring(3,12);
    }
    if(numer.substring(0,1) == '+'){
        return 'swiat';
        numer=numer.substring(1,15);
    }
    if(numer.substring(0,2) == '48'){
        numer=numer.substring(2,11);
    }

    var opcode = numer.substring(0,3);

    if ((opcode >= 500 && opcode < 600) || opcode==798)
    {
        return 'idea';
    }
    if ((opcode==784) || (opcode == 600) || ((opcode >= 600 && opcode < 700) && !(opcode % 2)))
    {
        return 'era';
    }
    if ((opcode > 600 && opcode < 700) && (opcode % 2) || (opcode.substring(0,2) == 78 && opcode!= 788))
    {
        return 'plus';
    }
    if(opcode == 887){
        return 'samiswoi';
    }
    if (opcode == 788 || opcode== 787 || (opcode >= 880 && opcode <= 900))
    {
        return 'heyah';
    }
    return '???';
}

function maxDlugoscSms(bramka){
    switch(bramka){
        case 'heyah':
        case 'eraomnix': return 109;
        case 'idea': return 390;
        case 'miastoPlusa': return 580;
        case 'mbox': return 640;
        case 'plusIframe':
        case 'plus': return 617;
        case '9gr': return 160;
        case '6grswiat': return 160;
        case 'tlen': return 1200;
        case 'gg': return 1200;
        case 'icq': return 1200;
        default: return 0;
    }
}

function podpisOddzielnie(bramka){
    switch(bramka){
        case 'heyah': return false;
        case 'eraomnix': return true;
        case 'idea': return true;
        case 'miastoPlusa': return false;
        case 'mbox': return false;
        case 'plusIframe':                
        case 'plus': return true;
        case '9gr': return false;
        case '6grswiat': return true;
        case 'tlen': return true;
        case 'gg': return true;
        default: return false;
    }
}

function wybranaBramka(dat){
    if(dat.bramka.value=="auto"){
        return domyslnaBramka(dat.numer.value);
    }
    else {
        return dat.bramka.value;
    }
}

function iloscSms(tresc,podpis,dlugosc,numeruj,podpisOddzielnie)
{
    var obetnij=0;
    var dodaj=0;

    if(podpis!="" && podpisOddzielnie) obetnij+=podpis.length;
    else if(podpis!="") dodaj=(2+podpis.length);

    if(dlugosc<1) return 0;

    if(Math.ceil((dodaj+tresc.length)/(dlugosc-obetnij))>1 && numeruj)
        obetnij+=5;

    if(Math.ceil((dodaj+tresc.length)/(dlugosc-obetnij))>9 && numeruj)
        obetnij+=2;

        return Math.ceil((dodaj+tresc.length)/(dlugosc-obetnij));
}
