﻿/*
*** mod date:		09/07/08
--- description:	removes the dashed line round links
                    
--- usage:			uses a mootools 'domready' function to apply to all links on the page
*/
function unblur() {
	this.blur();
} 
function blurLinks() {
	if (!document.getElementById) return;
	theLinks = document.getElementsByTagName("A");
	theAreas = document.getElementsByTagName("AREA");
	for(i=0; i<theLinks.length; i++) {theLinks[i].onfocus = unblur;}
	for(i=0; i<theAreas.length; i++) {theAreas[i].onfocus = unblur;}
}

/*
	opens centered pop-up window
*/
function centreWindow(url, windowName, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2 - 20;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar=no,status=no,location=no,menubar=no,resizable=no,status=yes,directories=no';
	win = window.open(url, windowName, winprops);
}

/*
	add's the passed value/text pairs array to the passed ddl
*/
function addDdlOptions(ddl, values)
{
	values.each(function(values)
	{
		new Element('option', {'value': values.StateID, 'text': values.State}).inject(ddl);
	});
}

/*
	removes all options from the passed ddl
*/
function removeDdlOptions(ddl)
{
	for (var i=ddl.options.length-1;i>=0;i--)
	{
		ddl.remove(i);
	}
}

/*
	sets the selected value of the passed ddl
*/
function setDdlSelected(ddl, selectedValue)
{
	for (i = 0; i < ddl.options.length; i++)
	{		
		if (ddl.options[i].value == selectedValue)
		{
			ddl.options[i].selected = true;
			break;
		}
	}
}

/*
	sets a form buttons disabled state and text value
*/
function enableDisableBtn(btnID, text, state)
{
	$(btnID).set('value', text);
	$(btnID).disabled = state;
}

function disableEnterKey(e)
{
	var key;
	if(window.event)
	{
		key = window.event.keyCode; //IE
	}
	else
	{
		key = e.which; //firefox
	}

	return (key != 13);
}

/*
	only allow numeric chars
*/
function NumbersOnly(evt) {
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
		return false;
	}

	return true;
}

/*
	validates a date based on the passed day/month/year
*/
function IsValidDate(d, m, y)
{
	var DateVal = m + "/" + d + "/" + y;
	var dt = new Date(DateVal);

	if (dt.getDate() != d)
	{
		return(false);
	}
	else if (dt.getMonth() != m-1)
	{
		return(false);
	}
	else if (dt.getFullYear() != y)
	{
		return(false);
	}

	return(true);
}

/*
	checks the characters length of the passed field
*/
function checkFieldLength(fieldID,maxLength)
{
	var fieldID = $(fieldID);
	var fieldIDLength = fieldID.value.length;

	if(fieldIDLength > maxLength)
	{
		return false;
	}
	else
	{
		return true;
	}   
}

/*
	checks the file extension of the passed frm field
*/
function checkFileExt(id, arrExt)
{
	var blnVerdict = false;
	var valid_arr = arrExt;
	var valid_files_arr = valid_arr.split(",")
	for (var i=0; i<valid_files_arr.length; i++)
	{
		if ($(id).value.toLowerCase().match(valid_files_arr[i]))
		{
			blnVerdict = true;
		}
	}
	if (blnVerdict == false)
	{
		return(false);
	}
	else
	{
		return(true);
	}
}

/*
	add any initialisation functions here
*/
window.addEvent('domready', function(){
	blurLinks();
});
