/*--------------------Username Validation-----------------------------*/


function Username_Validator(username)
{
 if (username.value == "")
  {
    alert("Please type your \"Username\"");
    return (false);
  }

 if (username.value.length < 6)
  {
    alert("\"Username\" must contain at least 6 characters");
    return (false);
  }
  	
  if (username.value.length > 20)
  	{
      alert("Please enter at most 20 characters in the \"username\" field.");
      return (false);
  	 }
  else
	{
  			var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-._@";
  			var checkStr = username.value;
  			var allValid = true;
  			var validGroups = true;
  			for (i = 0;  i < checkStr.length;  i++)
  			{
    			ch = checkStr.charAt(i);
    			for (j = 0;  j < checkOK.length;  j++)
      			if (ch == checkOK.charAt(j))
       			break;
    			if (j == checkOK.length)
    			{
      			allValid = false;
      			break;
    			}
  			}
  			if (!allValid)
  			{
    			alert("Username must contain only letter, digit, \" .\" , \"_\" and \"@\" characters");
    			return (false);
  			}
     }
}



/*----------------------------Password Validation-----------------------------*/



function Password_Validator(password)
{
	if (password.value == "")
  	{
    	alert("Please type your Password");
    	return (false);
  	}
  	else
  	{
		if (password.value.length < 6)
		{
    		alert("Password must contain at least 6 characters");
    		return (false);
		}
		else
		{

			if (password.value.length > 12)
			{
    			alert("Please enter at most 12 characters in the \"password\" field.");
    			return (false);
  			}
  			else
  			{
				var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-._@";
				var checkStr = password.value;
  				var allValid = true;
  				var validGroups = true;
  				for (i = 0;  i < checkStr.length;  i++)
  				{
    				ch = checkStr.charAt(i);
    				for (j = 0;  j < checkOK.length;  j++)
      				if (ch == checkOK.charAt(j))
        				{break;}
    				if (j == checkOK.length)
    				{
      					allValid = false;
      					break;
    				}
  				}
  				if (!allValid)
  				{
    				alert("Password must contain only letter, digit, \" .\" , \"_\" and \"@\" characters");
    				return (false);
  				}
  			}
  		}
  	}
}




/*----------------------------Name Validation-----------------------------*/


function Name_Validator(name)
{
	if (name.value == "")
  	{
    	alert("Please type your Name");
    	return (false);
  	}
	else
	{
  		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f";
  		var checkStr = name.value;
  		var allValid = true;
  		var validGroups = true;
  		for (i = 0;  i < checkStr.length;  i++)
  		{
    		ch = checkStr.charAt(i);
    		for (j = 0;  j < checkOK.length;  j++)
      		if (ch == checkOK.charAt(j))
        		break;
    		if (j == checkOK.length)
    		{
      			allValid = false;
      			break;
    		}
    		if (!allValid)
  			{
    			alert("Name must contain only letter and whitespace");
    			return (false);
  			}
  		}
  	}
}
  



/*----------------------------IC Validation-----------------------------*/



function IC_Validator(ic)
{
	if (ic.value =="")
	{
		alert("Please type your IC.No");
    	return (false);
  	}

	var checkOK = "0123456789-";
  	var checkStr = ic.value;
  	var allValid = true;
  	var validGroups = true;
  	for (i = 0;  i < checkStr.length;  i++)
  	{
    	ch = checkStr.charAt(i);
    	for (j = 0;  j < checkOK.length;  j++)
      	if (ch == checkOK.charAt(j))
        	break;
    	if (j == checkOK.length)
    	{
      		allValid = false;
      		break;
    	}
  	}
  
  	if (!allValid)
  	{
    	alert("Your IC No is invalid, please check again.");
    	return (false);
  	}
}




/*----------------------------Birth Date Validation-----------------------------*/



function BirthDate_Validator(day, month, year)
{
	if (day.selectedIndex <= 0)
  	{
    	alert("Please select your day of birth");
    	return (false);
  	}
  
  	if (month.selectedIndex <= 0)
  	{
    	alert("Please select your month of birth");
    	return (false);
  	}

  	if (year.selectedIndex <= 0)
  	{
    	alert("Please select your year of birth");
   		return (false);
  	}
}




/*----------------------------Gender Validation-----------------------------*/


function Gender_Validator(gender)
{
  if (gender.selectedIndex <= 0)
  	{
    	alert("Please select your gender");
    	return (false);
  	}
}





/*----------------------------Membership Validation-----------------------------*/


function Membership_Validator(membership)
{
  if (membership.value == "")
  	{
    	alert("Please type your membership no");
    	return (false);
  	}
}




/*----------------------------Address Validation-----------------------------*/




function Address_Validator(address)
{

  if (address.value == "")
  {
    alert("Please type your address");
    return (false);
  }
}




/*----------------------------Postal Code Validation-----------------------------*/



function Poscode_Validator(postcode)
{
	if (postcode.value == "")
  	{
    	alert("Please type your postal code.");
    	return (false);
  	}

  	if (postcode.value.length < 5)
  	{
    	alert("Your postal code is invalid, please check again");
    	return (false);
  	}

  	if (postcode.value.length > 15)
  	{
    	alert("Please enter at most 15 characters in the \"postcode\" field.");
    	return (false);
  	}

  var checkOK = "0123456789";
  var checkStr = postcode.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Your postal code is invalid, please check again");
    theForm.postcode.focus();
    return (false);
  }
}





/*----------------------------Company Registration No. Validation-----------------------------*/





function ComRegistration_Validator(registration_no)
{ 
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-";
  var checkStr = registration_no.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Your company registration no is invalid, please check again");
    return (false);
  }
}




/*----------------------------Contact No. Validation-----------------------------*/


function Contact_Validator(contact1)
{
  
if (contact1.value == "")
  {
    alert("Please type your contact no");
    return (false);
  }


  var checkOK = "0123456789-";
  var checkStr = contact1.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Your contact no is invalid, please check again.");
    return (false);
  }
}








/*----------------------------Fax Validation-----------------------------*/



function Fax_Validator(area3, fax)
{

  if (area3.value == "")
  {
    alert("Please enter a value for the \"area3\" field.");
    return (false);
  }

  if (area3.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"area3\" field.");
    return (false);
  }

  if (area3.value.length > 3)
  {
    alert("Please enter at most 3 characters in the \"area3\" field.");
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = area3.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"area3\" field.");
    return (false);
  }

  if (fax.value == "")
  {
    alert("Please enter a value for the \"fax\" field.");
    return (false);
  }

  if (fax.value.length < 7)
  {
    alert("Your fax no is invalid, please check again");
    return (false);
  }

  if (fax.value.length > 10)
  {
    alert("Please enter at most 10 characters in the \"fax\" field.");
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = fax.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Fax must contain only digit characters");
    fax.focus();
    return (false);
  }
} 
  
  
  
  
  
/*----------------------------Email Validation-----------------------------*/
  
  
  
  
  
  
function Email_Validator(email)
{
  if (email.value == "")
  {
    alert("Please type your e-mail address");
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-@_.";
  var checkStr = email.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Your e-mail address is invalid, please check again");
    return (false);
  }
  
	var apos=email.value.indexOf("@");
	var dotpos=email.value.lastIndexOf(".");
	var lastpos=email.value.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)
	{	
		alert("Your e-mail address is invalid, please check again");
 		return (false);
 	}
}



		


 
 
 /*----------------------------Start Date Validation-----------------------------*/



function StartDate_Validator(day, month, year)
{
	if (day.selectedIndex <= 0)
  	{
    	alert("Please select your day of start date");
    	return (false);
  	}
  
  	if (month.selectedIndex <= 0)
  	{
    	alert("Please select your month of start date");
    	return (false);
  	}

  	if (year.selectedIndex <= 0)
  	{
    	alert("Please select your year of start date");
   		return (false);
  	}
}



 /*----------------------------Expired Date Validation-----------------------------*/



function ExpiredDate_Validator(day, month, year)
{
	if (day.selectedIndex <= 0)
  	{
    	alert("Please select your day of expired date");
    	return (false);
  	}
  
  	if (month.selectedIndex <= 0)
  	{
    	alert("Please select your month of expired date");
    	return (false);
  	}

  	if (year.selectedIndex <= 0)
  	{
    	alert("Please select your year of expired date");
   		return (false);
  	}
}
 