// Listing Results & Details Page Scripts
function PopupVirtualTour ( virtualTourURL )
{
	var first7 = virtualTourURL.substr ( 0, 7 );
	var thisURL = virtualTourURL;
	if ( first7.toUpperCase () != "HTTP://" )
	{
		thisURL = "HTTP://" + thisURL;
	}
	popupDefn = "height=650,width=800,scrollbars=yes,resizable=yes";
	popupWindow = window.open(thisURL, 'VirtualTourWindow', popupDefn );
	popupWindow.focus();
}
function PopupVirtualTourLOG ( virtualTourURL,baseurl,session_key,reference_id,source )
{
	var first7 = virtualTourURL.substr ( 0, 7 );
	var thisURL = virtualTourURL;
	if ( first7.toUpperCase () != "HTTP://" )
	{
		thisURL = "http://" + thisURL;
	}
	ajaxLog(baseurl,session_key,"VT",reference_id,"LISTING_NO","LISTING","PHOTO",source,thisURL);
	popupDefn = "height=650,width=800,scrollbars=yes,resizable=yes";
	popupWindow = window.open(thisURL, 'VirtualTourWindow', popupDefn );
	popupWindow.focus();
}
function PopupSuburbProfile ( statsId )
{
	popupURL = "/res/res-popup-suburbprofile.cfm?Stats_Id=" + statsId;
	popupDefn = "height=850,width=750,scrollbars=Yes";
	popupWindow = window.open(popupURL, 'SuburbProfileWindow', popupDefn );
	popupWindow.focus();
}
function UpdatePropertyListDetail ( listingId, isInList, Comments )
{
	on_id  = document.getElementById("propertylist_ON" );
	off_id  = document.getElementById("propertylist_OFF" );
	if ( isInList == "YES" ) {
		on_id.style.display='';
		off_id.style.display='none';
	} 
	else {
		on_id.style.display='none';
		off_id.style.display='';
	}
	
	commentText_id = document.getElementById("MyCommentsText_Id" );
	comment_id = document.getElementById("MyComments_Id" );
	if ( Comments == "" ) {
		comment_id.style.display='none';
		commentText_id.style.display='none';
	} 
	else {
		commentText_id.innerHTML = Comments;
		comment_id.style.display='';
		commentText_id.style.display='';
	} 
}
function UpdatePropertyListResult ( listingId, isInList, Comments )
{
	on_id  = document.getElementById("propertyList_" + listingId + "_ON" );
	off_id  = document.getElementById("propertyList_" + listingId + "_OFF" );
	if ( isInList == "YES" ) {
		on_id.style.display='';
		off_id.style.display='none';
	} 
	else {
		on_id.style.display='none';
		off_id.style.display='';
	}
	comment_id = document.getElementById("MyComments_" + listingId );
	if ( Comments == "" ) {
		comment_id.style.display='none';
	} 
	else {
		comment_id.innerHTML = 'My Comments: ' + Comments;
		comment_id.style.display='';
	} 
}
function PopupMyPropertyList ( listingId, referPage )
{
	popupURL = "/lst/lst-popup-mypropertylist-maintain.cfm?Action=Display&ListingId=" + listingId + '&Refer=' + referPage;
	popupDefn = "height=430,width=350,scrollbars=no";
	popupWindow = window.open(popupURL, 'MyPropertyList', popupDefn );
	popupWindow.focus();
}
function PopupMyPropertyListAbout (  )
{
	popupURL = "/lst/lst-popup-mypropertylist-about.cfm";
	popupDefn = "height=600,width=580,scrollbars=Yes";
	popupWindow = window.open(popupURL, 'MyPropertyListAbout', popupDefn );
	popupWindow.focus();
}
			


// areaMap Function - Opens the Area Map in a new popup window
// Call methods (uses named arguments so pass into the function using an object literal):
//			a.	Listing Number method - pass through the Street Address & Listing Number of the property.
//				eg. areaMap( {strAddress : '2 A LEAROYD ST MOUNT LAWLEY', Listing : 3555555 } )
//			b. 	Co-ordinate method : pass through the Street Address, Lat & Lon co-ordinates of the property .
//				eg. areaMap( {strAddress : '2 A LEAROYD ST MOUNT LAWLEY#', Lat : -31.927062, Lon : 115.86434 } )
function areaMap( oArg )
{
	var strAddress = 'strAddress' in oArg? oArg.strAddress : "";
	var Listing = 'Listing' in oArg? oArg.Listing : "";
	var Lat = 'Lat' in oArg? oArg.Lat : "";
	var Lon = 'Lon' in oArg? oArg.Lon : "";
	if (Listing != "") 
	{
		window.open( "/map/map-popup-areamap-view.cfm?strAddress=" + strAddress + "&Listing=" + Listing,
					'AreaMap', 'scrollbars=yes,status=no,width=900,height=600,menubar=yes,titlebar=no');
	}
	else
	{
		window.open( "/map/map-popup-areamap-view.cfm?strAddress=" + strAddress + "&Lat=" + Lat + "&Lon=" + Lon,
					'AreaMap', 'scrollbars=yes,status=no,width=900,height=600,menubar=yes,titlebar=no');
	}
}

function PopupEmailFriend ( listing_no )
{
	popupURL = "/Lst/Lst-Popup-EmailFriend.cfm?listing_no=" + listing_no;
	popupDefn = "height=410,width=420,scrollbars=no";
	popupWindow = window.open(popupURL, 'SuburbProfileWindow', popupDefn );
	popupWindow.focus();
}
		
function PopupEmailAgent( realtor_no,listing_no,agency_no,branch_no,address,searchtype )
{
	popupURL = "/Lst/Lst-Popup-EmailAgent.cfm?realtor_no=" + realtor_no + "&listing_no=" + listing_no + "&agency_no=" + agency_no + "&branch_no=" + branch_no + "&address=" + address + "&searchtype=" + searchtype;
	popupDefn = "height=430,width=350,scrollbars=no";
	popupWindow = window.open(popupURL, 'SuburbProfileWindow', popupDefn );
	popupWindow.focus();
}

//WP-98
function PopupListingStats ( listing_no )
{
	popupURL = "/Lst/Lst-Popup-PopupListingStats.cfm?listing_no=" + listing_no;
	popupDefn = "height=350,width=420,scrollbars=no";
	popupWindow = window.open(popupURL, 'ListingStats', popupDefn );
	popupWindow.focus();
}

/* Validate & if not already popup then open new window for email agent */
function ValidateAgentEmail(form,popup) {
	var emailFrom = form.from_email.value;
	emailFrom = emailFrom.trim();
	if (emailFrom == "" || !isValidEmail(emailFrom)) {
		alert ( "Please enter a valid email address." );
		form.from_email.focus();
		return false;
	}
	if ( form.from_name.value == "" ) {
		alert ( "Please enter your name." );
		form.from_name.focus();
		return false;
	}
	if ( form.from_phone.value == "" ) {
		alert ( "Please enter your phone." );
		form.from_phone.focus();
		return false;
	}
	if ( form.email_body.value == "" ) {
		alert ( "Please enter a message." );
		form.from_phone.focus();
		return false;
	}
	if(!popup) {
		newWindow = window.open ( "", "msg_write", "height=430,width=350,scrollbars=no");
		form.target = newWindow.name;
		newWindow.focus();
	}
	form.submit();
	form.reset();
	return true;
}