var	numb = "0123456789";
var	lwr = "abcdefghijklmnopqrstuvwxyz";
var	upr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var oth = "~`!@#$%^&*()_+-={[}]|\\:\";'<,>.?/ ";

function IsNumeric(sText){
		var ValidChars = "0123456789.";
		var IsNumber=true;
		var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++) { 
			  Char = sText.charAt(i); 
			  if (ValidChars.indexOf(Char) == -1) {
					IsNumber = false;
			  }
		}
		return IsNumber;
}
function IsValidMail(x){
		//var x = document.forms[0].email.value;
		var isMail=true;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) isMail = true;
		else isMail = false;

		return isMail;
}
function enableLogin(x){
		var radio_choice = -1;
		for (var i=0; i< document.login.type.length; i++) {
			if (document.login.type[i].checked) radio_choice = document.login.type[i].value; 
		}
		if (x == "0"){
				if (radio_choice == 0){
						document.login.username.disabled=true;
						document.login.password.disabled=true;
				}else{
						document.login.username.disabled=false;
						document.login.password.disabled=false;
				}
		}
}
function checkRegistration(id){
		if (document.signup.companyname.value.length <= 0){
				alert('The company name is required. Please enter your company name');
				document.signup.companyname.focus();
				return false;
		}else if (document.signup.contact.value.length <= 0){
				alert('The company contact person is required. Please enter a person name');
				document.signup.contact.focus();
				return false;
		}else if (document.signup.passwd.value.length <= 0 && id == 0){
				alert('The password is blank. Please enter a password with at least 8 characters length');
				document.signup.passwd.focus();
				return false;
		}else if (document.signup.passwd1.value.length <= 0 && id == 0){
				alert('The confirm password is blank. Please confirm your new password');
				document.signup.passwd1.focus();
				return false;
		}else if (id == 0 && document.signup.passwd.value != document.signup.passwd1.value){
				alert('The new and confirm passwords are not the same. Please enter the same password as your new password');
				document.signup.passwd1.focus();
				return false;
		}else if (document.signup.telephone.value.length <= 0){
				alert('The contact telephone number is required. Please enter a telephone number');
				document.signup.telephone.focus();
				return false;
		}else if (document.signup.email.value.length <= 0){
				alert('The contact e-mail address is required. Please enter an e-mail address');
				document.signup.email.focus();
				return false;
		}else if (IsValidMail(document.signup.email.value) == false){
				alert('The e-maill address is invalid. Please enter a correct format of e-mail address');
				document.signup.email.focus();
				return false;
		}
		return true;
}
function checkNews(){
		if (document.news.author.value.length <= 0){
				alert('The author is required. Please enter author name');
				document.news.author.focus();
				return false;
		}else if (document.news.headline.value.length <= 0){
				alert('The headline for the announcement is required. Please enter a headline');
				document.news.headline.focus();
				return false;
		}

		return true;
}
function checkAll(id){
	var f = document.forms[id];
	for (var i=0; i< f.elements.length; i++) {
		f.elements[i].checked = true;
	}
}
function uncheckAll(id){
	var f = document.forms[id];
	for (var i=0; i< f.elements.length; i++) {
		f.elements[i].checked = false;
	}
}
function selectedForm(category) {
	var f = document.forms[0];
	for (var i=1; i< f.elements.length; i++) {
		if ( (f.elements[i].type == "checkbox") && (f.elements[i].checked == true) )
			return confirm('This will delete all information related to selected '+category+' from the database!\nContinue?');
	}
	alert("No boxes have been checked!");	
	return false;
}
function checkUser(){
		if (document.user.firstname.value.length <= 0){
				alert('The first name is required. Please enter admin first name');
				document.user.firstname.focus();
				return false;
		}else if (document.user.lastname.value.length <= 0){
				alert('The last name is required. Please enter admin last name');
				document.user.lastname.focus();
				return false;
		}else if (document.user.email.value.length <= 0){
				alert('The e-mail address is required. Please enter an e-mail address');
				document.user.email.focus();
				return false;
		}else if (IsValidMail(document.user.email.value) == false){
				alert('The e-maill address is invalid. Please enter a correct format of e-mail address');
				document.user.email.focus();
				return false;
		}
		return true;
}
function checkSchedule(){
		if (document.Schedule.title.value.length <= 0){
				alert('The title is required. Please enter the schedule title');
				document.Schedule.title.focus();
				return false;
		}else if (document.Schedule.eventstart.value.length <= 0){
				alert('The begining date for schedule is required. Please enter a beginning date');
				document.Schedule.eventstart.focus();
				return false;
		}else if (document.Schedule.eventexpiration.value.length <= 0){
				alert('The ending date for schedule is required. Please enter an ending date');
				document.Schedule.eventexpiration.focus();
				return false;
		}
		return true;
}
function checkEvent(){
		if (document.Event.cdate.value.length <= 0){
				alert('The event date is required. Please enter the event date');
				document.Event.cdate.focus();
				return false;
		}else if (document.Event.time.value.length <= 0){
				alert('The event time is required. Please enter the event time');
				document.Event.time.focus();
				return false;
		}else if (document.Event.location.value.length <= 0){
				alert('The event location is required. Please enter the event location');
				document.Event.location.focus();
				return false;
		}
		return true;
}
function checkOptions(){
		if (document.Registration.option_id.value.length <= 0){
				alert('The option number is required. Please enter the option number');
				document.Registration.option_id.focus();
				return false;
		}else if (document.Registration.options.value.length <= 0){
				alert('The registration option title is required. Please enter the registration option title');
				document.Registration.options.focus();
				return false;
		}else if (document.Registration.fee.value.length <= 0){
				alert('The registration fee is required. Please enter the registration fee');
				document.Registration.fee.focus();
				return false;
		}else if (document.Registration.number.value.length <= 0){
				alert('The number of seats is required. Please enter the number of seat available for this option');
				document.Registration.number.focus();
				return false;
		}
		return true;
}
function checkMessages(){
		if (document.Registration.option_id.value.length <= 0){
				alert('The option number is required. Please enter the option number');
				document.Registration.option_id.focus();
				return false;
		}else if (document.Registration.options.value.length <= 0){
				alert('The registration option title is required. Please enter the registration option title');
				document.Registration.options.focus();
				return false;
		}else if (document.Registration.number.value.length <= 0){
				alert('The number of seats is required. Please enter the number of seat available for this option');
				document.Registration.number.focus();
				return false;
		}
		return true;
}
function checkTransaction(){
		if (document.creditcard.transaction.value.length <= 0){
				alert('The transaction number is required. Please enter the trasaction number');
				document.creditcard.transaction.focus();
				return false;
		}

		return true;
}
//--------------------------------------------------------------Password Reset------------------------------------------------------------------------------------
function  BX_(x){ return ((x) - (((x)>>1)&0x77777777) - (((x)>>2)&0x33333333) - (((x)>>3)&0x11111111)); }
function BITCOUNT(x){ return  (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255); }
function haschar(parm,val) {
	if (parm == "") return false;
	for (i=0; i<parm.length; i++) {
		if (val.indexOf(parm.charAt(i),0) != -1) return true;
	}
	return false;
}
function ischars(parm,val) {
	if (parm == "") return false;
	for (i=0; i < parm.length; i++) {
		if( bal.indexOf(parm.charAt(i),0) == -1) return false;
	}
	return true;
}
function hasNum(parm) {return haschar(parm,numb);}
function hasLower(parm) {return haschar(parm,lwr);}
function hasUpper(parm) {return haschar(parm,upr);}
function hasAlpha(parm) {return haschar(parm,lwr+upr);}
function hasOther(parm) {return haschar(parm,oth);}
function hasAlphanum(parm) {return haschar(parm,lwr+upr+numb);}
function isNum(parm) {return ischars(parm,numb);}
function isLower(parm) {return ischars(parm,lwr);}
function isUpper(parm) {return ischars(parm,upr);}
function isAlpha(parm) {return ischars(parm,lwr+upr);}
function isOther(parm) {return ischars(parm,oth);}
function isAlphanum(parm) {return ischars(parm,lwr+upr+numb);}
function classcount(c) {
	has = 0;
	if(hasLower(c)){
		has = has | 0x1;
	} 
	if(hasUpper(c)){
		has = has | 0x2;
	} 
	if(hasNum(c)){
		has = has | 0x4;
	} 
	if(hasOther(c)){
		has = has | 0x8;
	}

	return BITCOUNT(has);
}
function highlight(c) {
	document.getElementById("lcase").style.color = "red";
	document.getElementById("ucase").style.color = "red";
	document.getElementById("num").style.color = "red";
	document.getElementById("special").style.color = "red";
	if(hasLower(c)){
		document.getElementById("lcase").style.color = "green";
	} 
	if(hasUpper(c)){
		document.getElementById("ucase").style.color = "green";
	} 
	if(hasNum(c)){
		document.getElementById("num").style.color = "green";
	} 
	if(hasOther(c)){
		document.getElementById("special").style.color = "green";
	}
}	
function mkpass(val){
	var charlist = new Array(5);
	val.value = "";
	charlist[0]="abcdefghijkmnopqrstuvwxyz";
	charlist[1]="23456789";
	charlist[2]=";[],./-=\\";
	charlist[3]="ABCDEFGHJKLMNPQRSTUVWXYZ";
	charlist[4]="~!@#$%^&*()_+<>?:\"{}";
	while(classcount(val.value) < 3 || val.value.length < 8){
		n = Math.floor(Math.random()*100);
		if(n < 50) { n = 0; }
		else if(n < 70){ n = 1; }
		else if(n < 85){ n = 2; }
		else if(n < 95){ n = 3; }
		else { n = 4; }
		c = Math.floor(Math.random()*charlist[n].length);
		if(val.value.length == 8){
			val.value = charlist[n][c];
		} else {
			val.value += charlist[n].substr(c,1);
		}
	}
}
function checkPassword() {
	if(document.PwdReset.newpass.value.length <= 0) {
		alert("Please enter your new password");
		document.PwdReset.newpass.focus();
		return false;
	}else if(document.PwdReset.confirm.value.length <= 0) {
		alert("Please enter your current password");
		document.PwdReset.confirm.focus();
		return false;
	}else if(document.PwdReset.secCode.value.length <= 0) {
		alert("Please enter a security code");
		document.PwdReset.secCode.focus();
		return false;
	}else if (document.PwdReset.newpass.value != document.PwdReset.confirm.value) {
		alert("Your new passwords do not match");
		document.PwdReset.confirm.focus();
		return false;
	}else if(document.PwdReset.newpass.value.length < 8){
		alert("Your new password is too short");
		document.PwdReset.newpass.focus();
		return false;
	} else if(classcount(document.PwdReset.newpass.value) == 1) {
		highlight(document.PwdReset.newpass.value);
		alert("Password does not meet the listed requirements. Please include at least 2 more character types.");
		document.PwdReset.newpass.focus();
		return false;
	} else if(classcount(document.PwdReset.newpass.value) == 2) {
		highlight(document.PwdReset.newpass.value);
		alert("Password does not meet the listed requirements. Please include at least 1 more character types.");
		document.PwdReset.newpass.focus();
		return false;
	}

	return true;
}