﻿// JScript File

        function body_onload()
            {
            var txtDate = new Date();
            var monthname = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
            txtDate.setDate(txtDate.getDate()+ 2)
            document.getElementById('txtDatePU').value = (txtDate.getDate()) + ' ' + monthname[txtDate.getMonth()] + ' ' + txtDate.getFullYear() ;
            txtDate.setDate(txtDate.getDate()+ 2)
            document.getElementById('txtDateDO').value = (txtDate.getDate()) + ' ' + monthname[txtDate.getMonth()] + ' ' + txtDate.getFullYear() ;
            CountryListLoad('ddlCountryRes');
            var optionsPU = { script: '/diyGetLocationList.aspx?', varname: 'searchterm', delay:'0', className: 'autosuggest', minchars: '1', noresults: 'No match found', json: true, maxresults: 3, callback: function (obj) { document.getElementById('txtLocationCodePU').value = obj.id ;}};
            var asPU = new bsn.AutoSuggest('txtLocationPU', optionsPU);
            var optionsDO = { script: '/diyGetLocationList.aspx?', varname: 'searchterm', delay:'0', className: 'autosuggest', minchars: '1', noresults: 'No match found', json: true, maxresults: 3, callback: function (obj) { document.getElementById('txtLocationCodeDO').value = obj.id ;}};
            var asDO = new bsn.AutoSuggest('txtLocationDO', optionsDO);

            var strLocationName = new String(document.location);
            var strFileNameIndex = strLocationName.lastIndexOf('/') ;
            if (strLocationName.indexOf('car-hire-') > 0) {
                strLocationName = strLocationName.substr(strFileNameIndex);
                strLocationName = strLocationName.replace(/\/car-hire-/gi,'');
                strLocationName = strLocationName.replace(/---/gi,'|||');
                strLocationName = strLocationName.replace(/-/gi,' ');
                strLocationName = strLocationName.replace(/\|\|\|/gi,' - ');
                strLocationName = strLocationName.replace(/.aspx/gi,'');
                document.getElementById('txtLocationPU').value = strLocationName;
                //asPU.getSuggestions(strLocationName);
            }

            var timeList = new Array('00:00','00:30','01:00','01:30','02:00','02:30','03:00','03:30','04:00','04:30','05:00','05:30','06:00','06:30','07:00','07:30','08:00','08:30','09:00','09:30','10:00','10:30','11:00','11:30','12:00','12:30','13:00','13:30','14:00','14:30','15:00','15:30','16:00','16:30','17:00','17:30','18:00','18:30','19:00','19:30','20:00','20:30','21:00','21:30','22:00','22:30','23:00','23:30');
            var ddlTimePU = document.getElementById('ddlTimePU') ;
            var ddlTimeDO = document.getElementById('ddlTimeDO') ;
	        for (var count = ddlTimePU.options.length-1; count >-1; count--)
	        {
		        ddlTimePU.options[count] = null;
	        }
	        for (var count = ddlTimeDO.options.length-1; count >-1; count--)
	        {
		        ddlTimeDO.options[count] = null;
	        }
	        for (var i=0; i < timeList.length;++i){
                var optn = document.createElement('OPTION');
                optn.text = timeList[i];
                optn.value = timeList[i];
                ddlTimePU.options.add(optn);
            }
	        for (var i=0; i < timeList.length;++i){
                var optn = document.createElement('OPTION');
                optn.text = timeList[i];
                optn.value = timeList[i];
                ddlTimeDO.options.add(optn);
            }
            //ddlTimePU.options.value = '09:00';
            //ddlTimeDO.options.value = '09:00';
            ddlTimePU.value = '09:00';
            ddlTimeDO.value = '09:00';
            var qs = new Querystring()
            if (qs.contains('LocationPU')) {
                if ( !qs.get('LocationPU') =='' )
                {
                document.getElementById('txtLocationPU').value = qs.get('LocationPU').replace('+',' ');
                }
            }
            if (qs.contains('SameReturnLoc')) {
                if (qs.get('SameReturnLoc') == '0') {
                    setCheckedValue(document.forms['aspnetForm'].elements['SameReturnLoc'], '0');
                    document.getElementById('txtLocationDO').style.visibility = 'visible';
                    document.getElementById('txtLocationDO').style.display = 'block';
                    if (qs.contains('LocationDO')) {
                        if ( !qs.get('LocationDO') =='' )
                        {
                        document.getElementById('txtLocationDO').value = qs.get('LocationDO').replace('+',' ');
                        }
                    }
                }
            }
            if (qs.contains('LocationCodePU')) {
                document.getElementById('txtLocationCodePU').value = qs.get('LocationCodePU').replace(/-/g,' ');
            }
            if (qs.contains('LocationCodeDO')) {
                document.getElementById('txtLocationCodeDO').value = qs.get('LocationCodeDO').replace(/-/g,' ');
            }
            if (qs.contains('DatePU')) {
                document.getElementById('txtDatePU').value = qs.get('DatePU').replace(/-/g,' ');
            }
            if (qs.contains('DateDO')) {
                document.getElementById('txtDateDO').value = qs.get('DateDO').replace(/-/g,' ');
            }
            if (qs.contains('TimePU')) {
                document.getElementById('ddlTimePU').value = qs.get('TimePU');
            }
            if (qs.contains('TimeDO')) {
                document.getElementById('ddlTimeDO').value = qs.get('TimeDO');
            }
            if (qs.contains('CountryRes')) {
                document.getElementById('ddlCountryRes').value = qs.get('CountryRes');
            }
            if (qs.contains('DriverAge')) {
                document.getElementById('ddlDriverAge').value = qs.get('DriverAge');
            }
            if (qs.contains('CarClass')) {
                document.getElementById('ddlCarClass').value = qs.get('CarClass');
            }
        }

function getCheckedValue(radioObj) {
	if(!radioObj)
		return '';
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return '';
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return '';
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}    
            
function disableDatesBeforeToday(theDate){
    //var today = new Date('16 Feb 2009');
    var txtDate = new Date();
    var monthname = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
    var today = new Date(txtDate.getDate() + ' ' + monthname[txtDate.getMonth()] + ' ' + txtDate.getFullYear()) ;
    if (theDate < today)
        {
        return true; //alert('Today is after 14th January 2010');
        }
        else
        {
        return false; //alert('Today is before 14th January 2010');
        }
}
            
function showdiv(id){ 
    if (document.getElementById){ 
        obj = document.getElementById(id); 
        obj.style.display = ''; 
        } 
    }

function hidediv(id){ 
    if (document.getElementById){ 
        obj = document.getElementById(id); 
        obj.style.display = 'none';
        } 
    }

function DateIsGreaterThanToday(sender, args)
  {
    var mydate = new Date(args.Value);
    var fulldatetime = new Date();
    var today = new Date(fulldatetime.getFullYear(), fulldatetime.getMonth(), fulldatetime.getDate() - 1);
    if (mydate > today) 
    {
       args.IsValid = true;
    }
    else
    {
       args.IsValid = false;
    }
  }

function RedirectCountry(ddl)
    {
    var index = ddl.selectedIndex;
    location = 'http://www.' + ddl.options[index].value;
    //alert(ddl.options[index].value);
    }

function ValidateSearchForm(btn)
    {
        var rdoSameReturnLoc = document.forms['aspnetForm'].elements['SameReturnLoc'];
        var strSameReturnLoc = getCheckedValue(rdoSameReturnLoc);
        var txtPU = document.getElementById('txtLocationPU');
        var txtDO = document.getElementById('txtLocationDO');
        var txtCodePU = document.getElementById('txtLocationCodePU');
        var txtCodeDO = document.getElementById('txtLocationCodeDO');
        var strPU = txtCodePU.value;
        var strDO = txtCodeDO.value;
        var divwarning = document.getElementById('search-warning');
        if ( !strPU == '' ) //PU is OK
        {
            if ( strSameReturnLoc == '0' ) //PU is OK AND check DO
            {
                if ( !strDO == '' ) //PU is OK AND DO is OK
                {
                return true;
                }
                else //PU is OK AND DO is not OK
                {
                divwarning.style.visibility = 'visible';
                divwarning.style.display = 'block';
                divwarning.innerHTML = 'Please enter a valid return location';
                txtDO.style.color = "#f00";
                return false;
                }
            }
            else //PU is OK AND do not check DO
            {
                return true;
            }
        }
            else //PU is not OK
        {
            divwarning.style.visibility = 'visible';
            divwarning.style.display = 'block';
            txtPU.style.color = '#f00';
            divwarning.innerHTML = 'Please enter a valid pick up location';
            return false;
        }
    }
    
function SameReturnLocSelected()
    {
    var txtPU = document.getElementById('txtLocationPU');
    var txtDO = document.getElementById('txtLocationDO');
    var txtCodeDO = document.getElementById('txtLocationCodeDO');
    var divwarning = document.getElementById('search-warning');
    txtDO.style.visibility = 'hidden';
    txtDO.style.display = 'none';
    txtDO.value = 'Return location';
    txtCodeDO.value = '';
    divwarning.innerHTML = '';
    divwarning.style.visibility = 'hidden';
    divwarning.style.display = 'none';
    txtPU.style.color = "#000";
    txtDO.style.color = "#000";
    }

function OtherReturnLocSelected()
    {
    var txtPU = document.getElementById('txtLocationPU');
    var txtDO = document.getElementById('txtLocationDO');
    var txtCodeDO = document.getElementById('txtLocationCodeDO');
    var divwarning = document.getElementById('search-warning');
    txtDO.style.visibility = 'visible';
    txtDO.style.display = 'block';
    txtDO.value = 'Click here to enter a return location';
    txtCodeDO.value = '';
    divwarning.innerHTML = '';
    divwarning.style.visibility = 'hidden';
    divwarning.style.display = 'none';
    txtPU.style.color = "#000";
    txtDO.style.color = "#000";
    }