// JavaScript Document
var arrAllCityIds = new Array();
	    var arrAllCityNames = new Array();
	    var arrAllCityMatrix = new Array();
        
        function setValues()
        {
            var fromCity = document.getElementById("cmbFrom"); 
		    var toCity = document.getElementById("cmbTo");
		    //toCity.options.length = 0;
		    
		    if(fromCity.selectedIndex==-1)
		    {
		        alert("Please select From city");
                return false;
		    }
		    
		    if(toCity.selectedIndex==-1)
		    {
		        alert("Please select To city");
                return false;
		    }
		    
//            if((fromCity.options[fromCity.selectedIndex].text=="")||(fromCity.options[fromCity.selectedIndex].text.toLowerCase()=="undefined")||(fromCity.options.length == -1))
//            {
//                alert("Please select From city");
//                return false;
//            }
//            if((toCity.options[toCity.selectedIndex].text=="")||(toCity.options[toCity.selectedIndex].text.toLowerCase()=="undefined")||(toCity.options.length == -1))
//            {
//                alert("Please select To city");
//                return false;
//            }
            
            //wait frame
            document.getElementById("waitDiv").style.visibility="visible"
            document.getElementById("cmbFrom").style.visibility="hidden"
            document.getElementById("cmbTo").style.visibility="hidden"
            document.getElementById("cmbSeats").style.visibility="hidden"
            
            //wait frame
            
            document.getElementById("txtFromCityId").value = document.getElementById("cmbFrom").value;
            document.getElementById("txtFromCityName").value = document.getElementById("cmbFrom").options[document.getElementById("cmbFrom").selectedIndex].text;

            document.getElementById("txtToCityId").value = document.getElementById("cmbTo").value;
            document.getElementById("txtToCityName").value = document.getElementById("cmbTo").options[document.getElementById("cmbTo").selectedIndex].text;
            
            
            return true;
        }
        
	    function init()
	    {
	    
		    arrCityIds = document.getElementById("txtCityIds").value.split("^");
		    arrCityNames = document.getElementById("txtCityNames").value.split("^");
		    arrCityMatrix = document.getElementById("txtCityMatrix").value.split("^");

		    //fillFromCities();
		    fillToCities();
		    
		    IsRoundTrip();
		    
		    try{SetToolTip();}catch(e){}
	    }
	    
	    function SetToolTip()
	    {
	        document.getElementById("rblRoundTrip_0").title= "Select if one way (no return journey) booking needed";
	        document.getElementById("rblRoundTrip_1").title= "Select if return journey booking needed";
	        document.getElementById("rblRoundTrip_0").parentNode.title= "Select if one way (no return journey) booking needed";
	        document.getElementById("rblRoundTrip_1").parentNode.title= "Select if return journey booking needed";
	        
	    }

	    function fillFromCities()
	    {
		    var fromCity = document.getElementById("cmbFrom");
		    fromCity.options.length = 0;
		    var arr= new Array();
		    for(var i=0;i<arrCityMatrix.length;i++)
		    {
			    arr = arrCityMatrix[i].split(":")
			    fromCity.options.length=fromCity.options.length+1;
			    fromCity.options[fromCity.options.length-1].text = getCityName(arr[0]);
			    fromCity.options[fromCity.options.length-1].value = arr[0];
		    }
	    }

	    function fillToCities()
	    {
		    var fromCityId =document.getElementById("cmbFrom").value; 
		    var toCity = document.getElementById("cmbTo");
		    toCity.options.length = 0;
		    var arr = new Array();
		    for(var i=0;i<arrCityMatrix.length;i++)
		    {
			    arr = arrCityMatrix[i].split(":");
			    if(arr[0]==fromCityId)
			    {
				    toCity.options.length=toCity.options.length+1;
				    toCity.options[toCity.options.length-1].text = getCityName(arr[1]);

				    toCity.options[toCity.options.length-1].value = arr[1];
			    }
		    }
	    }

	    function getCityName(cityId)
	    {
		    for(var i=0; i<arrCityIds.length;i++)
		    {
			    if(arrCityIds[i] == cityId)
			    {
				    return arrCityNames[i];
				    break;
			    }
		    }
	    }
	    
	    function IsRoundTrip()
	    {
	        var roundTrip = document.getElementById("rblRoundTrip_0").checked;
	        if(roundTrip == false)
	        {
	            document.getElementById("tblReturnDate").style.display = ""
	        }
	        else
	        {
	            //hide return date
	            document.getElementById("tblReturnDate").style.display = "none"
	        }
	    }
	    
	    function showCal()
        {
            var now = new Date();
            
            var cal18 = new CalendarPopup("testdiv1");

            cal18.offsetX=-97;
            cal18.offsetY=20;
            
            cal18.setCssPrefix("TEST");
            cal18.addDisabledDates(null,formatDate(addDays(now,-1),"yyyy-MM-dd")); 

            cal18.addDisabledDates(formatDate(addDays(now,30),"yyyy-MM-dd"),null);
            cal18.select(document.forms['form1'].txtDate,'anchor1','dd-NNN-yyyy',document.forms['form1'].txtDate2);

            
            return false;
        }
        
        function showCal2()
        {
            var currDate = new Date();
            
            var now = new Date();
            var date1=document.getElementById("txtDate").value;
            var year=date1.substring(7,11);
            var monthName=date1.substring(3,6);
            var month=GetMonthNo(monthName);
            var day=date1.substring(0,2);
            now.setFullYear(year,month-1,day);
            var cal28 = new CalendarPopup("testdiv2");

            cal28.offsetX=-97;
            cal28.offsetY=20;
                       
            cal28.setCssPrefix("TEST");
            cal28.addDisabledDates(null,formatDate(addDays(now,-1),"yyyy-MM-dd")); 

            cal28.addDisabledDates(formatDate(addDays(currDate,60),"yyyy-MM-dd"),null);
            cal28.select(document.forms['form1'].txtDate2,'anchor2','dd-NNN-yyyy',null);

            return false;
        }
        
        function GetMonthNo(monName)
        {
            var monNo=1;
            switch(monName)
            {
                    case "Jan": monNo=1;
                    break;
                    case "Feb": monNo=2;
                    break;
                    case "Mar": monNo=3;
                    break;
                    case "Apr": monNo=4;
                    break;
                    case "May": monNo=5;
                    break;
                    case "Jun": monNo=6;
                    break;
                    case "Jul": monNo=7;
                    break;
                    case "Aug": monNo=8;
                    break;
                    case "Sep": monNo=9;
                    break;
                    case "Oct": monNo=10;
                    break;
                    case "Nov": monNo=11;
                    break;
                    case "Dec": monNo=12;
                    break;
            }
            return monNo;
        }

        function addDays(myDate,days)
        {
	        return new Date(myDate.getTime()+days*60*60*24*1000);
        }
        
        function addMinuts(myDate,minuts)
        {
	        return new Date(myDate.getTime()+minuts*60*1000);
        }