/*
 * ForRent.com Site Javascript
 * @copyright (c) 2008 Forrent.com (Dominion Enterprises), All Rights Reserved
 * @author Kevin Strange <strange@forrent.com>
 * @version 1.0
 */

// Real Media Ad Code - Start
if(OAS_listpos!="0") {
	OAS_url='http://ads.traderonline.com/RealMedia/ads/';
	// OAS_sitepage, OAS_listpos, and OAS_query set in nav.templ - KTS
	OAS_target='_blank';
	// End configuration
	OAS_version=10;
	OAS_rn= new String (Math.random());
	OAS_rns=OAS_rn.substring (2, 11);
	function OAS_NORMAL(pos) {
		document.write('<a href="' + OAS_url + 'click_nx.cgi/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" target="' + OAS_target + '">');
		document.write('<img src="' + OAS_url + 'click_nx.cgi/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" border="0" /></a>');
	}
	OAS_version=11;
	if (( navigator.userAgent.indexOf('Mozilla/3') !=-1) || (navigator.userAgent.indexOf('Mozilla/4.0 WebTV') !=-1))
		OAS_version=10;
	if (OAS_version >=11)
		document.write('<scr' + 'ipt type="text/javascript" src="' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '?' + OAS_query + '"><\/script>');
	
	document.write('');
	function OAS_AD(pos) {
		if (OAS_version <=11)
			OAS_RICH(pos);
		else
			OAS_NORMAL(pos);
		}
}
// Real Media Ad Code - End

// Flash Check - Start
var MM_contentVersion=8;
var plugin=(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
	var words=navigator.plugins["Shockwave Flash"].description.split(" ");
	for (var i=0; i < words.length; ++i) {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion=words[i];
	}
	var MM_FlashCanPlay=MM_PluginVersion >=MM_contentVersion;
	FlashMode=0;
	if (navigator.plugins && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash"]) {
			var plugin_version=0;
			var words=navigator.plugins["Shockwave Flash"].description.split(" ");
			for (var i=0; i < words.length; ++i) {
				if (isNaN(parseInt(words[i])))
				continue;
				plugin_version=words[i];
			}
			if (plugin_version >=9) {
				var plugin=navigator.plugins["Shockwave Flash"];
				var numTypes=plugin.length;
				for (j=0; j < numTypes; j++) {
					mimetype=plugin[j];
					if (mimetype) {
						if (mimetype.enabledPlugin && (mimetype.suffixes.indexOf("swf") !=-1)) // Mac wierdness
						FlashMode=1;
						if (navigator.mimeTypes["application/x-shockwave-flash"]==null)
						FlashMode=0;
					}
				}
			}
		}
	}
	var MM_FlashCanPlay=(FlashMode==1) ? true : false
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") !=-1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay=( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}
// Flash Check - End

// Flash Map - Start
function searchMap(servDom) {
	var img_path = 'http://images.forrent.com/sites/frc/design/swf/';
	var which_swf = 'frc-map-1.swf';
	var flashParams = '?domain=' + servDom;
		document.write('<object type="application/x-shockwave-flash" data="' + img_path + which_swf + flashParams + '"  width="480" height="400"> ');
		document.write('<param name="movie" value="' + img_path + which_swf + flashParams + '" /><param name="menu" value="false" /><param name="wmode" value="transparent" /><param name="AllowScriptAccess" value="always" /><param name="embed" value="transparent" AllowScriptAccess="always" />');
		document.write('</object> ');
}
// Flash Map - End

/* Flash Video Player - Start - Compatability issues.. Need to revisit.
function flashVid() {
	var img_path = 'http://images.forrent.com/sites/frc/design/swf/';
	var which_swf = 'lightbox-player.swf';
	// var flashParams = ''; No extra params being passed in this function
		document.write('<object id="work" type="application/x-shockwave-flash" data="' + img_path + which_swf + '"  width="583" height="377" border="0"> ');
		document.write('<param name="movie" value="' + img_path + which_swf + '" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><param name="embed" value="transparent" /><param name="AllowScriptAccess" value="always" />');
		document.write('</object> ');
}
// Flash Video Player - End */

// Text Field Function - Start --- Clears the text field on focus, but puts the default value back if nothing is entered.
function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}
// Text Field Function - End
// jqModal error messaging
$(function() {
	// search suggestions lightbox
	$('.errorMessages').jqm({ 
		closeClass:'jqmCloseSoundsLike',
		modal:false,
		overlay: 71,
		onShow: function(hash){ 
			hash.w.show(); 
		}  
	});
	
	//click events for the returned results
	$('#soundsLikeMatches li').click(function() {
		$(':input[name="city_state"]').val($(this).text());
		$('#indexSubmit').trigger("click");
	});
   
	//show the modal as soon as the page loads
	$('.errorMessages').jqmShow();
	
    });
	
// Function for homepage field clearing.
$(function() { // When the document is ready...
    $('#cityState').keypress(function() { // When the city-state field changes...
        if (preFilledZip === true) {
            $('#zipCode').val(''); // Blank out the zip code's value
            preFilledZip = false; // Don't bother doing this again
        }
    });
    $('#zipCode').keypress(function() { // When the zip code field changes...
        if (preFilledCity === true) {
            $('#cityState').val(''); // Blank out the city-state's value
            preFilledCity = false; // Don't bother doing this again
        }
    });
});
