function jtrim(str)
{     while ((str.charAt(0) ==" ")||(str.charAt(0) =="กก"))
          {str=str.substr(1);}      
     while (str.charAt(str.length-1)==" ")
         {str=str.substr(0,str.length-1);}
     return(str);
}
function CheckNull(thisField,thisMassage)
{
	var checkStr = jtrim(thisField.value);
	if (checkStr == "")
	{
		alert(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckLength(thisField,iVar,jVar,thisMassage)
{
	var checkStr = thisField.value;
	if (checkStr.length < iVar || checkStr.length > jVar)
	{
		alert(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckFirstChar(thisField,thisMassage)
{
	var checkOK = "abcdefghijklmnopqrstuvwxyz";
	var checkStr = thisField.value;
	var allValid = true;
	checkStr = checkStr.toLowerCase();
	ch = checkStr.charAt(0);
	for (j = 0; j < checkOK.length; j++)
		if (ch == checkOK.charAt(j))
			break;
	if (j == checkOK.length)
	{
		allValid = false;
	}
	if (!allValid)
	{
		alert(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckvarcharAndNumber(thisField,thisMassage)
{
	var checkOK = "abcdefghijklmnopqrstuvwxyz0123456789";
	var checkStr = thisField.value;
	var allValid = true;
	checkStr = checkStr.toLowerCase();
	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(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckChar(thisField,thisMassage)
{
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var checkStr = thisField.value;
	var allValid = 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(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckNumber(thisField,thisMassage)
{
	var checkOK = "0123456789";
	var checkStr = thisField.value;
	var allValid = 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(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckPhone(thisField,thisMassage)
{
	var checkOK = "0123456789+*()-";
	var checkStr = thisField.value;
	var allValid = 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(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckIP(thisField,thisMassage)
{
	var checkOK = "0123456789.";
	var checkStr = thisField.value;
	var allValid = 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(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckEmail(thisField,thisMassage)
{
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@._-";
	var checkStr = thisField.value;
	var allValid = true;
	var at = 0;
	var dot = 0;
	for (i = 0; i < checkStr.length; i++)
	{
		ch = checkStr.charAt(i);
		if (ch == '@') at = 1;
		if (ch == '.') dot = 1;
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}
	if (!allValid || at == 0 || dot == 0)
	{
		alert(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}


function CheckWebSite(thisField,thisMassage)
{

	var mystring=thisField.valuetoUpperCase();
	var i;
	
	i=mystring.search("HTTP");
	if (i==-1)
			{
			alert(thisMassage);
			return false;
		}
	else 
		return true;
		
		
		
	


}
function CheckDomainName(thisField,thisMassage)
{
	var checkOK = "abcdefghijklmnopqrstuvwxyz0123456789-";
	var checkStr = thisField.value;
	var allValid = true;
	checkStr = checkStr.toLowerCase();
	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(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckCharAndNumberFirstChar(thisField,thisMassage)
{
	
	var checkStr = thisField.value;
	var allValid = true;
	checkStr = checkStr.toLowerCase();
	if(checkStr.charAt(0)=="-")
	{
	    allValid = false;
			
	}
	
	if (!allValid)
	{
		alert(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckUserName(thisField,thisMassage)
{
	var checkOK = "abcdefghijklmnopqrstuvwxyz0123456789-_";
	var checkStr = thisField.value;
	var allValid = true;
	checkStr = checkStr.toLowerCase();
	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(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
function CheckUserNameFirstChar(thisField,thisMassage)
{
	
	var checkStr = thisField.value;
	var allValid = true;
	checkStr = checkStr.toLowerCase();
	if(checkStr.charAt(0)=="-")
	{
	    allValid = false;
			
	}
		if(checkStr.charAt(0)=="_")
	{
	    allValid = false;
			
	}
	
	if (!allValid)
	{
		alert(thisMassage);
		thisField.focus();
		return (false);
	}
	return true;
}
