// amazing savings section on the homepage
function popUp(url)
{
  var popup_window1 = window.open(
    url, 'savings',
    'width=650,height=410,top=140,left=110,resizable,scrollbars,status,toolbar');

  if (focus_test == 1)
  {
    if (popup_window1.opener == null) popup_window1.opener = self;
    popup_window1.focus();
  }
}

// called onLoad executes win 1000 pop up 
// promotion pop-up commented out short term DC 26/9/01
function checkVisitor()
{
        self.name='ah_main';

        var time = new Date();
        var timeToday = time.getTime();

        var oneDay = 1000 * 60 * 60 * 24; // sets inactive period to one day
        //var oneDay = 1000 * 60 * 2; // test code sets inactive period to two mins.
        var timeInCookie = getCookie("win1000Popup");
      /*  if (timeInCookie != null)
        {
                var cookieTime = parseInt(timeInCookie);
                cookieTime = cookieTime + oneDay;
               if (cookieTime < timeToday)
               {
                    // time to show a popup
                       setCookie("win1000Popup", timeToday);
                       showwin1000();
                }        
        }
        else
        {
           showwin1000();
           setCookie("win1000Popup", timeToday);
        }*/
}
// Hotdeals and e-mail validation 17/04/2002

function invalidEmail(address) {
      var addressLength = address.length;

      var ok = -1;
      var noAts = 0;
      var noStops = 0;
      var illegalCharacters = "'\()[]{}<>,;: "; 
      var noIllegal = illegalCharacters.length;
      for(var n = 0; n < addressLength; n++)
      {
        for(var k = 0; k < noIllegal; k++) { //check for match in illegalCharacters
          if (illegalCharacters.charAt(k) == address.charAt(n)) {
            ok = 0;
            break;
          }
        }
        if (address.charAt(n) == "@") noAts++;
        if (address.charAt(n) == ".") noStops++;
      }
      if (noAts != 1) ok = 0;		//Exactly one @
      if (noStops < 1) ok = 0;	//One or more .
      if (address.charAt(0) == ".") ok = 0;	    //Can't start with .
      if (address.charAt((addressLength-1)) == ".") ok = 0;  //Can't end with .
      if (ok == -1) {
        return false; //Return false if address is valid
      }
      else {
        return true; //Return true if address is invalid
      }
    }
// Hotdeals function 17/04/2002
    function HotDeals(){
      var Message = '';
      if (document.gethotnews.email.value==''){
        Message = 'Please enter your e-mail address';
      }
      else
      {
        if (invalidEmail(document.gethotnews.email.value))
        {
          Message = 'Please enter a valid e-mail address';
        }
      }
      if (Message == '')
      {
        window.open('/xbook/servlet/HottestDealsSubscriber','hotdeals','width=250,height=150');
        document.gethotnews.action='/xbook/servlet/HottestDealsSubscriber';
        document.gethotnews.submit();
      }
      else
      {
        alert(Message);
      }
    }
//End HotDeals

// win 1000 pop up
function setCookie(name, value)
{
  var expDate = new Date();
  var threeDays = 1000 * 60 * 60 * 24 * 3; //3 days in milliseconds
  expDate.setTime(expDate.getTime() + threeDays); //set expiry date to 3 days
  document.cookie = name + "=" + escape(value) + ";expires=" + expDate.toGMTString()+';path=/';
}

// win 1000 pop up
function getCookie(name)
{
        var result = null;
        var myCookie = " " + document.cookie + ";";
        var searchName = " " + name + "=";
        var startOfCookie = myCookie.indexOf(searchName)
        var endOfCookie;
        if (startOfCookie != -1)
        {
          startOfCookie += searchName.length; //skip past cookie name
          endOfCookie = myCookie.indexOf(";", startOfCookie);
          result = unescape(myCookie.substring(startOfCookie, endOfCookie));
        }
        return result
}

//win 1000 pop up
function showwin1000()
{
        var newWin = window.open("promotions/popup.htm", "win1000", "scrollbars=no,width=215,height=340,left=200,top=50");
        if (newWin.opener==null) newWin.opener = self;
}

directoryon = new Image();
directoryon.src = "/images/directory-btn_lt.gif";
directoryoff = new Image();
directoryoff.src = "/images/directory-btn_dk.gif";
gocon = new Image();
gocon.src = "/images/go-btn_lt_cr_bk.gif";
gocoff = new Image();
gocoff.src = "/images/go-btn_dk_cr_bk.gif";
goon = new Image();
goon.src = "/images/go-btn_lt_gn_bk.gif";
gooff = new Image();
gooff.src = "/images/go-btn_dk_gn_bk.gif";
discounton = new Image();
discounton.src = "/images/discounts-btn_lt_cr_bk.gif";
discountoff = new Image();
discountoff.src = "/images/discounts-btn_dk_cr_bk.gif";
actionon = new Image();
actionon.src = "/images/action-btn-ffffcc-2.gif";
actionoff = new Image();
actionoff.src = "/images/action-btn-ffffcc.gif";
      
function go_to_city(form_name)
{
  var city_ref = document[form_name].by_city[document[form_name].by_city.selectedIndex].value;
  if (city_ref == "")
  {
    alert("You must choose a city");
  }
  else if (city_ref == "israel")
  {
    window.open('http://www.inisrael.com/allhotels/index.html', 'israel', 'toolbar,status,resizable,scrollbars,location,menubar');
  }
  else if (city_ref.indexOf('HRNChooseDates') == 0)
  {
    window.location.href = '/xbook/servlet/hrn-choose-d' + city_ref.substring(10, city_ref.length);
  }
  else if (city_ref.indexOf('resnet') >= 0)
  {
    window.location.href = city_ref;
  }
  else
  {
    window.location.href = '/xbook/servlet/hrn-choose-dates?locationID=' + city_ref;
  }
}
