g_srchstring_old=""
g_srchtype = GetCookie("c_srchtype");   
g_querytxt = GetCookie("c_querytxt");
g_querytxt2 = GetCookie("c_querytxt2");

var States = new Object();
States["AK"]="AK";
States["AL"]="AL";
States["AR"]="AR";
States["AZ"]="AZ";
States["CA"]="CA";
States["CO"]="CO";
States["CT"]="CT";
States["DC"]="DC";
States["DE"]="DE";
States["FL"]="FL";
States["GA"]="GA";
States["GU"]="GU";
States["HI"]="HI";
States["IA"]="IA";
States["ID"]="ID";
States["IL"]="IL";
States["IN"]="IN";
States["KS"]="KS";
States["KY"]="KY";
States["LA"]="LA";
States["MA"]="MA";
States["ME"]="ME";
States["MD"]="MD";
States["MI"]="MI";
States["MN"]="MN";
States["MS"]="MS";
States["MO"]="MO";
States["MT"]="MT";
States["NC"]="NC";
States["ND"]="ND";
States["NE"]="NE";
States["NH"]="NH";
States["NJ"]="NJ";
States["NM"]="NM";
States["NV"]="NV";
States["NY"]="NY";
States["MP"]="MP";
States["OH"]="OH";
States["OK"]="OK";
States["OR"]="OR";
States["PA"]="PA";
States["PR"]="PR";
States["RI"]="RI";
States["SC"]="SC";
States["SD"]="SD";
States["TN"]="TN";
States["TX"]="TX";
States["VA"]="VA";
States["VI"]="VI";
States["VT"]="VT";
States["UT"]="UT";
States["WA"]="WA";
States["WV"]="WV";
States["WI"]="WI";
States["WY"]="WY";

var Circuits = new Object();
Circuits ["01"]="First Circuit";
Circuits ["02"]="Second Circuit";
Circuits ["03"]="Third Circuit";
Circuits ["04"]="Fourth Circuit";
Circuits ["05"]="Fifth Circuit";
Circuits ["06"]="Sixth Circuit";
Circuits ["07"]="Seventh Circuit";
Circuits ["08"]="Eighth Circuit";
Circuits ["09"]="Ninth Circuit";
Circuits ["10"]="Tenth Circuit";
Circuits ["11"]="Eleventh Circuit";
Circuits ["DC"]="D.C. Circuit";
Circuits ["FC"]="Federal Circuit";

function keyChk(e) {

//Navigator
        if (e.which) {
                var charCode = e.which
                if (charCode > 12 && charCode < 14) {
                        return submitVal(document.search)
                }
        }

//IE
        if (e.keyCode)  {
                var charCode = e.keyCode
                if (charCode == "13") {
                        return submitVal(document.search)
                }
        }
}
        
function updateFieldDisplay(srchtype) {
        displayObj = document.getElementById("display");
               
        switch(srchtype) {
                        case 'Circuit':
                                displayObj.innerHTML = radioButton('srchstring', 'Circuit', Circuits);
                                break;
                        case 'City & State':
                        case 'County & State':
                                var display_arr = srchtype.split("&")
                                displayObj.innerHTML = textField('srchstring', trim(display_arr[0])) + " " + radioButton('srchstate', trim(display_arr[1]), States);
                                break;
                        case 'Area Code':
                        case 'Zip Code':
                                displayObj.innerHTML = textField('srchstring', srchtype);
                                break;
                        default:
                                displayObj.innerHTML = textField('srchstring', "City", true) + " " + radioButton('srchstates', "States", States,true);
                                break;
        }
        
}

function textField(name, caption, disable){
   var disable = (disable == null) ? "" : "disabled";
   var html = "<span id='FieldDisplay1'><strong>"+ caption + ":<\/strong><\/span> <input type='text' name='" + name + "' maxlength='20' size='20' onkeydown='return keyChk(event)' " + disable +">"; 
   return html;
}

function radioButton(name, caption, optObj, disable){
   var disable = (disable == null) ? "" : "disabled";        
   var html = "<span id='FieldDisplay2'><strong>"+ caption + ":<\/strong><\/span> <select name='" + name + "' onkeydown='typeAhead()'" + disable +"><option value='' selected><\/option>";
   for ( testKey in optObj )
        {
                html += "<option value='" + testKey +"'>" + optObj[testKey] + "<\/option>";
        }
   return html;
}
         
function refresh(formname) {
   srchtype = radioValue(formname,"srchtype")

   updateFieldDisplay(srchtype)
}

function submitVal(formname,mode) {
        srchtype = radioValue(formname,"srchtype")
		ofctype = radioValue(formname,"ofctype")
		
		if (empty(srchtype) && empty(ofctype)) {
                alert("\nPlease select either an office type or a search location and try again.")
                return false
        }
        
        if ((srchtype=="County & State" | srchtype=="City & State") && formname.srchstate.selectedIndex<=0) {
                alert("\nPlease select a state and try again.")
                return false
        }

        if (srchtype=="Circuit" && formname.srchstring.selectedIndex<=0) {
                alert("\nPlease select a circuit and try again.")
                return false
        }
		
        srchstring = trim(formname.srchstring.value)
        if (srchtype=="Zip Code" && srchstring.length<5) {
                alert("\nPlease enter all five-digits of the zipcode and try again.")
                return false
        }

        if (srchtype=="Area Code" && srchstring.length<3) {
                alert("\nPlease enter all three digits of the area code and try again.")
                return false
        }
        
        var expdate = new Date();
        expdate.setTime(expdate.getTime()+(24*60*60*1000)); //cookie expires in 1 day
        SetCookie ("c_srchtype", srchtype, expdate)
        SetCookie ("c_querytxt", srchstring, expdate)
        if (srchtype=="County & State" | srchtype=="City & State") {
           SetCookie ("c_querytxt2",  formname.srchstate.value, expdate)
        }
        formname.submit()
        return true
}      
