var ErrorCount = 0;
var ErrorMsg = new Array();
		
ErrorMsg[0] = "------------------------- The Following Errors Occured -------------------------";

/* To validate the type of input values in the form fields */
function CheckFieldString(type, formField, strMsg)
{
	// debugging code
	//if (type == 'radio' || type == 'checkbox')
	//	alert(type);
	//else
	//	alert(type + '/' + formField.name + '/' + formField.value);
		
	var checkOK;
	var checkStr;
  	var allValid = true;
	var flagDot  = false;
	var namestr, domainstr;
	
	if (type == 'noblank')
	{
		if (formField.value == "")
  		{
  			ErrorCount++;
	   	 	ErrorMsg[ErrorCount] = strMsg;
			if (ErrorCount == 1 && !formField.disabled) formField.focus();
			return false;
  		}
		return true;
	}
	else if (type == 'integer')
	{
  		checkOK = "0123456789";
  	}
	else if (type == 'decimal')
	{	
  		checkOK = "0123456789.";
	}
	else if (type == 'text')
	{
/*		checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "; */
		checkOK = text_chars;
	}
	else if (type == 'alphanumeric')
	{
/*		checkOK = "0123456789.+-_#,/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ()_"; */
		checkOK = alphanumeric_chars;
	}
	else if (type == 'full')
	{
/*		checkOK = "0123456789.,[]{}=+-_#,/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ()_:;'\\*^%$@<>?'\"\'"; */
		checkOK = full_chars;
	}
	else if (type == 'alphanum')
	{
/*		checkOK = "0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "; */
		checkOK = alphanum_chars;
	}
	else if (type == 'name')
	{
		if (! ereg_name.test(formField.value) )
		{
			ErrorCount++;
			ErrorMsg[ErrorCount] = strMsg;
			if (ErrorCount == 1) formField.focus();
			return false;
		}
		return true;
	}
	else if (type == 'email')
	{
		//if (! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,7})+$/.test(formField.value) )
		if (! ereg_email.test(formField.value) )
		{
			ErrorCount++;
			ErrorMsg[ErrorCount] = strMsg;
			if (ErrorCount == 1) formField.focus();
			return false;
		}
		return true;
	}
	else if (type == 'phone')
	{
		//checkOK = "0123456789-+";
		if (! ereg_phone.test(formField.value) )
		{
			ErrorCount++;
			ErrorMsg[ErrorCount] = strMsg;
			if (ErrorCount == 1) formField.focus();
			return false;
		}
		return true;
	}
	else if (type == 'password')
	{
		if (! ereg_password.test(formField.value) )
		{
			ErrorCount++;
			ErrorMsg[ErrorCount] = strMsg;
			if (ErrorCount == 1) formField.focus();
			return false;
		}
		return true;
	}
	else if (type == 'username')
	{
		if (! ereg_username.test(formField.value) )
		{
			ErrorCount++;
			ErrorMsg[ErrorCount] = strMsg;
			if (ErrorCount == 1) formField.focus();
			return false;
		}
		return true;
	}
	else if (type == 'URL')
	{
		checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.:/\\";
	}
	else if (type == 'path')
	{
		checkOK = "0123456789.+-_#,/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz () \\ ";
	}
	else if (typeof type == "number")
	{
		if (type > 0)
		{
			if (formField.value.length > type)
			{
				ErrorCount++;
				ErrorMsg[ErrorCount] = strMsg;
				if (ErrorCount == 1) formField.focus();
				return false;
			}
		}
		else
		{
			if (formField.value.length < -type)
			{
				ErrorCount++;
				ErrorMsg[ErrorCount] = strMsg;
				if (ErrorCount == 1) formField.focus();
				return false;
			}
		}
		return true;
	}
	else if (type == 'radio' || type == 'checkbox')
	{
		var dummy = null;
		
		for (i=0; i < formField.length; i++)
		{
			if (formField[i].checked)
			{
				dummy = i;
				break;
			}
		}
		
		if (dummy == null)
		{
			ErrorCount++;
			ErrorMsg[ErrorCount] = strMsg;
			if (ErrorCount == 1) formField[0].focus();
			return false;
		}
		return true;
	}
	else
	{
		ErrorMsg[1] = "Check Validation one of the mentioned validation type is wrong:" . strMsg;
		ErrorCount++;
		if (ErrorCount == 1) formField.focus();
		return false;
	}
	
	checkStr = formField.value;
	
	if (checkOK.length > 0)
	{
		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-1)
				{
					ErrorCount++;
					ErrorMsg[ErrorCount] = strMsg;
					if (ErrorCount == 1) formField.focus();
					return false;
				}
			}
		}
		
		if (type == 'decimal') /* for decimal type */
		{
			for (t = 0; t < checkStr.length; t++)
			{
				dot = checkStr.charAt(t);
				if (dot == '.' && flagDot == false)
				{
					flagDot = true;
				}
				else if (dot == '.' && flagDot == true)
				{
					ErrorCount++;
					ErrorMsg[ErrorCount] = strMsg;
					if (ErrorCount == 1) formField.focus();
					return false;
				}
			}
		}
	}
	return true;
}
