function searchService()
{
	var url = "http://www.great-nm-homes.com/homes/search-service.htm";
	openCenteredWindow(url, 500, 600);
}

function cmaRequest()
{
	var url = "http://www.great-nm-homes.com/homes/cma-request.htm";
	openCenteredWindow(url, 500, 600);
}

function virtualTour(url)
{
	openCenteredWindow(url, 600, 600);
}

function propertySearch(param) 
{
/*
	if( param != null && param.length > 0 )
		url =  "http://www.great-nm-homes.com/homes/property-search.htm?"+param;
	else
		url =  "http://www.great-nm-homes.com/homes/property-search.htm";

	window.open(url, 'search', 'width=1024,height=768,scrollbars=yes,menubar=0,toolbar=0,status=0,resizable=1');
*/
	window.location = "http://www.great-nm-homes.com/mls-search.htm#all-areas";
}

function autoListingEmail() 
{
	window.open("http://www.great-nm-homes.com/homes/notify.htm", '', 'status=no,height=600,width=600,scrollbars=yes,menubar=0,toolbar=0,top=0,left=0,resizable=1,location=0');
}

function getMlsPhoto(filePath)
{
	var mlsPhotoPath = "<img src=\"http://mediall.rapmls.com/albq/listingpics/tmbphoto/"+filePath+"\" width=\"110\" height=\"82\">";
	document.write(mlsPhotoPath);
}

function getMlsPhotoAlt(filePath, altTag)
{
	var mlsPhotoPath;
	
	if (filePath.indexOf("nophoto") == -1)
		mlsPhotoPath = "<img src=\"http://mediall.rapmls.com/albq/listingpics/tmbphoto/"+filePath+"\" width=\"110\" height=\"82\" border=\"0\" title=\"pictures of "+altTag+"\">";
	else
		mlsPhotoPath = "<img src=\"http://mediall.rapmls.com/albq/listingpics/"+filePath+"\" width=\"110\" height=\"82\" border=\"0\" title=\"pictures of "+altTag+"\">";
		
	document.write(mlsPhotoPath);
}

function pictureGallery(mlsNum)
{
	var url = "http://www.great-nm-homes.com/homes/picture-frame.htm?mlsNum="+mlsNum;
	openCenteredWindow(url, 800, 600);
}

function instantInfo(mlsNum)
{
	var url = "http://www.great-nm-homes.com/homes/instant-info.htm?mlsnum="+mlsNum;
	openCenteredWindow(url, 600, 480);
}

function listingReport() 
{
	//var url = "http://www.great-nm-homes.com/homes/listing-report.htm";
	//openCenteredWindow(url, 600, 480);
	alert("Select the 'MORE INFO' link for any property that you're interested in. Request the most complete and current listing information available and you'll automatically get additional property history and area statistics for comparison.");
}

function marketAnalysis() 
{
	var url = "http://www.great-nm-homes.com/homes/cma.htm";
	openCenteredWindow(url, 600, 480);
}

function buyerAdvantage() 
{
	//var url = "http://www.great-nm-homes.com/homes/buyer-advantage.htm";
	//openCenteredWindow(url, 600, 480);
	alert("Gain access to unique and in-depth market area information compiled weekly from the MLS database. This is information that you can't get anywhere else, that I share with you as my client!");

}

function openCenteredWindow(url, width, height) 
{
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,scrollbars,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    window.open(url, "subWind", windowFeatures);
}

function officeInfo(office, phone, agent)
{
	var text = "Listed by "+agent+" of "+office+", "+phone+".";
	alert(text);
}

function featuredLand(param) 
{
	if( param != null && param.length > 0 )
		url =  "http://www.great-nm-homes.com/land/featured-property.htm?"+param;
	else
		url =  "http://www.great-nm-homes.com/land/featured-property.htm";

	window.open(url, 'search', 'scrollbars=yes,menubar=0,toolbar=0,status=0,resizable=1'); 
}

function landSearch(param) 
{
	if( param != null && param.length > 0 )
		url =  "http://www.great-nm-homes.com/land/property-search.htm?"+param;
	else
		url =  "http://www.great-nm-homes.com/land/property-search.htm";

	window.open(url, 'search', 'scrollbars=yes,menubar=0,toolbar=0,status=0,resizable=1'); 
}

function streetMapOld(street, city, state, zip) 
{
	var url = "http://www.mapquest.com/maps/map.adp?formtype=address&addtohistory=&address="+street+"&city="+city+"&state="+state+"&zipcode="+zip+"&country=US&geodiff=1"
	openCenteredWindow(url, 600, 480); 
}

function streetMap(street, city, state, zip)
{
	var url = "../favorites/street-map.htm?street="+street+"&city="+city+"&state="+state+"&zip="+zip;
	var width = 800;
	var height = 600;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,scrollbars,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    window.open(url, "mapWindow", windowFeatures);
}

function emailLink(url, mailbox) 
{
	var sendTo = "mailto:"+mailbox+"@"+url;
	window.location = sendTo;
}

function sellerMotivationRating(param) 
{
	if( param != null && param.length > 0 )
		url =  "http://www.great-nm-homes.com/homes/seller-motivation-rating.htm?"+param;
	else
		url =  "http://www.great-nm-homes.com/homes/seller-motivation-rating.htm";

	openCenteredWindow(url, 400, 400);
}

function sellerMotivationRatingExtended(param) 
{
	if( param != null && param.length > 0 )
		url =  "http://www.great-nm-homes.com/homes/seller-motivation-rating-extended.htm?"+param;
	else
		url =  "http://www.great-nm-homes.com/homes/seller-motivation-rating-extended.htm";

	openCenteredWindow(url, 400, 400);
}

function featuredHouse(param) 
{
	if( param != null && param.length > 0 )
		url =  "http://www.great-nm-homes.com/homes/featured-property.htm?"+param;
	else
		url =  "http://www.great-nm-homes.com/homes/featured-property.htm";

	window.open(url, 'search', 'scrollbars=yes,menubar=0,toolbar=0,status=0,resizable=1'); 
}

function replaceChars(input, replaceThis, replaceWith)
{
	temp = "" + input; // temporary holder

	while (temp.indexOf(replaceThis)>-1) 
	{
		pos = temp.indexOf(replaceThis);
		temp = ""+(temp.substring(0, pos)+replaceWith+temp.substring((pos+replaceThis.length), temp.length));
	}
	return temp;
}

function searchAbqRealEstate()
{
	var location="";
	var area;

	area = replaceChars(document.search.area.value, "gnmh/", "");
	area = replaceChars(area, "abq/", "");
	area = replaceChars(area, "-", " ");

	if(document.search.type[0].checked)
	{
		location = replaceChars(document.search.area.value, "gnmh", "http://www.great-nm-homes.com/homes");
		location = replaceChars(location, "abq", "houses");
		location = location+".htm";
		
		if(document.search.house_category.value=="new")
			location = location+"#"+area+" New Homes";
		else if(document.search.house_category.value=="recent")
			location = location+"#"+area+" Recent Listings";
	}
	else if(document.search.type[1].checked)
	{
		location = replaceChars(document.search.area.value, "gnmh", "http://www.great-nm-homes.com/land");
		location = replaceChars(location, "abq", "land");
		location = location+".htm";
		
		if(document.search.land_category.value=="recent")
			location = location+"#"+area+" Recent Listings";
	}

	document.location = location;
}

function searchRealEstate()
{
	var location="";
	var area="";

	area = replaceChars(document.search.area.value, "gnmh/", "");
	area = replaceChars(area, "nmre/", "");
	area = replaceChars(area, "-", " ");

	if(document.search.type[0].checked)
	{
		location = replaceChars(document.search.area.value, "gnmh", "http://www.great-nm-homes.com/homes");
		location = replaceChars(location, "nmre", "houses");
		location = location+".htm";
		
		if(document.search.house_category.value=="new")
			location = location+"#"+area+" New Homes";
		else if(document.search.house_category.value=="recent")
			location = location+"#"+area+" Recent Listings";
	}
	else if(document.search.type[1].checked)
	{
		location = replaceChars(document.search.area.value, "gnmh", "http://www.great-nm-homes.com/land");
		location = replaceChars(location, "nmre", "land");
		location = location+".htm";
		
		if(document.search.land_category.value=="recent")
			location = location+"#"+area+" Recent Listings";
	}

	document.location = location;
}

function gnmhLink(path)
{
	document.location = "http://www.great-nm-homes.com"+path;
}

function logReferrer(path, website)
{
	var fullPath = path+"/cgi-bin/fhw.exe";

	if (document.referrer.length > 0 && document.referrer.search(website) == -1)
	{
		document.write("<br><img src=\""+fullPath+"?referrer=");
		document.write(document.referrer);
		document.write("\" width=\"100\" height=\"1\">");
	}
}

function oldgetEmblem(path, website)
{
	var fullPath = path+"/cgi-bin/fhw.exe";

	document.write("<img src=\""+fullPath+"?page=");
	document.write(escape(document.URL));
	document.write("\" width=\"100\" height=\"1\">");

	logReferrer(path, website);
}

function getEmblem(path, website)
{
	document.write("<img src=\"../scripts/get-emblem.php?page=");
	document.write(escape(document.URL));
	if (document.referrer.length > 0 && document.referrer.search("abq-real-estate") == -1)
	{
		document.write("&referrer=");
		document.write(escape(document.referrer));
	}
	document.write("\" width=\"100\" height=\"1\">");
}

function sleep(naptime)
{
	naptime = naptime * 1000;
	var sleeping = true;
	var now = new Date();
	var alarm;
	var startingMSeconds = now.getTime();

	while(sleeping)
	{
		alarm = new Date();
		alarmMSeconds = alarm.getTime();
		if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
	}      
}

function setDateCookie()
{
	var today = new Date();
	var day = today.getDate();
	var month = today.getMonth()+1;
	var year = today.getFullYear();
	var hour = today.getHours();
	var minute = today.getMinutes();
	var second = today.getSeconds();
	var ID = new String();

	if(getCookieField("DATE") != null)
		return;
	
	ID = year+"-";

	if( month < 10 )
		ID = ID+"0"+month+"-";
	else
		ID = ID+month+"-";

	if( day < 10 )
		ID = ID+"0"+day+"-";
	else
		ID = ID+day+"-";

	if( hour < 10 )
		ID = ID+"0"+hour+"-";
	else
		ID = ID+hour+"-";

	if( minute < 10 )
		ID = ID+"0"+minute+"-";
	else
		ID = ID+minute+"-";

	if( second < 10 )
		ID = ID+"0"+second;
	else
		ID = ID+second;

	setCookie( "DATE", ID, 730, "/", "", "" );
}

function setCookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
		if the expires variable is set, make the correct 
		expires time, the current script below will set 
		it for x number of days, to make it for hours, 
		delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}

	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function getCookieField(name) 
{
	var search = name + "=";
	
	if (document.cookie.length > 0) 
	{ // if there are any cookies
      	offset = document.cookie.indexOf(search);
      	
		if (offset != -1) 
		{// if cookie field exists 
         		offset += search.length;
         		end = document.cookie.indexOf(";", offset);
         		if (end == -1)
            		end = document.cookie.length;
         			
			return unescape(document.cookie.substring(offset, end));
      	} 
   	}
   	return null;
}



var qsParm = new Array();
function qs() 
{
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) 
	{
		var pos = parms[i].indexOf('=');
		if (pos > 0) 
		{
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}
}
qs();


function strltrim() {
	return this.replace(/^\s+/,'');
}

function strrtrim() {
	return this.replace(/\s+$/,'');
}

function strtrim() {
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;
setDateCookie();

