
  function validateEmail( strID, row )
  {
    var bValid = true;
    var cell=document.getElementById('contact_table').rows[row].cells;

    var str;
    str = document.getElementById( strID ).value;

    if( str == null || str == "" ) bValid = false;
    else if( str.length < 8 ) bValid = false;
    else if( str.indexOf("@") == -1 ) bValid = false;
    else if( str.indexOf(".") == -1 ) bValid = false;
	    
		if( bValid == false ) {
		
			cell[2].innerHTML   = "Required field"
			cell[2].style.color = "red";
			return true;
		}
		else {
		
			cell[2].innerHTML   = "&nbsp;"
			return false;
		}

	    return true;
	}
	
	function validatePhone( str, bForeign )
	{
		if( str == null || str == "" ) return false;
		if( bForeign == true ) return true;
		
	    if( str.length < 10 ) return false;
	    
	    var iDigits = 0;
	    
	    for( var i=0; i<str.length; i++ ) {
	    
	        if( "0" <= str.charAt(i) && str.charAt(i) <= "9" ) {

              iDigits++;	        
	        }
	    }

      if( iDigits < 10 ) return false;
	    return true;
	}
	
	function formatPhone2()
	{
    var str = document.getElementById( "hphone" ).value;
		document.getElementById( "hphone" ).value = formatPhone( str, false );
	}

	function formatPhone( str, bForeign )
	{
		if( bForeign ) return str;
		if( str == null || str == "" ) return str;
    if( str.length < 10 ) return str;
	    
	    var i;
	    var iDigits = 0;
	    var digit = new Array();
	    var ch;
	    var strNew = "";
	    
	    for( i=0; i<str.length; i++ ) {
	    
	        ch = str.charAt(i);
	        
	        if( "0" <= ch && ch <= "9" ) {

              digit[iDigits] = ch;
              iDigits++;	        
	        }
	    }

        if( iDigits < 10 ) return str;
        
        strNew = digit[0] + digit[1] + digit[2] + "-" + digit[3] + digit[4] + digit[5] + "-" + digit[6] + digit[7] + digit[8] + digit[9];
        
        if( 10 < iDigits ) {
        
            strNew += " ext ";
            
            for( i=10; i<iDigits; i++ ) {
            
                strNew += digit[i];
            }
        }
        
	    return strNew;
	}
	
	function validateString( strID, row )
	{
    var str;
		var cell=document.getElementById('contact_table').rows[row].cells;
        
	    if( row == 4 ) {
	    
		    var state = document.getElementById( "state" );
		    str = state.options[state.selectedIndex].value;
	    }
	    else {
	    
		    str = document.getElementById( strID ).value;
		}
		
		if( str == null || str == "" ) {
		
			cell[2].innerHTML   = "Required field"
			cell[2].style.color = "red";
			return true;
		}
		else {
		
			cell[2].innerHTML   = "&nbsp;"
			return false;
		}
	}

	function validate()
	{
		var bInvalid = false;
		bInvalid |= validateString( "fname", 0 );
		bInvalid |= validateString( "lname", 1 );
		bInvalid |= validateString( "addr1", 2 );
		bInvalid |= validateString( "city", 3 );
		bInvalid |= validateString( "state", 4 );
		bInvalid |= validateString( "zipcode", 5 );
		bInvalid |= validateEmail( "email1", 6 );
		
    str = document.getElementById( "hphone" ).value;
		document.getElementById( "hphone" ).value = formatPhone( str, false );

		if( !bInvalid ) {
		
		    var submit = document.getElementById( "submit" );
		    var reset = document.getElementById( "reset" );
		    var stat = document.getElementById( "stat" );
		    submit.style.visibility = "hidden";
		    reset.style.visibility = "hidden";
		    stat.innerHTML = "Please wait while we process your request...";
		    stat.style.color = "green";
        }
        
		return !bInvalid;
	}
	
	function ALS_reset()
	{
	    for(var i=0; i<7; i++ ) {
    		var cell=document.getElementById('contact_table').rows[i].cells;
		    cell[2].innerHTML = "&nbsp;"
			}
	}