// JavaScript Document

var xmlHttp = "";
var xmlHttp1 = "";
var xmlHttp2 = "";
var xmlHttp3 = "";
var xmlHttp4 = "";
var xmlHttp5 = "";
var xmlHttp6 = "";
var xmlHttp7 = "";
var xmlHttp8 = "";
var xmlHttp9 = "";
var xmlHttp10 = "";
var xmlHttp11 = "";
var xmlHttp12 = "";
var xmlHttp13 = "";

var show_div = "";

var time_top10;
var start = 0;


function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
}

function loading(){
	var xpos = document.body.clientWidth;
	var ypos = document.body.clientHeight;	
	
	if(navigator.appName == "Microsoft Internet Explorer"){
		document.getElementById("div_loading").style.filter='alpha(opacity=80)';
	}
		
		document.getElementById("div_loading").style.width = xpos+'px';
		document.getElementById("div_loading").style.height = ypos+'px';		
        document.getElementById("div_loading").style.visibility='visible';
		
		document.getElementById("div_table_loading").style.width = xpos+'px';
		document.getElementById("div_table_loading").style.height = ypos+'px';		
        document.getElementById("div_table_loading").style.visibility='visible';		
		
}
function endload(){
		document.getElementById("div_loading").style.visibility='hidden';
		document.getElementById("div_table_loading").style.visibility='hidden';		
}

//****************************** Include_page_all **************************************************
function include_page(string_page){

	var arr_page = string_page.split(",");
	for(var i =0;i < arr_page.length;i++){
		if(arr_page[i]==1){
			include_page1();		
		}else if(arr_page[i]==2){
			include_page2();		
		}else if(arr_page[i]==3){
			include_page3();		
		}else if(arr_page[i]==4){
			include_page4();		
		}else if(arr_page[i]==5){
			include_page5();		
		}else if(arr_page[i]==6){
			include_page6();		
		}else if(arr_page[i]==7){
			include_page7();		
		}else if(arr_page[i]==8){
			include_page8();		
		}else if(arr_page[i]==9){
			include_page9();		
		}else if(arr_page[i]==10){
			include_page10();		
		}else if(arr_page[i]==11){
			include_page11();				
		}else if(arr_page[i]==12){
			include_page12();		
		}else if(arr_page[i]==13){
        	include_page13();
        }  
	}
}

function include_page_all(txtDay){
	include_page1();
	include_page2();
	include_page3();
	include_page4();
	include_page5();
	include_page6(txtDay);
	include_page7();	
	include_page8();
	include_page12();	  
    include_page13(); 			
}
function include_cpage_all(){
	include_cpage1();		
}
function include_page1() {
	var param = "new_release.php";
	xmlHttp1 = new createXMLHttpRequest();
	xmlHttp1.onreadystatechange = result_include_page1;
	xmlHttp1.open("get" ,param, true);  
	xmlHttp1.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp1.send(null);
}

function result_include_page1() {
	if (xmlHttp1.readyState == 4) {
		if(xmlHttp1.status == 200) {
			document.getElementById("2_1").innerHTML = xmlHttp1.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page2() {

	if(navigator.appName == "Microsoft Internet Explorer"){
		var param = "best_seller2.php?start="+start;
	}else{
		var param = "best_seller.php?start="+start;
		//var param = "best_seller2.php?start="+start;
	}
	xmlHttp2 = new createXMLHttpRequest();
	xmlHttp2.onreadystatechange = result_include_page2;
	xmlHttp2.open("get" ,param, true);  
	xmlHttp2.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp2.send(null);
}

function result_include_page2() {
	if (xmlHttp2.readyState == 4) {
		if(xmlHttp2.status == 200) {
			document.getElementById("3_1").innerHTML = xmlHttp2.responseText;
			//endload();
			if(navigator.appName == "Microsoft Internet Explorer"){	
			document.getElementById("top10_2").start();
			}else{
				if(!time_top10){
					time_top10 = setInterval("slide_top10()",3000);
				}
			}	
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function slide_top10(){
	start++;
	if(start>9){
		start = 0;
	}
	include_page2_top10();
}
function include_page2_top10() {
	var param = "best_seller_top10.php?start="+start;
	xmlHttp2 = new createXMLHttpRequest();
	xmlHttp2.onreadystatechange = result_include_page2_top10;
	xmlHttp2.open("get" ,param, true);  
	xmlHttp2.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp2.send(null);
}

function result_include_page2_top10() {
	if (xmlHttp2.readyState == 4) {
		if(xmlHttp2.status == 200) {
			document.getElementById("div_top10").innerHTML = xmlHttp2.responseText;
		}
	} 
}
function include_page3() {
	var param = "recommend.php";
	xmlHttp3 = new createXMLHttpRequest();
	xmlHttp3.onreadystatechange = result_include_page3;
	xmlHttp3.open("get" ,param, true);  
	xmlHttp3.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp3.send(null);
}

function result_include_page3() {
	if (xmlHttp3.readyState == 4) {
		if(xmlHttp3.status == 200) {
			document.getElementById("3_2").innerHTML = xmlHttp3.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page4() {
	var param = "member.php";
	xmlHttp4 = new createXMLHttpRequest();
	xmlHttp4.onreadystatechange = result_include_page4;
	xmlHttp4.open("get" ,param, true);  
	xmlHttp4.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp4.send(null);
}

function result_include_page4() {
	if (xmlHttp4.readyState == 4) {
		if(xmlHttp4.status == 200) {
			document.getElementById("1_1").innerHTML = xmlHttp4.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page5() {
	var param = "news.php";
	xmlHttp5 = new createXMLHttpRequest();
	xmlHttp5.onreadystatechange = result_include_page5;
	xmlHttp5.open("get" ,param, true);  
	xmlHttp5.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 5000 00:00:00 GMT");
	xmlHttp5.send(null);
}

function result_include_page5() {
	if (xmlHttp5.readyState == 4) {
		if(xmlHttp5.status == 200) {
			document.getElementById("1_2").innerHTML = xmlHttp5.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page6(txtDay) {
	var param = "calendar.php?txtDay="+txtDay;
	xmlHttp6 = new createXMLHttpRequest();
	xmlHttp6.onreadystatechange = result_include_page6;
	xmlHttp6.open("get" ,param, true);  
	xmlHttp6.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp6.send(null);
}

function result_include_page6() {
	if (xmlHttp6.readyState == 4) {
		if(xmlHttp6.status == 200) {
			document.getElementById("1_3").innerHTML = xmlHttp6.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page7() {
	var param = "floor.php";
	xmlHttp7 = new createXMLHttpRequest();
	xmlHttp7.onreadystatechange = result_include_page7;
	xmlHttp7.open("get" ,param, true);  
	xmlHttp7.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp7.send(null);
}

function result_include_page7() {
	if (xmlHttp7.readyState == 4) {
		if(xmlHttp7.status == 200) {
			document.getElementById("1_4").innerHTML = xmlHttp7.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page8() {
	var param = "new_update.php";
	xmlHttp8 = new createXMLHttpRequest();
	xmlHttp8.onreadystatechange = result_include_page8;
	xmlHttp8.open("get" ,param, true);  
	xmlHttp8.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp8.send(null);
}

function result_include_page8() {
	if (xmlHttp8.readyState == 4) {

		if(xmlHttp8.status == 200) {
			document.getElementById("2_2").innerHTML = xmlHttp8.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page9() {
	var param = "category.php";
	xmlHttp9 = new createXMLHttpRequest();
	xmlHttp9.onreadystatechange = result_include_page9;
	xmlHttp9.open("get" ,param, true);  
	xmlHttp9.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp9.send(null);
}

function result_include_page9() {
	if (xmlHttp9.readyState == 4) {
		if(xmlHttp9.status == 200) {
			document.getElementById("1_2").innerHTML = xmlHttp9.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page10() {
	var param = "writer_corner.php";
	xmlHttp10 = new createXMLHttpRequest();
	xmlHttp10.onreadystatechange = result_include_page10;
	xmlHttp10.open("get" ,param, true);  
	xmlHttp10.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp10.send(null);
}

function result_include_page10() {
	if (xmlHttp10.readyState == 4) {
		if(xmlHttp10.status == 200) {
			document.getElementById("1_3").innerHTML = xmlHttp10.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page11() {
	var param = "news.php";
	xmlHttp11 = new createXMLHttpRequest();
	xmlHttp11.onreadystatechange = result_include_page11;
	xmlHttp11.open("get" ,param, true);  
	xmlHttp11.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 5000 00:00:00 GMT");
	xmlHttp11.send(null);
}

function result_include_page11() {
	if (xmlHttp11.readyState == 4) {
		if(xmlHttp11.status == 200) {
			document.getElementById("1_3").innerHTML = xmlHttp11.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page12() {
	var param = "download_0.php";
	xmlHttp12 = new createXMLHttpRequest();
	xmlHttp12.onreadystatechange = result_include_page12;
	xmlHttp12.open("get" ,param, true);  
	xmlHttp12.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 5000 00:00:00 GMT");
	xmlHttp12.send(null);
}

function result_include_page12() {
	if (xmlHttp12.readyState == 4) {
		if(xmlHttp12.status == 200) {
			document.getElementById("3_3").innerHTML = xmlHttp12.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_page13() {
	var param = "fun_update.php";
	xmlHttp13 = new createXMLHttpRequest();
	xmlHttp13.onreadystatechange = result_include_page13;
	xmlHttp13.open("get" ,param, true);  
	xmlHttp13.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp13.send(null);
}

function result_include_page13() {
	if (xmlHttp13.readyState == 4) {

		if(xmlHttp13.status == 200) {
			document.getElementById("2_3").innerHTML = xmlHttp13.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function include_cpage1() {
	var param = "c_menu.php";
	xmlHttp1 = new createXMLHttpRequest();
	xmlHttp1.onreadystatechange = result_include_cpage1;
	xmlHttp1.open("get" ,param, true);  
	xmlHttp1.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp1.send(null);
}

function result_include_cpage1() {
	if (xmlHttp1.readyState == 4) {
		if(xmlHttp1.status == 200) {
			document.getElementById("1_1").innerHTML = xmlHttp1.responseText;
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
//****************************** Include_page_all **************************************************
function check_username(){
	var username=document.getElementById("username2").value;
    var param = "check_username.php?username="+username;
	var valid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_+()";
	var ok = "yes";
	var temp;
		for (var i=0; i<username.length; i++) {
				temp = "" + username.substring(i, i+1);
				if (valid.indexOf(temp) == "-1") ok = "no";
		}	 
	if(ok == "no"){
    	document.getElementById("div_error").innerHTML = "username ต้องเป็นภาษาอังกฤษ เท่านั้นค่ะ!";	
    }else{                    
		xmlHttp = new createXMLHttpRequest();
		xmlHttp.onreadystatechange = result_check_username;
		xmlHttp.open("get" ,param, true);  
		xmlHttp.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		xmlHttp.send(null);
    }
}
function result_check_username() {
	if (xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
				document.getElementById("div_error").innerHTML = xmlHttp.responseText;		
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}

function login() {
	var username=document.getElementById("username").value;
   	var password=document.getElementById("password").value;
    var param = "login.php?username="+username+"&password="+password;
	xmlHttp = new createXMLHttpRequest();
	xmlHttp.onreadystatechange = result_login;
	xmlHttp.open("get" ,param, true);  
	xmlHttp.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp.send(null);
}

function result_login() {
	if (xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
            if(xmlHttp.responseText == 'loginComplete'){
				document.getElementById("div_login").innerHTML = "Log In Complete";
            	setTimeout("window.location.href='index.php';",1000);
            }else{
			    document.getElementById("div_login").innerHTML = xmlHttp.responseText;
				//endload();
            	setTimeout("reset()", 1500);				
            }			
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function login2() {
	var username2=document.getElementById("username2").value;
   	var password2=document.getElementById("password2").value;
    var param = "login.php?username="+username2+"&password="+password2;
	xmlHttp = new createXMLHttpRequest();
	xmlHttp.onreadystatechange = result_login2;
	xmlHttp.open("get" ,param, true);  
	xmlHttp.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp.send(null);
}

function result_login2() {
	if (xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
            if(xmlHttp.responseText == 'loginComplete'){
				document.getElementById("div_login2").innerHTML = "Log In Complete";
				var book_id = document.getElementById("book_id").value;	
				var param = "book.php?book_id="+book_id+"&div_review_input=1&aj=1";
				include_page4();			
				show_page('2',param);	
            }else{
			    document.getElementById("div_login2").innerHTML = xmlHttp.responseText;
				//endload();			
            }			
			//endload();
		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function reset() {
	document.getElementById("username").value = "";
    document.getElementById("password").value = "";
    document.getElementById("div_login").innerHTML = '';
}
function logout() {	
	var param = "logout.php";
	xmlHttp = new createXMLHttpRequest();
	xmlHttp.onreadystatechange = show_result_logout;
	xmlHttp.open("get" ,param, true);  
	xmlHttp.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp.send(null);
}
function show_result_logout() {
	if (xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			var arr = xmlHttp.responseText.split(",");
			var msg = arr[0];
            if(msg == "logoutComplete"){
            	setTimeout("endload();window.location.href='index.php';",100);
            }else{
				//endload();
			}
		}
	}else{
   		//loading();
    } 
}

function show_page(div,page) {	
	show_div = div;
	var param = page;
	xmlHttp = new createXMLHttpRequest();
	xmlHttp.onreadystatechange = show_result_show_page;
	xmlHttp.open("get" ,param, true);  
	xmlHttp.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp.send(null);
}
function show_result_show_page() {
	if (xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
				document.getElementById(show_div).innerHTML = xmlHttp.responseText;
				//endload();			
				var listArray = xmlHttp.responseText.split(",");
				if(listArray[0]=="CateInsertComplete"){
					cancel_add_cate();
					show_page('2-1','c_books.php');
				}
		}
	}else{
   		//loading();
    } 
}
function show_add_cate(){

		
	var xpos = document.body.clientWidth;
	var ypos = document.body.clientHeight;	

	if(navigator.appName == "Microsoft Internet Explorer"){
		document.getElementById("div_add_cate").style.filter='alpha(opacity=80)';
	}
		
		document.getElementById("div_add_cate").style.width = xpos+'px';
		document.getElementById("div_add_cate").style.height = ypos+'px';		
        document.getElementById("div_add_cate").style.visibility='visible';	
		
		document.getElementById("div_table_add_cate").style.width = xpos+'px';
		document.getElementById("div_table_add_cate").style.height = ypos+'px';		
        document.getElementById("div_table_add_cate").style.visibility='visible';			
		
		window.scroll(0,0);
}
function submit_add_cate() {
		var cate_name = document.getElementById("cate_name").value;
		document.getElementById("cate_name").value = '';
		if((cate_name.length>0) && (cate_name != "")){
		var param = "c_add_cate.php?cate_name="+cate_name;
		show_page('div_error',param);
		}else{
			document.getElementById("div_error").innerHTML='¡ÃØ³Ò»éÍ¹¢éÍÁÙÅËÁÇ´ËÁÙè´éÇÂ¤ÃÑº';	
		}

		

}
function cancel_add_cate(){

		document.getElementById("div_error").innerHTML = "";	
		document.getElementById("cate_name").value = '';
		document.getElementById("div_add_cate").style.visibility='hidden';
		document.getElementById("div_table_add_cate").style.visibility='hidden';		
		
}
function mailto(mail) {	

	document.getElementById("mailto").style.display='';
	document.getElementById("recipient").value=mail;

}
function cancel_mailto(){
	document.getElementById("recipient").value='';
	document.getElementById("mailto").style.display='none';
}
function new_post() {	
	document.getElementById("tb_new_post").style.display='';
}
function new_post2() {	
	document.getElementById("tb_reply").style.display='';
}
function cancel_new_post(){
	document.getElementById("topic").value='';
	document.getElementById("message").value='';
	document.getElementById("post_by").value='';
	document.getElementById("post_email").value='';
	document.getElementById("tb_new_post").style.display='none';
}
function cancel_new_post2(){
	document.getElementById("message").value='';
	document.getElementById("post_by").value='';
	document.getElementById("post_email").value='';
	document.getElementById("tb_reply").style.display='none';
}
function play(soundobj) {
  if(navigator.appName == "Microsoft Internet Explorer"){
  	document.getElementById("bg_sound").src = 'spot1.mp3';
  }else{
  	//var thissound= eval("document."+soundobj);
  	//thissound.Play();
  }
}
function stop(soundobj) {
  if(navigator.appName == "Microsoft Internet Explorer"){
  	document.getElementById("bg_sound").src = '';
  }else{
  	//var thissound= eval("document."+soundobj);
  	//thissound.Stop();
  }
}
function swap_sound(soundobj){

	if(document.getElementById("play_status").value==1){
		document.getElementById("play_status").value=0;
		document.getElementById("sound_img").src='images/sound.gif';
		stop(soundobj);
	}else{
		document.getElementById("play_status").value=1;	
		document.getElementById("sound_img").src='images/sound2.gif';		
		play(soundobj);	
	}
}
function tab_over(tab_num){
	document.getElementById("tab"+tab_num).style.backgroundColor='#FC306B';
}
function tab_out(tab_num){
	document.getElementById("tab"+tab_num).style.backgroundColor='#FFCCCC';
}
function show_tab(tab_num){
	for(var i=1;i <= 2;i++){
		if(i == tab_num){
			document.getElementById("tab_data"+i).style.display='';
			document.getElementById("tab"+i).style.display='none';			
			document.getElementById("tab"+i+"_click").style.display='';					
		}else{
			document.getElementById("tab_data"+i).style.display='none';
			document.getElementById("tab"+i).style.display='';			
			document.getElementById("tab"+i+"_click").style.display='none';			
		}
	}
}
function visible_div(div_name){
	document.getElementById(div_name).style.visibility='visible';	
}
function hide_div(div_name){
	document.getElementById(div_name).style.visibility='hidden';
}
function swap_div(div_name){
	if(document.getElementById(div_name).style.display == 'inline'){
		document.getElementById(div_name).style.display='none';
    }else{
    	document.getElementById(div_name).style.display='inline';
    }
}
function rate_over2(num){
	var rate_score = document.getElementById('rate_score').value;
	if(num==rate_score){
	  document.getElementById('rate_score').value = 0;
	}
	for(i=1;i<=num;i++){
		if(i%2==0){
			document.getElementById("rate"+i).src='images/raiting_user_half2.gif';
		}else{
			document.getElementById("rate"+i).src='images/raiting_user_half.gif';	
		}
	}
}
function rate_out2(num){
	var rate_score = document.getElementById('rate_score').value;
	var rate_score_up = parseInt(document.getElementById('rate_score').value) + 1;
	if(rate_score == 0){
		for(i=1;i<=num;i++){
			if(i%2==0){
				document.getElementById("rate"+i).src='images/raiting_inactive_half2.gif';
			}else{
				document.getElementById("rate"+i).src='images/raiting_inactive_half.gif';	
			}
		}
	}else{
		for(i=rate_score_up;i<=num;i++){
			if(i%2==0){
				document.getElementById("rate"+i).src='images/raiting_inactive_half2.gif';
			}else{
				document.getElementById("rate"+i).src='images/raiting_inactive_half.gif';	
			}		
		}
	}
}
function rate_2(num){
	for(i=10;i>num;i--){
		if(i%2==0){
				document.getElementById("rate"+i).src='images/raiting_inactive_half2.gif';
			}else{
				document.getElementById("rate"+i).src='images/raiting_inactive_half.gif';
		}
	}
}
function user_add_review() {
	document.getElementById("div_review_input").style.visibility='hidden';
	var name = document.getElementById("name").value;
	var subject = document.getElementById("subject").value;
	var user_review = document.getElementById("user_review").value;	
	var book_id = document.getElementById("book_id").value;	
	var rate_score	= document.getElementById("rate_score").value;	
	
	var param = "user_add_review.php?name="+name+"&subject="+subject+"&user_review="+user_review+"&book_id="+book_id+"&rate_score="+rate_score;
	xmlHttp1 = new createXMLHttpRequest();
	xmlHttp1.onreadystatechange = result_user_add_review;
	xmlHttp1.open("get" ,param, true);  
	xmlHttp1.setRequestHeader ("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp1.send(null);
}
function result_user_add_review() {
	if (xmlHttp1.readyState == 4) {
		if(xmlHttp1.status == 200) {
			//endload();
			document.getElementById("div_review").innerHTML = xmlHttp1.responseText;		
			setTimeout("document.getElementById('div_review_input').style.visibility='visible';document.getElementById('div_review').innerHTML ='';reload_page();",2000);
			

		}else{
			//loading();
		}
	}else{
   		//loading();
    } 
}
function reload_page(){
			var book_id = document.getElementById("book_id").value;	
			var param = "book.php?book_id="+book_id+"&r_page=1";
			show_page('2',param);		
}
function check_regis(){

	var username = document.f_regis.username2.value;
	var password = document.f_regis.password.value;
	var password2 = document.f_regis.password2.value;
	var fname = document.f_regis.fname.value;
	var lname = document.f_regis.lname.value;
	var nname = document.f_regis.nname.value;
	var nname = document.f_regis.nname.value;
	var mobtel = document.f_regis.mobtel.value;
	var email = document.f_regis.email.value;
    
    var select_country = document.f_regis.select_country.value;
    var country = document.f_regis.country.value;    
    
    //check username format****************************************************
	var valid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_+()";
	var ok = "yes";
	var temp;
				for (var i=0; i<username.length; i++) {
						temp = "" + username.substring(i, i+1);
						if (valid.indexOf(temp) == "-1") ok = "no";
				}	
                
    //check country and address*************************************************           
    var address_ok = "yes";     
	//alert(document.getElementById("select_country_th").checked);
	if(document.getElementById("select_country_th").checked){ 
    
	    var province = document.f_regis.province.value;
	    var tambon = document.f_regis.tambon.value;
	    var road = document.f_regis.road.value;
	    var postal = document.f_regis.postal.value;   
		var address = document.getElementById("address1").value;	

		if(province==2){
		    var amphor = document.getElementById("amphor").value;  
        }else if(province!=2){
		    var amphor = document.getElementById("amphor2").value;   
        }
		if(province.length==0 || province==0){
			document.getElementById("div_error").innerHTML ='กรุณาเลือก จังหวัด ด้วยค่ะ';
			address_ok = "no"; 
		}else if(amphor.length==0 || amphor==0){
			document.getElementById("div_error").innerHTML ='กรุณากรอก เขต/อำเภอ ด้วยค่ะ';
			address_ok = "no"; 
		}else if(tambon.length==0){
			document.getElementById("div_error").innerHTML ='กรุณากรอก แขวง/ตำบล ด้วยค่ะ';
			address_ok = "no"; 
		}else if(road.length==0){
			document.getElementById("div_error").innerHTML ='กรุณากรอก ถนน ด้วยค่ะ';
			address_ok = "no"; 
		}else if(postal.length==0){
			document.getElementById("div_error").innerHTML ='กรุณากรอก รหัสไปรษณีย์ ด้วยค่ะ';
			address_ok = "no"; 
		}else if(address.length==0){
			document.getElementById("div_error").innerHTML ='กรุณากรอก อาคาร/บ้านเลขที่/ห้อง ด้วยค่ะ';
			address_ok = "no"; 
        }                        
                
    }else if(document.getElementById("select_country_en").checked){ 
		var address = document.getElementById("address2").value;      
		if(country.length==0 || country==0){
			document.getElementById("div_error").innerHTML ='กรุณาเลือก ประเทศ ด้วยค่ะ';        
        	address_ok = "no"; 
        }else if(address.length==0){
			document.getElementById("div_error").innerHTML ='กรุณากรอก ที่อยู่ ด้วยค่ะ';
			address_ok = "no"; 
        }   
    }
	
                    
	if(username.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก username ด้วยค่ะ';
		window.scroll(0,0);
		document.f_regis.username2.focus();
	}else if(ok == "no"){
		document.getElementById("div_error").innerHTML ='username ต้องเป็นภาษาอังกฤษ เท่านั้นค่ะ!';
		window.scroll(0,0);
		document.f_regis.username2.focus();    
    }else if(password.length < 4){
		document.getElementById("div_error").innerHTML ='กรุณากรอก รหัสผ่าน( ไม่น้อยกว่า4ตัวอักษร ) ด้วยค่ะ';
		window.scroll(0,0);
	}else if(password2.length < 4){
		document.getElementById("div_error").innerHTML ='กรุณากรอก ยืนยันรหัสผ่าน ด้วยค่ะ';
		window.scroll(0,0);
	}else if(password != password2){
		document.getElementById("div_error").innerHTML ='ข้อมูลของรหัสผ่านแ ละยืนยันรหัสผ่าน ต้องตรงค่ะ';
		window.scroll(0,0);
	}else if(fname.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก ชื่อ ด้วยค่ะ';
		window.scroll(0,0);
	}else if(lname.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก นามสกุล ด้วยค่ะ';
		window.scroll(0,0);
	}else if(nname.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก ชื่อเล่น ด้วยค่ะ';
		window.scroll(0,0);
	}else if(emailCheck(email)==false){
		document.getElementById("div_error").innerHTML ="email address ไม่ถูกต้อง  กรุณาตรวจสอบใหม่ (อาจจะไม่มีเครื่องหมาย '@' หรือ '.' ";
		window.scroll(0,0);
	}else if(mobtel.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก เบอร์โทรศัพท์มือถือ ด้วยค่ะ';
		window.scroll(0,0);
	}else if(mobtel.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก เบอร์โทรศัพท์มือถือ ด้วยค่ะ';
		window.scroll(0,0);
	}else if(address_ok == "no"){
		window.scroll(0,0);    
    }else{
		document.f_regis.submit();
	}
}
function check_profile(){

	var password = document.f_regis.password.value;
	var password2 = document.f_regis.password2.value;
	var fname = document.f_regis.fname.value;
	var lname = document.f_regis.lname.value;
	var nname = document.f_regis.nname.value;
	var address = document.f_regis.address.value;
	var nname = document.f_regis.nname.value;
	var mobtel = document.f_regis.mobtel.value;
	var email = document.f_regis.email.value;
    var error_pass = 0;

	if(password.length > 0){
   		 	if(password.length < 4){
			  	document.getElementById("div_error").innerHTML ='ข้อมูลของรหัสผ่าน ต้องมากกว่า 4 ตัวอักษร!';
			  	window.scroll(0,0);
                error_pass = 1;
		 	}
   		 	if(password != password2){
			  	document.getElementById("div_error").innerHTML ='ข้อมูลของรหัสผ่านและยืนยันรหัสผ่าน ต้องตรงกัน ค่ะ!';
			  	window.scroll(0,0);
                error_pass = 1;                
		 	}            
    }
    
	if(fname.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก ชื่อ ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(lname.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก นามสกุล ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(nname.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก ชื่อเล่น ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(emailCheck(email)==false){
		document.getElementById("div_error").innerHTML ="email address ไม่ถูกต้อง  กรุณาตรวจสอบใหม่ (อาจจะไม่มีเครื่องหมาย '@' หรือ '.' !"
		window.scroll(0,0);
	}else if(mobtel.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก เบอร์โทรศัพท์มือถือ ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(mobtel.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก เบอร์โทรศัพท์มือถือ ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(address.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก ที่อยู่ ด้วยค่ะ!';
		window.scroll(0,0);
	}else{
    	if(error_pass != 1){
			document.f_regis.submit();
        }
	}
}
function emailCheck(emailStr) {
		var emailPat = /^.+@.+\..{2,3}$/;
		var matchArray = emailStr.match(emailPat);
		if (matchArray == null) {
			return false;
		}
	return true;
}
function check_career(){

	var salary = document.f_regis.salary.value;
	var name = document.f_regis.name.value;
	var age = document.f_regis.age.value;
	var religion = document.f_regis.religion.value;
	var birth_place = document.f_regis.birth_place.value;
	var high = document.f_regis.high.value;
	var weight = document.f_regis.weight.value;
	var id_card = document.f_regis.id_card.value;
   	var address = document.f_regis.address.value;
	var mobtel = document.f_regis.mobtel.value;    
    var tham = document.f_regis.tham.value;
    var tham_reason = document.f_regis.tham_reason.value;
    
    
	if(salary.length==0){
		document.getElementById("div_error").innerHTML ='กรุณาค่าจ้างต่ำสุดที่ยอมรับได้ ด้วยค่ะ!!';
		window.scroll(0,0);
	}else if(name.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก ชื่อ-นามสกุล ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(age.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก อายุ ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(religion.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก ศาสนา ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(birth_place.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก สถาณที่เกิด ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(high.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก ส่วนสูง ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(weight.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก น้ำหนัก ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(id_card.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก เลขที่บัตรประจำตัวประชาชน ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(address.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก ที่อยู่ ด้วยค่ะ!';
		window.scroll(0,0);
	}else if(mobtel.length==0){
		document.getElementById("div_error").innerHTML ='กรุณากรอก เบอร์โทรศัพท์มือถือด้วยค่ะ ด้วยค่ะ!';
		window.scroll(0,0);
	}else if((tham=='N') && (tham_reason.length==0)){
		document.getElementById("div_error").innerHTML ='กรุณากรอก เหตุผลที่ไม่ยินดีเข้าปฏิบัติธรรม 7 วันด้วยค่ะ!';
		window.scroll(0,0);    
    }else{
			document.f_regis.submit();
	}
}
function insertAtCursor(myField, myValue) {
	if (document.selection) {
	    //IE support
        myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}else if (myField.selectionStart || myField.selectionStart ==0) {
	    //MOZILLA/NETSCAPE support
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)+myValue+myField.value.substring(endPos, myField.value.length);
	}else{
		myField.value += myValue;
	}
    myField.focus();
}
function show_country(){
		document.getElementById("country").style.display='';
        document.getElementById("address_en").style.display='';
        document.getElementById("address_th").style.display='none';        
}
function hide_country(){
		document.getElementById("country").style.display='none';
        document.getElementById("address_en").style.display='none';
        document.getElementById("address_th").style.display='';                
}
function show_amphor(province_id){
	if(province_id==2){
   	 	document.getElementById("div_amphor1").style.display='';
		document.getElementById("div_amphor2").style.display='none';   	 
    }else{
   	 	document.getElementById("div_amphor1").style.display='none';
		document.getElementById("div_amphor2").style.display='';    
    }
function showblog(blog_id){

}
}