// JavaScript Document

<!-- 
function active_texfield(name){
	var s, F;
	F = document.contact;
	s = document.getElementsByName(name)[0]; 
	s.style.border = "solid #2C353C 1px";
}

function deactive_texfield(name){
	var s, F;
	F = document.contact;
	s = document.getElementsByName(name)[0]; 
	s.style.border = "solid #B2C5D1 1px";
}

function str_trim(sx) {
	return str_trim2(sx,0);	// do not filter cr or ln characters
}
function str_trim2(sx,crln) {
	return str_trim3(sx,0,1);	// do not filter cr or ln characters, change " to '
}
function str_trim3(sx,crln,chng_qt) {
	var s, i, str, c;
	s = sx + "";
	len = s.length;
	if (len <= 0)
		return "";
	i = 0;
	for (i = 0; i < len; ++i) {
		c = s.charAt(i);
		if (c != " " && c != "\t") {
			if (!crln || (crln && c != "\r" && c != "\n"))
				break;
		}
	}
	str = s.substr(i, len - i);
	len = str.length;
	if (len <= 0)
		return "";
	for (i = len - 1; i >= 0; --i) {
		c = str.charAt(i);
		if (c != " " && c != "\t") {
			if (!crln || (crln && c != "\r" && c != "\n"))
				break;
		}
	}
	if (i < 0)
		return "";
	if (chng_qt) {
		// convert " to '
		s = str.substr(0, i + 1);
		len = s.length;
		str = "";
		for (i = 0; i < len; ++i) {
			c = s.charAt(i);
			str += (c == '"') ? "'" : (crln && (c == '\r' || c == '\n')) ? " " : c;
		}
	}
	return str;
}
function chk_str(s, min_len) {
	var str;
	str = str_trim(s);
	if (str.length < min_len) {
		return false;
	}
	return true;
}
function chk_email(s) {
	var str;
	str = str_trim(s);
	if (!str.match("^[A-Za-z0-9][^@]*@[A-Za-z0-9][^.]*\\.[A-Za-z0-9][A-Za-z0-9_.-]*$"))
		return false;
	return true;
}

function chk_zip(s) {
	var str, n, x;
	str = str_trim(s);
	if (str.length < 5 || str.length > 10)
		return false;
	if (str.match("^[0-9][0-9][0-9][0-9][0-9]$")) {
		n = parseInt(str, 10);
		if (n < 210)
			return false;
		return true;
	}
	if (str.match("^[0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$")) {
		x = str.substr(0,5);
		n = parseInt(x, 10);
		if (n < 210)
			return false;
		return true;
	}
	return false;
}
function chk_contact_form(F) {
	var x, i, n;
	F.name.value = str_trim(F.name.value);
	if (F.name.value == "") {
		alert("Please enter Name.");
		F.name.focus();
		return false;
	}
	if (!chk_str(F.name.value,4)) {
		alert("Please enter a valid Name.");
		F.name.focus();
		return false;
	}
	F.company.value = str_trim(F.company.value);
	if (F.company.value == "") {
		alert("Please enter Company Name.");
		F.company.focus();
		return false;
	}
	if (!chk_str(F.company.value,2)) {
		alert("Please enter a valid Company Name.");
		F.company.focus();
		return false;
	}
	
	F.address.value = str_trim(F.address.value);
	if (F.address.value == "") {
		alert("Please enter Address.");
		F.address.focus();
		return false;
	}
	if (!chk_str(F.address.value,2)) {
		alert("Please enter a valid Address.");
		F.address.focus();
		return false;
	}
	
	F.city.value = str_trim(F.city.value);
	if (F.city.value == "") {
		alert("Please enter City.");
		F.city.focus();
		return false;
	}
	if (!chk_str(F.city.value,2)) {
		alert("Please enter a valid City.");
		F.city.focus();
		return false;
	}
	
	F.state.value = str_trim(F.state.value);
	if (F.state.value == "") {
		alert("Please enter State.");
		F.state.focus();
		return false;
	}
	
	if (!chk_str(F.state.value,2)) {
		alert("Please enter a valid State.");
		F.state.focus();
		return false;
	}
	
	F.zip.value = str_trim(F.zip.value);
	if (F.zip.value == "") {
		alert("Please enter Zipcode.");
		F.zip.focus();
		return false;
	}
	if (!chk_zip(F.zip.value)) {
		alert("Please enter a valid Zipcode.");
		F.zip.focus();
		return false;
	}
	
	F.phone.value = str_trim(F.phone.value);
	if (F.phone.value == "") {
		alert("Please enter Phone.");
		F.phone.focus();
		return false;
	}
	if (!chk_str(F.phone.value,5)) {
		alert("Please enter a valid Phone.");
		F.phone.focus();
		return false;
	}
	
	
	F.email.value = str_trim(F.email.value);
	if (F.email.value == "") {
		alert("Please enter Email.");
		F.email.focus();
		return false;
	}
	if (!chk_email(F.email.value)) {
		alert("Please enter a valid Email.");
		F.email.focus();
		return false;
	}

	return true;
}

// -->
