
function IsValidEmail(val){
    var rx = new RegExp("^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$");
    var matches = rx.exec(val);                     
    return (matches != null && val == matches[0]);
}


function onSubmit(){

	var objForm = document.mainform;
	var action = objForm.aFormAction.value;
	var sendIt = true;

	for (var iCounter=0; iCounter<objForm.length; iCounter++){
	var formEl=objForm.elements[iCounter];
	
	
	/*
	Todo: create generic validation
	if(formEl.type == "checkbox"){
	
	alert(objForm.elements[iCounter].checked);
	
		if(formEl.name.checked == false){
		alert(formEl.name.checked);
		}			
	}
	*/

	    // show validate message
	    if(document.getElementById("required"+formEl.id)){
	            var obj;
	            // required field validation
	            obj = document.getElementById("requiredText"+formEl.id);
	    	    if(obj){
	    	        if(formEl.value == ""){
		                obj.style.display = "inline";
		                sendIt = false;
		                continue;
		            }
		            else{
		                obj.style.display = "none";		                
		            }
   			    }
	    	
	    	
	    		
    		    // email validation if that is the case
	    	    obj = document.getElementById('validEmail' + formEl.id);			        
    	        if(obj){
                    if(!IsValidEmail(formEl.value)){
                         obj.style.display = "inline";
                         sendIt = false;                            
                    }
                    else{
                        obj.style.display = "none";                        
                    }
        	    }
		   }
     }
    
    
  
	if(sendIt==true){
		document.mainform.method="post";
		document.mainform.action=action;
		document.mainform.__VIEWSTATE.name ="NOVIEWSTATE";
		document.mainform.submit();
	}

}

