function toggleElement(id) {
	var html = document.getElementById(id);
	if (html.style.display != "none") {
		html.style.height = html.offsetHeight + "px";
		html.style.overflow = "hidden";
		animStep(id, false, html.offsetHeight);
	} else {
		html.style.display = "";
		html.style.overflow = "";
		html.style.height = "";
		var h = html.offsetHeight;
		html.style.overflow = "hidden";
		html.style.height = "0px";
		animStep(id, true, h);
	}
	
	return false;
}

var imgNames = new Array("images/services/managed_it.jpg",
						 "images/services/network_security.jpg",
						 "images/services/network_upgrade.jpg",
						 "images/services/network_design.jpg");

function displayService(index) {
	for (var i = 1; i < 5; i++) {
		var html = document.getElementById("service" + i);
		if (html.style.display != "none")
			toggleElement(html.id);
	}
	
	toggleElement("service" + index);
	var img = document.getElementById("imgService");
	img.src = imgNames[index - 1];
	return false;
}

function animStep(id, expanding, height) {
	var html = document.getElementById(id);
	var newHeight = parseInt(html.style.height);
	
	if (expanding) {
		newHeight += 36;
		
		if (newHeight >= height) {
			html.style.height = height + "px";
			return;
		}
	} else {
		newHeight -= 36;
		if (newHeight <= 0) {
			html.style.height = "0px";
			html.style.display = "none";
			return;
		}
	}
	
	html.style.height = newHeight + "px";
	setTimeout("animStep('" + id + "', " + expanding + ", " + height + ");", 10);
}

function submitForm(id) {
	document.getElementById(id).submit();
	return false;
}

/*was in contact*/
function validate(frm) {
	var inputFields = new Array("Name" ,"formmail_mail_email" ,"Phone");
	var counter;
	var name;
	var msg = "Please complete the following fields:\n";
	var badFields = "";
	for (counter = 0; counter < inputFields.length; counter++) {
		name = inputFields[counter];
		if (frm.elements[name].value.length == 0) {
			if (name == "formmail_mail_email") {
				badFields = badFields + "  - Email \n";
			} else {
				badFields = badFields + "  - " + name + "\n";
			}
		}
	}
	if (badFields.length != 0) {
		alert(msg + badFields);
		return false;
	}
	if (frm.formmail_mail_email.value.length > 0) {
		return emailCheck(frm.formmail_mail_email.value);
	} else {
		return true;
	}
}

function emailCheck(emailStr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];

	if (user.match(userPat)==null) {
			alert("The username doesn't seem to be valid.");
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
			return false;
			}
			}
			return true;
	}

	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.");
			return false;
	}

	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
	   alert("The address must end in a three-letter domain, or two letter country.");
		return false;
	}

	if (len<2) {
		var errStr="This address is missing a hostname!";
		alert(errStr);
	return false;
	}

	return true;
}

