// JavaScript Document

<!--
//function trim(st){

//var len =st.length;
//var begin = 0, end = len - 1;
//while (st.charAt(begin) == " " && begin < len) {
//	begin++;
//	}
//while (st.charAt(end) == " " begin < end) {
//	end--;
//	}
//return st.substring(begin, end+1);
//}



//validates that a zipcode has been entered into form3
/**
 * makes sure a field is not left empty
 */
function validateFieldNotEmpty(field,name){
	
    if(field.value == "") {
   
		alert("Please fill out the " + name + " field.");
         field.focus();
        return false;
    }
    else {
		
	     return true;
    }
} // end validateFieldNotEmpty

function emailphone(){
if ((document.forms.form3.email.value == "") && (document.forms.form3.phone.value == "")){
	alert("Please enter either a valid E-mail address or Phone number.");
	document.forms.form3.email.focus();
    return false;
	}
	else if (document.forms.form3.email.value != "")
	{ if (emailcheck(document.forms.form3.email) == false)
	 		{document.forms.form3.email.focus(); 
	   		 return false;} }
	else {
    return true;
    }
}

function forceDescription (field) {

var desc = field.value;
if (desc.length < 10 && desc != '\n' && desc != '/n/n')
	{alert("Please provide more information in the case description field.");
	field.focus();
	return false;}
else {return true;}
}

function formatPhone(field) {
    //field.value = trim(field.value);

    var ov = field.value;
    var v = "";
    var x = -1;

    // is this phone number 'escaped' by a leading plus?
    if (0 < ov.length && '+' != ov.charAt(0)) { //format it
        // count number of digits
        var n = 0;
        if ('1' == ov.charAt(0)) {  // skip it
            ov = ov.substring(1, ov.length);
        }

        for (i = 0; i < ov.length; i++) {
            var ch = ov.charAt(i);

            // build up formatted number
            if (ch >= '0' && ch <= '9') {
                if (n == 0) v += "(";
                else if (n == 3) v += ") ";
                else if (n == 6) v += "-";
                v += ch;
                n++;
            }
            // check for extension type section; 
            // are spaces, dots, dashes and parentheses the only valid non-digits in a phone number?
            if (! (ch >= '0' && ch <= '9') && ch != ' ' && ch != '-' && ch != '.' && ch != '(' && ch != ')')
{
                x = i;
                break;
            }
        }
        // add the extension
        if (x >= 0) v += " " + ov.substring(x,ov.length);

        // if we recognize the number, then format it
        if (n == 10 && v.length <= 40) field.value = v;
    }
    return true;
}


function validatezip(field)
{
  var len= field.value.length;
  var digits="0123456789";
  var x=field.value;
  var anum=/(^\d+$)|(^\d+\.\d+$)/;
   if(len !=5)
    {alert('Please enter your 5 digit zip code.');
     document.form3.zipcode.focus();
	 return false;
	 }
	 
//Checks to see if charaters entered are #'s	 
  if (anum.test(x))
  {testresult=true;}
  
  else{
  alert("Zipcodes must be numerical ex. 92109 ")
  document.form3.zipcode.focus();
  return false;
  }
  
  //checks for a valid e-mail address
//if(firstcheck != 1){
///var str = document.form3.email.value;
//var pattern =
///^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/;
//var eflag = pattern.test(str); 
//if ( !eflag ) {
//alert('Please enter a correct email address and submit again.');
//document.form3.email.focus();
//event.returnValue=false;
//return false; }
//}
}

function emailcheck(field){
  //checks for a valid e-mail address

var str = field.value;
var pattern =
/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/;
var flag = pattern.test(str); 
if ( !flag ) {
alert('Please enter a correct email address and submit again.');
document.forms.form3.email.focus();
return false;}
}

//Roll Over & Dropdown Functions
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->

function submitlink() {

window.open('../html/linkform.html','submitlink','width=400,height=500,top=30%,left=100%');    
   
}

function validate_email(email)
{
 
//checks for a valid e-mail address  
var str = email.value;
var pattern =
/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/;
var flag = pattern.test(str); 
if ( !flag ) {
alert('Please enter a correct email address and submit again.');
email.focus();
event.returnValue=false;
return false; }
return true;
}

// handle AAFY home page practice area pulldown
// this function will reload a certain practice area index page
// if there was a value selected in the pull down, otherwise
// nothing will be loaded.

function homePagePAPullDown(targ,selObj,restore) { //v3.0

  var optionValue = selObj.options[selObj.selectedIndex].value;

  if(optionValue !="0")
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;
}
