addLoadEvent(init_contact_form);

function init_contact_form() {
	var frmContact = document.getElementById("contact_form");
	if(frmContact) {
		frmContact.onsubmit = validateContact;
	}
}

function validateContact() {
	var theForm = document.getElementById("contact_form");

	var error = 0;
	var msg = "";

	if(theForm.message.value=="") {
		msg += "\n- " + label_contact_message;
		error++;
	}
	if(theForm.company.value=="") {
		msg += "\n- " + label_contact_company;
		error++;
	}
	if(theForm.city.value=="") {
		msg += "\n- " + label_contact_city;
		error++;
	}
	if(theForm.country.value=="") {
		msg += "\n- " + label_contact_country;
		error++;
	}
	if(theForm.title.selectedIndex==0) {
		msg += "\n- " + label_contact_title;
		error++;
	}
	if(theForm.last_name.value=="") {
		msg += "\n- " + label_contact_last_name;
		error++;
	}
	if(theForm.email.value=="") {
		msg += "\n- " + label_contact_email;
		error++;
	}
	if((theForm.how_did_you_hear0.selectedIndex==0)
	|| (theForm.how_did_you_hear0.selectedIndex==1 && theForm.how_did_you_hear1.selectedIndex==0)
	|| (theForm.how_did_you_hear0.selectedIndex==3 && theForm.how_did_you_hear2.selectedIndex==0)
	) {
		msg += "\n- " + label_contact_how_did_you_hear;
		error++;
	}
	if((theForm.how_did_you_hear0.selectedIndex==1 && theForm.how_did_you_hear1.selectedIndex==3 && theForm.how_did_you_hear_other.value=="")
	|| (theForm.how_did_you_hear0.selectedIndex==3 && theForm.how_did_you_hear2.selectedIndex!=3 && theForm.how_did_you_hear_other.value=="")
	) {
		msg += "\n- " + label_contact_how_did_you_hear + " > " + lbl_specify;
		error++;
	}
	
	if (error) {
		alert(label_contact_required_fields + msg);
		return false;
	}
	if (!validateEmail(theForm.email.value)) {
		alert(label_contact_valid_email);
		return false;
	}
	
	return true;
}
function validateEmail(email) {
	
	if (email != null && email != "") {
		a = email.lastIndexOf("@");
		b = email.lastIndexOf(".");
		c = email.indexOf(":");
		d = email.indexOf("/");
		e = email.substring(0,a);
		f = e.indexOf("@");
		g = email.substring(a+1,email.length);
		h = g.indexOf("[");
		i = g.indexOf("]");
		j = g.indexOf("<");
		k = g.indexOf(">");
		l = email.substring(a+1,b);
		m = email.substring(b+1,email.length);
		n = email.substring(0,a);
		p = email.indexOf("'");
		q = email.indexOf("\"");
		o = 0;
		if (a > b) {o++};
		if (c != -1) {o++};
		if (d != -1) {o++};
		if (f != -1) {o++};
		if (h != -1) {o++};
		if (i != -1) {o++};
		if (j != -1) {o++};
		if (k != -1) {o++};
		if (l.length < 2) {o++};
		if (m.length < 2) {o++};
		if (n.length < 1) {o++};
		if (p != -1) {o++};
		if (q != -1) {o++};
		if (o != 0) {
			return false;
		}
	}
	return true;
}
function how1(dropdown) {
	if(dropdown.selectedIndex==0) {
		document.getElementById("how_did_you_hear1").style.display="none";
		document.getElementById("how_did_you_hear2").style.display="none";
		document.getElementById("how_specify").style.display="none";
	} else if(dropdown.selectedIndex==1) {
		document.getElementById("how_did_you_hear1").style.display="inline";
		document.getElementById("how_did_you_hear2").style.display="none";
		document.getElementById("how_specify").style.display="none";
	} else if(dropdown.selectedIndex==2) {
		document.getElementById("how_did_you_hear1").style.display="none";
		document.getElementById("how_did_you_hear2").style.display="none";
		document.getElementById("how_specify").style.display="none";
	} else if(dropdown.selectedIndex==3) {
		document.getElementById("how_did_you_hear1").style.display="none";
		document.getElementById("how_did_you_hear2").style.display="inline";
		document.getElementById("how_specify").style.display="none";
	} else {
		document.getElementById("how_did_you_hear1").style.display="none";
		document.getElementById("how_did_you_hear2").style.display="none";
		document.getElementById("how_specify").style.display="none";	
	}
	document.getElementById("how_did_you_hear1").selectedIndex==0;
	document.getElementById("how_did_you_hear2").selectedIndex==0;
	document.getElementById("how_did_you_hear_other").value="";
}
function how2(dropdown2) {
	var dropdown1 = document.getElementById("how_did_you_hear0");
	
	if(dropdown1.selectedIndex==1) { // search engine
		if(dropdown2.selectedIndex==3) { // other search engine
			document.getElementById("how_specify").style.display="block";
		} else {
			document.getElementById("how_specify").style.display="none";
		}
	}
	document.getElementById("how_did_you_hear_other").value="";
}
function how3(dropdown3) {
	var dropdown1 = document.getElementById("how_did_you_hear0");
	
	if(dropdown1.selectedIndex==3) { // other
		if(dropdown3.selectedIndex==3) { // direct mail
			document.getElementById("how_specify").style.display="none";
		} else {
			document.getElementById("how_specify").style.display="block";
		}
	}
	document.getElementById("how_did_you_hear_other").value="";
}