function Tag(item) { 

	if (document.all) {

		return document.all[item];
	} else if (document.layers) {

		return false;
	} else {

		return document.getElementById(item);
	}
}


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) {

	if (!frm) {
        frm = document[str];
    }
    if (!formVal (frm)) {
        return false;
    }
    if (!validDate (foo)) {
        return false;
    }
    if (!checkDate ()) {
        return false;
    }
    return true;
}
*/

/* PW doForm function */
// QSearch form validation
function doFormQS()
{
 // get today's date
 var tDate = new Date();
 
 // build 2 dates from dropdowns
 var pDate = new Date(document.details.slFromYear.value,document.details.slFromMonth.value - 1,document.details.slFromDay.value);
 var dDate = new Date(document.details.slToYear.value,document.details.slToMonth.value - 1,document.details.slToDay.value);
 
 var tMonth = tDate.getMonth();
 var tDay = tDate.getDate();
 
 var pMonth = pDate.getMonth();
 var pDay = pDate.getDate();
 
 // check for a country
 if(document.details.area.value == "sel" || document.details.area.value == "none")
 {
  alert("Attenzione non hai selezionato il Paese di destinazione.");
  document.details.area.focus();
  return false;
 
 // check for a pick up location
 } else if(document.details.tlocation.value == "") {
  alert("Attenzione non hai selezionato la località di ritiro dell'autovettura");
  document.details.tlocation.focus();
  return false;
 
 // check for a drop off location
 } else if(document.details.tdropoff.value == "") {
  alert("Attenzione non hai selezionato la località di rilascio dell'autovettura");
  document.details.tdropoff.focus();
  return false;
 
 // check if pickup is today
 } else if (pMonth == tMonth && pDay == tDay) {
  alert("Spiacenti ma non possiamo garantirti il ritiro dell'autovettura per lo stesso giorno della prenotazione. Per maggiori informazioni telefona al nostro call center al numero 199.470.480");
  return false;}else if (pMonth == tMonth && pDay == (tDay + 1)) {
  alert("Spiacenti ma non possiamo garantirti il ritiro dell'autovettura per il giorno successivo a quello della prenotazione. Per maggiori informazioni telefona al nostro call center al numero 199.470.480");
  return false;
 
 // check pickup date hasn't already passed
 }
  else if (pDate < tDate){
  alert("Attenzione la data di ritiro dell'autovettura non è valida");
  document.details.slFromMonth.focus();
  return false;
 
 // compare the 2 dates
 } else if(dDate < pDate) {
  alert("Attenzione la data di rilascio dell'autovettura è anteriore alla data di ritiro");
  document.details.slFromMonth.focus();
  return false;
 
 // check there is a driver age
 } else if(document.details.fiDriverAge.value == "") {
  alert("Attenzione non hai inserito l'età del guidatore");
  document.details.fiDriverAge.focus();
  return false;
 
 // check driver age is valid
 } else if(document.details.fiDriverAge.value < 21 || document.details.fiDriverAge.value > 70) {
  alert("Se hai meno di 21 anni o più di 70 anni, non rientri nelle condizioni applicate per l'autonoleggio. Per maggiori informazioni telefona al nostro call center al numero 199.470.480");
  document.details.fiDriverAge.focus();
  return false;
 
 }
}






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;
}
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 () + 2;
myDayTo = newDate.getDate () + 3;
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;
	
}


// get a variable from the querystring
function getQueryVariable(variable)
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i = 0; i < vars.length; i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
		{
			return pair[1];
		}
	} 
}




// deeplink into carlist.w
function carlistLink(area,loc) {
	// get area & location
	var area = area;
	var location = loc;
	
	if(getQueryVariable("aff")) {
		var affcode = getQueryVariable("aff");
	} else {
		var affcode = "";
	}
	
	// get pick up dates
	var fDate = document.details.slFromDay.value;
	var fMonth = document.details.slFromMonth.value;
	if(fMonth < 10)
	{
		fMonth = "0" + fMonth;
	}
	var fYear = document.details.slFromYear.value;
	var fTime = document.details.slFromTime.value;
	fTimeNew = new String(fTime);
	fTimeNew.replace(":","%3A");
	
	// get drop off dates
	var tDate = document.details.slToDay.value;
	var tMonth = document.details.slToMonth.value;
	if(tMonth < 10)
	{
		tMonth = "0" + tMonth;
	}
	var tYear = document.details.slToYear.value;
	var tTime = document.details.slToTime.value;
	tTimeNew = new String(tTime);
	tTimeNew.replace(":","%3A");

	var baseURL = "/cgi-bin/liveweb.sh/carlist.w?UckUcZllaaIpkkac=&POlfigXkjkjkWbdq=&SblzdbFStskKccak=&ctryref=ITA&lang=IT";
	
	var action = baseURL + "&aff=" + affcode + 
						"&selFromTime=" + fTimeNew + 
						"&slFromDay=" + fDate + 
						"&slFromMonth=" + fMonth + 
						"&slFromYear=" + fYear + 
						"&selToTime=" + tTimeNew + 
						"&slToDay=" + tDate +
						"&slToMonth=" + tMonth + 
						"&slToYear=" + tYear + 
						"&area=" + area + 
						"&tlocation=" + location + 
						"&tdropoff=" + location + 
						"&fidriverage=26";

	window.location = action;
}

// chnDur and addDur to get rid of js errors
function chnDur() { }
function addDur() { }


