/* main functions */

function checkForm_fast(form) {
	/* fields: account, h_prefix, h_extension, l_prefix, l_extension 
	 *
	 * XXX: this should be re-factored into an array and actions to 
	 * get rid of the repeated code.
	 */

	if (! checkForm('Number', form.account)) {
		checkFormWarn(form.account, "Account number should be a number");
		return false;
	}

	if (! checkForm('NotNull', form.lastname)) {
		checkFormWarn(form.lastname, "Please add your last name");
		return false;
	}

	if (! checkForm('NotNull', form.email)) {
		checkFormWarn(form.email, "Please add your email address, so we can confirm your order");
		return false;
	}

	return true;
}

function checkForm_dsl(form) {
	/* fields: account, h_prefix, h_extension, l_prefix, l_extension 
	 *
	 * XXX: this should be re-factored into an array and actions to 
	 * get rid of the repeated code.
     * if the existing = Yes then check the account #
	 */
/*	if ( form.existing[0].checked ) { 
	    if (! checkForm('Number', form.account)) {
		    checkFormWarn(form.account, "Account number should be a number");
		    return false;
	    }
   } */

	if (! checkForm('NotNull', form.lastname)) {
		checkFormWarn(form.lastname, "Please add your last name");
		return false;
	}

    if (! checkForm('NotNull', form.firstname)) {
		checkFormWarn(form.firstname, "Please add your first name");
		return false;
	}

	if (! checkForm('NotNull', form.email)) {
		checkFormWarn(form.email, "Please add your email address, so we can confirm your order");
		return false;
	}

	if (! checkForm('TelNumPrefix', form.h_prefix)) {
		checkFormWarn(form.h_prefix, "Home Telephone Number needs more digits");
		return false;
	}

	if (! checkForm('TelNumExtension', form.h_extension)) {
		checkFormWarn(form.h_extension, "Home Telephone Number needs more digits");
		return false;
	}

    //inform the customer that this is for real
    var answer = confirm("This is not a price quote. By continuing you are ordering DSL from PA Online, and we will immediately begin the process of delivering DSL to you. Also, by clicking OK you are acknowledging that there is a $99 early termination fee. Continue?");
    if ( ! answer) {
       return false;
    } 

	// don't bother continuing to check if user didn't add anything
	if (form.l_prefix.value.length == 0) {
		return true;
	}

	if (! checkForm('TelNumPrefix', form.l_prefix)) {
		checkFormWarn(form.l_prefix, "Alternate Telephone Number needs more digits");
		return false;
	}

	if (! checkForm('TelNumExtension', form.l_extension)) {
		checkFormWarn(form.l_extension, "Alternate Telephone Number needs more digits");
		return false;
	}

   //return true;

}

function checkForm(type, field) {
	switch (type) {
		case 'NotNull':
			if (field.value == "") {
				return false;
			}
			return true;
			break;

		case 'Number':
			var ret = new String;
			var str = new String(field.value);
			for (i=0; i<str.length; i++) {
				for (j=0; j<=9; j++) {
					if(j.toString() == str.charAt(i)) {
						ret = ret + str.charAt(i);
					}
				}
			}
			if (ret == "") {
				return false;
			}
			field.value = ret;
			return ret;
			break;

		case 'TelNumPrefix':
			if ( checkForm('Number', field) && field.value.length == 3) {
				return true;
			}
			return false;
			break;

		case 'TelNumExtension':
			if ( checkForm('Number', field) && field.value.length == 4) {
				return true;
			}
			return false;
			break;
	}
}
				
function checkFormWarn(field, warning) {
	alert(warning);
	field.focus();
}

function popBox(URL) {
	window.open("http://www.paonline.com/" + URL, "help", "menubar=1,scrollbars=1,resizable=1,width=700,height=590");	
}
