function Trim(s) 
{
  while (s.substring(0,1) == ' ') 
    s = s.substring(1,s.length);
  while (s.substring(s.length-1,s.length) == ' ') 
    s = s.substring(0,s.length-1);
  return s;
}

function OutBoundLink(message) {
  return confirm(message);
}

function CookieWarning(item){
	if (item.checked){
	alert("Please take note that when this checkbox is checked, your login details will be available to anyone using your PC.");
    }
}

function Confirmation(form,message) {
  if (confirm(message))
  {
    form.submit();
  }  
}

function checkcomb(form,title) 
{
	var result=true;
	var missinginfo = title;
	for (var i=0; i<form.elements.length; i++) 
	{						
		var validateType = form.elements[i].getAttribute('alt');
		var validateObj = form.elements[i];
		if (validateType)
		{
			var params = validateType.split("|");
			for (var j=0;j<params.length;j++)
			{
				switch (params[j]) 
				{
				case 'COMB' : 
					var combineObjs = validateObj.getAttribute('combine');
					var combineObj = combineObjs.split("|");
					result = false;
					for (var k=0;k<combineObj.length;k++)
					{
						var x = combineObj[k];
						for (var l=0;l<form.elements.length;l++)
							if (x == form.elements[l].name)
								if (form.elements[l].value != 0)
									result = true;	
					}
					if (!result)
						missinginfo += "\n     -  " + validateObj.getAttribute('emsg') ;
					break;
				}
				if (!result) 
					break;
			}
		}	
	}

	if (result)
		form.submit();
	else
		alert(missinginfo);		
	return false;
}

function checkform(form,title) 
{
	var result=true;
	var nosubmit=false;
	var missinginfo = title;
	var confirmation = 'Are your sure you wish to continue?';
	for (var i=0; i<form.elements.length; i++) 
	{						
		var validateType = form.elements[i].getAttribute('alt');
		var validateObj = form.elements[i];
		if (validateType)
		{
			var params = validateType.split("|");
			for (var j=0;j<params.length;j++)
			{
				switch (params[j]) 
				{
				case 'NOSUBMIT' :
					{
						nosubmit = true;
						confirmation = validateObj.getAttribute('emsg') ;
					} break;
				case 'ZERO' : if (Trim(validateObj.value) == 0)
					{
					missinginfo += "\n     -  " + validateObj.getAttribute('emsg') ;
					if (result) validateObj.focus();
					result = false;
					} break;
				case 'NUMERIC' : if (isNaN(validateObj.value) || (Trim(validateObj.value) == '') )
					{
					missinginfo += "\n     -  " + validateObj.getAttribute('emsg') ;
					if (result) validateObj.focus();
					result = false;
					} break;

				case 'BLANK' : if (Trim(validateObj.value) == '')
					{
					missinginfo += "\n     -  " + validateObj.getAttribute('emsg') ;
					if (result) validateObj.focus();
					result = false;
					} break;
				case 'EMAIL' : 
					var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
				    if ((validateObj.value == '') || (validateObj.value == ' ') ||!re_mail.test(validateObj.value) )
					{
					missinginfo += "\n     -  " + validateObj.getAttribute('emsg') ;
					if (result) validateObj.focus();
					result = false;
					} break;
					
				case 'RANGE' : 
					var lb = parseInt(validateObj.getAttribute('mini'));
					var ub = parseInt(validateObj.getAttribute('maxi'));
					if (isNaN(validateObj.value) || (validateObj.value < lb) || (validateObj.value > ub))
					{
					missinginfo += "\n     -  " + validateObj.getAttribute('emsg') ;
					if (result) validateObj.focus();
					result = false;
					} break;
				case 'COMB' : 
					var combineObjs = validateObj.getAttribute('combine');
					var combineObj = combineObjs.split("|");
					result = false;
					for (var k=0;k<combineObj.length;k++)
					{
						var x = combineObj[k];
						for (var l=0;l<form.elements.length;l++)
							if (x == form.elements[l].name)
								if (form.elements[l].value != 0)
									result = true;	
					}
					if (!result)
						missinginfo += "\n     -  " + validateObj.getAttribute('emsg') ;
					break;					
				}	
				if (!result) break;
			}
		}	
	}
	if (result)
	{
		if (!nosubmit)
			form.submit();
		else
		{
		    //requires confirmation
			if (confirm(confirmation))
			{
				form.submitted = true;
				form.submit();
			}
			return true;
		}	
	}		
	else
		alert(missinginfo);		
	return false;
}

