﻿// JavaScript Document
//******************************************************************************
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//******************************************************************************
//---------------------------------------------
//Save Cookie variable with name and value
//---------------------------------------------
function saveCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000))
		var expires = "; expires=" + date.toGMTString()
	}
	else expires = ""
	document.cookie = name + "=" + value + expires + ";path=/"
}
//---------------------------------------------
//Read Cookie variable from Name
//---------------------------------------------
function readCookie(name) 
{
	var nameEQ = name + "="
	var ca = document.cookie.split(';')
	for(var i=0;i<ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length)
		if (c.indexOf(nameEQ) == 0) 
		{
			return c.substring(nameEQ.length,c.length)
		}
	}
	return null
}
//---------------------------------------------
//Delete Cookie variable from Name
//---------------------------------------------
function deleteCookie(name) 
{
	saveCookie(name,'',-1)
}
//---------------------------------------------
//Check str empty or not
//---------------------------------------------
function isempty(str) 
{
	atmp = str.split(String.fromCharCode(32));
	for (ii=0; ii< atmp.length;ii++ ) 
	{
		if (atmp[ii] != "") 
		return false;
	}	
	return true;
}
//---------------------------------------------
//Submit form by Javascript
//---------------------------------------------
function selfsubmit(straction) {
	window.document.forms[0].target = "_self";
	window.document.forms[0].action = straction;
	window.document.forms[0].submit();
}
//---------------------------------------------
//Check value for CheckBox
//---------------------------------------------
function setchecked(val,ctrChkName) {
  with (document.forms[0]) {
	 len = elements.length;
     for(var ii=0; ii<len; ii++) {
		if (elements[ii].name == ctrChkName) {
			elements[ii].checked = val;
		}
	}
  }
}
//---------------------------------------------
//Check value for CheckBox
//---------------------------------------------
function chkremove(ctrChkName) {
  fg = false;
  with (document.forms[0]) {
	 len = elements.length;
     for(var ii=0; ii<len; ii++) {
		if ((elements[ii].name == ctrChkName) && (elements[ii].checked)) {
			fg = true;
			break;
		}
	}
  }
  return(fg)
}
//--------------------------------------------------
// EmptyTextbox: Kiem tra textbox co rong hay khong
//--------------------------------------------------
function EmptyTextbox(FormName,TextboxName)
{
	x=document + "." + FormName + "." + TextboxName;
	if (x.value.length==0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//---------------------------------------------------
// FocusField(fieldname)
//---------------------------------------------------
function FocusField(FieldName)
{
	window.document.form[0].FieldName.focus();
	//x.focus();
}

//---------------------------------------------------
// eMailCheck(str): Kiem tra dia chi email
//---------------------------------------------------
function eMailCheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

//---------------------------------------------------
// IsNumeric: Kiem tra du lieu co phai So
//---------------------------------------------------
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
//----------------------------------------------------
// GetDateTime: Lay ngay gio he thong:
// strCountry: VIE or ENG
//----------------------------------------------------

function GetDateTime(strCountry)
{
	var d=new Date()
	var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
	
	if(strCountry.toUpperCase() == "ENG")
		var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	if(strCountry.toUpperCase() == "VIE")
		var weekday=new Array("Chủ Nhật","Thứ Hai","Thứ Ba","Thứ Tư","Thứ Năm","Thứ Sáu","Thứ Bảy")

	document.write(weekday[d.getDay()] + ", ")
	document.write(d.getDate() + "-")
	//document.write(monthname[d.getMonth()] + " ")
	document.write(d.getMonth() + 1 + "-")
	document.write(d.getFullYear())
	document.write(", " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds())
}