// ajax.js

function fillSelect(namevalue, controlId)
{
	if(oSelect=document.getElementById(controlId))
	{
		var content='';
		for(var i=oSelect.length-1;i>=0;i--)
		{
			oSelect.options[i]=null;
		}
		
		for(var i=0;i<namevalue.length;i++)
		{
			if(namevalue[i].value==undefined)
			{
				oSelect.options[oSelect.length]=new Option(namevalue[i].name);
				content+=namevalue[i].name+self.delimiter+namevalue[i].name+self.delimiter;
			}
			else
			{
				opt=new Option(namevalue[i].name,namevalue[i].value);
				oSelect.options[oSelect.length]=opt;
				content+=namevalue[i].name+self.delimiter+namevalue[i].value+self.delimiter;
			}
		}		

		if(content.substr(content.length-1,1)==self.delimiter)
		{
			content=content.substr(0,content.length-1);
		}
	
		if(oHidden=document.getElementById(self.hiddenId))
		{
			oHidden.value=content;
		}
		
		if(oSelect.selectedIndex>-1)
		{
			if(oSelect.fireEvent)
			{
				oSelect.fireEvent('onchange');
			}
			else if(oSelect.dispatchEvent)
			{
				var oEvent=document.createEvent('HTMLEvents');
				oEvent.initEvent('change',true,true);
				oSelect.dispatchEvent(oEvent);
			}
		}
	}
}



function contactCheck(fieldId,txtValue)
 {
	if ($(fieldId).value==""){
     $(fieldId).style.color="#A5A5A5";  
		 $(fieldId).value=txtValue;  
     }

 }
function contactCheckBox(fieldId,txtValue)
 {
	if ($(fieldId).innerHTML==""){
     $(fieldId).style.color="#A5A5A5";  
		 $(fieldId).innerHTML=txtValue;  
     }

 }


var imgRotImages;
var imgRotIdx;
var imgRotDur;
var updating = false;

var bannerDur;
var imgBannerImges;
var imgBannerTxt;
var imgBannerLinks;
var banner_array;
		

var imgiconImges;
var imgiconTxt;
var imgiconLinks;
var icon_array;

var IntRate;



Event.observe(window, 'load', function() 
{

//_______________________________________________________________

// News Ticker 2.0

if ($('newrotatorhighlights'))
 {
  showNewsHighlights();

	$("newrotatorhighlights").onmouseover = function () {stopScroll=1;}
	$("newrotatorhighlights").onmouseout = function () {stopScroll=0;highlightsScroll();}



}

//______________________________________________________________

if ($('find_specials_makes')){groupMakesUrl('find_specials_makes');}
if ($('find_service_makes')){groupMakesUrl('find_service_makes');}
if ($('find_research_makes')){groupMakesUrl('find_research_makes');}
if ($('find_testdrive_makes')){groupMakesUrl('find_testdrive_makes');}

	
//_______________________________________________________________

// Group Search Stock Number
 if ($('gInventorySearchStockNumber'))
 {
	   $('stock_number').observe('focus', function() {
				if ($('stock_number').value == "Enter Stock Number"){
	     $('stock_number').style.color="#000000";    
			 $('stock_number').value="";
			 }
	    });
	
		 $("btnsearchStockNum").onclick = function(){
		
						if ($('stock_number').value == "Enter Stock Number"){
						  alert("Please enter a value for the \"Stock Number\" field.");
							return;
             }
					  else
					  	if (!validRequired($("stock_number"),"Stock Number")) return;


				    window.location.href = "searchredirect.aspx?stock=" + $("stock_number").value;			   
	
			}

 }


//_______________________________________________________________

// New Group Search

 if ($('gInventorySearchNewWidget'))
 {

  if (IntRate){
   $('aprnew').value=IntRate;
   }

	$("btnsearchnewprice").onclick = function () {$('searchnewprice').style.display='block';$('searchnewpayment').style.display='none';$('searchnewpayment2').style.display='none';}
	$("btnsearchnewpayment").onclick = function () {$('searchnewpayment').style.display='block';$('searchnewpayment2').style.display='block';$('searchnewprice').style.display='none';}
//	$("searchnewpaymentD1").onclick = function () {$('searchnewpayment2').style.display='block';}

  groupNewMake();
  $('selNewModel').disabled = true;
	groupNewBodyStyles();

  $('selNewMake').observe('change', groupNewModel);
	 $("btnsearchnewfind").onclick = function(){
 	   document.formHome.type.value = "N";
     trackWidget('31','');
		  // submit
		  document.formHome.action = '/group-search.aspx';
		  document.formHome.submit();
		}


 }


//___________________________________ Used Group Search

 if ($('gInventorySearchUsedWidget'))
 {

  if (IntRate){
   $('aprused').value=IntRate;
   }
    
	$("btnsearchusedprice").onclick = function () {$('searchusedprice').style.display='block';$('searchusedpayment').style.display='none';$('searchusedpayment2').style.display='none';}
	$("btnsearchusedpayment").onclick = function () {$('searchusedpayment').style.display='block';$('searchusedpayment2').style.display='block';$('searchusedprice').style.display='none';}
//	$("searchusedpaymentD1").onclick = function () {$('searchusedpayment2').style.display='block';}

  groupUsedMake();
  $('selUsedModel').disabled = true;
	groupUsedBodyStyles();

  $('selUsedMake').observe('change', groupUsedModel);
 $("btnsearchusedfind").onclick = function(){

	  document.formHome.type.value = "U";
    trackWidget('32','');
    // submit
  	document.formHome.action = '/group-search.aspx';
	  document.formHome.submit();
}



 }

 if ($('gInventorySearchUsedWidget') || $('gInventorySearchNewWidget')){
	  fillGroupListsAjax();
 }






//________________________________ VVC 3.0 Gallery

 if ($('vvc3GalleryWidget'))
 {


	
	$("vvc3ginfoBar").onclick = function () {galleryType='info';changeDiv();}
	$("vvc3ginfoBar").onmouseover = function () {this.className = "over";}
	$("vvc3ginfoBar").onmouseout = function () {this.className = "";clearTimeout(galleryTimer);}

	$("vvc3g_video").onmouseover = function () {this.className = "over";}
	$("vvc3g_video").onmouseout = function () {this.className = "";}
	$("vvc3g_video").onclick = function () {galleryType='video';changeDiv();clearTimeout(galleryTimer);}

	$("vvc3g_gallery").onmouseover = function () {this.className = "over";}
	$("vvc3g_gallery").onmouseout = function () {this.className = "";}
	$("vvc3g_gallery").onclick = function () {galleryType='gallery';changeDiv();clearTimeout(galleryTimer);}

	$("vvc3g_exterior").onmouseover = function () {this.className = "over";}
	$("vvc3g_exterior").onmouseout = function () {this.className = "";}
	$("vvc3g_exterior").onclick = function () {galleryType='ext';changeDiv();clearTimeout(galleryTimer);}

	$("vvc3g_interior").onmouseover = function () {this.className = "over";}
	$("vvc3g_interior").onmouseout = function () {this.className = "";}
	$("vvc3g_interior").onclick = function () {galleryType='int';changeDiv();clearTimeout(galleryTimer);}

	$("vvc3g_color").onmouseover = function () {this.className = "over";}
	$("vvc3g_color").onmouseout = function () {this.className = "";}
	$("vvc3g_color").onclick = function () {galleryType='color';changeDiv();clearTimeout(galleryTimer);}

	$("vvc3g_more").onmouseover = function () {this.className = "over";}
	$("vvc3g_more").onmouseout = function () {this.className = "";}
	$("vvc3g_more").onclick = function () {galleryType='info';changeDiv();clearTimeout(galleryTimer);}
	
  vvc3Fill();

 //vvc3gActivateTab();


$('vvc3list').observe('change',function() {
    var url= "/home-ajax.aspx?fa=get_vvc_spins&" + $("vvc3list").options[$("vvc3list").selectedIndex].value;
	  new Ajax.Request(url, {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
       videoFile=transport.responseJSON.videofile;
			 izmoFile=transport.responseJSON.izmofile;
    	 changeDiv();
			}
		});
	});

 }



//________________________________ VVC3


 if ($('virtualVehicleCenter3Widget'))
 {
	vvc3Fill();
	
	$("infoBar").onclick = function () {galleryType='info';changeDiv();}
	$("infoBar").onmouseover = function () {this.className = "over";}
	$("infoBar").onmouseout = function () {this.className = "";}

	$("vvc3_video").onmouseover = function () {this.className = "over";}
	$("vvc3_video").onmouseout = function () {this.className = "";}
	$("vvc3_video").onclick = function () {galleryType='video';$('vvc3TitleBox').className = "vvc3TitleVideo";changeDiv();}

	$("vvc3_gallery").onmouseover = function () {this.className = "over";}
	$("vvc3_gallery").onmouseout = function () {this.className = "";}
	$("vvc3_gallery").onclick = function () {galleryType='gallery';$('vvc3TitleBox').className = "vvc3TitleGallery";changeDiv();}

	$("vvc3_exterior").onmouseover = function () {this.className = "over";}
	$("vvc3_exterior").onmouseout = function () {this.className = "";}
	$("vvc3_exterior").onclick = function () {galleryType='ext';$('vvc3TitleBox').className = "vvc3TitleExt";changeDiv();}

	$("vvc3_interior").onmouseover = function () {this.className = "over";}
	$("vvc3_interior").onmouseout = function () {this.className = "";}
	$("vvc3_interior").onclick = function () {galleryType='int';$('vvc3TitleBox').className = "vvc3TitleInt";changeDiv();}

	$("vvc3_color").onmouseover = function () {this.className = "over";}
	$("vvc3_color").onmouseout = function () {this.className = "";}
	$("vvc3_color").onclick = function () {galleryType='color';$('vvc3TitleBox').className = "vvc3TitleColor";changeDiv();}

	$("vvc3_more").onmouseover = function () {this.className = "over";}
	$("vvc3_more").onmouseout = function () {this.className = "";}
	$("vvc3_more").onclick = function () {galleryType='info';$('vvc3TitleBox').className = "vvc3TitleInfo";changeDiv();}
	

$('vvc3list').observe('change',function() {
    var url= "/home-ajax.aspx?fa=get_vvc_spins&" + $("vvc3list").options[$("vvc3list").selectedIndex].value;
	  new Ajax.Request(url, {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
       videoFile=transport.responseJSON.videofile;
			 izmoFile=transport.responseJSON.izmofile;
       	$('vvc3TitleBox').className ="vvc3TitleVideo";
			 changeDiv();
			}
		});
	});

}



//________________________________ quick quote

  if($('qqnew'))
  {
    // register events
    $('qqnew').observe('click', qqModeChange);
    $('qqused').observe('click', qqModeChange);
    $('qqyear').observe('change', qqYearChange);
    $('qqmake').observe('change', qqMakeChange);
    $('qqSubmit').observe('click', qqSubmit);
    
    // set initial control states
    $('qqyear').disabled = true;
    $('qqmake').disabled = true;
    $('qqmodel').disabled = true;
  }  


//______________________________________ Manufacture Special Scroller

  if($('manufscrollarea'))
  {
    new Ajax.Request("/home-ajax.aspx?fa=get_man_specials", { method: 'get',
    onSuccess: function(transport) 
    {
     if (transport.responseText.blank())
       {
          Element.remove('rotatorup');
          Element.remove('rotatordown');
        }  
      else
        { 
        $("scrollarea").insert(transport.responseText); 
         new Rotator("newsrotator"); 
        }
    }
  });
  } 
 else{

  //Special Scroller
  if($('scrollarea'))
  {
    new Ajax.Request("/home-ajax.aspx?fa=get_specials", { method: 'get',
    onSuccess: function(transport) 
    {
     if (transport.responseText.blank())
       {
          Element.remove('rotatorup');
          Element.remove('rotatordown');
        }  
      else
        { 
        $("scrollarea").insert(transport.responseText); 
         new Rotator("newsrotator"); 
        }
    }
  });
  } 



}
  



//____________________________________   //Special Ticker

  if($('specialTickerWidget'))
  {
	
    new Ajax.Request("/home-ajax.aspx?fa=get_spticker", { method: 'get',
    onSuccess: function(transport) 
    {
			
		  $("highlights").insert(transport.responseText); 
			$("heightCheck").insert(transport.responseText); 
			 repeatHeight = $('heightCheck').scrollHeight; //get the current height so we know when to wrap
			$('heightCheck').innerHTML='';
      $("heightCheck").style.display='none';
       if(repeatHeight>=280){      
					$('highlights').innerHTML = $('highlights').innerHTML + $('highlights').innerHTML ;	
			 }
			x = setTimeout("scrollMe()",1000)

    }
  });

			
  } 
//____________________________________  Banner

if ($('bannerWidget')){

	if (bannerParams)
		{
			imgBannerImges = bannerParams.imagelist;
		  imgBannerTxt = bannerParams.titlelist;
			imgBannerLinks = bannerParams.linklist;
		
		  bannerDur = bannerParams.imagedur*1000;
			var bannerWidth=bannerParams.imagewi;
			var bannerHeight=bannerParams.imagehi;
  
      $('bannerStart').style.display='none'; 
		  $('bannerLoader').style.background = 'url('+imgBannerImges[0]+')';
			$('bannerLoader').style.width= bannerWidth+'px';
			$('bannerLoader').style.height= bannerHeight+'px';
			$('wBannerLink').href=imgBannerLinks[0];
			$('wBannerLink').title=imgBannerTxt[0];
			
		  $('bannerAppear').style.background = 'url('+imgBannerImges[1]+')';
			$('bannerAppear').style.width= bannerWidth+'px';
			$('bannerAppear').style.height=bannerHeight+'px';

		
			banner_array = new Array();
			for (var i=0;i<=imgBannerImges.length-1;i++){
			  var tmpImg = new Image(bannerWidth,bannerHeight);
				tmpImg.src = imgBannerImges[i];
				banner_array[i] = tmpImg;
			}
	
   	setTimeout("bannerAppear(0, 1)", bannerDur);

	 }
}


//_______________________________  Inventory Carousel Horizontal

  if($('inventorycarusel'))
  {
//    new Ajax.Request("/home-ajax.aspx?fa=get_carusel&type=s", { method: 'get',
//    onSuccess: function(transport) 
//    {
//     if (transport.responseText.blank())
//       {

//        }
//      else
//        { 
//	        $("iccontainer").insert(transport.responseText); 
	         new UI.Carousel("horizontal_carousel");
//        }
//    }
//  });
  } 

//__________________________________ Inventory Carusel Vertical

  if($('inventorycaruselVertical'))
  {
    new Ajax.Request("/home-ajax.aspx?fa=get_carusel&type=s", { method: 'get',
    onSuccess: function(transport) 
    {
     if (transport.responseText.blank()){
 
       }
       
      else
        { 
	        $("iccontainer").insert(transport.responseText); 
	         new UI.Carousel("vertical_carousel", {direction: "vertical"});
	       
        }
    }
  });
  } 

//________________________________  Inventory Show Case

 if($('inventoryshowcase'))
  {
    new Ajax.Request("/home-ajax.aspx?fa=get_carusel", { method: 'get',
    onSuccess: function(transport) 
    {
     if (transport.responseText.blank())
       {
         // Element.remove('previous_button');
          //Element.remove('next_button');
        }  
      else
        { 
        $("horizontal").insert(transport.responseText); 

 //      	new Showcase.Horizontal($$('#horizontal ul li'), $$('#horizontal a.controls'), {duration: 0.3,size:5});
    new Showcase.Horizontal($$('#horizontal ul li'), $$('#horizontal a.controls'), {duration: 0.3,size:9});
		    }
     }
    });
  }

//_______________________________  contact Us


    if($('contactUsWidget'))
  {
    // register events
    $('cufirstname').observe('focus', function() {
			if ($('cufirstname').value == "First Name"){
     $('cufirstname').style.color="#000000";    
		 $('cufirstname').value="";
		 }
    });


    $('culastname').observe('focus', function() {
			if ($('culastname').value == "Last Name"){
     $('culastname').style.color="#000000"; 
		 $('culastname').value="";
		}
   });


   $('cuemail').observe('focus', function() {
			if ($('cuemail').value == "Email Address"){
     $('cuemail').style.color="#000000"; 
		 $('cuemail').value="";   
    }
   });


   $('cuphone').observe('focus', function() {
		 if ($('cuphone').value == "Phone Number"){
	     $('cuphone').style.color="#000000";  
			 $('cuphone').value="";
			}  
   });

   $('cuComments').observe('focus', function() {
 		if ($('cuComments').innerHTML== "Comments"){
     $('cuComments').style.color="#000000";
		 $('cuComments').innerHTML="";    
     }
		
   });
     $('cuSubmit').observe('click',cuSubmit);
  }  





function cuSubmit(event)
{
  // validate form input

	if ($('cufirstname').value == "First Name"){
	  alert("Please enter a value for the \"First Name\" field.");
		return;
  }
  else
  {
  	if (!validRequired($("cufirstname"),"First Name")) return;
  }

	if ($('culastname').value == "Last Name"){
	   alert("Please enter a value for the \"Last Name\" field.");
		return;
  }
  else
  {
  	if (!validRequired($("culastname"),"Last Name")) return;
	}

	if ($('cuemail').value == "Email Address"){
	  alert("Please enter a value for the \"Email Address\" field.");
		return;
  }
  else
  {
    if (!validEmail($("cuemail"),"Email",true)) return;
  }

	if ($('cuphone').value == "Phone Number"){
  	alert("Please enter a value for the \"phone Number\" field.");
		return;
  }
  else
  {
	  if (!validPhone($("cuphone"),"Phone",true)) return;
  }

  

  var reqUrl = "/home-ajax.aspx?ppc=" + dealerOnPoiPpc + "&vid=" + dealerOnPoiVisitId + "&cid=" + dealerOnPoiClientId + "&fa=";
  reqUrl = reqUrl + "email_cu&firstname=" + $("cufirstname").value + "&lastname=" + $("culastname").value + "&phone=" + $("cuphone").value + "&email=" + $("cuemail").value + "&comment=" + $("cuComments").innerHTML ;

 if($("bloglead"))
   reqUrl=reqUrl + "&blog=1";
  

  // submit
  trackWidget('23','');

  window.location.href=reqUrl;

}
//_________________________________________________




    if($('preApprovedWidget'))
  {
    // register events
    $('pafirstname').observe('focus', function() {
			if ($('pafirstname').value == "First Name"){
     $('pafirstname').style.color="#000000";    
		 $('pafirstname').value="";
		 }
    });


    $('palastname').observe('focus', function() {
			if ($('palastname').value == "Last Name"){
     $('palastname').style.color="#000000"; 
		 $('palastname').value="";
		}
   });


   $('paemail').observe('focus', function() {
			if ($('paemail').value == "Email Address"){
     $('paemail').style.color="#000000"; 
		 $('paemail').value="";   
    }
   });


   $('paphone').observe('focus', function() {
		 if ($('paphone').value == "Phone Number"){
	     $('paphone').style.color="#000000";  
			 $('paphone').value="";
			}  
   });

    $('paComments').observe('focus', function() {
 		if ($('paComments').innerHTML== "Comments"){
     $('paComments').style.color="#000000";
		 $('paComments').innerHTML="";    
     }
		
   });

     $('paSubmit').observe('click',paSubmit);
  }  


function paSubmit(event)
{
  // validate form input
	if ($('pafirstname').value == "First Name"){
	  alert("Please enter a value for the \"First Name\" field.");
		return;
	  }
	  else
	  {
	  	if (!validRequired($("pafirstname"),"First Name")) return;
	  }

	if ($('palastname').value == "Last Name"){
	   alert("Please enter a value for the \"Last Name\" field.");
		return;
	  }
	  else
	  {
	  	if (!validRequired($("palastname"),"Last Name")) return;
		}

	if ($('paemail').value == "Email Address"){
	  alert("Please enter a value for the \"Email Address\" field.");
		return;
	  }
	  else
	  {
	    if (!validEmail($("paemail"),"Email",true)) return;
	  }

	if ($('paphone').value == "Phone Number"){
  	alert("Please enter a value for the \"phone Number\" field.");
		return;
	  }
	  else
	  {
		  if (!validPhone($("paphone"),"Phone",true)) return;
	  }


		var FmtStr="";
    var index = 0;
    var LimitCheck;
    var PhoneNumberInitialString=$('paphone').value;
    var paArea="";
		var paPrefix="";
    var paSuffix="";

    LimitCheck = PhoneNumberInitialString.length;
    while (index != LimitCheck)
      {
        if (isNaN(parseInt(PhoneNumberInitialString.charAt(index))))
          { }
        else
          { FmtStr = FmtStr + PhoneNumberInitialString.charAt(index); }
        index = index + 1;
      }
    if (FmtStr.length == 10)
      {
         paArea= FmtStr.substring(0,3);
				 paPrefix= FmtStr.substring(3,6);
				 paSuffix= FmtStr.substring(6,10);
      }


  
   var reqUrl = "/lead.aspx?ppc=" + dealerOnPoiPpc + "&vid=" + dealerOnPoiVisitId + "&cid=" + dealerOnPoiClientId + "&form=pa&";
   reqUrl= reqUrl + "phone=" + $('paphone').value + "&name=" + $('pafirstname').value + "&lastname=" + $('palastname').value;
   reqUrl= reqUrl + "&email=" + $('paemail').value + "&comment=" + $("paComments").innerHTML ;
   reqUrl= reqUrl + "&pha=" + paArea + "&php=" + paPrefix + "&phs=" + paSuffix;

   trackWidget('46','');
   window.location.href=reqUrl;

}

//-________________________________________________


  if($('isnew'))
  {
    // register events

    $('isnew').observe('click', isModeChange);
    $('isused').observe('click', isModeChange);
    $('isyear').observe('change', isYearChange);
    $('ismake').observe('change', isMakeChange);
    $('isbodyStyle').observe('change', isbodyStyleChange);
    $('isSubmit').observe('click',isSubmit);

   // set initial control states
  //  $('isyear').disabled = true;
  //  $('ismake').disabled = true;
  //  $('ismodel').disabled = true;
  //  $('isbodyStyle').disabled = true;
  //  $('isprice').disabled = true;
  }
//__________ New Inventory search

 else if ($('isyear')){
  
    $('isyear').observe('change', isYearChange);
    $('ismake').observe('change', isMakeChange);
    $('isbodyStyle').observe('change', isbodyStyleChange);
    $('isSubmit').observe('click',isSubmit);
		$('isyear').disabled = true;
    $('ismake').disabled = true;
    $('ismodel').disabled = true;
    $('isbodyStyle').disabled = true;
    $('isprice').disabled = true;
		
		isModeChange();

	}  
  
  //_________________________Payment Search 
    
  if($('afnew'))
  {
    $('afpayment').value = "350";
    $('afloanTerm').value = "60";
    $('afapr').value = "3.9";
    $('afdownPayment').value = "2000";
      
    $('afSubmit').observe('click', afSubmit);
  }

  // VVC

  if($('vvclist'))
  {
    
    vvcFill();
    vvcrespondTomouse();

    $('vvclist').observe('change',function() {
    $("frm_vvc").src = 'http://assets.dealeron.com/vvc_dealeron.asp?' + $("vvclist").options[$("vvclist").selectedIndex].value;
	});


    $('vvc_exterior').observe('click',function() {
    $("frm_vvc").src = 'http://assets.dealeron.com/vvc_dealeron.asp?' + $("vvclist").options[$("vvclist").selectedIndex].value + '&type=ext&dId=' + $('dealerIdvvc').value;
	});

    $('vvc_interior').observe('click',function() {
    $("frm_vvc").src = 'http://assets.dealeron.com/vvc_dealeron.asp?' + $("vvclist").options[$("vvclist").selectedIndex].value + '&type=int&dId=' + $('dealerIdvvc').value;
	});

    $('vvc_gallery').observe('click',function() {
    $("frm_vvc").src = 'http://assets.dealeron.com/vvc_dealeron.asp?' + $("vvclist").options[$("vvclist").selectedIndex].value + '&type=gall&dId=' + $('dealerIdvvc').value;
  });

    $('vvc_more').observe('click',function() {
    	$("frm_vvc").src="/Manufacturer_Info.aspx?type=vvc";
	});
   
  }  
//____________________________________________________ News Ticker

if ($('newstickerrotator'))
 {
  if (newsTickerParams)
   {
	  new pausescroller(newsTickerParams, "newsScroller", "someclass", 3000);
    }
 }

//____________________________________________________ video player


 if ($("videoPlayer"))
 {
  loadVideoFile();
  setTimeout(flahsPlayerText, 1500);
 }

//____________________________________________________ video player Wide


 if ($("videoPlayerWide"))
 {
  loadVideoFileWide();
  setTimeout(flahsPlayerText, 1500);
 }

//____________________________________________________ Brows Inventory



 if ($('BrowseInventoryWidget'))
 {
   birespondTomouse();

   var dealerMake;
  
   new Ajax.Request("/home-ajax.aspx?fa=get_dmake", { method: 'get',
	 evalJSON: 'force',
    onSuccess: function(transport) 
    {
      dealerMake=transport.responseJSON.dmake;
	
     }

    });


  $('browseInventoryNew').observe('click', function() {
//	   	 Modalbox.show(' <IFRAME id="frm_data_brw" src="/noclick_new.aspx" frameBorder=0 width=555  scrolling=no height=700> </IFRAME>', {title: "Browse New Inventory", width: 575}); return false;
  window.location.href="/searchnew.aspx";
   });

  $('browseInventoryUsed').observe('click', function() {

  // if(dealerMake=="HONDA")
	//    {
	     window.location.href="/searchused.aspx";
	//		}
//	   else
//	    { 
//			Modalbox.show(' <IFRAME id="frm_data_brw" src="/noclick_used.aspx" frameBorder=0 width=555  scrolling=no height=700> </IFRAME>', {title: "Browse Used Inventory", width: 575}); return false;
//			}
   });

  }


//____________________________________________________ Group Map


 if ($('groupMapWidget'))
 {

$('gmap').src="http://maps.dealeron.com/mapgroup.aspx?id=" + gmDealerId + "&zipCode=&width=437&height=220&zoom=7";

}
});

function loadVideoFile()
{
  if (videoPlayerParams)
  {
   path_flv = videoPlayerParams.flvPath;
   playertype = videoPlayerParams.type;
   playermode=videoPlayerParams.mode;

	 key_flv = videoPlayerParams.flvKey;
	 if(key_flv != null && key_flv != 'default'){
     // Get model base on Keyword
	   var keyword="default";
   	 var videoValue;
		 var index=0;
		

     // If we have PoiKeyword
     if (poiKeyword>"")
	    {
			 	for (i=0; i<key_flv.length; i++) {
					videoValue=key_flv[i].toUpperCase();
				 	if(videoValue.indexOf(poiKeyword) >= 0)
				  	index=i;
					}
	
		 		 if ( playertype=="video")
				  	var vidPlyrFo = new FlashObject("/assets/widgets/videoPlayer.swf?path='" + path_flv[index] + "'&mode='" + playermode + "'", "mainVideo", "250", "250", "0", "#000000");
				 else
				    var vidPlyrFo = new FlashObject("/assets/widgets/audioPlayer.swf?path='" + path_flv[index] + "'&mode='" + playermode + "'", "mainAudio", "250", "25", "0", "#000000");
				 
				 vidPlyrFo.addParam('wmode', 'transparent');
		   	 vidPlyrFo.write("flashmovie");
		 }
   }
	 else{	 

		 if ( playertype=="video")
		   	var vidPlyrFo = new FlashObject("/assets/widgets/videoPlayer.swf?path='" + path_flv + "'&mode='" + playermode + "'", "main", "250", "250", "0", "#000000");		   
     else
		    var vidPlyrFo = new FlashObject("/assets/widgets/audioPlayer.swf?path='" + path_flv + "'&mode='" + playermode + "'", "main", "270", "25", "0", "#000000");
		 
		 vidPlyrFo.addParam('wmode', 'transparent');
   	 vidPlyrFo.write("flashmovie");

    }

  
  }

}


//------------------------------

function loadVideoFileWide()
{
  if (videoPlayerWiParams)
  {
   path_flv = videoPlayerWiParams.flvPath;
   playertype = videoPlayerWiParams.type;
   playermode=videoPlayerWiParams.mode;
   playerWidth = videoPlayerWiParams.fwidth;
   playerHeight=videoPlayerWiParams.fheight;
	 key_flv = videoPlayerWiParams.flvKey;

	 if(key_flv != null){
	   // Get model base on Keyword
		   var keyword="default";
	   	 var videoValue;
			 var index=0;
		

    // If we have PoiKeyword
	    if (poiKeyword>"")
		    {
					 	for (i=0; i<key_flv.length; i++) {
							videoValue=key_flv[i].toUpperCase();
						 	if(videoValue.indexOf(poiKeyword) >= 0)
						  	index=i;
							}
			
				 		var vidPlyrFo = new FlashObject("/assets/widgets/videoPlayerWide.swf?path='" + path_flv[index] + "'&mode='" + playermode + "'&mWidth='" + playerWidth + "'&mHeight='" + playerHeight + "'", "mainVideo", "630", "250", "0", "#000000");
					  vidPlyrFo.addParam('wmode', 'transparent');
				  	vidPlyrFo.write("flashmovieWide");
				
		    }
		}
	 else
    {
	 		var vidPlyrFo = new FlashObject("/assets/widgets/videoPlayerWide.swf?path='" + path_flv[0] + "'&mode='" + playermode + "'&mWidth='" + playerWidth + "'&mHeight='" + playerHeight + "'", "mainVideo", "630", "250", "0", "#000000");
    }
	
	
  	 vidPlyrFo.addParam('wmode', 'transparent');
   	 vidPlyrFo.write("flashmovieWide");
  
  }


}


//------------------------------

function flahsPlayerText()
{
if ($('playerText'))
	{
		$("playerText").style.display="block";
	}
}

// Image Rotator

if ($('imageRotator'))
{
	if (imageRotatorParams)
	{
		imgRotImages = imageRotatorParams.imagelist;
		imgRotDur = imageRotatorParams.imagedur;
    $('imageRotator').style.height=imageRotatorParams.imagehi + "px";
 		$('imageRotator').style.width=imageRotatorParams.imagewi + "px";
		imgRotIdx = 0;
		rotateRotator();
	}

}

function rotateRotator()
{
 
  if (imgRotIdx >= imgRotImages.length) imgRotIdx = 0;
 	$("imageRotatorimg").src = imgRotImages[imgRotIdx];

	new Effect.Opacity("imageRotatorimg", {duration:1.0, from:0.2, to:1.0});
	setTimeout("rotateRotatorFadeOut()", imgRotDur * 1000);
   imgRotIdx++;
}

function rotateRotatorFadeOut()
{
	new Effect.Opacity("imageRotatorimg", {duration:1.0, from:1.0, to:0.0});
	setTimeout("rotateRotator()", 1000);
}




function vvcFill(event)
{
   new Ajax.Request("/home-ajax.aspx?fa=get_vvc", {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON.vvc_list, "vvclist");
	  $("vvclist").selectedIndex = transport.responseJSON.selitem;
      $("frm_vvc").src="http://assets.dealeron.com/vvc_dealeron.asp?"+$("vvclist").options[$("vvclist").selectedIndex].value;
     
    }
  });

}
 function birespondTomouse(event) {

 	$("browseInventoryNew").onmouseover = function () {this.className = "over";}
	$("browseInventoryNew").onmouseout = function () {this.className = "";}

	$("browseInventoryUsed").onmouseover = function () {this.className = "over";}
	$("browseInventoryUsed").onmouseout = function () {this.className = "";}
}

 function vvcrespondTomouse(event) {
	$("vvc_exterior").onmouseover = function () {this.className = "over";}
	$("vvc_exterior").onmouseout = function () {this.className = "";}
			
	$("vvc_interior").onmouseover = function () {this.className = "over";}
	$("vvc_interior").onmouseout = function () {this.className = "";}

	$("vvc_gallery").onmouseover = function () {this.className = "over";}
	$("vvc_gallery").onmouseout = function () {this.className = "";}

	$("vvc_more").onmouseover = function () {this.className = "over";}
	$("vvc_more").onmouseout = function () {this.className = "";}
}

// mode changes
function qqModeChange(event)
{
  if (updating) return;
  var element = event.element();
  var qType = "u";
  
  // see which mode we're in
  qType = ((element.id == "qqnew") ? "n" : "u");
  
  updating = true;
  // get years for that mode
  new Ajax.Request("/home-ajax.aspx?fa=get_years&type=" + qType + "&select=1", {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "qqyear");
      updating = false;   
      if ($('qqyear').options.length == 2)
      {
        //$('qqyear').options[1].selected = true;
      }
    }
  });

  // enable year
  $('qqyear').disabled = false;

  // disable make/model dropdowns
  $('qqmake').selectedIndex = 0;
  $('qqmodel').selectedIndex = 0;
  $('qqmake').disabled = true;
  $('qqmodel').disabled = true;
}

// year changes
function qqYearChange(event)
{
//  if (updating || ($('qqnew').checked && $('qqmake').options.length == 2)) return;
  if (updating) return;
  
  var reqUrl = "/home-ajax.aspx?fa=";
  
  // see which mode we're in
  if ($('qqnew').checked)
  {
    reqUrl = reqUrl + "new_makes&year=" + $('qqyear').options[$('qqyear').selectedIndex].value + "&select=1";
  }
  else
  {
    reqUrl = reqUrl + "used_makes&year=" + $('qqyear').options[$('qqyear').selectedIndex].value + "&select=1";
  }
  
  // based on mode and year, get available makes
  updating = true;
  new Ajax.Request(reqUrl, {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "qqmake");    
      updating = false;  
      if ($('qqmake').options.length == 2)
      {
        $('qqmake').options[1].selected = true;
         qqMakeChange(null);
      }
    }
  });
  

  // enable make
  $('qqmake').disabled = false;
  
  // disable model dropdown
  $('qqmodel').disabled = true;
  

}

// make changes
function qqMakeChange(event)
{
  if (updating) return;
  var reqUrl = "/home-ajax.aspx?fa=";

  // see which mode we're in
  if ($('qqnew').checked)
  {
    reqUrl = reqUrl + "new_models&year=" + $('qqyear').options[$('qqyear').selectedIndex].value + "&make=" + $('qqmake').options[$('qqmake').selectedIndex].value + "&select=1";
  }
  else
  {
    reqUrl = reqUrl + "used_models&year=" + $('qqyear').options[$('qqyear').selectedIndex].value + "&make=" + $('qqmake').options[$('qqmake').selectedIndex].value + "&select=1";
  }

  // based on mode year and make, get available models
  updating = true;
  new Ajax.Request(reqUrl, {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "qqmodel");    
      updating = false;  
    }
  });

  // enable model
  $('qqmodel').disabled = false;
}



// submit qq form
function qqSubmit(event)
{
  // validate form input
  if (!validSelected($("qqyear"),"Vehicle Year")) return;
  if (!validSelected($("qqmake"),"Vehicle Make")) return;  
  if (!validSelected($("qqmodel"),"Vehicle Model")) return;  
  if (!validRequired($("qqfirstname"),"First Name")) return;
  if (!validRequired($("qqlastname"),"Last Name")) return;
  if (!validRequired($("qqemail"),"Email")) return;
  if (!validRequired($("qqphone"),"Phone")) return;
  if (!validEmail($("qqemail"),"Email",true)) return;
  if (!validPhone($("qqphone"),"Phone",true)) return;

  
	var vehType;
 	if ($('qqnew').checked)
  {
    vehType = "new";
  }
  else
  {
    vehType = "used";
  }  

  var reqUrl = "/home-ajax.aspx?ppc=" + dealerOnPoiPpc + "&vid=" + dealerOnPoiVisitId + "&cid=" + dealerOnPoiClientId + "&fa=";
  reqUrl = reqUrl + "email_qq&year=" + $('qqyear').options[$('qqyear').selectedIndex].value + "&make=" + $('qqmake').options[$('qqmake').selectedIndex].value + "&model=" + $('qqmodel').options[$('qqmodel').selectedIndex].value + "&";
  reqUrl = reqUrl + "firstname=" + $("qqfirstname").value + "&lastname=" + $("qqlastname").value + "&phone=" + $("qqphone").value + "&email=" + $("qqemail").value + "&type=" + vehType ;

  // submit
  trackWidget('10','');

  window.location.href=reqUrl;

}


// 


// New/Used mode changes
function isModeChange(event)
{

  if (updating) return;
	if($('isnew')){
	  var element = event.element();
	}
  var iType = "n";
  
  fillPriceLists();
  $('isprice').disabled = false;
  $('ismodel').disabled = true;
  $('ismodel').selectedIndex = 0;


  // see which mode we're in
	 if($('isnew')){
	  iType = ((element.id == "isnew") ? "n" : "u");
	 }
  
  updating = true;
  // get years for that mode
  new Ajax.Request("/home-ajax.aspx?fa=get_years&type=" + iType , {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "isyear");
 			$('isyear').options[1].selected = true;
    }

  });
 
  var MType = "new";
	if($('isnew')){
	  MType = ((element.id == "isnew") ? "new" : "used");
	}

 // get make 
  new Ajax.Request("/home-ajax.aspx?fa=" + MType + "_makes", {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "ismake");
			if ($('ismake').options.length == 2)
				{
          $('ismake').options[1].selected = true;
	   			 reqUrl = "/home-ajax.aspx?fa=new_models&year=" + $('isyear').options[$('isyear').selectedIndex].value + "&make=" + $('ismake').options[$('ismake').selectedIndex].value;
				  // based on mode year and make, get available models
				  updating = true;
				  new Ajax.Request(reqUrl, {
				    method: 'get',
				    evalJSON: 'force',
				    onSuccess: function(transport) 
				    {
				      fillSelect(transport.responseJSON, "ismodel");  
							$('ismodel').disabled = false;  
							selectIsModelKeyword();
				      updating = false;  
				    }
				  });
      }
    }

  });


  // get bodystyle
  new Ajax.Request("/home-ajax.aspx?fa=" + MType + "_bodystyles", {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "isbodyStyle");
      updating = false;   
    }

  });

  // enable year
  $('isyear').disabled = false;
  $('ismake').disabled = false;
  $('isbodyStyle').disabled = false;
  
}

function selectIsModelKeyword()
{
  
	 if (poiKeyword>"")
		{
    var checkWord=true; 
    var someNodeList = $('ismodel').getElementsByTagName('option');
		var nodes = $A(someNodeList);
	  for (var index = 0, len = nodes.length; index < len; ++index)
     {
       if (nodes[index].value==poiKeyword)
				{
         $('ismodel').options[index].selected = true;
          checkWord=false;
        }
      }
	  if (checkWord)
	 			$('ismodel').options[1].selected = true;
		}
	}


// year changes
function isYearChange(event)
{
  if (updating) return;
  
  var reqUrl = "/home-ajax.aspx?fa=";
  
  // see which mode we're in
	if($('isnew')){
		if ($('isnew').checked)
		{
			reqUrl = reqUrl + "new_makes";
		}
		else
		{
			reqUrl = reqUrl + "used_makes&year=" + $('isyear').options[$('isyear').selectedIndex].value ;
		}
	}
	else{
		reqUrl = reqUrl + "new_makes";
	}
	
	
  // based on mode and year, get available makes
  updating = true;
  new Ajax.Request(reqUrl, {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "ismake"); 
			if ($('ismake').options.length == 2)
				{
          $('ismake').options[1].selected = true;
			  
				  var reqUrl = "/home-ajax.aspx?fa=";
				
				  // see which mode we're in
					if($('isnew')){
						if ($('isnew').checked)
						{
						reqUrl = reqUrl + "new_models&year=" + $('isyear').options[$('isyear').selectedIndex].value + "&make=" + $('ismake').options[$('ismake').selectedIndex].value;
						}
						else
						{
						 reqUrl = reqUrl + "used_models&year=" + $('isyear').options[$('isyear').selectedIndex].value + "&make=" + $('ismake').options[$('ismake').selectedIndex].value;
						}
					}
					else {
				 		 reqUrl = reqUrl + "new_models&year=" + $('isyear').options[$('isyear').selectedIndex].value + "&make=" + $('ismake').options[$('ismake').selectedIndex].value;
					}
					
				
				  // based on mode year and make, get available models
				  updating = true;
				  new Ajax.Request(reqUrl, {
				    method: 'get',
				    evalJSON: 'force',
				    onSuccess: function(transport) 
				    {
				      fillSelect(transport.responseJSON, "ismodel");    
				      updating = false;  
				    }
				  });
				
				}

		  updating = false;  
    }
  });
  
  // enable make
  $('ismake').disabled = false;

}

// make changes
function isMakeChange(event)
{
  if (updating) return; 
  var reqUrl = "/home-ajax.aspx?fa=";

  // see which mode we're in
	if($('isnew')){
		if ($('isnew').checked)
		{
		reqUrl = reqUrl + "new_models&year=" + $('isyear').options[$('isyear').selectedIndex].value + "&make=" + $('ismake').options[$('ismake').selectedIndex].value;
		}
		else
		{
		 reqUrl = reqUrl + "used_models&year=" + $('isyear').options[$('isyear').selectedIndex].value + "&make=" + $('ismake').options[$('ismake').selectedIndex].value;
		}
	}
	else {
 		 reqUrl = reqUrl + "new_models&year=" + $('isyear').options[$('isyear').selectedIndex].value + "&make=" + $('ismake').options[$('ismake').selectedIndex].value;
	}
	

  // based on mode year and make, get available models
  updating = true;
  new Ajax.Request(reqUrl, {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "ismodel");    
      updating = false;  
    }
  });
 
var reqUrl = "/home-ajax.aspx?fa=";

  // see which mode we're in
	if($('isnew')){
		if ($('isnew').checked)
		{
			reqUrl = reqUrl + "new_bodystyles&make=" + $('ismake').options[$('ismake').selectedIndex].value;
		}
		else
		{
			reqUrl = reqUrl + "used_bodystyles&make=" + $('ismake').options[$('ismake').selectedIndex].value;
		}
	}
	else{
			reqUrl = reqUrl + "new_bodystyles&make=" + $('ismake').options[$('ismake').selectedIndex].value;
	}
 // get bodystyle
 updating = true;
  new Ajax.Request(reqUrl, {
     method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "isbodyStyle");
      updating = false;   
    }

  });


  // enable model
  $('ismodel').disabled = false;
}

// bodyStyle Changes
function isbodyStyleChange(event)
{

}

// submit is form
function isSubmit(event)
{

  var price_array;
	var priceValue,price1,price2,bodyStyle ;

 if (  $('isbodyStyle').selectedIndex == 0)
  {
   bodyStyle="";
  } 
 else
  {
		if($('isnew'))
    {
		 if ($('isnew').checked)
			{
			   bodyStyle=$("isbodyStyle").options[$("isbodyStyle").selectedIndex].text;
			}
		 else
			{
			   bodyStyle=$('isbodyStyle').value;
			}
    }
  
  } 

	priceValue=$("isprice").value;

  if (  $('isprice').selectedIndex == 0)
  {
  price1="";
  price2="";

  }
  else
  {
  price_array=priceValue.split(",");
  price1=price_array[0];
  price2=price_array[1];
  }

  
  var reqUrl = "/home-ajax.aspx?fa=";
  reqUrl = reqUrl + "redirect_search&year=" + $("isyear").value + "&make=" + $("ismake").value + "&model=" + $("ismodel").value + "&bodystyle=" + bodyStyle + "&price1=" + price1 + "&price2=" + price2 + "&hpForm=1";

  // submit
	if($('isnew')){
			 if ($('isnew').checked)
				{
				 reqUrl = reqUrl + "&type=new";
				}
			 else
				{
				 reqUrl = reqUrl + "&type=used";
				}

	}
	else{
		 reqUrl = reqUrl + "&type=new";
	}

  trackWidget('11','');
  window.location.href=reqUrl;
  
}

function fillPriceLists()
{
  var list = "[";
  var today = new Date();
   
  list = "[";
  list += "{\"value\":\"\",\"name\":\"- Any Price -\"},";
  list += "{\"value\":\"0,5000\",\"name\":\"Up to $5,000\"},";
  list += "{\"value\":\"5000,10000\",\"name\":\"$5,001 to $10,000\"},";
  list += "{\"value\":\"10001,15000\",\"name\":\"$10,001 to $15,000\"},";
  list += "{\"value\":\"15001,20000\",\"name\":\"$15,001 to $20,000\"},";
  list += "{\"value\":\"20001,25000\",\"name\":\"$20,001 to $25,000\"},";
  list += "{\"value\":\"25001,30000\",\"name\":\"$25,001 to $30,000\"},";
  list += "{\"value\":\"30001,40000\",\"name\":\"$30,001 to $40,000\"},";
  list += "{\"value\":\"40001,50000\",\"name\":\"$40,001 to $50,000\"},";
  list += "{\"value\":\"50001,60000\",\"name\":\"$50,001 to $60,000\"},";
  list += "{\"value\":\"60000,500000\",\"name\":\"$60,001 or more+\"}";
  list += "]";
 
  eval("var prices =" + list);
 
  fillSelect(prices, "isprice");
  updating = false;   

}



function afSubmit(event)
{
  var total = 1.0;

 if (Trim($('afdownPayment').value) == "")
 {
  alert('Please enter a value for the Down Payment field.');
  $('afdownPayment').focus();
  return false;

 }

	if (!validNumber($("afdownPayment"),"Down Payment")) return;

  var term = Number($("afloanTerm").value);
  var apr = parseFloat($("afapr").value) / 100 / 12;
  var pmt = parseFloat($("afpayment").value);
  for( var j = 0; j < term; j++)
  {
    total = total * (1.0 + apr);
  }
 
  total = ((total - 1) * pmt) / (total * apr) + 0.5
  total = Math.round(total)
  total = total + parseFloat($("afdownPayment").value);
  


  var reqUrl = "/home-ajax.aspx?fa=";
  reqUrl = reqUrl + "redirect_search&price2=" + total + "&hpForm=1";

  // submit
 if ($('afnew').checked)
  {
   reqUrl = reqUrl + "&type=new";
	 trackWidget('13','');
	 window.location.href=reqUrl;
  }
 else
  {
   if ($('afused').checked)
    {
     reqUrl = reqUrl + "&type=used";
		 trackWidget('13','');
	   window.location.href=reqUrl;
    }
   else
    {
			alert("Please select Vehicle Type.");

    }
  }


}

//__________________ Banner

	function onBannerAppear(first_image, second_image,num){		
		$('bannerLoader').style.background = 'url('+first_image+')';
		$('wBannerLink').href=imgBannerLinks[num];
		$('wBannerLink').title=imgBannerTxt[num];
		$('bannerAppear').style.display = 'none';
		$('bannerAppear').style.background = 'url('+second_image+')';				
	}
	
	function bannerAppear(pic_one_id, pic_two_id){
		
		var one_id, two_id;
		new Effect.Appear('bannerAppear');
 		
	  one_id = pic_two_id;
		if(pic_two_id == banner_array.length-1) 	two_id = 0;
			else 	two_id = pic_two_id+1;
		
		pic_one = banner_array[one_id];
		pic_two = banner_array[two_id];
		
		setTimeout("onBannerAppear('"+pic_one.src+"', '"+pic_two.src+"','"+two_id+"')", bannerDur-1000);
		setTimeout("bannerAppear("+one_id+", "+two_id+")", bannerDur);		
	}



//__________________ VVC3

function vvc3Fill(event)
{
	 new Ajax.Request("/home-ajax.aspx?fa=get_vvc", {
		method: 'get',
		evalJSON: 'force',
		onSuccess: function(transport) 
		{
			fillSelect(transport.responseJSON.vvc_list, "vvc3list");
      $("vvc3list").selectedIndex = transport.responseJSON.selitem;
//____________________________________


var url= "/home-ajax.aspx?fa=get_vvc_spins&" + $("vvc3list").options[$("vvc3list").selectedIndex].value;
   new Ajax.Request(url, {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport)
    {
       videoFile=transport.responseJSON.videofile;
			 izmoFile=transport.responseJSON.izmofile;
    	 changeDiv();
			}
		});


//________________________________
		
		}
	});

   
}
//_____________________ Group URL

function groupMakesUrl(id)
{

  	new Ajax.Request("/home-ajax.aspx?fa=MAKES_URLS&group=" + escape(groupName), {
			method: 'get',
			evalJSON: 'force',
			onSuccess: function(transport) 
			{
		  	fillSelect(transport.responseJSON, id);
			}
		});
 
}
// _____________________ Group New Search

function groupNewMake()
{

  	new Ajax.Request("/home-ajax.aspx?fa=NEW_MAKES&group=" + escape(groupName), {
			method: 'get',
			evalJSON: 'force',
			onSuccess: function(transport) 
			{
		  	fillSelect(transport.responseJSON, "selNewMake");
			  updating=false;
			}
		});
 
}

function groupNewModel()
{
		groupNewBodyStyles();

    if($('selNewMake').selectedIndex == 0){
		  $('selNewModel').selectedIndex = 0;
 		  $('selNewModel').disabled = true;
		  return;
    }

  	new Ajax.Request("/home-ajax.aspx?fa=NEW_MODELS&group=" + escape(groupName) + "&make=" + $('selNewMake').options[$('selNewMake').selectedIndex].value, {
			method: 'get',
			evalJSON: 'force',
			onSuccess: function(transport) 
			{
		  	fillSelect(transport.responseJSON, "selNewModel");
				update=false;
        $('selNewModel').disabled = false;

			}
		});
}

function groupNewBodyStyles()
{

  	new Ajax.Request("/home-ajax.aspx?fa=new_bodystyles&group=" + escape(groupName) + "&make=" + $('selNewMake').options[$('selNewMake').selectedIndex].value, {
			method: 'get',
			evalJSON: 'force',
			onSuccess: function(transport) 
			{
		  	fillSelect(transport.responseJSON, "selNewBodyStyle");
			}
		});

}



// _____________________ Group Used Search


function groupUsedMake()
{

  	new Ajax.Request("/home-ajax.aspx?fa=USED_MAKES&group=" + escape(groupName), {
			method: 'get',
			evalJSON: 'force',
			onSuccess: function(transport) 
			{
		  	fillSelect(transport.responseJSON, "selUsedMake");
			  updating=false;
			}
		});
 
}

function groupUsedModel()
{
    groupUsedBodyStyles();

   if($('selUsedMake').selectedIndex == 0){
	  $('selUsedModel').selectedIndex = 0;
		$('selUsedModel').disabled = true;
      return;
   }

  	new Ajax.Request("/home-ajax.aspx?fa=USED_MODELS&group=" + escape(groupName) + "&make=" + $('selUsedMake').options[$('selUsedMake').selectedIndex].value, {
			method: 'get',
			evalJSON: 'force',
			onSuccess: function(transport) 
			{
		  	fillSelect(transport.responseJSON, "selUsedModel");
				update=false;
			  $('selUsedModel').disabled = false;
			}
		});
}

function groupUsedBodyStyles()
{

  	new Ajax.Request("/home-ajax.aspx?fa=USED_BODYSTYLES&group=" + escape(groupName) + "&make=" + $('selUsedMake').options[$('selUsedMake').selectedIndex].value, {
			method: 'get',
			evalJSON: 'force',
			onSuccess: function(transport) 
			{
		  	fillSelect(transport.responseJSON, "selUsedBodyStyle");
			}
		});

}




//____________________________________________________

function fillGroupListsAjax()
{
  var list = "[";
  var today = new Date();
  var thisYear = (today.getYear()) + 1;
  
  if (thisYear < 1000) thisYear += 1900;
  
  for (var x = thisYear; x >= 1980; )
  {
    list += "{\"value\":\"" + x + "\",\"name\":\"" + x + "\"}";
    x--;
    if (x >= 1980) list += ",";
  }
  list += "]";
  

 if ($('gInventorySearchUsedWidget')){
  
//  eval("var years =" + list);
//  fillSelect(years, "preowned_year_start");
//  fillSelect(years, "preowned_year_end");

  // get years for that mode
  new Ajax.Request("/home-ajax.aspx?fa=get_years&type=used", {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "preowned_year_start");
 			$('preowned_year_start').options[1].selected = true;

     fillSelect(transport.responseJSON, "preowned_year_end");
     var optNum=$('preowned_year_end').options.length-1;
 			$('preowned_year_end').options[optNum].selected = true;

    }

  });
 


 }
  
//  var start = document.getElementById("preowned_year_start")
//  if (start) start.options.selectedIndex = (thisYear - 1990);
  

  list = "[";
  list += "{\"value\":\"\",\"name\":\"- Any Price -\"},";
  list += "{\"value\":\"0,5000\",\"name\":\"Up to $5,000\"},";
  list += "{\"value\":\"5000,10000\",\"name\":\"$5,001 to $10,000\"},";
  list += "{\"value\":\"10001,15000\",\"name\":\"$10,001 to $15,000\"},";
  list += "{\"value\":\"15001,20000\",\"name\":\"$15,001 to $20,000\"},";
  list += "{\"value\":\"20001,25000\",\"name\":\"$20,001 to $25,000\"},";
  list += "{\"value\":\"25001,30000\",\"name\":\"$25,001 to $30,000\"},";
  list += "{\"value\":\"30001,40000\",\"name\":\"$30,001 to $40,000\"},";
  list += "{\"value\":\"40001,50000\",\"name\":\"$40,001 to $50,000\"},";
  list += "{\"value\":\"50001,60000\",\"name\":\"$50,001 to $60,000\"},";
  list += "{\"value\":\"60000,500000\",\"name\":\"$60,001 or more+\"}";
  list += "]";
 
  eval("var prices =" + list);
  if ($('gInventorySearchNewWidget'))
   fillSelect(prices, "selNewPrice");

  if ($('gInventorySearchUsedWidget'))
   fillSelect(prices, "selUsedPrice");
  
  list = "[";
  list += "{\"value\":\"\",\"name\":\"- Any Mileage -\"},";
  list += "{\"value\":\"15000\",\"name\":\"Under 15,000\"},";
  list += "{\"value\":\"30000\",\"name\":\"Under 30,000\"},";
  list += "{\"value\":\"45000\",\"name\":\"Under 45,000\"},";
  list += "{\"value\":\"60000\",\"name\":\"Under 60,000\"},";
  list += "{\"value\":\"75000\",\"name\":\"Under 75,000\"},";
  list += "{\"value\":\"100000\",\"name\":\"Under 100,000\"}";
  list += "]";


	 if ($('gInventorySearchUsedWidget')){
	  eval("var miles =" + list);
	  fillSelect(miles, "preowned_mileage");
	}
}

//_______________________________ News Ticker 2.0


		var boxHeight
		var repeatHeight 
		var stopScroll = 0
		var highlightsScrollTime

function showNewsHighlights(){
 
  if (newsScrollerParams)
   {
	 
    var newsTickerParams = newsScrollerParams.newslist;
    var newsTickerHeight = newsScrollerParams.newsheight+'px';

		var tickerText='';
    var newsNum=0;

		for(newsNum;newsNum<newsTickerParams.length;newsNum++)
		 {
    //  if(newsNum > 0)
    //   tickerText=tickerText + '<hr size="1">';
      tickerText=tickerText+ newsTickerParams[newsNum] ;
		 }

		$('newrotatorhighlights').insert(tickerText);
    $('newrotatorhighlights').setStyle({
      height:newsTickerHeight
     });
    
		boxHeight = $('newrotatorhighlights').style.height.replace('px','')
		repeatHeight = $('newrotatorhighlights').scrollHeight //get the current height so we know when to wrap
		$('newrotatorhighlights').innerHTML = $('newrotatorhighlights').innerHTML + $('newrotatorhighlights').innerHTML  //add a second copy so we can scroll down to the wrap point
		
    x = setTimeout("highlightsScroll()",1000)

   }
 }



function highlightsScroll() 
{
	clearTimeout(highlightsScrollTime)
	if(stopScroll==1) {
		return
	}
	$('newrotatorhighlights').scrollTop=$('newrotatorhighlights').scrollTop+1
	if($('newrotatorhighlights').scrollTop<=repeatHeight) {
		// keep on scrolin' 
		highlightsScrollTime = setTimeout("highlightsScroll()",40)
	}
	else { //we have hit the wrap point
		$('newrotatorhighlights').scrollTop=0
		highlightsScrollTime = setTimeout("highlightsScroll()",40)
	}
}

//__________________ 37: Icon Gallery

//_________________________________________________________________

//Banner

if ($('iconGallery')){

	if (iconGalleryParams )
		{
			imgiconImges = iconGalleryParams .imagelist;
		  imgiconTxt = iconGalleryParams .titlelist;
			imgiconLinks = iconGalleryParams .linklist;
		

    var divIcon;
    var iconList;

		iconList="";

    divIcon = $('iconGallery');
    if (divIcon) {
	   for (var i=0;i<=imgiconImges.length-1;i++){
        iconList = iconList +"<a href=" + imgiconLinks[i] +  " title=" + imgiconTxt[i] + " alt=" + imgiconTxt[i] + ">"

        if (imgiconImges[i].indexOf("crm")>=0)
       		iconList = iconList + "<img src=http://www.edealertools.com" +  imgiconImges[i] + " />" ;
				else
          iconList = iconList + "<img src=" +  imgiconImges[i] + " />" ;
	      
        iconList = iconList +"</a>"
		}
	      divIcon.update(iconList);         
      
    } 


	 }
}

//___________________ Activate New on Search Inventory

if($('isnew'))
{
  	$('isnew').checked=true;
  	startNewInventory();
	
}


function startNewInventory()
{

  if (updating) return;

  var iType = "n";
  
  fillPriceLists();
  $('isprice').disabled = false;
  $('ismodel').disabled = true;
  $('ismodel').selectedIndex = 0;

  
  updating = true;
  // get years for that mode
  new Ajax.Request("/home-ajax.aspx?fa=get_years&type=" + iType , {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "isyear");
 			$('isyear').options[1].selected = true;
    }

  });
 
  var MType = "new";

 // get make 
  new Ajax.Request("/home-ajax.aspx?fa=" + MType + "_makes", {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "ismake");
			if ($('ismake').options.length == 2)
				{
          $('ismake').options[1].selected = true;
	   			 reqUrl = "/home-ajax.aspx?fa=new_models&year=" + $('isyear').options[$('isyear').selectedIndex].value + "&make=" + $('ismake').options[$('ismake').selectedIndex].value;
				  // based on mode year and make, get available models
				  updating = true;
				  new Ajax.Request(reqUrl, {
				    method: 'get',
				    evalJSON: 'force',
				    onSuccess: function(transport) 
				    {
				      fillSelect(transport.responseJSON, "ismodel");  
							$('ismodel').disabled = false;  
							selectIsModelKeyword();
				      updating = false;  
				    }
				  });
      }
    }

  });


  // get bodystyle
  new Ajax.Request("/home-ajax.aspx?fa=" + MType + "_bodystyles", {
    method: 'get',
    evalJSON: 'force',
    onSuccess: function(transport) 
    {
      fillSelect(transport.responseJSON, "isbodyStyle");
      updating = false;   
    }

  });

  // enable year
  $('isyear').disabled = false;
  $('ismake').disabled = false;
  $('isbodyStyle').disabled = false;
  
}