// +------------------------------------------------------------+
// | Form Validation Control		 Version 1.0                |
// | Created on 25/09/2001           Last Modified 26/09/2001   |
// | Authors:			             Narayana Rao Surapaneni	| 
// | eMail:                          narayana@consultant.com    |
// +------------------------------------------------------------+
// +------------------------------------------------------------+
// | Please follow the intructions given below. Don't change    |
// | anything other than required.                              |
// +------------------------------------------------------------+

//This form validation control is very useful for handling client-
//side validations like checking for null values, email, numeric 
//values, alpha values, alpha numeric values etc. Further it displays
//the consolidated details filled in by the user before being 
//submitted to another form/page. This gives the user a scope, to 
//check details entered and correct if required thus ensuring 
//un-necessary hits on server side.

//BOTH NETSCAPE AND INTERNET EXPLORER COMPATIBLE

//NAMING CONVENTIONS TO BE FOLLOWED FOR FORM VALIDATION CONTROL

//AD - All Digits
//WS - White Spaces
//NM - Numeric
//AN - Alpha Numeric
//AL - Alpha
//EM - Email

//All required fileds in html page must be marked with the prefix REQ bebore the
//name of the object.

//EXAMPLES

//Consider TextBox named, EmpName

//CASE 1
//If you want this filed to be validated for null value then you have to 
//name this field as REQEmpName

//CASE 2
//In case don't wish to make this field a required field, but would like
//to validate for email then name the object as EMEmpName

//CASE 3
//In case you wish to make a field be checked for null value as well as email
//then name the object as REQEMEmpName


//List of validations provided: refer to final_functions.js
//isAllDigits() - Checks for numeric characters
//isWhiteSpace() - Checks for early whitespace
//isNumeric() - Checks for numeric characters
//isAlphaNumeric() - Checks for Alpha and Numeric characters only
//isAlpha() - Checks Alpha characters only
//isEmail() - Checks for syntax of an email

//All the above functions have four parameters, namely: 
//function_name(formName,fieldName,fieldValue,fldLblValue)

//In the html page include final_validation.js and final_functions.js files

function confrm(formName)
{
var frmfields = new Array();

//Add all the lables of html form to the array
//When you have Option Boxes please add separate entry for each option object, though
//it belongs to same group
//Add the following line of code in form tag of HTML page. Submit="return confrm(this.name);"

var frmFldLables = new Array();

frmFldLables[3] = "NV naam";
frmFldLables[4] = "NV email adres";
frmFldLables[5] = "NV naam publiceren";
frmFldLables[6] = "NV naam publiceren";
frmFldLables[7] = "NV email publiceren";
frmFldLables[8] = "NV email publiceren";
frmFldLables[9] = "Vul aub de datum in van het onderwerp waarop u wilt reageren";
frmFldLables[10] = "Vul aub het onderwerp in waarop u wilt reageren";
frmFldLables[11] = "Vul aub uw reactie in";
frmFldLables[12] = "Type aub het nummer over";


//Add the lables for confirm message to be be shown after validation
var frmConfLables = new Array();
frmConfLables[3] = "Naam";
frmConfLables[4] = "Email adres";
frmConfLables[5] = "Mag uw naam gepubliceerd worden";
frmConfLables[6] = "Mag uw naam gepubliceerd worden";
frmConfLables[7] = "Mag email adres gepubliceerd worden";
frmConfLables[8] = "Mag email adres gepubliceerd worden";
frmConfLables[9] = "Datum";
frmConfLables[10] = "Onderwerp";
frmConfLables[11] = "Uw reactie";
frmConfLables[12] = "Het validatie nummer";


var j=0;
var displayInfo = "U HEEFT DE ONDERSTAANDE INFORMATIE INGEVULD.\nCONTROLEER DIT AUB EN KLIK OP OK OM TE VERZENDEN!\n\n";
var flag=true;

//Checking for required fields: text boxex, multiple-select / single-select and textarea
for(i=0;i<eval("document." + formName+ ".elements.length");i++)
{
	var fldName;
	fldName=eval("document."+formName+".elements["+i+"].name");
	if(navigator.appName=="Microsoft Internet Explorer")
	{
		if (fldName.substring(0,3)=="REQ" && eval("document."+formName+".elements["+i+"].value").length == 0)
			{
					
				alert(frmFldLables[j]);
				eval("document."+formName+"."+fldName+".focus()");
				return false;
			}
	}


	if ((navigator.appName=="Netscape") && (eval("document."+formName+".elements["+i+"].type")== "text" || eval("document."+formName+".elements["+i+"].type") == "textarea" ) )
	{
		if (fldName.substring(0,3)=="REQ" && eval("document."+formName+".elements["+i+"].value").length == 0)
		{
			
				alert(frmFldLables[j]);
				eval("document."+formName+"."+fldName+".focus()");
				return false;
		}

	}

	if(navigator.appName=="Netscape")
	{
		if(fldName.substring(0,3)=="REQ" && (eval("document."+formName+".elements["+i+"].type") == "select-multiple" || eval("document."+formName+".elements["+i+"].type") == "select-one"))
				{
					var collectListInfo="";
					var	selectFlag = false;
					var multiSelectName=eval("document."+formName+".elements["+i+"].name");

					for(var l=0; l<eval("document."+formName+"."+ multiSelectName + ".options.length");l++)
						{

							if(eval("document."+formName+"."+ multiSelectName+ ".options["+l+"].selected") && eval("document."+formName+"."+ multiSelectName+ ".options["+l+"].value.length") > 0 )
							{
								collectListInfo += eval("document."+formName+"."+ multiSelectName+ ".options["+l+"].value") + ","
								selectFlag = true;
							}
							
						}
						if(selectFlag)
						{
							//displayInfo += frmConfLables[i] + " :   " + collectListInfo.substring(0,collectListInfo.length -1) + "\r";
			
						}
						else
						{
							alert(frmFldLables[j]);
							return false;
						}

				}

		}

//Validation for required fields: checkbox
	if (eval("document."+formName+".elements["+i+"].type") == "checkbox"  && fldName.substring(0,3)=="REQ")
		{
			if (!(eval("document."+formName+".elements["+i+"].checked")))
			{
				alert(frmFldLables[j]);
				eval("document."+formName+"."+fldName+".focus()");
				return false;
			}
		}

//Validation for required fields: radio button.
	if (eval("document."+formName+".elements["+i+"].type") == "radio" && fldName.substring(0,3)=="REQ" && flag==true)		
		{
		 
			var optName =eval("document."+formName+".elements["+i+"].name");
			for(var k=0;k<=eval("document."+formName+"."+optName+".length")-1;k++)
			{
				
				if (eval("document."+ formName + "."+ optName + "["+ k +"]"+".checked"))
				{
					flag=false;
					
				}
						
			}
			
			if(flag)
				{				
					flag=true;
					alert(frmFldLables[j]);
					eval("document."+ formName + "."+ optName + "[0]"+".focus()");
					return false;
				}
			flag = true;	
		}
//AD - All Digits
//WS - White Spaces
//NM - Numeric
//AN - Alpha Numeric
//AL - Alpha
//EM - Email
//isAllDigits() - Checks for numeric characters
//isWhiteSpace() - Checks for early whitespace
//isNumeric() - Checks for numeric characters
//isAlphaNumeric() - Checks for Alpha and Numeric characters only
//isAlpha() - Checks Alpha characters only
//isEmail() - Checks for syntax of an email




	if ((fldName.substring(0,5)=="REQAD" || fldName.substring(0,2)=="AD")&& eval("document."+formName+".elements["+i+"].value").length > 0)
		{
				if(isAllDigits(formName,fldName,eval("document."+formName+".elements["+i+"].value"),frmFldLables[j]))
				{
				}
				else
				{
					return false;
				}
		}


	if ((fldName.substring(0,5)=="REQWS" || fldName.substring(0,2)=="WS")&& eval("document."+formName+".elements["+i+"].value").length > 0)
		{
				if(isWhiteSpace(formName,fldName,eval("document."+formName+".elements["+i+"].value"),frmFldLables[j]))
				{
				}
				else
				{
					return false;
				}
		}


	if ((fldName.substring(0,5)=="REQNM" || fldName.substring(0,2)=="NM")&& eval("document."+formName+".elements["+i+"].value").length > 0)
		{
				if(isNumeric(formName,fldName,eval("document."+formName+".elements["+i+"].value"),frmFldLables[j]))
				{
				}
				else
				{
					return false;
				}
		}


	if ((fldName.substring(0,5)=="REQAN" || fldName.substring(0,2)=="AN")&& eval("document."+formName+".elements["+i+"].value").length > 0)
			{
					if(isAlphaNumeric(formName,fldName,eval("document."+formName+".elements["+i+"].value"),frmFldLables[j]))
					{
					}
					else
					{
						return false;
					}
			}


	if ((fldName.substring(0,5)=="REQAL" || fldName.substring(0,2)=="AL")&& eval("document."+formName+".elements["+i+"].value").length > 0)
		{
				if(isAlpha(formName,fldName,eval("document."+formName+".elements["+i+"].value"),frmFldLables[j]))
				{
				}
				else
				{
					return false;
				}
		}

	if ((fldName.substring(0,5)=="REQEM" || fldName.substring(0,2)=="EM")&& eval("document."+formName+".elements["+i+"].value").length > 0)
		{
				if(isEmail(formName,fldName,eval("document."+formName+".elements["+i+"].value"),frmFldLables[j]))
				{
				}
				else
				{
					return false;
				}
		}

//Concatinating the information in the textboxes, listboxes and textarea objects
	if (eval("document."+formName+".elements["+i+"].type")== "text" ||   eval("document."+formName+".elements["+i+"].type") == "textarea" )

		{
			displayInfo += frmConfLables[i] + " : " + eval("document."+formName+".elements["+i+"].value") + "\r";
		}


//Concatinating the information in the select-multiple listboxes
	if(eval("document."+formName+".elements["+i+"].type") == "select-multiple")
		{
		var collectListInfo="";
		var multiSelectName=eval("document."+formName+".elements["+i+"].name");

		for(var l=0; l<eval("document."+formName+"."+ multiSelectName + ".options.length");l++)
			{

				if(eval("document."+formName+"."+ multiSelectName+ ".options["+l+"].selected"))
				{
					collectListInfo += eval("document."+formName+"."+ multiSelectName+ ".options["+l+"].value") + ","
				}
				
			}
			displayInfo += frmConfLables[i] + " :   " + collectListInfo.substring(0,collectListInfo.length -1) + "\r";
		}


//Concatinating the information in the sigle-select boxes
	if(eval("document."+formName+".elements["+i+"].type") == "select-one")
		{
			var collectSelectInfo="";
			var singleSelectName=eval("document."+formName+".elements["+i+"].name");
		for(var l=0; l<eval("document."+formName+"."+ singleSelectName + ".options.length");l++)
			{

				if(eval("document."+formName+"."+ singleSelectName+ ".options["+l+"].selected"))
				{
					collectSelectInfo += eval("document."+formName+"."+ singleSelectName+ ".options["+l+"].value") + ","
				}
				
			}
			displayInfo += frmConfLables[i] + " :   " + collectSelectInfo + "\r";
			
		}



//Concatinating the information in checkboxes and option objects
	if (eval("document."+formName+".elements["+i+"].type") == "checkbox" || eval("document."+formName+".elements["+i+"].type") == "radio")
		{
				if (eval("document."+formName+".elements["+i+"].checked"))
					{
						displayInfo += frmConfLables[i] + " :   " + eval("document."+formName+".elements["+i+"].value") + "\r";
					}
	
		}
		j++;
}

//If the combined informatiion is more than 4000 characters, first 4000 characters
//would be displayed in a alert box and then the reamining content in a confirm box.
//The following code handles the code till 8000 characters only. If combinded info
//exceeds 8000 characters please modify the code accrodingly

	if(displayInfo.length > 8000)
	{
		alert("DEVELOPERS ALERT!!!... Forms combined information exceeds more than 8000 characters. Please modify the code accordingly.");
		return false;

	}	
	if(displayInfo.length > 4000)
	{
		alert(displayInfo.substring(0,4000));
		if(confirm(displayInfo.substring(4000,displayInfo.length)))
			return true;
		else 
			return false;
	}
	else
	{
		if(confirm(displayInfo))
			return true;
		else
			return false;
	}
	
}
