function trim(inputString) 
	{
	   // Removes leading and trailing spaces from the passed string. Also removes
	   // consecutive spaces and replaces it with one space. If something besides
	   // a string is passed in (null, custom object, etc.) then return the input.
	   if (typeof inputString != "string") 
	   { 
		return inputString; 
	   }
	   var retValue = inputString;
	   var ch = retValue.substring(0, 1);
	   while (ch == " ") 
	   { // Check for spaces at the beginning of the string
	      retValue = retValue.substring(1, retValue.length);
	      ch = retValue.substring(0, 1);
	   }
	   ch = retValue.substring(retValue.length-1, retValue.length);
	   
	   while (ch == " ") 
	   { // Check for spaces at the end of the string
	      retValue = retValue.substring(0, retValue.length-1);
	      ch = retValue.substring(retValue.length-1, retValue.length);
	   }
	   
	   while (retValue.indexOf("  ") != -1) 
	   { // Note that there are two spaces in the string - look for multiple spaces within the string
	      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	   }
	   return retValue; 
	} 

function checkXMLName(psName)
{
	var xmlName = new ActiveXObject( "Microsoft.XMLDOM" );
		
	//XML Tag name validation !!
	try
	{
		xmlName.createElement(psName);
	}
	catch(e)
	{		
		return e.description;
	}
	return null;	
}



function downLoadFile()
{
	if(modDownLoad)
	{
		var Oform
		var OformLength
		var sformValue

		Oform = modDownLoad

		sformValue = ''

	 	OformLength = Oform.elements.children.length

		for(i=0;i<OformLength-1;i++)
		{
			sformValue = sformValue + Oform.elements.children(i).name + "="+ Oform.elements.children(i).value + "&"
		}
			sformValue = sformValue + Oform.elements.children(OformLength-1).name + "="+ Oform.elements.children(OformLength-1).value;

		var url = Oform.action + '?' + sformValue
		var windowName = "Downloading"
		var params = '';
		var sizeX = 340
		var sizeY = 160
		var screenY = (screen.availheight-sizeY) / 2;
		var screenX = (screen.availwidth-sizeX) / 2;

		params += 'toolbar=0,';
		params += 'location=0,';
		params += 'directories=0,';
		params += 'status=0,';
		params += 'menubar=0,';
		params += 'scrollbars=1,';
		params += 'resizable=1,';
		params += 'width=' + sizeX + ',';
		params += 'height=' + sizeY + ',';
		params += 'top=' + screenY +  ',';
		params += 'left=' + screenX;

		window.open(url, windowName, params);
	}
}

function setDecimale(oValue, iCount)
{
	var LenChrValue = oValue.length
	var LenNumValue = parseInt(oValue).toString().length
	
	var iDiff = LenChrValue - LenNumValue - 1
	
	if (iDiff > iCount)
		return (true);
	else
		return (false);
}

function lt(a, b)
{
	if (parseInt(a) < parseInt(b))
		return true;
	else
		return false;
}

function getLayer(psNameframe, psNameLayer) {
  
  return eval('top.frames.' + psNameframe +'.document.all.' + psNameLayer);
}

function showLayer(oLayer) 
{
	oLayer.style.visibility="visible";
	oLayer.style.zIndex += 1;
}
function hideLayer(oLayer) 
{
	oLayer.style.visibility="hidden";
	oLayer.style.zIndex = 0;		
}

function moveLayer(oLayer, lTop, lLeft) 
{
	if (oLayer)
	{
		oLayer.style.top=lTop;
		oLayer.style.left=lLeft;
	}
}

function parseHTML()
{
	//check if there is/are descriptions tags!!
	var oDescTag = document.getElementById('descriptions')
	
	if (oDescTag != null)
	{		
		var iLen = descriptions.length;
		var oDesc;
		
		if(iLen)
		{		
			for (var i=0; lt(i,descriptions.length); i++) 
			{
				oDesc = descriptions[i];
				if (oDesc.chrDesc)
				{	
					oDesc.innerHTML = oDesc.chrDesc + oDesc.innerHTML;
				}
			}
		}
		else
		{
			descriptions.innerHTML = descriptions.chrDesc;				
		}
	}
}

function slideWindow(plPos, sTag, sFilter)
{
	if (!document.XMLDocument)
	{
		//ie5.5 heeft soms geen 'document.XMLDocument' dan zit er niks anders op dan te refreshen
		location.reload();
		return false;
	}
	
	var vAlphabet = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	var sCriteria = "//" + sTag 
	var lPos = parseInt(plPos);
	
	if (!sFilter)
		sFilter = "chrName"
	
	switch (lPos)
	{
		case null: // return all
			break;
		case -1: // return all
			break;
		case -2: // return all For last selection
			break;
		case 0:	 //All non alphanumeric characters
			sCriteria += "[" + sFilter + " < 'A' or " + sFilter + " > 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZ']" 
			break;		
		case 26: //All that start with Z....
			sCriteria += "[" + sFilter + " >= 'Z' and " + sFilter + " < 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZ']"
			break;
		default: //all that starts with the selected char				
			sCriteria += "[" + sFilter + " < '" + vAlphabet.charAt(lPos+1) + "' and " + sFilter + " >= '" + vAlphabet.charAt(lPos) + "']" 
	}
			
	var oWindow = document.XMLDocument.selectNodes(sCriteria);
	
	xmlWindow.loadXML("<facade></facade>")
	
	for (i=0;i != oWindow.length;i++)
	{
		xmlWindow.documentElement.appendChild(oWindow(i).cloneNode(true))
	}
		
	xslTarget.innerHTML = xmlWindow.transformNode(styleREP.XMLDocument);

	return lPos;
}

function setIndex(poTable, plPos)
{
	var i;
	var lPos = parseInt(plPos);	
	var oTD = poTable.getElementsByTagName("TD");

	for (i = 0;i<oTD.length;i++)
  	{
  		if (oTD(i).firstChild)
  		{
	  		if (oTD(i).id == lPos)
	  		{
	  			oTD(i).firstChild.className = "cIndexSelected";
	  		}
	  		else
	  		{
	  			oTD(i).firstChild.className = "cIndex";
	  		}
	  	}
	}
}

function setCookie(sName, sValue)
{
  document.cookie = sName + "=" + escape(sValue) + "; expires=Mon, 31 Dec 2999 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 stripSpaces(theField) 
{    
	return theField.replace(/^\s*(.*)\b\s*$/, "$1");
}



function ResizeAllPics()
{ 
	var oPic = document.all.tags('IMG');
	for (var i=0; i<oPic.length; i++)
	{
		if (oPic[i].OrgSize == '0')
		{
			PicSize(oPic[i])
		}
	}
}


function PicSize(oPic)
{
	if (oPic)
	{
		var WinFrameSize	= document.body.clientWidth;
		var firstTDSize		= tabIndicators.firstChild.firstChild.firstChild.clientWidth
		var lastTDSize		= WinFrameSize - firstTDSize - 54
		var oPicSize		= oPic.clientWidth

		if (oPic.OrgSize == '0')
			oPic.OrgSize = oPic.clientWidth

		if ((lastTDSize > 50) && (oPic.OrgSize > lastTDSize))
			oPic.width = lastTDSize
	}
}

function ImgErr(oTD)
{
	oTD.onmouseover = ''
	oTD.onmouseout = ''
//	oTD.innerHTML = '<font color="red"><strong>File was not uploaded correctly.</strong></font>'
	oTD.innerHTML = '<font color="red"><strong>File cannot be displayed.</strong></font>'
}


function ResizeImage(oPic, iSize)
{
	if (oPic)
		if (iSize)
		{
			var ConsPixValue = 15
			var oPicSize = oPic.clientWidth

			if (oPic.OrgSize == '0')
				oPic.OrgSize = oPic.clientWidth

			switch(iSize)
			{
				case '0': // make it smaller
					oPic.width = oPicSize - ConsPixValue;
					break;					
				case '1': // make it bigger
					oPic.width = oPicSize + ConsPixValue;
					break;
				case '2': // make it actual size
					oPic.width = oPic.OrgSize;
					break;
				default:
					break;
			}
		}
}


function openAbout()
{
	var url= '/about/frmAbout.htm';	
	var params = '';

	params += "status:0;";
	params += "center:1;";
	params += "help:0;";	
	params += "resizable:0;";
	params += "dialogWidth:22;";
	params += "dialogHeight:17";
	
	window.showModalDialog(url, "", params );
}


function openCalendar(poDateField, pbToday)
{
	var url= '/cal/frmcalendar.htm';
	var params = '';
	var sXMLDate = '';

	

	if (!poDateField.value.match('Today')) // For user manual setting
		{
			setXMLDate(poDateField);
		 	sXMLDate = poDateField.sDate;
	 	}
	 else
	 	{
			sXMLDate = 'today';	
	 	}
	
	if ( !isDate(poDateField.value) )
	{
		sXMLDate = 'today';	
	}
	
	if (pbToday == true)
		url += "?today"

	params += "status:0;";
	params += "center:1;";
	params += "help:0;";	
	params += "resizable:0;";
	params += "dialogWidth:13.3;";
	params += "dialogHeight:14.5";

	var lsDate = window.showModalDialog(url, sXMLDate, params);

	if (lsDate)
		{
		poDateField.sDate = lsDate;
		getLDate(poDateField);
		}		
}

function openQueryName(poQueryName)
{
	var url= '/report/frmQuery.htm';		
	var params = '';
	
	params += "status:0;";
	params += "center:1;";
	params += "help:0;";	
	params += "resizable:0;";
	params += "dialogWidth:10.1;";
	params += "dialogHeight:8.5";
	
	var sQueryName = window.showModalDialog(url, "", params );
	
	poQueryName.value = sQueryName;

}


function openUpload(poField,plNodeId)
{

	var url = '/upload/frmUpload.htm?nbr=' + poField.nbrMaxLen + '&NodeId=' + plNodeId;
	var windowName = '_blank'
	var params = '';

	var sizeX = 300;
	var sizeY = 113;
	var screenY = (screen.availheight-sizeY)/2;
	var screenX = (screen.availwidth-sizeX)/2;

	params += 'toolbar=0,';
	params += 'location=0,';
	params += 'directories=0,';
	params += 'status=0,';
	params += 'menubar=0,';
	params += 'scrollbars=0,';
	params += 'resizable=0,';
	params += 'width=' + sizeX + ',';
	params += 'height=' + sizeY + ',';
	params += 'top=' + screenY +  ',';
	params += 'left=' + screenX;

	oTextFile = poField;
	
	win = window.open(url, windowName, params);
}

function openHelp(poField,plNodeId)
{

	var url = '/help/default.htm';
	var windowName = '_blank'
	var params = '';
		
	params += "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=1,";
	params += "menubar=0,";
	params += "scrollbars=1,";
	params += "resizable=1,";
	params += "center=1";
	
	win = window.open(url, windowName, params);
}

function getLDate(oThis)
{			
	if (oThis.sDate)
	{
		if (oThis.sDate == 'today')
			oThis.innerText = 'Today'
		else 
			oThis.innerText = convertXMLDateToString(oThis.sDate.substr(0,19), oThis.dt) ;
	}	
	return;
}

function isDate(sDate)
{
	//01-05-00
	//1-9-01
	//1-jan-2001
	var iDateMode = getDateMode();
	
	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 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 = getDateMode();
	
	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 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 getDateMode()
{
	var lDF = getCookie('dateformat');
	return parseInt(lDF);
}
function setDateMode(lDateFormat)
{
	setCookie('dateformat', lDateFormat);
	return;
}

function setXMLDate(oThis)
{
	var iDateMode = getDateMode();
	
	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);
		}		
		
		oThis.sDate = formatXMLDate(oDate);
	}

}


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 sXMLDate = sYear + '-' + sMonth + '-' + sDay + 'T00:00:00';

		return sXMLDate;
	}
}

function fVerifyMe(sMessage)
{
	return confirm(sMessage);
}

function showAndPositionDiv(poDiv, plX, plY)
{
		if (!plX)	
		{
			plX = event.clientX;
		}
		else
		{
			plX = parseInt(plX)
		}
		
		if (!plY)
		{
			plY = event.clientY;
		}
		else
		{
			plY = parseInt(plX);
		}
		
		//Make VISIBLE
		// y position of div
		if ((document.body.clientHeight) >= (poDiv.clientHeight))
		{
			// the poDiv box is at the bottom of the window
			// check the height of poDiv-box.
			if (((document.body.clientHeight)-(plY)- 17) <= (poDiv.clientHeight))
			{
				// the height of poDiv-box is more than the distance between the mouse-pointer and the bottom of window
				if ((plY + document.body.scrollTop  - 17 - poDiv.clientHeight) >= 0)
					// check the height of poDiv-box
				{
					// the height is OK
					poDiv.style.pixelTop  = plY + document.body.scrollTop  - 17 - poDiv.clientHeight
				}
				else
				{
					// the poDiv-box height is more than window
					poDiv.style.pixelTop  = document.body.scrollTop - 5
				}
			}
			else
			{
				// the normal size and manner of poDiv-box
				poDiv.style.pixelTop  = plY + document.body.scrollTop  + 17
			}
		}
		else
		{
			poDiv.style.pixelTop  = document.body.scrollTop - 5
		}

		// x position of poDiv-box
		if ((document.body.clientWidth) >= (poDiv.clientWidth))
		{
			// the poDiv box is at the right-side of the window
			// check the width of poDiv-box.
			if (((document.body.clientWidth)-(plX)- 80) <= (poDiv.clientWidth))
			{
				// the width of poDiv-box is bigger than the distance between the mouse-pointer and the right-side of window
				if ((plX + document.body.scrollLeft - 80 - poDiv.clientWidth) <= 0)
					// check the width of poDiv-box
				{
					// the Width is OK
					poDiv.style.pixelLeft = plX + document.body.scrollLeft - 80
				}
				else
				{
					// the poDiv-box width is bigger than window
					poDiv.style.pixelLeft = plX + document.body.scrollLeft - poDiv.clientWidth
				}
			}
			else
			{
				// the normal size and manner of poDiv-box
				if (plX > poDiv.clientWidth)
				{
					poDiv.style.pixelLeft = plX + document.body.scrollLeft - 80
				}
				else
				{
					poDiv.style.pixelLeft = plX + document.body.scrollLeft
				}
			}
		}
		else
		{
			poDiv.style.pixelLeft = document.body.clientWidth - poDiv.clientWidth 
		}
		
		poDiv.style.visibility = 'visible'
}


	function inDiv(poElement, oDiv)
	{
		var loElement = poElement;
		var sDivName = oDiv;
				
		while (loElement.id != sDivName && loElement.tagName != 'BODY')
		{
			loElement = loElement.parentElement;			
		}
		
		return (loElement.id == sDivName)		
	}

function isNum(checkStr)
{

	var checkOK = "-0123456789";	
	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;		
}
		

