﻿
        function openPUTTab(id,imgpl,childId,childImgId)
        {
            hidePUTTab();
            $("#"+id).fadeIn(800);
            $("#"+imgpl).attr("src","/images/"+id+".gif"); 
                       
        }
        function hidePUTTab()
        {
           $(".plTravel").hide();
           $("#dvSearchShop").html("");
        }

         $(document).ready(function() {	
            
               $('#btnShop').click(function () {
                  //choose shop	
                  var chk=false;
                  if($("#DDShTerminal").val()!="0" && $("#DDShCategory").val()!="0")
                   {
                    chk=true;
                   }

                   
                   if(!chk)
                   {
                    alert("choose terminal & category to display shops");
                    return false;
                   }
                   else
                   {
                     bindSearchDetails(1,$("#DDShTerminal").val(),$("#DDShLocation").val(),$("#DDShCategory").val(),$("#DDShShop").val())	       
	               }
	            });
	            
	            $('#btnEat').click(function () {
               //choose eat		
                var chk=false;
                
                if($("#DDETerminal").val()!="0" && $("#DDECategory").val()!="0")
                   {
                    chk=true;
                   }
                   
                 
                   
                   if(!chk)
                   {
                    alert("choose terminal & category to display eats");
                    return false;
                   }
                   else
                   {
		                bindSearchDetails(2,$("#DDETerminal").val(),$("#DDELocation").val(),$("#DDECategory").val(),$("#DDEShop").val())
	               }      
	            });
	            
	            $('#btnService').click(function () {
               //choose services	
               var chk=false;
                if($("#DDSrTerminal").val()!="0" && $("#DDSrCategory").val()!="0")
                   {
                    chk=true;
                   }
                   
                   
                        
                   if(!chk)
                   {
                    alert("choose terminal & category to display services");
                    return false;
                   }
                   else
                   {
		                bindSearchDetails(3,$("#DDSrTerminal").val(),$("#DDSrLocation").val(),$("#DDSrCategory").val(),$("#DDSrShop").val())
	               } 	       
	            });	            
        	  
		});
		
		 // bind search details		
		function bindSearchDetails(type,tid,lid,cid,sid)
        {
             $.ajax({
             type: "get",
             url: "get-shopeat-details.aspx" ,
             dataType: "text",
             data: {
              'type' : type,
              'tid' : tid,
              'lid' : lid,  
              'cid' : cid,  
              'sid' : sid,              
              'check': Math.random()
             },
             timeout: 68000,
             error: function(xhr,error) {
              //alert( "Error: an error occured please retry" + xhr.responseText)
              },
              success: function(data) {  
              
              if(type==1)
	        {
              $("#dvSearchShop1").html(data);                            
	        }
	        else if(type==2)
	        {
              $("#dvSearchShop2").html(data);                            
	        }
	        else if(type==3)
	        {
              $("#dvSearchShop3").html(data);                            
	        }
                        
               }
            });
          
        } 
        //end search details
        
	
	    function BindTerDD(type)
	    {
	        var tid,ddid;
	        if(type==1)
	        {
	        tid=$("#DDShTerminal").val();	
	        ddid="DDShCategory";       
	        }
	        else if(type==2)
	        {
	         tid=$("#DDETerminal").val();	
	         ddid="DDECategory";
	        }
	        else if(type==3)
	        {
	         tid=$("#DDSrTerminal").val();	
	         ddid="DDSrCategory";
	        }
	        bindDDTerminal(type,tid,ddid);
	    }
	    function BindLocDD(type)
	    {
	        var lid,ddid1,ddid2;
	        if(type==1)
	        {
	        lid=$("#DDShLocation").val();
	        ddid1="DDShCategory";
	        ddid2="DDShShop";		       
	        }
	        else if(type==2)
	        {
	        lid=$("#DDELocation").val();
	        ddid1="DDECategory";
	        ddid2="DDEShop";		       
	        }
	        else if(type==3)
	        {
	        lid=$("#DDSrLocation").val();
	        ddid1="DDSrCategory";
	        ddid2="DDSrShop";		       
	        }
	        bindDDLocation(type,lid,ddid1,ddid2);
	    }
	     function BindCatDD(type)
	    {
	        var cid,lid,tid,ddid;
	        if(type==1)
	        {
	        lid=$("#DDShLocation").val();
	        cid=$("#DDShCategory").val();
	        tid=$("#DDShTerminal").val();
	        ddid="DDShShop";		       
	        }
	        else if(type==2)
	        {
	         lid=$("#DDELocation").val();
	        cid=$("#DDECategory").val();
	        tid=$("#DDETerminal").val();
	        ddid="DDEShop";		       
	        }
	        else if(type==3)
	        {
	         lid=$("#DDSrLocation").val();
	         cid=$("#DDSrCategory").val();
	         tid=$("#DDSrTerminal").val();
	        ddid="DDSrShop";		       
	        }
	        bindDDCategory(type,cid,lid,tid,ddid);
	    }
	    
	    
	    // start terminal		
		function bindDDTerminal(type,tid,ddid)
        {
               
             $.ajax({
             type: "get",
             url: "bind-shopeat-terminal-change.aspx" ,
             dataType: "text",
             data: {
              'type' : type,
              'tid' : tid,            
              'check': Math.random()
             },
             timeout: 68000,
             error: function(xhr,error) {
              //alert( "Error: an error occured please retry" + xhr.responseText)
              },
              success: function(data) {   
              //alert(data);
                   $('#'+ddid+' >option').remove();
                   // binding locations only
                     var li=new Array();
                        li=data.split('##');
                       $('#'+ddid).append($('<option></option>').val("0").html("Choose a Category")); 
                        for(j=0;j<li.length;j++)
                        {
                            if(li[j].indexOf(',')!=-1)
                            {
                                var lidata=new Array();                                          
                                lidata=li[j].split(',');                                           
                                $('#'+ddid).append($('<option></option>').val(lidata[0].replace(/[\n\r\t]/g,'')).html(lidata[1].replace(/[\n\r\t]/g,''))); 

                             }                                                                        
                        }                   
                        
               }
            });
          
        } 
        //end terminal
        
        //start location
        function bindDDLocation(type,lid,ddid1,ddid2)
        {
               
             $.ajax({
             type: "get",
             url: "bind-shopeat-location-change.aspx" ,
             dataType: "text",
             data: {
              'type' : type,
              'lid' : lid,            
              'check': Math.random()
             },
             timeout: 68000,
             error: function(xhr,error) {
              //alert( "Error: an error occured please retry" + xhr.responseText)
              },
              success: function(data) {    
              //alert(data);
                  var liRes=new Array();
                  if(data.indexOf('$$')!=-1)
                   {
                    liRes=data.split('$$');
                   }
                  
                     if(liRes.length!=0)
                     {               
                    // binding category and shop
                     $('#'+ddid1+' >option').remove();
                        var li=new Array();
                        li=liRes[0].split('##');
                       $('#'+ddid1).append($('<option></option>').val("0").html("Choose a category")); 
                        for(j=0;j<li.length;j++)
                        {
                            if(li[j].indexOf(',')!=-1)
                            {
                                var lidata=new Array();                                          
                                lidata=li[j].split(',');                                           
                                $('#'+ddid1).append($('<option></option>').val(lidata[0].replace(/[\n\r\t]/g,'')).html(lidata[1].replace(/[\n\r\t]/g,''))); 

                             }                                                                        
                        }
                        // binding shop
                        $('#'+ddid2+' >option').remove();
                        var li=new Array();
                        li=liRes[1].split('##');
                       $('#'+ddid2).append($('<option></option>').val("0").html("Choose a shop")); 
                        for(j=0;j<li.length;j++)
                        {
                            if(li[j].indexOf(',')!=-1)
                            {
                                var lidata=new Array();                                          
                                lidata=li[j].split(',');                                           
                                $('#'+ddid2).append($('<option></option>').val(lidata[0].replace(/[\n\r\t]/g,'')).html(lidata[1].replace(/[\n\r\t]/g,''))); 

                             }                                                                        
                        }
                       }  
                    
                   }		       
            });
          
        } 
        //end location
        
         // start category		
		function bindDDCategory(type,cid,lid,tid,ddid)
        {
             $.ajax({
             type: "get",
             url: "bind-shopeat-category-change.aspx" ,
             dataType: "text",
             data: {
              'type' : type,
              'cid' : cid, 
              'lid' : lid,
              'tid' : tid,            
              'check': Math.random()
             },
             timeout: 68000,
             error: function(xhr,error) {
              //alert( "Error: an error occured please retry" + xhr.responseText)
              },
              success: function(data) {   
                   $('#'+ddid+' >option').remove();
                   // binding locations only
                     var li=new Array();
                        li=data.split('##');
                       $('#'+ddid).append($('<option></option>').val("0").html("Choose a shop")); 
                        for(j=0;j<li.length;j++)
                        {
                            if(li[j].indexOf(',')!=-1)
                            {
                                var lidata=new Array();                                          
                                lidata=li[j].split(',');                                           
                                $('#'+ddid).append($('<option></option>').val(lidata[0].replace(/[\n\r\t]/g,'')).html(lidata[1].replace(/[\n\r\t]/g,''))); 

                             }                                                                        
                        }                   
                        
               }
            });
          
        } 
        //end category
