// JavaScript Document


// I-CAR International Redirect File

//The purpose of this file is to redirect people that have previously visited the site. 

function formHandler(form){
var URL = document.form.countrySelect.options[document.form.countrySelect.selectedIndex].value;
window.location.href = URL;
}

//Cookies must be active for the this page and certain areas of the site to work. 

if (navigator.cookieEnabled == 0) {
  alert("You need to enable cookies for this site to load properly!");
}

//if a cookie isnt found, set one base don the link that is clicked. 

function SetCookie (name, value, hours) 
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

//Read to see if cookie is availalbe to determin if a redirect is necessary

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

var favorite = readCookie('icar');

//Change the links below to redirect to the approriate site once a link hase been clicked. 
if (favorite != null) {
var urllink = null;
switch (favorite) {	
case 'T4RCmhpHQe0EnDp' : urllink = '/index_us.shtml';
	     	break;
case 'Dt5NSV6MKiykUa0' : urllink = 'http://www.i-car.com.au';
	     	break;
case 'N8NWPfMXu6siNMR' : urllink = 'http://www.i-car.ca/index_ca.shtml';
		break;
//case 'H9RnDfMIP6MwH0c' : urllink = 'http://www.i-car.co.nz';
		//break;
		//break;
}
if(urllink != null){
window.location.href = urllink;
}
}