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 alert=function(msg)
{
	var errdiv = $('body-error');
	errdiv.innerHTML=msg;
	errdiv.style.display='';

	$(errdiv).scrollTo();

};

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}$/;
	urlRe	= /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

	
	if(color!="undefined")
	{
		color='yellow';
	};
	switch(data_type.toLowerCase())
	{
		case "null" :
		case "blank" :
		case "empty" :
			if(/^\s*$/.test($F(id)))
			{
				if(color!="undefined")
				{
					$(id).style.background=color;
				};
				alert(value+" is required.");
				return false;
			};
		break;
		case "email" :
			if (!emailRe.test($F(id)))
			{
				$(id).focus();
				alert(value+" is invalid.");
				if(color!="undefined")
				{
					$(id).style.background=color;
				};
				return false;
			};
		break;
		case 'url':
			if (!urlRe.test($F(id)))
			{
				$(id).focus();
				alert(value+" is invalid.");
				if(color!="undefined")
				{
					$(id).style.background=color;
				};
				return false;
			};
		break;
		case "mobile" :
			if (!phoneRe.test($F(id)))
			{
				$(id).focus();
				alert(value+" is invalid.");
				if(color!="undefined")
				{
					$(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($F(id),"0123456789- "))
			{
				$(id).focus();
				alert(value+" is invalid.");
				if(color!="undefined")
				{
					$(id).style.background=color;
				};
				return false;
			}
		break;
		default :
			if (!IsNumeric($F(id),data_type))
			{
				$(id).focus();
				alert(value+" is invalid.");
				if(color!="undefined")
				{
					$(id).style.background=color;
				};
				return false;
			}
	};
	return true;
};
