﻿function fnDisplayMessage(p_strMessage) {
	if (p_strMessage.length > 0) alert(p_strMessage);
}

function fnValidateKeypress(p_regExp, p_txt) {
	var regValidCharacters = new RegExp(p_regExp, "g");
	var intKeyCode = event.keyCode;
	
	if ((intKeyCode != 8) && (intKeyCode != 9) && (!regValidCharacters.test(String.fromCharCode(intKeyCode)))) {
		event.cancelBubble = true;
		return false;
	}
	
	return true;
}

function chkDate(objName)
{
	var dateField = objName;
	var strDate;
	var strDateArray;
	var strMonth;
	var strDay;
	var strYear;
	var intMonth;
	var intDay;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-","/");
	var intElementNr;
	
	strDate = dateField.value;
	
	if (strDate.length == 0) return true;
	
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++)
	{
	
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1)
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
	
			if (strDateArray.length != 3)
			{
				alert("Date is invalid.\r\nPlease enter in MM/DD/YYYY format.");
				
				return false;
			}
			else
			{
				strMonth = strDateArray[0];
				strDay = strDateArray[1];
				strYear = strDateArray[2];
			}
	
			booFound = true;
		}
	}
	
	if (booFound == false)
	{
		alert("Date is invalid.\r\nPlease enter in MM/DD/YYYY format.");
		
		return false;
	}
	
	if (strYear.length != 4)
	{
		alert("Year must be 4 digits.\r\nPlease enter in MM/DD/YYYY format.");
		
		return false;
	}
	
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth))
	{
		alert("Month portion of date is not numeric.\r\nPlease enter in MM/DD/YYYY format.");
		
		return false;
	}
	
	intDay = parseInt(strDay, 10);
	if (isNaN(intDay))
	{
		alert("Day portion of date is not numeric.\r\nPlease enter in MM/DD/YYYY format.");
		
		return false;
	}
	
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear))
	{
		alert("Year portion of date is not numeric.\r\nPlease enter in MM/DD/YYYY format.");
		
		return false;
	}
	else if (intYear <= 1753) {
		alert("Year portion of date after 1753.");
		
		return false;
	}
	
	if (intMonth > 12 || intMonth < 1)
	{
		if (!displayErrorMsg("Month must be between 1 and 12.\r\nPlease enter in MM/DD/YYYY format."))
			return false;
	}
	
	if (intDay < 1 || intDay > 31)
	{
		if (!displayErrorMsg("Day must be between 1 and 31.\r\nPlease enter in MM/DD/YYYY format."))
			return false;
	}
	
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intDay > 30))
	{
		alert("The specified month cannot contain more than 30 days.\r\nPlease enter in MM/DD/YYYY format.");
		
		return false;
	}
	
	if (intMonth == 2)
	{
		if (LeapYear(intYear) == true)
		{
			if (intDay > 29)
			{
				alert("February cannot contain more than 29 days in a leap year.\r\nPlease enter in MM/DD/YYYY format.");
				
				return false;
			}
		}
		else
		{
			if (intDay > 28)
			{
				alert("February cannot contain more than 28 days in a non leap year.\r\nPlease enter in MM/DD/YYYY format.");
				
				return false;
			}
		}
	}
	
	if (strMonth.length == 1)
	{
		strMonth = '0' + strMonth
	}
	if (strDay.length == 1)
	{
		strDay = '0' + strDay;
	}
	
	dateField.value = strMonth + '/' + strDay + '/' + strYear;
	
	return true;
}

// leap year must be divisable by 4, 100, and 400
function LeapYear(intYear)
{
	if (intYear % 100 == 0)
	{
		if (intYear % 400 == 0) return true;
	}
	else
	{
		if ((intYear % 4) == 0) return true;
	}
	return false;
}

		
function fnStringSort(p_strLeft, p_strRight) {
	if (p_strLeft < p_strRight) return -1
	if (p_strLeft > p_strRight) return 1
	return 0;
}

// correctly handle PNG transparency in Win IE 5.5 & 6.
function correctPNG() {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	
	if ((version >= 5.5) && (document.body.filters)) {
		for(var i=0; i< document.images.length; i++) {
			var img = document.images[i];
			var imgName = img.src.toUpperCase();
			
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
				var imgID = (img.id) ? "id='" + img.id + "' " : "";
				var imgClass = (img.className) ? "class='" + img.className + "' " : "";
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				var imgStyle = "display:inline-block;" + img.style.cssText;
				
				if (img.align == "left") imgStyle = "float:left;" + imgStyle;
				
				if (img.align == "right") imgStyle = "float:right;" + imgStyle;
				
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
				
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
				
				img.outerHTML = strNewHTML;
				
				i = i-1;
			}
		}
	}    
}
window.attachEvent("onload", correctPNG);