function getElement(name)
{
    if (document.getElementById)
    return document.getElementById(name)
    else if (document.all)
    return document.all.name
    return false;
}

function getMousePosElement(evt, eid)
{
    if (typeof evt != "undefined")
    {
        if (evt.pageX)
            x = evt.pageX;
        else if (evt.clientX)
            x = evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        else
            x = false;
        if (evt.pageY)
            y = evt.pageY;
        else if (evt.clientY)
            y = evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
        else y = null;
        e = getElement('scrollThumbs');
        CalculatedTotalOffsetLeft = 0;
        CalculatedTotalOffsetTop = 0;
        while (e.offsetParent)
        {
            CalculatedTotalOffsetLeft += e.offsetLeft;
            CalculatedTotalOffsetTop += e.offsetTop;
            e = e.offsetParent ;
        }

        x -= CalculatedTotalOffsetLeft;
        y -= CalculatedTotalOffsetTop;
        //getElement('info').innerHTML = (x+'x'+y+'<br>'+CalculatedTotalOffsetLeft+'x'+CalculatedTotalOffsetTop);
    }
    else if (evt=window.event)
    {
        x = evt.clientX;
        y = evt.clientY;
        e = getElement('scrollThumbs');
        var CalculatedTotalOffsetLeft = 0;
        var CalculatedTotalOffsetTop = 0;
        if(o=e)
        {
            do
            {
                CalculatedTotalOffsetLeft += o.offsetLeft;
                o = o.offsetParent;
            } while(o)
        }
        if(o=e)
        {
            do
            {
                CalculatedTotalOffsetTop += o.offsetTop;
                o = o.offsetParent;
            } while(o)
        }

        x -= CalculatedTotalOffsetLeft;
        y -= CalculatedTotalOffsetTop;
        y += truebody().scrollTop;
        //getElement('info').innerHTML = (x+'x'+y+'<br>'+CalculatedTotalOffsetLeft+'x'+truebody().scrollTop);
    }
    return {'x':x, 'y':y};
}

function handleMultiBlockInput (blockId, id)
{
    if ( vstup = getElement(blockId) )
    {
        var newCopy = vstup.childNodes[0].cloneNode(true);
        fList = newCopy.getElementsByTagName('INPUT');
        for (var i = 0; i < fList.length; i++)
            if ( fList[i].type == 'text' || fList[i].type == 'password' || fList[i].type == 'file' )
                if (fList[i].type == 'file')
                {
                    var newInput = document.createElement('input');
                    newInput.type = 'file';
                    newInput.name = fList[i].name;
                    newInput.id = fList[i].id;
                    newInput.className = fList[i].className;
                    newInput.onchange = fList[i].onchange;
                    fList[i].parentNode.replaceChild(newInput, fList[i]);
                }
                else if ( fList[i].parentNode )
                    fList[i].value = '';
        fList = newCopy.getElementsByTagName('TEXTAREA');
        for (var i = 0; i < fList.length; i++)
            if ( fList[i].parentNode )
                fList[i].value = '';
    }
    else return false;
    if ( typeof(newCopy) == 'undefined' )
        return false;
    for (var x = 0; vstup.childNodes[x]; x++)
    {
        rList = vstup.childNodes[x].getElementsByTagName('INPUT');
        if (typeof(id)=='undefined')
            id = '';
        exp = RegExp('' + id + '.*', 'i');
        for (var i=0; i<rList.length; i++)
        {
            if (rList[i].type=='file' || rList[i].type=='text' || rList[i].type=='select')
            {
                if (rList[i].id.toString().match(exp) && rList[i].value=='')
                {
                    vstup.removeChild(vstup.childNodes[x]);
                    x--;
                }
            }
        }
    }
    vstup.appendChild(newCopy);
}

function handleMultiBlockInputS (blockId, id)
{
    if ( vstup = getElement(blockId) )
    {
        var newCopy = vstup.childNodes[0].cloneNode(true);
        fList = newCopy.getElementsByTagName('SELECT');
        for (var i = 0; i < fList.length; i++)
            if ( fList[i].type == 'text' || fList[i].type == 'password' || fList[i].type == 'file' )
                if (fList[i].type == 'file')
                {
                    var newInput = document.createElement('input');
                    newInput.type = 'file';
                    newInput.name = fList[i].name;
                    newInput.id = fList[i].id;
                    newInput.className = fList[i].className;
                    newInput.onchange = fList[i].onchange;
                    fList[i].parentNode.replaceChild(newInput, fList[i]);
                }
                else if ( fList[i].parentNode )
                    fList[i].value = '';
        fList = newCopy.getElementsByTagName('TEXTAREA');
        for (var i = 0; i < fList.length; i++)
            if ( fList[i].parentNode )
                fList[i].value = '';
    }
    else return false;
    if ( typeof(newCopy) == 'undefined' )
        return false;
    for (var x = 0; vstup.childNodes[x]; x++)
    {
        rList = vstup.childNodes[x].getElementsByTagName('SELECT');
        if (typeof(id)=='undefined')
            id = '';
        exp = RegExp('' + id + '.*', 'i');
        for (var i=0; i<rList.length; i++)
        {
            if (rList[i].type=='file' || rList[i].type=='text' || rList[i].type=='select-one')
            {
            //alert(rList[i].value);
                if (rList[i].id.toString().match(exp) && rList[i].value=='')
                {
                    vstup.removeChild(vstup.childNodes[x]);
                    x--;
                }
            }
        }
    }
    vstup.appendChild(newCopy);
}

function unBlurAllLinks()
{
    rList = document.getElementsByTagName('A');
    for (var i = 0; i < rList.length; i++)
    {
        rList[i].onfocus = new Function('if (this.blur) this.blur();');
    }
}

function toggle()
{
	for ( var i=0; i < arguments.length; i++ )
    {
        if ( e = getElement(arguments[i]) )
        {
            e.style.display = ((e.style.display == 'none') || ((e.style.display=='') && (e.offsetWidth==0))) ? 'block' : 'none';
        }
	}
}

function wMail(login, domain, link, name)
{
    if (link)
        document.write('<a href="mailto:'+login+'@'+domain+'">'+((name)?name:login+'@'+domain)+'</a>');
    else
        document.write(login+'@'+domain);
}

function preloadImage()
{
    images = new Array();
	for ( var i=0; i < arguments.length; i++ )
    {
        images[i] = new Image(25, 25);
        images[i].src = dirImages + arguments[i];
        images[i].onerror = onerror;
	}
}

function trySubmit (id)
{
    if ( form = getElement(id) ) form.submit();
}

function unBlur(element)
{
    if ( element.blur ) element.blur();
}

function findPosX(obj) {
  var curleft = 0;

  if(obj.offsetParent) {
    while(1) {
      curleft += obj.offsetLeft;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;
    }
  } else if(obj.x) {
    curleft += obj.x;
  }

  obj.style.position = "static";

  return curleft;
}

function findPosY(obj) {
  var curtop = 0;

  if(obj.offsetParent) {
    while(1) {
      curtop += obj.offsetTop;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;
    }
  } else if(obj.y) {
    curtop += obj.y;
  }

  return curtop;
}

function findPos(obj) {
  var left = findPosX(obj);
  var top = findPosY(obj);

  return [left , top];
}

function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oElement.x, oElement.y ];
  }
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}


var tempMouseX = 0
var tempMouseY = 0

function getMouseXY(e) {
    var IE = document.all?true:false
    //if (!IE) document.captureEvents(Event.MOUSEMOVE)
    
    if (IE) { // grab the x-y pos.s if browser is IE
        ScrollTop = document.body.scrollTop;
        if (ScrollTop == 0)
        {
            if (window.pageYOffset)
                ScrollTop = window.pageYOffset;
            else
                ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
        }
        //alert(ScrollTop);
        tempMouseX = event.clientX + document.body.scrollLeft
        tempMouseY = event.clientY + ScrollTop
    } else {  // grab the x-y pos.s if browser is NS
        tempMouseX = e.pageX
        tempMouseY = e.pageY
    }  
    // catch possible negative values in NS4
    if (tempMouseX < 0){tempMouseX = 0}
    if (tempMouseY < 0){tempMouseY = 0}  
    // show the position values in the form named Show
    // in the text fields named MouseX and MouseY
    //document.Show.MouseX.value = tempX
    //document.Show.MouseY.value = tempY
    return true
}

function setDefaultValue(eId, val)
{
    if ((e=getElement(eId)) && typeof(e.value)!='undefined')
    {
        if (e.value=='')
            e.value = val;
        e.defaultvalue = val;
        e.onfocus = function() {
            if (this.value==this.defaultvalue)
                this.value = '';
            else
                this.oldvalue = this.value;
        };
        e.onblur = function() {
            if (this.value=='')
                this.value = (typeof(this.oldvalue)!='undefined') ? this.oldvalue : this.defaultvalue;
        };
    }
}
