var stayfocusedNumber= "not available";

function contact_how () {
	by_email= document.contact_how.radiogroup[0].checked;
	if (by_email) {
		document.location= "email.html?"+stayfocusedNumber;
	} else {
		document.location= "postal.html?"+stayfocusedNumber
	}
}

function set_stayfocusedNumber () {
	stayfocusedNumber= location.search ? unescape(location.search.substring(1)) : stayfocusedNumber;
}

function setStyleById (whichElement, whichStyle, whichValue) {
	var id= document.getElementById(whichElement);
	id.style[whichStyle]= whichValue;
}


function indicateValidField (whichElement, whichField) {
	setStyleById (whichElement, "color","black");
	whichField.style["background"]= "white";
	whichField.style["border"]= "1px solid #ff8000";
}


function indicateInvalidField (whichElement, whichField) {
	setStyleById (whichElement, "color","#ff8000");
	whichField.style["background"]= "#ff8000";
	whichField.style["border"]= "1px solid black";
}


function submit_form (whichForm, returnValue) {
	/* thanx ie */
		// returnValue needed because win ie would return "false" when submit_form was called by a <a href="javascript:submit_form()>
	/* thanx ie */
	var aForm= document.forms[whichForm];
	var validForm= true;

	if (whichForm == "by_email") {
		var regexp1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var regexp2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid

		if (!regexp1.test(aForm.email.value) && regexp2.test(aForm.email.value)) {
			indicateValidField ("contact_email", aForm.email); 
		} else {
			validForm= aForm.email;
			indicateInvalidField ("contact_email", aForm.email); 
		}
	
		if (aForm.name.value != "") {
			indicateValidField ("contact_name", aForm.name); 
		} else {
			validForm= aForm.name;
			indicateInvalidField ("contact_name", aForm.name); 
		}

	} else {
	
		if (aForm.country.value != "") {
			indicateValidField ("contact_country", aForm.country); 
		} else {
			validForm= aForm.country;
			indicateInvalidField ("contact_country", aForm.country); 
		}

		if (aForm.city.value != "") {
			indicateValidField ("contact_city", aForm.city); 
		} else {
			validForm= aForm.city;
			indicateInvalidField ("contact_city", aForm.city); 
		}

		if (aForm.zip.value != "") {
			indicateValidField ("contact_zip", aForm.zip); 
		} else {
			validForm= aForm.zip;
			indicateInvalidField ("contact_zip", aForm.zip); 
		}

		if (aForm.street.value != "") {
			indicateValidField ("contact_street", aForm.street); 
		} else {
			validForm= aForm.street;
			indicateInvalidField ("contact_street", aForm.street); 
		}

		if (aForm.name.value != "") {
			indicateValidField ("contact_name", aForm.name); 
		} else {
			validForm= aForm.name;
			indicateInvalidField ("contact_name", aForm.name); 
		}
	}
	
	if (validForm == true) {
		aForm.stayfocusedNumber.value= stayfocusedNumber;
		aForm.submit();
	} else {
		validForm.focus();
		validForm.select();
		validForm= false;
	}
	
	if (returnValue) {return validForm}
	
}
