// JavaScript Document
function loadContent(file){
  var head = document.getElementsByTagName('head').item(0)
  var scriptTag = document.getElementById('loadScript');
  if(scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  script.src = file;
	script.type = 'text/javascript';
	script.id = 'loadScript';
	head.appendChild(script)
							 }
function get_area(area)
{
var area_submit_html = "<a href='#' onclick='quick_search_filter()'><img src='images/ahib0803_38.png' border='0' /></a>";
var area_id = area;
	if (area_id == 'phx')
	{
		document.getElementById('area_phx').style.fontWeight = 'bold';
		document.getElementById('area_all').style.fontWeight = '';
		document.getElementById('area_tuc').style.fontWeight = '';
		document.getElementById('search_city').disabled = true;
		document.getElementById('search_city_alt').disabled = true;
		area_submit_html = "<a href='#' onclick=\"submit_area_filter('phx')\"><img src='images/ahib0803_38.png' border='0' /></a>";

	} else if (area_id == 'tuc')
	{
		document.getElementById('area_phx').style.fontWeight = '';
		document.getElementById('area_all').style.fontWeight = '';
		document.getElementById('area_tuc').style.fontWeight = 'bold';
		document.getElementById('search_city').disabled = true;
		document.getElementById('search_city_alt').disabled = true;
		area_submit_html = "<a href='#' onclick=\"submit_area_filter('tuc')\"><img src='images/ahib0803_38.png' border='0' /></a>";
	} else
	{
		document.getElementById('area_phx').style.fontWeight = '';
		document.getElementById('area_all').style.fontWeight = 'bold';
		document.getElementById('area_tuc').style.fontWeight = '';
		document.getElementById('search_city').disabled = false;
		document.getElementById('search_city_alt').disabled = false;
	}
	document.getElementById('quick_search_submit').innerHTML = area_submit_html;
}
function submit_area_filter(area)
{
var search_rent = document.getElementById('search_rent').value.split("*");
var price_min = search_rent[0];
var price_max = search_rent[1];
var beds=document.getElementById('search_bed').value;
var baths=document.getElementById('search_bath').value;
var search_garage=document.getElementById('search_garage').value;
var feature = "feature=";
if (search_garage != 'def') { feature += "garage"; }
var area_id = area;
	if (area_id == 'tuc')
	{
		loadContent("ahib_helper.php?action=advanced_search&"+feature+"&cities=Marana*Safford*Sahuarita*Tucson*Vail*Oro Valley"+"&price_min="+price_min+"&price_max="+price_max+"&sq_feet_min=def&sq_feet_max=def&address=&imagesonly=&beds="+beds+"&baths="+baths);
	} else
	{
		loadContent("ahib_helper.php?action=advanced_search&"+feature+"&cities=Maricopa*Mesa*Mesa East*Mesa West*Chandler*Gilbert*Queen Creek*Apache Junction*Arizona City*Fountain Hills*Gold Canyon*Scottsdale*Tempe*Ahwatukee*Florence*Coolidge*Eloy*San Tan Valley*Anthem*Avondale*Buckeye*El Mirage*Glendale*Goodyear*Laveen*Litchfield Park*Peoria*Phoenix West Surprise*Tolleson*Ahwatukee*Higley*Maricopa*Phoenix*Phoenix South*Tempe*Anthem*Phoenix North*Prescott Valley"+"&price_min="+price_min+"&price_max="+price_max+"&sq_feet_min=def&sq_feet_max=def&address=&imagesonly=&beds="+beds+"&baths="+baths);
	}
}
function quick_search_filter() {
//init vars
var search_rent=document.getElementById('search_rent').value;
var search_city=document.getElementById('search_city').value;
var search_city_alt=document.getElementById('search_city_alt').value;
var search_bed=document.getElementById('search_bed').value;
var search_bath=document.getElementById('search_bath').value;
var search_garage=document.getElementById('search_garage').value;

loadContent("ahib_helper.php?action=quick_search&search_rent="+search_rent+"&search_city="+search_city+"&search_city_alt="+search_city_alt+"&search_bed="+search_bed+"&search_bath="+search_bath+"&search_garage="+search_garage);

}
function qs_div_search() {
loadContent("ahib_helper.php?action=qs_div_search");
}
function close_qs() {
document.getElementById('qs_div').innerHTML="";
document.getElementById('qs_div').style.display='none';
}
function save_search_favs() {
document.getElementById('qs_div').style.display='';
loadContent("ahib_helper.php?action=save_search_favs");
}
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
function process_advanced() { 

//get all features into feature var
  var cb = getElementsByClass("feature"); 

  var feature = "feature="; 

  var isFirst = true;  for (var i = 0; i < cb.length; i++) { 

    var curr = cb[i]; 

    if (curr.type == "checkbox") { 

      // window.alert(curr.name + ": " + curr.type); 

      if (curr.checked) { 

        if (isFirst) { 

          feature = feature + curr.name; 

          isFirst = false; 

        } else { 

          feature = feature + "*" + curr.name; 

        } 

      } 

    } 

  } 
  //now get all cities into cities var
   var cb = getElementsByClass("cities"); 

  var cities = "cities="; 

  var isFirst = true;  for (var i = 0; i < cb.length; i++) { 

    var curr = cb[i]; 

    if (curr.type == "checkbox") { 

      // window.alert(curr.name + ": " + curr.type); 

      if (curr.checked) { 

        if (isFirst) { 

          cities = cities + curr.name; 

          isFirst = false; 

        } else { 

          cities = cities + "*" + curr.name; 

        } 

      } 

    } 

  } 
var price_min=document.getElementById('price_min').value;
var price_max=document.getElementById('price_max').value;
var beds=document.getElementById('beds').value;
var baths=document.getElementById('baths').value;
var sq_feet_min=document.getElementById('sq_feet_min').value;
var sq_feet_max=document.getElementById('sq_feet_max').value;
var address=document.getElementById('address').value;
var imagesonly;
	if(document.getElementById('imagesonly').checked==true) {
	imagesonly='Y';
	}
 // window.location = f.action + "?" + favorites; 
// alert("square feet min is "+sq_feet_min);
//loadContent...
loadContent("ahib_helper.php?action=advanced_search&"+feature+"&"+cities+"&price_min="+price_min+"&price_max="+price_max+"&sq_feet_min="+sq_feet_min+"&sq_feet_max="+sq_feet_max+"&address="+address+"&imagesonly="+imagesonly+"&beds="+beds+"&baths="+baths);


} //end process advanced function
function uncheck_as_cities() {
	//now get all cities into cities var
   var cb = getElementsByClass("cities"); 

  var cities = "cities="; 

  var isFirst = true;  for (var i = 0; i < cb.length; i++) { 

    var curr = cb[i]; 

    if (curr.type == "checkbox") { 

      // window.alert(curr.name + ": " + curr.type); 

      if (curr.checked) { 
		curr.checked=false;
        

      } 

    } 

  } 
	
	
	
	
} //end function uncheck advanced search cities
function run_compare() {
//now get all cities into cities var
   var cb = getElementsByClass("propcomp"); 

  var propcomp = "propcomp="; 

  var isFirst = true;  for (var i = 0; i < cb.length; i++) { 

    var curr = cb[i]; 

    if (curr.type == "checkbox") { 

      // window.alert(curr.name + ": " + curr.type); 

      if (curr.checked) { 

        if (isFirst) { 

          propcomp = propcomp + curr.name; 

          isFirst = false; 

        } else { 

          propcomp = propcomp + "*" + curr.name; 

        } 

      } 

    } 

  } 
//now process all of these properties for the comparison page...
loadContent("ahib_helper.php?action=rental_compare&"+propcomp);

}
function close_map(link_id) {
//close the map areas
document.getElementById('map_canvas_'+link_id).innerHTML="";
document.getElementById('pano_'+link_id).innerHTML="";
//hide the div areas
document.getElementById('map_canvas_'+link_id).style.display='none';
document.getElementById('pano_'+link_id).style.display='none';
document.getElementById('close_map_'+link_id).style.display='none';

}
function load_phase_two() {
var app_fname=document.getElementById('app_fname').value;
if(app_fname=='') {  
alert('You must fill out the first name field');
document.getElementById('app_fname').focus();

return false;
}
var app_lname=document.getElementById('app_lname').value;
if(app_lname=='') {  
alert('You must fill out the last name field');
document.getElementById('app_lname').focus();
return false;
}
var app_phone=document.getElementById('app_phone').value;
if(app_phone=='') {  
alert('You must fill out the phone field');
document.getElementById('app_phone').focus();
return false;
}
var app_birthdate=document.getElementById('app_birthdate').value;
if(app_birthdate=='') {  
alert('You provide your date of birth!');
document.getElementById('app_birthdate').focus();
return false;
}
var app_email=document.getElementById('app_email').value;
if(app_email=='') {  
alert('You must fill out the email field');
document.getElementById('app_email').focus();
return false;
}
var app_address=document.getElementById('app_address').value;
if(app_address=='') {  
alert('You must fill out the address field');
document.getElementById('app_address').focus();
return false;
}
var app_howlong_address=document.getElementById('app_howlong_address').value;
if(app_howlong_address=='') {  
alert('You must tell us how long you have been at this address!');
document.getElementById('app_howlong_address').focus();
return false;
}
var app_apartment_no=document.getElementById('app_apartment_no').value;
var app_city=document.getElementById('app_city').value;
if(app_city=='') {  
alert('You must fill out the city field');
document.getElementById('app_city').focus();
return false;
}
var app_state=document.getElementById('app_state').value;
if(app_state=='') {  
alert('You must fill out the state field');
document.getElementById('app_state').focus();
return false;
}
var app_zip=document.getElementById('app_zip').value;
if(app_zip=='') {  
alert('You must fill out the zipcode field');
document.getElementById('app_zip').focus();
return false;
}
var app_ssn=document.getElementById('app_ssn').value;
if(app_ssn=='') {  
alert('You must enter a valid ssn or fed id #!');
document.getElementById('app_ssn').focus();
return false;
}
var app_agent_name=document.getElementById('app_agent_name').value;
var rent_id=document.getElementById('rent_id').value;

loadContent("../ahib_helper.php?action=load_phase_two&app_fname="+app_fname+"&app_lname="+app_lname+"&app_phone="+app_phone+"&app_birthdate="+app_birthdate+"&app_email="+app_email+"&app_address="+app_address+"&app_howlong_address="+app_howlong_address+"&app_apartment_no="+app_apartment_no+"&app_city="+app_city+"&app_state="+app_state+"&app_zip="+app_zip+"&app_ssn="+app_ssn+"&app_agent_name="+app_agent_name+"&rent_id="+rent_id);
	
} //end function load_phase_two
function load_phase_three() {
var app_address=document.getElementById('app_address').value;
if(app_address=='') {  
alert('You must fill out the address field');
document.getElementById('app_address').focus();
return false;
}
var app_current_mopay=document.getElementById('app_current_mopay').value;
if(app_current_mopay=='') {  
alert('You must tell us your current monthly housing payment');
document.getElementById('app_current_mopay').focus();
return false;
}
var app_current_howlong_mopay=document.getElementById('app_current_howlong_mopay').value;
if(app_current_howlong_mopay=='') {  
alert('You must tell us how long you have made this payment.');
document.getElementById('app_current_howlong_mopay').focus();
return false;
}
var app_current_landlord=document.getElementById('app_current_landlord').value;
if(app_current_landlord=='') {  
alert('You must provide the name of your current landlord');
document.getElementById('app_current_landlord').focus();
return false;
}
var app_prev_address=document.getElementById('app_prev_address').value;
var app_prev_city=document.getElementById('app_prev_city').value;
var app_prev_state=document.getElementById('app_prev_state').value;
var app_prev_zip=document.getElementById('app_prev_zip').value;
var app_prev_address2=document.getElementById('app_prev_address2').value;
var app_prev_city2=document.getElementById('app_prev_city2').value;
var app_prev_state2=document.getElementById('app_prev_state2').value;
var app_prev_zip2=document.getElementById('app_prev_zip2').value;
var app_current_employer=document.getElementById('app_current_employer').value;
if(app_current_employer=='') {  
alert('You must provide the name of your current employer');
document.getElementById('app_current_employer').focus();
return false;
}
var app_current_years_atjob=document.getElementById('app_current_years_atjob').value;
if(app_current_years_atjob=='') {  
alert('You must provide the number of years at your current job.');
document.getElementById('app_current_years_atjob').focus();
return false;
}
var app_current_gross_income=document.getElementById('app_current_gross_income').value;
if(app_current_gross_income=='') {  
alert('You must provide your current gross yearly income.');
document.getElementById('app_current_gross_income').focus();
return false;
}
var app_prev_employer=document.getElementById('app_prev_employer').value;
var app_prev_years_atjob=document.getElementById('app_prev_years_atjob').value;
var app_prev_gross_income=document.getElementById('app_prev_gross_income').value;
var app_prev_employer2=document.getElementById('app_prev_employer2').value;
var app_prev_years_atjob2=document.getElementById('app_prev_years_atjob2').value;
var app_prev_gross_income2=document.getElementById('app_prev_gross_income2').value;

loadContent("../ahib_helper.php?action=load_phase_three&app_address="+app_address+"&app_current_mopay="+app_current_mopay+"&app_current_howlong_mopay="+app_current_howlong_mopay+"&app_current_landlord="+app_current_landlord+"&app_prev_address="+app_prev_address+"&app_prev_city="+app_prev_city+"&app_prev_state="+app_prev_state+"&app_prev_zip="+app_prev_zip+"&app_prev_address2="+app_prev_address2+"&app_prev_city2="+app_prev_city2+"&app_prev_state2="+app_prev_state2+"&app_prev_zip2="+app_prev_zip2+"&app_current_employer="+app_current_employer+"&app_current_years_atjob="+app_current_years_atjob+"&app_current_gross_income="+app_current_gross_income+"&app_prev_employer="+app_prev_employer+"&app_prev_years_atjob="+app_prev_years_atjob+"&app_prev_gross_income="+app_prev_gross_income+"&app_prev_employer2="+app_prev_employer2+"&app_prev_years_atjob2="+app_prev_years_atjob2+"&app_prev_gross_income2="+app_prev_gross_income2);	
	
}
//end function load phase III
function load_phase_four() {
var app_nearest_relative=document.getElementById('app_nearest_relative').value;
if(app_nearest_relative=='') {  
alert('You must provide the name of your closest relative.');
document.getElementById('app_nearest_relative').focus();
return false;
}
var app_relative_tele=document.getElementById('app_relative_tele').value;
if(app_relative_tele=='') {  
alert('You must provide the relative`s phone number.');
document.getElementById('app_relative_tele').focus();
return false;
}
var app_character_ref=document.getElementById('app_character_ref').value;
if(app_character_ref=='') {  
alert('You must provide an appropriate character or business reference.');
document.getElementById('app_character_ref').focus();
return false;
}
var app_character_relation=document.getElementById('app_character_relation').value;
if(app_character_relation=='') {  
alert('You must tell us what the character reference relationship is to you.');
document.getElementById('app_character_relation').focus();
return false;
}
var app_character_phone=document.getElementById('app_character_phone').value;
if(app_character_phone=='') {  
alert('You must provide a phone number for your character reference.');
document.getElementById('app_character_phone').focus();
return false;
}
var app_credit_reference=document.getElementById('app_credit_reference').value;
if(app_credit_reference=='') {  
alert('You must provide the name of a personal credit reference.');
document.getElementById('app_credit_reference').focus();
return false;
}
var app_bank_name=document.getElementById('app_bank_name').value;
if(app_bank_name=='') {  
alert('You must provide the name of your current bank.');
document.getElementById('app_bank_name').focus();
return false;
}
var app_bank_account_type=document.getElementById('app_bank_account_type').value;
if(app_bank_account_type=='') {  
alert('You must provide the bank account type.');
document.getElementById('app_bank_account_type').focus();
return false;
}
var app_bank_account_no=document.getElementById('app_bank_account_no').value;
if(app_bank_account_no=='') {  
alert('You must provide a valid bank account number.');
document.getElementById('app_bank_account_no').focus();
return false;
}

loadContent("../ahib_helper.php?action=load_phase_four&app_nearest_relative="+app_nearest_relative+"&app_relative_tele="+app_relative_tele+"&app_character_ref="+app_character_ref+"&app_character_relation="+app_character_relation+"&app_character_phone="+app_character_phone+"&app_credit_reference="+app_credit_reference+"&app_bank_name="+app_bank_name+"&app_bank_account_type="+app_bank_account_type+"&app_bank_account_no="+app_bank_account_no);	
	
}
function load_phase_five() {	
var app_pets;
if(document.getElementById('app_pets_y').checked==true) { app_pets='Y'; }
	else if(document.getElementById('app_pets_n').checked==true) { app_pets='N'; }
	else { alert('You must tell us if you have any pets!');return false;   }
	
var app_pets_no=document.getElementById('app_pets_no').value;
if(app_pets_no=='') {  
alert('You must tell us how many pets you have!');
document.getElementById('app_pets_no').focus();
return false;
}
var app_smoker;
if(document.getElementById('app_smoker_y').checked==true) { app_smoker='Y'; }
	else if(document.getElementById('app_smoker_n').checked==true) { app_smoker='N'; }
	else { alert('You must tell us if you or anyone else in the residence is a smoker!'); return false;  }
	
var app_smoker_no=document.getElementById('app_smoker_no').value;
if(app_smoker_no=='') {  
alert('You must tell us how many smokers will be in the residence!');
document.getElementById('app_smoker_no').focus();
return false;
}
var app_eviction;
if(document.getElementById('app_eviction_y').checked==true) { app_eviction='Y'; }
	else if(document.getElementById('app_eviction_n').checked==true) { app_eviction='N'; }
	else { alert('You must tell us if you have ever been evicted!');return false;   }
var app_civil_judgement;
if(document.getElementById('app_civil_judgement_y').checked==true) { app_civil_judgement='Y'; }
	else if(document.getElementById('app_civil_judgement_n').checked==true) { app_civil_judgement='N'; }
	else { alert('You must tell us if you have ever had a civil judgement on a rental property!');return false;   }
var app_collections;
if(document.getElementById('app_collections_y').checked==true) { app_collections='Y'; }
	else if(document.getElementById('app_collections_n').checked==true) { app_collections='N'; }
	else { alert('You must tell us if you have ever had a collections for a rental property!'); return false;  }
var app_convicted;
if(document.getElementById('app_convicted_y').checked==true) { app_convicted='Y'; }
	else if(document.getElementById('app_convicted_n').checked==true) { app_convicted='N'; }
	else { alert('You must tell us if you have ever been convicted of a felony!');return false;   }
	
var app_convicted_why=document.getElementById('app_convicted_why').value;
if(document.getElementById('app_convicted_y').checked==true && app_convicted_why=='') {  
alert('You must explain why you were convicted!');
document.getElementById('app_convicted_why').focus();
return false;
}	
var app_substance_abuser;
if(document.getElementById('app_substance_abuser_y').checked==true) { app_substance_abuser='Y'; }
	else if(document.getElementById('app_substance_abuser_n').checked==true) { app_substance_abuser='N'; }
	else { alert('You must tell us if you are currently using a controlled substance!');return false;   }
var app_substance_manuf;
if(document.getElementById('app_substance_manuf_y').checked==true) { app_substance_manuf='Y'; }
	else if(document.getElementById('app_substance_manuf_n').checked==true) { app_substance_manuf='N'; }
	else { alert('You must tell us if you have ever been convicted of the manufacture or distribution of a controlled substance!');return false;   }

loadContent("../ahib_helper.php?action=load_phase_five&app_pets="+app_pets+"&app_pets_no="+app_pets_no+"&app_smoker="+app_smoker+"&app_smoker_no="+app_smoker_no+"&app_eviction="+app_eviction+"&app_civil_judgement="+app_civil_judgement+"&app_collections="+app_collections+"&app_convicted="+app_convicted+"&app_convicted_why="+app_convicted_why+"&app_substance_abuser="+app_substance_abuser+"&app_substance_manuf="+app_substance_manuf);
	
} //end load phase five..
function finalize_app() {
if(document.getElementById('app_accepted').checked==true) {
var app_signature=document.getElementById('app_signature').value;
var app_dated=document.getElementById('app_dated').value;
//now finalize this application
loadContent("../ahib_helper.php?action=finalize_app&app_signature="+app_signature+"&app_dated="+app_dated);

														  } //end if 'Accepted' is checked
else {
alert('You must choose to `Accept` the application to proceed!');	
	
     }


}
function run_stats() {
try {
	//var feed_html=escape(document.getElementById('google_ads_frame1').src);
	//alert(feed_html);
	//setTimeout("loadContent('affiliate-list-inc.php?run_feed=Y&feed_html="+feed_html+"')",2000);
}
catch(e) {
	
}
	
}
