function ChangeLink()
{
    var links = document.getElementsByTagName('a');
    for(i=0;i<links.length;i++)
    {
       if((links[i].href).match("guestrecognition"))
        {
        }
        else
        { 
        links[i].href=(links[i].href).replace("global/en",countrySession +"/"+ cultureSession.substring(0,2));
        }
    }
}

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 ShowDeptDate()
{
    var monthYear = document.getElementById(content+'_cmbDeptMon').value;
    var month = monthYear.substr(0,2);
    var year = monthYear.substr(2,4);
    var isValidDate = IsValidDate(month + "/" + document.getElementById(content+'_cmbDeptDay').value + "/" + year);
    if (isValidDate)
    {
        popup = open('/sites/etihad/_layouts/etihad/obe/fltselectiondate.aspx?Day=' + document.getElementById(content+'_cmbDeptDay').value + "&month=" + month + "&year=" + year + '&txtDay=' + document.getElementById(content+'_cmbDeptDay').id + '&txtMonth=' + document.getElementById(content+'_cmbDeptMon').id + '&txtYear=txtYear&Source=Depart', 'SS', 'status=no, height=163, width=355, left = 618,top = 298 ','');
        popup.focus();
    }
    else
    {
        alert (InvalidDate);
    }
}

function ShowReturnDate()
{
	var radioOneWay    =  document.getElementById(content+'_rdbListTripType_0');
    var monthYear = document.getElementById(content+'_cmbRetMon').value;
    var month = monthYear.substr(0,2);
    var year = monthYear.substr(2,4);	    
    var deptMonthYear = document.getElementById(content+'_cmbDeptMon').value;
    var deptMonth = deptMonthYear.substr(0,2);
    var isValidDate = IsValidDate(month + "/" + document.getElementById(content+'_cmbRetDay').value + "/" + year);
	if(radioOneWay.checked == false)
    {      
	    if (isValidDate)
    	{
    		popup = open('/sites/etihad/_layouts/etihad/obe/fltselectiondate.aspx?Day=' + document.getElementById(content+'_cmbRetDay').value + "&month=" + month + "&year=" + year+ '&txtday=' + document.getElementById(content+'_cmbRetDay').id + '&txtMonth=' + document.getElementById(content+'_cmbRetMon').id + '&txtYear=txtYear&Source=Return' + '&DeptDay=' + document.getElementById(content+'_cmbDeptDay').value + "&DeptMonth=" + deptMonth, 'SS', 'status=no,height=163, width=355,left = 618,top = 298','');
    		popup.focus();
   		 }
    	else
    	{
    
       	 alert ("Invalid Date selection");
   		 }
    }
}

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 CompareDates()
{     
    var radioOneWay    =  document.getElementById(content+'_rdbListTripType_0');
    var radioRoundTrip =  document.getElementById(content+'_rdbListTripType_1');
    if(radioOneWay.checked == true)
    {
       tripCode = 'O';
    }
    else if(radioRoundTrip.checked == true)
    {
         tripCode = 'R';      
    }
    if (tripCode == "R")
    {
        var monthYearRet = document.getElementById(content+'_cmbRetMon').value;
        var dayRet = parseInt(document.getElementById(content+'_cmbRetDay').value,10);
        var monthRet = monthYearRet.substring(0,2);
        var yearRet = monthYearRet.substring(2,6);
        var monthYearDept = document.getElementById(content+'_cmbDeptMon').value;
        var dayDept = parseInt(document.getElementById(content+'_cmbDeptDay').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(content+'_cmbRetDay').options.length;i++)
                {
                    if(document.getElementById(content+'_cmbRetDay').options[i].value == dayDept)
                    {
                        document.getElementById(content+'_cmbRetDay').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(content+'_cmbRetMon').options.length;i++)
                {
                    if(document.getElementById(content+'_cmbRetMon').options[i].value == monthYearDept)
                    {
                        document.getElementById(content+'_cmbRetMon').options[i].selected = true;
                        for(i=0;i<document.getElementById(content+'_cmbRetDay').options.length;i++)
                        {
                            if(document.getElementById(content+'_cmbRetDay').options[i].value == dayDept)
                            {
                                document.getElementById(content+'_cmbRetDay').options[i].selected = true;
                            }
                        }
                    }
                }
            }
        }
    }
}

function DisableReturnDate()
{
    var radioOneWay    =  document.getElementById(content+'_rdbListTripType_0');
    var radioRoundTrip =  document.getElementById(content+'_rdbListTripType_1');
    var userMonReturn  =  document.getElementById(content+'_cmbRetMon');    
    var userDayReturn  =  document.getElementById(content+'_cmbRetDay');
    var userCal        =  document.getElementById('img1');

    if(radioOneWay.checked == true)
    {
        userCal.disabled= true;
        userMonReturn.disabled = true;
        userDayReturn.disabled = true;
    }
    else if(radioRoundTrip.checked == true)
    {
        userCal.disabled= false;
        userMonReturn.disabled = false;
        userDayReturn.disabled = false;
    }
}

/******************************************************************************
/Purpose:	It is called on click of  get flight schedule button  event 
/Inputs:	void
/Returns:	void
/*****************************************************************************/ 
function RequiredDate(errorCode1,errorCode2,errorCode3)
{
    // get the value of the textbox
    var todays=new Date();
    var radioRoundTrip =  document.getElementById(content+'_rdbListTripType_1');
    var radioOneWay    =  document.getElementById(content+'_rdbListTripType_0');

    departureMonth=document.getElementById(content+'_cmbDeptMon');
    deptMnthValue=departureMonth.options[departureMonth.selectedIndex].value;

    var userMon=deptMnthValue.substr(0,2);

    var userYear=deptMnthValue.substr(2,4);
    // Get the selected date for the departure
    var currdate= new Date(todays.getFullYear(),todays.getMonth(),todays.getDate())	   
    var userDay=document.getElementById(content+'_cmbDeptDay').selectedIndex+1;	

    var passedDate=new Date(userYear,userMon-1,userDay);

    	    
    // Get the return date	 
    returnMonth=   document.getElementById(content+'_cmbRetMon');
    retMnthValue=returnMonth.options[returnMonth.selectedIndex].value;
    var userMonReturn=retMnthValue.substr(0,2);
    var userYearReturn=retMnthValue.substr(2,4);
    var userDayReturn=document.getElementById(content+'_cmbRetDay').selectedIndex+1;

    var returnDate=new Date(userYearReturn,userMonReturn-1,userDayReturn);

    var todays1=new Date();
    var todays=new Date(todays1.getFullYear(),todays1.getMonth(),todays1.getDate());
               
       
    // If one way trip is selected     
    if(document.getElementById(content+'_rdbListTripType_0').checked)
    {         
        // If origin date is empty                            
        if(todays > passedDate )
        {
            alert(errorCode2);
            return false;
         } 
    }
    // If Round trip is selected
    else if(document.getElementById(content+'_rdbListTripType_1').checked )
    {
        // if Either of the return or origin date is not given                                         
        if(todays > passedDate || todays > returnDate )
        {
            alert(errorCode2);
            return false;
        } 
        // If departure date is greater than return date 
        else if(returnDate<passedDate)
        {
            alert(errorCode3);
            return false;
        }
    }
}  

function ValidateFields()
{      
    var origin =  document.getElementById(content+'_ddlOrigin1');
    var destination = document.getElementById(content+'_ddlDestination1');
  
    destinationValue = destination.options[destination.selectedIndex].value;
    originValue = origin.options[origin.selectedIndex].value;
           
     if(originValue == "AS")
    {
        alert("Please Select Origin");
        return false;
    }
    if(destinationValue == "AS")
    {
        alert("Please Select Destination");
        return false;
    }
} 
 

