var IsNumeric= function (sText,ValidChars)
{
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
};

var check= function(id,data_type,value,color)
{
	emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
	phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
	switch(data_type.toLowerCase())
	{
		case "null" :
		case "blank" :
		case "empty" :
			if(/^\s*$/.test(document.getElementById(id).value))
			{
				alert(value+" is mandatory field.");
				document.getElementById(id).focus();
				if(color!="undefined")
				{
					document.getElementById(id).style.background=color;
				};
				return false;
			};
		break;
		case "email" :
			if (!emailRe.test(document.getElementById(id).value))
			{
				alert(value+" field is invalid.");
				document.getElementById(id).focus();
				if(color!="undefined")
				{
					document.getElementById(id).style.background=color;
				};
				return false;
			};
		break;
		case "mobile" :
			if (!phoneRe.test(document.getElementById(id).value))
			{
				alert(value+" field is invalid.");
				document.getElementById(id).focus();
				if(color!="undefined")
				{
					document.getElementById(id).style.background=color;
				};
				return false;
			}
		break;

		case "PHONE" :
		case "Phone" :
		case "phone" :
		case "Numeric" :
		case "NUMERIC" :
		case "INTEGER" :
		case "Integer" :
		case "integer" :
			if (!IsNumeric(document.getElementById(id).value,"0123456789- "))
			{
				alert(value+" field is invalid.");
				document.getElementById(id).focus();
				if(color!="undefined")
				{
					document.getElementById(id).style.background=color;
				};
				return false;
			}
		break;
		default :
			if (!IsNumeric(document.getElementById(id).value,data_type))
			{
				alert(value+" field is invalid.");
				document.getElementById(id).focus();
				if(color!="undefined")
				{
					document.getElementById(id).style.background=color;
				};
				return false;
			}
	};
	return true;
};
