
var js3_loadingstack = 0;
//#######################################
function js3_getHtmlByPost(myurl,myvars,updateto) {
//#######################################
	js3_loadingstack++;
	if(js3_loadingstack==1) {
		js3_loadingHandler.style.display='';
		js3_loadingHandler.effect('opacity').custom(0,1);
	}
	new ajax(myurl,{ method: 'post', postBody: myvars, onComplete: js3_getHtml_onComplete, update: updateto}).request();
}
//#######################################
function js3_getHtmlByGet(myurl,myvars,updateto) {
//#######################################
	js3_loadingstack++;
	if(js3_loadingstack==1) {
		js3_loadingHandler.style.display='';
		js3_loadingHandler.effect('opacity').custom(0,1);
	}
	new ajax(myurl+"?"+myvars,{ method: 'get', onComplete: js3_getHtml_onComplete, update: updateto}).request();
}
//#######################################
function js3_getHtml_onComplete() {
//#######################################
	js3_loadingstack--;
	if(js3_loadingstack<=0) {
		js3_loadingHandler.effect('opacity').custom(1,0);
	}
}

//#######################################
function js3_getHtmlByPost_Effect(myurl,myvars,updateto,divObj) {
//#######################################
	js3_loadingstack++;
	if(js3_loadingstack==1) {
		js3_loadingHandler.style.display='';
		js3_loadingHandler.effect('opacity').custom(0,1);
	}
	var slidereffect = new Fx.Slide(divObj, {mode: 'vertical', duration: 1500, transition:Fx.Transitions.bounceOut, wait: true }).show();
	slidereffect.toggle();
	new ajax(myurl,{ method: 'post', postBody: myvars, onComplete: function() { js3_getHtml_onComplete_Effect(slidereffect); } , update: updateto}).request();
}
//#######################################
function js3_getHtmlByGet_Effect(myurl,myvars,updateto,divObj) {
//#######################################
	js3_loadingstack++;
	if(js3_loadingstack==1) {
		js3_loadingHandler.style.display='';
		js3_loadingHandler.effect('opacity').custom(0,1);
	}
	var slidereffect = new Fx.Slide(divObj, {mode: 'vertical', duration: 1500, transition:Fx.Transitions.bounceOut, wait: true }).show();
	slidereffect.toggle();
	new ajax(myurl+"?"+myvars,{ method: 'get', onComplete: function() { js3_getHtml_onComplete_Effect(slidereffect); } , update: updateto}).request();
}
//#######################################
function js3_getHtml_onComplete_Effect(slidereffect) {
//#######################################
	js3_loadingstack--;
	if(js3_loadingstack<=0) {
		js3_loadingHandler.effect('opacity').custom(1,0);
	}
	slidereffect.toggle();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function JS3_ChainObject() {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//  AJAX Chain handle Object 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	this.fnlist = [];
	//http://localhost/akin_Engine/object/obj_ecard/obj_something_browser.php?id=&menu_id=7
	this.fntype = [];
	this.addChain_AJAX = function (fn) {  
		this.fnlist.push(fn);
		this.fntype.push('AJAX');		
	}
	this.addChain_Function = function (fn) {  
		this.fnlist.push(fn);
		this.fntype.push('Function');		
	}
	this.callChain = function () {
		if(this.fnlist.length) {
			this.fnlist.splice(0, 1)[0].call();
			if(this.fntype.splice(0, 1)[0]=='Function') {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function js3_callAJAXChain() {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	while(js3_chain.callChain());
}
var js3_chain = new JS3_ChainObject();


//=== ตรวจสอบความแข็งแรงของรหัสผ่าน
function passwordChanged(id,pass) {
//=============================
	var strength = document.getElementById(id);
	var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
	var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
	var enoughRegex = new RegExp("(?=.{6,}).*", "g");
	var pwd = document.getElementById(pass);
	if (pwd.value.length==0) {
	strength.innerHTML = "กรุณาพิมพ์รหัสผ่าน";
	} else if (false == enoughRegex.test(pwd.value)) {
	strength.innerHTML = "พิมพ์รหัสผ่านอย่างน้อย 6 ตัวอักษร";
	} else if (strongRegex.test(pwd.value)) {
	strength.innerHTML = "<span style='color:green'>ยอดเยี่ยม!</span>";
	} else if (mediumRegex.test(pwd.value)) {
	strength.innerHTML = "<span style='color:orange'>ปานกลาง!</span>";
	} else {
	strength.innerHTML = "<span style='color:red'>น้อย!</span>";
	}
/**/
}

function CheckNumericKeyInfo($char, $mozChar) {
 if($mozChar != null) { // Look for a Mozilla-compatible browser
 if(($mozChar >= 48 && $mozChar <= 57) || $mozChar == 0 || $char == 8 || $mozChar == 13) $RetVal = true;
 else {
 $RetVal = false;
// alert('Please enter a numeric value.');
 }
 }
 else { // Must be an IE-compatible Browser
 if(($char >= 48 && $char <= 57) || $char == 13) $RetVal = true;
 else {
 $RetVal = false;
 //alert('Please enter a numeric value.');
 }
 }
 return $RetVal;
 }

function CheckNumericKeyDomain($char, $mozChar) {
 if($mozChar != null) { // Look for a Mozilla-compatible browser
 if(($mozChar >= 48 && $mozChar <= 57) || ($mozChar >=97 && $mozChar <= 122 ) || $mozChar == 45 || $mozChar == 0 || $char == 8 || $mozChar == 13) $RetVal = true;
 else {
 $RetVal = false;
 }
 }
 else { // Must be an IE-compatible Browser
 if(($char >= 48 && $char <= 57) || ($char >=97 && $char <= 122 ) || $char == 45 || $char == 13) $RetVal = true;
 else {
 $RetVal = false;
 }
 }
 return $RetVal;
 }

function numbersonly(){
    var c=allEve(e).key;
    // do something with c;
	alert(c);
	 if (c<48||c>57)
	  return false;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_ajax_SortingMoveUp(myListObj) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	var Len = $(myListObj).options.length;
	var tmpID,tmpValue;
	if(Len>0) 
	{
		for(var i=1;i<Len;i++)
		{
	    	if ($(myListObj).options[i]!=null && $(myListObj).options[i].selected==true) {
					if(!$(myListObj).options[i-1].selected) {
					   $(myListObj).options[i].selected=false;
					   tmpID = $(myListObj).options[i].value;
					   tmpValue = $(myListObj).options[i].text;
					   $(myListObj).options[i].value = $(myListObj).options[i-1].value;
					   $(myListObj).options[i].text = $(myListObj).options[i-1].text;
					   $(myListObj).options[i-1].value = tmpID;
					   $(myListObj).options[i-1].text = tmpValue;
					   $(myListObj).options[i-1].selected=true;
				}
			}
		}
	}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_ajax_SortingMoveDown(myListObj) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	var Len = $(myListObj).options.length;
	var tmpID,tmpValue;
	if(Len>0) 
	{
		for(var i=Len-2;i>=0;i--)
		{
	    	if ($(myListObj).options[i]!=null && $(myListObj).options[i].selected==true) {
					if(!$(myListObj).options[i+1].selected) {
					   $(myListObj).options[i].selected=false;
					   tmpID = $(myListObj).options[i].value;
					   tmpValue = $(myListObj).options[i].text;
					   $(myListObj).options[i].value = $(myListObj).options[i+1].value;
					   $(myListObj).options[i].text = $(myListObj).options[i+1].text;
					   $(myListObj).options[i+1].value = tmpID;
					   $(myListObj).options[i+1].text = tmpValue;
					   $(myListObj).options[i+1].selected=true;
				}
			}
		}
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_ajax_SelectAllSorting(myListObj) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	var Len = $(myListObj).options.length;
	if(Len>0) 
	{
		for(var i=0;i<Len;i++) { 
		   $(myListObj).options[i].selected=true;
		}
	}
}

function CheckSubmitFrom($char, $mozChar) {
 if($mozChar != null) { // Look for a Mozilla-compatible browser
	 if($mozChar == 13) $RetVal = true;
	 else {
	 $RetVal = false;
	 }
 }
 else { // Must be an IE-compatible Browser
	 if($char == 13) $RetVal = true;
	 else {
	 $RetVal = false;
	 }
 }
 return $RetVal;
 }

function js_my_theme(URL){//return skin ต้นแบบ
	$('area_loading_update').style.display = '';
	var js_vars = "&action=theme_my_css";
	new ajax("../../module/system_menu/theme_process.php",{ method: 'post', postBody: js_vars, onComplete: function(responseText) { 
		//alert(responseText.trim());
		if(responseText.trim()=='OK') {
			window.location = URL;
		}
		$('area_loading_update').style.display = 'none';
	} }).request();
}

function js_update_menu_theme(URL){
	//alert(URL);
	$('area_loading_update').style.display = '';
	var js_vars = "&action=theme_process_css";
	new ajax("../../module/system_menu/theme_process.php",{ method: 'post', postBody: js_vars, onComplete: function(responseText) { 
		//alert(responseText.trim());
		if(responseText.trim()=='OK') {
			window.location = URL;
		}
		$('area_loading_update').style.display = 'none';
	} }).request();
}

function js_update_menu_font(obj){ // เปลี่ยน font ตัวอักษร
	$('area_loading_font').style.display = '';
	var js_vars = "&action=save_theme_font_size&txt_font_size="+obj.value;
	new ajax("../../module/system_menu/theme_process.php",{ method: 'post', postBody: js_vars, onComplete: function(responseText) { 
		//alert(responseText.trim());
		if(responseText.trim()=='OK') {

		} else {
			alert('Error :');
		}
		$('area_loading_font').style.display = 'none';
	} }).request();
}

// for theme content 
function js_update_content_font(obj){ // เปลี่ยน font ตัวอักษร
	$('area_loading_font').style.display = '';
	var js_vars = "&action=save_theme_content_font_size&txt_font_size="+obj.value;
	new ajax("../../module/system_menu/theme_process.php",{ method: 'post', postBody: js_vars, onComplete: function(responseText) { 
		//alert(responseText.trim());
		if(responseText.trim()=='OK') {

		} else {
			alert('Error :');
		}
		$('area_loading_font').style.display = 'none';
	} }).request();
}

function js_update_content_theme(URL){
	$('area_loading_update').style.display = '';
	var js_vars = "&action=content_process_css";
	new ajax("../../module/system_menu/theme_process.php",{ method: 'post', postBody: js_vars, onComplete: function(responseText) { 
		//alert(responseText.trim());
		if(responseText.trim()=='OK') {
			window.location = URL;
		}
		$('area_loading_update').style.display = 'none';
	} }).request();
}

function js_my_content_theme(URL){//return skin ต้นแบบ
	$('area_loading_update').style.display = '';
	var js_vars = "&action=theme_my_content_css";
	new ajax("../../module/system_menu/theme_process.php",{ method: 'post', postBody: js_vars, onComplete: function(responseText) { 
		//alert(responseText.trim());
		if(responseText.trim()=='OK') {
			window.location = URL;
		}
		$('area_loading_update').style.display = 'none';
	} }).request();
}


function js_set_menu_tranparent(obj){ // สกินเมนู โปร่งแสง
	var js_vars = "&action=save_theme_transparent&txt_tranparent="+obj.checked;
	new ajax("../../module/system_menu/theme.php",{ method: 'post', postBody: js_vars, onComplete: function(responseText) { 
		//alert(responseText.trim());
		if(responseText.trim()=='OK') {
			//js_clearAreaData('area_add_edit',Mod_Text[3]);
			//js3_getHtmlByPost('add_edit.php?menu_id='+menu_id+'&menu_toggler='+menu_toggler,'action=data_list','area_data_list');
		} else {
			//js_clearAreaData('area_add_edit',Mod_Text[0]);
		}
	} }).request();
	/**/
}