	//------------------------------------------------------------------------------------------------
//-------------------------------- Flight Search Validation --------------------------------------
//------------------------------------------------------------------------------------------------
//            childAgesElemsIds
//            childAgesRowElemId
//            hfChildAgeValidityElemId 
//            hfChildAgeMsgElemId,
//            noOfNightsElemId,
function IMPACT_FltSearchValidation(
            depDateElemId,
            retDateElemId,
            depDateHFElemId,
            retDateHFElemId,
            childCountElemId,                        
            hfDateValidityElemId,
            hfDateMsgElemId,
            hfNightValidityElemId,
            hfNightMsgElemId,
            hfReturnTypeElemId,
            offset                      
            )
{
   this.depDateElem = document.getElementById(depDateElemId);
   this.retDateElem = document.getElementById(retDateElemId);
   this.depDateHFElem = document.getElementById(depDateHFElemId);
   this.retDateHFElem = document.getElementById(retDateHFElemId);
   this.childCountElem = document.getElementById(childCountElemId);
   //this.noOfNightsElem = document.getElementById(noOfNightsElemId);
   this.hfDateValidityElem = document.getElementById(hfDateValidityElemId);
   this.hfDateMsgElem = document.getElementById(hfDateMsgElemId);
   this.hfNightValidityElem = document.getElementById(hfNightValidityElemId);
   this.hfNightMsgElem = document.getElementById(hfNightMsgElemId);
   this.hfReturnTypeElem = document.getElementById(hfReturnTypeElemId);
   this.offset = offset;
   /*
   this.hfChildAgeValidityElem = document.getElementById(hfChildAgeValidityElemId);
   this.hfChildAgeMsgElem = document.getElementById(hfChildAgeMsgElemId);
   this.childAgesRowElem = document.getElementById(childAgesRowElemId);
   this.childAgesElems = new Array();
   for(var i = 0;i < childAgesElemsIds.length;i++)
   {
        this.childAgesElems[i] = document.getElementById(childAgesElemsIds[i]);
   }
   */
   this.IMPACT_validateFltSearchCriteria = IMPACT_validateFltSearchCriteria;
   //this.IMPACT_setChildCount = IMPACT_setChildCount;
   //this.IMPACT_showChildAges = IMPACT_showChildAges;   
}
function IMPACT_validateFltSearchCriteria() 
{
   var depDate = this.depDateElem.value;      
   var retDate = this.retDateElem.value;      
   var childCount = this.childCountElem.value;       
   var isDateValid = this.hfDateValidityElem.value;
   var invalidDateMsg = this.hfDateMsgElem.value ;
   var isNoOfNightsValid = this.hfNightValidityElem.value;
   var invalidNoOfNightsMsg = this.hfNightMsgElem.value;
   //var isChildAgesValid = this.hfChildAgeValidityElem.value;
   //var invalidChilAgeMsg = this.hfChildAgeMsgElem.value;
   var offset = this.offset;
   var returnType = this.hfReturnTypeElem.value;
   var noOfNights;
   // departure date validation
   if(depDate == '')
   {       
        isDateValid = false; 
        invalidDateMsg = "Departure date is empty";       
   } 
   else
   {
        if(depDate.split('/').length != 3)
        {
            isDateValid = false;
            invalidDateMsg = "Invalid departure date" ;
        }            
        else 
        {
            var day = depDate.split('/')[0];
            var month = depDate.split('/')[1];
            var year = depDate.split('/')[2];
            if(IMPACT_checkNumeric(day) && IMPACT_checkNumeric(month) && IMPACT_checkNumeric(year))
            {
                if(IMPACT_validateDate(day,month,year))
                {                       
                    if(IMPACT_isCorrectDateFlight(day,month,year,offset))
                    {
                        isDateValid = true;
                    }
                    else
                    {                            
                        isDateValid = false;
                        invalidDateMsg = "Invalid departure date. Searches cannot be made within " +offset+ " days";
                    }                     
                }
                else
                {
                   isDateValid = false;
                   invalidDateMsg = "Invalid departure date" ;
                }
            }
            else
            {
                isDateValid = false;
                invalidDateMsg = "Invalid departure date" ;
            }         
        }
   }
   var day1 = depDate.split('/')[0];
   var month1 = depDate.split('/')[1];
   var year1 = depDate.split('/')[2];
   var date1 = new Date();
   date1.setFullYear(parseInt(year1), parseInt(month1)-1, parseInt(day1));
   if(returnType == "RT")
   {
       var day2 = retDate.split('/')[0];
       var month2 = retDate.split('/')[1];
       var year2 = retDate.split('/')[2];
       var date2 = new Date();
       date2.setFullYear(parseInt(year2), parseInt(month2)-1, parseInt(day2));
       noOfNights = parseInt(date2 - date1) / 86400000;
       //alert(noOfNights);
       // no of night validation
       if(!IMPACT_checkNumeric(noOfNights))
        {
            isNoOfNightsValid = false;
            invalidNoOfNightsMsg = "Invalid no of nights"; 
        }
        else
        {
            if(parseInt(noOfNights) > 0 && parseInt(noOfNights) < 50)
            {
                 isNoOfNightsValid = true;
            }
            else
            {
                isNoOfNightsValid = true;
                invalidNoOfNightsMsg = "No of nights should be less than 50 days"; 
            }
        } 
   }  
   if(!isDateValid)
   {
        alert(invalidDateMsg);
        return 'F';
   }
   else if(!isNoOfNightsValid)
   {
        alert(invalidNoOfNightsMsg);
        return 'F';
   }
   else
   {
        return 'T';
   }               
}
function IMPACT_setChildCount(count)
{
    this.childCountElem.value = count;
}
function IMPACT_showChildAges()
{
    var childCount = this.childCountElem.value;        
    var maxNoOfChildren = 9;
    if(childCount == '0')
    {
        this.childAgesRowElem.style.display = 'none';
    }
    else
    {
        this.childAgesRowElem.style.display = '';
        for(var i=0; i<parseInt(childCount); i++)
        {
            this.childAgesElems[i].style.display = '';
        }
        for(var i=parseInt(childCount); i<maxNoOfChildren; i++)
        {
            this.childAgesElems[i].style.display = 'none';
        }        
    }
}    
//------------------------------------------------------------------------------------------------
//---------------------------- End Of Flight Search Validation -----------------------------------
//------------------------------------------------------------------------------------------------

