// 1st parameter field name.
// 2nd parameter error message.
// 3rd parameter minimum length.
// 4th parameter maximum length.
// 5th parameter required or not.
function authentication(fldname,msg,minlength,maxlength,required){
	str = fldname.value;
	if(required == "Y"){
		if(str.length == 0){
			alert("please enter "+msg+".");
			fldname.focus();
			return false;
		}
	}

	if(str.length > 0){
		if(str.length < minlength){
			alert(msg+" required minimum "+minlength+" characters.");
			fldname.focus();
			return false;
		}

		if(str.length > maxlength){
			alert(msg+" allowed maximum "+maxlength+" characters.");
			fldname.focus();
			return false;
		}

		if(str.indexOf(' ') >= 0){
			alert("please enter "+msg+" without any space.");
			fldname.focus();
			fldname.value = '';
			return false;
		}
	}
	return true;
}

// 1st parameter first field name.
// 2nd parameter second field name.
// 3rd parameter message.
function recheckpassword(fldname1,fldname2,msg){
	str1 = fldname1.value;
	str2 = fldname2.value;
	if(str1.length != str2.length){
		alert(msg+" are not same.");
		fldname1.focus();
		return false;
	}

	for(i=0;i<str1.length;i++){
		if(str1.charCodeAt(i) != str2.charCodeAt(i)){
			alert(msg+" are not same.");
			fldname2.focus();
			return false;
		}
	}
	return true;
}

// 1st parameter field name.
// 2nd parameter error message.
// 3rd parameter minimum length.
// 4th parameter maximum length.
// 5th parameter required or not.
function string_value(fldname,msg,minlength,maxlength,required){
	str = fldname.value;
	if(required == 'Y'){
		if(str.length == 0){
			alert("please enter "+msg+".");
			fldname.focus();
			return false;
		}
	}

	if(str.length < minlength){
		alert(msg+" required minimum "+minlength+" characters.");
		fldname.focus();
		return false;
	}

	if(str.length > maxlength){
		alert(msg+" allowed maximum "+maxlength+" characters.");
		fldname.focus();
		return false;
	}

	if(str.length > 0){
		/* to check whether any character exists or not*/
		flag = 0;
		for(i=0;i<str.length;i++){
			if(str.charAt(i) != " "){
				flag = 1;
				break;
			}
		}

		if(flag == 0){
			alert("please enter "+msg+".");
			fldname.focus();
			fldname.value = '';
			return false;
		}
	}
	return true;
}

// 1st parameter field name.
// 2nd parameter error message.
// 3rd parameter minimum length.
// 4th parameter maximum length.
// 5th parameter required or not.
function phone_fax(fldname,msg,minlength,maxlength,required){
	indx = "0123456789-[]()";
	str = fldname.value;

	if(required == 'Y'){
		if(str.length == 0){
			alert("please enter "+msg+".");
			fldname.focus();
			return false;
		}
	}

	if(str.length > maxlength){
		alert(msg+" allowed maximum "+maxlength+" characters.");
		fldname.focus();
		return false;
	}

	if(str.length > 0){
		for(i=0;i<str.length;i++){
			if(indx.indexOf(str.charAt(i)) < 0){
				alert("invalid "+msg+".");
				fldname.focus();
				fldname.value = "";
				return false;
			}
		}
	}
	return true;
}

// 1st parameter field name.
// 2nd parameter error message.
// 3rd parameter minimum length.
// 4th parameter maximum length.
// 5th parameter required or not.
function email(fldname,msg,minlength,maxlength,required){
	indx = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-@.";
	str = fldname.value;

	if(required == 'Y'){
		if(str.length == 0){
			alert("please enter "+msg+".");
			fldname.focus();
			return false;
		}
	}

	if(str.length > maxlength){
		alert(msg+" allowed maximum "+maxlength+" characters.");
		fldname.focus();
		return false;
	}

	if(str.length > 0){
		for(i=0;i<str.length;i++){
			if(indx.indexOf(str.charAt(i)) < 0){
				alert("invalid "+msg+".");
				fldname.focus();
				return false;
			}
		}

		if((str.indexOf('@') < 0) || (str.indexOf('.') < 0)){
			alert("invalid "+msg+".");
			fldname.focus();
			return false;			
		}

		if((str.charAt(0) == '@') || (str.charAt(0) == '.')){
			alert("invalid "+msg+".");
			fldname.focus();
			return false;
		}

		if((str.charAt(str.length-1) == '@') || (str.charAt(str.length-1) == '.')){
			alert("invalid "+msg+".");
			fldname.focus();
			return false;
		}

		if((str.indexOf('@@') >= 0) || (str.indexOf('..') >= 0)){
			alert("invalid "+msg+".");
			fldname.focus();
			return false;
		}

		if((str.indexOf('@.') >= 0) || (str.indexOf('.@') >= 0)){
			alert("invalid "+msg+".");
			fldname.focus();
			return false;
		}

		flag = 0;
		for(i=0;i<str.length;i++){
			if(str.charAt(i) == '@')
				flag++;
		}

		if(flag > 1){
			alert("invalid "+msg+".");
			fldname.focus();
			return false;
		}
	}
	return true;
}

// 1st parameter field name.
// 2nd parameter error message.
// 3rd parameter minimum length.
// 4th parameter maximum length.
// 5th parameter minimum value.
// 6th parameter maximum value.
// 7th parameter required or not.
function numberformat(fldname,msg,minlength,maxlength,minvalue,maxvalue,required){
	indx_num  ="0123456789";
	str = fldname.value;

	if(required == "Y"){
		if(str.length == 0){
			alert("please enter "+msg+".");
			fldname.focus();
			return false;
		}
	}

	if(str.length > 0){
		if(str.length < minlength){
			alert(msg+" required minimum "+minlength+" characters.");
			fldname.focus();
			return false;
		}

		if(str.length > maxlength){
			alert(msg+" allowed maximum "+maxlength+" characters.");
			fldname.focus();
			return false;
		}

		for(i=0;i<str.length;i++){
			if(indx_num.indexOf(str.charAt(i)) < 0){
				alert("invalid "+msg);
				fldname.focus();
				return false;
			}
		}

		if(parseInt(str) < minvalue){
			alert(msg+" must not be less than "+minvalue);
			fldname.focus();
			return false;
		}

		if(parseInt(str) > maxvalue){
			alert(msg+" must not be more than "+maxvalue);
			fldname.focus();
			return false;
		}
	}
	return true;
}

function combobox(fldname,msg){
	if(fldname.selectedIndex == 0){
		alert("select "+msg);
		fldname.focus();
		return false;
	}
	return true;
}

///////////////////////////////////////////////////////////////////////////////


function alpha_numeric_value(fldname,minlength,maxlength,msg,required){
	indx = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#@$ ";
	str = fldname.value;

	if(required == 'Y'){
		if(str.length == 0){
			alert("please enter "+msg+".");
			fldname.focus();
			return false;
		}
	}

	if(str.length < minlength){
		alert(msg+" must be more than or equal to "+minlength+" characters.");
		fldname.focus();
		return false;
	}

	if(str.length > maxlength){
		alert(msg+" allowed maximum "+maxlength+" characters.");
		fldname.focus();
		return false;
	}

	if(str.length > 0){
		for(i=0;i<str.length;i++){
			if(indx.indexOf(str.charAt(i)) < 0){
				alert("invalid "+msg+".");
				fldname.focus();
				return false;
			}
		}

		flag = 0;
		for(i=0;i<str.length;i++){
			if(str.charAt(i) != " ")
				flag++;
		}

		if(flag == 0){
			alert("please enter "+msg+".");
			fldname.focus();
			fldname.value = "";
			return false;
		}
	}
	return true;
}
