/*
Submit Once form validation- 
© Dynamic Drive (www.dynamicdrive.com)

the following functions cover verification for log in forms
verification for e-mail forms is covered in formverify_b.js
*/



function submitonce(f){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<f.length;i++){
var tempobj=f.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}



function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}



function validEmail(e) {
invalidChars = " /:,;"

e = trim(e);

if (e == "")  // cannot be empty
return false

for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
badChar = invalidChars.charAt(i)
if (e.indexOf(badChar,0) > -1)
return false
}

atPos = e.indexOf("@",1) // there must be one "@" symbol
if (atPos == -1) 
return false

if (e.indexOf("@",atPos+1) != -1)	// and only one "@" symbol
return false

periodPos = e.indexOf(".",atPos)
if (periodPos == -1)  		// and at least one "." after the "@"
return false

if (periodPos+3 > e.length) // and at least 2 chars after the "."
return false

return true
}



function action(f,msg,pre,wgt) {
if (pre == 1) {
msg = "Please enter "+msg
}
alert(msg);
f.elements[wgt].focus();
f.elements[wgt].select();
return false;
}



function submitlogin(f) {
	
if (f.f_email.value == "") {
action(f,"an e-mail address",1,"f_email");
return false;
}
else
{
if (!validEmail(f.f_email.value)) {
action(f,"The e-mail address that you have\nentered does not appear to be valid.",0,"f_email");
return false;
}
}


if (f.f_pass.value == "") {
action(f,"a password",1,"f_pass");
return false;
}

submitonce(f);

return true
}
