// JavaScript Document
function setGmailDefaults(){
  document.getElementById('portnum').value='995';
  document.getElementById('sslpop').checked=true;
  document.getElementById('pop3user').focus();
}

function confirm_submit2q(popusr,popsvr){
  return confirm('Clicking the OK button will clear the inbox for \n' + popusr + ' on ' + popsvr +'\n\nAre you sure this is want you want to do?');
}

function isUnsignedInteger(s) {
  return (s.toString().search(/^[0-9]+$/) == 0);
}

function echeck(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 Address");
		   return false;
		}

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

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

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

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

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

		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address");
		    return false;
		 }

 		 return true;
	}

function confirm_mainzapform1_Step1(){
	var emailID=document.getElementById('mailto');

	if ((document.getElementById('pop3server').value==null)||(document.getElementById('pop3server').value=="")){
		alert("POP3 Server required.");
		document.getElementById('pop3server').focus();
		return false;
	}
	else if ((document.getElementById('portnum').value==null)||(document.getElementById('portnum').value=="")){
		alert("Port Number required.");
		document.getElementById('portnum').focus();
		return false;
	}
	else if(isUnsignedInteger(document.getElementById('portnum').value)!=true){
    alert("Invalid Port Number");
    document.getElementById('portnum').focus();
    return false;
  }
	else if ((document.getElementById('pop3user').value==null)||(document.getElementById('pop3user').value=="")){
		alert("POP3 Username (e.g. login id) required.");
		document.getElementById('pop3user').focus();
		return false;
	}
	else if (document.getElementById('agree2legal').checked == false){
		alert("You must agree to legal terms before continuing.");
		document.getElementById('agree2legal').focus();
		return false;
	}
	else if ((emailID.value==null)||(emailID.value=="")){
		alert("You Haven't Entered an Email Address");
		emailID.focus();
		return false;
	}
	else if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
  else return true;
}

function confirm_zapform2_Step3(){
	if ((document.getElementById('pop3pwd').value==null)||(document.getElementById('pop3pwd').value=="")){
		alert("POP3 Password required.");
		document.getElementById('pop3pwd').focus();
		return false;
	}
	else if((document.getElementById('pop3pwd2').value==null)||(document.getElementById('pop3pwd2').value=="")){
		alert("Retype POP3 Password required.");
		document.getElementById('pop3pwd2').focus();
		return false;
  }
	else if (document.getElementById('pop3pwd').value != document.getElementById('pop3pwd2').value){
		alert("POP3 Passwords do not match.");
		document.getElementById('pop3pwd').focus();
		return false;
	}
	else return true;
}