/*****************************************************************
**		SO-DESIGN Standard Form Validations Functions			**
**																**
** A set of JavaScript functions that provide standard	form	**
** validation on Name & Surname lengths, telephone & email		**
** validation.													**
**																**
** Copyright: SO-Design											**
** Developed: 3/2004											**
*****************************************************************/

//****************************************************************
//** Declare some constants										**
//****************************************************************

var maxNameLength = 50;			//Max length of name (in characters)
var maxSurnameLength = 50;		//Max length of surname (in characters)
var maxAddrLine1Length = 50;	//Max length of address line 1 (in characters)
var maxAddrLine2Length = 50;	//Max length of address line 2 (in characters)
var maxTownLength = 50;			//Max length of town (in characters)
var maxPostcodeLength = 7;		//Max length of postcode (in characters)
var maxCountyLength = 50;		//Max length of county (in characters)
var maxTelephoneLength = 50;	//Max length of telephone (in characters)
var maxEmailLength = 50;		//Max length of email (in characters)


//****************************************************************
//** Make all checks and validations							**
//** FEATURE ENHANCEMENT:										**
//**	Supply parameters to define what validaion will be done	**
//****************************************************************
function validateForm() {
	var isValid;
	isValid = false;

	//isValid = nameLength();
	//isValid = surnameLength();
	//isValid = addrLine1Length();
	//isValid = addrLine2Length();
	//isValid = townLength();
	//isValid = postcodeLength();
	//isValid = countyLength();
	isValid = telephoneLength();
	//isValid = emailCheck();
}

//****************************************************************
//** Check name length											**
//****************************************************************
/*function nameLength() {
	frmName = document.forms[0].fname.value;

	if (frmName.length == 0){
		window.alert("Please enter your name");
		return false;
	}

	if (frmName.length > maxNameLength){
		window.alert("The name you entered is longer than " + maxNameLength + " characters long. Please shorten it!");
	}
}*/

//****************************************************************
//** Check surname length										**
//****************************************************************
/*function surnameLength() {
	frmSurname = document.forms[0].surname.value;
	if (frmSurname.length > maxSurnameLength){
		window.alert("The surname you entered is longer than " + maxSurnameLength + " characters long. Please shorten it!")
		return false;
	}
	else{
		return true;
	}
}?

//****************************************************************
//** Check address line 1 length								**
//****************************************************************
function addrLine1Length() {
	frmAddrLine1 = document.forms[0].addrLine1.value;
	if (frmAddrLine1.length > maxAddrLine1Length){
		window.alert("The 1st line of your address is longer than " + maxAddrLine1Length + " characters long. Please shorten it!")
		return false;
	}
	else{
		return true;
	}
}

//****************************************************************
//** Check address line 2 length								**
//****************************************************************
function addrLine2Length() {
	frmAddrLine2 = document.forms[0].addrLine2.value;
	if (frmAddrLine2.length > maxAddrLine2Length){
		window.alert("The 2nd line of your address is longer than " + maxAddrLine2Length + " characters long. Please shorten it!")
		return false;
	}
	else{
		return true;
	}
}

//****************************************************************
//** Check town length											**
//****************************************************************
function townLength() {
	frmTown = document.forms[0].town.value;
	if (frmTown.length > maxTownLength){
		window.alert("The town name you entered is longer than " + maxTownLength + " characters long. Please shorten it!")
		return false;
	}
	else{
		return true;
	}
}

//****************************************************************
//** Check postcode length										**
//****************************************************************
function postcodeLength() {
	frmPostcode = document.forms[0].postcode.value;
	if (frmPostcode.length > maxPostcodeLength){
		window.alert("The postcode you entered is longer than " + maxPostcodeLength + " characters long. Please shorten it!")
		return false;
	}
	else{
		return true;
	}
}

//****************************************************************
//** Check county length										**
//****************************************************************
function countyLength() {
	frmCounty = document.forms[0].county.value;
	if (frmCounty.length > maxCountyLength){
		window.alert("The county name you entered is longer than " + maxCountyLength + " characters long. Please shorten it!")
		return false;
	}
	else{
		return true;
	}
}
*/
//****************************************************************
//** Check telephone length										**
//****************************************************************
function telephoneLength(frmTelephone) {
	frmTelephone = document.forms[0].tel.value

	if (frmTelephone.length == 0){
		window.alert("Please enter your telephone");
		return false;
	}

	if (frmTelephone.length > maxTelephoneLength){
		window.alert("The telephone you entered is longer than " + maxTelephoneLength + " characters long. Please shorten it");
	}
}

//****************************************************************
//** Check email length and validity							**
//****************************************************************
/*function emailCheck() {

	var str=document.forms[0].email.value
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail address")
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail address")
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail address")
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail address")
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail address")
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail address")
		return false;
	 }

	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail address")
		return false;
	 }

	if (str.length > maxEmailLength){
		window.alert("The email you entered is longer than " + maxTelephoneLength + " characters long. Please shorten it!")
		return false;
	}

	return true;

}

*/








function echeck(str) {

						
	}