function validate_required(field, alertTxt, errorId) {
	with (field) {
		var errorVar = document.getElementById(errorId);
		if (value == null || value == "") {
			errorVar.innerHTML = alertTxt;
			return false;
		}
		return true;
	}
}

function validate_email(field, alertTxt, errorId) {
	with (field) {
		var errorVar = document.getElementById(errorId);
		aPos = value.indexOf("@");
		dotPos = value.lastIndexOf(".");
		if (value == null || value == "") {
			return true;
		}
		if (aPos < 1 || dotPos-aPos < 2 || dotPos == value.length-1) {
			errorVar.innerHTML = alertTxt;
			return false;
		}
		return true;
	}
}

function validate_phonenumber(field, errorId) {
	with (field) {
		var errorVar = document.getElementById(errorId);
		var stripped = value.replace(/[\(\)\.\ ]/g, '');
		
		if (isNaN(parseInt(stripped))) {
		   errorVar.innerHTML  = "The phone number is not valid.";
		   return false;
		}
		if(value.search(/\d{3}\-\d{3}\-\d{4}/) == -1) {
		  errorVar.innerHTML = "Please use this format: xxx-xxx-xxxx.";
		  return false;
		}
		return true;
	}
}


function validate_form() {
	var isSuccess = true;
	var thisform = document.getElementById("mainform");
	hideAllErrors();
	with (thisform) {
		if (validate_email(email, "Not a valid e-mail address!", "emailError") == false) {
			email.focus();
			isSuccess = false;
		}
		if (validate_required(phonenumber, "Please enter your phone number.", "phonenumberError") == false) {
			phonenumber.focus();
			isSuccess = false;
		}
		else {
			if (validate_phonenumber(phonenumber, "phonenumberError") == false) {
				phonenumber.focus();
				isSuccess = false;
			}
		}
		if (validate_required(name, "Please enter your name.", "nameError") == false) {
			name.focus();
			isSuccess = false;
		}
		if (isSuccess == true) {
		    thisform.method = "post";
		    thisform.action = "/Contact_us.aspx";
		    thisform.submit();
		    /*
			var contactName = document.getElementById("mainform").name.value;
			var contactEmail = document.getElementById("mainform").email.value;
			var contactPhone = document.getElementById("mainform").phonenumber.value;
			var contactCompany = document.getElementById("mainform").company.value;
			var contactComments = document.getElementById("mainform").comments.value;
			
			var subject = 'New Comment from Inflection Point Website';
			var body = 'Hi,\n\n\tYou have received a new comment from the website.\n\nName: ' + contactName + '\nPhone: ' + contactPhone + '\nE-Mail: ' + contactEmail + '\nCompany: ' + contactCompany + '\n\nComments:\n\n' + contactComments;
			location.href = 'mai' + 'lt' + 'o:info@ipo' + 'intsystems.com?subject=' + escape(subject) + '&body='+ escape(body);
			*/
		}
	}
}

function reset_form() {
	hideAllErrors();
	document.getElementById("mainform").reset();
}

function hideAllErrors() {
	document.getElementById("phonenumberError").innerHTML = "";
	document.getElementById("nameError").innerHTML = "";
	document.getElementById("emailError").innerHTML = "";
	document.getElementById("name").focus();
}

function button_clicked(btn, imgURL) {
	btn.src = imgURL;
}

function change_img(id, imgURL) {
	document.getElementById(id).src = imgURL;
}

function changeBaseColor() {
    
}
