// Set the tabs to active
function setActiveTab(which) {
	switch(which) {
		case 'sales':
			document.getElementById('sSales').className = 'search_salesActive';
			document.getElementById('sRentals').className = 'search_rentals';
			document.getElementById('sOpen').className = 'search_open';
		break;
		
		case 'rentals':
			document.getElementById('sRentals').className = 'search_rentalsActive';
			document.getElementById('sOpen').className = 'search_open';
			document.getElementById('sSales').className = 'search_sales';
		break;
		
		case 'open':
			document.getElementById('sOpen').className = 'search_openActive';
			document.getElementById('sRentals').className = 'search_rentals';
			document.getElementById('sSales').className = 'search_sales';
		break;
	}			
}

function turnBed(bed,chkBox,position,iePos) {
	var dom = document.getElementById(chkBox);
	
	if(document.all) {
		if(!dom.checked) {
			bed.style.backgroundPosition = position;
			dom.checked = true;
		} else {
			bed.style.backgroundPosition = iePos;
			dom.checked = false;
		}
	}
	else {
		if(!dom.checked) {
			bed.style.backgroundPosition = position;
			dom.checked = true;
		} else {
			bed.style.backgroundPosition = '';
			dom.checked = false;
		}
	}
}

// Set the bedrooms active or not... using hidden checkboxes
function setBedroom(bed,chkBox) {	
	switch(bed.className) {		
		case 'one_bedroom':	
			turnBed(bed,chkBox,'0px -60px','0px 0px');
		break;
		case 'two_bedroom':
			turnBed(bed,chkBox,'-48px -60px','-48px 0px');
		break;
		case 'three_bedroom':
			turnBed(bed,chkBox,'-96px -60px','-96px 0px');
		break;
		case 'four_bedroom':
			turnBed(bed,chkBox,'0px -90px','0px -30px');
		break;
		case 'five_bedroom':
			turnBed(bed,chkBox,'-48px -90px','-48px -30px');
		break;
		case 'unknown_bedroom':
			turnBed(bed,chkBox,'-96px -90px','-96px -30px');
		break;
	}	
}


// Set the image map section to active
function setActive(theId,which) {
	var dom = document.getElementById(which);
	var active = which+'Active';
	if(dom.className == active) { 
		dom.className = ''; 
	}	
	else { 
		dom.className = active; 
	}
	
	checkIt(theId,dom.className);
}

// Set up which checkboxes to check
function checkIt(id,className) {
	var checkState = className=="" ? false : true;	
	var whatCheckBoxes = new Array();
	
	switch(id) {
		case 'inwood': whatCheckBoxes.push("inwood"); break;
		case 'harlem': whatCheckBoxes.push("harlem"); break;
		case 'hamilton': whatCheckBoxes.push("hamilton"); break;				
		case 'east_village': whatCheckBoxes.push("east_village","noho"); break;
		case 'upper_eastside': whatCheckBoxes.push("upper_eastside","carnegie_hill","lenox_hill", "yorkville"); break;
		case 'upper_westside': whatCheckBoxes.push("upper_westside","lincoln_square","manhattan_valley", "morningside_hts"); break;
		case 'midtown_west': whatCheckBoxes.push("midtown_west","clinton","theatre_district","fashion_center","carnegie_hall"); break;
		case 'midtown_east': whatCheckBoxes.push("midtown_east","sutton_place","turtle_bay","murray_hill","kips_bay"); break;
		case 'murray_hill': whatCheckBoxes.push("murray_hill"); break;
		case 'chelsea': whatCheckBoxes.push("chelsea"); break;
		case 'gramercy_park': whatCheckBoxes.push("gramercy_park","union_square"); break;
		case 'west_village': whatCheckBoxes.push("west_village","greenwich_village"); break;				
		case 'soho': whatCheckBoxes.push("soho"); break;
		case 'lower_east_side': whatCheckBoxes.push("lower_east_side");	break;
		case 'tribeca': whatCheckBoxes.push("tribeca");	break;
		case 'chinatown': whatCheckBoxes.push("chinatown");	break;
		case 'battery_park_city': whatCheckBoxes.push("battery_park_city");	break;
		case 'financial_district': whatCheckBoxes.push("financial_district");break;				
	}
	
	makeCheck(id,whatCheckBoxes,checkState);
}

// Turn the checkboxes to CHECKED OR UNCHECKED
function makeCheck(id,boxes,checkOrUncheck) {
	for(var j=0; j < boxes.length; j++) {
		var dom = document.getElementById(boxes[j]);
		dom.checked = checkOrUncheck;				
	}			
}


// JavaScript Document
function checkArea(area) {
	
	
	if (theForm.cat[area-1].checked) {
	 	isOn = false;
	} else {
		isOn = true;
	}
	document.theForm.cat[area-1].checked = isOn;
}

function checkAreas(from,to) {
	if (document.theForm.cat[from].checked) {
	 	isOn = true;
	} else {
		isOn = false;
	}
	for (i=from; i<to+1; i++) {
		if (document.theForm.cat[i]) {
			document.theForm.cat[i].checked = isOn;
		}
	}

}


