var searchflag = 0;

function searchRecipeNew()
{
	if (document.qSearch.type.selectedIndex == 0&&document.qSearch.ingredient.selectedIndex == 0&&document.qSearch.cookery.selectedIndex == 0) {
		alert("請選擇至少一項!");
	} else{
	document.forms['qSearch'].submit()
 	}
 }

function searchRestNew()
{
	if (document.qSearchRest.location.selectedIndex == 0&&document.qSearchRest.cuisine.selectedIndex == 0&&document.qSearchRest.amenities.selectedIndex == 0) {
		alert("請選擇至少一項!");
	} else{
	document.forms['qSearchRest'].submit()
 	}
 }
 
function searchfocus() {
   if (searchflag == 0) {
      searchflag = 1;
      document.Frmsitesearch.q.value = "";
   }
}

function searchblur() {
   if (document.Frmsitesearch.q.value == "") {
      searchflag = 0;
      document.Frmsitesearch.q.value = "請輸入關鍵字";
   }
}

var menu = new Menu("esdlife_news_menu", "esdlife_news_menu");
menu.addItem("生活易盛事", "http://www.esdlife.com/esd_events/chi/default.asp", "menu_item_over", "menu_item_out");
menu.addItem("生活易新聞中心", "http://www.esdlife.com/about_us/chi/press/default.asp", "menu_item_over", "menu_item_out");
menu.addItem("獎賞結果告示板", "http://www.esdlife.com/esd_announce/chi/default.asp", "menu_item_over", "menu_item_out");

/* This function returns the upperleft x,y coordinates of the specified image */
function imgXY(imgID) {
	var XY = new Object();
	var imgObj = document.images[imgID];
	if (document.layers) {
		XY.x = eval(imgObj).x;
		XY.y = eval(imgObj).y;
	} else {
		var x,y, tempEl;
		x = eval(imgObj).offsetLeft;
		y = eval(imgObj).offsetTop;
		tempEl = eval(imgObj).offsetParent;
		while (tempEl != null) {
			x += tempEl.offsetLeft;
			y += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		XY.x = x;
		XY.y = y;
	}
	return XY;
}

function showESDNewsMenu() {
	MM_swapImage('btn09','','http://www.esdlife.com/common_img/chi/btn09_on.gif',1);
	var imgPos = imgXY("btn09");
	menu.getMenu().style.left = imgPos.x;
	menu.getMenu().style.top = imgPos.y + 25;
	menu.getMenu().style.display = "";
}

function hideESDNewsMenu() {
	setTimeout("realHideESDNewsMenu()", 200);
}

function realHideESDNewsMenu() {
	if (menu.getMouseOverStatus() == false) {
		MM_swapImgRestore();
		menu.getMenu().style.display = "none";
	}
}

function mainBodyOverBtn(arrayBtn, strOverBtnId) {
	var objImg, objDiv;
	for (var i=0; i<arrayBtn.length; i++) {
		objImg = document.getElementById(arrayBtn[i][0]);
		objDiv = document.getElementById(arrayBtn[i][3]);
		if (strOverBtnId == arrayBtn[i][0]) {
			objImg.src = arrayBtn[i][2];
			objDiv.style.display = "";
			arrayBtn[i][4] = 1;
		} else {
			objImg.src = arrayBtn[i][1];
			objDiv.style.display = "none";
			arrayBtn[i][4] = 0;
		}
	}
}

function displayAdvDisclaimer(strStatus) {
	var imgPos = imgXY("adv_disclaimer_img");
	var objDiv = document.getElementById("adv_disclaimer");
//	objDiv.style.left = imgPos.x;
//	objDiv.style.top = imgPos.y + 20;
	objDiv.style.display = strStatus;
}

var boolPauseESDNewsRotate = false;

function mainBodyAutoRotate(strArrayBtnName, intSpeed) {
	eval("var arrayTemp = " + strArrayBtnName);
	var intCurrentIndex;
	for (var i=0; i<arrayTemp.length; i++) {
		if (arrayTemp[i][4] == 1) {
			intCurrentIndex = i;
			break;
		}
	}
	intCurrentIndex = (intCurrentIndex + 1) % arrayTemp.length;
	if (strArrayBtnName == "arrayESDNewsBtn") {
		if (boolPauseESDNewsRotate == false) {
			mainBodyOverBtn(arrayTemp, arrayTemp[intCurrentIndex][0]);
		}
	} else {
		mainBodyOverBtn(arrayTemp, arrayTemp[intCurrentIndex][0]);
	}
	setTimeout("mainBodyAutoRotate('" + strArrayBtnName + "', " + intSpeed + ")", intSpeed);
}

function esd_swapDiv() {
	var obj, args=esd_swapDiv.arguments;
	if (args.length > 1) {
		for (i=0; i<args.length; i++) {
			obj = MM_findObj(args[i]);
			if (obj != null) {
				if (i == 0) {
					obj.style.display = "";
				} else {
					obj.style.display = "none";
				}
			}
		}
	}
}

function searchrecipe()
{
	if (document.searchrecipe.cat1.value==0&&document.searchrecipe.cat2.value==0&&document.searchrecipe.cat3.value==0&&document.searchrecipe.q.value=="") {
		alert("請選擇至少一項");	
	} else
	{
	document.searchrecipe.submit();
	}
}
function searchrestaurant()
{
	if (document.searchrestaurant.cat1.value==0&&document.searchrestaurant.cat2.value==0&&document.searchrestaurant.cat3.value==0&&document.searchrestaurant.cat4.value==0&&document.searchrestaurant.q.value=="") {
		alert("請選擇至少一項");	
	} else
	{
	document.searchrestaurant.submit();
	}
}
function addtomyfavourite()
{	var urllink=document.location.href.toString();
	var pagesubject=document.title.toString();	
	var pageurl=urllink.substring(urllink.indexOf('/',7), urllink.length );	
	top.location.href='/mydining/chi/addtofavourite.php?urllink=' + encodeURIComponent(pageurl) + '&pagesubject=' + encodeURIComponent(pagesubject);
}

function addtomyfavouritewithfrom(fromlink)
{	var urllink=document.location.href.toString();
	var pagesubject=document.title.toString();	
	var pageurl=urllink.substring(urllink.indexOf('/',7), urllink.length );	
	top.location.href='/mydining/chi/addtofavourite.php?fromlink=' + encodeURIComponent(pageurl) + '&urllink=' + encodeURIComponent(fromlink) + '&pagesubject=' + encodeURIComponent(pagesubject);
}

function clearCookie() { 
var expDate = new Date;
expDate.setTime(expDate.getTime()-60000); 
document.cookie = "alertmsg=;path=/;expires="+expDate.toGMTString();
} 

function fnIndexPopAlbum(strAlbumId, strTypeId, strCatId) {
	var albumpop = window.open('/showcase/chi/popup.php?aid=' + strAlbumId + '&cid=' + strCatId  + '&tid=' + strTypeId, 'popalbum', 'width=840,height=760,status=1,scrollbars=0');
	albumpop.focus();
}
