// JavaScript Document

function inputMask(input, mask)
{	
	var index = 0;
	var len = input.value.length;
		
	while ((index < len) && (len != 0))
		if (mask.indexOf(input.value.charAt(index)) == -1)
		{
			if (index == len-1)
				input.value = input.value.substring(0, len-1);
			else if (index == 0)
				 	input.value = input.value.substring(1, len);
				 else input.value = input.value.substring(0, index)+input.value.substring(index+1, len);
			index = 0;
			len = input.value.length;
		}
		else index++;
}	

function checkInputlh()
{
    if(document.formlh.txthoten.value=="")
	{
	  alert("Bạn chưa nhập họ tên");
	  document.formlh.txthoten.focus();
	  return false;
	}
	if(trim(document.formlh.txtemail.value) == "")
	{
	  alert("Bạn chưa nhập email");
	  document.formlh.txtemail.focus();
	  return false;
	}
	if( !isEmail(document.formlh.txtemail.value) )
	{
		alert("Địa chỉ email không hợp lệ");
		document.formlh.txtemail.focus();
		document.formlh.txtemail.select();
		return false;
	}
	if(document.formlh.txtthongtin.value=="")
	{
	  alert("Bạn chưa nhập nội dung");
	  document.formlh.txtthongtin.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 trim(str)
		{
		ch = '';
		for(i=0;i<str.length;i++)
		{
			cha = str.charAt(i);
			if(cha != ' ')
			{
				ch = ch + cha;
			}
		}
		return ch;
		}
		
	return true;
}

 function Change_Language(lang,url)
		 {
			 
			 setCookie("lang",lang);
			 //alert(url);
			 window.location =url;
			 
		 }
	  function setCookie(name, value, expires, path, domain, secure) 
	  {
		  var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") +((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
		 document.cookie = curCookie;
	  }
	  function clear_key(obj)
{
  if (obj.textfield.value == "Key words")
  {
    obj.textfield.value = ""
    return
  }
}
function clear_email(obj)
{
  if (obj.txtEmail.value == "Send Email")
  {
    obj.txtEmail.value = ""
    return
  }
}

