//alert ("notLoggedIn.js has been fired");

// new code to check the URL so that we have consistancy for the cookie (will send http://hppservices.com to http://www.hppservices.com)
var hostName = location.hostname;
var siteName = hppSitePrefix.substring(hppSitePrefix.indexOf("/")+2);
var pathName = location.pathname;
if (hostName != siteName) {
  var newURL = hppSitePrefix + pathName;
  location.href = newURL;
}

var cookieName = "zipcodeCheck";
var cookieData = new Array();
var cookieZip = "";
var cookieTerritory = "";
var cookieHWT = "";
var stayOnPage = true;
var territoryPath = "";

function checkCookie(){
  if (!readCookie(cookieName))
  {
    //alert ("cookie is null");
  }
  else
  {
    //shouldn't have a cookie, goto correct section based on cookie
    cookieData = readCookie(cookieName);
    cookieZip  = cookieData[0];
    cookieTerritory = cookieData[1];
    cookieHWT = cookieData[2];
    
    //alert ("cookieZip = " + cookieZip);
    // treat emptycookie is the same as no cookie
    if (cookieZip == "")
    {
      //alert ("cookie is empty");
    }
    else
    {
      territoryPath = "/" + cookieTerritory;
      stayOnPage = false;
    }
  }
  
  if (!stayOnPage)
  {
    //time to goto another page
    //alert ("time to switch pages");
  
    //get URL information for current page
    var currentPath = jQuery.url.attr('path');
    //alert ("currentPath = " + currentPath);
    var currentPage = "";
    var gotoLocation = "";
    
    if(jQuery.url.attr('file'))
    {
      currentPage = jQuery.url.attr('file');
    }
    else
    {
      currentPage = "index.html"
    }
    
    if (currentPage.indexOf('contactUs.html') >= 0)
    {
      gotoLocation = hppSecuredSitePrefix + territoryPath + "/contactUs.html"
    }
    else if (currentPath.indexOf('/app/') >= 0)
    {
      gotoLocation = hppUnsecuredSitePrefix + territoryPath + "/app"
    }
    else if (currentPath.indexOf('/ars/') >= 0)
    {
      gotoLocation = hppUnsecuredSitePrefix + territoryPath + "/ars"
    }
    else if (currentPath.indexOf('/ppp/') >= 0)
    {
      gotoLocation = hppUnsecuredSitePrefix + territoryPath + "/ppp"
    }
    else 
    {
      gotoLocation = hppUnsecuredSitePrefix  + territoryPath 
    }
  
    //alert ("Goto Location = " + gotoLocation);
    location.href = gotoLocation;
  } 
  else
  {
    //alert ("staying on page");
  }

}

jQuery().ready(function(){
  checkCookie();
}); //close jQuery(document).ready



