var Then = new Date();
Then.setTime(Then.getTime()+60*1000*60*24); //24小时

//写酒店
function WriteHotelCookie()
{
	var hotelStr="";
	if(idObj("raCityName").value!="")
	{
		hotelStr=hotelStr+"raCityName|"+idObj("raCityName").value+",";
		hotelStr=hotelStr+"raCityId|"+ ($("#raCityName").get(0)==null?"0101":  $("#raCityName").get(0).City.CityId)+",";
	}
	if(idObj("CheckInDate").value!=""||idObj("CheckInDate").value!="mm/dd/yyyy")
		hotelStr=hotelStr+"CheckInDate|"+idObj("CheckInDate").value+",";
	if(idObj("CheckOutDate").value!=""||idObj("CheckOutDate").value!="mm/dd/yyyy")
		hotelStr=hotelStr+"CheckOutDate|"+idObj("CheckOutDate").value;
	if(idObj("priceType")!=null && idObj("priceType").value!="")
		hotelStr=hotelStr+",priceType|"+idObj("priceType").value;
	if(idObj("price_usd")!=null && idObj("price_usd").value!="")
		hotelStr=hotelStr+",price_usd|"+idObj("price_usd").value;
	if(idObj("price_rmb")!=null && idObj("price_rmb").value!="")
		hotelStr=hotelStr+",price_rmb|"+idObj("price_rmb").value;
	if(idObj("Star")!=null && idObj("Star").value!="")
		hotelStr=hotelStr+",Star|"+idObj("Star").value;
	if(idObj("RoomNum")!=null && idObj("RoomNum").value!="")
		hotelStr=hotelStr+",RoomNum|"+idObj("RoomNum").value;
	if(idObj("PersonNum")!=null && idObj("PersonNum").value!="")
		hotelStr=hotelStr+",PersonNum|"+idObj("PersonNum").value;

	if(hotelStr!="")
		document.cookie = "elong_hotel_cookie="+escape(hotelStr)+";expires=" + Then.toGMTString() + ";path="+ "/" + ";domain="+"elong.net";
	//alert(document.cookie);
}

//读酒店
function ReadHotelCookie()
{
	if (typeof(ArriveCityName) != "undefined")
	  idObj("raCityName").value= ArriveCityName.length > 0 ? ArriveCityName : "";
	  
	if(WM_readCookie("elong_hotel_cookie")!="")//如果cookie不为空,则开始读.
	{
		var hotelCookieStr=unescape(WM_readCookie("elong_hotel_cookie"));//读取cookie字符串;
		var hotelCookieAry=hotelCookieStr.split(",");//拆分cookie字符串
		for(var i=0; i<hotelCookieAry.length; i++)//分为数组进行处理
		{
			var index=hotelCookieAry[i].indexOf("|");//确定拆分位置
			var objStr=hotelCookieAry[i].slice(0,index);//取元素名
			var objStrValue=hotelCookieAry[i].slice(index+1,hotelCookieAry[i].length);//取元素值
			//--edit by bin.wu 2009-01-13 去掉获取cookie值
			switch ( objStr.toLowerCase() )
			{
				case "raCityName".toLowerCase():
					idObj("raCityName").value=objStrValue;
					break;
				case "raCityId".toLowerCase():
				{
					 var city = {
						"CityId": objStrValue,
						"CityNameCn": idObj("raCityName").value ,
						"CityNameEn": idObj("raCityName").value
					 };
                      $("#raCityName")[0]["City"] = city;
 
				}
					break;
					
				//case "CheckInDate".toLowerCase():
				//	idObj("CheckInDate").value=objStrValue;
				//	break;
				//case "CheckOutDate".toLowerCase():
				//	idObj("CheckOutDate").value=objStrValue;
				//	break;
				//case "priceType".toLowerCase():
				//	if (idObj("priceType") != null)
				//		option_select( idObj("priceType"), objStrValue);
				//	break;
				//case "price_usd":
				//	if (idObj("price_usd") != null)
				//		option_select( idObj("price_usd"), objStrValue);
				//	break;
				//case "price_rmb":
				//	if (idObj("price_rmb") != null)
				//		option_select( idObj("price_rmb"), objStrValue);
				//	break;
				//case "star":
				//	if (idObj("Star") != null)
				//		option_select( idObj("Star"), objStrValue);
				//	break;
				//case "RoomNum".toLowerCase():
				//	if ( idObj("RoomNum") != null ) {
				//		option_select( idObj("RoomNum"), objStrValue);
				//		if(idObj("PersonNum") != null && idObj("RoomNum").value != '')
				//		{
				//			ChangeGuests(idObj("RoomNum").value);
				//		}
				//	}
				//	break;
				//case "PersonNum".toLowerCase():
				//	if ( idObj("PersonNum") != null ) {
				//		option_select( idObj("PersonNum"), objStrValue);
				//	}
			}
			
		}
	}
	else
	{ idObj("CheckInDate").value="mm/dd/yyyy";
	  idObj("CheckOutDate").value="mm/dd/yyyy";
	  if (idObj("priceType")!=null) idObj("priceType").selectedIndex = 0;
	  if (idObj("price_usd")!=null) idObj("price_usd").selectedIndex = 0;
	  if (idObj("price_rmb")!=null) idObj("price_rmb").selectedIndex = 0;
	  if (idObj("Star")!=null) idObj("Star").selectedIndex = 0;
	  if (idObj("RoomNum")!=null) idObj("RoomNum").selectedIndex = 0;
	  if (idObj("RoomNum")!=null && idObj("PersonNum")!=null) ChangeGuests(idObj("RoomNum").value);
	}
}

//写机票;
function WriteAirCookie()
{ 
	var airStr="";

  if(idObj("DEPART_CITY").value!="")
   airStr=airStr+"DEPART_CITY|"+idObj("DEPART_CITY").value+",";
  if(idObj("DEPART_CITY2")!=null && idObj("DEPART_CITY2").value!="")
   airStr=airStr+"DEPART_CITY2|"+idObj("DEPART_CITY2").value+",";
  if(idObj("DEST_CITY").value!="")
   airStr=airStr+"DEST_CITY|"+idObj("DEST_CITY").value+",";
  if(idObj("FLY_DATE").value!=""||idObj("FLY_DATE").value!="mm/dd/yyyy")
    airStr=airStr+"FLY_DATE|"+idObj("FLY_DATE").value+",";
  if(idObj("RETURN_DATE").value!=""||idObj("RETURN_DATE").value!="mm/dd/yyyy")
    airStr=airStr+"RETURN_DATE|"+idObj("RETURN_DATE").value+",";
  if(idObj("DEST_CITY2")!=null && idObj("DEST_CITY2").value!="")
    airStr=airStr+"DEST_CITY2|"+idObj("DEST_CITY2").value+",";
  if(idObj("FLY_DATE2")!=null && (idObj("FLY_DATE2").value!=""||idObj("FLY_DATE2").value!="mm/dd/yyyy") )
    airStr=airStr+"FLY_DATE2|"+idObj("FLY_DATE2").value+",";
  if(idObj("FCY").selectedIndex!=0)
   airStr=airStr+"FCY|"+idObj("FCY").value;
    
  if(airStr!="")
   document.cookie = "elong_air_cookie="+escape(airStr)+";expires=" + Then.toGMTString() + ";path="+ "/" + ";domain="+"elong.net";	
  //alert(document.cookie);	
}

//读机票
function ReadAirCookie()
{
	option_select(idObj("DEPART_CITY"), 'BJS');
	option_select(idObj("DEST_CITY"), 'SHA');
	if (idObj("DEST_CITY2") != null)
	{
		option_select(idObj("DEST_CITY2"), 'CAN');
	}
	
	if (typeof(ArriveCity3Code) != "undefined" && LeaveCity3Code!= "undefined" )
	{
		if (ArriveCity3Code.length > 0)
		{
			option_select(idObj("DEST_CITY"), ArriveCity3Code)
		}
		
		if (LeaveCity3Code.length > 0 && LeaveCity3Code != idObj("DEST_CITY").value)
		{
			option_select(idObj("DEPART_CITY"), LeaveCity3Code);
		}
		else if (idObj("DEST_CITY").value == 'BJS' )
		{
			option_select(idObj("DEPART_CITY"), 'SHA');
		}
		
		if (idObj("DEST_CITY2").length>0) idObj("DEST_CITY2").selectedIndex = 0;
		/*if (idObj("DEPART_CITY").value != 'BJS' && idObj("DEST_CITY").value != 'BJS')
		{
			option_select(idObj("DEST_CITY2"), 'BJS');
		}
		else if (idObj("DEPART_CITY").value != 'SHA' && idObj("DEST_CITY").value != 'SHA')
		{
			option_select(idObj("DEST_CITY2"), 'SHA');
		}*/
		select_sendticket(idObj("DEPART_CITY").selectedIndex);
	}
	if(WM_readCookie("com.eLong.BusinessRules.Flights.FlightCookie")!="")//如果cookie不为空,则开始读.
	{
		/*var airCookieStr=unescape(WM_readCookie("elong_air_cookie"));//读取cookie字符串;
		var airCookieAry=airCookieStr.split(",");//拆分cookie字符串
	
		for(var i=0; i<airCookieAry.length; i++)//分为数组进行处理
		{
			var index=airCookieAry[i].indexOf("|");//确定拆分位置
			var objStr=airCookieAry[i].slice(0,index);//取元素名
			var objStrValue=airCookieAry[i].slice(index+1,airCookieAry[i].length);//取元素值
			
			if ( idObj(objStr)!= null )
			{
				if ( objStr=="DEPART_CITY" || objStr=="DEST_CITY" || objStr=="DEPART_CITY2" || objStr=="DEST_CITY2") continue;
				
				if( idObj(objStr).type=="text" )
					idObj(objStr).value = objStrValue;
				else
					option_select( idObj(objStr), objStrValue );
			}
		}*/
		
		//idObj("FLY_DATE").value=getFlightsCookie("DepartDate");
		//idObj("FLY_DATE2").value=getFlightsCookie("DepartDate2");
		//idObj("RETURN_DATE").value=getFlightsCookie("ReturnDate");
		/*option_select(idObj("DEPART_CITY"),getFlightsCookie("DepartCity"));
		option_select(idObj("DEPART_CITY2"),getFlightsCookie("DepartCity2"));
		option_select(idObj("DEST_CITY"),getFlightsCookie("DestCity"));
		option_select(idObj("DEST_CITY2"),getFlightsCookie("DestCity2"));
		option_select(idObj("FCY"), getFlightsCookie("Fcy"));
		option_select(idObj("DELEVER_CITY"), getFlightsCookie("SendTicket"));
		*/
	}
	else
	{
		idObj("FLY_DATE").value="mm/dd/yyyy";
		if (idObj("FLY_DATE2") != null)
		{
			idObj("FLY_DATE2").value="mm/dd/yyyy";
		}
		idObj("RETURN_DATE").value="mm/dd/yyyy";
	}
}

function GetAirCookie( key )
{
	if(WM_readCookie("elong_air_cookie")=="")
	{
		return "";
	}
	
	var airCookieStr=unescape(WM_readCookie("elong_air_cookie"));
	var airCookieAry=airCookieStr.split(",");
	
	for(var i=0; i<airCookieAry.length; i++)//分为数组进行处理
	{
		var index=airCookieAry[i].indexOf("|");//确定拆分位置
		var objStr=airCookieAry[i].slice(0,index);//取元素名
		var objStrValue=airCookieAry[i].slice(index+1,airCookieAry[i].length);//取元素值
		
		if (objStr.toLowerCase() == key.toLowerCase())
		{
			return objStrValue;
		}
	}
	
	return "";			
}
