var county_cities = {		
	mapping: {},
	add: function(county, cities) {
		county_cities.mapping[county] = cities;
	},
	get: function(county) {
		return county_cities.mapping[county];
	},
	set_cities: function(search_type) {
			var city_html = '';
			var search_types_county = {'qs': 'qs_county', 'as': 'county'}
			var search_types_cites = {'qs': 'qs_city', 'as': 'city'}
			if (jQuery('#' + search_types_county[search_type]).size() > 0) {
				var cities = county_cities.get(jQuery('#' + search_types_county[search_type]).val()).split('|');
				for (i=0;i < cities.length ; i++){
					city_html += '<option value="' + cities[i].toUpperCase() + '">' + cities[i].toUpperCase() + '</option>';
				}
				jQuery('#' + search_types_cites[search_type]).html(city_html);
			}
	}
}


function map_initialize(street_number, street_name, town, county, zip_code) {
  var address = new Array();
  if (street_number) {
	  address.push(street_number);
  }
  if (street_name) {
	  address.push(street_name);
  }
  if (town) {
	  address.push(town);
  }
  if (county) {
	  address.push(county);
  }
  if (zip_code) {
	  address.push(zip_code);
  }
  address = address.join(", ");
  try {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 13);
        var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(address);
		map.setZoom(100)
		map.setUIToDefault();
      }
    }
  );
  } catch (e) {}
}

function morg_calculate(form) {
	var LoanAmount = form.LoanAmount.value;
	var DownPayment = "0";
	var AnnualInterestRate = form.InterestRate.value/100;
	var Years = form.NumberOfYears.value;
	var MonthRate = AnnualInterestRate/12;
	var NumPayments = Years*12;
	var Prin = LoanAmount-DownPayment;
	var MonthPayment = Math.floor((Prin*MonthRate)/(1-Math.pow((1+MonthRate),(-1*NumPayments)))*100)/100;

	form.NumberOfPayments.value = NumPayments;
	form.MonthlyPayment.value = MonthPayment;
} 

function remove_from_array(value) {
	arr = ($j.cookie('compare_list')) ? $j.cookie('compare_list').split('_') : new Array();
	var return_vars = new Array();
	for(i=0;i<arr.length;i++) {
		if (arr[i] != value) {
			return_vars.push(arr[i]);
		}
	}
	$j.cookie('compare_list', return_vars.join('_'), {path:'/'});
}

function add_to_array(value) {
	arr = ($j.cookie('compare_list')) ? $j.cookie('compare_list').split('_') : new Array();
	if ($j.inArray(value.toString(), arr) === -1) {	
		arr.push(value);
	}
	$j.cookie('compare_list', arr.join('_'), {path:'/'});
}



function show_compare_list() {
	compare_list = ($j.cookie('compare_list')) ? $j.cookie('compare_list').split('_') : new Array();
	if ($j('#compare_list_div').size())	{
		$j('#compare_list_div').find('.compare_num').html(compare_list.length);
		if (compare_list.length > 0)	{
			if ($j('#compare_list_div').is(':hidden')) 	{
				$j('#compare_list_div').slideDown();
			}
			if (compare_list.length > 1) {
				$j('#compare_button').val('Compare');	
				$j('#compare_button').attr('can_compare', 'yes');
			}
			else {
				$j('#compare_button').val( 'Select Atleast Two' );
				$j('#compare_button').attr('can_compare', 'no');
			}
		}
		else {
			$j('#compare_list_div').hide();
		}
	}
}

function check_compare_list() {
	compare_list = ($j.cookie('compare_list')) ? $j.cookie('compare_list').split('_') : new Array();
	$j('.comparison').each(function() {
		if ($j.inArray($j(this).val(), compare_list) !== -1) {
			$j(this).attr('checked', 'checked');
		}
		else {
			$j(this).removeAttr('checked');
		}
	});
}

function showWindow(url) {
    var prefs = "width=650,height=600,scrollbars=yes,directories=no,location=no,menubar=no,status=no,toolbar=no";
    window.open(url, "", prefs);
    return false;
}

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
}


