/* 
p.js

Software design and development by:
	Terence M. Bandoian
	P.O. Box 4074
	Austin, TX 78765
	http://www.tmbsw.com
	terence@tmbsw.com

Copyright (c) 2010 Terence M. Bandoian. All rights reserved.
*/

function showInfoForm( a, c, s, l ) { if ( isPopupVisible( a ) ) { return false; } setPopupAnchor( a ); $.ajax( { url: '/cgi-bin/listingagent/public/pubinfopopup.cgi' ,type: 'GET' ,cache: false ,data: '2=' + c + '&3=' + s + '&6=' + l ,success: showInfoFormResults ,error: showInfoFormError ,dataType: 'html' } ); return false; } function showInfoFormError( req ) { showInfoFormResults( req.responseText ); } function showInfoFormResults( data ) { var p; p = initPopup( data ); p.style.left = p.l3 + 'px'; p.style.top = p.t3 + 'px'; p.style.width = p.w3 + 'px'; p.style.height = p.h3 + 'px'; preAnimatePopup( p ); $(p).animate( { left: p.l2 ,top: p.t2 ,width: p.w2 ,height: p.h2 }, 200, function() { showPopup( p ); } ); } function submitInfoForm() { var p; setPopupAnchor( null ); if ( p = document.getElementById( 'popupContainer' ) ) { hidePopupContent(); $(p).animate( { left: p.l3 ,top: p.t3 ,width: 'hide' ,height: 'hide' }, 'fast', function() { hidePopup( p ); submitInfoFormPost(); } ); } return false; } function submitInfoFormPost() { var f; if ( f = document.getElementById( 'popupForm' ) ) { var c = f.getElementsByTagName( 'input' ); var d = ''; var a = false; for ( var n = 0; n < c.length; n++ ) { if (( c[ n ].type != 'button' ) && ( c[ n ].type != 'file' ) && ( c[ n ].type != 'image' ) && ( c[ n ].type != 'reset' ) && ( c[ n ].type != 'submit' )) { d += ( a ? '&' : '' ) + encodeURIComponent( c[ n ].name ) + '=' + encodeURIComponent( c[ n ].value ); a = true; } } $.ajax( { url: '/cgi-bin/listingagent/public/pubinfopopup.cgi' ,type: 'POST' ,cache: false ,data: d ,success: submitInfoFormResults ,error: submitInfoFormError ,dataType: 'html' } ); } return false; } function submitInfoFormError( req ) { submitInfoFormResults( req.responseText ); } function submitInfoFormResults( data ) { var p; p = initPopup( data ); p.style.left = p.l2 + 'px'; p.style.top = p.t2 + 'px'; showPopup( p ); } function showContactForm( a, c, s ) { if ( isPopupVisible( a ) ) { return false; } setPopupAnchor( a ); $.ajax( { url: '/cgi-bin/listingagent/public/pubformpopup.cgi' ,type: 'GET' ,cache: false ,data: '2=' + c + '&3=' + s ,success: showContactFormResults ,error: showContactFormError ,dataType: 'html' } ); return false; } function showContactFormError( req ) { showContactFormResults( req.responseText ); } function showContactFormResults( data ) { var p; p = initPopup( data ); p.style.left = p.l3 + 'px'; p.style.top = p.t3 + 'px'; p.style.width = p.w3 + 'px'; p.style.height = p.h3 + 'px'; preAnimatePopup( p ); $(p).animate( { left: p.l2 ,top: p.t2 ,width: p.w2 ,height: p.h2 }, 200, function() { showPopup( p ); } ); } function submitContactForm() { var p; setPopupAnchor( null ); if ( p = document.getElementById( 'popupContainer' ) ) { hidePopupContent(); $(p).animate( { left: p.l3 ,top: p.t3 ,width: 'hide' ,height: 'hide' }, 'fast', function() { hidePopup( p ); submitContactFormPost(); } ); } return false; } function submitContactFormPost() { var f; if ( f = document.getElementById( 'popupForm' ) ) { var c = f.getElementsByTagName( 'input' ); var d = ''; var a = false; for ( var n = 0; n < c.length; n++ ) { if (( c[ n ].type != 'button' ) && ( c[ n ].type != 'file' ) && ( c[ n ].type != 'image' ) && ( c[ n ].type != 'reset' ) && ( c[ n ].type != 'submit' )) { if (( c[ n ].type != 'checkbox' ) || ( c[ n ].checked )) { d += ( a ? '&' : '' ) + encodeURIComponent( c[ n ].name ) + '=' + encodeURIComponent( c[ n ].value ); a = true; } } } c = f.getElementsByTagName( 'textarea' ); for ( var n = 0; n < c.length; n++ ) { d += ( a ? '&' : '' ) + encodeURIComponent( c[ n ].name ) + '=' + encodeURIComponent( c[ n ].value ); a = true; } $.ajax( { url: '/cgi-bin/listingagent/public/pubformpopup.cgi' ,type: 'POST' ,cache: false ,data: d ,success: submitContactFormResults ,error: submitContactFormError ,dataType: 'html' } ); } return false; } function submitContactFormError( req ) { submitContactFormResults( req.responseText ); } function submitContactFormResults( data ) { var p; p = initPopup( data ); p.style.left = p.l2 + 'px'; p.style.top = p.t2 + 'px'; showPopup( p ); } function initPopup( c, s ) { var p; if ( p = document.getElementById( 'popupContainer' ) ) { hidePopup( p ); initPopupContent(); } else { p = document.createElement( 'div' ); p.id = 'popupContainer'; p.className = 'popup-container'; p.innerHTML = '<table border="0" cellspacing="0" cellpadding="0">' + '<tr>' + '<td>' + '<div class="popup-top-left"></div>' + '<div class="popup-top-right"></div>' + '<table border="0" cellspacing="0" cellpadding="0">' + '<tr>' + '<td class="popup-body-wrapper">' + '<div class="popup-body">' + '<div id="popupContent" class="popup-content"></div>' + '</div>' + '</td>' + '</tr>' + '</table>' + '<div class="popup-bottom-left"></div>' + '<div class="popup-bottom-right"></div>' + '</td>' + '</tr>' + '</table>'; document.body.appendChild( p ); } setPopupContent( c ); positionPopup( p, s ); return p; } var popupOffset = 0; function positionPopup( p, s ) { var e; p.style.display = 'block'; e = ( document.documentElement ? document.documentElement : document.body ); p.l2 = Math.floor( e.scrollLeft + ( e.clientWidth - p.offsetWidth ) / 2 ); p.t2 = Math.floor( e.scrollTop + ( e.clientHeight * 4 ) / 10 - p.offsetHeight / 2 ); p.w2 = p.offsetWidth; p.h2 = p.offsetHeight; if ( popupOffset ) { p.l2 += popupOffset; } if ( e = document.getElementById( 'listingMenu' ) ) { var m = e; var mt = 0; while ( m != null ) { mt += m.offsetTop; m = m.offsetParent; } if ( p.t2 - mt < e.offsetHeight * 2 ) { p.t2 = Math.floor( mt + e.offsetHeight * 2 ); } } p.r2 = p.l2 + p.w2 - 1; p.b2 = p.t2 + p.h2 - 1; p.l3 = Math.floor( p.l2 + p.w2 / 2 ); p.t3 = Math.floor( p.t2 + p.h2 / 2 ); p.w3 = 0; p.h3 = 0; if ( s ) { p.l1 = 0; p.t1 = 0; p.w1 = s.offsetWidth; p.h1 = s.offsetHeight; e = s; while ( e != null ) { p.l1 += e.offsetLeft; p.t1 += e.offsetTop; e = e.offsetParent; } } else { p.l1 = p.l3; p.t1 = p.t3; p.w1 = p.w3; p.h1 = p.h3; } } function preAnimatePopup( e ) { var p; if (( p = e ) || ( p = document.getElementById( 'popupContainer' ) )) { p.style.display = ''; p.style.visibility = 'visible'; hidePopupContent(); } } function isPopupVisible( a ) { var p; return (( a == popupAnchor ) && ( p = document.getElementById( 'popupContainer' ) ) && ( p.style.display == 'block' ) && ( p.style.visibility == 'visible' )); } function showPopup( e ) { var p; var f; if (( p = e ) || ( p = document.getElementById( 'popupContainer' ) )) { p.style.display = 'block'; p.style.visibility = 'visible'; p.style.width = ''; p.style.height = ''; showPopupContent(); addPopupListeners(); if ( f = document.getElementById( 'popupFocus' ) ) { setElementFocus( f ); } else { setFocus( 'popupFirst' ); } } } function hidePopup( e ) { var p; if (( p = e ) || ( p = document.getElementById( 'popupContainer' ) )) { p.style.display = ''; p.style.visibility = ''; hidePopupContent(); removePopupListeners(); } } function initPopupContent() { var p; if ( p = document.getElementById( 'popupContent' ) ) { p.innerHTML = ''; p.style.display = ''; p.style.visibility = ''; } } function setPopupContent( c ) { var p; if ( c && ( p = document.getElementById( 'popupContent' ) )) { p.innerHTML = c; } } function showPopupContent() { var p; if ( p = document.getElementById( 'popupContent' ) ) { p.style.visibility = ''; } } function hidePopupContent() { var p; if ( p = document.getElementById( 'popupContent' ) ) { p.style.visibility = 'hidden'; } } function addPopupListeners() { if ( document.body.addEventListener ) { document.body.addEventListener( 'click', popupClick, true ); document.addEventListener( 'keydown', popupKeyDown, true ); } else if ( document.attachEvent ) { document.attachEvent( 'onclick', popupClick ); document.attachEvent( 'onkeydown', popupKeyDown ); } } function removePopupListeners() { if ( document.body.addEventListener ) { document.body.removeEventListener( 'click', popupClick, true ); document.removeEventListener( 'keydown', popupKeyDown, true ); } else if ( document.attachEvent ) { document.detachEvent( 'onclick', popupClick ); document.detachEvent( 'onkeydown', popupKeyDown ); } } var popupAnchor = null; function setPopupAnchor( a ) { popupAnchor = a; if ( popupAnchor ) { var e; popupAnchor.l = 0; popupAnchor.t = 0; e = popupAnchor; while ( e != null ) { popupAnchor.l += e.offsetLeft; popupAnchor.t += e.offsetTop; e = e.offsetParent; } popupAnchor.r = popupAnchor.l + popupAnchor.offsetWidth - 1; popupAnchor.b = popupAnchor.t + popupAnchor.offsetHeight - 1; } } function popupClick( event ) { var p; var t; var x; var y; p = document.getElementById( 'popupContainer' ); if ( p ) { if ( window.event ) { t = event.srcElement; if ( document.compatMode && ( document.compatMode != 'BackCompat' )) { x = event.clientX - document.documentElement.clientLeft + document.documentElement.scrollLeft; y = event.clientY - document.documentElement.clientTop + document.documentElement.scrollTop; } else { x = event.x - document.body.clientLeft + document.body.scrollLeft; y = event.y - document.body.clientTop + document.body.scrollTop; } } else { t = event.target; x = event.clientX + window.pageXOffset; y = event.clientY + window.pageYOffset; } if (( t.nodeName.toLowerCase() != 'input' ) || ( t.form.id != 'popupForm' )) { if (( p.l2 > x ) || ( p.r2 < x ) || ( p.t2 > y ) || ( p.b2 < y )) { hidePopup( p ); if (( popupAnchor == t ) || ( popupAnchor && ( popupAnchor.l <= x ) && ( popupAnchor.r >= x ) && ( popupAnchor.t <= y ) && ( popupAnchor.b >= y ))) { return cancelEvent( event ); } } } } return true; } function popupKeyDown( event ) { var t; var n; if ( event ) { t = ( window.event ? event.srcElement : event.target ); n = t.nodeName.toLowerCase(); if ( event.keyCode == 9 ) { if (( n != 'a' ) && ( n != 'input' ) && ( n != 'textarea' )) { setFocus( event.shiftKey ? 'popupLast' : 'popupFirst' ); return cancelEvent( event ); } if ( event.shiftKey && ( t.id == 'popupFirst' )) { setFocus( 'popupLast' ); return cancelEvent( event ); } if ( !event.shiftKey && ( t.id == 'popupLast' )) { setFocus( 'popupFirst' ); return cancelEvent( event ); } } else if ( event.keyCode == 13 ) { if (( n == 'input' ) && ( t.form.id == 'popupForm' )) { t.form.onsubmit(); return cancelEvent( event ); } } else if ( event.keyCode == 27 ) { hidePopup(); return cancelEvent( event ); } } return true; } function initPopupBackground() { var b; var d; b = document.getElementById( 'popupBackground' ); if ( b == null ) { b = document.createElement( 'div' ); b.id = 'popupBackground'; b.className = 'popup-background'; document.body.appendChild( b ); } d = document.documentElement ? document.documentElement : document.body; b.style.width = Math.max( document.body.offsetWidth, d.clientWidth ) + 'px'; b.style.height = Math.max( document.body.offsetHeight, d.clientHeight ) + 'px'; return b; } function showPopupBackground() { var e; if ( e = document.getElementById( 'popupBackground' ) ) { e.style.display = 'block'; } } function hidePopupBackground() { var e; if ( e = document.getElementById( 'popupBackground' ) ) { e.style.display = 'none'; } } function cancelEvent( event ) { if ( event ) { if ( event.preventDefault ) { event.preventDefault(); event.stopPropagation(); } event.cancelBubble = true; event.returnValue = false; } return false; } function setFocus( id ) { setElementFocus( document.getElementById( id ) ); } function setElementFocus( e ) { if ( e ) { e.focus(); if ( document.selection ) { document.selection.empty(); if ( e.createTextRange ) { var r; r = e.createTextRange(); r.moveStart( 'character', e.value.length ); r.select(); } } } }

/* Copyright (c) 2010 Terence M. Bandoian. All rights reserved. */