
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function checkIsEmail(str) { // Add by TeeLek
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

// # Basic AJAX use Function #############################################################################
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);
	}
	js3_callAJAXChain();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function JS3_ChainObject() {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//  AJAX Chain handle Object 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	this.fnlist = [];
	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();

// # Prompt Function #############################################################################
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function JS3_Prompt() {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	this.close = function () {
		// close box
		this.box.close();
		// show all select object
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ActiveXObject ? 'select' : 'embed'));
		elements.each(function(el){ el.style.visibility = ''; });
	};
	this.show = function (wd,hi,content) {
		// hide all select object
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ActiveXObject ? 'select' : 'embed'));
		elements.each(function(el){ el.style.visibility = 'hidden'; });
		// create box
		js3_prompt_iframe_targetname = "ifname"+Math.floor(Math.random()*10000);
		this.box = new MooPrompt('myPrompt', content , js3_prompt_iframe_targetname , { buttons: 0, width: wd, height: hi });
	}; 
}
var js3_promptBox = new JS3_Prompt();
var js3_promptOnOpen = false;
var js3_prompt_iframe_targetname;

// # Paging Function #############################################################################
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_paging_CheckAll(objCheckHeader,txtCheckBoxFirstName,intTotalItems) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	if(intTotalItems>0)
		for(i=1;i<=intTotalItems;i++)
			$(txtCheckBoxFirstName+i).checked = objCheckHeader.checked;			
	return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_paging_CheckAllHandle(objCheckHeader,txtCheckBoxFirstName,intTotalItems) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	var isCheckedAll = true;
	if(intTotalItems>0)
		for(i=1;i<=intTotalItems;i++)
			if(!$(txtCheckBoxFirstName+i).checked) 
				isCheckedAll = false;
	objCheckHeader.checked = isCheckedAll;
	return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_paging_CountChecked(txtCheckBoxFirstName,intTotalItems) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	var intChecked = 0;
	if(intTotalItems>0)
		for(i=1;i<=intTotalItems;i++)
			if($(txtCheckBoxFirstName+i).checked) 
				intChecked ++;
	return intChecked ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_paging_CountSubChecked(txtCheckBoxFirstName,intTotalItems,TotalSubItemsName) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	var intChecked = 0;
	if(intTotalItems>0)
		for(i=1;i<=intTotalItems;i++)
			for(j=1;j<=$(TotalSubItemsName+i).value;j++)
				if($(txtCheckBoxFirstName+i+'_'+j).checked) 
					intChecked ++;
			if($(txtCheckBoxFirstName+i).checked) 
				intChecked ++;

	return intChecked ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_paging_GetFirstChecked(txtCheckBoxFirstName,intTotalItems) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	if(intTotalItems>0)
		for(i=1;i<=intTotalItems;i++)
			if($(txtCheckBoxFirstName+i).checked) 
				return $(txtCheckBoxFirstName+i).value;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_paging_CheckedThisItem(objCheckHeader,indexing,txtCheckBoxFirstName,intTotalItems) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	if(intTotalItems>0)
		for(i=1;i<=intTotalItems;i++)
			if(i==indexing) {
				$(txtCheckBoxFirstName+i).checked = true;
			} else {
				$(txtCheckBoxFirstName+i).checked = false;
			}
	objCheckHeader.checked = false;
	return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_setPageShow_ResizeList() {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	total = $('JS_RecordCountTotal').value*1;
	size = $('JS_PageSize').value*1;
	if(total>0) {
		maxpage = Math.ceil(total/size);
		$('JS_NoOfPage').value=maxpage;
		$('JS_PageMax').innerHTML=maxpage;
		var myListObj = $('JS_PageList');
		var Len = myListObj.options.length;
		if(Len>0) for(var i=0;i<Len;i++) if (myListObj.options[0]!=null) myListObj.options[0]=null;
		for(i=1;i<=maxpage;i++) {
			myListObj.options[myListObj.options.length] = new Option(i,i,0,false);
		}
		myListObj.value = 1;
	}
	js3_page = $('JS_Page').value*1;
	js3_maxpage = $('JS_NoOfPage').value*1;
	if(js3_page==js3_maxpage) { 	$('idGoC').style.display='none'; $('idGoD').style.display='none'; } else { $('idGoC').style.display=''; $('idGoD').style.display=''; }
	if(js3_page==1) { $('idGoA').style.display='none'; $('idGoB').style.display='none'; } else { $('idGoA').style.display=''; $('idGoB').style.display=''; }
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function mod_ajax_loadAction2Prompt(myform,myaction,mywidth,myheight) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	if(js3_promptOnOpen || js3_loadingstack>0) { // checking for js3_prompt is open or not
		return false;
	} else {
		js3_promptOnOpen = true;
		// loading blank prompt
		js3_chain.addChain_Function(function() { 
				js3_promptBox.show(mywidth,myheight,"<br><br><img src=\"/lib/mootool/ajax-loader-w.gif\" width=\"16\" height=\"16\" onClick=\"js3_promptBox.close(); \" style=\"cursor:pointer\" />");
		});
		// loading html form xxx-ajax-form.php
		js3_chain.addChain_AJAX(function() {  
				$(myform).JS_Action.value=myaction;
				var js3_filename = $(myform).JS_FileName.value;	
				var js_vars =  $(myform).toQueryString();
				js3_getHtmlByPost(js3_filename,js_vars,'idTemp');
		});
		// loading content to js3_prompt
		js3_chain.addChain_Function(function() { 
				if(js3_promptOnOpen) {
					var content = $('idTemp').innerHTML;
					$('idTemp').innerHTML='';
					$('promptContentData').innerHTML= content;
				}
		});
		return true;
	}
}

