﻿RadioKontrol = function(obj, active, PN) {
    this.pn = PN;
    this.bf = true;
    this.name = obj.name;
    var prm = obj.Tag.split("|");
    this.opt = (prm[0] == "E");
    this.che = !(prm[1] == "0");
    this.ID = prm[2];
    this.fn = prm[3];
    this.ti = Number(prm[4]);
    this.setevents(obj, active);
}
RadioKontrol.prototype =
{
    setevents: function(obj, active) {
        this.obj = obj;
        this.ba = active;
        this.sel = obj.findname("sl" + obj.name);
        this.makec(obj);
        this.token1 = obj.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.MouseUp));
        this.token2 = obj.addEventListener("mouseEnter", onHC);
        this.token3 = obj.addEventListener("mouseLeave", offHC);
        this.select();
    },
    makec: function(obj) {
        var ct = obj.findname("ct" + obj.name);
        var cc = this.cc = obj.findname("cc" + obj.name);
        ct.height = ct.ActualHeight;
        if (this.opt) {
            var cb = obj.findname("cb" + obj.name);
            cb.height = cb.width = ct.ActualHeight * 0.6;
            cb["Canvas.Top"] = (ct.height - cb.height) / 2;
            ct["Canvas.Left"] = cb.height * 1.2;
            cc.height = cc.width = cb.height * 0.7;
            cc["Canvas.Left"] = (cb.height - cc.height) / 2;
            cc["Canvas.Top"] = cb["Canvas.Top"] + cc["Canvas.Left"];
        } else {
            var ib = obj.findname("ib" + obj.name);
            var db = obj.findname("db" + obj.name);
            ct.height = ct.ActualHeight;
            db.height = db.width = ct.Height / 1.75;
            db["Canvas.Top"] = (ct.height - db.height) / 2;
            ct["Canvas.Left"] = ct.height;
            cc.height = cc.width = ib.height = ib.width = db.height * 0.80;
            var oah = cc.height;
            cc["Canvas.Top"] = ib["Canvas.Top"] = db["Canvas.Top"] + (db.height - ib.height) / 2;
            cc["Canvas.left"] = ib["Canvas.left"] = (db.height - ib.height) / 2;
            cc.strokeThickness = oah / 4;
            cc.data = "M1," + oah / 2 + "L" + oah / 2 + "," + (oah - (oah / 6)) + "M" + oah / 3 + "," + (oah - (oah / 6)) + "L" + oah + ",0";
        }
    },
    keydown: function(e) {
        if (e == 32 || e == 13)
            this.MouseUp();
    },
    release: function() {
        this.obj.RemoveEventListener("MouseLeftButtonUp", this.token1);
        this.obj.RemoveEventListener("MouseEnter", this.token2);
        this.obj.RemoveEventListener("mouseLeave", this.token3);
        this.ba = false;
    },
    setfocus: function() {
        sOf(this);
        this.sel.opacity = 100;
    },
    lostfocus: function() {
        this.sel.opacity = 0;
    },
    select: function() {
        if (this.che)
            this.cc.opacity = 100;
        else
            this.cc.opacity = 0;
    },
    MouseUp: function(sender, eventArgs) {
        if (this.opt) {
            this.che = true;
            for (var a = 0; a < asc.length; a++) {
                var mgopt = asc[a];
                if (mgopt.che && this.opt && mgopt != this && mgopt.pn == this.pn && mgopt.ID == this.ID) {
                    { mgopt.che = false; mgopt.select(); }
                }
            }
        } else
            this.che = !this.che;
        this.select();
        this.setfocus();
    }
}

StaticKontrol = function(obj,PN) {
    this.pn=PN;
    var tb = obj.findname("tb" + obj.name);
    tb.height = Math.min(tb.ActualHeight, obj.height);
    tb.width = Math.min(tb.ActualWidth, obj.width);
    tb["Canvas.Top"] = (obj.height - tb.height) / 2;
    if (obj.Tag.charAt(2)=="2")//Center
        tb["Canvas.Left"] = (obj.width - tb.width) / 2;
    else if (obj.Tag.charAt(2)=="1")//Right
        tb["Canvas.Left"] = (obj.width - tb.width);
}
StaticKontrol.prototype =
{
    setevents:function(){},
    release:function(){}
}
HyperLink = function(obj, active, PN) {
    this.pn = PN;
    this.bf = true;
    this.name = obj.name;
    var prm = obj.Tag.split("|");
    this.ty = prm[1];
    this.hl = prm[2];
    this.ti = Number(prm[3]);
    this.setevents(obj, active);
}
HyperLink.prototype =
{
    setevents: function(obj, active) {
        this.obj = obj;
        this.sel = obj.findname("sl" + obj.name);
        this.token1 = obj.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.MouseUp));
        this.token2 = obj.addEventListener("mouseEnter", onHC);
        this.token3 = obj.addEventListener("mouseLeave", offHC);
    },
    keydown: function(e) {
        if (e == 32 || e == 13)
            this.MouseUp();
    },
    release: function() {
        this.obj.RemoveEventListener("MouseLeftButtonUp", this.token1);
        this.obj.RemoveEventListener("MouseEnter", this.token2);
        this.obj.RemoveEventListener("mouseLeave", this.token3);
        this.ba = false;
    },
    setfocus: function() {
        sOf(this);
        this.sel.opacity = 100;
    },
    lostfocus: function() {
        this.sel.opacity = 0;
    },
    MouseUp: function(sender, eventArgs) {
        this.setfocus();
        if (this.ty == "0")
            window.open(this.hl);
        else if (this.ty == "1")
            location.replace(this.hl);
        else if (this.ty == "2") {
            var mDown = new XMLHttpRequest();
            mDown.open("POST", this.hl, false);
            mDown.send(null);
        } else if (this.ty == "3") {
            if (xax) {
                pcc.FindName(xax.Name + "_close").begin();
                xax = null;
            }
        } else if (this.ty == "4")
            if (!blo) CreateXAML(this.hl);
            else {
                if (xax) {
                    pcc.FindName(xax.Name + "_close").begin();
                    xax = null;
                }
        }
        else if (this.ty == "5")
            eval(this.hl);
    }
}
