//////////////////////////////////////////////////
//                                              //
// Filename: faq.js                             //
// Purpose: bind onclick events for each        //
// FAQ question                                 //
// Author: James Radford BSc                    //
// Creation date: 30/01/2008                    //
//                                              //
//////////////////////////////////////////////////

window.addEvent('domready', function() {

    // loop through all hyperlinks within the FAQ div
    // bind event for each
    
    $$('.faq a').each(function(el, i) {
		el.addEvent('click', function(e) {
		    toggleFAQ('answer'+i);
        });     	    
    });
    
    $$('.technical-help .trig').each(function(el, i) {
        el.addEvent('click', function(e) {
            toggleHelp("boxbody"+i);
        });     	    
    });


    // left nav roll over events for 'apply for an account'

    $$('.applyAcount').addEvent('mouseover', function(e) {
        this.src = 'images/button-apply4account-over.gif';        
    });
    
    $$('.applyAcount').addEvent('mouseout', function(e) {
        this.src = 'images/button-Apply4Account-navbar.gif';        
    });
    
    
    // appy for an account page events for button
    
    $$('.apply_acount').addEvent('mouseover', function(e) {
        this.src = 'images/1button-Apply4Account-over.gif';                
    });
    
    $$('.apply_acount').addEvent('mouseout', function(e) {
        this.src = 'images/button-Apply4Account.gif';        
    });
    
    
}); 



// control the css 'display' setting  
// 1. hide the default text
// 2. show the corresponding answer for the selected question
// note: cms does not allow id's to be used within markup, hence using classes

function toggleFAQ(theStyle) {
    var myclass = new RegExp('\\b'+theStyle+'\\b');
    var elem = document.getElementsByTagName('*');
    var name;
    
    for (var i = 0; i < elem.length; i++) {
        name = elem[i].className;
        
        // hide default text
        if(name.search('answer') != -1) {
            if(name.search('answer-default') != -1) {
                elem[i].style.display = "none";
            }
            elem[i].style.display = "none";
        }            
        
        // show answer
        if (myclass.test(name)) {
            elem[i].style.display = "block";
        }  
    }        
}


function toggleHelp(theStyle) {
    var myclass = new RegExp('\\b'+theStyle+'\\b');
    var elem = document.getElementsByTagName('*');
    var name;
    
    for (var i = 0; i < elem.length; i++) {
        name = elem[i].className;
        
        // show help
        if (myclass.test(name)) {
            if(elem[i].style.display != "block") {
                elem[i].style.display = "block";
            }
            else {
                elem[i].style.display = "none";
            }
        }             
    }        
}