    var menuOpened = false;
    var subcatMenuOpened = false;
    var subcat2MenuOpened = false;
    var lastParam = '';
    var fixedElement = '';
    
    function openWindow(url)
    {
       window.open(url, "_blank");
    }
    
    function setTitle(id, name)
    {
        if(name != "Primary" && name != "")
        {
            document.getElementById("title1").innerHTML = name;
            document.getElementById("title1").style.color = "#B5B5B5";
            document.getElementById("catParam").innerHTML = '<input type="hidden" name="category" value="' + name + '">';
            
            document.getElementById("menu2").innerHTML = '';
            
            for(i = 0; i < catList[id].length; i++)
            {
                document.getElementById("menu2").innerHTML += '<li onclick="SetSubcatTitle(' + id + ',' + i + ',\'' + catList[id][i]["name"] + '\'); return false;" style="width: 240px; padding-left: 4px;" id="' + catList[id][i]["id"] + '"><span style="font-size: 16px; color: #656565">' + catList[id][i]["name"] + '</span></li>\n';
            }
            
            document.getElementById("title2").innerHTML = "Secondary";
            document.getElementById("title3").innerHTML = "Tertiary";
        }
    }

    function SetSubcatTitle(top_id, id, name)
    {
        document.getElementById("title2").innerHTML = name;
        document.getElementById("subcatParam").innerHTML = '<input type="hidden" name="subcategory" value="' + name + '">';

        document.getElementById("menu3").innerHTML = '';
        
        for(i = 0; i < catList[top_id][id]["subcats"]["count"]; i++)
//        for(i = 0; i < 2; i++)
        {
            var cat = catList[top_id][id]["subcats"][i];
                
            document.getElementById("menu3").innerHTML += '<li onclick="SetSubcat2Title(' + cat["id"] + ',\'' + cat["name"] + '\'); return false;" style="width: 240px; padding-left: 4px;" id="' + cat["id"] + '"><span style="font-size: 16px; color: #656565">' + cat["name"] + '</span></li>\n';
        }        
/*        
        if (typeof catList[top_id][id]['subcategories'] != 'undefined')
        {
            for(i = 0; i < catList[top_id][id]['subcategories'].length; i++)
            {
                var cat = catList[top_id][id]['subcategories'][i];
                
                document.getElementById("menu3").innerHTML += '<li onclick="SetSubcat2Title(' + cat["id"] + ',\'' + cat["name"] + '\'); return false;" style="width: 240px; padding-left: 4px;" id="' + cat["id"] + '"><span style="font-size: 16px; color: #656565">' + cat["name"] + '</span></li>\n';
            }
        }
*/      
        document.getElementById("title3").innerHTML = "Tertiary";
        
        document.getElementById("menu").style.display = "none";
        menuOpened = false;
    }
    
    function SetSubcat2Title(id, name)
    {
        document.getElementById("title3").innerHTML = name;
        document.getElementById("subcat2Param").innerHTML = '<input type="hidden" name="subcategory2" value="' + name + '">';
        
        document.getElementById("menu").style.display = "none";
        document.getElementById("menu2").style.display = "none";
        menuOpened = false;
        subcatMenuOpened = false;
    }
    
    
    function ShowMenu()
    {
        if(menuOpened == false)
        {
            document.getElementById("menu").style.display = "block";
            menuOpened = true;
        }
        else
        {
            document.getElementById("menu").style.display = "none";

            menuOpened = false;
        }
    }
    
    function showPopup(type, url)
    {
        idSpacer    = document.getElementById("divSpacer");
        id_flow     = document.getElementById("wrapJsiBox");
        idForm      = document.getElementById("jsiMainBox");
        idContent   = document.getElementById("popupContent");
    
        if (type == "video")
        {
            video = "<iframe src='http://geniusfind.com/video_iframe.php?url="+ escape(url) +"' width='485' height='400' NORESIZE frameborder='no' scrolling='no'/>";
            idContent.innerHTML = video;
            idForm.style.width = 485;
        }
        if (type == "image")
        {
            idContent.innerHTML = "<img src='" + url +"' height='400' onload='document.getElementById("+"\"jsiMainBox\""+").style.width=this.width;'>";
        }
        
        id_flow.style.height = idSpacer.offsetTop + 10;
        id_flow.style.display = '';
        
        idForm.style.left = (document.body.clientWidth / 2 - 300) + "px";
        idForm.style.top = (document.body.scrollTop + document.body.clientHeight / 2 - 194) + "px";
        idForm.style.display = '';
    }   
    
    function sendContactForm(frm, root)
    {
        var isNameCorrect    = true;
        var isEmailCorrect   = true;
        var isCommentCorrect = true;
        var isCaptchaCorrect = true;
        
        var fields = new Array();
        var errors = new Array();
        fields["name"]     = "name-field";
        errors["name"]     = "this information is required";
        fields["email"]    = "email-field";
        errors["email"]    = "please enter valid address";
        fields["comments"] = "comments-field";
        errors["comments"] = "this information is required";
        fields["captcha"]  = "captcha-field";
        errors["captcha"]  = "please try again";
        
        if (frm.name.value == "")
        {
            isNameCorrect = false;
        }
        if (frm.email.value == "" || !(/^[^@]+@[^@\.]+\.[^@]+$/.test(frm.email.value)))
        {
            isEmailCorrect = false;
        }
        if (frm.comments.value == "")
        {
            isCommentCorrect = false;
        }
        if (frm.captcha.value.toLowerCase() != getURL(root + "support/captcha_current.php"))
        {
            isCaptchaCorrect = false;
        }
        
        if (isNameCorrect && isEmailCorrect && isCommentCorrect && isCaptchaCorrect)
        {
            frm.submit();
        }
        else
        {
            var obj = document.getElementById("error-message");
            obj.innerHTML = '<b style="color: #ff0000;">Please check the errors below and try again.<br><br></b>';
            
            showFieldStatus(fields["name"], errors["name"], isNameCorrect, root);
            showFieldStatus(fields["email"], errors["email"], isEmailCorrect, root);
            showFieldStatus(fields["comments"], errors["comments"], isCommentCorrect, root);
            showFieldStatus(fields["captcha"], errors["captcha"], isCaptchaCorrect, root);
        }
    }
    
    function showFieldStatus(id, error, field_status, root)
    {
        var imgs = new Array();
        imgs["ok"]        = new Image;
        imgs["ok"].src    = root + "images/ok_img.gif";
        imgs["error"]     = new Image;
        imgs["error"].src = root + "images/error_img.gif";
        
        var obj = document.getElementById(id);
        if (field_status)
        {
            obj.innerHTML = '<img src="' + root + 'images/ok_img.gif" width="22" height="21" alt="" />';
        }
        else
        {
            obj.innerHTML = '<img src="' + root + 'images/error_img.gif" width="22" height="22" alt="" style="float: left;" />&nbsp;&nbsp;' + error;
        }
    }

    function getURL(url)
    {
        var request = false;
    
        if (window.XMLHttpRequest)
        {
            request = new XMLHttpRequest();
        }
        else
        {
            if (window.ActiveXObject)
            {
                try
                {
                    request = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                    try
                    {
                        request = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    catch (e)
                    {
                    }
                }
            }
        }
    
        if (request)
        {
            request.open("GET", url, false);
            request.send(null);
            if (request.status == 200)
            {
                var data = request.responseText;
                return data;
            }
        }
    }

    function SetMenu(param)
    {
        fixedElement = param;
        
        document.getElementById("Web_img").style.display = "none";
        document.getElementById("Images_img").style.display = "none";
        document.getElementById("Videos_img").style.display = "none";
        document.getElementById("Blog_img").style.display = "none";
        document.getElementById("Directory_img").style.display = "none";
        
        document.getElementById(param + "_img").style.display = "";
        
        document.getElementById("searchParam").innerHTML = "<input type=\"hidden\" name=\"search\" value=\"" + param + "\">";
    }
    
    function SetMenuElementOn(param)
    {
        document.getElementById(param + "_img").style.display = "";
    }
    
    function SetMenuElementOff(param)
    {
        if (param != fixedElement)
           document.getElementById(param + "_img").style.display = "none";
    }
    
    function ShowSubcatDropdown()
    {
        document.getElementById("title2").style.color = "#B5B5B5";
        document.getElementById("title3").style.color = "#B5B5B5";
        
        document.getElementById("secdir").style.display = "none";
        document.getElementById("terdir").style.display = "none";
        
        if(subcatMenuOpened == false)
        {
            document.getElementById("menu2").style.display = "block";
            subcatMenuOpened = true;
        }
        else
        {
            document.getElementById("menu2").style.display = "none";
            subcatMenuOpened = false;
        }
    }
    
    function ShowSubcat2Dropdown()
    {
        document.getElementById("title3").style.color = "#B5B5B5";
        document.getElementById("terdir").style.display = "none";
        if(subcat2MenuOpened == false)
        {
            document.getElementById("menu3").style.display = "block";
            subcat2MenuOpened = true;
        }
        else
        {
            document.getElementById("menu3").style.display = "none";
            subcat2MenuOpened = false;
        }
    }
    
    function SubmitLink(frm)
    {
        var isTitleCorrect   = true;
        var isUrlCorrect     = true;
        var isCommentCorrect = true;
        var isCaptchaCorrect = true;
        var isEmailCorrect   = true;
        var isNameCorrect    = true;
        var isCategory1Correct = true;
        var isCategory2Correct = true;
        var isCategory3Correct = true;
        
        var root = "http://geniusfind.com/";
        
        var secdir = document.getElementById("secdir_suggest").value;
        var terdir = document.getElementById("terdir_suggest").value;
        
        if(secdir) document.getElementById("subcatParam").innerHTML = '<input type="hidden" name="subcategory" value="' + secdir + '">';
        if(terdir) document.getElementById("subcat2Param").innerHTML = '<input type="hidden" name="subcategory2" value="' + terdir + '">';
        
        if ((frm.title.value == "") || (frm.title.value == "Title"))
            isTitleCorrect = false;
        
        if ((frm.url.value == "") || (frm.url.value == "URL"))
            isUrlCorrect = false;
        
        if(isUrlCorrect)
        {
            if(!frm.url.value.match(/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/))
            {
                var httpurl = "http://" + frm.url.value;
                
                if(!httpurl.match(/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/))
                {
                    isUrlCorrect = false;
                }
                else
                {
                    isUrlCorrect = true;
                    frm.url.value = httpurl;
                }
            }
        }
        
        if (frm.email.value == "Your email" || !(/^[^@]+@[^@\.]+\.[^@]+$/.test(frm.email.value)))
           isEmailCorrect = false;
        
        if ((frm.name.value == "") || (frm.name.value == "Your name"))
            isNameCorrect = false;

        if ((frm.comments.value == "") || (frm.comments.value == "Description"))
            isCommentCorrect = false;
/*
        if (frm.captcha.value.toLowerCase() != getURL(root + "support/captcha_current.php"))
            isCaptchaCorrect = false;
*/
        if(document.getElementById("title1").innerHTML == "Primary")
            isCategory1Correct = false;
            
        if(document.getElementById("title2").innerHTML == "Secondary" && document.getElementById("secdir_suggest").value == "")
        {
            isCategory2Correct = false;
        }
        else
        {
            document.getElementById("title2").style.color = "#B5B5B5";
        }

        if(document.getElementById("title3").innerHTML == "Tertiary" && document.getElementById("terdir_suggest").value == "")
        {
            isCategory3Correct = false;
        }
        else
        {
            document.getElementById("title3").style.color = "#B5B5B5";
        }
            
        
        if (isTitleCorrect && isUrlCorrect && isCommentCorrect && isCaptchaCorrect && isCategory1Correct && isCategory2Correct && isCategory3Correct)
        {
            frm.submit();
        }
        else
        {
            var obj = document.getElementById("error-message");
            obj.innerHTML = '<b style="color: #ff0000;">Please check the errors below and try again.</b>';
            
            if(!isTitleCorrect)      document.getElementById("link_title").style.color="#FF0000";
            if(!isUrlCorrect)        document.getElementById("url").style.color="#FF0000";
            if(!isCommentCorrect)    document.getElementById("comment").style.color="#FF0000";
            if(!isCaptchaCorrect)    document.getElementById("captcha").style.color="#FF0000";
            if(!isNameCorrect)       document.getElementById("name").style.color="#FF0000";
            if(!isEmailCorrect)      document.getElementById("email").style.color="#FF0000";
            if(!isCategory1Correct)  document.getElementById("title1").style.color="#FF0000";
            if(!isCategory2Correct)  document.getElementById("title2").style.color="#FF0000";
            if(!isCategory3Correct)  document.getElementById("title3").style.color="#FF0000";
        }
    }
    
    function SuggestSecDirectory()
    {
        document.getElementById("secdir").style.display = "block";
        document.getElementById("terdir").style.display = "block";
    }
    
    function SuggestTerDirectory()
    {
        document.getElementById("terdir").style.display = "block";
    }

function showPreloader(delta)
{
    idSpacer = document.getElementById("divSpacer");
    id_flow = document.getElementById("wrapJsiBox");
    idForm = document.getElementById("jsiMainBox2");
    
    id_flow.style.height = idSpacer.offsetTop + 10;
    id_flow.style.display = '';
    
    idForm.style.left = (document.body.clientWidth / 2 - 229) + "px";
    idForm.style.top = (document.body.scrollTop + document.body.clientHeight / 2 - delta) + "px";
    idForm.style.display = '';
    
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        changeAllSelectDisabled("hidden");
    }
    
    runLoader = true;
    setTimeout("animateLoading()", 900);
    setTimeout("hidePreloader()", 30000);
}

function changeAllSelectDisabled(vis)
{
    var coll = document.all.tags("SELECT");
    if (coll.length > 0)
    {
        for (i = 0; i < coll.length; i++)
        {
            coll.item(i).style.visibility = vis;
        }
    }
}

var showImgNum = 0;
var runLoader = false;
var ids = new Array();
ids[0] = "lt1";
ids[1] = "lt2";
ids[2] = "lt3";
ids[3] = "lt4";
ids[4] = "lt5";
ids[5] = "lt6";
ids[6] = "lt7";
ids[7] = "lt8";

function animateLoading()
{
    if (showImgNum < 8)
    {
        obj = document.getElementById(ids[showImgNum]);
        obj.style.backgroundColor = "#0099CC";
        showImgNum++;
    }
    else
    {
        showImgNum = 0;
        for (i = 0; i < 8; i++)
        {
            obj = document.getElementById(ids[i]);
            obj.style.backgroundColor = "#b3b3b3";
        }
    }
    
    if (runLoader)
    {
        setTimeout("animateLoading()", 150);
    }
}

function hidePreloader()
{
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        changeAllSelectDisabled("visible");
    }
    
    runLoader = false;
    showImgNum = 0;
    for (i = 0; i < 8; i++)
    {
        obj = document.getElementById(ids[i]);
        obj.style.backgroundColor = "#b3b3b3";
    }
    
    id_flow = document.getElementById("wrapJsiBox");
    idForm = document.getElementById("jsiMainBox2");
    id_flow.style.display = 'none';
    idForm.style.display = 'none';
}


function ShowFullArticle()
{
    var otherText = document.getElementById('otherText').style.display;
    var showFullHref = '';
    
    if (otherText == 'none')
    {
        otherText = '';
        showFullHref = 'Roll up...'
        
    }
    else
    {
        otherText = 'none';
        showFullHref = "Read this full article...";
    }
    
    document.getElementById('otherText').style.display = otherText;
    document.getElementById('showFullHref').innerHTML = showFullHref;
}

function ShowData(block)
{
    document.getElementById('buythis').style.display = 'none';
    document.getElementById('overview').style.display = 'none';
    
    document.getElementById('buythis_img').src = 'images/buythis_inactive.gif';
    document.getElementById('overview_img').src = 'images/overview_inactive.gif';
    
    document.getElementById(block).style.display = '';
    document.getElementById(block + '_img').src = 'images/' + block + '_active.gif';
}

function setTicker(ticker)
{
    document.getElementById('t_web').style.display = 'none';
    document.getElementById('t_images').style.display = 'none';
    document.getElementById('t_videos').style.display = 'none';
    document.getElementById('t_blog').style.display = 'none';
    document.getElementById('t_answers').style.display = 'none';
    document.getElementById('t_directory').style.display = 'none';
    
    document.getElementById('t_' + ticker).style.display = '';
    
    document.getElementById("searchParam").innerHTML = "<input type=\"hidden\" name=\"search\" value=\"" + ticker + "\">";
}