var url = "/ajaxFunction/ajax.BlogPost.php";
function ajaxShowFirstForum(gID) {
	if($('G1').options[$('G1').selectedIndex].value == "none"){
		$('path').innerHTML=$('G1').options[$('G1').selectedIndex].text;
		$('selectPath').innerHTML="";
		$('fNo').value="";
	}else{
		$('path').innerHTML=$('G1').options[$('G1').selectedIndex].text+"<span id=\'P1\'></span>";
		var op = "showFirstForum";
		var qStr = "op="+op+"&gID="+$('G1').options[$('G1').selectedIndex].value;
		var ajax = new Ajax.Request (url,
		{
			method: 'post',
			parameters: qStr,
			onComplete: rajaxShowFirstForum
		}) ;
	}
}

function rajaxShowFirstForum(reqObj) {
	Text = reqObj.responseText.split("[nextResponse]");
	$('selectPath').innerHTML = '<img src="/images/blog_img/Blog_mana_a_orange_.gif" hspace="5">'+Text[0];
	$('fNo').value=Text[1];
}

function ajaxShowNextForum(fNo) {
    var op = "showNextForum";
    var qStr = "op="+op+"&fNo="+fNo;
    var ajax = new Ajax.Request (url,
    {
        method: 'post',
        parameters: qStr,
        onComplete: rajaxShowNextForum
    }) ;
}

function rajaxShowNextForum(reqObj) {
	Text = reqObj.responseText.split("[nextResponse]");
	if(Text[0] != 'none'){
		$('S'+Text[1]).innerHTML = '<img src="/images/blog_img/Blog_mana_a_orange_.gif" hspace="5">'+Text[0];
	}else{
		$('S'+Text[1]).innerHTML = "";
	}
}
function intToChinese(gInt){
  number = Array("○","一","二","三","四","五","六","七","八","九","十");
  return number[gInt];
}
function post(action){
	if(action == "preView")
		document.postForm.action += "?op=preView";
	if(action == "save_title")
		if(!newPageCheck(document.postForm))
			return;
	document.postForm.op.value = action;
	document.postForm.submit();
}
function newPageCheck(postObj){
	var error="";
	if(postObj.title.value==""){
		error+="請輸入[文章標題]";
	}

	if(postObj.Attribute.selectedIndex == 0){
		error+="\n請選擇[文章屬性]";
	}
	if(error){
		alert(error);
		return false;
	}else{
		return true;
	}
}

function ShowStar(num){
	for(var i=1;i<=num;i++){
		document.getElementById('star_'+i).src = "/images/forum/buyinfo_star_on.gif";
	}
	for(var i=5;i>num;i--){
		document.getElementById('star_'+i).src = "/images/forum/buyinfo_star.gif";
	}
	document.getElementById('ShopStar').value = num;
}
function SubmitShopInfo(num){
	var error 		=	"敗物資訊錯誤，錯誤如下：";
	var ShopName	=	document.getElementById('ShopName').value;
	var ShopMoney	=	document.getElementById('ShopMoney').value;
	var coin		=	document.getElementById('coin');
	var ShopBill	=	document.getElementById('ShopBill');
	var Date_Year	=	document.getElementById('Date_Year');
	var Date_Month	=	document.getElementById('Date_Month');
	var Date_Day	=	document.getElementById('Date_Day');
	var ShopInfo	=	document.getElementById('ShopInfo').value;
	var ShowAdv		=	document.getElementById('ShowAdv').checked;
	var ShopAge		=	document.getElementById('ShopAge').value;
	var ShopStore	=	document.getElementById('ShopStore').value;
	var ShopTell	=	document.getElementById('ShopTell').value;
	var ShopMemo	=	document.getElementById('ShopMemo').value;
	var ShopStar	=	parseInt(document.getElementById('ShopStar').value);
	var ShopApprise	=	document.getElementById('ShopApprise').value.replace(String.fromCharCode(13),"<br>");
	if(ShopName == "")
		error += "\n請輸入商品名稱";
	if(ShopMoney == "")
		error += "\n請輸入商品價格";
	if(ShopInfo == "")
		error += "\n請輸入內容描述";
	if(error == ""){
	var html 	= 	'<table id="ShopInfo" border="0" width="100%" cellspacing="1" style="border: 1 solid #C0C0C0">';
        html 	+=	'<tr>';
        html 	+=	'<td width="10%" bgcolor="#C5DAAD"><font size="2" color="#52642D">項目名稱</font></td>';
        html 	+=	'<td width="60%" bgcolor="#C5DAAD">'+ShopName+'</td>';
        html 	+=	'<td width="11%" bgcolor="#C5DAAD"><font size="2" color="#52642D">消費時間</font></td>';
        html 	+=	'<td width="21%" bgcolor="#C5DAAD">　</td>';
        html 	+=	'</tr>';
        html 	+=	'<tr>';
        html 	+=	'<td width="10%" bgcolor="#ECF3E4"><font size="2" color="#52642D">消費金額</font></td>';
        html 	+=	'<td width="60%" bgcolor="#ECF3E4">'+coin[coin.selectedIndex].value+ShopMoney+'</td>';
        html 	+=	'<td width="11%" bgcolor="#ECF3E4"><font size="2" color="#52642D">付款方式</font></td>';
        html 	+=	'<td width="21%" bgcolor="#ECF3E4">'+ShopBill[ShopBill.selectedIndex].value+'</td>';
        html 	+=	'</tr>';
        html 	+=	'<tr>';
        html 	+=	'<td width="10%" bgcolor="#C5DAAD"><font size="2" color="#52642D">內容描述</font></td>';
        html 	+=	'<td width="91%" colspan="3" bgcolor="#C5DAAD">'+ShopInfo+'</td>';
        html 	+=	'</tr>';
		if(ShowAdv){
			if(ShopStore != "" && ShopAge !=""){
			html 	+=	'<tr>';
				if(ShopStore != ""){
					html 	+=	'<td width="10%" bgcolor="#ECF3E4"><font size="2" color="#52642D">商家名稱</font></td>';
					html 	+=	'<td width="60%" bgcolor="#ECF3E4">'+ShopStore+'</td>';
				}
				if(ShopAge != ""){
					html 	+=	'<td width="11%" bgcolor="#ECF3E4"><font size="2" color="#52642D">所在區域</font></td>';
					html 	+=	'<td width="20%" bgcolor="#ECF3E4">'+ShopAge+'</td>';
				}
			html 	+=	'</tr>';
			}
			if(ShopTell != ""){
				html 	+=	'<tr>';
				html 	+=	'<td width="10%" bgcolor="#C5DAAD"><font size="2" color="#52642D">聯絡資訊</font></td>';
				html 	+=	'<td width="91%" colspan="3" bgcolor="#C5DAAD">'+ShopTell+'</td>';
				html 	+=	'</tr>';
			}
			if(ShopMemo != ""){
				html 	+=	'<tr>';
				html 	+=	'<td width="10%" bgcolor="#ECF3E4"><font size="2" color="#52642D">附註說明</font></td>';
				html 	+=	'<td width="91%" colspan="3" bgcolor="#ECF3E4">'+ShopMemo+'</td>';
				html 	+=	'</tr>';
			}
			if(ShopStar > 0){
				html 	+=	'<tr>';
				html 	+=	'<td width="10%" bgcolor="#C5DAAD"><font size="2" color="#52642D">整體評價</font></td>';
				html 	+=	'<td width="91%" colspan="3" bgcolor="#C5DAAD">';
				for(i=0;i<ShopStar;i++){
					html 	+=	'<img src="/images/forum/s2.gif" width="15">';	
				}
				html 	+=	'</td>';
				html 	+=	'</tr>';
			}
			if(ShopApprise != ""){
				html 	+=	'<tr>';
				html 	+=	'<td width="101%" colspan="4">';
				html 	+=	'<table border="0" width="100%" cellspacing="1" bgcolor="#D03F37">';
				html 	+=	'<tr>';
				html 	+=	'<td width="10%" bgcolor="#D03F37"><font size="2" color="#FFFFFF">我的評語</font></td>';
				html 	+=	'<td width="90%" bgcolor="#FFFFFF">'+ShopApprise+'</td>';
				html 	+=	'</tr>';
				html 	+=	'</table>';
				html 	+=	'</td>';
				html 	+=	'</tr>';	
			}
		}
		html 	+=	'</table>';
		if(frames[0].document.getElementById('ShopInfo')){
			frames[0].document.getElementById('ShopInfo').outerHTML=html;
		}else{
			frames[0].document.body.innerHTML=html + frames[0].document.body.innerHTML;
		}
	}else{
		alert(error);	
	}
}
function editPost(){
	var ReturnValue = showModalDialog('/dialogs/editPost.php', '', 'dialogHeight:250px; dialogWidth:366px; resizable:no; status:no'); 
	if(ReturnValue != null)
		document.getElementById('forum_post_title').innerHTML = "【"+ReturnValue.Attribute+"】"+ReturnValue.title.replace(/ $/,"");
}
function editPostPage(){
	var nowPage = document.getElementById('nowPage').innerHTML;
	var ReturnValue = showModalDialog('/dialogs/editPostPage.php?nowPage=' + nowPage , '', 'dialogHeight:250px; dialogWidth:366px; resizable:no; status:no'); 
	if(ReturnValue != null)
		document.getElementById('forum_post_page_title').innerHTML = ReturnValue.replace(/ $/,"");
}

function addPostPage(){
	if(document.postForm.pageNum.value >= 10){
		alert("分頁數已達十頁，無法再新增頁面！");
	}else{
		var page_title = prompt("請輸入新分頁的標題","");
		if(page_title == ""){
			alert("您未輸入分頁標題");	
		}else if(page_title != null){
			if(confirm("你確定要新增標題為["+page_title+"]的分頁？")){
				document.postForm.pageNum.value = parseInt(document.postForm.pageNum.value)+1;
				document.postForm.post_page_title.value = page_title;
				document.postForm.op.value = "addPostPage";
				document.postForm.submit();
			}else{
				alert("取消新增分頁");	
			}
		}
	}
}
function change_page(page_num){
	document.postForm.op.value = "change_page";
	document.postForm.nowPage.value = page_num;
	document.postForm.submit();
}
function pop_createTopicClass(){
	var ReturnValue = showModalDialog('/dialogs/BlogCreateClass.php', '', 'dialogHeight:480px; dialogWidth:640px; resizable:no; status:no'); 
	if(ReturnValue != null){
		optObj=document.createElement("option");
		optObj.value=ReturnValue.id;
		optObj.text=ReturnValue.name;
		$('blog_class').options[$('blog_class').length] = optObj;
	}
}
function ajaxInsertGoogleMap(str) {
	if (GBrowserIsCompatible()) {
		var geocoder = new GClientGeocoder();
		if (geocoder) {   
			 geocoder.getLatLng(   
			   str,   
			   function(point) {   
				 if (!point) {   
				   alert(str + " 無法定位，請重新輸入");   
				 } else {
					 insertGoogleMap(point,str);
				 }   
			   }   
			 );   
		 }
	}else{
		alert("您的瀏覽器不支援google map");
	}
    return false;
}