/*
function submitOnEnter(e, submitFunction)
function submitOnEnterBlock(e)
function fieldValue_StoreThenClear(currentFieldElement, action)
function fieldValue_ActOrLoadStore(currentFieldElement, actionEmpty, actionValue)
function switchTab(tabToTurnOn)
function textAreaMaxLength(textAreaObject, maxLength, countField)
function flipContentVisibility(divToChange, storeState)
function displayJSError(e, message)
function initializeMap()
function clearMap()
function headerQuickSearchSubmit()
function headerQuickSearchSubmit_return(searchID, propertyClass)
function hideShowSingleLayer(layerName)
function PopupCenterWindow(Url, Width, Height, Scroll)
function Format_price(Price)
function UNFormat_price(Price)
function globalApplyClickBlur()
function globalApplySingleClickActions(linkObject)
function globalBlurOnClick()
function globalCalendarOnClick(e, activeForm, activeElement, startDateString, endDateString)
function globalCalendarMouseOver()
function globalCalendarMouseOut()
function globalContactAttach(contactNameField, contactNameList)
function globalContactAttach_return(contactList, contactName, contactID)
function globalContactEnableAttach(contactNameField)
function globalContactEnableAttach_return(contactNameField, contactCount)
function globalContactDetach(contactID, contactList)
function globalCartViewListings()
function globalCartViewListings_return(URL)
function globalSignatureInsert(emailField)
function globalSignatureInsert_return(emailField, signatureText)
function globalContactSunshine(contactType)
function globalContactSunshine_init(contactType)
function globalContactSunshine_initReturn(contactName, contactEmail)
function globalContactSunshine_setType(contactType)
function globalContactSunshine_execute()
function globalCauseError_caught()
function globalCauseError_uncaught()
function globalChangeUser()
function globalChangeUser_return(optionList, accessLevel)
function globalChangeUser_set()
*/

//var
var _googleMap						= null;
var _globalOriginalOnLoadCommand	= DynAPI.onLoad;
var _globalLastError				= null;
var _globalLastErrorObject			= null;
var _globalLastErrorString			= null;
//var

Array.max = function( array ){return Math.max.apply( Math, array );};
Array.min = function( array ){return Math.min.apply( Math, array );}; 
Array.avg = function( array )
{
	//var
	var arraySum	= 0;
	var average		= 0;
	//var
	
	for(runner=0; runner<array.length; runner++)
		arraySum += array[runner];
	
	average = arraySum/array.length;
	
	return Math.round(average);
};
Array.median = function( array )
{
	//var
    var arrayMiddle = Math.floor(array.length / 2);
    var median		= 0;
    var localArray	= array.sort(numericalSort);
    //var
    
    if ((localArray.length % 2) != 0)
        median = localArray[arrayMiddle];
    else
        median = (localArray[arrayMiddle - 1] + localArray[arrayMiddle]) / 2;
	
	return median;
};
Array.sum = function( array )
{
	//var
	var arraySum	= 0;
	//var
	
	for(runner=0; runner<array.length; runner++)
		arraySum += array[runner];
	
	return arraySum;
};

function numericalSort(a, b)
{
	return (a - b);
};

DynAPI.onLoad = function()
{
	_globalOriginalOnLoadCommand();
	globalApplyClickBlur();
};

existingFieldValues = new Array();

function submitOnEnter(e, submitFunction)
{
	if(window.event && window.event.keyCode == '13')
	{
		window.event.keyCode = 0;
		textBox_DropDownClose();
		eval(submitFunction + "()");
	}else if(e.which == '13'){
		textBox_DropDownClose();
		eval(submitFunction + "()");
	};
};

function submitOnEnterBlock(e)
{
	//var
	var enterPressed = false;
	//var
	
	if(window.event && (!window.event.keyCode || window.event.keyCode == '13'))
		enterPressed = true;
	else if(e.which && e.which == '13')
		enterPressed = true;
	
	return !enterPressed;
};

function fieldValue_StoreThenClear(currentFieldElement, action)
{
	if(!existingFieldValues[currentFieldElement.id])
		existingFieldValues[currentFieldElement.id] = currentFieldElement.value;
	if(existingFieldValues[currentFieldElement.id] == currentFieldElement.value)
		currentFieldElement.value = '';
	
	if(action && action != '')
		eval(action + "(currentFieldElement)");
};

function fieldValue_ActOrLoadStore(currentFieldElement, actionEmpty, actionValue)
{
	if(currentFieldElement.value == '')
	{
		currentFieldElement.value = existingFieldValues[currentFieldElement.id];
		if(actionEmpty && actionEmpty != '')
			eval(actionEmpty + "(currentFieldElement)");
	}else{
		if(actionValue && actionValue != '')
			eval(actionValue + "(currentFieldElement)");
	};
};

function switchTab(tabToTurnOn)
{
	//var
	var tabContentHeader = tabToTurnOn.match(/div[A-Z][a-z]+/).toString();
	var tabHeader = tabContentHeader.replace("div", "divTab");
	var tabColorSet = "";
	var Runner = 0;
	//var
	
	//reset all of the tabs and layers first
	for(Runner=0; Runner<document.getElementsByTagName('div').length; Runner++)
	{
		if(document.getElementsByTagName('div')[Runner].id.match(tabContentHeader))
			document.getElementsByTagName('div')[Runner].style.display = 'none';
		if(document.getElementsByTagName('div')[Runner].id.match(tabHeader))
		{
			if(!document.getElementsByTagName('div')[Runner].className.match(/Hidden/))
			{
				tabColorSet = document.getElementsByTagName('div')[Runner].className.match(/border[A-Z][a-z]+([A-Z][a-z]+)/)[1];
				document.getElementsByTagName('div')[Runner].className = "borderLight" + tabColorSet + "Title";
			};
		};
	};
	
	//enable the selected layer
	if(document.getElementById(tabToTurnOn))
		document.getElementById(tabToTurnOn).style.display = 'block';
	
	//enable the selected tab if a tab exists
	if(document.getElementById(tabHeader + tabToTurnOn.replace(tabContentHeader,"")))
	{
		tabColorSet = document.getElementById(tabHeader + tabToTurnOn.replace(tabContentHeader,"")).className.match(/border[A-Z][a-z]+([A-Z][a-z]+)/)[1];
		document.getElementById(tabHeader + tabToTurnOn.replace(tabContentHeader,"")).className = "borderDark" + tabColorSet + "Title";
	};
};

function textAreaMaxLength(textAreaObject, maxLength, countField)
{
	if(textAreaObject.value.length > maxLength)
		textAreaObject.value=textAreaObject.value.substring(0,maxLength);
	if(countField && document.getElementById(countField))
		document.getElementById(countField).innerHTML = (maxLength - textAreaObject.value.length);
};

function flipContentVisibility(divToChange, storeState)
{
	if(document.getElementById(divToChange).style.display == '' || document.getElementById(divToChange).style.display == 'block')
		document.getElementById(divToChange).style.display = 'none';
	else
		document.getElementById(divToChange).style.display = 'block';
};

function displayJSError(e, message)
{
	//var
	var errorMessage = 'SunshineMLS has encountered an error, please reload this page and try again.\nIf this error continues, please contact SunshineMLS support.\nThank you.\n\n';
	//var
	
	if(!message || message == '')
	{
		if(e.stack)
			errorMessage	+= e.stack;
		else
			errorMessage	+= e;
	}else
		errorMessage	+= message;
	
	alert(errorMessage);
/*
	if(!message || message == '')
		alert("SunshineMLS has encountered an error, please reload this page and try again.\nIf this error continues, please contact SunshineMLS support.\nThank you.\n\n" + e.message);
	else
		alert("SunshineMLS has encountered an error, please reload this page and try again.\nIf this error continues, please contact SunshineMLS support.\nThank you.\n\n" + message);
*/
	
	_globalLastErrorObject	= e;
	_globalLastErrorString	= message;
};

function initializeMap(mapName)
{
	try{
		if(GBrowserIsCompatible())
		{
			_googleMap = new GMap2(document.getElementById(mapName),{mapTypes:[G_NORMAL_MAP,G_HYBRID_MAP]});
			_googleMap.addControl(new GLargeMapControl3D());
//			_googleMap.addControl(new GLargeMapControl());
			_googleMap.addControl(new GMapTypeControl());
			_googleMap.addControl(new GScaleControl());
			geocoder = new GClientGeocoder();
			_googleMap.setCenter(new GLatLng(26.212878, -81.718964), 10);
			_googleMap.enableScrollWheelZoom();
		};
	}catch(e){
		displayJSError(e);
	};
};

function clearMap()
{
	if (_googleMap)
		GUnload();
};

function headerQuickSearchSubmit()
{
	//var
	var regexMLNumber	= new RegExp(/^(\d{6,9})$/);
	var regexPID		= new RegExp(/^((\d{11,})|(\d[\d\-\w]{16,}\.[\d\w]+))$/i);
	var quicksearchData	= document.getElementById("f_headerQuickSearch").value.replace(/\s/g,'');
	var Js_post			= new postback("/search/storeSearchSessionCriteria.asp");
	//var
	
	if(regexPID.test(quicksearchData))
		Js_post.Parameters = "chr6572=" + quicksearchData + '&f_metaSearchClass=PR';
	else if(regexMLNumber.test(quicksearchData))
		Js_post.Parameters = "MLNum=" + quicksearchData;
	else
		Js_post.Parameters = "Full_Address=" + document.getElementById("f_headerQuickSearch").value;
	
//		Js_post.Parameters = "MLNum=" + quicksearchData + '&f_metaSearchClass=XPROP';
	Js_post.Retrieve();
};

function headerQuickSearchSubmit_return(searchID, propertyClass)
{
	//var
	var resultsString	= '/search/';
	//var
	
	if(propertyClass != '')
	{
		switch(propertyClass)
		{
			case 'COM'		: resultsString += 'commercialResults.asp'; break;
			case 'LOT'		: resultsString += 'lotAndLandResults.asp'; break;
			case 'RES'		: resultsString += 'residentialResults.asp'; break;
			case 'RIN'		: resultsString += 'residentialIncomeResults.asp'; break;
			case 'RNT'		: resultsString += 'residentialRentalResults.asp'; break;
			case 'DOCK'		: resultsString += 'dockResults.asp'; break;
			case 'XPROP'	: resultsString += 'crossResults.asp'; break;
			case 'PR'		: resultsString += 'publicRecordsResults.asp'; break;
		};
		
		window.location = resultsString + '?sid=' + searchID;
	}else
		alert("The appropriate property class could not be determined for this input.");
};

function PopupCenterWindow(Url, Width, Height, Scroll) {
	/*
	RETURN VALUE:
	none
	
	USAGE:
	href=JavaScript:PopupCenterWindow('global_functions_implementation.html',400,100,'no');
	
	PARAMETERS:
	Url:	File or address to open in the new window.
	Width:	The width of the window to open
	Height:	The height of the window to open
	Scroll:	yes/no Allow the new window to contain scrollbars or not
	
	NOTE:
	Each window is given a unique name so that subsequent requests will crate new windows.
	There is no navigation, Menus, Address, or status in the window.
	*/

	//var
	var WindowString;
	var Now = new Date();
	var RandName = Now.getUTCMilliseconds();
	var X = (screen.availWidth - Width) / 2;
	var Y = (screen.availHeight - Height) / 2 - 10;
	//var

	RandName = RandName.toString();
	if (Scroll == "")
		Scroll = "no";
	if (!window.screenX) //screexX==NS
	{
		X += parseInt(window.screenLeft / screen.availWidth) * screen.availWidth;
		Y += parseInt(window.screenTop / screen.availHeight) * screen.availHeight;
	} else {
		X += parseInt(window.screenX / screen.availWidth) * screen.availWidth;
		Y += parseInt(window.screenY / screen.availHeight) * screen.availHeight;
	};
	WindowString = "width=" + Width + ",height=" + Height + ",screenX=" + X + ",screenY=" + Y + ",left=" + X + ",top=" + Y + ",toolbar=0,scrollbars=" + Scroll + ",location=0,directories=0,status=0,menubar=0,resizable=yes";
	newWindow = open(Url, RandName, WindowString);
	try{
		newWindow.moveTo(X, Y);
	}catch(e){};
	//newWindow.location=Url;
};

function GetCursorPosition(inputElement)
{
	//var
	var inputLength	= inputElement.value.length;
	var inputRange	= null;
	//var
	
	if (inputElement.createTextRange)
	{
		inputRange = document.selection.createRange().duplicate();
		while (inputRange.parentElement() == inputElement && inputRange.move("character", 1) == 1)
			--inputLength;
		return inputLength;
	}else{
		return -1;
	};
};

function UNFormat_price(Price) {
	/*
	RETURN VALUE:
	None from the function, the element will contain a value converted from a formatted monetary number 
	as a flat integer format Ex. 1,000,000 is converted to 1000000 and placed int the 'Price' object
	
	USAGE:
	onFocus=Javascript:UNFormat_price(this);
	
	PARAMETERS:
	Price: An text input element
	
	NOTE:
	UNFormat_price(Price) works in conjuntion with Format_price(Price)
	*/

	//var
	var Current = Price.value;
	var Cursor_pos = -1;
	var Runner = 0;
	var Selection;
	//var
	
	//alert(document.all);
	if(document.all)
	{
		//IE
		Selection = document.selection.createRange().duplicate();
		
		//Block from coming back to a blurred window and re-firing the onfocus event
		if (Selection.parentElement() == Price)
		{
			//Find the cursor position
			Cursor_pos = Price.value.length;
			while (Selection.move("character", 1) == 1)
				--Cursor_pos;
		};
	}else
		//FF
		Cursor_pos = Price.selectionStart;
	
	if (Cursor_pos > -1)
	{
		//Remove Commas
		for (Runner = 0; Runner < Cursor_pos; Runner++)
			if (Price.value.charAt(Runner) == ",")
				Cursor_pos--;
		
		//Clean everything out
		if (Current != "0" && !isNaN(Current)) {
			Current = Current.replace(/^0+(.*)$/, "$1");
			Current = Current.replace(/,/g, "");
			//Current=parseInt(Current);
		} else {
			Current = Current.replace(/,/g, "");
			Current = Current.replace(/^0+(\d*)$/, "$1");
			//Current = "";
		};
		Current = Current.replace(String.fromCharCode(94), "");
		
		//Put the new val back
		Price.value = Current;
	};
	
	if(document.selection)
	{
		//IE
		//Put the cursor there
		Selection = Price.createTextRange();
		Selection.collapse(true);
		Selection.moveStart('character', Cursor_pos);
		Selection.select();
	}else{
		//FF
		Price.selectionStart = Cursor_pos;
		Price.selectionEnd = Cursor_pos;
	};
};

function Format_price(Price) {
	/*
	RETURN VALUE:
	1. A value from an integer converted into the appropiate monetary amount Ex. 1000000 is returned as 1,000,000
	2. The original value if it is not an integer or able to be converted to a monetary amount.
	
	USAGE:
	onBlur=JavaScript:this.value=Format_price(this);
	
	PARAMETERS:
	Price: An text input element
	
	NOTE:
	Format_price(Price) works in conjuntion with UNFormat_price(Price)
	*/

	//var
	var Price_value = Price.value;
	//var
	
	return formatPrice(Price_value);
};
function formatPrice(Price_value)
{
	//var
	var Mod = 0;
	var New_price;
	var Runner = 0;
	var Sign_Offset = false;
	var Decimal = '';
	//var
	
	//Quick comma replace
	if (isNaN(Price_value))
		Price_value = Price_value.replace(/[,$]/g, "");
	if (!isNaN(Price_value)) {
		if (Price_value != "") {
			if (Price_value.toString().indexOf(".") == 0)
				Price_value = 0;
			else if (Price_value.toString().indexOf(".") > 0) {
				Decimal = Price_value.toString().substr((Price_value.toString().indexOf(".") + 1), 3);
				Price_value = Price_value.toString().substr(0, Price_value.toString().indexOf("."));
				if (Decimal.length == 1)
					Decimal += '0';
			};
			Price_value = parseInt(Price_value);
			if (Decimal > 994) {
				Price_value++;
				Decimal = '00';
			};
			Price_value = Price_value + '';
			if (Price_value < 0) {
				Sign_Offset = true;
				Price_value = Math.abs(Price_value).toString();
			};
			if ((Price_value.length) > 3) {
				New_price = 0;
				Mod = Price_value.length % 3;
				New_price = (Mod > 0 ? (Price_value.substring(0, Mod)) : '');
				for (Runner = 0; Runner < Math.floor(Price_value.length / 3); Runner++) {
					if ((Mod == 0) && (Runner == 0))
						New_price += Price_value.substring(Mod + 3 * Runner, Mod + 3 * Runner + 3);
					else
						New_price += ',' + Price_value.substring(Mod + 3 * Runner, Mod + 3 * Runner + 3);
				};
			} else
				New_price = Price_value;
		} else
			New_price = 0;
	};
	if (Sign_Offset)
		New_price = '-' + New_price;
	
	if (Decimal != '') {
		if (Decimal > 99)
			New_price = New_price + '.' + Math.round(Decimal / 10);
		else
			New_price = New_price + '.' + Decimal;
	};
	
	return New_price;
};

function clickThough(addID)
{
	//var
	var Js_post=new postback("/includesASP/logClickThough.asp");
	//var
	
	Js_post.Parameters = "addid=" + addID;
	
	Js_post.Retrieve();
};

function globalApplyClickBlur()
{
	//var
	var runner = 0;
	//var
	
	for(runner = 0; runner < document.getElementsByTagName('a').length; runner++)
			globalApplySingleClickActions(document.getElementsByTagName('a')[runner]);
};

function globalApplySingleClickActions(linkObject)
{
	//onclick="this.blur();"
	if(!linkObject.attachEvent)
		linkObject.setAttribute('onclick', 'this.blur();'); //FF
	else
		linkObject.attachEvent('onclick', globalBlurOnClick); //IE
};

function globalBlurOnClick()
{
	event.srcElement.blur();
};

function globalCalendarOnClick(e, activeForm, activeElement, startDateString, endDateString)
{
	//var
	var startDate	= null;
	var endDate		= null;
	var splitDate	= "";
	var User_agent	= navigator.userAgent.toLowerCase().replace(/\+/g," ");
    var Is_IE		= (User_agent.indexOf("msie") != -1);
    var Browser_ver	= -1;
	//var
	
	if(Is_IE)
		Browser_ver	= User_agent.match(/msie ([\d\.]+)/)[1];
	
	if(!Is_IE || (Is_IE && (Browser_ver > 6)))
	{
		if(startDateString != '' && startDateString != undefined)
		{
			splitDate = startDateString.split("/");
			startDate = new Date(splitDate[2], (splitDate[0]-1), splitDate[1]);
		};
		if(endDateString != '' && endDateString != undefined)
		{
			splitDate = endDateString.split("/");
			endDate = new Date(splitDate[2], (splitDate[0]-1), splitDate[1]);
		};
		
		g_Calendar.show(e, activeForm + '.' + activeElement, false, 'mm/dd/yyyy', startDate, endDate);
	}else{
		alert("The browser you are using does not support the SunshineMLS calendar functionality. To use the SunshineMLS calendar and avoid possible future issues, please upgrade your browser. You may type in the date(s) until you upgrade your browser, at which point you will be able to use the SunshineMLS calendar.");
	};
};

function globalCalendarMouseOver()
{
	if (timeoutId)
		clearTimeout(timeoutId);
	document.body.style.cursor = 'pointer';
//	window.status = 'Show Calendar';
//	return true;
};

function globalCalendarMouseOut()
{
	if (timeoutDelay)
		calendarTimeout();
	document.body.style.cursor = 'default';
//	window.status = '';
};

function globalContactAttach(contactNameField, contactNameList, singleContact)
{
	//var
	var Js_post		= new postback("/includesASP/contactAttach.asp");
	var contactName	= "";
	//var
	
	try
	{
		contactName	= escape(document.getElementById(contactNameField).value);
		
		Js_post.Parameters = "contactName=" + contactName + "&contactList=" + contactNameList + "&singlecontact=" + singleContact;
		
		Js_post.Retrieve();
		
		document.getElementById(contactNameField).value = "";
	}catch(e){
		displayJSError(e, contactNameField + ' does not exist yet.');
	};
};

function globalContactAttach_return(contactList, contactName, contactID, singleContact)
{
	//var
	var existingContacts	= document.getElementById(contactList).innerHTML;
	var newContactUID		= "memberContact_" + contactID
	var newContactString	= "<span id='memberContact_" + contactID + "'>" + contactName + " <a href='javaScript:globalContactDetach(" + contactID + ",\"" + contactList + "\");'><img src='/graphics/button_X.png' alt='Remove " + contactName + "' /></a><br /></span>";
	//var
	
	if(singleContact && existingContacts == '')
		//If Single contact only AND there are no contacts added yet
		document.getElementById(contactList).innerHTML = newContactString;
	else if(!singleContact && !existingContacts.match(newContactUID,"i") && (contactID != ''))
		//If allow for multiple contacts AND the contact is not there already
		document.getElementById(contactList).innerHTML = existingContacts + newContactString;
};

function globalContactEnableAttach(contactNameField, contactArea)
{
	//var
	var Js_post	= new postback("/includesASP/contactEnableAttach.asp");
	//var
	
	Js_post.Parameters = "fieldName=" + contactNameField + "&contactarea=" + contactArea;
	
	Js_post.Retrieve();
};

function globalContactEnableAttach_return(contactNameField, contactCount, contactArea)
{
	if(contactCount > 0)
		init_post_load_text_box(contactNameField);
	else{
		if(document.getElementById("f_searchSaveSearchContactLookup_section"))
			document.getElementById("f_searchSaveSearchContactLookup_section").style.display = 'none';
		if(document.getElementById("f_searchEmailContactLookup_section"))
			document.getElementById("f_searchEmailContactLookup_section").style.display = 'none';
		if(document.getElementById(contactArea))
			document.getElementById(contactArea).style.display = 'none';
	};
};

function globalContactDetach(contactID, contactList)
{
	//var
	var existingContacts	= document.getElementById(contactList).innerHTML;
	var newContactUID		= new RegExp("<span id=['\"]?memberContact_" + contactID + ".+?</span>", "i");
	//var
	
	document.getElementById(contactList).innerHTML = existingContacts.replace(newContactUID, "");
};

function globalCartViewListings()
{
	//var
	var Js_post		= new postback("/search/cartToResults.asp");
	//var
	
	Js_post.Retrieve();
};

function globalCartViewListings_return(URL)
{
	//var
	var localURL		= URL;
	var searchResultsID	= window.location.toString().match(/sid=(\d+)/);
	//var
	
	if(URL == '')
		alert("Listings must be added to the cart before the cart may be viewed.");
	else{
		if(URL.match(/\?/))
		{
			if((URL.match(/sid=/)) && (searchResultsID))
				localURL += "&lsid=" + searchResultsID[1];
			if(window.location.toString().match(/eid=(\d+)/))
				localURL += "&eid=" + window.location.toString().match(/eid=(\d+)/)[1];
		};
		
		window.location = localURL;
	};
};

function globalSignatureInsert(emailField)
{
	//var
	var Js_post	= new postback("/includesASP/emailSignatureInsert.asp");
	//var
	
	Js_post.Parameters = "fieldName=" + emailField;
	
	Js_post.Retrieve();
};

function globalSignatureInsert_return(emailField, signatureText)
{
	document.getElementById(emailField).value = '\n' + signatureText;
};

function globalContactSunshine(contactType)
{
	//alert(contactType);
	overlayFadeIn('overlayContactSunshine');
	
	setTimeout("globalContactSunshine_init('" + contactType + "');",10);
};

function globalContactSunshine_init(contactType)
{
	//var
	var currentURL		= window.location.toString();
	var Js_post			= new postback("/includesASP/getInfoForContactSMLS.asp");
	var regexListPrice	= /List Price:\D+(\$[\d,]+)/i;
	var regexSalePrice	= /Sale Price:\D+(\$[\d,]+)/i;
	var regexStatus		= /Status:<\/span>\w+-(\w+)/i;
	var regexAddress1	= /listingAddress1.?>([\w\s,#-]+)</i;
	var regexAddress2	= /listingAddress2.?>([\w,\s]+)</i;
	var regexBoardCode	= /listingBoardCode.?>(\d+)</i;
	var listingDetails	= '';
	//var
	
	//Load General Contact Details
	Js_post.Retrieve();
	
	//Load details for Error Message type
	testCompliance();
	document.getElementById('f_contactErrorInfo').value						= document.getElementById('contactErrorInfo').innerHTML;
	document.getElementById('f_contactSupportInfo').value					= document.getElementById('contactErrorInfo').innerHTML;
	document.getElementById('contactSupportInfo').innerHTML					= document.getElementById('contactErrorInfo').innerHTML;
	if(_globalLastErrorObject || _globalLastErrorString)
	{
		document.getElementById('contactErrorDetails').innerHTML			= currentURL + "<br />";
		if(_globalLastErrorObject)
		{
			if(_globalLastErrorObject.stack)
				document.getElementById('contactErrorDetails').innerHTML	+= _globalLastErrorObject.stack;
			else
				document.getElementById('contactErrorDetails').innerHTML	+= _globalLastErrorObject;
		}else if(_globalLastErrorString)
			document.getElementById('contactErrorDetails').innerHTML		+= _globalLastErrorString;
	};
	document.getElementById('f_contactErrorDetails').value					= document.getElementById('contactErrorDetails').innerHTML;
	
	//Load details for Violation Message type
	if(typeof(_searchCurrentListing) != 'undefined' && _listingDetails[_searchCurrentListing])
	{
//		alert(_listingDetails[_searchCurrentListing].reportRealtor.match(regexBoardCode));
		listingDetails			+= "<table border='0' cellpadding='0' cellspacing='0'>";
		listingDetails			+= "	<tr>";
		listingDetails			+= "		<td>MLNum:</td>";
		listingDetails			+= "		<td>" + _searchCurrentListing + "</td>";
		listingDetails			+= "	</tr>";
		if(_listingDetails[_searchCurrentListing].reportRealtor.match(regexStatus))
		{
			listingDetails		+= "	<tr>";
			listingDetails		+= "		<td>Status:</td>";
			listingDetails		+= "		<td>" + _listingDetails[_searchCurrentListing].reportRealtor.match(regexStatus)[1] + "</td>";
			listingDetails		+= "	</tr>";
		};
		if(_listingDetails[_searchCurrentListing].reportRealtor.match(regexListPrice))
		{
			listingDetails		+= "	<tr>";
			listingDetails		+= "		<td>List Price:&nbsp;</td>";
			listingDetails		+= "		<td>" + _listingDetails[_searchCurrentListing].reportRealtor.match(regexListPrice)[1] + "</td>";
			listingDetails		+= "	</tr>";
		};
		if(_listingDetails[_searchCurrentListing].reportRealtor.match(regexSalePrice))
		{
			listingDetails		+= "	<tr>";
			listingDetails		+= "		<td>Sale Price:</td>";
			listingDetails		+= "		<td>" + _listingDetails[_searchCurrentListing].reportRealtor.match(regexSalePrice)[1] + "</td>";
			listingDetails		+= "	</tr>";
		};
		if(_listingDetails[_searchCurrentListing].reportRealtor.match(regexAddress1) || _listingDetails[_searchCurrentListing].reportRealtor.match(regexAddress2))
		{
			listingDetails		+= "	<tr>";
			listingDetails		+= "		<td valign='top' >Address:</td>";
			listingDetails		+= "		<td>";
			if(_listingDetails[_searchCurrentListing].reportRealtor.match(regexAddress1))
				listingDetails	+= "			" + _listingDetails[_searchCurrentListing].reportRealtor.match(regexAddress1)[1] + "<br />";
			if(_listingDetails[_searchCurrentListing].reportRealtor.match(regexAddress2))
				listingDetails	+= "			" + _listingDetails[_searchCurrentListing].reportRealtor.match(regexAddress2)[1] + "<br />";
			listingDetails		+= "		</td>";
			listingDetails		+= "	</tr>";
		};
		listingDetails			+= "</table>"
		document.getElementById('inputViolationDetails').innerHTML			= listingDetails;
		if(_listingDetails[_searchCurrentListing].reportRealtor.match(regexBoardCode))
			document.getElementById('f_contactViolationBoardCode').value	= _listingDetails[_searchCurrentListing].reportRealtor.match(regexBoardCode)[1];
	};
	document.getElementById('f_contactViolationDetails').value				= document.getElementById('inputViolationDetails').innerHTML;
	
	//Update the display to the defaults of the contactType
	globalContactSunshine_setType(contactType);
	
	//set focus
	document.getElementById('f_commentText').focus();
};

function globalContactSunshine_initReturn(contactName, contactEmail, contactBoardCode)
{
	document.getElementById('f_contactName').value				= contactName;
	document.getElementById('f_contactEmailAddress').value		= contactEmail;
	document.getElementById('f_contactAgentBoardCode').value	= contactBoardCode;
};

function globalContactSunshine_setType(contactType)
{
	switch(contactType)
	{
		case 'suggestion'	: 
			document.getElementById('f_contactType_suggestion').checked	= true;
			document.getElementById('contactTextTitle').innerHTML		= 'Suggestion:';
			document.getElementById('inputSuggestion').style.display	= 'block';
			document.getElementById('inputSupport').style.display		= 'none';
			document.getElementById('inputError').style.display			= 'none';
			document.getElementById('inputViolation').style.display		= 'none';
			break;
		case 'support'	: 
			document.getElementById('f_contactType_support').checked	= true;
			document.getElementById('contactTextTitle').innerHTML		= 'Question:';
			document.getElementById('inputSuggestion').style.display	= 'none';
			document.getElementById('inputSupport').style.display		= 'block';
			document.getElementById('inputError').style.display			= 'none';
			document.getElementById('inputViolation').style.display		= 'none';
			break;
		case 'error'	: 
			document.getElementById('f_contactType_error').checked		= true;
			document.getElementById('contactTextTitle').innerHTML		= 'Error Description:';
			document.getElementById('inputSuggestion').style.display	= 'none';
			document.getElementById('inputSupport').style.display		= 'none';
			document.getElementById('inputError').style.display			= 'block';
			document.getElementById('inputViolation').style.display		= 'none';
			break;
		case 'violation'	: 
			document.getElementById('f_contactType_violation').checked	= true;
			document.getElementById('contactTextTitle').innerHTML		= 'Violation Details:';
			document.getElementById('inputSuggestion').style.display	= 'none';
			document.getElementById('inputSupport').style.display		= 'none';
			document.getElementById('inputError').style.display			= 'none';
			document.getElementById('inputViolation').style.display		= 'block';
			break;
	};
};

function globalContactSunshine_execute()
{
	document.contactOverlayForm.submit();
	
	overlayFadeOut();
};

function globalCauseError_caught()
{
	try{
		document.getElementById("nonExistantElement").value = '2';
	}catch(e){
		displayJSError(e);
	};
};

function globalCauseError_uncaught()
{
	displayJSError(null, 'This is an test for an uncaught error.');
};

function globalChangeUser()
{
	//var
	var Js_post	= new postback("/includesASP/impersonateLookup.asp");
	//var
	
	overlayFadeIn('overlayChangeUser');
	
	Js_post.Retrieve();;
};

function globalChangeUser_return(optionList, accessLevel)
{
	document.getElementById('overlayChangeUser_userList').innerHTML = optionList;
	if(accessLevel == 'SA')
		document.getElementById('overlayChangeUser_admin').style.display = 'block';
};

function globalChangeUser_set()
{
	//var
	var selectedUser	= document.getElementById('f_impOverlayList')[document.getElementById('f_impOverlayList').selectedIndex];
	var manualUserID	= document.getElementById('f_impOverlayText').value;
	var Js_post			= new postback("/includesASP/impersonateUpdate.asp");
	//var
	
	if(manualUserID != '')
		Js_post.Parameters = "agentID=" + manualUserID;
	else
		Js_post.Parameters = "agentID=" + selectedUser.value;
	Js_post.Retrieve();
	
	setTimeout("window.location.reload();",100);
};

function globalContactSunshine_welcomePage(formField)
{
	formField.blur();
	globalContactSunshine();
};

function globalSendEmail(address, linkto)
{
	//var
	var aryAddress	= new Array;
	var mailTo		= new String;
	//var
	
	address = address.replace(/x/g, ',64');
	address = address.replace(/y/g, ',46');
	address = address.replace(/z/g, ',');
	aryAddress = address.split(',');
	for (i=1; i<aryAddress.length;i++)
		mailTo = mailTo + String.fromCharCode(aryAddress[i]);
	
	linkto.href = 'mailto:' + mailTo;
};

