function goto_URL_drop_down(object)
{
	if(object != null)
	{
		var urlToGoTo = object.options[object.selectedIndex].value;
		if(urlToGoTo != "")
		{
			window.location.href = urlToGoTo;
		}
		else
		{
			object.options[0].selected = true;
		}
	}
}

function OnDropDownChange( dropdownId, hiddenId)
{
    var dd = document.getElementById(dropdownId);
    var hd = document.getElementById(hiddenId);
    hd.value = dd.value;
}

function Switch(objectId, linkId)
{
    var object = document.getElementById(objectId);
    if (object != null)
    {        	    
        var link = document.getElementById( linkId);
        var status = object.style.display;
		if( status == '' || status == 'block')
		{
			object.style.display = 'none';
			
			if (link != null)			
			    link.innerHTML = "CHANGE VEHICLE";			    
	    }
		else
		{
			object.style.display = 'block';
			
			if (link != null)
			    link.innerHTML = "CLOSE";
	    }	    
    }
}

function SwitchView( objectId, imageId, linkId)
{
	var image = document.getElementById( imageId);
	if( image != null)
		SwitchImage( image);
		
	var link = document.getElementById( linkId);
	if( link != null)
		SwitchLink( link);
		
	var object = document.getElementById(objectId);
	if( object != null)
	{
		var status = object.style.display;
		if( status == '' || status == 'block')
			object.style.display = 'none';
		else
			object.style.display = 'block';
	}
}

function SwitchObjectViews( openObjectId, closedObjectId, imageId, linkId)
{
	var image = document.getElementById( imageId);
	if( image != null)
		SwitchImage( image);
		
	var link = document.getElementById( linkId);
	if( link != null)
		SwitchLink( link);
				
	var openObject = document.getElementById(openObjectId);
	if( openObject != null)
	{
		var status = openObject.style.display;
		if( status == '' || status == 'block')
			openObject.style.display = 'none';
		else
			openObject.style.display = 'block';
	}
	
	var closedObject = document.getElementById(closedObjectId);
	if( closedObject != null)
	{
		var status = closedObject.style.display;
		if( status == '' || status == 'block')
			closedObject.style.display = 'none';
		else
			closedObject.style.display = 'block';
	}
}
function SwitchTextDisplay(showObjectId, strOpenText,strHideText)
{	
				
	var openObject = document.getElementById(showObjectId);
	if( openObject != null)
	{
		var status = openObject.innerHTML;

		if( status == '' || status == strOpenText)
		{
			openObject.innerHTML= strHideText;			
		}
		else
		{
			openObject.innerHTML= strOpenText;
		}
	}

}

function SwitchTexts(partialTextId, partialTextDotId, hiddenTextId, switchLinkId)
{
    var partialText = $('#' + partialTextId);
    var partialTextDot = $('#' + partialTextDotId);
    var hiddenText = $('#' + hiddenTextId);
    var switchLink = $('#' + switchLinkId);

    // checking if visible returns expected results more so than checking for hidden
    if (partialText.is(":visible")) {
        hiddenText.show();
        partialText.hide();
        partialTextDot.hide();
        switchLink.html('hide');
    }
    else {
        hiddenText.hide();
        partialText.show();
        partialTextDot.show();
        switchLink.html('read more');
    }    
}

function SwitchRowView( rowId, imgId, linkId)
{
	var img = document.getElementById( imgId);
	if( img != null)
		SwitchImage( img);
		
	var link = document.getElementById( linkId);
	if( link != null)
		SwitchLink( link);
	
	//alert(rowId);	
	for( var i = 1; i < 200; i++)
	{	    
		var currRow = document.getElementById(rowId + i);
		if( currRow != null)
		{
			var status = currRow.style.display;
			if( status == '')
				currRow.style.display = 'none';
			else
				currRow.style.display = '';
		}
		else i = 200;
	}
}

function ShowHidePricing(trimID,hideFlag)
{    
    for(var i=0; i<25;i++)
    {
        if(trimArray != null)
        {
            var currRow = document.getElementById('div' + trimArray[i]);                    
		    if(currRow != null)
		    {		        
			    currRow.style.display = 'none';						
		    }
		    else
		        break;
		        
		    currRow = document.getElementById('divRight' + trimArray[i]);                    
		    if(currRow != null)
		    {		        
			    currRow.style.display = 'none';						
		    }		    
		}
    }
    var currRow1 = document.getElementById('div' + trimID);       
    if(currRow1 != null) 
        currRow1.style.display = '';
    currRow1 = document.getElementById('divRight' + trimID);       
    if(currRow1 != null) 
        currRow1.style.display = '';
}

function ShowHideTrimPricing(trimID, clientid, msrpid)
{
    var currRow1 = document.getElementById('div' + trimID);
    var msrpclientid = document.getElementById(msrpid);
        
    if(currRow1 != null)
    {
        var link = document.getElementById(clientid);
        var app = navigator.appName.substring(0,1);
        
        if(currRow1.style.display == '')
        {   
            if(app == 'M')            
                link.innerText = "Select Options";
            else
                link.firstChild.nodeValue="Select Options";
             
            if(msrpclientid != null)
            {   
                var msrp = document.getElementById('ctl00_ctl12_ctl00_rptTrimDisplay_ctl00_PricingNew_lblTotalMSRP2');
                if(msrp != null)
                {                
                    msrpclientid.innerHTML = msrp.innerHTML;
                }                
            }
                
            currRow1.style.display = 'none';
        }
        else
        {
            if(app == 'M')            
                link.innerText = "Hide Options";
            else
                link.firstChild.nodeValue="Hide Options";            
            currRow1.style.display = '';
        }
    }
}



function SwitchAllRowView(rowsAreOpen, tableId, switchAllLink, imagePrefix)
{
    rowsAreOpen = !rowsAreOpen;
	
    var rows = document.getElementById( tableId).getElementsByTagName( 'tr');
    for( var i = 0; i < rows.length; i++)
    {
	    var tableRow = rows.item( i);
	    if( tableRow != null && tableRow.id.indexOf( 'Row') >= 0 && rowsAreOpen)
		    tableRow.style.display = '';
	    else if( tableRow != null && tableRow.id.indexOf( 'Row') >= 0)
		    tableRow.style.display = 'none';
    }
    
    var rows = document.getElementById( tableId).getElementsByTagName( 'div');
    for( var i = 0; i < rows.length; i++)
    {
	    var tableRow = rows.item( i);
	    if( tableRow != null && tableRow.id.indexOf( 'Row') >= 0 && rowsAreOpen)
		    tableRow.style.display = '';
	    else if( tableRow != null && tableRow.id.indexOf( 'Row') >= 0)
		    tableRow.style.display = 'none';
    }
	
    var images = document.getElementById( tableId).getElementsByTagName( 'img');
    for( var i = 0; i < images.length; i++)
    {        
	    var currImage = images.item( i);
	    if( currImage != null && currImage.id.indexOf( 'Img') >= 0 && rowsAreOpen)
		    currImage.src = imagePrefix + 'section_opened.gif';
	    else if( currImage != null && currImage.id.indexOf( 'Img') >= 0)
		    currImage.src = imagePrefix + 'section_closed.gif';
    }
	
    var links = document.getElementById( tableId).getElementsByTagName( 'a');
    for( var i = 0; i < links.length; i++)
    {
	    var currLink = links.item( i);
	    if( currLink != null && currLink.id.indexOf( 'Link') >= 0 && rowsAreOpen)
		    currLink.innerHTML = 'Hide';
	    else if( currLink != null && currLink.id.indexOf( 'Link') >= 0)
		    currLink.innerHTML = 'View';
    }
    
    if( rowsAreOpen)
	    document.getElementById( switchAllLink).innerHTML = 'Collapse All';
    else
	    document.getElementById( switchAllLink).innerHTML = 'Expand All';
}

function SwitchAllTBodyView(tableId, labelID)
{   
	var txtLink = document.getElementById(labelID).innerHTML;
	
    var tBody = document.getElementById(tableId).getElementsByTagName('tbody');
    for(var i = 0; i < tBody.length; i++)
    {
        var tableBody = tBody[i].id;        
        if ((tableBody != null) && (tableBody.indexOf('TBodySection') >= 0)) 
	    {
	        //alert(tableBody);
            if (txtLink == 'Expand All')
            {
                document.getElementById(tableBody).style.display = '';
                document.getElementById(tableBody).style.opacity = 0.99;
                document.getElementById(labelID).innerHTML = 'Collapse All';                
            }	    
            else
            {
                document.getElementById(tableBody).style.display = 'none';
                document.getElementById(labelID).innerHTML = 'Expand All';                
            }
	    }		    
    }
    
    var mozilla = document.getElementById&&!document.all;

    var images = document.getElementById(tableId).getElementsByTagName('img');
    var alternative = true;
    
    for( var i = 0; i < images.length; i++)
    {           
	    var currImage = images.item(i);	    	    
	    if(currImage != null && currImage.src.indexOf('section_') >= 0)
	    {
	        var n = mozilla ? currImage.parentNode.parentNode.id : currImage.parentElement.parentElement.id;	        
	        
	        if (txtLink == 'Expand All')
	        {
	            if (alternative)
	            {
	                document.getElementById(n).style.display = '';
	                document.getElementById(n).style.opacity = 0.99;
	                alternative = false;
	            }
	            else
	            {
	                document.getElementById(n).style.display = 'none';
	                alternative = true;
	            }	            
	        }
	        else
	        {	     
	            if (alternative)
	            {
	                document.getElementById(n).style.display = 'none';
	                alternative = false;
	            }
	            else
	            {
	                document.getElementById(n).style.display = '';
	                document.getElementById(n).style.opacity = 0.99;
	                alternative = true;
	            }	   
		        //currImage.src = currImage.src.replace('opened', 'closed');
		    }
		}
    }
    return;
}

function ShowHideRows(linkId,tableId,collapseText,collapseStyle,expandStyle)
{   
    var close = false;
    if(document.getElementById(linkId).innerHTML == "-")
        close = true;
   
    var rows = document.getElementById(tableId).getElementsByTagName('tr');    
    for(var i = 0; i < rows.length; i++)
    {
        if(i == 0)
        {
             var headers = document.getElementById(tableId).getElementsByTagName('th'); 
             headers[0].className = (close==true)?collapseStyle:expandStyle;
                
             for(var j=1; j<headers.length;j++)      
             {
                headers[j].style.display = (close==true)?'none':'';             
             }       
        }
        else        
        {
            rows[i].style.display = (close==true)?'none':'';        
            rows[i].style.height = (close==true)?'0px':'auto';        
        }
    }
    
    if(close)
        document.getElementById(linkId).innerHTML = '+ ' + collapseText;
    else
        document.getElementById(linkId).innerHTML = '-';            
}

function SwitchImage( image)
{
	if( image.src != null)
	{
		if( image.src.indexOf('opened') >= 0)
	        image.src = image.src.replace('opened', 'closed');
	    else if( image.src.indexOf('closed') >= 0)
	        image.src = image.src.replace('closed', 'opened');
	}	
}

function SwitchLink( link)
{
	if( link.innerHTML != null)
	{
		if( link.innerHTML.indexOf( 'Hide') >= 0)
	        link.innerHTML = link.innerHTML.replace('Hide', 'View');
	    else if( link.innerHTML.indexOf( 'View') >= 0)
	        link.innerHTML = link.innerHTML.replace('View', 'Hide');
	}	
}

function IsFlashInstalled(requiredVersion)
{
    var maxVersion = 9;
    var actualVersion = 0;

    if( navigator.plugins && navigator.plugins.length)
    {
        if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"])
        {
            var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; 
            var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description; 
            if(parseInt(flashDescription.substring(16)) >= requiredVersion)
                return true;
        }
    }
    else
    {
        flashObj = false;
        for(var i = 2; i <= maxVersion; i++)
        {
            execScript('on error resume next: flashObj = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + i + '"))','VBScript');
            if(flashObj == true && i >= requiredVersion) 
                return true;
        }
    }

    if(navigator.userAgent.indexOf("WebTV") != -1 && 4 >= requiredVersion)
        return true;
    
    return false;
}

function IsQTInstalled()
{
	var qtInstalled = false;
	qtObj = false;
	
	if( navigator.plugins && navigator.plugins.length)
	{
        for( var i = 0; i < navigator.plugins.length; i++ )
        {
            var plugin = navigator.plugins[i];
            if( plugin.name.indexOf("QuickTime") > -1)
                qtInstalled = true;
        }
	}
	else
	{
		execScript('on error resume next: qtObj = IsObject(CreateObject("QuickTimeCheckObject.QuickTimeCheck.1"))','VBScript');	
		qtInstalled = qtObj;
	}
	return qtInstalled;
}

var intCurrPage = -1;

function NextPage(strTableId, intNumPages, intNumVehiclesPerPage, intNumStaticColumns)
{
    if( intCurrPage >= intNumPages) return;
    intCurrPage++;
    var intStartIndex = intNumVehiclesPerPage*intCurrPage + intNumStaticColumns;
    var intEndIndex = intNumVehiclesPerPage*intCurrPage + (intNumStaticColumns-1) + intNumVehiclesPerPage;
        	
    var main_table = document.getElementById( strTableId);
    var main_table_elements = main_table.getElementsByTagName( 'tr');
    for( var i = 0; i < main_table_elements.length; i++)
    {
	    var main_table_cells = main_table_elements[i].getElementsByTagName( 'td');
	    for( var j = intNumStaticColumns; j < main_table_cells.length; j++)
	    {
		    if( j < intStartIndex || j > intEndIndex) main_table_cells[j].style.display = 'none';
		    else main_table_cells[j].style.display = '';
	    }
    }
	
    if( intCurrPage > 0) document.getElementById( 'prev').style.display = '';
    if( intCurrPage >= intNumPages) document.getElementById( 'next').style.display = 'none';
}

function PrevPage(strTableId, intNumVehiclesPerPage, intNumStaticColumns)
{
    if( intCurrPage <= 0) return;
    intCurrPage--;
    var intStartIndex = intNumVehiclesPerPage*intCurrPage + intNumStaticColumns;
    var intEndIndex = intNumVehiclesPerPage*intCurrPage + (intNumStaticColumns-1) + intNumVehiclesPerPage;
	
    var main_table = document.getElementById( strTableId);
    var main_table_elements = main_table.getElementsByTagName( 'tr');
    for( var i = 0; i < main_table_elements.length; i++)
    {
	    var main_table_cells = main_table_elements[i].getElementsByTagName( 'td');
	    for( var j = intNumStaticColumns; j < main_table_cells.length; j++)
	    {
		    if( j < intStartIndex || j > intEndIndex) main_table_cells[j].style.display = 'none';
		    else main_table_cells[j].style.display = '';
	    }
    }
	
    document.getElementById( 'next').style.display = '';
    if( intCurrPage <= 0) document.getElementById( 'prev').style.display = 'none';
}

function Popup(url, width, height)
{
	InfoWindow = window.open(url,"PopupWindow","fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=" + width + ",height=" + height + ",left=200,top=200");
	if(window.focus) 
	{
		InfoWindow.focus() 
	}
}
function Popup_Center(url, width, height)
{

	var left = (screen.availWidth/2) - (width/2);
	var top = (screen.availHeight/2) - (height/2);


	InfoWindow = window.open(url,"PopupWindow","fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);	
	if(window.focus) 
	{
		InfoWindow.focus() 
	}
}

function Popup_Open_Redirect_Full (url, redirectUrl)
{
	window.location.href = redirectUrl;
	InfoWindow = window.open(url,"PopupWindow","resizable=yes,fullscreen=no,scrollbars=yes,width=1000,height=600,left=200,top=200");
	if( InfoWindow != null) 
		InfoWindow.blur();
	self.focus();	
}

function Popup_WindowName(url, window_name, width, height)
{
	InfoWindow = window.open(url,window_name,"fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=" + width + ",height=" + height + ",left=200,top=200");
	if(window.focus) 
	{
		InfoWindow.focus() 
	}
}

//********************************************************
//********************Forum Utils*************************
//********************************************************
function resizeAvatars(width, height)
{
    var images = document.getElementsByTagName( 'img');
	if( images != null)
	{ 
		for( var i = 0; i < images.length; i++)
		{
			if( images[i].className == 'forums_thread_user_avatar')
				ResizeAvatar( images[i] );
				
		    if( images[i].name == 'avatarImage')
		    {	
		        ResizeAvatar( images[i] );
		    }
				
			if( images[i].name == 'signatureImage')
				ResizeSignature( images[i] );
		}
	}
}
function resize( width, height)
{
	var images = document.getElementsByTagName( 'img');
	if( images != null)
	{ 
		for( var i = 0; i < images.length; i++)
		{
			if( images[i].className == 'forums_thread_user_avatar')
				ResizeAvatar( images[i] );
				
		    if( images[i].name == 'avatarImage')
		    {	
		        ResizeAvatar( images[i] );
		    }
				
			if( images[i].name == 'signatureImage')
				ResizeSignature( images[i] );
		}
	}
}

function ResizeAvatar( avatar)
{
	ResizeAvatarCustom( avatar, 100, 67);
}

function ResizeAvatarCustom( avatar, width, height)
{
	// alert('w:' + width + ', h:' + height + ', avatar w:' + avatar.width + ', avatar h:' + avatar.height);
	var widthRatio = avatar.width / width;
	var heightRatio = avatar.height / height;
	if( heightRatio > widthRatio && avatar.height > height)
	{
		avatar.width = avatar.width / (avatar.height/height);
		avatar.height = height;
	}
	else if( avatar.width > width)
	{
		avatar.height = avatar.height / (avatar.width/width);
		avatar.width = width;
	}
	
	avatar.style.visibility = "visible";
}

function ResizeSignature( oSignatureImage )
{
	width = 300;
	height = 100;
	
	// alert('w:' + width + ', h:' + height + ', Signature w:' + oSignatureImage.width + ', Signature h:' + oSignatureImage.height);
	
	var widthRatio = oSignatureImage.width / width;
	var heightRatio = oSignatureImage.height / height;
	if( heightRatio > widthRatio && oSignatureImage.height > height)
	{
		oSignatureImage.width = oSignatureImage.width / (oSignatureImage.height/height);
		oSignatureImage.height = height;
	}
	else if( oSignatureImage.width > width)
	{
		oSignatureImage.height = oSignatureImage.height / (oSignatureImage.width/width);
		oSignatureImage.width = width;
	}
	
	oSignatureImage.style.visibility = "visible";
}

function ValidateAvatar( tboxId, btnId, imgId)
{
	UpdateAvatar( tboxId, btnId, imgId)
	var avatar = document.getElementById( imgId);
	var avatarButton = document.getElementById( btnId);
	if( avatar != null && avatarButton != null)
	{
		if( avatar.height * avatar.width > 250000)
			alert( 'Error: This avatar exceeds the maximum allowed filesize');
		else if( avatar.height > 67 || avatar.width > 100)
		{
			if( confirm( 'Warning: This image exceeds the maximum resolution, click "OK" to continue anyway and let us reduce the size for you'))
			{
				avatarButton.disabled = false;
				ResizeAvatar( avatar);
			}
		}
		else
		{
			avatarButton.disabled = false;
			ResizeAvatar( avatar);
		}
	}
}

function UpdateAvatar( tboxId, btnId, imgId)
{
	var avatar = document.getElementById( imgId);
	var avatarTextbox = document.getElementById( tboxId);
	var avatarButton = document.getElementById( btnId);
	if( avatar != null && avatarTextbox != null)
	{
		var newImage = new Image();
		newImage.src = avatar.src = avatarTextbox.value;
		if( newImage.height != null && newImage.width != null)
		{
			avatar.height = newImage.height;
			avatar.width = newImage.width;
		}
	}
}

function MakeVisible( id)
{
	var element = document.getElementById( id);
	if( element != null) element.style.display = '';
}

function ReplaceLink( bbcode, selectedText)
{
	if( bbcode.indexOf( '{{{url_link}}}') != -1)
	{
		if( selectedText == '' || selectedText == null) selectedText = 'http://';
		var answer = prompt( "Choose the url for your link (must contain 'http://')", selectedText);
		if( answer == null) return '';
		return ReplaceLinkDisplay( bbcode.replace( '{{{url_link}}}', answer), answer);
	}
	return bbcode;
}

function ReplaceLinkDisplay( bbcode, selectedText)
{
	if( bbcode.indexOf( '{{{url_display}}}') != -1)
	{
		var answer = prompt( "Choose the text to display for your link", selectedText);
		if( answer == null) return '';
		return bbcode.replace( '{{{url_display}}}', answer);
	}
	return bbcode;
}

function ReplaceImage( bbcode, selectedText)
{
	if( bbcode.indexOf( '{{{image_url}}}') != -1)
	{
		var answer = prompt( "Choose the full url of your image (must be of the form 'http://')", selectedText);
		if( answer == null) return '';
		return bbcode.replace( '{{{image_url}}}', answer);
	}
	return bbcode;
}

function SetCursorPosition( ctrl, iCaretStart, iCaretEnd)
{
	//Firefox
	if( ctrl.selectionStart || ctrl.selectionStart == '0')
	{
		ctrl.selectionStart = iCaretStart;

		if( iCaretEnd != null)
			ctrl.selectionEnd = iCaretEnd;
		else
			ctrl.selectionEnd = iCaretStart;

		ctrl.focus();
	}
}

function Set_Cookie( 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" : "" );
}



// this function gets the cookie, if it exists
// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

// this deletes the cookie when called
function Set_Search_Cookie(name,make,model,yearFrom,yearTo,priceFrom,priceTo,range,mileage,color,bodystyle,transmission,doors,engine,driveType)
{    
    var makeDD = document.getElementById(make);
    var modelDD = document.getElementById(model);
    var yearFromDD = document.getElementById(yearFrom);
    var yearToDD = document.getElementById(yearTo);
    var priceFromDD = document.getElementById(priceFrom);
    var priceToDD = document.getElementById(priceTo);
    var rangeDD = document.getElementById(range);
    var mileageDD = document.getElementById(mileage);
    var colorDD = document.getElementById(color);
    var bodystyleDD = document.getElementById(bodystyle);
    var transmissionDD = document.getElementById(transmission);
    var doorsDD = document.getElementById(doors);
    var engineDD = document.getElementById(engine);
    var driveTypeDD = document.getElementById(driveType);
    var strCookie;
    var tempSelectedValue='';
    
    if(makeDD != null) 
    {
        tempSelectedValue = makeDD.options[makeDD.selectedIndex].value;
        if(tempSelectedValue != null && tempSelectedValue.indexOf("|")>0)
            tempSelectedValue = tempSelectedValue.substring(0,tempSelectedValue.indexOf("|"));
        strCookie =  tempSelectedValue+'&';
        
    }
    if(modelDD != null)
    {
        tempSelectedValue = modelDD.options[modelDD.selectedIndex].value;
        if(tempSelectedValue != null && tempSelectedValue.indexOf("|")>0)
            tempSelectedValue = tempSelectedValue.substring(0,tempSelectedValue.indexOf("|")); 
        strCookie += tempSelectedValue+'&';
    }
    if(yearFromDD != null) 
        strCookie +=  yearFromDD.options[yearFromDD.selectedIndex].text+'&';
   
    if(yearToDD != null) 
        strCookie +=  yearToDD.options[yearToDD.selectedIndex].text+'&';
   
    if(priceFromDD != null) 
        strCookie +=  priceFromDD.options[priceFromDD.selectedIndex].text+'&';
   
    if(priceToDD != null) 
        strCookie +=  priceToDD.options[priceToDD.selectedIndex].text+'&';
   
    if(rangeDD != null) 
        strCookie +=  rangeDD[rangeDD.selectedIndex].text+'&';
    
    if(mileageDD != null) 
        strCookie +=  mileageDD.options[mileageDD.selectedIndex].text+'&';
   
    if(colorDD != null) 
        strCookie +=  colorDD.options[colorDD.selectedIndex].text+'&';
   
    if(bodystyleDD != null) 
        strCookie +=  bodystyleDD.options[bodystyleDD.selectedIndex].text+'&';
  
    if(transmissionDD != null) 
        strCookie +=  transmissionDD.options[transmissionDD.selectedIndex].text+'&';
   
    if(doorsDD != null) 
        strCookie += doorsDD.options[doorsDD.selectedIndex].text+'&';
   
    if(engineDD != null) 
        strCookie +=  engineDD.options[engineDD.selectedIndex].text+'&';
   
    if(driveTypeDD != null) 
        strCookie +=  driveTypeDD.options[driveTypeDD.selectedIndex].text;
   
    document.cookie = name+"="+escape(strCookie);
}

function Length_TextField_Validator(elmId)
{
    var element = document.getElementById(elmId);
    var strText = element.value;
    // Check the length of the value of the element named text_name
    // from the form named form_name if it's < 2 and > 64 characters
    // display a message asking for different input
    strText = strText.replace(/^\s+|\s+$/g, "");
    element.value = strText;
    if ((strText.length < 2) || (strText.length > 64))
    {
    
    // Build alert box message showing how many characters entered
    mesg = "Your search keyword must be at least 2 characters.\n"   
    mesg = mesg + "Please verify your input and try again."
    alert(mesg);
    // Place the cursor on the field for revision
    element.focus();
    // return false to stop further processing
    return (false);
    }
    // If text_name is not null continue processing
    return (true);
}

// Extended Tooltip Javascript
// http://javascript.about.com/library/bltip1.htm
// copyright 9th August 2002, 3rd July 2005
// by Stephen Chapman, Felgall Pty Ltd

// permission is granted to use this javascript provided that the below code is not altered
var DH = 0;var an = 0;var al = 0;var ai = 0;if (document.getElementById) {ai = 1; DH = 1;}else {if (document.all) {al = 1; DH = 1;} else { browserVersion = parseInt(navigator.appVersion); if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {an = 1; DH = 1;}}} function fd(oi, wS) {if (ai) return wS ? document.getElementById(oi).style:document.getElementById(oi); if (al) return wS ? document.all[oi].style: document.all[oi]; if (an) return document.layers[oi];}
function pw() {return window.innerWidth != null? window.innerWidth: document.body.clientWidth != null? document.body.clientWidth:null;}
function mouseX(evt) {if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return null;}
function mouseY(evt) {if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return null;}
function popUp(evt,oi) {if (DH) {var wp = pw(); ds = fd(oi,1); dm = fd(oi,0); st = ds.visibility; if (dm.offsetWidth) ew = dm.offsetWidth; else if (dm.clip.width) ew = dm.clip.width; if (st == "visible" || st == "show") { ds.visibility = "hidden"; } else {tv = mouseY(evt) + 20; lv = mouseX(evt) - (ew/4) - 50; if (lv < 2) lv = 2; else if (lv + ew > wp) lv -= ew/2; if (!an) {lv += 'px';tv += 'px';} ds.left = lv; ds.top = tv; ds.visibility = "visible";}}}

function SetTooltipText(controlId, textControlId)
{
    var control = document.getElementById(controlId);
    var textControl = document.getElementById(textControlId);
    
    if((control != null) && (textControl != null))
    {        
        control.innerHTML = textControl.innerHTML;
    }
}     

function SetUniqueRadioButton(nameregex, current)
{
    re = new RegExp(nameregex);  

    for(i = 0; i < document.forms[0].elements.length; i++) 
    {

	    elm = document.forms[0].elements[i]

	    if (elm.type == 'checkbox') 
	    {
		    if (re.test(elm.id)) 
		    {
			    elm.checked = false;
		    }
	    }
    }
    current.checked = true;
}

function PopOpen( strUrl) {
	PopOpenDimensions( strUrl, '575', '220', '0');
}
function PopOpenDimensions(strUrl, intWidth, intHeight, intScrollBars) {
    strUrl = strUrl.replace("Town & Country", "Town %26 Country");
    var new_blog;
	if (intWidth == undefined) {
	    new_blog = window.open(strUrl, "new_blog", "fullscreen=yes,scrollbars=yes,resizable=yes,status=1");
	}
	else {
	    new_blog = window.open(strUrl, "new_blog", "width=" + intWidth + ",height=" + intHeight + ",scrollbars=" + intScrollBars + ",status=1");
	}
    new_blog.focus();
}

function createcssmenu2(){
for (var i=0; i<cssmenuids.length; i++){
  var ultags=document.getElementById(cssmenuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px"
			
			// IE6 hack
			if (ultags[t].parentNode.offsetLeft < 0)
			    ultags[t].style.left=ultags[t].parentNode.offsetLeft+csssubmenuoffsetleft2+"px"
			else			
			    ultags[t].style.left=ultags[t].parentNode.offsetLeft+csssubmenuoffsetleft+"px"
			
    	var spanref=document.createElement("span")
			spanref.className="arrowdiv"
			spanref.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;"
			ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
    	ultags[t].parentNode.onmouseover=function(){
    	this.getElementsByTagName("ul")[0].style.visibility="visible"
    	}
    	ultags[t].parentNode.onmouseout=function(){
			this.getElementsByTagName("ul")[0].style.visibility="hidden"
    }
    }
  }
}

function UpdateHiddenFieldValue(hiddenFieldControlId, valueToUpdate)
{
    var hiddenField = document.getElementById(hiddenFieldControlId);
    
    if(hiddenField != null)
    {
        //remove
        if(hiddenField.value.indexOf(valueToUpdate) > -1)
        {            
            //remove it
            hiddenField.value = hiddenField.value.replace(valueToUpdate + ',', '');
        }
        else //add
        {
            hiddenField.value = hiddenField.value + valueToUpdate + ',';
        }
    }
}

function init_scroller_flipper()
{        
    if (startIndexMain < 0)
        startIndexMain = 0;
                
    var leftScrollButton = document.getElementById("leftScrollButton");
    var rightScrollButton = document.getElementById("rightScrollButton");  
    var scrollerDivider = document.getElementById("scrollerDivider");           
    var main_table = document.getElementById("main_content");
	var main_table_rows = main_table.getElementsByTagName('tr');
	var main_table_row;
	var main_table_cells;					
	
	if (main_table_rows.length != 1)
        return;
    
    main_table_row = main_table_rows[0];
    main_table_cells = main_table_row.getElementsByTagName("td");
    
    // keep trackc of table cells
    for (j = 0; j < main_table_cells.length; j++)
        tableCells[j] = main_table_cells[j];
		
    // hide all drilldown items
    for (i = 0; i < drilldownItems.length; i++)
    {                
        drilldownItems[i].style.display = 'none';        
        drilldownItems[i].parentNode.parentNode.style.display = 'none';
    }    
    
    if (numImages == 1)
    {
        // fill row with empty TDs
        var td = document.createElement("td");                       
        main_table_row.appendChild(td);
        td = document.createElement("td");                       
        main_table_row.appendChild(td);
        td = document.createElement("td");                       
        main_table_row.appendChild(td);
        
        // hide scroll buttons
        leftScrollButton.src = leftImageButtonDisabled;
        rightScrollButton.src = rightImageButtonDisabled;
        scrollerDivider.className = "s2_f_624_2 mgn_l";
        
        // show first TD/Item
        drilldownItems[0].parentNode.parentNode.style.display = "";    
        drilldownItems[0].style.display = "";   
        main_table_cells[0].style.display = "";        
        scroller_onmouseover(0);   
    }
    else if (numImages == 2)
    {
        // fill row with empty TDs
        var td = document.createElement("td");               
        main_table_row.appendChild(td);        
        td = document.createElement("td");                
        main_table_row.appendChild(td);
        
        // hide scroll buttons
        leftScrollButton.src = leftImageButtonDisabled;
        rightScrollButton.src = rightImageButtonDisabled;
        scrollerDivider.className = "s2_f_624_2 mgn_l";
        
        // show first 2 TD/Items
        drilldownItems[0].style.display="";
        drilldownItems[0].parentNode.parentNode.style.display="";
        main_table_cells[0].style.display="";
        main_table_cells[1].style.display="";        
        scroller_onmouseover(1);
    }
    else if (numImages == 3)
    {
        // fill row with empty TD
        var td = document.createElement("td");               
        main_table_row.appendChild(td);         
        
        // hide scroll buttons
        leftScrollButton.src = leftImageButtonDisabled;
        rightScrollButton.src = rightImageButtonDisabled;        
        
        // show first 3 TD/Items
        drilldownItems[0].style.display="";
        drilldownItems[0].parentNode.parentNode.style.display="";
        main_table_cells[0].style.display="";
        main_table_cells[1].style.display="";
        main_table_cells[2].style.display="";
        main_table_cells[2].className = cssClassHighlightedItem;
        scroller_onmouseover(2);
    }
    else 
    {
        leftScrollButton.src = leftImageButtonDisabled;
    
        for (var i = 0; i < main_table_cells.length; i++)
        {
            if (i < numImagesPerPage)
                main_table_cells[i].style.display = "";
            else
                main_table_cells[i].style.display = "none";
        }
        drilldownItems[2].style.display = "";        
        drilldownItems[2].parentNode.parentNode.style.display = "";
        main_table_cells[2].className = cssClassHighlightedItem;
        scroller_onmouseover(2);
    }        
}

function select_image(selImageUrl, srcImage, styleOff, styleOn, selImageUrlMain)
{
    var selectFirstImage = false;
    var selImageTitle = "";
    if(!selImageUrl)
    {
        selectFirstImage = true;
    }
    
    selImageUrl = selImageUrl.replace(" ", "%20");
//alert(selImageUrl);
//alert(styleOff);
//alert(styleOn);

	var main_table = document.getElementById('main_content');
	if(!main_table)
	{
	    //alert("Entered");
	    var scrollerContent = document.getElementById('ScrollerContentTable');
	    if (scrollerContent!=null) {
	        document.getElementById('ScrollerContentTable').innerHTML = "";
	    }
	    return;
	}
	var main_table_elements = main_table.getElementsByTagName('tr');
	for( var i = 0; i < main_table_elements.length; i++)
	{
		var main_table_cells = main_table_elements[i].getElementsByTagName( 'td');
		for( var j = 0; j < main_table_cells.length; j++)
		{
		    var main_image = main_table_cells[j].getElementsByTagName('img');		    
		    if(main_image[0].src == selImageUrl)
		    {
		        selectFirstImage = true;
		    }
		    if(selectFirstImage)
		    {
    		    //alert("Source : " + main_image + " --- " + main_image[0].src + " --- " + main_image.length);
    		    main_image[0].className = styleOn;
    		    selImageUrl = main_image[0].src;
    		    selImageTitle = main_image[0].alt;
    		    selImageIndex = j;
    		    selectFirstImage = false;
		    }
		    else
		    {
		        main_image[0].className = styleOff;
		    }
		}
	}
	srcImage.src = selImageUrl;
    if(selImageUrlMain)
        srcImage.src = selImageUrlMain;
    srcImage.alt = selImageTitle.replace("Picture","Photo");
    srcImage.title = selImageTitle.replace("Picture","Photo");
}

function LoadImage(eMoz, imgMain)
{
    if (!eMoz)
        eMoz = window.event;
    if(eMoz.target)
        LoadMainImage(eMoz.target.src, document.getElementById(imgMain), true);
    else
        LoadMainImage(eMoz.srcElement.src, document.getElementById(imgMain), true);
}
function HideVisibility(objElement)
{
    if (navigator.appName.indexOf('Netscape') != -1)
    {
        document.getElementById(objElement).innerHTML = "";
    }
    else
    {
        document.getElementById(objElement).innerText = "";
    }
    document.getElementById(objElement).className = "hide";
}

/****************Table Utils*****************/
function HighlightRowCol (tableName, row, col, regionRowStart, regionRowEnd, regionColStart, regionColEnd, cssClassHighlightCell, cssClassHighlightRow, cssClassHighlightCol, highlightLeft, highlightRight, highlightTop, highlightBottom)
{
    var tbl = document.getElementById (tableName);
    for (var i = 0; i < tbl.rows.length; i++)
    {
        for (var j = 0; j < tbl.rows[i].cells.length; j++)
        {
            if (((regionRowStart == -1) || (i >= regionRowStart)) &&
                ((regionRowEnd == -1) || (i <= regionRowEnd)) &&
                ((regionColStart == -1) || (i >= regionColStart)) &&
                ((regionColEnd == -1) || ( i <= regionRowEnd)) &&
                ((row == i) || (col == j)))
            {
                tbl.rows[i].cells[j].classNameBackup = tbl.rows[i].cells[j].className;
                if ((row == i) && (col == j) && (cssClassHighlightCell != ''))
                    tbl.rows[i].cells[j].className = cssClassHighlightCell; 
                else if ((row == i) && (col != j) && (cssClassHighlightRow != '') &&
                    (((highlightLeft == 'True') && (j < col)) || ((highlightRight == 'False') && (j > col))))
                    tbl.rows[i].cells[j].className = cssClassHighlightRow;
                else if ((row != i) && (col == j) && (cssClassHighlightCol != '') &&
                    (((highlightTop == 'True') && (i < row)) || ((highlightBottom == 'False') && (i > row))))
                    tbl.rows[i].cells[j].className = cssClassHighlightCol;
            }
        }
    }
}

function UnhighlightRowCol (tableName, row, col, regionRowStart, regionRowEnd, regionColStart, regionColEnd)
{    
    var tbl = document.getElementById (tableName);
    for (var i = 0; i < tbl.rows.length; i++)
    {
        for (var j = 0; j < tbl.rows[i].cells.length; j++)
        {
            if (((regionRowStart == -1) || (i >= regionRowStart)) &&
                ((regionRowEnd == -1) || (i <= regionRowEnd)) &&
                ((regionColStart == -1) || (i >= regionColStart)) &&
                ((regionColEnd == -1) || ( i <= regionRowEnd)) &&
                ((row == i) || (col == j)))
                tbl.rows[i].cells[j].className = tbl.rows[i].cells[j].classNameBackup;
        }
    }
}

function TableHighlightSetup (tableName, regionRowStart, regionRowEnd, regionColStart, regionColEnd, cssClassHighlightCell, cssClassHighlightRow, cssClassHighlightCol, highlightLeft, highlightRight, highlightTop, highlightBottom)
{
    var tbl = document.getElementById (tableName);
    for (var i = 0; i < tbl.rows.length; i++)
    {
        for (var j = 0; j < tbl.rows[i].cells.length; j++)
        {
            if (((regionRowStart == -1) || (i >= regionRowStart)) &&
                ((regionRowEnd == -1) || (i <= regionRowEnd)) &&
                ((regionColStart == -1) || (i >= regionColStart)) &&
                ((regionColEnd == -1) || ( i <= regionRowEnd)))
            {
                tbl.rows[i].cells[j].onmouseover = new Function ("HighlightRowCol ('" + tableName + "', " + i + ", " + j + ", " + regionRowStart + ", " + regionRowEnd + ", " + regionColStart + ", " + regionColEnd + ", '" + cssClassHighlightCell + "', '" + cssClassHighlightRow + "', '" + cssClassHighlightCol + "', '" + highlightLeft + "', '" + highlightRight + "', '" + highlightTop + "', '" + highlightBottom + "');");
                tbl.rows[i].cells[j].onmouseout = new Function ("UnhighlightRowCol ('" + tableName + "', " + i + ", " + j + ", " + regionRowStart + ", " + regionRowEnd + ", " + regionColStart + ", " + regionColEnd + ");");
            }
        }
    }
}
/****************End Table Utils*****************/
// Search functions
    


/****************Navbar*****************/
var cssnavmenuid_arr=new Array(); //Enter id(s) of CSS Horizontal UL menus, separated by commas
var menuCount = 0;
var itemCount = 0;

function addnavmenu(id)
{    
    cssnavmenuid_arr[menuCount] = "cssnavmenu" + id;        
    menuCount++;
}

function createcssnavmenu2()
{           
    if (navigator.appName == "Microsoft Internet Explorer")
    {                
        var b = document.getElementById("break");
        if (b)
            b.parentNode.removeChild(b);
    }
    var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

    for (var i=0; i<cssnavmenuid_arr.length; i++)
    {
        //alert(document.getElementById(cssnavmenuid_arr[i]));
        var ultags=document.getElementById(cssnavmenuid_arr[i]).getElementsByTagName("ul")
        for (var t=0; t<ultags.length; t++) {
            if (isIE6)
                ultags[t].style.top = ultags[t].parentNode.offsetHeight + "px"
            else
                ultags[t].style.top = ultags[t].parentNode.offsetHeight + cssnavsubmenuoffset + "px"
            if (ultags[t].parentNode.onmouseover == undefined) {
                ultags[t].parentNode.onmouseover = function() {
                    this.getElementsByTagName("ul")[0].style.visibility = "visible"
                }
            }
            if (ultags[t].parentNode.onmouseout == undefined) {
                ultags[t].parentNode.onmouseout = function() {
                    this.getElementsByTagName("ul")[0].style.visibility = "hidden"
                }
            }
        }
    }
}

function createcssnavmenu()
{   
    if (!document.getElementById("cssnavmenu"))
        return;
    if (navigator.appName == "Microsoft Internet Explorer")
    {                
        var b = document.getElementById("break");
        if (b)
            b.parentNode.removeChild(b);
    }
    var imgtags = document.getElementById("cssnavmenu").getElementsByTagName("img");
    for (var d=0; d<imgtags.length;d++)
    {    
        //alert(imgtags[d].width + ", " + imgtags[d].parentNode.style.width);
        //imgtags[d].parentNode.style.width = imgtags[d].width + "px";   
    }    
    for (var i=0; i<cssnavmenuids.length; i++)
    {
        var ultags=document.getElementById(cssnavmenuids[i]).getElementsByTagName("ul")
        for (var t=0; t<ultags.length; t++)
        {
		    ultags[t].style.top=ultags[t].parentNode.offsetHeight+cssnavsubmenuoffset+"px"
    	    ultags[t].parentNode.onmouseover=function()
    	    {
    	        this.getElementsByTagName("ul")[0].style.visibility="visible"
    	    }
    	    ultags[t].parentNode.onmouseout=function()
    	    {
			    this.getElementsByTagName("ul")[0].style.visibility="hidden"
            }
        }
    }
}
/****************End NavBar*****************/

// Take content in a div with id="defer-xyz" and move it to a div with id="xyz"
function relocateDeferredContent()
{
    var dc = document.getElementById("ctl00_dc");
    if(dc != null)
    {
		var divs = dc.getElementsByTagName("div");
		var replacements = new Array();
	    
		if(divs != null)
		{
			for(var i = 0; i < divs.length; i++)
			{
				var deferredContent = divs[i];
				if (deferredContent.id.indexOf("defer-") == 0)
				{
					var placeHolder = document.getElementById(deferredContent.id.slice(6));
					if(deferredContent && placeHolder)
					    replacements.push([deferredContent, placeHolder]);
				}
			}
			
			for(i = 0; i < replacements.length; i++)
			{
				replacements[i][0].parentNode.removeChild(replacements[i][0]);
				replacements[i][1].parentNode.replaceChild(replacements[i][0], replacements[i][1]);
				replacements[i][0].style.display = "block";
				replacements[i][0].className = replacements[i][1].className;
			}

		    return true;
		}
	}
	return false;
}

function ResizeAvatarImage()
{
resize( 50, 25);
}

function selectOptionValue(obj, value)
{
    if (obj != null && value != null)
    {
        if (obj.length > 0)
        {
            obj.options[0].selected = true;
        }
        for(i=obj.length-1; i>=0; i--)
        {
            if(obj.options[i].text == value.value )
            {
                obj.options[i].selected = true;
            }
        }    
    }
}
function setSelectedValue(obj, value)
{
    if (obj != null && value != null)
    {
        if (obj.length > 0)
        {
            obj.options[0].selected = true;
        }
        for(i=obj.length-1; i>=0; i--)
        {
            if(obj.options[i].text == value )
            {
                obj.options[i].selected = true;
            }
        }    
    }
}

function SetAvatarImgSrc(controlId, imgSrc)
{
    var control = document.getElementById(controlId);
    
    if(control != null)
    {
        control.onload = function(){ResizeAvatar(document.getElementById(control.id));}
        control.src = imgSrc;       
    }
}
function SetSignatureImgSrc(controlId, imgSrc)
{
    var control = document.getElementById(controlId);
    
    if(control != null)
    {
        control.onload = function(){ResizeSignature(document.getElementById(control.id));}
        control.src = imgSrc;       
    }
}

function SetBodyImgSrc(controlId, imgSrc)
{
    var control = document.getElementById(controlId);
    
    if(control != null)
    {        
        control.src = imgSrc;  
        control.style.visibility="visible";
    }	
}

function RedirectClick( strUrl)
{
    window.location=strUrl;
}

//*****Motor Trend Comparison List *****//
var vehDetails = new Array();
var norVehicleMake;
var norVehicleModel;
var norVehicleYear;

function SelectItem(ev, strVehicleYear, strVehicleMake, strVehicleModel, norStrVehicleMake, norStrVehicleModel)
{
    if (!ev) ev = window.event;
    var srcObj;
    //alert(strVehicleMake + " --- " + strVehicleModel);

    if(ev.target)
    {
        srcObj = ev.target;
    }
    else
    {
        srcObj = ev.srcElement;
    }
   
    var p = srcObj;
    
    for (; p; p = p.parentNode)
    {   
        if(p.id.indexOf("phControl") != -1)
            break;
    }

    if(srcObj.src.indexOf("plus") != -1)
    {
        srcObj.src = srcObj.src.replace("plus.jpg", "minus.jpg");
        p.className  = "selItemStyle";
        PopulateVehicleDetails(strVehicleYear, strVehicleMake, strVehicleModel, true, norStrVehicleMake, norStrVehicleModel); 
    }
    else
    {
        srcObj.src = srcObj.src.replace("minus.jpg", "plus.jpg");
        p.className = "itemStyle";
        PopulateVehicleDetails(strVehicleYear, strVehicleMake, strVehicleModel, false, norStrVehicleMake, norStrVehicleModel); 
    }
   
    return false;
}

function PopulateVehicleDetails(StrVehicleYear, StrVehicleMake, StrVehicleModel, BoolAddItem, norStrVehicleMake, norStrVehicleModel)
{
    var arrLen = vehDetails.length;
    var i;
    //alert(arrLen);
    if(vehDetails.length == 0)
    {
        norVehicleYear = StrVehicleYear;
        norVehicleMake = norStrVehicleMake;
        norVehicleModel = norStrVehicleModel;
    }
    if(BoolAddItem)
    {        
        vehDetails[arrLen] = new Array();
        vehDetails[arrLen][0] = StrVehicleYear;
        vehDetails[arrLen][1] = StrVehicleMake;
        vehDetails[arrLen][2] = StrVehicleModel;
    }
    else
    {
        for (i = 0; i < arrLen; i++)
        {
        //alert( vehDetails[i][0] + " -- " +  vehDetails[i][1] + " -- " +  vehDetails[i][2])
            if((StrVehicleYear == vehDetails[i][0]) && (StrVehicleMake == vehDetails[i][1]) && (StrVehicleModel == vehDetails[i][2]))
            {
                vehDetails[i][0] = "";
                vehDetails[i][1] = "";
                vehDetails[i][2] = "";
                break;
            }
        }
    }    
}

function CompareVehicles(strHost)
{
    var arrLen = vehDetails.length;
    var i;
    //alert(arrLen);
    
    var compVehDetails = new Array();
    var vehCount = 0;
    var strUrl;

    for (i = 0; i < arrLen; i++)
    {
        if(vehDetails[i][0] != "")
        {
            //alert( vehDetails[i][0] + " -- " +  vehDetails[i][1] + " -- " +  vehDetails[i][2])
            compVehDetails[vehCount] = new Array();
            
            compVehDetails[vehCount][0] = vehDetails[i][0];
            compVehDetails[vehCount][1] = vehDetails[i][1];
            compVehDetails[vehCount][2] = vehDetails[i][2];
            
            vehCount++;
        }
    }
    if(vehCount>0)
    {
        strUrl = strHost + "/cars/" + norVehicleYear + "/" + norVehicleMake + "/" + norVehicleModel + "/comparisons/index.html?Loadfromurl=true&";        
        if(vehCount > 4)
            vehCount = 4;
        for (i = 0; i < vehCount; i++)
        {
            if(i == 0)
            {
                strUrl += "Vehicle" + (i) + ".Make=" + compVehDetails[i][1] +  "&Vehicle" + (i) + ".Model=" + compVehDetails[i][2] + "&Vehicle" + (i) + ".Year=" + compVehDetails[i][0];
            }
            else
            {
                strUrl += "&Vehicle" + (i) + ".Make=" + compVehDetails[i][1] +  "&Vehicle" + (i) + ".Model=" + compVehDetails[i][2] + "&Vehicle" + (i) + ".Year=" + compVehDetails[i][0];
            }
        }
    }
    if(strUrl)
        window.location.href = strUrl;
}


function HoverItem(ev)
{
    if (!ev) ev = window.event;
    var srcObj;
    //alert(strVehicleMake + " --- " + strVehicleModel);
   
    if(ev.target)
    {
        srcObj = ev.target;
    }
    else
    {
        srcObj = ev.srcElement;
    }
   
    var p = srcObj;
    
    for (; p; p = p.parentNode)
    {   
        if(p.id.indexOf("phControl") != -1)
            break;
    }
    if(p.className != "selItemStyle")
        p.className  = "hoverItemStyle";

   
    return false;
}

function UnHoverItem(ev)
{
    if (!ev) ev = window.event;
    var srcObj;
    //alert(strVehicleMake + " --- " + strVehicleModel);
   
    if(ev.target)
    {
        srcObj = ev.target;
    }
    else
    {
        srcObj = ev.srcElement;
    }
   
    var p = srcObj;
    
    for (; p; p = p.parentNode)
    {   
        if(p.id.indexOf("phControl") != -1)
            break;
    }
    if(p.className != "selItemStyle")
        p.className = "";
   
    return false;
}

//*****Motor Trend End Comparison List *****//

function textMaximize(minbutton,maxbutton,textblock,mindisableclass,minenableclass,maxdisableclass,maxenableclass)
{

    var txt = document.getElementById(textblock);
    var fonttext = txt.style.fontSize;
    var actualsize = fonttext.substring(0,fonttext.indexOf("px"));

    if(actualsize < 16)
    {
        txt.style.fontSize=(parseInt(actualsize)+1)+"px";
        document.getElementById(minbutton).className=minenableclass;
    }
    if(actualsize==15)
    {
       document.getElementById(maxbutton).className=maxdisableclass;
    }
    return false;
}

function textMinimize(minbutton,maxbutton,textblock,mindisableclass,minenableclass,maxdisableclass,maxenableclass)
{
    var txt = document.getElementById(textblock);
    var fonttext = txt.style.fontSize;
    var actualsize = fonttext.substring(0,fonttext.indexOf("px"));

    if(actualsize > 8)
    {
        txt.style.fontSize=(parseInt(actualsize)-1)+"px";
        document.getElementById(maxbutton).className=maxenableclass;
    }
    if(actualsize==9)
    {
       document.getElementById(minbutton).className=mindisableclass;
    }
    return false;
}
function UrlNormalize(url, deliminator)
{
    if (url == null)
    {
        return '';
    }
    else
    {
		url = url.replace( /[^a-zA-Z0-9]+/g, deliminator);
        return url.toLowerCase();
    }
}

//***** REDIR POST FUNCTION *****//
function post_to_url(path, params, method) {
    method = method || "post"; // Set method to post by default, if not specified.    
    
    // The rest of this code assumes you are not using a library.    
    // It can be made less wordy if you use one.    
    
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);
    
    for(var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);
        
        form.appendChild(hiddenField);
    }    
    
    document.body.appendChild(form);    // Not entirely sure if this is necessary
    form.submit();
}
//***** REDIR POST FUNCTION *****//
function post_url_to_new_window(path, params, method) {
    method = method || "post"; // Set method to post by default, if not specified.    

    // The rest of this code assumes you are not using a library.    
    // It can be made less wordy if you use one.    

    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);
    form.setAttribute("target","_blank")

    for (var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);

        form.appendChild(hiddenField);
    }

    document.body.appendChild(form);    // Not entirely sure if this is necessary
    form.submit();
}

function openSearchTextBox(me)
{
    var searchWordContainer = document.getElementById("searchWordContainer");
    if ( searchWordContainer.style.display == 'none' )
    {
        searchWordContainer.style.display = '';
        if (altImageSrc != '')
            me.src = altImageSrc;
        return false;
    }
    else
    {
        return validateHeaderSearchText();
    }
}

function validateHeaderSearchText()
{
    var strSearchText = textBoxSearchWord.value;		
    if (textTrim(strSearchText).length > 0 && textTrim(strSearchText) != defaultText)
    {
	    return true;
    }
    else
    {
        textBoxSearchWord.style.backgroundImage='url()';
        textBoxSearchWord.style.backgroundColor = '#fdb139';
        textBoxSearchWord.style.color = 'black';
        return false;
    }
}
function focusTextBox()
{
    var strSearchText = textBoxSearchWord.value;
    
    if(defaultText.length > 0 && strSearchText == defaultText)
    {
        textBoxSearchWord.value = "";
    }
}

function blurTextBox()
{
	var strSearchText = textBoxSearchWord.value;
    
    if(textTrim(strSearchText).length == 0 && defaultText.length > 0)
    {
        textBoxSearchWord.value = defaultText;
    }
}
function SwitchTextContent(hdnContent, actualContent, readMoreContent)
{
var tempActualContent = document.getElementById(actualContent).innerHTML;
var tempHdnContent = document.getElementById(hdnContent).value;
var tempReadMore = document.getElementById(readMoreContent).innerHTML;

document.getElementById(actualContent).innerHTML = tempHdnContent;
document.getElementById(hdnContent).value = tempActualContent;
if(tempReadMore == "read more")
{
document.getElementById(readMoreContent).innerHTML = "hide";
}
else
{
document.getElementById(readMoreContent).innerHTML = "read more";
}
}
function getXY( oElement, side )
{
    if (side == "")
        return 0;

    var iReturnX = 0;
    var iReturnY = 0;
    while( oElement != null )
    {
        iReturnX += oElement.offsetLeft;
        iReturnY += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    if (side == "xy")
        return [iReturnX, iReturnY];
    else if (side == "x")
        return iReturnX;
    else if (side == "y")
        return iReturnY;
}
function PopupImageCaption(oElement)
{
    var captionPopup = document.getElementById('captionPopup');
    if (captionPopup)
    {
        captionPopup.style.display="none";
        captionPopup.id="";
    }
    firstSib = oElement.getElementsByTagName('div')[0];
    secondSib = GetNextSibling(firstSib);
    
    if((firstSib) && (secondSib))
    {
        // just to find xy co-ordinates
        if (firstSib.style.display == 'inline')
            firstSib.style.display = 'block';
        
        secondSib.style.display="block";
        secondSib.id="captionPopup";
        secondSib.style.zIndex=9999;
        secondSib.onmouseout = HidePopupImageCaption;
        secondSib.onmouseover = ShowPopupOnOver;
        
        // to make it veritically/horizontally center aligned - deferred calculation
        var top = (getXY(firstSib, "y") - ((secondSib.offsetHeight - firstSib.offsetHeight)/2));
        var left = (getXY(firstSib, "x") - ((secondSib.offsetWidth - firstSib.offsetWidth)/2));

        try {
            left = left - popupOffsetLeft;
        }
        catch (exception) {
        }

        secondSib.style.left=left+"px";
        secondSib.style.top=top+"px";
        
        // replace style after finding xy co-ordinates
        if (firstSib.style.display == 'block')
            firstSib.style.display = 'inline';
    }
}
function HidePopupImageCaption()
{
    var element = document.getElementById('captionPopup');
    if (!element) return;
    
    element["timeout"] = setTimeout("HidePopupOnOut()", 30);
}
function ShowPopupOnOver()
{
    var element = document.getElementById('captionPopup');
    if (!element) return;
    element.style.display="block";
    clearTimeout(element["timeout"]);
}
function HidePopupOnOut()
{
    var element = document.getElementById('captionPopup');
    if (!element) return;
    element.style.display="none";
    element.id="";
}
//Fixes the bug in firefox which counts whitespace as a node, use instead of ELEMENT.nextSibling
function GetNextSibling(startBrother)
{
    var endBrother = startBrother.nextSibling;
    while(endBrother && endBrother.nodeType != 1)
    {
        endBrother = endBrother.nextSibling;
    }
    return endBrother;
}
function getContentFrame(id, url,width)
{
    return "<iframe id='sm_iframe_" + id + "' src ='" + url + "' scrolling='no' frameborder='0' height='1200' width='"+ width + "' allowtransparency='true'></iframe>";
}

//IC Drilldown swap image - Control : TopCarConsider
 function SwapMainImage(image_path, caption, link_id, row_id){
    var image=document.getElementById("main_image");
    image.src = image_path;
    image.alt = caption;
    
    var as = document.getElementsByTagName("a");
    var aCount = 1;
	if(as != null)
	{
		for(var i = 0; i < as.length; i++)
		{
			var currentA = as[i];
			if (currentA.id.indexOf("top_car_link_") == 0)
			{
                currentA.className = 'topcarlink_off';
                currentA.style.color = '#0484c3';
                
                var currentDiv=document.getElementById("top_car_div_" + aCount);
                if(aCount%2 == 1)
                    currentDiv.className = 'topcaritem';
                else
                    currentDiv.className = 'topcaritem2';
                    
                aCount++;
			}
		}
    }
    
    var link=document.getElementById("top_car_link_" + link_id);
    link.className = 'topcarlink_on';
    link.style.color = 'white';
    
    var currentDiv=document.getElementById("top_car_div_" + link_id);
    currentDiv.className = 'topcaritem_on_' + row_id;
    
    if (document.all)
	    image_caption.innerHTML = caption;
    else if (document.getElementById){
	    var image=document.getElementById("image_caption");
	    var rng = document.createRange();
	    rng.setStartBefore(image);
	    var htmlFrag = rng.createContextualFragment(caption);
	    while (image.hasChildNodes())
		    image.removeChild(image.lastChild);
	    image.appendChild(htmlFrag);
    }
}
function toggle(elementId)
{
    var toggleElement=document.getElementById(elementId);
    
    if (!toggleElement) return;
    
    if (toggleElement.style.display=='none')
        toggleElement.style.display='block';
    else if  (toggleElement.style.display=='block')
        toggleElement.style.display='none';
    else if (toggleElement.style.visibility=='visible')
        toggleElement.style.display='hidden';
    else if  (toggleElement.style.visibility=='hidden')
        toggleElement.style.display='visible';
        
}
function refreshAdUnits()
{
    iframes = document.getElementsByTagName("iframe");
    for (var i = 0; i < iframes.length; i++) {
        if(iframes[i].id=='')
            iframes[i].src = iframes[i].src;
    }
}
function sortNumberDesc(a,b)
{
	return b-a;
}
function sortAssociativeArray(array)
{
	var vals = [];
	var retArray = {};
	var oArray = {};
	
	for(key in array)
	{
		oArray[key] = array[key];
	}
		
	for(key in oArray)
	{
		vals[vals.length] = oArray[key];
	}
	
	vals.sort(sortNumberDesc);	

	for(i=0;i<vals.length;i++)
	{
		for(key in oArray)
		{
			if(oArray[key] == vals[i])
			{
				retArray[key] = vals[i];
				oArray[key] = -1;
				break;
			}
		}
	}
	return retArray;
}

//Allows multiple onloads to be set by a function so no onload is overriden unknowingly
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function ieSelectFix(visibility) {
    if (navigator.appName == 'Microsoft Internet Explorer') {
        selects = document.getElementsByTagName('select');
        for (i = 0; i < selects.length; i++) {
            if (selects[i].className != 'hidden') {
                selects[i].style.visibility = visibility;
            }
        }
    }
}

function ShowShareIcons(objShare, cssShareOff, cssShareOn) {
    if (document.getElementsByClassName) {
        var elements = document.getElementsByClassName(cssShareOn);
        for (i = 0; i < elements.length; i++) {
            if (elements[i].id != objShare)
                elements[i].className = cssShareOff;
        }
    }
    else {
        var elements = document.getElementsByTagName("div");
        for (i = 0; i < elements.length; i++) {
            if (elements[i].className == cssShareOn && elements[i].id != objShare)
                elements[i].className = cssShareOff;
        }
    }
    if (document.getElementById(objShare).className == cssShareOff)
        document.getElementById(objShare).className = cssShareOn;
    else
        document.getElementById(objShare).className = cssShareOff;        
    return false;
}
function sub_form_close() {
    Element.remove($('lbContent'));
    window.scrollTo(0, 0);

    bod = document.getElementsByTagName('body')[0];
    bod.style.height = 'auto';
    bod.style.overflow = 'hidden';

    htm = document.getElementsByTagName('html')[0];
    htm.style.height = 'auto';
    htm.style.overflowY = 'auto';
    htm.style.overflowX = 'hidden';

    if (browser == "Internet Explorer") {
        selects = document.getElementsByTagName('select');
        for (i = 0; i < selects.length; i++) {
            if (selects[i].className != 'hidden') {
                selects[i].style.visibility = 'visible';
            }
        }
    }
    jQuery("#lightbox").attr("style", "display:none");
}
