function showRegAgreement() {

 popupWin = window.open('http://www.directcomplaint.com/registrationagreement.htm',

 'open_window',

 'scrollbars, menubar, resizable, dependent, width=640, height=480, left=0, top=0')

}

function regFormValidate(submitBtn)
{
	if (!submitBtn || !submitBtn.form)
		return;

	submitBtn.disabled = true;

	var msg = "Please enter a value for each of the following required fields:  \n";
	var firstMissingFld = null;

	for (var i = 0; i < submitBtn.form.length; i++)
	{
		var elm = submitBtn.form.elements[i];
		var required = elm.getAttribute("required");
		if (!required || (required.toLowerCase() != "true"))
			continue;

		var hasValue = true;
		switch (elm.type.toLowerCase())
		{
			case "text":
            	if (_trim(elm.value).length == 0)
					hasValue = false;
                else if(elm.id == "Zipcode") {
                  if(!IsNumeric(elm.value)){
                   msg += '\n    Zipcode may only contain numbers';
                   if (!firstMissingFld)
			         firstMissingFld = elm;
                  }
                  else if(elm.value.length < 5){
                     msg += '\n    Zipcode must be at least 5 digits';
                     if (!firstMissingFld)
			         firstMissingFld = elm;
                     }
                }
                else if(elm.id == "email" && !CheckEmail(elm.value)){
                     msg += '\n    Invalid e-mail address';
                    if (!firstMissingFld)
			    	firstMissingFld = elm;
                }
                break;
			case "textarea":
            case "checkbox":
            if(elm.id == "agreeTerms" && !elm.checked){
              msg += '\n    You must agree to the terms of service';
              if (!firstMissingFld)
			  firstMissingFld = elm;
            }
            break;
			case "select-one":
			case "select-multiple":
				if (elm.selectedIndex == 0)
					hasValue = false;
				break;
            case "password":
            newelm = submitBtn.form.elements[++i];
                if(elm.value != newelm.value){
                 msg += "\n    " + "Blank or mismatched passwords.";
              if (!firstMissingFld)
			  firstMissingFld = elm;
                }
              else if(elm.value.length < 6){
              msg += "\n    " + "Password must be at least 6 characters long.";
              if (!firstMissingFld)
			  firstMissingFld = elm;
                }
                break;
		}

		if (!hasValue)
		{
			msg += ('\n    ' + elm.id);
			if (!firstMissingFld)
				firstMissingFld = elm;
		}
	}

	if (!firstMissingFld)
		submitBtn.form.submit();
	else
	{
		alert(msg);
		_select(firstMissingFld);
		submitBtn.disabled = false;
	}

	return !firstMissingFld;

	function _trim(str) { return str.replace(/^\s*|\s*$/g, ''); }

	function _select(elm)
	{
		elm.focus();
		if (elm.type=="text" || elm.type=="textarea")
			elm.select();
	}

}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;


   for (i = 0; i <= sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

   }
function CheckEmail(email) {
var AtPos = email.indexOf("@")
var StopPos = email.lastIndexOf(".")
var good = true;

if (email == "") {
good = false;
}
if (AtPos == -1 || StopPos == -1) {
good = false;
}

if (StopPos < AtPos) {
good = false;
}

if (StopPos - AtPos == 1) {
good = false;
}

return good;
}
