        function emailCheck(type)
        {
        var EmailOk  = true
        var Temp     = document.emailForm.emailAddress.value
        var AtSym    = Temp.indexOf('@')
        var Period   = Temp.lastIndexOf('.')
        var Space    = Temp.indexOf(' ')
        var Length   = Temp.length - 1   // Array is from 0 to length-1

        if ((AtSym < 1) ||                // '@' cannot be in first position
            (Period <= AtSym+1) ||        // Must be atleast one valid char btwn '@' and '.'
            (Period == Length ) ||             // Must be atleast one valid char after '.'
            (Space  != -1))                    // No empty spaces permitted
           {
              EmailOk = false;
              alert('Please enter a valid e-mail address.');
              return false;
           }
                if(type == 1)
                {
                document.emailForm.submit();
                }
        }

function valEmail(pField)
{
        var ok = true;
        var AtSym    = pField.value.indexOf('@');
        var Period   = pField.value.lastIndexOf('.');
        var Space    = pField.value.indexOf(' ');
        var Length   = pField.value.length - 1;
        if ((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space  != -1))
        {
                ok = false;
        }
        return (ok);
}

function valLogin()
{
        var f = document.returningCustomer;
        if (f.email.value != '' && f.password.value != '' && valEmail(f.email))
        {
                f.submit();
        }
        else
        {
                if (f.email.value == '' || f.password.value == '')
                {
                        alert('Please be certain to enter both your email address and an accurate password.');
                }
                if (f.email.value != '' && f.password.value != '')
                {
                        if (!valEmail(f.email))
                        {
                                alert('Please be certain you have entered a valid email address.');
                        }
                }
        }
}

function valSignUp()
{
        var f = document.newCustomer;
        if (f.email.value != '' && f.newPassword.value != '' && f.newPassword2.value != '' &&
                f.newPassword.value.length >= 6 && f.newPassword2.value.length >= 6 &&
                f.newPassword.value == f.newPassword2.value && valEmail(f.email))
        {
                f.submit();
        }
        else
        {
                if (f.email.value == '' || f.newPassword.value == '' || f.newPassword2.value == '')
                {
                        alert('Please be certain to enter both your email address and a password.');
                }
                else if (f.email.value != '' &&  !valEmail(f.email))
                {
                        alert('Please be certain you have entered a valid email address.');
                }
                if ((f.newPassword.value.length != 0 && f.newPassword.value.length < 6) ||
                        (f.newPassword2.value.length != 0 && f.newPassword2.value.length < 6))
                {
                        alert('Your password must be at least 6 characters in length.');
                }
                if (f.newPassword.value != '' && f.newPassword2.value != '' &&
                        f.newPassword.value != f.newPassword2.value)
                {
                        alert('Your passwords do not match.');
                }
        }
}
function checkEmail (checkString) 
{
	var newstr="";
	var at = false;
	var dot = false;
// Do some preliminary checks on the data
	if (checkString.indexOf("@") != -1) {
		at = true;

	// if email address has a '.' char.
	} else if (checkString.indexOf(".") != -1) {
		dot = true;
	}

	//Parse the remainder of the string
	for (var i =0; i < checkString.length; i++) {
		ch = checkString.substring( i, i+1)
		if ((ch > "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
			|| (ch == "@") || (ch == ".") || (ch == "_")
			|| (ch == "-") || (ch >= "0" && ch <= "9")) {

			newstr += ch;
			if (ch == "@") {
				at = true;
			}
			if (ch == ".") {
				dot=true;
			}
		}
	}
	if ((at ==true) && (dot == true)) {
		return newstr;
	}
	else {
		// DISPLAY ERROR MESSAGE
		alert ("Sorry , the email address you've entered is not in the correct\n format.");
		return checkString;
	}
}
