function check_numeric(which) {
	var cornum = which.value.replace(/[^\d]/g,'');

	if (cornum != which.value)
		return false;

	return true;
}

function check_fields() {

	errMsg = false;
	errTxt = "";
	emailerr = false;

	ai=0;
	di=0;

	if ( document.reg.name.value == "" ) {
		errMsg = true;
		errTxt += "You must supply a registration name.\n\nThe registration name is matched to the registration key. The name you enter here will also\nneed to be entered into the i-Catcher software.\n\n";
	}

	if ( document.reg.name.value.length <6 ) {
		errMsg = true;
		errTxt += "You must supply a registration name longer than six characters.\n\n";
	}

	ai=document.reg.email.value.indexOf('@');
	di=document.reg.email.value.lastIndexOf('.');

	if ( document.reg.email.value == "" ) {
		emailerr = true;
	}

	if ((ai<0) || (di<ai) || (ai==0)) {
		emailerr = true;
        }

 	if (emailerr) {
		errMsg = true;
		errTxt += "You must supply a valid email address.\n\n Registration keys are ONLY sent by email. If a valid email address is not entered you will\nNOT be able to receive your registration key.\n\n";
	}

	prod = document.reg.product.value;

	if (( prod == 50) || (prod == 51) || (prod == 18) || (prod == 15) || (prod == 12)) {
		if ( document.reg.qty.value < 2 ) {
			errMsg = true;
			errTxt += "i-Catcher Console can not be licensed for less than 2 cameras.\n";
		}

		if ( !check_numeric(document.reg.qty) ) {
			errMsg = true;
			errTxt += "The number of cameras you have specified is not valid. Please enter a single number, in digits\nwith no other characters such as spaces, hyphens, dashes, quotes, etc.";
		}
	} else {
		if ( document.reg.qty.value < 1 ) {
			errMsg = true;

			errTxt += "You can not purchase less than 1 license for " + products[prod] + ".\n\n";
		}
	}

	if ( errMsg == true ) {
		alert("One or more of the mandatory registration fields has not been completed correctly. Please\nCorrect the following errors:\n\n"+ errTxt);
		return false;
	}

	if ( errMsg == false ) {
		return true;
	}

	return false;
}

function do_click() {

	if (( check_fields() == true) && (submitted == false)) {
		submitted = true;

		document.reg.submit();
	}
}

var submitted = false;

var products = new Array();

products[9]  = 'i-Catcher Monitor';
products[25] = 'i-Catcher Video Server';
products[41] = 'i-Catcher PocketMonitor';
products[50] = 'i-Catcher Console';
products[52] = 'i-Catcher Sentry';
products[53] = 'i-Catcher Wildlife';


