function submitRequest()
{
	if(document.form.NAME.value.trim().length==0 || 
	   document.form.PHONE.value.trim().length==0 ||
	   document.form.EMAIL.value.trim().length==0)
	{
		alert("Name, Telephone and Email are required! Your privacy is guaranteed.");
		document.form.EMAIL.focus();
		return false;
	}
	else
	{
		alert("Thank you! Your request will be processed very soon!");
		document.form.action = "../scripts/request.php";
		return true;
	}
}

function requiredFields()
{
	if(document.form.FIRST_NAME.value.trim().length==0 || 
	   document.form.LAST_NAME.value.trim().length==0 ||
	   document.form.PHONE.value.trim().length==0 ||
	   document.form.EMAIL.value.trim().length==0)
	{
		alert("Name, Telephone and Email are required! Your privacy is guaranteed.");
		document.form.FIRST_NAME.focus();
		return false;
	}
	else
	{
		alert("Thank you! Your request will be processed very soon!");
		document.form.action = "../scripts/request.php";
		return true;
	}
}

function emailLink(url, mailbox) 
{
	var sendTo = "mailto:"+mailbox+"@"+url;
	window.location = sendTo;
}

function virtualTour(url)
{
	openCenteredWindow(url, 600, 480);
}

function pictureGallery(mlsNum)
{
	var url = "picture-frame.htm?mlsNum="+mlsNum;
	openCenteredWindow(url, 600, 480);
}

function instantInfo(mlsNum)
{
	var url = "../homes/instant-info.htm?mlsnum="+mlsNum;
	openCenteredWindow(url, 600, 480);
}

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 autoListingEmail() 
{
	openCenteredWindow("../homes/notify.htm", 600, 600);
}

function buyerAdvantage() 
{
	var url = "../homes/buyer-advantage.htm";
	openCenteredWindow(url, 600, 480);
}

function areaReport() 
{
	var url = "../homes/area-report.htm";
	openCenteredWindow(url, 600, 480);
}

function marketAnalysis() 
{
	var url = "../homes/cma.htm";
	openCenteredWindow(url, 600, 480);
}

function completeMLS() 
{
	var url = "../homes/complete-mls-sheet.htm";
	openCenteredWindow(url, 600, 480);
}

function listingReport() 
{
	var url = "../homes/listing-report.htm";
	openCenteredWindow(url, 600, 480);
}

function myListings() 
{
	url = "http://abqrealtors.rapmls.com/scripts/mgrqispi.dll?APPNAME=albq&PRGNAME=MLSLogin&ARGUMENT=oxdEJDS7W9Pgd3%2BCPVNblceLmsTgxYEKEHWYHb1617M%3D&KeyRid=1";
	openCenteredWindow(url, 600, 480);
}

function listingHistory(param) 
{
	if( param != null && param.length > 0 )
		url =  "../homes/listing-history.htm?"+param;
	else
		url =  "../homes/listing-history.htm";

	window.open(url, '', 'status=no,height=400,width=400,scrollbars=yes,menubar=0,toolbar=0,top=0,left=0,resizable=1,location=0');
}

function sellerMotivationRating(param) 
{
	if( param != null && param.length > 0 )
		url =  "../homes/seller-motivation-rating.htm?"+param;
	else
		url =  "../homes/seller-motivation-rating.htm";

	openCenteredWindow(url, 600, 480);
}

function streetMap(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 houseSearch(param) 
{
	if( param != null && param.length > 0 )
		url =  "../homes/property-search.htm?"+param;
	else
		url =  "../homes/property-search.htm";

	openCenteredWindow(url, 1024, 768);
}

function landSearch(param) 
{
	if( param != null && param.length > 0 )
		url =  "../land/property-search.htm?"+param;
	else
		url =  "../land/property-search.htm";

	window.open(url, 'search', 'width=1024,height=768,scrollbars=yes,menubar=0,toolbar=0,status=0,resizable=1'); 
}

function propertySearch(param) 
{
	if( param != null && param.length > 0 )
		url =  "../homes/property-search.htm?"+param;
	else
		url =  "../homes/property-search.htm";

	window.open(url, 'search', 'width=1024,height=768,scrollbars=yes,menubar=0,toolbar=0,status=0,resizable=1');
}

function featuredHouse(param) 
{
	if( param != null && param.length > 0 )
		url =  "../homes/featured-property.htm?"+param;
	else
		url =  "../homes/featured-property.htm";

	window.open(url, 'search', 'width=1024,height=768,scrollbars=yes,menubar=0,toolbar=0,status=0,resizable=1'); 
}

function featuredLand(param) 
{
	if( param != null && param.length > 0 )
		url =  "../land/featured-property.htm?"+param;
	else
		url =  "../land/featured-property.htm";

	window.open(url, 'search', 'width=1024,height=768,scrollbars=yes,menubar=0,toolbar=0,status=0,resizable=1'); 
}



function getRecentSearches()
{
	window.location = "../cgi-bin/fhw.exe?getrefs";
}

function oldlogReferrer(path)
{
	if (document.referrer.length > 0 && document.referrer.search("great-nm-homes") == -1)
	{
		document.write("<br><img src=\""+path+"?referrer=");
		document.write(document.referrer);
		document.write("\" width=\"100\" height=\"1\">");
	}
}

function logReferrer(path)
{
	if (document.referrer.length > 0 && document.referrer.search("great-nm-homes") == -1)
	{
		document.write("<br><img src=\"../scripts/get-emblem.php?referrer=");
		document.write(document.referrer);
		document.write("\" width=\"100\" height=\"1\">");
	}
}

function getEmblem(path)
{
	document.write("<img src=\"../scripts/get-emblem.php?page=");
	document.write(escape(document.URL));
	if (document.referrer.length > 0 && document.referrer.search("great-nm-homes") == -1)
	{
		document.write("&referrer=");
		document.write(escape(document.referrer));
	}
	document.write("\" width=\"100\" height=\"1\">");
	oldgetEmblem(path);
}

function oldgetEmblem(path)
{
	document.write("<br><img src=\""+path+"?page=");
	document.write(escape(document.URL));
	document.write("\" width=\"100\" height=\"1\">");
	//logReferrer(path);
}

function getMlsPhoto(filePath)
{
	var mlsPhotoPath = "<img src=\"http://medialaxf.rapmls.com/albq/listingpics/tmbphoto/"+filePath+"\" width=\"110\" height=\"82\">";
	document.write(mlsPhotoPath);
}

function getMlsPhotoAlt(filePath, altTag)
{
	var mlsPhotoPath = "<img src=\"http://medialaxf.rapmls.com/albq/listingpics/tmbphoto/"+filePath+"\" width=\"110\" height=\"82\" border=\"0\" alt=\"pictures of "+altTag+"\">";
	document.write(mlsPhotoPath);
}

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;
}

function deleteCookie(name, path, domain) 
{
	if ( getCookieField(name) )
	{
		document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}


function isIdToday()
{
	var today = new Date();
	var day = today.getDate();
	var month = today.getMonth()+1;
	var year = today.getFullYear();
	var ID = new String();
	
	ID = year+"-";

	if( month < 10 )
		ID = ID+"0"+month+"-";
	else
		ID = ID+month+"-";

	if( day < 10 )
		ID = ID+"0"+day;
	else
		ID = ID+day;

	var ARDID = getCookieField("ARDID");

	if( ARDID.search(ID) == -1 )
		return false;
	else
		return true;
}

function getViewCount()
{
	var increment = 1;
	var views = getCookieField("VIEWS");
	
	if( views == null )
	{
		setCookie( "VIEWS", 1, 1, "/", "", "" );
	}
	else
	{
		increment = 1 + parseInt(views);
		setCookie( "VIEWS", increment, 1, "/", "", "" );
	}

	return increment;
}

function setNextFeaturedMain(param)
{
	if( getCookieField("RESPONDED") != null )
	{
		setFooter();
		return;
	}

	if( getCookieField("COMPLETE") == null )
	{
		main.location="../homes/complete-mls-sheet-frame.htm?"+param;
		setCookie( "COMPLETE", "true", 1, "/", "", "" );
	}
	else if( getCookieField("NOTIFY") == null )
	{
		main.location="../homes/notify-frame.htm?"+param;
		setCookie( "NOTIFY", "true", 1, "/", "", "" );
	}
	else if( getCookieField("HISTORY") == null )
	{
		main.location="../homes/listing-report-frame.htm?"+param;
		setCookie( "HISTORY", "true", 1, "/", "", "" );
	}
	else
	{
		main.location="../homes/help-frame.htm?"+param;
	}
}

function setNextAreaMain(param)
{
	if( getCookieField("RESPONDED") != null )
	{
		setFooter();
		return;
	}

	if( getCookieField("NOTIFY") == null )
	{
		if( param == null )
			main.location="../homes/notify-frame.htm";
		else
			main.location="../homes/notify-frame.htm?"+param;
		
		setCookie( "NOTIFY", "true", 1, "/", "", "" );
	}
	else if( getCookieField("REPORT") == null )
	{
		if( param == null )
			main.location="../homes/area-report-frame.htm";
		else
			main.location="../homes/area-report-frame.htm?"+param;
		
		setCookie( "REPORT", "true", 1, "/", "", "" );
	}
	else if( getCookieField("COMPLETE") == null )
	{
		if( param == null )
			main.location="../homes/complete-mls-sheet-frame.htm";
		else
			main.location="../homes/complete-mls-sheet-frame.htm?"+param;
		
		setCookie( "COMPLETE", "true", 1, "/", "", "" );
	}
	else
	{
		if( param == null )
			main.location="../homes/help-frame.htm";
		else
			main.location="../homes/help-frame.htm?"+param;
		
		main.location="../homes/help-frame.htm?"+param;
	}
}

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 setHelp2() 
{
	help.location.replace("property-search-help2.htm");
	setTimeout('setHelp3()',5000);

}

function setHelp3() 
{
	help.location.replace("property-search-help3.htm");
	setTimeout('setHelp4()',5000);

}

function setHelp4() 
{
	help.location.replace("property-search-help4.htm");
	setTimeout('setHelp5()',5000);

}

function setHelp5() 
{
	help.location.replace("property-search-help.htm");
}

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 wait(time)
{
	var sleeping = true;
	var now = new Date();
	var alarm;
	var startingMSeconds = now.getTime();

	while(sleeping)
	{
		alarm = new Date();
		alarmMSeconds = alarm.getTime();
		if(alarmMSeconds - startingMSeconds > time){ sleeping = false; }
	}      
}

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();
