// JavaScript Document
//Validate string by input is empty
function isEmpty(str)
{
	if(del_space(str)=="")
		return true;
	else
		return false;
}
//Compare two string
function isEqual(str1,str2)
{
	if(del_space(str1)==del_space(str2))
		return true;
	else
		return false;
}
//Validate string by input is safe
function isSafe(str)
{
	var reg=/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/;
	if(reg.test(reg))
		return true;
	else
		return false;
}
//Validate Email by input is correct
function isCorrectEmail(str)
{
	//var reg=/^[_a-z0-9\.]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;
	 var reg=/^([\w-\']+(?:\.{0,2}[\w-\']+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,16}(?:\.[a-z]{2})?)$/i
	 if (reg.test(str))
		return true
	 else
		return false		
	
}
//Validate Email by input is currency
function isCurrency(str)
{
	var reg=/^\d+(\.\d+)?$/;
	if(reg.test(str))
		return true;
	else
		return false;
}
//Validate Url by input is correct
function isUrl(str){
	var reg=/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
	if(reg.test(str))
		return true;
	else
		return false;
}
//Validate Url by input is Number
function isNumber(str)
{
	var reg=/^\d+$/;
	if(reg.test(str))
		return true;
	else
		return false;
}
//Validate Url by input is Number
function isInteger(str)
{
	var reg=/^[-\+]?\d+$/;
	if(reg.test(str))
		return true;
	else
		return false;
}
//Validate Url by input is Number
function isDouble(str)
{
	var reg=/^[-\+]?\d+(\.\d+)?$/;
	if(reg.test(str))
		return true;
	else
		return false;
}
//delete space in str
function del_space(str)
{
	for(i=0;i<str.length;++i)
	{
	 if(str.charAt(i)!=" ")
		break;
	}

	for(j=str.length-1;j>=0;--j)
	{
	 if(str.charAt(j)!=" ")
		break;
	}

	return str.substring(i,++j);
}


//limit the amount of text entered in textarea
function textareaCounter(field,maxlimit) {
	if (field.value.length > maxlimit){ // if too long...trim it!

		alert("The amount of text you have entered has exceeded the maximum!")
		field.value = field.value.substring(0, maxlimit);
	}

}


