var houseMessageRplyFlag=false;
function loadPic(hid){
	makeRequest("include/house_pic.php?hid="+hid,"housePic","","");
}
//屋主回覆
function HouseMessageReply(id){
		mid=id;
		if(!houseMessageRplyFlag){
			houseMessageRplyFlag=true;
			tmpobj = document.createElement('div');
			tmpobj.id='ajaxReplyForm';
			tmpobj.style.position='absolute';
			tmpobj.style.top=(document.body.scrollTop+(document.body.clientHeight/2)-100)+"px";
			tmpobj.style.left=((document.body.clientWidth/2)-250)+"px";
			tmpobj.style.zIndex=103;
			document.body.appendChild(tmpobj);
		}
		afterinclude=false;
		makeRequest("house_message_reply_form.php?mid="+mid,"ajaxReplyForm","HouseMessageReplyCallback","");
}

function HouseMessageReplyCallback(){
	showMask();
	document.getElementById("loginmask").onclick=function(){
		Effect.Shrink('ajaxReplyForm');
		document.getElementById("loginmask").style.display="none";
	}
	Effect.Grow('ajaxReplyForm');
}

function HouseMessageReplyShrink(){
	hideMask();
	Effect.Shrink('ajaxReplyForm');
}

function checkLoginReply(){
	var str="";
	with(document.replyForm){
		if(acc.value==""){
				str+="◎ 帳號未填\n";
		}else if(acc.value.length<6 || acc.value.length>15){
				str+="◎ 帳號應介於6至15個字\n";
		}
		if(pwd.value==""){
				str+="◎ 密碼未填\n";
		}else if(pwd.value.length<6 || pwd.value.length>15){
				str+="◎ 密碼應介於6至15個字\n";
		}
		if(replycontent.value==""){
			str+="◎ 留言內容未填\n";
		}
		if(str!=""){
			alert("★★★注意★★★\n以下資料未填寫完整\n\n"+str+"\n\n請重新檢查您的資料再送出\n謝謝！！");
			return false;
		}else{
			//document.getElementById("subbtn").style.display="none";
		}
		return true;
	}
}

function checkReply(){
	var str="";
	with(document.replyForm){
		if(replycontent.value==""){
			str+="◎ 留言內容未填\n";
		}
		if(str!=""){
			alert("★★★注意★★★\n以下資料未填寫完整\n\n"+str+"\n\n請重新檢查您的資料再送出\n謝謝！！");
			return false;
		}else{
			//document.getElementById("subbtn").style.display="none";
		}
		return true;
	}
}
function replyLoginMessage(){
	if(checkLoginReply()){
		afterinclude=true;
		ajaxstr="type=login&acc="+document.getElementById("acc").value+"&pwd="+document.getElementById("pwd").value+"&content="+document.getElementById("replycontent").value+"&mid="+document.getElementById("mid").value+"&hid="+document.getElementById("hid").value;
		makeRequest("house_message_reply.php","","replyMessageCallback","");
	}
}
function replyMessage(){
	if(checkReply()){
		afterinclude=true;
		ajaxstr="mid="+document.getElementById("mid").value+"&content="+document.getElementById("replycontent").value+"&hid="+document.getElementById("hid").value;
		makeRequest("house_message_reply.php","","replyMessageCallback","");
	}
}
function replyMessageCallback(t){
	if(t=="ok"){
		document.location.reload();
	}else{
		HouseMessageReplyShrink();
		alert(t);
	}
}
//網友新增留言
function HouseMessage(){
	if(checkMessage()){
		afterinclude=true;
		var pubval;
		if(document.housemessageform.pub[0].checked==true) pubval="Y";
		else if(document.housemessageform.pub[1].checked==true) pubval="N";
		ajaxstr="content="+document.getElementById("content").value+"&email="+document.getElementById("email").value+"&pub="+pubval+"&code="+document.getElementById("code").value+"&hid="+document.getElementById("hid").value;
		makeRequest("house_message_ajax.php","","HouseMessageCallback","");
	}	
}

function HouseMessageCallback(t){
	if(t=="ok"){
		alert("留言已加入");
		document.location.reload();
	}else{
		alert(t);
	}
}

function checkMessage(form){
	var testmail;
	var str="";
	with(housemessageform){
		if(content.value==""){
			str+="◎ 問答內容未填\n";
		}
		if(code.value==""){
			str+="◎ 驗證碼未填\n";
		}else if(code.value.length!=6){
			str+="◎ 驗證碼為6位數字\n";
		}else if(isNaN(code.value)){
			str+="◎ 驗證碼請填入數字\n";
		}
		
		testmail=/\w+@\w+.\w+/g;	
		if(email.value!="" && (testmail.test(email.value)==false || email.value.indexOf('.',1)==-1)){
				str+="◎ 電子郵件信箱格式錯誤\n";
		}
		if(str!=""){
			alert("★★★注意★★★\n以下資料未填寫完整\n\n"+str+"\n\n請重新檢查您的資料再送出\n謝謝！！");
			return false;
		}
		return true;
	}	
}

