//Cek validasi alamat e-Mail.
function cek_email(form)
{
  var emailvar = form.value
  var emailparts = emailvar.split("@")
  var emailnameonly = ""
  var minimumextlength = 2
  var maximumextlength = 4
  var urltestchar = ""
  var charok = 0
  var acceptable = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","-",".","1","2","3","4","5","6","7","8","9","0","@","_")
  
  // focus on text input in case the user has entered an invalid address
  // so when they re-enter the email address they don't have to focus manually
  form.focus();
  form.select();
  
  // check to see if there are any @'s in the string
  if (emailparts.length > 2) 
  {
    alert("Invalid e-Mail address.\nRe-enter your right e-Mail address, please.")
    return false
  }
  if (emailparts.length <= 1)
  {
    alert("Invalid e-Mail address.\nRe-enter your right e-Mail address, please.");
    return false;
  }
  
  // There is one @ - now check for a dot 
  // and data before and after the @
  var emailurl=(emailparts[emailparts.length - 1])
  for (var i=0; i < emailparts.length-1; i++) emailnameonly=emailnameonly+emailparts[i]
  
  // Examine emailurl for a dot and data in front of it 
  // and two or three characters after the last dot
  var urlparts = emailurl.split(".")
  
  // check to see if there are any dot's in the string
  // more than one is ok
  if (urlparts.length <= 1)
  {
    alert("Invalid e-Mail address.\nRe-enter your right e-Mail address, please.");
    return false;
  }
  
  // Check to see how long the last urlpart is
  // Must be either two or three characters long
  if (urlparts[urlparts.length - 1].length < minimumextlength || 
  urlparts[urlparts.length-1].length > maximumextlength)
  {
  alert("Invalid e-Mail address.\nRe-enter your right e-Mail address, please.");
  return false;
  }
  
  // Check all characters of the address to make sure there are no
  // invalid characters - default allows the use of an underscore
  // although that is technically not allowed in a domain name
  // it's not that big a risk as it is allowed in the email name.
  for (i=0; i < emailvar.length-1; i++) 
  {
    urltestchar = emailvar.substr(i,1)
    for (var ii=0; ii < acceptable.length; ii++) 
    {
      if (urltestchar == acceptable[ii]) charok = 1
    }
    if (charok == 0)
    {  
      alert("Invalid e-Mail address.\nRe-enter your right e-Mail address, please.");
      return false;
    }
    charok = 0
  }
  
  // check to make sure the length of the string prior to the 
  // extension is greater than minimumextlength
  if (emailurl.length-urlparts[urlparts.length - 1].length-1 < minimumextlength)
  {
    alert("Invalid e-Mail address.\nRe-enter your right e-Mail address, please.");
    return false;
  }
  
  // check to make sure the length of the string prior to the 
  // domain is greater than minimumextlength
  if (emailnameonly.length < minimumextlength)
  {
  alert("Invalid e-Mail address.\nRe-enter your right e-Mail address, please.");
  return false;
  }
}

function cek_telp(ini)
{
  var i = 33;
	for(i=33;i<256;i++)
	{
		if(i==48) i=58;
		aneh = String.fromCharCode(i);
		if(aneh!= '+')
		{
			if(ini.value.indexOf(aneh,0) != -1)
			{
				alert('Invalid Phone Number , Re-enter your right Phone Number');
				ini.value = "";
				ini.focus();
				return false;
			}
		}
	}
}

//Cek form Kontak.
function cek_gb()
{
	if(this.document.form_gb.name.value=="")
	{
	alert("Enter your name, please.");
	this.document.form_gb.name.focus();
	return false;
	}
	if(this.document.form_gb.state.value=="")
	{
		alert("Select your state, please.");
		this.document.form_gb.state.focus();
		return false;
	}
	if(this.document.form_gb.email.value=="")
	{
	alert("Enter your e-Mail address, please.");
	this.document.form_gb.email.focus();
	return false;
	}
	if(this.document.form_gb.comment.value=="")
	{
	alert("Enter your comment, please.");
	this.document.form_gb.comment.focus();
	return false;
	}
	return cek_telp(this.document.form_gb.phone);
	return cek_email(this.document.form_gb.email);
}

function cek_search()
{
	if(this.document.form_search.key.value=="")
	{
	alert("Enter your keyword, please.");
	this.document.form_search.key.focus();
	return false;
	}
	if(this.document.form_search.key.value.length < 3)
	{
	alert("Keyword min 3 characters.");
	this.document.form_search.key.focus();
	return false;
	}
}