var monthsT = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
function Cookie (name, y, m, d) {
    this.name = name;
    this.value = null;
    this.cookie = document.cookie;
    this.params = new Array ();
    var now = new Date ();
    this.expiry = new Date ((now.getYear () + y), (now.getMonth () + m), (now.getDate () + d));
}
Cookie.prototype.Write = function (value) {
    this.value = value;
    document.cookie = this.name + "=" + escape (this.value) + ";expires=" + this.expiry.toGMTString () + ";path=/;";
}
Cookie.prototype.Read = function () {
    this.params = this.cookie.split (';');
    for (var x = 0; x < this.params.length; x++) {
        var pieces = this.params[x].split('=');
        if (pieces[0].substring(0,1) == ' ') {
            pieces[0] = pieces[0].substring(1, pieces[0].length);
 	    }
 	    this.value = (pieces[0] == this.name) ? pieces[1] : this.value;
    }
    return this.value;
}
function getwidth () {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (document.body && document.body.offsetWidth) {
        return document.body.offsetWidth;
    } else {
        return 0;
    }
}
function popHome (n, u, h, w, l, t) {
    if (qsStr ("supresscookie")) {
        var nW = window.open (u, "nW", "height=" + h + ",width=" + w + ",toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no,left=" + (getwidth () - l) + ",top=" + t);
        return false;
    }
    var tcookie = new Cookie (n, 1, 0, 0);
    var times = tcookie.Read ();
    var maxTimes = 1;
    if (times == null || times < maxTimes) {
        if (times == null) {
            var nW = window.open (u, "nW", "height=" + h + ",width=" + w + ",toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no,left=" + (getwidth () - l) + ",top=" + t);
            times = 1;
        } else {
            var nW = window.open (u, "nW", "height=" + h + ",width=" + w + ",toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no,left=" + (getwidth () - l) + ",top=" + t);
            times++;
        }
    }
    tcookie.Write (times);
}
function doHoverHTML () {
    //if (unescape (location.hash) == "#gatwick north airport" ||
    //    unescape (location.hash) == "#gatwick south airport") {
        if (document.all) {
            document.write ("<div style=\"z-index: 100; position: absolute; left: 120; top: 130;\" id=\"foo\" name=\"foo\"><img alt=\"\" src=\"/GBR/images/hover.gif\" usemap=\"#Map\" border=\"0\"><map name=\"Map\">  <area shape=\"rect\" coords=\"337,-2,358,16\" href=\"#\" onclick=\"document.all.foo.style.display = 'none'; return false;\"></map></div>");
            setTimeout ("document.all.foo.style.display = \"none\"", 7500);
        }
    //}
}
function qsReplace (search, replace, string) {
  while (string.indexOf (search) > -1) {
    pos = string.indexOf (search);
    string = (string.substring (0, pos) + replace +
    string.substring ((pos + search.length), string.length));
  }
  return string;
}
qsKeys = new Array ();
qsValues = new Array ();
function qsParse () {
  var query = location.search.substring (1);
  var pairs = query.split ("&");
  for (var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf ('=');
    if (pos >= 0) {
      var argname = pairs[i].substring (0,pos);
      var value = pairs[i].substring (pos+1);
      if (value) {
          qsKeys[qsKeys.length] = argname;
          qsValues[qsValues.length] = qsReplace ('+',' ', unescape (value));
      }
    }
  }
}
function qsStr (key) {
  var value = "";
  for (var i = 0; i < qsKeys.length; i++) {
    if (qsKeys[i] == key) {
      return qsValues[i];
    }
  }
  return false;
}
function isAff () {
    return qsStr ("aff");
}
function isAmB () {
    if (window.location.href.indexOf ('bkgsrch.w') != -1) {
        return true;
    }
    return false;
}
function isQS () {
    if (window.location.href.indexOf ('QSearch.w') != -1) {
        return true;
    }
    return false;
}
function chnSlct (frm, vlu, typ) {
    var slct = parseFloat (frm.slct.value);
    if (vlu == "false" || frm[typ].length == 1) {
        frm[typ].length = 1;
        frm[typ][frm[typ].length] = new Option ("n/a", "false");
        frm[typ][0].selected = true;
        return;
    }
    arr = eval (vlu);
    arr.sort ();
    arr.reverse ();
    frm[typ].length = 1;

    var i = arr.length-1;
    do {
        frm[typ][frm[typ].length] = new Option (arr[i], arr[i]);
    }
    while (--i);

    frm[typ][slct].selected = true;
}
function doChange () {
    var ckArea = document.details.area[document.details.area.selectedIndex];
    if (fldVlu (ckArea, "Please select a specific destination from the dropdown list.")) {
        return;
    }
    document.details.xsearch.value = "";
    document.details.onsubmit = "";
    document.details.submit ();
}
function myCheck () {
    if (!doFormQS (document.details)) {
        return false;
    }
    return true
}
function chnClass (id, nclass) {
    return;
}
function fldVlu (fld, msg) {
    if (fld) {
        if (fld.value == "false" ||
            fld.value == "none" ||
            fld.value == "sel" ||
            fld.value == "" ||
            fld.value == null ||
            fld.value == false ||
            fld.value == 0 ||
            fld.value == "0") {
            alert (msg);
            fld.focus ();
            return true;
        }
    }
}
function formVal (frm, foo) {
	var empty;
    var dspnum = "";
    if (foo == empty) {
		dspnum = "0870 400 4447";
    } else {
		dspnum = foo;
	}
    if (window.affnum == empty) {	
    } else {
		dspnum = window.affnum;
	}
    if (!frm) {
        frm = document[str];
    }
    if (fldVlu (frm.region, "Please select a region") ||
        fldVlu (frm.area, "Please select a country") ||
        fldVlu (frm.station, "Please select a pick up location") ||
        fldVlu (frm.tlocation, "Please select a pick up location")) {
        return false;
    }

 //   if (frm.fiDriverAge.value < 21 || frm.fiDriverAge.value > 65 || frm.fiDriverAge.value == "" || frm.fiDriverAge.length < 2 || !valChar (frm.fiDriverAge, false)) {
 //       alert ("Please enter a valid driver age.  If you are under 21 or over 65, please phone our call centre on " + dspnum + ".");
   if (frm.fiDriverAge.value < 21  || frm.fiDriverAge.value == "" || frm.fiDriverAge.length < 2 || !valChar (frm.fiDriverAge, false)) {
        alert ("Please enter a valid driver age.  If you are under 21 please call our call center on "+dspnum+".");
        frm.fiDriverAge.focus ();
        frm.fiDriverAge.select ();
        return false;
    } 
	
	 if (document.details.selFromTime.value == document.details.selToTime.value  && document.details.slFromDay.value == document.details.slToDay.value) {
	alert('dropping off a car on the same day as booking requires more than an hour between the to and from times ')
	return false;
	}
	
 if (document.details.slFromDay.value == document.details.slToDay.value  && document.details.selFromTime.value > document.details.selToTime.value) {
	alert('dropping off a car on the same day as booking requires the pick up time to be less than your drop off time')
	return false;
	}	
	
    return true;
}

function doFormQS (frm, foo) {
    //alert("QA testing - doFormQS");
	if (!frm) {
        frm = document[str];
    }
    if (!formVal (frm)) {
        return false;
    }
    if (!validDate (foo)) {
        return false;
    }
    if (!checkDate ()) {
        return false;
    }
    return true;
}
function doForm (frm) {
//alert("QA testing - doForm");
    tmp = frm.timeFrom[frm.timeFrom.selectedIndex].value.split ("|");
    tFrom = tmp[0];
    tFromPart = tmp[1];
    tmp = frm.timeTo[frm.timeTo.selectedIndex].value.split ("|");
    tTo = tmp[0];
    tToPart = tmp[1];
    frm.slFromTime.value = tFrom;
    frm.slFromTimePart.value = tFromPart;
    frm.slToTime.value = tTo;
    frm.slToTimePart.value = tToPart;
    if (!formVal (frm)) {
        return false;
    }
    if (!validDate ()) {
        return false;
    }
    return true;
}
//var foo = false;
var str = "details";
function setUpForm () {

    frm = document[str];
    frm.onsubmit = doFormQS;
}
function getValue (fix, type, swch) {
    with (document.details) {
        return (type == 'Year')
		? (swch)
			? elements[fix + type].selectedIndex
			: elements[fix + type].options[elements[fix + type].selectedIndex].text
		: (elements[fix + type].selectedIndex + 1);
    }
}
function setDefYear (frm) {
    if (frm.defyearFrom.value) {
        frm.slFromYear[frm.defyearFrom.value].selected = true;
    }
    if (frm.defyearTo.value) {
        frm.slToYear[frm.defyearTo.value].selected = true;
    }
}
function setYear (ipt) {
     ipt.length = 0;
     var year = new Date ().getFullYear ();
     ipt[ipt.length] = new Option (year, year);
     ipt[ipt.length] = new Option (year+1, year+1);
     ipt[ipt.length] = new Option (year+2, year+2);
}
var months = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
function doLeapYear (inY) {
    if ((inY % 400 == 0) || (inY % 4 == 0) && (!(inY % 100 == 0))) {
        months[1] = 29;
    } else {
        months[1] = 28;
    }
}
function setDays (ipt, mn, inY, slo) {
    var sl = 0;
    if (ipt.selectedIndex) {
        sl = ipt.selectedIndex;
    }
    doLeapYear (inY);
    ipt.length = 0;
    for (var i = 0; i < months[mn-1]; i++) {
        ipt[ipt.length] = new Option (i+1, i+1);
    }
    if (sl > (ipt.length-1)) {
        sl = (ipt.length-1);
    }
    if (slo) {
        ipt.options[0].selected = true;
    } else {
        ipt.options[sl].selected = true;
    }
}
function checkTime() {
 if (frm.selFromTime.value == frm.selToTime.value) {
	alert('check rental time')
	return false;
	}
	}
function modDays () {
    with (document.details) {
        setDays (slFromDay, slFromMonth[slFromMonth.selectedIndex].value, slFromYear[slFromYear.selectedIndex].value);
        setDays (slToDay, slToMonth[slToMonth.selectedIndex].value, slToYear[slToYear.selectedIndex].value);
    }
}
function addDur () {
    modDays ();
    return;
}
function chnDur () {
    modDays ();
    return;
}
function validDate (foo) {                
 var dspnum = '0870 400 4447';                
 if (foo) {dspnum = foo;}
        if (window.affnum) {dspnum = window.affnum;}        
        var daterror = 'The date specified has already passed.  If you wish to make a late booking then please call ' + dspnum + ' (7am - 10pm).'; 
        var daterror2 = 'drop off date is before pick up date.  please re-enter.';  
        var daterror3 = 'your rental must be between 09:00 to 17:30';  
        var daterror4 = 'the date specified indicates that you wish to make a booking which will either start within 12 hours, or you have selected a date that has already passed.';                
 var now = new dateAdd (-1);                
 var dateFrom = new Date(getValue('slFrom', 'Year'), (getValue('slFrom', 'Month') - 1), getValue('slFrom', 'Day'));                
 var dateTo = new Date(getValue('slTo', 'Year'), (getValue('slTo', 'Month') - 1), getValue('slTo', 'Day'));
 if (dateTo < dateFrom) {                    
  alert (daterror2);                    
  return false;                } 
 else {                    
 if (dateFrom <= (now.getDate() + 2)) {                        
  alert (daterror);                        
  return false;                    }   
/*
  now = new dateAdd (); 
 if (dateFrom <= now) {                        
  alert (daterror4);                        
  return false;                    }                
 }                
*/
 }

        
//
 return true;            
}          
var rootLength = 0;
function dateAdd (i, d) {
    var hours = (i) * 24
    var mills = (hours) * 3600000;
    tempDate = new Date ();
    if (d) {
        tempDate = d;
    }
    var buffer = Date.parse (tempDate) + mills;
    return new Date (buffer);
}
var myDate  = dateAdd (1);
var newDate = dateAdd (8);
myMonth = myDate.getMonth () + 1;
myMonthTo = newDate.getMonth () + 1;
myYear = myDate.getFullYear ();
myYearTo = newDate.getFullYear ();
myDay = myDate.getDate ();
myDayTo = newDate.getDate ();
function setDate (frm) {
    with (frm) {
        setYear (slFromYear);
        setYear (slToYear);
        if (parseInt(slToMonth.options[slToMonth.selectedIndex].value) == 1 &&
            parseInt(slFromMonth.options[slFromMonth.selectedIndex].value)) {
            for (var i = 0; i < slFromMonth.options.length; i++) {
                if (myMonth == parseInt (slFromMonth.options[i].value)) {
		            slFromMonth.options[i].selected = true;
		        }
		    }
            for (var i = 0; i < slFromYear.options.length; i++) {
                if (myYear == slFromYear.options[i].value) {
		            slFromYear.options[i].selected = true;
		        }
		    }
            for (var i = 0; i < slToMonth.options.length; i++) {
                if (myMonthTo == parseInt (slToMonth.options[i].value)) {
		            slToMonth.options[i].selected = true;
		        }
		    }
            for (var i = 0; i < slToYear.options.length; i++) {
                if (myYearTo == slToYear.options[i].value) {
		            slToYear.options[i].selected = true;
		        }
		    }
        }
        setDays (slToDay, slToMonth[slToMonth.selectedIndex].value, slToYear[slToYear.selectedIndex].value);
        setDays (slFromDay, slFromMonth[slFromMonth.selectedIndex].value, slFromYear[slFromYear.selectedIndex].value);
        if (parseInt(slToDay.options[slToDay.selectedIndex].value) == 1 &&
            parseInt(slFromDay.options[slFromDay.selectedIndex].value) == 1) {
            for (var i = 0; i < slFromDay.options.length; i++) {
                if (myDay == parseInt (slFromDay.options[i].value)) {
		            slFromDay.options[i].selected = true;
		        }
		    }
            for (var i = 0; i < slToDay.options.length; i++) {
                if (myDayTo == parseInt (slToDay.options[i].value)) {
		            slToDay.options[i].selected = true;
		        }
		    }
      }
    }
}
function launchpress (file) {
    window.open ("/GBR/press_releases/" + file);
}
function winPop (url) {
    var width = 400; 	// width of window
    var height = 250; 	// height of window
    var top = 0;		// distance from top of left corner
    var left = 0;		// distance from left of left corner
    var details = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",scrollbars=yes";
    if (url) {
        var win = window.open(url, '', details);
        win.focus();
    } else {
        alert("please select an option");
        document.details.popup.focus();
    }
}
function valChar (elmt, valType) {
    var valid;
    if (valType == "text") {
        valid = " abcdefghijklmnopqrstuvwxyz";
    } else {
        valid = "0123456789";
    }
    var rtn = true;
    var temp;
    for (var i = 0; i < elmt.value.length; i++) {
        temp = elmt.value.toLowerCase ().substring (i, i+1);
        if (valid.indexOf (temp) == -1) {
            rtn = false;
        }
    }
    return rtn;
}
function signUp () {
    window.open ('http://www.holidayautos.co.uk/cgi-bin/liveweb.sh/pagewrapper.w?ctryref=GBR&lang=EN&page=subscribepage', '', 'status,noscrollbars,width=500,height=500');
}
function priceTrack () {
window.open ('/GBR/pricetrackerform.htm' ,'pricetrack' ,'height=640,width=350');
}
var _ie   = navigator.appName.indexOf ("Microsoft Internet Explorer");
var _ns   = navigator.appName.indexOf ("Netscape");
var bVer = parseInt (navigator.appVersion);
function bookMarkIt () {
    if (_ie != -1 && bVer >= 4) {
        window.external.AddFavorite (location.href, document.title);
    } else if (_ns != -1 || _ie != -1 && bVer <= 3) {
        alert ("Sorry your browser does not support auto-bookmarking please press Ctrl+D to bookmark");
    } else {
        alert ("Sorry your browser does not support auto-bookmarking please use your browsers bookmark function");
    }
}
function getElement (id) {
    if (document.getElementById ()) {
        return document.getElementById (id);
    }
    if (document.all) {
        return document.all[id];
    }
    if (document.layers) {
        return document.layers[id];
    }
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function doResetSwap () { //v3.0
  var i,j=0,x,a=doResetSwap.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; x.oSrc=null;}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function replace(string,text,by) {
// Replaces text with by in string - used for the locaton names for omniture, some have comma seperated text values, and these commas need replacimg with dashes so that the data doesn't get confused.
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
	
}


