function IMPACT_setReturnType(type)
{
    IMPACT_radioBtnElem.value = type;
}
//function IMPACT_setReturnDateItSelf()
//{
//    var dd = txtCheckOutDate.value.split("/" )[0];
//	var mm = txtCheckOutDate.value.split("/" )[1];
//	var yyyy = txtCheckOutDate.value.split("/" )[2];
//	
//	if(dd.length < 2)
//	{
//	    dd = "0" + dd;
//	}
//	
//	if(mm.length < 2)
//	{
//	    mm = "0" + mm;
//	}
//	
//	//alert(dd + "/" + mm + "/" + yyyy);
//	retDateHF.value = dd + "/" + mm + "/" + yyyy;
//}
//function IMPACT_setReturnDate()
//{
//    Date.fromUKFormat = function(sUK) 
//    { 
//        var A = sUK.split(/[\\\/]/); 
//        A = [A[1],A[0],A[2]]; 
//        return new Date(Date.parse(A.join('/'))); 
//    }
//    var depDate = new Date(Date.fromUKFormat(IMPACT_checkInDate.value));
//    var newRetDate = new Date();
//    newRetDate.setFullYear(depDate.getFullYear(),depDate.getMonth(),depDate.getDate() + IMPACT_dateDiff);
//    
//    if (!(IMPACT_checkOutDate.value == null || IMPACT_checkOutDate.value == 'dd/mm/yyyy'))
//    {
//        var tmpDate = new Date(Date.fromUKFormat(IMPACT_checkOutDate.value));
//        if (tmpDate - newRetDate > 0)
//        {
//            newRetDate = tmpDate;
//        }
//    }
//    
//	IMPACT_checkOutDate.value = newRetDate.format("dd/MM/yyyy");
//	
//	checkInDateHF.value = depDate.format("dd/MM/yyyy");
//	checkOutDateHF.value = newRetDate.format("dd/MM/yyyy");
//	IMPACT_setNoOfNightsCombo();
//}
function IMPACT_getSelectedDateForRet()
{
    IMPACT_LoadElement();
    Date.fromUKFormat = function(sUK) 
    { 
        var A = sUK.split(/[\\\/]/); 
        A = [A[1],A[0],A[2]]; 
        return new Date(Date.parse(A.join('/'))); 
    }
    var newRetDate = null;
    if (IMPACT_checkOutDate.value == null || IMPACT_checkOutDate.value == 'dd/mm/yyyy')
    {
        var depDate = new Date();
        var newRetDate = new Date();
        newRetDate.setFullYear(depDate.getFullYear(),depDate.getMonth(),depDate.getDate() + IMPACT_dateDiff);
    }
    else
    {
        newRetDate = new Date(Date.fromUKFormat(IMPACT_checkOutDate.value));
    }
    return newRetDate;
}
function IMPACT_getSelectedDateForRetCar() {
    IMPACT_LoadElement();
    Date.fromUKFormat = function(sUK) {
        var A = sUK.split(/[\\\/]/);
        A = [A[1], A[0], A[2]];
        return new Date(Date.parse(A.join('/')));
    }
    var newRetDate = null;
    if (IMPACT_CarcheckOutDate.value == null || IMPACT_CarcheckOutDate.value == 'dd/mm/yyyy') {
        var depDate = new Date();
        var newRetDate = new Date();
        newRetDate.setFullYear(depDate.getFullYear(), depDate.getMonth(), depDate.getDate() + IMPACT_dateDiff);
    }
    else {
        newRetDate = new Date(Date.fromUKFormat(IMPACT_CarcheckOutDate.value));
    }
    return newRetDate;
}
function IMPACT_getSelectedDateForRetTrns() {
    IMPACT_LoadElement();
    Date.fromUKFormat = function(sUK) {
        var A = sUK.split(/[\\\/]/);
        A = [A[1], A[0], A[2]];
        return new Date(Date.parse(A.join('/')));
    }
    var newRetDate = null;
    if (IMPACT_TrnscheckOutDate.value == null || IMPACT_TrnscheckOutDate.value == 'dd/mm/yyyy') {
        var depDate = new Date();
        var newRetDate = new Date();
        newRetDate.setFullYear(depDate.getFullYear(), depDate.getMonth(), depDate.getDate() + IMPACT_dateDiff);
    }
    else {
        newRetDate = new Date(Date.fromUKFormat(IMPACT_TrnscheckOutDate.value));
    }
    return newRetDate;
}
function IMPACT_getSelectedDateForDep()
{
    IMPACT_LoadElement();
    Date.fromUKFormat = function(sUK) 
    { 
        var A = sUK.split(/[\\\/]/); 
        A = [A[1],A[0],A[2]]; 
        return new Date(Date.parse(A.join('/'))); 
    }
    var newRetDate = null;
    if (IMPACT_checkInDate.value == null || IMPACT_checkInDate.value == 'dd/mm/yyyy')
    {
        var depDate = new Date();
        var newRetDate = new Date();
        newRetDate.setFullYear(depDate.getFullYear(),depDate.getMonth(),depDate.getDate() + IMPACT_dateOffset);
    }
    else
    {
        newRetDate = new Date(Date.fromUKFormat(IMPACT_checkInDate.value));
    }
    return newRetDate;
}
function IMPACT_getSelectedDateForDepCar() {
    IMPACT_LoadElement();
    Date.fromUKFormat = function(sUK) {
        var A = sUK.split(/[\\\/]/);
        A = [A[1], A[0], A[2]];
        return new Date(Date.parse(A.join('/')));
    }
    var newRetDate = null;
    if (IMPACT_CarcheckInDate.value == null || IMPACT_CarcheckInDate.value == 'dd/mm/yyyy') {
        var depDate = new Date();
        var newRetDate = new Date();
        newRetDate.setFullYear(depDate.getFullYear(), depDate.getMonth(), depDate.getDate() + IMPACT_dateOffset);
    }
    else {
        newRetDate = new Date(Date.fromUKFormat(IMPACT_CarcheckInDate.value));
    }
    return newRetDate;
}
function IMPACT_getSelectedDateForDepTrns() {
    IMPACT_LoadElement();
    Date.fromUKFormat = function(sUK) {
        var A = sUK.split(/[\\\/]/);
        A = [A[1], A[0], A[2]];
        return new Date(Date.parse(A.join('/')));
    }
    var newRetDate = null;
    if (IMPACT_TrnscheckInDate.value == null || IMPACT_TrnscheckInDate.value == 'dd/mm/yyyy') {
        var depDate = new Date();
        var newRetDate = new Date();
        newRetDate.setFullYear(depDate.getFullYear(), depDate.getMonth(), depDate.getDate() + IMPACT_dateOffset);
    }
    else {
        newRetDate = new Date(Date.fromUKFormat(IMPACT_TrnscheckInDate.value));
    }
    return newRetDate;
}
function IMPACT_getMinDateForFromCalender()
{
    var tmpDate = new Date();
    var minDate = new Date();
    minDate.setFullYear(tmpDate.getFullYear(),tmpDate.getMonth(),tmpDate.getDate() + IMPACT_dateOffset);     
    return minDate;    
}
function IMPACT_getMinDateForReturnCalender()
{
    var tmpDate = IMPACT_getSelectedDateForDep();
    var minDate = IMPACT_getSelectedDateForDep();
    minDate.setFullYear(tmpDate.getFullYear(),tmpDate.getMonth(),tmpDate.getDate() + IMPACT_dateDiff);     
    return minDate;
}
function IMPACT_getMinDateForReturnCalenderCar() {
    var tmpDate = IMPACT_getSelectedDateForDepCar();
    var minDate = IMPACT_getSelectedDateForDepCar();
    minDate.setFullYear(tmpDate.getFullYear(), tmpDate.getMonth(), tmpDate.getDate() + IMPACT_dateDiff);
    return minDate;
}
function IMPACT_getMinDateForReturnCalenderTrns() {
    var tmpDate = IMPACT_getSelectedDateForDepTrns();
    var minDate = IMPACT_getSelectedDateForDepTrns();
    minDate.setFullYear(tmpDate.getFullYear(), tmpDate.getMonth(), tmpDate.getDate() + IMPACT_dateDiff);
    return minDate;
}
function IMPACT_setNoOfNightsCombo()
{
    var date1 = null;
    var date2 = null;
    Date.fromUKFormat = function(sUK) 
    { 
        var A = sUK.split(/[\\\/]/); 
        A = [A[1],A[0],A[2]]; 
        return new Date(Date.parse(A.join('/'))); 
    }
    if (!(IMPACT_checkInDate.value == null || IMPACT_checkInDate.value == 'dd/mm/yyyy'))
    {
        date1 = new Date(Date.fromUKFormat(IMPACT_checkInDate.value)); 
        IMPACT_setComboDate(false, date1);
    }
    if (!(IMPACT_checkOutDate.value == null || IMPACT_checkOutDate.value == 'dd/mm/yyyy'))     
    {
        date2 = new Date(Date.fromUKFormat(IMPACT_checkOutDate.value));
        IMPACT_setComboDate(true, date2);
    } 
    if (date1 != null && date2 != null)
    {
        var noOfNights = ((date2 - date1) /(1000*60*60*24));
        nightsCombo.value = noOfNights;
        nightsHf.value = noOfNights;
    }
}
function IMPACT_setDateOptions(checkout, yearMonth)
{
    var daysMon = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    var datesField = null;
    if (checkout)
    {
        datesField = document.getElementById('cmbCheckOutDate');
    }
    else
    {
        datesField = document.getElementById('cmbCheckinDate');
    }
    var selected = datesField.value;
    var last  = 0;
    var A = yearMonth.split('-'); 
    var month = A[0];
    var year = A[1];
    var longYear = year%4==0;
    if (longYear)
    {
        daysMon[1] = 29;
    }        
    var days = daysMon[month];
    while(datesField.options.length > 1)
    {
        datesField.remove(1);
    }
    var opt = document.createElement("option");
    opt.text = "Select Nights";
    opt.value = "";
    datesField.add(opt,null);
    for (var i = 1; i < days ; i++)
    {
        var opt = document.createElement("option");
        opt.text = i + 1;
        opt.value = i + 1;
        datesField.add(opt,null);
        last = i+1;
    }
    datesField.value = selected > last?last : selected;      
}
function IMPACT_setComboDate(checkout, newDate)
{
    daysCombo = null;
    monthYearCombo = null;
    if (checkout)
    {
        daysCombo = document.getElementById('cmbCheckOutDate');  
        monthYearCombo = document.getElementById('cmbCheckOutMonthYear'); 
    }
    else
    {
        daysCombo = document.getElementById('cmbCheckinDate');  
        monthYearCombo = document.getElementById('cmbCheckinMonthYear');  
    }
    if (monthYearCombo != null && daysCombo != null)
    {
        monthYearCombo.value = newDate.getMonth() + "-" + newDate.getFullYear();
        IMPACT_setDateOptions(true,monthYearCombo.value);
        daysCombo.value = newDate.getDate();  
    }
}
function IMPACT_getDate(checkout)
{
    daysCombo = null;
    monthYearCombo = null;
    if (checkout)
    {
        daysCombo = document.getElementById('cmbCheckOutDate');  
        monthYearCombo = document.getElementById('cmbCheckOutMonthYear'); 
    }
    else
    {
        daysCombo = document.getElementById('cmbCheckinDate');  
        monthYearCombo = document.getElementById('cmbCheckinMonthYear');  
    }
    var A = monthYearCombo.value.split('-'); 
    var month = A[0];
    var year = A[1];
    var date = daysCombo.value;
    var selDate = new Date();
    selDate.setFullYear(parseInt(year),parseInt(month),parseInt(date));  
    return selDate; 
}
function IMPACT_checkIfDateRangeIsOk(checkout)
{
    var minDate = null;
    var maxDate = null;
    if (checkout)
    {
        minDate = IMPACT_getMinDateForReturnCalender();
    }
    else
    {   
        minDate = IMPACT_getMinDateForFromCalender();
        maxDate = IMPACT_getDate(true);
    }
    var selDate = IMPACT_getDate(checkout);
    if (((selDate - minDate) < 0) || (maxDate != null && (selDate - maxDate > 0)))
    {
        var date1 = null;
        var date2 = null;
        Date.fromUKFormat = function(sUK) 
        { 
            var A = sUK.split(/[\\\/]/); 
            A = [A[1],A[0],A[2]]; 
            return new Date(Date.parse(A.join('/'))); 
        }
        if (!checkout)
        {
            if (!(IMPACT_checkInDate.value == null || IMPACT_checkInDate.value == 'dd/mm/yyyy'))
            {
                date1 = new Date(Date.fromUKFormat(IMPACT_checkInDate.value)); 
                IMPACT_setComboDate(false, date1);  
            }
        }
        if (checkout)
        {
            if (!(IMPACT_checkOutDate.value == null || IMPACT_checkOutDate.value == 'dd/mm/yyyy'))     
            {
                date2 = new Date(Date.fromUKFormat(IMPACT_checkOutDate.value));
                IMPACT_setComboDate(true, date2);
            }
        }   
    }
    else
    {
        if (checkout)
        {
            IMPACT_checkOutDate.value = IMPACT_getDate(checkout).format('dd/MM/yyyy'); 
            checkOutDateHF.value = IMPACT_getDate(checkout).format('dd/MM/yyyy');
        }
        else
        {
            IMPACT_checkInDate.value = IMPACT_getDate(checkout).format('dd/MM/yyyy');
            checkInDateHF.value = IMPACT_getDate(checkout).format('dd/MM/yyyy');  
        }
        //IMPACT_setNoOfNightsCombo();
    }    
}

