/*Delete Button Confirm Popup*/
function confirmDel()
{
	if(confirm('Are you sure want to delete ?'))
		return true;
	else
		return false;
}
/*Add-Member validation start from here*/
function $(id){
	return document.getElementById(id);
}
function validateFormOnSubmit(theForm){
	var reason = "";

	reason += validatename(theForm.name);
	reason += validateTitle(theForm.title);
	reason += validateOrganization(theForm.organizaton);
  reason += validatesaddress(theForm.saddress);
  reason += validatecaddress(theForm.caddress);
	reason += validatecity(theForm.city);
	reason += validatestate(theForm.state);
	reason += validatecountry(theForm.country);
	reason += validatephone(theForm.phone);
	reason += validatehphone(theForm.hphone);
	reason += validatefax(theForm.fax);
  reason += validateemail(theForm.email);
  reason += validatesample(theForm.sample);

	if (reason != ""){
		alert("Some fields need correction:\n" + reason);
		return false;
	}
	return true;
}
function validateEmpty(fld){
	var error = "";
	if(fld.value.length == 0){
		fld.style.background = 'White';
		error = "The requiWhite field has not been filled in.\n"
	}
	else{
		fld.style.background = 'White';
	}
	return error;
}
function validatename(fld){
	var error = "";
	var illegalChars = /[_0-9]/; // allow letters, numbers, and underscores
	if (fld.value == ""){
		fld.focus();
		fld.style.background = 'White';
		error = "You didn't enter a name.\n";
	}
	else if ((fld.value.length < 2) || (fld.value.length > 20)){
		fld.style.background = 'White';
		error = "The name is the wrong length.(min.3 And max.20)\n";
	}
	else if (illegalChars.test(fld.value)){
		fld.style.background = 'White';
		error = "The name contains illegal characters.\n";
	}
	else{
		document.form1.title.focus();
		fld.style.background = 'White';
	}
	return error;
}
function validateTitle(fld){
	var error = "";
	var illegalChars = /[_0-9]/; // allow letters, numbers, and underscores
	if (fld.value == ""){
		fld.style.background = 'White';
		error = "You didn't enter a title.\n";
	}
	else if ((fld.value.length < 2) || (fld.value.length > 20)){
		fld.style.background = 'White';
		error = "The title is the wrong length.(min.3 And max.20)\n";
	}
	else if (illegalChars.test(fld.value)){
		fld.style.background = 'White';
		error = "The title contains illegal characters.\n";
	}
	else{
		document.form1.organizaton.focus();
		fld.style.background = 'White';
	}
	return error;
}
function validateOrganization(fld){
	var error = "";
	var illegalChars = /[_0-9]/; // allow letters, numbers, and underscores
	if (fld.value == ""){
		fld.style.background = 'White';
		error = "You didn't enter a organization.\n";
	}
	else if ((fld.value.length < 2) || (fld.value.length > 20)){
		fld.style.background = 'White';
		error = "The organization is the wrong length.(min.3 And max.20)\n";
	}
	else if (illegalChars.test(fld.value)){
		fld.style.background = 'White';
		error = "The organization contains illegal characters.\n";
	}
	else{
		document.form1.saddress.focus();
		fld.style.background = 'White';
	}
	return error;
}
function validatesaddress(fld){
	var error = "";
	var illegalChars = /[W]/; // allow letters, numbers, and underscores
	
	if (fld.value == ""){
		fld.style.background = 'White';
		error = "You didn't enter a street address.\n";
	}
	else if ((fld.value.length < 3)){
		fld.style.background = 'White';
		error = "The street address is the wrong length.(min 3)\n";
	}
	else if (illegalChars.test(fld.value)){
		fld.style.background = 'White';
		error = "The street address contains illegal characters.\n";
	}
	else{
		document.form1.caddress.focus();
		fld.style.background = 'White';
	}
	return error;
}
function validatecaddress(fld){
	var error = "";
	var illegalChars = /[W]/; // allow letters, numbers, and underscores
	
	if (fld.value == ""){
		fld.style.background = 'White';
		error = "You didn't enter a address (Cont.).\n";
	}
	else if ((fld.value.length < 3)){
		fld.style.background = 'White';
		error = "The address (Cont.) is the wrong length.(min 3)\n";
	}
	else if (illegalChars.test(fld.value)){
		fld.style.background = 'White';
		error = "The address (Cont.) contains illegal characters.\n";
	}
	else{
		document.form1.city.focus();
		fld.style.background = 'White';
	}
	return error;
}
function validatecity(fld){
	var error = "";
	var illegalChars = /[_0-9]/; // allow letters only
	if (fld.value == ""){
		fld.style.background = 'White';
		error = "You didn't enter a city.\n";
	}
	else if ((fld.value.length < 2) || (fld.value.length > 20)){
		fld.style.background = 'White';
		error = "The city is the wrong length.(min.3)\n";
	}
	else if (illegalChars.test(fld.value)){
		fld.style.background = 'White';
		error = "The city contains illegal characters.\n";
	}
	else{
		document.form1.state.focus();
		fld.style.background = 'White';
	}
	return error;
}
function validatestate(fld){
	var error = "";
	var illegalChars = /[_0-9]/; // allow letters, numbers, and underscores
	if (fld.value == ""){
		fld.style.background = 'White';
		error = "You didn't enter a state.\n";
	}
	else if ((fld.value.length < 2) || (fld.value.length > 20)){
		fld.style.background = 'White';
		error = "The state is the wrong length.(min.3 And max.20)\n";
	}
	else if (illegalChars.test(fld.value)){
		fld.style.background = 'White';
		error = "The state contains illegal characters.\n";
	}
	else{
		document.form1.country.focus();
		fld.style.background = 'White';
	}
	return error;
}
function validatecountry(fld){
	var error = "";
	var illegalChars = /[_0-9]/; // allow letters, numbers, and underscores
	if (fld.value == ""){
		fld.style.background = 'White';
		error = "You didn't enter a country.\n";
	}
	else if ((fld.value.length < 2) || (fld.value.length > 20)){
		fld.style.background = 'White';
		error = "The country is the wrong length.(min.3 And max.20)\n";
	}
	else if (illegalChars.test(fld.value)){
		fld.style.background = 'White';
		error = "The country contains illegal characters.\n";
	}
	else{
		document.form1.phone.focus();
		fld.style.background = 'White';
	}
	return error;
}
function validatephone(fld) {
   	var error = "";
   	var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

	if (fld.value == "") {
       	error = "You didn't enter a phone number.\n";
       	fld.style.background = 'White';
   	}
   	else if (isNaN(parseInt(stripped))) {
       	error = "The phone number contains illegal characters.\n";
       	fld.style.background = 'White';
   	}
   	else if (!(stripped.length > 9 )){
       	error = "The phone number is the wrong length. Make sure you included an area code.\n";
       	fld.style.background = 'White';
   	}
   	else if (!(stripped.length < 16 )){
       	error = "The phone number is the wrong length.\n";
       	fld.style.background = 'White';
   	}
   	else{
		document.form1.hphone.focus();
   		fld.style.background = 'White';
	}
   	return error;
}
function validatehphone(fld) {
   	var error = "";
   	var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

	if (fld.value == "") {
       	error = "You didn't enter a home phone number.\n";
       	fld.style.background = 'White';
   	}
   	else if (isNaN(parseInt(stripped))) {
       	error = "The home phone number contains illegal characters.\n";
       	fld.style.background = 'White';
   	}
   	else if (!(stripped.length > 9 )){
       	error = "The home phone number is the wrong length. Make sure you included an area code.\n";
       	fld.style.background = 'White';
   	}
   	else if (!(stripped.length < 16 )){
       	error = "The home phone number is the wrong length.\n";
       	fld.style.background = 'White';
   	}
   	else{
		document.form1.fax.focus();
   		fld.style.background = 'White';
	}
   	return error;
}
function validatefax(fld) {
   	var error = "";
   	var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

	if (fld.value == "") {
       	error = "You didn't enter a fax number.\n";
       	fld.style.background = 'White';
   	}
   	else if (isNaN(parseInt(stripped))) {
       	error = "The fax number contains illegal characters.\n";
       	fld.style.background = 'White';
   	}
   	else if (!(stripped.length > 9 )){
       	error = "The fax number is the wrong length. Make sure you included an area code.\n";
       	fld.style.background = 'White';
   	}
   	else if (!(stripped.length < 16 )){
       	error = "The fax number is the wrong length.\n";
       	fld.style.background = 'White';
   	}
   	else{
		document.form1.email.focus();
   		fld.style.background = 'White';
	}
   	return error;
}

function trim(s){
	return s.replace(/^\s+|\s+$/, '');
}
function validateemail(fld) {
   	var error="";
   	var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
   	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
   	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

	if (fld.value == "") {
       	fld.style.background = 'White';
       	error = "You didn't enter a email address.\n";
   	}
   	else if (!emailFilter.test(tfld)) {              //test email for illegal characters
       	fld.style.background = 'White';
       	error = "Please enter a valid email address.\n";
   	}
   	else if (fld.value.match(illegalChars)) {
       	fld.style.background = 'White';
       	error = "The email address contains illegal characters.\n";
   	}
   	else {
   		document.form1.sample.focus();
       	fld.style.background = 'White';
   	}
   	return error;
}
function validatesample(fld){
	var error = "";
	var illegalChars = /[W]/; // allow letters, numbers, and underscores
	
	if (fld.value == ""){
		fld.style.background = 'White';
		error = "You didn't enter a sample.\n";
	}
	else if ((fld.value.length < 3)){
		fld.style.background = 'White';
		error = "The sample is the wrong length.(min 3)\n";
	}
	else if (illegalChars.test(fld.value)){
		fld.style.background = 'White';
		error = "The sample contains illegal characters.\n";
	}
	else{
		fld.style.background = 'White';
	}
	return error;
}
function numbersonly(myfield, e, dec){
	var key;
	var keychar;

	if (window.event)
	key = window.event.keyCode;
	else if (e)
	 key = e.which;
	else
	 return true;
	keychar = String.fromCharCode(key);

	if ((key==null) || (key==0) || (key==8) || 
   	(key==9) || (key==13) || (key==27) )
	return true;

	else if ((("0123456789").indexOf(keychar) > -1))
	return true;

	else if (dec && (keychar == ".")){
		myfield.form.elements[dec].focus();
		return false;
	}
	else
	return false;
}
/*Add-Member Validatio end here */



