﻿// JScript File
var popUpWin=0;
function popUpWindow(URLStr, width, height)
{
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbar=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
function popUp(URLStr, width, height)
{
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'scrollbars=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
function popUpFull(URLStr)
{
  var width = screen.width;
  var height = screen.height;
  open(URLStr, '', 'scrollbars=yes,width='+width+',height='+height+',left=0, top=0,screenX=0,screenY=0');    
}
function ActiveForm()
{
    alert("sasas");
    //window.top.focus();
}
function msgBox(str)
{
    alert("Thông báo\n-------------------------------\n[ " +str+ " ]")
}
function back()
{
    history.go(-1);    
}
function LTrim( value )
{
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value )
{
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");	
}

// Removes leading and ending whitespaces
function trim( value )
{
    return LTrim(RTrim(value));
}

function over(obj)
{
    obj.style.backgroundColor = '#DDEEFF';
}
function out(obj)
{
    obj.style.backgroundColor = '';
}
function check_extension(obj)
    {
        if(trim(obj.value)!=''&&obj.value.toUpperCase().lastIndexOf(".JPG")==-1&&obj.value.toUpperCase().lastIndexOf(".BMP")==-1&& obj.value.toUpperCase().lastIndexOf(".GIF")==-1&&obj.value.toUpperCase().lastIndexOf(".PNG")==-1) 
	    {
            alert("Vui lòng chọn file hình( JPG,BMP,PNG,GIF )");
            obj.focus();
            return 0;
        }
        
        return 1;
    }
function check_extension_EN(obj)
{
    if(trim(obj.value)!=''&&obj.value.toUpperCase().lastIndexOf(".JPG")==-1&&obj.value.toUpperCase().lastIndexOf(".BMP")==-1&&obj.value.toUpperCase().lastIndexOf(".GIF")==-1&&obj.value.toUpperCase().lastIndexOf(".PNG")==-1) 
    {
        alert("please choose picture( JPG,BMP,PNG,GIF)");
        obj.focus();
        return 0;
    }
    return 1;
}
function nhapso(m)
{
    p="0123456789";
    s=m.value;
    l=s.length;
    i=0;
    if(l!=0)
    {
	    while((i<l) && (l!=0))
	    {
		    if(p.indexOf(m.value.charAt(i))==-1)
		    {
			    if(i==(l-1))
				    m.value=m.value.substring(0,l-1);
			    else
			    {
					    if(i==0)
						    m.value=m.value.substring(1,l);
					    else
					    {
						    m.value=m.value.substring(0,i)+ m.value.substring(i+1,l);
						    l=m.length;
					    }					
			    }						
		    }
		    else
			    i++;
	    }
    	
    }
}

function docheck_one()
{
    var is_check_all = true;
    var dem = 1;
    if(document.aspnetForm.chkid.length > 1)
        dem = document.aspnetForm.chkid.length;
    if(dem > 1)
    {
        for(i=0; i<document.aspnetForm.chkid.length;i++)
        {
            if(!document.aspnetForm.chkid[i].checked)
            {
                is_check_all = false;
                break;
            }
        }
    }        
    else
    {
        if(!document.aspnetForm.chkid.checked)
        {
            is_check_all = false;                
        }
    }
    document.aspnetForm.chkall.checked = is_check_all;
}
function docheck_all(is_check)
{        
    //Truong hop nay la khong co bat ky mot chkid nao
    //khi do no se null, newu khong kiem soat se loi
    if(document.aspnetForm.chkid != null)
    {    
        var dem = 1;
        if(document.aspnetForm.chkid.length > 1)
            dem = document.aspnetForm.chkid.length;
        if(dem > 1)
        {
            for(i=0; i<document.aspnetForm.chkid.length;i++)
            {
                document.aspnetForm.chkid[i].checked = is_check;
            }
        }
        else
        {
            document.aspnetForm.chkid.checked = is_check;
        }
    }
    document.aspnetForm.chkall.checked = is_check;
}
function checkSubmit()
{
    document.aspnetForm.arrID.value = '';
    var dem = 1;
    if(document.aspnetForm.chkid.length > 1)
        dem = document.aspnetForm.chkid.length;
    
    if(dem > 1)
    {
        for(i=0; i<document.aspnetForm.chkid.length;i++)
        {
            if(document.aspnetForm.chkid[i].checked == true)            
                document.aspnetForm.arrID.value += trim(document.aspnetForm.chkid[i].value)+';';            
        }
        document.aspnetForm.arrID.value = document.aspnetForm.arrID.value.substr(0,document.aspnetForm.arrID.value.length-1);
    }
    else
    {
        if(document.aspnetForm.chkid.checked == true)
                document.aspnetForm.arrID.value += document.aspnetForm.chkid.value;
    }        
    
    if(document.aspnetForm.arrID.value == '')
    {
        alert("Thông báo\n-------------------------------------\nChọn ít nhất một mẫu tin trước thực hiện");
        return false;
    }        
    if(confirm("Bạn có chắc là mình muốn thực hiện lệnh này không") == false)
        return false                
    return true;
}

function isvaliddate(s)
{
    //alert(s.substring(6,10));
    var d = s.substring(0,2);
    var m = s.substring(3,5);
    var y = s.substring(6,10);
    if (d > 31)
    {
        alert('Day is not great 31');
        return 0; 
    }
    if (m > 12)
    {
        alert('Month is not great 12');
        return 0; 
    }
    if (d == 31 &&(m == 4 || m == 6 || m == 9 || m == 11))
    {
        alert('This month has no 31');
        return 0; // 31st of a month with 30 days
    }
    if (d >= 30 && m == 2)
    {
        alert('February has no 30 or 31');
        return 0; //February 30th or 31st
    } 
    if (m == 2 && d == 29 &&  (y % 4 != 0 && (y % 100 == 0 || y % 400 != 0)))
    {
      alert('February 29th outside a leap year');
      return 0; // February 29th outside a leap year
    }
                      
    return 1; // Valid date
}
function checkvalidate(s, whatDate)
{        
    //Xoa khoang trang cua chuoi ngay thang        
    s = trim(s);        
    if(s.length==0)
    {
        alert('Vui lòng chọn ngày '+whatDate);
            return 0;
    }
    else
    {
        re = /^\d{2}\/\d{2}\/\d{4}$/;
        if(s != '' && !s.match(re)) 
        {
            alert("Ngày phải đúng định dạng :dd/mm/yyyy");
            return 0;
        }
    }
    
    if(isvaliddate(s)==0)
        return 0
    return 1;
}
function CompareTwoDate(d1_str,d2_str)
{
    //d1_str = trim(document.aspnetForm.ctl00$ContentPlaceHolder1$TreeView1$txt_Obj_Start.value);
    //d2_str = trim(document.aspnetForm.ctl00$ContentPlaceHolder1$TreeView1$txt_Obj_Deadline.value);
    d1_str = trim(d1_str);
    d2_str = trim(d2_str);
    
    d1 = new Date(d1_str.split('/')[2],d1_str.split('/')[1],d1_str.split('/')[0]);
    d2 = new Date(d2_str.split('/')[2],d2_str.split('/')[1],d2_str.split('/')[0]);

    if (d2.getTime()<d1.getTime())
    {            
        return 0;
    }        
    return 1;
}



function emailcheck(str,mes) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert(mes)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(mes)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(mes)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(mes)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(mes)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(mes)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(mes)
		    return false
		 }

 		 return true					
	}
	
	
