<!--

var PrintWindow=0;
var PrintHelp=0;
var Multiview=0;
var Go=false;
var CMA=false;

// print helper for ie4
function printIsNativeSupport() {
  var agent = window.navigator.userAgent;
  var i = agent.indexOf("MSIE ")+5;
  return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}

// pops print dialog in ie5
function PrintReport()
{
	TogglePrintDisplay(false);
	if ( printIsNativeSupport() )
	{
		window.print();
		TogglePrintDisplay(true);
	}
}

// Called when user toggles show photos on and off
function ShowPhotosClick( chkBox )
{
	if(!Go)
		RefreshPage();
	else
	{
		if ( chkBox.checked )
			mainform.elements('ShowPhotos').value = 1;
		else
			mainform.elements('ShowPhotos').value = 0;
	}
}


// Routine returns true if checkbox is for data row
function IsDataCheckbox( formElement )
{
	if (( formElement.type == "checkbox" ) && 
		( formElement.name != 'SetSpecialOrder' ) && 
		( formElement.name != 'PrintLandscape' ) &&
		( formElement.name != 'ShowPhotosChkBox' ))
		return true;
	else
		return false;
}


// Routine to addup the number of checked data records in the form and display to user
function ResultsCountTagged(myform) 
{
	var myitem=myform.multiview;
	if(!Go)
		RefreshPage();
	else
	{
		var intCount = 0;
		for(count=0;count<myform.elements.length-1;count++)
		{
			if ( IsDataCheckbox( myform.elements[count] ) && myform.elements[count].checked )
				intCount++;
		}
		alert("You have " + intCount + " properties tagged");
	}
}

// Routine to re-add check labels after a search results page is reordered.  Needed
// as otherwise when going 'back' to the page the numbers in the labels are gone
function ResultsUpdateLabels( blnForce )
{
	var chkBox;
	var intOrder = -1;

	if ( Go && mainform.elements('SetSpecialOrder').checked )
	{
		var colSpan = document.all.tags("SPAN");
		
		mainform.elements('SpecialOrder').value = 1;
			
		for ( i=0; i<mainform.elements.length; i++ )
		{
			chkBox = mainform.elements(i);
			if ( IsDataCheckbox( chkBox ) )
			{
				if ( chkBox.checked )
				{
					if (( Number(chkBox.value) == -1 ) || ( intOrder != -1 ))
					{
						if ( intOrder == -1 )
						{
							// First checked one - abort if labels already there
							intOrder = 1;
							if (( colSpan(chkBox.name + '-LABEL').innerHTML != '' ) && !blnForce )
								return;
						}
						chkBox.value = intOrder;
						intOrder = intOrder + 1;
					}
					colSpan(chkBox.name + '-LABEL').innerHTML = Number(chkBox.value);
				}
				else
				{
					chkBox.value = -1;
					colSpan(chkBox.name + '-LABEL').innerHTML = '';
				}
			}
		}
	}
}


// Called when user toggles show order labels on and off
function ResultsShowOrder( chkOrder )
{
	var chkBox;
	var intOrder = 1;
	var blnShowSpecialOrder = chkOrder.checked;

	if(!Go)
		RefreshPage();
	else
	{
		var colSpan = document.all.tags("SPAN");
		
		if ( blnShowSpecialOrder )
			mainform.elements('SpecialOrder').value = 1;
		else
			mainform.elements('SpecialOrder').value = 0;
			
		for ( i=0; i<mainform.elements.length; i++ )
		{
			chkBox = mainform.elements(i);
			if ( IsDataCheckbox( chkBox ) )
			{
				if ( blnShowSpecialOrder && chkBox.checked )
				{
					chkBox.value = intOrder;
					colSpan(chkBox.name + '-LABEL').innerHTML = intOrder;
					intOrder = intOrder + 1;
				}
				else
				{
					chkBox.value = -1;
					colSpan(chkBox.name + '-LABEL').innerHTML = '';
				}
			}
		}
	}
}


// Checks or unchecks all checkboxes on search results supporting ordering
function ResultsCheckAll( mainform, bCheck )
{
	var chkBox;
	var blnShowSpecialOrder = mainform.elements('SetSpecialOrder').checked;
	var colSpan = document.all.tags("SPAN")

	if(!Go)
		RefreshPage();
	else
	{
		var iRowOrder = 1

		for ( i=0; i<mainform.elements.length; i++ )
		{
			chkBox = mainform.elements(i);
			if ( IsDataCheckbox( chkBox ) )
			{
				chkBox.checked = bCheck;
				if ( !bCheck )
				{
					// Removing all checks
					chkBox.value = -1;
					if ( blnShowSpecialOrder )
						colSpan(chkBox.name + '-LABEL').innerHTML = '';
				}
				else
				{
					// Checking so add order text
					chkBox.value = iRowOrder;
					if ( blnShowSpecialOrder )
						colSpan(chkBox.name + '-LABEL').innerHTML = iRowOrder;
					iRowOrder++;
				}
			}

		}
	}
}


// Adjust the row order in SR report due to a check/uncheck.
function ResultsChangeOrder( chkRow )
{
	var intChangedOrder, chkBox, intOrder;

	if ( mainform.elements('SetSpecialOrder').checked )
	{
		var colSpan = document.all.tags("SPAN");
		
		if ( chkRow.checked )
		{
			// Just checked one - scan to see greatest number 
			intChangedOrder = 0;
			for ( i=0; i<mainform.elements.length; i++ )
			{
				chkBox = mainform.elements(i);
				if ( IsDataCheckbox( chkBox ) )
				{
					intOrder = Number(chkBox.value);
					if ( intOrder > intChangedOrder )
						intChangedOrder = intOrder;
				}
			}
			intChangedOrder++;
			chkRow.value = intChangedOrder;
			ShowCheckOrder(chkRow);
			colSpan(chkRow.name + '-LABEL').innerHTML = intChangedOrder;
		}
		else
		{
			// We just unchecked this row - clear order
			intChangedOrder = Number(chkRow.value);
			chkRow.value = -1;
			ShowCheckOrder(chkRow);
			colSpan(chkRow.name + '-LABEL').innerHTML = '';

			// Adjust other orders above one unchecked
			for ( i=0; i<mainform.elements.length; i++ )
			{
				chkBox = mainform.elements(i);
				if ( IsDataCheckbox( chkBox ) )
				{
					intOrder = Number(chkBox.value);
					if ( intOrder > intChangedOrder )
					{
						chkBox.value = intOrder-1;
						colSpan(chkBox.name + '-LABEL').innerHTML = intOrder-1;
					}
				}
			}
		}
	}
}


// Show the check order in the status bar
function ShowCheckOrder( chkBox )
{
	if ( mainform.elements('SetSpecialOrder').checked )
	{
		if ( chkBox.checked && ( Number(chkBox.value) != -1 ))
			window.status = 'Report order ' + chkBox.value;
		else
			window.status = 'Unchecked';
	}
	else
		window.status = '';
}


// Following 4 routines support the GridReport.asp code
// Add fields selected in listbox to those selected in column checkboxes via server trip
function GridReviseReport()
{
	var strURL = 'GridReport.asp?ReportID=Grid&PropType=' + strPropType;
	var blnFirst = true;
	var chkBox;
	var colSpan = document.all.tags("SPAN");

	// See how many field selection columns are checked
	var intChecked = 0;
	for ( i=0; i<mainform.elements.length; i++ )
	{
		chkBox = mainform.elements(i);
		if (( chkBox.type == 'checkbox' ) && ( chkBox.checked ))
			if ( chkBox.name.substr(0,8) == 'gridCOL-' )
				intChecked++;
	}

	// If some checked add these in order of check
	if ( intChecked > 0 )
	{
		var intNext = 1;
		
		while ( intNext <= intChecked )
		{	
			var intWasNext = intNext;
			for ( i=0; i<mainform.elements.length; i++ )
			{
				chkBox = mainform.elements(i);
				if (( chkBox.type == 'checkbox' ) && ( chkBox.checked ))
				{
					if ( chkBox.name.substr(0,8) == 'gridCOL-' )
					{
						if ( Number(chkBox.value) == intNext )
						{
							if ( !blnFirst )
								strURL = strURL + ',';
							else
							{
								strURL = strURL + '&Fields=';
								blnFirst = false;
							}

							var strValue = colSpan(chkBox.name + '-LABEL').value;
							if ( strValue != 'undefined' )
								strURL = strURL + strValue;

							intNext++;
						}
					}
				}
			}
			if ( intWasNext == intNext )
				intChecked = 0;
		}
	}

	// Add on any new fields from list box
	var objList = mainform.elements['gridNewFields']
	for ( i=0; i<objList.length; i++ )
	{
		if ( objList.options(i).selected )
		{
			if ( !blnFirst )
				strURL = strURL + ',';
			else
			{
				blnFirst = false;
				strURL = strURL + '&Fields=';
			}

			strURL = strURL + objList.options(i).value;
		}
	}

	// If no columns checked and no new fields send 'none' to remove any on screen
	if ( blnFirst )
		strURL = strURL + '&Fields=none';
	
	// See how many sort order columns are checked
	blnFirst = true;
	intChecked = 0;
	for ( i=0; i<mainform.elements.length; i++ )
	{
		chkBox = mainform.elements(i);
		if (( chkBox.type == 'checkbox' ) && ( chkBox.checked ))
			if ( chkBox.name.substr(0,9) == 'gridSORT-' )
				intChecked++;
	}

	// If some checked add these in order of check for forced sort order
	if ( intChecked == 0 )
		strURL = strURL + '&Sort=none';
	else
	{
		var intNext = 1;
		while ( intNext <= intChecked )
		{
			var intWasNext = intNext;
			for ( i=0; i<mainform.elements.length; i++ )
			{
				chkBox = mainform.elements(i);
				if (( chkBox.type == 'checkbox' ) && ( chkBox.checked ))
				{
					if ( chkBox.name.substr(0,9) == 'gridSORT-' )
					{
						if ( Number(chkBox.value) == intNext )
						{
							if ( !blnFirst )
								strURL = strURL + ',';
							else
							{
								strURL = strURL + '&Sort=';
								blnFirst = false;
							}

							var strValue = colSpan(chkBox.name + '-LABEL').value;
							if ( strValue != 'undefined' )
								strURL = strURL + strValue;

							intNext++;
						}
					}
				}
			}
			if ( intWasNext == intNext )
				intChecked = 0;
		}
	}

	// If specialorder before retain order flag
	if ( intSpecialOrder == 1 )
		strURL = strURL + '&SpecialOrder=1';
	
	// And redo report via server trip
	location.href = strURL;
}


// Adjust the column order due to a check/uncheck
function GridColOrder( chkCol, strType )
{
	var iChangedOrder, iOrder, chkBox;
	var colSpan = document.all.tags("SPAN");

	if ( chkCol.checked )
	{
		// Just checked one - scan to see greatest number 
		iChangedOrder = 0;
		for ( i=0; i<mainform.elements.length; i++ )
		{
			chkBox = mainform.elements(i);
			if (( chkBox.type == 'checkbox' ) && ( chkBox.checked ))
			{
				if ( chkBox.name.substr(0,5+strType.length) == 'grid' + strType + '-' )
				{
					iOrder = Number(chkBox.value);
					if ( iOrder > iChangedOrder )
						iChangedOrder = iOrder;
				}
			}
		}
		iChangedOrder++;
		colSpan(chkCol.name + '-LABEL').innerHTML = iChangedOrder;
		chkCol.value = iChangedOrder;
	}
	else
	{
		// We just unchecked this col - clear order
		iChangedOrder = Number(chkCol.value);
		colSpan(chkCol.name + '-LABEL').innerHTML = '';
		chkCol.value = 0;

		// Adjust other orders above one unchecked
		for ( i=0; i<mainform.elements.length; i++ )
		{
			chkBox = mainform.elements(i);
			if (( chkBox.type == 'checkbox' ) && ( chkBox.checked ))
			{
				if ( chkBox.name.substr(0,5+strType.length) == 'grid' + strType + '-' )
				{
					iOrder = Number(chkBox.value);
					if ( iOrder > iChangedOrder )
					{
						colSpan(chkBox.name + '-LABEL').innerHTML = iOrder - 1;
						chkBox.value = iOrder - 1;
					}
				}
			}
		}
	}
}


// Checks or unchecks all column checkboxes on grid report
function GridCheckAll( mainform, bCheck )
{
	var chkBox;
	
	if(!Go)
		RefreshPage();
	else
	{
		var iColOrder = 1
		var colSpan = document.all.tags("SPAN");

		for ( i=0; i<mainform.elements.length; i++ )
		{
			chkBox = mainform.elements(i);
			if (( chkBox.type == "checkbox" ) && ( chkBox.name != "PrintLandscape" ) && ( chkBox.name.substr(0,8) == 'gridCOL-' ))
			{
				chkBox.checked = bCheck;
				if ( !bCheck )
				{
					// /Unchecking so remove label
					colSpan(chkBox.name + '-LABEL').innerHTML = '';
					chkBox.value = 0;
				}
				else
				{
					// Checking so add order text
					colSpan(chkBox.name + '-LABEL').innerHTML = iColOrder;
					chkBox.value = iColOrder;
					iColOrder++;
				}
			}
		}
	}
}



// Setup keystroke handler - inactive until handler set to function
var fntHandleEnter = null;
var fntHandleEscape = null;

function fntKeyPress(d)
{
	if (blnNetscape4) 
		var key=d.which;
	else
	if (blnIE4)
		var key=event.keyCode;

	if ((key==13) && ( fntHandleEnter != null )) // enter
		fntHandleEnter();
	else
	if ((key==27) && ( fntHandleEscape != null )) // escape
		fntHandleEscape();
}

if (navigator.appName.indexOf("Netscape") >= 0 && parseInt(navigator.appVersion) >= 4)
{
	var blnNetscape4 = true
	document.captureEvents(Event.KEYDOWN);
}
else
if (navigator.appName.indexOf("Explorer") >= 0 && parseInt(navigator.appVersion) >= 4) 
	var blnIE4 = true

document.onkeypress = fntKeyPress;

// Changes to the specified report
function SelectReport( where )
{
	switch (where)
	{
	case 0: // edit report
		mainform.multiview.value=where;
		document.mainform.submit();
		break;

	case 1: // search results checked
//		document.mainform.CMA.value=""; what is this for?
		ViewReport(document.mainform,where);
		break;

	case 2: // search results all
		mainform.multiview.value=where;
		document.mainform.submit();
		break;

	case 3: // summary report checked
		ViewReport(document.mainform,where);
		break;

	case 4: // summary all records
		mainform.multiview.value=where;
		document.mainform.submit();
		break;

	case 5: // current report printed
		if (navigator.appName.indexOf("Explorer") >= 0 && parseInt(navigator.appVersion) >= 4) 
			TogglePrintDisplay(false); // go to printmode
		else
			DoPrint(0);
		break;

	case 6: // current report printed with print help
		PrintHelp=window.open("/print_help.asp","Help","resizable=yes,status=no,scrollbars=yes,width=600,height=400");
		break;

	case 7: // open house results checked
		ViewReport(document.mainform,where);
		break;

	case 8: // open house results all
		mainform.multiview.value=where;
		document.mainform.submit();
		break;

	case 9:	 // CMA subject property
		ViewReport(document.mainform,where);
		break;
	
	case 10: // broker tour results checked
		ViewReport(document.mainform,where);
		break;

	case 11: // broker tour results all
		mainform.multiview.value=where;
		document.mainform.submit();
		break;

	case 12: // hotsheet search results checked
		ViewReport(document.mainform,where);
		break;

	case 13: // hotsheet search results all
		mainform.multiview.value=where;
		document.mainform.submit();
		break;

	case -13: // Revise Search
		mainform.multiview.value=where;
		document.mainform.submit();
		break;

	case 30:
		window.open("", "MyWindow");
		document.mainform.target = "MyWindow";
		ViewReport(document.mainform,where);
		break;

	case 31:
		window.open("", "MyWindow");
		document.mainform.target = "MyWindow";
		ViewReport(document.mainform,where);
		break;
		
	case 32:
		window.open("", "MyWindow");
		document.mainform.target = "MyWindow";
		ViewReport(document.mainform,where);
		break;
	
	default: // all other normal report selections
		ViewReport(document.mainform,where);
		break;
	}
}

// Toggle print mode with styles - if from body ignore unless in printmode
function TogglePrintDisplay(bFromBody)
{
	var bCurrentPrintMode = false;
	var col = document.styleSheets(0);

	// See if document has a landscape option
	var blnLandscape = false;
	var formMain = document.forms('mainform');
	if ( formMain != null )
	{
		var chkLandscape = mainform.elements('PrintLandscape')
		if ( chkLandscape != null )
			blnLandscape = chkLandscape.checked;
	}

	if (col!=null) 
	{
		if (col.rules!=null) 
		{
			// Set bCurrentPrintMode to the current mode
			for (i=0; i<col.rules.length; i++)
			{
				if ( col.rules(i).selectorText == ".np" ) 
				{
					if ( col.rules(i).style.display == "none" )
					{
						bCurrentPrintMode = true;

						// Changing back from print mode so put navbar back in place if from body
						// Next 2 lines by Robert Overman
						if ( bFromBody )
							RestoreMenuBar();

						break;
					}
				}
			}

			// Toggle styles as long as not in displaymode and clicked on body
			if ( !bFromBody || ( bFromBody && bCurrentPrintMode ))
			{
				for ( i=0; i<col.rules.length; i++ )
				{
					if ( col.rules(i).selectorText == ".np" ) 
					{
						if ( !bCurrentPrintMode )
							col.rules(i).style.display = "none";
						else
							col.rules(i).style.display = "inline";
					}
					else
					if ( col.rules(i).selectorText == ".p" ) 
					{
						if ( !bCurrentPrintMode )
							col.rules(i).style.display = "inline";
						else
							col.rules(i).style.display = "none";
					}
					else
					if ( col.rules(i).selectorText == ".r1" ) 
					{
						if ( !bCurrentPrintMode )
							col.rules(i).style.backgroundColor = "white";
						else
							col.rules(i).style.backgroundColor = "#F0E9D9";
					}
					else
					if ( col.rules(i).selectorText == ".r2" ) 
					{
						if ( !bCurrentPrintMode )
							col.rules(i).style.backgroundColor = "white";
						else
							col.rules(i).style.backgroundColor = "#969696";
					}
					else
					if ( col.rules(i).selectorText == "A" ) 
					{
						if ( !bCurrentPrintMode )
						{
							document.linkColor = "black";
							col.rules(i).style.textDecoration = "none";
						}
						else
						{
							document.linkColor = "blue";
							col.rules(i).style.textDecoration = "underline";
						}
					}
					else
					if ( col.rules(i).selectorText == "BODY" ) 
					{
						if ( !bCurrentPrintMode )
							col.rules(i).style.margin = "0px";
						else
							col.rules(i).style.margin = "10px";
					}
				}
			}
		}
	}

	// Toggle table widths as long as not from body in display mode
	if ( !bFromBody || ( bFromBody && bCurrentPrintMode ))
	{
		var col = null;
		if ( document.forms.length > 0 )
		{
			col = document.forms("mainform");
			if (col!=null) 
				col = col.children;
		}
		if (col!=null) 
		{
			for (i=0; i<col.length; i++)
			{
				if ( col.item(i).tagName == "TABLE" )
				{
					if ( !bCurrentPrintMode && ( col.item(i).width > 700 ))
					{
						if ( blnLandscape )
							col.item(i).width = 960;
						else
							col.item(i).width = 710;
					}
					else
					if ( bCurrentPrintMode && ( col.item(i).width > 700 ))
						col.item(i).width = 750;
				}
			}
		}
	}
	
	// If changing to print mode move the menu bar frame off screen so it ever gets the focus
	// Next 2 lines by Robert Overman
	if ( !bFromBody && !bCurrentPrintMode )
		HideMenuBar();
}

// Routine called to Restore the New Menu Bar
// written by Robert Overman
function HideMenuBar()
{
	// This should be set at the start of the page
	//var NavColor;
	
	if(!NavColor=="")
	{
	idToolbar.style.display ='none';
	return true;
	}
}

// Routine called to Restore the New Menu Bar
// written by Robert Overman
function RestoreMenuBar()
{
	// This should be set at the start of the page
	//var NavColor;
	
	if(!NavColor=="")
	{
	idToolbar.style.display ='block';
	return true;
	}
}

// Prompt to load page
function RefreshPage()
{
	alert("Please refresh this page by right clicking over the page\nand selecting the refresh option, then wait for the page\nto finish re-loading (or click on back to change the search\ncriteria).");
}

// Filter called to limit display of rows to those checked.  Only works on ie and requires table with property
// defined by MLS number in value of checkbox to have an id=P#######
function Filter( myform, bCheckedOnly )
{
	var checked=false;
	if(!Go)
	{
		RefreshPage();
		return false;
	}

	for ( count=0; count<myform.elements.length-1; count++ )
	{
		if ( myform.elements[count].checked )
		{
			checked=true;
			break;
		}
	}

	if ( bCheckedOnly && !checked )
	{
		alert("You need to select at least one property to do this.");
		return false;
	}

	for ( count=0; count<myform.elements.length-1; count++ )
	 {
		if ( myform.elements[count].type == "checkbox" && !myform.elements[count].checked )
		{
			if ( bCheckedOnly )
				document.all.item("P"+myform.elements[count].value).style.display = "none";
			else
				document.all.item("P"+myform.elements[count].value).style.display = "inline";
		}
	}
}

// Only for netscape or when going to different report - makes sure at least 1 record is checked
function Checkit(myform) 
{
	var checked=false;
	var myitem=myform.multiview;
	if(!Go)
	{
		RefreshPage();
		return false;
	}
	myitem.value=0;
	for(count=0;count<myform.elements.length-1;count++)
	{
		if ( IsDataCheckbox( myform.elements[count] ) && myform.elements[count].checked )
		{
			checked=true;
			break;
		}
	}
	if ( checked || ( myform.SwitchReport.value == 1 ))
	{
		myitem.value=Multiview;
		myform.submit();
		return true;
	}
	else
	{
		alert("You need to select at least one property to do this.");
		return false;
	}
}

// Checks the page is loaded then calls SelectReport to display it
function DisplayReport( intReport )
{
	if(!Go)
		RefreshPage();
	else
	{
		//if(CMA)
			//UpdateSubjectProperty();
		SelectReport( intReport );
	}
}

function ViewReport(myform,viewnumber)
{
	Multiview=viewnumber;
	if(!Checkit(myform))
		Multiview=0;
}

// Checks or unchecks all checkboxes on searchresults report
function checkAll(myform, bCheck) {
	if(!Go)
		RefreshPage();
	else
	{
		for(i=0;i<myform.elements.length;i++)
		{
			if(myform.elements[i].type == "checkbox")
				myform.elements[i].checked=bCheck;
		}
	}
}

// Called in search screen
function SetForm() {
document.forms[0].fname.focus();
}

// Called in search screen
function PropType(myform, prop_type)
{
myform.prop_type.value=prop_type;
myform.submit();
}

// Called in search screen
function DoSearch(myform, search_type)
{
	if(allowSend(myform))
	{
		myform.search_type.value = search_type;
		myform.submit();
	}
}

// SwitchImage takes an Img tag object and looks for "image_no=nnofyy" where nn is the current image number and
// yy is the maximum possible.  It then increments the count and changes the SRC= part of the tag to tell
// Showimg.asp to get the next image in turn.  This routine does work but as of 08/06/99 Reports.asp does not output
// the IMG tag source URL for photos with the "image_no=nnofyy" component and showimg.asp does not check for this
// when extracting an image.
//
// Example URL in img SRC= tag is 
//
//"http://dev.xxxxxx.terradatum.com/showimg.asp?image_no=01of04&image_id=820448t"
//
function SwitchImage( objImgTag )
{
	
	var intIndex = objImgTag.src.search("image_no=")
	if ( intIndex > -1 )
	{
		var strSrc = objImgTag.src;
		var intThisImage = 0;
		var intLastImage = 0;

		var intThisImage=new Number(strSrc.substr(intIndex+9,2));
		intThisImage = intThisImage + 1;
		var intLastImage=new Number(strSrc.substr(intIndex+13,2));
		if ( intThisImage > intLastImage ) intThisImage = 1;
		var strThisImage = intThisImage.toString();
		if ( strThisImage.length == 1 ) strThisImage = "0" + strThisImage;

		objImgTag.src = strSrc.substr(0,intIndex+9) + strThisImage + strSrc.substring(intIndex+11,strSrc.length)
		alert("Image=" + objImgTag.src );
	}
}

//-->

