﻿$(function(){
	var email = $("#email");
	var emailInfo = $("#emailInfo");
	
	$("#add_mail").submit(function(){
		$('.loadingSave').fadeIn(1000,function(){
				$(this).html('<img src="images/ajax-loader.gif" alt="Loading" align="absmiddle" />').removeClass().addClass('loadingSave').fadeTo(900,1);
		});
			$.post("save_youremail.php",{your_email:$('#your_email').val()} ,function(data){
				if(data=='yes'){
					$('.loadingSave').fadeTo(200,0.1,function(){ 
						//$(this).html('<img src="images/yes.png" alt="บันทึกข้อมูลแล้ว" align="absmiddle" />').addClass('available').fadeTo(900,1);
						$(this).html(unescape('<img src="images/yes.png" alt="บันทึกข้อมูลแล้ว ทางเราจะส่ง e-mail ไปยังเมล์ที่ท่านระบุ เพื่อเป็นการแจ้งให้ท่านทราบอีกครั้ง ขอขอบคุณ" align="absmiddle" />')).removeClass().addClass('loadingSave').fadeTo(900,1);
					});
				}else if(data=='no'){
					$('.loadingSave').fadeTo(200,0.1,function(){ 
					//add message and change the class of the box and start fading
						//$(this).html('<img src="images/no.png" alt="ไม่สามารถบันทึกได้!!" align="absmiddle" />').addClass('error').fadeTo(900,1);
						$(this).html(unescape('<img src="images/no.png" alt="เกิดข้อผิดพลาดในการจัดเก็บข้อมูล โปรดลองใหม่อีกครั้ง!!" align="absmiddle" />')).removeClass().addClass('loadingSave').fadeTo(900,1);
					});
				}else if(data=='haved'){
					$('.loadingSave').fadeTo(200,0.1,function(){ 
					//add message and change the class of the box and start fading
						//$(this).html('<img src="images/no.png" alt="ไม่สามารถบันทึกได้!!" align="absmiddle" />').addClass('error').fadeTo(900,1);
						$(this).html(unescape('<img src="images/mail.png" alt="e-mail address นี้มีอยู่ในระบบแล้ว" align="absmiddle" />')).removeClass().addClass('loadingSave').fadeTo(900,1);
					});
				}else if(data=='no_match'){
					$('.loadingSave').fadeTo(200,0.1,function(){ 
						$(this).html(unescape('<img src="images/no.png" alt="รูปแบบอีเมล์ไม่ถูกต้อง โปรดลองอีกครั้ง" align="absmiddle" />')).removeClass().addClass('loadingSave').fadeTo(900,1);
					});
				}
			});
		return false;
	});
});
/*function  show_wb(sID,sForm,sIDB,sIDok,sIDno,sA,sB,sC,sD,sE,sF,sG,sH,sI,sJ,sK){
	oObj = document.getElementById(sID);
	if(sForm=='' || sForm==0){
		display(sID);
		hide(sIDB);
		hide(sIDok);
		hide(sIDno);
		hide(sA);
		hide(sB);
		hide(sC);
		hide(sD);
		hide(sE);
		hide(sF);
		hide(sG);
		hide(sH);
		hide(sI);
		hide(sJ);
		hide(sK);
		document.form_chk_wb.chk_wb.value=1;
	}else{
		hide(sID);
		display(sIDB);
		display(sIDok);
		display(sIDno);
		display(sA);
		display(sB);
		display(sC);
		display(sD);
		display(sE);
		display(sF);
		display(sG);
		display(sH);
		display(sI);
		display(sJ);
		display(sK);
		document.form_chk_wb.chk_wb.value=0;
	}
}*/
function uzXmlHttp(){
var xmlhttp = false;
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlhttp = false;
}
}

if(!xmlhttp && document.createElement){
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
// End XmlHttp Object
function result_addform(){
	var name = document.form_wb.name.value;
	var email = document.form_wb.email.value;
	var subject = document.form_wb.subject.value;
	var note = document.form_wb.note.value;
	/*var result;
	var url = 'addwebboard.php?name=' + name + '&email='+ email + '&subject=' + subject + '&note='  + note; 
	//alert(url);
	xmlhttp = uzXmlHttp();
	xmlhttp.open("GET", url, false);
	xmlhttp.send(null); 
	// ѺҡѺҡ server ŧ result
	result = xmlhttp.responseText;*/
			$.post("addwebboard.php",{ name:name,email:email,subject:subject,note:note,rand:Math.random() } ,function(result){
				//alert(result);
				if(result==1){
					display("re_ok");
					hide("re_no");
					location.href='webboard.php';
				}else{
					hide("re_ok");
					display("re_no");
				}
			});
	//alert(result);
	/*if(result==1){
		display("re_ok");
		hide("re_no");
		location.href='webboard.php';
	}else{
		hide("re_ok");
		display("re_no");
	}*/
	hide("wb");
}
function result_addform_ans(){
	var id = document.form_swb.id.value;
	var name = document.form_swb.name.value;
	var email = document.form_swb.email.value;
	var note = document.form_swb.note.value;
			$.post("addwebboard_ans.php",{ id:id,name:name,email:email,note:note,rand:Math.random() } ,function(result){
				if(result==1){
					display("re_ok");
					hide("re_no");
					location.href='showwebboard.php?id=' + id;
				}else{
					hide("re_ok");
					display("re_no");
				}
			});
	/*var result;
	var url = 'addwebboard_ans.php?id=' + id + '&name=' + name + '&email='+ email + '&note='  + note; 
	xmlhttp = uzXmlHttp();
	xmlhttp.open("GET", url, false);
	xmlhttp.send(null); 
	// รับค่ากลับจาก server มาเก็บลง result
	result = xmlhttp.responseText;
	//alert(result);
	// นำค่าที่ได้ออกไปแสงผล
	if(result==1){
		display("re_ok");
		hide("re_no");
		location.href='showwebboard.php?id=' + id;
	}else{
		hide("re_ok");
		display("re_no");
	}*/
	hide("wb_ans");
}
function  show_wb(sID,sForm){
	oObj = document.getElementById(sID);
	if(sForm=='' || sForm==0){
		display(sID);
		document.form_chk_wb.chk_wb.value=1;
	}else{
		hide(sID);
		document.form_chk_wb.chk_wb.value=0;
	}
}
function display(sID) {
	var oObj = document.getElementById(sID);
	if (oObj) {
		oObj.style.display='inline';
	}
}

function hide(sID) {
	var oObj = document.getElementById(sID);
	if (oObj) {
		oObj.style.display='none';
	}
}

function emoticon(what,num){
	if(num==0){
		document.form_wb.note.value = document.form_wb.elements.note.value+" "+what;
		document.form_wb.note.focus();
	}else if(num==1){
		document.form_swb.note.value = document.form_swb.elements.note.value+" "+what;
		document.form_swb.note.focus();
	}else if(num==2){
		document.form_contact.c_detail.value = document.form_contact.elements.c_detail.value+" "+what;
		document.form_contact.c_detail.focus();
	}
}