function toggleClass(id,className){
	var obj = document.getElementById(id);
	obj.className = className;
}

function toggleTab(id){
	var obj = document.getElementById(id);
	if(obj.style.display=='block'){
		obj.style.display='none';
	}else{
		obj.style.display='block';
	}		
}

function submitDestinationForm(type){
	url = document.getElementById(type).value;
	window.location=url;
}

function swapImage(image_id,path){
	//change image
	var mainImage = document.getElementById('mainImage');
	var new_image = document.getElementById('image_'+image_id);
	mainImage.src = path;
	mainImage.alt = new_image.alt;
	mainImage.onClick = 'javascript:alert('+image_id+');';
	
	//remove border from old selected image
	var old_image = document.getElementById('image_'+currentImageId);
	old_image.className = '';
	//add border to new selected image
	new_image.className = 'current';	
	
	//set new image to page variable
	currentImageId = image_id;
}

function openImagePopUp(listing_id){
	fncNamedCenteredChildWindow('/includes/photos.php?id='+listing_id+'#'+currentImageId,'detailImages',600,900,'yes','yes')
}

function fncNamedCenteredChildWindow(URL,name,vHeight,vWidth,vScroll,vStatus){
	if (screen.width) {
		var winl=(screen.width-vWidth)/2;
		var wint=(screen.height-vHeight)/2;
	} else { 
		winl=0;wint=0;
	}
	if(winl<0)winl=0;
	if(wint<0)wint=0;
	var child = window.open(URL,name,'height='+vHeight+',width='+vWidth+',scrollbars='+vScroll+',status='+vStatus+',top='+wint+',left='+winl+',resizable=yes');
	if (window.focus) child.focus();
}


function refreshPropSubTypes(obj,section){
	refreshOptions('/includes/ajax.php?m=search&sm=pstype&section='+section+'&ptype='+obj.value,'pstype_id_div');
	var prop_size = document.getElementById('prop_size');
	if (obj.options[obj.options.selectedIndex].text == 'Vacant Land') {
    prop_size.options.length = 0;
    prop_size.options[0] = new Option("Any Size","9");
    prop_size.options[1] = new Option("< 1 acre","10");
    prop_size.options[2] = new Option("1 - 3 acres","11");
    prop_size.options[3] = new Option("3 - 10 acres","12");
    prop_size.options[4] = new Option("10 - 20 acres","13");
    prop_size.options[5] = new Option("20 - 50 acres","14");
    prop_size.options[6] = new Option("> 50 acres","15");
  } else {
    if (prop_size.options[1].text == "< 1 acre") {
      prop_size.options.length = 0;
      prop_size.options[0] = new Option("Any Size","0");
      prop_size.options[1] = new Option("< 1,000","1");
      prop_size.options[2] = new Option("1,000 - 3,000","2");
      prop_size.options[3] = new Option("3,000 - 5,000","3");
      prop_size.options[4] = new Option("5,000 - 7,000","4");
      prop_size.options[5] = new Option("7,000 - 10,000","5");
      prop_size.options[6] = new Option("10,000 - 15,000","6");
      prop_size.options[7] = new Option("15,000 - 20,000","7");
      prop_size.options[8] = new Option("20,000 +","8");
    }
  }
}
function refreshStates(obj,section){
	refreshOptions('/includes/ajax.php?m=search&sm=state&section='+section+'&region='+obj.value,'state_id_div');
}
function refreshCounties(obj,section){
	refreshOptions('/includes/ajax.php?m=search&sm=county&section='+section+'&state='+obj.value,'county_id_div');
}
function refreshIndustrySubs(obj,section){
	refreshOptions('/includes/ajax.php?m=search&sm=itype&section='+section+'&itype='+obj.value,'is_id_div');
}
function refreshProCatSubs(obj,section){
	refreshOptions('/includes/ajax.php?m=search&sm=pctype&section='+section+'&pctype='+obj.value,'psc_id_div');
}

function mapGo(state,mode,list_type) {
  switch (mode * list_type) {
    case 2:
      document.location = '/business/listing.php?listing_is_distressed=1&state_id='+state;
      break;
    case 3:
      document.location = '/commercial/listing.php?listing_is_distressed=1&state_id='+state;
      break;
    case 5:
      document.location = '/residential/listing.php?listing_is_distressed=1&state_id='+state;
      break;
    case 4:
      document.location = '/professionals/listing.php?pc_id=11&psc_id=130&state_id='+state;
      break;
    case 6:
      document.location = '/professionals/listing.php?pc_id=4&psc_id=48&state_id='+state;
      break;
    case 10:
      document.location = '/professionals/listing.php?pc_id=3&psc_id=29&state_id='+state;
      break;
    default:
      var element = document.getElementById('select').value;
      switch (element) {
        case '1':     //BUSINESS
          document.location = '/business/map.php?s='+state;
          break;
        case '2':     //COMMERCIAL
          document.location = 'commercial/map.php?s='+state;
          break;
        case '3':     //RESIDENTIAL
          document.location = 'residential/map.php?s='+state;
          break;
      }
      break;
  }
}

function refreshOptions(url,element){
	if(element){
		loadFragmentInToElement(url, element);
	}
}

function toggleAdDivs(obj){
	var current = currentAdDiv;
	toggleClass(currentAdDiv,'ad-div-hidden');
	toggleClass('adDiv'+obj.value,'ad-div-shown');
	currentAdDiv = 'adDiv'+obj.value;
}