
function isEmpty(value2check)
{
	if (value2check == "" || value2check == null)
	{
		return true;
	}
	//nice bit of regexp!
	var nonSpaceCharacters = /\w/;
	hasCharacters = nonSpaceCharacters.exec(value2check);
	
	if (hasCharacters == null)
	{
		return true;
	}
	
	return false;
}

// ---

function integerInRange(checkValue)
{
	if (checkValue < -2147483648 || checkValue > 2147483647)
	{
		return false;
	}
	return true;
}

// ---

function isInteger(checkValue)
{
	if (isNaN(checkValue))
	{
		return false;
	}
	if(parseInt(checkValue) != checkValue)
	{
		return false;
	}
	if(!integerInRange(checkValue))
	{
		alert("The value is out of acceptable range (-2,147,483,648 to 2,147,483,647)")
		alerted = true;
		return false;
	}	
	return true;
}

// ---

function isPositive(checkValue, integer)
{
	if (isNaN(checkValue))
	{
		return false;
	} 
	if(checkValue < 0)
	{
		return false;
	}
	if(checkValue.length < 1)
	{
		return false;
	}
	if(integer)
	{
		if(parseInt(checkValue) != checkValue)
		{
			return false;
		}
	}
	if(!integerInRange(checkValue))
	{
		alert("The value is out of acceptable range (-2,147,483,648 to 2,147,483,647)")
		alerted = true;
		return false;
	}
	return true;
}

// ---

function openWindow(url,height,width,winObj)
{
	intWidth = width	
	intHeight = height
	if (navigator.appName=="Netscape")
	{
		intTopDiff=(screen.height/10);
	 	intXPos=(screen.width/2)-(intWidth/2);
	 	intYPos=((screen.height/2)-(intHeight/2))-intTopDiff;

	}
	else
	{
	 	intXPos=(screen.availWidth/2)-(intWidth/2);
	 	intYPos=(screen.availHeight/2)-(intHeight/2);
	}
	intXPos=intXPos>0?intXPos:0;
	intYPos=intYPos>0?intYPos:0;
	strProperties="location=no,menubar=no,resizable=yes,status=no,toolbar=no,titlebar=no,directories=no,scrollbars=yes,toolbar=0,screenX="+intXPos+",left="+intXPos+",screenY="+intYPos+",top="+intYPos+",width="+intWidth+",height="+intHeight;
	winObj=window.open(url,"" + winObj + "",strProperties);
	winObj.focus();
}

// ---

function openWindowWithMenu(url,height,width,winObj)
{
	intWidth = width	
	intHeight = height
	if (navigator.appName=="Netscape")
	{
		intTopDiff=(screen.height/10);
	 	intXPos=(screen.width/2)-(intWidth/2);
	 	intYPos=((screen.height/2)-(intHeight/2))-intTopDiff;
	}
	else
	{
	 	intXPos=(screen.availWidth/2)-(intWidth/2);
	 	intYPos=(screen.availHeight/2)-(intHeight/2);
	}
	intXPos=intXPos>0?intXPos:0;
	intYPos=intYPos>0?intYPos:0;
	strProperties="location=no,menubar=yes,resizable=yes,status=no,toolbar=no,titlebar=no,directories=no,scrollbars=yes,toolbar=0,screenX="+intXPos+",left="+intXPos+",screenY="+intYPos+",top="+intYPos+",width="+intWidth+",height="+intHeight;
	winObj=window.open(url,"" + winObj + "",strProperties);
	winObj.focus();
}

// ---

function validateDate(dateIn,monthIn,yearIn, strName)
{
	if (parseInt(yearIn, 10)  < 1753)
	{
		alert("You've entered a year earlier than 1753. Unfortunately we can only support dates after 1753, because this is when the Gregorian and Julian calendars were synchronized! Please re-enter a more recent date.")
		return false;
	}
	if( isNaN(dateIn) || isNaN(monthIn) || isNaN(yearIn))
	{
		alert("Part of your date " + strName + " is not in the right format (dd/mm/yyyy)");
		return false;
	}
	if (dateIn.length==1)
	{
		dateIn = "0" + dateIn;
	}
	if (monthIn.length==1)
	{
		monthIn = "0" + monthIn;
	}
	var textStr = dateIn+"/"+monthIn+"/"+yearIn;
	
	var chkDate=new Date();
	
	if(dateIn.indexOf("0") == 0)
	{
		dateIn = dateIn.substring(1);
	}

	if(monthIn.indexOf("0") == 0)
	{
		monthIn = monthIn.substring(1);
	}
	
	chkDate.setMonth((parseInt(monthIn)-1),(parseInt(dateIn)));
	chkDate.setFullYear(parseInt(yearIn));
	
	var chkMonthInt  = chkDate.getMonth()+1;
	var chkMonthStr = chkMonthInt+"/";
	if (chkMonthStr.length == 2)
	{
		chkMonthStr = "0"+chkMonthStr;
	} 
	
	var chkDateInt = chkDate.getDate();
	var chkDateStr = chkDateInt+"/";
	if (chkDateStr.length == 2)
	{
		chkDateStr = "0"+chkDateStr;
	}

	var cmpDate=chkDateStr+chkMonthStr+(chkDate.getFullYear());
	
	if (cmpDate.length != 10)
	{
		alert("You've entered a " + strName + " that does not exist or used an invalid date format.\n\nPlease use the dd/mm/yyyy format.");
		return false;
	}
	else
	{
		if (textStr!=cmpDate)
		{
			alert("You've entered a " + strName + " that does not exist or used an invalid date format.\n\nPlease use the dd/mm/yyyy format.");
			return false;
		}
		else
		{
			if (cmpDate=="NaN/NaN/NaN")
			{
				alert("You've entered a " + strName + " that does not exist or used an invalid date format.\n\nPlease use the dd/mm/yyyy format.");
				return false;
			}
		}
	}
	return true;
}

// ---

function setValue(formName, formItem, value)
{
	objField = eval('document.forms["' + formName + '"].elements["' + formItem +'"]');
	if (objField)
	{
		for (i=0; i < objField.options.length; i++)
		{
			if (objField.options[i].value == value)
			{
				objField.options[i].selected = true	
			}
		}
	}
}

// ---

function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g, "");
	
	if (isNaN(num))
	{
		alert(num + " : This is not a valid number");
		return( "0" );
	}
	
	if (num.length < 1)
	{
		return( "" );
	}
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if (cents < 10)
	{
		cents = "0" + cents;
	}
	
	return( num + "." + cents );
}

// ---
	
function strReplace(originalString, searchText, replaceText)
{

	var strLength = originalString.length;
	var txtLength = searchText.length;

	if ((strLength == 0) || (txtLength == 0))
	{
		return( originalString );
	}

	var i = originalString.indexOf(searchText);

	if ((!i) && (searchText != originalString.substring(0, txtLength)))
	{
		return( originalString );
	}

	if (i == -1)
	{
		return( originalString );
	}

	var newStr = originalString.substring(0, i) + replaceText;

	if (i+txtLength < strLength)
	{
		newStr += strReplace(originalString.substring(i+txtLength, strLength), searchText, replaceText);
		return( newStr );
	}

}

// ---

function performAction(inStr)
{
	if (inStr != "null")
	{
		eval(inStr);
	}
}

// ---

function isValidFileType( strFileName, arrExt )
{
	if (!strFileName.length)
	{
		return( false );
	}
	
	strFileName = strFileName.toLowerCase();
	
	for ( var j=0; j<arrExt.length; j++ )
	{
		if ( strFileName.substring( strFileName.length, strFileName.indexOf( arrExt[j].toLowerCase() ) ) == arrExt[j].toLowerCase() )
		{
			return( true );
		}
	}
	
	return( false );
}