

var startList = function() {
    if (document.all&&document.getElementById) {
        navRoot = document.getElementById("nav");
        if(navRoot) setlist(navRoot);
        
        
    }
};

var faqStart = function() {
    var dl_array = document.getElementsByTagName("dl");
    for (i=0; i<dl_array.length; i++) {
        if(dl_array[i].className == 'faq') {
            setClick(dl_array[i]);
        }
    }
};

var switcherStart = function() {
    var switcher = document.getElementById("switcher");
    if(switcher) {
        switcher.onchange = function() {
            if(this.options[this.selectedIndex].value.length > 0)
                document.location.href = this.options[this.selectedIndex].value;
        };
    }
};


var toolStart = function() {
    if(document.all)
    {
        var a_array = document.getElementsByTagName("a");
        for (i=0; i<a_array.length; i++) {
            if(a_array[i].getAttribute('rel') && a_array[i].rel == 'tool') {
                setstatus(a_array[i]);
            }
        }
    }
};  

//enable return false on links that use popup script
var linkStart = function() {
    var a_array = document.getElementsByTagName("a");
    for (i=0; i<a_array.length; i++) {
        if(a_array[i].getAttribute('rel') && (a_array[i].rel.indexOf('popup') >= 0 || a_array[i].rel.indexOf('print') >= 0 )) {
            a_array[i].onclick = function() {return false;}
        }
        if(a_array[i].className == 'objective') {
            a_array[i].onclick = function() {
                objective(this);
                return false;
            };
        }
    }
};


function setlist(element) {
    for (i=0; i<element.childNodes.length; i++) {
        node = element.childNodes[i];
        if (node.nodeName=="LI") {
            setitem(node);
        }
    }

}

function setClick(element) {
    for (k=0; k<element.childNodes.length; k++) {
        node = element.childNodes[k];
        if (node.nodeName=="DT") {
            node.onclick=function() { faq(this); };
        }
        if (node.nodeName=="DD") {
            addClass(node,'answer');
        }
    }
}

function setitem(element) {
    element.onmouseover=function() {
        addClass(this,"over");
        selectTypes("hidden");
    };
    element.onmouseout=function() {
        removeClass(this,"over");
        selectTypes("visible");
    };
}

function setstatus(element) {
    element.onmouseover=function() {
        window.status = element.getAttribute('title');
        return true;
    };
    element.onmouseout=function() {
        window.status = '';
        return true;
    };
}

var loginModule = {
    form:false,
    username:false,
    password:false,
    button:false,
    init: function() {
        loginModule.form = document.getElementById('login');
        loginModule.username = document.getElementById('username');
        loginModule.password = document.getElementById('password');
        loginModule.button = document.getElementById('login_submit');
        
        if(loginModule.form)
        {
            
            loginModule.form.onsubmit = loginModule.onSubmit;
            if(loginModule.username) loginModule.username.onkeydown = loginModule.enterOnFrom;
            if(loginModule.password) loginModule.password.onkeydown = loginModule.enterOnFrom;
            if(loginModule.button) loginModule.button.onclick = function() { loginModule.onSubmit(); return false;}
        }
        
        if(document.getElementById("user_tryagain")) {
            var flick = function() {
                document.getElementById("user").style.display = 'block';
                document.getElementById("usererror").style.display = 'none';
                loginModule.username.focus();
                return false;
            };
            //loginModule.timeout = window.setTimeout(flick,10000);
            document.getElementById("user_tryagain").onclick = flick;
            //if(document.getElementById("usererror").style.display == 'block')
            //  document.getElementById("user_tryagain").focus();
        }
        
    },
    enterOnFrom: function(event){
        var key = window.event ? window.event.keyCode : event.keyCode;
        if(key == 13) loginModule.onSubmit();
    },
    validate: function() {
        if((loginModule.username && loginModule.username.value == "") || (loginModule.password && loginModule.password.value == "")) {
            if(document.getElementById("user_tryagain")) {
                var flick = function() {
                    document.getElementById("user").style.display = 'block';
                    document.getElementById("usererror").style.display = 'none';                    
                    if(loginModule.password.value == "") { loginModule.password.focus();}
                    if(loginModule.username.value == "") { loginModule.username.focus();}                   
                    return false;
                };
                document.getElementById("user_tryagain").onclick = flick;
                document.getElementById("user").style.display = 'none';
                document.getElementById("usererror").style.display = 'block';
                document.getElementById("user_message").innerHTML = "Please enter the required fields";
                //if(document.getElementById("usererror").style.display == 'block')
                    //document.getElementById("user_tryagain").focus();
            }
            return false;
        }
        
        return true;
    },
    onSubmit: function() { if(loginModule.validate()) loginModule.form.submit();}
}

/*
addLoadListener(startList);
addLoadListener(faqStart);
addLoadListener(switcherStart);
addLoadListener(toolStart);
addLoadListener(linkStart);
addLoadListener(loginModule.init);
*/

function addLoadListener(fn)
{
    if (typeof window.addEventListener != 'undefined') { window.addEventListener('load', fn, false); }
    else if (typeof document.addEventListener != 'undefined') { document.addEventListener('load', fn, false); }
    else if (typeof window.attachEvent != 'undefined') { window.attachEvent('onload', fn); }
    else
    { var oldfn = window.onload;
      if (typeof window.onload != 'function') { window.onload = fn;}
      else{ window.onload = function() { oldfn();   fn();}; } }
}

function domready() {
	startList();
	faqStart();
	switcherStart();
	toolStart();
	linkStart();
	loginModule.init();
}

function selectTypes(value) {
    if(document.all) {
        var select_array  = document.getElementsByTagName('select');
        for (i=0; i<select_array.length; i++) {
            if(select_array[i]) select_array[i].style.visibility = value;
        }
    }
}





