<html>
<head>
	<script src="http://js.3conline.com/min2/temp/v2/plugin-location2.js" charset="utf-8"></script>

</head>
<body>
	<script type="text/javascript">

		// real url /choose/r1/sg8670/
		var preFix="http://{{{host}}}";
		var oriUrl="{{originalUrl}}";

		// 获取定位
		var rid=null;
		var ridInUrl="{{ridInUrl}}";

		// 
		if(!ridInUrl||ridInUrl==''){
			Location.init(function(location) {
				if(location.error){
					//定位失败
					redUrl=preFix+oriUrl;
					window.location.href="http://m.pcauto.com.cn/x/selectcity/jr/?returns="+redUrl;
				}else{
					if(location && location.regionCity){
						if(oriUrl=='/'){
							redUrl=preFix+'/';
						}else{
							rid = location.regionCity
							redUrl=preFix+insertRid(oriUrl,rid);
						}
						window.location.href=redUrl;
					}
				}

		})}else{
			rid=ridInUrl;
			Location.setLocationRegion(rid,function(location){
				if(location.error){
					//定位失败
					redUrl=preFix+oriUrl;
					window.location.href="http://{{{host}}}/err/404.htm";
				}else{
					redUrl=preFix+oriUrl;
					window.location.href=redUrl;
				}
			});
		}


		function insertRid(str,rid){
			if(str=='/wx/')
				return '/r'+rid+'/wx/';

			var splits =str.split('/');
			if(splits.length==2)
				return str+'r'+rid+'/';

			var resStr='';
			var length=splits.length;
			for(var i=0; i<length; i++){
				if(i==0){
					// do nothing
				}else if(i==2){
					resStr+='/r'+rid+'/'+splits[i];
				}else{
					resStr+='/'+splits[i];
				}
			}
			return resStr;
		}
	</script>
</body>
</html>

