function validfrmProduct()
{
	

}


// JavaScript Document

//****************************************
// validfrmUserGroup
//****************************************
function validfrmUserGroup(){
	var theForm = document.frmAddNewUserGroup;

	if(trim(theForm.Title.value)==""){
		alert("Nhập Title");
		theForm.Title.focus();
		return false;
	}

	if(!isValidRadio(theForm.Permission)){
		alert("Nhập Permission");
    	return false;
	}	

	return true;
}
//****************************************
// validfrmUserGroup
//****************************************
function validfrmUser(){
	var theForm = document.frmAddNewUser;

	if(trim(theForm.Email.value)==""){
		alert("Nhập Email");
		theForm.Email.focus();
		return false;
	}
		if(trim(theForm.email_chk.value)=="no_ok"){
		alert("Email không hợp lệ");
		theForm.Email.focus();
		return false;
	}



	if(trim(theForm.Pass.value)==""){
		alert("Nhập Password ");
		theForm.Pass.focus();
    	return false;
	}	
	
	if(trim(theForm.FirstName.value)==""){
		alert("Nhập FirstName ");
		theForm.FirstName.focus();
    	return false;
	}	
	
	if(trim(theForm.LastName.value)==""){
		alert("Nhập LastName ");
		theForm.LastName.focus();
    	return false;
	}	
	
	if(trim(theForm.Address.value)==""){
		alert("Nhập Address ");
		theForm.Address.focus();
    	return false;
	}	
	if(trim(theForm.CountryID.value)==""){
		alert("Nhập CountryID ");
		theForm.CountryID.focus();
    	return false;
	}	
	if(trim(theForm.CityID.value)==""){
		alert("Nhập CityID ");
		theForm.CityID.focus();
    	return false;
	}	
	if(trim(theForm.GroupID.value)==""){
		alert("Nhập GroupID ");
		theForm.GroupID.focus();
    	return false;
	}	
	return true;
}

//****************************************
// validfrmRoleGroup
//****************************************
function validfrmRoleGroup(){
	var theForm = document.frmAddNewRoleGroup;

	if(trim(theForm.Title.value)==""){
		alert("Nhập Title");
		theForm.Title.focus();
		return false;
	}


	return true;
}
//****************************************
// validfrmRoleGroup
//****************************************
function validfrmRole(){
	var theForm = document.frmAddNewRole;

	if(trim(theForm.Title.value)==""){
		alert("Nhập Title");
		theForm.Title.focus();
		return false;
	}
	if(trim(theForm.Description.value)==""){
		alert("Nhập Description");
		theForm.Description.focus();
		return false;
	}
	if(trim(theForm.RoleGroupID.value)==""){
		alert("Nhập RoleGroupID");
		theForm.RoleGroupID.focus();
		return false;
	}
	return true;
}
//****************************************
// validfrmRoleGroup
//****************************************
function validfrmCountry(){
	var theForm = document.frmAddNewCountry;

	if(trim(theForm.CountryName.value)==""){
		alert("Nhập CountryName");
		theForm.CountryName.focus();
		return false;
	}
	return true;
}

//****************************************
// validfrmRoleGroup
//****************************************
function validfrmCity(){
	var theForm = document.frmAddNewCity;

	if(trim(theForm.CityName.value)==""){
		alert("Nhập CityName");
		theForm.CityName.focus();
		return false;
	}
	if(trim(theForm.CountryID.value)==""){
		alert("Nhập CountryID");
		theForm.CountryID.focus();
		return false;
	}
	
	return true;
}

//****************************************
// validfrmUserDB
//****************************************
function validfrmUserDB(){
	var theForm = document.frmAddNewUserDB;

	if(trim(theForm.txtUserDBID.value)==""){
		alert("Nhập UserDB");
		theForm.txtUserDBID.focus();
		return false;
	}
	if(trim(theForm.userDB_chk.value)=="no_ok"){
		alert("UserDB không hợp lệ");
		theForm.userDB_chk.focus();
		return false;
	}

	if(trim(theForm.txtPassDB.value)==""){
		alert("Nhập Password ");
		theForm.txtPassDB.focus();
    	return false;
	}	
	
	return true;
}

function validfrmUserAccessDB()
{
	var theForm = document.frmAddNewUserAccessDB;
	
	if (trim(theForm.txtEmail.value)=="")
	{
		alert("Vui lòng nhập Email.");	
		theForm.txtEmail.focus();
		return false;
	}
	
	return true;
}

function validfrmPlaceLogo()
{
	var theForm = document.frmAddNewPlaceLogo;
	
	if (trim(theForm.txtPlaceName.value)=="")
	{
		alert("Vui lòng nhập tên.");	
		theForm.txtPlaceName.focus();
		return false;
	}
	
	if (isNaN(theForm.txtWidth.value))
	{
		alert("Vui lòng nhập đúng độ rộng.");	
		theForm.txtWidth.focus();
		theForm.txtWidth.select();
		return false;
	}

	if (isNaN(theForm.txtHeight.value))
	{
		alert("Vui lòng nhập đúng chiều cao.");	
		theForm.txtHeight.focus();
		theForm.txtHeight.select();
		return false;
	}

	return true;
}
function askdo()
{
	return confirm ("Bạn biết chắc hành động này thực hiện chứ ?");
	
	
}

function validfrmAdvertise()
{
	var theForm = document.frmAddNewAdvertise;
	if(trim(theForm.SiteAdvertise.value)=="")
	{
		alert("Vui lòng nhập tên nhà quảng cáo ");
		theForm.SiteAdvertise.focus();
		return false;
	}
	return true;
}

function validTimeInput()
{
	var theForm = document.frmAdvertiseStatistics;
	if(trim(theForm.fromDate.value) == "")
	{
		alert("Vui lòng chọn thời gian bắt đầu");
		return false;
	}
	if(trim(theForm.toDate.value) == "")
	{
		alert("Vui lòng chọn thời gian kết thúc");
		return false;
	}
	
	return true;
}

function display_message(message){
	document.getElementById("div_notice").innerHTML = message;
	document.getElementById("div_notice").style.display="block";
}

function clear_message(){
	document.getElementById("div_notice").innerHTML = '';
	document.getElementById("div_notice").style.display="none";
}

function getVerifyString(){
	var chars ="A1B2C3D4E5F6G7H8I9JKLMNOPQRSTUVWXYZ";
	var ret='';
	for(i=0;i<3;i++){
		var pos = Math.round(Math.random()*(chars.length-1));
		ret += chars.charAt(pos);
	}
	return ret;
}
		
function checkVerifyString(a, b){
	if(a.toLowerCase()==b.toLowerCase())
		return true;	
	return false;	
}

	
	
function register(){ 
	clear_message();
	var theForm = document.frmRegister;	var name = trim(theForm.txtName_1.value);
	//check email
	
	if(theForm.txtEmail_1.value==""){
		display_message("Vui lòng nhập địa chỉ email!");
		theForm.txtEmail_1.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
	else if(!chkEMail(theForm.txtEmail_1)){
		display_message("Email không đúng! Ví dụ email đúng: tencuatui@dicho.vn");
		theForm.txtEmail_1.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
	
	else if(theForm.email_chk.value=='no_ok'){
		display_message("Email bị trùng, vui lòng nhập địa chỉ email khác!");
//		alert("Email bị trùng, bạn hãy nhập địa chỉ email khác!");
		theForm.txtEmail_1.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
		
	//check password
	else if(theForm.txtPass_1.value==""){
		display_message("Vui lòng nhập mật khẩu!");
		theForm.txtPass_1.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
	else if(theForm.txtPass_1.value.length < 7 || theForm.txtPass_1.value.length>13){
		display_message("Vui lòng nhập mật khẩu có từ 7 đến 13 ký tự");
		theForm.txtPass_1.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
	else if(theForm.txtPassA_1.value==""){
		display_message("Vui lòng nhập lại mật khẩu!");
		theForm.txtPassA_1.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
	
	else if(theForm.txtPass_1.value != theForm.txtPassA_1.value){
		display_message("Vui lòng nhập mật khẩu trùng khớp!");
		theForm.txtPassA_1.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
	//check ho
	else if(name==""){
		display_message("Vui lòng nhập họ tên!");
		theForm.txtName_1.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
	else if(name.indexOf(' ')<1){
		display_message("Vui lòng nhập đầy đủ họ tên!");
		theForm.txtName_1.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
	
	else if(theForm.txtPhone_1.value==""){
		display_message("Vui lòng cho biết điện thoại liên lạc!");
		theForm.txtPhone_1.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
	
	//captcha
	if(theForm.txtCaptcha.value == ""){
		display_message("Vui lòng nhập các ký tự trong ảnh bên dưới!");
		theForm.txtCaptcha.focus();
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		return false;
	}
	//ajax captcha
	else if(!checkVerifyString(theForm.txtCaptcha.value, captchaValue)){
		display_message("Vui lòng nhập đúng các ký tự trong ảnh bên dưới!");
		theForm.txtCaptcha.value="";
		//document.getElementById('image').src = 'public_library/securimage_ajax/securimage_show.php?sid=' + Math.random();
		captchaValue = getVerifyString();
		document.getElementById('verified_image').innerHTML = captchaValue;
		theForm.txtCaptcha.focus();
		return false;
	}
	
	//check	
	else
	{
		//alert("submit di!");
		theForm.submit();
		return true;
	}		
}

function getPassAgain(){
	var email = document.getElementsByName('txtYourEmail')[0];
	if(chkEMail(email)){
		checkEmailExist('checkEmail.php',email.value,'divEmail');
		
		setTimeout(function(){if(document.getElementsByTagName("input")['email_chk'].value == 'no_ok') {window.location = "mail.php?email=" + email.value;} else {display_message('Email này không phải là email đã được đăng ký! Bạn có gõ nhầm phím?'); email.focus();}}, 50);
	}
	else{
		display_message("Email không đúng!\n Ví dụ email đúng: tencuatui@dicho.vn");
	}
}

//mailaddress check
function chkEMail(obj)
{
	if (obj.value == '')
		return false;
  	if (obj.value != '' && ! obj.value.match(/^[A-Za-z\d_\-\.]+@([A-Za-z\d_\-]+\.)+[A-Za-z]+$/)) {
    	obj.focus();
    	return false;
  	}
  	return true;
}

//phone is number
function checkNum(e)
{
	var keynum
	var keychar
	var numcheck
	
	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	if(keynum==undefined)
	{
	//		alert('AAAA');
		//Tab
		return true;
	}
	//alert(keynum)
	keychar = String.fromCharCode(keynum)
	//alert(keynum)
	numcheck = /\d/
	// 46 . 44 , 43 +,32 khoang trang; 44 day ,
	//return (numcheck.test(keychar) || (keynum == 8)||(keynum == 45));
	if((numcheck.test(keychar) || (keynum == 8) || (keynum == 9) ||(keynum == 45) ||(keynum == 41) ||(keynum == 40) ||(keynum == 32)||(keynum == 44)))
	//if((keynum >47 && keynum <58))
	{
		return true
	}
	else
	{
		return false		
	}

}

//url check
function chkUrl(obj)
{
  if (obj.value != '' && ! obj.value.match(/^[!#-9A-~]+\.+[a-z0-9]+/i)) {
    obj.focus();
    return false;
  }
  return true;
}

function askIfCancelOrder(forwardLink){
	if(confirm("Một khi đã hủy thì không thể phục hồi.\nBạn có chắc là không muốn đặt đơn hàng này nữa?"))
		location.href=forwardLink;
}

function searchTrans(){
	var theForm = document.frmSearchTrans;
	var checkedVal = getCheckedValue(theForm.radio_soche);
	if(checkedVal == "radO"){
		var str_FDay = theForm.selFMonth.value+"/"+theForm.selFDay.value+"/"+theForm.selFYear.value;
		var str_TDay = theForm.selTMonth.value+"/"+theForm.selTDay.value+"/"+theForm.selTYear.value;
		
		var fd = new Date(Date.parse(str_FDay)); 
		var td = new Date(Date.parse(str_TDay));
		
		if(fd.getDate()!=theForm.selFDay.value){
			show_message_box('w', "Ngày: "+ theForm.selFDay.value+"/"+theForm.selFMonth.value+"/"+theForm.selFYear.value + " không tồn tại.\nVui lòng chọn một ngày khác!", 500, 300, 3000);
			return;
		}
		
		if(td.getDate()!=theForm.selTDay.value){
			show_message_box('w', "Ngày: "+ theForm.selTDay.value+"/"+theForm.selTMonth.value+"/"+theForm.selTYear.value + " không tồn tại\nVui lòng chọn một ngày khác!", 500, 300, 3000);
			return;
		}		
	}
	
	theForm.submit();
}

function checkFDay(){
	var theForm = document.frmSearchTrans;
	var str_FDay = theForm.selFMonth.value+"/"+theForm.selFDay.value+"/"+theForm.selFYear.value;
	//alert(str_FDay);
	
	day = new Date(2009,1,29);
	alert(day.toString());
	//var day = Date.parse("Feb 29, 2009");
	alert(typeof day);
	
	
	if(!isNaN(Date.parse("1/29/2009"))){
		alert("tired");
		document.frmSearchTrans.selFDay.firstChild.selected = "selected";
	}
}