/*///////////////function popup/////////////////////*/	
var win=null;
function NewWindow(mypage,myname,w,h,pos,scrollbars,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars="+scrollbars+",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();}
/*///////////////end/////////////////////*/	

/*///////////////function jumpmenu/////////////////////*/	
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
/*///////////////end/////////////////////*/

/*///////////////function checkbox all/////////////////////*/	
function SetAllCheckBoxes(FormName, FieldName, CheckValue) {
     if (!document.forms[FormName]) return;
     var objCheckBoxes = document.forms[FormName].elements[FieldName];
     if (!objCheckBoxes) return;
     var countCheckBoxes = objCheckBoxes.length;
     if (!countCheckBoxes) objCheckBoxes.checked = CheckValue;
     else // เลือกเชคบ๊อกทั้งหมดตามที่กำหนดมา          
          for(var n = 0; n < countCheckBoxes; n++)
               objCheckBoxes[n].checked = CheckValue;
}
/*///////////////end/////////////////////*/	
/*///////////////function ลบ field/////////////////////*/	
	var oBuffer=new FieldBuffer();
	
	function FieldBuffer() {
		FieldBuffer.prototype.BufferForm=fnBufferForm;
		FieldBuffer.prototype.RestoreForm=fnRestoreForm;
		FieldBuffer.prototype.ClearFileFields=fnClearFileFields
		arrEls=new Array;		
		hshEls={};
		function fnBufferForm(oFrm) {
			oEls=oFrm.elements;
			for (i=0;i<oEls.length;i++) {
				arrEls[i]=new Element(oEls[i]);
			}
		}
		function fnRestoreForm(oFrm) {
			for (i=0;i<arrEls.length;i++) {
				oEl=arrEls[i];
				if (oEl.BufferThis)
					oEl.SetValue();
			}
		}
		function fnClearFileFields(oFrm) {
			this.BufferForm(oFrm);
			oFrm.reset();
			this.RestoreForm(oFrm);
		}
		function Element(oEl) {
			Element.prototype.SetValue=fnSetValue;
			this.Type=oEl.type;
			this.ObjRef=oEl;
			this.Required=false;
			this.CommonName='';
			switch(this.Type) {
				case 'select-one':
					this.Value=oEl.selectedIndex;
					this.BufferThis=true;
					break;
				case 'checkbox':
				case 'radio':
					this.Value=oEl.checked;
					this.BufferThis=true;
					break;
				case 'textarea':
				case 'text':
				case 'password':
				case 'hidden':
					this.Value=oEl.value;
					this.BufferThis=true;
					break;
				default:
					this.BufferThis=false;
			}
			function fnSetValue() {
				switch(this.Type) {
					case 'select-one':
						this.ObjRef.selectedIndex=this.Value;
						break;
					case 'checkbox':
					case 'radio':
						this.ObjRef.checked=this.Value;
						break;
					case 'textarea':
					case 'text':
					case 'password':
					case 'hidden':
						this.ObjRef.value=this.Value;
						break;
				}
			}
		}
	}
/*///////////////end/////////////////////*/		
/*///////////////function ตรวจสอบไฟล์รูป/////////////////////*/	
var fileTypes=["jpg","jpeg","gif"];

function checkfile(form,what){
  var source=what.value;
  var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
  for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
  globalPic=new Image();
  if (i<fileTypes.length) globalPic.src=source;

  else {
		alert("กรุณาเลือกรูปที่ท่านต้องการ หรือปล่อยว่างไว้\nไฟล์ที่สามารถใส่ได้คือ \n\n"+fileTypes.join(", "));
		oBuffer.ClearFileFields(form);
		return false;
  }
}
/*///////////////end/////////////////////*/	

function check_form_login(){

	if(document.form_login.check[0].checked == false && document.form_login.check[1].checked == false ){
		alert('กรุณาเลือกประเภทในการเข้าสู่ระบบ\n - ข้อมูลส่วนตัว เป็นการเข้าไปแก้ไขข้อมูลส่วนตัว และประวัติการสั่งซื้อ\n - การจัดการร้าน เป็นส่วนที่ใช้ในการจัดการร้านค้าของท่าน');
		return false;
	}else{
		return true;	
	}

}

function dis(f,m){
	var total;
	//alert(m);
	total = m*f.value/100;
	document.product_do.ProductPriceDiscount.value = m-total;
}

function button_over(btn) {
     btn.className="hover";
}

function button_out(btn) {
     btn.className="button";
}

function button_click(url) {
     window:parent.location= url;
}

function button_click_img(tem) {
	
 // var maxWidth=248;
//  var maxHeight=191;
  var outImage="previewField";
   var temPic=tem;

var field = document.getElementById(outImage);
 field.src = temPic;
}

function button_click_img1(tem,fieldimg) {
	
 // var maxWidth=248;
//  var maxHeight=191;
  var outImage= fieldimg;
   var temPic=tem;

var field = document.getElementById(outImage);
 field.src = temPic;
 //alert(field.src);
}


function SetAllCheckBoxes_ck(FormName, FieldName, CheckValue, OutName) {

     if (!document.forms[FormName]) return;
     var objCheckBoxes = document.forms[FormName].elements[FieldName];
	  var objOutBoxes = document.forms[FormName].elements[OutName];
     if (!objCheckBoxes) return;
     var countCheckBoxes = objCheckBoxes.length;
     if (!countCheckBoxes){
		 if(objCheckBoxes.checked == true){
		  	objOutBoxes.value = 1;
			}else{
				objOutBoxes.value = 0;
			}
	 }
     else // เลือกเชคบ๊อกทั้งหมดตามที่กำหนดมา          
          for(var n = 0; n < countCheckBoxes; n++)
			// alert(objCheckBoxes[n].checked);
			if(objCheckBoxes[n].checked == true){
		  	objOutBoxes[n].value = 1;
			}else{
				objOutBoxes[n].value = 0;
			}
}

function echeck(str) {
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
     alert("Invalid E-mail ID")
     return false
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     alert("Invalid E-mail ID")
     return false
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Invalid E-mail ID")
      return false
  }
   if (str.indexOf(at,(lat+1))!=-1){
      alert("Invalid E-mail ID")
      return false
   }
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert("Invalid E-mail ID")
      return false
   }
   if (str.indexOf(dot,(lat+2))==-1){
      alert("Invalid E-mail ID")
      return false
   }
   if (str.indexOf(" ")!=-1){
      alert("Invalid E-mail ID")
      return false
   }
   return true          
}

function ValidateForm(){
  var emailID=document.frmSample.txtEmail
  
  if ((emailID.value==null)||(emailID.value=="")){
    alert("Please Enter your Email ID")
    emailID.focus()
    return false
  }
  if (echeck(emailID.value)==false){
    emailID.value=""
    emailID.focus()
    return false
  }
  return true
 }
 
 ///////////////////////////
 function Inint_AJAX() {
   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;
	};

function startCallback() {
     if (req.readyState == 4) {
          if (req.status == 200) {         
               document.getElementById("content_chat").innerHTML= req.responseText; //รับค่ากลับมา และ แสดงผล
               setTimeout("doStart()", 10000); //Auto Refresh กลับมาอ่าน เวลาทุก 1 วินาที
          }
     }
}

function startCallback1() {
     if (req1.readyState == 4) {
          if (req1.status == 200) {         
               document.getElementById("content_cart").innerHTML= req1.responseText; //รับค่ากลับมา และ แสดงผล
               setTimeout("doStart1()", 10000); //Auto Refresh กลับมาอ่าน เวลาทุก 1 วินาที
          }
     }
}

function startCallback2() {
     if (req2.readyState == 4) {
          if (req2.status == 200) {         
               document.getElementById("mem_online").innerHTML= req2.responseText; //รับค่ากลับมา และ แสดงผล
               setTimeout("doStart2()", 10000); //Auto Refresh กลับมาอ่าน เวลาทุก 1 วินาที
          }
     }
}

function startCallback3() {
	
     if (req3.readyState == 4) {
		
          if (req3.status == 200) {  
		  alert("test");
               document.getElementById("online").innerHTML= req3.responseText; //รับค่ากลับมา และ แสดงผล
               setTimeout("doStart3()", 10000); //Auto Refresh กลับมาอ่าน เวลาทุก 1 วินาที
          }
     }
}
function doStart() {
     req = Inint_AJAX();
     var url = "status_chat.php";
     req.open("GET", url, true);
     req.onreadystatechange = startCallback; //กำหนด ฟังก์ชั่นเพื่อส่งค่ากลับ
     req.send(null);
};

function doStart1() {
     req1 = Inint_AJAX();
     var url1 = "status_cart.php";
     req1.open("GET", url1, true);
     req1.onreadystatechange = startCallback1; //กำหนด ฟังก์ชั่นเพื่อส่งค่ากลับ
     req1.send(null);
};

function doStart2() {
     req2 = Inint_AJAX();
     var url2 = "mem_online.php";
     req2.open("GET", url2, true);
     req2.onreadystatechange = startCallback2; //กำหนด ฟังก์ชั่นเพื่อส่งค่ากลับ
     req2.send(null);
};
function doStart3() {

     req3 = Inint_AJAX();
     var url3 = "onlifffgne.php";
	 
     req3.open("GET", "mem_online.php",true);
	
     req3.onreadystatechange = startCallback3; //กำหนด ฟังก์ชั่นเพื่อส่งค่ากลับ
	 
     req3.send(null);
	  
};

///////////////////////////	