// JavaScript Document
function snapIn(jumpSpaces,position) {                
        var msg = "Welcome to lam-son.net!!!"        
        var out = ""      

        if (killScroll) {return false}        
        for (var i=0; i<position; i++){
                out += msg.charAt(i)}        
        for (i=1;i<jumpSpaces;i++) {
                out += " "}        
        out += msg.charAt(position)        
        window.status = out        
        if (jumpSpaces <= 1) {        
                position++        
        if (msg.charAt(position) == ' ') {
                position++ }
                jumpSpaces = 100-position        
        } 
        else if (jumpSpaces >  3) {
                jumpSpaces *= .75}        
        else {
                jumpSpaces--}        
        if (position != msg.length) {        
                var cmd = "snapIn(" + jumpSpaces + "," + position + ")";        
                scrollID = window.setTimeout(cmd,5);        
        } 
        else {        
                scrolling = false
                return false         
        }        
        return true
}

function snapSetup() {        
        if (scrolling)           
        if (!confirm('Re-initialize snapIn?'))        
        return false   
        killScroll = true  
        scrolling = true   
        var killID = window.setTimeout('killScroll=false',6)        
        scrollID = window.setTimeout('snapIn(100,0)',10)        
        return true    

}
        var scrollID = Object
        var scrolling = false        
        var killScroll = false


function showTBody(category) {
  var category = document.getElementById(category);
  if (category == null) return;

  if ( category.style.display == 'none' ) {
    category.style.display = '';
  } 
}
function hideTBody(category) {
  var category = document.getElementById(category);
  if (category == null) return;

   if ( category.style.display == '' ) {
    category.style.display = 'none';
//	document.mail.image.
  }
}
function showRow(i){
	showTBody(i);
}

function hideRow(i){
	hideTBody(i);
}

function showItems(arr,items, from, to){
	//alert(items);
	for(var i=from;i<to;i++){
//		alert(arr[i]);
		if(arr[i]==items){
		//	alert(i);
			showRow(arr[i]);
		}else{
			hideRow(arr[i]);
		}
	}
}
function Check_Register()
{
	var password;
	var MaKiemTra;
	password=document.frmRegister.txtPassword.value;
	MaKiemTra=document.frmRegister.txtMaKiemTra.value.toUpperCase();
	if(document.frmRegister.txtUsername.value=="")
	{
		  alert("Vui lòng nhập tài khoản");
		  document.frmRegister.txtUsername.focus();
		  return false;
	}
	if(document.frmRegister.txtPassword.value=='')
	{
		  alert("Vui lòng nhập mật khẩu");
		  document.frmRegister.txtPassword.focus();
		  return false;
	}
	if(password.length<6)
	{
		alert("Mật khẩu phải từ 6 ký tự trở lên");
		return false;
	}
	if(document.frmRegister.txtRePassword.value=="")
	{
		  alert("Vui lòng nhập mật khẩu xác nhận");
		  document.frmRegister.txtRePassword.focus();
		  return false;
	}
	if(document.frmRegister.txtRePassword.value!=document.frmRegister.txtPassword.value)
	{
		  alert("Mật khẩu và mật khẩu xác nhận không giống nhau");
		  document.frmRegister.txtRePassword.focus();
		  return false;
	}
	if(!isEmail(document.frmRegister.txtEmail.value))
	{
			alert("Email không đúng định dạng");
			return false;
	}
	
	if(MaKiemTra!=document.frmRegister.codeCheck.value)
	{
		  alert("Mã kiểm tra không đúng");
		  document.frmRegister.txtMaKiemTra.focus();
		  return false;
	}
	
}
function isEmail(emailstr)
{
	dotchar = emailstr.indexOf('.');
	atchar = emailstr.indexOf('@');
	dotlast = emailstr.lastIndexOf('.');
	spacechar = emailstr.indexOf(' ');
	len = emailstr.length;
	if( (dotchar == -1) || (atchar == -1) || (spacechar != -1) || (dotlast < atchar) || (dotlast == len - 1))
	{
		return false;
	}
	else
	{
		return true;
	}
						
}
function checkLogin()
{
	if(document.frmLogin.txtUsername.value=="")
	{
		alert("Bạn chưa nhập tài khoản");
		document.frmLogin.txtUsername.focus();
		return false;
	}
	if(document.frmLogin.txtPassword.value=="")
	{
		alert("Bạn chưa nhập mật khẩu");
		document.frmLogin.txtPassword.focus();
		return false;
	}
	//document.frmLogin.submit();
}
function checkChangeInfoMember()
{
	if(!isEmail(document.frmInfoMember.txtEmail.value))
	{
			alert("Email không đúng định dạng");
			return false;
	}
}
function checkSendComment()
{
	var codecheck1;
	var codecheck2;
	codecheck1=document.frmcomment.codecheck1.value.toUpperCase();
	codecheck2=document.frmcomment.codecheck2.value;
	//alert(codecheck1);
	//alert(codecheck2);
	if(codecheck1!=codecheck2)
	{
		alert("Mã kiểm tra không đúng");
		document.frmcomment.codecheck1.focus();
		return false;
	}
	if(document.frmcomment.txtPhanHoi.value=="")
	{
		alert("Vui lòng nhập ý kiến phản hồi");
		document.frmcomment.txtPhanHoi.focus();
		return false;
	}
	
}
//----------------------------------------------------------------------------------------------------
function checkSendComment2()
{
	var codecheck1;
	var codecheck2;
	codecheck1=document.frmComment2.codecheck1.value.toUpperCase();
	codecheck2=document.frmComment2.codecheck2.value;
	//alert(codecheck1);
	//alert(codecheck2);
	
	if(document.frmComment2.txtName.value=="")
	{
		alert("Vui lòng nhập họ tên");
		document.frmComment2.txtName.focus();
		return false;
	}
	if(document.frmComment2.txtEmail.value=="")
	{
		alert("Vui lòng nhập Email");
		document.frmComment2.txtEmail.focus();
		return false;
	}
	if(!isEmail(document.frmComment2.txtEmail.value))
	{
			alert("Email không đúng định dạng");
			return false;
	}
	if(document.frmComment2.txtTell.value=="")
	{
		alert("Vui lòng nhập số điện thoại");
		document.frmComment2.txtTell.focus();
		return false;
	}
	
	if(document.frmComment2.txtPhanHoi.value=="")
	{
		alert("Vui lòng nhập ý kiến phản hồi");
		document.frmComment2.txtPhanHoi.focus();
		return false;
	}
	if(document.frmComment2.codecheck1.value=="")
	{
		alert("Vui lòng nhập mã kiểm tra");
		document.frmComment2.codecheck1.focus();
		return false;
	}
	if(codecheck1!=codecheck2)
	{
		alert("Mã kiểm tra không đúng");
		document.frmComment2.codecheck1.focus();
		return false;
	}
	
}

//------------------------------------------------------------------------------------------------
function checkDangTinRaoVat()
{
	if(document.frmDangTinRaoVat.txtTenTinRaoVat.value=="")
	{
		alert("Vui lòng nhập tiêu đề tin rao vặt");
		document.frmDangTinRaoVat.txtTenTinRaoVat.focus();
		return false;
	}
	if(document.frmDangTinRaoVat.txtMoTa.value=="")
	{
		alert("Vui lòng nhập giới thiệu ngắn tin rao vặt");
		document.frmDangTinRaoVat.txtMoTa.focus();
		return false;
	}
	if(document.frmDangTinRaoVat.cboMenu.value==0)
	{
		alert("Vui lòng nhập loại tin rao vặt");
		document.frmDangTinRaoVat.cboMenu.focus();
		return false;
	}
	if(document.frmDangTinRaoVat.txtPrice1.value=="")
	{
		alert("Vui lòng nhập giá bán");
		document.frmDangTinRaoVat.txtPrice1.focus();
		return false;
	}
	if(document.frmDangTinRaoVat.cboDiaDiem.value=="")
	{
		alert("Vui lòng chọn nơi đăng tin rao vặt");
		document.frmDangTinRaoVat.cboDiaDiem.focus();
		return false;
	}
	
}
////////////////////////////////////////////////////////////////////////
function checkSuaTinRaoVat()
{
	if(document.frmSuaTinRaoVat.txtTenTinRaoVat.value=="")
	{
		alert("Vui lòng nhập tiêu đề tin rao vặt");
		document.frmSuaTinRaoVat.txtTenTinRaoVat.focus();
		return false;
	}
	if(document.frmSuaTinRaoVat.txtMoTa.value=="")
	{
		alert("Vui lòng nhập giới thiệu ngắn tin rao vặt");
		document.frmSuaTinRaoVat.txtMoTa.focus();
		return false;
	}
	if(document.frmSuaTinRaoVat.cboMenu.value==0)
	{
		alert("Vui lòng nhập loại tin rao vặt");
		document.frmSuaTinRaoVat.cboMenu.focus();
		return false;
	}
	if(document.frmSuaTinRaoVat.txtPrice1.value=="")
	{
		alert("Vui lòng nhập giá bán");
		document.frmSuaTinRaoVat.txtPrice1.focus();
		return false;
	}
	if(document.frmSuaTinRaoVat.cboDiaDiem.value=="")
	{
		alert("Vui lòng chọn nơi đăng tin rao vặt");
		document.frmSuaTinRaoVat.cboDiaDiem.focus();
		return false;
	}
	
}
//------------------------------------------------------------------------------------------



