function check(formname, submitbutton) {
var errors = '';
errors += checkText(formname, 'fname', 'First name');
errors += checkText(formname, 'lname', 'Last name');
errors += checkText(formname, 'address1', 'Address');
errors += checkText(formname, 'city', 'City');
errors += checkText(formname, 'state', 'State');
errors += checkText(formname, 'zip', 'ZIP')
errors += checkZIP(formname, 'zip', 'ZIP');
errors += checkText(formname, 'homephone', 'Home phone'); errors += checkUSPhone(formname, 'homephone', 'Home phone'); errors += checkText(formname, 'email', 'E-mail'); errors += checkEmail(formname, 'email', 'E-mail');
errors += checkText(formname, 'howlongathomeaddress', 'How long at this address?');
errors += checkNum(formname, 'howlongathomeaddress', 'How long at this address?');
errors += checkText(formname, 'bmonth', 'Date of birth - Month'); errors += checkText(formname, 'bday', 'Date of birth - Day');
errors += checkText(formname, 'byear', 'Date of birth - Year'); errors += checkDOB(formname, 'bmonth', 'bday', 'byear', 'Date of birth');
errors += checkText(formname, 'ssn', 'Social Security #');
errors += checkSSN(formname, 'ssn', 'Social Security #');
errors += checkText(formname, 'employername', 'Employer name');
errors += checkText(formname, 'yourjobtitle', 'Your job title');
errors += checkText(formname, 'howlongwithemployer', 'How long with this employer');
errors += checkNum(formname, 'howlongwithemployer', 'How long with this employer');
errors += checkText(formname, 'monthlyincome', 'Monthly income');
errors += checkNum(formname, 'monthlyincome', 'Monthly income');
errors += checkText(formname, 'workphone', 'Work phone');
errors += checkUSPhone(formname, 'workphone', 'Work phone');
if (eval('document.'+formname+'.agreetopolicy.checked') == false)
errors += '- You must indicate your agreement to the policies and disclosures if you want to proceed.';
if (errors == '')
{
var now = new Date();
var ldid = eval('999') + '-' + now.getTime();
eval('document.'+formname+'.leadID.value="' + ldid + '"');
SubmitForm(formname, 'B1'); }
else
{
alert(errors);
}
return false;
}

function SubmitForm(t,K){eval('document.'+t+'.action="https://www.web2carz.com/customer/lead_redirect.php"');eval('document.'+t+'.'+K+'.disabled=true');eval('document.'+t+'.submit()');};function checkText(t,L,n){var B='';if(d(eval('document.'+t+'.'+L+'.value'))==''){B='- '+n+' is Required.\n';}return B;};function checkNum(t,L,n){var B='';if(isNaN(eval('document.'+t+'.'+L+'.value'))){B='- '+n+' Should Be A Number With No Spaces.\n';}return B;};function checkSelect(t,I,n){var B='';if(eval('document.'+t+'.'+I+'.selectedIndex')==0){B='- '+n+' is Required.\n';}return B;};function checkRadio(t,H,n){var B='';var G='';for(var i=0;i<eval('document.'+t+'.'+H+'.length');i++){if(eval('document.'+t+'.'+H+'[i].checked')){G+='-';}}if(G==''){B='- '+n+' is Required.\n';}return B;};function d(s){while((s.substring(0,1)==' ')||(s.substring(0,1)=='\n')||(s.substring(0,1)=='\r')){s=s.substring(1,s.length);}while((s.substring(s.length-1,s.length)==' ')||(s.substring(s.length-1,s.length)=='\n')||(s.substring(s.length-1,s.length)=='\r')){s=s.substring(0,s.length-1);}return s;};function checkZIP(t,L,n){var B='';var O=d(eval('document.'+t+'.'+L+'.value'));if(O.search(/\d{5}$|\d{5}-\d{4}$/)==-1)B+='- Invalid '+n+'.\n';return B;};function checkSSN(t,L,n){var B='';var J=d(eval('document.'+t+'.'+L+'.value'));if(J.search(/^\d{3}-\d{2}-\d{4}$/)==-1)B+='- Invalid '+n+'.\n';return B;};function e(c){return(c>='0'&&c<='9');};function checkUSPhone(t,L,n){var B='';var F=d(eval('document.'+t+'.'+L+'.value'));var m='';for(i=0;i<F.length;i++){if(e(F.charAt(i))){m+=F.charAt(i);}}if(m.length!=10){B='- '+n+' must contain only 10 digits\n';}else{var j=m.slice(0,3);var M=m.slice(3,6);var z=m.slice(6,10);var v='900.911.411.456.500.222.333.444.555.666.777.999';if((v.indexOf(j)!=-1)||(j.charAt(0)=='0')||(j.charAt(0)=='1'))B+='- Invalid area code in '+n+'\n';var w='411.555.611.911';if((w.indexOf(M)!=-1)||(M.charAt(0)=='0')||(M.charAt(0)=='1'))B+='- Invalid exchange in '+n+'\n';var A=M+z;var g=true;for(i=1;i<A.length;i++)if(A.charAt(i)!=A.charAt(0)){g=false;break;}if(g)B+='- Repeating digits in '+n+' are not allowed.\n';}return B;};function checkEmail(t,L,n){var B='';var r=d(eval('document.'+t+'.'+L+'.value'));if(r.search(/([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/)==-1)B+='- Invalid '+n+'.\n';return B;};function checkDOB(t,C,l,N,n){var B='';var o=eval('document.'+t+'.'+C+'.value')+'/'+eval('document.'+t+'.'+l+'.value')+'/'+eval('document.'+t+'.'+N+'.value');if(isNaN(Date.parse(o))){B+='- Invalid '+n+'.\n';}else{var D=new Date();var k=new Date(o);var f=D.getFullYear()-k.getFullYear();if(f<18)B+='- You must be 18 or older - you are only '+f+' according to your '+n+'.\n';}return B;} 
