function checkString( ts, u )
{
	var currentChar;

	for ( i=0; i<ts.length; i++ ) {
		currentChar = ts.charAt(i);
		if ( u.indexOf(currentChar) == -1 ) return false;
	}

	return true;
}

function isValidLength( ts, min, max )
{
	if ( ts.length >= min && ts.length <= max ) return true;
	else return false;
}

var ws = " \t\n\r";

function isEmpty( ts )
{
	if ( ts == null ) return true;
	if ( ts.length < 1 ) return true;
	if ( ts == "" ) return true;
	if ( checkString( ts, ws ) ) return true;
	return false;
}

function Contains( ts, u )
{
	var currentChar;

	for ( i=0; i<u.length; i++ ) {
		currentChar = u.charAt(i);
		if ( ts.indexOf(currentChar) == -1 ) return false;
	}

	return true;
}

function checkAdd( pf )
{
	var ts = new String();
	var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var special = "A@BCEDFGIHJKMLNOPQSRTUVXZY[\]^_a`bcedfgihjkmlnopqsrtuvxzy{|}";
	var name = " -,'";
	var surname = "-' ";
	var mail = "@.-_";
	var num = "0123456789";
	var phone = "-./\+ ";
	var plus = "-. ,°#_&";
	var alphanum = alpha + num;

	ts = pf.Nome.value; /* first name validation */

	if ( isEmpty(ts) ) {
		alert("Please specify Your Name.");
		return false;
	}

	if ( !isValidLength(ts, 2, 30) || !checkString(ts, alpha + special + name) ) {
		alert("Your Name not valid.");
		return false;
	}

	ts = pf.Rifer.value; /* last name validation */

	if ( isEmpty(ts) ) {
		alert("Please specify a Last Name.");
		return false;
	}

	if ( !isValidLength(ts, 2, 30) || !checkString(ts, alpha + special + surname) ) {
		alert("It does not appear that the last name you entered is valid.");
		return false;
	}

	ts = pf.Email.value; /* e-mail validation */

	if ( isEmpty(ts) ) {
		alert("Please specify an E-mail Address.");
		return false;
	}

	if ( !isValidLength(ts, 5, 60) || !checkString(ts, alphanum + mail) || !Contains(ts, "@.") || ts.indexOf("@") != ts.lastIndexOf("@") ) {
		alert("It does not appear that the e-mail address you entered is valid.");
		return false;
	}

	ts = pf.Tel.value; /* phone validation */

	if ( !isEmpty(ts) ) {
		if ( !isValidLength(ts, 5, 21) || !checkString(ts, num + phone) ) {
			alert("It does not appear that the phone number you entered is valid.");
			return false;
		}
	}
	
	return true;
}

function checkContact( pf )
{
	var ts = new String();
	var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var special = "A@BCEDFGIHJKMLNOPQSRTUVXZY[\]^_a`bcedfgihjkmlnopqsrtuvxzyàéèìòù{|}";
	var name = " -,'";
	var surname = "-' ";
	var mail = "@.-_";
	var num = "0123456789";
	var phone = "-./\+ ";
	var plus = "-. ,°#_&";
	var alphanum = alpha + num;

	ts = pf.Name.value; /* first name validation */

	if ( isEmpty(ts) ) {
		alert("Please specify Your Name.");
		return false;
	}

	if ( !isValidLength(ts, 2, 30) || !checkString(ts, alpha + special + name) ) {
		alert("Your Name not valid.");
		return false;
	}

	ts = pf.Cogn.value; /* last name validation */

	if ( isEmpty(ts) ) {
		alert("Please specify a Last Name.");
		return false;
	}

	if ( !isValidLength(ts, 2, 30) || !checkString(ts, alpha + special + surname) ) {
		alert("It does not appear that the last name you entered is valid.");
		return false;
	}

	ts = pf.Email.value; /* e-mail validation */

	if ( isEmpty(ts) ) {
		alert("Please specify an E-mail Address.");
		return false;
	}

	if ( !isValidLength(ts, 5, 60) || !checkString(ts, alphanum + mail) || !Contains(ts, "@.") || ts.indexOf("@") != ts.lastIndexOf("@") ) {
		alert("It does not appear that the e-mail address you entered is valid.");
		return false;
	}

	ts = pf.Message.value; /* last name validation */

	if ( isEmpty(ts) ) {
		alert("Please specify a Message.");
		return false;
	}
	
	return true;
}

function checkTell( pf )
{
	var ts = new String();
	var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var special = "A@BCEDFGIHJKMLNOPQSRTUVXZY[\]^_a`bcedfgihjkmlnopqsrtuvxzyàéèìòù{|}";
	var name = " -,'";
	var surname = "-' ";
	var mail = "@.-_";
	var num = "0123456789";
	var phone = "-./\+ ";
	var plus = "-. ,°#_&";
	var alphanum = alpha + num;

	ts = pf.Name.value; /* first name validation */

	if ( isEmpty(ts) ) {
		alert("Please specify Your Name.");
		return false;
	}

	if ( !isValidLength(ts, 2, 30) || !checkString(ts, alpha + special + name) ) {
		alert("Your Name not valid.");
		return false;
	}

	ts = pf.Email.value; /* e-mail validation */

	if ( isEmpty(ts) ) {
		alert("Please specify an E-mail Address.");
		return false;
	}

	if ( !isValidLength(ts, 5, 60) || !checkString(ts, alphanum + mail) || !Contains(ts, "@.") || ts.indexOf("@") != ts.lastIndexOf("@") ) {
		alert("It does not appear that the e-mail address you entered is valid.");
		return false;
	}

	ts = pf.Name2.value; /* first name validation */

	if ( isEmpty(ts) ) {
		alert("Please specify Your Friend's Name.");
		return false;
	}

	if ( !isValidLength(ts, 2, 30) || !checkString(ts, alpha + special + name) ) {
		alert("Your Friend's Name not valid.");
		return false;
	}

	ts = pf.Email2.value; /* e-mail validation */

	if ( isEmpty(ts) ) {
		alert("Please specify an E-mail Address for your friend.");
		return false;
	}

	if ( !isValidLength(ts, 5, 60) || !checkString(ts, alphanum + mail) || !Contains(ts, "@.") || ts.indexOf("@") != ts.lastIndexOf("@") ) {
		alert("It does not appear that the e-mail address of your friend you entered is valid.");
		return false;
	}	
	
	return true;
}

function checkRes( pf )
{
	var ts = new String();
	var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var special = "A@BCEDFGIHJKMLNOPQSRTUVXZY[\]^_a`bcedfgihjkmlnopqsrtuvxzyàéèìòù{|}";
	var name = " -,'";
	var surname = "-' ";
	var mail = "@.-_";
	var num = "0123456789";
	var phone = "-./\+ ";
	var plus = "-. ,°#_&";
	var alphanum = alpha + num;

	ts = pf.Email.value; /* e-mail validation */

	if ( isEmpty(ts) ) {
		alert("Please specify an E-mail Address.");
		return false;
	}

	if ( !isValidLength(ts, 5, 60) || !checkString(ts, alphanum + mail) || !Contains(ts, "@.") || ts.indexOf("@") != ts.lastIndexOf("@") ) {
		alert("It does not appear that the e-mail address you entered is valid.");
		return false;
	}

	return true;
}