/*
===============================================================================
PAGE:			RealMedia.js 

AUTHOR:			Gary Winter

DESCRIPTION:	Javascript Routines for RealMedia calls

INCLUDES:		/HomesCom/Resources/RealMedia.js
	
NOTES:			

START DATE:		October 04, 2005

MODIFICATIONS:
MM/DD/YYYY      Author          Change
04/07/206		Gary Winter		Added replace for OAS_query to replace
								plus, space and %20 with a dash
04/19/206		Gary Winter		Added code to replace single quotes with no space in OAS_QUERY
===============================================================================
*/

/* Function for parsing querystring */
function GetParam(name,search)
{
  var start=search.indexOf("?"+name+"=");
  if (start<0) 
  	start=search.indexOf("&"+name+"=");
  if (start<0) 
  	return '';
  start += name.length+2;
  var end=search.indexOf("&",start)-1;
  if (end<0) 
  	end=search.length;
  var result=location.search.substring(start,end);
  var result='';
  for(var i=start;i<=end;i++) {
    var c=location.search.charAt(i);
    result=result+(c=='+'?' ':c);
  }
  return unescape(result);
}
/* OAS SETUP begin */
//Configuration
// Initilaize variables
	//Array of page names the use the Middle1 Position
		//If adding to this, make sure the page name is in lower case
		//  and full script_name is used.
	var page_array = new Array(
	"/content/financecenter.cfm",
	"/content/financecenterresults.cfm");
	// RealMedia server
	var OAS_url = 'http://ads.traderonline.com/RealMedia/ads/';
	// RealMeadia page - this is the full location
	//OAS_sitepage = 'www.homes.com/homepage.html';
	//var OAS_sitepage = 'www.homes.com' + window.location.pathname.toLowerCase();
	// variable to use so we can compare and not worry about case in the pathname
	//var page = window.location.pathname.toLowerCase();
	// Initialize OAS_listpos ( RealMedia Position List )
	var OAS_listpos = "";
	// Initialize OAS_target
	var OAS_target = '_top';
	// Initialize OAS_query ( RealMedia Targeting )
	if ( ! OAS_query )
		var OAS_query = '';
//OAS Position List Setup Begin
	// This checks which page we are on and set the proper position list
	//alert(page);
	
	if ( page == '/content/financecenter.cfm' || page == '/'){
		OAS_listpos = 'Top,Right1,Bottom1'
	} else if ( page == '/content/mortgage-calculator.cfm') {
		OAS_listpos = 'Top,Bottom1'
	} else if ( page == '/content/financecenterresults.cfm' ) {
		OAS_listpos = 'Top,Right1,Bottom1'
	} else if (page == '/content/propertyrecord.cfm') {
		OAS_listpos = 'Top,Bottom1'
	} else {
		for ( var i = 0; i < page_array.length; i++ ) {
			if ( page_array[i] == page )
				OAS_listpos = 'Top,Right1,Left1';
		}
		if ( ! OAS_listpos.length )
			OAS_listpos = 'Top,Right1,Left1';
	}
	//alert(OAS_listpos);
//OAS_query setup start
	// This sets the targeting parameters passed through the URL variables
	if ( location.search.length > 0 ) {
	// set the url string to all lower case for ease of comparison
	var search = location.search.toLowerCase();
		if ( GetParam('city',search) ) {
			if (OAS_query.length == 0)
				OAS_query = 'city=' + GetParam('city',search);
			else
				OAS_query = OAS_query + '&city=' + GetParam('city',search);
		}
		if ( GetParam('state',search) ) {
			if (OAS_query.length == 0)
				OAS_query = 'state=' + GetParam('state',search);
			else
				OAS_query = OAS_query + '&state=' + GetParam('state',search);			
		}
		if ( GetParam('zipcode',search) ) {
			if (OAS_query.length == 0)
				OAS_query = 'zipcode=' + GetParam('zipcode',search);
			else
				OAS_query = OAS_query + '&zipcode=' + GetParam('zipcode',search);
		}
		if ( GetParam('county',search) ) {
			if (OAS_query.length == 0)
				OAS_query = 'county=' + GetParam('county',search);
			else
				OAS_query = OAS_query + '&county=' + GetParam('county',search);
		}		
	}
//Make sure everything is lower case
OAS_query = OAS_query.toLowerCase();
//make sure query string doesn't have pluses or spaces
OAS_query = OAS_query.replace(/[\+]+/g, '-');
OAS_query = OAS_query.replace(/%20/g, '-');
OAS_query = OAS_query.replace(/[ ]+/g, '-');
OAS_query = OAS_query.replace(/[\']+/g, '');
//alert(OAS_query);
//OAS_query setup end
//End Configuration
OAS_version = 10;
OAS_rn = '00123456789';
OAS_rns = '00123456789';
OAS_rn = new String (Math.random());
OAS_rns = OAS_rn.substring (2, 11);
// this is the nonconforming version of the RealMedia call
function OAS_NORMAL(pos) {
	document.write('<a href="' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@'
		+ OAS_listpos + '!' + pos + '?' + OAS_query + '" TARGET=' + OAS_target + '>');
	document.write('<img src=""="' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@'
		+ OAS_listpos + '!' + pos + '?' + OAS_query + '" TARGET=' + '" border=0></a>');
}	
// Here we check for which navigator is used and show the tags accordingly
OAS_version = 11;
if (( navigator.userAgent.indexOf('Mozilla/3') != -1) || (navigator.userAgent.indexOf('Mozilla/4,0 WebTV') != -1))
	OAS_version = 10;
// This loads in the OAS_RICH function from ad server if the navigator is a standard one
if ( OAS_version >= 11 )
	document.write('<scr' + 'ipt language=JavaScript1.1 src="' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + 
	OAS_rns + '@' + OAS_listpos + '?' + OAS_query + '">' + OAS_target + '"></script>');
document.write('');
// Function called in code to display RealMedia - Must be cased exactly like it is in the position list
function OAS_AD(pos) {
	if ( OAS_version >= 11 )
		OAS_RICH(pos);
	else
		OAS_NORMAL(pos);
}
//-->
/* OAS SETUP end */

