

var timeoutID = '';

function startTimer()
{
    window.clearTimeout(timeoutID);
    timeoutID = window.setTimeout("history.back()",120000);
    stb();
}

var timeoutID = '';

function closewindowTimer()
{
    window.clearTimeout(timeoutID);
    timeoutID = window.setTimeout("history.back()",5000);
}


function validatefriend()
{

var f = document.friend;

	if (f.friendsfirstname.value==''||f.friendsfirstname.value==null)
	{
		alert("Please enter your friend's first name");
		f.friendsfirstname.focus();
		f.friendsfirstname.select();
		return false;
	}

	if (f.friendsemail.value==''||f.friendsemail.value==null)
	{
		alert("Please enter your friend's email address");
		f.friendsemail.focus();
		f.friendsemail.select();
		return false;
	}
 
	if (!validEmail(f.friendsemail.value)) 
	{
		alert("Please enter a valid email address. It should be like 'someone@somewhere.co.uk'.")
		f.friendsemail.focus();
		f.friendsemail.select();
		return false;
	}

	if (f.myfirstname.value==''||f.myfirstname.value==null)
	{
		alert('Please enter your first name');
		f.myfirstname.focus();
		f.myfirstname.select();
		return false;
	}

	if (f.myemail.value==''||f.myemail.value==null)
	{
		alert('Please enter your email address');
		f.myemail.focus();
		f.myemail.select();
		return false;
	}
 
	if (!validEmail(f.myemail.value)) 
	{
		alert("Please enter a valid email address. It should be like 'someone@somewhere.co.uk'.")
		f.myemail.focus();
		f.myemail.select();
		return false;
	}

	if (window.confirm("Are you ready to send this email?"))
	{
		alert('Submitting your email may take a few moments. Please do not click the Send button again.');
		closewindowTimer();
		setHourglass();
		return true;
	}
	else
	{
		return false;
	}

}

function setHourglass()
{
    if (document.all)
        for (var i=0;i < document.all.length; i++)
             document.all(i).style.cursor = 'wait';
}

function validEmail(email)
{
	invalidChars = " /:,;#!$%^&*()|\?<>~`+"
	if (email=="")
	{
	return true
	}
	for (i=0; i < invalidChars.length; i++)	
	{
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1)
		{
		return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos==-1)
	{
	return false
	}
	if (email.indexOf("@",atPos+1) != -1)
	{
	return false
	}
	periodPos = email.indexOf(".",atPos)
		if (periodPos==-1)
		{
			return false
		}
		if (periodPos+3 > email.length)
		{
			return false
		}
	return true
}

function stb()
{
	document.friend.friendsfirstname.focus();
}
