var DHTML = (document.getElementById || document.all || document.layers);
function invi(flag) { 
	if (flag == 1) {
        $("#feedback").css("display","block") ;
    } else {
        $("#feedback").css("display","none") ;
    }
}
function searchCourt(flag) { if (!DHTML) return; var x = new getObj('searchCourt'); x.style.visibility = (flag) ? 'hidden' : 'visible' }
function blogMenu(flag) { if (!DHTML) return; var x = new getObj('blogMenu'); x.style.visibility = (flag) ? 'hidden' : 'visible' }
function choo() {
    show_or_hide_flag_content(0) ;
	blogMenu(0); invi(0); searchCourt(1);
	$("#feedback").css("display","") ;
}

function show_or_hide_flag_content(flag){
    if (flag == 1) {
        $("#flagContent").css("display","block") ;
    } else {
        $("#flagContent").css("display","none") ;
    }
    invi(0);
}

function getObj(name)
{
  if (document.getElementById) { this.obj = document.getElementById(name); this.style = document.getElementById(name).style; }
  else if (document.all) { this.obj = document.all[name]; this.style = document.all[name].style; }
  else if (document.layers) { this.obj = document.layers[name]; this.style = document.layers[name]; }
}

function getCounty(url,statecode){
	$("#select_county").remove("select");
	if(statecode){
		url = url + "?stateCode=" + statecode;
	}
	$.get(url,
		function(data){
			$("#select_county").html(data);
		});
}

function getCourtCounty(url,countyID){
	if(countyID){
		url = url + "?countyID=" + countyID;
	}
	window.location=url
}

function statecourt(url){
	var sub_state_code = $("#id_state").val();
	if(sub_state_code){
		url = url + "?stateCode=" + sub_state_code;
		window.location = url;
	}
	return false;
}

// Insert the json data into select element
function refresh_select_list(json, element){
	element.empty();
	for (var i=0;i<json.length;i++) {
		element.get(0).options.add(new Option(json[i].name, json[i].id));
	}
}

// Reset the element list
function reset_court(element){
	element.empty();
	element.get(0).options.add(new Option('--------', ''));
}

// AJAX get the json data according the value of county_element,
// then insert it into court_element.
function set_court_list(county_element, court_element){
	if (county_element.value == ''){
		court_element.html('<option value="">--------</option>');
	} else {
		county = county_element.value;
		url = '/lawyer/refresh_court/?county=' + county;
		$.getJSON(
			url,
			function(json){
				refresh_select_list(json, court_element);
			}
		);
	}
}

function set_article_court_list(county_element, court_element){
		county = county_element.value;
		url = '/lawyer/refresh_court/?county=' + county;
		$.getJSON(
			url,
			function(json){
				refresh_select_list(json, court_element);
			}
		);
}
