﻿// validation on requested url -- start
     var flt_timing_inter;
     var flt_timing_domest_arr;
     var flt_timing_domest_dep;      
     var flt_type=querySt("stype");
     var flt_way=querySt("smode");
     var sflno=querySt("sflno");
     var sdest=querySt("sdest");
     var flno,fldest;

function doInit()
{
    if(flt_way=='NoVal')
    {
    flt_way="A";
    }
    else
    {
        if(flt_way=='A')
        {    
        flt_way="A";
        }
        else
        {
        flt_way="D";
        } 
    }
   
    if(flt_type=='NoVal')
    {
    flt_type="I";
    }
    else
    {
        if(flt_type=='I')
        {    
        flt_type="I";
        }
        else
        {
        flt_type="D";
        }     
    }

    if(sflno=="NoVal")
    {
    document.getElementById('txtArrFlightNo').value="";
    document.getElementById('txtDepFlightNo').value="";
    sflno="";
    }
    else
    {
        if(flt_way=='A')
        {
        document.getElementById('txtArrFlightNo').value=sflno;
        }
        else
        {
        document.getElementById('txtDepFlightNo').value=sflno;
        }
    }

    if(sdest=="NoVal")
    {
     document.getElementById('txtArrFlightFrom').value="";
     document.getElementById('txtDepFlightFrom').value="";
     sdest="";
    }
    else
    {
        if(flt_way=='A')
        {
        document.getElementById('txtArrFlightFrom').value=sdest;
        }
        else
        {
        document.getElementById('txtDepFlightFrom').value=sdest;
        }    
    }

     flno=$('#txtArrFlightNo').val();
     fldest=$('#txtArrFlightFrom').val();  
     
     // init tab image and radio bt start
      if(flt_way=="A")
        {
         hideFlightInfoTab();
          $("#live-fligh-arrival-on").fadeIn(500);
          $("#imgFInfoFT").attr("src","/images/live-fligh-arrival-on.gif");
          
            if(flt_type=="I")
            {
            $("#rblArrFlType_0").attr("checked","true");
            }
            else
            {
            $("#rblArrFlType_1").attr("checked","true");
            }    
        }
        else
        {
           hideFlightInfoTab();
          $("#live-fligh-departure-on").fadeIn(500);
          $("#imgFInfoFT").attr("src","/images/live-fligh-departure-on.gif");
          
            if(flt_type=="I")
            {
            $("#rblDepFlType_0").attr("checked","true");
            }
            else
            {
            $("#rblDepFlType_1").attr("checked","true");
            }    
        
        }
        // init tab image and radio bt end
        
        // init search start  
     getFlInfoTimeSch(flt_way,flt_type,sflno,sdest); 
      // init search end
    }
     
     
    function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
    ft = gy[i].split("=");
    if (ft[0] == ji) {
    return ft[1];
    }
    else
    {
    return "NoVal";
    }
    }
    } 
      
//postnumber
	
		

         $(document).ready(function() {	
               doInit();
                 $('#btFindArr').click(function () {
                
		            // get arrival filter
		                var mode;
                      if(document.getElementById('rblArrFlType_0').checked==true)
                         mode="I";
                        else
                         mode="D";
		                var flno=$('#txtArrFlightNo').val();
		                var fldest=$('#txtArrFlightFrom').val();
	                   getFlInfoTimeSch('A',mode,flno,fldest);
	            });
        	    
	            $('#btFindDept').click(function () {
		            // get departure filter
		           var mode;
                  if(document.getElementById('rblDepFlType_0').checked==true)
                     mode="I";
                    else
                     mode="D";
	                var flno=$('#txtDepFlightNo').val();
	                var fldest=$('#txtDepFlightFrom').val();
		            getFlInfoTimeSch('D',mode,flno,fldest);
	           });
		}); 		
		
		// tab control
		 function openFlightInfoTab(id)
            {
                hideFlightInfoTab();
              $("#"+id).fadeIn(500);
             $("#imgFInfoFT").attr("src","/images/"+id+".gif");
             if(id=='live-fligh-arrival-on')
             {
                var type;
                  if(document.getElementById('rblArrFlType_0').checked)
                     type="I";
                    else
                     type="D";                    
                    var flno=$('#txtArrFlightNo').val();
                    var fldest=$('#txtArrFlightFrom').val();
                  
                    getFlInfoTimeSch('A',type,flno,fldest);
             }
             else
             {
              var type;
                  if(document.getElementById('rblDepFlType_0').checked)
                     type="I";
                    else
                     type="D";                   
	                var flno=$('#txtDepFlightNo').val();
	                var fldest=$('#txtDepFlightFrom').val();
                    
                    getFlInfoTimeSch('D',type,flno,fldest);
             }
            	
            }
            
        function hideFlightInfoTab()
        {
            $("#live-fligh-arrival-on").hide();
            $("#live-fligh-departure-on").hide();
        }	
		         
		function getFlInfoTimeSch(mode,type,FltNum,FltFrom)
		{
	
		
		 $.ajax({
             type: "get",
             url: "getFidsAllflightSch.aspx" ,
             data: "FltType="+mode+"&FltWay="+type+"&FltNum="+FltNum+"&FltFrom="+FltFrom+"&rn=" + Math.random(),dataType:"text",
               error: function(xhr,error) {
                  //alert( "Error: an error occured please retry" + xhr.responseText)
                  },
              success: function(response) 
              {
             
                  if(mode=='A') // for type arrival
                  {
                   $("#flArrTime").html(response);
	              }
	              else // for type departure
	              {
	                $("#flDeptTime").html(response);               
                  }
               }
            });
		}
		
		function getFlInfoTime(type,mode)
		{	

		    if(type=='a') // arrival
		    {
		        var flno=$('#txtArrFlightNo').val();
                var fldest=$('#txtArrFlightFrom').val();
		        if(mode==1) //inter
		        {
		          getFlInfoTimeSch('A','I',flno,fldest);
		        }
		        if(mode==2)// domestic
		        {
		           getFlInfoTimeSch('A','D',flno,fldest);
		        }
		    }
		    else // departure
		    {
		        var flno=$('#txtDepFlightNo').val();
	            var fldest=$('#txtDepFlightFrom').val();
		        if(mode==1) //inter
		        {
		           getFlInfoTimeSch('D','I',flno,fldest);
		        }
		        if(mode==2) // domestic
		        {
		            getFlInfoTimeSch('D','D',flno,fldest);
		        }
		    } 
		}

