
function validateemail(form) {
	if (CheckEmail(form.txtEmail.value) == false) 
	{
	alert("The Email field is not valid.")
	form.email.focus()
	return false;
	}
	else 
	{ 
	return true;
	}
}


function validateform(theform) 
{

	if (theform.txtFName.value == "") 
		{
		alert("The first name field is not filled in.");
		theform.txtFName.focus();
		return false;
		}

	if (theform.txtLName.value == "") 
		{
		alert("The last name field is not filled in.");
		theform.txtLName.focus();
		return false;
		}

	if (CheckEmail(theform.txtEmail.value) == false) 
		{
		alert("The email address entered is not valid.");
		theform.txtEmail.focus();
		return false;
		}

  	return true;

}

function validatedealerform(theform) 
{

	if (theform.txtFName.value == "") 
		{
		alert("The first name field is not filled in.");
		theform.txtFName.focus();
		return false;
		}

	if (theform.txtLName.value == "") 
		{
		alert("The last name field is not filled in.");
		theform.txtLName.focus();
		return false;
		}

	if (theform.txtAddress.value == "") 
		{
		alert("Please enter an address.");
		theform.txtAddress.focus();
		return false;
		}

	if (theform.txtCity.value == "") 
		{
		alert("Please enter a city.");
		theform.txtCity.focus();
		return false;
		}

	if (theform.txtState.value == "") 
		{
		alert("Please enter a state.");
		theform.txtState.focus();
		return false;
		}

	if (theform.txtZip.value == "") 
		{
		alert("Please enter a zip code.");
		theform.txtZip.focus();
		return false;
		}

	if (CheckEmail(theform.txtEmail.value) == false) 
		{
		alert("The email address entered is not valid.");
		theform.txtEmail.focus();
		return false;
		}

	if (theform.txtPhone.value == "") 
		{
		alert("The phone field is not filled in.");
		theform.txtPhone.focus();
		return false;
		}

	if (theform.txtHowMarket.value == "") 
		{
		alert("Please enter 'How do you plan to market...'.");
		theform.txtHowMarket.focus();
		return false;
		}

	if (theform.txtEstNumber.value == "") 
		{
		alert("Please describe how many units you envision selling.");
		theform.txtEstNumber.focus();
		return false;
		}

	if (theform.txtMinOrder.value == "") 
		{
		alert("Please describe how you will be ordering units.");
		theform.txtMinOrder.focus();
		return false;
		}

	if (theform.txtHowSell.value == "") 
		{
		alert("Please describe how you will be selling units.");
		theform.txtHowSell.focus();
		return false;
		}

  	return true;
}

function CheckEmail(email) 
{
var valid = 1
var atPos = 0
var atPos1= 0
	atPos1 = email.indexOf(".")
	atPos = email.indexOf("@")
	if (atPos < 1) {
	// Return false if @ isn't found.
	valid = 0
	}
	else  if (atPos == email.length-1) {
	// If @ is found, make sure it isn't last character in string.
	valid = 0
	}
	else if (atPos1 < 1) {
	valid = 0
	}
	else if (atPos1 == email.length-1) 
	{
	valid = 0
	}
	return valid
}


function isNum(argvalue) 
{
var nNum
    nNum = '';
	argvalue = argvalue.toString();

	if (argvalue.length == 0)
		return false;

	for (var n = 0; n < argvalue.length; n++)
		if (argvalue.substring(n, n+1) == " " || argvalue.substring(n, n+1) == "-")
		{
			//nNum = nNum 
		}
		else
		{
			nNum = nNum + argvalue.substring(n, n+1);
		}

	for (var n = 0; n < nNum.length; n++)
		if (nNum.substring(n, n+1) < "0" || nNum.substring(n, n+1) > "9")
			return false;

	return true;
}

function toNum(argvalue) 
{
var nNum
    nNum = '';
	argvalue = argvalue.toString();

	if (argvalue.length == 0)
		return false;

	for (var n = 0; n < argvalue.length; n++)
		if (argvalue.substring(n, n+1) == " " || argvalue.substring(n, n+1) == "-")
		{
			//nNum = nNum 
		}
		else
		{
			nNum = nNum + argvalue.substring(n, n+1);
		}

	for (var n = 0; n < nNum.length; n++)
		if (nNum.substring(n, n+1) < "0" || nNum.substring(n, n+1) > "9")
			return false;

	return nNum;
}

function luhnCheck(ccnumber) 
{
	var no_digit = ccnumber.length;
	var oddoeven = no_digit & 1;
	var sum = 0;

	for (var count = 0; count < no_digit; count++) 
	{
		var digit = parseInt(ccnumber.charAt(count));
		if (!((count & 1) ^ oddoeven)) 
		{
			digit *= 2;
			if (digit > 9)
				digit -= 9;
		}
		sum += digit;
	}
	if (sum % 10 == 0)
		
	//	 return true;
//	 else
		return false;
}
