function CheckForm() {
	formcheck();
}

function submitData(theform, output) {
  var status = AjaxRequest.submit(
    theform
    ,{'parameters':{ '_securityVal':''+scval+''}
    ,'onSuccess':function(req){	output.innerHTML = req.responseText; setTimeout('reLoadForm()',5000); }
    }
  );
}

function formReturn(output) {
	 AjaxRequest.get(
    {
     'url':'sendtoafriend.asp'
    ,'onSuccess':function(req){	output.innerHTML = req.responseText;}
    }
  );
}

function reLoadForm(){
	formReturn(document.getElementById('sendToAFriend'));
}

function formcheck() {

	//Initialise variables
	var errorMsg = "";

	//Check for a first name
	if (document.contactForm.yName.value == ""){
		errorMsg += "\n\tYour Name\t- Enter your name";
		document.getElementById('sendtofriendyname').style.visibility = 'visible';
	} else {
		document.getElementById('sendtofriendyname').style.visibility = 'hidden';
	}

	//Check for a last name
	if (document.contactForm.fName.value == ""){
		errorMsg += "\n\tFriends Name\t- Enter your friends Name";
		document.getElementById('sendtofriendname').style.visibility = 'visible';
	} else {
		document.getElementById('sendtofriendname').style.visibility = 'hidden';
	}

	//Check for an e-mail address and that it is valid
	if ((document.contactForm.fEmail.value == "") || (document.contactForm.fEmail.length > 0 && (document.contactForm.fEmail.value.indexOf("@",0) == - 1 || document.contactForm.fEmail.value.indexOf(".",0) == - 1))) {
		errorMsg += "\n\tE-mail\t- Enter your friends e-mail address";
		document.getElementById('sendtofriendemail').style.visibility = 'visible';
	} else {
		document.getElementById('sendtofriendemail').style.visibility = 'hidden';
	}

	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "__________________________________________________\n\n";
		msg += "There are one or more errors on the form.\n";
		msg += "Please correct the problem(s) and re-send to a friend.\n";
		msg += "__________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";

		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	submitData(document.forms['contactForm'], document.getElementById('sendToAFriend'));
}