

var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos = appVer.indexOf('msie');
if (iePos !=-1) {
is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
is_major = parseInt(is_minor);
}
var is_getElementById = (document.getElementById) ? "true" : "false"; 
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
var is_documentElement = (document.documentElement) ? "true" : "false"; 
var is_ie = ((iePos!=-1));
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && is_major == 4);
var is_ie4up = (is_ie && is_minor >= 4);
var is_ie5 = (is_ie && is_major == 5);
var is_ie5up = (is_ie && is_minor >= 5);
var is_ie5_5 = (is_ie && (agt.indexOf("msie 5.5") !=-1)); 
var is_ie5_5up =(is_ie && is_minor >= 5.5); 
var is_ie6 = (is_ie && is_major == 6);
var is_ie6up = (is_ie && is_minor >= 6);

var arrowPositions = new Array();






function hoverButton(num) {
	showArrow(num);
	var imageButtonPathsColor = new Array();
	imageButtonPathsColor[1] = "images/shapeimage_4_color.jpg";
	imageButtonPathsColor[2] = "images/shapeimage_6_color.jpg";
	imageButtonPathsColor[3] = "images/shapeimage_5_color.jpg";
	document.getElementById('imageButton'+num).src = imageButtonPathsColor[num];
}

function unHoverButton(num) {
	hideArrow();
	var imageButtonPaths = new Array();
	imageButtonPaths[1] = "images/shapeimage_4.jpg";
	imageButtonPaths[2] = "images/shapeimage_6.jpg";
	imageButtonPaths[3] = "images/shapeimage_5.jpg";
	document.getElementById('imageButton'+num).src = imageButtonPaths[num];
}

function showArrow(num) {
	var imageButtonTops = new Array();
	imageButtonTops[1] = "134px";
	imageButtonTops[2] = "250px";
	imageButtonTops[3] = "363px";
	var greenArrow = document.getElementById('greenArrow');
	greenArrow.style.top = imageButtonTops[num];
	greenArrow.style.display = "block";
}

function hideArrow() {
	document.getElementById('greenArrow').style.display = "none";
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadi() { //v3.0
  var d=document; if(d.i){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadi.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function shOptions(){
	if(document.getElementById("minBed")){
		if(document.getElementById("multi_family").checked){
			document.getElementById("minBed").options[0].selected = true;
			document.getElementById("minBed").style.display = 'none';
			document.getElementById("minBedNot").style.display = '';
		}else{
			document.getElementById("minBed").style.display = '';
			document.getElementById("minBedNot").style.display = 'none';
		}
	}
	if(document.getElementById("minBath")){
		if(document.getElementById("multi_family").checked){
			document.getElementById("minBath").options[0].selected = true;
			document.getElementById("minBath").style.display = 'none';
			document.getElementById("minBathNot").style.display = '';
		}else{
			document.getElementById("minBath").style.display = '';
			document.getElementById("minBathNot").style.display = 'none';
		}
	}
}
function shCondoAcres(){
	cTrip = 0;
	if(document.getElementById("minAcres")){
		if(document.getElementById("condo_townhouse")){
			if(document.getElementById("condo_townhouse").checked){
				cTrip = 1;
				document.getElementById("minAcres").options[0].selected = true;
				document.getElementById("minAcres").style.display = 'none';
				document.getElementById("minAcresNot").style.display = '';
			}else{
				document.getElementById("minAcres").style.display = '';
				document.getElementById("minAcresNot").style.display = 'none';
			}
		}
		if(document.getElementById("condo") && cTrip == 0){
			if(document.getElementById("condo").checked){
				cTrip = 1;
				document.getElementById("minAcres").options[0].selected = true;
				document.getElementById("minAcres").style.display = 'none';
				document.getElementById("minAcresNot").style.display = '';
			}else{
				document.getElementById("minAcres").style.display = '';
				document.getElementById("minAcresNot").style.display = 'none';
			}
		}
		if(document.getElementById("townhouse") && cTrip == 0){
			if(document.getElementById("townhouse").checked){
				cTrip = 1;
				document.getElementById("minAcres").options[0].selected = true;
				document.getElementById("minAcres").style.display = 'none';
				document.getElementById("minAcresNot").style.display = '';
			}else{
				document.getElementById("minAcres").style.display = '';
				document.getElementById("minAcresNot").style.display = 'none';
			}
		}
	}
}
function openWinRegist() {
	var n=open('/ga_mls/teresasmith/index.cfm?action=whyRegister','HTML','width=500,height=500,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function pushToMapForm(){
	return;
}
// detailed search form saver
function searchProperties(p_save) {
	window.open('about:blank','search_results','width=825,height=600,status=no,menubar=no,scrollbars=yes,resizable=yes');
	var f = document.forms.searchForm;
	
		f.action_override.value = (p_save) ? "save" : "";
	
	f.submit();
}
function llInfo(){
	tllat = document.getElementById("map_tl_lat").value;
	tllng = document.getElementById("map_tl_lng").value;
	brlat = document.getElementById("map_br_lat").value;
	brlng = document.getElementById("map_br_lng").value;

	alert(tllat+':'+tllng+':'+brlat+':'+brlng);
}
function showRadio(t){
	window.location.href = "?primarySearchType=" + t.value;
}
function addDateToSearchForm(){
	$('date_from').value = $('date_from_top').value;
	$('date_to').value = $('date_to_top').value;
}
function addAgeToSearchForm(){
	//alert($('sold_age_top').options[$('sold_age_top').selectedIndex].value);
	$('sold_age').value = $('sold_age_top').options[$('sold_age_top').selectedIndex].value;
	pushLL();
}

function MoveDropDown(tsource, tdest){
	var thelength = 0;
	var returnvalue;
	for (var i = tsource.length - 1; i >= 0; i--) {
		if (tsource.options[i].selected) {
			returnvalue = tsource.options[i].value;

			tdest.length ++;
			thelength = tdest.length;
			
			tdest.options[thelength - 1].text = tsource.options[i].text;
			tdest.options[thelength - 1].value = tsource.options[i].value;
			
		
			var oldlength = tsource.length;
			for (var j = i; tsource.length > j + 1; j++) {
				tsource.options[j].value = tsource.options[j + 1].value;
				tsource.options[j].text = tsource.options[j + 1].text;
			}
			
			tsource.options[j].value = "";
			tsource.options[j].text = "";
			tsource.length = tsource.length - 1;
		}
	}
	return (returnvalue);
}
function MoveDropDown2(tsource, tdest){
	for (var i = 0; i < tsource.length; i++) {
		if (tsource.options[i].selected) {
			AddIf(tdest,tsource.options[i].text,tsource.options[i].value)
		}
	}
	RemoveSelected(tsource);
}

function SelectOption(tsource, thevalue, nocase){
	tsource.selectedIndex = -1;
	var hit = 0;
	for (var i = 0; i < tsource.length; i++) {
		if (listfind(thevalue.toLowerCase(),tsource.options[i].value.toLowerCase())>0 || tsource.options[i].value.toLowerCase() == thevalue.toLowerCase()) {
			tsource.options[i].selected = true;
			if (hit == 0 ){
//				alert(i + ' ' + tsource[i].text);
				tsource.selectedIndex = i;
				hit = 1;
			}
		}
	}
}
function RemoveSelected(tsource){

	for (var x = tsource.length-1; x>= 0; x--){
		if (tsource.options[x].selected){
			for (var j = x; tsource.length > j + 1; j++) {
				tsource.options[j].value = tsource.options[j + 1].value;
				tsource.options[j].text = tsource.options[j + 1].text;
			}
			
			tsource.options[j].value = "";
			tsource.options[j].text = "";
			tsource.length = tsource.length - 1;
		}
	}
	tsource.selectedIndex = -1;
}

function ChangeSelected(tsource, thetext, thevalue){

	for (var x = tsource.length-1; x>= 0; x--){
		if (tsource.options[x].selected){
			tsource.options[x].value = thevalue;
			tsource.options[x].text = thetext;
		}
	}
}

function AddToSelect(destdrop, thetext, thevalue){
	destdrop.length ++;
	thelength = destdrop.length;
	destdrop.options[thelength - 1].text = thetext;
	destdrop.options[thelength - 1].value = thevalue;
	return (1);
}


function SelectAll(tsource){
	for (var x = 0; x < tsource.length; x++){
		tsource.options[x].selected = true;
	}
}

function RemoveAll(formelement){
	var thelength = formelement.length
	for (var i = 0; thelength > i; i++) {
		RemoveLast(formelement);
	}
}


function RemoveLast(formelement){
	var thelength = formelement.length;
	
	if (thelength >= 1){
		formelement.options[thelength - 1].value = "";
		formelement.options[thelength - 1].text = "";
		formelement.length = thelength - 1;	
	}
}

function MoveUpDown(source, whichway){
	s = source.selectedIndex;
	if (s == 0 && whichway == 'up'){
		return;
	}
	if (s == (source.length-1) && whichway == 'down'){
		return;
	}
	if(whichway == 'up'){
		offset = -1;
	}else{
		offset = 1;
	}
	v = source.options[s + offset].value;
	t = source.options[s+ offset].text;
	source.options[s + offset].value = source.options[s].value;
	source.options[s + offset].text = source.options[s].text;
	source.options[s].value = v;
	source.options[s].text = t;
	source.options[s + offset].selected = true;
	source.options[s].selected = false;
}

function listappend(thelist, newval, delim){
	if (newval == ""){
		newval = " ";
	}
	if (! delim){
		delim = ",";
	}

	if (thelist == ""){
		newstring = newval;
	}else{
		newstring = thelist + delim + newval;
	}
	return newstring;
}

function listgetat(thelist, theindex, delim){
	if (! delim){
		delim = ",";
	}

	currpos = 1;
	start = 0;
	end = -1;
	if (theindex == 1){
		setendflag = 1;
	}else{
		setendflag = 0;
	}
	for (var x=1; x <= thelist.length; x++){
		if (thelist.substring(x,x+1) == delim){
			currpos ++;
			if(setendflag == 1){
				setendflag = 0;
				end = x;
			}
			if(currpos == theindex){
				start = x + 1;
				end = thelist.length;
				setendflag = 1;
			}
		}
	}
	if (start == 0 && end == -1){
		returnstring = "";
	}else{
		returnstring = thelist.substring(start,end);
	}
//	alert("thelist = " + thelist)
//	alert("theindex = " + theindex)
//	alert("returnstring = "+ returnstring)
//	alert("start = "+ start)
//	alert("end = "+ end)
	return returnstring;
}

function listdeleteat(thelist, listpos, delim){
	if (! delim){
		delim = ",";
	}
	l = listlen(thelist, delim);

	newlist = '';
	for (var x = 1; x <= l; x++){
		if (x != listpos){
			listelement = listgetat(thelist,x,delim);
			newlist = listappend(newlist,listelement,delim);
		}
	}
	return newlist;
}

function listlen(thelist, delim){
	if (! delim){
		delim = ",";
	}
	listcount = 1;
	for (var x=1; x <= thelist.length; x++){
		if (thelist.substring(x,x+1) == delim){
			listcount ++;
		}
	}
	return listcount;
}

function listcontains(thelist, thevalue, delim){
	if (! delim){
		delim = ",";
	}
	l = listlen(thelist, delim);
	listpos = -1;
	
	for (var x = 1; x < l; x++){
		listelement = listgetat(thelist,x,delim);
		if (listelement.indexOf(thevalue) >= 0){
			listpos = x;
			break;
		}
	}
	return listpos;
}

function listcontainsnocase(thelist, thevalue, delim){
	if (! delim){
		delim = ",";
	}
	l = listlen(thelist, delim);
	listpos = -1;
	uc = thevalue.toUpperCase();
	
	for (var x = 1; x < l; x++){
		listelement = listgetat(thelist,x,delim);
		listelement = listelement.toUpperCase();
		if (listelement.indexOf(uc) >= 0){
			listpos = x;
			break;
		}
	}
	return listpos;
}

function listfind(thelist, thevalue, delim){
	if (! delim){
		delim = ",";
	}
	l = listlen(thelist, delim);
	listpos = -1;
	
	for (var x = 1; x < l; x++){
		listelement = listgetat(thelist,x,delim);
		if (listelement == thevalue){
			listpos = x;
			break;
		}
	}
	return listpos;
}

function listfindnocase(thelist, thevalue, delim){
	if (! delim){
		delim = ",";
	}
	l = listlen(thelist, delim);
	listpos = -1;
	
	for (var x = 1; x < l; x++){
		listelement = listgetat(thelist,x,delim);
		if (listelement.toUpperCase() == thevalue.toUpperCase()){
			listpos = x;
			break;
		}
	}
	return listpos;
}

function listfirst(thelist, delim){
	return listgetat(thelist,1,delim);
}

function listlast(thelist, delim){
	return listgetat(thelist,listlen(thelist,delim),delim);
}

function listprepend(thelist, thevalue, delim){
	return listappend(thevalue, thelist, delim)
}

function listsetat(thelist, listpos, thevalue, delim){
	if (! delim){
		delim = ",";
	}
	l = listlen(thelist, delim);

	newlist = '';
	for (var x = 1; x <= l; x++){
		if (x != listpos){
			listelement = listgetat(thelist,x,delim);
			newlist = listappend(newlist,listelement,delim);
		}else{
			newlist = listappend(newlist,thevalue,delim);
		}
	}
	return newlist;
}

function listsort(thelist, delim){
	if (! delim){
		delim = ",";
	}
	l = listlen(thelist, delim);
	a = new Array(1);

	for (var z = 1; z <= l; z++){
		newl = a.length;
		a[newl] = listgetat(thelist, z, delim);
	}
	
	var v = '';
	var t = '';
	
	for (var x = 1; x < a.length; x++){
		for (var y = x; y < a.length; y++){
			string1 = a[x];
			string1 = string1.toUpperCase();
			string2 = a[y];
			string2 = string2.toUpperCase();
//			alert (string1 + " " + string2);
			if (string2 < string1){
				v = a[x];
				a[x] = a[y];
				a[y] = v;
			}
		}
	}
	
	
	newlist = "";
	for (var x = 1; x <= l; x++){
		newlist = listappend(newlist,a[x],delim);
	}
	return( newlist);
}

MaxCityCount  = 10;


function SelectOption(tsource, thevalue, nocase){
	tsource.selectedIndex = -1;
	var hit = 0;
	for (var i = 0; i < tsource.length; i++) {
		if (listfind(thevalue.toLowerCase(),tsource.options[i].value.toLowerCase())>0 || tsource.options[i].value.toLowerCase() == thevalue.toLowerCase()) {
			tsource.options[i].selected = true;
			if (hit == 0 ){
				tsource.selectedIndex = i;
				hit = 1;
			}
		}
	}
}

function UpdateHiddenCityField(){
	f = document.searchForm;
	c = f.city;
	c.value = '';
	cc = f.chosencities;
	for (var i = 0; i < cc.length; i++) {
		c.value = listappend(c.value,cc.options[i].value);
	}
}

function addselectedcity(){
	f = document.searchForm;
	AddIf(f.citylist, f.chosencities);
	UpdateHiddenCityField();
}

function deleteselectedcity(){
	f = document.searchForm;
	RemoveSelected(f.chosencities);
	UpdateHiddenCityField();
}

function AddIf(tsource, tdest){
	for (var i = 0; i < tsource.length; i++) {
		if (tsource.options[i].selected) {
			addit = 1;
			for (var j = 0; j < tdest.length; j++) {
				if (tdest.options[j].value == tsource.options[i].value){
					addit=0;
					break;
				}
			}
			if (addit == 1){
				if (tdest.length < MaxCityCount){
					AddToSelect(tdest, tsource.options[i].text, tsource.options[i].value);
				} else {
					alert("You may search on up to "+MaxCityCount+" cities");
					return;
				}
			}
		}
	}
}

// this is set to yes after all the variables have been loaded
city_county_loaded = "no";
city_page_load_first_run = "Y";
// Changed this to N so that the Cities would reload on the first run ..
// county_page_load_first_run = "Y";

	county_page_load_first_run = "Y";


useall = true;
allfactor = 1;

function isdefined( variable) 
{ 
	return (typeof(window[variable]) == "undefined")?  false: true; 
}

// when all the variables have been loaded via the external js file the city_county_loaded variable will be set to yes.
// then we can move on
function checkDataLoad(){
	if (city_county_loaded == "no"){
		setTimeout ("checkDataLoad();", 1000);
	}else{
		updateCounties();
	}
}

// checks the current state (if one is defined) and populates the list of counties in the select box
function updateCounties(){
	f = document.searchForm;
	
	// blank the select box
	RemoveAll(f.county);

	// if we need to, add the 'all' option
	if (useall){
		AddToSelect(f.county,"All","");
	}

	// loop over the array of states, adding them to the dropdown
	if (isdefined("counties")){
		for (x=0; x<counties.length; x++){
			// a little test to make sure only the right counties show up if a state is chosen
			use_this_county = 1;
			
				chosen_state = "GA";
				if(states[x] != chosen_state){
					use_this_county = 0;
				}
			

			// if the state matches, or if there is no state, add it to the select
			if(use_this_county == 1){		
				AddToSelect(f.county,counties[x],counties[x]);
			}
		}
	}

	// select the first one
	f.county.selectedIndex=0;
	if (county_page_load_first_run == "Y"){
		county_page_load_first_run = "N";
		
			if ("" != ''){
				SelectOption(f.county, "", "");
			}else if ("" != ''){
				SelectOption(f.county, "", "");
				updateCities();
			}
			else if ("" != ''){
				SelectOption(f.county, "", "");
				updateCities();
			}
		
	}else{
		// populate the city list
		RemoveAll(f.chosencities);
		updateCities();
	}
}

// since i had to change the page after the fact to accomodate states, the counties are not in the nice
// order they were in orginally.  this function accepts a county name and returns the index of that county
// from within the js array that contains the city data
function getCountyIndex(countyname){
	chosen_state = "GA";
	for (x=0; x<counties.length; x++){
		if(counties[x] == countyname && states[x] == chosen_state){
			return(x);
		}
	}
}

// update the city dropdown according to chosen county or 'all' for a given state
function updateCities() {
	// blank the dropdown
	RemoveAll(f.citylist);
	// get the county array index
	countySelectIndex = f.county.selectedIndex - allfactor;
	// less than zero if they chose 'all'
	if (countySelectIndex < 0) {
		// now we choose which index points to the chosen state
		chosen_state = "GA";
		chosen_state_index = listfind(state_list, chosen_state);

		// loop over the state/city array and build the list
		if(chosen_state_index > 0){
			for (x=0; x<all_array[chosen_state_index].length; x++){
				AddToSelect(f.citylist, all_array[chosen_state_index][x], all_array[chosen_state_index][x]);
			}
		}else{
			// this will only happen if the admin puts a state in the list for a given market and there happen
			// to be no cities in the db that match.  this will be VERY rare, if ever.
			alert("No Cities in this state")
		}
	} else {
		// pull back the index for the chosen county
		countyIndex = getCountyIndex(f.county.options[f.county.selectedIndex].value)
		
		// loop over the county/city array and add to city select
		for (x=0; x<cities[countyIndex].length; x++){
			AddToSelect(f.citylist, cities[countyIndex][x], cities[countyIndex][x]);
		}
	}
}
var f;