function CheckDisabler(checkId,disElems) {
    this.c = $(checkId);
    if (this.c==null) return;
    this.elems=new Array();
    for(var i=0;i<disElems.length;i++) {
        var el=$(disElems[i]);
        if (el!=null)
            this.elems[this.elems.length]=el;
    }
    this.c.cd=this;
    $(this.c).observe("click", this.make);
    this.makeDis();
}
CheckDisabler.prototype.make=function(e){
    var d=Event.findElement(e,"input");
    if (d==null) return;
    d.cd.makeDis();
}
CheckDisabler.prototype.makeDis=function() {
    for (var i=0;i<this.elems.length;i++) {
        this.elems[i].disabled=!this.c.checked;
        if (this.elems[i].type=="text" && this.elems[i].disabled)
            this.elems[i].value="";
    }
}
function SpamCodeGetter(idEl) {
    var el=$(idEl);
    if (el==null)
        return false;
    el.value="";
    el.scg = this;
    $(el).observe("click", this.listen);
}
SpamCodeGetter.prototype.listen=function(e) {
    var d=Event.findElement(e,"input");
    if (d==null) return;

    new Ajax.Request("http://"+ document.location.host+"/exec/ajax/getcode.php", {
        method: "get",
        onSuccess: function(response) {
            d.value=response.responseText;
        }
    });
}
String.prototype.reverse = function() {
    var newCena = new String();
    for (var j=this.length-1;j>-1;j--)
        newCena+=this.substr(j,1);
    return newCena.valueOf();
}
function ChangeSum(id, elem, sourceId) {
    var col = $(id).getElementsByTagName("span");
    var inp = $(id).getElementsByTagName("input");

    for(i=0;i<col.length;i++) {

        inp[i].price = parseFloat(col[i].innerHTML.replace(/ /gi,"").replace(/,/gi,"."));
        inp[i].elem = elem;
        inp[i].sourceId = sourceId;
        inp[i].onclick = function() {
            var suma = parseFloat( $(this.sourceId).innerHTML.replace(/ /gi,"").replace(/,/gi,"."));

            if ($("sleva"))
                suma -= parseInt($("sleva").innerHTML.replace(/ /gi,""));

            var total = suma+this.price;
            var Cena = new String(total);
            Cena = Cena.reverse().replace(/(\d{3})/gi, "$1 ").reverse().replace(/\./gi,",").replace(/,(\d{1})$/gi,",$10");
            if (total-parseInt(total)==0) Cena+=",-";
            for (var i=0;i<elem.length; i++)
                $(elem[i]).innerHTML = Cena;
        }
    }
}

var CheckBoxToggler = Class.create();
CheckBoxToggler.prototype = {
    sw:null,
    state:false,
    elems:null,
    initialize:function(switcherID, elemsIDprefix) {
        this.sw = $(switcherID);
        this.elems = Element.select("input", "[id^=\""+elemsIDprefix+"\"]");
        if (this.sw==null || this.elems==null)
            return;
        this.state=!this.sw.checked;
        this.sw.observe("click", (function(event) { this.resetElems(); }).bind(this) );
        var cbt=this;
        this.elems.each(function(node) {node.observe("click", (function(event) { this.resetMain(); }).bind(cbt) )} );
    },
    resetElems:function() {
        this.state=!this.state;
        if (!this.state) {
            var s=this.state;
            this.elems.each(function(node) {node.checked=s});
        }
    },
    resetMain:function(){
        if (this.sw.checked) {
            this.sw.checked=false;
            this.state=true;
        }
    }
};

