
/**
	 * 填充芒果推荐
	 */
function fillCommendTable() {
	var cityCode = getCookie("ticketCityId") == null || getCookie("ticketCityId").length == 0 ? "PEK" : getCookie("ticketCityId");
	var tempDisplayCitys = new Array(); // 显示的数据
	var tempDisplayCitys2 = new Array();
	//var ticketTurn = getCookie("ticketTurn") == null || getCookie("ticketTurn").length == 0 ? "first" : getCookie("ticketTurn");
	for (var i = 0, j = 0; i < airplaneCommendArray.length; i++) {
		if (airplaneCommendArray[i][0] == cityCode) {
			tempDisplayCitys[j] = new Array(airplaneCommendArray[i][0], airplaneCommendArray[i][1], airplaneCommendArray[i][2], airplaneCommendArray[i][3], airplaneCommendArray[i][4], airplaneCommendArray[i][10]);
			j++;
		}
	}
	
	///*
	var pages = 0;
	var page = getCookie("ticketPage") == null || getCookie("ticketPage").length == 0 ? "1" : getCookie("ticketPage");
	if (tempDisplayCitys.length / 4 == 0) {
		pages = 1;
	} else {
		if (tempDisplayCitys.length % 4 == 0) {
			pages = tempDisplayCitys.length / 4;
		} else {
			pages = tempDisplayCitys.length / 4 + 1;
		}
	}
	if (tempDisplayCitys.length > 0) {
		if (parseInt(page) <= pages) {
			if (parseInt(page) * 4 < tempDisplayCitys.length) {
				for (var i = (parseInt(page) - 1) * 4, j = 0; i < parseInt(page) * 4; i++) {
					tempDisplayCitys2[j] = tempDisplayCitys[i];
					j++;
				}
			} else {
				for (var i = (parseInt(page) - 1) * 4, j = 0; i < tempDisplayCitys.length; i++) {
					tempDisplayCitys2[j] = tempDisplayCitys[i];
					j++;
				}
			}
			setCookie("ticketPage", (parseInt(page) + 1));
		} else {
			if (tempDisplayCitys.length < 4) {
				for (var i = 0; i < tempDisplayCitys.length; i++) {
					tempDisplayCitys2[i] = tempDisplayCitys[i];
					setCookie("ticketPage", "1");
				}
			} else {
				for (var i = 0; i < 4; i++) {
					tempDisplayCitys2[i] = tempDisplayCitys[i];
					setCookie("ticketPage", "2");
				}
			}
		}
	}
	removeRows("comTBody");
	addCommendRows("comTBody", tempDisplayCitys2);
	//beginrefresh();
}
/**
 * 删除行 
 * add by Chenjiajie 2008-9-19
 */
function removeRows(tbodyId) {
	var tbodyObj = document.getElementById(tbodyId);
	tbodyObj.innerHTML = "";
}
/**
	 * 增加行 芒果推荐
	 */
function addCommendRows(tbodyId, displayCitys) {
	var tbodyObj = document.getElementById(tbodyId);
	var inner = "<table width=266 border=0 align=center cellpadding=0 cellspacing=0 >";
	for (var i = 0; i < displayCitys.length; i++) {
		var content1 = displayCitys[i][3];
		var content2 = displayCitys[i][4];
		var content3 = displayCitys[i][5];
			// tr开始bgcolor="#FFFFFF"
		if (i % 2 == 0) {
			inner += "<tr bgcolor='#FFFFFF' height='1%'>";
		} else {
			inner += "<tr bgcolor='#fcf8e4' height='1%'>";
		}
		
			// 添加城市中文名
		inner += "<td height='0' align='center' width='107' valign='center' style='line-height:14px'>";
		inner += "<a href='javascript:void(0)' onclick=onClickEventHandler('" + displayCitys[i][0] + "','" + displayCitys[i][1] + "')>";
		inner += displayCitys[i][2].split(",")[0];
		inner += " <img src='images/2008pic/arrow_f.gif' width='5' height='5' border='0' alt='' align='absmiddle' /> ";
		if(displayCitys[i][1]=='JZH'){
		inner += "九寨沟";
		}else{
		inner += displayCitys[i][2].split(",")[1];
		}
		inner += "</a>";
		inner += "</td>";
	
			// 添加价格
		inner += "<td  height='0'  align='center' width='51'  valign='top' style='line-height:14px'>";
		if (content1.split(",")[1].length != 0) {
			inner += "<a href='/TWEB/search.action?LineType=0&BeginCity=" + displayCitys[i][0] + "&EndCity=" + displayCitys[i][1] + "&BeginDate=" + content1.split(",")[1] + "&BackDate=yyyy-mm-dd' target='_blank' remote=yes><font color='#ff6633'>￥";
		} else {
			inner += "<a href='/TWEB/search.action?LineType=0&BeginCity=" + displayCitys[i][0] + "&EndCity=" + displayCitys[i][1] + "&BeginDate=" + todayDate + "&BackDate=yyyy-mm-dd' target='_blank' remote=yes><font color='#ff6633'>￥";
		}
		inner += content1.split(",")[0];
		inner += "</font></a><br>";
		if (content1.split(",")[1].length != 0) {
			inner += content1.split(",")[1].split("-")[1] + "." + content1.split(",")[1].split("-")[2];
		} else {
			inner += todayDate.split("-")[1] + "." + todayDate.split("-")[2];
		}
		inner += "</td>";
		inner += "<td  height='0'  align='center' width='44'  valign='top' style='line-height:14px'>";
		if (content2.split(",")[1].length != 0) {
			inner += "<a href='/TWEB/search.action?LineType=0&BeginCity=" + displayCitys[i][0] + "&EndCity=" + displayCitys[i][1] + "&BeginDate=" + content2.split(",")[1] + "&BackDate=yyyy-mm-dd' target='_blank' remote=yes><font color='#ff6633'>￥";
		} else {
			inner += "<a href='/TWEB/search.action?LineType=0&BeginCity=" + displayCitys[i][0] + "&EndCity=" + displayCitys[i][1] + "&BeginDate=" + tomorrowDate + "&BackDate=yyyy-mm-dd' target='_blank' remote=yes><font color='#ff6633'>￥";
		}
		inner += content2.split(",")[0];
		inner += "</font></a><br>";
		if (content2.split(",")[1].length != 0) {
			inner += content2.split(",")[1].split("-")[1] + "." + content2.split(",")[1].split("-")[2];
		} else {
			inner += tomorrowDate.split("-")[1] + "." + tomorrowDate.split("-")[2];
		}
		inner += "</td>";
		var unitStr = parseCurrency(displayCitys[i][4]);
		var price = unitStr + displayCitys[i][5].split(".")[0] + " ";
		inner += " <td  height='0'  align='center' width='64'  valign='top' style='line-height:14px'>";
		if (content3.split(",")[1].length != 0) {
			inner += "<a href='/TWEB/search.action?LineType=0&BeginCity=" + displayCitys[i][0] + "&EndCity=" + displayCitys[i][1] + "&BeginDate=" + content3.split(",")[1] + "&BackDate=yyyy-mm-dd' target='_blank' remote=yes><font color='#ff6633'>￥";
			inner += content3.split(",")[0];
			inner += "</font></a><br>";
		} else {
			inner += "<font color='#ff6633'>￥</font><br>";
		}
		if (content3.split(",")[1].length != 0) {
			inner += content3.split(",")[1].split("-")[1] + "." + content3.split(",")[1].split("-")[2];
		} else {
			inner += "&nbsp;";
		}
		inner += "</td>";
		inner += "</tr>";
	}
	inner += "</table>";
	tbodyObj.innerHTML = inner;
}	




	// 取得cookie的值
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}   
 
// 取得cookie  
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) {
			break;
		}
	}
	return null;
} 
 
 // 赋值给cookie
function setCookie(name, value) {
	document.cookie = name + "=" + value + "; path=/";
	var exp = new Date();
	exp.setTime(exp.getTime() + 3600000000);
	//document.cookie = name + "=" + value + "; expires=" + exp.toGMTString() + ";domain=.mangocity.com";
}
/**
 * 解析币种
 * add by Chenjiajie 2008-9-19
 */
function parseCurrency(currency) {
	var unitStr = "\uffe5";
	switch (currency) {
	  case "USD":
		unitStr = "USD$";
		break;
	  case "HKD":
		unitStr = "HK$";
		break;
	  case "EUR":
		unitStr = "EUR\u20ac";
		break;
	  case "GBP":
		unitStr = "GBP$";
		break;
	  case "JPY":
		unitStr = "JPY\uffe5";
		break;
	  case "DEM":
		unitStr = "DM";
		break;
	  case "MOP":
		unitStr = "MOP";
		break;
	  default:
		unitStr = "\uffe5";
		break;
	}
	return unitStr;
}
var parselimit = 3;
function beginrefresh() {
	if (parselimit == 1) {
		var cityCode = getCookie("ticketCityId") == null || getCookie("ticketCityId").length == 0 ? "PEK" : getCookie("ticketCityId");
		parselimit = 3;
		fillCommendTable(cityCode);
	} else {
		parselimit -= 1;
		setTimeout("beginrefresh()", 1000);
	}
}

var todayDate = getToDay(1);
var tomorrowDate = getNextDay(1,60);

function change_iframe_tic(obj, cityId) {
	setCookie("ticketPage", "1");
	setCookie("ticketCityId", cityId);
	var left = obj.parentNode.parentNode.getElementsByTagName("a");
	for (i = 0; i < left.length; i++) {
		if (left[i] == obj) {
			left[i].className = "current";
		} else {
			left[i].className = "";
		}
	}
	fillCommendTable(cityId);
}


