// ********************* VAlidation for Members *************************

//function to validate by length
function ValidLength(item, len) {
   return (item.length >= len);
 
 }
 
//function to check the name fields contain only string
function isString(checkStr) {
var checkOK="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/,*.- ()&";
var OK = true;

for(i=0;i<checkStr.length;i++){
	ch=checkStr.charAt(i);
	for(j=0;j<checkOK.length;j++){
		if(OK=(ch==checkOK.charAt(j))) break;
		
	}
	
	if(!OK)			
		break;
		
}
return OK;
}



//function to check the phone fields contains only digit
function isPhoneDigit(checkStr) {
var checkOK="0123456789+-/";
var OK = true;

for(i=0;i<checkStr.length;i++){
	ch=checkStr.charAt(i);
	for(j=0;j<checkOK.length;j++){
		if(OK=(ch==checkOK.charAt(j))) break;
		
	}
	
	if(!OK)			
		break;
		
}
return OK;
}


//function to validate an email address
function ValidEmail(item) {

var dotPosition;
var atPosition;
var afterDotPos;
var blankPosition;

blankPosition = item.indexOf(' ', 0);
atPosition = item.indexOf('@',1);
dotPosition = item.indexOf('.',atPosition+2);
afterDotPos = dotPosition+1;

   if(blankPosition !=-1 ) return false;
   if (!ValidLength(item, 5)) return false;
   if (atPosition == -1 || dotPosition == -1) 	 return false;
   if (item.length <= afterDotPos)	return false;
   return true;
}


// display an error alert
function error(item, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   item.select();
   item.focus();
   errfound = true;
}

var lengthOK=true;


// main validation function
function Validate() {
   errfound = false;
   
 
   // Validation for Organization 
   if (!ValidLength(document.frmMember.org.value,3))
      error(document.frmMember.org, "Organization Name should be at least 3 characters long");
   else lengthOK=true;
	if(lengthOK){
		if(!isString(document.frmMember.org.value)){
			error(document.frmMember.org, "Please enter only string characters")
			lengthOK=false;
		}
      	}

// Validation for phone 
   if (!ValidLength(document.frmMember.phone.value,7))
      	error(document.frmMember.org, "Phone number should be at least 7 characters long");
   else 
	lengthOK=true;
   if(lengthOK){
		if(!isPhoneDigit(document.frmMember.phone.value)){
			error(document.frmMember.phone, "Please enter only digit,+,/,- characters")
			lengthOK=false;
		}
   }


	// Validation for Email
	if(!ValidEmail(document.frmMember.email.value))
		error(document.frmMember.email, "E-Mail address is not in valid form")
	
	// Validation for Password 
    if (!ValidLength(document.frmMember.pass.value  ,4))
      error(document.frmMember.pass,"Password must be 4 characters long");   
      
// ********************************************************************** 

// true if there are no errors /
   return !errfound; 
}
// **********************************************************************

