	var moForm;	
	var msASPSave;
	var msASPTarget;
	var mbValid       = "true"
		

function showDiv(sName, sName2)
{	
	var oDivs = document.getElementsByTagName('DIV');
	var oDiv;

	for ( var teller=0; teller < oDivs.length; teller++)
	{
		oDiv = oDivs[teller];

		if ( oDiv.id == sName || oDiv.id == sName2)
			{
				oDiv.style.visibility = 'visible';
				oDiv.style.zIndex = 1;
			}
			else
			{
				if ( oDiv.name == 'hide' )
				{
					oDiv.style.visibility = 'hidden';
					oDiv.style.zIndex = 0;
				}
			}
		}
	}	

	function validateOnly(poForm)
	{	
		// set reference to Form local.
		if (poForm)
		{
			moForm = poForm;
		}
		else
		{
			alert('No form defined')
			return false;
		}			
		getData();
		
		return mbValid;		
	}
		
	function submitForm(poForm)
	{	
		// set reference to Form local.
		if (poForm)
		{
			moForm = poForm;
			msASPSave = poForm.action;
				
			if (poForm.target)
			{
				msASPTarget =  poForm.action;
				
			}
		}
		else
		{
			alert('No form defined');
			return false;
		}
						
		//build XML string !!
		var sXML = generateXML();
								
		if (mbValid)
		{
			submitText(sXML);
			return true;
		}
	}
	
	function generateXML()
	{		
		var sXML = '<object>';		
		sXML += getData();		
		sXML += "</object>"	
		return sXML;
	}

	function getPicklistelements(poField)
	{
		var sElement;
		var sString 	= '';
		var oElements 	= poField.children;
		var sName  		= poField.name;				
		var sDatatype	= getAttributeValue(poField, 'nbrDataTypeId');
		var bRequired 	= (getAttributeValue(poField, 'bitRequired') == 'TRUE')

		for (i=0;i<oElements.length;i++) 
		{			
			bSelected = oElements[i].checked;
			sValue 	  = oElements[i].value;
			
			if( !isNaN(sValue) && bSelected )
			{
				sString += addBaseNode('attribute', sValue, sName, sDatatype);
			}
		}	
		
		if ( sString.length == 0 && bRequired)
		{
			return isRequired(poField);
		}
		else
		{
			if ( sString.length == 0 )
			{
				sString = addBaseNode('attribute', '', sName, sDatatype);
			}			
			return sString;
		}
	}


	function getReference(poField, bSelectAll)
	{
		var oOption;
		var sString 	= '';
		var oOptions 	= poField.children;
		var sName  		= poField.name;				
		var bRequired 	= (getAttributeValue(poField, 'bitRequired') == 'TRUE')
		var lMax		= getAttributeValue(poField, 'nbrMaxVal');
				
		if (lMax > 0)
		{
			if ( oOptions.length > parseInt(lMax) )
			{
				mbValid = false;
				poField.focus();
				alert('Too many reference. You are allowed to use ' + lMax + ' reference(s)!')	
				return;
			}
		}
		
		for (oOption in oOptions) 
		{	
			sValue    = oOptions[oOption].value;
			bSelected = oOptions[oOption].selected;
			
			if( !isNaN(sValue) && ( bSelected || bSelectAll) )
			{
				sString += addBaseNode('attribute', sValue, sName, 'REFERENCE');				
			}
		}	
		
		if (sString.length == 0 && bRequired)
		{
			return isRequired(poField);
		}
		else
		{
			return sString;	
		}		
		
	}

	function loadKeyword(poForm, plLinkId)
	{
		moForm = poForm;
		
		var poField = getElement(plLinkId);		
		if (poField)
		{
			openWindow('/keyword/frmClassification.asp?nbrLinkId=' + plLinkId, 400, 500, 1,1)				
		}		
	}

	function removeReference(poForm, plName)
	{		
		moForm = poForm;
		
		var poField = getElement(plName);		
		if (poField)
		{
			if (poField.selectedIndex >= 0)
			{
				poField.remove(poField.selectedIndex)
			}
		}		
	}

	function delReference(poForm, url, plLinkId)
	{
		var lObjectId;
		
		moForm = poForm;
		
		var poField = getElement(plLinkId);		
		if (poField)
		{			
			if (poField.selectedIndex >= 0)
			{
				var oOption   = poField.options[poField.selectedIndex]
				if (oOption)
				{
					var lObjectId = oOption.value;
					var sName 	  = oOption.text;
					if (!isNaN(lObjectId))
					{
						var lAnswer = confirm('Are you sure you want to delete the object "' + sName + '"')
						if(lAnswer)
						{
							url += 'nbrObjectId=' + lObjectId + '&chrName=' + sName
							openWindow(url, 200, 100, 0,0)
							poField.remove(poField.selectedIndex)
						}
					}		
				}
			}
		}
	}	

	function viewReference(poForm, url, plLinkId)
	{
		var lObjectId;
		
		moForm = poForm;

		var poField = getElement(plLinkId);		
		if (poField)
		{			
			if (poField.selectedIndex >= 0)
			{
				var oOption   = poField.options[poField.selectedIndex]
				if (oOption)
				{
					var lObjectId = oOption.value;
					var sName 	  = oOption.text;
					if (!isNaN(lObjectId))
					{
						url += 'nbrObjectId=' + lObjectId + '&chrName=' + sName
						openWindow(url, 500, 400, 1, 1)
					}		
				}
			}
		}
	}	

	function newReference(poForm, url, plLinkId)
	{
		moForm = poForm;
		
		var poField = getElement(plLinkId);		
		if (poField)
		{
			openWindow(url, 500, 400, 1, 1);
		}
	}	

	function editReference(poForm, url, plLinkId)
	{
		var lObjectId;
		
		moForm = poForm;

		var poField = getElement(plLinkId);		
		if (poField)
		{			
			if (poField.selectedIndex >= 0)
			{
				var oOption   = poField.options[poField.selectedIndex]
				if (oOption)
				{
					var lObjectId = oOption.value;
					var sName 	  = oOption.text;
					if (!isNaN(lObjectId))
					{
						url += '&nbrObjectId=' + lObjectId
						openWindow(url, 500, 400, 1, 1)
					}		
				}
			}
		}
	}	


	function addReference(poForm, url, plLinkId)
	{
		moForm = poForm;
				
		var poField = getElement(plLinkId);		
		if (poField)
		{
			openWindow(url, 400, 400, 1, 0);
		}
	}	

	function openWindow(url, width, height, resizable, scrollbars)
	{
		var windowName = '_blank'
		var params = '';
		var screenY = (screen.availheight / 2) - parseInt(height) / 2;
		var screenX = (screen.availwidth / 2) - parseInt(width) / 2;
		
		params += "toolbar=0,";
		params += "location=0,";
		params += "directories=0,";
		params += "status=0,";
		params += "menubar=0,";
		params += "scrollbars=" + scrollbars + ",";
		params += "resizable=" + resizable + ",";
		params += "width=" + width + ",";
		params += "height=" + height + ",";
		params += "top=" + screenY +  ",";
		params += "left=" + screenX;
		
		oChildWindow = window.open(url, windowName, params);				
		return oChildWindow;
	}

// ===================== Validation func ================

	function isRequired(poField)
	{
		if (poField.bitAutoNumber)
		{
			if (poField.bitAutoNumber == 'TRUE')
			{
				return false	
			}
		}
		
		if (!(poField.disabled || poField.style.display == 'none' || poField.style.visibility == 'hidden'))
		{		
			poField.focus();
		}
		if (document.all)
		{
			poField.scrollIntoView (true)
		}
		alert( '"' + unHTML(getAttributeValue(poField, 'chrDesc')) + '" is required!')
		mbValid = false;
		return false;
	}						


	function validateField( poField )
	{	
		if (!poField)
		{	
			mbValid = false;
			return '';
		}
		
		var sDatatypeId = getAttributeValue(poField, 'nbrDataTypeId');
		var bRequired 	= (getAttributeValue(poField, 'bitRequired') == 'TRUE')
		var sDesc 		= getAttributeValue(poField, 'chrDesc')
		
		switch (poField.type)
		{
			// ============ All radioboxes ===============
			case 'radio':				
				if (poField.checked)
				{	
					return addBaseNode('attribute', poField.value, poField.name, sDatatypeId);
				}	
				else
				{
					return addBaseNode('attribute', '', poField.name, sDatatypeId);	
				}			
				break;				
			// ============ All checkboxes ===============
			case 'checkbox':				
							
				if (poField.checked)
				{
					return addBaseNode('attribute', poField.value, poField.name, sDatatypeId);
				}
				else
				{
					return addBaseNode('attribute', '', poField.name, sDatatypeId);	
				}			
				break;
			// ============ fieldset, container of multiple checkboxes ===============
			case 'fieldset':

				return getPicklistelements( poField );				
				break;
			
			// ============ All (hidden) textboxes ===============
			case 'hidden':
			case 'text':				
				switch (sDatatypeId)
				{
					// ============= NUMERIC ================
					case 'NUMERIC':				
										
						if (poField.value.length == 0 && bRequired )
						{
							return isRequired(poField);	
						}
						if (!isNumeric(poField, 'Please supply a numeric value for "' + unHTML(getAttributeValue(poField, 'chrdesc')) + '"!') )
						{
							mbValid = false;
							return '';
						}
						else
						{
							var lMin = getAttributeValue(poField, 'nbrMinVal');
							var lMax = getAttributeValue(poField, 'nbrMaxVal');
							
							if ( parseInt(poField.value) < parseInt(lMin) || parseInt(poField.value) > parseInt(lMax))
							{
								alert('Please supply a numeric value (between: ' + lMin + ' - ' + lMax +  ') for:\n"' + unHTML(getAttributeValue(poField, 'chrdesc')));
								poField.focus();
								mbValid = false;
								return '';
							}
						}
						return addBaseNode('attribute', poField.value, poField.name, sDatatypeId);
						break;
					// ============= date ================	
					case 'DATE':
												
						if (isEmpty(poField.value) && bRequired )
						{
							return isRequired(poField);	
						}
						
						if ( !isEmpty(poField.value))
						{
							if (isDate(poField.value))
							{	
								setXMLDate(poField)
																
								var lDate    = getAttributeValue(poField, 'sDate');
								var lMinDate = getAttributeValue(poField, 'datMinDate');
								var lMaxDate = getAttributeValue(poField, 'datMaxDate');

								if (!isBetweenDate(lDate, lMinDate, lMaxDate))
								{
									var sString = 'Please supply a valid date for : "' + sDesc + '"\n'
									if ( !isEmpty(lMinDate) )
										sString += 'after ' + convertXMLDateToString(lMinDate, 'date') + '\n';
									if ( !isEmpty(lMinDate) && !isEmpty(lMaxDate))
										sString += 'and '		
									if ( !isEmpty(lMaxDate) )
										sString += 'before ' + convertXMLDateToString(lMaxDate, 'date') + '\n';
									
									alert( sString );
									
									poField.focus();
									poField.select();
									mbValid = false;
									return '';
								}
								else
								{
									return addBaseNode('attribute', setXMLDate(poField), poField.name, sDatatypeId);
								}
							}
							else
							{
								alert('Please supply a valid date for "' + unHTML(getAttributeValue(poField, 'chrdesc'))  + '" - DD-MM-YYYY');
								poField.select();
								mbValid = false;
								return '';
							}							
						}
						else
						{
							return addBaseNode('attribute', '', poField.name, sDatatypeId);	
						}
						break;						
					case 'MAIL':
						
						if ( isEmpty(poField.value) && bRequired )
						{
							return isRequired(poField);	
						}
						
						if ( !validateMail(poField.value) && !isEmpty(poField.value))
						{
							alert('Please supply a valid e-mail address!');
							poField.select();
							mbValid = false;
							return '';
						}
						return addBaseNode('attribute', poField.value, poField.name, sDatatypeId);

					case 'FILE': 
						if ( isEmpty(poField.value) && bRequired )
						{
							return isRequired(poField);	
						}
						return addBaseNode('attribute', poField.xmlValue, poField.name, sDatatypeId);										
	
					default:								
						if ( isEmpty(poField.value) && bRequired )
						{
							return isRequired(poField);	
						}
						return addBaseNode('attribute', poField.value, poField.name, sDatatypeId);										
				}
				break;
			// ============ All select boxes ===============
			case 'select-one':
				if ( (poField.value < 0 || isEmpty(poField.value))  && bRequired )
				{
					return isRequired(poField);	
				}
				return addBaseNode('attribute', poField.value, poField.name, sDatatypeId);
				break;			
			case 'select-multiple':
						
				if (sDatatypeId == 'PICKLIST')
					return getReference(poField, false)
				else				
					return getReference(poField, true)
				break;
			// ============ All text areas ===============
			case 'textarea':					
				if (isEmpty(poField.value) && bRequired )
				{
					return isRequired(poField);	
				}
				return addBaseNode('attribute', poField.value, poField.name, sDatatypeId);
				break;
			default:
				return addBaseNode('attribute', poField.value, poField.name, sDatatypeId);
		}			
		return '';
	}
	
	// functions that collects and checks every field
	function getData()
	{		
		var oFormElements = moForm.elements;
		var sXML ='';
		var sValue ='';
						
		mbValid = true;
				
		if (oFormElements)
		{
			for (var i=0; i < oFormElements.length; i++)
			{					
				// ignore the checkboxes and radio buttons that are children of fieldsets
				if ( oFormElements[i].parentElement.type != 'fieldset')
				{										
					if (oFormElements[i].name)
					{
						switch ( oFormElements[i].name.toString() )
						{
							case 'objName':							
								
								sValue = oFormElements[i].value
								if (!isEmpty(sValue))
								{
									sXML += addTag('chrName', sValue);
								}
								else
								{
									return isRequired(oFormElements[i]);	
								}
								break;
							case 'objId':
								sXML += addTag('nbrNodeId', oFormElements[i].value);
								break;
							case 'nbrReferenceId':							
								break;		
							case 'entId':
								sXML += addTag('nbrNodeTypeId', oFormElements[i].value);
								break;
							default:
								if (oFormElements[i].name)
								{
									sXML += validateField( oFormElements[i] );
								}
						}
					}
				}
				
				if (mbValid == false)
				{
					return false;	
				}				
			}
		}		
		return sXML;
	}

	function getElement(plName)
	{	
		var oFormElements = moForm.elements;							
				
		if (oFormElements)
		{
			for (var i=0; i != oFormElements.length; i++)
			{
				if ( oFormElements[i].name.toString() == plName)
				{
					return oFormElements[i];
				}					
			}
		}		
		return;
	}		

	function submitText(psText)	
	{
    	var poReference = getElement("nbrReferenceId");

		var oForm = document.createElement("FORM");
		oForm.name = 'frmNode';
		oForm.method = 'post';
		oForm.action = msASPSave;
		oForm.target = msASPTarget;
		document.body.appendChild(oForm);
	
		var oTextBox = document.createElement("INPUT");
		oTextBox.name = "txtXML";
		oTextBox.type = "hidden";
		oTextBox.value = psText;
		oForm.appendChild(oTextBox);
		delete oTextBox;
	
		if (poReference)
		{
	     	var oTextBox = document.createElement("INPUT");
			oTextBox.name = "nbrReferenceId";
			oTextBox.type = "hidden";
			oTextBox.value = poReference.value;
			oForm.appendChild(oTextBox);
			delete oTextBox;
		}
		
		oForm.submit();
		delete oForm;
	}

//======================= XML tools ===================
	function addBaseNode(psTag, psValue, psID, psDTID, psPicklistId, psShow)
	{

		var sXML = '<' + psTag + ' id="' + psID + '" dt="' + psDTID + '"' 
		
		if (psPicklistId)
			sXML += ' nbrPicklistId="' + psPicklistId + '"'  
		
		if ( parseInt(psShow) == 1 )
			sXML += ' show="1"'

		if ( psDTID == 'FILE' )		
			sXML += '>' + psValue + '</' + psTag + '>'
		else
			sXML += '><![CDATA[' + psValue + ']]></' + psTag + '>'
	
		return sXML 
	}

	function addEmptyBaseNode(psTag, psValue, psID, psDTID, psPicklistId, psShow)
	{
		var sXML = '<' + psTag + ' id="' + psID + '" dt="' + psDTID + '"' 
		
		if (psPicklistId)
			sXML += ' nbrPicklistId="' + psPicklistId + '"'  
		
		if ( parseInt(psShow) == 1 )
			sXML += ' show="1"'


		if ( psDTID == 7 )
			sXML += '><upload><nbrResult>0</nbrResult></upload></' + psTag + '>'
		else
			sXML += '><![CDATA[]]></' + psTag + '>'
	
		return sXML 
	}


	function addTag(psTag, psValue)
	{
		return '<' + psTag +'><![CDATA[' + psValue + ']]></' + psTag + '>'
	}

//======================= tools ===================

	function setAttributeValue(poField, psName, psValue)
	{
		if (document.all)
		{	// IE
			return poField.setAttribute(psName, psValue);
		}
		else
		{	// NS
			var oAttribute = document.createAttribute(psName);
			oAttribute.value = psValue;
			poField.attributes.setNamedItem(oAttribute);			
		}
		return ;
	}

	function getAttributeValue(poField, psName)
	{		
		if (document.all)
		{	// IE
			return poField.getAttribute(psName);
		}
		else
		{	// NS
			for (var i=0; i < poField.attributes.length; i++)
			{						
				if (poField.attributes.item(i).name.toLowerCase() == psName.toLowerCase())
				{
					return poField.attributes.item(i).value;
				}			
			}			
		}
		return ;
	}

	function unHTML(sHTML)
	{
		if (!document.all)
		{
			return sHTML;
		}		
		var oAnchor = document.createElement("A")
		oAnchor.innerHTML = sHTML		
		return oAnchor.innerText;
	}

	function stripSpaces(theField)
	{    
		return theField.replace(/^\s*(.*)\b\s*$/, "$1");
	}
	
	//
	// Checks variable for lenght null if all white-space removed
	//
	function isEmpty(text)
	{
		var bEmpty
		
		if (text != null)
		{		
			bEmpty = (0 == stripSpaces(text).length);
		}
		else
		{
			bEmpty = true;
		}		
		return bEmpty;
	}
	
	function isBetweenDate(lDate, lMinDate, lMaxDate)
	{	//X has to be between A and Z
	
		var lX = lDate;
		var lA = lMinDate;
		var lZ = lMaxDate;
	
		if ((lDate >= lMinDate | lMinDate == 0 | lMinDate == null) & (lDate <= lMaxDate | lMaxDate == 0 | lMaxDate == null ))
			return true;
	
		return false;
	}

	
	function isDate(sDate)
	{
		//01-05-00
		//1-9-01
		//1-jan-2001
		var iDateMode = 0;
	
		if (sDate)
		{
			var iLength = sDate.length;
			var sChar;
			var sSeporator = '';
			var iMode = 0;
			
			var sFirst='';
			var sSecond='';
			var sThird='';
	
			if (iLength ==0)
			{
				return true;
			}
			
			for (var i=0; i<iLength; i++)
			{
				sChar = sDate.charAt(i);
	
				if (isNaN(sChar))
				{
					sSeporator = sChar;
					iMode += 1
				}
				else
				{
					switch(iMode)
					{
						case 0:
							sFirst += sChar;
							break;
						case 1:
							sSecond += sChar;
							break;
						case 2:
							sThird += sChar;
							break;
						default:
							return;
					}
				}
			}
			var bResult = true;
			
			switch (iDateMode)
			{
				case 1:
					bResult = (sFirst < 13)
					bResult = bResult && (sSecond < 32)
					break;
				default:
					bResult = (sFirst < 32)
					bResult = bResult && (sSecond < 13)
			}
			
			// Year
			bResult = bResult && (sThird.length == 4)
		}
		
		return bResult;
	}
	
	function setXMLDate(oThis)
	{
		var iDateMode = 0;
		
		if (oThis)
		{
			var sDate = oThis.value;
			var iLength = sDate.length;
			var sChar;
			var sSeporator = '';
			var iMode = 0;
	
			var sFirst='';
			var sSecond='';
			var sThird='';
	
			if (iLength ==0)
			{			
				oThis.sDate = '';
				return;
			}
	
			for (var i=0; i<iLength; i++)
			{
				sChar = sDate.charAt(i);
	
				if (isNaN(sChar))
				{
					sSeporator = sChar;
					iMode += 1
				}
				else
				{
					switch(iMode)
					{
						case 0:
							sFirst += sChar;
							break;
						case 1:
							sSecond += sChar;
							break;
						case 2:
							sThird += sChar;
							break;
						default:
							return;
					}
				}
			}
			
			var oDate;
			switch (iDateMode)
			{
				case 1:	//mm-dd-yyyy
					oDate = new Date(sThird, --sFirst, sSecond);
					break;			
				default: //dd-mm-yyyy
					oDate = new Date(sThird, --sSecond, sFirst);
			}
			
			var sDate = formatXMLDate(oDate)
			
			setAttributeValue(oThis, 'sDate', formatXMLDate(oDate))
			
			return sDate;
		}
	
	}
	function formatXMLDate(oDate)
	{
		if (oDate)
		{
			var iMonth = oDate.getMonth() + 1
			var iDay   = oDate.getDate();
			var sDay   = '';
			var sMonth = '';
	
			if (iDay < 10) {sDay = '0'};
	
			sDay += iDay.toString();
	
			if (iMonth < 10) {sMonth = '0'};
	
			sMonth += iMonth.toString();
	
			var sYear  = oDate.getFullYear();
		
			var sTime = formatNumber(oDate.getHours(), 2) + ':' + formatNumber(oDate.getMinutes(), 2) + ':' + formatNumber(oDate.getSeconds(), 2)
	
			var sXMLDate = sYear + '-' + sMonth + '-' + sDay + 'T' + sTime;
	
			return sXMLDate;
		}
	}
	
	function formatNumber(lNum, pos) 
	{		
		var sString = lNum.toString();
		for (var lTeller=0;lTeller < pos; lTeller++) 
		{
			sString = "0" + sString;
		}
		
		var lLength = sString.length;
		
		return sString.substring(lLength - pos);		
	}
	
	function convertXMLDateToNum(sDateIn)
	{
		sDateIn = sDateIn.replace(/T/i, " ");
		sDateIn = sDateIn.replace(/-/i, "/");
		sDateIn = sDateIn.replace(/-/i, "/");

		var dIn = new Date(sDateIn);

		if (isNaN(Date.parse(dIn.toGMTString())))
			return 0;

		return Date.parse(dIn.toGMTString());
	}

	function convertXMLDateToString(sDateIn, sFormat)
	{
		//iMode :0	dd-mm-yyyy (default)
		//iMode :1  mm-dd-yyyy
				
		//sFormat : 'date'     = date only
		//sFormat : 'datetime' = date and time
		
		var iDateMode = 0;
		
		if (!sDateIn)
			return '';
		
		if (!sFormat)
			sFormat = 'date'
		
		sDateIn = sDateIn.replace(/T/i, " ");
		sDateIn = sDateIn.replace(/-/i, "/");
		sDateIn = sDateIn.replace(/-/i, "/");
	
		var oDate = new Date(sDateIn);
	
		if (oDate) 
		{
			//Check if date is OK!!
			if (isNaN(Date.parse(oDate.toGMTString())))
				return '';
			var iMonth = oDate.getMonth() + 1;
			var iDay   = oDate.getDate();
			var sYear  = oDate.getFullYear();
			var sDay   = '';
			var sMonth = '';
			if (iDay < 10)
				{sDay = '0'};
			sDay += iDay.toString();
	
			if (iMonth < 10)
				{sMonth = '0'};
			sMonth += iMonth.toString();
	
			switch (iDateMode)
			{
				case 1:
					var sDateReturn = sMonth + '-' + sDay + '-' + sYear;
					break;			
				default:	
					var sDateReturn = sDay + '-' + sMonth + '-' + sYear;
			}
			
			switch (sFormat)
			{
				case 'datetime':
					var sHours = '';
					var sMinutes = '';
					
					if (oDate.getHours() < 10)
						{sHours = '0'};
					sHours += oDate.getHours().toString();
					
					if (oDate.getMinutes() < 10)
						{sMinutes = '0'};
					sMinutes += oDate.getMinutes().toString()
		
					sDateReturn += ' ' + sHours + ':' + sMinutes;
					break;
				default:
			}
		}
		else
			sDateReturn = '';
				
		return sDateReturn;
	}

	
	function isNumeric(poField, psMessage)
	{
		var checkOK = "-0123456789.,";
		var checkStr = poField.value;
		var allValid = true;
		var decPoints = 0;
		var allNum = "";
	
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
			allNum += ch;
		}
	
		if (!allValid)
		{
			alert(psMessage);
			poField.select();
			return (false);
		}
		return true;
	}
	
	function validateMail(sMail)
	{
		var firstPos   = sMail.indexOf("@");
		var lastPos    = sMail.lastIndexOf("@");
		var firstDot   = sMail.indexOf('.');
		var mailLength = sMail.length;
	
		if (mailLength < 6)
		{
			return false;
		}
		
		if (firstPos == -1 | firstPos != lastPos | firstPos == 0)
		{
			return false;
		}
	
		if (firstDot == -1|firstDot == 0|firstDot == (mailLength-1))
		{			
			return false;
		}
	
		if (checkSpace(sMail) == false)
		{
			return (false);
		}
		
		return true;
	}
	
	
	function checkSpace(sMail)
	{
	  var checkOK = " ";
	  var checkStr = sMail;
	  var allValid = true;
	  var decPoints = 0;
	  var allNum = "";
	
	  for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch != checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	    allNum += ch;
	  }
	
		return allValid;
	}


function openUpload(poForm, sName,plNodeId)
{
	moForm = poForm;
	
	var poField = getElement(sName)
	var url = '/upload/frmUpload.htm?nbr=' + poField.nbrMaxLen + '&NodeId=' + plNodeId;
	var windowName = '_blank'
	var params = '';
	
	var winHeight='140'
	var winWidth='300'
		
	var screenY = (screen.availheight - winHeight)  / 2;
	var screenX = (screen.availwidth - winWidth) / 2;

	params += "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=0,";
	params += "menubar=0,";
	params += "scrollbars=0,";
	params += "resizable=0,";
	params += "width=" + winWidth + ",";
	params += "height=" + winHeight + ",";
	params += "top=" + screenY +  ",";
	params += "left=" + screenX;

	oTextFile = poField;
	
	win = window.open(url, windowName, params);
}


function delUpload (poForm, sName)
{
	moForm = poForm;	
	
	var poField = getElement(sName);
	
	if (poField.value)
	{
		if (confirm('You are about to delete file:\n"' + poField.value + '"\nAre you sure ?')) // Geen id of confirm bij Netscape werkt ?
		{
		poField.xmlValue = "<upload><delete>TRUE</delete></upload>";	
		poField.value = "";
		}
	}
}

function downloadfile (sNodeId, sName)
{
	var oForm = document.createElement("FORM");
	oForm.name = 'modDownLoad';
	oForm.method = 'get';
	oForm.action = '/upload/DownLoad.asp';
	document.body.appendChild(oForm);

	var oTextBox = document.createElement("INPUT");
	oTextBox.name = "chrFileName";
	oTextBox.type = "hidden";
	oTextBox.value = sName;
	oForm.appendChild(oTextBox);
	delete oTextBox;
	
	var oTextBox = document.createElement("INPUT");
	oTextBox.name = "chrFileDir";
	oTextBox.type = "hidden";
	oTextBox.value = sNodeId;
	oForm.appendChild(oTextBox);
	delete oTextBox;

	oForm.submit();
	delete oForm;	
}			


function login(poForm, sUserName, sPassWord, sDatabase)
{
	moForm = poForm;	
	
	var poUsrNmField = getElement(sUserName);
	var poPwdField = getElement(sPassWord);
	var poDBField = getElement(sDatabase);
	
	if (!poUsrNmField.value)
	{
		poUsrNmField.focus()
		alert ('Enter your user name.')
		return false
	}

	if (!poPwdField.value)
	{
		poPwdField.focus()
		alert ('Enter your password.')
		return false
	}

	setCookie('chrUsername',poUsrNmField.value)
	
	moForm.submit()
}

function clearValue(poForm, oPickLists)
{	
	moForm = poForm
	var oFormElements = moForm.elements;							
			
	if (oFormElements)
	{
		for (var i=0; i != oFormElements.length; i++)
		{
			if ( oFormElements[i].name.toString() == oPickLists)
			{
				if (oFormElements[i].type == 'radio' || oFormElements[i].type == 'checkbox')
					oFormElements[i].checked=false;
				if (oFormElements[i].type == 'select-multiple')					
					oFormElements[i].selectedIndex = -1;
			}					
		}
	}		
	return;
}		

function setCookie(sName, sValue)
{
  document.cookie = sName + "=" + escape(sValue) + "; expires=Mon, 31 Dec 2050 23:59:59 UTC;path=/;";
}

// Retrieve the value of the cookie with the specified name.
function getCookie(psName)
{
  var sName;
  var sValue;

  // cookies are separated by semicolons
  var aCookie = document.cookie.split(";");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign

    var aCrumb = aCookie[i].split("=");

    sName  = aCrumb[0]
    sValue = unescape(aCrumb[1])

    if (stripSpaces(psName) == stripSpaces(sName))
    {	
	return sValue;
    }
  }

  // a cookie with the requested name does not exist return null;
  return ''
}

function initLogin()
{
	var sUserName =	getCookie('chrUsername')
	if (sUserName) 
	{
		frmLogin.chrUsrNm.value = sUserName		
		frmLogin.chrPwd.focus()
	}
	else
	{
		frmLogin.chrUsrNm.focus()
	}
}

function checkframe(id, lng)
{
	var sLanguage
	var lng
	
	if (lng == 0)
	{
	sLanguage = "&lng=En";
	}
	else
	{
	sLanguage = "&lng=Nl";
	}	

	


 	try
	{
		if (self != top)
		{
			//alert('in a frame');
			if (window.parent.document.body.innerHTML) { 
			//dit kan alleeen als domein hetzelfde is.. 
			} 

		}
		else
		{
		//alert('not in a frame');
		
		document.location="basis.asp?DLid="+id+sLanguage ;

		}
	}
	catch(er)
    {
		document.location="basis.asp?dlid="+id+sLanguage ;
    }
}

function checkframe2(id){

      var par, curloc, parloc, parfile;

      try{

            par = parent.document.location.host;

            parloc = par.substr(0,par.lastIndexOf("\/"));


            curloc = document.location.host;

            curloc = curloc.substr(0,curloc.lastIndexOf("\/"));


            if (!(parloc == curloc )) document.location="basis.asp?dlid="+id;

      }

      catch(er)

      {

            document.location="basis.asp?dlid="+id;

      }

}
