﻿//Copyright 2008 QuaJoo GmbH. All rights reserved.
Point.prototype.x	= null;
Point.prototype.y = null;
function Point(x,y)
{
   this.x = parseInt(x);
   this.y = parseInt(y);
}

Point.prototype.unsign = function()
{
   if(this.x < 0)this.x = 0;
   if(this.y < 0)this.y = 0;
}
Point.prototype.toString = function()
{
   return "[" + this.x + "," + this.y + "]";
}

Rec.prototype.x= null;
Rec.prototype.y= null;
Rec.prototype.w= null;
Rec.prototype.h= null;
Rec.prototype.invw= null;
Rec.prototype.invh= null;
Rec.prototype.ry= function(){return this.y+this.h;};
Rec.prototype.rx= function(){return this.x+this.w;};
function Rec(x,y,w,h)
{
   this.x = parseInt(x);
   this.y = parseInt(y);
   this.w = parseInt(w);
   this.h = parseInt(h);
   this.invw = false;
   this.invh = false;
   
   if(this.w<0)
   {
      this.x +=w;
      this.w *=-1;
      this.invw = true;
   }
   
   if(this.h<0)
   {
      this.y +=h;
      this.h *=-1;
      this.invh = true;
   }
}

Rec.prototype.setw = function(value)
{
   if(this.invw)this.x = this.x+this.w-value;
   this.w = value;
}

Rec.prototype.seth = function(value)
{
   if(this.invh)this.y = this.y+this.h-value;
   this.h = value;
}

Rec.prototype.toString = function()
{
   return "[x,y:" + this.x + "," + this.y + " w,h:"+this.w+","+this.h+"]";
}

String.format = function() 
{
    if (arguments.length == 0)
        return null;

    var str = arguments[0];

    for (var i = 1; i < arguments.length; i++) 
    {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

function digit(e) {
    return digit(e, false);
}
function digit(e, allowComma)
{
    var k = window.event ? event.keyCode : e.which;
    if (!window.event) {
        if( (k > 47 && k < 58) || k == 0 || k == 8 )
            return true;
        else if(allowComma)
            return (k == 44 || k == 46);
        else
            return false;
     }
     else {
        if (k != 44 && k != 46 && ((k < 48) || (k > 57)))
            e.returnValue = false;
    } 
}
function setGroup(it, g)
{
   var a=document.getElementsByTagName("input");if(a!=null){for(var i=0;i<a.length;i++){if(a[i].name.endsWith(g)){a[i].checked=a[i].id==it?"checked":"";}}}
}
function bkmrk(url, txt)
{
   if(document.all)window.external.AddFavorite(url,txt);
   else{setquery('tc','fav');if(typeof bknoie != 'undefined'){alert(bknoie)}else{alert('STRG + D')}}
}

function setquery(key,val)
{
    var re = new RegExp('([?|&])'+key+'=.*?(&|$)','i');
    if(self.location.search.match(re)){var s = self.location.href.replace(re,'$1'+key+"="+val+'$2');self.location = s;return;}else{self.location = self.location+(self.location.search==''?'?':'&')+key+'='+val;}
}

function setsize()
{
    var p = new Point(0,0);
    if (typeof window.innerWidth != 'undefined'){p.x=window.innerWidth;p.y=window.innerHeight;}
    else if (typeof document.documentElement!='undefined'&&typeof document.documentElement.clientWidth!='undefined'&&document.documentElement.clientWidth!=0)
    {p.y=document.documentElement.clientHeight;p.x=document.documentElement.clientWidth;}else{p.x=document.getElementsByTagName('body')[0].clientWidth;p.y=document.getElementsByTagName('body')[0].clientHeight;}
    
    return p;
}

function abspos(s, t)
{
   var pos = globalpos(s);
   $get(t).style.left=pos.x+"px";
   $get(t).style.top=pos.y+"px";
}

function globalpos(element) {
   var itm=document.getElementById(element);
   var p = new Point(0,0);
   if(itm != null && typeof(itm) != "undefined"){if (itm.offsetParent){p.x=itm.offsetLeft;p.y=itm.offsetTop;while (itm=itm.offsetParent){p.x += itm.offsetLeft;p.y += itm.offsetTop;}}}
   return p;
}

function sizepos(t,s)
{
   var ti=$get(t);var si=$get(s);ti.style.height=si.offsetHeight+"px";ti.style.width=si.offsetWidth+"px";abspos(s,t);
}

function openinfo(e,a,i,framewidth,frameheight) {
   var iinfo=$get("iinfo");var inframe=$get("inframe");var pos=getmousepos(e);
   if (iinfo != null && inframe != null) {
       inframe.src = "info.aspx?a=" + a + "&i=" + i;
       if (framewidth != null) inframe.style.width = framewidth;
       if (frameheight != null) inframe.style.height = frameheight;
       if (pos != null)
       {
           iinfo.style.left = framewidth + "px";
           iinfo.style.top = frameheight + "px";
       };
       iinfo.style.display = "block";
   }
   return false;
}

function closeinfo()
{
   var iinfo=$get("iinfo");if(iinfo != null){iinfo.style.display="none";}
}

function getmousepos(e)
{
   var pos=new Point(0,0);
   pos.x=document.all?(e.clientX != null?e.clientX+document.body.scrollLeft:0):e.pageX<0?0:e.pageX;
   pos.y=document.all?(e.clientY != null?e.clientY+document.body.scrollTop:0):e.pageY<0?0:e.pageY;
   return pos;
}

function emobf(i,one, two)
{ document.getElementById(i).href = 'mailto:' + one + two; }

function stretch(name, ignorewidth)
{
   var size = getwindowsize(ignorewidth);
   
   var stretchtarget = document.getElementById(name);
   if (!ignorewidth) stretchtarget.style.width = size.x + "px";
   stretchtarget.style.height = size.y + "px";
}

function getwindowsize(ignorewidth, ignorescroll) {

   var pointSize = new Point(0,0);
   if (typeof window.innerWidth != 'undefined')
   {
      if(!ignorewidth) pointSize.x = Math.max(window.innerWidth, document.body.scrollWidth);
      pointSize.y = ignorescroll ? window.innerHeight : Math.max(window.innerHeight, document.body.scrollHeight);
  }
   else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
   {
       if(!ignorewidth) pointSize.x = Math.max(document.documentElement.clientWidth, document.body.scrollWidth);
       pointSize.y = ignorescroll? document.documentElement.clientHeight : Math.max(document.documentElement.clientHeight, document.body.scrollHeight);
   }
   else
   {
      if(!ignorewidth) pointSize.x = Math.max(document.getElementsByTagName('body')[0].clientWidth, document.body.scrollWidth);
      pointSize.y = ignorescroll ? document.getElementsByTagName('body')[0].clientHeight : Math.max(document.getElementsByTagName('body')[0].clientHeight, document.body.scrollHeight);
   }
   
   return pointSize;
}

function open(bg, item, ignorewidth)
{
   stretch(bg,ignorewidth);
   $get(bg).style.display = "block";
   $get(item).style.display = "block";
}

function close(bg, item)
{
   $get(bg).style.display = "none";
   $get(item).style.display = "none";
}

function switchToPassword(el) {
    if(el.type != 'password'){
    if (document.all) {
        var nEl = el.cloneNode(false);
        nEl.type = 'password';
        el.parentNode.replaceChild(nEl, el);
        setTimeout('document.getElementById("'+nEl.id+'").focus();', 10);
        return nEl;
    } else el.type = 'password';
    }
}