

var COOKIE_NAME = 'polycom_newsites';
var NEWCOOKIE_NAME = 'polycom_newsites_1';
var USURL = "www.polycom.com";
 var countryArray = new Array();
	 
	 countryArray['us_en'] = 'http://www.polycom.com/index.html';
	 countryArray['cala_es'] ='http://latinamerica.polycom.com/index.html';
	 countryArray['ar_es'] = 'http://latinamerica.polycom.com/index.html';
	 countryArray['au_en'] ='http://www.polycom.com.au/index.html';
	 countryArray['br_pt'] ='http://www.polycom.com.br/index.html';
	 countryArray['cala_en'] ='http://cala.polycom.com/index.html';
	
	
	countryArray['cl_es'] ='http://www.polycom.cl/index.html';
	
	countryArray['mx_es'] ='http://www.polycom.com.mx/index.html';
	countryArray['pe_es'] ='http://www.polycom.com.pe/index.html';
	countryArray['apac_en'] ='http://www.polycom.asia/index.html';

	countryArray['cn_zh'] ='http://www.polycom.com.cn/index.html';
	countryArray['in_en'] ='http://www.polycom.co.in/index.html';
	countryArray['jp_ja'] ='http://www.polycom.co.jp/';

	countryArray['dk_da'] ='http://www.polycom.dk/index.html';
	countryArray['de_de'] ='http://www.polycom.de/index.html';
	countryArray['emea_en'] ='http://www.polycom.eu/index.html';
	countryArray['fr_fr'] ='http://www.polycom.fr/index.html';
	countryArray['es_es'] ='http://www.polycom.es/index.html';

	countryArray['it_it'] ='http://www.polycom.co.it/index.html';
	countryArray['pl_pl'] ='http://www.polycom.pl/index.html';
	countryArray['pt_pt'] ='http://www.polycom.pt/index.html';
	countryArray['ro_ro'] ='http://www.polycom.com.ro/index.html';

	countryArray['fi_fi'] ='http://www.polycom.fi/index.html';
	countryArray['se_sv'] ='http://sweden.polycom.com/index.html';
	countryArray['uk_en'] ='http://www.polycom.co.uk/index.html';
	countryArray['ru_ru'] ='http://russia.polycom.com/index.html';
	countryArray['no_no'] ='http://www.polycom.no/index.html';
	countryArray['nl_nl'] ='http://www.polycomnederland.nl/index.html';
	countryArray['can_en'] = 'http://www.polycom.ca/ca_en/index.html';
	countryArray['ca_fr'] = 'http://www.polycom.ca/ca_fr/index.html';
	countryArray['cz_ce'] = 'http://czech.polycom.com/index.html';
	
	

	
	function RedirectUser(p_SelectedLocation)
	{
	
	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.polycom.com/index.html?showme=y';
	}


	function setCookie(p_selectedLocation)
	{
		
		$.cookie(NEWCOOKIE_NAME, null);  //delete cookie
		$.cookie(NEWCOOKIE_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.polycom.com/index.html?showme=y';
		}
		
	}


