﻿function riddle(riddlerarray)
{
/***********************************************
* Encrypt Email script- Please keep notice intact
* Tool URL: http://www.dynamicdrive.com/emailriddler/
* **********************************************/

//var emailriddlerarray=[121,111,117,64,121,111,117,114,100,111,109,97,105,110,46,99,111,109]
var encryptedemail_id32='' //variable to contain encrypted email 
for (var i=0; i<riddlerarray.length; i++)
 encryptedemail_id32+=String.fromCharCode(riddlerarray[i])

//document.write('<a href="mailto:'+encryptedemail_id32+'">Contact Us</a>')
document.write(encryptedemail_id32)
}

function riddle2(riddlerarray)
{
/***********************************************
* Encrypt Email script- Please keep notice intact
* Tool URL: http://www.dynamicdrive.com/emailriddler/
* **********************************************/

//var emailriddlerarray=[121,111,117,64,121,111,117,114,100,111,109,97,105,110,46,99,111,109]
var encryptedemail_id32='' //variable to contain encrypted email 
for (var i=0; i<riddlerarray.length; i++)
 encryptedemail_id32+=String.fromCharCode(riddlerarray[i])

//document.write('<a href="mailto:'+encryptedemail_id32+'">Contact Us</a>')
window.location.assign(encryptedemail_id32)
}


/* bannières */
function feedBan(HtmlDivID,video, flash, image, alt, link, banWidth, banHeight, target) {
	var ctnr = document.getElementById(HtmlDivID);
	var img = '';
	if (target != '') {
		img = '<a href="' + link + '" target="' + target + '"><img src="' + image + '" alt="' + alt + '" />';
	} else {
		img = '<a href="' + link + '"><img src="' + image + '" alt="' + alt + '" />';
	}


if (flash == "" && video=="") {
		ctnr.innerHTML = img;
} else {
	if(flash!='') {
		var so = new SWFObject(flash, "banner", banWidth, banHeight, "7.0.0", "#FEFCF1");
		so.write(HtmlDivID);
		if (so.write(HtmlDivID) == false) ctnr.innerHTML = img;
	}

if (video != '') {
	   var so = new SWFObject('/medias/communs/videoplayer.swf', 'videoplayer', 602, 420, '9', '#FFFFFF');
		so.addParam('allowfullscreen', 'true');
		so.addParam('wmode', 'transparent');
		so.addVariable('stretching', 'fill');
		so.addVariable('file', video);
		so.addVariable("autostart", "true");
		so.addVariable('image', image);
		so.addVariable('backcolor', "0x313335");
		so.addVariable('frontcolor', "0xe3e3e1");
		so.addVariable('lightcolor', "0xffffff");
		so.setAttribute("id", "player1");
		so.setAttribute("name", "player1");

		so.write(HtmlDivID);
	}
	}
	ctnr.style.display = "block";
}

/* print */

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);

function printPage()
{
  if (pr) // NS4, IE5
	window.print()
  else if (da && !mac) // IE4 (Windows)
	vbPrintPage()
  else // other browsers
	alert("Sorry, your browser doesn't support this feature.");
  return false;
}

if (da && !pr && !mac) with (document)
{
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}


function ShowHide(elementId)
{
	var element = document.getElementById(elementId);
	if(element.style.display != "block")
	{
		element.style.display = "block";
	}
	else
	{
		element.style.display = "none";
	}
}

 

/* flash  */

function Media(id, media) 
{ 
	if (document.getElementById) { 
document.getElementById(id).innerHTML = media; 
	} 
} 
function Media1(id, media1) 
{ 
	if (document.getElementById) { 
document.getElementById(id).innerHTML = media1; 
	}
}


//tri en tenant compte des accents
//http://stackoverflow.com/questions/286921/javascript-efficiently-replace-all-accented-characters-in-a-string
// ajouter "textExtraction: GetTextExtractor()" dans l'init de tablesorter
function GetTextExtractor() {
	return (function () {
		var patternLetters = /[öäüÖÄÜáàâéèêúùûóòôÁÀÂÉÈÊÚÙÛÓÒÔß]/g;
		var patternDateDmy = /^(?:\D+)?(\d{1,2})\.(\d{1,2})\.(\d{2,4})$/;
		var lookupLetters = {
			"ä": "a", "ö": "o", "ü": "u",
			"Ä": "A", "Ö": "O", "Ü": "U",
			"á": "a", "à": "a", "â": "a",
			"é": "e", "è": "e", "ê": "e",
			"ú": "u", "ù": "u", "û": "u",
			"ó": "o", "ò": "o", "ô": "o",
			"Á": "A", "À": "A", "Â": "A",
			"É": "E", "È": "E", "Ê": "E",
			"Ú": "U", "Ù": "U", "Û": "U",
			"Ó": "O", "Ò": "O", "Ô": "O",
			"ß": "s"
		};
		var TranslateCallback = function (match) {
			if (lookupLetters[match])
				return lookupLetters[match];
			else
				return match;
		}

		return function (node) {
			var text = $.trim($(node).text());
			var matches;
			if (matches = text.match(patternDateDmy))
				return [matches[3], matches[2], matches[1]].join("-");
			else
				return text.replace(patternLetters, TranslateCallback);
		}
	})();
}

/*custom js dans le master*/
$(document).ready(function () {

	/*bouton achat*/
	$("#btnachat").mouseover(function (e) {

		//remplir la liste des spectacles (seulement une fois)
		if (!$(this).hasClass("ItemFedd")) {
			$(this).addClass("ItemFedd");
			var $DivData = $(this).children("div");
			$DivData.show();

			$.get("/usercontrols/EnteteBoutonAchatBillets.aspx", function (data) {
				$DivData.html(data);
				
				/*tri sur le tableau*/
				$("#classeur").tablesorter({
					// sort on the first column order asc 
					sortList: [[0, 0]],
					textExtraction: GetTextExtractor()
				});
			});
		}
	});


});


$(document).ready(function () {
	var $txtRecherche = $("#ctl00_entete_txtRecherche");

	$txtRecherche.keypress(function (e) {
//        if (e.which == 13) {
//            if ($txtRecherche.val().length < 2) {
//                e.preventDefault();
//                alert("Vous devez entrer au moins un mot-clé.");
//            }
//            else {
//                e.preventDefault();
//                document.location.href = BaseHref + "/billet-spectacle/recherche.aspx?Query=" + encodeURIComponent($txtRecherche.val());
//            }
//        }
	});

	$("#ctl00_entete_btnSearch").click(function (e) {
		if ($txtRecherche.val().length < 2 || $txtRecherche.val() == 'Rechercher...') {
			e.preventDefault();
			alert("Vous devez entrer au moins un mot-clé.");
		}
		else {
			e.preventDefault();
			document.location.href = BaseHref + "/billet-spectacle/recherche.aspx?Query=" + encodeURIComponent($txtRecherche.val());
		}
	});
});


/* autocomplete */
$(document).ready(function () {
	addHighlight();
	var cache = {};
	$("#ctl00_entete_txtRecherche").autocomplete({
		source: function (request, response) {
			if (cache.term == request.term && cache.content) {
				response(cache.content);
			}
			if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) {
				var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
				response($.grep(cache.content, function (value) {
					return matcher.test(value.value)
				}));
			}
			$.ajax({
				type: "POST",
				url: "/Main.asmx/FindSpectacle",
				dataType: "json",
				data: "{'Query': '" + request.term + "','languageViewId' : 'FR'}",
				contentType: "application/json; charset=utf-8",
				dataType: "json",
				success: function (data) {
					cache.term = request.term;
					cache.content = data.d;
					response(data.d);
				},
				error: function (data) {
				 
				}
			});
		},
		minLength: 3,
		select: function (event, ui) {
			document.location.href = BaseHref + "/billet-spectacle/recherche.aspx?Query=" + encodeURIComponent(ui.item.label);
		}
	});
});
/* regex gras si match */
function addHighlight() {
	$.ui.autocomplete.prototype._renderItem = function (ul, item) {
		var re = new RegExp("(" + this.term + ")", "i");
		var t = item.label.replace(re, "<strong>$1</strong>");
		return $("<li></li>")
			.data("item.autocomplete", item)
			.append("<a>" + t + "</a>")
			.appendTo(ul);
	};
}

/**
* jQuery Opacity Rollover plugin
*
* Copyright (c) 2009 Trent Foley (http://trentacular.com)
* Licensed under the MIT License:
*   http://www.opensource.org/licenses/mit-license.php
*/
; (function ($) {
	var defaults = {
		mouseOverOpacity: 0.67,
		mouseOutOpacity: 1.0,
		fadeSpeed: 'fast',
		exemptionSelector: '.selected'
	};

	$.fn.opacityrollover = function (settings) {
		// Initialize the effect
		$.extend(this, defaults, settings);

		var config = this;

		function fadeTo(element, opacity) {
			var $target = $(element);

			if (config.exemptionSelector)
				$target = $target.not(config.exemptionSelector);

			$target.fadeTo(config.fadeSpeed, opacity);
		}

		this.css('opacity', this.mouseOverOpacity)
			.hover(
				function () {
					fadeTo(this, config.mouseOutOpacity);
				},
				function () {
					fadeTo(this, config.mouseOverOpacity);
				});

		return this;
	};
})(jQuery);


/*!
Slimbox v2.04 - The ultimate lightweight Lightbox clone for jQuery
(c) 2007-2010 Christophe Beyls <http://www.digitalia.be>
MIT-style license.
*/

(function ($) {

	// Global variables, accessible to Slimbox only
	var win = $(window), options, images, activeImage = -1, activeURL, prevImage, nextImage, compatibleOverlay, middle, centerWidth, centerHeight,
		ie6 = !window.XMLHttpRequest, hiddenElements = [], documentElement = document.documentElement,

	// Preload images
	preload = {}, preloadPrev = new Image(), preloadNext = new Image(),

	// DOM elements
	overlay, center, image, sizer, prevLink, nextLink, bottomContainer, bottom, caption, number;

	/*
	Initialization
	*/

	$(function () {
		// Append the Slimbox HTML code at the bottom of the document
		$("body").append(
			$([
				overlay = $('<div id="lbOverlay" />')[0],
				center = $('<div id="lbCenter" />')[0],
				bottomContainer = $('<div id="lbBottomContainer" />')[0]
			]).css("display", "none")
		);

		image = $('<div id="lbImage" />').appendTo(center).append(

			sizer = $('<div style="position: relative;" />').append([
			  description = $('<div id="lbDescription" />')[0],
				prevLink = $('<a id="lbPrevLink" href="#" />').click(previous)[0],
				nextLink = $('<a id="lbNextLink" href="#" />').click(next)[0]
			])[0]
		)[0];

		bottom = $('<div id="lbBottom" />').appendTo(bottomContainer).append([
			$('<a id="lbCloseLink" href="#" />').add(overlay).click(close)[0],

			caption = $('<div id="lbCaption" />')[0],
			number = $('<div id="lbNumber" />')[0],
			$('<div style="clear: both;" />')[0]
		])[0];
	});


	/*
	API
	*/

	// Open Slimbox with the specified parameters
	$.slimbox = function (_images, startImage, _options) {
		options = $.extend({
			loop: false, 			// Allows to navigate between first and last images
			overlayOpacity: 0.8, 		// 1 is opaque, 0 is completely transparent (change the color in the CSS file)
			overlayFadeDuration: 400, 	// Duration of the overlay fade-in and fade-out animations (in milliseconds)
			resizeDuration: 400, 		// Duration of each of the box resize animations (in milliseconds)
			resizeEasing: "swing", 		// "swing" is jQuery's default easing
			initialWidth: 250, 		// Initial width of the box (in pixels)
			initialHeight: 250, 		// Initial height of the box (in pixels)
			imageFadeDuration: 400, 		// Duration of the image fade-in animation (in milliseconds)
			captionAnimationDuration: 400, 	// Duration of the caption animation (in milliseconds)
			counterText: "Image {x} of {y}", // Translate or change as you wish, or set it to false to disable counter text for image groups
			closeKeys: [27, 88, 67], 	// Array of keycodes to close Slimbox, default: Esc (27), 'x' (88), 'c' (67)
			previousKeys: [37, 80], 		// Array of keycodes to navigate to the previous image, default: Left arrow (37), 'p' (80)
			nextKeys: [39, 78]			// Array of keycodes to navigate to the next image, default: Right arrow (39), 'n' (78)
		}, _options);

		// The function is called for a single image, with URL and Title as first two arguments
		if (typeof _images == "string") {
			_images = [[_images, startImage]];
			startImage = 0;
		}

		middle = win.scrollTop() + (win.height() / 2);
		centerWidth = options.initialWidth;
		centerHeight = options.initialHeight;
		$(center).css({ top: Math.max(0, middle - (centerHeight / 2)), width: centerWidth, height: centerHeight, marginLeft: -centerWidth / 2 }).show();
		compatibleOverlay = ie6 || (overlay.currentStyle && (overlay.currentStyle.position != "fixed"));
		if (compatibleOverlay) overlay.style.position = "absolute";
		$(overlay).css("opacity", options.overlayOpacity).fadeIn(options.overlayFadeDuration);
		position();
		setup(1);

		images = _images;
		options.loop = options.loop && (images.length > 1);
		return changeImage(startImage);
	};

	/*
	options:	Optional options object, see jQuery.slimbox()
	linkMapper:	Optional function taking a link DOM element and an index as arguments and returning an array containing 2 elements:
	the image URL and the image caption (may contain HTML)
	linksFilter:	Optional function taking a link DOM element and an index as arguments and returning true if the element is part of
	the image collection that will be shown on click, false if not. "this" refers to the element that was clicked.
	This function must always return true when the DOM element argument is "this".
	*/
	$.fn.slimbox = function (_options, linkMapper, linksFilter) {
		linkMapper = linkMapper || function (el) {
			return [el.href, el.title, $(el).attr("description")];
		};

		linksFilter = linksFilter || function () {
			return true;
		};

		var links = this;

		return links.unbind("click").click(function () {
			// Build the list of images that will be displayed
			var link = this, startIndex = 0, filteredLinks, i = 0, length;
			filteredLinks = $.grep(links, function (el, i) {
				return linksFilter.call(link, el, i);
			});

			// We cannot use jQuery.map() because it flattens the returned array
			for (length = filteredLinks.length; i < length; ++i) {
				if (filteredLinks[i] == link) startIndex = i;
				filteredLinks[i] = linkMapper(filteredLinks[i], i);
			}

			return $.slimbox(filteredLinks, startIndex, _options);
		});
	};


	/*
	Internal functions
	*/

	function position() {
		var l = win.scrollLeft(), w = win.width();
		$([center, bottomContainer]).css("left", l + (w / 2));
		if (compatibleOverlay) $(overlay).css({ left: l, top: win.scrollTop(), width: w, height: win.height() });
	}

	function setup(open) {
		if (open) {
			$("object").add(ie6 ? "select" : "embed").each(function (index, el) {
				hiddenElements[index] = [el, el.style.visibility];
				el.style.visibility = "hidden";
			});
		} else {
			$.each(hiddenElements, function (index, el) {
				el[0].style.visibility = el[1];
			});
			hiddenElements = [];
		}
		var fn = open ? "bind" : "unbind";
		win[fn]("scroll resize", position);
		$(document)[fn]("keydown", keyDown);
	}

	function keyDown(event) {
		var code = event.keyCode, fn = $.inArray;
		// Prevent default keyboard action (like navigating inside the page)
		return (fn(code, options.closeKeys) >= 0) ? close()
			: (fn(code, options.nextKeys) >= 0) ? next()
			: (fn(code, options.previousKeys) >= 0) ? previous()
			: false;
	}

	function previous() {
		return changeImage(prevImage);
	}

	function next() {
		return changeImage(nextImage);
	}

	function changeImage(imageIndex) {
		if (imageIndex >= 0) {
			activeImage = imageIndex;
			activeURL = images[activeImage][0];
			prevImage = (activeImage || (options.loop ? images.length : 0)) - 1;
			nextImage = ((activeImage + 1) % images.length) || (options.loop ? 0 : -1);

			stop();
			center.className = "lbLoading";

			preload = new Image();
			preload.onload = animateBox;
			preload.src = activeURL;
		}

		return false;
	}

	function animateBox() {
		center.className = "";
		$(image).css({ backgroundImage: "url(" + activeURL + ")", visibility: "hidden", display: "" });
		$(sizer).width(preload.width);
		$([sizer, prevLink, nextLink]).height(preload.height);

		$(description).hide();
		if (images[activeImage][2] != undefined) {
			$(description).show();
			$(description).html(images[activeImage][2] || "");
		}

		$(caption).html(images[activeImage][1] || "");
		$(number).html((((images.length > 1) && options.counterText) || "").replace(/{x}/, activeImage + 1).replace(/{y}/, images.length));

		if (prevImage >= 0) preloadPrev.src = images[prevImage][0];
		if (nextImage >= 0) preloadNext.src = images[nextImage][0];

		centerWidth = image.offsetWidth;
		centerHeight = image.offsetHeight;
		var top = Math.max(0, middle - (centerHeight / 2));
		if (center.offsetHeight != centerHeight) {
			$(center).animate({ height: centerHeight, top: top }, options.resizeDuration, options.resizeEasing);
		}
		if (center.offsetWidth != centerWidth) {
			$(center).animate({ width: centerWidth, marginLeft: -centerWidth / 2 }, options.resizeDuration, options.resizeEasing);
		}
		$(center).queue(function () {
			$(bottomContainer).css({ width: centerWidth, top: top + centerHeight, marginLeft: -centerWidth / 2, visibility: "hidden", display: "" });
			$(image).css({ display: "none", visibility: "", opacity: "" }).fadeIn(options.imageFadeDuration, animateCaption);
		});
	}

	function animateCaption() {
		if (prevImage >= 0) $(prevLink).show();
		if (nextImage >= 0) $(nextLink).show();
		$(bottom).css("marginTop", -bottom.offsetHeight).animate({ marginTop: 0 }, options.captionAnimationDuration);
		bottomContainer.style.visibility = "";
	}

	function stop() {
		preload.onload = null;
		preload.src = preloadPrev.src = preloadNext.src = activeURL;
		$([center, image, bottom]).stop(true);
		$([prevLink, nextLink, image, bottomContainer]).hide();
	}

	function close() {
		if (activeImage >= 0) {
			stop();
			activeImage = prevImage = nextImage = -1;
			$(center).hide();
			$(overlay).stop().fadeOut(options.overlayFadeDuration, setup);
		}

		return false;
	}

})(jQuery);


// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
	jQuery(function ($) {
		$("a[rel^='lightbox']").slimbox({/* Put custom options here */
		}, null, function (el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
	});
}
