﻿var g_hash_Main = new MainHashtable();
var g_hash_Condition = new ConditionHashtable();
var g_hash_Result = new ResultHashtable();
var g_arr_Promotions = new Array();
var g_hash_FilterResult = new ResultHashtable();
var g_arr_TotalResult = new Array();
var g_arr_PageResult = new Array();
var g_arr_workResult = new Array();
var g_arr_pageNum;
var PageSize = 100000;
var g_arr_CurrentPageNumber = 1;
var g_source = '';
//var g_arr_FilterCity ='SHA-PEK-HKG|Shanghai-Beijing-Hong Kong' ;

var g_weekday=new Array(7);
g_weekday[0]="Sun";
g_weekday[1]="Mon"; 
g_weekday[2]="Tue";
g_weekday[3]="Wed";
g_weekday[4]="Thu";
g_weekday[5]="Fri";
g_weekday[6]="Sat";

var g_month =new Array(12);
g_month[0] = "Jan";
g_month[1] = "Feb";
g_month[2] = "Mar";
g_month[3] = "Apr";
g_month[4] = "May";
g_month[5] = "Jun";
g_month[6] = "Jul";
g_month[7] = "Aug";
g_month[8] = "Sep";
g_month[9] = "Oct";
g_month[10] = "Nov";
g_month[11] = "Dec";

var temp_areaItem = '<td><table width="50" border="0" cellspacing="0" cellpadding="0"><tr><td width="3"><img id="img_left_#AreaCode#" src="img/area_off_l.gif"></td><td align="center" id="td_#AreaCode#" class="area-off"><a href="#" id="#AreaCode#" onclick="ChangeArea(this.id);" class="area-link">#AreaName#</a></td><td width="3"><img id="img_right_#AreaCode#" src="img/area_off_r.gif"></td></tr></table></td>';
var temp_areaItemCompart = '<td width="5"><img src="img/menu_space.gif"></td>'
var temp_destionCity = '<td  align="left"  style="PADDING-right: 0px;" class=#class# ><b>#CITY#</b></td>'
var temp_totalPrice = '<tr><td  align="center" ><table width="100%" border="0" align="right" cellpadding="0" cellspacing="0"><tr><td  align="left"></td>#DPT# #FARE#</tr></table></td></tr>'
var temp_DeptCity = '<td width="22%" align="left" class="box_txt">#DEPTCITY#</td>'
var temp_PriceItem = '<td   align="left" class="#CLASS#" style="#STYLE#"><a href="#" class="box_links" id="#SUBCODE#" name="#AREACODE#" title="#TITLE#" onclick="#ONCLICK#">$#PRICE#</a></td>'
var temp_divDES = '<table cellpadding="0" width="100%" cellspacing="0" border="0" align="center"><tr>#DestionCity#</tr></table>'
var temp_divPrice = '<table width="100%" border="0" cellspacing="0" cellpadding="0">#PRICE_LIST#</table>'
//var temp_ResultPriceItem='<tr><td height="23" align="right" style="background:#BGCOLOR#"><table width="100%" border="0" align="right" cellpadding="0" cellspacing="0"><tr><td width="6%" align="center" class="t-10g" id="td_M"><a href="#" class="b-10U" id="#MY#" onclick="ClickMonth(this.id);">#MONTH#</a></td><td width="8%" align="right" class="t-10g" style=" padding-right:10px;"><a href="#" class="b-10U" id="a_#CODE#" onclick="ClickSearch(this.id);">$#PRICE#</a></td><td width="18%" align="left" class="t-10g" style=" padding-left:10px;">#DEPTDATE#</td><td width="18%" align="left" class="t-10g" style=" padding-left:10px;">#RTNDATE#</td><td width="10%" align="right" class="t-10g" style=" padding-right:10px;">#DURATION# days</td><td width="8%" align="center" class="t-10g">#STOPS#</td><td width="22%" align="center" class="t-10g">#AIRLINE#</td><td width="10%" align="center" class="t-10g"><a href="#" class="b-10U" id="Search_#CODE#" onclick="ClickSearch(this.id);">Search</a></td></tr></table></td></tr>'
var new_temp_table = '<table width="100%" border="0" cellspacing="0" cellpadding="0">#Result#</table>'
var new_temp_title = '<tr>#Title#</tr>';
var new_temp_price = '<tr>#Item#</tr>'
var new_temp_title_item = '<td  align="center" class="#Class#">#DesCity#</td>';
var new_temp_depcity = '<td align="left" class="box_txt">#DepCity#</td>';
var new_temp_price_item = '<td align="center" class="#Class#"><a href="#" class="box_links" id="#SUBCODE#" name="#AREACODE#" title="#TITLE#" onclick="#ONCLICK#">$#PRICE#</a></td>';

var price_Item = '<tr height="23" align="right" bgcolor="#BGCOLOR#" id="td_#BGCOLOR#" style="background: #BGCOLOR#"><td width="6%" align="center" class="t-10g">#NUM#</td><td width="8%" align="center" class="t-10g" id="td_M" style="display:block"><a href="#" class="b-10U" id="#MY#" onclick="ClickMonth(this.id)">#MONTH#</a></td><td width="8%" align="right" class="t-10g" style="padding-right:10px"><a href="#" class="b-10U" id="a_#CODE#" onclick="ClickSearch(this.id);">$#PRICE#</a></td><td width="13%" align="left" class="t-10g" style="padding-left:10px">#DEPTDATE#</td><td width="13%" align="left" class="t-10g" style="padding-left: 10px">#RTNDATE#</td><td width="10%" align="right" class="t-10g" style="padding-right:10px;display:none">#DURATION# days</td><td width="8%" align="center" class="t-10g">#STOPS#</td><td width="20%" align="center" class="t-10g">#AIRLINE#</td><td width="16%" align="center" class="t-10g" style="padding-left:10px">#TIME# ago</td><td width="8%" align="center" class="t-10g"><a href="#" class="b-10U" id="Search_#CODE#" onclick="ClickSearch(this.id)">Search</a></td></tr>';


function MainHashtable()
{
	this.length = 0;
	this.items = new Array();
//	var names = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
	/////////////////////////////////////////////////
	this.getItem = function(_promotionConditinCode) {
		return this.items[_promotionConditinCode];
	}

	///////////////////////////////////////////////
	this.setItem = function(_promotionConditinCode,_promotionConditinName,_X,_Y,_XCode,_YCode,_XAirPortCode,_YAirPortCode){
			//condition check if existing
			this.length++;	
			this.items[_promotionConditinCode] = new this.InsertNewItem(_promotionConditinCode,_promotionConditinName,_X,_Y,_XCode,_YCode,_XAirPortCode,_YAirPortCode);
	}															

	////////////////////////////////////////////
	this.InsertNewItem= function (_promotionConditinCode,_promotionConditinName,_X,_Y,_XCode,_YCode,_XAirPortCode,_YAirPortCode){	
			this.length++;
			this.Code=_promotionConditinCode;
			this.Name=_promotionConditinName;
			//this.Value=_Promotion;
			this.RegionX = _X
			this.RegionY = _Y
			this.RegionXCode = _XCode;
			this.RegionYCode = _YCode;
			this.RegionXACode = _XAirPortCode;
			this.RegionYACode = _YAirPortCode;
			
			
		}
		
		
	////////////////////////////////////////////////////////////////////
	this.hasItem = function(in_key)
	{ return typeof(this.items[in_key]) != 'undefined';  }
		
}


function PromotionHashtable()
{
    this._hash = {};
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
	/////////////////////////////////////////////////
	this.getItem = function(_SubItemCode) {
		return this.items[_SubItemCode];
	}

	///////////////////////////////////////////////
	this.setItem = function(_SubItemCode,_DeptCity,_DesCity,_FatherCode,_Stops,_TotalPrice,_DeptDate,_RtnDate,_Airlines,_FlightType){
			//condition check if existing
			this.length++;	
			this.items[_SubItemCode] = new this.InsertNewItem(_SubItemCode,_DeptCity,_DesCity,_FatherCode,_Stops,_TotalPrice,_DeptDate,_RtnDate,_Airlines,_FlightType);
	}															

	////////////////////////////////////////////
	this.InsertNewItem= function (_SubItemCode,_DeptCity,_DesCity,_FatherCode,_Stops,_TotalPrice,_DeptDate,_RtnDate,_Airlines,_FlightType){	
			this.length++;
			this.Code = _SubItemCode;
			this.DeptCode = _DeptCity;
			this.DesCode = _DesCity;
			this.Stops = _Stops;
			this.TotalPrice = _TotalPrice;
			this.DeptDate = _DeptDate;
			this.RtnDate = _RtnDate;
			this.FatherCode = _FatherCode;
			this.AirLine = _Airlines;
			this.FlightType = _FlightType;
		}
		
    this.removeItem = function(_SubItemCode) 
	{ delete this.items[_SubItemCode]; this.length--; } 
		
	////////////////////////////////////////////////////////////////////
	this.hasItem = function(in_key)
	{ return typeof(this.items[in_key]) != 'undefined';  }
		
}

//Search Condition 
function ConditionHashtable()
{
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
	/////////////////////////////////////////////////
	this.getItem = function(_Code) {
		return this.items[_Code];
	}

	///////////////////////////////////////////////
	this.setItem = function(_Code,_DeptCode,_DesCode,_DeptDate,_RtnDate,_AdultNum,_ChildNum,_Cabin,_Airlines,_FlightType){
			//condition check if existing
			this.length++;	
			this.items[_Code] = new this.InsertNewItem(_Code,_DeptCode,_DesCode,_DeptDate,_RtnDate,_AdultNum,_ChildNum,_Cabin,_Airlines,_FlightType);
	}															

	////////////////////////////////////////////
	this.InsertNewItem= function (_Code,_DeptCode,_DesCode,_DeptDate,_RtnDate,_AdultNum,_ChildNum,_Cabin,_Airlines,_FlightType){	
			this.length++;
			this.Code = _Code;
			this.DeptCode = _DeptCode;
			this.DesCode = _DesCode;
			this.DeptDate = _DeptDate;
			this.RtnDate = _RtnDate;
			this.AdultNum = _AdultNum;
			this.ChildNum = _ChildNum;
			this.Cabin = _Cabin;
			this.AirLines = _Airlines;
			this.FlightType = _FlightType;
		}

		
	////////////////////////////////////////////////////////////////////
	this.hasItem = function(in_key)
	{ return typeof(this.items[in_key]) != 'undefined';  }
		
}

function ResultHashtable()
{
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
	/////////////////////////////////////////////////
	this.getItem = function(_Code) {
		return this.items[_Code];
	}

	///////////////////////////////////////////////
	this.setItem = function(_Code,_Month,_Price,_DeptDate,_RtnDate,_Duration,_Stops,_Airlines,_dDate,_rDate,_isLowerFare,_FlightType,_UpdateTime,_UpdateTimeNum){
			//condition check if existing
			this.length++;	
			this.items[_Code] = new this.InsertNewItem(_Code,_Month,_Price,_DeptDate,_RtnDate,_Duration,_Stops,_Airlines,_dDate,_rDate,_isLowerFare,_FlightType,_UpdateTime,_UpdateTimeNum);
	}															

	////////////////////////////////////////////
	this.InsertNewItem= function (_Code,_Month,_Price,_DeptDate,_RtnDate,_Duration,_Stops,_Airlines,_dDate,_rDate,_isLowerFare,_FlightType,_UpdateTime,_UpdateTimeNum){	
			this.length++;
			this.Code = _Code;
			this.Month = _Month;
			this.Price = _Price;
			this.DeptDate = _DeptDate;
			this.RtnDate = _RtnDate;
			this.Duration = _Duration;
			this.Stops = _Stops;
			this.AirLines = _Airlines;
			this.DDate = _dDate;
			this.RDate = _rDate;
			this.IsLowerFare = _isLowerFare;
			this.FlightType = _FlightType;
			this.UpdateTime = _UpdateTime;
			this.UpdateTimeNumber = _UpdateTimeNum;
		}

	
	////////////////////////////////////////////////////////////////////
	this.hasItem = function(in_key)
	{ return typeof(this.items[in_key]) != 'undefined';  }
		
}

function resultDetail(_Code,_Month,_Price,_DeptDate,_RtnDate,_Duration,_Stops,_Airlines,_dDate,_rDate,_isLowerFare,_isMore,_flightType,_updateTime,_updateTimeNum)
{	

	this.Code = _Code;
	this.Month = _Month;
	this.Price = _Price;
	this.DeptDate = _DeptDate;
	this.RtnDate = _RtnDate;
	this.Duration = _Duration;
	this.Stops = _Stops;
	this.AirLines = _Airlines;
	this.DDate = _dDate;
	this.RDate = _rDate;
	this.IsLowerFare = _isLowerFare;
	this.IsMore = _isMore;
	this.FlightType = _flightType;
	this.UpdateTime = _updateTime;
	this.UpdateTimeNumber = _updateTimeNum;
}

var g_str_main='';//"1|China|PVG-PEK|DFW-NYC@2|Asia|BKK-NRT|DFW-NYC";
var g_str_subItems='';//"DFW|PVG|1|800|2|10/11/2009|10/15/2009~DFW|PEK|1|900|2|10/11/2009|10/15/2009~NYC|PVG|1|820|2|10/11/2009|10/15/2009~NYC|PEK|1|1000|2|10/11/2009|10/15/2009^DFW|BKK|2|700|2|10/11/2009|10/15/2009~DFW|NRT|2|500|2|10/11/2009|10/15/2009~NYC|BKK|2|620|2|10/11/2009|10/15/2009~NYC|NRT|2|740|2|10/11/2009|10/15/2009";
var g_str_conditons='';
var g_str_results='';
var FlightNumber = 0;

function Build_g_arr_FlightPromotions(strData)
{
    FlightNumber = 10;
    try
    {
        var promotions = strData.split('^');
        
        for(i=0;i<promotions.length ;i++)
        {
            var items = promotions[i].split('~');
            var promoHashTable = new PromotionHashtable();
            var fatherCode ;
            for(j=0;j<items.length ;j++)
            {
                var properties = items[j].split('|')
                var citys = properties[0].split('-');
                var deptCityCode = citys[0];
                var rtnCityCode = citys[1];
                var deptCode = properties[1];
                var desCode = properties[2];
                fatherCode = properties[3];
                var totalPrice = Number(properties[4]).toFixed(0);
                var stops = properties[5];
                var detpDate = properties[6];
                var rtnDate = properties[7];
                var airline = properties[8];
                var flighttype = properties[9];
                if(promoHashTable.hasItem(deptCityCode+'-'+rtnCityCode))
                {
                    if(Number(promoHashTable.getItem(deptCityCode+'-'+rtnCityCode).TotalPrice) > Number(totalPrice))
                    {
                        //if(promoHashTable.length < FlightNumber)
                            promoHashTable.setItem(deptCityCode+'-'+rtnCityCode,deptCode,desCode,fatherCode,stops,totalPrice,detpDate,rtnDate,airline,flighttype);//promoHashTable.removeItem(deptCityCode+'-'+rtnCityCode);
                    }
                }
                else
                {
                    //if(promoHashTable.length < FlightNumber)
                        promoHashTable.setItem(deptCityCode+'-'+rtnCityCode,deptCode,desCode,fatherCode,stops,totalPrice,detpDate,rtnDate,airline,flighttype);
                }
            }
            
            g_arr_Promotions[fatherCode]=promoHashTable;

        }
    }
    catch(e)
    {

    }

}


function Build_g_arr_Promotions(strData)
{
    try
    {
        var promotions = strData.split('^');
        
        for(i=0;i<promotions.length ;i++)
        {
            var items = promotions[i].split('~');
            var promoHashTable = new PromotionHashtable();
            var fatherCode ;
            for(j=0;j<items.length ;j++)
            {
                var properties = items[j].split('|')
                var citys = properties[0].split('-');
                var deptCityCode = citys[0];
                var rtnCityCode = citys[1];
//                if(g_arr_FilterCity.indexOf(rtnCityCode) < 0)
//                {
//                    continue;
//                }
                var deptCode = properties[1];
                var desCode = properties[2];
                fatherCode = properties[3];
                var totalPrice = Number(properties[4]).toFixed(0);
                var stops = properties[5];
                var detpDate = properties[6];
                var rtnDate = properties[7];
                var airline = properties[8];
                var flighttype = properties[9];
                if(promoHashTable.hasItem(deptCityCode+'-'+rtnCityCode))
                {
                    if(Number(promoHashTable.getItem(deptCityCode+'-'+rtnCityCode).TotalPrice) > Number(totalPrice))
                        promoHashTable.setItem(deptCityCode+'-'+rtnCityCode,deptCode,desCode,fatherCode,stops,totalPrice,detpDate,rtnDate,airline,flighttype);//promoHashTable.removeItem(deptCityCode+'-'+rtnCityCode);
                }
                else
                {
                    promoHashTable.setItem(deptCityCode+'-'+rtnCityCode,deptCode,desCode,fatherCode,stops,totalPrice,detpDate,rtnDate,airline,flighttype);
                }
            }
            
            g_arr_Promotions[fatherCode]=promoHashTable;
        }
    }
    catch(e)
    {

    }

}


function Build_g_hash_Main(strData)
{
   try
   {
        var hashmain = strData.split('@');
        
        for(i=0;i<hashmain.length ;i++)
        {
            var properties = hashmain[i].split('|')
            var Code = properties[0];
            var Name = properties[1];
            var isExist = false;
            var tX = properties[2].split('-');
            var _X = new Array();

            for(j=0;j<tX.length;j++)
            {
                isExist = false;
//                if(g_arr_FilterCity.indexOf(tX[j])<0)
//                    continue;
                for(k=0;k<_X.length;k++)
                {
                    if(_X[k] == tX[j])
                    {
                        isExist = true;
                        break;
                    }
                }
                if(!isExist)
                    _X.push(tX[j]);
            }
            
            var tY = properties[3].split('-');
            var _Y = new Array();

            for(j=0;j<tY.length;j++)
            {
                isExist = false;
                for(k=0;k<_Y.length;k++)
                {
                    if(_Y[k] == tY[j])
                    {
                        isExist = true;
                        break;
                    }
                }
                if(!isExist)
                    _Y.push(tY[j]);
            }
            
            var tXC = properties[5].split('-');
            var tXAC = properties[7].split('-');
            var _XCode = new Array();
            var _XACode = new Array();
            
            for(j = 0;j<tXC.length; j++)
            {
                isExist = false;
//                if(g_arr_FilterCity.indexOf(tXC[j])<0)
//                    continue;
                for(k=0;k<_XCode.length;k++)
                {
                    if(_XCode[k] == tXC[j])
                    {
                        isExist = true;
                        break;
                    }
                }
                if(!isExist)
                {
                    _XCode.push(tXC[j]);
                    _XACode.push(tXAC[j]);
                }
            }
            
            var tYC = properties[4].split('-');
            var tYAC = properties[6].split('-');
            var _YCode = new Array();
            var _YACode = new Array();
            for(j = 0;j<tYC.length; j++)
            {
                isExist = false;
                for(k=0;k<_YCode.length;k++)
                {
                    if(_YCode[k] == tYC[j])
                    {
                        isExist = true;
                        break;
                    }
                }
                if(!isExist)
                {
                    _YCode.push(tYC[j]);
                    _YACode.push(tYAC[j]);
                }
            }
            
            g_hash_Main.setItem(Code,Name,_X,_Y,_XCode,_YCode,_XACode,_YACode);
            
        }
    }
    catch(e)
    {

    }
}


function Build_g_arr_Conditions(strData)
{   try{
    var conditions = strData.split('^');
    for(i=0;i<conditions.length ;i++)
    {
        var items = conditions[i].split('@');
        for(j=0;j<items.length ;j++)
        {
           var properties = items[j].split('|');
           var deptCode = properties[0];
           var desCode = properties[1];
           var deptDate = properties[2];
           var rtnDate = properties[3];
           var adult = properties[4];
           var child = properties[5];
           var cabin = properties[6];
           var airlines = properties[7];
           var code =  properties[8];
           var flighttype = properties[9];
           g_hash_Condition.setItem(code,deptCode,desCode,deptDate,rtnDate,adult,child,cabin,airlines,flighttype);
        }
        
    }
    }catch(e){}
}


function Build_g_arr_Results(strData)
{
    try{
    if(strData.length > 0)
    {
        var Results = strData.split('^');
        for(i=0;i<Results.length ;i++)
        {
            var items = Results[i].split('@');

            for(j=0;j<items.length ;j++)
            {
                var properties = items[j].split('|')
                var month = properties[0];
                var price = Number(properties[1]).toFixed(0);
                var deptDate = properties[2];
                var rtnDate = properties[3];
                var duration = Number(properties[4]);
                var stops = Number(properties[5]);
                var airlines = properties[6];
                var deptCode = properties[7];
                var desCode = properties[8];
                var code = properties[9];
                var flighttype = properties[10];
                var updatetime = properties[11];
                var updatetimenum = properties[12];
                var tempDptDate = new Date(deptDate);
                var tempRtnDate = new Date(rtnDate);
                var dptDate = deptDate;//g_month[tempDptDate.getMonth()] + ' ' + tempDptDate.getDate() + ', ' + tempDptDate.toDateString().substr(tempDptDate.toDateString().length -2,2) + ' ' + g_weekday[tempDptDate.getDay()] ;
                var rtDate;// = g_month[tempRtnDate.getMonth()] + ' ' + tempRtnDate.getDate() + ', ' + tempRtnDate.toDateString().substr(tempRtnDate.toDateString().length -2,2) + ' ' + g_weekday[tempRtnDate.getDay()] ;
                if(flighttype.toLowerCase() == 'oneway' )
                {
                    rtDate = '';      
                    duration = '/';
                }
                else
                    rtDate = rtnDate;//g_month[tempRtnDate.getMonth()] + ' ' + tempRtnDate.getDate() + ', ' + tempRtnDate.toDateString().substr(tempRtnDate.toDateString().length -2,2) + ' ' + g_weekday[tempRtnDate.getDay()] ;

    //           g_hash_Result.setItem(deptCode+'-'+desCode+'-'+deptDate.replace('/','').replace('/','')+'-'+rtnDate.replace('/','').replace('/',''),month,price,dptDate,rtDate,duration,stops,airlines,deptDate,rtnDate,false,false);
    //           g_arr_TotalResult.push(new resultDetail(deptCode+'-'+desCode+'-'+deptDate.replace('/','').replace('/','')+'-'+rtnDate.replace('/','').replace('/',''),month,price,dptDate,rtDate,duration,stops,airlines,deptDate,rtnDate,false,false));
              
                g_hash_Result.setItem(code,month,price,dptDate,rtDate,duration,stops,airlines,deptDate,rtnDate,false,false,flighttype,updatetime,updatetimenum);
                g_arr_TotalResult.push(new resultDetail(code,month,price,dptDate,rtDate,duration,stops,airlines,deptDate,rtnDate,false,false,flighttype,updatetime,updatetimenum));
            }
        }
        //
        FirstInit();
    }
    }catch(e){}
}

function FirstInit()
{
    for(key=0;key<g_arr_TotalResult.length;key++)
    {
        g_arr_PageResult.push(g_arr_TotalResult[key]);
    }
}

function InitResult()
{

    g_arr_PageResult.length = 0;

    for(index=0;index<g_arr_TotalResult.length;index++)
    {
        var price = g_arr_TotalResult[index].Price;
        var month = g_arr_TotalResult[index].Month;
        var deptdate = g_arr_TotalResult[index].DDate;
        var IsExist = false;
        for(i=0;i< g_arr_PageResult.length;i++)
        {
            if(g_arr_PageResult[i].Month == month && g_arr_PageResult[i].DDate.substr(g_arr_PageResult[i].DDate.length-4,4) == deptdate.substr(deptdate.length-4,4))
            {
                IsExist = true;
                g_arr_PageResult[i].IsMore = true;
                if(Number(g_arr_PageResult[i].Price) > Number(price))
                {
                    g_arr_PageResult[i].Price = price;
                    break;
                }
            }

        }

        if(!IsExist)
        {
            g_arr_TotalResult[index].IsLowerFare= true
            g_arr_PageResult.push(new resultDetail(g_arr_TotalResult[index].Conde,g_arr_TotalResult[index].Month,g_arr_TotalResult[index].Price,g_arr_TotalResult[index].DeptDate,g_arr_TotalResult[index].RtnDate,g_arr_TotalResult[index].Duration,g_arr_TotalResult[index].Stops,g_arr_TotalResult[index].AirLines,g_arr_TotalResult[index].DDate,g_arr_TotalResult[index].RDate,g_arr_TotalResult[index].IsLowerFare,g_arr_TotalResult[index].IsMore,g_arr_TotalResult[index].FlightType,g_arr_TotalResult[index].UpdateTime,g_arr_TotalResult[index].UpdateTimeNumber));

        }

    }
   
}

//
function OpratePage(number,ArrObj)
{
    try{
    g_arr_workResult.length=0;
    g_arr_pageNum = Math.ceil(ArrObj.length/PageSize);
    if(g_arr_pageNum>1)
    {
        if(number == 1)
        {
            for(i=0;i<PageSize;i++)
            {
                g_arr_workResult.push(ArrObj[i]);
            }
        }
        if(number > 1 && number < g_arr_pageNum)
        {
            for(j=PageSize*(number-1);j<PageSize*number;j++)
            {
                g_arr_workResult.push(ArrObj[j]);
            }
        }
        if(number == g_arr_pageNum)
        {
            for(x=PageSize*(number-1);x<ArrObj.length;x++)
            {
                g_arr_workResult.push(ArrObj[x]);
            }
        }
    }
    else
    {
        for(k=0;k<ArrObj.length;k++)
        {
            g_arr_workResult.push(ArrObj[k]);
        }
    }
    Drawing(g_arr_pageNum);
    if(g_arr_pageNum > 1)
    {
        document.getElementById('a_'+number).style.color='#ff6600';
        document.getElementById('a_'+number).style.textDecoration='none';
        document.getElementById('a_'+number).style.fontWeight = 'bold';
    }
    
    }catch(e){}
}

function Drawing(pagenumber)
{
    try{
    document.getElementById('div_PageNum').innerHTML='#PAGE#';
    document.getElementById('div_PageNum').style.display = 'none';
    var HtmlString = '';
    if(pagenumber>1)
    {
        for(i=0;i<pagenumber;i++)
        {   
            var PageNumberString = document.getElementById('temp_Page').innerHTML;
            PageNumberString = PageNumberString.replace(/#NUM#/g,i+1);
            HtmlString += '&nbsp;' + PageNumberString;
        }
        var PageString = document.getElementById('div_PageNum').innerHTML;
        PageString = PageString.replace('#PAGE#',HtmlString);
        document.getElementById('div_PageNum').innerHTML = PageString;
        document.getElementById('div_PageNum').style.display = '';
    }
    else
    {
        var SpacePageString = document.getElementById('div_PageNum').innerHTML;
        SpacePageString = SpacePageString.replace('#PAGE#','&nbsp;');
        document.getElementById('div_PageNum').innerHTML = SpacePageString;
        document.getElementById('div_PageNum').style.display = '';
    }
    }catch(e){}
}

//
function InitMain(source)
{
    try
    {
        g_source = source;
        BoundCityAndPrice('1');
        BoundMain();
        //BoundDepCityAndPrice('1');
        var AreaCode = g_hash_Main.items[1].Code;
        ChangeDefaultClass(AreaCode);
    }
    catch(e)
    {
    
    }
}

//
function BoundDepCityAndPrice(FatherCode)
{
    try{
    var htmlStr='' ;
    var areaCode = FatherCode;
    var hash_Promation = g_arr_Promotions[FatherCode];

    if(hash_Promation != undefined)
    {
        if(g_hash_Main != undefined)
        {
            var DesCity = g_hash_Main.getItem(String(areaCode)).RegionX;
            var DepCity = g_hash_Main.getItem(String(areaCode)).RegionY;
            var DesCode = g_hash_Main.getItem(String(areaCode)).RegionXCode;
            var DepCode = g_hash_Main.getItem(String(areaCode)).RegionYCode;
            var DesAirportCode = g_hash_Main.getItem(String(areaCode)).RegionXACode;
            var DepAirportCode = g_hash_Main.getItem(String(areaCode)).RegionYACode;
            var FlightType = g_hash_Main.getItem(String(areaCode)).FlightType;
            var template = temp_divPrice;//document.getElementById('temp_divPrice').innerHTML;
            var tempHtml = '';
            var len = 0;
            if(FlightNumber>0 && DepCity.length > FlightNumber)
                len = FlightNumber
            else
                len = DepCity.length
            for(y=0;y<len;y++)
            {
                var tempDeptCity= temp_DeptCity;//document.getElementById('temp_DeptCity').innerHTML;
                var temptotalPrice = temp_totalPrice;//document.getElementById('temp_totalPrice').innerHTML;
                var tempStr='';
                for(x=0;x<DesCity.length;x++)
                {
                    var subCode = DepCode[y]+ "-" + DesCode[x];
                    var subAirportCode = DepAirportCode[y]+ "-" + DesAirportCode[x];;
                    var temp_Price= temp_PriceItem;//document.getElementById('temp_PriceItem').innerHTML;
                    var flightType = 'roundtrip';
                    if(hash_Promation.getItem(subCode) != undefined)
                    {   
                        subAirportCode = hash_Promation.getItem(subCode).DeptCode+'-'+hash_Promation.getItem(subCode).DesCode
                        flightType = hash_Promation.getItem(subCode).FlightType;
                        temp_Price = temp_Price.replace('#PRICE#',hash_Promation.getItem(subCode).TotalPrice);
                        temp_Price = temp_Price.replace('#ONCLICK#','SelectPromotion(this.id,this.name)');
                        if(hash_Promation.getItem(subCode).FlightType.toLowerCase() == 'oneway')
                            temp_Price = temp_Price.replace('#TITLE#','Sample Date: depart on ' + hash_Promation.getItem(subCode).DeptDate + ', Travel on '+ hash_Promation.getItem(subCode).AirLine);
                        else
                            temp_Price = temp_Price.replace('#TITLE#','Sample Date: depart on ' + hash_Promation.getItem(subCode).DeptDate + ' and return on ' + hash_Promation.getItem(subCode).RtnDate + ', Travel on '+ hash_Promation.getItem(subCode).AirLine);
                    }
                    else
                    {
                        //subAirportCode = subCode;
                        temp_Price = temp_Price.replace('$#PRICE#','Search');
                        temp_Price = temp_Price.replace('#ONCLICK#','SelectSearch(this.id,this.name)');
                        temp_Price = temp_Price.replace('#TITLE#','');
                    }
                    if(g_source == '')
                        temp_Price = temp_Price.replace("#CLASS#",x==0?'firstClass':'box_txt')
                    else
                        temp_Price = temp_Price.replace("#CLASS#",'box_txt')
                    temp_Price = temp_Price.replace('#SUBCODE#',subAirportCode+'-'+flightType);
                    temp_Price = temp_Price.replace('#AREACODE#',areaCode);
                    temp_Price = temp_Price.replace('#STYLE#','width:' + String(78/DesCity.length)+ '%;padding-right:3px');
                    tempStr += temp_Price;
                }
                tempDeptCity = tempDeptCity.replace('#DEPTCITY#',DepCity[y]);
                temptotalPrice= temptotalPrice.replace('#DPT#',tempDeptCity);
                temptotalPrice = temptotalPrice.replace('#FARE#',tempStr); 
//                if(y%2 == 0)
//                {
//                    temptotalPrice = temptotalPrice.replace('#BGCOLOR#',''); 
//                }
//                else
//                {
//                    temptotalPrice = temptotalPrice.replace('#BGCOLOR#','#F1FAE8'); 
//                }
                tempHtml+=temptotalPrice;
                
            }
        }
        
         document.getElementById('div_Price').innerHTML = template.replace('#PRICE_LIST#',tempHtml);
    }
    else
    {
        document.getElementById('div_Price').innerHTML = '&nbsp;';
    }
    
    }catch(e){}
}

//
function BoundCityAndPrice(FatherCode)
{
    try{
    var htmlResultStr = '';
    var htmlTitleStr='<td height="20" align="left" class="box_up"><b>' + MSG_FROM_TO + '</b></td>' ;
    var areaCode = FatherCode;
    var desCity = g_hash_Main.getItem(String(areaCode)).RegionX;
    for(j=0;j<desCity.length;j++)
    {
        var tamplate= new_temp_title_item;
        var cityName  = desCity[j];
        if(g_source == '')
        {
            tamplate = tamplate.replace('#Class#',j==0?'firstbgcolor':'box_up');
            tamplate = tamplate.replace('#DesCity#',j==0?("<font class=\"firstCity\">"+cityName+"</font>"):cityName);
        }
        else
        {
            tamplate = tamplate.replace('#Class#','box_up');
            tamplate = tamplate.replace('#DesCity#',cityName);
        }
        htmlTitleStr += tamplate;
    }
    var htmlTitle = new_temp_title;
    htmlTitle = htmlTitle.replace('#Title#',htmlTitleStr);
    
    var hash_Promation = g_arr_Promotions[areaCode];

    var htmlPrice = '';
    if(hash_Promation != undefined)
    {
        if(g_hash_Main != undefined)
        {
            var DesCity = g_hash_Main.getItem(String(areaCode)).RegionX;
            var DepCity = g_hash_Main.getItem(String(areaCode)).RegionY;
            var DesCode = g_hash_Main.getItem(String(areaCode)).RegionXCode;
            var DepCode = g_hash_Main.getItem(String(areaCode)).RegionYCode;
            var DesAirportCode = g_hash_Main.getItem(String(areaCode)).RegionXACode;
            var DepAirportCode = g_hash_Main.getItem(String(areaCode)).RegionYACode;
            var FlightType = g_hash_Main.getItem(String(areaCode)).FlightType;

            var len = 0;
            if(FlightNumber>0 && DepCity.length > FlightNumber)
                len = FlightNumber
            else
                len = DepCity.length
            for(y=0;y<len;y++)
            {
                var htmlPriceStr = new_temp_price;
                var htmlDepCityStr = new_temp_depcity;
                htmlDepCityStr = htmlDepCityStr.replace('#DepCity#',DepCity[y]);
                if(g_source == '')
                {
                    if(y == len-1)
                        htmlDepCityStr = htmlDepCityStr.replace('box_txt','lastClass');
                }
                var tempStr=htmlDepCityStr;
                for(x=0;x<DesCity.length;x++)
                {
                    var subCode = DepCode[y]+ "-" + DesCode[x];
                    var subAirportCode = DepAirportCode[y]+ "-" + DesAirportCode[x];;
                    var htmlPrictItemStr = new_temp_price_item;
                    var flightType = 'roundtrip';
                    if(hash_Promation.getItem(subCode) != undefined)
                    {   
                        subAirportCode = hash_Promation.getItem(subCode).DeptCode+'-'+hash_Promation.getItem(subCode).DesCode
                        flightType = hash_Promation.getItem(subCode).FlightType;
                        htmlPrictItemStr = htmlPrictItemStr.replace('#PRICE#',hash_Promation.getItem(subCode).TotalPrice);
                        htmlPrictItemStr = htmlPrictItemStr.replace('#ONCLICK#','SelectPromotion(this.id,this.name)');
                        if(hash_Promation.getItem(subCode).FlightType.toLowerCase() == 'oneway')
                            htmlPrictItemStr = htmlPrictItemStr.replace('#TITLE#','Sample Date: depart on ' + hash_Promation.getItem(subCode).DeptDate + ', Travel on '+ hash_Promation.getItem(subCode).AirLine);
                        else
                            htmlPrictItemStr = htmlPrictItemStr.replace('#TITLE#','Sample Date: depart on ' + hash_Promation.getItem(subCode).DeptDate + ' and return on ' + hash_Promation.getItem(subCode).RtnDate + ', Travel on '+ hash_Promation.getItem(subCode).AirLine);
                    }
                    else
                    {
                        //subAirportCode = subCode;
                        htmlPrictItemStr = htmlPrictItemStr.replace('$#PRICE#','Search');
                        htmlPrictItemStr = htmlPrictItemStr.replace('#ONCLICK#','SelectSearch(this.id,this.name)');
                        htmlPrictItemStr = htmlPrictItemStr.replace('#TITLE#','');
                    }
                    if(g_source == '')
                    {
                        if(y == len-1)
                            htmlPrictItemStr = htmlPrictItemStr.replace("#Class#",x==0?'firstLastClass':'lastClass');
                        else
                            htmlPrictItemStr = htmlPrictItemStr.replace("#Class#",x==0?'firstClass':'box_txt')
                    }
                    else
                    {
                        htmlPrictItemStr = htmlPrictItemStr.replace("#Class#",'box_txt')
                    }
                    htmlPrictItemStr = htmlPrictItemStr.replace('#SUBCODE#',subAirportCode+'-'+flightType);
                    htmlPrictItemStr = htmlPrictItemStr.replace('#AREACODE#',areaCode);
                    htmlPrictItemStr = htmlPrictItemStr.replace('#STYLE#','width:' + String(78/DesCity.length)+ '%;padding-right:3px');
                    tempStr += htmlPrictItemStr;
                }

             htmlPriceStr = htmlPriceStr.replace('#Item#',tempStr);
             htmlPrice += htmlPriceStr;
            }
            
        }
        
         htmlResultStr = htmlTitle + htmlPrice;
         var resultstring = new_temp_table;
         resultstring = resultstring.replace('#Result#',htmlResultStr);
         document.getElementById('div_Price').innerHTML = resultstring;
         
    }
    else
    {
        document.getElementById('div_Price').innerHTML = '&nbsp;';
    }
    
//    var tmp= temp_divDES;
//    tmp = tmp.replace('#DestionCity#',htmlStr);
//    document.getElementById('divDES').innerHTML = tmp;
    
    }catch(e){}
}

//
function BoundMain(Name)
{try{
    var htmlStr='' ;
    for(i=0;i<g_hash_Main.length;i++)
    {
        var AreaName = g_hash_Main.items[i+1].Name;
        var AreaCode = g_hash_Main.items[i+1].Code;
        var tamplate= temp_areaItem;//document.getElementById('temp_areaItem').innerHTML;
        var tempCompart= temp_areaItemCompart;//document.getElementById('temp_areaItemCompart').innerHTML;
        
        if(i<g_hash_Main.length-1)
        {
           
            tamplate = tamplate.replace('#AreaName#',AreaName);
            tamplate = tamplate.replace(/#AreaCode#/g,AreaCode);
            htmlStr += tamplate;
            htmlStr += tempCompart;
        }
        else
        {
           
            tamplate = tamplate.replace('#AreaName#',AreaName);
            tamplate = tamplate.replace(/#AreaCode#/g,AreaCode);
            htmlStr += tamplate;
        }

    }
    
    var tmp= document.getElementById('divMain').innerHTML;
    tmp = tmp.replace('#TEMPLATE#',htmlStr);
    document.getElementById('divMain').innerHTML = tmp;
    document.getElementById('tbLowerFare').style.display = '';
}catch(e){}
}

//
function ChangeArea(AreaCode)
{try{
    BoundCityAndPrice(AreaCode);
    //BoundDepCityAndPrice(AreaCode);
    ClearSelectTab();
    ChangeDefaultClass(AreaCode);
    }catch(e){}
}


function ChangeDefaultClass(AreaCode)
{
try{
    document.getElementById('img_left_' + AreaCode).src = document.getElementById('img_left_' + AreaCode).src.replace("img/area_off_l.gif","img/area_on_l.gif");
    document.getElementById('img_right_' + AreaCode).src = document.getElementById('img_right_' + AreaCode).src.replace("img/area_off_r.gif","img/area_on_r.gif");;
    document.getElementById('td_' + AreaCode).className = 'area-on';
    document.getElementById(AreaCode).className = "area-on-link";
}catch(e){}
}

function ClearSelectTab()
{
    for(i=0;i<g_hash_Main.length;i++)
    {
        var AreaCode = g_hash_Main.items[i+1].Code;
        document.getElementById('img_left_' + AreaCode).src = "img/area_off_l.gif";
        document.getElementById('img_right_' + AreaCode).src = "img/area_off_r.gif";
        document.getElementById('td_' + AreaCode).className = "area-off";
        document.getElementById(AreaCode).className = "area-link";
    }
}

function getURL() {var  url = window.location.pathname;  var last_slash = url.lastIndexOf('/'); 	return url.substr(0,last_slash+1).toLowerCase(); }	

function SelectPromotion(subCode,AreaCode)
{
try{
    document.getElementById("btn_ClickLowFare").click();
    var codes = subCode.split('-');
    var deptCode = codes[0];
    var desCode = codes[1];
    var flightType = codes[2];
    if(window.location.pathname.indexOf("/Flight/")>0)
    {   
        window.location.href = "FlightSearch.aspx?DeptCode=" + deptCode + "&DesCode=" + desCode + "&FlightType=" + flightType;}
    else
    {
    
        window.location.href = "Page/Flight/FlightSearch.aspx?DeptCode=" + deptCode + "&DesCode=" + desCode + "&FlightType=" + flightType;
        }
    }catch(e){}
}

function SelectSearch(subCode,AreaCode)
{
try{
    var codes = subCode.split('-');
    var deptCode = codes[0];
    var desCode = codes[1];
    var flightType = codes[2];
    if(window.location.pathname.indexOf("/Flight/")>0)
        window.location.href = "FightRedirect.aspx?ToCity=" + desCode  + "&FromCity=" + deptCode;
    else
        window.location.href = "Page/Flight/FightRedirect.aspx?ToCity=" + desCode  + "&FromCity=" + deptCode;
    
    }catch(e){}
}

function InitBoundResults()
{
   
    g_arr_TotalResult.sort(MySortByPrice);
    FirstSort(g_arr_TotalResult);
    OpratePage(1,g_arr_TotalResult);
    BoundResults(g_arr_workResult,false);
}

function FirstSort(Obj)
{
    if(Obj.length > 0)
    {
        var temp_g_arr_result = new Array();
        var temp_g_arr = new Array();
        temp_g_arr_result.push(Obj[0]); 
        for(var j=1;j<Obj.length;j++)
        {
            temp_g_arr.push(Obj[j]);
        }
        Obj.length = 0;
        Obj.push(temp_g_arr_result[0]);
        temp_g_arr.sort(MysortbySearchTime);
        for(var i = 0;i< temp_g_arr.length;i++)
        {
             Obj.push(temp_g_arr[i]);
        }  
    }  
}

function BoundResults(ArrObj,IsGroupDisplay)
{
try{
    //document.getElementById('div_List').innerHTML = '<table width="602" border="0" cellspacing="0" cellpadding="0"> ';//#RESULT_LIST#</table>';
    var htmlString = '';
    var index = 0;
    if(ArrObj.length != 0)
    {
        document.getElementById('td_BestFareHead').style.display = '';
        for(key=0;key<ArrObj.length;key++)
        {
            var tempHtml = price_Item;//document.getElementById('tem_PriceItem').innerHTML;
            var code = ArrObj[key].Code;
            var month = ArrObj[key].Month;
            var price = ArrObj[key].Price;
            var deptDate = ArrObj[key].DeptDate;
            var rtnDate = ArrObj[key].RtnDate;
            var duration = ArrObj[key].Duration;
            var stops = ArrObj[key].Stops;
            var airlines = ArrObj[key].AirLines;
            var ismore = ArrObj[key].IsMore;
            var dDate = ArrObj[key].DDate;
            var updatetime = ArrObj[key].UpdateTime;
            var dates = dDate.toString().split('/');
            var my = Number(dates[0]) + '-' + dates[2];
            
            tempHtml = tempHtml.replace("#NUM#",key+1);
            if(ismore && IsGroupDisplay)
                tempHtml = tempHtml.replace("#MONTH#",'+'+ month);
            else
                tempHtml = tempHtml.replace("#MONTH#",month);
            tempHtml = tempHtml.replace("#PRICE#",price);
            tempHtml = tempHtml.replace("#DEPTDATE#",deptDate);
            tempHtml = tempHtml.replace("#RTNDATE#",rtnDate);
            tempHtml = tempHtml.replace("#DURATION#",duration);
            tempHtml = tempHtml.replace("#STOPS#",stops);
            tempHtml = tempHtml.replace("#TIME#",updatetime);
            tempHtml = tempHtml.replace("#AIRLINE#",airlines);
            tempHtml = tempHtml.replace(/#CODE#/g,code);
            tempHtml = tempHtml.replace(/#MY#/g,my);
            if(index%2 == 0)
            {
                tempHtml = tempHtml.replace(/#BGCOLOR#/g,'');
            }
            else
            {
                tempHtml = tempHtml.replace(/#BGCOLOR#/g,'#F1FAE8');
            }
            
            htmlString += tempHtml;
            index++;
        }
        var htmlList  = '<table width="602" border="0" cellspacing="0" cellpadding="0"> ';
        htmlList = htmlList+htmlString+'</table>';//htmlList.replace("#RESULT_LIST#",htmlString);
        if(!IsGroupDisplay)
        {
            if(document.all) //if IE 
            {
                htmlList = htmlList.replace(/block/g,'none');
                document.getElementById('td_Num').width = '6%'
                document.getElementById('td_Month').style.display='none';
                document.getElementById('td_Price').width = '9%'
                document.getElementById('td_Depart').width = '13%'
                document.getElementById('td_Return').width = '13%'
                document.getElementById('td_Duration').width = '10%'
                document.getElementById('td_Stops').width = '9%'
                document.getElementById('td_Airline').width = '21%'
                document.getElementById('td_UpdateTime').width = '17%'
                document.getElementById('td_Space').width = '7%' 
            }
            else //if FireFox
            {
                htmlList = htmlList.replace(/block/g,'none');
                document.getElementById('td_Num').width = '6%'
                document.getElementById('td_Month').style.display='none';
                document.getElementById('td_Price').width = '8%'
                document.getElementById('td_Depart').width = '12%'
                document.getElementById('td_Return').width = '12%'
                document.getElementById('td_Duration').width = '10%'
                document.getElementById('td_Stops').width = '8%'
                document.getElementById('td_Airline').width = '20%'
                document.getElementById('td_UpdateTime').width = '16%'
                document.getElementById('td_Space').width = '8%'
            }
        }
        else
        {
            if(document.all) // if IE
            {
                htmlList = htmlList.replace(/block/g,'');
                document.getElementById('td_Num').width = '6%'
                document.getElementById('td_Month').style.display='';
                document.getElementById('td_Price').width = '6%'
                document.getElementById('td_Depart').width = '12%'
                document.getElementById('td_Return').width = '12%'
                document.getElementById('td_Duration').width = '10%'
                document.getElementById('td_Stops').width = '8%'
                document.getElementById('td_Airline').width = '20%'
                document.getElementById('td_UpdateTime').width = '16%'
                document.getElementById('td_Space').width = '8%' 
            }
            else // if FireFox
            {
                htmlList = htmlList.replace(/block/g,'');
                document.getElementById('td_Num').width = '5%'
                document.getElementById('td_Month').style.display='';
                document.getElementById('td_Month').width = '7%';
                document.getElementById('td_Price').width = '7%'
                document.getElementById('td_Depart').width = '12%'
                document.getElementById('td_Return').width = '12%'
                document.getElementById('td_Duration').width = '9%'
                document.getElementById('td_Stops').width = '7%'
                document.getElementById('td_Airline').width = '19%'
                document.getElementById('td_UpdateTime').width = '15%'
                document.getElementById('td_Space').width = '7%' 
            }
        }
        document.getElementById('div_List').innerHTML = htmlList;
        document.getElementById('div_List').style.display = 'block';
        document.getElementById('div_DisplayNoResult').style.display = 'none';
    }
    else
    {
        document.getElementById('td_BestFareHead').style.display = 'none';
        document.getElementById('div_DisplayNoResult').style.display = '';
        document.getElementById('div_List').style.display='none';
    }
    
    }catch(e){}
}


function ClickSearch(code)
{
try{
    var codes = code.split('_');
    var index = codes[1];
    var deptdate = g_hash_Condition.getItem(index).DeptDate;
    var rtndate = g_hash_Condition.getItem(index).RtnDate;
    var deptCity = g_hash_Condition.getItem(index).DeptCode;
    var rtnCity = g_hash_Condition.getItem(index).DesCode;
    var adultnumber = g_hash_Condition.getItem(index).AdultNum;
    var childnumber = g_hash_Condition.getItem(index).ChildNum;
    var cabin = g_hash_Condition.getItem(index).Cabin;
    var airline = g_hash_Condition.getItem(index).AirLines;
    var conditionStr = deptCity + '|' + rtnCity + '|' + deptdate + '|' + rtndate + '|' + adultnumber + '|' + childnumber + '|' + cabin + '|' + airline;
    document.getElementById('SearchCondition').value = conditionStr;
    document.getElementById("btn_CreateSearchConditionAndSearch").click();
    
    }catch(e){}
}   


//
function FilterResult()
{
    g_arr_PageResult = new Array();
    var date = document.getElementById('listBDate').value
    var IsGroupDisplay = false;
    if(date != "0" && date != "99")
    {
        var dates = date.split('-');
        var monthnum = dates[0];
        var year = dates[1];
        for(key=0;key<g_arr_TotalResult.length;key++)
        {
            var tempdate = new Date(g_arr_TotalResult[key].DDate);
             if(tempdate.getMonth()+1 == monthnum && tempdate.toDateString().substr(tempdate.toDateString().length -4,4) == year)
            {
                g_arr_PageResult.push(g_arr_TotalResult[key]);
            }
         }
    }
    else if(date == "0")
    {
        for(key=0;key<g_arr_TotalResult.length;key++)
        {
            g_arr_PageResult.push(g_arr_TotalResult[key]);
        }
    }
    else
    {
        IsGroupDisplay = true;
        InitResult();
    }
    
    g_arr_PageResult.sort(MySortByPrice);
    if(date != "99")
        FirstSort(g_arr_PageResult);
    OpratePage(1,g_arr_PageResult);
    BoundResults(g_arr_workResult,IsGroupDisplay);
       
}  

//
function MySortByPrice(a, b) { var x = Number(a.Price); var y = Number(b.Price); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }   

function MySortByPriceDesc(a, b) { var x = Number(a.Price); var y = Number(b.Price); return ((x > y) ? -1 : ((x < y) ? 1 : 0)); }

function MysortbyAirlines(a,b) { var x = a.AirLines.toLowerCase(); var y = b.AirLines.toLowerCase(); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }

function MysortbyAirlinesDesc(a,b) { var x = a.AirLines.toLowerCase(); var y = b.AirLines.toLowerCase(); return ((x > y) ? -1 : ((x < y) ? 1 : 0)); }

function MysortbyDuration(a,b) { var x = a.Duration; var y = b.Duration; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }

function MysortbyDurationDesc(a,b) { var x = a.Duration; var y = b.Duration; return ((x > y) ? -1 : ((x < y) ? 1 : 0)); }

function MysortByStops(a, b) { 	var x = a.Stops; 	var y = b.Stops; 	return ((x < y) ? -1 : ((x > y) ? 1 : 0)); 	}

function MysortByStopsDesc(a, b) { 	var x = a.Stops; 	var y = b.Stops; 	return ((x > y) ? -1 : ((x < y) ? 1 : 0)); 	}

function MysortByDepart(a, b) { 	var x = a.DDate; 	var y = b.DDate; 	return ((x < y) ? -1 : ((x > y) ? 1 : 0)); 	}

function MysortByDepartDesc(a, b) { 	var x = a.DDate; 	var y = b.DDate; 	return ((x > y) ? -1 : ((x < y) ? 1 : 0)); 	}

function MysortbyArrival(a, b) { var x = a.RDate; var y = b.RDate; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }
function MysortbyArrivalDesc(a, b) { var x = a.RDate; var y = b.RDate; return ((x > y) ? -1 : ((x < y) ? 1 : 0)); }

function MysortbySearchTime(a, b) { var x = Number(a.UpdateTimeNumber); var y = Number(b.UpdateTimeNumber); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }
function MysortbySearchTimeDesc(a, b) { var x = Number(a.UpdateTimeNumber); var y = Number(b.UpdateTimeNumber); return ((x > y) ? -1 : ((x < y) ? 1 : 0)); }
//End

function CheckFares()
{
    g_arr_PageResult.length = 0;
    g_arr_CurrentPageNumber = 1;
    var dDate = document.getElementById('depCalendar_calendarDate').value;
    var rDate = document.getElementById('rtnCalendar_calendarDate').value;
    var dDays;
    var rDays;
    var IsGroupDisplay = false;
    if(dDate != '')
    {
        dDays = document.getElementById('txtDeptFlexible').value;
        if(dDays == '')
        {
            dDays = 0;
        }
    }
    else
    {
        dDays = 0;
    }
    if(rDate != '')
    {
        rDays = document.getElementById('txtRtnFlexible').value;
        if(rDays == '')
        {
            rDays = 0;
        }
    }
    else
    {
        rDays = 0;
    }
    
    if(dDate == '' && rDate == '')
    {
        for(key=0;key<g_arr_TotalResult.length;key++)
        {
            g_arr_PageResult.push(g_arr_TotalResult[key]);
        }
    }
    else
    {
        var tempCompDdate;
        var tempCompRdate;
        for(key=0;key<g_arr_TotalResult.length;key++)
        {
            var tempDdate = new Date(g_arr_TotalResult[key].DDate);
            var tempRdate = new Date(g_arr_TotalResult[key].RDate);
            var tempHtml = document.getElementById('tem_PriceItem').innerHTML;
            
            if(dDate != '')
                tempCompDdate = new Date(dDate);
            if(rDate != '')
                tempCompRdate = new Date(rDate);

            if(tempCompDdate != null && tempCompRdate != null)
            {
                if((tempDdate >= tempCompDdate.setDate(tempCompDdate.getDate()-Number(dDays)) && tempDdate <= tempCompDdate.setDate(tempCompDdate.getDate()+Number(dDays)*2)) && (tempRdate >= tempCompRdate.setDate(tempCompRdate.getDate()-Number(rDays)) && tempRdate <=tempCompRdate.setDate(tempCompRdate.getDate()+Number(rDays)*2)))
                {
                    g_arr_PageResult.push(g_arr_TotalResult[key]);
                }
            }
            else
            {
                if(tempCompDdate != null)
                {
                    if((tempDdate >= tempCompDdate.setDate(tempCompDdate.getDate()-Number(dDays)) && tempDdate <= tempCompDdate.setDate(tempCompDdate.getDate()+Number(dDays)*2)))
                    {
                        g_arr_PageResult.push(g_arr_TotalResult[key]);
                    }
                }
                if(tempCompRdate != null)
                {
                    if((tempRdate >= tempCompRdate.setDate(tempCompRdate.getDate()-Number(rDays)) && tempRdate <= tempCompRdate.setDate(tempCompRdate.getDate()+Number(rDays)*2)))
                    {
                        g_arr_PageResult.push(g_arr_TotalResult[key]);
                    }
                }
            }
        }
    }
    g_arr_PageResult.sort(MySortByPrice);
    OpratePage(1,g_arr_PageResult);
    BoundResults(g_arr_workResult,false);
}

function ClickSearchBestFare()
{
    var datestr = document.getElementById('listBDate').value;
    var deptCity = document.getElementById('depCity_txtCity').value;
    var toCity = document.getElementById('toCity_txtCity').value;
    document.getElementById('DeptCity').value = document.getElementById('depCity_txtCity').value;
    document.getElementById('RtnCity').value = document.getElementById('toCity_txtCity').value;
    var flightType = document.getElementById('FlightType').value
    document.getElementById("iframeLowerFare").src='SearchLowerFare.aspx?IsIndex=false&DeptCode=' + deptCity + '&DesCode=' + toCity +'&IsSearch=true' + "&FlightType=" + flightType;
   // SelectDate(datestr);
}

function BoundCountryAndCity(stringData)
{
try{
    var countryandcitystr = stringData.split('|');
    document.getElementById('lbDept').innerHTML = countryandcitystr[0];
    document.getElementById('lbDes').innerHTML = countryandcitystr[1];
    document.getElementById('lbDept').style.display = '';
    document.getElementById('lbDes').style.display = '';
    document.getElementById('lblFrom').style.display = '';
    document.getElementById('lblTo').style.display = '';
    }catch(e){}
}

//// 
function ClearPromotionAll()
{
    
    g_hash_Main = new MainHashtable();
    g_arr_Promotions.length = 0;
}

////
function ClearResultAll()
{
    g_hash_Condition = new ConditionHashtable();
    g_hash_Result = new ResultHashtable();
    g_hash_FilterResult = new ResultHashtable();
    g_arr_TotalResult.length = 0;
    g_arr_workResult.length = 0;
    g_arr_PageResult.length = 0;
    g_arr_CurrentPageNumber = 1;
}



//
function OrderBy(orderkey)
{
    var IsGroupDisplay = false;
    var flag = Number(document.getElementById('OrderByFlag').value);
    switch(orderkey)
    {
        case 'month':
            if(flag%2 != 0)
            {
                g_arr_PageResult.sort(MysortByDepart);
                //g_arr_workResult.sort(MysortByDepart);
            }
            else
            {
                g_arr_PageResult.sort(MysortByDepartDesc);
                //g_arr_workResult.sort(MysortByDepartDesc);
            }
            flag++;
            break;
        case 'price':
            if(flag%2 != 0)
            {
                g_arr_PageResult.sort(MySortByPrice);
                //g_arr_workResult.sort(MySortByPrice);
            }
            else
            {
                g_arr_PageResult.sort(MySortByPriceDesc);
                //g_arr_workResult.sort(MySortByPriceDesc);
            }
            flag++;
            break;
        case 'depart':
            if(flag%2 != 0)
            {
                g_arr_PageResult.sort(MysortByDepart);
                //g_arr_workResult.sort(MysortByDepart);
            }
            else
            {
                g_arr_PageResult.sort(MysortByDepartDesc);
                //g_arr_workResult.sort(MysortByDepartDesc);
            }
            flag++;
            break;
        case 'return':
            if(flag%2 != 0)
            {
                g_arr_PageResult.sort(MysortbyArrival);
                //g_arr_workResult.sort(MysortbyArrival);
            }
            else
            {
                g_arr_PageResult.sort(MysortbyArrivalDesc);
                //g_arr_workResult.sort(MysortbyArrivalDesc);
            }
            flag++;
            break;
        case 'duration':
            if(flag%2 != 0)
            {
                g_arr_PageResult.sort(MysortbyDuration);
                //g_arr_workResult.sort(MysortbyDuration);
            }
            else
            {
                g_arr_PageResult.sort(MysortbyDurationDesc);
                //g_arr_workResult.sort(MysortbyDurationDesc);
            }
            flag++;
            break;
        case 'stops':
            if(flag%2 != 0)
            {
                g_arr_PageResult.sort(MysortByStops);
                //g_arr_workResult.sort(MysortByStops);
            }
            else
            {
                g_arr_PageResult.sort(MysortByStopsDesc);
                //g_arr_workResult.sort(MysortByStopsDesc);
                
            }
            flag++;
            break;
        case 'airline':
            if(flag%2 != 0)
            {
                g_arr_PageResult.sort(MysortbyAirlines);
                //g_arr_workResult.sort(MysortbyAirlines);
            }
            else
            {
                g_arr_PageResult.sort(MysortbyAirlinesDesc);
                //g_arr_workResult.sort(MysortbyAirlinesDesc);
            }
            flag++;
            break;
        case 'searchtime':
            if(flag%2 != 0)
            {
                g_arr_PageResult.sort(MysortbySearchTime);
                //g_arr_workResult.sort(MysortbyAirlines);
            }
            else
            {
                g_arr_PageResult.sort(MysortbySearchTimeDesc);
                //g_arr_workResult.sort(MysortbyAirlinesDesc);
            }
            flag++;
            break;
        default:
            if(flag%2 != 0)
            {
                g_arr_PageResult.sort(MySortByPrice);
                //g_arr_workResult.sort(MySortByPrice);
            }
            else
            {
                g_arr_PageResult.sort(MySortByPriceDesc);
                //g_arr_workResult.sort(MySortByPriceDesc);
            }
            flag++;
            break;
    }
    document.getElementById('OrderByFlag').value = flag;
    
    var date = document.getElementById('listBDate').value
    if(date == "99")
        IsGroupDisplay = true;
    OpratePage(g_arr_CurrentPageNumber,g_arr_PageResult);
    BoundResults(g_arr_workResult,IsGroupDisplay);
}

function ClickMonth(obj)
{
try{
    g_arr_CurrentPageNumber = 1;
    var option = document.getElementById('listBDate').options;
    for(i=0;i<option.length;i++)
    {
        if(option[i].value == obj)
        {
          option[i].selected = true;
          FilterResult();
          break;
        }
    }
    //HiddenMonthCol();
    }catch(e){}
}

function HiddenMonthCol()
{
    var htmlString = document.getElementById('div_List').innerHTML;
    htmlString = htmlString.replace(/block/g,'none');
    document.getElementById('div_List').innerHTML = htmlString;
    document.getElementById('td_Month').style.display='none';
}

function ClickPageNumber(obj)
{
try{
    var data = obj.split('_');
    g_arr_CurrentPageNumber = Number(data[1]);
    OpratePage(g_arr_CurrentPageNumber,g_arr_PageResult);
    BoundResults(g_arr_workResult,false);
    document.getElementById(obj).style.color='#ff6600';
    document.getElementById(obj).style.textDecoration='none';
    }catch(e){}
}

function SetUsableDate()
{
    try
    {
        var dDate = document.getElementById('depCalendar_calendarDate').value;
        if(dDate == '')
        {
            alert('OK');
            document.getElementById('rtnCalendar_calendarDate').LowerLimitID = '';
        }
    }
    catch(e)
    {

    }
}

var MyMar1;
var showIndex = 0;
var temp_PriceItemForEsoonBanner = '<td width="97" align="center"><a href="#" id="#SUBCODE#" name="#AREACODE#" title="#TITLE#" onclick="#ONCLICK#" onmouseover="#ONMOUSEOVER#" onmouseout="#ONMOUSEOUT#" class="price">$#PRICE#</a></td>';
var temp_DeptCityForEsoonBanner = '<table border="0" cellspacing="0" cellpadding="0"><tr><td width="125" align="center"><span class="depart">#DEPTCITY#</span></td><td width="38">&nbsp;</td>'

function InitMainForSina()
{
    try
    {
        MyMar1 = setTimeout("BoundDepCityAndPriceForSina(1)",0) 
        
    }
    catch(e)
    {
    
    }
}
function BoundDepCityAndPriceForSina(FatherCode)
{
    
    try{
    var htmlStr='' ;
    var areaCode = FatherCode;
    var hash_Promation = g_arr_Promotions[FatherCode];
   
    if(hash_Promation != undefined)
    {
        if(g_hash_Main != undefined)
        {
            var DesCity = g_hash_Main.getItem(String(areaCode)).RegionX;
            var DepCity = g_hash_Main.getItem(String(areaCode)).RegionY;
            var DesCode = g_hash_Main.getItem(String(areaCode)).RegionXCode;
            var DepCode = g_hash_Main.getItem(String(areaCode)).RegionYCode;
            var DesAirportCode = g_hash_Main.getItem(String(areaCode)).RegionXACode;
            var DepAirportCode = g_hash_Main.getItem(String(areaCode)).RegionYACode;
            var FlightType = g_hash_Main.getItem(String(areaCode)).FlightType;
            var tempHtml = '';

            if(showIndex>=DepCity.length)
            showIndex=0;
            y=showIndex;

            var tempDeptCity= temp_DeptCityForEsoonBanner;
          
            var tempStr='';
            for(x=0;x<DesCity.length;x++)
            {
                var subCode = DepCode[y]+ "-" + DesCode[x];
                var subAirportCode = DepAirportCode[y]+ "-" + DesAirportCode[x];;
                var temp_Price= temp_PriceItemForEsoonBanner;//document.getElementById('temp_PriceItem').innerHTML;
                var flightType = 'roundtrip';
                if(hash_Promation.getItem(subCode) != undefined)
                {   
                    subAirportCode = hash_Promation.getItem(subCode).DeptCode+'-'+hash_Promation.getItem(subCode).DesCode
                    flightType = hash_Promation.getItem(subCode).FlightType;
                    temp_Price = temp_Price.replace('#PRICE#',hash_Promation.getItem(subCode).TotalPrice);
                    temp_Price = temp_Price.replace('#ONCLICK#','SelectPromotionForEsoonBanner(this.id,this.name,1)');
                    if(hash_Promation.getItem(subCode).FlightType.toLowerCase() == 'oneway')
                        temp_Price = temp_Price.replace('#TITLE#','Sample Date: depart on ' + hash_Promation.getItem(subCode).DeptDate + ', Travel on '+ hash_Promation.getItem(subCode).AirLine);
                    else
                        temp_Price = temp_Price.replace('#TITLE#','Sample Date: depart on ' + hash_Promation.getItem(subCode).DeptDate + ' and return on ' + hash_Promation.getItem(subCode).RtnDate + ', Travel on '+ hash_Promation.getItem(subCode).AirLine);
                }
                else
                {
                    //subAirportCode = subCode;
                    temp_Price = temp_Price.replace('$#PRICE#','Search');
                    temp_Price = temp_Price.replace('#ONCLICK#','SelectPromotionForEsoonBanner(this.id,this.name,0)');
                    temp_Price = temp_Price.replace('#TITLE#','');
                }

                temp_Price = temp_Price.replace('#ONMOUSEOVER#',"clearTimeout(MyMar1)");
                temp_Price = temp_Price.replace('#ONMOUSEOUT#',"javascript:MyMar1=setTimeout('BoundDepCityAndPriceForSina(1)',1500)");
                temp_Price = temp_Price.replace('#SUBCODE#',subAirportCode+'-'+flightType);
                temp_Price = temp_Price.replace('#AREACODE#',areaCode);
                temp_Price = temp_Price.replace('#STYLE#','width:' + String(72/DesCity.length)+ '%;padding-right:3px');
                tempStr += temp_Price;
            }
            tempDeptCity = tempDeptCity.replace('#DEPTCITY#',DepCity[y]);
       
            tempHtml+=tempDeptCity + tempStr;
            
        }
        showIndex++ ;
       
        tempHtml = tempHtml+"</tr></table>";
        document.getElementById('div_Price').innerHTML = tempHtml;
        $('#div_Price').fadeIn('slow');

        
    }
    else
    {
        document.getElementById('div_Price').innerHTML = '&nbsp;';
       
    }
    MyMar1 = setTimeout("BoundDepCityAndPriceForSina(1)",10000)   
    }catch(e){}
   
}

function SelectPromotionForEsoonBanner(subCode,AreaCode,type)
{
    try{
        if(document.getElementById("btn_ClickLowFare")!=null)
            document.getElementById("btn_ClickLowFare").click();
    
        var codes = subCode.split('-');
        var deptCode = codes[0];
        var desCode = codes[1];
        var flightType = codes[2];
        if(type==1)
            window.open( "Page/Flight/FlightSearch.aspx?DeptCode=" + deptCode + "&DesCode=" + desCode + "&FlightType=" + flightType,"blankWindows") 
        else
            window.open( "Page/Flight/FightRedirect.aspx?ToCity=" + desCode  + "&FromCity=" + deptCode,"blankSearchWindows") 
       
    }catch(e){}
}
var poload =1;
