// JavaScript Document
function initialLoad()
{
	allFade();
	if (params.group)
	{
		ffilter(params.group);
		MM_effectAppearFade(params.group, 500, 30, 100, false)
	}
	else
	{
		ffilter('a2');
		MM_effectAppearFade('a2', 500, 30, 100, false)

	}
}

function selectcar(whichcar)
{
	var getcar=document.getElementById(whichcar);
}

function allFade()
{
	MM_effectAppearFade('allstock', 10, 30, 30, false);
	MM_effectAppearFade('a1', 10, 30, 30, false);
	MM_effectAppearFade('a2', 10, 30, 30, false);
	MM_effectAppearFade('a3', 10, 30, 30, false);
	MM_effectAppearFade('a4', 10, 30, 30, false);
	MM_effectAppearFade('a5', 10, 30, 30, false);
	MM_effectAppearFade('a6', 10, 30, 30, false);
	MM_effectAppearFade('a7', 10, 30, 30, false);
	MM_effectAppearFade('a8', 10, 30, 30, false);
}

function removeFilter()
{
	allFade();
	MM_effectAppearFade('allstock', 300, 30, 100, false);
	dsCars.filter(null);
}

function ffilter(choosegroup) 
{
	allFade();
	var getcar=document.getElementById(choosegroup);
	MM_effectAppearFade(getcar, 300, 30, 100, false);
	var filterFunc = function(ds, row, rowNumber)
	{
		var str = row["Group"];
		if (str == choosegroup)
			return row;
		return null;
	};
		dsCars.filter(filterFunc);
}

function StartFilterTimer()
{
	if (StartFilterTimer.timerID)
		clearTimeout(StartFilterTimer.timerID);
	StartFilterTimer.timerID = setTimeout(function() { StartFilterTimer.timerID = null; ffilter(); }, 100);
}

function MM_effectAppearFade(targetElement, duration, from, to, toggle)
{
	Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}

function doSort(choice) {
switch (choice) {
	case '1': dsCars.sort("Retail","ascending"); break;
	case '2': dsCars.sort("Retail","descending"); break;
	case '3': dsCars.sort("RegYear","descending"); break;
	case '4': dsCars.sort("Model","ascending"); break;
};
}

function vehicledetails(enquiryReg) {
	MM_showHideLayers('apBackground','','show','apDetails','','show','apResponse','','show');
	document.forms["sortPick"].listSort.style.visibility="hidden";
	document.Enquiry.vehicle.value = (enquiryReg);
}
function CloseDetails() {
	MM_showHideLayers('apBackground','','hide','apDetails','','hide','apResponse','','hide');
	document.forms["sortPick"].listSort.style.visibility="visible";
	document.getElementById('apResponse').innerHTML = "";
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function warrantyTest(region, lookupFunction) {
	
	if (lookupFunction('{Warranty}') == "Approved")
	{
		warrantyTimerApproved();
		return;
	}
	else
	{
		warrantyTimerSelect();
		return;
	}
}
function warrantyTextSelect()
{
		  with (document) if (getElementById && ((obj=getElementById('warrantyDiv'))!=null))
    with (obj) innerHTML = unescape('<ul><li>Comprehensive 69 point check</li><li>3 month Companion warranty</li><li>Free MOTs whilst you own the vehicle</li></ul>');
}
function warrantyTimerSelect()
{
	if (warrantyTimerSelect.timerID)
		clearTimeout(warrantyTimerSelect.timerID);
	warrantyTimerSelect.timerID = setTimeout(function() { warrantyTimerSelect.timerID = null; warrantyTextSelect();}, 100);
}

function warrantyTextApproved()
{
		  with (document) if (getElementById && ((obj=getElementById('warrantyDiv'))!=null))
    with (obj) innerHTML = unescape('<ul><li>Complimentary 7-day drive-away insurance</li><li>12-month Honda Happiness guarantee </li><li>Rigorous checking and preparation </li><li>Assured vehicle history </li><li>Mileage certification </li><li>30-day exchange policy </li><li>Free MOTs whilst you own the vehicle</li></ul>');
}
function warrantyTimerApproved()
{
	if (warrantyTimerApproved.timerID)
		clearTimeout(warrantyTimerApproved.timerID);
	warrantyTimerApproved.timerID = setTimeout(function() { warrantyTimerApproved.timerID = null; warrantyTextApproved();}, 100);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_setTextOfLayer(objId,x,newText) { //v9.0
  with (document) if (getElementById && ((obj=getElementById(objId))!=null))
    with (obj) innerHTML = unescape(newText);
}
function CarsObserver(notificationType, dataSet, data)
{
	if (notificationType == "onPostUpdate")
		dsCars.removeObserver(CarsObserver);
		MM_showHideLayers('apLoad','','hide');

}