function popUp (url, width, height) {			
	//center the pop-up	
	if (parseInt(navigator.appVersion) >= 4 ) {
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;}

	args = "width=" + width + ","
	+ "height=" + height + ","
	+ "location=0," 
	+ "menubar=0,"
	+ "resizable=1,"
	+ "scrollbars=1,"
	+ "status=no," 
	+ "titlebar=1,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "screenx=" + xposition + ","  //NN Only
	+ "screeny=" + yposition + ","  //NN Only
	+ "left=" + xposition + ","     //IE Only
	+ "top=" + yposition;           //IE Only
		
	window.open(url,'myfile',args );
}

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;

    elements.push(element);
  }

  return elements;
}

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function doAjax (url, pars, outputdiv, meth, display_load) {	

	if (display_load == undefined)
		display_load = 0;
	
	if (display_load == 1 && $(outputdiv))
		$(outputdiv).innerHTML = '<p><img src="images/layout/ajax-loader.gif" /></p>';	
		
	pars = pars + '&nocache=' + Math.random();
	// alert(pars);
	var myAjax = new Ajax.Updater(outputdiv, url, {method: meth, parameters: pars, evalScripts: true});		
	
}

function genPassword(trgt, len) {

	var useChars = "0123456789abcdefghijklmABCDEFGHIJKLMnopqrstuvwxyzNOPQRSTUVWYXZ";	
	var password = "";
	
	for (var j = 1; j <= len; j++) {
		password += useChars.charAt(Math.floor(Math.random() * (useChars.length - 0)) + 0);
	}
	
	$(trgt).value = password;	
}



// http://24ways.org/2005/splintered-striper

/*
 * Summary:      Core experiment function that applies any number of classes to all child elements
 *               contained in all occurences of a parent element (either with or without a specific class)
 * Parameters:   parentElementTag - parent tag name
 *               parentElementClass - class assigned to the parent; if null, all parentElementTag elements will be affected
 *               childElementTag -  tag name of the child elements to apply the styles to
 *               styleClasses - comma separated list of any number of style classes (using 2 classes gives the classic "zebra" effect)
 * Return:       none
 */
 
// striper('tbody','striped','tr','odd,even');

/*
<table>
<tbody class="striped">
	<tr>
		<td></td>
	</tr>
	<tr>
		<td></td>
	</tr>
</tbody>
</table>

*/
 
function zebra(parentElementTag, parentElementClass, childElementTag, styleClasses)
{
	var i=0,currentParent,currentChild;
	if ((document.getElementsByTagName)&&(parentElementTag)&&(childElementTag)&&(styleClasses)) {
		var styles = styleClasses.split(',');
		var parentItems = document.getElementsByTagName(parentElementTag);
		while (currentParent = parentItems[i++]) {
			if ((parentElementClass == null)||(currentParent.className.indexOf(parentElementClass) > -1)) {
				var j=0,k=0;
				var childItems = currentParent.getElementsByTagName(childElementTag);
				while (currentChild = childItems[j++]) {
					k = (j+(styles.length-1)) % styles.length;
					currentChild.className = currentChild.className+" "+styles[k];
				}
			}
		}
	}
}

function close_open_divs(close_these, open_these) {
	
	var close_these_array = close_these.split("|");
	var open_these_array = open_these.split("|");
	
	for (var j = 0; j < close_these_array.length; j++) {
		$(close_these_array[j]).style.display = 'none';
		$(close_these_array[j] + '_li').className = '';
	}
	
	for (var j = 0; j < open_these_array.length; j++) {
		$(open_these_array[j]).style.display = 'block';
		$(open_these_array[j] + '_li').className = 'on';
	}	
	
	//alert(close_these_array);
	//alert(open_these_array);
	
}

function loadVideo(url, showid, videoTitle, credit) {
	
	var so = new SWFObject("swf/player.video.swf", "", "570", "336", "6", "");
	so.addParam("wmode", "opaque");
	so.addVariable("video", url);
	so.addVariable("videoTitle", "" + videoTitle + "");
	so.addVariable("show_id", "" + showid + "");
	so.write("mediaPlayer");			

	// if (credit == undefined) 
		// credit = "";				

	$('creditline').innerHTML = credit;

}

function loadAudio(url, show_id, caption) {

	var so = new SWFObject("swf/mp3player.swf", "", "70", "23", "6", "#FFFFFF");
	so.addVariable("mp3audio", "media/audio/<?= $audio['link']; ?>");
	so.addVariable("caption", "" + caption + "");
	so.addVariable("show_id", "" + showid + "");
	so.write("audclip");	
	

}

function cart_add(event_id, show_id) {
		
	if (event_id != "") {
		doAjax('ajax.shop.php?f=addProduct', 'event_id=' + event_id + '&show_id=' + show_id, 'cart_list', 'get');	
		
		if ($('show_add_'+ show_id))		
			new Effect.Pulsate(('show_add_'+ show_id), {pulses: 2});
	}
	else
		alert('Please select a date and time');
	
}

function cart_remove(show_id) {	
	doAjax('ajax.shop.php?f=removeProduct', 'show_id=' + show_id, 'cart_list', 'get');
}

function display_cart() {
	doAjax('ajax.shop.php?f=displayCart', '', 'cart_list', 'get', 1);
}

function cart_clear() {
	doAjax('ajax.shop.php?f=clearCart', '', 'cart_list', 'get');
}

function remove_item_atcheckout(event_id) {
	
	$('cart_size').value = ($('cart_size').value * 1) - 1;
	$('listed_' + event_id).style.display = 'none';
	
	
	cart_remove(event_id);
	
	if ($('cart_size').value == 0) {
		$('CheckoutList').innerHTML = '<div style="padding: 5px;"><p>Your cart is empty. Click below to browse for available tickets.</p><p><button name="checkout" value="" onClick="location.href=\'http://www.comedyfestival.com.au/season/2008/shows/a-z/\'">Keep Browsing</button></p></div>';
	}
	
}


var floatActivityDivTop = 0;
function floatActivityDiv() {

   if (document.documentElement && document.documentElement.scrollTop) {
       scrollTop = document.documentElement.scrollTop;
   } else {
       scrollTop = document.body.scrollTop;
   }
   
   floatActivityDivTop += (scrollTop + 2 - floatActivityDivTop) / 6;

   $('showActivity').style.top = floatActivityDivTop + 'px';
   $('showActivity').style.right = 2 + 'px';

}



function showActivity() {	 
   if($('showActivity')) {
       Effect.Appear('showActivity',{duration: 0.5, queue: {position:'front', scope:'showActivity', limit: 50}});
   }
}
function hideActivity() {
   if($('showActivity')) {
       Effect.Fade('showActivity',{duration: 0.5, queue: {position:'end', scope:'showActivity', limit: 50}});
   }
}		
	
function cookie_checker() {
	if (navigator.cookieEnabled == false) {
		$('noCookieWarning').className = 'noscript';
	} 
}


function myfestival_register() {
	
	if (confirm('Sorry, you need to be a MyFestival member to access this feature.\nClick OK to register now. It\'s Free!')) {
		location.href='http://www.comedyfestival.com.au/season/2008/myfestival/register/';
	}
		
}

function loadExternalBooking(url) {
	
	if ($('cart_size_holder') && ($('cart_size_holder').value > 0)) {
	
		if (confirm('You are about to be taken to an external site to buy tickets. This window will remain open. You must return to this page to purchase your TICKETMASTER CART')) { 
			window.open(url); 
		} 
		
		return false;
			
	} else {
		window.open(url); 
	}
	
	
}

function loadShowsInMaps(ven_id, output_div) {
	doAjax('ajax.calls.php?f=loadShowsInMaps', 'venue_id=' + ven_id, output_div, 'get');
}	

function loadLatesComedyTV(way, start, output_div) {
	doAjax('ajax.calls.php?f=loadLatesComedyTV', 'way=' + way + '&start=' + start, output_div, 'get');
}	

function loadComedyTV(videoUrl, videoTitle, videoImg) {
	
	var so = new SWFObject("swf/ComedyTV.swf", "", "576", "388", "6", "#eeec10");
	so.addParam("wmode", "opaque");
	so.addVariable("videoFile", videoUrl);
	so.addVariable("videoTitle", videoTitle);
	so.addVariable("videoImg", videoImg);
	so.write("comedyTvPlayer");	
	
}


