var myGlobalHandlers = {
	onCreate: function(){
		Element.show('calWorking');
	},

	onComplete: function() {
		if(Ajax.activeRequestCount == 0){
			Element.hide('calWorking');
		}
	}
};

Ajax.Responders.register(myGlobalHandlers);

function makeCalendar(searchPars)
{
	var url = "/inc/Calendar/calendar.inc.php";
	var pathName = location.pathname;
	var thePaths = pathName.split('/');
	var cityName = thePaths[1];
	var pars = (searchPars == '' ) ? 'city='+cityName : searchPars+'&city='+cityName;
	var myAjax = new Ajax.Updater(
			{
				success: 'myCalendar'
			}, 
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onFailure: reportError,
				onComplete: _update
			});
}

function testMe()
{
	alert('test');
}
function _update()
{
	Behaviour.apply();
}
function reportError(request)
{
	alert("We're Sorry. There was an error loading the arts calendar.");
}

/*--------------------------------
		FORM FUNCTIONS
---------------------------------*/

function changeInputField(inputID, inputClass, inputValueDefault) {
	// Variable Descriptions
	//
	// inputID - element ID
	// inputClass - class name to change to
	// [inputValueDefault - if this is called onBlur and value of element is empty specify dafault value]
	var inputObj;
	if (document.all && !document.getElementById) 
	{ 
		var inputObj = document.all(inputID)
	} 
	else 
	{ 
		var inputObj = document.getElementById(inputID)
	}
	inputObj.className = inputClass;
	if (inputObj.value == "")
	{
		inputObj.value = inputValueDefault;
	} 
	else 
	{
		if (inputObj.value == inputValueDefault)
		{
			inputObj.value = "";
		}
	}
};

/* ************************************************************
Created: 20060120
Author:  Steve Moitozo <god at zilla dot us>
Description: This is a quick and dirty password quality meter 
		 written in JavaScript so that the password does 
		 not pass over the network.
License: MIT License (see below)
Modified: 20060620 - added MIT License

---------------------------------------------------------------
Copyright (c) 2006 Steve Moitozo <god at zilla dot us>

Permission is hereby granted, free of charge, to any person 
obtaining a copy of this software and associated documentation 
files (the "Software"), to deal in the Software without 
restriction, including without limitation the rights to use, 
copy, modify, merge, publish, distribute, sublicense, and/or 
sell copies of the Software, and to permit persons to whom the 
Software is furnished to do so, subject to the following 
conditions:

   The above copyright notice and this permission notice shall 
be included in all copies or substantial portions of the 
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 
OR OTHER DEALINGS IN THE SOFTWARE. 
---------------------------------------------------------------


Password Strength Factors and Weightings

password length:
level 0 (3 point): less than 4 characters
level 1 (6 points): between 5 and 7 characters
level 2 (12 points): between 8 and 15 characters
level 3 (18 points): 16 or more characters

letters:
level 0 (0 points): no letters
level 1 (5 points): all letters are lower case
level 2 (7 points): letters are mixed case

numbers:
level 0 (0 points): no numbers exist
level 1 (5 points): one number exists
level 1 (7 points): 3 or more numbers exists

special characters:
level 0 (0 points): no special characters
level 1 (5 points): one special character exists
level 2 (10 points): more than one special character exists

combinatons:
level 0 (1 points): letters and numbers exist
level 1 (1 points): mixed case letters
level 1 (2 points): letters, numbers and special characters 
					exist
level 1 (2 points): mixed case letters, numbers and special 
					characters exist


NOTE: Because I suck at regex the code below is incomplete and 
	  does not accurately assess the strength of passwords 
	  according to the above factors and weightings
	  
NOTE: Instead of putting out all the logging information,
	  the score, and the verdict it would be nicer to stretch
	  a graphic as a method of presenting a visual strength
	  guage.

************************************************************ */
function testPassword(passwd)
{
		var intScore   = 0
		var strVerdict = "Very Weak"
		
		// PASSWORD LENGTH
		if (passwd.length<5)                         // length 4 or less
		{
			intScore = (intScore+3)
		}
		else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
		{
			intScore = (intScore+6)
		}
		else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
		{
			intScore = (intScore+12)
		}
		else if (passwd.length>15)                    // length 16 or more
		{
			intScore = (intScore+18)
		}
		
		
		// LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
		if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
		{
			intScore = (intScore+1)
		}
		
		if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
		{
			intScore = (intScore+5)
		}
		
		// NUMBERS
		if (passwd.match(/\d+/))                                 // [verified] at least one number
		{
			intScore = (intScore+5)
		}
		
		if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		{
			intScore = (intScore+5)
		}
		
		
		// SPECIAL CHAR
		if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		{
			intScore = (intScore+5)
		}
		
																 // [verified] at least two special characters
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		{
			intScore = (intScore+5)
		}
	
		
		// COMBOS
		if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		{
			intScore = (intScore+2)
		}

		if (passwd.match(/(\d.*\D)|(\D.*\d)/))                    // [FAILED] both letters and numbers, almost works because an additional character is required
		{
			intScore = (intScore+2)
		}
 
																  // [verified] letters, numbers, and special characters
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		{
			intScore = (intScore+2)
		}
	
	
		if(intScore < 16)
		{
		   strVerdict = "Very Weak"
		}
		else if (intScore > 15 && intScore < 25)
		{
		   strVerdict = "Weak"
		}
		else if (intScore > 24 && intScore < 35)
		{
		   strVerdict = "Mediocre"
		}
		else if (intScore > 34 && intScore < 45)
		{
		   strVerdict = "Strong"
		}
		else
		{
		   strVerdict = "Stronger"
		}
	
	return strVerdict;
};

	// Function to calculate the total cost of tickets
function calcTotal()
{
	var numTickets	= $("num_sections").value;
	var qty 		= 0;
	var price 		= 0;
	var charge 		= 0;
	var cost 		= 0;
	var totalQty 	= 0;
	var totalPrice	= 0;
	var totalCharge = 0;
	var totalTotal 	= 0;
	var currencyCode= "USD";
	
	// Loop thru each ticket type
	for (var i = 0; i < numTickets; i++)
	{
			// Qty
		qty 		= parseInt($("qty" + i).value);
		if (isNaN(qty))
		{
			qty		= 0;
		}
		totalQty   += qty;
			// Price
		price 		= $("price" + i).value;
		price 		= parseFloat(price);
			// Service Charge
		charge 		= $("charge" + i).value;
		charge 		= qty * parseFloat(charge);
		totalCharge+= charge;
			// Calculate ticket cost
		cost 		= qty * price;
		totalPrice += cost;
			// Update ticket total
		$("ticketTotal" + i).innerHTML = formatCurrency(cost+charge, 2, currencyCode, true, true, false);
			// Increment overall total
		totalTotal += cost + charge;
	}
	
		// Update totals
	if (isNaN(totalQty))
	{
		$("totalQty").innerHTML = "0";
	}
	else
	{
		$("totalQty").innerHTML = totalQty;
	}
	$("totalPrice").innerHTML 	= formatCurrency(totalPrice, 2, currencyCode, true, false, false);
	$("totalCharge").innerHTML 	= formatCurrency(totalCharge, 2, currencyCode, true, false, false);
	$("totalTotal").innerHTML 	= formatCurrency(totalTotal, 2, currencyCode, true, true, false);
};

	// Function to format a numeric value using currency formatting
function formatCurrency(number, decimalPlaces, currencyCode, leadingDigit, trailingCode, useParens) {
/*
ARGUMENTS:
number
  Required. Number to be formatted.
decimalPlaces
  Optional. Numeric value indicating how many places to the right of the decimal are displayed.
  Default value is 2.
currencyCode
  Optional. Character value that specifies which country's currency to use.
  Default value is USD.
leadingDigit
  Optional. Boolean value that indicates whether or not a leading zero is displayed for fractional values.
  Default value is False.
trailingCode
  Optional. Boolean value that indicates whether or not the trailing currency code is displayed.
  Default value is False.
useParens
  Optional. Boolean value that indicates whether or not to place negative values within parentheses.
  Default value is False.
*/
	var sign;
	var currency;
	var dollar;
	var cents;
	
	if (isNaN(decimalPlaces))
	{
		number = "0";
	}
	else
	{
		decimalPlaces = Math.abs(decimalPlaces)
	}
	
	switch (currencyCode)
	{
		case "CAD":
			currency = "$";
			break;
		case "EUR":
			currency = "";
			break;
		case "GBP":
			currency = "£";
			break;
		default:
			currencyCode = "USD";
			currency = "$";
			break;	
	}
	
	if (!leadingDigit)
	{
		leadingDigit = false;
	}
	
	if (!trailingCode)
	{
		trailingCode = false;
	}
	
	if (!useParens)
	{
		useParens = false;
	}
	
	number = number.toString().replace(/\$|\£|\/,'');
	number = number.toString().replace(/\,/g,'');
	if (isNaN(number))
	{
		number = "0";
	}
	sign = (number != (number = Math.abs(number)));
	number = Math.floor(number * 100 + 0.50000000001);
	dollar = Math.floor(number / 100).toString();
	cents = (number % 100).toString();
	if (cents < 10)
	{
		cents = '0' + cents;
	}
    while (cents.length < decimalPlaces)
    {
        cents += '0';
	}
	
	for (var i = 0; i < Math.floor((dollar.length - (1 + i)) / 3); i++)
	{
		dollar = dollar.substring(0, dollar.length - (4 * i + 3)) + ',' + dollar.substring(dollar.length - (4 * i + 3));
	}
	
	if (sign)
	{
		number = ((useParens)?'(':'-') + currency + ((dollar == 0 && !leadingDigit)?'':dollar) + '.' + cents + ((useParens)?')':'') + ((trailingCode)?' '+currencyCode:'');
	}
	else
	{
		number = currency + ((dollar == 0 && cents != 0 && !leadingDigit)?'':dollar) + '.' + cents + ((trailingCode)?' '+currencyCode:'');
	}
	
	return number;
};

	// Function to round number
function round(number, decimalPlaces) {
	if (isNaN(number))
	{
		number = "0";
	}
	
	if (decimalPlaces == undefined)
	{
		number = Math.round(number);
	}
	else
	{
		number = Math.round(number * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces);
	}
	return number;
};

var searchPars = '';
makeCalendar(searchPars);