﻿    // Random number generator 
    function rnd(max) { 
        var rndnum = max * Math.random() 
        rndnum = Math.ceil (rndnum) 
        return rndnum 
    } 

    function rndFunction() { 
        var maxr = 4 
        var rand = new Array(maxr) 

        // set up array 
        var str = "" 
        
        document.getElementById('random').innerHTML =  str;
        
        for (i = 1; i <= maxr; i++) { 
            
                var tmp = 0;
                
                while (tmp == 0)
                {
                    tmp = rnd(26); //26
                    for (j=0; j<rand.length; j++)
                    {
                        if (rand[j] == tmp)
                        {
                            tmp=0;
                            break;
                        }
                    }
                }
                
                rand [i] = tmp;
                str = rand [i];

                switch (str) {
                case 1: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=28&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Accounting, Auditing & Finance</a></li>"; break;
                case 2: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=29&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Advertising, Marketing & Public</a></li>"; break;
                case 3: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=7793&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Aerospace & Defence</a></li>"; break;
                case 4: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=30&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Arts, Entertainment & Media</a></li>"; break;
                case 5: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=31&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Banking & Financial Services</a></li>"; break;
                case 6: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=49&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Business Intelligence & Market Research</a></li>"; break;
                case 7: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=41&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Community, Social Services & Non-profit</a></li>"; break;
                case 8: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=1812&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Construction, Property & Surveying</a></li>"; break;
                case 9: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=62&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Consumer Products & FMCG</a></li>"; break;
                case 10: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=58&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Education</a></li>"; break;
                case 11: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=1455&utm_source=TOL&utm_medium=Widget&utm_content=1'  class='link-666' target='blank'>Energy, Utilities & Environmental Services</a></li>"; break;
                case 12: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=33&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Engineering</a></li>"; break;
                case 13: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=55&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Hospitality, Travel & Tourism</a></li>"; break;
                case 14: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=53&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Internet, eCommerce & New Media</a></li>"; break;
                case 15: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=35&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>IT & Telecommunications</a></li>"; break;
                case 16: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=37&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Legal</a></li>"; break;
                case 17: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=34&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Local Government & Civil Service</a></li>"; break;
                case 18: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=50&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Logistics, Transport, Purchasing & Supply</a></li>"; break;
                case 19: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=38&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Management Consultancy</a></li>"; break;
                case 20: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=39&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Manufacturing</a></li>"; break;
                case 21: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=43&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Medical & Pharmaceutical</a></li>"; break;
                case 22: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=44&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Publishing, Journalism & Languages</a></li>"; break;
                case 23: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=32&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Recruitment</a></li>"; break;
                case 24: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=45&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Retail, Buying & Merchandising</a></li>"; break;
                case 25: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=48&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Science & Research</a></li>"; break;
                case 26: document.getElementById('random').innerHTML += "<li><a href='http://www.milkround.com/search-browse.aspx?industryid=7794&utm_source=TOL&utm_medium=Widget&utm_content=1' class='link-666' target='blank'>Uniformed Services </a></li>"; break;
                default: ;
          }  
        } 
    }
    
    //The overall initialisation function
    function toggle(obj)
    {            
        disableLists(obj.id);
        enableList(obj);
        displayList(obj.id);
        rndFunction(); 
    }
    
    //Enables an individual link
    function enableList(obj)
    {
        obj.className = 'highlighted';
        obj.style.color = '#0066cc';
        displayList(obj.id);
        document.getElementById(obj.id).removeAttribute("href"); 
    }
    
    //Resets all the link controls the standard grey background which is un-highlighted
    function disableLists(id)
    {
        var anchorLinks = document.getElementsByTagName('a');
        
        for(x=0; x < anchorLinks.length; x++)
        {
            if(anchorLinks[x].id.indexOf('-link') != -1)
            {                    
                anchorLinks[x].href = '#';                        
                anchorLinks[x].className = 'link-666';
                anchorLinks[x].style.backgroundColor = '#d9d9d9';
                anchorLinks[x].style.borderBottom = "1px solid #999999"; 
                anchorLinks[x].style.MarginBottom = "-1px"; 
            }
        }  
     
         id = id.substring(0,4) + '-link';
         document.getElementById(id).style.borderBottom = "1px solid White";      
                  
    }
    
    //Shows or hides the list dependent on what the user has selected
    function displayList(id)
    {
        var divLinks = document.getElementsByTagName('div');
       
        for(x=0; x < divLinks.length; x++)
        {
           if(divLinks[x].id.indexOf('-box') != -1)
           {    
              divLinks[x].style.display = 'none';
           }
        } 
        
        id = id.substring(0,4) + '-box'
        document.getElementById(id).style.display = 'block';
       
    }
    
    //manages the mouse out and mouse over events for the anchor links
    function onMouseToggle(obj, color, bgColor)
    {
        if(obj.className != 'highlighted')
        {
            obj.style.color = color;
            obj.style.backgroundColor = bgColor;
        }
    }