
// JavaScript Document
// JavaScript Document
// JScript source code

var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkEmail(email)
{
	var splitted = email.match("^(.+)@(.+)$");
	if(splitted == null) return false;
	if(splitted[1] != null )
	{
		var regexp_user=/^\"?[\w-_\.]*\"?$/;
		if(splitted[1].match(regexp_user) == null)
		return false;
	}
	
	if(splitted[2] != null)
	{
		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		if(splitted[2].match(regexp_domain) == null) 
		{
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if(splitted[2].match(regexp_ip) == null)
			return false;
		}
		return true;
	}
	return false;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function trim(inputString)
{
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") 
	{
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") 
	{
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) 
	{
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	return retValue;
}
function validater()
{
	var flag=false;
	var focus=false;
	var err_msg="";
	var theFrmm=document.adminForm_2;
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	if(trim(theFrmm.aics_fname.value) =='')
	 {
		 
		flag=true;
		alert("Please Enter First Name!");
		theFrmm.aics_fname.focus();
		return false;
	}
	
	else if(trim(theFrmm.aics_fname.value) =='First Name')
	 { 
	 
		flag=true;
		alert("Please Enter First Name!");
		theFrmm.aics_fname.focus();
		return false;
	}
	
	else if(trim(theFrmm.aics_fname.value) !='')
	 { 
		var test=false;
		for (var i = 0;i<theFrmm.aics_fname.value.length;i++) 
		 {
		  if (iChars.indexOf(theFrmm.aics_fname.value.charAt(i)) != -1) 
		  { 
		   test=true;
		  }
		 }
		 if(test==true)
		 {
			flag=true;
			alert("The First Name has special characters. \nThese are not allowed.\n");
			theFrmm.aics_fname.focus();
			return flase;
		 }
	}
	if(trim(theFrmm.aics_lname.value) =='')
	 {
		flag=true;
		alert("Please Enter Last Name!");
		theFrmm.aics_lname.focus();
	    return false;
	}
	else if(trim(theFrmm.aics_lname.value) =='Last Name')
	 {
		flag=true;
		alert("Please Enter Last Name!");
		theFrmm.aics_lname.focus();
		return false;
	}
	
	else if(trim(theFrmm.aics_lname.value) !='')
	 { 
		var test=false;
		for (var i = 0;i<theFrmm.aics_lname.value.length;i++) 
		 {
		  if (iChars.indexOf(theFrmm.aics_lname.value.charAt(i)) != -1) 
		  { 
		   test=true;
		  }
		 }
		 if(test==true)
		 {
			flag=true;
			alert("The Last Name has special characters. \nThese are not allowed.\n");
			theFrmm.aics_lname.focus();
			return flase;
		 }
	}
	
	
	
   
	

	
	if(trim(theFrmm.aics_email.value) =='')
	{
		flag=true;
		alert("Please Enter Email Id!");
		theFrmm.aics_email.focus();
         return false;
	}
	
	if(trim(theFrmm.aics_email.value) =='Email Address')
	{
		flag=true;
		alert("Please Enter Email Id!");
		theFrmm.aics_email.focus();
         return false;
	}
	
	else if(trim(theFrmm.aics_email.value) !='')
	{
		 if(!checkEmail(trim(theFrmm.aics_email.value)))
		{
		flag=true;
		alert("Please Enter Valid Email Id!");
		theFrmm.aics_email.focus();
		return false;
		}
	}
	
	
	
	if(trim(theFrmm.aics_subject.value) =='')
	 {
		flag=true;
		alert("Please Select a Subject!");
		theFrmm.aics_subject.focus();
		return false;
	}
	
	if(trim(theFrmm.aics_message.value) =='Message')
	 {
		flag=true;
		alert("Please Enter Your Message!");
		theFrmm.aics_message.focus();
		return false;
	}
	
	if(trim(theFrmm.aics_message.value) =='')
	 {
		flag=true;
		alert("Please Enter Your Message!");
		theFrmm.aics_message.focus();
		return false;
	}
	alert('Since this is an unsecured message, please do not send personal account information (account numbers, social security number, etc.) or other confidential information through standard email.');
	theFrmm.submit();
	return true;
	
}

function submitform()
     {
		 if(trim(document.branchlocator.txtzip.value) =='' || trim(document.branchlocator.txtzip.value) =='Enter address or ZIP')
		 {
			alert("Please Enter Zip Code!");
			document.branchlocator.txtzip.focus();
			return false;
		}

		else if(trim(document.branchlocator.txtzip.value)!='')
		 {
		  var test=false;
		  for (var i = 0;i<document.branchlocator.txtzip.value.length;i++) 
		  {
		  if (iChars.indexOf(document.branchlocator.txtzip.value.charAt(i)) != -1) 
		  { 
		  test=true;
		  }
		  }
		  if(test==true)
		  {
		  flag=true;
		  alert("The Zip Code has special characters. \nThese are not allowed.\n");
		   document.branchlocator.txtzip.focus();
		  return flase;
		  }
		}
		document.branchlocator.submit();
      }

