 function setcode(code)
{
document.getElementById('TxtDestCitycode').value = code;
 }
function setUpAir(flag)
{
  //alert(flag);
  var divobj_zero,divobj_one,divobj_two;
  divobj_zero   = document.getElementById("zero");
  divobj_one   = document.getElementById("one");
  divobj_onedate   = document.getElementById("onedate");
  divobj_two   = document.getElementById("two");
 // var img2 = document.getElementById("imageCalendar2");
  
  if (flag=="0")
  {
    divobj_zero.style.display    = "";
	divobj_one.style.display    = "none";
	divobj_two.style.display    = "none";
	divobj_onedate.style.display    = "none";
	//img2.style.visibility = "hidden";

  }

  if (flag=="1")
  {
    divobj_zero.style.display    = "";
	divobj_one.style.display    = "";
	divobj_onedate.style.display    = "";	
	divobj_two.style.display    = "none";
	//img2.style.visibility = "visible";
  }

  if (flag=="2")
  {
    divobj_zero.style.display    = "none";
	divobj_one.style.display    = "none";
	divobj_onedate.style.display    = "none";	
	divobj_two.style.display    = "block";
	//img2.style.visibility = "hidden";
	
  }
}
function Verify()
{
    if( !document.all["radioTripType0"].checked && !document.all["radioTripType1"].checked && !document.all["radioTripType2"].checked)
    {
        alert("Please select route type.");
        return false;
    }
    if( document.all["radioTripType0"].checked == true )
    {
        var FromCity = document.all.DropDownListFromCity0;
        var DestCity = document.all.TxtDestCity0;
        
        if( DestCity.value.length == 0 || DestCity.value == CityTextBoxDefaultText )
        {
            alert( "Please input destination city." );
            DestCity.focus();
            return false;
        }
        if( FromCity.options[FromCity.selectedIndex].value == DestCity.value )
        {
            alert( "Error!Departure and destinaton can not be the same city." );
            FromCity.focus();
            return false;
        }
        //var DateControl = document.all.inputLeaveDate;
		var DateControl = document.getElementById("inputLeaveDate");
        if( DateControl.value.length == 0 )
        {
            alert( "Please input departure date." );
            DateControl.focus();
            return false;
        }
        if( !isValidDateTime( DateControl.value ) )
        {
            alert( "Wrong departure date form." );
            DateControl.focus();
            return false;
        } 
    }
    if( document.all["radioTripType1"].checked == true )
    {
        var LeaveDate = document.all.inputLeaveDate;
        var FromCity = document.all.DropDownListFromCity0;
        var DestCity = document.all.TxtDestCity0;
        
        if( DestCity.value.length == 0 || DestCity.value == CityTextBoxDefaultText )
        {
            alert( "Please input destination city." );
            DestCity.focus();
            return false;
        }
        if( FromCity.options[FromCity.selectedIndex].value == DestCity.value )
        {
            alert( "Error!Departure and destinaton can not be the same city." );
            FromCity.focus();
            return false;
        }
        if( LeaveDate.value.length == 0 )
        {
            alert( "Please input departure date." );
            LeaveDate.focus();
            return false;
        }
        if( !isValidDateTime( LeaveDate.value ) )
        {
            alert( "Wrong departure date form." );
            LeaveDate.focus();
            return false;
        } 
        var ReturnDate = document.all.inputReturnDate;
        if( ReturnDate.value.length == 0 )
        {
            alert( "Please input return date." );
            ReturnDate.focus();
            return false;
        }
        if( !isValidDateTime( ReturnDate.value ) )
        {
            alert( "Wrong return date form." );
            ReturnDate.focus();
            return false;
        }
        if( compareDate(LeaveDate.value , ReturnDate.value ) < 0 )
        {
            alert( "Error!Retuen date can not be earlier than departure date." );
            ReturnDate.focus();
            return false;
            
        }
        
    }
    if( document.all["radioTripType2"].checked == true )
    {
        //行程1必须输入
        var FromCity = document.all.DropDownListFromCity1;
        var DestCity = document.all.TxtDestCity1;
        var DateControl = document.all.inputDate1;
        
        
        if( DestCity.value.length == 0 || DestCity.value == CityTextBoxDefaultText )
        {
            alert( "Please input destination city in route1." );
            DestCity.focus();
            return false;
        }

        if( FromCity.options[FromCity.selectedIndex].value == DestCity.value )
        {
            alert( "Departure and destinaton can not be the same city  in route1" );
            FromCity.focus();
            return false;
        }
        if( DateControl.value.length <=0  )
        {
            alert( "Please input departure date  in route1." )  ;
            DateControl.focus();
            return false;
        }
        if( !isValidDateTime( DateControl.value ) )
        {
            alert( "Wrong departure date form in route1" );
            DateControl.focus();
            return false;
        } 
        //行程2-4可选择输入
        for( var i=2; i<=4; i++ )
        {
            
            FromCity = eval("document.all.TxtFromCity"+i);
            DestCity = eval("document.all.TxtDestCity"+i);
            DateControl = eval( "document.all.inputDate"+i );
            if( (FromCity.value.length > 0 && FromCity.value != CityTextBoxDefaultText) || (DestCity.value.length >0 && DestCity.value != CityTextBoxDefaultText) || DateControl.value.length >0)
            {
                if( FromCity.value.length <=0 || FromCity.value == CityTextBoxDefaultText )
                {
                    alert( "Please input departure city in route"+i );
                    FromCity.focus();
                    return false;
                }
                if( DestCity.value.length <=0 || DestCity.value == CityTextBoxDefaultText )
                {
                    alert( "Please input destination city in route"+i );
                    DestCity.focus();
                    return false;
                }
                if( FromCity.value == DestCity.value )
                {
                    alert( "Departure and destinaton can not be the same city in route"+i );
                    FromCity.focus();
                    return false;
                }
                if( DateControl.value.length <=0  )
                {
                    alert( "Please input departure date in route"+i );
                    DateControl.focus();
                    return false;
                }
                if( !isValidDateTime( DateControl.value ) )
                {
                    alert( "Wrong departure date form in route"+i );
                    DateControl.focus();
                    return false;
                } 
                for( var j=1; j<i; j++ )
                {
                    
                    var BeforeDateControl = eval( "document.all.inputDate"+j );
                    if( BeforeDateControl.value.length > 0 && isValidDateTime( BeforeDateControl.value ) )
                    {
                        if( compareDate(BeforeDateControl.value , DateControl.value ) < 0 )
                        {
                            alert( "Retuen date in route"+i+" can not be earlier than departure date in route "+j );
                            DateControl.focus();
                            return false;
                            
                        }
                    }
                    
                }
            }
        }
    }
    
    return true;
}
function isValidDateTime(str)
{
    //var re = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
    var re = /^(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29))$)|(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))$/;
    return re.test(str);
}
function compareDate( Date1, Date2 )
{
    var Days = 0;
	try
	{
		var beginDate = parseDate( Date1 );
		var endDate = parseDate( Date2 );
		Days = (endDate - beginDate)/24/60/60/1000;
	}
	catch(e){}
	return Days;
}
function parseDate( str )
{
	var yearS,monthS,dayS;
	var index1,index2;
	
	yearS=str.substr(0,4);
	
	if((index1=str.indexOf("-"))==-1) return "";	// Can not find delimitor charactor 
	if((index2=str.indexOf("-",index1+1))==-1) return "";	// Can not find delimitor charactor 
	monthS=str.substr(index1+1,index2-index1-1);
	if(monthS.length<2) monthS="0"+monthS;
	
	dayS=str.substr(index2+1);
	if(dayS.length<2) dayS="0"+dayS;
	
	var year = eval( yearS );
	var month = eval( monthS - 1 );
	var day = eval( dayS );
	return new Date( year, month, day );
}
