// JavaScript Document
// Counting Alpha for the Text Fields
function checkChars(fieldObj, maxLength, errorId){
	
	//This function writes how many characters the user has left in the message div.
	
	var messageBox = fieldObj;
	var messageLength = messageBox.value.length;
	var lengthRemaining = maxLength - messageLength;
		if (document.getElementById) {
		if(lengthRemaining >1 || lengthRemaining == 0){
			msgText ="<strong>"+ lengthRemaining + "</strong> characters remaining"
		} else if(lengthRemaining == 1){
			msgText = "<strong>"+ lengthRemaining + "</strong> character remaining"
		} else {
			//This stops the user entering any more chars when they reach the maxLength
			messageBox.value = messageBox.value.substring(0, maxLength);
		}
		//Write error message to message div.
		document.getElementById(errorId).innerHTML = msgText;
	}
}
//-----------------------------------------------------------------------------------------------
//Chk the White space in the Text Fields.
function isWhitespace(s)
{
   var i;
   for (i = 0; i < s.length; i++)
   {
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if(c!=" ")
		return false;
   }
   // All characters are whitespace.
   return true;
}
//-----------------------------------------------------------------------------------------------
function LoginValidation(myform){

	if((myform.LoginID.value == "") || (myform.LoginID.value == "Login ID")){
		alert("Please enter 'Login ID'.");
		myform.LoginID.focus();		
		return false;}
	else{
		if(isWhitespace(myform.LoginID.value)){
			alert("'Login ID' cannot contain only spaces.");
			myform.LoginID.focus();
			return false;}
		}	

	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	for (var i = 0; i < myform.LoginID.value.length; i++) {
  		if (iChars.indexOf(myform.LoginID.value.charAt(i)) != -1) {
  		alert ("'Login ID' has special characters. \nThese are not allowed.\n Please remove them and try again.");
		myform.LoginID.focus();
  		return false;
  		}
 	 } 
	
	if((myform.Pass.value == "") || (myform.Pass.value == "Password") ){
		alert("Please enter 'Password'.");
		myform.Pass.focus();		
		return false;}
	else{
		if(isWhitespace(myform.Pass.value)){
			alert("'Password' cannot contain only spaces.");
			myform.Pass.focus();
			return false;}
		}	
	
	
	return true;
}
//-----------------------------------------------------------------------------------------------
function ForgotPassword(){
	window.open('ForgotPassword.asp','ForgotPassword','width=550,height=325,top=20px,left=20px');
}
//-----------------------------------------------------------------------------------------------
function ShowCompleteNotice(NBID){
	window.open('NoticBoardPopup.asp?NBID='+NBID+'','NoticeBoard','scrollbars=yes, width=570, height=550, top=20px, left=20px');		
}
//-----------------------------------------------------------------------------------------------
function SearchresetVal(myform){
	myform.value = "";
	myform.focus();
}	
//---------------------------------------------------------------
function SearchValidation(myform){
	
	if ((myform.SKeywords.value=="Key Word" || myform.SKeywords.value=="") ){
		alert("Please enter any Key Work for Search.");
		return false;
	}

	return true;
}
//-----------------------------------------------------------------------------------------------
function Validation_Newsletter(myform){

	if(myform.MName.value == ""){
		alert("Please enter 'Name'.");
		myform.MName.focus();		
		return false;}
	else{
		if(isWhitespace(myform.MName.value)){
			alert("'Name' cannot contain only spaces.");
			myform.MName.focus();
			return false;}
		}	

	var EmailID = myform.EmailID.value;
	if (EmailID==""){
	alert ("Please enter E-mail Address.");
	myform.EmailID.focus();
	return false;}
	if (EmailID.length >0) {
	 i=EmailID.indexOf("@")
	 j=EmailID.indexOf(".",i)
	 k=EmailID.indexOf(",")
	 kk=EmailID.indexOf(" ")
	 jj=EmailID.lastIndexOf(".")+1
	 len=EmailID.length
 	if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
 	}
 	else {
 		alert("Please enter an exact email address.\n'" +
		EmailID+ "' is invalid.");
		myform.EmailID.focus();
		return false;
 		}
	 }

	return true;
}
function Unsubscribe(){
	var GoToAction="0";
	
	var EmailID = document.NewsletterSignup.EmailID.value;
	if (EmailID==""){
		alert ("Please enter E-mail Address.");
		document.NewsletterSignup.EmailID.focus();
		GoToAction="1";
		//return false;
	}
	if (EmailID.length >0) {
	 i=EmailID.indexOf("@")
	 j=EmailID.indexOf(".",i)
	 k=EmailID.indexOf(",")
	 kk=EmailID.indexOf(" ")
	 jj=EmailID.lastIndexOf(".")+1
	 len=EmailID.length
 	if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
 	}
 	else {
 		alert("Please enter an exact email address.\n'" +
		EmailID+ "' is invalid.");
		document.NewsletterSignup.EmailID.focus();
		//return false;
		GoToAction="1";
 		}
	 }

	if(GoToAction=="0"){
		document.NewsletterSignup.action="Newsletter_Unsubscribe_DB.asp";
		document.NewsletterSignup.submit();
	}
}
//-----------------------------------------------------------------------------------------------
function Validation_DirectoryReport(myform){

	if(myform.MName.value == ""){
		alert("Please enter 'Name'.");
		myform.MName.focus();		
		return false;}
	else{
		if(isWhitespace(myform.MName.value)){
			alert("'Name' cannot contain only spaces.");
			myform.MName.focus();
			return false;}
		}	

	var EmailID = myform.EmailID.value;
	if (EmailID==""){
	alert ("Please enter E-mail Address.");
	myform.EmailID.focus();
	return false;}
	if (EmailID.length >0) {
	 i=EmailID.indexOf("@")
	 j=EmailID.indexOf(".",i)
	 k=EmailID.indexOf(",")
	 kk=EmailID.indexOf(" ")
	 jj=EmailID.lastIndexOf(".")+1
	 len=EmailID.length
 	if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
 	}
 	else {
 		alert("Please enter an exact email address.\n'" +
		EmailID+ "' is invalid.");
		myform.EmailID.focus();
		return false;
 		}
	 }

	return true;
}
//-----------------------------------------------------------------------------------------------