/**
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function(name, value, options)
{
	if (typeof value != 'undefined')
	{
		options = options || {};
		if (value === null)
		{
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString))
		{
			var date;
			if (typeof options.expires == 'number')
			{
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else
			{
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString();
		}
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else
	{ 
		var cookieValue = null;
		if (document.cookie && document.cookie != '')
		{
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++)
			{
				var cookie = jQuery.trim(cookies[i]);
				if (cookie.substring(0, name.length + 1) == (name + '='))
				{
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};/**
 * Copyright (c) 2005 - 2010, James Auldridge
 * All rights reserved.
 *
 * Licensed under the BSD, MIT, and GPL (your choice!) Licenses:
 *  http://code.google.com/p/cookies/wiki/License
 *
 */
var jaaulde = window.jaaulde || {};
jaaulde.utils = jaaulde.utils || {};
jaaulde.utils.cookies = ( function()
{
	var resolveOptions, assembleOptionsString, parseCookies, constructor, defaultOptions = {
		expiresAt: null,
		path: '/',
		domain:  null,
		secure: false
	};
	/**
	* resolveOptions - receive an options object and ensure all options are present and valid, replacing with defaults where necessary
	*
	* @access private
	* @static
	* @parameter Object options - optional options to start with
	* @return Object complete and valid options object
	*/
	resolveOptions = function( options )
	{
		var returnValue, expireDate;

		if( typeof options !== 'object' || options === null )
		{
			returnValue = defaultOptions;
		}
		else
		{
			returnValue = {
				expiresAt: defaultOptions.expiresAt,
				path: defaultOptions.path,
				domain: defaultOptions.domain,
				secure: defaultOptions.secure
			};

			if( typeof options.expiresAt === 'object' && options.expiresAt instanceof Date )
			{
				returnValue.expiresAt = options.expiresAt;
			}
			else if( typeof options.hoursToLive === 'number' && options.hoursToLive !== 0 )
			{
				expireDate = new Date();
				expireDate.setTime( expireDate.getTime() + ( options.hoursToLive * 60 * 60 * 1000 ) );
				returnValue.expiresAt = expireDate;
			}

			if( typeof options.path === 'string' && options.path !== '' )
			{
				returnValue.path = options.path;
			}

			if( typeof options.domain === 'string' && options.domain !== '' )
			{
				returnValue.domain = options.domain;
			}

			if( options.secure === true )
			{
				returnValue.secure = options.secure;
			}
		}

		return returnValue;
		};
	/**
	* assembleOptionsString - analyze options and assemble appropriate string for setting a cookie with those options
	*
	* @access private
	* @static
	* @parameter options OBJECT - optional options to start with
	* @return STRING - complete and valid cookie setting options
	*/
	assembleOptionsString = function( options )
	{
		options = resolveOptions( options );

		return (
			( typeof options.expiresAt === 'object' && options.expiresAt instanceof Date ? '; expires=' + options.expiresAt.toGMTString() : '' ) +
			'; path=' + options.path +
			( typeof options.domain === 'string' ? '; domain=' + options.domain : '' ) +
			( options.secure === true ? '; secure' : '' )
		);
	};
	/**
	* parseCookies - retrieve document.cookie string and break it into a hash with values decoded and unserialized
	*
	* @access private
	* @static
	* @return OBJECT - hash of cookies from document.cookie
	*/
	parseCookies = function()
	{
		var cookies = {}, i, pair, name, value, separated = document.cookie.split( ';' ), unparsedValue;
		for( i = 0; i < separated.length; i = i + 1 )
		{
			pair = separated[i].split( '=' );
			name = pair[0].replace( /^\s*/, '' ).replace( /\s*$/, '' );

			try
			{
				value = decodeURIComponent( pair[1] );
			}
			catch( e1 )
			{
				value = pair[1];
			}

			if(isNaN(Number(value)) && typeof JSON === 'object' && JSON !== null && typeof JSON.parse === 'function' )
			{
				try
				{
					unparsedValue = value;
					value = JSON.parse( value );
				}
				catch( e2 )
				{
					value = unparsedValue;
				}
			}

			cookies[name] = value;
		}
		return cookies;
	};

	constructor = function(){};

	/**
	 * get - get one, several, or all cookies
	 *
	 * @access public
	 * @paramater Mixed cookieName - String:name of single cookie; Array:list of multiple cookie names; Void (no param):if you want all cookies
	 * @return Mixed - Value of cookie as set; Null:if only one cookie is requested and is not found; Object:hash of multiple or all cookies (if multiple or all requested);
	 */
	constructor.prototype.get = function( cookieName )
	{
		var returnValue, item, cookies = parseCookies();

		if( typeof cookieName === 'string' )
		{
			returnValue = ( typeof cookies[cookieName] !== 'undefined' ) ? cookies[cookieName] : null;
		}
		else if( typeof cookieName === 'object' && cookieName !== null )
		{
			returnValue = {};
			for( item in cookieName )
			{
				if( typeof cookies[cookieName[item]] !== 'undefined' )
				{
					returnValue[cookieName[item]] = cookies[cookieName[item]];
				}
				else
				{
					returnValue[cookieName[item]] = null;
				}
			}
		}
		else
		{
			returnValue = cookies;
		}

		return returnValue;
	};
	/**
	 * filter - get array of cookies whose names match the provided RegExp
	 *
	 * @access public
	 * @paramater Object RegExp - The regular expression to match against cookie names
	 * @return Mixed - Object:hash of cookies whose names match the RegExp
	 */
	constructor.prototype.filter = function( cookieNameRegExp )
	{
		var cookieName, returnValue = {}, cookies = parseCookies();

		if( typeof cookieNameRegExp === 'string' )
		{
			cookieNameRegExp = new RegExp( cookieNameRegExp );
		}

		for( cookieName in cookies )
		{
			if( cookieName.match( cookieNameRegExp ) )
			{
				returnValue[cookieName] = cookies[cookieName];
			}
		}

		return returnValue;
	};
	/**
	 * set - set or delete a cookie with desired options
	 *
	 * @access public
	 * @paramater String cookieName - name of cookie to set
	 * @paramater Mixed value - Any JS value. If not a string, will be JSON encoded; NULL to delete
	 * @paramater Object options - optional list of cookie options to specify
	 * @return void
	 */
	constructor.prototype.set = function( cookieName, value, options )
	{
		if( typeof options !== 'object' || options === null )
		{
			options = {};
		}

		if( typeof value === 'undefined' || value === null )
		{
			value = '';
			options.hoursToLive = -8760;
		}

		else if( typeof value !== 'string' )
		{
			if( typeof JSON === 'object' && JSON !== null && typeof JSON.stringify === 'function' )
			{
				value = JSON.stringify( value );
			}
			else
			{
				throw new Error( 'cookies.set() received non-string value and could not serialize.' );
			}
		}


		var optionsString = assembleOptionsString( options );

		document.cookie = cookieName + '=' + encodeURIComponent( value ) + optionsString;
	};
	/**
	 * del - delete a cookie (domain and path options must match those with which the cookie was set; this is really an alias for set() with parameters simplified for this use)
	 *
	 * @access public
	 * @paramater MIxed cookieName - String name of cookie to delete, or Bool true to delete all
	 * @paramater Object options - optional list of cookie options to specify ( path, domain )
	 * @return void
	 */
	constructor.prototype.del = function( cookieName, options )
	{
		var allCookies = {}, name;

		if( typeof options !== 'object' || options === null )
		{
			options = {};
		}

		if( typeof cookieName === 'boolean' && cookieName === true )
		{
			allCookies = this.get();
		}
		else if( typeof cookieName === 'string' )
		{
			allCookies[cookieName] = true;
		}

		for( name in allCookies )
		{
			if( typeof name === 'string' && name !== '' )
			{
				this.set( name, null, options );
			}
		}
	};
	/**
	 * test - test whether the browser is accepting cookies
	 *
	 * @access public
	 * @return Boolean
	 */
	constructor.prototype.test = function()
	{
		var returnValue = false, testName = 'cT', testValue = 'data';

		this.set( testName, testValue );

		if( this.get( testName ) === testValue )
		{
			this.del( testName );
			returnValue = true;
		}

		return returnValue;
	};
	/**
	 * setOptions - set default options for calls to cookie methods
	 *
	 * @access public
	 * @param Object options - list of cookie options to specify
	 * @return void
	 */
	constructor.prototype.setOptions = function( options )
	{
		if( typeof options !== 'object' )
		{
			options = null;
		}

		defaultOptions = resolveOptions( options );
	};

	return new constructor();
} )();

( function()
{
	if( window.jQuery )
	{
		( function( $ )
		{
			$.cookies = jaaulde.utils.cookies;

			var extensions = {
				/**
				* $( 'selector' ).cookify - set the value of an input field, or the innerHTML of an element, to a cookie by the name or id of the field or element
				*                           (field or element MUST have name or id attribute)
				*
				* @access public
				* @param options OBJECT - list of cookie options to specify
				* @return jQuery
				*/
				cookify: function( options )
				{
					return this.each( function()
					{
						var i, nameAttrs = ['name', 'id'], name, $this = $( this ), value;

						for( i in nameAttrs )
						{
							if( ! isNaN( i ) )
							{
								name = $this.attr( nameAttrs[ i ] );
								if( typeof name === 'string' && name !== '' )
								{
									if( $this.is( ':checkbox, :radio' ) )
									{
										if( $this.attr( 'checked' ) )
										{
											value = $this.val();
										}
									}
									else if( $this.is( ':input' ) )
									{
										value = $this.val();
									}
									else
									{
										value = $this.html();
									}

									if( typeof value !== 'string' || value === '' )
									{
										value = null;
									}

									$.cookies.set( name, value, options );

									break;
								}
							}
						}
					} );
				},
				/**
				* $( 'selector' ).cookieFill - set the value of an input field or the innerHTML of an element from a cookie by the name or id of the field or element
				*
				* @access public
				* @return jQuery
				*/
				cookieFill: function()
				{
					return this.each( function()
					{
						var n, getN, nameAttrs = ['name', 'id'], name, $this = $( this ), value;

						getN = function()
						{
							n = nameAttrs.pop();
							return !! n;
						};

						while( getN() )
						{
							name = $this.attr( n );
							if( typeof name === 'string' && name !== '' )
							{
								value = $.cookies.get( name );
								if( value !== null )
								{
									if( $this.is( ':checkbox, :radio' ) )
									{
										if( $this.val() === value )
										{
											$this.attr( 'checked', 'checked' );
										}
										else
										{
											$this.removeAttr( 'checked' );
										}
									}
									else if( $this.is( ':input' ) )
									{
										$this.val( value );
									}
									else
									{
										$this.html( value );
									}
								}
								
								break;
							}
						}
					} );
				},
				/**
				* $( 'selector' ).cookieBind - call cookie fill on matching elements, and bind their change events to cookify()
				*
				* @access public
				* @param options OBJECT - list of cookie options to specify
				* @return jQuery
				*/
				cookieBind: function( options )
				{
					return this.each( function()
					{
						var $this = $( this );
						$this.cookieFill().change( function()
						{
							$this.cookify( options );
						} );
					} );
				}
			};

			$.each( extensions, function( i )
			{
				$.fn[i] = this;
			} );

		} )( window.jQuery );
	}
} )();if(typeof ($) == 'undefined') alert('Vehix.Web.Ads.js requires the jquery framework');
if(typeof (Vehix) == 'undefined') Vehix = new Object();
if(typeof (Vehix.Web) == 'undefined') Vehix.Web = new Object();
Vehix.Web.Ads = function(url)
{
	this.items = new Array();
	this.parameters = new Array();
	this.parameters.set = this.__set_parameter;
	this.parameters.get = this.__get_parameter;
	this.url = url;
	this._disableAdvertisingKey = 'DisableAdvertising';
}
Vehix.Web.Ads.prototype=
{
	__get_parameter: function(name)
	{
		var result='';
		if (typeof name == "string")
		{
			for(var index=0;index<this.length;index++)
			{
				if(this[index].name.toLowerCase()==name.toLowerCase())
				{
					result=this[index].value;
					break;
				}
			}
		}
		return result;
	},
	__set_parameter: function(name,value)
	{
		if (typeof name == "string" && name.length > 0)
		{
			var exists=false;
			for(var index=0;index<this.length;index++)
			{
				if(exists=(this[index].name.toLowerCase()==name.toLowerCase()))
				{
					this[index].value=value;
					break;
				}
			}
			if(!exists)
			{
				var normalizedName = name.charAt(0).toUpperCase() + name.slice(1);
				this.push({ name: normalizedName, value: value });
			}
		}
	},
	get_disabled: function()
	{
		var result=window.location.search.match(this._disableAdvertisingKey+'=true');
		if(result)
		{
			$.cookie(this._disableAdvertisingKey,'true');
		}
		else
		{
			result=($.cookie(this._disableAdvertisingKey)=='true');
		}
		return result;
	},
	rotate: function(rotationGroup)
	{
		if(!this.get_disabled())
		{
			var url=this.url+'?'
			for(var index=0;index<this.items.length;index++)
			{
				var element=this.items[index];
				if(rotationGroup=='*'||element.rotationGroup==rotationGroup)
				{
					var width=$(element).width();
					var height=$(element).height();
					var param='&parameters=';
					for(var parameterIndex=0;parameterIndex<this.parameters.length;parameterIndex++)
					{
						var parameter=this.parameters[parameterIndex];
						param+=encodeURIComponent(parameter.name+'='+parameter.value+',');
					}
					for(var parameterIndex=0;parameterIndex<element.parameters.length;parameterIndex++)
					{
						var parameter=element.parameters[parameterIndex];
						param+=encodeURIComponent(parameter.name+'='+parameter.value)+',';
						if(parameter.name=="Width")
						{
							width=parameter.value;
						}
						if(parameter.name=="Height")
						{
							height=parameter.value;
						}
					}
					var src=url+'resourceID='+element.resourceID+'&width='+width+'&height='+height;
					src+=param;
					element.innerHTML='';
					element.innerHTML='<iframe src="'+src+'" width="'+width+'" height="'+height+'" frameborder="0" scrolling="no"></iframe>'
				}
			}
		}
	},
	create: function(id,resourceID,rotationGroup)
	{
		var advertisement=document.createElement("div");
		advertisement.className=id;
		advertisement.resourceID=resourceID;
		advertisement.rotationGroup=rotationGroup;
		advertisement.parameters=new Array();
		advertisement.parameters.set=this.__set_parameter;
		advertisement.parameters.get=this.__get_parameter;
		advertisement.parameters.push({ name: 'Tile',value: Vehix.Web.Ads.items.length });
		this.items.push(advertisement);
		var scpid=id;
		var scpad=advertisement;
		$(document).ready(function()
		{
			$("#"+scpid).replaceWith(scpad);
		});
		return advertisement;
	},
	getShowcaseAdScriptTag: function(location,condition,make,model,bodyStyle)
	{
		/// <summary>Writes out a showcase ad - delivered via OAS JX Tag.</summary>
		if(typeof location=='undefined'||location==null||location=='')
			throw "location is required.";
		if(typeof OAS_url=='undefined')
			OAS_url='http://oascentral.vehix.com';
		if(typeof OAS_pos=='undefined')
			OAS_pos='Top';
		if(typeof OAS_query=='undefined')
		{
			OAS_query=''
			// Prefer ad parameters over function arguments.
			if(typeof gvhxAds!='undefined'&&gvhxAds!=null&&gvhxAds.length>0&&document.getElementById(gvhxAds[0])!='undefined')
			{
				var parameters=document.getElementById(gvhxAds[0]).parameters;
				for(var index=0;index<parameters.length;index++)
				{
					var param=parameters[index];
					if(param.name=='Segment')
						condition=param.value;
					if(param.name=='Make')
						make=param.value;
					if(param.name=='Model')
						model=param.value;
					if(param.name=='BodyStyle')
						bodyStyle=param.value;
				}
			}
			else
			{
				try
				{
					condition=Vehix.Web.Ads.parameters.get('segment');
					make=Vehix.Web.Ads.parameters.get('make');
					model=Vehix.Web.Ads.parameters.get('model');
					bodyStyle=Vehix.Web.Ads.parameters.get('bodystyle');
				}
				catch(e) { }
			}

			// convert undefined to default values.
			if(typeof condition=='undefined' || condition == null) condition="new";
			if(typeof make=='undefined') make=null;
			if(typeof model=='undefined') model=null;
			if(typeof bodyStyle=='undefined') bodyStyle=null;

			// remove spaces
			if(condition!=null) condition=condition.replace(' ','');
			if(make!=null) make=make.replace(' ','');
			if(model!=null) model=model.replace(' ','');
			if(bodyStyle!=null) bodyStyle=bodyStyle.replace(' ','');

			var query='condition='+encodeURIComponent(condition).toLowerCase()
				+'&make='+encodeURIComponent(make).toLowerCase()
				+'&model='+encodeURIComponent(model).toLowerCase()
				+'&type='+encodeURIComponent(bodyStyle).toLowerCase();
			OAS_query+=query.replace(/%20/g,'+');
		}
		if(typeof OAS_sitepage=='undefined')
			OAS_sitepage='showcase.vehix.com/'+encodeURIComponent(location);
		if(typeof OAS_RN=='undefined')
			OAS_RN=new String(Math.random());
		if(typeof OAS_RNS=='undefined')
			OAS_RNS=OAS_RN.substring(2,11);
		return '<scr'+'ipt type="text/javascript" src="'+OAS_url+'/RealMedia/ads/adstream_jx.ads/'+OAS_sitepage+'/1'+OAS_RNS+'@'+OAS_pos+'?'+OAS_query+'"></scr'+'ipt>';
	},
	resizeRightPanel: function(num)
	{
		if(num==160)
		{
			$(".right-panel").css("width","162px");
			$(".right-panel .relatedInventoryFragmentSkyScraper").css("width","160px");
			$(".ad160x600").css("width","160px").css("margin-left","1px");
			$(".ad160x600 iframe").attr("width","160");
			$(".page .content .left-panel").addClass("wide");
		}
		else if(num==300)
		{
			$(".right-panel").css("width","300px");
			$(".right-panel .relatedInventoryFragmentSkyScraper").css("width","298px");
			$(".ad160x600").css("width","300px").css("margin-left","0");
			$(".ad160x600 iframe").attr("width","300");
			$(".page .content .left-panel").removeClass("wide");
		}
		if (typeof this.resizeEvent != "undefined" && this.resizeEvent != null) {
			$("body").trigger(this.resizeEvent);
		}
	},
	checkExternalAd: function()
	{
		$(".ad160x600").data("fitcontentcount",0);
		$(".ad160x600").bind("fitcontent",function(event)
		{
			if($(this).data("fitcontentcount")>5)
				clearInterval($(this).data("fitcntInt"));
			else
			{
				$(this).children().each(function(index)
				{
					if($(this)[0].tagName!="IFRAME")
					{
						var wdth=$(this).width();
						if(wdth>0&&wdth==160||wdth==300)
						{
							Vehix.Web.Ads.resizeRightPanel(wdth);
							$(this).data("fitcontentcount",9);
						}
					}
				});
				$(this).data("fitcontentcount",$(this).data("fitcontentcount")+1);
			}
		});
		$(".ad160x600").data("fitcntInt",setInterval(function()
		{
			$(".ad160x600").trigger("fitcontent");
		}),600);
	}
}
Vehix.Web.Ads = new Vehix.Web.Ads('http://www.vehix.com/tagFrame.aspx');jQuery.fn.isControlKey = function(keyCode) {
	return keyCode == 8  // backspace
		|| keyCode == 9  // tab
		|| keyCode == 16 // shift
		|| keyCode == 37 // left arrow
		|| keyCode == 38 // up arrow
		|| keyCode == 39 // right arrow
		|| keyCode == 40 // down arrow
		|| keyCode == 46 // delete
}

jQuery.fn.unsignedInteger = function() {
	return this.keydown(function(data) {
		var keyCode = data.keyCode;
		return jQuery.fn.isControlKey(keyCode) || (48 <= keyCode && keyCode <= 57) || (96 <= keyCode && keyCode <= 105);
	});
};

jQuery.fn.signedInteger = function() {
	return this.keydown(function(data) {
		var keyCode = data.keyCode;
		return jQuery.fn.isControlKey(keyCode)
			|| keyCode == 109 // minus
			|| keyCode == 190 // period
			|| (48 <= keyCode && keyCode <= 57) // numeric
			|| (96 <= keyCode && keyCode <= 105); // ten-key
	});
};

jQuery.fn.unsignedFloat = function() {
	return this.keydown(function(data) {
		var keyCode = data.keyCode;
		return jQuery.fn.isControlKey(keyCode) || (48 <= keyCode && keyCode <= 57) || (96 <= keyCode && keyCode <= 105);
	});
};

jQuery.fn.signedFloat = function() {
	return this.keydown(function(data) {
		var keyCode = data.keyCode;
		return jQuery.fn.isControlKey(keyCode)
			|| keyCode == 109 // minus
			|| keyCode == 190 // period
			|| (48 <= keyCode && keyCode <= 57) // numeric
			|| (96 <= keyCode && keyCode <= 105); // ten-key
	});
};

jQuery.fn.autoTab = function(count, target) {
	return this.keyup(function(data) {
		if (data.currentTarget.value.length == count && !jQuery.fn.isControlKey(data.keyCode)) {
			$(target).focus();
		}
	});
};

if(typeof ($)=='undefined') alert('Vehix.Web.Ads.js requires the jquery framework');
function DM_prepClient(csid,client)
{
	if(csid=='H05525')
	{
		try
		{
			client.DM_addEncToLoc('sid',(Vehix.Web.Ads.parameters.get('Brand')!=null)?Vehix.Web.Ads.parameters.get('Brand'):'');
			client.DM_addEncToLoc('type',(Vehix.Web.Ads.parameters.get('BodyStyle')!=null)?Vehix.Web.Ads.parameters.get('BodyStyle'):'');
			client.DM_addEncToLoc('make',(Vehix.Web.Ads.parameters.get('Make')!=null)?Vehix.Web.Ads.parameters.get('Make'):'');
			client.DM_addEncToLoc('model',(Vehix.Web.Ads.parameters.get('Model')!=null)?Vehix.Web.Ads.parameters.get('Model'):'');
			client.DM_addEncToLoc('year',(Vehix.Web.Ads.parameters.get('Year')!=null)?Vehix.Web.Ads.parameters.get('Year'):'');
			client.DM_addEncToLoc('section',(Vehix.Web.Ads.parameters.get('Section')!=null)?Vehix.Web.Ads.parameters.get('Section'):'');
			client.DM_addEncToLoc('content',Vehix.Web.Ads.parameters.get('Content').length>0?Vehix.Web.Ads.parameters.get('Content'):Vehix.Web.Ads.parameters.get('Z1'));
			$.cookie('jag_rsi_segs',escape(rsinetsegs.slice(0,20).join('|')),{ domain: 'vehix.com',path: '/' });
		}
		catch(err) { }
	}
}
var s_account='vehixglobal'
var s_accountalt='vehixglobal'

