function ___jsSelectAll(obj, textid){
	var obj_arr = document.getElementById("report").getElementsByTagName("input");
	for (var i=0; i < obj_arr.length; i++){
		if(obj_arr[i].name == textid){
			obj_arr[i].checked = (obj.checked ? true:false);
		}
	}
	return true;
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function ___initKeyword(obj,epl,mout){
	var sval = new Array('Nhập tên công việc cần tìm','Nhập từ khóa cần tìm');
	if(obj.value==sval[epl]){
		obj.value='';
	}
	if(mout==true){
		if(obj.value==''){
			obj.value=sval[epl];
		}
	}
}
function ___websdesigner(show){
	var obj = document.getElementById('websdesigner');
	if(obj!=null){
		obj.style.display=(show ? 'block':'none');
	}
}
function ___choice_listbox(obj,id){
	for (var i = 0; i<obj.length; i++){
		if(obj.options[i].value==id){
			obj.options[i].selected=true;
		}	
	}
}
function ___get_listbox_id(obj){
	var str='';
	for(var i=0; i<obj.length; i++){
		str += (','+obj.options[i].value);
	}
	return ((str.length>1) ? str.substr(1, str.length-1):str);
}
function ___remove_listbox(obj) {
	if(obj!=null){
		var td = obj.length -1;
		for (td; td > -1; td--) {
			obj.options[td] = null;
		}
	}
	return true;
}
function remove_all_item(obj){
	while(obj.length != 1){
		obj.remove(1);
	}
	return true;	
}

function extract_number_on_string(str){
	for(var i=0; i<str.length; i++){
		var ch = str.charAt(i);
		if((ch>=0)&&(ch<=9))
			return str.substr(i,(str.length-i));
	}
	return 0;
}
function __previewImage(image){
	var pathlink = '../thumbnails.php?image='+image+'&width=400&height=300';
	window_open(pathlink, 400, 300, 'no', 'normal');
}
function __uploadProImage(revalto,folder,typeid){
	pathlink = 'tools/includes/proimage_upload.php?revalto='+revalto+'&folder='+folder+'&tid='+typeid;
	window_open(pathlink,300,300,'no','normal');
}	
function __uploadWindow(revalto, indext, folder){
	var pathlink = 'tools/includes/imageup.php?revalto='+revalto+'&folder='+folder;
	if(indext==false)
		pathlink = 'imageup.php?revalto='+revalto+'&folder='+folder;
	window_open(pathlink,300,300,'no','normal');
}	
function windowupload(revalto, ishtml){
	var pathlink = 'tools/includes/imageup.php?revalto='+revalto;
	if(ishtml==true)
		pathlink = 'tools/includes/htmlfilelup.php?revalto='+revalto;
	window_open(pathlink,300,300,'no','normal');
}

var priority_value=0;
function all_selection(textid){
	var obj_arr = document.getElementById("report").getElementsByTagName("input");
	for (var i=0; i < obj_arr.length; i++){
		if(obj_arr[i].name == textid){
			obj_arr[i].checked = true;
		}
	}
}
function is_selected(textid){
	var ok=false;
	var obj_arr = document.getElementById("report").getElementsByTagName("input");
	for (var i=0; i < obj_arr.length; i++){
		if((obj_arr[i].name == textid)&&(obj_arr[i].checked == true))
			return true;
	}
	return false;
}
function reset_priority_values(){
	document.frm.reset();
	priority_value = 0;
	var obj_arr = document.getElementById("report").getElementsByTagName("input");
	for (var i=0; i < obj_arr.length; i++){
		if((obj_arr[i].name == "priority[]")){
			var id = obj_arr[i].value;
			var obj = document.getElementById("priority"+id);
			if(obj.disabled == false)
				obj.disabled = true;
		}
	}
}
function default_priority_values(){
	priority_value = 0;
	var obj_arr = document.getElementById("report").getElementsByTagName("input"); //DynamicDrive.com change
	for (var i=0; i < obj_arr.length; i++){
		if(obj_arr[i].name == "priority[]"){
			var id =obj_arr[i].value; 
			document.getElementById("priority"+id).value = document.frm.total.value;
		}

		if(obj_arr[i].name == "priority[]")
			obj_arr[i].checked= false;
	}
}
function priority_selection(obj){
	var id = obj.value;
	if(obj.checked == true){
		priority_value++;
		//priority_value = document.getElementById("priority"+id).value;
		document.getElementById("priority"+id).value = priority_value;
		document.getElementById("priority"+id).disabled = false;
	}
	else{
		if(priority_value > 0)
			priority_value--;
		document.getElementById("priority"+id).value = document.frm.total.value;		
		document.getElementById("priority"+id).disabled = true;
	}	
}
function counter_selected(textid){
	var count=0;
	var obj_arr = document.getElementById("report").getElementsByTagName("input");
	for (var i=0; i < obj_arr.length; i++){
		if((obj_arr[i].name == textid)&&(obj_arr[i].checked == true))
			count++;
	}
	return count;
}
function value_priority_exits(obj){
	var pos=0;
	var msg = '';
	var dup = false;
	var obj_arr = document.getElementById("report").getElementsByTagName("input"); //DynamicDrive.com change
	for (var i=0; i < obj_arr.length; i++){
		if(obj_arr[i].name.substr(0,5) == "priority"){
			pos++;
			if((obj.name != obj_arr[i].name)&&(parseInt(obj.value)== parseInt(obj_arr[i].value))){
				msg += pos + ', ';
				dup=true;
			}
		}		
	}
	if(dup==true)
		alert(msg.substr(0,msg.length-2));
	return msg;	
}
var last_click;             // zuletzt angeklickter Button
var windows = new Array();  // Array mit Win-Objekten
function button_mouse_overme(obj){
	obj.className='mybutton_over';
}
function button_mouse_outme(obj){
	obj.className='mybutton';
}
function set_over(obj) {
   document.getElementById(obj).style.borderTopColor = "white";
   document.getElementById(obj).style.borderLeftColor = "white";
   document.getElementById(obj).style.borderBottomColor = "black";
   document.getElementById(obj).style.borderRightColor = "black";
}

function set_out(obj) {
   document.getElementById(obj).style.borderColor = "black";
}
function set_outh(obj) {
   document.getElementById(obj).style.borderColor = "ButtonFace";
}

function set_click(obj)
{
   document.getElementById(obj).style.borderTopColor = "black";
   document.getElementById(obj).style.borderLeftColor = "black";
   document.getElementById(obj).style.borderBottomColor = "white";
   document.getElementById(obj).style.borderRightColor = "white";
   elem1 = document.getElementById(last_click);
   if (elem1) elem1.style.fontWeight = "normal";
   last_click = obj;
   document.getElementById(obj).style.fontWeight = "bold";
}

function Win(ref, posx, posy) {
   this.ref  = ref;
   this.posx = posx;
   this.posy = posy;
}

function check_windows() {
   var windows_new = new Array();
   var i;
   for (i=0; i<windows.length; i++)
   {
    var found = false;
    try{
        if(!windows[i].ref.closed)
            found = true;
    }
    catch(e){
        found = false;
    }
    if (found && windows[i] && windows[i].ref && !windows[i].ref.closed) {
         windows_new.push(windows[i]);
         windows[i].ref.focus();
      }
   }
   windows = windows_new;
}

function window_open(url, w_width, w_height, scroll, type) {
   var proper;
   var posx;
   var posy;
   check_windows();
   var ind = windows.length - 1;
   if (windows[ind]) {
      posx = windows[ind].posx + 20;
      posy = windows[ind].posy + 20;
   }
   else {
      posx = (screen.width - w_width) / 2;
      posy = (screen.height - w_height) / 2 - 30;
   }
   if (type == 'resizeable')  proper = 'titlebar=no,toolbar=yes,menubar=no,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=yes,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'normal')      proper = 'titlebar=no,toolbar=no,menubar=no,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=no,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'menu')        proper = 'titlebar=no,toolbar=no,menubar=yes,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=no,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'mresizeable') proper = 'titlebar=no,toolbar=no,menubar=yes,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=yes,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'minimized')   proper = 'titlebar=no,toolbar=no,menubar=yes,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=no,left='+screen.width+',top='+screen.height+',screenX='+screen.width+',screenY='+screen.height;
   
   var win_ref;
   win_ref = window.open(url, '', proper);
   if (win_ref) {
      var tmp;
	  tmp = new Win(win_ref, posx, posy);
      windows.push(tmp);
      win_ref.focus();
   }
   return win_ref;
}

function modal_open(url, w_width, w_height, scroll, type) {
	var proper;	
   if (type == 'normal')     proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:no;scroll:'+scroll+';status:no;';
   if (type == 'resizeable') proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:yes;scroll:'+scroll+';status:no;';
   window.showModalDialog(url, window, proper);
}

function modless_open(url, w_width, w_height, scroll, type) {
	var proper;
   if (type == 'normal')     proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:no;scroll:'+scroll+';status:no;';
   if (type == 'resizeable') proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:yes;scroll:'+scroll+';status:no;';
   window.showModalDialog(url, window, proper);
}


function vntext(st)
{
var Rex = ["&#224;","&#7843;","&#227;","&#225;","&#7841;","&#259;","&#7857;","&#7859;","&#7861;","&#7855;","&#7863;","&#226;","&#7847;","&#7849;","&#7851;","&#7845;","&#7853;","&#273;","&#232;","&#7867;","&#7869;","&#233;","&#7865;","&#234;","&#7873;","&#7875;","&#7877;","&#7871;","&#7879;","&#236;","&#7881;","&#297;","&#237;","&#7883;","&#242;","&#7887;","&#245;","&#243;","&#7885;","&#244;","&#7891;","&#7893;","&#7895;","&#7889;","&#7897;","&#417;","&#7901;","&#7903;","&#7905;","&#7899;","&#7907;","&#249;","&#7911;","&#361;","&#250;","&#7909;","&#432;","&#7915;","&#7917;","&#7919;","&#7913;","&#7921;","&#7923;","&#7927;","&#7929;","&#253;","&#7925;","&#192;","&#7842;","&#195;","&#193;","&#7840;","&#258;","&#7856;","&#7858;","&#7860;","&#7854;","&#7862;","&#194;","&#7846;","&#7848;","&#7850;","&#7844;","&#7852;","&#272;","&#200;","&#7866;","&#7868;","&#201;","&#7864;","&#202;","&#7872;","&#7874;","&#7876;","&#7870;","&#7878;","&#204;","&#7880;","&#296;","&#205;","&#7882;","&#210;","&#7886;","&#213;","&#211;","&#7884;","&#212;","&#7890;","&#7892;","&#7894;","&#7888;","&#7896;","&#416;","&#7900;","&#7902;","&#7904;","&#7898;","&#7906;","&#217;","&#7910;","&#360;","&#218;","&#7908;","&#431;","&#7914;","&#7916;","&#431&#7918;","&#7920;","&#7922;","&#7926;","&#7928;","&#221;","&#7924;"]
var Req = ["224","7843","227","225","7841","259","7857","7859","7861","7855","7863","226","7847","7849","7851","7845","7853","273","232","7867","7869","233","7865","234","7873","7875","7877","7871","7879","236","7881","297","237","7883","242","7887","245","243","7885","244","7891","7893","7895","7889","7897","417","7901","7903","7905","7899","7907","249","7911","361","250","7909","432","7915","7917","7919","7913","7921","7923","7927","7929","253","7925","192","7842","195","193","7840","258","7856","7858","7860","7854","7862","194","7846","7848","7850","7844","7852","272","200","7866","7868","201","7864","202","7872","7874","7876","7870","7878","204","7880","296","205","7882","210","7886","213","211","7884","212","7890","7892","7894","7888","7896","416","7900","7902","7904","7898","7906","217","7910","360","218","7908","431","7914","7916","4317918","7920","7922","7926","7928","221","7924"]

     function replaceString(szString,szFind,szReplace){
    var iMatched, fSubstring, sSubstring;
    iMatched=0;
        while(iMatched>=0){
        iMatched=szString.indexOf(szFind);
        if(iMatched<0)
        return szString;
        fSubstring=szString.substring(0,iMatched);
        sSubstring=szString.substring(iMatched+szFind.length,szString.length);
        szString=fSubstring + szReplace + sSubstring;
    }
    // Next line for Netscape compatibility 
    //     only - no effects
    return(0);
}

var s = st
for (i=0;i<133;i++)
{

	s = replaceString(s,Rex[i],String.fromCharCode(Req[i]))
}
return s
}	
// Ham kiem tra chuoi nhap so dau cho cac Mang 

function ValidString(sText,sodau,socuoi)
{
	var ValidChars = "0123456789,";
	var IsNumber=true;
	var Char;
	// Kiem tra tinh hop le cua cac Ky tu trong chuoi
	for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
			Char = sText.charAt(i); 
			if (i == 0 && Char=="," ) // Kiem tra dau o dau chuoi
				{
					return false;
				}
					//continue;
			if (ValidChars.indexOf(Char) == -1) 
				{
					return false;
				}
       }		
// kiem tra tinh hop le cua vi tri dau cham (,) trong chuoi so, khong the co <> 3-4  chu so giua 2 dau ,
//var mang=new Array();
    var luu=sText;
	var mang=luu.split(",");
	if (mang.length>0)	
		for(i=0;i<mang.length;i++)
			{
			    if(mang[i].length>socuoi || mang[i].length <sodau)
				    return false;				
			}			

	return true;

}
//--> 
function isNumeric(str)
{	var iLen;
	iLen=str.length;
	var c ;
	for(var i=0; i<iLen; i++){	c = str.charAt(i);
		if ((c<'0') || (c>'9'))
			return false;
	}
	return true;
}
function numberInput(obj){
	var len = obj.value.length;
	obj.value = format_strnumber(obj.value);
	
	function format_strnumber(number){
		number = isNumber(resetValue(number));	
		var res='';
		var len = number.length;
		if(len <= 3)
			return number;
		else{
			var pos = len%3;
			if(pos>0)
				res += number.substr(0, pos)+'.';
			for(var i=pos; i < len; i+=3){
				res += number.substr(i, 3);
				if(i < len-3)
					res += '.';
			}
		}
		return res;
	}
	function resetValue(num){
		var str='';
		for(var i=0; i < num.length; i++){
			if(num.charAt(i) !='.')
				str += num.charAt(i);
		}
		return str;	
	}
	function isNumber(str){
		for(var i=0; i<str.length; i++){
			var c = str.charAt(i);
			if ((c<'0') || (c>'9'))
				return str.substr(0, i);
		}
		return str;
	}
}
function writeTime(s)
{
	var mydate;
	if (s)
		mydate = new Date(s);
	else
		mydate = new Date();
	
	var year = mydate.getYear()
	if (year < 1000)
		year += 1900
	var month = mydate.getMonth() + 1
	if (month < 10)
		month = "0" + month
	var day = mydate.getDate()
	if (day < 10)
		day = "0" + day

	var dayw = mydate.getDay()
	
	var hour = mydate.getHours()
	if (hour < 10)
		hour = "0" + hour
	
	var minute=mydate.getMinutes()
	if (minute < 10)
		minute = "0" + minute
	var dayarray=new Array("Ch&#7911; Nh&#7853;t","Th&#7913; Hai","Th&#7913; Ba","Th&#7913; T&#432;","Th&#7913; N&#259;m","Th&#7913; S&#225;u","Th&#7913; B&#7843;y")
	document.write(dayarray[dayw]+", "+day+"/"+month+"/"+year+",&nbsp;"+hour+":"+minute + " GMT+7")
}
function ___isnumber(obj){
	obj.value = ___number(obj.value);
}
function ___number(str){
	for(var i=0; i<str.length; i++){
		var c = str.charAt(i);
		if ((c<'0') || (c>'9'))
			return str.substr(0, i);
	}
	return str;
}
function ___email(obj){
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	return emailRegExp.test(obj.value);
}
function ___inputnumber(obj){
	obj.value = ___number(obj.value);
	if(obj.value.length==9){
		for(var i=0; i<=9; i++){
			var count=0;
			for(var j=0; j<obj.value.length; j++){
				if(obj.value.charAt(j)==i)
					count++;
			}
			if(count==obj.value.length){
				obj.value='';
				obj.focus();
				break;
			}
		}
	}
}
function ___pause(millisecondi){
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;
    while(true)  {
        now = new Date();
        if(now.getTime() > exitTime) return;
    }
}
function nl2br (str, is_xhtml) {
    breakTag = '<br />';
    if (typeof is_xhtml != 'undefined' && !is_xhtml) {
        breakTag = '<br>';
    }

    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag);
}
function brl2n (str) {
    return str.replace(/<br\s*\/?>/mg,"\n");
}
function explode( delimiter, string, limit ) {
    var emptyArray = { 0: '' };
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
  
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
  
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
  
    if ( delimiter === true ) {
        delimiter = '1';
    }
     
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}