
// This function verifies that an email conforms to RFC 822 email address standard
function isValidEmailAddress(strEmail) 
{
    if (strEmail == null || strEmail == "") 
    {
        return false;
    }
    else 
    {
        // Patterns
        var emailPat=/^(.+)@(.+)$/
        var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
        var validChars="\[^\\s" + specialChars + "\]"
        var quotedUser="(\"[^\"]*\")"
        var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
        var atom=validChars + '+'
        var word="(" + atom + "|" + quotedUser + ")"
        var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
        var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

        var matchArray = strEmail.match(emailPat)
        if (matchArray == null) 
        {
	        return false;
        }

        var user = matchArray[1]
        var domain = matchArray[2]

        // See if "user" is valid 
        if (user.match(userPat) == null) 
        {
            // user is not valid
			return false;
		}

        var IPArray = domain.match(ipDomainPat)
        if (IPArray!=null) 
        {
			// this is an IP address
			for (var i=1;i<=4;i++) 
			{
				if (IPArray[i]>255) 
				{
			        return false;
				}
			}
        }

        // Domain is symbolic name
        var domainArray = domain.match(domainPat)
        if (domainArray == null) 
        {
	        return false;
        }

        // Now we need to break up the domain to get a count of how many atoms it consists of.
        var atomPat = new RegExp(atom,"g")
        var domArr = domain.match(atomPat)
        var len = domArr.length
        if (domArr[domArr.length-1].length < 2 || domArr[domArr.length-1].length > 4) 
        {
           // the address must end in a two, three, or four letter word.
	        return false;
        }

        // Make sure there's a host name preceding the domain.
        if (len < 2) 
        {
	        return false;
        }
    }

    return true;
}

function isAlphaNumeric(strText)
{
	// Check each letter to make sure it's a letter or a number
	for (var i = 0; i < strText.length; i++)
	{
		if ((strText.charAt(i) < '0' || strText.charAt(i) > '9') && (strText.charAt(i) < 'a' || strText.charAt(i) > 'z') && (strText.charAt(i) < 'A' || strText.charAt(i) > 'Z'))
		{
			return false;
		}
	}

	return true;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   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;
   
}
//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}

function isValidIPAddress(strIPAddress)
{
	var VALID_FORMAT = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
	if (VALID_FORMAT.test(strIPAddress)) 
	{
		var strParts = strIPAddress.split(".");
		if (parseInt(parseFloat(strParts[0])) == 0) { return false; }
		for (var i = 0; i < strParts.length; i++) 
		{
			if (parseInt(parseFloat(strParts[i])) > 255) { return false; }
		}

		return true;
	}
	else
	{
		return false;
	}
}
function isHasSpecialChar(strValue)
{
	//var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	var iChars = "!@#$%^&*()[]\\\'{}|\":<>?";
  for (var i = 0; i < strValue.length; i++)
	{
  	if (iChars.indexOf(strValue.charAt(i)) != -1)
		{
			//alert ("The box has special characters. \nThese are not allowed.\n");
			return true;
		}
	}
	return false;
}

function checkDomain(nname)
{
var mai = nname;
var val = true;

var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
	
if(dot>2 && dot<57)
{
	for(var j=0; j<dname.length; j++)
	{
	  var dh = dname.charAt(j);
	  var hh = dh.charCodeAt(0);
	  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
	  {
		 if((j==0 || j==dname.length-1) && hh == 45)	
	  	 {
	 	  	 alert("Domain name should not begin are end with '-'");
		      return false;
	 	 }
	  }
	else	{
	  	 alert("Your domain name should not have special characters");
		 return false;
	  }
	}
}
else
{
 alert("Your Domain name is too short/long");
 return false;
}	

return true;
}

function checkDomain1(nname)
{
var arr = new Array(
'.com','.net','.org','.biz','.coop','.info','.museum','.name',
'.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag',
'.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw',
'.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm',
'.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc',
'.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr',
'.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz',
'.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm',
'.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm',
'.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm',
'.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq',
'.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li',
'.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg',
'.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt',
'.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng',
'.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf',
'.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py',
'.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg',
'.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv',
'.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn',
'.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um',
'.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws',
'.wf','.ye','.yt','.yu','.za','.zm','.zw');

var mai = nname;
var val = true;

var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
	
if(dot>2 && dot<57)
{
	for(var i=0; i<arr.length; i++)
	{
	  if(ext == arr[i])
	  {
	 	val = true;
		break;
	  }	
	  else
	  {
	 	val = false;
	  }
	}
	if(val == false)
	{
	  	 alert("Your domain extension "+ext+" is not correct");
		 return false;
	}
	else
	{
		for(var j=0; j<dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	 alert("Domain name should not begin are end with '-'");
			      return false;
		 	 }
		  }
		else	{
		  	 alert("Your domain name should not have special characters");
			 return false;
		  }
		}
	}
}
else
{
 alert("Your Domain name is too short/long");
 return false;
}	

return true;
}
