function addList() 
{
	//alert('submit');
	document.forms["frmAddlist"].submit();
}

function addPhone() 
{
	//alert('submit');
	document.forms["frmAddPhone"].submit();
}

function editPhone() 
{
	//alert('submit');
	document.forms["frmeditPhone"].submit();
}
/** Add SMS Draft **/
function addsmsDraft() 
{
	//alert('submit');
	document.forms["frmAddDraft"].submit();
}
function addEmailSubject() 
{
	//alert('submit');
	document.forms["frmAddDraft"].submit();
}

/** Edit SMS Draft **/
function editsmsDraft() 
{
	//alert('submit');
	document.forms["frmeditDraft"].submit();
}
function editEmailSubject() 
{
	//alert('submit');
	document.forms["frmeditDraft"].submit();
}


function returnexport()
{
	//alert("dd");
	document.forms["export"].submit();
}


function CustomerSubmit(seatZone, seatNo) 
{
	if(document.frm['name'].value.length==0){
			alert("กรุณาระบุชื่อ-สกุล ของลูกค้าค่ะ");
			document.getElementById('name').focus();
	}else	if(document.frm['seat_zone'].value.length==0&&document.frm['seat_no'].value.length==0){
			alert("กรุณาระบุที่บล็อกที่นั่ง ของลูกค้าค่ะ");
			document.getElementById('seat_zone').focus();
	}else	if(document.frm['seat_zone'].value.length>0&&document.frm['seat_no'].value.length!=2){
			alert("กรุณาระบุทีเลขที่นั่ง  2 หลักค่ะ");
			document.getElementById('seat_no').focus();
	}else	if(document.frm['address'].value.length==0){
			alert("กรุณาระบุ ที่อยู่ ของลูกค้าค่ะ");
			document.getElementById('address').focus();
	}else	if(document.frm['sex'].value.length==0){
			alert("กรุณาระบุเพศ ของลูกค้าค่ะ");
			document.getElementById('sex').focus();

	}else	if(document.frm['province'].value.length==0){
			alert("กรุณาระบุจังหวัด ของลูกค้าค่ะ");
			document.getElementById('province').focus();
	}else	if(document.frm['hdnMaxLine'].value==0){
			alert("กรุณาระบุ หมายเลขโทรศัพท์ ของลูกค้าค่ะ");
			return false;
	}else	if(document.frm['hdnMaxLineEmail'].value==0){
			alert("กรุณาระบุ อีเมล์ ของลูกค้าค่ะ");
			return false;

	}else	if(document.frm['customer_type'].value.length==0){
			alert("กรุณาเลือกประเภทลูกค้าค่ะ");
			document.getElementById('customer_type').focus();
	
	}else	if(document.frm['groupmain'].value.length==0){
			alert("กรุณาเลือกกลุ่มลูกค้าหลักค่ะ");
			document.getElementById('groupmain').focus();

	}else	if(document.frm['groupsub'].value.length==0){
			alert("กรุณาเลือกกลุ่มลูกค้ารองค่ะ");
			document.getElementById('groupsub').focus();
	
	}else	if(document.frm['groupzone'].value.length==0){
			alert("กรุณาเลือกเขตลูกค้าค่ะ");
			document.getElementById('groupzone').focus();
	}else	if(document.frm['groupzone'].value.length==0){
			alert("กรุณาเลือกเขตลูกค้าค่ะ");
			document.getElementById('groupzone').focus();

	}else if(valit_seat(seatZone, seatNo)==false){
		document.getElementById('seat_zone').focus();
		return false;
	}
	

}

/** A */
function valit_seat(seatZone, seatNo)
{
	uri = '/customer/valid_seat/'+seatZone+'/'+seatNo;

	//alert(uri);

	//id = 'display-list';
	dojo.xhrPost({
		url: uri,
		handleAs: 'text',
		handle: function(data) {
			
	//	alert(data);

			if(data =="Again") {
				alert("เลขที่บล็อกและที่นั่งซ้ำค่ะ กรุณาใส่อีกครั้ง");
				document.getElementById('seat_zone').focus();
				return false;

			}else{

				if(confirm('ต้องการบันทึกใช่หรือไม่')==true)
					{
						document.forms["frm"].submit();
					}
				return true;
			}
		}

	});

}

function RegisterMember()
{

	if(document.frm['name'].value.length==0){
			alert("กรุณาระบุชื่อ-สกุล ของลูกค้าค่ะ");
			document.getElementById('name').focus();
	}else	if(document.frm['address'].value.length==0){
			alert("กรุณาระบุ ที่อยู่ ของลูกค้าค่ะ");
			document.getElementById('address').focus();

	}else	if(document.frm['sex'].value.length==0){
			alert("กรุณาระบุเพศ ของลูกค้าค่ะ");
			document.getElementById('sex').focus();

	}else	if(document.frm['province'].value.length==0){
			alert("กรุณาระบุจังหวัด ของลูกค้าค่ะ");
			document.getElementById('province').focus();
	}else	if(document.frm['hdnMaxLine'].value==0){
			alert("กรุณาระบุ หมายเลขโทรศัพท์ ของลูกค้าค่ะ");
			return false;
	}else	if(document.frm['hdnMaxLineEmail'].value==0){
			alert("กรุณาระบุ อีเมล์ ของลูกค้าค่ะ");
			return false;

	}else	if(document.frm['customer_type'].value.length==0){
			alert("กรุณาเลือกประเภทลูกค้าค่ะ");
			document.getElementById('customer_type').focus();
	
	}else	if(document.frm['groupmain'].value.length==0){
			alert("กรุณาเลือกกลุ่มลูกค้าหลักค่ะ");
			document.getElementById('groupmain').focus();

	}else	if(document.frm['groupsub'].value.length==0){
			alert("กรุณาเลือกกลุ่มลูกค้ารองค่ะ");
			document.getElementById('groupsub').focus();
	
	}else	if(document.frm['groupzone'].value.length==0){
			alert("กรุณาเลือกเขตลูกค้าค่ะ");
			document.getElementById('groupzone').focus();
	}else{
		if(confirm('ต้องการบันทึกใช่หรือไม่')==true)
		{
			document.forms["frm"].submit();
		}
	}
}


function Confirm_note()
{

	if(document.frmnote['wholetext'].value.length==0){
			alert("กรุณาระบุรายละเอียด");
			//document.frm['cusid'].value.focus();
			document.getElementById('wholetext').focus();

	}else	if(document.frmnote['point'].value.length==0){
			alert("กรุณาระบุคะแนน");
			document.getElementById('point').focus();
	}else	if(isNaN(document.frmnote.point.value))
		 {
			alert('กรุณาระบุคะแนนเป็นตัวเลขเท่านั้น');
			return false;
	}else{
			if(confirm('ต้องการบันทึกใช่หรือไม่')==true)
				{
					document.forms["frmnote"].submit();
				}
	}
}

function confirm_upload()
{
	if(document.getElementById('userfile').value=='')
	{
		alert('เลือกไฟล์ที่ต้องการอัพโหลดด้วยคะ');
		document.getElementById('userfile').focus();
		return false;

	}else{

		var fty=new Array(".xls"); // ประเภทไฟล์ที่อนุญาตให้อัพโหลด     
			var a=document.frm.userfile.value; //กำหนดค่าของไฟล์ใหกับตัวแปร a     
			var permiss=0; // เงื่อนไขไฟล์อนุญาต  
			a=a.toLowerCase();      
			if(a !=""){  
				for(i=0;i<fty.length;i++){ // วน Loop ตรวจสอบไฟล์ที่อนุญาต     
					if(a.lastIndexOf(fty[i])>=0){  // เงื่อนไขไฟล์ที่อนุญาต     
						permiss=1;  
						break;  
					}else{  
						continue;  
					}  
				}    
				if(permiss==0){   
					alert("อัพโหลดได้เฉพาะไฟล์ .xls เท่านั้น");       
					return false;                 
				}else{
				
					if(confirm('คุณต้องการอัพโหลดใช่หรือไม่')==true)
					{
						document.forms["frm"].submit();
					}
				}         
			} 
	}

}



/** Select All Check **/
checked = false;
function checkedAll(frmId) {
	var frm = document.getElementById(frmId);
	
	if(checked == false){ checked = true}
	else{checked = false}

	for (var i =0; i < frm.elements.length; i++) {
		frm.elements[i].checked = checked;
	}
}

function changeStatus(num)
{
 elem = dojo.byId("arrow"+num);
 //path = 'http://new007.rasabutr.com/cms/public/img/icon/';
 path = 'http://localhost/cms/public/img/icon/';

 if(elem.src == path+'resultset_down.png') {
	elem.src = path+'resultset_up.png';
	dojo.byId('nav-msg-body'+num).className = '';
 } else {
	elem.src = path+'resultset_down.png';
	dojo.byId('nav-msg-body'+num).className = 'hide';
 }
}

function del(guid){
	if(confirm('คุณต้องการลบ ? ใช่ หรือ ไม่')==true){
		window.location = '/maichailen/dinsorworks/index.php/webboard/del/'+guid;
	}else {
		window.location = 'webboard';
	}
}

var htmlText = null;
var magad;
function addElement() 
{
    if(htmlText ==null) {
        magad = parseInt(dojo.byId('total-magad').value);
        
        htmlText = '<div style="height:30px;" id="magad-'+magad+'">'+dojo.byId('magad-'+magad).innerHTML+'</div>';
        //alert(htmlText)
    }
  
    next = magad + 1;
    while(htmlText.search('magad-'+magad) >-1) {
        htmlText = htmlText.replace('magad-'+magad, 'magad-'+next);
        //alert(htmlText)
    }
    dojo.byId('fmagad-list').innerHTML += htmlText;
    dojo.byId('fmagad-'+next).value = '';
    magad = next;
}

function resetValues(id)
{
    dojo.byId(id).value = '';
}

function removeElement(id)
{
    dojo.destroy(id);
}

function confirmSubmit()
{
var agree=confirm("ต้องการนำฝากยอดเงินให้ลูกค้าใช่หรือไม่");
if (agree)
	return true ;
else
	return false ;
}

/** Onchang select menu sendsms **/
function openTime() {
	//alert(document.getElementById('eduction').value);
	if(dojo.byId('time').value == 'stime') {
		dojo.byId('stime').style.display = '';
	} else {
		dojo.byId('stime').style.display = 'none';
	}
}
