//State variables:
//var FormStates = {"Fill In", "Preview", "Complete", "Print"};
/*var FormState = <?php

//if (isset($SESSION['FORM_STATE']) && ($SESSION['FORM_STATE'] != "")) {
//	echo $SESSION['FORM_STATE'];
//} else {
//	echo "0";
//}

?>;*/

	var PrinterMode = false;
	var DefaultForm = "http://orders.lancet.co.za/index.php";
	var SubmitPage = 	"http://orders.lancet.co.za/SubmitForm.php";
	var PreviewPage = "http://orders.lancet.co.za/PreviewForm.php";
	var TestArrayString = "";
	var TestArray = Array();


	/*	Generates a style string to be inserted into the calling document	*/
	function GetStyleString(){
		return '<style>'+
						'<'+'!-'+'-'+
						' /* Font Definitions */'+
						'@font-face'+
						'	{font-family:Impact;panose-1:2 11 8 6 3 9 2 5 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:647 0 0 0 159 0;}'+
						' /* Style Definitions */'+
						'p.MsoNormal, li.MsoNormal, div.MsoNormal'+
						'	{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;mso-pagination:widow-orphan;font-size:10.0pt;font-family:Arial;color:#006600;mso-fareast-font-family:"Times New Roman";}'+
						'h1'+
						'	{mso-style-next:Normal;margin:0cm;margin-bottom:.0001pt;mso-pagination:widow-orphan;page-break-after:avoid;mso-outline-level:1;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Arial;color:#003399;mso-font-kerning:0pt;}'+
						'h2'+
						'	{mso-style-next:Normal;margin:0cm;margin-bottom:.0001pt;text-align:center;mso-pagination:widow-orphan;page-break-after:avoid;mso-outline-level:2;font-size:24.0pt;mso-bidi-font-size:12.0pt;font-family:Impact;mso-bidi-font-family:Arial;color:white;}'+
						'h3'+
						'	{mso-style-next:Normal;margin:0cm;margin-bottom:.0001pt;text-align:center;mso-pagination:widow-orphan;page-break-after:avoid;mso-outline-level:3;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Impact;mso-bidi-font-family:Arial;color:#193C81;font-weight:normal;text-decoration:underline;text-underline:single;}'+
						'h4'+
						'	{mso-style-next:Normal;margin:0cm;margin-bottom:.0001pt;text-align:center;mso-pagination:widow-orphan;page-break-after:avoid;mso-outline-level:4;font-size:6.0pt;mso-bidi-font-size:12.0pt;font-family:Arial;color:#193C81;}'+
						'h5'+
						'	{mso-style-next:Normal;margin:0cm;margin-bottom:.0001pt;mso-pagination:widow-orphan;page-break-after:avoid;mso-outline-level:5;font-size:6.0pt;mso-bidi-font-size:12.0pt;font-family:Arial;color:#193C81;}'+
						'h6'+
						'	{mso-style-next:Normal;margin:0cm;margin-bottom:.0001pt;mso-pagination:widow-orphan;page-break-after:avoid;mso-outline-level:6;font-size:8.0pt;mso-bidi-font-size:12.0pt;font-family:Arial;color:white;}'+
						'p.MsoHeading7, li.MsoHeading7, div.MsoHeading7'+
						'	{mso-style-next:Normal;margin:0cm;margin-bottom:.0001pt;text-align:center;mso-pagination:widow-orphan;page-break-after:avoid;mso-outline-level:7;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Arial;mso-fareast-font-family:"Times New Roman";color:white;font-weight:bold;}'+
						'p.MsoHeading8, li.MsoHeading8, div.MsoHeading8'+
						'	{mso-style-next:Normal;margin:0cm;margin-bottom:.0001pt;text-align:center;mso-pagination:widow-orphan;page-break-after:avoid;mso-outline-level:8;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Arial;mso-fareast-font-family:"Times New Roman";color:#006600;font-weight:bold;}'+
						'p.MsoHeading9, li.MsoHeading9, div.MsoHeading9'+
						'	{mso-style-next:Normal;margin:0cm;margin-bottom:.0001pt;text-align:center;mso-pagination:widow-orphan;page-break-after:avoid;mso-outline-level:9;font-size:32.0pt;mso-bidi-font-size:12.0pt;font-family:Impact;mso-fareast-font-family:"Times New Roman";mso-bidi-font-family:"Times New Roman";color:white;}'+
						'p.MsoBodyText, li.MsoBodyText, div.MsoBodyText'+
						'	{margin:0cm;margin-bottom:.0001pt;text-align:center;mso-pagination:widow-orphan;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Arial;mso-fareast-font-family:"Times New Roman";color:#193C81;font-weight:bold;text-decoration:underline;text-underline:single;}'+
						'p.MsoBodyText2, li.MsoBodyText2, div.MsoBodyText2'+
						'	{margin:0cm;margin-bottom:.0001pt;text-align:center;mso-pagination:widow-orphan;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Impact;mso-fareast-font-family:"Times New Roman";mso-bidi-font-family:Arial;color:#193C81;text-decoration:underline;text-underline:single;}'+
						/*--==  Style for page breaks:  ==--*/
						'@page Section1'+
						'	{size:595.3pt 841.9pt;margin:0.0pt 0.0pt 0.0pt 0.0pt;mso-header-margin:35.4pt;mso-footer-margin:35.4pt;mso-paper-source:0;}'+
						'div.Section1'+
						'	{page:Section1;}'+
						'-'+'->'+
						'P.page {page-break-after: always}'+
						/*--== Style for erroneous inputs:  ==--*/
						'#errormsg'+
						'	{'+
						'		border:2px solid #c00;'+
						'		padding:5px;'+
						'		width:20em;'+
						'		align:left;'+
						'	}'+
						'.error'+
						'	{'+
						'		background:#fcc;'+
						'	}'+
						'<\/style>';
	}

	/*	Checks if the browser is infact any IE browser >= version 4	*/
	function IsIE(){
		if ((navigator.appName.indexOf("Microsoft")!= -1)&&(parseInt(navigator.appVersion)>=4)){
			return true;
		}
		return false;
	}

	/*	Checks if the browser is infact the non-standard conformist: IE7	*/
	function IsIE6(){
		if ((navigator.appVersion.indexOf("MSIE ") != -1) && (document.getElementById)){
			return true;
		}
		return false;
	}

	/*	Checks if the browser is infact the non-standard conformist: IE7	*/
	function IsIE7(){
		if ((navigator.appVersion.indexOf("MSIE 7") != -1) && (document.getElementById)){
			return true;
		}
		return false;
	}

	/*	Checks if the client is a netscape/mozilla browser	*/
	function IsMozilla(){
		if ((navigator.appName.indexOf("Netscape")!=-1)&&(parseInt(navigator.appVersion)>=5)){
			return true;
		}
		return false;
	}

	/*	Checks if the client is a netscape/mozilla browser	*/
	function IsOpera(){
		if (navigator.appName.indexOf("Opera")!=-1){
			return true;
		}
		return false;
	}

	/*	Sets the opacity of the specified object	*/
	function SetOpacity(IconObject, Opacity){
		try {
			if (IsMozilla() || IsOpera()){
				IconObject.style.MozOpacity=(Opacity/100);
			} else
			if (IsIE7()){
				IconObject.filters.alpha.opacity=Opacity;
			}
		}
		catch (ERROR){
		}
	}

	/*	Submits the form with a "ClearForm" command which will "reset" the form	*/
	function ClearForm(){
		/*
		if ((IsIE6()) || (IsMozilla())){
			document.getElementById("Command").value="ClearForm";
		} else {
			SUBMITPHP.Command.value="ClearForm";
		}
		*/
		SetCommand("ClearForm");
	}

	/*	This function extracts the printable data from the form and then calls the print dialog	*/
	function PrintForm()
	{
		var VirtDisp =	"toolbar=yes,location=no,directories=yes,menubar=yes,"+
												"scrollbars=yes,width=650, height=600, left=100, top=25";
		var PrintingContent = (((IsIE6() || IsMozilla() || IsOpera()) && (document.getElementById("printable_content").innerHTML != null))?document.getElementById("printable_content").innerHTML:document.printable_content.innerHTML);
		var PrintDoc = window.open("","",VirtDisp);
		PrintDoc.document.open();
		PrintDoc.document.write('<html><head><title>Lancet Laboratories - Electronic Request Form<\/title>');
		PrintDoc.document.write(GetStyleString());
		//PrintDoc.document.write('<SCRIPT Language="JavaScript" type="text/javascript" src="http://orders.lancet.co.za/BuildTableScript.js"></SCRIPT>');
		//PrintDoc.document.write('<SCRIPT Language="JavaScript" type="text/javascript" src="http://orders.lancet.co.za/HeaderJava.js"></SCRIPT>');
		PrintDoc.document.write('<SCRIPT>var PrinterMode=true;<\/SCRIPT>');
		PrintDoc.document.write('<\/head><body onLoad="self.print(); window.close();">');
		PrintDoc.document.write(PrintingContent);
		PrintDoc.document.write('<\/body><\/html>');
		PrintDoc.document.close();
		PrintDoc.focus();
	}

	/*	Initializes the various div tags to their respective opacities	*/
	function InitOpacity(InitialValue){
		if (IsIE6() || IsMozilla() || IsOpera()){
			SetOpacity(document.getElementById("PrintIcon"),InitialValue);
			SetOpacity(document.getElementById("ClearIcon"),InitialValue);
			SetOpacity(document.getElementById("SubmitIcon"),InitialValue);
		}
	}

	/*	This function was going to be used to create a dynamic DIV tag with an icon...	*/
	function CreateIcon(LayerName, IconOrder, IconName, IconImage, IconCode, IconTitle){
		var LayerTop = (70*(IconOrder-1));
		if (IsMozilla() || IsOpera()){
			//document.writeln('<div name=\"'+LayerName+'\" id=\"'+LayerName+'\" style=\"cursor:hand; position:fixed; width:64px; height:60px; z-index:200; left:'+(document.body.clientWidth-84)+'px; top:'+LayerTop+'px; MozOpacity:0.5; alpha:opacity(50);\">');
			document.writeln('<div name=\"'+LayerName+'\" id=\"'+LayerName+'\" style=\"cursor:hand; position:fixed; width:64px; height:60px; z-index:200; left:'+(document.body.clientWidth-84)+'px; top:'+LayerTop+'px; MozOpacity:0.5; alpha:opacity(50);\">');
		} else {
			//document.writeln('<div name=\"'+LayerName+'\" id=\"'+LayerName+'\" style=\"cursor:hand; position:absolute; width:64px; height:60px; z-index:200; left:expression(document.body.clientWidth-74); top:expression(document.body.clientTop+'+LayerTop+'); alpha:opacity(50);\">');
			document.writeln('<div name=\"'+LayerName+'\" id=\"'+LayerName+'\" style=\"cursor:hand; position:absolute; width:64px; height:60px; z-index:200; left:expression(document.body.clientWidth-74); top:expression(document.body.clientTop+'+LayerTop+'); alpha:opacity(50);\">');
		}
		document.writeln('	<img NAME=\"'+IconName+'\"  ID=\"'+IconName+'\" src=\"http://orders.lancet.co.za/'+IconImage+'\" width=\"64\" height=\"60\" onMouseOut=\'{SetOpacity(this,50)}\' onMouseOver=\'{SetOpacity(this,100)}\' onClick=\"{'+IconCode+'}\" TITLE=\"'+IconTitle+'\" ALT=\"'+IconTitle+'\">');
		document.writeln('<\/div>');
	}

	/*	Retrieves the client details to be submitted to the server	*/
	function SetUserDetails(){
		if (IsIE6() || IsMozilla() || IsOpera()){
			document.getElementById("user_browser").value = navigator.appName;
			document.getElementById("user_version").value = navigator.appVersion;
			document.getElementById("user_agent").value = navigator.userAgent;
		} else {
			SUBMITPHP.user_browser.value = navigator.appName;
			SUBMITPHP.user_version.value = navigator.appVersion;
			SUBMITPHP.user_agent.value = navigator.userAgent;
		}
	}

	/*	Sets the command type (used when printing, previewing, submitting etc.)	*/
	function SetCommand(CommandString){
		if (IsIE6() || IsMozilla() || IsOpera()){
			document.getElementById("Command").value = CommandString;
		} else {
			SUBMITPHP.Command.value = CommandString;
		}
	}

	/*	Specifies that the form has just been submitted	*/
	function SetCommandSubmit(){
		SetCommand("SUBMIT");
	}

	/*	Specifies that the form has just been printed	*/
	function SetCommandPrint(){
		SetCommand("PRINT");
	}

	function GetCommand() {
		if (IsIE6() || IsMozilla() || IsOpera()){
			return document.getElementById("Command").value;
		} else {
			return SUBMITPHP.Command.value;
		}
	}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


	/*	Writes the opening tags and header for the test table	*/
  function TableHeader(TableLabel, Columns){
  	var HeaderString = "";
		HeaderString += "<table cellspacing=1 width=\"100%\" style=\'background:#FFFFFF;border-top:solid #006600 1.5pt;border-left:solid #006600 1.5pt;border-bottom:solid #006600 1.5pt;border-right:solid #006600 1.5pt; BEHAVIOR: url(tablehl.htc);\' hlcolor=\"#BEC5DE\" slcolor=\"#ffffcc\" dragcolor=\"gray\">\n";
		HeaderString += "<THEAD><tr><TH COLSPAN=\'"+Columns+"\' style=\'border-top:#88CA88 1.5pt;border-left:#88CA88 1.5pt;border-bottom:solid #006600 1.5pt;border-right:#88CA88 1.5pt;mso-border-top-alt:solid #006600 1.5pt;background:#88CA88;padding:0cm 5.4pt 0cm 5.4pt;height:10.2pt\'>"+
			"<p class=MsoHeading8>"+TableLabel+"<\/p><\/TH><\/tr><\/THEAD>\n<TBODY>";
		return HeaderString;
	}


	/*	Creates the footer/closing tags for the test table	*/
	function TableFooter(){
		return "<\/TBODY><\/table>";
	}


	/*	Draws a single row in the test table	*/
	function DrawRow(TestID, TestCode, TestLabel, Specimens, Department, Posted){
		var RowString = "";
		RowString += "<tr style='font-size:10.0pt;mso-bidi-font-size:12.0pt; font-family:Arial;color:#193C81'>";
		RowString += "<td>"+TestCode+"<\/td>";
		//if (Posted) {
			//this.document.writeln("<td>X<\/td>");
		//} else {
			RowString += "<td><input type = \"checkbox\" ID=\""+TestID+"\" NAME=\""+TestID+"\" value=\""+TestCode+"\" title=\""+TestLabel+"\""+((Posted == 1)?" CHECKED ":"")+"><\/td>";
		//}
		RowString += "<td>"+TestLabel+"</td>";
		//this.document.writeln("<td align=\"right\">"+Specimens+"<\/td>");
		RowString += "<td>"+Specimens+"<\/td>";
		RowString += "<td>"+Department+"</td>";
		RowString += "<\/tr>";
		return RowString;
	}


	/*  Build the tables for the tests  */
	function BuildTestTables(TestArrayString) {
		try {
			var TableString = "";
			var Printing_Doc = (((document.getElementById)?document.getElementById("Command").value:document.SUBMITPHP.Command.value) == "");
			//var Printing_Doc = (((IsIE6() || IsMozilla() || IsOpera())?document.getElementById("Command").value:document.Command.value) == "");
			if (TestArrayString.length > 0){
				var TestArray = SplitStringz(TestArrayString);

				var Category = "";
				var CategoryTableString = "";
				for (var cnt=0; cnt < TestArray.length; cnt++){
					var RowRecord = TestArray[cnt];
					//if the category is different from the last - create a new table for it.

					if (RowRecord[0] != Category){
						if (CategoryTableString.length > 0) {
							//write the subsection's table to the TableString...
							TableString +=	"<TR><TD>"+
																TableHeader(Category, 5)+
																	CategoryTableString+
																TableFooter()+
															"<\/TD><\/TR>";
							CategoryTableString = "";
						}
					}
					//Get the current record's category
					Category = RowRecord[0];

					//create the row for the the current category table.
					if ((!PrinterMode) || (RowRecord[6] == 1)){
						CategoryTableString += DrawRow('TEST'+RowRecord[5], RowRecord[1], RowRecord[2], RowRecord[3], RowRecord[4], RowRecord[6]);
					}
				}

				//check if the CategoryTableString is not empty (occurs on the last table generated)
				if (CategoryTableString.length > 0) {
					//write the subsection's table to the TableString...
					TableString +=	"<TR><TD>"+
														TableHeader(Category, 5)+
															CategoryTableString+
														TableFooter()+
													"<\/TD><\/TR>";
					CategoryTableString = "";
				}

				if (TableString.length >0) {
					TableString = "<TABLE width=100% height=100% align=center style='background:#FFFFFF;'>"+TableString;
					TableString += "<\/TABLE>";
				}
			}
			this.document.writeln(TableString);
		}
		catch(ERROR) {
			this.document.writeln("<TABLE width=100% height=100% align=center style='background:#FFFFFF;'><TR><TD width=100%>");
			this.document.writeln("<FONT COLOR=#FF0000>TableGeneration Script had fatal error: "+ERROR.message+"<\/FONT>");
			this.document.writeln("<\/TD><\/TR><\/TABLE>");
		}
	}


	/*  Create a blank, white box with a green border to take the place of an input box - for printing  */
	function CreateBlankInputBox() {
		try {
			var NewElement = document.createElement('span');
			NewElement.style.border = 1;
			NewElement.style.background = "#FFFFFF";
		}
		catch (ERROR) {
		}
	}


	/*  Remove Objects for Printing  */
	function RemoveForPrinting() {
		try {
			var InputList = document.getElementsByTagName('input');
			for (var cnt = 0; cnt < InputList.length; cnt++){
				if ((InputList[cnt].type.toLowerCase() == 'text') && (InputList[cnt].value == "")) {
					//Either create a new blank box to swap the input box with or remove the section all together.
				} else if ((InputList[cnt].type.toLowerCase() == 'text') && (InputList[cnt].value != "")) {
					//Create a box and place the value from the input into the box.
				}
			}
		}
		catch (ERROR) {
			//showmessage('Error intercepted while trying to remove unused elements: '+ERROR.message);
		}
	}


	/*
	function addEvent()
	{
		var ni = document.getElementById('myDiv');
		var numi = document.getElementById('theValue');
		var num = (document.getElementById("theValue").value -1)+ 2;
		numi.value = num;
		var divIdName = "my"+num+"Div";
		var newdiv = document.createElement('div');
		newdiv.setAttribute("id",divIdName);
		newdiv.innerHTML = "Element Number "+num+" has been added! <a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">Remove the div &quot;"+divIdName+"&quot;</a>";
		ni.appendChild(newdiv);
	}

	function removeEvent(divNum)
	{
		var d = document.getElementById('myDiv');
		var olddiv = document.getElementById(divNum);
		d.removeChild(olddiv);
	}
	*/


/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

	/*	This function just prints out the browser version and a logo depending on which browser is being used.	*/
	function PrintBrowserInfo() {
		if (!PrinterMode) {
			if (navigator.userAgent.indexOf("MSIE") >= 0){
				//document.writeln("<center><b><p class=MsoNormal><span style=\'font-size:6.0pt;mso-bidi-font-size:12.0pt; font-family:Arial;color:#193C81\'>This page is compatable with Internet Explorer<\/span><\/p><\/b><img src='http://orders.lancet.co.za/Images/IE.PNG' ALT=\'Supports Internet Explorer V7+\'><\/center>");
				document.writeln("<center><img src='http://orders.lancet.co.za/Images/IE.gif' ALT=\'Supports Internet Explorer V6+, recommends Mozilla Firefox\' TITLE=\'Supports Internet Explorer V7+, recommends Mozilla Firefox\'><b><p class=MsoNormal><span style=\'font-size:6.0pt;mso-bidi-font-size:12.0pt; font-family:Arial;color:#193C81\'>This page is compatable with Internet Explorer<\/span><\/p><\/b><BR><b><p class=MsoNormal><span style=\'font-size:6.0pt;mso-bidi-font-size:12.0pt; font-family:Arial;color:#193C81\'>However, I suggest you upgrade your browser to a standards compliant one such as <A HREF=\'http://www.getfirefox.com\'>Mozilla Firefox</A> or <A HREF=\'http://www.Opera.com\'>Opera</A><\/span><\/p><\/b><\/center>");
			} else
			if (navigator.userAgent.indexOf("Firefox") >= 0){
				document.writeln("<center><img src='http://orders.lancet.co.za/Images/Firefox.PNG' ALT=\'Supports & recommends Mozilla FireFox\' TITLE=\'Supports & recommends Mozilla FireFox\'><b><p class=MsoNormal><span style=\'font-size:6.0pt;mso-bidi-font-size:12.0pt; font-family:Arial;color:#193C81\'>This page supports, and is optimized for Mozilla Firefox<\/span><\/p><\/b><\/center>");
			}
			if (navigator.userAgent.indexOf("Opera") >= 0){
				document.writeln("<center><img src='http://orders.lancet.co.za/Images/Opera_sm.gif' ALT=\'Supports Opera\' TITLE=\'Supports Opera\'><b><p class=MsoNormal><span style=\'font-size:6.0pt;mso-bidi-font-size:12.0pt; font-family:Arial;color:#193C81\'>This page supports Opera<\/span><\/p><\/b><\/center>");
			}
			document.writeln("<FONT COLOR=#FFFFFF>");
			document.writeln("Browser: "+navigator.appName+"<BR>");
			document.writeln("Version: "+navigator.appVersion+"<BR>");
			document.writeln("Agent: "+navigator.userAgent+"<BR>");
			document.writeln("</FONT>");
		}
	}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*  FORM VALIDATION FUNCTIONS  */

	function checkform(of)
	{
		// Test if DOM is available and there is an element called required
		if(!document.getElementById || !document.createTextNode){return;}
		if(!document.getElementById('required')){return;}

		// Define error messages and split the required fields
		var errorID='errormsg';
		var errorClass='error'
		/* changes for linked list */
		var errorMsg='Please enter or change the following fields:';
		/* end changes for linked list */
		var errorImg='http://orders.lancet.co.za/Images/alert.gif';
		var errorAlt='Error';
		var errorTitle='This field has an error!';
		var reqfields=document.getElementById('required').value.split(',');

		// Cleanup old mess
		// if there is an old errormessage field, delete it
		//try {
			if(document.getElementById(errorID))
			{
				var em=document.getElementById(errorID);
				em.parentNode.removeChild(em);
			}
		//}
		//catch(ERROR) {
		//}
		// remove old images and classes from the required fields
		for(var i=0;i<reqfields.length;i++)
		{
			var f=document.getElementById(reqfields[i]);
			if(!f){continue;}
			if(f.previousSibling && /img/i.test(f.previousSibling.nodeName))
			{
				f.parentNode.removeChild(f.previousSibling);
			}
			f.className='';
		}
		// loop over required fields
		for(var i=0;i<reqfields.length;i++)
		{
			// check if required field is there
			var f=document.getElementById(reqfields[i]);
			if(!f){continue;}
			// test if the required field has an error,
			// according to its type
			switch(f.type.toLowerCase())
			{
				case 'text':
					if(f.value=='' && f.id!='email'){
						cf_adderr(f);
					} else 
					// email is a special field and needs checking
					if(f.id=='email' && !cf_isEmailAddr(f.value)){
						cf_adderr(f);
					} else 
					// Dates are special fields and require special checking too
					try {
						if(f.title.match('YYYYMMDD') && !cf_isValidDate(f.value)){
							cf_adderr(f)
						}
					} catch (ERROR){alert('the following error was found: '+ERROR.message);}
				break;
				case 'textarea':
					if(f.value==''){cf_adderr(f)}
				break;
				case 'checkbox':
					if(!f.checked){cf_adderr(f)}
				break;
				case 'select-one':
					if(!f.selectedIndex && f.selectedIndex==0){cf_adderr(f)}
				break;
			}
		}

		/*---===  Tool methods ===---*/
		function cf_adderr(o)
		{
			// create image, add to and colourise the error fields
			var errorIndicator=document.createElement('img');
			errorIndicator.alt=errorAlt;
			errorIndicator.src=errorImg;
			errorIndicator.title=errorTitle;
			o.className=errorClass;
			o.parentNode.insertBefore(errorIndicator,o);

			//try {
				// Check if there is no error message
				if(!document.getElementById(errorID))
				{
					// create errormessage and insert before submit button
					var em=document.createElement('div');
					em.id=errorID;
					var newp=document.createElement('p');
					newp.appendChild(document.createTextNode(errorMsg))
					em.appendChild(newp);
					/* added for linked list */
					var newul=document.createElement('ul');
					em.appendChild(newul);
					/* end added for linked list */
					// find the submit button
					for(var i=0;i<of.getElementsByTagName('div').length;i++)
					{
						if(/Browser_Info/i.test(of.getElementsByTagName('div')[i].id))
						{
							var sb=of.getElementsByTagName('div')[i];
							break;
						}
					}
					if(sb)
					{
						sb.parentNode.insertBefore(em,sb);
						//sb.parentNode.appendChild(em);
					}
				}
				/* added for linked list */
				var em=document.getElementById(errorID).getElementsByTagName('ul')[0];
			//}
			//catch(ERROR){
			//}
			var newli=document.createElement('li');
			var newa=document.createElement('a');
			//find the label for the required field...
			for(var i=0;i<of.getElementsByTagName('label').length;i++)
			{
				if(of.getElementsByTagName('label')[i].htmlFor==o.id)
				{
					var txt=of.getElementsByTagName('label')[i].firstChild.nodeValue;
					break;
				}
			}
			//if no label was found, then use the required field's description...
			if (!txt) {
				if (o.title) {
					var txt=o.title;
				} else if (o.alt) {
					var txt=o.alt;
				} else {
					var txt=o.id;
				}
			}

			newa.appendChild(document.createTextNode(txt.toUpperCase()));
			newa.href='#'+f.id;
			newa.onclick=function()
			{
				var loc=this.href.match(/#(\w.+)/)[1];
				document.getElementById(loc).focus();
				return false;
			}
			newli.appendChild(newa);
			em.appendChild(newli);
			/* end added for linked list */
		}

		return (!document.getElementById(errorID));
	}

	/*--==  FUNCTION TO VALIDATE E-MAIL ADDRESS STRINGS USING REGEX  ==--*/
	function cf_isEmailAddr(str)
	{
	    return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
	}

	/*--==  FUNCTION TO VALIDATE DATE STRINGS USING REGEX  ==--*/
	function cf_isValidDate(str)
	{
	    return str.match(/^((19|20)\d{2})((0|1)\d{1})([0-3]\d)$/);
	}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

