// JavaScript Document
var whitespace=" \t\n\r";
function IsEmpty(oStr){
	var iIndex;
	var iBlanks;
	if ((oStr==null)||(oStr.length<=0)) return true;
	for(iIndex=0;iIndex<oStr.length;iIndex++){
		/*if ((oStr[iIndex]==' ')||(oStr[iIndex]=='\t')||(oStr[iIndex]=='\n'))
			iBlanks++;*/
		var c=oStr.charAt(iIndex);
		if(whitespace.indexOf(c)==-1)
			return false;
	}
	/*if (oStr.length==iBlanks) return true;
	return false;*/
	return true;
}
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function IsEmail(emailStr) {
		var checkTLD=1;
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		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=emailStr.match(emailPat);
		
		if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
		for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
		alert("Ths username in email contains invalid characters.");
		return false;
		   }
		}
		for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
		alert("Ths domain name in email contains invalid characters.");
		return false;
		   }
		}
		if (user.match(userPat)==null) {
		alert("The username in email doesn't seem to be valid.");
		return false;
		}
		
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
		alert("Destination IP address is invalid!");
		return false;
		   }
		}
		return true;
		}
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
		alert("The domain name does not seem to be valid.");
		return false;
		   }
		}
		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
		}
		if (len<2) {
		alert("This address is missing a hostname!");
		return false;
		}
		return true;
}

function checkArray(form, arrayName)
  {
    var retval = new Array();
    for(var i=0; i < form.elements.length; i++) {
      var el = form.elements[i];
      if(el.type == "checkbox" && el.name == arrayName && el.checked) {
        retval.push(el.value);
      }
    }
    return retval;
  }
  
function howManyChecked(whichForm,whichCheckBoxArray,myMax,myMin,whichQuestion)
{
	var _countChecked = 0;
	var err = 0;
	var len = 0;
	/* iterate through all the elements in the checkbox array */
	if(document[whichForm][whichCheckBoxArray].length)
	{
			len=document[whichForm][whichCheckBoxArray].length
			for(i=0;i<len;i++)
			{
				/* and check to see if each is checked */
				if(document[whichForm][whichCheckBoxArray][i].checked==true)
					/* if it is, increment a counter */
					{ _countChecked++; }
			}
	}
	else if(document[whichForm][whichCheckBoxArray].checked)
	{
			len=1;
			_countChecked++;
	}
	
	//alert(_countChecked);
	/* is the count too high? */
	if(_countChecked > myMax)
		{ alert('Limit '+myMax+' checks for the '+whichQuestion+' question.');
			err = 1;}
	/* of is the count too low */
	else if(_countChecked < myMin)
		{ alert('Check at least '+myMin+' '+whichQuestion+'');
			err = 1;}
	if (err == 1) 
	{ 
	return false; 
	}
	else
	return true;
}
function check_url(address) {
	if(address.match(/w+(\.\w+)*\.(\w{2}|com|net|org|mil|int|edu|gov|info|biz|coop|aero|pro|name|museum)(\/[\w\-\.])*$/) == null){
   return false
}
  return true;
}