// JavaScript Document
function telephone(){
	if(document.addForm.telephone_validation[0].checked){
		document.addForm.telephone_price.disabled = false;
		document.addForm.telephone_unit.disabled = false;
	}
	if(document.addForm.telephone_validation[1].checked){
		document.addForm.telephone_price.disabled = true;	
		document.addForm.telephone_unit.disabled = true;
		document.addForm.telephone_price.value = '';
	}
}
function telephone2(){
	document.addForm.telephone_price.value = '';
}


function internet(){
	if(document.addForm.internet_validation[0].checked){
		document.addForm.internet_unit.disabled = false;
		
		if(document.addForm.internet_unit[1].selected || document.addForm.internet_unit[2].selected){
			document.addForm.internet_price.disabled = false;
		}
	}
	if(document.addForm.internet_validation[1].checked){
		document.addForm.internet_price.disabled = true;
		document.addForm.internet_unit.disabled = true;
		document.addForm.internet_price.value = '';
	}
}
function internet2(){
	document.addForm.internet_price.value = '';
	if(document.addForm.internet_unit[1].selected || document.addForm.internet_unit[2].selected){
		document.addForm.internet_price.disabled = false;
	}else{
		document.addForm.internet_price.disabled = true;
		document.addForm.internet_price.value = '';
	}
}



function checkForm(){
	if(document.addForm.name.value == ''){
		document.addForm.name.focus();
		alert('กรุณากรอก "ชื่อที่พัก" ด้วยค่ะ');
	}else if(document.addForm.l_m_price.value == '' && document.addForm.month_rent[0].checked){
		document.addForm.l_m_price.focus();
		alert('กรุณากรอก "ราคาเช่ารายเดือน" ด้วยค่ะ');
	}else if(parseInt(document.addForm.l_m_price.value) >= parseInt(document.addForm.u_m_price.value) && document.addForm.u_m_price.value.length > 0){
		document.addForm.l_m_price.focus();
		document.addForm.l_m_price.select();
		alert('"ราคา" ช่องที่1ต้องน้อยกว่า "ราคา" ช่องที่2คุ่ะ');
	}else if(document.addForm.l_insurance.value == '' && document.addForm.month_rent[0].checked){
		document.addForm.l_insurance.focus();
		alert('กรุณากรอก "เงินประกัน" ด้วยค่ะ');
	}else if(parseInt(document.addForm.l_insurance.value) >= parseInt(document.addForm.u_insurance.value) && document.addForm.u_insurance.value.length > 0){
		document.addForm.l_insurance.focus();
		document.addForm.l_insurance.select();
		alert('"เงินประกัน" ช่องที่1ต้องน้อยกว่า "เงินประกัน" ช่องที่2คุ่ะ');
	}else if(document.addForm.l_d_price.value == '' && document.addForm.day_rent[0].checked){
		document.addForm.l_d_price.focus();
		alert('กรุณากรอก "ราคาเช่ารายวัน" ด้วยค่ะ');
	}else if(parseInt(document.addForm.l_d_price.value) >= parseInt(document.addForm.u_d_price.value) && document.addForm.u_d_price.value.length > 0){
		document.addForm.l_d_price.focus();
		document.addForm.l_d_price.select();
		alert('"ราคา" ช่องที่1ต้องน้อยกว่า "ราคา" ช่องที่2คุ่ะ');
	}else if(document.addForm.month_rent[1].checked && document.addForm.day_rent[1].checked){
		document.addForm.month_rent[1].focus();
		alert('กรุณากรอกราคาของการเ่ช่ารายเดือน หรือเช่ารายวัีนอย่างใดอย่างหนึ่งค่ะ');
	}else if(document.addForm.l_size.value == ''){
		document.addForm.l_size.focus();
		alert('กรุณากรอก "ขนาด" ด้วยค่ะ');
	
	}else if(parseInt(document.addForm.l_size.value) >= parseInt(document.addForm.u_size.value) && document.addForm.u_size.value.length >0){
		document.addForm.l_size.focus();
		document.addForm.l_size.select();
		alert('"ขนาด"ช่องที่1ต้องน้อยกว่า"ขนาด"ช่องที่2ค่ะ');
	}else if(document.addForm.water_price.value == ''){
		document.addForm.water_price.focus();
		alert('กรุณากรอก "ราคาน้ำประปา/หน่วย" ด้วยค่ะ');
	}else if(document.addForm.electric_price.value == ''){
		document.addForm.electric_price.focus();
		alert('กรุณากรอก "ราคาไฟ้ฟ้า/หน่วย" ด้วยค่ะ');
	}else if(document.addForm.contact.value == ''){
		document.addForm.contact.focus();
		alert('กรุณากรอก "ชื่อผู้ติดต่อ(ชื่อของคุณ)" ด้วยค่ะ');
	}else if(document.addForm.tel.value == '' && document.addForm.cellphone.value == ''){
		document.addForm.tel.focus();
		alert('กรุณากรอก "เบอร์โทรศัพท์ของคุณ" ด้วยค่ะ');
	}else if(!document.addForm.tel.value == '' && (document.addForm.tel.value.length<9 || !document.addForm.tel.value.match(/^0+/))){
		document.addForm.tel.focus();
		document.addForm.tel.select();
		alert('กรุณากรอก "เบอร์โทรศัพท์" ให้ถูกต้องด้วยค่ะ');
	}else if( !document.addForm.cellphone.value == '' && (document.addForm.cellphone.value.length<10 || !document.addForm.cellphone.value.match(/^0+/))){
		document.addForm.cellphone.focus();
		document.addForm.cellphone.select();
		alert('กรุณากรอก "เบอร์โทรศัพท์มือถือ" ให้ถูกต้องด้วยค่ะ เบอร์โทรมี10หลักนะค่ะ');
	}else if(!document.addForm.fax.value == '' && (document.addForm.fax.value.length<9 || !document.addForm.fax.value.match(/^0+/))){
		document.addForm.fax.focus();
		document.addForm.fax.select();
		alert('กรุณากรอก "เบอร์แฟ็กซ์" ให้ถูกต้องด้วยค่ะ');
	}else if(!document.addForm.email.value == '' && (!document.addForm.email.value.match( /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) || document.addForm.email.value.match(/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/))){
		document.addForm.email.focus();
		document.addForm.email.select();
		alert('กรุณากรอก "อีเมล์" ให้ถูกต้องด้วยค่ะ');
	}else if(document.addForm.address.value == ''){
		document.addForm.address.focus();
		alert('กรุณากรอก "ที่ตั้ง เลขที่ หมู่ี่" ด้วยค่ะ');
	}else if(document.addForm.soi.value == '' && document.addForm.road.value ==""){
		document.addForm.soi.focus();
		alert('กรุณากรอก "ซอย หรือ ถนน" ด้วยค่ะ');
	}else if(document.addForm.kwang.value == ''){
		document.addForm.kwang.focus();
		alert('กรุณากรอก "แขวง/ตำบล" ด้วยค่ะ');
	}else if(document.addForm.ket.value == ''){
		document.addForm.ket.focus();
		alert('กรุณากรอก "เขต/อำเภอ" ด้วยค่ะ');
	}else if(document.addForm.post.value == '' || document.addForm.post.value.length<5){
		document.addForm.post.focus();
		document.addForm.post.select();
		alert('กรุณากรอก "รหัสไปรษณีย์" ด้วยค่ะ');
	}else if(document.addForm.internet_unit[1].selected && document.addForm.internet_price.value == '' && document.addForm.internet_validation[0].checked){
		document.addForm.internet_price.focus();
		alert('กรุณากรอก  "ค่าใช้ของอินเตอร์ด้วยค่ะ" ด้วยค่ะ');
	}else if((document.addForm.telephone_unit[0].selected || document.addForm.telephone_unit[1].selected) && document.addForm.telephone_price.value == '' && document.addForm.telephone_validation[0].checked){
		document.addForm.telephone_price.focus();
		alert('กรุณากรอก  "ค่าใข้จ่ายของการใช้โทรศัพท์" ด้วยค่ะ');
	}else if(document.addForm.bus[0].checked && document.addForm.bus_num.value.length == 0){
		document.addForm.bus_num.focus();
		alert('กรุณากรอก "สายรถเมล์" ด้วยค่ะ');
	}else{
		document.addForm.submit();
	}
}

function tologinForm(){
	document.loginForm.username.focus();
}


function checklsize(){
	if(document.addForm.l_size.value.length == 0){
		document.addForm.u_size.disabled = true;
		document.addForm.u_size.value = '';
	}
	if(document.addForm.l_size.value.length > 0){
		document.addForm.u_size.disabled = false;
	}
	if(!document.addForm.l_size.value.match(/^([0-9]{1,4}((\.)[0-9]{1,2})?)?$/) && !document.addForm.l_size.value.length == 0){
		alert('กรุณากรอก "ขนาด" เฉพาะตัวเลขค่ะ');
		document.addForm.l_size.value = '';
		document.addForm.u_size.disabled = true;
		document.addForm.u_size.value = '';
	}
}
function checkusize(){
	
	
	if(!document.addForm.u_size.value.match(/^([0-9]{1,4}((\.)[0-9]{1,2})?)?$/) && !document.addForm.u_size.value.length == 0){
	//if(document.addForm.u_size.value.match(/[^0-9]/)){
		alert('กรุณากรอก  "ขนาด" เฉพาะตัวเลขคุ่ะ');
		document.addForm.u_size.value = '';
	}
}

function waterpricecheck(){
	if(!document.addForm.water_price.value.match(/^[0-9]{1,2}((\.)(5|50|25|75))?$/) && !document.addForm.water_price.value.length == 0){
		alert('กรุณากรอก "ราคาน้ำประปา บาท/หน่วย" ให้ถูกต้องค่ะ');
		document.addForm.water_price.value = '';
	}
}
function electricpricecheck(){
	if(!document.addForm.electric_price.value.match(/^[0-9]{1,2}((\.)(5|50|25|75))?$/) && !document.addForm.electric_price.value.length == 0){
		alert('กรุณากรอก "ราคาไฟ้ฟ้า บาท/หน่วย" ให้ถูกต้องค่ะ');
		document.addForm.electric_price.value = '';
	}
}
function telcheck(){
	if(document.addForm.tel.value.match(/[^0-9]/)){
		alert('กรุณากรอก "เบอร์โทรศัพท์" เฉพาะตัวเลขค่ะ');
		document.addForm.tel.value = '';
	}
}
function cellphonecheck(){
	if(document.addForm.cellphone.value.match(/[^0-9]/)){
		alert('กรุณากรอก "เบอร์โทรศัพท์มือถือ" เฉพาะตัวเลขค่ะ');
		document.addForm.cellphone.value = '';
	}
}
function faxcheck(){
	if(document.addForm.fax.value.match(/[^0-9]/)){
		alert('กรุณากรอก "เบอร์แฟกซ์" เฉพาะตัวเลขค่ะ');
		document.addForm.fax.value = '';
	}
}
function postcheck(){
	if(document.addForm.post.value.match(/[^0-9]/)){
		alert('กรุณากรอก "รหัสไปรษณีย์" เฉพาะตัวเลขค่ะ');
		document.addForm.post.value = '';
	}
}
function internetpricecheck(){
	if(document.addForm.internet_price.value.match(/[^0-9]/) && document.addForm.internet_unit[1].selected){
		alert('กรุณากรอก "ค่าอินเตอร์เน็ต" เฉพาะตัวเลขค่ะ');
		document.addForm.internet_price.value = '';
	}
	if(document.addForm.internet_price.value.length>3 && document.addForm.internet_unit[1].selected){
		document.addForm.internet_price.value = document.addForm.internet_price.value.substring(0,3);
	}
}
function telephonepricecheck(){
	if(!document.addForm.telephone_price.value.match(/^[0-9]{1,2}((\.)(50|25|75))?$/) && (document.addForm.telephone_unit[0].selected || document.addForm.telephone_unit[1].selected) && !document.addForm.telephone_price.value.length == 0){
		alert('กรุณากรอก "ค่าโทรศัพท์" เฉพาะตัวเลขค่ะ');
		document.addForm.telephone_price.value = '';
	}
	//if(document.addForm.telephone_price.value.length>5 && (document.addForm.telephone_unit[0].selected || document.addForm.telephone_unit[1].selected)){
		//document.addForm.telephone_price.value = document.addForm.telephone_price.value.substring(0,5);
	//}
}

function detailcheck(){
	if(document.addForm.detail.value.length > 2048){
		document.addForm.detail.value = document.addForm.detail.value.substring(0,2048);
	}else{
		document.addForm.detail_limit.value = 2048-document.addForm.detail.value.length;
	}
}
function buscheck(){
	if(document.addForm.bus[0].checked){
		document.addForm.bus_num.disabled = false;
	}else{
		document.addForm.bus_num.value ='';
		document.addForm.bus_num.disabled = true;
	}
}
/*
function universitycheck(){
	if(document.addForm.university_validation[0].checked){
		document.addForm.university_name.disabled = false;
	}else{
		document.addForm.university_name[0].selected = true;
		document.addForm.university_name.disabled = true;
		document.addForm.university_range.disabled = true;
		document.addForm.university_range.value = "";
	}
	if(!document.addForm.university_name[0].selected){
		document.addForm.university_range.disabled = false;
	}else{
		document.addForm.university_range.disabled = true;
		document.addForm.university_range.value = "";
	}
}
function universityrange(form){
	if(!form.value.match(/^[0-9]*$/)){
		form.focus();
		form.value = "";
		alert("กรุณากรอกระยะทางที่พักกับมหาวิทยาลัยเฉพาะตัวเลขค่ะ");
	}	
}*/


function gpscheck(form){
	if(!form.value.match(/^[0-9]*$/)){
		form.focus();
		alert("กรุณากรอกเฉพาะตัวเลขค่ะ");
		form.value = "";
	}
}
function gpscheck2(form){
	if(!form.value.match(/^([0-9]{1,2}((\.)[0-9]{1,2})?)?$/) && !form.value.length == 0){
		form.focus();
		form.value = "";
		alert("กรุณากรอกเฉพาะตัวเลขค่ะ เช่น 12.25 หรือ  12");;
	}
}
/*
function btscheck(){
	if(document.addForm.bts[0].checked){
		document.addForm.bts_name.disabled = false;
	}
	if(document.addForm.bts[1].checked){
		document.addForm.bts_name.disabled = true;
		document.addForm.bts_name[0].selected = true;
		document.addForm.bts_range.value = "";
		document.addForm.bts_range.disabled = true;
	}
	if(!document.addForm.bts_name[0].selected){
		document.addForm.bts_range.disabled = false;
	}
}
function btsrange(){
	if(!document.addForm.bts_range.value.match(/^[0-9]*$/)){
		document.addForm.bts_range.value = '';
		document.addForm.bts_range.focus();
		alert('กรุณากรอก"ระยะทางระหว่างที่พักกับสถานีรถไฟฟ้า"เฉพาะตัวเลขค่ะ');
	}	
}
function mtrcheck(){
	if(document.addForm.mtr[0].checked){
		document.addForm.mtr_name.disabled = false;
	}
	if(document.addForm.mtr[1].checked){
		document.addForm.mtr_name.disabled = true;
		document.addForm.mtr_name[0].selected = true;
		document.addForm.mtr_range.value = "";
		document.addForm.mtr_range.disabled = true;
	}
	if(!document.addForm.mtr_name[0].selected){
		document.addForm.mtr_range.disabled = false;
	}
}
function mtrrange(){
 	if(!document.addForm.mtr_range.value.match(/^[0-9]*$/)){
		document.addForm.mtr_range.value = '';
		document.addForm.mtr_range.focus();
		alert('กรุณากรอก"ระยะทางระหว่างที่พักกับสถานีรถไฟฟ้า"เฉพาะตัวเลขค่ะ');
	}
}
*/


function month_disable(){
	document.addForm.l_m_price.disabled = true;
	document.addForm.l_m_price.value = "";
	document.addForm.u_m_price.disabled = true;
	document.addForm.u_m_price.value = "";
	document.addForm.l_insurance.disabled = true;
	document.addForm.l_insurance.value = "";
	document.addForm.u_insurance.disabled = true;
	document.addForm.u_insurance.value = "";
	document.addForm.m_roomstatus[0].disabled = true;
	document.addForm.m_roomstatus[1].disabled = true;
	document.addForm.m_roomstatus[1].checked = true;
}
function month_enable(){
	document.addForm.l_m_price.disabled = false;
	document.addForm.l_insurance.disabled = false;
	document.addForm.m_roomstatus[0].disabled = false;
	document.addForm.m_roomstatus[1].disabled = false;
	document.addForm.m_roomstatus[0].checked = true;
}
function lmprice(){
	if(document.addForm.l_m_price.value.length > 0){
		document.addForm.u_m_price.disabled = false;
	}else{
		document.addForm.u_m_price.disabled = true;
		document.addForm.u_m_price.value = "";
	}
	if(!document.addForm.l_m_price.value.match(/^[0-9]*$/)){
		alert("กรุณากรอกราคาเฉพาะตัวเลขค่ะ");
		document.addForm.l_m_price.value = "";
		document.addForm.l_m_price.focus();
		document.addForm.u_m_price.disabled = true;
		document.addForm.u_m_price.value = "";
	}
	
}
function umprice(){
	if(!document.addForm.u_m_price.value.match(/^[0-9]*$/)){
		alert("กรุณากรอกราคาเฉพาะตัวเลขค่ะ");
		document.addForm.u_m_price.value = "";
		document.addForm.u_m_price.focus();
	}
}
function linsurance(){
	if(document.addForm.l_insurance.value.length > 0){
		document.addForm.u_insurance.disabled = false;
	}else{
		document.addForm.u_insurance.disabled = true;
		document.addForm.u_insurance.value = "";
	}
	if(!document.addForm.l_insurance.value.match(/^[0-9]*$/)){
		alert("กรุณากรอกเงินประกันเฉพาะตัวเลขค่ะ");
		document.addForm.l_insurance.value = "";
		document.addForm.l_insurance.focus();
		document.addForm.u_insurance.disabled = true;
		document.addForm.u_insurance.value = "";
	}
}
function uinsurance(){
	if(!document.addForm.u_insurance.value.match(/^[0-9]*$/)){
		alert("กรุณากรอกเงินประกันเฉพาะตัวเลขค่ะ");
		document.addForm.u_insurance.value = "";
		document.addForm.u_insurance.focus();
	}
}
function day_disable(){
	document.addForm.l_d_price.disabled = true;
	document.addForm.l_d_price.value = "";
	document.addForm.u_d_price.disabled = true;
	document.addForm.u_d_price.value = "";
	document.addForm.d_roomstatus[0].disabled = true;
	document.addForm.d_roomstatus[1].disabled = true;
	document.addForm.d_roomstatus[1].checked = true; 
}
function day_enable(){
	document.addForm.l_d_price.disabled = false;
	document.addForm.d_roomstatus[0].disabled = false;
	document.addForm.d_roomstatus[1].disabled = false;
	document.addForm.d_roomstatus[0].checked = true;
}
function ldprice(){
	if(document.addForm.l_d_price.value.length > 0){
		document.addForm.u_d_price.disabled = false;
	}else{
		document.addForm.u_d_price.disabled = true;
		document.addForm.u_d_price.value = "";
	}
	if(!document.addForm.l_d_price.value.match(/^[0-9]*$/)){
		alert("กรุณากรอกราคาเฉพาะตัวเลขค่ะ");
		document.addForm.l_d_price.value = "";
		document.addForm.l_d_price.focus();
		document.addForm.u_d_price.disabled = true;
		document.addForm.u_d_price.value = "";
	}	
}
function udprice(){
	if(!document.addForm.u_d_price.value.match(/^[0-9]*$/)){
		alert("กรุณากรอกราคาเฉพาะตัวเลขค่ะ");
		document.addForm.u_d_price.value = "";
		document.addForm.u_d_price.focus();
	}
}

















/*function blocking(nr){
	document.getElementById(nr).style.display = 'block';
	//document.getElementById(nr).style.visibility = 'visible';
}
function blocking2(nr){
	document.getElementById(nr).style.display = 'none';
	//document.getElementById(nr).style.visibility = 'hidden';
}*/
