function isEmpty(value)
{
	return (value != null ) && value.toString().match(/^\s*$/) ? true : false;
}

function checkEmail(email)
{
	return email.toString().match(/^\s*(\w+[\.\-])*\w+\@(\w+[\.\-])*\w*\.\w+\s*$/);
}

function checkZip(zip)
{
	return zip.toString().match(/^\s*(\d{5})\s*$/);
}

function checkDlxForm(form,ctrl_suffix)
{
	var suffix = (ctrl_suffix == null) ? '' : '_'+ctrl_suffix;

	// Checking vehicle parameters
	vp = ['year', 'make', 'model', 'trim'];

	for (i = 0; i < vp.length; i++)
	{
		select = form[vp[i]+suffix];
		if (select && select.value==0)
		{
			alert('Please select vehicle '+vp[i]);
			select.focus();
			return false;
		}
	}

	// Checking email
	email = form['email'+suffix];
	if (!checkEmail(email.value))
	{
		alert('Please provide valid email address');
		email.focus();
		return false;		
	}

	// Checking ph1, ph2, ph3
	ph1 = form['ph1'+suffix];
	ph2 = form['ph2'+suffix];
	ph3 = form['ph3'+suffix];

	var bad_ph = 0;
	if (!ph1.value.toString().match(/^\s*\d{3}\s*$/)) bad_ph = ph1;
	else if (!ph2.value.toString().match(/^\s*\d{3}\s*$/)) bad_ph = ph2;
	else if (!ph3.value.toString().match(/^\s*\d{4}\s*$/)) bad_ph = ph3;

	if (bad_ph)
	{
		alert('Please provide valid phone number');
		bad_ph.focus();
		return false;
	}



	// Checking fname, lname 
	vp = [['fname','first name'],['lname','last name']];

	for (i = 0; i<vp.length; i++)
	{
		input = form[vp[i][0]+suffix];
		if (isEmpty(input.value))
		{
			alert('Please provide correct '+vp[i][1]);
			input.focus();
			return false;	
		}
	}
//	vp = [['addr','address'], ['city','city']];
	vp = [['addr','address']];

	for (i = 0; i<vp.length; i++)
	{
		input = form[vp[i][0]+suffix];
		if (isEmpty(input.value))
		{
			alert('Please provide correct '+vp[i][1]);
			input.focus();
			return false;	
		}
	}

        // Checking state
/*
        state = form['state'+suffix];
        if (state.value == 0)
        {
                alert('Please select state');
                state.focus();
                return false;
        }
*/

	// Checking zip
	zip = form['zip'+suffix];
	if (!checkZip(zip.value))
	{
		alert('Please provide valid zip code');
		zip.focus();
		return false;		
	}



	btfm = form['btfm'+suffix];
	if (btfm.value == 0)
	{		
		alert('Please select buying timeframe');
		btfm.focus();
		return false;
	}

	/*
	ctpref = form['ctpref'+suffix];
	if (ctpref.value == 0)
	{		
		alert('Please select contact method');
		ctpref.focus();
		return false;
	}
	*/

	return true;
}

