function CheckNumber(FieldName, FieldValue) {
	if (isNaN(FieldValue) || FieldValue=="") {
		alert("Not a valid number! Please try again.");
		FieldName.select();
		FieldName.focus();
		return false;
	}
	return true;
}

function CheckPath(FieldName, FieldValue) {
	if (FieldValue.indexOf('#')>=0 || FieldValue.indexOf('%')>=0 ||
		FieldValue.indexOf('&')>=0 || FieldValue.indexOf('*')>=0 ||
		FieldValue.indexOf('|')>=0 || FieldValue.indexOf('"')>=0 ||
		FieldValue.indexOf('<')>=0 ||	FieldValue.indexOf('>')>=0 ||
		FieldValue.indexOf('?')>=0 ||	FieldValue.indexOf('/')>=0) {
		alert('Not a valid path!\n\nPath names cannot contain the characters: #%&*|:"<>?/');
		FieldName.select();
		FieldName.focus();
		return false;
	}
	return true;
}

function CheckDrive(FieldName, FieldValue) {
	var Ch;
	
	Ch=FieldValue.substring(0,1);
	if (FieldValue.length>2 || FieldValue.length==2 && FieldValue.substring(1,2)!=':' ||
		!(Ch>='a' && Ch<='z' || Ch>='A' && Ch<='Z')) {
		alert('Not a valid drive!\n\nDrive should consist of a letter followed by a colon.');
		FieldName.select();
		FieldName.focus();
		return false;
	}
	if (FieldValue.length==1)
		FieldName.value=FieldName.value+':';
	return true;
}

function CheckFile(FieldName, FieldValue, AllowWildcards) {
	if (FieldValue.indexOf('#')>=0 || FieldValue.indexOf('%')>=0 ||
		FieldValue.indexOf('&')>=0 || FieldValue.indexOf('\\')>=0 ||
		FieldValue.indexOf('|')>=0 || FieldValue.indexOf(':')>=0 ||
		FieldValue.indexOf('"')>=0 || FieldValue.indexOf('<')>=0 ||
		FieldValue.indexOf('>')>=0 || FieldValue.indexOf('/')>=0 ||
		(FieldValue.indexOf('*')>=0 || FieldValue.indexOf('?')>=0) && !AllowWildcards) {

		if (AllowWildcards)
			alert('Not a valid path!\n\nPath names cannot contain the characters: #%&|:"<>/\\');
		else
			alert('Not a valid path!\n\nPath names cannot contain the characters: #%&|:"<>/\\?*');
		FieldName.select();
		FieldName.focus();
		return false;
	}
	return true;
}

function CheckTime(FieldName, FieldValue) {
	var MatchArray;
	var Hour,Minute,Second,AmPm;
	
	MatchArray=FieldValue.match(/^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/);
	if (MatchArray==undefined) {
		alert('Not a valid time!\n\nTime must be in the format hh:mm:ss.');
		FieldName.select();
		FieldName.focus();
		return false;
	}

	Hour=MatchArray[1];
	Minute=MatchArray[2];
	Second=MatchArray[4];
	AmPm=MatchArray[6];

	if (AmPm!=undefined && (Hour<1 || Hour>12)) {
		alert('Not a valid time!\n\nHour must be between 1 and 12.');
		FieldName.select();
		FieldName.focus();
		return false;
	} else if (Hour<0 || Hour>23) {
		alert('Not a valid time!\n\nHour must be between 0 and 23.');
		FieldName.select();
		FieldName.focus();
		return false;
	} else if (Minute<0 || Minute>59) {
		alert('Not a valid time!\n\nMinute must be between 0 and 59.');
		FieldName.select();
		FieldName.focus();
		return false;
	} else if (Second<0 || Second>59) {
		alert('Not a valid time!\n\nSecond must be between 0 and 59.');
		FieldName.select();
		FieldName.focus();
		return false;
	}

	if (AmPm!=undefined && AmPm.toUpperCase()=='PM' && Second==undefined) {
		if (Hour==12)
			FieldName.value='12:'+Minute+':00';
		else
			FieldName.value=(parseInt(Hour)+12)+':'+Minute+':00';

	} else if (AmPm!=undefined && Second==undefined) {
		if (Hour==12)
			FieldName.value='00:'+Minute+':00';
		else
			FieldName.value=Hour+':'+Minute+':00';

	} else if (Second==undefined) {
		FieldName.value=Hour+':'+Minute+':00';

	} else if (AmPm!=undefined && AmPm.toUpperCase()=='PM') {
		if (Hour==12)
			FieldName.value='12:'+Minute+':'+Second;
		else
			FieldName.value=(parseInt(Hour)+12)+':'+Minute+':'+Second;

	} else if (AmPm!=undefined) {
		if (Hour==12)
			FieldName.value='00:'+Minute+':'+Second;
		else
			FieldName.value=Hour+':'+Minute+':'+Second;

	} else
		FieldName.value=Hour+':'+Minute+':'+Second;
	return true;
}

function CheckDelay(FieldName, FieldValue) {
	var MatchArray;
	var Hour,Minute;

	MatchArray=FieldValue.match(/^(\d{1,4}):(\d{2})?$/);
	if (MatchArray==undefined) {
		alert('Not a valid delay!\n\nDelay must be in the format hh:mm.');
		FieldName.select();
		FieldName.focus();
		return false;
	}

	Hour=MatchArray[1];
	Minute=MatchArray[2];

	if (Hour<0) {
		alert('Not a valid delay!\n\nHour must be between 0 and 9999.');
		FieldName.select();
		FieldName.focus();
		return false;
	} else if (Minute<0 || Minute>59) {
		alert('Not a valid delay!\n\nMinute must be between 0 and 59.');
		FieldName.select();
		FieldName.focus();
		return false;
	}

	FieldName.value=Hour+':'+Minute;
	return true;
}

function CheckPassword(Passwd) {
	var Description;
	var Score,Verdict;
	
	Description=new Array();
	Description[0]="<img src='images/weakest.gif' alt='Weakest' width='50' height='12'>&nbsp;&nbsp;Weakest";
	Description[1]="<img src='images/weak.gif' alt='Weak' width='50' height='12'>&nbsp;&nbsp;Weak";
	Description[2]="<img src='images/better.gif' alt='Better' width='50' height='12'>&nbsp;&nbsp;Better";
	Description[3]="<img src='images/strong.gif' alt='Strong' width='50' height='12'>&nbsp;&nbsp;Strong";
	Description[4]="<img src='images/strongest.gif' alt='Strongest' width='50' height='12'>&nbsp;&nbsp;Strongest";
	Description[5]="<img src='images/nopassword.gif' alt='No Password!' width='50' height='12'>&nbsp;&nbsp;No Password!";

	Score=Verdict=0;
	if (Passwd.length==0 || !Passwd.length)
		Score=-1;
	else if (Passwd.length>0 && Passwd.length<5)
		Score+=3;
	else if (Passwd.length>4 && Passwd.length<8)
		Score+=6;
	else if (Passwd.length>7 && Passwd.length<12)
		Score+=12;
	else if (Passwd.length>11)
		Score+=18;
		
	if (Passwd.match(/[a-z]/))
		Score+=1;
	if (Passwd.match(/[A-Z]/))
		Score+=5;
	if (Passwd.match(/\d+/))
		Score+=5;
	if (Passwd.match(/(.*[0-9].*[0-9].*[0-9])/))
		Score+=5;
	if (Passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))
		Score+=5;
	if (Passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		Score+=5;
	
	if (Passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))
		Score+=2;
	if (Passwd.match(/(\d.*\D)|(\D.*\d)/))
		Score+=2;
	if (Passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		Score+=2;
	
	if (Score==-1)
		Verdict=Description[5];
	else if (Score<16)
		Verdict=Description[0];
	else if (Score<25)
		Verdict=Description[1];
	else if (Score<35)
		Verdict=Description[2];
	else if (Score<45)
		Verdict=Description[3];
	else
		Verdict=Description[4];
	
	document.getElementById("PasswordStrength").innerHTML=(Verdict);
}