﻿// JavaScript Document
function TestNull(str)
{
	if (str.length <=0)
		return true;

		var j=0;
		var flag=0;
		for (j=0;j<str.length;j++)
		{
			if(str.charAt(j) == " ")
				flag=flag+1;
		}
	if(flag!=str.length){		
		return false;
	}
	return true;
}


function TestEmail(s)
{   
	if (s=="") return false;
	if(s.indexOf(" ")>0) return false;
	if(s.indexOf("@")==-1) return false;
	var i = 1;
	var dodai = s.length;
	if (s.indexOf(".")==-1) return false;
	if (s.indexOf("..")!=-1) return false;
	if (s.indexOf("@")!=s.lastIndexOf("@")) return false;
	if (s.lastIndexOf(".")==s.length-1) return false;
	var str="0123456789abcdefghikjlmnopqrstuvwxyz-@._"; 
	for(var j=0;j<s.length;j++)
	if(str.indexOf(s.charAt(j))==-1)
	return false;
	return true;
}				

function TestNumber(stringIn) {
	var valid = "0123456789";
	var temp="";
	for (var i=0; i<stringIn.length; i++) {
		temp = "" + stringIn.substring(i, i+1);
		if (valid.indexOf(temp) == -1) 
			return false;
	}
	return true;
}

function checkPhone(stringIn) {
	var valid = "0123456789";
	var temp="";
	for (var i=0; i<stringIn.length; i++) {
		temp = "" + stringIn.substring(i, i+1);
		if (valid.indexOf(temp) == -1) 
			return false;
	}							
	if (stringIn.length == 10)
	{
		temp = "" + stringIn.substring(0, 2);
		if (temp == "09")
			return true;
		else
			return false;
	}
	else if (stringIn.length == 11)
	{
		temp = "" + stringIn.substring(0, 3);
		if (temp=="016" || temp=="012")
			return true;		
		else
			return false;
	}							
	else	
		return false;
}

function ShowPopup(URL, WinTitle, WinWidth, WinHeight, WinLeft, WinTop){
	attr = "scrollbars=yes,resizable=no,width=" + WinWidth + ",height=" + WinHeight + ",screenX=" + WinLeft + ",screenY=" + WinTop + ",left=" + WinLeft + ",top=" + WinTop + "";
	var bname = navigator.appName;
	if (bname == "Microsoft Internet Explorer")
		msgWindow=window.open(URL, null, attr);
	else
		msgWindow=window.open(URL, WinTitle, attr);
	if (msgWindow.opener == null) msgWindow.opener = self;
}

function keydownTestLogin(e){
	var characterCode
	if(e && e.which){
		e = e;
		characterCode = e.which;
	}
	else{
		e = event;
		characterCode = e.keyCode;
	}	 
	if(characterCode == 13){
		TestLogin();
		return false;
	}
	return true;
}		

function TestLogin()
{
	if (TestNull(document.getElementById("idDangNhap").value))
	{
		alert("Chưa nhập Tên đăng nhập");
		document.getElementById("idDangNhap").focus();
		return false; 
	} 
	else if (TestNull(document.getElementById("idMatKhau").value))
	{
		alert("Chưa nhập Mật khẩu");
		document.getElementById("idMatKhau").focus();
		return false; 
	} 
	else
	{		
		var chuoi;
		chuoi = WebVietEdu.ajaxThanhVien.KiemTraDangNhap(document.getElementById("idDangNhap").value,document.getElementById("idMatKhau").value).value;
		if (chuoi=='loi')
			alert("Tên đăng nhập hoặc mật khẩu của bạn không chính xác");
		else if (chuoi=='chuakichhoat')
			alert("Tài khoản chưa được kích hoạt");			
		else if (chuoi=='khoa')
			alert("Tài khoản của bạn đã bị khóa");			
		else if (chuoi=='hethan')
			alert("Tài khoản của bạn đã hết hạn sử dụng. Vui lòng liên hệ để sử dụng tiếp");
		else if (chuoi=='dangsudung')
			alert("Tài khoản đã có người đang sử dụng");
		else			
		{
			document.getElementById("login").innerHTML = chuoi;
			//window.location ="index.aspx";
		}
	}
	return false;
}

function Logout()
{
	var chuoi;
	chuoi = WebVietEdu.ajaxThanhVien.ThoatDangNhap().value;
	document.getElementById("login").innerHTML = chuoi;
	//window.location ="index.aspx";
}

function checkEnterSearchNews(e){
	var characterCode
	if(e && e.which){
		e = e;
		characterCode = e.which;
	 }
	 else{
		 e = event;
		 characterCode = e.keyCode;
	 }	 
	 if(characterCode == 13){
		SearchNews();
		return false;
	 }
	return true;
}		

function SearchNews()
{
	if (TestNull(document.getElementById("idchuoitim").value))
	{
		alert("Chưa nhập nội dung cần tìm");
		document.getElementById("idchuoitim").focus();
		return false; 
	} 
	else
		window.location ="news.aspx?text=" + document.getElementById("idchuoitim").value;
	return false;
}
				