var URL = unescape(location.href);	// get current URL in plain ASCII
var urlStart = URL.lastIndexOf("/") + 1;
var urlEnd = URL.length;
var fileName = URL.substring(urlStart,urlEnd);

function searchProperties(theForm){
		var pid = theForm.propId.value;
				
		if(isSearchPage(fileName)){
			var q = (document.location.search);
   			document.getElementById('searchmain').src = "/listings/searchResults.php?propId=" + pid;
			return (false);
		}else{
			location.href = "/search.php?propId=" + pid;
			return (false);
		}
	
	};
	
	function isSearchPage(fileName){
		searchPage = new RegExp("search", "i")
		results = fileName.match(searchPage)
		if (results == null){
			return false;
		}else{ 
			return true;
		}
	};
	
	window.onload = function () {
		if ((querystring("propId"))!= "does_not_exist"){
   			document.getElementById('searchmain').src = "/listings/searchResults.php?propId="+querystring("propId");
		}
	};
	
	
	function querystring(name)   // returns a named value from the querystring
		{
		
		   var tmp = ( location.search.substring(1) );
		   var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");
		
		   if ( i >= 0 )
		   {
		      tmp = tmp.substring( name.length+i+1 );
		      i = tmp.indexOf("&");
		      return unescape( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));
		   }
		
		   return("does_not_exist");
		};


