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];}
}

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_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 imagePreloadHandler(){
	MM_preloadImages('resources/images/topNavHomeOff.gif', 'resources/images/topNavHomeOn.gif', 'resources/images/topNavAboutOff.gif', 'resources/images/topNavAboutOn.gif', 'resources/images/topNavServicesOff.gif', 'resources/images/topNavServicesOn.gif', 'resources/images/topNavContactOff.gif', 'resources/images/topNavContactOn.gif', 'resources/images/topNavLoginOff.gif', 'resources/images/topNavLoginOn.gif');
}




function convertPlainTextToHTML(sFieldID){
	var objField = document.getElementById(sFieldID);
	if (objField != null){
		if (objField.value){
			objField.value = regExpReplaceAll(objField.value, "\r\n", "<br/>");
			objField.value = regExpReplaceAll(objField.value, "\n", "<br/>");
		}
	}
}

function convertHTMLToPlainText(sFieldID){
	var objField = document.getElementById(sFieldID);
	if (objField != null){
		if (objField.value){
			objField.value = regExpReplaceAll(objField.value, "<br/>", "\n");
		}
	}
}

function regExpReplaceAll(sString, sOldChars, sNewChars){
	var objRegExp;
	var sOutput;
	
	// Create the Regular Expression object and set it to search for the content of sOldChars
	objRegExp = new RegExp(sOldChars, "g");
	
	// Perform the conversion
	sOutput = sString.replace(objRegExp, sNewChars);
	
	// Return the string to the calling function
	return sOutput;
}


function appendString(sExistingString, sDelimiter, sNewString, bAlwaysApplyDelimiter){
	var strReturn = '';
	
	// Ensure all are valid strings
	if (sExistingString == null){sExistingString = '';}
	if (sDelimiter == null){sDelimiter = '';}
	if (sNewString == null){sNewString = '';}
	
	// Add the delimiter if needed
	if (sExistingString != '' || bAlwaysApplyDelimiter){
		strReturn = sExistingString + sDelimiter;
	}
	
	// Append the new string to the existing string
	strReturn = strReturn + sNewString;

	// Return the new string
	return strReturn;
}


function isInt (str){
	var i = parseInt (str);

	if (isNaN (i)){
		return false;
	}
	
	i = i.toString ();
	
	if (i != str){
		return false;
	}
	
	return true;
}


function saveBrochure(intPropertyID, intDevelopmentID){
	var strSaveBrochureURL = 'index.cfm?action=controlpanel.ModifyBrochurePopup&save=1&popup=1';
	var objChildWindow;
	
	// Check if we have a Property ID
	if (intPropertyID != null){
		strSaveBrochureURL = strSaveBrochureURL + '&propertyID=' + intPropertyID;
	}
	
	// Check if we have a New Development ID
	if (intDevelopmentID != null){
		strSaveBrochureURL = strSaveBrochureURL + '&developmentID=' + intDevelopmentID;
	}
	
	// Launch the popup
	objChildWindow = open(strSaveBrochureURL, 'winAddBrochure', 'width=400,height=150');
	//doPopup(strSaveBrochureURL)
}

function removeBrochureFromAccount(intPropertyID, intDevelopmentID){
	var strRetURL = escape(window.location);
	var strRemoveBrochureURL = 'index.cfm?action=controlpanel.ModifyBrochurePopup&delete=1';
	
	// Check if we have a Property ID
	if (intPropertyID != null){
		strRemoveBrochureURL = strRemoveBrochureURL + '&propertyID=' + intPropertyID;
	}
	
	// Check if we have a New Development ID
	if (intDevelopmentID != null){
		strRemoveBrochureURL = strRemoveBrochureURL + '&developmentID=' + intDevelopmentID;
	}
	
	// Goto the URL
	window.location.href = strRemoveBrochureURL + '&retURL=' + strRetURL
}

function doPopup(sURL){
	var oNewWinArgs = new Object();
	var objResult;
	
	// Get the result
	objResult = window.showModalDialog(sURL, oNewWinArgs, "dialogWidth:400px;dialogHeight:175px;center:yes;help:no;status:no");

	// Send the result to the calling function
	return objResult;
}



function printProperty(intPropertyID){
	var objNewWindow;
	var strURL;
	var strWindowName;
	var strArgs;
	
	// Build the URL
	strURL = 'index.cfm?action=pages.PrintProperty&propertyID=' + intPropertyID;
	
	// Build the window name
	strWindowName = 'winPrintProperty' + intPropertyID;
	
	// Build the Arguments list
	strArgs = 'width=650,resizable=yes,scrollbars=yes';

	// Open the new window
	objNewWindow = window.open(strURL, strWindowName ,strArgs)
}

function printDevelopment(intDevelopmenID){
	var objNewWindow;
	var strURL;
	var strWindowName;
	var strArgs;
	
	// Build the URL
	strURL = 'index.cfm?action=pages.PrintDevelopment&developmentID=' + intDevelopmenID;
	
	// Build the window name
	strWindowName = 'winPrintDevelopment' + intDevelopmenID;
	
	// Build the Arguments list
	strArgs = 'width=650,resizable=yes,scrollbars=yes';

	// Open the new window
	objNewWindow = window.open(strURL, strWindowName ,strArgs)
}



function confirmDelete(){
	if (confirm('Are you sure you want to delete these items?')){
		return true;
	}else{
		return false;
	}
}


function displayGallery(iPropertyID, iDevelopmentID, iImageTypeID){
	var strURL = 'index.cfm?action=gallery.ShowGallery';
	
	// Add the ID to the URL
	if (iPropertyID != null){
		strURL = strURL + '&propertyID=' + iPropertyID
	}else if (iDevelopmentID != null){
		strURL = strURL + '&developmentID=' + iDevelopmentID
	}else{
		alert('Unable to display the image gallery. Please try again.');
		return false;
	}
	
	// Add the Image Type ID to the URL
	strURL = strURL + '&imageType=' + iImageTypeID
	
	// Open the window
	//window.open(strURL,'wndImageGallery','width=450,height=500')
	window.open(strURL,'wndImageGallery','width=650,height=650')
				
	// Always return false
	return false;
}


function displayNewDevFeatures(iNewDevID){
	var sURL = 'index.cfm?action=pages.NewDevelopmentFeatures&developmentID=';
	var sWindowName = 'winNewDevFeatures';
	var sArgs = '';

	if (iNewDevID != null){
		// Build the URL
		sURL = sURL + String(iNewDevID);

		// Build the window name
		sWindowName = sWindowName + String(iNewDevID);
		
		// Build the Arguments list
		sArgs = 'width=440,height=300,resizable=yes,scrollbars=yes';
	
		// Open the new window
		objNewWindow = window.open(sURL, sWindowName, sArgs)
	}
}


function displayFutureDevFeatures(iFutureDevID){
	var sURL = 'index.cfm?action=pages.FutureDevelopmentFeatures&developmentID=';
	var sWindowName = 'winFutureDevFeatures';
	var sArgs = '';

	if (iFutureDevID != null){
		// Build the URL
		sURL = sURL + String(iFutureDevID);

		// Build the window name
		sWindowName = sWindowName + String(iFutureDevID);
		
		// Build the Arguments list
		sArgs = 'width=440,height=300,resizable=yes,scrollbars=yes';
	
		// Open the new window
		objNewWindow = window.open(sURL, sWindowName, sArgs)
	}
}