﻿/*
*** 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();
});

/*
	accordian used on the ticket packages page
*/
window.addEvent('domready', function() {
	var get = $get();
	
	var index = parseInt(get.index);

	if (isNaN(index)) {
		index = -1;
	}	
	
	var myAccordion = new Accordion($('accordion'), 'h3.toggler', 'div.element', {
		opacity: false,
		display : index,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#000');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#cc3399');
		}
	});
});

/*
Function: $get
	This function provides access to the "get" variable scope + the element anchor

Version: 1.3

Arguments:
	key - string; optional; the parameter key to search for in the url's query string (can also be "#" for the element anchor)
	url - url; optional; the url to check for "key" in, location.href is default

Example:
	>$get("foo","http://example.com/?foo=bar"); //returns "bar"
	>$get("foo"); //returns the value of the "foo" variable if it's present in the current url(location.href)
	>$get("#","http://example.com/#moo"); //returns "moo"
	>$get("#"); //returns the element anchor if any, but from the current url (location.href)
	>$get(,"http://example.com/?foo=bar&bar=foo"); //returns {foo:'bar',bar:'foo'}
	>$get(,"http://example.com/?foo=bar&bar=foo#moo"); //returns {foo:'bar',bar:'foo',hash:'moo'}
	>$get(); //returns same as above, but from the current url (location.href)
	>$get("?"); //returns the query string (without ? and element anchor) from the current url (location.href)

Returns:
	Returns the value of the variable form the provided key, or an object with the current GET variables plus the element anchor (if any)
	Returns "" if the variable is not present in the given query string

Credits:
		Regex from [url=http://www.netlobo.com/url_query_string_javascript.html]http://www.netlobo.com/url_query_string_javascript.html[/url]
		Function by Jens Anders Bakke, webfreak.no
		http://webfreak.no/wp/2007/09/05/get-for-mootools-a-way-to-read-get-variables-with-javascript-in-mootools/
*/
function $get(key,url){
	if(arguments.length < 2) url =location.href;
	if(arguments.length > 0 && key != ""){
		if(key == "#"){
			var regex = new RegExp("[#]([^$]*)");
		} else if(key == "?"){
			var regex = new RegExp("[?]([^#$]*)");
		} else {
			var regex = new RegExp("[?&]"+key+"=([^&#]*)");
		}
		var results = regex.exec(url);
		return (results == null )? "" : results[1];
	} else {
		url = url.split("?");
		var results = {};
			if(url.length > 1){
				url = url[1].split("#");
				if(url.length > 1) results["hash"] = url[1];
				url[0].split("&").each(function(item,index){
					item = item.split("=");
					results[item[0]] = item[1];
				});
			}
		return results;
	}
}