﻿// JavaScript Document

function checkmail(e){
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	var returnval=emailfilter.test(e.value)
	/*if (returnval==false){
		alert("Please enter a valid email address.")
		e.select()
	}
	*/
	return returnval
}

function goMenu(module){
	if(module=="sangiaodichtudo"){
		document.location.href='index.php?module=sangiaodich&mode=tudo';	
	}else{
		document.location.href='index.php?module='+module;	
	}
}

function getLoginCookie(){
	
	if(getCookie('loginvalue') && getCookie('passwdvalue')){
		var theForm = document.frm_login;
		theForm.email_txt.value = getCookie('loginvalue');
		theForm.pass_txt.value = getCookie('passwdvalue');
		return true;
	}
}

function FormatYear(str){
	var validChars = '0123456789';

	for(var i = 0; i < val.length; i++) {
		if(validChars.indexOf(val.charAt(i)) == -1)
			return false;
	}
	
	if(strTemp.length != 4){
		return false;
	}
	
	return true;	
}

function isNumeric(val) {
	var validChars = '0123456789.,';

	for(var i = 0; i < val.length; i++) {
		if(validChars.indexOf(val.charAt(i)) == -1)
			return false;
	}

	return true;
}

function FormatNumber(str){
	if(!isNumeric(str)){
		alert("Vui long nhap so (0-9)!");
		return "";
	}
	return str;
	/*
	var strTemp = GetNumber(str);
	
	if(strTemp.length <= 3)
		return strTemp;
	strResult = "";
	for(var i =0; i< strTemp.length; i++)
		strTemp = strTemp.replace(",", "");
	for(var i = strTemp.length; i>=0; i--)
	{
		if(strResult.length >0 && (strTemp.length - i -1) % 3 == 0)
			strResult = "," + strResult;
		strResult = strTemp.substring(i, i + 1) + strResult;
	}
	return strResult;
	*/
}
function GetNumber(str)
{
	for(var i = 0; i < str.length; i++)
	{
		var temp = str.substring(i, i + 1);
		if(!(temp == "," || temp == "." || (temp >= 0 && temp <=9)))
		{
			alert("Vui long nhap so (0-9)!");
			return str.substring(0, i);
		}
		if(temp == " ")
			return str.substring(0, i);
	}
	return str;
}

function checkIsImage(img_name){
	
	var mess="không hợp lệ." + "\nBạn chỉ được chọn file ảnh: *.jpg, *.gif, *.png";
	
	var spl=img_name.split('.');
	var ext=spl[spl.length-1].toLowerCase();
	if(!(ext=='jpg' || ext=='gif' || ext=='png')){				
		var spl2=img_name.split('\\');
		alert("File '"+spl2[(spl2.length)-1]+"' : "+mess);		
		return false;
	}	
	
	return true;
}