var stl_CSearch = Class.create();
stl_CSearch.prototype = {
	gArrCate: new Array(),
	gArrStrCate : "",
	gAreaID : 0,
	gArrGenre: "",
	gTitleID: 0,
	gResName: "",
	gFreeWord: "",
	gNumCase:0,
	gPage: 1,
	gString: "",
	gFlagResname: 0,
	gFlagFreeword : 0,
	gCateChosen: false,	
	initialize: function(){
    },
	stl_SetCateValue:function(current)
	{
		var frmCate = document.forms['form_cate'];
		for (var i=0; i<frmCate.elements.length; i++)
		{
			var e = frmCate.elements[i];
			if (e.type == 'checkbox' && e.name == 'cate_list[]')
			{
				e.checked = false;
			}
		}
		current.checked = true;
	},
	stl_GetCateValue:function() 
	{
		var frmCate = document.forms['form_cate'];
		this.gArrStrCate = "";
		for (var i=0; i<frmCate.elements.length; i++)
		{
			var e = frmCate.elements[i];
			if ( e.type == 'checkbox' && e.name == 'cate_list[]')
			{
				if (e.checked == 1)
				{
					this.gArrCate[i] = 1;
					this.gArrStrCate += e.value + ", ";
					this.gCateChosen = true;
				}
				else
				{
					this.gArrCate[i] = 0;
				}
			}
		}
		
		this.gArrStrCate = this.gArrStrCate.substr( 0, (this.gArrStrCate.length)-2 );
	},
	stl_GetGenreValue:function() 
	{
		var frmGenre = document.forms['form_genre'];		
		this.gArrGenre = "";
		for (var i=0; i<frmGenre.elements.length; i++)
		{
			var e = frmGenre.elements[i];
			if ( e.type == 'checkbox' && e.name == 'genre_list[]')
			{
				if (e.checked == true)
				{
					this.gArrGenre += e.value + ",";
				}
			}
		}
		this.gArrGenre = this.gArrGenre.substr(0,(this.gArrGenre.length)-1);		//10:20 2008/06/28		
	},
    stl_Search:function(numCase) 
	{
		var url = "htm/user/stl_SearchRestaurant.htm";		
		this.gArrCate.clear();
		this.gAreaID = 0;
		this.gResName = "";
		this.gFreeWord = "";
		this.gString = "";
		this.gTitleID = 0;
		this.gNumCase = numCase;
		this.gFlagResname = 0;
		this.gFlagFreeword = 0;
        switch(this.gNumCase) {
            case 1:
				this.stl_GetCateValue();
				this.stl_GetGenreValue();
				var areaID = $('avt_area').value;
				if (areaID == "" && this.gCateChosen == false && this.gArrGenre.length == 0)
				{
					$('avt_Search_Validate1').show();
					return;
				}
				else
				{
					$('avt_Search_Validate1').hide();
				}
				this.gCateChosen = false;
				this.gAreaID = areaID;
				var arrCate = this.gArrCate;				
				arrCate = arrCate.toJSON();
				var arrStrCate = this.gArrStrCate;
				var arrGenre = this.gArrGenre;
				$('arrCate').value = arrCate;
				$('arrStrCate').value = arrStrCate;
				$('areaID').value = areaID;				
				$('arrGenre').value = arrGenre;
				$('pst1').value = 1;				
				document.Search1.submit();				
            break;
            case 2:
				var titleID = $('avt_title').value;				
				this.gTitleID = titleID;
				if (titleID != "")
				{
					var tmp = "title_" + titleID;
					this.gString = $(tmp).innerHTML;
				}				
				var titleString = this.gString;				
				if ( titleID === "" || titleID === oCommon.stl_AlertMessage("MSG00002") )					
					$('avt_Search_Validate2').show();
				else
				{
					$('avt_Search_Validate2').hide();
					this.gTitleID = titleID;
					$('titleString').value = titleString;
					$('titleID').value = titleID;
					$('pst2').value = 2;					
					document.Search2.submit();					
				}
            break;
            case 3:
				var resName = $('txtResName').value.strip();
				if (resName === oCommon.stl_AlertMessage("MSG00003") && this.gFlagResname == 0)
				{					
					$('avt_Search_Validate3').show();
					this.gFlagResname = 1;
					return;
				}
				if (resName === "")					
					$('avt_Search_Validate3').show();
				else
				{
					$('avt_Search_Validate3').hide();					
					this.gResName = resName;					
					$('objName').value = resName;
					$('pst3').value = 3;					
					document.Search3.submit();					
				}
			break;
			case 4:
				var freeWord = $('txtFreeText').value.strip();
				if (freeWord === oCommon.stl_AlertMessage("MSG00004") && this.gFlagFreeword == 0)
				{					
					$('avt_Search_Validate4').show();
					this.gFlagFreeword = 1;
					return;
				}
				if (freeWord === "")					
					$('avt_Search_Validate4').show();
				else
				{
					$('avt_Search_Validate4').hide();					
					this.gFreeWord = freeWord;
					$('objFreeWord').value = freeWord;
					$('pst4').value = 4;					
					document.Search4.submit();					
				}
			break;
        }
    },
	stl_ViewDetail:function(id, page)
	{
		$('id').value = id;
		document.SearchDetail.Page.value = page;		
		document.location = "stl_ViewSearchDetail.html?id=" + id;	
	},
	stl_Empty:function(id)
	{
		$(id).value = "";
		$(id).setStyle({
			color: '#333333'
		});
	},
    stl_ClearInput:function(thisObj)
	{
		var str = thisObj.value.strip();
		if (str === oCommon.stl_AlertMessage("MSG00003") || str === oCommon.stl_AlertMessage("MSG00004"))
		{
			thisObj.value = "";
		}
		else
		{
			thisObj.value = str;
		}
		thisObj.style.color = "black";		
    },
	stl_PagingResultOpt1:function(Page)
	{
		this.gPage = Page;
		$('Page').value = Page;
		document.SearchResult.submit();		
	},
	stl_ResultOpt1:function(Page)
	{
		if (Page==null)
            Page = 1;
	},
	stl_PagingResultOpt2:function(Page)
	{
		this.gPage = Page;
		this.stl_ResultOpt2(Page);
	},
	stl_ResultOpt2:function(Page)
	{
		if (Page==null)
            Page = 1;		
		document.SearchResult.submit();	
		var titleString = new Array();
		titleString.push(this.gString);
		titleString = titleString.toJSON();
		var url = "stl_SearchRestaurant.html";
		new Ajax.Request(
			url,
			{
				method: 'post',
				parameters: {titleID: this.gTitleID, titleString:titleString, Page:Page, pst:2, sid: Math.random()},
				onSuccess:function(trans)
				{
					var rs = trans.responseText;
					$('avt_Search_Option').innerHTML = rs;
					oMain.stl_LoadTop2();
					$('pageTitle').innerHTML = oCommon.stl_AlertMessage('MSG00008');
				}
			}
		);
	},
	stl_PagingResultOpt3:function(Page)
	{
		this.gPage = Page;
		this.stl_ResultOpt3(Page);
	},
	stl_ResultOpt3:function(Page)
	{
		if (Page==null)
            Page = 1;
		var objName = this.gResName;
		objName = objName.toJSON();
		var url = "stl_SearchRestaurant.html";
		new Ajax.Request(
			url,
			{
				method: 'post',
				parameters: {objName:objName, Page:Page, pst:3, sid: Math.random()},
				onSuccess:function(trans)
				{
					var rs = trans.responseText;
					$('avt_Search_Option').innerHTML = rs;
					oMain.stl_LoadTop2();
					$('pageTitle').innerHTML = oCommon.stl_AlertMessage('MSG00008');
				}
			}
		);
	},
	stl_PagingResultOpt4:function(Page)
	{
		this.gPage = Page;
		this.stl_ResultOpt4(Page);
	},
	stl_ResultOpt4:function(Page)
	{
		if (Page==null)
            Page = 1;
		var objFreeWord = this.gFreeWord;
		objFreeWord = objFreeWord.toJSON();
		var url = "stl_SearchRestaurant.html";
		new Ajax.Request(
			url,
			{
				method: 'post',
				parameters: {objFreeWord:objFreeWord, Page:Page, pst:4, sid: Math.random()},
				onSuccess:function(trans)
				{
					var rs = trans.responseText;
					$('avt_Search_Option').innerHTML = rs;
					oMain.stl_LoadTop2();
					$('pageTitle').innerHTML = oCommon.stl_AlertMessage('MSG00008');
				}
			}
		);
	},
	stl_SearchBack:function()
	{	
		document.SearchDetail.submit();
	},
	stl_SumitFrame:function(numCase)
	{
		this.gNumCase = numCase;
		$('loadPage').location = "htm/user/stl_Back.htm";
	}
}
