function cSearchNode(oNode)
{
	if(!oNode.getAttribute("searchnode")|| oNode.getAttribute("searchnode") == "false")
		throw new Error("Not a valid Search Node");
	this.oReferenceLink = oNode;
	this.sUrl = oNode.getAttribute("url") || null;
	this.sId = oNode.getAttribute("id") || null;
	this.sValue = oNode.value;
	this.rPattern = (oNode.getAttribute("pattern")) || null;
	this.sErrorMessage = (oNode.getAttribute("message"));
	this.sErrorAction = (oNode.getAttribute("error"));
	this.sType = oNode.type;
	this.bRequired = (oNode.getAttribute("required")) || false;
	this.iValidationValue = null;
	this.bChecked = (oNode.checked) || null;
	this.iSelectedIndex = (oNode.selectedIndex) || null;
}
cSearchNode.prototype.Validate = function()
{
	var sType = this.sType;
	switch(sType)
	{	
		case "select-one" :
			if(this.sId == "lYear" || this.sId == "hYear"){
				if(this.sValue == "Any")
					this.iValidationValue = -1;
					return;
			}
			else
				this.iValidationValue = this.iSelectedIndex;
			break;
		case 'radio' :
			if(this.bChecked == true)
			{
				this.iValidationValue =  0;
				return;
			}
			this.iValidationValue = -1;
			break;
		case "text" :
			switch(this.sErrorAction)
			{
			case 'fix' :
				if(this.sValue)
				{
					var rPattern = this.rPattern;
					var arSuccess = new Array();
					arSuccess = this.sValue.match(eval(rPattern));
					if(!arSuccess)
					{
						this.oReferenceLink.value = "";
						this.oReferenceLink
						this.iValidationValue = -1;
						return;
					}
					this.oReferenceLink.value = arSuccess.join('');
					this.iValidationValue = (arSuccess.length > 0) ? 1 : -1;
					return;
				}
				this.iValidationValue = -1;
				break;
			case 'alert' :
				var rPattern = this.rPattern;
				if(this.sValue)
				{
					if(!eval(rPattern).test(this.sValue))
					{
						this.iValidationValue = -1;
						alert(this.sErrorMessage);
						this.oReferenceLink.value = "";
						return;
					}
					this.iValidationValue = 0;
					return;
				}
				this.iValidationValue = -1;
				break;
			default :
				break;
			}
		case 'checkbox' :
			if(this.bChecked)
			{
				this.iValidationValue = 1;
				return 1;
			}
			this.iValidationValue = -1;
			return -1;
			break;
		default :
			break;
	}
}
cSearchNode.prototype.isRequired = function()
{
	return this.bRequired;
}
function cSearchNodeList()
{
	this.arSearchNodeList = new Array();
	this.iSize = 0;
}
cSearchNodeList.prototype.length = function()
{
	return this.iSize;
}
cSearchNodeList.prototype.addToNodeList = function(oNode)
{
	try
	{
		var oTempNode = new cSearchNode(oNode);
		this.arSearchNodeList.push(oTempNode);
		this.iSize++;
	}
	catch(ex)
	{}
}
cSearchNodeList.prototype.buildSearchNodeList = function(oNode)
{
	var arChildren = oNode.childNodes;
	if(oNode.nodeType == 1)
	{
		this.addToNodeList(oNode);
	}
	for(var x = 0; x < arChildren.length; x++)
		this.buildSearchNodeList(arChildren[x]);
}
cSearchNodeList.prototype.validateNode = function(iArrayIndex)
{
	this.arSearchNodeList[iArrayIndex].Validate();
}
cSearchNodeList.prototype.getSearchNode = function(iArrayIndex)
{
	return this.arSearchNodeList[iArrayIndex];
}

function validateAll(oSearchNodeArray, arValidNodes)
{
	var ptrNode;
	var bIsRequired;
	var iValidation;
	
	for(var x = 0; x < oSearchNodeArray.length(); x++)
	{
		ptrNode  = oSearchNodeArray.getSearchNode(x);
		oSearchNodeArray.validateNode(x);
		bIsRequired = ptrNode.bRequired;
		iValidation = ptrNode.iValidationValue;
		if(iValidation >= 0)
			arValidNodes.push(ptrNode);
		else
			if((bIsRequired))
			{
				alert(ptrNode.sErrorMessage);
				return false;
			}
	}
	return true;
}
function buildUrl(oSearchNodeArray)
{
	var sUrlString = "";
	var arRangeArray = Array();
	var ptrTempNode;
	
	for(var x = 0; x < oSearchNodeArray.length(); x++)
	{
		ptrTempNode = oSearchNodeArray.getSearchNode(x);
		if(ptrTempNode.iValidationValue >= 0 && ptrTempNode.sUrl != null)
		{
			ptrTempNode.sValue = translateValue(ptrTempNode.sValue);
			sUrlString += ptrTempNode.sUrl + ptrTempNode.sValue;
		}
	}
	return sUrlString;
}
function quickValidate(oElement)
{
	var iValidateValue;
	var oTempNode = new cSearchNode(oElement);
	
	oTempNode.Validate();
	iValidateValue = oTempNode.iValidationValue;
	delete oTempNode;
	if(iValidateValue >= 0)
		return true;
	return false;
}
function cleanUrl(sUrl)
{
	var sTempUrl = "";
	var rAnyPattern = /\/\w*-(,*any|,*undefined)+/ig;
	
	sTempUrl = sUrl.replace(rAnyPattern,'');
	if(!sTempUrl.match(/\/zip/i))
		sTempUrl = sTempUrl.replace(/\/radius-(\d)+/i,"");
	if(!sTempUrl.match(/\/radius/i))
		sTempUrl = sTempUrl.replace(/\/zip-(\d)+/i,"");
	sTempUrl = sTempUrl.replace(/\/Radius-exact/i,"");
	sTempUrl = sTempUrl.replace(/\/Price-0,99999999/i,"");
	return sTempUrl;
}
function translateValue(sValue)
{
	var sTemp = sValue || "";
	sTemp = sTemp.replace(/\//,'%25');
	sTemp = sTemp.replace(/-/,'%2D');
	return sTemp;
}
function setCookies(arValidNodes)
{
	var sCookie = '';
	var sNodeValue;
	var sNodeId;
	
	for(var x = 0; x < arValidNodes.length; x++)
	{
		sNodeId = arValidNodes[x].sId;
		sNodeValue = arValidNodes[x].sValue;
		sCookie += sNodeId + '=' + sNodeValue + '#';
	}
	document.cookie = "searchform=" + sCookie + ";path=/;expires="; 
	return true;
}
function populateForm()
{
	var sCookie = 'searchform=';
	var sDocumentCookie = document.cookie || '';
	var iStartPoint = sDocumentCookie.indexOf(sCookie);
	var iEndPoint;
	var sSearchCookie = '';
	var arSplitResult;
	var bdebug = true;
	var iIndex = 0;
	var arNameValuePair = new Array();
	var oElement = null;
	var sUrlAttribute = '';

	
	if(iStartPoint >= 0) //we have what we are looking for
	{
		iStartPoint +=  + sCookie.length;
		iEndPoint = sDocumentCookie.indexOf(";",iStartPoint);
		sSearchCookie = sDocumentCookie.slice(iStartPoint,iEndPoint);
		arSplitResult = sSearchCookie.split(/#/);
		for(; iIndex < arSplitResult.length; iIndex++)
		{
			arNameValuePair = arSplitResult[iIndex].split(/=/);
			oElement = document.getElementById(arNameValuePair[0]);
			if(oElement != null)
			{
				switch(oElement.type)
				{
					case 'select-one':
						oElement.setAttribute('searchnode','true');
						oElement.value = arNameValuePair[1].replace('%25','/');
						oElement.value = decodeURI(arNameValuePair[1]);
						changeDivStatus(oElement,arNameValuePair[1]);
						break;
					case 'radio':
						oElement.setAttribute('searchnode','true');
						oElement.setAttribute('checked',true);
						changeDivStatus(oElement);
						break;
					case 'text':
						oElement.setAttribute('searchnode','true');
						oElement.value = decodeURI(arNameValuePair[1]);
						changeDivStatus(oElement);
						break;
					case 'checkbox':
						oElement.setAttribute('searchnode','true');
						oElement.setAttribute('checked',true);
						changeDivStatus(oElement);
						break;
					default:
						oElement.setAttribute('checked',true);
						changeDivStatus(oElement);
						break;
				}
			}
		}
	}
}
function changeDivStatus(oElement,sCookie)
{
	var sSearchForm = 'mainsearch';
	var oTempNode = null;
	switch(oElement.getAttribute('url'))
	{
		case '/Type-':
			sType(oElement.value);
			break;
		case '/AreaCode-' :
			sArea(sSearchForm,'area');
			break;
		case '/State-' :
			sArea(sSearchForm,'state');
			break;
		case '/Caribbean-':
			sArea(sSearchForm,'carb');
			break;
		case '/More-all':
			shwMore();
			break;
		case '/Price-':
			oElement.setAttribute('searchnode','true');
			setHPrice(document.getElementById('lprice'),'hprice');
			document.getElementById('hprice').setAttribute('searchnode','true');
			break;
		case '/Year-':
			oElement.setAttribute('searchnode','true'); 
			populateSelect(document.getElementById('hYear'), oElement.value, 'hYear',1);
			document.getElementById('hYear').setAttribute('searchnode','true');
			break;
		default:
			break;
			
	}
		return true;
}

function repopulateModel(oSelectObject,sCookieVal)
{
	var oModelSelect = document.getElementById(oSelectObject);
	for(y=0;y<oModelSelect.options.length;y++)
	{
		if(oModelSelect.options[y].value==sCookieVal)
			oModelSelect.options[y].selected = true;
	}
}

function validatePrice(oLowPrice, oHighPrice)
{
	var iLowPrice = parseFloat(oLowPrice.value);
	var iHighPrice = parseFloat(oHighPrice.value);
	
	if(!iLowPrice)
	{
		oHighPrice.value = '';
		oHighPrice.disabled = true;
	}
	else
	{
		if(!iHighPrice)
		{
			oHighPrice.value = oLowPrice.value;
			oHighPrice.disabled = false;
		}
	}
	if(iHighPrice < iLowPrice)
		swapValue(oHighPrice, oLowPrice);
	
	return true;
}
function swapValue(oNode1, oNode2)
{
	var sTemp = '';
	
	sTemp = oNode1.value;
	oNode1.value = oNode2.value;
	oNode2.value = sTemp;
	return true;
}
function setTypeSelect()
{
	document.mainsearch.elements['slt_GetClasses'].setAttribute('id',document.mainsearch.elements['slt_GetClasses'].value+'type');
	document.mainsearch.elements['category_select'].setAttribute('id','type'+document.mainsearch.elements['slt_GetClasses'].value);
}
/****************************
main search form functions
****************************/
sTSlct = 'Motorcycle';
function sType(val1) {
	var catClass = 'sCt';
	var manfClass = 'sShw';
	if(window.location.href.indexOf('search-results') > 0)
	{
		catClass = 'mCt';
		manfClass = 'mCt';
	}
	if((sTSlct!='Snowmobiles')&&(sTSlct!='PWC')){document.getElementById(sTSlct).className = 'sHid';} //hide exposed select box
	if((val1!='Snowmobiles')&&(val1!='PWC')){document.getElementById(val1).className = catClass;} //show selected select box
	if((sTSlct!='Snowmobiles')&&(sTSlct!='PWC'))
	{
		document.getElementById('type'+sTSlct).setAttribute('searchnode','false');
	}
	if((val1!='Snowmobiles')&&(val1!='PWC'))
	{
		document.getElementById('type'+val1).setAttribute('searchnode','true');
	}
	document.getElementById(sTSlct+'Manf').className = 'sHid'; //hide previous type manufacturer field
	document.getElementById(val1+'Manf').className = manfClass; //show selected type manufacturer field
	document.getElementById(sTSlct+'Make').setAttribute('searchnode','false');
	document.getElementById(val1+'Make').setAttribute('searchnode','true');
	resetHt();
	sTSlct = val1; //set which type field is currently visible
}


sASlct = 'zip';
function sArea(form_name, val1) {
	document.getElementById(sASlct).style.display = 'none'; 
	document.getElementById(val1).style.display = 'block'; 
	var srchNod = document.forms[form_name].elements[val1+'Code'];
	srchNod.setAttribute("searchnode", "true");
	if(val1=='zip')
	{
		var srchNod = document.forms[form_name].elements[val1+'Rad'];
		srchNod.setAttribute("searchnode", "true");
	}
	var srchNod = document.forms[form_name].elements[sASlct+'Code'];
	srchNod.setAttribute("searchnode", "false");
	if(sASlct=='zip')
	{
		var srchNod = document.forms[form_name].elements[sASlct+'Rad'];
		srchNod.setAttribute("searchnode", "false");
	}
	if(window.location.href.indexOf('search-results') > 0)
	{
		if(val1!='zip'){document.getElementById('zipLbl').innerHTML='ZIP Code';}
		if(val1=='zip'){document.getElementById('zipLbl').innerHTML='ZIP Code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;within';}
	}
	sASlct = val1; 
}
//show or hide the Type dropdowns
function shwTyp(obj) {
	if(obj.value=='any'){
		hidNode("srchTyp");
		hidNode("srchCat");
	}else{
		shwNode("srchTyp");
	}
}
//show or hide the Additional Search fields - bottom of page
function shwMore() {
	var current_class = document.getElementById('more_options').className;
	if(current_class=='sHid'){
		document.getElementById('more_options').className='sShw';
		chngPls(current_class);
		resetHt();
	}else{
		document.getElementById('more_options').className='sHid';
		chngPls(current_class);
		resetHt();
	}
}


//Force a SHOW, - we need this for Regurgitate func
function shwMoreEx() 
{
  shwNode("more_options");
  chngPls(document.getElementById('more_options').className);
}

//change text and image for Additional Criteria Links
function chngPls(val1) {
	if (val1=='sHid') {
		document.getElementById('mre').innerHTML = 'Hide display options';
		document.getElementById('mre').className = 'sLess';
	} else {
		document.getElementById('mre').innerHTML = 'Show display options';
		document.getElementById('mre').className = 'sMore';	
	}
}
//show an element - and reset column heights
function showNode(idVal){
	document.getElementById(idVal).style.display='block';
	resetHt();
}
//hide an element - and reset column heights 
function hideNode(idVal) {
	document.getElementById(idVal).style.display='none';
	resetHt();
}



// show/hide refine search components
function dspMr(obj) 
{
	if (obj.nextSibling.nodeType==3){var nxtElm=obj.nextSibling.nextSibling;}else{var nxtElm=obj.nextSibling;}
	if(nxtElm.style.display=='none'){nxtElm.style.display='block';obj.innerHTML = '[-]';}else{nxtElm.style.display='none';obj.innerHTML = '[+]';}
} 



/*******************************************************************************
			My Trader Functions
*******************************************************************************/
var req = null;
var timer=0;
var curad=Array();
var needtologin=false;
var returned=false;
var imgname='';
var ad = null;
var checkbox;
var bLoginError;
var current_url = window.location.href.substring(0,window.location.href.indexOf('/find'));
var email_url = current_url+"/myt/join/";
var forgot_url = current_url+"/myt/forgot-password";




function popCntnt() 
{
  var cnt;
  cnt = '<h3 class="sMyH">MY <span>TRADER</span></h3><a href="" onclick="javascript:cls(this);return false;" class="sCls">Close</a><div class="dtd"></div><strong>SIGN IN HERE TO SAVE THIS VEHICLE TO YOUR MY TRADER ACCOUNT</strong>';
  cnt += '<form id="savevehiclesloginform" method="post" action=""><fieldset class="sLrg"><label>Email Address</label><input type="text" name="HANDLE_ID"/></fieldset>';
  cnt += '<fieldset class="sLrg"><label>Password</label><input type="password" name="PASSWORD" value="" /></fieldset>';
  cnt += '<input type="hidden" value="" name="ad_id"/>';
  cnt += '<a href="javascript: performLogin();" id="sSbmt" ;"></a><a href="'+forgot_url+'" id="sFrgt">Forgot Password?</a><div class="dtd"></div><div>Don\'t have an account? <a href="'+email_url+'">Join Now</a></div></form>';
  return cnt;
}
function cls(elm) 
  { 
       elm.parentNode.parentNode.removeChild(elm.parentNode);
       returned=false;
  }

// save this ad
function savAd(pElement, iAdID ) 
{
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', "newDv");
	newdiv.className="svDv";
	saveSearchResultAd(pElement,iAdID);
}

function saveSearchResultAd(pElement,ad_id)
{
	ad = ad_id;
	checkbox = pElement;
	//dtypeid=adTypeId;	
	var req = create_xml_object();
	var newsrc;
	sv_typetoreturn='LLLL';
	d=new Date();
	curad.push(ad_id);
	

	if (req!= null)
	{		
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id', "newDv");
		newdiv.className="svDv";
		newdiv.style.visibility='hidden';
		newdiv.innerHTML=popCntnt();
		pElement.parentNode.appendChild(newdiv);
		//change image to show ad is saved
		//pElement.className = 'sSavD';
		newsrc="/login-popup?action=save1&AD_ID="+ad_id+"&"+d.getTime();
		var url = getServerName()+newsrc;
		req.open("post", url, true);
		req.onreadystatechange = processChange;
		req.send(null);
	} 
}


function getServerName()
{
	var str = window.location.protocol + '//' + window.location.hostname;
	return str;
}
function create_xml_object()
{
	// Internet Explorer
	try
	{
		req = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			req = null;
		}
	}
	// Mozailla/Safari
	if (req == null && (typeof XMLHttpRequest != "undefined" || window.XMLHttpRequest))
	{
		req = new XMLHttpRequest();
	}
	return(req);
}

function performLogin()
{	
	var req = create_xml_object();
	var newsrc;
	var ad_id;
	lidiv = document.getElementById("newDv");	
	lidiv.style.visibility='hidden';
	if (req!= null)
	{
		form = document.getElementById("savevehiclesloginform");
		ad_id=form.ad_id.value;
		newsrc="&HANDLE_ID="+form.HANDLE_ID.value+"&";
		newsrc+="PASSWORD="+form.PASSWORD.value+"&";
		newsrc1="/login-popup?action=save1&AD_ID="+ad_id+newsrc;
		var url = getServerName()+newsrc1;
		req.open("post", url, true);
		req.onreadystatechange = processChange;
		req.send(null);
	}
}

function processChange(evt)
{
	if (req.readyState == 4)
	{
		if (req.status == 200)
		{
			var response = req.responseText;
			if( (response.length < 40) && (response.indexOf('LoginFailure') < 0) ) 
			{
				checkbox.className="sSavD";
				parameters=response.split("&");
				ad_id=parameters[1];				
				if(imgname!="")
				{
				tab=document.getElementById(ad_id);
				tab.className=imgname;
				}
				else
				{					
				chk=document.getElementById(ad_id);
				tab=document.getElementById(ad_id);
				}
			}
			else
			{
				if(returned)
				{
					alert('Email Address and/or Password incorrect');
									}
				lidiv = document.getElementById("newDv");
				document.forms['savevehiclesloginform'].elements['ad_id'].value = ad;
				lidiv.style.visibility='visible';
				if(timer) clearTimeout(timer);
				needtologin=true;
				returned= true;
			}
		}
	}
}

function setHPrice(oElement,sElementName) 
{
	var sLPrice = oElement.value;
	var oHPrice = document.getElementById(sElementName);
	var iIncrement = 5000;
	var iLimit = 100000;
	var sOptionPrepend = '$';
	var iStart = parseFloat(sLPrice);
	var sCurrentHighValue = document.getElementById(sElementName).value;
	 
	oHPrice.innerHTML = '';
	for(x=0; iStart <= iLimit ;x++)
	{
		oHPrice.options[x] = new Option(sOptionPrepend + CommaFormatted(iStart), iStart);
		iStart += iIncrement;
	}
	oHPrice.options[oHPrice.options.length] = new Option('Bce','',true);
	
	for(i=0; i < oHPrice.options.length; i++)
	{
		if(oHPrice.options[i].value == sCurrentHighValue)
		{
			oHPrice.options[i].setAttribute('selected','true');
		}
	}
}


function populateSelect(oNode,iStartNumber,sName,iScale,iLimit)
{
	var oToday = new Date();
	var iStart;
	var iEnd;
	var iIndexOffset = 0;
	var iInterval = iScale;
	var sOptionPrepend = "";
	var iDiff;
	iStart = parseInt(iStartNumber);	
	switch(sName)
	{
		case 'lYear':
		case 'hYear':
			iEnd = oToday.getFullYear() + 2;
			break;
		default:
			break;
	}
	iDiff = iEnd - iStart;
	oNode.innerHTML = '';
	var x = 0
	for(x = iIndexOffset; iStart <= iEnd; x++)
	{
		oNode.options[x] = new Option(sOptionPrepend + iStart, iStart);
		if(iStart==iEnd)
			oNode.options[x].selected=true;
		iStart += (iInterval);
	}
	if(iStartNumber=='Any') {
		oNode.innerHTML = '';
		oNode.options[0] = new Option('Any', 'Any');
	}
}
function setNodeFalse(obj)
{
	if(obj.value!='')
	{
		document.getElementById('zipCode').setAttribute('searchnode','false');
		document.getElementById('zipRad').setAttribute('searchnode','false');
		document.getElementById('area').setAttribute('searchnode','false');
	}
}

function CommaFormatted(amount)
{
	var nAmount = amount + '.00';
	var delimiter = ","; // replace comma if desired
	var a = nAmount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	amount = amount.split('.',2);
	return amount[0];
}

function setCTOLTypeDomain(arURL)
{
	var sType = '';
	var sTypeDomain = '';
	var arUrlCriteria = '';
	var sDomain = '';
	var iURLIndex = 1;
	var sKeySearch = 'Type';
	var sUrlPrepend = '/find/search-results';

	arUrlCriteria = arURL.split("/");
	for(iURLIndex;iURLIndex < arUrlCriteria.length; iURLIndex++)
	{
		if(arUrlCriteria[iURLIndex].indexOf(sKeySearch) >= 0)
		{
			sType = arUrlCriteria[iURLIndex].substr(5);
		}
	}
	
	switch(sType)
	{
		case 'ATV':
			sDomain = document.domain.replace('cycletrader','atvtraderonline');
			sTypeDomain = 'http://' + sDomain + sUrlPrepend + arURL;
			break;
		case 'PWC':
			sDomain = document.domain.replace('cycletrader','pwc-traderonline');
			sTypeDomain = 'http://' + sDomain + sUrlPrepend + arURL;
			break;
		case 'Snowmobiles':
			sDomain = document.domain.replace('cycletrader','snowmobiletraderonline');
			sTypeDomain = 'http://' + sDomain + sUrlPrepend + arURL;
			break;
		default:
			sTypeDomain = sUrlPrepend + arURL;
			break;
	}	
	return sTypeDomain;
}

function clearFormComplete()
{
	document.mainsearch.reset();
	if(document.getElementById('Motorcycletype'))
		sType('Motorcycle');
	sArea('mainsearch','zip');
	document.getElementById('hYear').innerHTML = '<option value="Any">Bce</option>';
	document.getElementById('hprice').innerHTML = '<option value="">No Limit</option>';
	if(document.getElementById('more_options').className =='sShw')
		shwMore();
}

function setTypesQuickSearch(sValue,oElement)
{
	
	document.getElementById('typeMotorcycle').setAttribute('searchnode','false');
	document.getElementById('typeMotorcycle').value  = '';
	var oParentType = oElement.options[oElement.selectedIndex].parentNode.getAttribute('value');
	if(sValue != 'All')
	{
		document.getElementById('typeMotorcycle').setAttribute('searchnode','true');
		document.getElementById('typeMotorcycle').value = sValue;
	}
	document.forms['mainsearch'].elements['Type'].value = oParentType;
	document.forms['mainsearch'].elements['Type'].setAttribute('id',oParentType+'Type');

	getMakesSelect(oParentType); //populate the makes box based on selected type
}
function getMakesSelect(sVehicleType) {
	createAjaxRequest();
	var url = "cycletrader/json.php?type="+sVehicleType;
	request.open("GET",url);
	request.onreadystatechange = function() {
			setMakesSelect();
						}
	request.send(null);
}
var request = null;
function createAjaxRequest() 
{
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try { 
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request = null;
			}
		}
	}
	if(request==null) {
		alert("Error creating request object");
	} else {
		return request;
	}
}
function setMakesSelect() 
{
	if (request.readyState == 4) 
		document.getElementById('dynamicMakes').innerHTML = request.responseText;
}
function search(sForm)
{	
	var bNewOrUsedSelected = false;
	var bMileageSelected = false;
	var oSearchNodeArray = new cSearchNodeList();
	var sUrl = "";
	var sFormName = sForm || "mainsearch";
	var bIsValid = false;
	var sUrlPrepend = "";
	var arMatched = "";
	var sClass = "";
	var arValidNodes = Array();
	var bDebug = false;
	 
	oSearchNodeArray.buildSearchNodeList(document.forms[sFormName]);
	bIsValid = validateAll(oSearchNodeArray, arValidNodes);
	sUrl = buildUrl(oSearchNodeArray);
	if(bIsValid)
	{
		sUrl = cleanUrl(sUrl); 
		setCookies(arValidNodes);
		
		sDomain = setCTOLTypeDomain(sUrl);
		
		if(bDebug)
		{
			alert(sDomain);
			return;
		}
		window.location = sDomain + '/';
	}
}
