/*
function mhfSignup()
function changeFieldType(currentFieldElement)
function setFieldTypeToPassword(currentFieldElement)
function setFieldTypeToPassword_delayedFocus(fieldID)
function setFieldTypeToPassword_delayedOnFocus(fieldID)
function setFieldTypeToText(currentFieldElement)
function mhfLogin()
function hideShow(section)
function watchlistNotify(listingID, notification)
function savedSearchesNotify(sid, propertyClass, notification)
function savedSearchesRemove(sid, propertyClass)
function watchlistRemoveListing(listingID)
function deleteAccount()
function mhfUpdateAccount()
function compareWatchList()
*/

function mhfSignup()
{
	//var
	var signupEmail		= document.getElementById('f_mhfSignupEmail').value.replace('Enter your email address','');
	var signupPass		= document.getElementById('f_mhfSignupPassword').value.replace('Enter desired password','');
	var signupPassConf	= document.getElementById('f_mhfSignupPassConf').value.replace('Confirm password','');
	//var
	
	if(signupEmail == "" || !_regexEmail.test(signupEmail))
		alert("Please enter a valid Email Address.");
	else{
		if(signupPass == "")
			alert("Please enter your desired password.");
		else{
			if(signupPass != signupPassConf)
				alert("Your passwords do not match, please enter then again.");
			else{
				document.getElementById('formMHFSignup').submit();
			};
		};
	};
};

function changeFieldType(currentFieldElement)
{
	if(currentFieldElement.type != 'password')
		fieldValue_StoreThenClear(currentFieldElement,'setFieldTypeToPassword');
};

function setFieldTypeToPassword(currentFieldElement)
{
	var newPasswordField = document.createElement('input');
	var fieldID = currentFieldElement.getAttribute('id')
	
	newPasswordField.type = "password";
	newPasswordField.style.width = currentFieldElement.style.width
	newPasswordField.name = fieldID;
	newPasswordField.id = fieldID;
	this.tempDelayedOnFocusEvent = currentFieldElement.getAttribute('onfocus');
	
	newPasswordField.setAttribute('onblur',currentFieldElement.getAttribute('onblur'));
	newPasswordField.setAttribute('onkeyup',currentFieldElement.getAttribute('onkeyup'));

	currentFieldElement.parentNode.replaceChild(newPasswordField,currentFieldElement);
	if(fieldID == 'f_new_password1')
		document.getElementById("divPasswordQualityDisplay").style.display = "block";

	setTimeout('setFieldTypeToPassword_delayedFocus("' + fieldID + '");',1);
};

function setFieldTypeToPassword_delayedFocus(fieldID)
{

	document.getElementById(fieldID).focus();
	setTimeout('setFieldTypeToPassword_delayedOnFocus("' + fieldID + '");',1);
};

function setFieldTypeToPassword_delayedOnFocus(fieldID)
{
	document.getElementById(fieldID).setAttribute('onfocus',this.tempDelayedOnFocusEvent);
	this.tempDelayedOnFocusEvent = null;
};

function setFieldTypeToText(currentFieldElement)
{

	var newPasswordField = document.createElement('input');
	var fieldID = currentFieldElement.getAttribute('id')

	newPasswordField.type = "text";
	newPasswordField.style.width = currentFieldElement.style.width
	newPasswordField.name = fieldID;
	newPasswordField.id = fieldID;
	newPasswordField.value = currentFieldElement.value
	
	newPasswordField.setAttribute('onfocus',currentFieldElement.getAttribute('onfocus'));
	newPasswordField.setAttribute('onblur',currentFieldElement.getAttribute('onblur'));
	newPasswordField.setAttribute('onkeyup',currentFieldElement.getAttribute('onkeyup'));

	if(fieldID == 'f_new_password1')
		document.getElementById("divPasswordQualityDisplay").style.display = "none";

	currentFieldElement.parentNode.replaceChild(newPasswordField,currentFieldElement);
};

function mhfLogin()
{
	//var
	var signinEmail	= document.getElementById('f_mhfLoginEmail').value.replace('Enter your email address','');
	var signinPass	= document.getElementById('f_mhfLoginPassword').value.replace('Enter password','');
	//var
	
	if(signinEmail == "" || !_regexEmail.test(signinEmail))
		alert("Please enter your Email Address.");
	else{
		if(signinPass == "")
			alert("Please enter your password.");
		else
			document.getElementById('formMHFLogin').submit();
	};
};

function hideShow(section)
{
	if(document.getElementById(section).style.display == 'none')
		document.getElementById(section).style.display = 'block';
	else
		document.getElementById(section).style.display = 'none';
};

function watchlistRemoveListing(listingID)
{
	//var
	var Js_post = new postback("/includesASP/MHF_watchlistManageListings.asp");
	var detailsRunner = 0;
	var currentCount = 0;
	//var

	if (confirm("Are you sure you want to remove listing #" + listingID + " from your watch list?"))
	{
		//remove from the overview layout
		document.getElementById('watchListing_overview').childNodes[0].removeChild(document.getElementById('watchListing_overview_' + listingID));
		
		//remove listing from watchlist layout
		for(detailsRunner = 0; detailsRunner < document.getElementById('watchListing_detail').childNodes[0].childNodes.length; detailsRunner++)
		{
			try
			{
				document.getElementById('watchListing_detail').childNodes[0].childNodes[detailsRunner].removeChild(document.getElementById('watchListing_detail_' + listingID));
			}catch(e){
			};
		};
		
		currentCount = document.getElementById('watchListing_count').innerHTML.match(/\d+/);
		if(!isNaN(currentCount))
			document.getElementById('watchListing_count').innerHTML = '(' + --currentCount + ')';
		
		Js_post.Parameters = "action=removeItem&lid=" + listingID;
		
		Js_post.Retrieve();
	};
};

function savedSearchesRemove(sid, propertyClass)
{
	//var
	var Js_post = new postback("/includesASP/MHF_savedSearchesManageListings.asp");
	var currentCount = 0;
	//var
	
	if (confirm("Are you sure you want to delete the selected saved search? Please note that you will not be able to undo this action."))
	{
		//remove from the overview tab
		document.getElementById('savedSearch_overview').childNodes[0].removeChild(document.getElementById('savedSearch_overview_' + sid));
		
		//remove from saved searches tab
		document.getElementById('savedSearch_detail').childNodes[0].removeChild(document.getElementById('savedSearch_detail_' + sid));
		
		currentCount = document.getElementById('savedSearch_count').innerHTML.match(/\d+/);
		if(!isNaN(currentCount))
			document.getElementById('savedSearch_count').innerHTML = '(' + --currentCount + ')';
		
		Js_post.Parameters = "action=removeItem&sid=" + sid + "&PropertyClass=" + propertyClass;
		
		Js_post.Retrieve();
	};
};

function savedSearchesNotify(sid, propertyClass, notification)
{
	//var
	var Js_post = new postback("/includesASP/MHF_savedSearchesManageListings.asp");
	var linkText = "";
	//var

	if (confirm("Are you sure you want to change your automatic notification for this saved search?"))
	{
		if(notification == 'No')
			linkText = "<span class='fontError'>(OFF)</span> <a href='JavaScript:savedSearchesNotify(" + sid + ",\"" + propertyClass + "\",\"Yes\");'>Turn On</a>";
		else
			linkText = "<span class='fontAccept'>(ON)</span> <a href='JavaScript:savedSearchesNotify(" + sid + ",\"" + propertyClass + "\",\"No\");'>Turn Off</a>";
		
		//update the overview tab
		document.getElementById('searchStatus_overview_' + sid).innerHTML = linkText;
		//update the watchlist tab
		document.getElementById('searchStatus_detail_' + sid).innerHTML = linkText;

		Js_post.Parameters = "action=notifyChange&sid=" + sid + "&PropertyClass=" + propertyClass + "&notification=" + notification;

		Js_post.Retrieve();
	};
};

function watchlistNotify(listingID, notification)
{
	//var
	var Js_post = new postback("/includesASP/MHF_watchlistManageListings.asp");
	var linkText = "";
	//var

	if (confirm("Are you sure you want to change your automatic notification preference for listing #" + listingID + "?"))
	{
		if(notification == 0)
			linkText = "<span class='fontError'>(OFF)</span> <a href='JavaScript:watchlistNotify(\"" + listingID + "\",1);'>Turn On</a>";
		else
			linkText = "<span class='fontAccept'>(ON)</span> <a href='JavaScript:watchlistNotify(\"" + listingID + "\",0);'>Turn Off</a>";
		
		//update the watchlist tab
		document.getElementById('watchStatus_detail_' + listingID).innerHTML = linkText;
		
		Js_post.Parameters = "action=notifyChange&lid=" + listingID + "&notification=" + notification;
		
		Js_post.Retrieve();
	};
};

function deleteAccount()
{
	if(confirm('Are you sure you wish to delete your Naplesarea.com "My Home Finder" account? This will delete your account information, including all saved searches and watch list properties. Please note that this is a permanent action and cannot be undone.'))
		window.location = '/includesASP/MHF_acctChanges_Process.asp?action=Delete'
};

function mhfUpdateAccount()
{
	//var
	var accPass		= document.getElementById('f_accPasswordNew').value.replace('Enter desired password','');
	var accPassConf	= document.getElementById('f_accPasswordConf').value.replace('Confirm password','');
	//var
	
	if(accPass != "")
	{
		if(accPass != accPassConf)
			alert("Your passwords do not match, please enter then again.");
		else
			document.getElementById('formMHFAccount').submit();
	}else
		document.getElementById('formMHFAccount').submit();
}

function compareWatchList()
{
	//var
	var currentCount = 0;
	var currentIDList = "";
	var detailsRunner = 0;
	var innerRunner = 0;
	var currentRow = "";
	//var
	
	//currentIDList
	//Build a list of current watchlist listings
	for(detailsRunner = 0; detailsRunner < document.getElementById('watchListing_detail').childNodes[0].childNodes.length; detailsRunner++)
	{
		currentRow = document.getElementById('watchListing_detail').childNodes[0].childNodes[detailsRunner];
		
		for(innerRunner = 0; innerRunner < currentRow.childNodes.length; innerRunner++)
			currentIDList += currentRow.childNodes[innerRunner].innerHTML.match(/A href="(\d+)-/)[1] + ",";
	};
	
	currentCount = document.getElementById('watchListing_count').innerHTML.match(/\d+/);
	if(!isNaN(currentCount) && currentCount > 0)
		popUpCenterWindow('/listings-compare.asp?otherIDs=' + currentIDList,780,580,'yes');
	else
		alert("Please add watched listings before comparing.");
};