function textual_update() {
    var s="В этих торгах смогут подать предложения";
    var form = document.forms['create_tender_form'];
    if(form==null){
        form = document.forms['edit_tender_form']; 
    }
    var wholesale_restriction =	form.elements['restrictionOnlyConfirmedCompanies'].checked ||
                            form.elements['restrictionPositiveRating'].checked;
    if (form.elements['restrictionPartners'].checked) {
        s+=" партнёры Вашей организации (см. закладку \"Партнёры\")";
        if (wholesale_restriction) s+=", а также";
    } else {
        if (!wholesale_restriction) s+=" все организации зарегистрировавшиеся на вэб сайте";
    }
    if (wholesale_restriction) {
        s+=" организации зарегистрировавшиеся на вэб сайте и";

        if (form.elements['restrictionOnlyConfirmedCompanies'].checked)
            s+=" документально подтвердившие государственную регистрацию";

        if (form.elements['restrictionPositiveRating'].checked) {
            if (form.elements['restrictionOnlyConfirmedCompanies'].checked)
                s+=" и";
            s+=" имеющие рейтинг выше нуля";
        }
    }
//		if (!restrictionGroups.isEmpty()) {
//			if (wholesale_restriction) s+=", при этом";
//			s+=" входящие хотя бы в одну из указанных Вами групп";
//		}
    s+=".";
    document.getElementById('constraints-status').innerHTML=s;

    if (form.elements['restrictionOnlyConfirmedCompanies'].checked ||
        form.elements['restrictionPositiveRating'].checked ||
        form.elements['restrictionPartners'].checked)
    {
        document.getElementById('constraints-status').className = "constrained-tender";
    }
    else {
        document.getElementById('constraints-status').className = "no-constraints";
    }
}

var cid = 37;
function newid(){
    return 'unique_id_' + (++cid);
}

function addRestrictionGroup(){
    var groups = document.getElementById('groups');
    var template = document.getElementById('group-template');
    var el = template.cloneNode(true);
    var nid = newid();
    el.id = nid;
    var els = el.getElementsByTagName('input');
    for(var i=0; i<els.length; i++){
        var inp = els.item(i);
        if(inp.getAttribute('type')=='button'){
            inp.setAttribute('onclick', 'deleteRestrictionGroup(\''+nid+'\');');
            break;
        }
    }
    els = el.getElementsByTagName('select');
    for(i=0; i<els.length; i++){
        var sel = els.item(i);
        sel.disabled = false;
    }
    groups.appendChild(el);
    el.style.display = '';
    el.style.visibility = 'visible';
}

function deleteRestrictionGroup(id){
    document.getElementById('groups').removeChild(document.getElementById(id));
}

function updateTenderSum(){
    document.getElementById('tender-summ').innerHTML =
            multiply(document.getElementById('tender-price').value, document.getElementById('tender-qty').value);
}

function updateOfferSum(){
    document.getElementById('offer-summ').innerHTML =
            multiply(document.getElementById('offer-price').value, document.getElementById('offer-qty').value);
}

function updateOfferSum1(id){
    document.getElementById('offer-summ_'+id).innerHTML =
            multiply(document.getElementById('offer_price_'+id).value, document.getElementById('offer_quantity_'+id).value);
}

function multiply(m1, m2){
    return numberValue(m1)*numberValue(m2);
}

function numberValue(val){
    var v = new Number(val.replace(",", "."));
    if(v!=Number.NaN){
        return v;
    }else{
        return 0;
    }
}

function expandOpinionForm(id) {
    document.getElementById('expand_opinion_form_' + id).style.display = 'none';
    document.getElementById('collapse_opinion_form_' + id).style.display = 'block';
    document.getElementById('opinion_form_' + id).style.display = 'block';
}

function collapseOpinionForm(id) {
    document.getElementById('expand_opinion_form_' + id).style.display = 'block';
    document.getElementById('collapse_opinion_form_' + id).style.display = 'none';
    document.getElementById('opinion_form_' + id).style.display = 'none';
}

function expandOfferForm(id) {
    document.getElementById('expand_offer_form_' + id).style.display = 'none';
    document.getElementById('collapse_offer_form_' + id).style.display = 'block';
    document.getElementById('offer_form_' + id).style.display = 'block';
}

function collapseOfferForm(id) {
    document.getElementById('expand_offer_form_' + id).style.display = 'block';
    document.getElementById('collapse_offer_form_' + id).style.display = 'none';
    document.getElementById('offer_form_' + id).style.display = 'none';
}

