function ShowDeptDate()
{
    var monthYear = document.getElementById(cmbDeptMonId).value;
    var month = monthYear.substr(0,2);
    var year = monthYear.substr(2,4);
    var isValidDate = IsValidDate(month + "/" + document.getElementById(cmbDeptDayId).value + "/" + year);
    
    if (isValidDate)
    {
        var outputDateFormat = 'ddMMyyyy';
        
        var origin = document.getElementById(BookFlightId+'_ddlOrigin1').value;
        var destination = document.getElementById(BookFlightId+'_ddlDestination1').value;
        
        var guestZone = document.getElementById(BookFlightId+'_ddlGuestZone').value;
        
        var radioOneWay    =  document.getElementById(BookFlightId+'_rdbListTripType_0');
        var radioRoundTrip =  document.getElementById(BookFlightId+'_rdbListTripType_1');
        var tripCode = "";
        
        
        if(radioOneWay.checked == true)
        {
            tripCode = "O";
        }
        else
        {
            tripCode = "R";
        }
        
        //popup = open('/sites/etihad/_layouts/etihad/obe/fltselectiondate.aspx?Day=' + document.getElementById(cmbDeptDayId).value + "&month=" + month + "&year=" + year + '&txtDay=' + document.getElementById(cmbDeptDayId).id + '&txtMonth=' + document.getElementById(cmbDeptMonId).id + '&txtYear=txtYear&Source=Depart', 'SS', 'status=no, height=163, width=355, left = 162,top = 134 ','');

        var qryStr = 
        '/sites/Etihad/_layouts/Etihad/obe/ShowCalenderX.aspx?Day=' + 
                        document.getElementById(cmbDeptDayId).value + "&month=" + 
                        month + "&year=" + year + '&txtDay=' + 
                        document.getElementById(cmbDeptDayId).id + '&txtMonth=' + 
                        document.getElementById(cmbDeptMonId).id + 
                        '&txtYear=txtYear&Source=Depart' +
                        '&DeptDay=&DeptMonth=' + 
                        '&OutputDateFormat=' + outputDateFormat + 
                        '&OriginPort=' + origin +
                        '&DestPort=' + destination + 
                        '&StartDate=&EndDate=' +
                        '&GuestZone=' + guestZone + '&TripCode=' + tripCode + '&IsSerach=Y';
                     
        var returnValue = window.open(qryStr, 'SS', 'status=no, height=163, width=355, left = 162,top = 134 ','');
    }
    else
    {
        alert (InvalidDate);
    }
}

function ShowReturnDate()
{
    var monthYear = document.getElementById(cmbRetMonId).value;
    var month = monthYear.substr(0,2);
    var year = monthYear.substr(2,4);	    
    var deptMonthYear = document.getElementById(cmbDeptMonId).value;
    var deptMonth = deptMonthYear.substr(0,2);
    var isValidDate = IsValidDate(month + "/" + document.getElementById(cmbRetDayId).value + "/" + year);

    if (isValidDate)
    {
        var outputDateFormat = 'ddMMyyyy';
        
        var origin = document.getElementById(BookFlightId+'_ddlOrigin1').value;
        var destination = document.getElementById(BookFlightId+'_ddlDestination1').value;
        
        var guestZone = document.getElementById(BookFlightId+'_ddlGuestZone').value;
        
        var radioOneWay    =  document.getElementById(BookFlightId+'_rdbListTripType_0');
        var radioRoundTrip =  document.getElementById(BookFlightId+'_rdbListTripType_1');
        var tripCode = "";
        
        if(radioOneWay.checked == true)
        {
            tripCode = "O";
        }
        else
        {
            tripCode = "R";
        }

        //popup = open('/sites/etihad/_layouts/etihad/obe/fltselectiondate.aspx?Day=' + document.getElementById(cmbRetDayId).value + "&month=" + month + "&year=" + year+ '&txtday=' + document.getElementById(cmbRetDayId).id + '&txtMonth=' + document.getElementById(cmbRetMonId).id + '&txtYear=txtYear&Source=Return' + '&DeptDay=' + document.getElementById(cmbDeptDayId).value + "&DeptMonth=" + deptMonth, 'SS','status=no,height=163, width=355,left = 200,top = 134','');

        var qryStr = 
        '/sites/etihad/_layouts/etihad/obe/ShowCalenderX.aspx?Day=' + 
                        document.getElementById(cmbRetDayId).value + "&month=" + 
                        month + "&year=" + year+ '&txtday=' + 
                        document.getElementById(cmbRetDayId).id + '&txtMonth=' + 
                        document.getElementById(cmbRetMonId).id + 
                        '&txtYear=txtYear&Source=Return' + 
                        '&DeptDay=' + document.getElementById(cmbDeptDayId).value + 
                        '&DeptMonth=' + deptMonth +  
                        '&OutputDateFormat=' + outputDateFormat + 
                        '&OriginPort=' + destination +
                        '&DestPort=' + origin + 
                        '&StartDate=&EndDate=' +
                        '&GuestZone=' + guestZone + '&TripCode=' + tripCode + '&IsSerach=Y';
                     
        var returnValue = window.open(qryStr, 'SS', 'status=no, height=163, width=355, left = 200,top = 134 ','');
    }
    else
    {
        alert ("Invalid Date selection");
    }
}

function OnDestinationChange()
{
    var flag = 0;
    var destList = "";
    var isStopOverFlt = false;
    var isStopOverFltDep = false;
    var isStopOverFltRet = false;
    var isOptionalStopOverDep = true;
    var isOptionalStopOverRet = true;
    var isOptionalStopOver = true;
    var isFlexiDateOption = true;
    
    var origin = document.getElementById(BookFlightId+'_ddlOrigin1').value;
    var destination = document.getElementById(BookFlightId+'_ddlDestination1').value;
    
	var radioOneWay = document.getElementById(BookFlightId+'_rdbListTripType_0');
	var tripCode = "";

	if(radioOneWay.checked == true)
	{tripCode = "O";}
	else
	{tripCode = "R";}
    
    if('' != origin && '' != destination)
    {           
        for (r = 0; r < route.length; r++)
        {
            if (flag == 1){flag = 0;break;}
            if (origin == route[r][0])
            {
                destList = route[r][1];
                flag = 1;
            }
        }
        for (indx = 0; indx < destList.length; indx++)
        {
            if (flag == 1){flag = 0;break;}
            if (destination == destList[indx])
            {
                flag = 1;
                isStopOverFltDep = destList[indx+1][0];
                isOptionalStopOverDep = destList[indx+1][1];
                isFlexiDateOption = destList[indx+1][2];
            }
        }

		if (tripCode == "R")
		{
			for (r = 0; r < route.length; r++)
			{
				if (flag == 1){flag = 0;break;}
				if (destination == route[r][0])
				{
					destList = route[r][1];
					flag = 1;
				}
			}
			for (indx = 0; indx < destList.length; indx++)
			{
				if (flag == 1){flag = 0;break;}
				if (origin == destList[indx])
				{
					flag = 1;
					isStopOverFltRet = destList[indx+1][0];
					isOptionalStopOverRet = destList[indx+1][1];
				}
			}

			isStopOverFlt = isStopOverFltDep || isStopOverFltRet;
		}
		else 
		{
			isStopOverFlt = isStopOverFltDep;
		}
		
        if(!isStopOverFltDep)
        {
            isOptionalStopOverDep = true;
        }
        
        if (tripCode == "R")
        {
			if(!isStopOverFltRet)
			{
				isOptionalStopOverRet = true;
			}
	        isOptionalStopOver = isOptionalStopOverDep && isOptionalStopOverRet;
        }
		else 
		{
			isOptionalStopOver = isOptionalStopOverDep;
		}

        if(isStopOverFlt)
        {
            var BookFlightName =ReplaceAll(BookFlightId,"_","$");

            if(isOptionalStopOverDep)
            {                
                if(navigator.appName=='Microsoft Internet Explorer')
                {
                    if (document.getElementById(BookFlightId+'_StopOverFlagDep') != null)
                    {
                        document.getElementById(BookFlightId+'_StopOverFlagDep').value = 'Y';
                    }
                }
                else
                {
                    if (document.getElementById(BookFlightName+'$StopOverFlagDep') != null)
                    {
                        document.getElementsByName(BookFlightName+'$StopOverFlagDep').value = 'Y';
                    }
                }
            }
            else
            {
                if(navigator.appName=='Microsoft Internet Explorer')
                {
                    if (document.getElementById(BookFlightId+'_StopOverFlagDep') != null)
                    {
                        document.getElementById(BookFlightId+'_StopOverFlagDep').value = 'N';
                    }
                }
                else
                {
                    if (document.getElementById(BookFlightName+'$StopOverFlagDep') != null)
                    {
                        document.getElementsByName(BookFlightName+'$StopOverFlagDep').value = 'N';
                    }
                }
            }
            
            if(isOptionalStopOverRet)
            {
                if(navigator.appName=='Microsoft Internet Explorer')
                {
                    if (document.getElementById(BookFlightId+'_StopOverFlagRet') != null)
                    {
                        document.getElementById(BookFlightId+'_StopOverFlagRet').value = 'Y';
                    }
                }
                else
                {
                    if (document.getElementById(BookFlightName+'$StopOverFlagRet') != null)
                    {
                        document.getElementsByName(BookFlightName+'$StopOverFlagRet').value = 'Y';
                    }
                }
            }
            else
            { 
                if(navigator.appName=='Microsoft Internet Explorer')
                {
                    if (document.getElementById(BookFlightId+'_StopOverFlagRet') != null)
                    {
                        document.getElementById(BookFlightId+'_StopOverFlagRet').value = 'N';
                    }
                }
                else
                {
                    if (document.getElementById(BookFlightName+'$StopOverFlagRet') != null)
                    {
                        document.getElementsByName(BookFlightName+'$StopOverFlagRet').value = 'N';
                    }
                }
            }
            
            if (document.getElementById(BookFlightId+'_chkStopOver') != null)
            {
                if(!isOptionalStopOver)
                {
                    document.getElementById(BookFlightId+'_chkStopOver').checked = true;
                    document.getElementById(BookFlightId+'_chkStopOver').disabled = true;
                    document.getElementById(BookFlightId+'_hdnStopoverDisabled').value = 'Y';
                    document.getElementById(BookFlightId+'_hdnStopoverCheck').value = 'Y'; 
                    document.getElementById(BookFlightId+'_chkStopOver').style.display = '';
                    document.getElementById(BookFlightId+'_lblStopOver').style.display = '';
                }
                else
                {
                    document.getElementById(BookFlightId+'_chkStopOver').checked = false;
                    document.getElementById(BookFlightId+'_chkStopOver').disabled = false;
                    document.getElementById(BookFlightId+'_ddlOrigin1').disabled = false;
                    document.getElementById(BookFlightId+'_hdnStopoverDisabled').value = 'N';
                    document.getElementById(BookFlightId+'_hdnStopoverCheck').value = 'N'; 
                    document.getElementById(BookFlightId+'_chkStopOver').style.display = '';
                    document.getElementById(BookFlightId+'_lblStopOver').style.display = '';
                }
            }
        }
        else
        {
            if (document.getElementById(BookFlightId+'_StopOverFlagDep') != null)
            {
                document.getElementById(BookFlightId+'_StopOverFlagDep').value = 'N';
            }
            if (document.getElementById(BookFlightId+'_StopOverFlagRet') != null)
            {
                document.getElementById(BookFlightId+'_StopOverFlagRet').value = 'N';
            }        
            HideStopOverChk();
        }

        if (isFlexiDateOption)
        {
            if(document.getElementById(BookFlightId + '_divFlexiDates') != null
                && document.getElementById(BookFlightId + '_divFlexiDates').style.display=='none')
            {
               document.getElementById(BookFlightId + '_divFlexiDates').style.display = '';
               document.getElementById(BookFlightId + '_chkFlexiDates').style.display = '';
               document.getElementById(BookFlightId + '_lblFlexiDates').style.display = '';
            }
            
            if (document.getElementById(BookFlightId + '_hdnFlexiDatesOption') != null)
            {
                document.getElementById(BookFlightId + '_hdnFlexiDatesOption').value = 'Y';
                document.getElementById(BookFlightId + '_chkFlexiDates').checked = true;
            }
        }
        else 
        {
            if (document.getElementById(BookFlightId + '_hdnFlexiDatesOption') != null)
            {
                document.getElementById(BookFlightId + '_hdnFlexiDatesOption').value = 'N';
                HideFlexiDatesChk();
            }
        }
    }
    else
    {
        HideStopOverChk();
        HideFlexiDatesChk();
    }
}


function fillArrivalList(id)
{
    var destinationClientID = document.getElementById(BookFlightId+'_ddlDestination1');    
    var currentDest = destinationClientID.value;
    
    var flag = 0;
    var destList = "";
    var destName = "";
    var destCode = "";
    
    for (r = 0; r < route.length; r++)
    {
        if (flag == 1){break;}
        if (id == route[r][0])
        {
	        destList = route[r][1];
	        flag = 1;
        }
    }
    
    var len = destinationClientID.length;
    for (indx = len-1; indx >= 0; indx--)
    {
        destinationClientID.remove(indx);
    }
    
    var optn = document.createElement('option');
    optn.text = "Please Select";
    optn.value = '';
	destinationClientID[destinationClientID.length] = optn;
	
    if (destList != "")
    {
        for (r = 0; r < codeNameArr.length; r+=2)
        {
            flag = 0;
            destCode = "";
            destName = "";
            for (indx = 0; indx < destList.length; indx++)
            {
	            if (flag == 1){break;}
	            if (codeNameArr[r] == destList[indx])
	            {
		            destCode = codeNameArr[r];
		            destName = codeNameArr[r+1];
                    flag = 1;
	            }
            }
            if (destCode != "" && destName != "")
            {
                optn = document.createElement('option');
                optn.text = destName;
                optn.value = destCode;
	            destinationClientID[destinationClientID.length] = optn;
            }
         }
    }
    
    if (currentDest != '') {
        for(j = 0; j < destinationClientID.options.length; j++) {
            if (destinationClientID.options[j].value == currentDest) {
                destinationClientID.value = currentDest;
                break;
            }
        }
        
    }
    
    OnDestinationChange();
}


function fillOrigDestCombo(originPort) 
{
    var originControl = document.getElementById(BookFlightId+'_ddlOrigin1');
    optn = document.createElement('option');     
    optn.text = "Please Select";
    optn.value = '';
	originControl[originControl.length] = optn;
    
	for (r = 0; r < codeNameArr.length; r+=2)
    {
        flag = 0;
        for (indx = 0; indx < route.length; indx++)
        {
	        if (flag == 1){break;}
	        if (codeNameArr[r] == route[indx][0])
	        {
		        orgCode = codeNameArr[r];
		        orgName = codeNameArr[r+1];
                flag = 1;
	        }
        }
        if (flag == 1)
        {
            optn = document.createElement('option');
            optn.text = orgName;
            optn.value = orgCode;
	        originControl[originControl.length] = optn;
        }
        if(originControl.length == (route.length+1)){break;}
    }
    selectDefaultPort(BookFlightId+'_ddlOrigin1', originPort);
    fillArrivalList(originControl.options[originControl.selectedIndex].value);
}


function fillDestCombo(destinationPort) 
{
    var destinationControl = document.getElementById(BookFlightId+'_ddlDestination1');
    selectDefaultPort(BookFlightId+'_ddlDestination1', destinationPort);
}

function selectDefaultPort(portDropDownName, defaultPort)
{
    if (defaultPort != "" || defaultPort != null)
    {
        var portControl = document.getElementById(portDropDownName);
        for(i=0;i<portControl.options.length;i++)
        {
            if (portControl.options[i].value ==  defaultPort)
            {
                
                portControl.options[i].selected = true;
                break;
            }
        }
    }
}

function onRadioChange()
{
    var radioOneWay    =  document.getElementById(BookFlightId+'_rdbListTripType_0');
    var radioRoundTrip =  document.getElementById(BookFlightId+'_rdbListTripType_1');
    var userMonReturn  =  document.getElementById(BookFlightId+'_cmbRetMon');
    var userDayReturn  =  document.getElementById(BookFlightId+'_cmbRetDay');
    var userCal        =  document.getElementById('img1');
    if(radioOneWay.checked == true)
    {
        userMonReturn.disabled = true;
        userDayReturn.disabled = true;
        userCal.disabled=true;
    }
    else if(radioRoundTrip.checked == true)
    {
        userMonReturn.disabled = false;
        userDayReturn.disabled = false; 
        userCal.disabled=false;           
    }
    OnDestinationChange();
}    

function stopoverCheck()
{
    if(document.getElementById(BookFlightId+'_chkStopOver').checked)
    {
        document.getElementById(BookFlightId+'_hdnStopoverCheck').value = 'Y'; 

        if(document.getElementById(BookFlightId + '_chkFlexiDates') != null
            && document.getElementById(BookFlightId + '_chkFlexiDates').checked)
        {
            document.getElementById(BookFlightId + '_chkFlexiDates').checked = false;
            document.getElementById(BookFlightId + '_hdnFlexiDatesOption').value = 'N'; 
        }
    }
    else
    {
        document.getElementById(BookFlightId+'_hdnStopoverCheck').value = 'N'; 
    }
}

function FlexiDatesCheck()
{
    if(document.getElementById(BookFlightId + '_chkFlexiDates') != null
        && document.getElementById(BookFlightId + '_chkFlexiDates').checked)
    {
        document.getElementById(BookFlightId + '_hdnFlexiDatesOption').value = 'Y'; 

        if(document.getElementById(BookFlightId + '_chkStopOver') != null
            && document.getElementById(BookFlightId + '_chkStopOver').checked)
        {
            document.getElementById(BookFlightId + '_chkStopOver').checked = false;
            document.getElementById(BookFlightId + '_hdnStopoverCheck').value = 'N'; 
        }
    }
    else
    {
        if (document.getElementById(BookFlightId + '_hdnFlexiDatesOption') != null)
        {
            document.getElementById(BookFlightId + '_hdnFlexiDatesOption').value = 'N';
        }
    }
}

function HideStopOverChk()
{
    if (document.getElementById(BookFlightId+'_chkStopOver') != null)
    {
        document.getElementById(BookFlightId+'_chkStopOver').style.display = 'none';
        document.getElementById(BookFlightId+'_lblStopOver').style.display = 'none';
        document.getElementById(BookFlightId+'_hdnStopoverCheck').value = 'N';     
        document.getElementById(BookFlightId+'_hdnStopoverDisabled').value = 'N';     
    }
}

function HideFlexiDatesChk()
{
    if (document.getElementById(BookFlightId + '_hdnFlexiDatesOption') != null)
    {
        //document.getElementById(BookFlightId + '_chkFlexiDates').style.display = 'none';
        //document.getElementById(BookFlightId + '_lblFlexiDates').style.display = 'none';
        //document.getElementById(BookFlightId + '_divFlexiDates').style.display = 'none';
        document.getElementById(BookFlightId + '_hdnFlexiDatesOption').value = 'N';
    }
}

function validateBookFlight(bookingErr1 ,bookingErr2, bookingErr3,bookingErr4,bookingErr5 ,bookingErr6 ,                                       bookingErr7,bookingErr8,selectOrig,ButtonClicked)
{
    var todays=new Date();
	var radioRoundTrip = document.getElementById(BookFlightId+'_rdbListTripType_1');
	var radioOneWay = document.getElementById(BookFlightId+'_rdbListTripType_0');
    departureMonth=document.getElementById(BookFlightId+'_cmbDeptMon');
    deptMnthValue=departureMonth.options[departureMonth.selectedIndex].value;
	
	var userMon=deptMnthValue.substr(0,2);
	   
	var userYear=deptMnthValue.substr(2,4);
	
	var currdate= new Date(todays.getFullYear(),todays.getMonth(),todays.getDate())	   
	var userDay=document.getElementById(BookFlightId+'_cmbDeptDay').selectedIndex+1;	
	    
	var passedDate=new Date(userYear,userMon-1,userDay);
	  
	returnMonth=   document.getElementById(BookFlightId+'_cmbRetMon');
	retMnthValue=returnMonth.options[returnMonth.selectedIndex].value;
	var userMonReturn=retMnthValue.substr(0,2);
	var userYearReturn=retMnthValue.substr(2,4);
	var userDayReturn=document.getElementById(BookFlightId+'_cmbRetDay').selectedIndex+1;
	   	    
	var returnDate=new Date(userYearReturn,userMonReturn-1,userDayReturn);
	    	     
	if(document.getElementById(BookFlightId+'_ddlOrigin1').selectedIndex==0)
	{
	    alert(selectOrig); 	    	    
	    return false;
    }
	else if(document.getElementById(BookFlightId+'_ddlDestination1').selectedIndex==0)
	{
	    alert(bookingErr1); 
	    return false;
    }
    if(radioOneWay.checked == true)
    {
        if(!validDates(userMon,userDay,userYear,'dept'))
        {
            return false;
        }
        else if(passedDate < currdate)
	    {	
	        alert(bookingErr7);
            return false;
        }        
    }
    if(radioRoundTrip.checked == true)
    { 
        if(document.getElementById(BookFlightId+'_ddlDestination1').options[document.getElementById(BookFlightId+         '_ddlDestination1').selectedIndex].value == document.getElementById(BookFlightId+'_ddlOrigin1').options           [document.getElementById(BookFlightId+'_ddlOrigin1').selectedIndex].value) 
        {
            alert(bookingErr6); 
            document.getElementById(BookFlightId+'_ddlOrigin1').focus();                  
            return false ;
        }
        else if(!validDates(userMon,userDay,userYear,'dept'))
        {
            return false;
        }
        else if(!validDates(userMonReturn,userDayReturn,userYearReturn,'ret'))
        {
            return false;
        }
        else if(passedDate < currdate || returnDate < currdate )
        {	
            alert(bookingErr7);
            return false;
        }
        // If departure date is greater than return date    
        else if(passedDate > returnDate)
        {
            alert(bookingErr8);
            return false;
        }
    } 
    if(ButtonClicked=='1' && pName=='guestrecognition')
    {
        var orig_code=document.getElementById(BookFlightId+'_ddlOrigin1').options[document.getElementById                             (BookFlightId+'_ddlOrigin1').selectedIndex].value;
        var dest_code=document.getElementById(BookFlightId+'_ddlDestination1').options[document.getElementById                        (BookFlightId+'_ddlDestination1').selectedIndex].value;
        var sliderURL='/sites/etihad/_layouts/etihad/attaek_popup.aspx?origin='+orig_code+'&destination='+                            dest_code;        
        fnOpenWin(sliderURL,'407','220');
        return false;
    }
} 

function validDates(month,day,year,type)
{
    var Message;
    if(type=='dept')
    {
        Message=invalidDepDate;
    }
    else
    {
        Message=invalidRetDate;
    }
 
    if ((month==04 || month==06 || month==09 || month==11) && day>30)
	{
	    alert(Message);
		return false;
    }
	else if (month == 02)
	{
	    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap))
		{
		    alert(Message);
			return false;
        }
    }
    return true;  
}

function fnOpenWin(strURL,winWidth,winHeight) 
{
    var chngpass;
    strWinName='EtihadPopup'
    winTop=0; 
    winLeft=0;
    winLeft=Math.floor((Math.abs(screen.availWidth-winWidth))/2);
    winTop= Math.floor((Math.abs(screen.availHeight-winHeight))/2);
    try
    {
        if(strWin!=null)
        {     		
            strWin.close();
        }
    }
    catch (e){};
    strWin=window.open(strURL,"DownloadImage",'top= '+ winTop + ',left=' + winLeft + ',width=' + winWidth + ',        height= '+winHeight+',toolbar=nomenubar=yes,location=no,directories=no,status=no,resizable=yes,scrollbars=no,     scrollbar=no');
    strWin.focus();
}

function popUp(URL) 
{
    eval("poppage = window.open(URL, 'poppage', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable    =0,width=450,height=420,left = 162,top = 134');");
}

var tripCode;
function IsValidDate(PossibleDate)
{
    var PDate = new String(PossibleDate);
	var regex = /(^\d{1,2})\/(\d{1,2})\/(\d{4,4})|(^\d{1,2})\/(\d{1,2})\/(\d{2,2})/;
	if( regex.test(PDate) )
	{
	    var month = new String(RegExp.$1);
		var day = new String(RegExp.$2);
		var year = new String(RegExp.$3);
		if( month.length == 0 )
		{
		    month = new String(RegExp.$4);
			day = new String(RegExp.$5);
			year = new String(RegExp.$6);
        }
		var today = new Date();
		var thisYear = new String(today.getFullYear());
		if( year.length == 2 )
		{
		    if( year > 50 )
			{
			    year = String(Number(thisYear.substring(0,2))-1) + year;
            }
			else
			{
			    year = thisYear.substring(0,2) + year;
            }
        }
		if( month < 1 || month > 12 ) { return false; }
		if( day < 1 || day > 31 ) { return false; }
		if ((month==4 || month==6 || month==9 || month==11) && day>30)
		{
            return false;
        }
        if (month == 2)
        {
            var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
            if (day>29 || (day==29 && !isleap))
            {
			    return false;
            }
        }
		if((Number(year) < Number(thisYear) - 250)||(Number(year) > Number(thisYear) + 250) )
		{
		    return false;
        }
        return true;
    }
	return false;
}

function ValidateDepDate(source, arguments)
{
    var monthYear = document.getElementById(cmbDeptMonId).value;
    var month = monthYear.substring(0,2);
    var year = monthYear.substring(2,6);
    var day = document.getElementById(cmbDeptDayId).value;
    if (ValidateDate(day, month, year)== false)
    {
        strErrMsg=document.getElementById("OBE_530_INVALIDDEPARTUREDATE").value;
        document.getElementById("custValDepDate").errormessage = strErrMsg;
        arguments.IsValid = false;
    }
}

function ValidateRetDate(source, arguments)
{
    var radioOneWay    =  document.getElementById(BookFlightId+'_rdbListTripType_0');
    var radioRoundTrip =  document.getElementById(BookFlightId+'_rdbListTripType_1');
    if(radioOneWay.checked == true)
    {
        tripCode = 'O';
    }
    else if(radioRoundTrip.checked == true)
    {
        tripCode = 'R';      
    }
    if (tripCode == "R")
    {
        var monthYear = document.getElementById(cmbRetMonId).value;
        var month = monthYear.substring(0,2);
        var year = monthYear.substring(2,6);
        var day = document.getElementById(cmbRetDayId).value;
        if(ValidateDate(day, month, year) == false)
        {
            strErrMsg=document.getElementById("OBE_533_INVALIDRETURNDATE").value;
            document.getElementById("custValRetDate").errormessage = strErrMsg;
            arguments.IsValid = false;
        }
    }
}

function CompareDates()
{      

    var radioOneWay    =  document.getElementById(BookFlightId+'_rdbListTripType_0');
    var radioRoundTrip =  document.getElementById(BookFlightId+'_rdbListTripType_1');
    if(radioOneWay.checked == true)
    {
        tripCode = 'O';
    }
    else if(radioRoundTrip.checked == true)
    {
        tripCode = 'R';      
    }
    if (tripCode == "R")
    {
        var monthYearRet = document.getElementById(cmbRetMonId).value;
        var dayRet = parseInt(document.getElementById(cmbRetDayId).value,10);
        var monthRet = monthYearRet.substring(0,2);
        var yearRet = monthYearRet.substring(2,6);
        var monthYearDept = document.getElementById(cmbDeptMonId).value;
        var dayDept = parseInt(document.getElementById(cmbDeptDayId).value,10);
        var monthDept = monthYearDept.substring(0,2);
        var yearDept =monthYearDept.substring(2,6);
        if((parseInt(yearRet) == parseInt(yearDept)) && (parseInt(monthRet,10) == parseInt(monthDept,10)))
        {
            if(dayRet < dayDept)
            {
                for(i=0;i<document.getElementById(cmbRetDayId).options.length;i++)
                {
                    if(document.getElementById(cmbRetDayId).options[i].value == dayDept)
                    {
                        document.getElementById(cmbRetDayId).options[i].selected = true;
                    }
                }
            }
        }
        else
        {
            if (((parseInt(yearRet) == parseInt(yearDept)) && (parseInt(monthRet,10) < parseInt(monthDept,10)))||
                (parseInt(yearRet) < parseInt(yearDept)) )
            {
                for(i=0;i<document.getElementById(cmbRetMonId).options.length;i++)
                {
                    if(document.getElementById(cmbRetMonId).options[i].value == monthYearDept)
                    {
                        document.getElementById(cmbRetMonId).options[i].selected = true;
                        for(i=0;i<document.getElementById(cmbRetDayId).options.length;i++)
                        {
                            if(document.getElementById(cmbRetDayId).options[i].value == dayDept)
                            {
                                document.getElementById(cmbRetDayId).options[i].selected = true;
                            }
                        }
                    }
                }
            }
        }
    }
}

function CompareToSysDate(source, arguments)
{
    var currentDate = new Date();
	var monthYearDept = document.getElementById(cmbDeptMonId).value;
	var dayDept = parseInt(document.getElementById(cmbDeptDayId).value,10);
	var monthDept = monthYearDept.substring(0,2);
	var yearDept =monthYearDept.substring(2,6);
	if(parseInt(yearDept) == currentDate.getFullYear() && parseInt(monthDept,10) == (currentDate.getMonth() + 1))
    {
        if(dayDept < currentDate.getDate() )
	    {
            strErrMsg = document.getElementById("OBE_530_INVALIDDEPARTUREDATE").value;
            document.getElementById("custValCompSysDate").errormessage = strErrMsg;
            arguments.IsValid = false;
        }
    }
}

function ValidateDate(day, month, year)
{
    if((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30 )){return false;}
    if((year % 4) == 0 && day > 29 && month == 2){return false;}
    if((year % 4) != 0 && day > 28 && month == 2){return false;}
    return true;
}
function ReplaceAll(Source,stringToFind,stringToReplace){
  var temp = Source;
    var index = temp.indexOf(stringToFind);
        while(index != -1){
            temp = temp.replace(stringToFind,stringToReplace);
            index = temp.indexOf(stringToFind);
        }
        return temp;
}
function rdbalign()
   {
        var radioOneWay    =  document.getElementById(BookFlightId+'_rdbListTripType_0');
        var radioRoundTrip =  document.getElementById(BookFlightId+'_rdbListTripType_1');
        radioOneWay.style.verticalAlign='middle';
        radioRoundTrip.style.verticalAlign='middle';
        radioOneWay.nextSibling.style.verticalAlign='middle';
        radioRoundTrip.nextSibling.style.verticalAlign='middle';
       return false;
  }
