// this page is used by all the files for validation

// array of questions to select for forgotten password
	
var ques = new Array();

	ques[0] = "My mother's maiden name?";
  
	ques[1] = "My favourite place?";
  
      ques[2] = "My pet's name?";
  
	ques[3] = "My favourite superhero?";

function isEmpty( strg){

	var chars = strg.split("");
	for (var i = 0; i < chars.length; i++) {
		if ((chars[i] != " " && chars[i] != "\n") && (chars[i] != "\t" && chars[i] != "\r")) {
      		return false;
		}
	}
	return true;
}

function strtrim( str) {
	var sl = ""+str.length;
	var i;
	for (i = 0; i < sl; i++) {
		if (str.charAt(i) != ' ' &&
			str.charAt(i) != '\t' &&
			str.charAt(i) != '\n') {
			break;
		}
	}
	start = i;

	for (i = sl-1; i > 0; i--) {
		if (str.charAt(i) != ' ' &&
			str.charAt(i) != '\t' &&
			str.charAt(i) != '\n') {
			break;
		}
	}
	return str.substring(start, i+1);
}


// to check whether it is empty or contains invalid chars

function chkPlainTxt( txt) {
	txt = strtrim(txt);
	if (isEmpty(txt)) {
		return false;
	}
	for (i = 0; i < txt.length; i++) {
		c = txt.charAt(i);
		if (((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c == '-' || c == '.' || c == ' ' || c == "'" || c == '&') == false) {
			return false;
		}
	}
	return true;
}

// to check the Email 

function isBadEmail( txt) {
	email_array = txt.split('@');
	if (email_array.length != 2) return true;
	if (email_array[1].split(".").length < 2) return true;
	if (email_array[1].split(".")[1].length < 1) return true;
	if (txt.indexOf('@') < 1) return true;
	if (txt.indexOf(' ') != -1) return true;
	if (email_array[1].indexOf('.') < 1) return true;
	if (txt.length < 5) return true;
	return false;
}


// to check whether the radio object is selected

function isRadioSelected( radioObject){
	
	for (var i = 0; i< radioObject.length; i++){
		if (radioObject[i].checked)   
			return true; 
	}
	return false;
}

// to check whether the radio object is selected

function isComboSelected( comboObject){
	
	if (comboObject.selectedIndex != 0) 
		return true;
	return false;
}

// to check whether it is empty or contains nonalphanumeric chars

function isAlphanumeric( txt) {
	txt = strtrim(txt);
	for (i = 0; i < txt.length; i++) {
		c = txt.charAt(i);
		if (((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ) == false) {
			return false;
		}
	}
	return true;
}


function containsMinchar( txt, min_length) {
	// Make sure it's at least min_length characters...
	txt = strtrim(txt);
	if (isEmpty(txt)) {
		return false;
	}
	if ( txt.length < parseInt(min_length)) return false;
	return true;
}



