var pass=true;
var fail=false;
var stat;
var process;
var cur_func;
var timed_counter;
var email_id=17;
var reg=Array(
	[["Company Name"],								[".{1,}"],				["company"],	1],
	[["Billing Address"],							[".{1,}"],				["b_address"],	1],
	[["Billing City"],								[".{1,}"],				["b_city"],		1],
	[["Billing State"],								["[^0]"],				["b_state"],	1],
	[["Billing Zip"],								["\\d{5,}"],			["b_zip"],		1],
	[["Shipping Address"],							[".{1,}"],				["s_address"],	2],
	[["Shipping City"],								[".{1,}"],				["s_city"],		2],
	[["Shipping State"],							["[^0]"],				["s_state"],	2],
	[["Shipping Zip"],								["\\d{5,}"],			["s_zip"],		2],
	[["Owner's First Name"],						[".{1,}"],				["fname"],		3],
	[["Owner's Last Name"],							[".{1,}"],				["lname"],		3], 
	[["Type of Business"],							["[^0]"],				["bus_type"],	3], 
	[["Is this a chain of stores?"],				["[^0]"],				["chain"],		3], 
	[["Is business being operated out of house?"],	["[^0]"],				["house"],		3],
	[["e-Mail"],									["[^0]"],				["email"],		3],
	[["Phone"],										[".{1,}"],				["phone"],		4]
);

var hobbyistReg=Array(
	[["First Name"],								[".{1,}"],				["fname"],		1],
	[["Last Name"],									[".{1,}"],				["lname"],		1], 
	[["e-Mail"],									["[^0]"],				["email"],		1],
	[["Password"],									["[^0]"],				["pw"],			1],

//	[["Billing Address"],							[".{1,}"],				["b_address"],	2],
//	[["Billing City"],								[".{1,}"],				["b_city"],		2],
//	[["Billing State"],								["[^0]"],				["b_state"],	2],
	[["Billing Zip"],								["\\d{5,}"],			["b_zip"],		2]
);

function validate() {
	var list=reg;
	try {
		if (document.getElementById('CustomerBanner').innerHTML.trim().indexOf('Hobbyist')>-1) {
			list=hobbyistReg;
		}
	} catch(e) { ; }
	stat=pass;
	for (var i=0; i<list.length; i++) {
		var cur_id=''+list[i][2];
		if (document.getElementById('shipping_address')) {
			var ship=document.getElementById('shipping_address');
			if (ship.checked) {
				if (cur_id.substr(0,2)!='s_') {
					check_entry(document.getElementById(cur_id),list[i][1]);
				}
			}
		}
		else {
			check_entry(document.getElementById(cur_id),list[i][1]);
		}
	}
	/*var pw=document.getElementById('pw');
	var pwconf=document.getElementById('pwconf');
	if (pw.value.length>0) {
		if (pwconf.value!=pw.value) {
			document.getElementById('lblpwconf').style.color='#ff0000';
			pwconf.value='';
			stat=fail;
		}
	}
	if (check_entry(document.getElementById('email'),".{1,}@.{1,}")) {
		var email=document.getElementById('email').value;
		load_xml('verify_user.asp?email='+email,'verify_user');
		check_entry(document.getElementById('email'),".{1,}@.{1,}");
	}*/
	if(stat) {
		document.getElementById('register').submit();
	}
	else {
		alert('Please re-enter the item(s) marked in red.');
	}
	//return(false);
}
function check_entry(obj,expr) {
	var reg=new RegExp(expr, "i");
	try {
		var pay=frames['payment_info'].document;
	    if(obj) {
		    if(reg.test(obj.value)) {
			    pay.getElementById('lbl'+obj.id).style.color='#000000';
			    return(pass);
		    }
		    else {
			    pay.getElementById('lbl'+obj.id).style.color='#ff0000';
			    stat=fail;
			    return(fail);
		    }
	    }
    }
    catch (e){
		try {
			if(obj) {
				if(reg.test(obj.value)) {
					document.getElementById('lbl'+obj.id).style.color='#000000';
					return(pass);
				}
				else {
					document.getElementById('lbl'+obj.id).style.color='#ff0000';
					stat=fail;
					return(fail);
				}
			}
		}
		catch(f) {
	        //alert(obj.id+'\n'+expr+'\n'+e);
		}
    }
}
function check_entry_lblExplicit(obj,expr,lbl) {
	var reg=new RegExp(expr, "i");
	if(obj) {
		if(reg.test(obj.value)) {
			document.getElementById(lbl).style.color='#000000';
			return(pass);
		}
		else {
			document.getElementById(lbl).style.color='#ff0000';
			stat=fail;
			return(fail);
		}
	}
}

function verify_pw() {
	var new_password				=document.getElementById('new_password');
	var confirm_new_password		=document.getElementById('confirm_new_password');
	if (new_password.value==confirm_new_password.value) {
		return(true);
	}
	else {
		new_password.value			='';
		confirm_new_password.value	='';
		alert('Your new password entries do not match.\nPlease try again');
		return(false);
	}
}
