// Common JavaScript functions
// Author: Gerd Riesselmann
// http://www.gerd-riesselmann.net
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//



// After loading page, do what should be done

addEvent(window, 'load', initFocus);

// Ads eventhandelr to given object
function addEvent(obj, evType, fn)
{
    if (obj.addEventListener)
    {
           obj.addEventListener(evType, fn, false);
           return true;
    } 
    else if (obj.attachEvent)
    {
           var r = obj.attachEvent("on"+evType, fn);
           return r;
     } 
     else 
     {
           return false;
     }
}

// Sets focus to first input with class "focus"
function initFocus()
{
    if (findFocus('input'))
        return;
        
    if (findFocus('select'))
        return;
        
    if (findFocus('textarea'))
        return;
}

function findFocus(elementName)
{
    var inputs = document.getElementsByTagName(elementName);
    for (var i = 0; i < inputs.length; i++)
    {
        if (inputs[i].className.indexOf('focus') != -1 )
        {
            inputs[i].focus();
            return true;            
        }
    }
    return false;
}
// Drop-in content box- By Dynamic Drive
// For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
// This credit MUST stay intact for use

var ie=document.all
var dom=document.getElementById
var ns4=document.layers
var calunits=document.layers? "" : "px"

var bouncelimit=32 //(must be divisible by 8)
var direction="up"

function initbox(){
if (!dom&&!ie&&!ns4)
return
crossobj=(dom)?document.getElementById("dropin").style : ie? document.all.dropin : document.dropin
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
crossobj.top=scroll_top-250+calunits
crossobj.visibility=(dom||ie)? "visible" : "show"
dropstart=setInterval("dropin()",50)
}

function dropin(){
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
if (parseInt(crossobj.top)<80+scroll_top)
crossobj.top=parseInt(crossobj.top)+40+calunits
else{
clearInterval(dropstart)
bouncestart=setInterval("bouncein()",50)
}
}

function bouncein(){
crossobj.top=parseInt(crossobj.top)-bouncelimit+calunits
if (bouncelimit<0)
bouncelimit+=8
bouncelimit=bouncelimit*-1
if (bouncelimit==0){
clearInterval(bouncestart)
}
}

function dismissbox(){
if (window.bouncestart) clearInterval(bouncestart)
crossobj.visibility="hidden"
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}



function doPopup() {
	initbox();
}

