function checkCookie() {
  var locale=getCookie('locale');
  
  if (locale == 'en-au') {
	window.location = 'http://au.canada.travel';   
  }
  else if (locale != null) {
    window.location = "splash."+locale+".html";
  }
  else {
    detectBrowserLanguage();
  }
}

function detectBrowserLanguage() {
  if (navigator.appName == 'Netscape') { 
    var language = navigator.language; 
  }
  else {  
    var language = navigator.userLanguage;
  }  
  if (language.indexOf('de') > -1) window.location = 'splash.de.html';  
  else if (language.indexOf('es') > -1) window.location = 'splash.es.html';  
  else if (language.indexOf('ja') > -1) window.location = 'splash.ja.html';  
  else if (language.indexOf('ko') > -1) window.location = 'splash.ko.html';
  else if (language.indexOf('zh-cn') > -1) window.location = 'splash.zh-cn.html';    
  else if (language.indexOf('fr-ca') > -1) window.location = 'splash.fr-ca.html';
  else if (language.indexOf('fr-fr') > -1) window.location = 'splash.fr.html';  
  else if (language.indexOf('fr') > -1) window.location = 'selectCountry-fr.html';  
  else if (language.indexOf('en-ca') > -1) window.location = 'selectCountry-ca.html';  
  else if (language.indexOf('en-gb') > -1) window.location = 'splash.en-gb.html';
  else if (language.indexOf('en-au') > -1) window.location = 'http://au.canada.travel';    
  
  else {
    window.location = 'selectCountry.html';
  }   
}

function createCookie(name,value,days) {
  if (days) {
  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
  } else {
      begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) {
      end = dc.length;
  }
  return unescape(dc.substring(begin + prefix.length, end));
}  
