function twoTabChange(object,tab)
{
    var h3 = object.parentNode;
    var div = h3.parentNode;
    var step = (navigator.userAgent.indexOf("Firefox") != -1 ? 2 : 1);
    if(tab == "left-tab")
    {            
        div.childNodes[step * 1 - 1].className = "forums-tab current";        
        div.childNodes[step * 2 - 1].className = "iframe-content current";
        div.childNodes[step * 3 - 1].className = "blogs-tab";
        div.childNodes[step * 4 - 1].className = "iframe-content notcurrent";
    }
    else if(tab == "right-tab")
    {
        div.childNodes[step * 1 - 1].className = "forums-tab";    
        div.childNodes[step * 2 - 1].className = "iframe-content notcurrent";
        div.childNodes[step * 3 - 1].className = "blogs-tab current";
        div.childNodes[step * 4 - 1].className = "iframe-content current";
    }
}

function over(object)
{
    object.style.textDecoration = "underline";
}

function out(object)
{
    object.style.textDecoration = "none";
}

function threeTabChange(object, tab)
{
    var h3 = object.parentNode;
    var div = h3.parentNode;
    var step = (navigator.userAgent.indexOf("Firefox") != -1 ? 2 : 1);
    if (tab == "tab1")
    {
        div.childNodes[step * 1 - 1].className = "tab1-tab current";        
        div.childNodes[step * 2 - 1].className = "iframe-content current";
        div.childNodes[step * 3 - 1].className = "tab2-tab";
        div.childNodes[step * 4 - 1].className = "iframe-content notcurrent";
        div.childNodes[step * 5 - 1].className = "tab3-tab";
        div.childNodes[step * 6 - 1].className = "iframe-content notcurrent";
    }
    else if (tab == "tab2")
    {
        div.childNodes[step * 1 - 1].className = "tab1-tab";        
        div.childNodes[step * 2 - 1].className = "iframe-content notcurrent";
        div.childNodes[step * 3 - 1].className = "tab2-tab current";
        div.childNodes[step * 4 - 1].className = "iframe-content current";
        div.childNodes[step * 5 - 1].className = "tab3-tab";
        div.childNodes[step * 6 - 1].className = "iframe-content notcurrent";
    }
    else if (tab == "tab3")
    {
        div.childNodes[step * 1 - 1].className = "tab1-tab";        
        div.childNodes[step * 2 - 1].className = "iframe-content notcurrent";
        div.childNodes[step * 3 - 1].className = "tab2-tab";
        div.childNodes[step * 4 - 1].className = "iframe-content notcurrent";
        div.childNodes[step * 5 - 1].className = "tab3-tab current";
        div.childNodes[step * 6 - 1].className = "iframe-content current";
    }
}

/* Used for switching between large tabs e.g. on the Tab - List Overview page */
function fourTabChange(object, tab, contentId)
{
    var h3 = object.parentNode;
    var div = h3.parentNode;
    var contentdiv;
    var currentContentViewId;
    var step = (navigator.userAgent.indexOf("Firefox") != -1 ? 2 : 1);
    /* Clean up */
    div.childNodes[step * 1 - 1].className = "notcurrent";        
    if (div.childNodes[step * 2 - 1].className.indexOf("no-tab") == -1) {
        div.childNodes[step * 2 - 1].className = "notcurrent";
	}
    if (div.childNodes[step * 3 - 1].className.indexOf("no-tab") == -1) {
        div.childNodes[step * 3 - 1].className = "notcurrent";
    }
    if (div.childNodes[step * 4 - 1].className.indexOf("no-tab") == -1) {
        div.childNodes[step * 4 - 1].className = "no-border notcurrent";
    }
    contentdiv = div.childNodes[step * 5 - 1];
    for (i = 1; i < 5; i++) contentdiv.childNodes[step * i - 1].className = "notcurrent";
    /* Display selected content */
    if (tab == "tab1") div.childNodes[step * 1 - 1].className = "current";
    else if (tab == "tab2") div.childNodes[step * 2 - 1].className = "current";
    else if (tab == "tab3") div.childNodes[step * 3 - 1].className = "current";
    else if (tab == "tab4") div.childNodes[step * 4 - 1].className = "no-border current";
    contentdiv.childNodes[step * contentId - 1].className = "current";
}

/* used for formatting rows in the auto completer */
function formatItem(row) {
    if (row.length == 1)
        return "<a class=\"close\" href=\"#\">Close</a>" + row[0];
    else
        return "<a href=" + row[1] + ">" + row[0] + "</a>";
}

/* the function called when the autocomplete item is chosen */
function selectItem(li) {
    if (li.extra) {
        document.location.href = li.extra[0];
    }
}

function clearTextField(elem)
{
   if (elem != null && elem.value != null && elem.value == 'Keyword Search')
   {
     elem.value = '';
    }
}

function validatePostcode(e)
{
    var keynum = (window.event ? e.keyCode : (e.which ? e.which : 0));
    var keychar = String.fromCharCode(keynum);
    var numcheck = /\d/;
    return keynum < 32 || numcheck.test(keychar);
}
    
function quickSearch(url)
{
    var $results = $("#keyword-results");
    $results.load(url, {}, formatQuickSearch);
    $results.css("visibility","visible");
    var obj = $("#search-text")[0];
    curLeft = 0;
    curTop = 0;
    if (obj.offsetParent) {
        curLeft = obj.offsetLeft;
        curTop = obj.offsetTop + obj.offsetHeight;
        while (obj = obj.offsetParent) {
            curLeft += obj.offsetLeft;
            curTop += obj.offsetTop;
        }
    }
    var $div = $("div.select-free");
    $div[0].style.left = curLeft + "px";
    $div[0].style.top = curTop + "px";
}

function formatQuickSearch(text)
{
    $("#keyword-results").html("<ul><li><a href=\"javascript:closeSearch()\" class=\"close\">Close</a></li>" + 
        text.replace(/\s*(.+)\s+\|\s+(.+)\s+NEWLINE/g, "<li><a href=\"$2\">$1</a></li>") + "</ul>");
}
    
function closeSearch()
{
    var $results = $("#keyword-results");
    $results.css("visibility","hidden");
    $results.html("");
    $("#search-text")[0].focus();
}

