
var activeTab = "CurrentHomes";
function ToggleTab(tab){
	activeTab = tab;
	$get("Tab1").className='taboff2';
	$get("Tab2").className='taboff2';
	$get("Tab3").className='taboff2';
	$get("Tab4").className='taboff2';
	if (tab == 'CurrentHomes' || tab == 'OpenHouses') {
		if (tab == 'CurrentHomes')
			$get("Tab1").className='tabon2';
		else 
			$get("Tab2").className='tabon2';
		$get("tbRegion").className='show';
		$get("tbPrice").className='show';
		$get("tbLuxuryPrice").className='hide';
		$get("tbWaterFront").className='show';
		$get("tbZip").className='show';
		$get("tbLake").className='hide';
		$get("aAdvancedSearch").style.display='inline';
	}
	else if (tab == 'LuxuryHomes') {
		$get("Tab3").className='tabon2';
		$get("tbRegion").className='show';
		$get("tbPrice").className='hide';
		$get("tbLuxuryPrice").className='show';
		$get("tbWaterFront").className='show';
		$get("tbZip").className='show';
		$get("tbLake").className='hide';
		$get("aAdvancedSearch").style.display='inline';
	}
	else if (tab == 'FingerLakes'){
		$get("Tab4").className='tabon2';
		$get("tbRegion").className='hide';
		$get("tbPrice").className='show';
		$get("tbLuxuryPrice").className='hide';
		$get("tbWaterFront").className='hide';
		$get("tbZip").className='hide';
		$get("tbLake").className='show';
		$get("aAdvancedSearch").style.display='none';
	}
}

function getHTTPObject() {
	var xmlhttp;
 	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    	try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; }
	}
	else {
		try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) { 
			try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }	catch (E) { xmlhttp = false; } 
		} 
 	}
	return xmlhttp;
}

/* Removed 7/22/08 by JZ, new "region" dd list added, replaced radio btns
function getRegion() {
	radioObj = document.forms['frmSearch'].elements['radMLSID'];
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
*/

var http = null;
function refreshRegion(objSource) {
    http = getHTTPObject();
    if(http != null) {
		var strQS = '?MLSID=' + $get('ddRegion').value + '&CountyID=' + $get('ddCounty').value + '&Source=' + objSource.id;
		http.open("GET", "/_incs/getRegion.asp" + strQS, true);
       	http.onreadystatechange = function (aEvt) {
           	if(http.readyState == 4) {
               	if(http.status == "200") {
                   	var xmlDoc;
		        	var strHTMLCounties;
                   	if(window.ActiveXObject) { // IE
                   	    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                   	    xmlDoc.async = false;
                   	    xmlDoc.loadXML(http.responseText);
                   	}
                   	else if(document.implementation && document.implementation.createDocument) // Mozilla
                   	    xmlDoc = http.responseXML;

					// Counties
					var countyList = xmlDoc.documentElement.getElementsByTagName("county");
    	            if(countyList.length > 0) {
						strHTMLCounties =  '<select name="ddCounty" id="ddCounty" class="forminput" style="width:250px;" onchange="refreshRegion(this);">\r\n';
						strHTMLCounties += '  <option value="All">------- All Counties -------\r\n';
    	            	for (var i = 0; i < countyList.length; i++)
    	            	    strHTMLCounties += '  <option value="' + countyList[i].getAttribute("id") + '" >' + countyList[i].getAttribute("name") + '\r\n';
    	            	strHTMLCounties += '</select>\r\n'
    	            	$get('tdCounty').innerHTML = strHTMLCounties;
					}
					
					// Areas
					var areaList = xmlDoc.documentElement.getElementsByTagName("area");
                   	strHTMLAreas =  '<select name="ddArea" id="ddArea" class="forminput" style="width:250px;">\r\n';
					strHTMLAreas += '  <option value="">-------- All Areas --------\r\n';
                   	for (var i = 0; i < areaList.length; i++)
                   	    strHTMLAreas += '  <option value="' + areaList[i].getAttribute("id") + '" >' + areaList[i].getAttribute("name") + '\r\n';
                   	strHTMLAreas += '</select>\r\n'
                   	$get('tdArea').innerHTML = strHTMLAreas;
                   
					// Schools
					var schoolList = xmlDoc.documentElement.getElementsByTagName("school");
				    strHTMLSchools =  '<select name="ddSchool" id="ddSchool" class="forminput" style="width:250px;">\r\n';
					strHTMLSchools += '  <option value="">------- All Schools -------\r\n';
                   	for (var i = 0; i < schoolList.length; i++)
                   	    strHTMLSchools += '  <option value="' + schoolList[i].getAttribute("id") + '" >' + schoolList[i].getAttribute("name") + '\r\n';
                   	strHTMLSchools += '</select>\r\n'
                   	$get('tdSchool').innerHTML = strHTMLSchools;

               	}
           	}
       	};
       	http.send(null);
	} 
}

function runSearch() {
	$get("OH").value='';	
	$get("MLSID").value='';
	$get('County').value = '';
	$get('Area').value = '';
	$get('School').value = '';
	$get('PropertyType').value = '';
	$get('MinPrice').value = '';
	$get('MaxPrice').value = '';
	$get('WF').value = '';
	$get('Zip').value = '';
	$get('ListDate').value = '';
	$get('FL').value = '';
	if (activeTab == 'CurrentHomes' || activeTab == 'OpenHouses') {
		if (activeTab == 'OpenHouses')
		$get("OH").value='1';
		$get('MLSID').value = $get('ddRegion').value;
		$get('County').value = $get('ddCounty').value;
		$get('Area').value = $get('ddArea').value;
		$get('School').value = $get('ddSchool').value;
		$get('MinPrice').value = $get('ddMinPrice').value;
		$get('MaxPrice').value = $get('ddMaxPrice').value;
		$get('WF').value = $get('ddWF').value;
		$get('Zip').value = $get('txtZip').value;
	}
	else if (activeTab == 'LuxuryHomes') {
		$get('MLSID').value = $get('ddRegion').value;
		$get('County').value = $get('ddCounty').value;
		$get('Area').value = $get('ddArea').value;
		$get('School').value = $get('ddSchool').value;
		$get('PropertyType').value = '7,3';
		$get('MinPrice').value = $get('ddLMinPrice').value;
		$get('MaxPrice').value = $get('ddLMaxPrice').value;
		$get('WF').value = $get('ddWF').value;
		$get('Zip').value = $get('txtZip').value;
	}
	else if (activeTab == 'FingerLakes'){
		$get('FL').value = $get('ddLake').value;
		$get('MinPrice').value = $get('ddMinPrice').value;
		$get('MaxPrice').value = $get('ddMaxPrice').value;
		$get('WF').value = $get('ddWF').value;
	}
	$get('frmSearch').submit();
}

// slideshow
var slides = new Array(); var ims = new Array();
var speed = 60; var interval = 8000; var c = 1;
function createSlide(turl, iurl, copy) { slides[slides.length] = new Array(turl, iurl, copy); }
function loadImages() { 
	for(var i = 0; 
	i < slides.length; i++) { var img = new Image();
	img.src = slides[i][1]; ims[i] = img; } 
}
function swapImage() {
	o = c; c++; 
	if(c > slides.length) { c = 1; } 
	fadeSlide('slide' + o,1,'slide' + c,0); 
	setTimeout('swapImage();',interval);
	$get('slide' + o).style.zIndex = 0;
	$get('slide' + c).style.zIndex = 99;
}
function createSS() {
	loadImages();
	var HTML = '';
	for(var i = 0; i < slides.length; i++) {
		HTML += '<div id="slide' + (i + 1) + '" class="divSlide">';
		if(slides[i][0] != '') { HTML += ' <a href="' + slides[i][0] + '" title="' + slides[i][2] + '">'; }
		HTML += '  <img src="' + ims[i].src + '" alt="' + slides[i][2] + '" border="0" />';
		if(slides[i][0] != '') { HTML += ' </a>'; }
		HTML += '</div>';
	}
	$get('slideshow').innerHTML = HTML;
	$get('slide1').style.opacity = 1.0;
	$get('slide1').style.filter = "alpha(opacity=100)";
	$get('slide1').style.zIndex = 99;
	setTimeout('swapImage();',interval);
}
function fadeSlide(os,oo,ns,no) {
	$get(os).style.opacity = oo; $get(os).style.filter = "alpha(opacity=" + (oo * 100) + ")";
	$get(ns).style.opacity = no; $get(ns).style.filter = "alpha(opacity=" + (no * 100) + ")";
	if(oo > 0) { oo -= 0.20; no += 0.20; setTimeout('fadeSlide(\'' + os + '\',' + (Math.round(oo * 1000) / 1000) + ',\'' + ns + '\',' + (Math.round(no * 1000) / 1000) + ');',speed); }
}

// creates onload event handler
window.onload = function () { if ( refreshRegion ) { refreshRegion(document.frmSearch.ddRegion); setTimeout('createSS();',1); } }
