// JavaScript Document

// -=-=-=-=-=-=-=-[ posting page specific scripts ]-=-=-=-=-=-=-=-
 
 // ----- global vars
	var imgParams ='width="424" height="318" border="0" class="shadowboxImg" id="propertyImage"';
	var emailerTarget = '/_ajx/emailPosting.php';
	var inquiryTarget = '/_ajx/postingInquiry.php';
	var saveSrchTarget = '/_ajx/saveSearch.php';
	var dfltSrchTarget = '/_ajx/saveSearchDflt.php';
	var lastTo = '';
	var lastID = '';
	var extSiteAlert = 'Selecting this link will open a new window that will take you to another site.\n\nDo you wish to continue?\n\nNote: iPost360 is not affilated with this web site.';
								
	//-=-=-=-=-=-[ external site redirect]-=-=-=-=-=-
	
	function confirmExt(alertMsg,urlStr) {
		var confirmThis =  confirm(alertMsg);
		if (confirmThis) {
			MM_openBrWindow(urlStr,'extLink','scrollbars=yes,resizable=yes,width=800,height=600')
		} else {
			return false;
		}
	}

	//-=-=-=-=-=-[ post email posting to server]-=-=-=-=-=-
	
	function ajaxEmail(formObj,emailerTarget,responseDiv) {
		var thisTo = document.getElementById("emailTo").value;
		var thisID = document.getElementById("adID").value;
		if ((thisTo == lastTo) && (thisID == lastID) && (thisTo != '')) {
			confirmed = confirm("You already sent this posting to this email address. Do you want to continue?")
		} else {
			confirmed = true;
		}
		if (confirmed) {
			var trgtPost = emailerTarget;
			var trgtDiv = responseDiv;
			// gather the form data
			var postStr = 	"emailTo=" + encodeURI( thisTo ) +
							"&emailFrom=" + encodeURI( document.getElementById("emailFrom").value ) +
							"&emailMsg=" + encodeURI( document.getElementById("emailMsg").value ) +
							"&clid=" + encodeURI( thisID );
							
			lastTo = thisTo;
			lastID = thisID;
			// ajax it!			
			postRequest(trgtPost, postStr,trgtDiv);
		}
   }
   
   //-=-=-=-=-=-[ post email inquiry to server]-=-=-=-=-=-
   
	function inquiryEmail(formObj,inquiryTarget,responseDiv) {
		var thisID = document.getElementById("inquiryID").value;
		var thisMsg = document.getElementById("inquiryMsg").value;
		if ((thisID == lastID) && (thisMsg != '')) {
			confirmed = confirm("You already sent a message regarding this posting. Do you want to continue?")
		} else {
			confirmed = true;
		}
		if (confirmed) {
			var trgtPost = inquiryTarget;
			var trgtDiv = responseDiv;
			// gather the form data
			var postStr = 	"&inquiryFullname=" + encodeURI( document.getElementById("inquiryFullname").value ) +
							"&inquiryFrom=" + encodeURI( document.getElementById("inquiryFrom").value ) +
							"&inquiryMsg=" + encodeURI( document.getElementById("inquiryMsg").value ) +
							"&inquiryID=" + encodeURI( thisID ) +
							"&clid=" + encodeURI( thisID );
			lastID = thisID;
			// ajax it!			
			postRequest(trgtPost, postStr,trgtDiv);
		}
		
	}
   //-=-=-=-=-=-[ auto clear form field]-=-=-=-=-=-
	function clearField(fieldRef,testTxt) {
		if (fieldRef.value == testTxt) {
			fieldRef.value = '';
			return false;
		}
		
	}
	
	//-=-=-=-=-=-[ save listing to favorites]-=-=-=-=-=-
	function saveListing(str,elmtID,newDivName) {
		mlsID = str;
		targetElmt = elmtID;
		childElmt = newDivName;
		// instantiate new child
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) { 
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="/_ajx/saveListing.php?mlsID="+mlsID;
		xmlHttp.onreadystatechange=stateChangedMLS;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}

	//-=-=-=-=-=-[ save search as Property Alert ]-=-=-=-=-=-
	
	function saveSearch(formObj,saveSrchTarget,responseDiv) {
		var trgtPost = saveSrchTarget;
		var trgtDiv = responseDiv;
		if (document.getElementById("alertFreq")) {
			// form data
			var alertFreq = document.getElementById("alertFreq").value;
			var alertName = document.getElementById("alertName").value;
			// gather the form data
			var postStr = 	"alertFreq=" + encodeURI( alertFreq ) +
							"&alertName=" + encodeURI( alertName );
		} else {
			var postStr = '';
		}
		// ajax it!			
		postRequest(trgtPost, postStr,trgtDiv);

	}