﻿   
    
        function g(sV) {
            return document.getElementById(ctl+sV).value
        }
        
        function checkZip(sP) { 
	        // Check for correct phone number 
	        reZip = new RegExp(/^\d{5}$/);
    		
	        if (!reZip.test(sP)) {
		        return false; 
	        }

	        return true; 

        }
        
        function checkEmail(str) {

		    var at="@"
		    var dot="."
		    var lat=str.indexOf(at)
		    var lstr=str.length
		    var ldot=str.indexOf(dot)
		    if (str.indexOf(at)==-1){
		       return false
		    }

		    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		       return false
		    }

		    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		        return false
		    }

		     if (str.indexOf(at,(lat+1))!=-1){
		        return false
		     }

		     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		        return false
		     }

		     if (str.indexOf(dot,(lat+2))==-1){
		        return false
		     }
    		
		     if (str.indexOf(" ")!=-1){
		        return false
		     }

 		     return true					
	    }
    
        function doForm() {
			//
			var msg = "";
			var bGo = true;
			
			if (g("txtFirstname") == "") {			    
			        msg += " - First Name\n";
			        bGo = false;
			}
			
			if (g("txtLastname") == "") {
			        msg += " - Last Name\n";
			        bGo = false;
			}
			
			if (g("txtAddress") == "") {
			        msg += " - Address\n";
			        bGo = false;
			}
			
			if (g("txtCity") == "") {
			        msg += " - City\n";
			        bGo = false;
			}
			
			if (g("drpStates") == "--") {
			        msg += " - State\n";
			        bGo = false;
			}
			
			if (g("txtZip") == "") {
			        msg += " - Zipcode\n";
			        bGo = false;
			} else {
			    if(!checkZip(g("txtZip"))) {
			        msg += " - Zipcode is invalid\n";
			        bGo = false;
			    }
			}
			
			if (g("txtEmail") == "") {
			        msg += " - Email\n";
			        bGo = false;
			} else {
			    if (!checkEmail(g("txtEmail"))) {
			        msg += " - Email is invalid\n";
			        bGo = false;
			    }
			}
			
			if (g("txtPhone") == "") {
			        msg += " - Phone\n";
			        bGo = false;
			}
			
			
			
			
			        
			if (bGo) {
			    //doPost();
			    return true;
			} else {
			    alert("Please correct the following:\n\n" + msg);
			    return false;
			}
		}
    
    



