	var strValidDate = ' must be a valid date';
	var strValidTime = ' must be a valid time (e.g. 23:59 or 00:01:59 )';
	var strValidEmail = ' must be a valid email address (e.g. info@onlineprintsolutions.com)';
	var strValidDecimal = ' must be a decimal';
	var strValidCurrency = ' must be a number/decimal (e.g. 42.05 for £42.05)';
	var strValidPercent = ' must be a number/decimal (e.g. 10.5 for 10.5%)';
	
	var strValidNumber = ' must be a number';
	var strValidYear = ' must be a valid 4 digit year';
	var strValidDay = ' must be a valid day';
	var strValidMonth = ' must be a valid month (e.g enter 1 for Jan, 2 for Feb, 3 for March etc..)';
	
	var daysInMonth = makeArray(12);
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;   // must programmatically check this
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;


function ShowError(strControlName, strError)
{
	
	if (frm1.elements(strControlName).type.toLowerCase() != 'hidden')
	{
		frm1.elements(strControlName).focus();
	}

	alert(strError);
	return false;
	
}

function CheckDate(strControlName, strCaption, blnRequired)
{
	var strDay, strMonth, strYear

	strDay = frm1.elements(strControlName + 'day').value;
	strMonth = frm1.elements(strControlName + 'month').value;
	strYear = frm1.elements(strControlName + 'year').value;
	
	if (blnRequired == true)
	{
		if (strDay == '')
		{
			return ShowError(strControlName + 'day', strCaption + ' is required');
		}
		else if  (strMonth == '')
		{
			return ShowError(strControlName + 'month', strCaption + ' is required');
		}
		else if (strYear == '')
		{
			return ShowError(strControlName + 'year', strCaption + ' is required');
		}
	}
	else
	{
		if (strDay == '' && strMonth == '' && strYear == '')
		{
			return(true);
		}
		else
		{
			if (strDay == '')return ShowError(strControlName + 'day','Day missing');
			if (strMonth == '')return ShowError(strControlName + 'month','Month missing');
			if (strYear == '')return ShowError(strControlName + 'year','Year missing');
		}
	}
	
	if (isDate(strYear, strMonth, strDay) == false)
	{
	   alert(strCaption + ' ' + strValidDate);
	   return(false)
	}
	else
	{
	  return(true);
	}
	
	
}		

function CheckEntry(strControlName, strCaption, strDataType, intMaxLen, blnRequired)
{
	var s

	if ((strDataType == 'file') && (frm1.elements(strControlName) == null || frm1.elements(strControlName).value == ''))
	{
		strControlName = 'btn' + strControlName;
	}

	if (blnRequired == true)
	{
		if (frm1.elements(strControlName) == null || frm1.elements(strControlName).value == '')
		{
			return ShowError(strControlName, strCaption + ' is required');
		}
	}

	s = frm1.elements(strControlName).value;

	if (strDataType == 'date')
	{
		return isDate(frm1.elements(strControlName).item(2).value, frm1.elements(strControlName).item(1).value, s);
	}
	if (strDataType == 'day')
	{
		if (isDay(s) == false){return ShowError(strControlName, strCaption + strValidDay)} 	
	}
	
	if (strDataType == 'year')
	{
		if (isYear(s) == false){return ShowError(strControlName, strCaption + strValidYear)} 	
	}

	if (strDataType == 'month')
	{
		if (isMonth(s) == false){return ShowError(strControlName, strCaption + strValidMonth)} 	
	}
		
	if (strDataType == 'text')
	{
		if (blnRequired)		
		{
			
			if (isWhitespace(s)) {return ShowError(strControlName, strCaption + ' is required')}
		}
		
		if (intMaxLen < s.length)
		{
			return ShowError(strControlName, strCaption + ' has a maximum length of ' + intMaxLen + ' characters. You have entered ' + s.length + ' characters.');
		}
	}

	if (strDataType == 'number')
	{
		if (isInteger(s, !blnRequired) == false){return ShowError(strControlName, strCaption + strValidNumber)}
	}
	else if (strDataType == 'selectnumber')
	{
		if (isInteger(s, !blnRequired) == false){return ShowError(strControlName, 'Please select a ' + strCaption + ' from the list')}
	}
	else if (strDataType == 'decimal')
	{
		if (isFloat(s,!blnRequired) == false){return ShowError(strControlName, strCaption + strValidDecimal)}
	}
	else if (strDataType == 'currency')
	{
		if (isFloat(s,!blnRequired) == false){return ShowError(strControlName, strCaption + strValidCurrency)}
	}
	else if (strDataType == 'percent')
	{
		if (isFloat(s,!blnRequired) == false){return ShowError(strControlName, strCaption + strValidPercent)}
	}

	else if (strDataType == 'memo')
	{
		if (blnRequired) 
		{
			if (isWhitespace(s)) {return ShowError(strControlName, strCaption + ' is required')}
		}
		
	}
	else if (strDataType == 'date')
	{
		if (GetDate(s, !blnRequired) == false){return ShowError(strControlName, strCaption + strValidDate)}
		
	}
	else if (strDataType == 'time')
	{
		if (GetTime(s, !blnRequired) == false){return ShowError(strControlName, strCaption + strValidTime)}
		
	}
	else if (strDataType == 'email')
	{
		if (isEmail(s,!blnRequired) == false){return ShowError(strControlName, strCaption + strValidEmail)}		
	}	
	return(true);

}

function GetDate(s)
{
	var strDay
	var strMonth
	var strYear

   if (isWhitespace(s))
       if (GetDate.arguments.length == 1) return false;
       else return (GetDate.arguments[1] == true);
	
	if ((s.length < 10) || s.length > 11) return false;
	
	if (isWhitespace(s.substring(2,1))) 
	{
		intOffset = 0;
	}
	else
	{
		intOffset = 1;
	}

	strDay = s.substring(0,1+intOffset);

	if (s.substring(1+intOffset,2+intOffset) != ' ') return false;
	strMonth = s.substring(2+intOffset,5+intOffset).toLowerCase();
	if (s.substring(5+intOffset,6+intOffset) != ' ') return false;
	strYear = s.substring(6+intOffset,10+intOffset);

/*	if (strMonth == 'jan') strMonth = '1';
	else if (strMonth == 'feb') strMonth = '2';
	else if (strMonth == 'mar') strMonth = '3';
	else if (strMonth == 'apr') strMonth = '4';
	else if (strMonth == 'may') strMonth = '5';
	else if (strMonth == 'jun') strMonth = '6';
	else if (strMonth == 'jul') strMonth = '7';
	else if (strMonth == 'aug') strMonth = '8';
	else if (strMonth == 'sep') strMonth = '9';
	else if (strMonth == 'oct') strMonth = '10';
	else if (strMonth == 'nov') strMonth = '11';
	else if (strMonth == 'dec') strMonth = '12';
	else return false;
*/

	return isDate(strYear, strMonth, strDay)
}

function GetTime(s)
{

   var strHr
   var strMin
   var strSec
   var strSep
   
   if (isWhitespace(s)) 
       if (GetTime.arguments.length == 1) return false;
       else return (GetTime.arguments[1] == true);

	if ((s.length != 5) && (s.length != 8)) return false;

	strHr = s.substring(0,2);
	
	strSep = s.substring(2,3);
	if (strSep != ':') return false;
	
	strMin = s.substring(3,5);
	
	if (s.length == 8)
	{
		strSep = s.substring(5,6);	
		if (strSep != ':') return false;
		strSec = s.substring(6,8);
	}

	return isTime(strHr, strMin, strSec)
}

function isTime(strHr, strMin, strSec)
{   
	
    if (! (isHour(strHr, false) && isMin(strMin, false) && isSec(strSec, true))) return false;

    return true;
}

function isHour (s)
{

   if (isWhitespace(s)) 
       if (isHour.arguments.length == 1) return false;
       else return (isHour.arguments[1] == true);
       
    if ((parseInt(s) < 0) || (parseInt(s) > 23)) return false;
    return (s.length == 2)
}


function isMin (s)
{

   if (isWhitespace(s)) 
       if (isMin.arguments.length == 1) return false;
       else return (isMin.arguments[1] == true);
       
    if ((parseInt(s) < 0) || (parseInt(s) > 59)) return false;
    return (s.length == 2)
}

function isSec (s)
{

   if (isWhitespace(s)) 
       if (isSec.arguments.length == 1) return false;
       else return (isSec.arguments[1] == true);
       
    if ((parseInt(s) < 0) || (parseInt(s) > 59)) return false;
    return (s.length == 2)
}


function makeArray(n) {

   for (var i = 1; i <= n; i++) {this[i] = 0} 
   return this
}


function isInteger (s)

{   var i;

    if (isWhitespace(s)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    return true;
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isWhitespace(s)) 
       if (isFloat.arguments.length == 1) return false;
       else return (isFloat.arguments[1] == true);

    if (s == ".") return false;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if ((c == ".") && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    return true;
}


function isWhitespace (strCurrent)

{   var i;
	var whitespace = " \t\n\r";
	
    if (isEmpty(strCurrent)) return true;

    for (i = 0; i < strCurrent.length; i++)
    {   
        var c = strCurrent.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }
    
    return true;
}

function isEmpty(strCurrent)
{  
	return ((strCurrent == null) || (strCurrent.length == 0))
}

function isEmail (s)
{   if (isWhitespace(s)) 
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
   
    if (isWhitespace(s)) return false;

    var i = 1;
    var sLength = s.length;
    
    while ((i < sLength) && (s.charAt(i) != "@")) {i++}

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


function daysInFebruary (year)
{
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function isDate (year, month, day)
{   
	
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

function isYear (s)
{

   if (isWhitespace(s)) 
       if (isYear.arguments.length == 1) return false;
       else return (isYear.arguments[1] == true);
    if (parseInt(s) < 0) return false;
    return ((s.length == 2) || (s.length == 4));
}



function newisYear (s)
{

   if (isWhitespace(s)) 
       if (isYear.arguments.length == 1) return false;
       else return (isYear.arguments[1] == true);
	
	if (s.length != 4) return false;

	for (i = 0; i < s.length; i++){if (!isDigit(s.charAt(i))) return false}
}



function isMonth (s)
{   if (isWhitespace(s)) 
       if (isMonth.arguments.length == 1) return false;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}



function isIntegerInRange (s, a, b)
{   if (isWhitespace(s)) 
       if (isIntegerInRange.arguments.length == 1) return false;
       else return (isIntegerInRange.arguments[1] == true);

    if (!isInteger(s, false)) return false;

	s = RemoveLeadingZeros (s, '0')

    var num = parseInt (s);
    
    return ((num >= a) && (num <= b));
}

function RemoveLeadingZeros (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function isDay (s)
{   if (isWhitespace(s)) 
       if (isDay.arguments.length == 1) return false
       else return (isDay.arguments[1] == true); 
        
    return isIntegerInRange (s, 1, 31);
}


function HasSelected(strControlName, intUpper, blnRequired)
{
	var i

	for (i=0; i<intUpper; i++)
	{
		if (frm1.item(strControlName,i).checked)return true
	}
	
	if (blnRequired)
	{
		alert('Please select a ' + strControlName);
		return false;
	}
}


function AddOption(selTo, selFrom, strIDs, blnTo, strSep)
{
	var intIndex;

	intIndex=selFrom.selectedIndex;
	
	if (intIndex > -1)
	{
		//selTo.add(selFrom.item(intIndex));
		selTo[selTo.length] = new Option(selFrom.item(intIndex).text, selFrom.item(intIndex).value);
		selFrom.remove(intIndex);
		selFrom.selectedIndex=-1;
		if (selFrom.options.length==intIndex) {intIndex=intIndex-1}
		selFrom.selectedIndex=intIndex;
	}

	var strNewIds = '';	
	if (blnTo)
	{
		for (i=0; i<selFrom.options.length;i++)
		{			
			if (i>0){strNewIds=strNewIds + strSep};
			strNewIds=strNewIds + selFrom.item(i).value;
		}		
	}
	else
	{
		for (i=0; i<selTo.options.length;i++)
		{			
			if (i>0){strNewIds=strNewIds + strSep};
			strNewIds=strNewIds + selTo.item(i).value;				
		}
	}
	strIDs.value = strNewIds
}

	function OpenEd(strName)
	{
	    var winEd
			winEd = window.open("editor.asp?textbox=" + strName,"","width=440,height=350,toolbar=0,status=0,location=0,menubar=0,scrollbars=0,resizable=1");
			winEd.focus(); 
	}


function OpenLocator(strName)
{
	var winEd
	winEd = window.open(strName,"","width=600,height=600,toolbar=0,status=0,location=0,menubar=0,scrollbars=1,resizable=1");
	winEd.focus(); 
}

function FilterSelect(aryCur,cboxMain)
{
 var cboxCur;
 var intIndex;
 
  intIndex = cboxMain.selectedIndex;
  
  for (var i = 1; i<= aryCur[1].length; i++)
  {
    cboxCur = frm1.elements(aryCur[1][i-1]);
    
    while (cboxCur.options.length > 0)cboxCur.remove(0);
    if (intIndex != 0)
      for (var j = 0; j<aryCur[i+1][intIndex].length; j=j+2)
        cboxCur[cboxCur.length] = new Option(aryCur[i+1][intIndex][j+1],aryCur[i+1][intIndex][j]);
  }  
}