﻿var cssdropdown={
    disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout
    inside: 0,
    //No need to edit beyond here////////////////////////
    dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all,
    dropmenuobjchild: null, ie: document.all, firefox: document.getElementById&&!document.all,
    getposOffset:function(what, offsettype)
    {
        var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
        var parentEl=what.offsetParent;
        while (parentEl!=null)
        {
            if (this.ie )
            {
                if (offsettype == "left" )
                {
                    if (parentEl.style.position.toLowerCase() != "relative" && parentEl.style.position.toLowerCase() != "absolute")
                    {
                        totaloffset=totaloffset+parentEl.offsetLeft - parentEl.style.posLeft;
                    }
                }
                else 
                {
                    if (parentEl.style.position.toLowerCase() != "relative" && parentEl.style.position.toLowerCase() != "absolute")
                    {
                        totaloffset=totaloffset+parentEl.offsetTop - parentEl.style.posTop;
                    }
                }
            }
            else
            {
                var posLeft = 0;
                var posTop = 0;
                if (parentEl.style.left != "" && parentEl.style.left.indexOf("px") != -1)
                {
                    posLeft = parseInt(parentEl.style.left.substring(0, parentEl.style.left.indexOf("px")));
                }
                if (parentEl.style.top != "" && parentEl.style.top.indexOf("px") != -1)
                {
                    posTop = parseInt(parentEl.style.top.substring(0, parentEl.style.top.indexOf("px")));
                }
                if (parentEl.style.position.toLowerCase() != "relative")
                {
                    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop ;
                }
                else
                {
                totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop ;
                }
            }
            parentEl=parentEl.offsetParent;
        }
        return totaloffset;
    },

    showhide:function(obj, e, visible, hidden)
    {
        if (this.ie || this.firefox)
        {
           obj.style.left=obj.style.top="-500px";
        }
        if (e.type=="click" && obj.style.visibility==hidden || e.type=="mouseover")
        {
            obj.style.visibility=visible;
            obj.style.display="block";
        }
        else if (e.type=="click")
        {
            obj.style.visibility=hidden;
            obj.style.display="none";
        }
    },

    iecompattest:function()
    {
        return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    },

    clearbrowseredge:function(obj,dm, whichedge)
    {
        var edgeoffset=0
        if (whichedge=="rightedge")
        {
            var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
            dm.contentmeasure=dm.offsetWidth;
            if (windowedge-dm.x < dm.contentmeasure)  //move menu to the left?
            {
                edgeoffset=dm.contentmeasure-obj.offsetWidth;
            }
        }
        else
        {
            var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset;
            var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
            dm.contentmeasure=dm.offsetHeight;
            if (windowedge-dm.y < dm.contentmeasure)
            { //move up?
                edgeoffset=dm.contentmeasure+obj.offsetHeight;
                if ((dm.y-topedge)<dm.contentmeasure) //up no good either?
                {
                    edgeoffset=dm.y+obj.offsetHeight-topedge;
                }
            }
        }
        return edgeoffset
    },
    clearbrowseredgechild:function(obj,dm, whichedge)
    {
        var edgeoffset=0;
        var offset=0;
        var parentEl=dm.offsetParent;
        while (parentEl!=null)
        {
            
            offset= (whichedge == "rightedge")? offset+parentEl.offsetLeft :offset + parentEl.offsetTop
            
            parentEl=parentEl.offsetParent;
        }
        if (whichedge=="rightedge")
        {
            var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
            dm.contentmeasure=dm.offsetWidth;
            if (windowedge- offset - obj.offsetWidth - dm.contentmeasure < 0)  //move menu to the left?
            {
                edgeoffset= -dm.contentmeasure;
            }
            else
            {
                edgeoffset = obj.offsetWidth;
            }
        }
        else
        {
            var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset;
            var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
            dm.contentmeasure=dm.offsetHeight;
            if (windowedge- offset - obj.offsetHeight - dm.contentmeasure < 0)
            { //move up?
                edgeoffset= 0 - dm.contentmeasure + obj.offsetTop+ obj.offsetHeight;
                
            }
            else
            {
                edgeoffset = obj.offsetTop - 1;
            }
        }
        return edgeoffset
    },

    dropit:function(obj, e, dropmenuID, direction)
    {
        if (this.dropmenuobj!=null) //hide previous menu
        {
            if (this.ie&&this.dropmenuobj.contains(obj))
            {
                if (this.dropmenuobjchild != null)
                {
                    this.dropmenuobjchild.style.visibility="hidden";
                    this.dropmenuobjchild.style.display="none";
                }
                this.SetChild(obj,e,dropmenuID, direction);
            }
            else if (this.firefox && this.contains_firefox(this.dropmenuobj,obj))
            {
                if (this.dropmenuobjchild != null)
                {
                    this.dropmenuobjchild.style.visibility="hidden";
                    this.dropmenuobjchild.style.display="none";
                }
                this.SetChild(obj,e,dropmenuID, direction);
            }
            else
            {
                this.dropmenuobj.style.visibility="hidden";
                this.dropmenuobj.style.display="none";
                this.SetParent(obj,e,dropmenuID,direction);
            }    
        }
        else 
        {
            this.SetParent(obj,e,dropmenuID,direction);
        }
        
    },
    SetChild:function(obj,e,dropmenuID,direction)
    {
        this.clearhidemenuchild();
        if (this.ie||this.firefox)
        {
            obj.onmouseout=function(){cssdropdown.delayhidemenuchild()};
            var tempdropobject = document.getElementById(dropmenuID);
            tempdropobject.onmouseover=function(){cssdropdown.clearhidemenuchild()};
            tempdropobject.onmouseout=function(){cssdropdown.dynamichidechild(e)};
            //tempdropobject.onclick=function(){cssdropsown.delayhidemenuchild()};
            this.showhide(tempdropobject, e, "visible", "hidden");
            
            tempdropobject.x = 0;
            tempdropobject.y= 0;
            tempdropobject.style.left=this.clearbrowseredgechild(obj,tempdropobject, "rightedge")+"px";
            tempdropobject.style.top=this.clearbrowseredgechild(obj, tempdropobject, "bottomedge") +"px";
            this.dropmenuobjchild = tempdropobject;
            
        }
    },
    SetParent:function(obj,e,dropmenuID,direction)
    {
        this.clearhidemenu();
        if (this.ie||this.firefox)
        {
            obj.onmouseout=function(){cssdropdown.delayhidemenu()};
            var tempdropobject = document.getElementById(dropmenuID);
            tempdropobject.onmouseover=function(){cssdropdown.clearhidemenu()};
            tempdropobject.onmouseout=function(){cssdropdown.dynamichide(e)};
            //tempdropobject.onclick=function(){cssdropdown.delayhidemenu()};
            this.showhide(tempdropobject, e, "visible", "hidden");
            tempdropobject.x=this.getposOffset(obj, "left");
            tempdropobject.y=this.getposOffset(obj, "top");
            
            tempdropobject.style.left=tempdropobject.x-this.clearbrowseredge(obj,tempdropobject, "rightedge", direction)+"px";
            tempdropobject.style.top=tempdropobject.y-this.clearbrowseredge(obj, tempdropobject, "bottomedge" , direction)+obj.offsetHeight+1+"px";
            this.dropmenuobj = tempdropobject;
            
        }
    },
    contains_firefox:function(a, b) 
    {
        while (b.parentNode)
        {
            if ((b = b.parentNode) == a)
            return true;
        }
        return false;
    },

    dynamichide:function(e)
    {
        var evtobj=window.event? window.event : e;
        if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
        {            
            this.delayhidemenu();
            
        }
        else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
        {
            this.delayhidemenu();
        }
    },
    dynamichidechild:function(e)
    {
        var evtobj=window.event? window.event : e;
        if (this.ie&&!this.dropmenuobjchild.contains(evtobj.toElement))
        {            
            this.delayhidemenuchild();
            
        }
        else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
        {
            this.delayhidemenuchild();
        }
    },

    delayhidemenu:function()
    {
        this.delayhide=setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden';cssdropdown.dropmenuobj.style.display='none';",this.disappeardelay);
    },
    delayhidemenuchild:function()
    {
        this.delayhidechild=setTimeout("cssdropdown.dropmenuobjchild.style.visibility='hidden';cssdropdown.dropmenuobjchild.style.display='none';",this.disappeardelay);
    },
    clearhidemenu:function()
    {
        if (this.delayhide!="undefined")
        {
            clearTimeout(this.delayhide);
            
        }
       
    },
    clearhidemenuchild:function()
    {
        if (this.delayhide!="undefined")
        {
            clearTimeout(this.delayhide);
            clearTimeout(this.delayhidechild);
            
        }
       
    }
    
}
var cssdropmenu={
    disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout
    inside: 0,
    //No need to edit beyond here////////////////////////
    dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all,
    dropmenuobjchild: null, ie: document.all, firefox: document.getElementById&&!document.all,
    getposOffset:function(what, offsettype)
    {
        var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
        var parentEl=what.offsetParent;
        while (parentEl!=null)
        {
            
            if (this.ie )
            {
                if (offsettype == "left" )
                {
                    if (parentEl.style.position.toLowerCase() != "relative")
                    {
                        totaloffset=totaloffset+parentEl.offsetLeft - parentEl.style.posLeft;
                    }
                }
                else 
                {
                    if (parentEl.style.position.toLowerCase() != "relative")
                    {
                        totaloffset=totaloffset+parentEl.offsetTop - parentEl.style.posTop;
                    }
                }
            }
            else
            {
                var posLeft = 0;
                var posTop = 0;
                if (parentEl.style.left != "" && parentEl.style.left.indexOf("px") != -1)
                {
                    posLeft = parseInt(parentEl.style.left.substring(0, parentEl.style.left.indexOf("px")));
                }
                if (parentEl.style.top != "" && parentEl.style.top.indexOf("px") != -1)
                {
                    posTop = parseInt(parentEl.style.top.substring(0, parentEl.style.top.indexOf("px")));
                }
                if (parentEl.style.position.toLowerCase() != "relative")
                {
                    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop ;
                }
                else
                {
                totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop ;
                }
            }
            parentEl=parentEl.offsetParent;
        }
        return totaloffset;
    },

    showhide:function(obj, e, visible, hidden)
    {
        if (this.ie || this.firefox)
        {
           obj.style.left=obj.style.top="-500px";
        }
        if (e.type=="click" && obj.style.visibility==hidden || e.type=="mouseover")
        {
            obj.style.visibility=visible;
            obj.style.display="block";
        }
        else if (e.type=="click")
        {
            obj.style.visibility=hidden;
            obj.style.display="none";
        }
    },

    iecompattest:function()
    {
        return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    },

    clearbrowseredge:function(obj,dm, whichedge)
    {
        var edgeoffset=0
        if (whichedge=="rightedge")
        {
            var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
            dm.contentmeasure=dm.offsetWidth;
            if (windowedge-dm.x < dm.contentmeasure)  //move menu to the left?
            {
                edgeoffset=dm.contentmeasure-obj.offsetWidth;
            }
        }
        else
        {
            var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset;
            var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
            dm.contentmeasure=dm.offsetHeight;
            if (windowedge-dm.y < dm.contentmeasure)
            { //move up?
                edgeoffset=dm.contentmeasure+obj.offsetHeight;
                if ((dm.y-topedge)<dm.contentmeasure) //up no good either?
                {
                    edgeoffset=dm.y+obj.offsetHeight-topedge;
                }
            }
        }
        return edgeoffset
    },
    clearbrowseredgechild:function(obj,dm, whichedge)
    {
        var edgeoffset=0;
        var offset=0;
        var parentEl=dm.offsetParent;
        while (parentEl!=null)
        {
            
            offset= (whichedge == "rightedge")? offset+parentEl.offsetLeft :offset + parentEl.offsetTop
            
            parentEl=parentEl.offsetParent;
        }
        if (whichedge=="rightedge")
        {
            var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
            dm.contentmeasure=dm.offsetWidth;
            if (windowedge- offset - obj.offsetWidth - dm.contentmeasure < 0)  //move menu to the left?
            {
                edgeoffset= -dm.contentmeasure;
            }
            else
            {
                edgeoffset = obj.offsetWidth;
            }
        }
        else
        {
            var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset;
            var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
            dm.contentmeasure=dm.offsetHeight;
            if (windowedge- offset - obj.offsetHeight - dm.contentmeasure < 0)
            { //move up?
                edgeoffset= 0 - dm.contentmeasure + obj.offsetTop+ obj.offsetHeight;
                
            }
            else
            {
                edgeoffset = obj.offsetTop - 1;
            }
        }
        return edgeoffset
    },

    dropit:function(obj, e, dropmenuID, direction)
    {
        if (this.dropmenuobj!=null) //hide previous menu
        {
            if (this.ie&&this.dropmenuobj.contains(obj))
            {
                if (this.dropmenuobjchild != null)
                {
                    this.dropmenuobjchild.style.visibility="hidden";
                }
                this.SetChild(obj,e,dropmenuID, direction);
            }
            else if (this.firefox && this.contains_firefox(this.dropmenuobj,obj))
            {
                if (this.dropmenuobjchild != null)
                {
                    this.dropmenuobjchild.style.visibility="hidden";
                }
                this.SetChild(obj,e,dropmenuID, direction);
            }
            else
            {
                this.dropmenuobj.style.visibility="hidden";
                this.SetParent(obj,e,dropmenuID,direction);
            }    
        }
        else 
        {
            this.SetParent(obj,e,dropmenuID,direction);
        }
        
    },
    SetChild:function(obj,e,dropmenuID,direction)
    {
        this.clearhidemenuchild();
        if (this.ie||this.firefox)
        {
            obj.onmouseout=function(){cssdropmenu.delayhidemenuchild()};
            var tempdropobject = document.getElementById(dropmenuID);
            tempdropobject.onmouseover=function(){cssdropmenu.clearhidemenuchild()};
            tempdropobject.onmouseout=function(){cssdropmenu.dynamichidechild(e)};
            //tempdropobject.onclick=function(){cssdropsown.delayhidemenuchild()};
            this.showhide(tempdropobject, e, "visible", "hidden");
            
            tempdropobject.x = 0;
            tempdropobject.y= 0;
            tempdropobject.style.left=this.clearbrowseredgechild(obj,tempdropobject, "rightedge")+"px";
            tempdropobject.style.top=this.clearbrowseredgechild(obj, tempdropobject, "bottomedge") +"px";
            this.dropmenuobjchild = tempdropobject;
            
        }
    },
    SetParent:function(obj,e,dropmenuID,direction)
    {
        this.clearhidemenu();
        if (this.ie||this.firefox)
        {
            obj.onmouseout=function(){cssdropmenu.delayhidemenu()};
            var tempdropobject = document.getElementById(dropmenuID);
            tempdropobject.onmouseover=function(){cssdropmenu.clearhidemenu()};
            tempdropobject.onmouseout=function(){cssdropmenu.dynamichide(e)};
            //tempdropobject.onclick=function(){cssdropmenu.delayhidemenu()};
            this.showhide(tempdropobject, e, "visible", "hidden");
            tempdropobject.x=this.getposOffset(obj, "left");
            tempdropobject.y=this.getposOffset(obj, "top");
            tempdropobject.style.left=tempdropobject.x-this.clearbrowseredge(obj,tempdropobject, "rightedge", direction)+"px";
            tempdropobject.style.top=tempdropobject.y-this.clearbrowseredge(obj, tempdropobject, "bottomedge" , direction)+obj.offsetHeight+1+"px";
            this.dropmenuobj = tempdropobject;
            
        }
    },
    contains_firefox:function(a, b) 
    {
        while (b.parentNode)
        {
            b = b.parentNode;
            if (b == a)
            {
                return true;
            }
        }
        return false;
    },

    dynamichide:function(e)
    {
        var evtobj=window.event? window.event : e;
        if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
        {            
            this.delayhidemenu();
            
        }
        else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
        {
            this.delayhidemenu();
        }
    },
    dynamichidechild:function(e)
    {
        var evtobj=window.event? window.event : e;
        if (this.ie&&!this.dropmenuobjchild.contains(evtobj.toElement))
        {            
            this.delayhidemenuchild();
            
        }
        else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
        {
            this.delayhidemenuchild();
        }
    },

    delayhidemenu:function()
    {
        this.delayhide=setTimeout("cssdropmenu.dropmenuobj.style.visibility='hidden'",this.disappeardelay);
    },
    delayhidemenuchild:function()
    {
        this.delayhidechild=setTimeout("cssdropmenu.dropmenuobjchild.style.visibility='hidden'",this.disappeardelay);
    },
    clearhidemenu:function()
    {
        if (this.delayhide!="undefined")
        {
            clearTimeout(this.delayhide);
            
        }
       
    },
    clearhidemenuchild:function()
    {
        if (this.delayhide!="undefined")
        {
            clearTimeout(this.delayhide);
            clearTimeout(this.delayhidechild);
            
        }
       
    }
    
}


function TabPressed(index)
{
    if (currentIndex != index )
    {
        var pressedTab = document.getElementById("Tab" + index.toString());
        var pressedTable = document.getElementById("PTable" + index.toString());
        var currentTab = document.getElementById("Tab" + currentIndex.toString());
        var currentTable = document.getElementById("PTable" + currentIndex.toString());
        if (currentTab!=null)
        {
            currentTab.className="properties_inactive_tab";
        }
        if (pressedTab!=null)
        {
            pressedTab.className="properties_active_tab";
        }
        if (currentTable!=null)
        {
            currentTable.style.display= "none";
        }
        if (pressedTable!=null)
        {
            pressedTable.style.display= "block";
        }
        currentIndex = index;
        var manager = document.getElementById("manager0");
        var tools = document.getElementById("console_container");
        var tsize = tools.clientWidth;
        manager.style.width= tsize;
        manager.style.height = tools.clientHeight;
    }
}
//function mymodalDialogShow(url,width,height)//moz
//    {
//    var left = screen.availWidth/2 - width/2;
//    var top = screen.availHeight/2 - height/2;
//    activeModalWin = window.open(url, "", "width="+width+"px,height="+height+",left="+left+",top="+top);
//    window.onfocus = function(){if (activeModalWin.closed == false){activeModalWin.focus();};};
//    }
function TabLoad()
{
    
    currentIndex = 0;
    setTimeout("DelayTabLoad()",1);
    
}
function DelayTabLoad()
{
    TabPressed(1);
    TabPressed(0);
}
function DisplayFile(filename)
{
    var imgtag = document.getElementById("fileimg");
    if (imgtag != null)
    {
        imgtag.src = filename;
    }
}
function submitAdminForm(action)
{
    var adminForm = document.getElementById("AdminForm");
    if (adminForm != null)
    {
        adminForm.mgr.value = action;
        adminForm.submit();
    }
}

function catcalc(cal) 
{
    var date = cal.date;
    var time = date.getTime();
    var field = document.getElementById("f_calcdate");
    if (field == cal.params.inputField) 
    {
        field = document.getElementById("f_date_a");
        var begin_date = Date.parseDate(field.value,"%d.%m.%Y");
        if (date <=  begin_date)
        {
            begin_date.setDate(date.getDate()-1);
            field.value = begin_date.print("%d.%m.%Y");
        }
    } 
    else 
    {
        var end_date = Date.parseDate(field.value,"%d.%m.%Y");
        if (date >= end_date)
        {
            end_date.setDate(date.getDate()+ 1);
            field.value = end_date.print("%d.%m.%Y");
        }
    }
//    var date2 = new Date(time);
//    field.value = date2.print("%d.%m-%Y");
}
function setCalendarPair()
{
    Calendar.setup({
        inputField     :    "f_date_a",
        ifFormat       :    "%d.%m.%Y %H:%M",
        showsTime      :    true,
        timeFormat     :    "24",
        onUpdate       :    catcalc
    });
    Calendar.setup({
        inputField     :    "f_calcdate",
        ifFormat       :    "%d.%m.%Y %H:%M",
        showsTime      :    true,
        timeFormat     :    "24",
        onUpdate       :    catcalc
    });
}
function setCalendar(field)
{
    Calendar.setup({
        inputField     :    field,
        ifFormat       :    "%d.%m.%Y",
        showsTime      :    true,
        timeFormat     :    "24",
        onUpdate       :    catcalc
    });
}
function centerConsole()
{
    var console = document.getElementById("manager0");
    if (manager0 != null)
    {
        
        var winl = (document.body.offsetWidth-console.offsetWidth)/2;
        var wint = (screen.height-console.offsetHeight)/2-100;
        console.style.top = wint + "px";
        console.style.left = winl + "px";    

    }
}
function calcHeight(frameid)
{
    var iframe = document.getElementById(frameid);
    if (iframe != null)
    {
        var body = iframe.contentWindow.document.body;
        if (body != null)
        {
            
	        var the_height= body.scrollHeight;
	        document.getElementById(frameid).height = the_height;
	    }
	}
}
function writeHtml(html)
{
    document.write(html);
}
function writeFlash(src,url,width,height,id)
{
    var flashobj = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\" width=\"" + 
         width + "\" height=\"" + height + "\" id=\"link" + id + "\">" + 
         "<param name=\"movie\"  value=\""  + src + "\" />" +
         "<param name=\"quality\" value=\"high\" />" +
	     "<param name=\"wmode\"   value=\"Opaque\" />"  +
         "<param name=\"bgcolor\" value=\"white\">" +
         "<param name=\"flashvars\" value=\"ClickUrl=" + url + "\">" +
         "<embed src=\"" + src + "\" quality=\"high\" bgcolor=\"white\" wmode=\"Opaque\" width=\"" + 
         width + "\" height=\"" + height + "\" name=\"link" + id + "\"  align=\"\" type=\"application/x-shockwave-flash\"" +
         " pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed></object>";
    document.write(flashobj);
}

function showWindow(url,name,params)
{
    window.open(url,name,params);
}
function print_content(id)
{ 
    var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,"; 
        disp_setting += "scrollbars=yes,width=650, height=600, left=100, top=25"; 
    var content = document.getElementById(id).innerHTML; 
    if (content != null)
    {
        var docprint=window.open("","",disp_setting); 
        docprint.document.open(); 
        docprint.document.write('<html>'); 
        docprint.document.write('<body onLoad="self.print()">');
        docprint.document.write('<div style="width:600px;margin:10px;text-align:left;">');	
        docprint.document.write(content);
        docprint.document.write('</div></body></html>'); 
        docprint.document.close();
        docprint.focus(); 
    }
}
function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    
  }
  return  scrOfY ;
}
function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posY = 0; oElement; oElement = oElement.offsetParent ) {
      posY += oElement.offsetTop;
    }
    return posY ;
  } else {
    return oElement.y;
  }
}
function findPositionX( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
    }
    return posX ;
  } else {
    return oElement.x;
  }
}
function moveticket()
{
    var scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) 
    {
        //Netscape compliant
        scrOfY = window.pageYOffset;
    } 
    else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
    {
        //DOM compliant
        scrOfY = document.body.scrollTop;
    } 
    else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
    {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
    }
    var dv = document.getElementById('ticket_div');
    if (dv != null)
    {
        var position;
        if (dv.style.top)
        {
            position = dv.style.top.indexOf("px");
              
            if ( position == -1)
            {
                position = scrOfY - findPosition(dv) + dv.style.top;
            }
            else
            {
                position = scrOfY - findPosition(dv) + parseInt(dv.style.top.substring(0,position));
            }
            
            
        }
        else
        {
            position = scrOfY - findPosition(dv);
        }
        
        if (position < -1)
        {
            //dv.style.paddingTop =0;
            dv.style.position = "relative";
            dv.style.top = "0px";
            
        }
        else if (position > 1)
        {
            dv.style.position="relative";
//            dv.style.top = position + "px";
            
            var paddingTop = parseInt(dv.style.top);
//            alert(dv.style.paddingTop);
            if  (paddingTop > position + 1)
            {
                dv.style.top = (position + 1) + "px";
            }
            else if (paddingTop < position - 1)
            {
                if ( document.documentElement.clientHeight > dv.offsetHeight)
                {
                    dv.style.top = (position + 1) + "px";
                }
                
                else if (paddingTop != position + 1 - dv.offsetHeight + document.documentElement.clientHeight)
                {
                    //alert(position +'&'+ dv.height + '&' + document.documentElement.clientHeight);
                    position = position - 1 - dv.offsetHeight + document.documentElement.clientHeight;
                    if (position > 0)
                    {
                        dv.style.top = position;
                    }
                    else dv.style.top = 0;
                }
            }
        }
    }
    
}

function resizeParentFrame()
{
    if ( window.parent != null)
    {
//        var iframe = window.parent.document.getElementById("ticket_frame");
//        if (iframe != null)
//        {
//            var el = document.getElementById("div34");
//            
//                iframe.height = el.offsetHeight;
//                //clearTimeout(toutId);
//            
//            
//        }
        
    }
}
var first_match = "0";
var second_match = "0";

function ToggleMerger(id)
{
    var toggled_link = document.getElementById(id);
    if ( toggled_link != null)
    {
        if ( first_match == "0")
        {
            first_match = toggled_link.innerHTML;
            toggled_link.style.backgroundColor="80ff80";
            ShowDeleter(toggled_link);            
        }
        else if (second_match == "0")
        {
            if ( first_match == toggled_link.innerHTML)
            {
                toggled_link.style.backgroundColor = "Transparent";
                first_match = "0";
                HideDeleter();
            }
            else
            {
                second_match = toggled_link.innerHTML;
                toggled_link.style.backgroundColor="ff8080";
                ShowMerger(toggled_link);
            }
        }
        else
        {
            if (first_match == toggled_link.innerHTML)
            {
                HideMerger();
                toggled_link.style.backgroundColor= "Transparent";
                first_match = second_match;
                second_match = "0";
                toggled_link = document.getElementById(first_match);
                if (toggled_link != null)
                {
                    toggled_link.style.backgroundColor = "80ff80";
                    ShowDeleter(toggled_link);
                }
            }
            else if (second_match == toggled_link.innerHTML)
            {
                toggled_link.style.backgroundColor = "Transparent";
                second_match = "0";
                HideMerger();
            }
            else
            {
                toggled_link.style.backgroundColor="ff8080";
                var tmp = second_match;
                second_match = toggled_link.innerHTML;
                ShowMerger(toggled_link);
                toggled_link = document.getElementById(tmp);
                if (toggled_link != null)
                {
                    toggled_link.style.backgroundColor = "Transparent";
                }
            }
        }
    }
}
function ShowMerger(link)
{
    var merger = document.getElementById("merger");
    if (merger == null)
    {
        //there is no merger element
        merger = document.createElement("DIV");
        merger.id = "merger";
        document.body.appendChild(merger);
        merger.style.position = "absolute";
        merger.style.display = "block";
        merger.style.backgroundColor = "white";
        
        
    }
    
    var x = findPositionX(link) -200;
    var y = findPosition(link) + 15;
    
    merger.style.top = y.toString() + "px";
    merger.style.left = x.toString() + "px";
    merger.innerHTML = "<div style='width:200px;padding:3px;background-color:#ff8080;border:1px solid black;'><strong>spajanje parova</strong></div>" +
                        "<div style='width:200px;padding:3px;border:1px solid black'>" +
                        "<form method='post'>" +
                        "<input type='hidden' name='ctrl' value='13' />" +
                        "<input type='hidden' name='act' value='mm' />" +
                        "<input type='hidden' name='original_match' value='" + first_match.toString() + "' />" +
                        "<input type='hidden' name='faulty_match' value='" + second_match.toString() + "' />" +
                        "<input type='checkbox' name='invert' value='1' />invertiraj ekipe prije spajanja<br />" +
                        "<input type='submit' name='merge' value='spoji' /></form></div>";
    
}
function ShowDeleter(link)
{
    var deleter = document.getElementById("deleter");
    if (deleter == null)
    {
        //there is no merger element
        deleter = document.createElement("DIV");
        deleter.id = "deleter";
        document.body.appendChild(deleter);
        deleter.style.position = "absolute";
        deleter.style.display = "block";
        deleter.style.backgroundColor = "white";
    }
    var x = findPositionX(link) -200;
    var y = findPosition(link) + 15;
    deleter.style.top = y.toString() + "px";
    deleter.style.left = x.toString() + "px";
    deleter.innerHTML = "<div style='width:200px;padding:3px;background-color:#8080ff;border:1px solid black;'><strong>brisanje parova</strong></div>" +
                        "<div style='width:200px;padding:3px;border:1px solid black'>" +
                        "<form method='post'>" +
                        "<input type='hidden' name='ctrl' value='13' />" +
                        "<input type='hidden' name='act' value='dm' />" +
                        "<input type='hidden' name='match_id' value='" + first_match.toString() + "' />" +
                        "<input type='checkbox' name='delete_teams' value='1' />ujedno obrisi i ekipe<br />" +
                        "<input type='submit' name='merge' value='obriši' /></form></div>";
    
}
function HideMerger()
{
    var merger = document.getElementById("merger");
    if (merger != null)
    {
        merger.parentNode.removeChild(merger);
    }
}
function HideDeleter()
{
    var deleter = document.getElementById("deleter");
    if (deleter != null)
    {
        deleter.parentNode.removeChild(deleter);
    }
}
function xhr(file){
	
	this.xmlhttp = null;

	this.resetData = function(){
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function(){
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function(){
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}

function callAjax(filename)
{

    ajax = new xhr();
    ajax.requestFile = filename;
    ajax.onCompletion = function(){ajaxCallback();}; 
    ajax.runAJAX();
}
function callAjaxThroughForm(formId)
{
    var form  = document.getElementById(formId);
    var query = '';
    if ( form != null)
    {
        for(i=0; i<form.elements.length; i++)
        {
            if(form.elements[i].type != "checkbox" || (form.elements[i].type == "checkbox" && form.elements[i].checked == true))
            {
                query +=form.elements[i].name + "=" + form.elements[i].value;
                if ( i < form.elements.length  - 1)
                {
                    query += '&';
                }
            }
        }
    }
    callAjax('/AjaxHandler.ashx?' + query);
} 
function ajaxCallback(){
    if (ajax != null && ajax.response != null)
    {
        var wrapper = eval('(' + ajax.response + ')');
        if ( wrapper != null)
        {
            wrapper.execute();
        }
    }
}
function onEnter( evt , frm) 
{
    var keyCode = null;

    if( evt.which ) 
    {
        keyCode = evt.which;
    } 
    else if( evt.keyCode ) 
    {
        keyCode = evt.keyCode;
    }
    if( 13 == keyCode ) 
    {
        callAjaxThroughForm(frm.id);
        return false;
    }
    return true;
}
function getPosition(what, offsettype)
    {
        var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
        var parentEl=what.offsetParent;
        while (parentEl!=null)
        {
            
            if (this.ie )
            {
                if (offsettype == "left" )
                {
                    if (parentEl.style.position.toLowerCase() != "relative")
                    {
                        totaloffset=totaloffset+parentEl.offsetLeft - parentEl.style.posLeft;
                    }
                }
                else 
                {
                    if (parentEl.style.position.toLowerCase() != "relative")
                    {
                        totaloffset=totaloffset+parentEl.offsetTop - parentEl.style.posTop;
                    }
                }
            }
            else
            {
                var posLeft = 0;
                var posTop = 0;
                if (parentEl.style.left != "" && parentEl.style.left.indexOf("px") != -1)
                {
                    posLeft = parseInt(parentEl.style.left.substring(0, parentEl.style.left.indexOf("px")));
                }
                if (parentEl.style.top != "" && parentEl.style.top.indexOf("px") != -1)
                {
                    posTop = parseInt(parentEl.style.top.substring(0, parentEl.style.top.indexOf("px")));
                }
                if (parentEl.style.position.toLowerCase() != "relative")
                {
                    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop ;
                }
                else
                {
                totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop ;
                }
            }
            parentEl=parentEl.offsetParent;
        }
        return totaloffset;
    }
    function removeFloater()
    {
        var element = document.getElementById('floater');
        if ( element != null)
        {
            element.parentNode.removeChild(element);
        }
        inside= false;
        
    }
    var inside = false;
    function displayFloater(url)
    {
        inside = true;
        callAjax(url);
    }
    function addFloater (posX, posY, data) {

        
        var floater = document.getElementById('floater');
        if ( floater != null)
        {
            floater.parentNode.removeChild(floater);
        }
        floater = document.createElement('div');+
        floater.setAttribute("id", "floater");
        floater.style.position = "absolute";
        floater.style.left = posX + "px";
        floater.style.top = posY + "px";
        floater.innerHTML = data;
        if ( inside)
        {
            document.body.appendChild(floater);
        }
        
                            
    }
    var Event = {
	add: function(obj,type,fn) {
		if (obj.attachEvent) {
			obj['e'+type+fn] = fn;
			obj[type+fn] = function() { obj['e'+type+fn](window.event); }
			obj.attachEvent('on'+type,obj[type+fn]);
		} else
		obj.addEventListener(type,fn,false);
	},
	remove: function(obj,type,fn) {
		if (obj.detachEvent) {
			obj.detachEvent('on'+type,obj[type+fn]);
			obj[type+fn] = null;
		} else
		obj.removeEventListener(type,fn,false);
	}
}
function calcSureBet(m) {
    var pt = m.parentNode.parentNode.nextSibling;
    if (pt != null) {
        var tbl = pt.getElementsByTagName("TABLE");
        if (tbl != null && tbl.length > 0) {
            var rows = tbl[0].getElementsByTagName("TR");
            if (rows != null) {
                var c1 = 0;
                var c1_c = "";
                var c2 = 0;
                var c2_c = "";
                var c3 = 0;
                var c3_c = "";
                for (var x = 0; x < rows.length; x++) {
                    if (rows[x].childNodes.length > 2 && Math.round(rows[x].childNodes[2].innerText.replace(',','.')*100)/100 > c1) {
                        c1 = Math.round(rows[x].childNodes[2].innerText.replace(',', '.') * 100) / 100;
                        c1_c = rows[x].childNodes[1].innerText;
                    }
                    if (rows[x].childNodes.length > 3 && Math.round(rows[x].childNodes[3].innerText.replace(',', '.') * 100) / 100 > c2) {
                        c2 = Math.round(rows[x].childNodes[3].innerText.replace(',', '.') * 100) / 100;
                        c2_c = rows[x].childNodes[1].innerText;
                    }
                    if (rows[x].childNodes.length > 4 && Math.round(rows[x].childNodes[4].innerText.replace(',', '.') * 100) / 100 > c3) {
                        c3 = Math.round(rows[x].childNodes[4].innerText.replace(',', '.') * 100) / 100;
                        c3_c = rows[x].childNodes[1].innerText;
                    }
                }
                if (c3 < 1) {
                    wincoef = 1 / c1 + 1 / c2;
                    wincoef = 1 / wincoef / 1.05;

                    var r_td = '1: ' + c1 + ' (' + c1_c + ')<br /> 2: ' + c2 + ' (' + c2_c + ')<br /> koeficijent(-M.T. 5%): ' + Math.round(wincoef * 100) / 100;
                }
                else {
                    
                    wincoef = 1 / c1 + 1 / c2 + 1 / c3;
                    wincoef = 1 / wincoef / 1.05;
                    var r_td = '1: ' + c1 + ' (' + c1_c + ')<br /> X: ' + c2 + ' (' + c2_c + ')<br /> 2: ' + c3 + ' (' + c3_c + ')<br /> koeficijent(-M.T. 5%): ' + Math.round(wincoef * 100) / 100;

                }
                var x = getPosition(m, 'left');
                var y = getPosition(m, 'top');
                //alert(x +"," +y + '->' + r_td);
                inside = true;                 
                addFloater(x,y + 20, r_td);
            }
        }
    }

}