var bad;
function testAll()
	{
	bad=0;
	passwordV();
	}
function testregister()
	{
	bad=0;
	passwordV();
	}

function noUsername(){
//not used with ipnstock
mt=document.isn.username.value;
if (mt.length<4){
	alert("Please enter a username.  (at least 4 letters)");
	document.isn.focus();
	bad++;
	return false;
	} 

else {
     isAlphanumeric();
     }

return true;
}

function isAlphanumeric(mt)
{   
var i;
na=0;
s=document.isn.username.value;

    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
	na = 1;
    }

   if (na > 0){
	alert("Usernames must be alphanumeric. (letters and numbers, no spaces)");
	bad++;
        return false;
    }
    else {
    passwordV();
    }
    return true;
}



function passwordV(){
bone="";
btwo="";
ps=document.isn.password.value;
cps=document.isn.cpassword.value;
if (ps.length<1) {
	alert("You need to enter a password please.");
	bad++;
	return false;
	}
if (ps != cps) {
	alert("The password and confirm password are not the same. Please re-enter the passwords.");
	document.isn.password.value=bone
	document.isn.cpassword.value=btwo;
	bad++;
	return false;
	} else {
		firstname();
		}
return true;
}

function emailCheck() {
//not used in ipnstock
txt=document.isn.email.value;
if (txt.indexOf("@")<2){
	alert("I'm sorry. This email address seems invalid. Please"
	+" check the prefix and '@' sign.");
	bad++;
	return false;
	} else {
		firstname();
		}
return true;
}

function firstname() {
fname=document.isn.firstname.value;
if (fname.length<1){
	alert("Please enter your first name.");
	document.isn.firstname.focus();
	bad++;
	return false;
	} else {
		lastname();
		}
return true;
}

function lastname() {
lname=document.isn.lastname.value;
if (lname.length<1){
	alert("Please enter your last name.");
        document.isn.lastname.focus();
	bad++;
	return false;
	} else {
		companyname();
		}
return true;
}

function companyname() {
lname=document.isn.company.value;
if (lname.length<1){
        alert("Please enter your Company's name.");
        document.isn.company.focus();
        bad++;
        return false;
        } else {
                checkStreet();
                }    
return true;
}


function checkStreet() {
street=document.isn.street.value;
if (street.length<1){
	alert("Please enter your street address.");
	        document.isn.street.focus();
	bad++;
	return false;
	} else {
		checkCity();
		}
return true;
}

function checkCity() {
city=document.isn.city.value;
if (city.length<1){
	alert("Please enter your city.");
        document.isn.city.focus();
	bad++;
	return false;
	} else {
		checkState();
		}
return true;
}

function checkState() {
state=document.isn.state.selectedIndex;
if (state<1){
	alert("Please enter your state / province. You can select none if it does not apply to your country.");
        document.isn.state.focus();
	bad++;
	return false;
	} else {
		checkZip();
		}
return true;
}

function checkZip() {
zip=document.isn.zip.value;
if (zip.length<1){
	alert("Please enter your zip / postal code.");
	        document.isn.zip.focus();
	bad++;
	return false;
	} else {
		checkPhone();
		}
return true;
}

function checkCountry() {
//assumed usa
country=document.isn.country.value;
if (country.length<1){
	alert("Please enter your country.");
        document.isn.country.focus();
	bad++;
	return false;
	} else {
		checkPhone();
		}
return true;
}

function checkPhone() {
phone=document.isn.phone.value;
if (phone.length<1){
        alert("Please enter your telephone number.");
        document.isn.phone.focus();
        bad++;
        return false;
        } else {
                termsBox();
                }
return true;
}


function termsBox(){
if (document.isn.iagree.checked){
	submitCheck();
	} else {
		alert("Please sign the Terms and Conditions agreement by checking the I Agree box which is located just under the large legal text box.");
		}
}

function submitCheck(){
if (bad==0){
	document.isn.submit();
	} else {
	alert('problem with registration');
	}
}

function clearIt(){
document.isn.password.value = "";
document.isn.cpassword.value = "";
document.isn.username.value = "";
document.isn.email.value = "";
document.isn.firstname.value = "";
document.isn.lastname.value = "";
}


function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")))
}
       

    
// Returns true if character c is a digit
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
  


// Returns true if character c is a letter or digit.
     
function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}
 
function isEmpty(mt)
{   return ((mt == null) || (mt.length == 0))
}
 



