//jquery.hint.js
//jquery.hoverIntent.minfied.js

// JavaScript Document
//var _url_prefix = 'http://localhost/toow.com';
var _url_prefix = 'http://www.toow.com';

//var _file_path_path = "/toow.com/files";
var _file_path_path = "/files";

if (_url_prefix == "http://localhost/toow.com") {
	pre = "/toow.com/";
} else {
	pre = "/";
}
// JavaScript Document
var ajax_request;

var dialog_closable = true;

$(function(){ 
	// find all the input elements with title attributes
	$('input[title!=""]').hint();
});

function delconfirm()
{
	$("#errtext").html("<img src='"+_url_prefix+"/images/Circle-warning.gif' style='margin-right:10px' align='left' />ต้องการลบรายการที่เลือกใช่หรือไม่?");	
	document.chkbdel.TypeAction.value = "delete";	
	$( "#dialog-confirm" ).dialog("destroy");
	$( "#dialog-confirm" ).dialog({
		resizable: false,
		height:180,
		show: "fade",
		hide: "fade",
		modal: true,
		buttons: {
			"ตกลง": function() {
				document.chkbdel.submit();		
				return false;
			},
			"ยกเลิก": function() {
				$( this ).dialog( "destroy" );
				return false;
			}
		}
	});
	return false;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function CheckAll()  {

	for (var i=0; i < document.chkbdel.elements.length; i++)
	{
		var e = document.chkbdel.elements[i];
		if (e.name != "allchk") 
			e.checked = document.chkbdel.allchk.checked;
	}
}

function popUP(mypage, myname, w, h, scroll, titlebar)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function showmedialog(modal,callback,height) {
	if (modal==undefined)
		modal = true;
	$( "#dialog-confirm" ).dialog("destroy");
	$( "#dialog-confirm" ).dialog({
		resizable: false,
		height: height,
		show: "fade",
		hide: "fade",
		modal: modal
	});
	var options = { 
		buttons: {"ตกลง": callback} 
	};
	$('#dialog-confirm').dialog('option', options); 
}

function generalErrorCallBack() {
	$( "#dialog-confirm" ).dialog( "destroy" );
}
function generalCompleteCallBack() {
	$( "#dialog-confirm" ).dialog( "destroy" );
}

function showwaitdialog(modal) {
	if (modal==undefined)
		modal = true;
	$( "#dialog-confirm" ).dialog("destroy");
	$( "#dialog-confirm" ).dialog({
		resizable: false,
		height:90,
		modal: modal,
		show: "fade",
		hide: "fade",
		beforeClose: function(event, ui) { 
			if (dialog_closable) {
				//do nothing
			}  else {
				return false;
			}
		},
		close: function(event, ui) { 
			dialog_closable = true;		
			if (ajax_request)
				ajax_request.abort();
		}
	});
}

function ErrorDialog(err, modal, callback, height) {
	$("#errtext").html("<img src='"+_url_prefix+"/images/Circle-warning.gif' style='margin-right:10px' align='left' />"+err);
	if (callback != undefined) {
		callback = callback;
	} else {
		callback = generalErrorCallBack;
	}
	if (height != undefined) {
		height = height;
	} else {
		height = 180;
	}
	showmedialog(modal,callback,height);
}

function CompleteDialog(text, modal, callback, height ) {
	$("#errtext").html("<img src='"+_url_prefix+"/images/Circle-info.gif' style='margin-right:10px' align='left' />"+text);
	if (callback != undefined ) {
		callback = callback;
	} else {
		callback = generalCompleteCallBack;
	}	
	if (height != undefined) {
		height = height;
	} else {
		height = 180;
	}
	showmedialog(modal,callback,height);
}

function WaitDialog(modal) {
	$("#errtext").html("<img style='margin-left:70px' src='"+_url_prefix+"/images/progressbar.gif'/>");
	showwaitdialog(modal);
	$("#dialog-confirm" ).dialog( "option", "title", '<font style="font-family:Tahoma; font-size:11px; color:black">กำลังโหลดข้อมูล, กรุณารอสักครู่...</font>' );	
}


function number_format(number, decimals, dec_point, thousands_sep) {
    number = (number+'').replace(',', '').replace(' ', '');
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }    return s.join(dec);
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}
function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
}
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
}
function Trim(str){
	return LTrim(RTrim(str));
}

//jquery.hint.js
//jquery.hoverIntent.minfied.js

(function ($) {

$.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }
    
  return this.each(function () {
    // get jQuery version of 'this'
    var $input = $(this),
    
    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = $(this.form),
      $win = $(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title
      
      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

})(jQuery);

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
