﻿function checkSS(obj)
{
    if (document.getElementById("DefaultText").value == "Y")
    {
        document.getElementById("afs").style.color = "#CCCCCC";
        document.getElementById("afs").value = "";	
        document.getElementById("DefaultText").value = "N";	
       }	                    
}

function validateSSSize(obj, limit){
    
    document.getElementById("afs").style.color = "#000000";
    var val = trimSSString(obj.value);
    if (val.length > limit){
        alert("You have exceeded the field limit of " + limit + " characters.");
        obj.value = val.substring(0, limit);
    }
}

function trimSSString(str)
{
    if (!(str == "")) {
    while('' + str.charAt(0) == ' '){
        str=str.substring(1,str.length);
    }
    }
    //take out trailing spaces
    if (!(str == "")) {
    while (str.charAt(str.length - 1) == ' '){
        str = str.substring(0, str.length - 1);
    }
    }
    return str;
}

function checkKWVal() {
    if (document.getElementById("DefaultText").value == "Y") {
        document.getElementById("afs").style.color = "#CCCCCC";
        document.getElementById("afs").value = "";
        return false;
    }
    if (document.getElementById("afs").value == "") {
        return false;
    }

}

function ToggleSearchOptions() {
    var div = document.getElementById("divSearchOptions");
    if (div.style.display == "none")
        ShowSearchOptions();
    else
        CloseSearchOptions();
}

 function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
        
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function HideSearchOptions()
{                       
    
    var div = document.getElementById("divSearchOptions");                                                                                      
    div.style.display = "none";                                               
    IsSearchOptionsOpen = "N";
    
    var divSearchType = document.getElementById("divSearchType");

    divSearchType.style.borderLeftWidth  = "0px" ;
    divSearchType.style.borderRightWidth  = "0px" ;
    divSearchType.className = "search-type";
    
 
    return true;
}




function SelectSearchType(option) {
    var text;
    document.getElementById("freeSearchForm").target = "_self";
    var SetMask = "N";
    var test = document.getElementById("MaskText").value;
    if (document.getElementById("afs").value == document.getElementById("MaskText").value ||
    trimSSString(document.getElementById("afs").value) == "") {
        SetMask = "Y";
    }
    switch (option) {
        case "1":

            text = 'Search for People';
            document.getElementById("MaskText").value = "Find people by name, practice area, geography, etc.";
            document.getElementById("ft").value = "1";
            document.getElementById("frm").value = "freesearch";
            document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://www.martindale.com/Find-Lawyers-and-Law-Firms.aspx' title='Advanced Search'>&#160;Advanced Search</a>";
            document.getElementById("freeSearchForm").action = "http://www.martindale.com/Results.aspx";
            document.getElementById("afs").name = "afs";
            document.getElementById("freeSearchForm").method = "post";
            break;

        case "2":

            text = 'Search for Law Firms';
            document.getElementById("MaskText").value = "Find law firm by name, practice area, geography, etc.";
            document.getElementById("ft").value = "2";
            document.getElementById("frm").value = "freesearch";
            document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://www.martindale.com/Find-Lawyers-and-Law-Firms.aspx' title='Advanced Search'>&#160;Advanced Search</a>";
            document.getElementById("freeSearchForm").action = "http://www.martindale.com/Results.aspx";
            document.getElementById("afs").name = "afs";
            document.getElementById("freeSearchForm").method = "post";
            break;

        case "3":

            text = 'Search for Companies';
            document.getElementById("MaskText").value = "Find companies by name, location, etc.";
            document.getElementById("ft").value = "3";
            document.getElementById("frm").value = "freesearch";
            document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://www.martindale.com/Find-Lawyers-and-Law-Firms.aspx' title='Advanced Search'>&#160;Advanced Search</a>";
            document.getElementById("freeSearchForm").action = "http://www.martindale.com/Results.aspx";
            document.getElementById("afs").name = "afs";
            document.getElementById("freeSearchForm").method = "post";
            break;

        case "4":

            //TO DO
            text = 'Search for Community';
            document.getElementById("MaskText").value = "Find blog, forum and group posts by keyword.";
            document.getElementById("freeSearchForm").action = "http://community.martindale.com/search/default.aspx";
            document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://community.martindale.com/search/default.aspx' title='Advanced Search'>&#160;Advanced Search</a>";
            document.getElementById("freeSearchForm").method = "get";
            document.getElementById("afs").name = "q";
            break;

        case "5":

            text = 'Search Legal Library';
            document.getElementById("MaskText").value = "Find law firm authored articles, documents, etc.";
            document.getElementById("freeSearchForm").action = "http://www.martindale.com/legal-library/Results.aspx"
            document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://www.martindale.com/legal-library/Advanced-Search.aspx' title='Advanced Search'>&#160;Advanced Search</a>";
            document.getElementById("frm").value = "articleAdvanced";
            document.getElementById("wid").value = "Y";
            document.getElementById("afs").name = "k2";
            document.getElementById("wr").value = "0";
            document.getElementById("freeSearchForm").method = "post";
            break;

        case "6":
            text = 'Search for Jobs';
            document.getElementById("MaskText").value = "Find jobs in the legal industry by title, geography, etc.";
            document.getElementById("divAdvancedFind").innerHTML = "";
            document.getElementById("freeSearchForm").action = "http://www.martindale.com/Careers/Job-Seeker-Job-Search.htm";
            document.getElementById("afs").name = "keywords";
            document.getElementById("freeSearchForm").method = "get";
            break;

        case "7":

            text = 'Search for Experts & Services';
            document.getElementById("MaskText").value = "Find legal experts, consultants, and service providers.";
            document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://experts.martindale.com/Advanced-Expert-Search.html' title='Advanced Search' target = '_blank'>&#160;Advanced Search</a>";
            document.getElementById("freeSearchForm").action = "http://experts.martindale.com/Results.aspx";
            document.getElementById("freeSearchForm").method = "get";
            document.getElementById("afs").name = "Ntt";
            document.getElementById("freeSearchForm").target = "_blank";
            break;

        case "8":

            text = 'Search the Web';
            document.getElementById("MaskText").value = "Powered by LexisWeb.";
            document.getElementById("divAdvancedFind").innerHTML = "";
            document.getElementById("freeSearchForm").action = "http://www.lexisweb.com/Search.aspx";
            document.getElementById("freeSearchForm").method = "get";
            document.getElementById("afs").name = "Query";
            document.getElementById("freeSearchForm").target = "_blank";
            break;

        default:
            result = 'unknown';
    }

    if (SetMask == "Y") {
        document.getElementById("afs").style.color = "#CCCCCC";
        document.getElementById("DefaultText").value = "Y";
        document.getElementById("afs").value = document.getElementById("MaskText").value;
    }

    var aSearchType = document.getElementById("aSearchType");
    aSearchType.innerHTML = text + "&nbsp;&nbsp;&nbsp;";
    HideSearchOptions();
}

function ClientSelectedIndexChanged(sender, args)
{    
    //Get OrginalText and set to the selected item
    var orginalText = sender.get_selectedItem().get_text();    
    //<a href=http://dev2-martindale.reedref.com/Brenda-V-Smith/-200114-lawyer.htm>Brenda V.<b>Smith</b>, Associate Professor of Law<br /></a>
    var nBeginIndex = orginalText.indexOf("a href=\"http");
    if (nBeginIndex == -1) {
        nBeginIndex = orginalText.indexOf("a href=http");
        orginalText = orginalText.substring(nBeginIndex + 7);
    }
    else {
        orginalText = orginalText.substring(nBeginIndex + 8);
    }
    
    var nEndIndex = orginalText.indexOf("\">");    
    if(nEndIndex == "-1")
    {
        nEndIndex = orginalText.indexOf(">");        
    }
    var URL = orginalText.substring(0, nEndIndex);    
    window.location.href = URL;        
    sender.set_text("");     
}

function ClientItemsRequested(sender, args)
{    
    
    if(sender.get_items().get_count() == 0)
    {
        sender.hideDropDown();
        return false;
    }
    else
    {        
        sender.showDropDown();
    }
}

function ClientKeyPressing(sender, args) {
    if (args.get_domEvent().keyCode == "13") {
        btnSearchClientClick();
        return true;
    }
    if (sender.get_items().get_count() == 0) {
        sender.hideDropDown();
        return false;
    }
    else {
        sender.showDropDown();
    }
}

function HandleOpen(sender, args)
{        
    var comboText = sender.get_text();
    if(comboText.length < 3)
    {
       args.set_cancel(true);       
    }
    if(sender.get_items().get_count() == 0)
    {
        
        args.set_cancel(true);        
    }
}
    
function ShowSearchOptions()
    {                         
        var div = document.getElementById("divSearchOptions");
        div.style.display = "block";                       
        
        document.getElementById("hidSearchOptionsOpen").value = 'C';
        
        var divSearchType = document.getElementById("divSearchType");
        	  
        divSearchType.style.borderLeftWidth  = "1px" ;
        divSearchType.style.borderRightWidth  = "1px" ;
        divSearchType.className = "search-type-drop";
                              
        
        var top= 0,left= 0;               
        top = findPosY(divSearchType);
        left = findPosX(divSearchType);
        
        var width =document.getElementById("divSearchType").offsetWidth;
        
        div.style.position = "absolute";
        div.style.top = (top + 30) + "px";
        div.style.left = left + "px";    	               
        div.style.width = "225px";
        
        return true;
    } 
    
   function CloseSearchOptions()
    {
        var srchOptions = document.getElementById("hidSearchOptionsOpen").value;        
        if(srchOptions == 'Y')
        {            
            HideSearchOptions();
            document.getElementById("hidSearchOptionsOpen").value = 'N';
        }
        else if(srchOptions == 'C')
        {
            document.getElementById("hidSearchOptionsOpen").value = 'Y';
        }    
    }



    function SetTextValue(obj) 
    {
        var TextToSet = document.getElementById("MaskText").value;
        if (obj.value == "") {
            obj.value = TextToSet;
            obj.style.color = "#AAAAAA";
        }
    }



    function RemoveTextValue(obj) 
    {   
        var TextToCompare =  document.getElementById("MaskText").value;     
        if(obj.value == TextToCompare) 
        {
            obj.value = ""; 
            obj.style.color = "#333333";
        }
    }
    
    function OnFocus(sender, eventArgs) {
        var TextToCompare = document.getElementById("MaskText").value;
        var inputElement = sender.get_inputDomElement();
        if (sender.get_text() == TextToCompare) {
            sender.set_text("");
            inputElement.style.color = "#333333";
        }
    }

    function OnBlur(sender, eventArgs) {
        var TextToSet = document.getElementById("MaskText").value;
        var inputElement = sender.get_inputDomElement();
        if (sender.get_text() == "") {
            sender.set_text(TextToSet);
            inputElement.style.color = "#AAAAAA";
        }
    }
     function ShowSearchBox(showPPl,showOther)                        
    {
        document.getElementById("divAutoSuggestPPlBox").style.display = showPPl;        
        document.getElementById("divWithoutAutoSuggestBox").style.display = showOther;
    }
    
     function SetAdvancedFind(option)
    {
        
        var aSearchType = document.getElementById("aSearchType"); 
        
        switch (option) 
        {
            case "1":
                document.getElementById("MaskText").value = "Find people by name, practice area, geography, etc.";
                ShowSearchBox('block', 'none');
                aSearchType.innerHTML = "Search for People" + "&nbsp;&nbsp;&nbsp;";
                document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://www.martindale.com/Find-Lawyers-and-Law-Firms.aspx' title='Advanced Search'>&#160;Advanced Search</a>";
                break;
                
            case "2":
                document.getElementById("MaskText").value = "Find law firm by name, practice area, geography, etc.";   
                ShowSearchBox('none','block');    
                aSearchType.innerHTML  = "Search for Law Firms"+ "&nbsp;&nbsp;&nbsp;";
                document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://www.martindale.com/Find-Lawyers-and-Law-Firms.aspx' title='Advanced Search'>&#160;Advanced Search</a>";                
                break;
           
            case "3": 
                document.getElementById("MaskText").value = "Find companies by name, location, etc.";   
                ShowSearchBox('none','block'); 
                aSearchType.innerHTML  = "Search for Companies"+ "&nbsp;&nbsp;&nbsp;";
                document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://www.martindale.com/Find-Lawyers-and-Law-Firms.aspx' title='Advanced Search'>&#160;Advanced Search</a>";
                
                break;
                
            case "4": 
                document.getElementById("MaskText").value = "Find blog, forum and group posts by keyword.";   
                ShowSearchBox('none','block'); 
                aSearchType.innerHTML = "Search Community"+ "&nbsp;&nbsp;&nbsp;";;
                document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='" + document.getElementById("CSServerURL").value + "/search/default.aspx' title='Advanced Search'>&#160;Advanced Search</a>";
               
                break;
                
            case "5":
                document.getElementById("MaskText").value = "Find law firm authored articles, documents, etc.";   
                ShowSearchBox('none','block'); 
                aSearchType.innerHTML = "Search Legal Library"+ "&nbsp;&nbsp;&nbsp;";
                document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://www.martindale.com/legal-library/Advanced-Search.aspx' title='Advanced Search'>&#160;Advanced Search</a>";
               
                break;
                
            case "6":
                document.getElementById("MaskText").value = "Find jobs in the legal industry by title, geography, etc.";   
                ShowSearchBox('none','block'); 
                aSearchType.innerHTML = "Search for Jobs"+ "&nbsp;&nbsp;&nbsp;";
                document.getElementById("divAdvancedFind").innerHTML = "";                               
               
                break;
                
            case "7": 
                document.getElementById("MaskText").value = "Find legal experts, consultants, and service providers.";   
                ShowSearchBox('none','block'); 
                aSearchType.innerHTML = "Search for Experts and Services"+ "&nbsp;&nbsp;&nbsp;";
                document.getElementById("divAdvancedFind").innerHTML = "<a class='mhc-t-8' href='http://experts.martindale.com/Advanced-Expert-Search.html' title='Advanced Search' target = '_blank'>&#160;Advanced Search</a>";                                                                
               
                break;
                
            case "8":         
                document.getElementById("MaskText").value = "Powered by LexisWeb.";                                   
                ShowSearchBox('none','block'); 
                aSearchType.innerHTML = "Search the Web"+ "&nbsp;&nbsp;&nbsp;";
                document.getElementById("divAdvancedFind").innerHTML = "";
               
                break;                    
                
            default: 
                result = 'unknown';
        }
       
    }
    