var flag=0;
function ShowModelDialog(div)
{    
    document.getElementById(div).style.display="none";     
    document.getElementById(div).style.width=window.screen.availWidth;     
    // document.getElementById("123").style.width=window.screen.availWidth;    
    document.getElementById("123").style.height=window.screen.availHeight-100;
    
}
function ShowMenu(sObj, sClassName)
{
    var nLen = sClassName.length;
    var sClsObj = sObj.className;
    var nTmpLen = sClsObj.length;
    if (nLen==nTmpLen)
	{
		sClassName=sClassName+"Over";
	}
	sObj.className = sClassName;
}			
function ShowDiv(div,div1)
{
    var width = 326;
	var height = 282;
    var left = window.screen.availWidth/2 - width/2;
	var top = window.screen.availHeight/2 - height/2;
    //-----------------------------
    
    document.getElementById(div).style.left=left;
    document.getElementById(div).style.top=top;
    if(document.getElementById(div).style.display=="")
    {
        document.getElementById(div).style.display="none";
        document.getElementById(div1).style.display="none";
        document.getElementById(div1).style.width=0;
        }
    else
    {
        document.getElementById(div).style.display="";    
        document.getElementById(div1).style.display="";
        document.getElementById("123").style.width=window.screen.availWidth;
        document.getElementById("123").style.height=window.screen.availHeight-100;               
    }
}
function checkMail(txt)
{
	var x = document.getElementById(txt).value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
	if (filter.test(x)) 	
	    return true;
	else 
	    return false;
}

function CheckEmpty(txt1,txt2)
{
    if(document.getElementById(txt1).value=="")
    {
        alert("Chưa nhập tên đăng nhập");
        return false;
    }
    else
    if(document.getElementById(txt2).value=="")
    {
        alert("Chưa nhập địa chỉ email!");
        return false;
    }
    else
    if(!checkMail(txt2))
    {
        alert("Địa chỉ email không hợp lệ!");
        return false;
    }
    else
        return true;
}
function CheckLogin(txt1)
{
    if(document.getElementById(txt1).value=="")
    {
        alert("Chưa nhập tên đăng nhập");
        return false;
    }    
    else
        return true;
}
function CheckChangePass(txt1,txt2,txt3)
{


    if(document.getElementById(txt1).value=="")
    {
        alert("Chưa nhập mật khẩu cũ!");
        return false;
    }   
    if(document.getElementById(txt2).value=="")
    {
        alert("Chưa nhập mật khẩu mới");
        return false;
    }    
    else
    if(document.getElementById(txt1).value==document.getElementById(txt2).value ||
    document.getElementById(txt1).value.lenght>document.getElementById(txt2).value.lenght )
    {
        alert("Mật khẩu cũ và mật khẩu mới không được trùng nhau.\nMật khẩu mới phải dài hơn mật khẩu cũ!");
        return false;
    }    
    else 
    if(document.getElementById(txt2).value!=document.getElementById(txt3).value)
    {
        alert("Chưa nhập mật khẩu xác nhận, hoặc nhập chưa khớp!");
        return false;
    }  
    else
        return true;
}
//---------------------------------------------------
function DeleteItems(url)
	{
		if(confirm('Bạn thực sự muốn xóa cấu trúc này không? \nNếu xóa cấu trúc này thì tất cả các dữ liệu liên quan sẽ bị mất'))
		{			
			document.forms[0].action=url;
			document.forms[0].submit();
		}	
	}
function CheckEmpty_(txt1,txt2,txt3,txt4)
{
    if(document.getElementById(txt1).value=="")
    {
        alert("Chưa nhập tên đăng nhập");
        document.getElementById(txt1).focus();
        return false;
    }
    else
    if(document.getElementById(txt2).value!=
        document.getElementById(txt3).value)
    {
        alert("Mật khẩu xác nhận nhập chưa khớp!");
        return false;
    }
    else
    if(document.getElementById(txt4).value=="")
    {
        alert("Chưa nhập địa chỉ email.\nEmail sẽ nhận thông tin đăng nhập của bạn!");
        document.getElementById(txt4).focus();
        return false;
    }
    else
    if(!checkMail(txt4))
    {
        alert("Địa chỉ email không hợp lệ!\nEmail sẽ nhận thông tin đăng nhập của bạn!");
        document.getElementById(txt4).focus();
        return false;
    }
    else
        return true;
}
//---------------------------------------------------
function HiddenModelDialog(div)
{ 
   window.opener.document.getElementById(div).style.display="none"; 
   window.opener.document.location.reload();
}
function Alert(div)
{
    if(document.getElementById(div).style.display=="")
    {
        alert("Bạn phải tắt cửa sổ vừa mở, mới có thể thao tác được công việc!");
    }
}
function openclose(obj1,obj2,obj3,i)
{
    //obj1 la do tuong can mo
    //obj2 la doi tuong can dong      
//    if(i!=0)
//        document.getElementById(obj3).value=document.getElementById(obj2).style.display;
//        
//    document.getElementById(obj1).style.display=document.getElementById(obj3).value;
    //-------------------------------------------
    if (document.getElementById(obj1)!=null && document.getElementById(obj2)!=null)
    {
        if(document.getElementById(obj1).style.display=="none")
            document.getElementById(obj2).style.display="";
        else
            document.getElementById(obj2).style.display="none";    
    }
}
function showdate()
		{
			d = new Date();
			var a = new Array("Chủ nhật","Thứ hai","Thứ ba","Thứ tư","Thứ năm","Thứ sáu","Thứ bảy");
			s = "<b>" + a[d.getDay()] + 
				", ngày " +	(d.getDate()<10?"0" + d.getDate():d.getDate()) +
				" tháng " +	(d.getMonth()+1 <10?"0" + (d.getMonth() + 1):(d.getMonth()+1)) +
				" năm " +	d.getFullYear() + "</b>";
			document.write(s);			
		}
function showdateEnglish()
		{
			d = new Date();
			var a = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
			s = "<b>" + a[d.getDay()] + 
			    ", " +	(d.getMonth()+1 <10?"0" + (d.getMonth() + 1):(d.getMonth()+1)) +
				"." +	(d.getDate()<10?"0" + d.getDate():d.getDate()) +
				"." +	d.getFullYear() + "</b>";
			document.write(s);			
		}
function showdateShort()
		{
			d = new Date();
			var a = new Array("Chủ nhật","Thứ hai","Thứ ba","Thứ tư","Thứ năm","Thứ sáu","Thứ bảy");
			s = "" +//+ a[d.getDay()] + 
				"" +	(d.getDate()<10?"0" + d.getDate():d.getDate()) +
				"." +	(d.getMonth()+1 <10?"0" + (d.getMonth() + 1):(d.getMonth()+1)) +
				"." +	d.getFullYear() + "";
				
			document.write(s);			
		}		
		
    function checkall(chk)
		{								    			
			var frm = document.forms[0];						
			for(j=0;j<frm.length;j++)
			{			
				e=frm.elements[j];		 
				if(e.type=='checkbox' && e.name.indexOf(chk)!=-1 && !e.disabled)
				{				
					if(flag==0)
					    e.checked=true;					
					else					
					    e.checked=false;					    
				}			
			}					
			if(flag==0)
			    flag=1
			 else
			    flag=0
		}
function subCheck(chkall,chk)
		{
			var frm = document.forms[0];			
			flag=true;
			for(j=0;j<frm.length;j++)
			{			
				e=frm.elements[j];			 
				if(e.type=='checkbox' && e.name.indexOf(chk)!=-1 && !e.disabled)
				{					
					if(!e.checked)						
						flag=false;
				}			
			}		
			for(j=0;j<frm.length;j++)
			{
				e=frm.elements[j];			 
				if(e.type=='checkbox' && e.name.indexOf(chkall)!=-1)
				{					
					e.checked=flag;
					break;
				}
			}		
		}
function HoiTruocKhiXoa(chk)
{
	var frm = document.forms[0];
		//var ch = document.getElementById(obj.id);				
		flag=false;
		for(j=0;j<frm.length;j++)
		{			
			e=frm.elements[j];			 
			if(e.type=='checkbox' && e.name.indexOf(chk)!=-1)
			{					
				if(e.checked)					
					flag=true;
			}			
		}
	if(flag)
	{
		if(confirm("Bạn có chắc chắn muốn xóa không?\n" +
			"Mọi thông tin bạn xóa bạn phải chịu mọi trách nhiệm,\n" 
			+ "một khi có lỗi xảy ra đối hệ thống."))
		{
			return true;
		}
	}
	else
	{
		alert("Bạn chưa chọn thông tin cần xóa!");
	}
	return false;
}
function DangTai(chk,index)
{
	tb1="Bạn có chắc chắn muốn đưa tin lên mạng không?\n" +
			"Mọi thông tin không chính xác bạn phải chịu mọi trách nhiệm";
	tb11="Bạn chưa chọn thông tin cần duyệt, đăng tin!";
	tb2="Bạn có chắc chắn không muốn đưa tin lên mạng không?";			
	tb22="Bạn chưa chọn tin để thôi đăng tải!";
	if(index==1)
	{
	    tb1=tb2;
	    tb11=tb22;
	}
	var frm = document.forms[0];
		//var ch = document.getElementById(obj.id);				
		flag=false;
		for(j=0;j<frm.length;j++)
		{			
			e=frm.elements[j];			 
			if(e.type=='checkbox' && e.name.indexOf(chk)!=-1)
			{					
				if(e.checked)					
					flag=true;
			}			
		}
	if(flag)
	{
		if(confirm(tb1))			
		{
			return true;
		}
	}
	else
	{
		alert(tb11);
	}
	return false;
}
function Xoa()
{
    if(confirm("Bạn có chắc chắn muốn xóa không?\nCác thông tin liên quan cũng bị xóa!"))
		return true;
	else 
	    return false;	
}
function CheckTextBox(obj)
{	
	var frm = document.forms[0];
	var o = document.getElementById(obj);
	
	for(j=0;j<frm.length;j++)
		{			
			e=frm.elements[j];			 
			if(e.type=='text' && e.id!=obj)				
			{								
				var o1= document.getElementById(e.id);
				if(o.value==o1.value)
				{
					alert("Thứ tự sắp xếp đã tồn tại!\nĐể tránh sắp xếp sai, thứ tự không được trùng.");
					return;
				}
			}			
		}
}
function ShowForm(app,id)
{
   window.open(app + '/admin/default.aspx?idcell=' + id,'',
               'top=0,left=0,width=' + (screen.availWidth - 10) + ',height=' + (screen.availHeight -30) + ',resizable=no,scrollbars=yes');
}
function OpenWindow(app,txtFile)
{
    var url = app + txtFile;
    var width = 700;
	var height = 500;
	var resizable = 'yes';
	var scrollbars = 'yes';
	var left = ((document.body.clientWidth - width) / 2) + window.screenLeft;
	var top = (((document.body.clientHeight - height) / 2)) + window.screenTop;
	window.open(url,'', 'width='+width+',height='+height+',left='+left+',top='+top+',resizable='+resizable+',scrollbars='+scrollbars);
}
function popupWindow(url,w,h,bt)
{    
    var width = w;
	var height = h;
	var resizable = 'no';
	var scrollbars = 'yes';
	var left = ((document.body.clientWidth - width) / 2) + window.screenLeft;
	var top = (((document.body.clientHeight - height) / 2)) + window.screenTop;
	window.open(url,'', 'width='+width+',height='+height+',left='+left+',top='+top+',resizable='+resizable+',scrollbars='+scrollbars);
	document.getElementById(bt).disabled = true;
}
function popupWindows(url,w,h)
{    
    if (w==0)
        w=document.body.clientWidth-100;
    if (h==0)
        h=document.body.clientHeight-200;
	
	var resizable = 'no';
	var scrollbars = 'yes';
	var left = ((document.body.clientWidth - w) / 2);// + window.screenLeft;
	var top = ((document.body.clientHeight - h) / 2);// + window.screenTop;
	window.open(url,'', 'width='+w+',height='+h+',left='+left+',top='+top+',resizable='+resizable+',scrollbars='+scrollbars);	
}
function BatTat(obj,o,i)
{    
    if(i==0)
       document.getElementById(obj).disabled=o;
    else
    {
       window.opener.document.getElementById(obj).disabled=o;       
       }
}
function returnSt(obj,obj1)
{
    window.opener.document.getElementById(obj).value=document.getElementById(obj1).value;
    window.close();
}
function ChonFile(bt,rad,text)
{
    var file = document.getElementById(rad).value;
    //-------------------------------------------
        alert(file);  
    
}
function TextEmpty(txt,thongbao)
{
    if(document.getElementById(txt).value=="")
        {
            alert(thongbao);
            document.getElementById(txt).focus();
            return false;    
        }
    else
        return true;
}
function ChonGiaoDien(obj, strID)
{
    var f =document.forms[0];
    //---------------------   
   for(i=0;i<f.length;i++)
    {
        e = f.elements[i];
        if(e.type=='checkbox' && e.name.indexOf(strID)!=-1)   
   e.checked = false;   
   }   
   document.getElementById(obj).checked=true;
}

function IsCheckCha(ckbCha, ckbCon)
{
    var f =document.forms[0];    
   for(i=0;i<f.length;i++)
    {
        e = f.elements[i];
        if(e.type=='checkbox' && e.name.indexOf(ckbCha)!=-1)   
        {
            if(e.checked)
            {
                for(j=0;j<f.length;j++)
                {
                    sub = f.elements[j];
                    if(sub.type=='checkbox' && sub.name.indexOf(ckbCon)!=-1 && sub.id!=e.id)   
                        sub.checked=true;                           
                }
            }
            else
            {
                for(j=0;j<f.length;j++)
                {
                    sub = f.elements[j];
                    if(sub.type=='checkbox' && sub.name.indexOf(ckbCon)!=-1 && sub.id!=e.id)   
                        sub.checked=false;                           
                }
            }
        }
     } 
}
    
function IsCheckCon(ckbCha, ckbCon)
{
    var f =document.forms[0];
    var icheck=true;
    //---------------------       
   for(i=0;i<f.length;i++)
    {
        e = f.elements[i];
        if(e.type=='checkbox' && e.id.indexOf(ckbCon)!=-1)   
        {                             
            if(e.checked)
            {                             
                for(j=0;j<f.length;j++)
                {                  
                    cha = f.elements[j];
                    if(cha.type=='checkbox' && cha.id.indexOf(ckbCha)!=-1)   
                    {
                        cha.checked=true;    
                     //   Alert("Check cha");                       
                        break;
                    }
                }
            }
            else
            {                
                for(j=0;j<f.length;j++)
                {
                    sub = f.elements[j];
                    if(sub.type=='checkbox' && sub.id.indexOf(ckbCon)!=-1)   
                        icheck=sub.checked;                           
                }
                for(t=0;t<f.length;t++)
                {
                    b = f.elements[t];
                    if(b.type=='checkbox' && b.id.indexOf(ckbCha)!=-1 && b.id!=e.id)   
                    {
                        b.checked=icheck;                           
                        break;
                    }
                }
            }
        }
     }      
  }
  function SetForcusButton(btn)
  {								    			
    // document.getElementById(btn).focus();                   
  }
function hideLoaded() 
 {    
  var l = document.getElementById("LoadingDiv");
  l.style.visibility = "hidden";   
 } 
 function displayLoaded()
 {
     var l = document.getElementById("LoadingDiv");
  l.style.visibility = "visible"; 
  setTimeout(hideLoaded,50);
 }
 function open_window(boxmenu) 
 {
var url = boxmenu[boxmenu.selectedIndex].value;
if (url != '') {
window.open(url);
}
}


function taExpand(e)
{    
  var a, i, r, c = 0;
  a = e.value.split('\n');
  for (i = 0; i < a.length; i++)
    {
      if (a[i].length > e.cols) // find number of wrapped lines
      {
        c += Math.floor(a[i].length / e.cols);
      }
    }
    r = c + a.length; // add number of wrapped lines to number of lines
  if (r < e.rows)
  {
    r = e.rows;
  }
  e.rows = r;
}

function KiemTraCheck()
{
    var f=document.forms[0];  
    var bChon = false;                                                                                  
    for(j=0;j<f.length;j++)
    {
        ckbCheckChon=f.elements[j];
        if(ckbCheckChon.type=="checkbox")
        {                   
            if(ckbCheckChon.checked)
            {
                bChon = true;
                break;
            }
        }
    }
    if (bChon == false)
    {
        alert("Bạn chưa chọn thông tin để xóa");
        return false;
    }
    else
    {
        return confirm("Bạn có chắc chắn muốn xóa các thông tin đã chọn không?");
    }    
}   

 function KiemTraCheck_Chon()
{
    var f=document.forms[0];  
    var bChon = false;                                                                                  
    for(j=0;j<f.length;j++)
    {
        ckbCheckChon=f.elements[j];
        if(ckbCheckChon.type=="checkbox")
        {                   
            if(ckbCheckChon.checked)
            {
                bChon = true;
                break;
            }
        }
    }
    if (bChon == false)
    {
        alert("Bạn chưa chọn thông tin để thực hiện");
        return false;
    }
    else
    {
        return confirm("Bạn có chắc chắn muốn thực hiện các thông tin đã chọn không?");
    }   
}


//Dùng trong lịch công tác
function SetCssDongChon(txtID,sCssDangChon)
{    
    var b=  document.getElementById("LuuCssTruocDo");
    var o = document.getElementById(txtID);
    $(".Tin_DuocChon").attr("class",b.value);
    b.value=sCssDangChon;
    $(o).attr("class","Tin_DuocChon");
} 

//====================
//Dùng cho video media
function changeSource(strSource)
{
	var s;
	s="<object id='winMediaPlayerID'";
	s+="codeBase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' ";
	s+="type='application/x-oleobject' height='400' ";
	s+="standby='Loading Microsoft Windows Media Player components...' "; 
	s+="width='100%' classid='CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6' ";
	s+="name='winMediaPlayer'>";
	s+="<param name='URL' value='"+strSource+"'/> ";
	s+="<param name='rate' value='1'/>";
	s+="<param name='balance' value='0'/>";
	s+="<param name='currentPosition' value='0'/>";
	s+="<param name='defaultFrame' value='0'/>";
	s+="<param name='playCount' value='1'/><param name='CursorType' value='-1'/>";
	s+="<param name='autoStart' value='1'/><param name='currentMarker' value='0'/><param name='invokeURLs' value='-1'/>";
	s+="<param name='volume' value='50'/>";
	s+="<param name='mute' value='0'/><param name='stretchToFit' value='-1'/>";
	s+="<param name='windowlessVideo' value='0'/><param name='enabled' value='1'/>";
	s+="<param name='fullScreen' value='0'/><param name='enableErrorDialogs' value='0'/>";
	s+="<embed type='application/x-mplayer2' pluginspage='http://www.microsoft.com/windows/windowsmedia/download/' filename='"+strSource+"' src='"+strSource+"' Name='MediaPlayerTV' "; 
	s+="width='440' ";
	s+="height='450' ";
	s+="AutoSize='1' ";
	s+="AutoStart='1' ";
	s+="ClickToPlay='1' ";
	s+="DisplaySize='1' ";
	s+="EnableContextMenu='1' ";
	s+="EnableFullScreenControls='1' "; 
	s+="EnableTracker='1' ";
	s+="Mute='0' ";
	s+="PlayCount='1' "; 
	s+="ShowControls='1' "; 
	s+="ShowAudioControls='1' "; 
	s+="ShowDisplay='0' ";
	s+="ShowGotoBar='0' ";
	s+="ShowPositionControls='1' "; 
	s+="ShowStatusBar='1' ";
	s+="ShowTracker='1'> ";
	s+="<\/embed> ";
	s+="<\/object>";
	
	document.getElementById("MediaPlayer").innerHTML=s;
}               
