﻿// JScript File

$(document).ready(function() {
    // for flight
    $('.planBgInc').hide();
    $('#tabInternational').hide();
    $("#dvFlight").fadeIn();
    check();
    bindAirport(0); // for domestic
    //bindAirport(1);// for international
    // search flight
    $("#ibtSearchFlight").click(function() {
        var isoneway, ffrom, fto;
        if ($("#hdInternational").val() == "1") {
            ffrom = $('#txtIntFlightFrom').val();
            fto = $('#txtIntFlightTo').val();
            if ($('#txtIntFlightTo').val() == "London or LON") {
                alert("please select international destination");
                return false;
            }
        }
        else {
            ffrom = $('#Planyourtrip1_DDFlightFrom option:selected').text();
            fto = $('#Planyourtrip1_DDFlightTo option:selected').text();
        }

        if (document.forms[0].elements['Planyourtrip1_rbtTripType_0'].checked) {
            isoneway = 1;
            if ($('#Planyourtrip1_txtDepartDate').val() == "") {
                alert("please select depart date");
                return false;
            }
            if ($('#Planyourtrip1_txtReturnDate').val() == "") {
                alert("please select return date");
                return false;
            }
        }
        else {
            isoneway = 0;
            if ($('#Planyourtrip1_txtDepartDate').val() == "dd/mm/yyyy") {
                alert("please select depart date");
                return false;
            }
        }


        // store search flights details
        $.ajax({

            type: "post",
            url: "save-search-flights.aspx",
            dataType: "text",
            data: {
                'isinternational': $("#hdInternational").val(),
                'isoneway': isoneway,
                'from': ffrom,
                'to': fto,
                'ddate': $('#Planyourtrip1_txtDepartDate').val(),
                'rdate': $('#Planyourtrip1_txtReturnDate').val(),
                'adult': $('#Planyourtrip1_DDAdult').val(),
                'child': $('#Planyourtrip1_DDChild').val(),
                'infant': $('#Planyourtrip1_DDInfant').val(),
                'class': 'e'
            },
            beforeSend: function() {

            },
            timeout: 68000,
            error: function(xhr, error) {
                //alert( "Error: an error occured please retry" + xhr.responseText)
            },
            success: function(data) {

                // open window
                var xurl = "http://dial.ixigo.com/search/result/flight/";
                if ($("#hdInternational").val() == "1") {

                    var intDes1 = $('#txtIntFlightFrom').val();
                    is1 = intDes1.lastIndexOf("(");
                    ie1 = intDes1.lastIndexOf(")");
                    strInter1 = intDes1.substring(is1 + 1, ie1);

                    xurl += strInter1 + "/";

                    var is, ie, strInter;
                    var intDes = $('#txtIntFlightTo').val();
                    is = intDes.lastIndexOf("(");
                    ie = intDes.lastIndexOf(")");
                    strInter = intDes.substring(is + 1, ie);

                    xurl += strInter + "/";
                }
                else {
                    xurl += $('#Planyourtrip1_DDFlightFrom').val() + "/";
                    xurl += $('#Planyourtrip1_DDFlightTo').val() + "/";
                }

                if (document.forms[0].elements['Planyourtrip1_rbtTripType_0'].checked) {
                    xurl += $('#Planyourtrip1_txtDepartDate').val().replace(RegExp('/', 'g'), '') + "/";
                    xurl += $('#Planyourtrip1_txtReturnDate').val().replace(RegExp('/', 'g'), '') + "/";
                }
                else {
                    xurl += $('#Planyourtrip1_txtDepartDate').val().replace(RegExp('/', 'g'), '') + "//";
                }
                xurl += $('#Planyourtrip1_DDAdult').val() + "/";
                xurl += $('#Planyourtrip1_DDChild').val() + "/";
                xurl += $('#Planyourtrip1_DDInfant').val() + "/";
                xurl += "e";
                document.location.href = xurl;
                //                       var ix=window.open(xurl,'_blank','width=800,height=400,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes')
                //                        if(ix==null)
                //                       alert("Pop up is blocked in your browser. Kindly enable it");
                return false;
                // end 
            }
        });
        // end search	

    });

    // search hotel
    $("#ibtHotelBooking").click(function() {


        if ($('#Planyourtrip1_txtHFromDate').val() == "dd/mm/yyyy") {
            alert("please select check in date");
            return false;
        }
        if ($('#Planyourtrip1_txtHToDate').val() == "dd/mm/yyyy") {
            alert("please select check out date");
            return false;
        }

        // store search hotels details
        $.ajax({

            type: "post",
            url: "save-search-hotels.aspx",
            dataType: "text",
            data: {
                'place': $("#txtHotelPlace").val(),
                'check_in': $('#Planyourtrip1_txtHFromDate').val(),
                'check_out': $('#Planyourtrip1_txtHToDate').val(),
                'rooms': $('#Planyourtrip1_DDHRooms').val(),
                'r1a1': $('#Planyourtrip1_DDHAdult1').val(),
                'r1c1': $('#Planyourtrip1_DDHChildren1').val(),
                'r2a2': $('#Planyourtrip1_DDHAdult2').val(),
                'r2c2': $('#Planyourtrip1_DDHChildren2').val(),
                'r3a3': $('#Planyourtrip1_DDHAdult3').val(),
                'r3c3': $('#Planyourtrip1_DDHChildren3').val()
            },
            beforeSend: function() {

            },
            timeout: 68000,
            error: function(xhr, error) {
                //alert( "Error: an error occured please retry" + xhr.responseText)
            },
            success: function(data) {

                // open window
                var xurl = "http://dial.ixigo.com/search/result/hotel/";
                xurl += $('#txtHotelPlace').val() + "/";
                xurl += $('#Planyourtrip1_txtHFromDate').val().replace(RegExp('/', 'g'), '') + "/";
                xurl += $('#Planyourtrip1_txtHToDate').val().replace(RegExp('/', 'g'), '') + "/";
                if ($('#Planyourtrip1_DDHRooms').val() == "1") {
                    xurl += $('#Planyourtrip1_DDHAdult1').val() + "/" + $('#Planyourtrip1_DDHChildren1').val() + "/0/0/0/0";
                }
                else if ($('#Planyourtrip1_DDHRooms').val() == "2") {
                    xurl += $('#Planyourtrip1_DDHAdult1').val() + "/" + $('#Planyourtrip1_DDHChildren1').val() + "/" + $('#Planyourtrip1_DDHAdult2').val() + "/" + $('#Planyourtrip1_DDHChildren2').val() + "/0/0";
                }
                else {
                    xurl += $('#Planyourtrip1_DDHAdult1').val() + "/" + $('#Planyourtrip1_DDHChildren1').val() + "/" + $('#Planyourtrip1_DDHAdult2').val() + "/" + $('#Planyourtrip1_DDHChildren2').val() + "/" + $('#Planyourtrip1_DDHAdult3').val() + "/" + $('#Planyourtrip1_DDHChildren3').val();
                }
                document.location.href = xurl;
                //                       var ix=window.open(xurl,'_blank','width=800,height=400,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes')
                //                       if(ix==null)
                //                       alert("Pop up is blocked in your browser. Kindly enable it");
                return false;
                // end 
            }
        });
        // end search
    });

    // start cab booking
    $("#btCabBooking").click(function() {

        var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
        var emaili = $('#Planyourtrip1_txtCabEmail').val();
        if ($('#Planyourtrip1_txtCabDate').val() == "dd/mm/yyyy") {
            alert("please select travel date");
            return false;
        }
        if ($('#Planyourtrip1_txtCabFlNo').val() == "") {
            alert("please enter flight no");
            return false;
        }
        if ($('#txtCabTo').val() == "") {
            alert("please enter drop location");
            return false;
        }
        if ($('#Planyourtrip1_txtCabName').val() == "") {
            alert("please enter your name");
            return false;
        }
        if ($('#Planyourtrip1_txtCabContactNo').val() == "") {
            alert("please enter your contact no");
            return false;
        }
        if (emaili == "") {
            alert("please enter your email id");
            return false;
        }

        if (!emaili.match(emailRegex)) {
            alert("please enter valid email id");
            return false;
        }

        var newdate, tradate, tradate1;

        tradate = $('#txtCabDate').val();
        tradate1 = $('#txtCabDate').val();
        var temdate = Array();
        tradate = tradate.split('/');
        newdate = tradate[1] + '/' + tradate[0] + '/' + tradate[2];
        
        // store search hotels details
        $.ajax({

            type: "post",
            url: "save-search-cabs.aspx",
            dataType: "text",
            data: {
            'tdate': newdate,
                'ttime': $('#Planyourtrip1_DDHour').val() + ':' + $('#Planyourtrip1_DDMinite').val(),
                'fno': $('#Planyourtrip1_txtCabFlNo').val(),
                'from': $('#Planyourtrip1_DDCabPickFrom option:selected').text(),
                'to': $('#txtCabTo').val(),
                'name': $('#Planyourtrip1_txtCabName').val(),
                'cno': $('#Planyourtrip1_txtCabContactNo').val(),
                'email': $('#Planyourtrip1_txtCabEmail').val(),
                'check': Math.random()
            },
            beforeSend: function() {

            },
            timeout: 68000,
            error: function(xhr, error) {
                //alert( "Error: an error occured please retry" + xhr.responseText)
            },
            success: function(data) {

                ///
                $.ajax({

                    type: "get",
                    url: "getcab-droplocationvalue.aspx",
                    dataType: "text",
                    data: {
                        'cval': $('#Planyourtrip1_txtCabTo').val(),
                        'check': Math.random()
                    },
                    beforeSend: function() {

                    },
                    timeout: 68000,
                    error: function(xhr, error) {
                        //alert( "Error: an error occured please retry" + xhr.responseText)
                    },
                    success: function(data) {

                        var dropid = data;
						
                        if (parseInt(dropid) != 0) {
                            //alert(dropid);
                            // open window
                            var xurl = "cabsdetails.aspx?";
                            xurl += "DDCabPickFrom=" + $('#Planyourtrip1_DDCabPickFrom').val() + "&DDHour=" + $('#Planyourtrip1_DDHour').val() + "&DDMinite=" + $('#Planyourtrip1_DDMinite').val() + "&txtCabContactNo=" + $('#Planyourtrip1_txtCabContactNo').val() + "&txtCabDate=" + tradate1;
                            xurl += "&txtCabEmail=" + $('#Planyourtrip1_txtCabEmail').val() + "&txtCabFlNo=" + $('#Planyourtrip1_txtCabFlNo').val() + "&txtCabName=" + $('#Planyourtrip1_txtCabName').val() + "&txtCabTo=" + $('#txtCabTo').val();

                            //alert(xurl);
                            document.location.href = xurl;

                        }
                        else {
                            alert("Invalid destination. Kindly type to choose from the list");
                            $('#txtCabTo').focus();
                        }
                        return false;
                        // end 

                    }
                });
                //

            }
        });
        // end search
    });

    //end cab booking
});
	
	 function openplanTripTab(id,imgpl)
    {
      $(".planBgInc").hide();
        $("#"+id).fadeIn(800);
        $("#imgplanTrip").attr("src","/images/"+imgpl+".gif");
    }

    function openplanIntTripTab(id, imgpl) {
        $(".planBgInc").hide();
        $("#" + id).fadeIn(800);
        $("#imgplanIntTrip").attr("src", "/images/" + imgpl + ".gif");
    }
    
    
	function doHide()
	{
	var id;
    if(document.forms[0].elements['Planyourtrip1_rbtTripType_0'].checked)
       {
       $('#trNew').fadeIn(500);
         $('#dvRet').fadeIn(500);
           
       }
       else if(document.forms[0].elements['Planyourtrip1_rbtTripType_1'].checked)
       {
       $('#trNew').fadeOut(500);
        $('#dvRet').fadeOut(500);        	
           
       }
	
	}

	function check() {
	    var id;
	    if (document.forms[0].elements['Planyourtrip1_rbtInternational_0'].checked) {
	        showInter('0');

	    }
	    else if (document.forms[0].elements['Planyourtrip1_rbtInternational_1'].checked) {
	    showInter('1');

	    }

	}
	
    
//for flight date booking
$(function()
            {
				$('.date-pick').datePicker({horizontalPosition:$.dpConst.POS_RIGHT})
				$('#Planyourtrip1_txtDepartDate').bind(
					'dpClosed',
					function(e, selectedDates)
					{
						var d = selectedDates[0];
						if (d) {
							d = new Date(d);
							$('#Planyourtrip1_txtReturnDate').dpSetStartDate(d.addDays(0).asString());
						}
					}
				);
				//$('#tr').dpSetPosition($.dpConst.POS_TOP, $.dpConst.POS_RIGHT);

				$('#Planyourtrip1_txtReturnDate').bind(
					'dpClosed',
					function(e, selectedDates)
					{
						var d = selectedDates[0];
						if (d) {
							d = new Date(d);
							
							$('#Planyourtrip1_txtDepartDate').dpSetStartDate(d.addDays(1).asString());
						}
					}
				);
				//$('#tr').dpSetPosition($.dpConst.POS_TOP, $.dpConst.POS_RIGHT);
				
            });
            
            
            //for flight date booking
$(function()
            {
				$('#Planyourtrip1_txtHFromDate').bind(
					'dpClosed',
					function(e, selectedDates)
					{
						var d = selectedDates[0];
						if (d) {
							d = new Date(d);
							$('#Planyourtrip1_txtHToDate').dpSetStartDate(d.addDays(0).asString());
						}
					}
				);
				$('#Planyourtrip1_txtHToDate').bind(
					'dpClosed',
					function(e, selectedDates)
					{
						var d = selectedDates[0];
						if (d) {
							d = new Date(d);
							$('#Planyourtrip1_txtHFromDate').dpSetEndDate(d.addDays(1).asString());
						}
					}
				);
				
				
            });
        function showNoRoom(id)
	{
	    if(id==1)
	    {
	        $('#dvRoom2').css("display","none");
	         $('#dvRoom3').css("display","none");
	    }
	    if(id==2)
	    {
	        $('#dvRoom2').css("display","block");
	        $('#dvRoom3').css("display","none");
	    }
	    if(id==3)
	    {
	        $('#dvRoom3').css("display","block");
	        $('#dvRoom2').css("display","block");
	    }
	}
function bindAirport(id)
        {
        // id=1 then international else domestic
             $.ajax({
             type: "get",
             url: "get-domestic-airports-list.aspx" ,
             dataType: "text",
             data: 'rn='+Math.random()+'&mode='+id,
             timeout: 68000,
             error: function(xhr,error) {
              //alert( "Error: an error occured please retry" + xhr.responseText)
              },
              success: function(data) { 
                  if(id==0)
                  {
                   $('#Planyourtrip1_DDFlightFrom >option').remove();
                   $('#Planyourtrip1_DDFlightTo >option').remove();
                   // $('#Planyourtrip1_DDIntFlightFrom >option').remove();
                   var checked=false;
		            var li=new Array();
                    li=data.split('##');                
                    for(j=0;j<li.length;j++)
                    {
                        if(li[j].indexOf(',')!=-1)
                        {
                            var lidata=new Array();                                          
                            lidata=li[j].split(',');              
                            $('#Planyourtrip1_DDFlightFrom').append($('<option></option>').val(lidata[0].replace(/[\n\r\t]/g,'')).html(lidata[1].replace(/[\n\r\t]/g,''))); 
                            $('#Planyourtrip1_DDFlightTo').append($('<option></option>').val(lidata[0].replace(/[\n\r\t]/g,'')).html(lidata[1].replace(/[\n\r\t]/g,''))); 
                            //$('#Planyourtrip1_DDIntFlightFrom').append($('<option></option>').val(lidata[0].replace(/[\n\r\t]/g,'')).html(lidata[1].replace(/[\n\r\t]/g,''))); 


                        }                                        
                                                                                                  
                    }
                    $('#Planyourtrip1_DDFlightTo').val("BLR");   
                   $('#Planyourtrip1_DDFlightFrom').val("DEL"); 
                  }
                           
               }
            });
           
        }  
        
         function showInter(x)
	        {
	            var id;	       
	            id = x;
	            if(id==1)
	            {
	                $("#trFlightDomes").css("display","none");
	                $("#trFlightInter").css("display","block");
	                
	                $("#dvDom").css("display","block");
	                $("#dvIn").css("display","none");
	                $("#hdInternational").val("1");
	               
	            }
	            else {
	            
	                $("#trFlightDomes").css("display","block");
	                $("#trFlightInter").css("display","none");
	                 $("#dvDom").css("display","none");
	                $("#dvIn").css("display","block");
	                $("#hdInternational").val("0");
	              
	            }
	        }

	        // TRAIN BOOKING //

	        $("#imgbutTrain").click(function() {
	            var isoneway, ffrom, fto;
	            if ($("#hdInternational").val() == "1") {
	                ffrom = $('#txtIntFlightFrom').val();
	                fto = $('#txtIntFlightTo').val();
	                if ($('#txtIntFlightTo').val() == "London or LON") {
	                    alert("please select international destination");
	                    return false;
	                }
	            }
	            else {
	                ffrom = $('#Planyourtrip1_DDFlightFrom option:selected').text();
	                fto = $('#Planyourtrip1_DDFlightTo option:selected').text();
	            }

	            if (document.forms[0].elements['Planyourtrip1_rbtTripType_0'].checked) {
	                isoneway = 1;
	                if ($('#Planyourtrip1_txtDepartDate').val() == "dd/mm/yyyy") {
	                    alert("please select depart date");
	                    return false;
	                }
	                if ($('#Planyourtrip1_txtReturnDate').val() == "dd/mm/yyyy") {
	                    alert("please select return date");
	                    return false;
	                }
	            }
	            else {
	                isoneway = 0;
	                if ($('#Planyourtrip1_txtDepartDate').val() == "dd/mm/yyyy") {
	                    alert("please select depart date");
	                    return false;
	                }
	            }


	            // store search flights details
	            $.ajax({

	                type: "post",
	                url: "save-search-flights.aspx",
	                dataType: "text",
	                data: {
	                    'isinternational': $("#hdInternational").val(),
	                    'isoneway': isoneway,
	                    'from': ffrom,
	                    'to': fto,
	                    'ddate': $('#Planyourtrip1_txtDepartDate').val(),
	                    'rdate': $('#Planyourtrip1_txtReturnDate').val(),
	                    'adult': $('#Planyourtrip1_DDAdult').val(),
	                    'child': $('#Planyourtrip1_DDChild').val(),
	                    'infant': $('#Planyourtrip1_DDInfant').val(),
	                    'class': 'e'
	                },
	                beforeSend: function() {

	                },
	                timeout: 68000,
	                error: function(xhr, error) {
	                    //alert( "Error: an error occured please retry" + xhr.responseText)
	                },
	                success: function(data) {

	                    // open window
	                    var xurl = "http://dial.ixigo.com/search/result/flight/";
	                    if ($("#hdInternational").val() == "1") {

	                        var intDes1 = $('#txtIntFlightFrom').val();
	                        is1 = intDes1.lastIndexOf("(");
	                        ie1 = intDes1.lastIndexOf(")");
	                        strInter1 = intDes1.substring(is1 + 1, ie1);

	                        xurl += strInter1 + "/";

	                        var is, ie, strInter;
	                        var intDes = $('#txtIntFlightTo').val();
	                        is = intDes.lastIndexOf("(");
	                        ie = intDes.lastIndexOf(")");
	                        strInter = intDes.substring(is + 1, ie);

	                        xurl += strInter + "/";
	                    }
	                    else {
	                        xurl += $('#Planyourtrip1_DDFlightFrom').val() + "/";
	                        xurl += $('#Planyourtrip1_DDFlightTo').val() + "/";
	                    }

	                    if (document.forms[0].elements['Planyourtrip1_rbtTripType_0'].checked) {
	                        xurl += $('#Planyourtrip1_txtDepartDate').val().replace(RegExp('/', 'g'), '') + "/";
	                        xurl += $('#Planyourtrip1_txtReturnDate').val().replace(RegExp('/', 'g'), '') + "/";
	                    }
	                    else {
	                        xurl += $('#Planyourtrip1_txtDepartDate').val().replace(RegExp('/', 'g'), '') + "//";
	                    }
	                    xurl += $('#Planyourtrip1_DDAdult').val() + "/";
	                    xurl += $('#Planyourtrip1_DDChild').val() + "/";
	                    xurl += $('#Planyourtrip1_DDInfant').val() + "/";
	                    xurl += "e";
	                    document.location.href = xurl;
	                    //                       var ix=window.open(xurl,'_blank','width=800,height=400,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes')
	                    //                        if(ix==null)
	                    //                       alert("Pop up is blocked in your browser. Kindly enable it");
	                    return false;
	                    // end 
	                }
	            });
	            // end search	

	        });    
