VGIMG = 'http://www.upconcert.com/img';
VGJS = 'http://www.upconcert.com/include/js';

function getElementDiv(id) {
		if (!document.getElementById) { 
			return;
		}

		if (document.all) {
			return eval("document.all." + id);
		} else {
			return document.getElementById(id);
		}
	}

	function DisplayDiv(id) {
		var DivArray;
		var i;
		
		DivArray = id.split(",")

		for (i = 0; i < DivArray.length; i++) {
			getElementDiv(DivArray[i]).style.display = (getElementDiv(DivArray[i]).style.display == "none" ? "inline" : "none");
		}
	}

	function DivOn(id) {
		var DivArray;
		var i;
		
		DivArray = id.split(",")

		for (i = 0; i < DivArray.length; i++) {
			getElementDiv(DivArray[i]).style.display = "inline";
		}
	}

	function DivOff(id) {
		var DivArray;
		var i;
		
		DivArray = id.split(",")

		for (i = 0; i < DivArray.length; i++) {
			getElementDiv(DivArray[i]).style.display = "none";
		}
	}

	function DisplayDiv2(id) {
		var DivArray;
		var i;
		
		DivArray = id.split(",")

		for (i = 0; i < DivArray.length; i++) {
			getElementDiv(DivArray[i]).style.display = (getElementDiv(DivArray[i]).style.display == "none" ? "block" : "none");
		}
	}

	function DivOn2(id) {
		var DivArray;
		var i;
		
		DivArray = id.split(",")

		for (i = 0; i < DivArray.length; i++) {
			getElementDiv(DivArray[i]).style.display = "block";
		}
	}

	function SelectAll(id, nb) {
		var i;

		for (i = 0; i < nb; i++) {
			getElementDiv(id + i).checked = true;
		}
	}

	function UnselectAll(id, nb) {
		var i;

		for (i = 0; i < nb; i++) {
			getElementDiv(id + i).checked = false;
		}
	}

	function Inverser(id, nb) {
		var i;

		for (i = 0; i < nb; i++) {
			if (getElementDiv(id + i).checked) {
				getElementDiv(id + i).checked = false;
			} else {
				getElementDiv(id + i).checked = true;
			}
		}
	}

	function SelectList(id) {
		var DivArray;
		var i;
		
		DivArray = id.split(",")

		for (i = 0; i < DivArray.length; i++) {
			getElementDiv(DivArray[i]).checked = true;
		}
	}

	function UnselectList(id) {
		var DivArray;
		var i;
		
		DivArray = id.split(",")

		for (i = 0; i < DivArray.length; i++) {
			getElementDiv(DivArray[i]).checked = false;
		}
	}

	Ajax = {};

	Ajax.Request = function(url, options){
		var request = null;

		var tentatives = [
			function(){return new XMLHttpRequest();},
			function(){return new ActiveXObject("Msxml2.XMLHTTP");},
			function(){return new ActiveXObject("Microsoft.XMLHTTP");},
			];

		for (i=0;(null==request)&&i<tentatives.length;i++)
		{
			try{
				request = tentatives[i]();
			}
			catch(e){
				continue;
			}
		}

		if (null == request)
			throw new Error("XmlHttp non supporté");

		options = options||{};

		request.onreadystatechange = function() {
			if (request.readyState == 4)
				if ( (request.status == 200) && (options.onSuccess) )
					options.onSuccess(request);
				else if (options.onFailure)
					options.onFailure(request)
		}

		options.method = options.method || "get";

		switch(options.method.toLowerCase()){
			case "get":
				request.open(options.method.toUpperCase(), url + (options.parameters?("?" + options.parameters):""), true);
				request.send(null);
				break;
			case "post":
				request.open(options.method.toUpperCase(), url, true);
				request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				request.setRequestHeader("Content-Length", (options.parameters?("'" + options.parameters.length + "'"):"0"));
				request.send(options.parameters||"");
				break;
			default:
				break;
		}
	}

	Ajax.EncodeParameters = function(parameters){
		if ("object" == typeof parameters){
			var ar = [];
			for (name in parameters){
				var value = parameters[name].toString();
				ar.push(encodeURIComponent(name).replace(/%20/,"+") + '=' +
					encodeURIComponent(value).replace(/%20/,"+"));
			}
			return ar.join("&");
		}
		else
			return "";
	}

	function Confirmation(text, url) {
		var answer = confirm(text);
		if (answer){
			window.location = url;
		} else{
			return false;
		}
	}

	function vire_accents(my_string) {
		var new_string = "";
		var pattern_accent = new Array("À","Á","Â","Ã","Ä","Å","à","á","â","ã","ä","å","Ò","Ó","Ô","Õ","Ö","Ø","ò","ó","ô","õ","ö","ø","È","É","Ê","Ë","è","é","ê","ë","Ì","Í","Î","Ï","ì","í","î","ï","Ù","Ú","Û","Ü","ù","ú","û","ü","ÿ","Ñ","ñ","Ç","ç");
		var pattern_replace_accent = new Array("A","A","A","A","A","A","a","a","a","a","a","a","O","O","O","O","O","O","o","o","o","o","o","o","E","E","E","E","e","e","e","e","I","I","I","I","i","i","i","i","U","U","U","U","u","u","u","u","y","N","n","C","c");
		if (my_string && my_string != "") {
			new_string = preg_replace (pattern_accent, pattern_replace_accent, my_string);
			}
		return new_string;
	}

	function preg_replace (array_pattern, array_pattern_replace, my_string) {
		var new_string = String (my_string);
		for (i=0; i<array_pattern.length; i++) {
			var reg_exp = RegExp(array_pattern[i], "gi");
			var val_to_replace = array_pattern_replace[i];
			new_string = new_string.replace (reg_exp, val_to_replace);
		}
		return new_string;
	}

	function updateEtoile(ref, note) {
		new Ajax.Request('/compte/agenda/noter.ajax.php',{method:'post',onSuccess:function(xhr){if (xhr.responseText == '1') {setEtoile(ref, note, 'red');setTimeout('setEtoile(' + ref + ', ' + note + ')', 600);getElementDiv('ietoile' + ref).value = note;}},onFailure:function(){getElementDiv('etoile' + ref).innerHTML = '<h5 style="color: #F00;">Une erreur est survenue</h5>';}, parameters:'refconcert=' + ref + '&note=' + note})
	}

	function setEtoile(ref, note, couleur) {
		if (couleur == undefined || couleur == '') { couleur = 'orange'; }
		for (i = 1; i <= 5; i++) {
			if (i <= note) {
				getElementDiv('e' + ref + 'p' + i).src = 'http://www.upconcert.com/img/etoile/' + couleur + '.gif';
			} else {
				getElementDiv('e' + ref + 'p' + i).src = 'http://www.upconcert.com/img/etoile/grey.gif';
			}
		}
	}

	function getNote(ref, note, couleur) {
		var text = '';
		if (couleur == undefined || couleur == '') { couleur = 'orange'; }
		for (i = 1; i <= 10; i++) {
			if (i % 2 == 1){ img = 'left'; } else { img = 'right'; }
			if (i <= note) {
				document.getElementById('e' + ref + 'p' + i).src = 'http://www.upconcert.com/img/note/' + couleur + '_' + img + '.gif';
			} else {
				document.getElementById('e' + ref + 'p' + i).src = 'http://www.upconcert.com/img/note/grey_' + img + '.gif';
			}
		}
	}

	function setNote(refnote, refconcert, refartiste, note) {
		getNote(refnote, note, 'red');
		document.getElementById('ietoile' + refnote).value = note;
		new Ajax.Request('/compte/agenda/ajax/setnote.ajax.html',{method:'post',onSuccess:function(xhr){if (xhr.responseText == '1') {getNote(refnote, note);}},onFailure:function(){}, parameters:'refconcert=' + refconcert + '&refartiste=' + refartiste + '&note=' + note / 2})
	}

	function printEtoile(ref, note) {
		for (i = 1; i <= 5; i++) {
			if (i <= note) {
				document.write('<a href="javascript:void(0);" onClick="updateEtoile(' + ref + ', ' + i + ')" style="outline: 0px;"><img id="e' + ref + 'p' + i + '" src="http://www.upconcert.com/img/etoile/orange.gif" width="14" height="13" border="0" alt="" onMouseOver="setEtoile(' + ref + ', ' + i + ')" onMouseOut="setEtoile(' + ref + ', getElementDiv(\'ietoile' + ref + '\').value)" /></a>');
			} else {
				document.write('<a href="javascript:void(0);" onClick="updateEtoile(' + ref + ', ' + i + ')" style="outline: 0px;"><img id="e' + ref + 'p' + i + '" src="http://www.upconcert.com/img/etoile/grey.gif" width="14" height="13" border="0" alt="" onMouseOver="setEtoile(' + ref + ', ' + i + ')" onMouseOut="setEtoile(' + ref + ', getElementDiv(\'ietoile' + ref + '\').value)" /></a>');
			}
		}
	}

	function printEtoileOff(ref, url) {
		for (i = 1; i <= 5; i++) {
			document.write('<a href="/compte/?url=' + url + '"><img id="e' + ref + 'p' + i + '" src="http://www.upconcert.com/img/etoile/grey.gif" width="14" height="13" border="0" alt="" onMouseOver="setEtoile(' + ref + ', ' + i + ')" onMouseOut="setEtoile(' + ref + ', 0)" /></a>');
		}
	}
	
	function trim (chaine) {
		return chaine.replace(/^\s+/g,'').replace(/\s+$/g,'')
	}

	function in_array(needle, haystack) {
		var key = '';

		for (key in haystack) {
			if (haystack[key] == needle) {
				return true;
			}
		}
		return false;
	}

	function addslashes(ch) {
		ch = ch.replace(/\\/g,"\\\\")
		ch = ch.replace(/\'/g,"\\'")
		ch = ch.replace(/\"/g,"\\\"")
		return ch
	}

	function tab(genre, step) {
		if (step == 'on') {
			DivOff(genre + '_off');
			DivOn2(genre + '_on');
		} else {
			DivOff(genre + '_on');
			DivOn2(genre + '_off');
		}
	}

	function trim(myString) {
		return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
	}

	function timestamp() {
		return Math.round(Math.random()*10000000000);
	}

	function EventOn(url) {
		var params = '';
		var postop = 0;
		if (url.indexOf('?') != -1) {
			params = url.substring(url.indexOf('?') + 1, url.length);
		}

		postop = document.body.scrollTop + document.documentElement.scrollTop;

		DivOn('eventbg,event');
		document.getElementById('eventbg').style.top = postop + 'px';
		document.getElementById('event').style.top = (postop + (getWindowHeight() / 4)) + 'px';
		document.body.style.overflow = 'hidden';
		document.getElementById('eventframe').innerHTML = '<img src="http://www.upconcert.com/img/loading.gif" width="16" height="16" border="0" style="vertical-align: middle;" /><h5> Chargement...</h5>';
		new Ajax.Request(url,{method:'post',onSuccess:function(xhr){document.getElementById('eventframe').innerHTML = xhr.responseText;AddScript(document.getElementById('eventframe'));},onFailure:function(){document.getElementById('eventframe').innerHTML = '<h5 style="color: #F00;">Une erreur est survenue</h5>';}, parameters:params})
	}

	function EventOff() {
		DivOff('eventbg,event');
		document.body.style.overflow = 'scroll';
	}

	function error_message(message) {
		var text = ''; var img = ''; var color = '';
		if (message.substring(0, 4) == '[PB]') {
			img = '<img src="http://www.upconcert.com/img/icon/error_24.gif" width="24" height="24" border="0" alt="" style="vertical-align: middle;" />';
			color = 'C20000';
			message = message.substring(4, message.length);
		} else if (message.substring(0, 4) == '[OK]') {
			img = '<img src="http://www.upconcert.com/img/icon/check_24.gif" width="24" height="24" border="0" alt="" style="vertical-align: middle;" />';
			color = '390';
			message = message.substring(4, message.length);
		} else {
			color = '999';
		}
		text += '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>';
		if (img != '') {
			text += '<td width="24" style="padding: 5px;">' + img + '</td>';
		}
		text += '<td style="padding: 5px; background: #' + color + ';"><h4 style="color: #FFF;"><b>' + message + '</b></h4></td></tr></table>';
		return text;
	}

	function SignIn() {
		document.getElementById('eventmessage').innerHTML = '<img src="http://www.upconcert.com/img/loading.gif" width="16" height="16" border="0" style="vertical-align: middle;" /><h5> Chargement...</h5>';
		new Ajax.Request('/compte/auth.ajax.html',{method:'post',onSuccess:function(xhr){if(xhr.responseText=='1'){EventOn(document.getElementById('signinurl').value)}else{document.getElementById('eventmessage').innerHTML = error_message('[PB]Votre adresse e-mail et/ou votre mot de passe sont incorrects.');}},onFailure:function(){document.getElementById('eventmessage').innerHTML = error_message('[PB]Une erreur est survenue');}, parameters:'email=' + document.getElementById('signinemail').value + '&password=' + document.getElementById('signinpassword').value})
	}
	
	function showlist(id, list) {
		var DivArray;
		var i;
		var divid;
		
		DivArray = list.split(",")

		for (i = 0; i < DivArray.length; i++) {
			divid = id + DivArray[i];
			getElementDiv(divid).style.display = (getElementDiv(divid).style.display == "none" ? "block" : "none");
		}
	}
	
	function selectlist(id, list, flag) {
		var DivArray;
		var i;
		
		DivArray = list.split(",")

		for (i = 0; i < DivArray.length; i++) {
			getElementDiv(id + DivArray[i]).checked = flag;
		}
	}

	function postcritique(idconcert) {
		if (trim(document.getElementById('critiquetitle').value) != '' && trim(document.getElementById('critiquebody').value) != '') {
			document.getElementById('buttoncritique').innerHTML = '<img src="http://www.upconcert.com/img/loading.gif" width="16" height="16" border="0" style="vertical-align: middle;" /><h5> Envoi en cours...</h5>';
			new Ajax.Request('/compte/agenda/ajax/critique.ajax.html',{method:'post',onSuccess:function(xhr){document.getElementById('eventframe').innerHTML = xhr.responseText;},onFailure:function(){document.getElementById('eventmessage').innerHTML = error_message('[PB]Une erreur est survenue');}, parameters:'idconcert=' + idconcert + '&titre=' + escape(document.getElementById('critiquetitle').value) + '&corps=' + escape(document.getElementById('critiquebody').value)})
		} else {
			alert('Vous devez écrire un titre et une critique');
		}
	}

	function AddScript(object) {
		var d = object.getElementsByTagName("script");
		var t = d.length;
		for (var x = 0; x < t; x++) {
			var newScript = document.createElement('script');
			newScript.type = "text/javascript";
			newScript.text = d[x].text;
			object.appendChild (newScript);
		}
	}

	function SelectShow(id){
		if (document.getElementById(id).style.display == 'none') {
			document.getElementById(id).style.display = 'block';
			divactive = id;
		} else {
			document.getElementById(id).style.display = 'none';
		}
	}

	function SelectSet(type, id, text){
		document.getElementById('i' + type).value = id;
		document.getElementById('t' + type).innerHTML = '<h5>' + text + '</h5>';
	}

	function getWindowHeight() {
		var windowHeight=0;
		if (typeof(window.innerHeight)=='number') {
			windowHeight=window.innerHeight;
		} else {
			if (document.documentElement && document.documentElement.clientHeight) {
				windowHeight = document.documentElement.clientHeight;
			} else {
				if (document.body&&document.body.clientHeight) {
					windowHeight=document.body.clientHeight;
				}
			}
		}
		return windowHeight;
	}