﻿//	function validate_email(this_str){
	function validate_email(s){	
		var ok = true;
		var at = s.indexOf("@");
		var name = s.substr(0, at);
		var dom = s.substr(at+1);
		var domdot = dom.lastIndexOf(".");
		
		var rn1 = new RegExp("[^A-Za-z0-9._-]|^[._-]");
		var rd1 = new RegExp("[^A-Za-z0-9.-]|^[.-]");

		if(name.search(rn1)!=-1) ok=false;
		if(name.length==0) ok=false;
		
		if(dom.search(rd1)!=-1) ok=false;
		if(domdot<2) ok=false;
		if(dom.length-domdot<3) ok=false;
	
		return ok;
	
	
//		if(this_str.length != 0){
//			var spacer = 3;					//this is the minimum distance between the identifying characters, ie @ and .
//			var at = this_str.indexOf("@");
//			var dot = this_str.indexOf(".", at+spacer);
//			var ok = 0;
			
//			if( at != -1 && dot != -1 ){
//				if (at >=1 && at+spacer<=dot && dot+spacer<=this_str.length){
//					ok = 1
//				}
//			}
//		}
//		return ok
	}




	function validate_radios(fm, el){
		/*
			This simple interates through the radio elements in the specified form element.
			If one is selected then returns the value of that radio otherwise returns -1.
			If the value is null/undefined returns 1
		*/
		this_el = document[fm][el];
		var found = -1;		
		for(var i=0;i<this_el.length;i++){ 
			if(this_el[i].checked){
				if (""+this_el[i].value =="undefined"){
					found = 1;
				} else {
					found = this_el[i].value;
				}
			}
		}
		return found;
	}
	

