
var COOKIE_NAME = 'tsa_siteselector';
var USURL = "wwww.transition-asia.com";
 var countryArray = new Array();
	 
	 countryArray['tsa'] = 'http://www.transition-asia.com/';
	 countryArray['tsau'] ='http://au.transition-asia.com';
	 countryArray['tsv'] = 'http://www.tsv.com.vn';
	

	
	function RedirectUser(p_SelectedLocation)
	{
	alert(p_selectedLocation);
	alert(RedirectURL);
	var RedirectURL = countryArray[p_SelectedLocation];
	
	
	if(findQueryString('setcookie') == 'y')   //set the cookie if querystring says setCookie
		setCookie(p_SelectedLocation);
	if(RedirectURL != '')
		window.location = RedirectURL;
	else
		window.location = 'http://www.transition-asia.com/';
	}


	function setCookie(p_selectedLocation)
	{
		
		$.cookie(COOKIE_NAME, null);  delete cookie
		$.cookie(COOKIE_NAME, p_selectedLocation , { path: '/', expires: 365 });
	}


		// To get query string 
	function findQueryString( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return results[1];
	}

	function findQueryforRedirect( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	 
	  if( results == null )
		return "";
	  else
		{
			
			var RedirectURL = countryArray[results[1]];
			
			if(findQueryString('remember_me') == 'on')   //set the cookie if querystring says setCookie
				setCookie(results[1]);
			if(RedirectURL != '')
				top.location.href = RedirectURL;
			else
				top.location.href = 'http://www.transition-asia.com';
		}
		
	}