// JavaScript Document
function grabobj(objname) // v1.0
{
	return $(objname);
}
function $(objname)
{
	if (document.getElementById) return document.getElementById(objname);
	if (document.all) return document.all[objname];
	if (document.layers) return document.layers[objname];
}
function hideSubMenus()
{
	var i = 1;
	while($('catMenu_'+ i +'_content'))
	{
		$('catMenu_'+ i +'_content').style.display = 'none';
		i++;
	}
	return
}
function changeSubMenu(obj)
{
//	hideSubMenus();
//	$(obj.id+'_content').style.display	=	'block';
}
var menusInt=new Array();
function leftMenuExp(subId)
{
	clearInterval(menusInt[subId]);
	entries = $('subcount_'+subId).value;
//	Different browsers this height is different so get height from DOM
	fullheight=$('catMenu_'+subId+'_content').childNodes[1].offsetHeight*entries;
	closeAllMenus();
	if($('catMenu_'+subId+'_content').offsetHeight<1) {
		$('expand_'+subId).innerHTML = '[<span class="menuShrink">-</span>]';
		menuDown(subId,fullheight);
	} else {
		menuUp(subId);
	}
}
function closeAllMenus()
{
	id=1
	while($("catMenu_"+id+"_content"))
	{
		if($("catMenu_"+id+"_content").className!="subMenuActive")
		{
			clearInterval(menusInt[id]);
			menuUp(id);
		}
		id++;
	}
}
msg=0
function menuDown(subId,fullheight)
{
	clearInterval(menusInt[subId]);
	var speed=10;
	if(($('catMenu_'+subId+'_content').offsetHeight+speed)>=fullheight) {
		$('catMenu_'+subId+'_content').style.height = fullheight+"px";
	} else {
		$('catMenu_'+subId+'_content').style.height = $('catMenu_'+subId+'_content').offsetHeight+speed+"px";
	}
	if($('catMenu_'+subId+'_content').offsetHeight<fullheight) {menusInt[subId]=window.setInterval("menuDown("+subId+","+fullheight+")",10);}
	if($('catMenu_'+subId+'_content').offsetHeight>=fullheight) {clearInterval(menusInt[subId]);}
}
function menuUp(subId)
{
	clearInterval(menusInt[subId]);
	var speed=10;
	if(($('catMenu_'+subId+'_content').offsetHeight-speed)<=0) {
		$('expand_'+subId).innerHTML = '[+]';
		$('catMenu_'+subId+'_content').style.height = "0px";
	} else {
		$('catMenu_'+subId+'_content').style.height = ($('catMenu_'+subId+'_content').offsetHeight-speed)+"px";
	}
	if($('catMenu_'+subId+'_content').offsetHeight>0) {menusInt[subId]=window.setInterval("menuUp("+subId+")",10);}
	if($('catMenu_'+subId+'_content').offsetHeight<=0) { clearInterval(menusInt[subId]);}
}
/*function viewLarge(Pno)
{
	ajaxObj		=	new ajaxObject("/viewLarge/",evalAjax)
	ajaxObj.update("id="+Pno,"POST");
}*/
function evalAjax(r,s)
{
	eval(unescape(r));
}
function ajaxObject(url, callbackFunction) {
	var that=this;
	this.updating = false;
	this.abort = function() {
		if (that.updating) {
			that.updating=false;
			that.AJAX.abort();
			that.AJAX=null;
		}
	}
	this.update = function(passData,postMethod) {
		if (that.updating) { return false; }
		that.AJAX = null;
		if (window.XMLHttpRequest) {
			that.AJAX=new XMLHttpRequest();
		} else {
			that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (that.AJAX==null) {
			return false;
		} else {
			that.AJAX.onreadystatechange = function() {
				if (that.AJAX.readyState==4) {
					that.updating=false;
					that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);
					that.AJAX=null;
				}
			}
			that.updating = new Date();
			if (/post/i.test(postMethod)) {
				var uri=urlCall+'?'+that.updating.getTime();
				that.AJAX.open("POST", uri, true);
				that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				that.AJAX.send(passData);
			} else {
				var uri=urlCall+'?'+passData+'&tstamp='+(that.updating.getTime());
				that.AJAX.open("GET", uri, true);
				that.AJAX.send(null);
			}
			return true;
		}
	}
	var urlCall = url;
	this.callback = callbackFunction || function () { };
}
function updateModels(premod)
{
	var selmol=$('anymanu').options[$('anymanu').selectedIndex].value.toUpperCase();
	$('anymodel').innerHTML='';
	$('anymodel')[$('anymodel').length] = new Option('Any Model', '');
	if (selmol!="")
	{
		for (var i=0;i<CARMAKES[selmol].length;i++)
		{
			$('anymodel')[$('anymodel').length] = new Option(CARMAKES[selmol][i].split('-')[1], CARMAKES[selmol][i].split('-')[0].toLowerCase());
			if (premod) { if (premod==CARMAKES[selmol][i].split('-')[0].toLowerCase()) { $('anymodel')[$('anymodel').length-1].selected=true; }}
		}
	}

 if ($('anyyear'))
 {
	if ($('anymanu').selectedIndex>0)
	{
		$('anymodel').disabled=false;
	} else {
		$('anymodel').disabled=true;
	}

	$('anycats').disabled=true;
	$('anyyear').disabled=true;

	$('anycats').selectedIndex=0;
	$('anyyear').selectedIndex=0;
 }
}

function checkModel ()
{
	if ($('anymodel').selectedIndex==0)
	{
		$('anycats').disabled=true;
		$('anyyear').disabled=true;
		$('anycats').selectedIndex=0;
		$('anyyear').selectedIndex=0;
		
		if ($('anymanu').selectedIndex!=0)
		{
			alert('Please select a model.');
			$('anymodel').focus();
			flashInput('anymodel');
			return false;
		}
	} 
}
var flashCnt=0;
var flashTimer;
var flashObj;
function flashInput (obj)
{
	flashCnt=0;
	flashObj=$(obj);
	flashTimer=window.setInterval(doFlashInput,100);
}
function doFlashInput ()
{
	flashCnt=flashCnt+1
	if (!flashObj.style.background)
	{
		flashObj.style.background='#FFF86F';
	} else {
		flashObj.style.background='';
	}
	if (flashCnt>5) clearTimeout(flashTimer);
}
function updateYears()
{
	$('anycats').disabled=true;
	$('anyyear').disabled=true;
	$('anycats').selectedIndex=0;
	$('anyyear').selectedIndex=0;
	var ajaxObj=new ajaxObject("/ajaxy/",evalAjax)
	ajaxObj.update("man="+$('anymanu').options[$('anymanu').selectedIndex].value+"&mod="+$('anymodel').options[$('anymodel').selectedIndex].value,"POST");
}
function updateCats()
{
	$('anycats').disabled=true;
	$('anycats').selectedIndex=0;
	var ajaxObj=new ajaxObject("/ajaxs/",evalAjax)
	ajaxObj.update("year="+$('anyyear').options[$('anyyear').selectedIndex].value+"&man="+$('anymanu').options[$('anymanu').selectedIndex].value+"&mod="+$('anymodel').options[$('anymodel').selectedIndex].value,"POST");
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}





function viewLarge(ref,opt)
{
	html="<div style=\"width:550px;\">";
	html+="<CSP:INCLUDE PAGE=\"viewLarge.csp\">";

	html+="<div align=\"center\"><input type=\"button\" style=\"font-size:14px; color:#111111;\" onclick=\"clearItem('bigimg');\" value=\"Close Viewport\"></div>";
	html+="</div>";
	displayBox('bigimg',html);
}

/*function viewLarge(ref,opt)
{
	html="<div style=\"width:550px;\">";
	html+="<iframe src=\"/csp/carm/web/viewLarge.csp?id="+ref+"\" style=\"width:550px;height:540px;border:0px;\" height=\"100%\" scrolling=\"no\" frameborder=\"0\"></iframe>";

	html+="<div align=\"center\"><input type=\"button\" style=\"font-size:14px; color:#111111;\" onclick=\"clearItem('bigimg');\" value=\"Close Viewport\"></div>";
	html+="</div>";
	displayBox('bigimg',html);
}
*/




