function emailonlyregis(obj){		
	if (obj.value.indexOf('@') == -1) {  
		return true;
	}else if (obj.value.indexOf('.')==-1)   {  
		return true;
	}else{
		return false;
	}		
}

function ReplaceNumberWithCommas(yourNumber) {
	var n= yourNumber.toString().split(".");
	n[0] = n[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
	return n.join(".");
}

function enumonly(e) {
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);
	//var AllowRegex  = /^[0-9-A-z]$/;
	var AllowRegex = /^([0-9]+)$/;
	if (AllowRegex.test(character)) return true;
	character.replace(/-/g,'');
	return false;
}

function emailonly(obj){		
	if (obj.value.indexOf('@') == -1) {  
		return true;
	}else if (obj.value.indexOf('.')==-1)   {  
		return true;
	}else{
		return false;
	}		
}

function chsetting(){
	var fm = document.formsetting;
	if(fm.puser.value==''){
		alert("กรุณากำหนด ชื่อเรียกเวบไซต์ ");
		return false;
	}else if(fm.puser.length<4){
		alert("กรุณากำหนด ชื่อเรียกเวบไซต์ ที่มีตัวอักษรตั้ง 4 ตัวอักษรขึ้นไป");
		return false;
	}else{
		return true;
	}
}
function chpsw(){
	var fm = document.fmchpsw;
	if(fm.ppsw.value==''){
		alert('กรุณาใส่รหัสผ่าน ของคุณ');
		fm.ppsw.focus(); 
		return false;
	}else if(fm.ppsw.value!=fm.ppsw2.value){
		alert('กรุณายืนยัน รหัสผ่าน ของคุณ');
		fm.ppsw2.focus(); 
		return false;
	}else{
		return true;
	}
}
function ckregister(){
	var fm = document.fmregister;

	if (isNaN(fm.mobile.value)) {
		alert('กรุณาใส่เบอร์โทรศัพท์มือถือ ของคุณ');
		fm.mobile.value='';
		fm.mobile.focus();
		return false;
	}else if(fm.mobile.value=='' || fm.mobile.value.length<10){
		alert('กรุณาใส่เบอร์โทรศัพท์มือถือ ของคุณ');
		fm.mobile.focus();
		return false;
	}else if(fm.ppsw.value.length<4){
		alert('กรุณาใส่รหัสผ่าน ไม่ต่ำกว่า 4 ตัวอักษร');
		fm.ppsw.focus(); 
		return false;
	}else if(fm.ppsw.value==''){
		alert('กรุณาใส่รหัสผ่าน ของคุณ');
		fm.ppsw.focus(); 
		return false;
	}else if(fm.ppsw.value!=fm.ppsw2.value){
		alert('กรุณายืนยัน รหัสผ่าน ของคุณ');
		fm.ppsw2.focus(); 
		return false;
	}else if($('#agree').prop('checked')==false){
		alert('กรุณาอ่านข้อตกลงงานใช้งาน\nและกดยอมรับเงื่อนไข ก่อนทำการลงทะเบียนใช้งาน');
		return false;
	}else{
		return true;
	}
}
function cklogin(){
	var fm = document.fmlogin;
	if (isNaN(fm.mobile.value)) {
		alert('กรุณาใส่เบอร์โทรศัพท์มือถือ ของคุณ');
		fm.mobile.value='';
		fm.mobile.focus();
		return false;
	}else if(fm.mobile.value=='' || fm.mobile.value.length<10){
		alert('กรุณาใส่เบอร์โทรศัพท์มือถือ ของคุณ');
		fm.mobile.focus(); 
		return false;
	}else if(fm.ppsw.value==''){
		alert('กรุณาใส่รหัสผ่าน ของคุณ');
		fm.ppsw.focus(); 
		return false;
	}else{
		return true;
	}
}
function ckforgot(){
	var fm = document.fmforgot;
	if(fm.mobile.value==''){ 
		alert('กรุณาใส่เบอร์โทรศัพท์มือถือ ของคุณ');
		fm.mobile.focus();
		return false;
	}else{
		return true;
	}
}  

function detectCardType(number) {
    var re = {
        electron: /^(4026|417500|4405|4508|4844|4913|4917)\d+$/,
        maestro: /^(5018|5020|5038|5612|5893|6304|6759|6761|6762|6763|0604|6390)\d+$/,
        dankort: /^(5019)\d+$/,
        interpayment: /^(636)\d+$/,
        unionpay: /^(62|88)\d+$/,
        visa: /^4[0-9]{12}(?:[0-9]{3})?$/,
        mastercard: /^5[1-5][0-9]{14}$/,
        amex: /^3[47][0-9]{13}$/,
        diners: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
        discover: /^6(?:011|5[0-9]{2})[0-9]{12}$/,
        jcb: /^(?:2131|1800|35\d{3})\d{11}$/
    }

    for(var key in re) {
        if(re[key].test(number)) {
            return key
        }
    }
}


////////////////////////////////////////// FACEBOOK ////////////////////////////////////////
function FBLogin() {
	FB.login(
		function(response) {
			if (response.authResponse) { 
			   FB.api('/me?fields=id,name,email,picture.width(800).height(800),permissions', function(response) { 
				   $.post( "/", { ac:"member-add-new", xname: response.name, xsec:'facebook', xid: response.id, xemail: response.email , xpicture: response.picture, xmemtype:$('#xmemtype').val() }).done(function( data ) { 
					  //console.log(data);
					  if(data=="OK"){
						  window.location = '/member';
					  }else{
						  window.location = '/';
					  }
				   });
			   });
			} else { 
				//window.location = '/';
			}
		},					
		{scope:'email'}
		//{scope:'email,user_birthday,user_location,user_likes'}
	);
}

function FBLogout() { 
	$.post( "/member/", { ac:"member-logout" }).done(function( data ) { 
		if(data) window.location = '/';
	}); 
}
////////////////////////////////////////// FACEBOOK ////////////////////////////////////////

		function ucheck(xac,xval){
			var fm = document.formsetting ; 

			if(xac=="usercheck" && xval){ 
				if(xval.length<4){
					alert("กรุณาเลือก ชื่อผู้ใช้ ที่มีตัวอักษรตั้ง 4 ตัวอักษรขึ้นไป");  
				}else{ 
					$("#"+xac+"load").show();
					$("#"+xac+"load").html('<i class="icon-spin5 animate-spin"></i>'); 
					$.post("action_member.php?ac="+xac+"&u="+xval, function(data) { 
						 
					if(data=="Y"){
						$("#"+xac+"load").html('<span class="text-success"><i class="icon-ok icon-success"></i> สามารถใช้ชื่อนี้ได้</span>');
					}else{ 
						alert("ขออภัย ชื่อนี้ไม่สามารถใช้งานได้ หรืออาจถูกใช้งานแล้ว กรุณาลองใหม่อีกครั้ง");
						$("#"+xac+"load").hide();
						$("#"+xac+"load").html('');
						$("#puser").val('').focus();  
					}
				}); 
		 
				}
			}
		}

$("#puser").on("input", function(){
  var regexp = /[^0-9a-zA-Z]/g;
  if($(this).val().match(regexp)){
    $(this).val( $(this).val().replace(regexp,'') );
  }
});


function copyText(namex) { 
  var copyText = document.getElementById(namex); 
  copyText.select(); 
  document.execCommand("copy"); 
  alert("ก๊อปปี้ลิงค์ เรียบร้อยแล้ว\nคุณสามารถนำไปแชร์ เพื่อโปรโมทเว็บของคุณได้ทันที\n" + copyText.value);
}