function validateEmailAddress (str) { 
	
	
     	var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true	
}


// This validates email form. Any fields listed in a form

// field named "required" are required.




function validateEmailForm (emailForm) {


      if (emailForm.required && emailForm.required.value != "") {

            var reqFields = emailForm.required.value.split(",");

 
            for (var i=0; i<reqFields.length; i++) {

                  var fname = reqFields[i];

					

                  // Strip whitespace

                  while (fname.length > 0 && fname.charAt(0) == " ") {

                        fname = fname.substring(1);

                  }

                  while (fname.length > 0 && fname.charAt(fname.length - 1) == " ") {

                        fname = fname.substring(0, fname.length - 1);

                  }

 

                  if (emailForm[fname]) {

                        var f = emailForm[fname];

                        var isEmpty = false;

 

                        if (f.type == 'text' || f.type == 'textarea' ) {

                              if (f.value == '' || (f.value).replace(/\s/g, '') == '') { 
                              
                                    isEmpty = true;

                              }

                        } else if (f.type == 'checkbox') {

                              if (!f.checked) {

                                    isEmpty = true;

                              }

                        } else if (f.type == 'select-multiple') {

                              if (f.selectedIndex < 0) {

                                    isEmpty = true;

                              }

                        } else if (f.type == 'select' || f.type == 'select-one') {

                              if (f.selectedIndex < 0 || f.options[f.selectedIndex].value ==  '') {

                                    isEmpty = true;

                              }

                        } else if (!f.type) {

                              // Assume the object is an array of radio buttons

                              isEmpty = true;

                              for (var j=0; j<f.length; j++) {

                                    if (f[j].checked) {

                                          isEmpty = false;

                                          break;

                                    }

                              }

 

                              // radio buttons cannot be focused.

                              f = null;

                        }

 

                        if (isEmpty) {

                              alert("Please provide information for " + fname + ".");

                              if (f != null) {

                                    if (f.focus) {

                                          f.focus();

                                    }

                                    if (f.select) {

                                          f.select();

                                    }

                              }

                              return false;

                        }

                  }

            }

      }

 
      
	  var emailID = emailForm.e_mail;
    var retval =   validateEmailAddress(emailID.value);
      		
  	if (emailForm.validate && emailForm.validate.value != '') {
		retval = eval(emailForm.validate.value + '(emailForm)');
	}

	if (retval == true && !(emailForm.redirect && emailForm.redirect.value != "")) {
		msgWindow = window.open("", "SendEmailWindoid","height=400,width=400,resizable=1");
		emailForm.target = "SendEmailWindoid";
		
		// Copy fields to hidden fields.
		for (var i=0; i<emailForm.length; i++) {
			var f = emailForm.elements[i];
			if (f.type == 'hidden' && f.name.substring(0, 2) == 'i_') {
				var nonHidden = emailForm.elements[f.name.substring(2)];
				if (nonHidden != null) {
					f.value = nonHidden.value;
					nonHidden.value = '';
				}
			}
		}
	}
   	return retval;
}

