function urlTable(){
	var urls = new Array();
	urls["rightparts"] = "/html/tas_main.jsp?evar15=RIGHTPARTS";
	urls["rightparts/"] = "/html/tas_main.jsp?evar15=RIGHTPARTS";
	urls["rightparts/index.jsp"] = "/html/tas_main.jsp?evar15=RIGHTPARTS";
	
	return urls;
}

function process404() {
	var urlAgain = window.location.search;
	if(urlAgain.indexOf("?exist") > -1) return null;
	//checkUrlEncoded( window.location);
	var userURL = getURL('pathname').substring(1);
	userURL = userURL.replace(/[^A-Za-z0-9_\-\/]/ig, "");
	var targetUrl = isDirectMatch( userURL );
	if (targetUrl != null) {
  		window.location.href = targetUrl /*+ window.location.search*/;
	}else{
		var actually = window.location.href;	
		var newURL;
		if(userURL.indexOf("explore") > -1){
			newURL = actually.replace(/explore/,"experience");
			if (newURL.indexOf("?") > -1) window.location.href = newURL+"&exist=false";
			else window.location.href = newURL+"?exist=false";
		}else if(userURL.indexOf("shop") > -1){
			newURL = actually.replace(/shop/,"vehicles");
			if (newURL.indexOf("?") > -1) window.location.href = newURL+"&exist=false";
			else window.location.href = newURL+"?exist=false";	
		} else if (userURL.toLowerCase().indexOf("redtag") > -1) {
			window.location.href = window.location.href.substring(0,window.location.href.toLowerCase().indexOf("redtag")) + "vehicles/currentoffers/";
		}
	}
}


function isDirectMatch(url){
	var url = url.toLowerCase();
	var urls = urlTable();
	for (var i in urls) 
	  if ( url == i.toLowerCase() ) 
	    return urls[i];
	return null;
}

function checkUrlEncoded( url ){
  var newUrl = new String(url);
  result = newUrl.match(/%/i);
  if(result != null){
    newUrl = unescape(newUrl);
    window.location.href = newUrl;
  }
}

function getURL(){
	var urlParts = new Array(8);
	var wl = window.location;
	urlParts['href'] = wl.href;
	urlParts['protocol'] = wl.protocol;
	urlParts['host'] = wl.host;
	urlParts['hostname'] = wl.hostname;
	urlParts['port'] = wl.port;
	urlParts['pathname'] = wl.pathname;
	urlParts['search'] = wl.search;
	urlParts['hash'] = wl.hash;
	if (arguments.length < 1) return urlParts;
	else if(urlParts[arguments[0]] != "undefined" ) return urlParts[arguments[0]];
	else return null;
}

process404();