function save(FORM,ACTION) {
	var oForm = document.forms[FORM];
	oForm.ACTION.value = ACTION;
	oForm.action = "/free-roofing-estimate-request.html";
	
	if		(ACTION == 'SAVE')	{
			if (isEmpty(oForm.first_name.value))					{ alert('Your first name MUST be at least 1 characters long!'); oForm.first_name.focus(); 	
			}			
			else if (isEmpty(oForm.last_name.value))				{ alert('Your last name MUST be at least 1 characters long!'); oForm.last_name.focus(); 	
			}			
			else if	(oForm.company.value.length > 50) 				{ alert('Company name cannot be longer than 50 characters!'); oForm.company.focus(); 
			}			
			else if	(!isNumeric(oForm.phone.value))  				{ alert('Phone number must consist of numbers ONLY'); oForm.phone.focus(); 			
			}
			else if	(oForm.phone.value.length > 50) 				{ alert('Phone number cannot be longer than 50 characters!'); oForm.phone.focus(); 
			}
			else if (isEmpty(oForm.phone.value))					{ alert('Please provide a phone number'); oForm.phone.focus(); 	
			}
			else if	(oForm.extension.value.length > 10) 			{ alert('Extension cannot be longer than 10 characters!'); oForm.extension.focus(); 
			}			
			else if (isEmpty(oForm.email.value))					{ alert('Please provide your email address'); oForm.email.focus(); 	
			}			
			else if	(oForm.email.value.length > 50) 				{ alert('Email address cannot be longer than 50 characters!'); oForm.email.focus(); 
			}	
			else if	(oForm.address_1.value.length > 50) 			{ alert('Address 1 cannot be longer than 50 characters!'); oForm.address_1.focus(); 
			}
			else if	(oForm.address_2.value.length > 50) 			{ alert('Address 2 cannot be longer than 50 characters!'); oForm.address_2.focus(); 
			}
			else if	(oForm.city.value.length > 50) 					{ alert('City name cannot be longer than 50 characters!'); oForm.city.focus(); 
			}	
			else if	(oForm.state.value.length > 50) 				{ alert('State cannot be longer than 50 characters!'); oForm.state.focus(); 
			}
			else if	(oForm.zip.value.length > 20) 					{ alert('Zip code cannot be longer than 20 characters!'); oForm.zip.focus(); 
			}
			else if	(oForm.comments.value.length > 1000) 			{ alert('Comments cannot be longer than 1000 characters!'); oForm.comments.focus(); 
			}
			else {
			oForm.submit();	
			}
	}
	else if	(ACTION == 'CANCEL')	{
			oForm.submit(); 
	}
}

// JavaScript Document
function goto(adres){
window.location = adres;
}


function isEmpty(str)
{
	var ie = document.all;
	str = stripSpaces(str);
	
	if (ie) {
		if(str=="") return true;
		var re = /(\S+)/gi;
		var t = re.test(str); 
		return !t;
	} else {
		if(str=="")	 return true;
		return false;
	}
}

function isEmail(str)
{
	var tmp = str + "";
	if(tmp!="")
	{		
		var exclude=/[^@\-\.\[A-Za-z0-9]]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;				
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,3}$/;

		if(((tmp.search(exclude) != -1)||(tmp.search(check)) == -1)||(tmp.search(checkend) == -1))
			return false;	
	}
	return true;	
}

function isDate(year,month,day) {
	var date = new Date(year,month-1,day);		
	var y = date.getFullYear();
	var m = date.getMonth();
	var d = date.getDate();
		
	m++;	
	if(month.length==2 && month.substr(0,1)=="0")
		m = "0" + m;

	if(day.length==2 && day.substr(0,1)=="0")
		d = "0" + d;

	if(year+" "+month+" "+day != y +" "+ m +" "+ d)
		return false;
	else	
		return true;
}

function isClean(str,type) {
	if 		(type == 1) { var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>? "; }
	else if (type == 2) { var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";  }
	
	for (var i = 0; i < str.length; i++) {
		if (iChars.indexOf(str.charAt(i)) != -1) { return false; }
	}
	return true;
}

function isNumeric(str) {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < str.length && IsNumber == true; i++) { 
      Char = str.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }
   return IsNumber;
}



function stripSpaces(x) {
    while (x.substring(0,1) == ' ') x = x.substring(1);
    while (x.substring(x.length-1,x.length) == ' ') x = x.substring(0,x.length-1);
    return x;
}
