var newURL;


// determine the base URL for redirect
if (document.domain && document.domain == "integration.vw.com")
	newURL = "http://integration.m.vw.com";
else if (document.domain && document.domain == "stage.vw.com")
	newURL = "http://staging.m.vw.com";
else
	newURL = "http://m.vw.com";



// detect dealer redirects
if (location.search.indexOf("service=") > -1) {
	newURL += "/dealers/dealer_direct.php" + location.search;
}


// detect mobile devices
if (navigator.userAgent.match(/iPhone/i) || 
	navigator.userAgent.match(/iPad/i) ||
	navigator.userAgent.match(/android/i) ||
	navigator.userAgent.match(/BenQ/i) ||
	navigator.userAgent.match(/Blackberry/i) ||
	navigator.userAgent.match(/DoCoMo/i) ||
	navigator.userAgent.match(/hiptop/i) ||
	navigator.userAgent.match(/iPod/i) ||
	navigator.userAgent.match(/j2ME/i) ||
	navigator.userAgent.match(/Kindle/i) ||
	navigator.userAgent.match(/MIDP/i) ||
	navigator.userAgent.match(/Minimo/i) ||
	navigator.userAgent.match(/Mozilla\/.*Avant/i) ||
	navigator.userAgent.match(/NetFront/i) ||
	navigator.userAgent.match(/Nokia/i) ||
	navigator.userAgent.match(/Opera Mini/i) ||
	navigator.userAgent.match(/Opera Mobi/i) ||
	navigator.userAgent.match(/Palm-/i) ||
	navigator.userAgent.match(/PalmOS/i) ||
	navigator.userAgent.match(/PalmSource/i) ||
	navigator.userAgent.match(/SEC-SGH600/i) ||
	navigator.userAgent.match(/SEC-SGHD410/i) ||
	navigator.userAgent.match(/Symbian\s*OS/i) ||
	navigator.userAgent.match(/Vodaphone/i) ||
	navigator.userAgent.match(/Windows CE/i) ||
	navigator.userAgent.match(/WMS\s*PIE/i) ||
	navigator.userAgent.match(/Xiino/i) ||
	navigator.userAgent.match(/\sBrew\s/i) ||
	navigator.userAgent.match(/\sPre\//i)) {

	// IF this is not a dealer redirect AND there is a document referrer, add it 
	if (newURL.indexOf("dealers/dealer_direct.php") == -1 && document.referrer != '') {
		newURL += '/?referrer=' + document.referrer;
	}

	// redirect
	location.href = newURL; 

} else {

	// Do not execute this code on the Routine Maintenance page
	if (String(document.location).indexOf("update/en/us") == -1) {
		if(location.search){
			location.href = 'home.html'+location.search;
		} else {
			var go = 'home.html';
			if(document.referrer) {
				go += '?origref=' + escape(document.referrer);
			}
			location.href = go;
		}
	} // IF not maintenance page
}