	var ok = "img/design/default/form/valid.png";
	var no = "img/design/default/form/croix.png";
	var nv = "img/design/default/form/info.png";
	
function switch_valc(field, old_value, new_value, new_class)
{
	if (field.value == old_value) {
		field.value = new_value;
		if (new_class != null)
			field.className = new_class;
	}
}
function switch_type(field, old_value)
{
	if(field.getAttribute('type')=='text')
		field.setAttribute('type','password');
	else if (field.value == old_value)
		field.setAttribute('type','text');
}
function switch_signastro(day, month, img) {
	if (day != 0 && month != 0) {
		var astro = file('libs/getastro.php?a=get&d='+day+'&m='+month);
		img.src = "img/design/default/astro/" + astro + ".png";
		img.title = astro;
	}
}

function file(fichier)
{
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);
		
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) return(xhr_object.responseText);
	else return(false);
}

function exCP(cp, img, inpCity) {
	if(cp.value.length<5 || cp.value.length>5) {
		img.src=no;
		img.title="Code Postal invalide !"
	}
	else if(text = file('libs/verifcp.php?cp='+escape(cp.value))) {
		if(text == 1) {
			img.src=ok;
			img.title="Code Postal valide !"
		}
		else {
			img.src=no;
			img.title="Code Postal invalide !"
		}
	}
	else {
		img.src=nv;
		img.title="Impossible de savoir si le Code Postal est valide..."
	}
}

$(document).ready(function() {
	$('#id_cp').keyup(function() {
		var valeur = $('#id_cp').val();
			$.ajax({
				type: 'GET',
				dataType: 'json',
				url: 'libs/getcity.php?a=get&',
				data: {cp: valeur},
				success: 
					function(json) {
						if (json != null)
							document.getElementById('id_ville').innerHTML = '';
						loadCity(json);
					}
			});
		return false;
	});
});

function loadCity(cities) {
	var i = 0;
	for(var key in cities) {
        document.getElementById('id_ville').options[i] = new Option(cities[key].ville,cities[key].id);
        i++;
	}
}

$(function() {
	$('a[rel*=lightbox]').lightBox();
	/*var first = $('#page div').eq(0), ok = false, elem = first;
	for (;!ok;) {
		elem = elem.next()
		if (elem.is('div')) ok = true;
	}
	setInterval(function(){
		elem.css('minHeight', first.height());
	}, 500);*/
	$('object').each(function () {
		var param = $(this).find('param[name=wmode]');
		if (param.length == 0) {
			$('<param name="wmode" value="transparent" />').appendTo(this);
		} else {
			param.attr('value', 'transparent');
		}
		$(this).find('embed').attr('wmode', 'transparent');
		$(this).attr('wmode', 'transparent');
	});
	$('.menu ul li').hover(function () {
		if ($.browser.msie && ($.browser.version=="6.0" || $.browser.version=="7.0")) {
			$(this).find('ul').css('display', 'block');
			if (!$(this).parent().parent().is('li')) {
				$(this).css('background', "url('images/design/menu.png')");
			}
			if ($.browser.version=="6.0")
				$(this).find('ul').css('visibility', 'visible');
		} else {
			$(this).find('ul').stop(true, true).slideDown(400);
		}
	}, function () {
		if ($.browser.msie && ($.browser.version=="6.0" || $.browser.version=="7.0")) {
			$(this).find('ul').css('display', 'none');
			if (!$(this).parent().parent().is('li')) {
				$(this).css('background', 'none');
			}
			if ($.browser.version=="6.0")
				$(this).find('ul').css('visibility', 'hidden');
		} else {
			$(this).find('ul').stop(true, true).slideUp();
		}
	});
});

function voteTitre() {
    alert('Les votes sont momentanément suspendus car une maintenance est en cours...'+"\n"+'Merci de votre compréhension.');
    /*      voteTitre(cible, vote)
	var res = file('libs/vote.php?a=titre&c='+ cible +'&v='+ vote);

	if(res == 0) {
                jQuery.facebox('<h2 id=\'ok\'>Vote enregistré !</h2>Nous avons bien pris en compte ton vote.<br />Merci de ta participation !');
        }
        else {
                jQuery.facebox('<h2 id=\ko\'>Vote interrompu !</h2>Une erreur inattendue est survenue...<br />Nous te conseillons de recommencer ultérieurement.');
        }
    */
}

var LWtitre = " ";
var LWimage = " ";
var LWemission = " ";

var timerdedis = '';
var timeronair = '';

function emission () {
	var fich = file('libs/getinfo.php?a=get&d=emis');
	var data = typeof JSON !='undefined' ?  JSON.parse(fich) : eval('('+fich+')');

	if (LWemission != data.name) {
		if (LWemission != null) {
			$("#pic-onair").fadeTo(2500, 0.01, function () {
				$("#pic-onair").html('<img src="img/emission/' + data.image + '" alt="' + data.name + '" title="' + data.name + '" />');
			}).fadeTo(2500, 0.9);
			$("#anim-onair").html(data.anim);
			$("#time-onair").html(data.start + " - " + data.end);
			$("#info-onair").html(data.desc);
			$("#heure-next").html(data.after.start);
			$("#nom-emission").html(data.after.name);
			$("#info-emission").html(data.after.anim);
		} else {
			$("#pic-onair").html('<img src="img/emission/' + data.image + '" alt="' + data.name + '" title="' + data.name + '" />');
			$("#anim-onair").html(data.anim);
			$("#time-onair").html(data.start + " - " + data.end);
			$("#info-onair").html(data.desc);
			$("#heure-next").html(data.start);
			$("#nom-emission").html(data.after.name);
			$("#info-emission").html(data.after.anim);
		}
		LWemission = data.name;
		file('libs/server.php');
		setLector('listen.m3u', 'standard');
		setLector('listen.m3u', 'standard');
	}
}

function picTitre (titre) {	
	var image = file('libs/getinfo.php?a=get&d=pic&t='+escape(titre));
	
	if (LWimage != image) {
		if (LWimage != null) {
			$("#image-titre").fadeTo(2500, 0.01, function () {
				$("#image-titre").html('<img src="' + image + '" alt="Illustration du titre en cours de chargement..." />');
			}).fadeTo(2500, 0.9);
		} else {
			$("#image-titre").html('<img src="' + image + '" alt="Illustration du titre en cours de chargement" />');
		}
		LWimage = image;
	}
}

function onAir () {
	var titre = file('titre.txt');
	
	if (LWtitre != titre) {
		if (LWtitre != null) {
                    /*
			$("#letitreencours").fadeTo(2500, 0.01, function () {
				$("#letitreencours").html(titre);
			}).fadeTo(2500, 0.9); */
                    $("#letitreencours").html(titre);
		} else
			$("#letitreencours").html(titre);
		LWtitre = titre;
		picTitre(LWtitre);
		if(titre != '<div style="font-style:italic; font-size:8px; text-align:center;">Un Max de BoN SoN sur ta WebRadio préférée !<br />Listen with caution...</div>') {
			$('#votepour').attr("href", "javascript:voteTitre('"+ titre +"', 'pour')");
			$('#votecontre').attr("href", "javascript:voteTitre('"+ titre +"', 'contre')");
		}
		else {
			$('#votepour').attr("href", "javascript:jQuery.facebox('<h2 id=\\'ko\\'>Vote impossible !</h2>Aucun titre n\\'est indiqué pour le moment.<br />Nous t\\'invitons à réessayer ultérieurement...')");
			$('#votecontre').attr("href", "javascript:jQuery.facebox('<h2 id=\\'ko\\'>Vote impossible !</h2>Aucun titre n\\'est indiqué pour le moment.<br />Nous t\\'invitons à réessayer ultérieurement...')");
		}
	}
	emission();
}

function flashDetect () {
	var flashinstalled = 0;
	MSDetect = "false";
	if (navigator.mimeTypes && navigator.mimeTypes.length) {
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin) flashinstalled = 2;
		else flashinstalled = 1;
	}
	else {MSDetect = "true";}
	
	if (flashinstalled == 1) {
		$("#fplayerbox").html('<div class="noflplayer" title="Télécharger le plugin Flash Player..." onclick="gotourl(\'http://get.adobe.com/fr/flashplayer/\', 1);"></div>');
	}
	else {
		var flux = file('libs/server.php?a=get');
		setLector(flux,'flash');
	}
}

function loadOnAir () {
	onAir();
        if(timerdedis != null) {
            clearInterval(timerdedis);
            timerdedis = setInterval("lesDedis()", 34600);
        }
        else {timerdedis = setInterval("lesDedis()", 34600);}
        if(timeronair != null) {
            clearInterval(timeronair);
            timeronair = setInterval("onAir()", 20000);
        }
        else {timeronair = setInterval("onAir()", 20000);}
	flashDetect();
	heure();
}

function heure() {
		auj = new Date();
		h = auj.getHours();
		m = auj.getMinutes();
		s = auj.getSeconds();
		
		if(h<10)
			h = '0'+h;
                if(m<10)
			m = '0'+m;
                if(s<10)
			s = '0'+s;

		date = ''+h+' h '+m+' min '+s+'';
		
		if(document.getElementById)
			document.getElementById("heure_dyna").innerHTML = date;
		else if(document.all)
			document.all["heure_dyna"].innerHTML = date;
			
		setTimeout("heure()", 1000);
}

/*
function scroll(id, hmax) {
	var scrollTimer = null;
	var o = document.getElementById(id);
	scrollTimer = setInterval(function() {
		var h = o.offsetHeight;
		if (h != hmax) { h++; }
		else { clearInterval(scrollTimer); }
		o.style.height=h+"px";
	}, 10);
} */

function setLector(flux, type) {
        var lector = '';
	if (type == 'flash') {
		lector = '					<object class="fplayer">'
					+ '						<param name="movie" value="player.swf" />'
					+ '						<param name="flashvars" value="url=' + flux + '&amp;lang=fr&amp;codec=mp3&amp;volume=100&amp;autoplay=false&amp;tracking=false&amp;jsevents=false&amp;buffering=5&amp;skin=player.xml&amp;title=LaWadio&trade;%20OnLive%20!&amp;welcome=Listen%20with%20Caution..." />'
					+ '						<param name="wmode" value="window" />'
					+ '						<param name="allowscriptaccess" value="always" />'
					+ '						<param name="scale" value="noscale" />'
					+ '						<embed class="fplayer" type="application/x-shockwave-flash" src="player.swf" flashvars="url=' + flux + '&amp;lang=fr&amp;codec=mp3&amp;volume=100&amp;autoplay=false&amp;tracking=false&amp;jsevents=false&amp;buffering=5&amp;skin=player.xml&amp;title=LaWadio&trade;%20OnLive%20!&amp;welcome=Listen%20with%20Caution..." scale="noscale" wmode="window" allowscriptaccess="always" />'
					+ '					</object>'
		$("#fplayerbox").html(lector);
	}
	else {
		lector = '										<object width="400" height="62" standby="Loading Microsoft Windows Media Player components...">'
					+ '											<param name="AudioStream" value="-1" />'
					+ '											<param name="AutoSize" value="0" />'
					+ '											<param name="AutoStart" value="-1" />'
					+ '											<param name="AnimationAtStart" value="-1" />'
					+ '											<param name="AllowScan" value="-1" />'
					+ '											<param name="AllowChangeDisplaySize" value="-1" />'
					+ '											<param name="AutoRewind" value="0" />'
					+ '											<param name="Balance" value="0" />'
					+ '											<param name="BufferingTime" value="5" />'
					+ '											<param name="ClickToPlay" value="-1" />'
					+ '											<param name="CursorType" value="0" />'
					+ '											<param name="CurrentPosition" value="1" />'
					+ '											<param name="CurrentMarker" value="0" />'
					+ '											<param name="DisplayBackColor" value="0" />'
					+ '											<param name="DisplayForeColor" value="16777215" />'
					+ '											<param name="DisplayMode" value="0" />'
					+ '											<param name="DisplaySize" value="4" />'
					+ '											<param name="Enabled" value="-1" />'
					+ '											<param name="EnableContextMenu" value="-1" />'
					+ '											<param name="EnablePositionControls" value="-1" />'
					+ '											<param name="EnableFullScreenControls" value="0" />'
					+ '											<param name="EnableTracker" value="-1" />'
					+ '											<param name="Filename" value="' + flux + '"/>'
					+ '											<param name="InvokeURLs" value="-1" />'
					+ '											<param name="Language" value="1" />'
					+ '											<param name="Mute" value="0" />'
					+ '											<param name="PlayCount" value="1" />'
					+ '											<param name="PreviewMode" value="0" />'
					+ '											<param name="Rate" value="1" />'
					+ '											<param name="SelectionStart" value="-1" />'
					+ '											<param name="SelectionEnd" value="-1" />'
					+ '											<param name="SendOpenStateChangeEvents" value="-1" />'
					+ '											<param name="SendWarningEvents" value="-1" />'
					+ '											<param name="SendErrorEvents" value="-1" />'
					+ '											<param name="SendKeyboardEvents" value="0" />'
					+ '											<param name="SendMouseClickEvents" value="0" />'
					+ '											<param name="SendMouseMoveEvents" value="0" />'
					+ '											<param name="SendPlayStateChangeEvents" value="-1" />'
					+ '											<param name="ShowCaptioning" value="0" />'
					+ '											<param name="ShowControls" value="-1" />'
					+ '											<param name="ShowAudioControls" value="-1" />'
					+ '											<param name="ShowDisplay" value="0" />'
					+ '											<param name="ShowGotoBar" value="0" />'
					+ '											<param name="ShowPositionControls" value="0" />'
					+ '											<param name="ShowStatusBar" value="-1" />'
					+ '											<param name="ShowTracker" value="-1" />'
					+ '											<param name="TransparentAtStart" value="-1" />'
					+ '											<param name="VideoBorderWidth" value="1" />'
					+ '											<param name="VideoBorderColor" value="1" />'
					+ '											<param name="VideoBorder3D" value="-1" />'
					+ '											<param name="Volume" value="-600" />'
					+ '											<param name="WindowlessVideo" value="-1" />'
					+ '											<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" filename="' + flux + '" src="' + flux + '" showcontrols="1" showdisplay="0" showstatusbar="1" width="400" height="62" align="middle">'
					+ '											</embed>'
					+ '										</object>';
					
		$("#lector").html(lector);
	}
}

function lesDedis() {
	var dedis = file('libs/getinfo.php?a=get&d=dedis');
		$("#alldedis").fadeTo(2500, 0.01, function () {
                        $("#alldedis").empty();
			$("#alldedis").append(dedis);
		}).fadeTo(2500, 0.9);
}

function popUp(url, name, attr) {
    window.open(url,name,attr);
}

function gotourl(url, newwin) {
	if(newwin == 0)
		window.parent.location.href=url; /* $(location).attr('href',url); */
	else
		window.open(url); 
}
function gotourlRebour(num, url, newwin) {
    var time = $('#decpt').text();
    if(time == null) {
        $('#decpt').append(num);
        gotourlRebour(num, url, newwin);
    }
    else if(num == 0) {
        clearTimeout(tempo);
        gotourl(url,newwin);
    }
    else {
        var i = num - 1;
        $('#decpt').empty();
        $('#decpt').append(i);
        tempo = setTimeout(function(){gotourlRebour(i,url,newwin)}, 1000);
    }
}

function openPlayer() {
    popUp('http://player.lawadio.com','RadioPlayer','menubar=no, status=no, scrollbars=no, width=680, height=400, top:90, left:90');
}

function copyToClipboardIE1(sText) {
	window.clipboardData.setData('Text', sText);
	return false;
}

function copyToClipboardFF(sText) {
	try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	}
	catch (e) {
		alert("Impossible d'accéder au presse-papier !\nPour savoir comment remédier à cela, dirige-toi sur notre FAQ.");
	}
	var gClipboardHelper =
		Components.classes["@mozilla.org/widget/clipboardhelper;1"]
		.getService(Components.interfaces.nsIClipboardHelper);
	gClipboardHelper.copyString(sText);
	return false;
}

function copyToClipboard(sText) {
	if (window.clipboardData)
		return copyToClipboardIE1(sText);
	else if (typeof(netscape) == 'object' && typeof(Components) == 'object')
		return copyToClipboardFF(sText);
	else
		alert("Cette fonctionnalité n'est pas disponible pour votre navigateur.");
	return false;
}

var iduser = null;

function loadWadioz(iduser, nbre, numwadioz, i, t){
	if(iduser != null) {
		if (t == 0) {
			var numwadioz = file('libs/getwadioz.php?a=get&i='+escape(iduser));
			t=1;
		}
		
		$('#numbwadioz').html(nbre);
		
		if (12468 + nbre < numwadioz)
			i=12468;
		if (2468 + nbre < numwadioz)
			i=2468;
		else if (246 + nbre < numwadioz)
			i=246;
		else if (24 + nbre < numwadioz)
			i=24;
		else
			i=2;
		
		nbre += i;
		if (nbre < numwadioz) {
			var writWadioz = setTimeout("loadWadioz(" + iduser + ", " + nbre + ", " + numwadioz + ", " + i + ", " + t + ")", 100);
		}
		else {
			$('#numbwadioz').html(numwadioz);
			clearTimeout(writWadioz);
		}
	}
}

function favori() {
	if (window.sidebar) {
		window.sidebar.addPanel('LaWadio™ OnLive !', 'http://www.lawadio.com','');
	}
	else if ( window.external ) {
		window.external.AddFavorite('http://www.lawadio.com', 'LaWadio™ OnLive !');
	}
}
function homePage(obj) {
	obj.style.behavior='url(#default#homepage)';
	obj.setHomePage('http://www.lawadio.com');
}

function openNewWindow(lurl, lenom, width, height) {
	var left = Math.round( (screen.width - width) / 2 ),
		top = Math.round( (screen.height - height) / 2 );
	if (left<0) left = 0;
	if (top<0) top = 0;
	window.open(lurl, lenom, 'toolbar=0,menubar=0,resize=0,location=1,scrollbars=1,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left);
}

if(etatch == null) var etatch = 0;
function scrollCh() {
	var hmax;
	var scrollChTimer = null;
	var o = document.getElementById('chat');
	if(etatch == 0) {
		hmax = 300;
		etatch = 1;
		$("#ch_close").fadeTo(600, 0.01, function () {
			$("#ch_close").css('display', 'block');
		}).fadeTo(600, 0.9);
	}
	else {
		hmax = 30;
		etatch = 0;
		$("#ch_close").fadeTo(800, 0.01, function () {
			$("#ch_close").css('display', 'none');
		}).fadeTo(100, 0.9);
	}
	
	scrollChTimer = setInterval(function() {
		var h = o.offsetHeight;
		if (h != hmax) {
			if(etatch == 1) h = h + 10;
			else h = h - 10;
		}
		else {clearInterval(scrollChTimer);}
		o.style.height=h+"px";
	}, 0);
}
