// Compiled by: Burnz ^_^
function count_chars() { 
  counter = document.warrantyappb.txtask.value 
  left = (250 - (counter.length)) 
	  
	 if ( left <= 0 ) { 
		document.warrantyappb.count.value = 0 
		document.warrantyappb.txtask.value = document.warrantyappb.txtask.value.substr(0,250) 
	 } else { 
		document.warrantyappb.count.value = left 
	 } 
} 

function nextbox(fldobj,nbox)
{
if(fldobj.value.length>2)
{document.form.elements[nbox].focus()}
}

function getKeyCode(e)
{
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}
function keyRestrict(e, validchars) { 
	var key='', keychar='';
	key = getKeyCode(e);
	if (key == null) return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
	if (validchars.indexOf(keychar) != -1)
		return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	return false;
}

function bwarranty()
{
	var themessage = "Please complete the following fields: \r\n";
	var msgctr = 0;
	//GENERAL PROJECT INFORMATION
	themessage = themessage + "\r\n GENERAL PROJECT INFORMATION";
	if (document.warrantyappb.bappprojname.value=="") {
	themessage = themessage + "\r\n Project Name";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.bappprojadd.value=="") {
	themessage = themessage + "\r\n Project Address";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.bappfuncbldg.value=="") {
	themessage = themessage + "\r\n Start Date";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.bappcomdate.value=="") {
	themessage = themessage + "\r\n Completion Date";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.bappprojsqft.value=="") {
	themessage = themessage + "\r\n Project Square Footage";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.bappslope.value=="") {
	themessage = themessage + "\r\n Slope";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.bmat1.value=="") {
	themessage = themessage + "\r\n Materials Used";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.bqty1.value=="") {
	themessage = themessage + "\r\n Quantity";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.bdatep1.value=="") {
	themessage = themessage + "\r\n Date Purchased";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.blotnum1.value=="") {
	themessage = themessage + "\r\n Lot Numbers";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.bappprob.value=="") {
	themessage = themessage + "\r\n Application Problems Encountered";
	msgctr = msgctr+1;
	}
	if (document.warrantyappb.baddcom.value=="") {
	themessage = themessage + "\r\n ADDITIONAL COMMENTS";
	msgctr = msgctr+1;
	}
	
	if (document.warrantyappb.txttitle.value=="") {
	themessage = themessage + "\r\n Title";
	msgctr = msgctr+1;
	}
	
	
	if (document.warrantyappb.txtname.value=="") {
	themessage = themessage + "\r\n Name";
	msgctr = msgctr+1;
	}
	
	

//email validation	
  if (document.warrantyappb.txtemail.value =="") 
    {
    themessage = themessage + "\r\n Email";
	msgctr = msgctr+1;
    }
else{
		
var str=document.warrantyappb.txtemail.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
themessage = themessage + "\r\n Valid Email";
msgctr = msgctr+1;
}}//end email validation
	
	
	
	if (msgctr==0){
	themessage = themessage + "\r\n---Completed---";
	}


//alert if fields are empty and cancel form submit
	if (themessage == "Please complete the following fields: \r\n\r\n GENERAL PROJECT INFORMATION\r\n---Completed---")
	{
		document.warrantyappb.action = "sendmail.php"; 
		document.warrantyappb.submit(); 
//		document.warrantyappb.reset();

	}
	else
	{
		alert(themessage);
		return false;
	}
}