function switcher(formID, rPrefix, sPrefix) {
    this.form = document.getElementById(formID);
    if (this.form==null)
        return;

    this.last=null;
    var col = this.form.getElementsByTagName("input");
    for (var i=0; i<col.length; i++) {
        var ind=col[i].id.indexOf(rPrefix);
        if (ind!=-1) {
            col[i].sel = document.getElementById(sPrefix+col[i].id.substr(rPrefix.length));
            col[i].s=this;
            if (col[i].sel!=null) {
                col[i].sel.disabled = !col[i].checked;
                if (col[i].checked)
                    this.last = col[i].sel;
            }
            col[i].onclick = function() {
                if (this.sel!=null)
                    this.sel.disabled = !this.checked;
                if (this.s.last!=null)
                    this.s.last.disabled = true;
                this.s.last = this.sel;
            }
        }
    }
}
function DblClick(idEl) {
    var el=document.getElementById(idEl);
    if (el==null)
        return false;
    var url="http://"+ document.location.host+"/js/getcode.php";
    el.value="";
    el.ondblclick=function() {
        function setCode() { el.value=(objXmlHttp.readyState==4) ? objXmlHttp.responseText : ""; }
        var ua = navigator.userAgent;
        var objXmlHttp=null;
        if (ua.indexOf("Opera")>=0) return;
        if (ua.indexOf("MSIE")>=0) {
            var strName="Msxml2.XMLHTTP";
            if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
                strName="Microsoft.XMLHTTP";
            }
            try {
                objXmlHttp=new ActiveXObject(strName);
                objXmlHttp.onreadystatechange=setCode;
            }
            catch(e) {
                return ;
            }
        }
        else if (ua.indexOf("Mozilla")>=0) {
            objXmlHttp=new XMLHttpRequest();
            objXmlHttp.onload=setCode;
            objXmlHttp.onerror=setCode;
        }
        else
            return;

        objXmlHttp.open("GET", url, true);
        objXmlHttp.send(null);

    }
}
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 = document.getElementById(id).getElementsByTagName("span");
    var inp = document.getElementById(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( document.getElementById(this.sourceId).innerHTML.replace(/ /gi,"").replace(/,/gi,"."));

            if (document.getElementById("sleva"))
                suma -= parseInt(document.getElementById("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++)
                document.getElementById(elem[i]).innerHTML = Cena;
        }
    }
}
function Images(parentID) {
    if (Browser.isIE() && !Browser.isIE6() && !Browser.isIE7())
        return;
    var pEl = document.getElementById(parentID);
    if (pEl==null)
        return;
    this.thumb = pEl.getElementsByTagName("img");
    for (var i=0; i<this.thumb.length; i++) {
        var a =this.thumb[i].parentNode;
        if (a!=null && a.nodeName=="A" && a.href.substr(a.href.length-3, 3)=="jpg") {
            a.img = new Image();
            a.img.src = a.href;
            a.thumb = this.thumb[i];
            a.href="javascript: //nop/";
            EventTools.setEvent( a, "click", this.open);
        }
    }
    EventTools.setEvent(window, "keydown", this.dKey);
}

Images.prototype.open = function(e) {

    var el = EventTools.getElement(e, "img");
    if (el==null)
        return;

    if (WWinMan.activeW!=null && WWinMan.count>0) {
        WWinMan.activeW.close();
        WWinMan.activeW=null;
    }

    var opacity = 20, hAdd = 40;
    // content
    var content = document.createElement("div");
    var img = document.createElement("img");
    img.src = el.img.src;
    Element.setOpacity(img, 0);
    content.appendChild(img);
    if (el.thumb.alt!="") {
        var p =  document.createElement("p");
        p.innerHTML = el.thumb.alt;
        p.className="hidden";
        content.appendChild(p);
    }

    var elDim = [parseInt(el.img.width+10),parseInt(el.img.height+hAdd)],scD=Pos.getMaxDim(false);
    var endpos = Pos.correctCoords([parseInt((scD[0]/2)-(elDim[0]/2)),parseInt((scD[1]/2)-(elDim[1]/2))], elDim, true);
    el.pos = Pos.findPos(el.thumb);
    Element.setOpacity(el.thumb,opacity);
    el.thumb.blur();
    var i = WWinMan.createWin(null, content,{styleClass:"okno center",left:endpos[0]+"px",top:endpos[1]+"px",width:elDim[0]+"px",height:elDim[1]+"px",position:"absolute"}, true, el.pos, [el.thumb.width, el.thumb.height],"Image");
    i.onLoad( function() {
                Element.setUnVisible(el.thumb);
                Element.fadeOut(img);
                p.className="";
            } );
    i.onClose( function() {
                Element.setUnVisible(img);
                Element.setVisible(el.thumb);
                Element.setOpacity(el.thumb,100); } );
    i.onChange( function(param) { Element.setOpacity(el.thumb,parseInt(.2*(1-param)*100)); });

}
Images.prototype.dKey=function(e) {
    var k = EventTools.getKeyCode(e);
    if (WWinMan.activeW!=null) {
        if (k==27) {
            WWinMan.activeW.close();
            WWinMan.activeW=null;
        }
/*
        if (k==39 || k==37) {
            alert("Tady");
        }
*/
    }
}

