
function checkPaymentInfo(thisform) {

	var f = thisform;
	var fields = new Array;

	fields[0] = new Array;
	fields[0][0] = new Array('billTo_firstName','Billing First Name');
	fields[0][1] = new Array('billTo_lastName','Billing Last Name');
	fields[0][2] = new Array('billTo_street1','Billing Address Line 1');
	fields[0][3] = new Array('billTo_city','Billing City');
	fields[0][4] = new Array('billTo_state','Billing State/Province');
	fields[0][5] = new Array('billTo_country','Billing Country');
	fields[0][6] = new Array('billTo_postalCode','Billing Zip Code');
	fields[0][7] = new Array('billTo_phoneNumber','Billing Telephone Number');
	fields[0][8] = new Array('billTo_email','Billing Email Address');

	//fields[1] = new Array;
	//fields[1][0] = new Array('shipTo_firstName','Shipping First Name');
	//fields[1][1] = new Array('shipTo_lastName','Shipping Last Name');
	//fields[1][2] = new Array('shipTo_street1','Shipping Address Line 1');
	//fields[1][3] = new Array('shipTo_city','Shipping City');
	//fields[1][4] = new Array('shipTo_state','Shipping State/Province');
	//fields[1][5] = new Array('shipTo_country','Shipping Country');
	//fields[1][6] = new Array('shipTo_postalCode','Shipping Zip Code');
	//fields[1][7] = new Array('shipTo_phoneNumber','Shipping Telephone Number');

	var s = "";
	var result;

	for (i=0;i<fields.length;i++) {
		if ( (i!=1) || (( i==1 ) /*&& ( f.ioc_shipto_same_as_billto.selectedIndex != 0 ) */) ) {
			for (j=0;j<fields[i].length;j++) {
				t = eval("f." + fields[i][j][0] + ".type")
				result = false;
				if ( t == 'text' ) {
					v = eval("f." + fields[i][j][0] + ".value");
					v = trimAll(v);
					if (v.length > 0) { result = true }
					}
				if ( t == 'select-one' ) {
					v = eval("f." + fields[i][j][0] + ".selectedIndex");
					if (v != 0) { result = true }
					}
				if ( !result ) { s = s + fields[i][j][1] + "\n"; }
			}
		}
	}

	if ( s.length > 0 ) { 
		alert("You didn't fill the following required fields:\n\n" + s);
		return false;
	}

	// Validator Object
	var valid = new Object();

	/*
	valid.State = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i;
	if (!valid.State.test(f.billTo_state.value)) {
		s = s + 'Billing State/Province' + "\n";
	}
	*/

	valid.zipCode = /\d{5}(-\d{4})?/;
	if (!valid.zipCode.test(f.billTo_postalCode.value)) {
		s = s + 'Billing Zip Code' + "\n";
	}

	valid.phoneNumber = /^\(?\d{3}\)?-\d{3}-\d{4}$/;
	if (!valid.phoneNumber.test(f.billTo_phoneNumber.value)) {
		s = s + 'Billing Telephone Number' + "\n";
	}
	valid.emailAddress = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if (!valid.emailAddress.test(f.billTo_email.value)) {
		s = s + 'Billing Email Address' + "\n";
	}

	if ( s.length > 0 ) { 
		alert("You incorrectly filled the following fields:\n\n" + s);
		return false;
	}

	return true;

}

function checkCardInfo(thisform) {

	var f = thisform;

	var fields = new Array;

	fields[0] = new Array;
	fields[0][0] = new Array('card_cardType','Card Type');
	fields[0][1] = new Array('card_accountNumber','Card Number');
	fields[0][2] = new Array('card_expirationMonth','Exp Month');
	fields[0][3] = new Array('card_expirationYear','Exp Year');

	var s = "";
	var result;

	for (i=0;i<fields.length;i++) {
		if ( i!=1 || i==1 ) {
			for (j=0;j<fields[i].length;j++) {
				t = eval("f." + fields[i][j][0] + ".type")
				result = false;
				if ( t == 'text' ) {
					v = eval("f." + fields[i][j][0] + ".value");
					v = trimAll(v);
					if (v.length > 0) { result = true }
					}
				if ( t == 'select-one' ) {
					v = eval("f." + fields[i][j][0] + ".selectedIndex");
					if (v != 0) { result = true }
					}
				if ( !result ) { s = s + fields[i][j][1] + "\n"; }
			}
		}
	}

	if ( s.length > 0 ) { 
		alert("You didn't fill the following required fields:\n\n" + s);
		return false;
	}

	// Validator Object
	var valid = new Object();

	valid.cardNumber = /\d{16}$/;
	if (!valid.cardNumber.test(f.card_accountNumber.value) || f.card_accountNumber.value.length > 16) {
		s = s + 'Card Number' + "\n";
	}
	if ( s.length > 0 ) { 
		alert("You incorrectly filled the following fields:\n\n" + s);
		return false;
	}

	return true;

}

function checkFill() {

var i = document.search;

var tmp = trimAll(i.keyword.value);
if ((tmp.length > 0)) { i.submit(); } else { return false; }

}


function trimAll( strValue ) {

	var objRegExp = /^(\s*)$/;

    if(objRegExp.test(strValue)) {
		strValue = strValue.replace(objRegExp, '');
		if( strValue.length == 0)
			return strValue;
    }

	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(strValue)) { strValue = strValue.replace(objRegExp, '$2'); }
	return strValue;
}