//<![CDATA[
jsHover = function() {
	if(document.getElementById("main_nav"))
	{
	var hEls = document.getElementById("main_nav").getElementsByTagName("LI");
		for (var i=0, len=hEls.length; i<len; i++) {
			if (hEls[i].className.indexOf('li_drop') + 1)
			{	
				hEls[i].onmouseover = function() { this.className +=" jshover"; }
				hEls[i].onmouseout = function() { this.className = this.className.replace(" jshover", ""); }
			}
		}
	}
}

if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1) window.attachEvent("onload", jsHover);

function gotoTN() {
	var TN_val = document.frmTN.select_TN[document.frmTN.select_TN.selectedIndex].value;
	if (TN_val != '') { document.location.href = TN_val }
}

function submitQuickContact() {
	var qc_submit = $('qc_submit');
	var qc_response = $('qc_response');
	var params = $('frmQuickContact').serialize();
	var validEmail = IsValidEmail($('quick_contact_email'));
	
	if (document.frmQuickContact.Name.value == '') { 
		alert('Please enter your name.'); 
		document.frmQuickContact.Name.focus(); 
		return false 
	} else if (document.frmQuickContact.Email.value == '') { 
		alert('Please enter your email address.'); 
		document.frmQuickContact.Email.focus(); 
		return false  
	} else if (document.frmQuickContact.Comments.value == '') { 
		alert('Please enter a question.'); 
		document.frmQuickContact.Comments.focus(); 
		return false  
	} else if (!validEmail) {
		alert('Please enter a valid email address.');
		document.frmQuickContact.Email.focus();
		return false;
	} else {
		var bindArgs = {
		method: 'post',
		parameters: params,	
		onFailure: function(){ // email was not sent
			qc_response.innerHTML = 'Unfortunately, a problem occurred and your email could not be sent. Please call 502-458=-4100 to report this problem.';
			new Effect.Highlight(qc_response, {queue: 'end', duration: 5.0});
			new Effect.Fade(qc_response, {queue: 'end', duration: 0.5});
			new Effect.Appear(qc_submit, {queue: 'end', duration: 0.5});
			return false
		},
		onSuccess: function(t){
			var returnVal = parseFloat(t.responseText);
			// Login unsuccessful
			if (returnVal <= 0) { // email was not sent
				qc_response.innerHTML = 'Unfortunately, a problem occurred and your email could not be sent. Please call 502-458=-4100 to report this problem.';
				new Effect.Highlight(qc_response, {queue: 'end', duration: 5.0});
				new Effect.Fade(qc_response, {queue: 'end', duration: 0.5});
				new Effect.Appear(qc_submit, {queue: 'end', duration: 0.5});
				return false
			} else { 			
				qc_response.innerHTML = '<strong>Success!</strong> Your message has been sent.  We\'ll get back to you as quickly as we can.  Thanks!';
				new Effect.Highlight(qc_response, {queue: 'end', duration: 8.0});
				new Effect.Fade(qc_response, {queue: 'end', duration: 0.5});
				new Effect.Appear(qc_submit, {queue: 'end', duration: 0.5});					
				return false
			}
		}
		};
		
		new Effect.Fade(qc_submit, {queue: 'end', duration: 0.1});
		new Effect.Appear(qc_response, {queue: 'end', duration: 0.1});
		new Ajax.Request('/res/includes/quick_contact_process.asp', bindArgs);	
		return false
	}
	
	return false
}

function removeVal(elm, initVal) {
	if ($F(elm) == initVal) {
	  $(elm).removeClassName('empty')
	  $(elm).value = '';
	 }	 	
}
 
function restoreVal(elm, initVal) {
	if ($F(elm) == '') {
	  $(elm).addClassName('empty')
	  $(elm).value = initVal;
	 }	 	
}

function cleanValue(numVal) {
	
	var emptyVal = '';
	var alphaNumExp = /^[0-9]+$/;
	
	var fieldToClean = numVal;
	
	if ((fieldToClean != "")) {
		var tempName = '';
		
		for(var i = 0; i < fieldToClean.length; i++) {
			var c = fieldToClean.charAt(i);
			if (c.match(alphaNumExp)) {
				tempName += c;
			}				
		}
		
		return tempName;
	}
	
	return emptyVal;
}

function runQuickSearch(searchType, searchAction) {
	var frmAction;
	var counter;
	
	if (searchAction == 'map') {
		frmAction = '/property-search/map/'
	}	else {
		frmAction = '/property-search/list/'
	}

	switch (searchType){
		case '1':
			document.frmQSArea.action = frmAction;
			document.frmQSArea.method = 'post';
			document.frmQSArea.target = '_parent';
			document.frmQSArea.submit();
			break;
		case '2': 
			document.frmQSSubdivision.action = frmAction;
			document.frmQSSubdivision.method = 'post';
			document.frmQSSubdivision.target = '_parent';
			document.frmQSSubdivision.submit();
			break;
	    case '3':
			for (counter = 0; counter < document.frmQSMLS.mls.length; counter++) {
				if (document.frmQSMLS.mls[counter].value == 'MLS #') {
					document.frmQSMLS.mls[counter].value = '';
				}
			}
			
			document.frmQSMLS.action = frmAction;	
			document.frmQSMLS.method = 'post';
			document.frmQSMLS.target = '_parent';
			document.frmQSMLS.submit();
			break;
		case '4':
			if (document.frmQSZipCode.zip.value == 'Enter Zip Codes') { document.frmQSZipCode.zip.value = '' }
			
			document.frmQSZipCode.action = frmAction;
			document.frmQSZipCode.method = 'post';
			document.frmQSZipCode.target = '_parent';
			document.frmQSZipCode.submit();
			break;
		case '5':
			if (document.frmQSStreetName.streetnumber1.value == 'Street #') { document.frmQSStreetName.streetnumber1.value = '' }
			if (document.frmQSStreetName.streetnumber2.value == 'Street #') { document.frmQSStreetName.streetnumber2.value = '' }
			if (document.frmQSStreetName.streetname1.value == 'Street Name') { document.frmQSStreetName.streetname1.value = '' }
			if (document.frmQSStreetName.streetname2.value == 'Street Name') { document.frmQSStreetName.streetname2.value = '' }

			document.frmQSStreetName.action = frmAction;
			document.frmQSStreetName.method = 'post';
			document.frmQSStreetName.target = '_parent';
			document.frmQSStreetName.submit();
			break;
		default:
			document.frmQSArea.action = frmAction;	
			document.frmQSArea.method = 'post';
			document.frmQSArea.target = '_parent';
			document.frmQSArea.submit();
			break;
	}
}

function runSidebarQuickSearch(searchType, searchAction) {
	var frmAction;
	var counter;
	var mls = '';
	var zip = '';
	var lbeds = '';
	var lbaths = '';
	var lprice = '';
	var uprice = '';
	var area = '';
	var subdivision = '';
	var streetname1 = '';
	var streetnumber1 = '';
	var quicksearchid = '';
	var sep = '';
	
	if (searchAction == 'map') {
		frmAction = '/property-search/map/'
	}	else {
		frmAction = '/property-search/list/'
	}
	
	switch (searchType){
		case '1':
			area = document.frmQSArea.qs_area[document.frmQSArea.qs_area.selectedIndex].value;
			lprice = document.frmQSArea.qs_lprice[document.frmQSArea.qs_lprice.selectedIndex].value;
			uprice = document.frmQSArea.qs_uprice[document.frmQSArea.qs_uprice.selectedIndex].value;
			lbeds = document.frmQSArea.qs_lbeds[document.frmQSArea.qs_lbeds.selectedIndex].value;
			lbaths = document.frmQSArea.qs_lbaths[document.frmQSArea.qs_lbaths.selectedIndex].value;
			mls = '';
			zip = '';
			subdivision = '';
			streetname1 = '';
			streetnumber1 = '';
			quicksearchid = '';

			break;
	    case '3':
			for (counter = 0; counter < document.frmQSMLS.qs_mls.length; counter++) {
				if (document.frmQSMLS.qs_mls[counter].value == 'MLS #') {
					document.frmQSMLS.qs_mls[counter].value = '';
				} else if (document.frmQSMLS.qs_mls[counter].value != '') {
					mls += (sep + document.frmQSMLS.qs_mls[counter].value)
					sep = ','
				}
			}
			
			quicksearchid = '1';
			sep = '';
			zip = '';
			area = '';
			subdivision = '';
			streetname1 = '';
			streetname1 = '';
			lbeds = '';
			lbaths = '';
			lprice = '';
			uprice = '';

			break;
		case '4':
			if (document.frmQSZipCode.qs_zip.value == 'Enter Zip Codes') { document.frmQSZipCode.qs_zip.value = '' }
			
			zip = document.frmQSZipCode.qs_zip.value
			lprice = document.frmQSZipCode.qs_lprice[document.frmQSZipCode.qs_lprice.selectedIndex].value;
			uprice = document.frmQSZipCode.qs_uprice[document.frmQSZipCode.qs_uprice.selectedIndex].value;
			lbeds = document.frmQSZipCode.qs_lbeds[document.frmQSZipCode.qs_lbeds.selectedIndex].value;
			lbaths = document.frmQSZipCode.qs_lbaths[document.frmQSZipCode.qs_lbaths.selectedIndex].value;
			mls = '';
			area = '';
			subdivision = '';
			streetname1 = '';
			streetnumber1 = '';		
			quicksearchid = '';

			break;
		case '5':
			if (document.frmQSStreetName.qs_streetnumber1.value == 'Enter Street #') { document.frmQSStreetName.qs_streetnumber1.value = '' } 
			if (document.frmQSStreetName.qs_streetname1.value == 'Enter Street Name') { document.frmQSStreetName.qs_streetname1.value = '' }
			
			streetnumber1 = document.frmQSStreetName.qs_streetnumber1.value;
			streetname1 = document.frmQSStreetName.qs_streetname1.value;
			quicksearchid = '3';
			
			zip = '';
			area = '';
			subdivision = '';
			lbeds = '';
			lbaths = '';
			lprice = '';
			uprice = '';

			break;
		default:
			zip = '';
			area = '';
			subdivision = '';
			streetname1 = '';
			streetname1 = '';
			lbeds = '';
			lbaths = '';
			lprice = '';
			uprice = '';
			mls = '';
			break;
	}
	
	document.frmQSSubmitter.quicksearchid.value = quicksearchid;
	document.frmQSSubmitter.area.value = area;
	document.frmQSSubmitter.uprice.value = uprice;
	document.frmQSSubmitter.lprice.value = lprice;
	document.frmQSSubmitter.lbeds.value = lbeds;
	document.frmQSSubmitter.lbaths.value = lbaths;
	document.frmQSSubmitter.subdivision.value = subdivision;
	document.frmQSSubmitter.zip.value = zip;
	document.frmQSSubmitter.mls.value = mls;
	document.frmQSSubmitter.streetname1.value = streetname1;
	document.frmQSSubmitter.streetnumber1.value = streetnumber1;
	
	document.frmQSSubmitter.action = frmAction;
	document.frmQSSubmitter.submit();
	
	return false
}

function qsvalidateLPrice()
{
		
	var lPrice = document.getElementById('qs_lprice');
	var uPrice = document.getElementById('qs_uprice');
	
	var minPrice = parseInt(lPrice.options[lPrice.selectedIndex].value);
	var maxPrice = parseInt(uPrice.options[uPrice.selectedIndex].value);
	
	if(isNaN(maxPrice))
	{
		maxPrice = 0;
	}
	var newSelected = false;

	var newMax = lPrice.options[lPrice.selectedIndex + 1].value;
	if(maxPrice > newMax)
	{
		newMax = maxPrice;
	}
	
	for (var i=1;i<lPrice.options.length; i++)
	{
	
		if(parseInt(lPrice.options[i].value) < minPrice)
		{
			//alert("Set it grey");			
			//lPrice.options[i].style.color='#999999';
		}
		else if(parseInt(lPrice.options[i].value) <= newMax)
		{
			lPrice.options[i].style.color='#000000';
		}
		else
		{
			break;
		}
	}

	for (var i=uPrice.options.length - 1;i>=0; i--) {
		if(parseInt(uPrice.options[i].value) < minPrice)
		{
			//uPrice.options[i].disabled = true;					
			//alert(i);
			//alert(uPrice.options[i].style.color);
			uPrice.options[i].style.color = '#CCCCCC';
			//alert(uPrice.options[i].style.color);
			if(!newSelected && maxPrice < minPrice)
			{
				if( (i + 2) < uPrice.options.length)
				{					
					if(uPrice.selectedIndex != 0)
					{
						uPrice.options[i + 2].selected = true;
					}
					newSelected = true;
				}
			}
			//uPrice.remove(i);
		}
		else
		{
			uPrice.options[i].style.color='#000000';
			//uPrice.options[i].disabled = false;
		}
	}

}

function qsvalidateUPrice()
{	

	var lPrice = document.getElementById('qs_lprice');
	var uPrice = document.getElementById('qs_uprice');
	
	var minPrice = parseInt(lPrice.options[lPrice.selectedIndex].value);
	var maxPrice = parseInt(uPrice.options[uPrice.selectedIndex].value);
	
	if(isNaN(minPrice))
	{
		minPrice = 0;
	}
	uPrice.options[uPrice.selectedIndex].style.color = '#000000';
	//var newSelected = false;
	for (var i=lPrice.options.length - 1;i>=0; i--) {
		if(parseInt(lPrice.options[i].value) >= maxPrice)
		{
			lPrice.options[i].style.color='#CCCCCC';
			//lPrice.options[i].disabled = true;
			//lPrice.options[i].style.display = "none"
			//lPrice.remove(i);
			if( minPrice > maxPrice)
			{
				lPrice.options[i - 1].selected = true;	
				lPrice.options[i - 1].style.color = '#000000';
			}
		}	
		else if(parseInt(lPrice.options[i].value) >= minPrice)
		{
			lPrice.options[i].style.color='#000000';
			//lPrice.options[i].disabled = false;
		}
	}
}

// validate an email address, returns bool
function IsValidEmail(element){
	// assume an email address cannot start with an @ or white space, but it
	// must contain the @ character followed by groups of alphanumerics and '-'
	// followed by the dot character '.'
	// It must end with 2 or 3 alphanumerics.
	var e = element.value;
	var alnum="a-zA-Z0-9";
	exp="^[^@\\s]+@(["+alnum+"+\\-]+\\.)+["+alnum+"]["+alnum+"]["+alnum+"]?$";
	emailregexp = new RegExp(exp);

	result = e.match(emailregexp);
	if (result != null)
	{
		return true;
	}
	else
	{
		return false;
	}
}

// ----------------------------------------------------------------
// Homepage rotating slideshow for what is my home worth feature
// ----------------------------------------------------------------
function setupHomeSlideShow() {

	home_Pic[0] = '/res/images/home-value/rotator-1.png';
	home_PicCaption[0] = 'Complete recent home sales data';
	
	home_Pic[1] = '/res/images/home-value/rotator-2.png';
	home_PicCaption[1] = 'Search recent sales in your neighborhood';
		
	home_Pic[2] = '/res/images/home-value/rotator-3.png';
	home_PicCaption[2] = 'Compare asking prices vs. sold prices';
	
	home_m_intCurrentIndex = -1;
	home_m_intArrayLen = home_Pic.length;
	home_preLoad = new Array();	
	
	for (i = 0; i < home_m_intArrayLen; i++)	{
		home_preLoad[i] = new Image();
		home_preLoad[i].src = home_Pic[i];
	}// end for
}

function runHomeSlideShow() {		
	// if there is a SLIDE SHOW
	if (home_m_intArrayLen > 0) { 
		home_m_intCurrentIndex = home_m_intCurrentIndex + 1;
		if (home_m_intCurrentIndex > (home_m_intArrayLen-1)) { home_m_intCurrentIndex = 0; }
		if (!(home_first)) { displayHomeSlide();  }
		home_first = false;
		clearTimeout(home_m_intTimeOut);
		home_m_intTimeOut = setTimeout('runHomeSlideShow()', home_slideShowSpeed);
	}
}

function displayHomeSlide() {
	new Effect.Fade($('home_value'),{ queue: 'end', duration: 1, afterFinish: function() { $('home_value').src = home_preLoad[home_m_intCurrentIndex].src; } });
	new Effect.Appear($('home_value'),{ queue: 'end', duration: 1 });
}

// ----------------------------------------------------------------
// Interior rotating slideshow for what is my home worth feature
// ----------------------------------------------------------------

function setupIntSlideShow() {

	int_Pic[0] = '/res/images/home-value/rotator-int-1.png';
	int_PicCaption[0] = 'Complete recent home sales data';
	
	int_Pic[1] = '/res/images/home-value/rotator-int-2.png';
	int_PicCaption[1] = 'Search recent sales in your neighborhood';
		
	int_Pic[2] = '/res/images/home-value/rotator-int-3.png';
	int_PicCaption[2] = 'Compare asking prices vs. sold prices';
	
	int_m_intCurrentIndex = -1;
	int_m_intArrayLen = int_Pic.length;
	int_preLoad = new Array();	
	
	for (i = 0; i < int_m_intArrayLen; i++)	{
		int_preLoad[i] = new Image();
		int_preLoad[i].src = int_Pic[i];
	}// end for
}

function runIntSlideShow() {		
	// if there is a SLIDE SHOW
	if (int_m_intArrayLen > 0) { 
		int_m_intCurrentIndex = int_m_intCurrentIndex + 1;
		if (int_m_intCurrentIndex > (int_m_intArrayLen-1)) { int_m_intCurrentIndex = 0; }
		if (!(int_first)) { displayIntSlide();  }
		int_first = false;
		clearTimeout(int_m_intTimeOut);
		int_m_intTimeOut = setTimeout('runIntSlideShow()', int_slideShowSpeed);
	}
}


function displayIntSlide() {
	new Effect.Fade($('int_value'),{ queue: 'end', duration: 1, afterFinish: function() { $('int_value').src = int_preLoad[int_m_intCurrentIndex].src; } });
	new Effect.Appear($('int_value'),{ queue: 'end', duration: 1 });
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
		   
function popOHWin (theURL) { 
  var newWin = window.open(theURL, 'OHWin', 'location=1,status=1,scrollbars=1,resizable=1,toolbar=1,width=770,height=550');
}
		   
function popWin (theURL) { //v2.0
  var newWin = window.open(theURL, 'realtyInfo', 'location=1,status=1,scrollbars=1,resizable=1,toolbar=1,width=770,height=540');
  newWin.moveTo(10,10); 
}

function vidWin (theURL,theName,theFeatures) {
  var newVid = window.open(theURL, theName, theFeatures);
}
 
function noSpam(user,domain) {
locationstring = "mailto:" + user + "@" + domain;
window.location = locationstring;
}
 
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//]]>