function clearInfo() {
	holdingDiv = document.getElementById("contactforminfo");
	for (i=0; i<holdingDiv.childNodes.length; i++) {
		node = holdingDiv.childNodes[i];
		if (node.nodeName=="DIV") {
			node.style.display = "none";
		}
	}
	holdingDiv.style.display = "none";
	document.getElementById('enquiry_label').innerHTML = "Enquiry";
	document.getElementById('fields_accnumber').style.display = "none";
	document.getElementById('salesInfo').style.display = "none";
}

function showInfo(listItem){
	selectDiv = listItem+"Info";
	document.getElementById(selectDiv).style.display = "block";
	document.getElementById("contactforminfo").style.display = "block";
}

function disableForm(){
	thisForm = document.contactform;
	thisForm.style.className = "blanked";
	
	for (i=0; i<thisForm.elements.length; i++) {
		node = thisForm.elements[i];
		
		if (node.nodeName=="INPUT") {
			if (node.id != 'send') {
				node.disabled = true; 
				node.className += " blanked";
			}
			else {
				node.disabled = true; 
				node.className += " blanked";
			}
		}
		else if (node.nodeName=="TEXTAREA") {
			node.disabled = true;
			node.className += " blanked";
		} if (node.nodeName=="FIELDSET" && node.id != "contactforminfo" && node.id != "category") {
			node.className = "blanked";
		}
	}
		
	
}

function enableForm() {
	thisForm = document.contactform;
	thisForm.style.className = "";
	for (i=0; i<thisForm.elements.length; i++) {
		node = thisForm.elements[i];
		
		if (node.nodeName=="INPUT") {
			node.disabled = false;
			node.className=node.className.replace(" blanked", "");
		}
		else if (node.nodeName=="TEXTAREA") {
			node.disabled = false;
			node.className=node.className.replace(" blanked", "");
		}else if (node.nodeName=="FIELDSET" && node.id != "contactforminfo" && node.id != "category") {
			node.className = "";
		}
	}
}

function modForm(selObj){
	var emailAddress = "";
	clearInfo();
	enableForm();
	contactFunc = selObj.options[selObj.selectedIndex].value;

	switch (contactFunc){
		case "sales":
			//showInfo(contactFunc);
			document.getElementById('salesInfo').style.display = "block";
			enableForm();
			break;
		case "support":
			showInfo(contactFunc);
			disableForm();
			break;
		case "abuse":
			showInfo(contactFunc);
			disableForm();
			break;
		case "domrelease":
			showInfo(contactFunc);
			disableForm();
			break;
		case "press":
			showInfo(contactFunc);
			enableForm();
			break;
		case "feedback":
			showInfo(contactFunc);
			enableForm();
			document.getElementById('enquiry_label').innerHTML = "Your comments";
			document.getElementById('fields_accnumber').style.display = "block";
			break;
		default:
			enableForm();
			break;
	}
	
}

function initForm(){
	modForm(document.getElementById('contact_subject'));
}


document.getElementsByClassName = function (class_name) {
	var all_obj, ret_obj = new Array(), j = 0;

	if (document.all) {
		all_obj = document.all;
	}
	else if (document.getElementsByTagName && !document.all) {
		all_obj = document.getElementsByTagName("*");
	}

	for (i = 0; i < all_obj.length; i++) {		
		if ((' ' + all_obj[i].className + ' ').toLowerCase().match(new RegExp(('^.* ' + class_name + ' .*$' ).toLowerCase(),'g'))) {
			ret_obj[j++] = all_obj[i];
		}
	}
	return ret_obj;
}

strEmailRegEx = /^(\w([-._\w]*\w)*@(\w[-_\w]*\w\.)+\w{2,9})$/;
function checkContactForm() {
	strError = '';
	
	if (document.getElementById("contact_name").value == '')
		strError += '\n* Your name';
	
	if (!regExCheck(document.getElementById("contact_email").value, strEmailRegEx))
		strError += '\n* Your email address';	
		
	if (document.getElementById("contact_phone").value == '')
		strError += '\n* Your phone number';	
		
	if (document.getElementById("contact_accnumber").value == '' && document.getElementById("contact_subject").value == 'feedback')
		strError += '\n* Your Fasthosts account number';	
		
	if (document.getElementById("contact_enquiry").value == '')
		strError += '\n* An enquiry';	
	
		
	if (strError.length > 0) {
		strError = 'You have not entered the following fields:\n' + strError;	
		alert(strError);
		return false;
	}
	else
		return true;
}

function regExCheck(strToCheck, arrItem) {
	var pattern = new RegExp(arrItem);
		return (pattern.test(strToCheck));
}