//	****************************************************************************	
//	* Program Name  : ValidationRoutines					   *   
//	* Programmer    : Jayaprakash Narayanan   				   *    
//	* Purpose	: The purpose of the program is to validate all form  	   *
//	*		  fields of User Login Screen and User Registration screen *
//	* Last Modified : 06/04/2000              				   *
//	* Last Modified : 28/04/2000              				   *
//	****************************************************************************	
//	* Purpose	: Modified to include validation for Pricing Info request  *
//	* 		  form.	- function validatePricing                 	   *
//	* Last Modified : 14/02/2003              				   *
//	****************************************************************************	

function validateLogin(theForm)
{

  var retStatus = 0;
// Project Group Validation

  theForm.txtProjectGroup.value = stripSpaces(theForm.txtProjectGroup.value);
  retStatus = allowedCharater(theForm.txtProjectGroup.value, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ",24,true);

  if(retStatus==1)
  {
    alert("Please enter a value for the Group Name.");

  }

  if(retStatus==2)
  {
    alert("Please enter at most 24 characters in the Group Name.");
  }

  if(retStatus==3)
  {

    alert("Please enter only Letter, Digit and Whitespace characters in the Group Name.");
  }

  if(retStatus!=0)
  {

    theForm.txtProjectGroup.focus();
    theForm.txtProjectGroup.select();
    return (false);
  }

// Ends



//  User Login Name Validation

  theForm.txtUserLoginName.value = stripSpaces(theForm.txtUserLoginName.value);

  retStatus = allowedCharater(theForm.txtUserLoginName.value,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi jklmnopqrstuvwxyz123456_7890-",24,true);

  if(retStatus==1)
  {
    alert("Please enter a value for the Login Name.");
  }

  if(retStatus==2)
  {
    alert("Please enter at most 24 characters in the Login Name.");
  }

  if(retStatus==3)
  {
    alert("Please enter only Letter , Digit,  Whitespace charaters,\"_\" and \"-\"  in the Login Name.");
  }

  if(retStatus==0)
  {
	  retStatus = startsOk(theForm.txtUserLoginName.value,"-_");
	  if(retStatus!=0)
	  {
//		theForm.txtUserLoginName.value = theForm.txtUserLoginName.value.trim();
		alert("Login Name can not start or end with \"-_\".");
	  }

  }
  if(retStatus!=0)
  {
		theForm.txtUserLoginName.focus();
  		theForm.txtUserLoginName.select();
		return (false);
   }


// Ends

// User Password Checking

  retStatus = allowedCharater(theForm.txtPassword.value, 
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU_-VWXYZ12345677890",16,true);

//"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU_-VWXYZ12345677890",8,true);

  if(retStatus==1)
  {
    alert("Please enter a value for the Password.");
  }


  if(retStatus==2)
  {
    alert("Please enter at most 16 characters in the Password.");
  }

  if(retStatus==3)
  {
    alert("Please enter only Letter, Digit and \"_\",\"-\" characters in the Password.");
  }

  if(retStatus!=0)
  {
 
    theForm.txtPassword.focus();
    theForm.txtPassword.select();
    return (false);
  }

// Ends
  return (true)

}


function validateRoot(theForm)
{

  var retStatus = 0;
  
  // Root Administrator Logon Name and Password Validation

  theForm.txtLoginName.value = stripSpaces(theForm.txtLoginName.value);

  retStatus = allowedCharater(theForm.txtLoginName.value,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi jklmnopqrstuvwxyz123456_7890-",24,true);

  if(retStatus==1)
  {
    alert("Please enter a value for the Root Administrator Login Name.");
  }

  if(retStatus==2)
  {
    alert("Please enter at most 24 characters in the Root Administrator Login Name.");
  }

  if(retStatus==3)
  {
    alert("Please enter only Letter , Digit,  Whitespace charaters,\"_\" and \"-\"  in the Root Administrator Login Name.");
  }

  if(retStatus==0)
  {
	  retStatus = startsOk(theForm.txtLoginName.value,"-_");
	  if(retStatus!=0)
	  {
		alert("Login Name can not start or end with \"-_\".");
	  }

  }
  if(retStatus!=0)
  {
		theForm.txtLoginName.focus();
  		theForm.txtLoginName.select();
		return (false);
   }


  retStatus = allowedCharater(theForm.txtPassword.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU_-VWXYZ12345677890",16,true);

  if(retStatus==1)
  {
    alert("Please enter a value for the Password.");
  }

  if(retStatus==2)
  {
    alert("Please enter at most 16 characters in the Password.");
  }

  if(retStatus==3)
  {
    alert("Please enter only Letter, Digit and \"_\",\"-\" characters in the Password.");
  }

  if(retStatus!=0)
  {
 
    theForm.txtPassword.focus();
    theForm.txtPassword.select();
    return (false);
  }
  return (true)

}

// The following function is used to validate Root Change Password.

function validatechangepwd(theForm)
{

  var retStatus = 0;
  
  theForm.txtLoginName.value = stripSpaces(theForm.txtLoginName.value);

  retStatus = allowedCharater(theForm.txtLoginName.value,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi jklmnopqrstuvwxyz123456_7890-",24,true);

  if(retStatus==1)
  {
    alert("Please enter valid Root Administrator Login Name in the User Name field");
  }

  if(retStatus==2)
  {
    alert("Please enter at most 24 characters in the Root Administrator Login Name.");
  }

  if(retStatus==3)
  {
    alert("Please enter only Letter , Digit,  Whitespace charaters,\"_\" and \"-\"  in the Root Administrator Login Name.");
  }

  if(retStatus==0)
  {
	  retStatus = startsOk(theForm.txtLoginName.value,"-_");
	  if(retStatus!=0)
	  {
		alert("User Name can not start or end with \"-_\".");
	  }

  }
  if(retStatus!=0)
  {
		theForm.txtLoginName.focus();
  		theForm.txtLoginName.select();
		return (false);
   }


  retStatus = allowedCharater(theForm.txtOldPassword.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU_-VWXYZ12345677890",16,true);

  if(retStatus==1)
  {
    alert("Please enter a valid Password in the Old Password field.");
  }

  if(retStatus==2)
  {
    alert("Please enter at most 16 characters in the Old Password.");
  }

  if(retStatus==3)
  {
    alert("Please enter only Letter, Digit and \"_\",\"-\" characters in the Old Password.");
  }

  if(retStatus!=0)
  {
 
    theForm.txtOldPassword.focus();
    theForm.txtOldPassword.select();
    return (false);
  }

  retStatus = allowedCharater(theForm.txtNewPassword.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU_-VWXYZ12345677890",16,true);

  if(retStatus==1)
  {
    alert("Please enter a valid New Password in the New Password field.");
  }

  if(retStatus==2)
  {
    alert("Please enter at most 16 characters in the New Password.");
  }

  if(retStatus==3)
  {
    alert("Please enter only Letter, Digit and \"_\",\"-\" characters in the New Password.");
  }

  if(retStatus!=0)
  {
 
    theForm.txtNewPassword.focus();
    theForm.txtNewPassword.select();
    return (false);
  }

  retStatus = allowedCharater(theForm.txtConNewPassword.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU_-VWXYZ12345677890",16,true);

  if(retStatus==1)
  {
    alert("Please enter a valid Confirm New Password in the Confirm New Password field.");
  }

  if(retStatus==2)
  {
    alert("Please enter at most 16 characters in the Confirm New Password.");
  }

  if(retStatus==3)
  {
    alert("Please enter only Letter, Digit and \"_\",\"-\" characters in the Confirm New Password.");
  }

  if(retStatus!=0)
  {
 
    theForm.txtConNewPassword.focus();
    theForm.txtConNewPassword.select();
    return (false);
  }

  if(theForm.txtNewPassword.value!=theForm.txtConNewPassword.value)
  {
  	alert("New password and Confirm new password are not same. Please enter both new password & confirm new password and try again.");
    	theForm.txtNewPassword.focus();
    	theForm.txtNewPassword.select();
    	return (false);

  }

  return (true)

}


function validateRegistration(theForm)
{

  var retStatus = 0;

  if(validateLogin(theForm))
  {


// Email Mail Checking 
	var isValidMail=0; 

	theForm.txtEmailId.value = stripSpaces(theForm.txtEmailId.value);
	isValidMail = startsOk(theForm.txtEmailId.value,"-_.@");

	if(isValidMail!=0)
	{
		alert("E-Mail ID field can not start or end with \"-\",\"_\",\"@\",\".\".");
		theForm.txtEmailId.focus();
    		theForm.txtEmailId.select();
	    	return (false);
	}
	else
	{
		isValidMail = VerifyEmail(theForm.txtEmailId.value);

		if(isValidMail == -9)
	  	{
			alert("Please enter atmost 64 characters in E-Mail ID.");
			theForm.txtEmailId.focus();
	    		theForm.txtEmailId.select();
			return(false);
		}
		else
  		{
			if(isValidMail!=0)
			{
//				alert("Please enter a Valid E-Mail ID.");
				alert("Please enter a Valid E-Mail ID field. Only Alphanumeric characters and \"-\",\"_\", \"@\",\".\" characters are allowed in E-Mail ID field.");
				theForm.txtEmailId.focus();
	    			theForm.txtEmailId.select();
			    	return (false);
			}

  		}

	}

// Ends

// Project Purpose Validation


  	retStatus = allowedCharater(theForm.txtProjectGroupPurpose.value,"XXX",255,true);

  	if(retStatus==1)
  	{
		alert("Please enter a value for the \"Project Purpose\" field.");
  	}

  	if(retStatus==2)
  	{
		alert("Please enter at most 255 characters in \"Project Purpose\" field.");
  	}

  	if(retStatus!=0)
  	{
		theForm.txtProjectGroupPurpose.focus();
    		theForm.txtProjectGroupPurpose.select();
    		return (false);
  	}

// Ends



// User Verify Password Checking

	 retStatus = allowedCharater(theForm.txtConfirmPassword.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU_-VWXYZ12345677890",16,true);

  	if(retStatus==1)
  	{
    		alert("Please enter a value for the Password field.");
  	}


  	if(retStatus==2)
  	{
    		alert("Please enter at most 16 characters in the Password field.");
  	}

  	if(retStatus==3)
  	{
    		alert("Please enter only Letter, Digit and \"_\",\"-\" characters in the \"Password\" field.");
  	}

  	if(retStatus!=0)
  	{
	    	theForm.txtConfirmPassword.focus();
    		theForm.txtConfirmPassword.select();
    		return (false);
  	}

// Ends





// User First Name Validation

	theForm.txtFirstName.value = stripSpaces(theForm.txtFirstName.value);

  	retStatus = allowedCharater(theForm.txtFirstName.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ", 24,true);

  	if(retStatus==1)
  	{
    		alert("Please enter a value for the FirstName field");
  	}


  	if(retStatus==2)
  	{
    		alert("Please enter at most 24 characters in  the FirstName field.");
  	}


  	if(retStatus==3)
  	{
	   	alert("Please enter only Letter, Digit and Whitespace charaters in the FirstName field.");
  	}

  	if(retStatus!=0)
  	{
    		theForm.txtFirstName.focus();
    		theForm.txtFirstName.select();
    		return (false);
  	}

// Ends



// User Last Name Validation

	theForm.txtLastName.value = stripSpaces(theForm.txtLastName.value);

  	retStatus = allowedCharater(theForm.txtLastName.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ",24,true);

  	if(retStatus==1)
  	{
    		alert("Please enter a value for the LastName field.");
  	}


  	if(retStatus==2)
  	{
    		alert("Please enter at most 24 characters in the LastName field.");
  	}


  	if(retStatus==3)
  	{

	   	alert("Please enter only Letter, Digit and Whitespace charaters in the LastName field.");
  	}


  	if(retStatus!=0)
  	{
    		theForm.txtLastName.focus();
    		theForm.txtLastName.select();
    		return (false);
  	}
// Ends


// Company Name Validations

	theForm.txtCompanyName.value = stripSpaces(theForm.txtCompanyName.value);

  	retStatus = allowedCharater(theForm.txtCompanyName.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,&12345677890()._- ",64,true);
  	if(retStatus==1)
  	{
		alert("Please enter a value for the CompanyName field.");
  	}

  	if(retStatus==2)
  	{
    		alert("Please enter at most 64 characters in the CompanyName field.");
  	}

  	if(retStatus==3)
  	{
    		alert("Please enter only Letter, Digit, space character,\"(\",\")\",\".\",\"_\",\"&\",\"-\" and \",\"in the CompanyName field.");
 	}

	if(retStatus==0)
  	{
		retStatus = startsOk(theForm.txtCompanyName.value,"-_");
	  	if(retStatus!=0)
	  	{
			alert("CompanyName Field can not start or end with \"-_\".");
	  	}
  	}

  	if(retStatus!=0)
  	{
    		theForm.txtCompanyName.focus();
    		theForm.txtCompanyName.select();
    		return (false);
  	}


// Ends



// Company Address Validations

	theForm.txtCompanyAddress.value = stripSpaces(theForm.txtCompanyAddress.value);

  	retStatus = allowedCharater(theForm.txtCompanyAddress.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345677890()@_~-.,/ ",48,true);


  	if(retStatus==1)
  	{
		alert("Please enter a value for the CompanyAddress field.");
  	}

  	if(retStatus==2)
  	{
    		alert("Please enter at most 48 characters in the CompanyAddress field.");
  	}

  	if(retStatus==3)
  	{
    		alert("Please enter only Letter, Digit, Whitespace and \"@\",\"_\",\"~\",\"-\",\".\",\",\",\"(\" ,\"/\" and \")\"  characters in the CompanyAddress field.");
  	}

  	if(retStatus!=0)
  	{
    		theForm.txtCompanyAddress.focus();
    		theForm.txtCompanyAddress.select();
    		return (false);
  	}

// Ends


// Company City Validation

	theForm.txtCompanyCity.value = stripSpaces(theForm.txtCompanyCity.value);

  	retStatus = allowedCharater(theForm.txtCompanyCity.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345677890-. ",32,true);

  	if(retStatus==1)
  	{
		alert("Please enter a value for the CompanyCity field.");
  	}

  	if(retStatus==2)
  	{
    		alert("Please enter at most 32 characters in the CompanyCity field.");
  	}

  	if(retStatus==3)
  	{
    		alert("Please enter only Letter, Digit, Whitespace , \"-\" and \".\" charaters in the CompanyCity field.");
  	}
  	if(retStatus!=0)
  	{
		theForm.txtCompanyCity.focus();
    		theForm.txtCompanyCity.select();
    		return (false);
  	}

// Ends


// Company State Validation

	theForm.txtCompanyState.value = stripSpaces(theForm.txtCompanyState.value);

  	retStatus = allowedCharater(theForm.txtCompanyState.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345677890-. ",32,true);

  	if(retStatus==1)
  	{
		alert("Please enter a value for the CompanyState field.");
  	}

  	if(retStatus==2)
  	{
    		alert("Please enter at most 32 characters in the CompanyState field.");
  	}

  	if(retStatus==3)
  	{
    		alert("Please enter only Letter, Digit, Whitespace and \"-\",\".\"   charaters in the CompanyState field.");
  	}
  	if(retStatus!=0)
  	{

    		theForm.txtCompanyState.focus();
    		theForm.txtCompanyState.select();
    		return (false);
  	}
// Ends

// Comapny Zip Validation

	theForm.txtCompanyZip.value = stripSpaces(theForm.txtCompanyZip.value);

  	retStatus = allowedCharater(theForm.txtCompanyZip.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345677890 ",16,true);


  	if(retStatus==1)
  	{
		alert("Please enter a value for the Zip field.");
  	}
  	if(retStatus==2)
  	{
	    	alert("Please enter at most 16 characters in the Zip field.");
  	}

  	if(retStatus==3)
  	{
    		alert("Please enter only Alphabet,Numeric and Blank charaters in the Zip field.");
  	}

  	if(retStatus!=0)
  	{

    		theForm.txtCompanyZip.focus();
    		theForm.txtCompanyZip.select();
    		return (false);
  	}

// Ends


// Compnay Coutry Checking 
	theForm.txtCompanyCountry.value = stripSpaces(theForm.txtCompanyCountry.value);

  	retStatus = allowedCharater(theForm.txtCompanyCountry.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345677890 ",32,true);


  	if(retStatus==1)
  	{
		alert("Please enter a value for the Country field.");
  	}
  	if(retStatus==2)
  	{
		alert("Please enter at most 32 characters in the Country field.");
  	}

  	if(retStatus==3)
  	{
    		alert("Please enter only Letter, Digit and Whitespace characters in the Country field.");
  	}

	if(retStatus!=0)
  	{
    		theForm.txtCompanyCountry.focus();
    		theForm.txtCompanyCountry.select();
    		return (false);
  	}

// Ends

// Company Phone Checking

	theForm.txtCompanyPhone.value = stripSpaces(theForm.txtCompanyPhone.value);

  	retStatus = allowedCharater(theForm.txtCompanyPhone.value,"XXX",32,true);

  	if(retStatus==1)
  	{
		alert("Please enter a value for the Company Phone field.");
  	}

  	if(retStatus==2)
  	{
    		alert("Please enter at most 32 characters in the Company Phone field.");
  	}

  	if(retStatus!=0)
  	{
    		theForm.txtCompanyPhone.focus();
    		theForm.txtCompanyPhone.select();
    		return (false);
  	}
//Ends




// Company Fax Checking

	theForm.txtCompanyFax.value = stripSpaces(theForm.txtCompanyFax.value);
  	retStatus = allowedCharater(theForm.txtCompanyFax.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345677890-()_,. ",32,true);

  	if(retStatus==1)
  	{
		alert("Please enter a value for the Fax field.");
  	}

  	if(retStatus==2)
  	{
    		alert("Please enter at most 32 characters in the Fax field.");
  	}

  	if(retStatus==3)
  	{
    		alert("Please enter only Letter, Digit, Whitespace and \"-\",\"_\",\"(\",\")\",\".\"  and \",\" characters in the Fax field.");
  	}

  	if(retStatus!=0)
  	{
    		theForm.txtCompanyFax.focus();
    		theForm.txtCompanyFax.select();
    		return (false);
  	}

// Ends

// Password confirmation Checking
 
  	if(theForm.txtPassword.value!=theForm.txtConfirmPassword.value)
  	{
    		alert("Password confirmation failed");
    		theForm.txtPassword.focus();
    		theForm.txtPassword.select();
    		return (false);

  	}

  }
  else
  {
	return (false);
  }
  return (true);
}


function validatePricing(theForm)
{

  var retStatus = 0;
	

//Company Name
	theForm.company.value = stripSpaces(theForm.company.value);

  	retStatus = allowedCharater(theForm.company.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345677890(),._ ",64,true);

  	if(retStatus==1)
  	{
		alert("Please enter a value for the company name field.");
  	}

  	if(retStatus==2)
  	{
    		alert("Please enter at most 64 characters in the company name field.");
  	}

  	if(retStatus==3)
  	{
    		alert("Please enter only Letter, Digit, Whitespace character,\"(\",\")\",\".\",\"_\" and \",\"in the Company Name field.");
  	}

	if(retStatus==0)
  	{
		retStatus = startsOk(theForm.company.value,"-_");
	  	if(retStatus!=0)
	  	{
			alert("Company Name Field can not start or end with \"-_\".");
	  	}
  	}

  	if(retStatus!=0)
  	{
    		theForm.company.focus();
    		theForm.company.select();
    		return (false);
  	}

//Company Name end

//contact Name
	theForm.contact.value = stripSpaces(theForm.contact.value);

  	retStatus = allowedCharater(theForm.contact.value,"abcdefghi jklmnopqrstuvwxyzABCDEFGHIJKL MNOPQRSTUVWXYZ,12345677890()._",48,true);

  	if(retStatus==1)
  	{
		alert("Please enter a value for the Contact Name field.");
  	}

  	if(retStatus==2)
  	{
    		alert("Please enter at most 48 characters in the Contact Name field.");
  	}

  	if(retStatus==3)
  	{
    		alert("Please enter only Letter, Digit, Whitespace character,\"(\",\")\",\".\",\"_\" and \",\"in the Contact Name field.");
  	}

	if(retStatus==0)
  	{
		retStatus = startsOk(theForm.contact.value,"-_");
	  	if(retStatus!=0)
	  	{
			alert("Contact Name Field can not start or end with \"-_\".");
	  	}
  	}

  	if(retStatus!=0)
  	{
    		theForm.contact.focus();
    		theForm.contact.select();
    		return (false);
  	}

//Contact Name end

// Email Mail Checking 
	var isValidMail=0; 

	theForm.email.value = stripSpaces(theForm.email.value);
	isValidMail = startsOk(theForm.email.value,"-_");

	if(isValidMail!=0)
	{
		alert("E-Mail ID field can not start or end with \"-\",\"_\".");
		theForm.email.focus();
    		theForm.email.select();
	    	return (false);
	}
	else
	{
		isValidMail = VerifyEmail(theForm.email.value);

		if(isValidMail==-9)
	  	{
			alert("Please enter atmost 64 characters in E-Mail ID.");
		}
		else
  		{
			if(isValidMail!=0)
			{
				alert("Please enter a Valid E-Mail ID.");
				theForm.email.focus();
	    			theForm.email.select();
			    	return (false);
			}

  		}

	}

// Ends email varification

// Company Phone Checking

	theForm.phone.value = stripSpaces(theForm.phone.value);
  	retStatus = allowedCharater(theForm.phone.value,"12345677890-()",16,true);

  	if(retStatus==1)
  	{
    		alert("Please enter a value for the Company Phone field.");
  	}


  	if(retStatus==2)
  	{
    		alert("Please enter at most 16 characters in the Company Phone field.");
  	}

  	if(retStatus==3)
	{
    		alert("Please enter only Digit and \"-\",\"(\" and \")\" characters in the Phone field.");
  	}

  	if(retStatus!=0)
  	{
    		theForm.phone.focus();
    		theForm.phone.select();
    		return (false);
  	}
//Ends

// Users Checking

	theForm.users.value = stripSpaces(theForm.users.value);
  	retStatus = allowedCharater(theForm.users.value,"12345677890",5,true);

  	if(retStatus==1)
  	{
    		alert("Please enter a value for the Users field.");
  	}


  	if(retStatus==2)
  	{
    		alert("Please enter at most 5 digits in the Users field.");
  	}

  	if(retStatus==3)
	{
    		alert("Please enter only Digit in the Users field.");
  	}

  	if(retStatus!=0)
  	{
    		theForm.users.focus();
    		theForm.users.select();
    		return (false);
  	}
//Ends

}





function VerifyEmail(email) 
{ 
	var at_pos =-1; 
	var atMore_pos= -1; 
	var pd_pos = -1; 
	var pdMore_pos = -1;	
	var sp_pos= -1; 
	var em_len= -1; 
	var allowed= -1;
// Make sure there is a value 
	em_len = email.length; 
	if (em_len < 1) 
	{ 
	return -1; 
	} 


// Make sure it does not exceed 64 and conatins allowed chars

	allowed=allowedCharater(email,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_@.",64,true);
	


 	if(allowed==2)
        {
		return -9; 
	}
 	if(allowed==3)
        {
		return -10; 
	}


// Check for spaces 
	sp_pos = email.indexOf(" ", 0); 
	if (sp_pos != -1) { 

	return -2; 
	} 
// Check for an @ symbol 
	at_pos = email.indexOf("@", 0); 
	if (at_pos == -1) { 
	return -3; 
	} 
// Check for a period after the @ symbol 
	pd_pos = email.indexOf(".", at_pos); 
	if (pd_pos == -1) { 
	return -4; 
	} 


// Check for period as last character 
	if (pd_pos == (em_len - 1)) 
	{ 
		return -5; 
	} 


// Make sure there is at least one character 
// between @ and . 
	if (pd_pos == (at_pos + 1)) 
	{ 
		return -6; 
	} 
// Make sure address doesn't start with @ 
//symbol 
	if (at_pos == 0) 
	{ 
	return -7; 
	} 

// Make sure there @ doesn't occur more than once

 
	atMore_pos = email.indexOf("@", at_pos+1); 
	if (atMore_pos != -1) { 
	return -8; 
	} 

	while(email.indexOf(".", pd_pos+1)!=-1)
	{
		pdMore_pos = email.indexOf(".", pd_pos+1); 
		if(pdMore_pos == pd_pos+1)
		{
			return -11;
		}
		pd_pos = pdMore_pos;
	}

	return 0; 
} 



function allowedCharater(fieldToBeChecked, allowedChar,maxLength,isMust)
{
//  fieldToBeChecked = stripSpaces(fieldToBeCheckedP);
  var illegal;
  if(isMust && fieldToBeChecked=="")
  {
    return 1; 
	
  }

  if(fieldToBeChecked.length>maxLength)
  {
    return 2; 
  }



  if(allowedChar=="XXX")
  {
	return 0;
  }
  var checkOK = allowedChar;
  var checkStr = fieldToBeChecked;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      return 3;
    }
  }
  return 0;

}

function startsOk(fieldToBeChecked,notAllowedChar)
{
  var checkField = fieldToBeChecked;
  var notAllowed = notAllowedChar;
  var chStart = checkField.charAt(0);
  var chEnd = checkField.charAt(checkField.length-1);

  for (j = 0;  j < notAllowed.length;  j++)
  {
	var chNotAllowed = notAllowed.charAt(j);
      	if((chStart == chNotAllowed) || (chEnd == chNotAllowed))
	{
		return 1; // Not OK
	}
  }
  return 0; // OK

}

function stripSpaces(fieldToBeChecked) 
{
    x = fieldToBeChecked;
    while (x.substring(0,1) == ' ') x = x.substring(1);
    while (x.substring(x.length-1,x.length) == ' ') x = x.substring(0,x.length-1);
    return x;

}


//	****************************************************************************	
//	* Purpose	: Modified to include Cookie handling			   *
//	* Last Modified : 14/02/2003              				   *
//	****************************************************************************	

function Cookie(document,name,hours,path,domain,secure)
{
 // any VAR in "this" that does not start with a "$" will
 // be written into the cookie (read from also)
  this.$doc  = document
  this.$name = name
  if (hours)  this.$expiration=new Date((new Date()).getTime()+hours*3600000); else this.$expiration = null
  if (path)   this.$path   = path;                                             else this.$path       = null
  if (domain) this.$domain = domain;                                           else this.$domain     = null
  if (secure) this.$secure = true;                                             else this.$secure     = false
}

function CookieWrite() {
  var cookieval=""
  for(var prop in this) {
    if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function') || prop == '') continue
	if (cookieval != "") cookieval += '&'
	cookieval+=prop+":"+escape(this[prop])
  }
  var cookie=this.$name+"="+cookieval
  if (this.$expiration) cookie+='; expires=' + this.$expiration.toGMTString()
  if (this.$path)       cookie+='; path='    + this.$path
  if (this.$domain)     cookie+='; domain='  + this.$domain
  if (this.$secure)     cookie+='; secure'
 //alert("writting cookie="+cookie)
  this.$doc.cookie=cookie
}

function CookieRead() {
  var allcookies=this.$doc.cookie
  if (allcookies=="") {
    return false
  }
  var start= allcookies.indexOf(this.$name+'=')
  if (start== -1) {
    return false
  }
  start += this.$name.length+1
  var end=allcookies.indexOf(';',start)
  if (end == -1) end=allcookies.length
  var cookieval = allcookies.substring(start,end)
  var a = cookieval.split('&')
  for (var i=0;i<a.length;i++) a[i]=a[i].split(':')
  for (var i=0;i<a.length;i++) this[a[i][0]]=unescape(a[i][1])
  return true
}

function CookieDelete() {
  var cookie = this.$name+'='
  if (this.$path)   cookie+='; path='+this.$path
  if (this.$domain) cookie+='; domain='+this.$domain
  cookie+='; expires=Mon, 18-Dec-1972 00:00:00 GMT' // MAKE IT EXPIRE!
  this.$doc.cookie=cookie
}

new Cookie()
Cookie.prototype.write = CookieWrite
Cookie.prototype.del   = CookieDelete
Cookie.prototype.read  = CookieRead

function changeText()
{
	myCookie.text=prompt("Enter Text:","");
	myCookie.write();
	document.exf1.t1.value=myCookie.text;
}
