numpeople = 5;
numccsets = 5;

function resetForm() {
	document.forms[0].reset();
}

function checkInput() {
	var inName = document.forms[0].cname.value;
	var inEmail = document.forms[0].cemail.value;
	var inBody = document.forms[0].cbody.value;
	var validdetails=true;
	var badfieldsMsg="Please correct the following: \n";
	
	if (inName=="") {
		validdetails=false;
		badfieldsMsg += "\n * Enter your name or company name in the NAME box";
	}
	
	if (inEmail=="") {
		validdetails=false;
		badfieldsMsg += "\n * Enter your email address in the EMAIL box";
	} else {
		if (checkEmailStructure(inEmail)==false) {
			validdetails=false;
			badfieldsMsg += "\n * Enter a valid email address in the EMAIL box";
		}
	}
	
	if (inBody=="") {
		validdetails=false;
		badfieldsMsg += "\n * Enter your message in the BODY box";
	}

	if (validdetails==false) {
		alert(badfieldsMsg);
	} else {
		// all input valid so post to mailer
		//document.forms[0].action="autosend.php"
		document.forms[0].action="autosend.php";
		document.forms[0].submit();
		//return true;
	}
}

function checkEmailStructure (strEml) {
	var intAtPlace=0;
	var intDotPlace=0;
	var blnAtFound=false;
	var blnDotFound=false;
	var blnAtnDotSpace=false;
	var strAddress="";
	
	strAddress=strEml;
	for (i=1; i<strAddress.length; i++) {
		if (strAddress.charAt(i)=="@") {
			intAtPlace=i;
			blnAtFound=true;
		}
	}
	
	if (blnAtFound) {
		for (i=intAtPlace; i<strAddress.length; i++) {
			if (strAddress.charAt(i)==".")
				intDotPlace=i;
				blnDotFound=true;
		}
	}
	
	if (blnAtFound&&blnDotFound) {
		// make sure there is space between the @ sign and the dot
		if ((intDotPlace>(intAtPlace+2))&&((intDotPlace+1)<strAddress.length)) {
			blnAtnDotSpace = true;
		}
	}
	
	return (blnAtFound&&blnDotFound&&blnAtnDotSpace);
}

function showPeronalDetails(persId) {
	hideAllMenus(numpeople, 'pers');
	changeObjectVisibility('pers' + persId, 'visible');
}

function showCCDetails(sectId) {
//	alert ('id: ' + sectId);
	hideAllMenus(numccsets, 'cc');
	//alert ('OK');
	changeObjectVisibility('cc' + sectId, 'visible');
}

function hideAllMenus(numToHide, idStart) {
	for(counter = 1; counter <= numToHide; counter++) {
		changeObjectVisibility(idStart + counter, 'hidden');
	}
}

function changeObjectVisibility(objectId, newVisibility) {
	// get a reference to the cross-browser style object and make sure the object exists
	var styleObject = getStyleObject(objectId);
	if(styleObject) {
		styleObject.visibility = newVisibility;
	}
} // changeObjectVisibility
	
	function getStyleObject(objectId) {
		// cross-browser function to get an object's style object given its id
		if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId).style;
		} else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId).style;
		} else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
		} else {
		return false;
		}
	} // getStyleObject