function CheckDisabler(checkId,disElems) {
    this.c = $(checkId);
    if (this.c==null) return;
    this.elems=new Array();
    for(var i=0;i<disElems.length;i++)
        this.elems[this.elems.length]=$(disElems[i]);
    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 ShClass = Class.create();
ShClass.prototype = {
    elems:null,
    rClass:null,
    initialize:function(checkId,parentID, rClass) {
        this.rClass=rClass;
        var c = $(checkId);
        if (c==null) return;
        c.showed=false;
        this.elems=$$("#"+parentID+" input,#"+parentID+" select,#"+parentID+" textarea");
        this.makeIt(!c.checked);
        c.observe("click", (function(e) {this.show(e)}).bind(this));
    },
    show:function(e) {
        var d=Event.findElement(e,"input");
        if (d==null) return;
        this.makeIt(d.showed);
        d.showed=!d.showed;
    },
    makeIt:function(sh){
        var rc=this.rClass;
        this.elems.each( function(node) { if (sh) node.removeClassName(rc); else node.addClassName(rc); } );
    }
}

var SearchBox = Class.create();
SearchBox.prototype = {
    start:true,
    initialize:function(id){
        var n=$(id), SB=this;
        if (n!=null)
            n.observe("focus", function(){ if (SB.start) n.value=""; SB.start=false; } );
    }
}


